]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
* fill the migrate buffer so the new sock_getln works
[citadel.git] / citadel / modules / network / serv_network.c
index e2d16dd9aa08e521799e10ba0cbfa84cdbf15c23..db178a4b2a12cb5656e727046dcbab7a074f63b0 100644 (file)
@@ -1799,7 +1799,7 @@ void receive_spool(int *sock, char *remote_nodename) {
        FILE *fp, *newfp;
 
        CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
-       if (sock_puts(*sock, "NDOP") < 0) return;
+       if (sock_puts(sock, "NDOP") < 0) return;
        if (sock_getln(sock, buf, sizeof buf) < 0) return;
        CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
        if (buf[0] != '2') {
@@ -1830,7 +1830,7 @@ void receive_spool(int *sock, char *remote_nodename) {
                        bytes_received,
                     ((download_len - bytes_received > IGNET_PACKET_SIZE)
                 ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
-               if (sock_puts(*sock, buf) < 0) {
+               if (sock_puts(sock, buf) < 0) {
                        fclose(fp);
                        unlink(tempfilename);
                        return;
@@ -1859,7 +1859,7 @@ void receive_spool(int *sock, char *remote_nodename) {
                unlink(tempfilename);
                return;
        }
-       if (sock_puts(*sock, "CLOS") < 0) {
+       if (sock_puts(sock, "CLOS") < 0) {
                unlink(tempfilename);
                return;
        }
@@ -1922,7 +1922,7 @@ void transmit_spool(int *sock, char *remote_nodename)
        int fd;
        char sfname[128];
 
-       if (sock_puts(*sock, "NUOP") < 0) return;
+       if (sock_puts(sock, "NUOP") < 0) return;
        if (sock_getln(sock, buf, sizeof buf) < 0) return;
        CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
        if (buf[0] != '2') {
@@ -1953,7 +1953,7 @@ void transmit_spool(int *sock, char *remote_nodename)
                        }
                        
                        snprintf(buf, sizeof buf, "WRIT %ld", bytes_to_write);
-                       if (sock_puts(*sock, buf) < 0) {
+                       if (sock_puts(sock, buf) < 0) {
                                close(fd);
                                return;
                        }
@@ -1963,7 +1963,7 @@ void transmit_spool(int *sock, char *remote_nodename)
                        }
                        thisblock = atol(&buf[4]);
                        if (buf[0] == '7') {
-                               if (sock_write(*sock, pbuf,
+                               if (sock_write(sock, pbuf,
                                   (int) thisblock) < 0) {
                                        close(fd);
                                        return;
@@ -1982,7 +1982,7 @@ ABORTUPL:
        if(CtdlThreadCheckStop())
                return;
                
-       if (sock_puts(*sock, "UCLS 1") < 0) return;
+       if (sock_puts(sock, "UCLS 1") < 0) return;
        /**
         * From here on we must complete or messages will get lost
         */
@@ -2006,6 +2006,7 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
        char buf[SIZ];
        char err_buf[SIZ];
        char connected_to[SIZ];
+       CitContext *CCC=CC;
 
        if (network_talking_to(node, NTT_CHECK)) return;
        network_talking_to(node, NTT_ADD);
@@ -2019,7 +2020,9 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
        }
        
        CtdlLogPrintf(CTDL_DEBUG, "Connected!\n");
-
+       CCC->sReadBuf = NewStrBuf();
+       CCC->sMigrateBuf = NewStrBuf();
+       CCC->sPos = NULL;
        /* Read the server greeting */
        if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
        CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
@@ -2036,7 +2039,7 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
                /* We're talking to the correct node.  Now identify ourselves. */
                snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret);
                CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
-               if (sock_puts(sock, buf) <0) goto bail;
+               if (sock_puts(&sock, buf) <0) goto bail;
                if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
                CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
                if (buf[0] != '2') goto bail;
@@ -2048,8 +2051,12 @@ void network_poll_node(char *node, char *secret, char *host, char *port) {
                        transmit_spool(&sock, node);
        }
 
-       sock_puts(sock, "QUIT");
-bail:  sock_close(sock);
+       sock_puts(&sock, "QUIT");
+bail:  
+       FreeStrBuf(&CCC->sReadBuf);
+       FreeStrBuf(&CCC->sMigrateBuf);
+       if (sock != -1)
+               sock_close(sock);
        network_talking_to(node, NTT_REMOVE);
 }