]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
Use IOBuffer with its StrBuf + const char* inside instead of having two of them
[citadel.git] / citadel / modules / network / serv_network.c
index 075b4578a9616204d3ae5af0497192bc9df386da..300b1b6bc37aaaffac17d18a94caebcc446f2951 100644 (file)
@@ -682,6 +682,9 @@ void network_spool_msg(long msgnum, void *userdata) {
                 */
                msg = CtdlFetchMessage(msgnum, 1);
                if (msg != NULL) {
+                       int len, rlen;
+                       char *pCh;
+
                        if (msg->cm_fields['V'] == NULL){
                                /* local message, no enVelope */
                                StrBuf *Buf;
@@ -711,9 +714,26 @@ void network_spool_msg(long msgnum, void *userdata) {
                        if (msg->cm_fields['U'] == NULL) {
                                msg->cm_fields['U'] = strdup("(no subject)");
                        }
-                       snprintf(buf, sizeof buf, "[%s] %s", CC->room.QRname, msg->cm_fields['U']);
-                       free(msg->cm_fields['U']);
-                       msg->cm_fields['U'] = strdup(buf);
+                       
+                       len  = strlen(msg->cm_fields['U']);
+                       rlen = strlen(CC->room.QRname);
+                       pCh  = strstr(msg->cm_fields['U'], CC->room.QRname);
+                       if ((pCh == NULL) ||
+                           (*(pCh + rlen) != ']') ||
+                           (pCh == msg->cm_fields['U']) ||
+                           (*(pCh - 1) != '[')
+                               )
+                       {
+                               char *pBuff;
+
+                               rlen += len + 4;
+                               pBuff = malloc (rlen * sizeof(char));
+
+                               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. */
 
                        /* Set the recipient of the list message to the
                         * email address of the room itself.
@@ -2160,9 +2180,9 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
        }
        
        CtdlLogPrintf(CTDL_DEBUG, "Connected!\n");
-       CCC->sReadBuf = NewStrBuf();
+       CCC->SBuf.Buf = NewStrBuf();
        CCC->sMigrateBuf = NewStrBuf();
-       CCC->sPos = NULL;
+       CCC->SBuf.ReadWritePointer = NULL;
 
        /* Read the server greeting */
        if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
@@ -2199,7 +2219,7 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
 
        sock_puts(&sock, "QUIT");
 bail:  
-       FreeStrBuf(&CCC->sReadBuf);
+       FreeStrBuf(&CCC->SBuf.Buf);
        FreeStrBuf(&CCC->sMigrateBuf);
        if (sock != -1)
                sock_close(sock);