From 6b11b1b74d1b60068d67bd1b0e38ea66d3823d07 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 26 Nov 2004 22:44:09 +0000 Subject: [PATCH] * 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 --- citadel/ChangeLog | 7 +++ citadel/citadel.h | 4 +- citadel/routines2.c | 13 +++- citadel/serv_network.c | 135 +++++++++++++++++++++++++++++------------ citadel/serv_network.h | 8 ++- 5 files changed, 121 insertions(+), 46 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 880312699..e9433304c 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citadel.h b/citadel/citadel.h index 47c93997d..44fa989ab 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -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 */ diff --git a/citadel/routines2.c b/citadel/routines2.c index 52e836f18..94772edbb 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -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; icm_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); + } } diff --git a/citadel/serv_network.h b/citadel/serv_network.h index 927b980d8..47c0158e2 100644 --- a/citadel/serv_network.h +++ b/citadel/serv_network.h @@ -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; -- 2.39.2