]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
Fix warnings all over citserver; handle function replies; remove unused code.
[citadel.git] / citadel / modules / network / serv_network.c
index 99d7f6a28d3f9d86afadc9fc683759ca20cabe19..7955f5a2eb935ebe4b16336c2f0d51a9653a9a36 100644 (file)
@@ -494,7 +494,6 @@ void network_deliver_digest(SpoolControl *sc) {
        long msglen;
        char *recps = NULL;
        size_t recps_len = SIZ;
-       size_t siz;
        struct recptypes *valid;
        namelist *nptr;
        char bounce_to[256];
@@ -541,7 +540,7 @@ void network_deliver_digest(SpoolControl *sc) {
 
        msg->cm_fields['M'] = malloc(msglen + 1);
        fseek(sc->digestfp, 0L, SEEK_SET);
-       siz = fread(msg->cm_fields['M'], (size_t)msglen, 1, sc->digestfp);
+       fread(msg->cm_fields['M'], (size_t)msglen, 1, sc->digestfp);
        msg->cm_fields['M'][msglen] = '\0';
 
        fclose(sc->digestfp);
@@ -653,7 +652,6 @@ void network_spool_msg(long msgnum, void *userdata) {
        SpoolControl *sc;
        int i;
        char *newpath = NULL;
-       size_t instr_len = SIZ;
        struct CtdlMessage *msg = NULL;
        namelist *nptr;
        maplist *mptr;
@@ -672,15 +670,15 @@ void network_spool_msg(long msgnum, void *userdata) {
        /*
         * Process mailing list recipients
         */
-       instr_len = SIZ;
        if (sc->listrecps != NULL) {
                /* Fetch the message.  We're going to need to modify it
                 * in order to insert the [list name] in it, etc.
                 */
                msg = CtdlFetchMessage(msgnum, 1);
                if (msg != NULL) {
-                       int len, rlen;
+                       int rlen;
                        char *pCh;
+                       StrBuf *Subject, *FlatSubject;
 
                        if (msg->cm_fields['V'] == NULL){
                                /* local message, no enVelope */
@@ -709,39 +707,53 @@ void network_spool_msg(long msgnum, void *userdata) {
 
                        /* Prepend "[List name]" to the subject */
                        if (msg->cm_fields['U'] == NULL) {
-                               msg->cm_fields['U'] = strdup("(no subject)");
+                               Subject = NewStrBufPlain(HKEY("(no subject)"));
                        }
-                       
-                       len  = strlen(msg->cm_fields['U']);
+                       else {
+                               Subject = NewStrBufPlain(msg->cm_fields['U'], -1);
+                       }
+                       FlatSubject = NewStrBufPlain(NULL, StrLength(Subject));
+                       StrBuf_RFC822_to_Utf8(FlatSubject, Subject, NULL, NULL);
+
                        rlen = strlen(CC->room.QRname);
-                       pCh  = strstr(msg->cm_fields['U'], CC->room.QRname);
+                       pCh  = strstr(ChrPtr(FlatSubject), CC->room.QRname);
                        if ((pCh == NULL) ||
                            (*(pCh + rlen) != ']') ||
-                           (pCh == msg->cm_fields['U']) ||
+                           (pCh == ChrPtr(FlatSubject)) ||
                            (*(pCh - 1) != '[')
                                )
                        {
-                               char *pBuff;
+                               StrBuf *tmp;
+                               StrBufPlain(Subject, HKEY("["));
+                               StrBufAppendBufPlain(Subject, CC->room.QRname, rlen, 0);
+                               StrBufAppendBufPlain(Subject, HKEY("] "), 0);
+                               StrBufAppendBuf(Subject, FlatSubject, 0);
+                               tmp = Subject;  Subject = FlatSubject;  FlatSubject = tmp; /* so we can free the right one... */
+                               StrBufRFC2047encode(&Subject, FlatSubject);
+                       }
+                       
+                       if (msg->cm_fields['U'] != NULL)
+                               free (msg->cm_fields['U']);
+                       msg->cm_fields['U'] = SmashStrBuf(&Subject);
 
-                               rlen += len + 4;
-                               pBuff = malloc (rlen * sizeof(char));
+                       FreeStrBuf(&FlatSubject);
 
-                               snprintf(pBuff, rlen, "[%s] %s", CC->room.QRname, msg->cm_fields['U']);
-                               free(msg->cm_fields['U']);
-                               msg->cm_fields['U'] = pBuff;
-                       }
                        /* else we won't modify the buffer, since the roomname is already here. */
 
-                       /* if we don't already have a 'reply to' field, put our roomname in. */
-                       if (msg->cm_fields['K'] == NULL) {
-                               msg->cm_fields['K'] = malloc(256);
-                               snprintf(msg->cm_fields['K'], 256,
-                                        "room_%s@%s", CC->room.QRname,
-                                        config.c_fqdn);
-                               for (i=0; msg->cm_fields['K'][i]; ++i) {
-                                       if (isspace(msg->cm_fields['K'][i])) {
-                                               msg->cm_fields['K'][i] = '_';
-                                       }
+                       /* Set the recipient of the list message to the
+                        * email address of the room itself.
+                        * FIXME ... I want to be able to pick any address
+                        */
+                       if (msg->cm_fields['R'] != NULL) {
+                               free(msg->cm_fields['R']);
+                       }
+                       msg->cm_fields['R'] = malloc(256);
+                       snprintf(msg->cm_fields['R'], 256,
+                               "room_%s@%s", CC->room.QRname,
+                               config.c_fqdn);
+                       for (i=0; msg->cm_fields['R'][i]; ++i) {
+                               if (isspace(msg->cm_fields['R'][i])) {
+                                       msg->cm_fields['R'][i] = '_';
                                }
                        }
 
@@ -795,7 +807,6 @@ void network_spool_msg(long msgnum, void *userdata) {
        /*
         * Process client-side list participations for this room
         */
-       instr_len = SIZ;
        if (sc->participates != NULL) {
                msg = CtdlFetchMessage(msgnum, 1);
                if (msg != NULL) {
@@ -1986,7 +1997,7 @@ void receive_spool(int *sock, char *remote_nodename) {
                 * If shutting down we can exit here and unlink the temp file.
                 * this shouldn't loose us any messages.
                 */
-               if (CtdlThreadCheckStop())
+               if (server_shutting_down)
                {
                        fclose(fp);
                        unlink(tempfilename);
@@ -2028,7 +2039,7 @@ void receive_spool(int *sock, char *remote_nodename) {
        fclose(fp);
 
        /* Last chance for shutdown exit */
-       if (CtdlThreadCheckStop())
+       if (server_shutting_down)
        {
                unlink(tempfilename);
                return;
@@ -2099,7 +2110,7 @@ void transmit_spool(int *sock, char *remote_nodename)
                bytes_to_write = plen;
                while (bytes_to_write > 0L) {
                        /* Exit if shutting down */
-                       if (CtdlThreadCheckStop())
+                       if (server_shutting_down)
                        {
                                close(fd);
                                return;
@@ -2132,7 +2143,7 @@ ABORTUPL:
        close(fd);
 
        /* Last chance for shutdown exit */
-       if(CtdlThreadCheckStop())
+       if(server_shutting_down)
                return;
                
        if (sock_puts(sock, "UCLS 1") < 0) return;
@@ -2205,9 +2216,9 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
                }
        
                /* At this point we are authenticated. */
-               if (!CtdlThreadCheckStop())
+               if (!server_shutting_down)
                        receive_spool(&sock, node);
-               if (!CtdlThreadCheckStop())
+               if (!server_shutting_down)
                        transmit_spool(&sock, node);
        }
 
@@ -2244,7 +2255,7 @@ void network_poll_other_citadel_nodes(int full_poll) {
 
        /* Use the string tokenizer to grab one line at a time */
        for (i=0; i<num_tokens(working_ignetcfg, '\n'); ++i) {
-               if(CtdlThreadCheckStop())
+               if(server_shutting_down)
                        return;
                extract_token(linebuf, working_ignetcfg, i, '\n', sizeof linebuf);
                extract_token(node, linebuf, 0, '|', sizeof node);
@@ -2354,14 +2365,14 @@ void network_do_queue(void) {
        /* 
         * Go ahead and run the queue
         */
-       if (full_processing && !CtdlThreadCheckStop()) {
+       if (full_processing && !server_shutting_down) {
                syslog(LOG_DEBUG, "network: loading outbound queue\n");
                CtdlForEachRoom(network_queue_room, NULL);
        }
 
        if (rplist != NULL) {
                syslog(LOG_DEBUG, "network: running outbound queue\n");
-               while (rplist != NULL && !CtdlThreadCheckStop()) {
+               while (rplist != NULL && !server_shutting_down) {
                        char spoolroomname[ROOMNAMELEN];
                        safestrncpy(spoolroomname, rplist->name, sizeof spoolroomname);
                        begin_critical_section(S_RPLIST);
@@ -2386,7 +2397,7 @@ void network_do_queue(void) {
        }
 
        /* If there is anything in the inbound queue, process it */
-       if (!CtdlThreadCheckStop()) {
+       if (!server_shutting_down) {
                network_do_spoolin();
        }
 
@@ -2436,7 +2447,7 @@ void cmd_netp(char *cmdbuf)
                        "An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
                        node, CC->cs_host, CC->cs_addr
                );
-               syslog(LOG_WARNING, err_buf);
+               syslog(LOG_WARNING, "%s", err_buf);
                cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
                CtdlAideMessage(err_buf, "IGNet Networking.");
                return;
@@ -2447,7 +2458,7 @@ void cmd_netp(char *cmdbuf)
                        "A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
                        CC->cs_host, CC->cs_addr, node
                );
-               syslog(LOG_WARNING, err_buf);
+               syslog(LOG_WARNING, "%s", err_buf);
                cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
                CtdlAideMessage(err_buf, "IGNet Networking.");
                return;