* Added a sooper-seekrit way to spool network messages to a remote node
authorArt Cancro <ajc@citadel.org>
Fri, 26 Nov 2004 22:44:09 +0000 (22:44 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 26 Nov 2004 22:44:09 +0000 (22:44 +0000)
  where the room has a different name
* Internal version number is now 6.28, so that WebCit doesn't b0rk the
  netconfigs of older Citadel servers

citadel/ChangeLog
citadel/citadel.h
citadel/routines2.c
citadel/serv_network.c
citadel/serv_network.h

index 880312699033fb5fa329754ed6c2eb17b91d1427..e9433304c787c285e92a168d9cf02a59dbfcd90f 100644 (file)
@@ -1,4 +1,10 @@
  $Log$
+ Revision 627.10  2004/11/26 22:44:08  ajc
+ * Added a sooper-seekrit way to spool network messages to a remote node
+   where the room has a different name
+ * Internal version number is now 6.28, so that WebCit doesn't b0rk the
+   netconfigs of older Citadel servers
+
  Revision 627.9  2004/11/19 02:31:56  ajc
  * Added developer ID # 177
 
@@ -6222,3 +6228,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 47c93997d9fbe7bb66d20731fb5f5d1f14d6e311..44fa989abfd0ba65e0b69764f63815552af6c74a 100644 (file)
@@ -32,7 +32,7 @@ extern "C" {
 /*
  * Text description of this software
  */
-#define CITADEL        "Citadel 6.27"
+#define CITADEL        "Citadel 6.28"
 
 /*
  * REV_LEVEL is the current version number (multiplied by 100 to avoid having
@@ -44,7 +44,7 @@ extern "C" {
  * usually more strict because you're not really supposed to dump/load and
  * upgrade at the same time.
  */
-#define REV_LEVEL      627             /* This version */
+#define REV_LEVEL      628             /* This version */
 #define REV_MIN                591             /* Oldest compatible database */
 #define EXPORT_REV_MIN 626             /* Oldest compatible export files */
 
index 52e836f1860f92839a2b6398de4b8de755a3567b..94772edbb850253bc9052a1effd81912e21dbbd3 100644 (file)
@@ -1018,7 +1018,7 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
        int e_ex_code;
        pid_t editor_pid;
        int cksum;
-       int b, i;
+       int b, i, tokens;
        char buf[SIZ];
        char instr[SIZ];
        char addr[SIZ];
@@ -1054,8 +1054,15 @@ void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
                        remove_token(listing, 0, '\n');
                        extract(instr, buf, 0);
                        if (!strcasecmp(instr, entrytype)) {
-                               extract(addr, buf, 1);
-                               fprintf(tempfp, "%s\n", addr);
+                               tokens = num_tokens(buf, '|');
+                               for (i=1; i<tokens; ++i) {
+                                       extract(addr, buf, i);
+                                       fprintf(tempfp, "%s", addr);
+                                       if (i < (tokens-1)) {
+                                               fprintf(tempfp, "|");
+                                       }
+                               }
+                               fprintf(tempfp, "\n");
                        }
                }
        }
index 145e2eff67491ece0e6f84e51505aac25aace1ae..e014411000681f843579faea15e555cd82452350 100644 (file)
@@ -421,6 +421,7 @@ void network_spool_msg(long msgnum, void *userdata) {
        struct CtdlMessage *msg = NULL;
        struct CtdlMessage *imsg;
        struct namelist *nptr;
+       struct maplist *mptr;
        struct ser_ret sermsg;
        FILE *fp;
        char filename[SIZ];
@@ -521,15 +522,6 @@ void network_spool_msg(long msgnum, void *userdata) {
                        free(msg->cm_fields['P']);
                        msg->cm_fields['P'] = newpath;
 
-                       /*
-                        * Force the message to appear in the correct room
-                        * on the far end by setting the C field correctly
-                        */
-                       if (msg->cm_fields['C'] != NULL) {
-                               free(msg->cm_fields['C']);
-                       }
-                       msg->cm_fields['C'] = strdup(CC->room.QRname);
-
                        /*
                         * Determine if this message is set to be deleted
                         * after sending out on the network
@@ -541,21 +533,16 @@ void network_spool_msg(long msgnum, void *userdata) {
                                }
                        }
 
-                       /* 
-                        * Now serialize it for transmission
-                        */
-                       serialize_message(&sermsg, msg);
-
                        /* Now send it to every node */
-                       for (nptr = sc->ignet_push_shares; nptr != NULL;
-                           nptr = nptr->next) {
+                       for (mptr = sc->ignet_push_shares; mptr != NULL;
+                           mptr = mptr->next) {
 
                                send = 1;
 
                                /* Check for valid node name */
-                               if (is_valid_node(NULL, NULL, nptr->name) != 0) {
+                               if (is_valid_node(NULL, NULL, mptr->remote_nodename) != 0) {
                                        lprintf(CTDL_ERR, "Invalid node <%s>\n",
-                                               nptr->name);
+                                               mptr->remote_nodename);
                                        send = 0;
                                }
 
@@ -565,25 +552,46 @@ void network_spool_msg(long msgnum, void *userdata) {
                                if (bang > 1) for (i=0; i<(bang-1); ++i) {
                                        extract_token(buf, msg->cm_fields['P'],
                                                i, '!');
-                                       if (!strcasecmp(buf, nptr->name)) {
+                                       if (!strcasecmp(buf, mptr->remote_nodename)) {
                                                send = 0;
                                        }
                                }
 
                                /* Send the message */
                                if (send == 1) {
+
+                                       /*
+                                        * Force the message to appear in the correct room
+                                        * on the far end by setting the C field correctly
+                                        */
+                                       if (msg->cm_fields['C'] != NULL) {
+                                               free(msg->cm_fields['C']);
+                                       }
+                                       if (strlen(mptr->remote_roomname) > 0) {
+                                               msg->cm_fields['C'] = strdup(mptr->remote_roomname);
+                                       }
+                                       else {
+                                               msg->cm_fields['C'] = strdup(CC->room.QRname);
+                                       }
+
+                                       /* serialize it for transmission */
+                                       serialize_message(&sermsg, msg);
+
+                                       /* write it to the spool file */
                                        snprintf(filename, sizeof filename,
                                                "./network/spoolout/%s",
-                                               nptr->name);
+                                               mptr->remote_nodename);
                                        fp = fopen(filename, "ab");
                                        if (fp != NULL) {
                                                fwrite(sermsg.ser,
                                                        sermsg.len, 1, fp);
                                                fclose(fp);
                                        }
+
+                                       /* free the serialized version */
+                                       free(sermsg.ser);
                                }
                        }
-                       free(sermsg.ser);
                        CtdlFreeMessage(msg);
                }
        }
@@ -706,10 +714,12 @@ void network_spoolout_room(char *room_to_spool) {
        char buf[SIZ];
        char instr[SIZ];
        char nodename[SIZ];
+       char roomname[SIZ];
        char nexthop[SIZ];
        FILE *fp;
        struct SpoolControl sc;
        struct namelist *nptr = NULL;
+       struct maplist *mptr = NULL;
        size_t miscsize = 0;
        size_t linesize = 0;
        int skipthisline = 0;
@@ -760,14 +770,16 @@ void network_spoolout_room(char *room_to_spool) {
                         * configurations at this time.
                         */
                        extract(nodename, buf, 1);
+                       extract(roomname, buf, 2);
                        strcpy(nexthop, "xxx");
                        if (is_valid_node(nexthop, NULL, nodename) == 0) {
                                if (strlen(nexthop) == 0) {
-                                       nptr = (struct namelist *)
-                                               malloc(sizeof(struct namelist));
-                                       nptr->next = sc.ignet_push_shares;
-                                       strcpy(nptr->name, nodename);
-                                       sc.ignet_push_shares = nptr;
+                                       mptr = (struct maplist *)
+                                               malloc(sizeof(struct maplist));
+                                       mptr->next = sc.ignet_push_shares;
+                                       strcpy(mptr->remote_nodename, nodename);
+                                       strcpy(mptr->remote_roomname, roomname);
+                                       sc.ignet_push_shares = mptr;
                                }
                        }
                }
@@ -860,13 +872,17 @@ void network_spoolout_room(char *room_to_spool) {
                         * purge nodes which do not exist from room network
                         * configurations at this time.
                         */
-                       if (is_valid_node(NULL, NULL, sc.ignet_push_shares->name) == 0) {
+                       if (is_valid_node(NULL, NULL, sc.ignet_push_shares->remote_nodename) == 0) {
+                       }
+                       fprintf(fp, "ignet_push_share|%s",
+                               sc.ignet_push_shares->remote_nodename);
+                       if (strlen(sc.ignet_push_shares->remote_roomname) > 0) {
+                               fprintf(fp, "|%s", sc.ignet_push_shares->remote_roomname);
                        }
-                       fprintf(fp, "ignet_push_share|%s\n",
-                               sc.ignet_push_shares->name);
-                       nptr = sc.ignet_push_shares->next;
+                       fprintf(fp, "\n");
+                       mptr = sc.ignet_push_shares->next;
                        free(sc.ignet_push_shares);
-                       sc.ignet_push_shares = nptr;
+                       sc.ignet_push_shares = mptr;
                }
                if (sc.misc != NULL) {
                        fwrite(sc.misc, strlen(sc.misc), 1, fp);
@@ -888,15 +904,48 @@ void network_spoolout_room(char *room_to_spool) {
 int network_sync_to(char *target_node) {
        struct SpoolControl sc;
        int num_spooled = 0;
+       int found_node = 0;
+       char buf[SIZ];
+       char sc_type[SIZ];
+       char sc_node[SIZ];
+       char sc_room[SIZ];
+       char filename[SIZ];
+       FILE *fp;
 
-       /* Concise syntax because we don't need a full linked-list */
-       memset(&sc, 0, sizeof(struct SpoolControl));
-       sc.ignet_push_shares = (struct namelist *)
-               malloc(sizeof(struct namelist));
-       sc.ignet_push_shares->next = NULL;
-       safestrncpy(sc.ignet_push_shares->name,
-               target_node,
-               sizeof sc.ignet_push_shares->name);
+       /* Grab the configuration line we're looking for */
+       assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
+       begin_critical_section(S_NETCONFIGS);
+       fp = fopen(filename, "r");
+       if (fp == NULL) {
+               end_critical_section(S_NETCONFIGS);
+               return(-1);
+       }
+       while (fgets(buf, sizeof buf, fp) != NULL) {
+               buf[strlen(buf)-1] = 0;
+               extract(sc_type, buf, 0);
+               extract(sc_node, buf, 1);
+               extract(sc_room, buf, 2);
+               if ( (!strcasecmp(sc_type, "ignet_push_share"))
+                  && (!strcasecmp(sc_node, target_node)) ) {
+                       found_node = 1;
+                       
+                       /* Concise syntax because we don't need a full linked-list */
+                       memset(&sc, 0, sizeof(struct SpoolControl));
+                       sc.ignet_push_shares = (struct maplist *)
+                               malloc(sizeof(struct maplist));
+                       sc.ignet_push_shares->next = NULL;
+                       safestrncpy(sc.ignet_push_shares->remote_nodename,
+                               sc_node,
+                               sizeof sc.ignet_push_shares->remote_nodename);
+                       safestrncpy(sc.ignet_push_shares->remote_roomname,
+                               sc_room,
+                               sizeof sc.ignet_push_shares->remote_roomname);
+               }
+       }
+       fclose(fp);
+       end_critical_section(S_NETCONFIGS);
+
+       if (!found_node) return(-1);
 
        /* Send ALL messages */
        num_spooled = CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL,
@@ -922,7 +971,13 @@ void cmd_nsyn(char *argbuf) {
 
        extract(target_node, argbuf, 0);
        num_spooled = network_sync_to(target_node);
-       cprintf("%d Spooled %d messages.\n", CIT_OK, num_spooled);
+       if (num_spooled >= 0) {
+               cprintf("%d Spooled %d messages.\n", CIT_OK, num_spooled);
+       }
+       else {
+               cprintf("%d No such room/node share exists.\n",
+                       ERROR + ROOM_NOT_FOUND);
+       }
 }
 
 
index 927b980d8a1294644299898e45f8f4d6f7a3a5a3..47c0158e28ffd0f3f0df44cbe5f1b2234142acd8 100644 (file)
@@ -3,11 +3,17 @@ struct namelist {
        char name[SIZ];
 };
 
+struct maplist {
+       struct maplist *next;
+       char remote_nodename[SIZ];
+       char remote_roomname[SIZ];
+};
+
 struct SpoolControl {
        long lastsent;
        struct namelist *listrecps;
        struct namelist *digestrecps;
-       struct namelist *ignet_push_shares;
+       struct maplist *ignet_push_shares;
        char *misc;
        FILE *digestfp;
        int num_msgs_spooled;