]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_netspool.c
Networker: Memleaks; make the_netmap pass in both directions, as it was meant to.
[citadel.git] / citadel / modules / network / serv_netspool.c
index c014026458964f927ea1b0c82f25626dbcc3b629..fbd0eb0e5f6bf9b13e6028fe3c34b0637e9f261d 100644 (file)
 /*
  * Learn topology from path fields
  */
-void network_learn_topology(char *node, char *path, NetMap *the_netmap, int *netmap_changed) {
+void network_learn_topology(char *node, char *path, NetMap **the_netmap, int *netmap_changed) {
        char nexthop[256];
        NetMap *nmptr;
 
-       strcpy(nexthop, "");
+       *nexthop = '\0';
 
        if (num_tokens(path, '!') < 3) return;
-       for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) {
+       for (nmptr = *the_netmap; nmptr != NULL; nmptr = nmptr->next) {
                if (!strcasecmp(nmptr->nodename, node)) {
                        extract_token(nmptr->nexthop, path, 0, '!', sizeof nmptr->nexthop);
                        nmptr->lastcontact = time(NULL);
@@ -116,8 +116,8 @@ void network_learn_topology(char *node, char *path, NetMap *the_netmap, int *net
        strcpy(nmptr->nodename, node);
        nmptr->lastcontact = time(NULL);
        extract_token(nmptr->nexthop, path, 0, '!', sizeof nmptr->nexthop);
-       nmptr->next = the_netmap;
-       the_netmap = nmptr;
+       nmptr->next = *the_netmap;
+       the_netmap = &nmptr;
        (*netmap_changed) ++;
 }
 
@@ -380,7 +380,10 @@ int is_recipient(SpoolControl *sc, const char *Name)
 /*
  * Batch up and send all outbound traffic from the current room
  */
-void network_spoolout_room(char *room_to_spool) {
+void network_spoolout_room(char *room_to_spool,                       
+                          char *working_ignetcfg,
+                          NetMap *the_netmap)
+{
        char buf[SIZ];
        char filename[PATH_MAX];
        SpoolControl *sc;
@@ -407,6 +410,9 @@ void network_spoolout_room(char *room_to_spool) {
        }
        syslog(LOG_INFO, "Networking started for <%s>\n", CC->room.QRname);
 
+       sc->working_ignetcfg = working_ignetcfg;
+       sc->the_netmap = the_netmap;
+
        /* If there are digest recipients, we have to build a digest */
        if (sc->digestrecps != NULL) {
                sc->digestfp = tmpfile();
@@ -445,7 +451,7 @@ void network_spoolout_room(char *room_to_spool) {
  * Process a buffer containing a single message from a single file
  * from the inbound queue 
  */
-void network_process_buffer(char *buffer, long size, char *working_ignetcfg, NetMap *the_netmap, int *netmap_changed)
+void network_process_buffer(char *buffer, long size, char *working_ignetcfg, NetMap **the_netmap, int *netmap_changed)
 {
        struct CtdlMessage *msg = NULL;
        long pos;
@@ -497,7 +503,7 @@ void network_process_buffer(char *buffer, long size, char *working_ignetcfg, Net
                                          NULL, 
                                          msg->cm_fields['D'], 
                                          working_ignetcfg, 
-                                         the_netmap) == 0) 
+                                         *the_netmap) == 0) 
                        {
                                /* prepend our node to the path */
                                if (msg->cm_fields['P'] != NULL) {
@@ -629,7 +635,7 @@ void network_process_message(FILE *fp,
                             long msgstart, 
                             long msgend,
                             char *working_ignetcfg,
-                            NetMap *the_netmap, 
+                            NetMap **the_netmap, 
                             int *netmap_changed)
 {
        long hold_pos;
@@ -660,7 +666,7 @@ void network_process_message(FILE *fp,
  */
 void network_process_file(char *filename,
                          char *working_ignetcfg,
-                         NetMap *the_netmap, 
+                         NetMap **the_netmap, 
                          int *netmap_changed)
 {
        FILE *fp;
@@ -717,7 +723,7 @@ void network_process_file(char *filename,
 /*
  * Process anything in the inbound queue
  */
-void network_do_spoolin(char *working_ignetcfg, NetMap *the_netmap, int *netmap_changed)
+void network_do_spoolin(char *working_ignetcfg, NetMap **the_netmap, int *netmap_changed)
 {
        DIR *dp;
        struct dirent *d;
@@ -772,6 +778,7 @@ void network_consolidate_spoolout(char *working_ignetcfg, NetMap *the_netmap)
        char filename[PATH_MAX];
        char cmd[PATH_MAX];
        char nexthop[256];
+       long nexthoplen;
        int i;
        char *ptr;
 
@@ -784,9 +791,12 @@ void network_consolidate_spoolout(char *working_ignetcfg, NetMap *the_netmap)
                        && (strcmp(d->d_name, ".."))
                        && (strchr(d->d_name, '@') != NULL)
                ) {
-                       safestrncpy(nexthop, d->d_name, sizeof nexthop);
+                       nexthoplen = safestrncpy(nexthop, d->d_name, sizeof nexthop);
                        ptr = strchr(nexthop, '@');
-                       if (ptr) *ptr = 0;
+                       if (ptr) {
+                               *ptr = 0;
+                               nexthoplen = ptr - nexthop;
+                       }                               
        
                        snprintf(filename, 
                                sizeof filename,
@@ -796,21 +806,21 @@ void network_consolidate_spoolout(char *working_ignetcfg, NetMap *the_netmap)
                        );
        
                        syslog(LOG_DEBUG, "Consolidate %s to %s\n", filename, nexthop);
-                       if (network_talking_to(nexthop, NTT_CHECK)) {
+                       if (network_talking_to(nexthop, nexthoplen, NTT_CHECK)) {
                                syslog(LOG_DEBUG,
                                        "Currently online with %s - skipping for now\n",
                                        nexthop
                                );
                        }
                        else {
-                               network_talking_to(nexthop, NTT_ADD);
+                               network_talking_to(nexthop, nexthoplen, NTT_ADD);
                                snprintf(cmd, sizeof cmd, "/bin/cat %s >>%s/%s && /bin/rm -f %s",
                                        filename,
                                        ctdl_netout_dir, nexthop,
                                        filename
                                );
                                system(cmd);
-                               network_talking_to(nexthop, NTT_REMOVE);
+                               network_talking_to(nexthop, nexthoplen, NTT_REMOVE);
                        }
                }
        }