From e030afb588888ece2d27aca76e8d9eb0ebf4c3a0 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sat, 12 Jan 2013 20:12:32 +0100 Subject: [PATCH] NETCFG: reimplement network_sync_to using the new api --- citadel/include/ctdl_module.h | 1 + citadel/modules/network/netspool.h | 12 +--- citadel/modules/network/serv_netmail.c | 56 +++++++++--------- citadel/modules/network/serv_netspool.c | 4 +- citadel/modules/network/serv_network.c | 77 ++++++++----------------- citadel/netconfig.c | 14 +++++ 6 files changed, 70 insertions(+), 94 deletions(-) diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index 3525504a8..6b1e6c007 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -420,6 +420,7 @@ void RegisterRoomCfgType(const char* Name, long len, RoomNetCfg eCfg, CfgLinePar void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *sc); void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *sc, RoomNetCfgLine *data); void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data); +RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data); const OneRoomNetCfg* CtdlGetNetCfgForRoom(long QRNumber); diff --git a/citadel/modules/network/netspool.h b/citadel/modules/network/netspool.h index 7d7517277..2caecf372 100644 --- a/citadel/modules/network/netspool.h +++ b/citadel/modules/network/netspool.h @@ -27,21 +27,13 @@ * */ -typedef struct MapList MapList; - -struct MapList { - MapList *next; - StrBuf *remote_nodename; - StrBuf *remote_roomname; -}; - - typedef struct SpoolControl SpoolControl; struct SpoolControl { - OneRoomNetCfg *RNCfg; + RoomNetCfgLine *NetConfigs[maxRoomNetCfg]; FILE *digestfp; int num_msgs_spooled; + long lastsent; HashList *working_ignetcfg; HashList *the_netmap; diff --git a/citadel/modules/network/serv_netmail.c b/citadel/modules/network/serv_netmail.c index ca44ec690..9bc9df123 100644 --- a/citadel/modules/network/serv_netmail.c +++ b/citadel/modules/network/serv_netmail.c @@ -150,8 +150,8 @@ void network_deliver_digest(SpoolControl *sc) { /* * Figure out how big a buffer we need to allocate */ - for (nptr = sc->RNCfg->NetConfigs[digestrecp]; nptr != NULL; nptr = nptr->next) { - recps_len = recps_len + StrLength(nptr->Value) + 2; + for (nptr = sc->NetConfigs[digestrecp]; nptr != NULL; nptr = nptr->next) { + recps_len = recps_len + StrLength(nptr->Value[0]) + 2; } recps = NewStrBufPlain(NULL, recps_len); @@ -164,11 +164,11 @@ void network_deliver_digest(SpoolControl *sc) { } /* Each recipient */ - for (nptr = sc->RNCfg->NetConfigs[digestrecp]; nptr != NULL; nptr = nptr->next) { - if (nptr != sc->RNCfg->NetConfigs[digestrecp]) { + for (nptr = sc->NetConfigs[digestrecp]; nptr != NULL; nptr = nptr->next) { + if (nptr != sc->NetConfigs[digestrecp]) { StrBufAppendBufPlain(recps, HKEY(","), 0); } - StrBufAppendBuf(recps, nptr->Value, 0); + StrBufAppendBuf(recps, nptr->Value[0], 0); } /* Where do we want bounces and other noise to be heard? @@ -203,15 +203,15 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc, const char char bounce_to[256]; /* Don't do this if there were no recipients! */ - if (sc->RNCfg->NetConfigs[listrecp] == NULL) return; + if (sc->NetConfigs[listrecp] == NULL) return; /* Now generate the delivery instructions */ /* * Figure out how big a buffer we need to allocate */ - for (nptr = sc->RNCfg->NetConfigs[listrecp]; nptr != NULL; nptr = nptr->next) { - recps_len = recps_len + StrLength(nptr->Value) + 2; + for (nptr = sc->NetConfigs[listrecp]; nptr != NULL; nptr = nptr->next) { + recps_len = recps_len + StrLength(nptr->Value[0]) + 2; } recps = NewStrBufPlain(NULL, recps_len); @@ -224,11 +224,11 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc, const char } /* Each recipient */ - for (nptr = sc->RNCfg->NetConfigs[listrecp]; nptr != NULL; nptr = nptr->next) { - if (nptr != sc->RNCfg->NetConfigs[listrecp]) { + for (nptr = sc->NetConfigs[listrecp]; nptr != NULL; nptr = nptr->next) { + if (nptr != sc->NetConfigs[listrecp]) { StrBufAppendBufPlain(recps, HKEY(","), 0); } - StrBufAppendBuf(recps, nptr->Value, 0); + StrBufAppendBuf(recps, nptr->Value[0], 0); } /* Where do we want bounces and other noise to be heard? @@ -256,6 +256,7 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc, const char void network_spool_msg(long msgnum, void *userdata) { + RoomNetCfgLine* mptr; struct CitContext *CCC = CC; StrBuf *Buf = NULL; SpoolControl *sc; @@ -263,7 +264,6 @@ void network_spool_msg(long msgnum, char *newpath = NULL; struct CtdlMessage *msg = NULL; RoomNetCfgLine *nptr; - MapList *mptr; struct ser_ret sermsg; FILE *fp; char filename[PATH_MAX]; @@ -279,7 +279,7 @@ void network_spool_msg(long msgnum, /* * Process mailing list recipients */ - if (sc->RNCfg->NetConfigs[listrecp] != NULL) { + if (sc->NetConfigs[listrecp] != NULL) { /* Fetch the message. We're going to need to modify it * in order to insert the [list name] in it, etc. */ @@ -392,7 +392,7 @@ void network_spool_msg(long msgnum, /* * Process digest recipients */ - if ((sc->RNCfg->NetConfigs[digestrecp] != NULL) && (sc->digestfp != NULL)) { + if ((sc->NetConfigs[digestrecp] != NULL) && (sc->digestfp != NULL)) { msg = CtdlFetchMessage(msgnum, 1); if (msg != NULL) { fprintf(sc->digestfp, @@ -448,7 +448,7 @@ void network_spool_msg(long msgnum, /* * Process client-side list participations for this room */ - if (sc->RNCfg->NetConfigs[participate] != NULL) { + if (sc->NetConfigs[participate] != NULL) { msg = CtdlFetchMessage(msgnum, 1); if (msg != NULL) { @@ -497,7 +497,7 @@ void network_spool_msg(long msgnum, /* * Figure out how big a buffer we need to alloc */ - for (nptr = sc->RNCfg->NetConfigs[participate]; + for (nptr = sc->NetConfigs[participate]; nptr != NULL; nptr = nptr->next) { @@ -505,7 +505,7 @@ void network_spool_msg(long msgnum, free(msg->cm_fields['R']); } msg->cm_fields['R'] = - strdup(ChrPtr(nptr->Value)); + strdup(ChrPtr(nptr->Value[0])); valid = validate_recipients(msg->cm_fields['R'], NULL, 0); @@ -550,12 +550,12 @@ void network_spool_msg(long msgnum, } /* Now send it to every node */ - if (sc->RNCfg->NetConfigs[ignet_push_share] != NULL) - for (mptr = (MapList*)sc->RNCfg->NetConfigs[ignet_push_share]; mptr != NULL; + if (sc->NetConfigs[ignet_push_share] != NULL) + for (mptr = sc->NetConfigs[ignet_push_share]; mptr != NULL; mptr = mptr->next) { send = 1; - NewStrBufDupAppendFlush(&Buf, mptr->remote_nodename, NULL, 1); + NewStrBufDupAppendFlush(&Buf, mptr->Value[0], NULL, 1); /* Check for valid node name */ if (CtdlIsValidNode(NULL, @@ -566,7 +566,7 @@ void network_spool_msg(long msgnum, { QN_syslog(LOG_ERR, "Invalid node <%s>\n", - ChrPtr(mptr->remote_nodename)); + ChrPtr(mptr->Value[0])); send = 0; } @@ -582,8 +582,8 @@ void network_spool_msg(long msgnum, sizeof buf); QN_syslog(LOG_DEBUG, "Compare <%s> to <%s>\n", - buf, ChrPtr(mptr->remote_nodename)) ; - if (!strcasecmp(buf, ChrPtr(mptr->remote_nodename))) { + buf, ChrPtr(mptr->Value[0])) ; + if (!strcasecmp(buf, ChrPtr(mptr->Value[0]))) { send = 0; break; } @@ -592,7 +592,7 @@ void network_spool_msg(long msgnum, QN_syslog(LOG_INFO, "%sSending to %s\n", (send)?"":"Not ", - ChrPtr(mptr->remote_nodename)); + ChrPtr(mptr->Value[0])); } /* Send the message */ @@ -606,9 +606,9 @@ void network_spool_msg(long msgnum, if (msg->cm_fields['C'] != NULL) { free(msg->cm_fields['C']); } - if (StrLength(mptr->remote_roomname) > 0) { + if (StrLength(mptr->Value[0]) > 0) { msg->cm_fields['C'] = - strdup(ChrPtr(mptr->remote_roomname)); + strdup(ChrPtr(mptr->Value[0])); } else { msg->cm_fields['C'] = @@ -624,7 +624,7 @@ void network_spool_msg(long msgnum, sizeof(filename), "%s/%s@%lx%x", ctdl_netout_dir, - ChrPtr(mptr->remote_nodename), + ChrPtr(mptr->Value[0]), time(NULL), rand() ); @@ -656,7 +656,7 @@ void network_spool_msg(long msgnum, } /* update lastsent */ - sc->RNCfg->lastsent = msgnum; + ///sc->lastsent = msgnum; ////// TODO /* Delete this message if delete-after-send is set */ if (delete_after_send) { diff --git a/citadel/modules/network/serv_netspool.c b/citadel/modules/network/serv_netspool.c index f2ad74dde..edf974a4d 100644 --- a/citadel/modules/network/serv_netspool.c +++ b/citadel/modules/network/serv_netspool.c @@ -182,13 +182,13 @@ void network_spoolout_room(RoomProcList *room_to_spool, sc->the_netmap = the_netmap; /* If there are digest recipients, we have to build a digest */ - if (sc->RNCfg->NetConfigs[digestrecp] != NULL) { + if (sc->NetConfigs[digestrecp] != NULL) { sc->digestfp = tmpfile(); fprintf(sc->digestfp, "Content-type: text/plain\n\n"); } /* Do something useful */ - CtdlForEachMessage(MSGS_GT, sc->RNCfg->lastsent, NULL, NULL, NULL, + CtdlForEachMessage(MSGS_GT, sc->lastsent, NULL, NULL, NULL, network_spool_msg, sc); /* If we wrote a digest, deliver it and then close it */ diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index beec9b4f7..41eae0940 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -184,13 +184,6 @@ int network_usetable(struct CtdlMessage *msg) - - - - -#if 0 - - /* * Send the *entire* contents of the current room to one specific network node, * ignoring anything we know about which messages have already undergone @@ -199,60 +192,38 @@ int network_usetable(struct CtdlMessage *msg) int network_sync_to(char *target_node, long len) { struct CitContext *CCC = CC; + const OneRoomNetCfg *OneRNCFG; + const RoomNetCfgLine *pCfgLine; SpoolControl sc; int num_spooled = 0; - int found_node = 0; - char buf[256]; - char sc_type[256]; - char sc_node[256]; - char sc_room[256]; - char filename[PATH_MAX]; - FILE *fp; /* Grab the configuration line we're looking for */ - assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir); 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) + OneRNCFG = CtdlGetNetCfgForRoom(CCC->room.QRnumber); + if ((OneRNCFG == NULL) || + (OneRNCFG->NetConfigs[ignet_push_share] == NULL)) { - buf[strlen(buf)-1] = 0; + return -1; + } - extract_token(sc_type, buf, 0, '|', sizeof sc_type); - if (strcasecmp(sc_type, "ignet_push_share")) - continue; + pCfgLine = OneRNCFG->NetConfigs[ignet_push_share]; + while (pCfgLine != NULL) + { + if (strcmp(ChrPtr(pCfgLine->Value[0]), target_node)) + break; + pCfgLine = pCfgLine->next; + } + if (pCfgLine == NULL) + { + return -1; + } + memset(&sc, 0, sizeof(SpoolControl)); - extract_token(sc_node, buf, 1, '|', sizeof sc_node); - if (strcasecmp(sc_node, target_node)) - continue; + sc.NetConfigs[ignet_push_share] = DuplicateOneGenericCfgLine(pCfgLine); - extract_token(sc_room, buf, 2, '|', sizeof sc_room); - found_node = 1; - - /* Concise syntax because we don't need a full linked-list */ - memset(&sc, 0, sizeof(SpoolControl)); - sc.ignet_push_shares = (maplist *) - malloc(sizeof(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) { - free(sc.ignet_push_shares); - return(-1); - } - - sc.working_ignetcfg = load_ignetcfg(); + sc.working_ignetcfg = CtdlLoadIgNetCfg(); sc.the_netmap = CtdlReadNetworkMap(); /* Send ALL messages */ @@ -260,7 +231,7 @@ int network_sync_to(char *target_node, long len) network_spool_msg, &sc); /* Concise cleanup because we know there's only one node in the sc */ - free(sc.ignet_push_shares); + DeleteGenericCfgLine(NULL/*TODO*/, &sc.NetConfigs[ignet_push_share]); DeleteHash(&sc.working_ignetcfg); DeleteHash(&sc.the_netmap); @@ -270,8 +241,6 @@ int network_sync_to(char *target_node, long len) return(num_spooled); } -#endif - /* * Implements the NSYN command @@ -284,7 +253,7 @@ void cmd_nsyn(char *argbuf) { if (CtdlAccessCheck(ac_aide)) return; len = extract_token(target_node, argbuf, 0, '|', sizeof target_node); - ///// TODO num_spooled = network_sync_to(target_node, len); + num_spooled = network_sync_to(target_node, len); if (num_spooled >= 0) { cprintf("%d Spooled %d messages.\n", CIT_OK, num_spooled); } diff --git a/citadel/netconfig.c b/citadel/netconfig.c index e6e0ea8a2..e5a5cb0b2 100644 --- a/citadel/netconfig.c +++ b/citadel/netconfig.c @@ -131,6 +131,20 @@ void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data) free(*data); *data = NULL; } +RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data) +{ + RoomNetCfgLine *NewData; + + NewData = (RoomNetCfgLine*)malloc(sizeof(RoomNetCfgLine)); + int i; + NewData->Value = (StrBuf **)malloc(sizeof(StrBuf*) * data->nValues); + + for (i = 0; i < data->nValues; i++) + { + NewData->Value[i] = NewStrBufDup(data->Value[i]); + } + return NewData; +} int ReadRoomNetConfigFile(OneRoomNetCfg **pOneRNCFG, char *filename) { int fd; -- 2.30.2