typedef struct __roomlists {
RoomProcList *rplist;
- HashList *RoomsInterestedIn;
}roomlists;
/*
* When we do network processing, it's accomplished in two passes; one to
*/
int network_usetable(struct CtdlMessage *msg)
{
+ StrBuf *msgid;
struct CitContext *CCC = CC;
- char msgid[SIZ];
- struct cdbdata *cdbut;
- struct UseTable ut;
+ time_t now;
/* Bail out if we can't generate a message ID */
- if (msg == NULL) {
- return(0);
- }
- if (msg->cm_fields['I'] == NULL) {
- return(0);
- }
- if (IsEmptyStr(msg->cm_fields['I'])) {
+ if ((msg == NULL) || (msg->cm_fields['I'] == NULL) || (IsEmptyStr(msg->cm_fields['I'])))
+ {
return(0);
}
/* Generate the message ID */
- strcpy(msgid, msg->cm_fields['I']);
- if (haschar(msgid, '@') == 0) {
- strcat(msgid, "@");
+ msgid = NewStrBufPlain(msg->cm_fields['I'], -1);
+ if (haschar(ChrPtr(msgid), '@') == 0) {
+ StrBufAppendBufPlain(msgid, HKEY("@"), 0);
if (msg->cm_fields['N'] != NULL) {
- strcat(msgid, msg->cm_fields['N']);
+ StrBufAppendBufPlain(msgid, msg->cm_fields['N'], -1, 0);
}
else {
+ FreeStrBuf(&msgid);
return(0);
}
}
-
- cdbut = cdb_fetch(CDB_USETABLE, msgid, strlen(msgid));
- if (cdbut != NULL) {
- cdb_free(cdbut);
- QN_syslog(LOG_DEBUG, "network_usetable() : we already have %s\n", msgid);
+ now = time(NULL);
+ if (CheckIfAlreadySeen("Networker Import",
+ msgid,
+ now, 0,
+ eCheckUpdate,
+ CCC->cs_pid, 0) != 0)
+ {
+ FreeStrBuf(&msgid);
return(1);
}
+ FreeStrBuf(&msgid);
- /* If we got to this point, it's unique: add it. */
- strcpy(ut.ut_msgid, msgid);
- ut.ut_timestamp = time(NULL);
- cdb_store(CDB_USETABLE, msgid, strlen(msgid), &ut, sizeof(struct UseTable) );
return(0);
}
int network_sync_to(char *target_node, long len)
{
struct CitContext *CCC = CC;
- const OneRoomNetCfg *OneRNCFG;
+ OneRoomNetCfg OneRNCFG;
+ OneRoomNetCfg *pRNCFG;
const RoomNetCfgLine *pCfgLine;
SpoolControl sc;
int num_spooled = 0;
/* Grab the configuration line we're looking for */
begin_critical_section(S_NETCONFIGS);
- OneRNCFG = CtdlGetNetCfgForRoom(CCC->room.QRnumber);
- if ((OneRNCFG == NULL) ||
- (OneRNCFG->NetConfigs[ignet_push_share] == NULL))
+ pRNCFG = CtdlGetNetCfgForRoom(CCC->room.QRnumber);
+ if ((pRNCFG == NULL) ||
+ (pRNCFG->NetConfigs[ignet_push_share] == NULL))
{
return -1;
}
- pCfgLine = OneRNCFG->NetConfigs[ignet_push_share];
+ pCfgLine = pRNCFG->NetConfigs[ignet_push_share];
while (pCfgLine != NULL)
{
- if (strcmp(ChrPtr(pCfgLine->Value[0]), target_node))
+ if (!strcmp(ChrPtr(pCfgLine->Value[0]), target_node))
break;
pCfgLine = pCfgLine->next;
}
{
return -1;
}
- memset(&sc, 0, sizeof(SpoolControl));
- sc.NetConfigs[ignet_push_share] = DuplicateOneGenericCfgLine(pCfgLine);
+ memset(&sc, 0, sizeof(SpoolControl));
+ memset(&OneRNCFG, 0, sizeof(OneRoomNetCfg));
+ sc.RNCfg = &OneRNCFG;
+ sc.RNCfg->NetConfigs[ignet_push_share] = DuplicateOneGenericCfgLine(pCfgLine);
+ sc.Users[ignet_push_share] = NewStrBufPlain(NULL,
+ StrLength(pCfgLine->Value[0]) +
+ StrLength(pCfgLine->Value[1]) + 10);
+ StrBufAppendBuf(sc.Users[ignet_push_share],
+ pCfgLine->Value[0],
+ 0);
+ StrBufAppendBufPlain(sc.Users[ignet_push_share],
+ HKEY(","),
+ 0);
+
+ StrBufAppendBuf(sc.Users[ignet_push_share],
+ pCfgLine->Value[1],
+ 0);
+ CalcListID(&sc);
end_critical_section(S_NETCONFIGS);
network_spool_msg, &sc);
/* Concise cleanup because we know there's only one node in the sc */
- DeleteGenericCfgLine(NULL/*TODO*/, &sc.NetConfigs[ignet_push_share]);
+ DeleteGenericCfgLine(NULL/*TODO*/, &sc.RNCfg->NetConfigs[ignet_push_share]);
DeleteHash(&sc.working_ignetcfg);
DeleteHash(&sc.the_netmap);
+ free_spoolcontrol_struct_members(&sc);
QN_syslog(LOG_NOTICE, "Synchronized %d messages to <%s>\n",
num_spooled, target_node);
}
}
-RoomProcList *CreateRoomProcListEntry(struct ctdlroom *qrbuf, const OneRoomNetCfg *OneRNCFG)
+RoomProcList *CreateRoomProcListEntry(struct ctdlroom *qrbuf, OneRoomNetCfg *OneRNCFG)
{
int i;
struct RoomProcList *ptr;
ptr->lcname[ptr->namelen] = '\0';
ptr->key = hashlittle(ptr->lcname, ptr->namelen, 9872345);
- ptr->OneRNCFG = OneRNCFG;
+ ptr->lastsent = OneRNCFG->lastsent;
+ ptr->OneRNCfg = OneRNCFG;
return ptr;
}
/*
* Batch up and send all outbound traffic from the current room
*/
-void network_queue_interesting_rooms(struct ctdlroom *qrbuf, void *data, const OneRoomNetCfg *OneRNCfg)
+void network_queue_interesting_rooms(struct ctdlroom *qrbuf, void *data, OneRoomNetCfg *OneRNCfg)
{
struct RoomProcList *ptr;
roomlists *RP = (roomlists*) data;
+ if (!HaveSpoolConfig(OneRNCfg))
+ return;
+
ptr = CreateRoomProcListEntry(qrbuf, OneRNCfg);
- ptr->next = RP->rplist;
- RP->rplist = ptr;
+ if (ptr != NULL)
+ {
+ ptr->next = RP->rplist;
+ RP->rplist = ptr;
+ }
}
/*
int network_room_handler (struct ctdlroom *qrbuf)
{
struct RoomProcList *ptr;
- const OneRoomNetCfg* RNCfg;
+ OneRoomNetCfg* RNCfg;
if (qrbuf->QRdefaultview == VIEW_QUEUE)
return 1;
if (RNCfg == NULL)
return 1;
+ if (!HaveSpoolConfig(RNCfg))
+ return 1;
+
ptr = CreateRoomProcListEntry(qrbuf, RNCfg);
if (ptr == NULL)
return 1;
+ ptr->OneRNCfg = NULL;
begin_critical_section(S_RPLIST);
ptr->next = rplist;
rplist = ptr;
-
-
-
-
/*
* network_do_queue()
*
void network_do_queue(void)
{
struct CitContext *CCC = CC;
- static int doing_queue = 0;
static time_t last_run = 0L;
int full_processing = 1;
HashList *working_ignetcfg;
HashList *the_netmap = NULL;
int netmap_changed = 0;
roomlists RL;
+ SpoolControl *sc = NULL;
+ SpoolControl *pSC;
/*
* Run the full set of processing tasks no more frequently
);
}
- /*
- * This is a simple concurrency check to make sure only one queue run
- * is done at a time. We could do this with a mutex, but since we
- * don't really require extremely fine granularity here, we'll do it
- * with a static variable instead.
- */
- if (doing_queue) {
- return;
- }
- doing_queue = 1;
-
become_session(&networker_spool_CC);
begin_critical_section(S_RPLIST);
RL.rplist = rplist;
while (ptr != NULL && !server_shutting_down) {
cmp = ptr->next;
-
+ /* filter duplicates from the list... */
while (cmp != NULL) {
if ((cmp->namelen > 0) &&
(cmp->key == ptr->key) &&
}
if (ptr->namelen > 0) {
- network_spoolout_room(ptr,
- working_ignetcfg,
- the_netmap);
+ InspectQueuedRoom(&sc,
+ ptr,
+ working_ignetcfg,
+ the_netmap);
}
ptr = ptr->next;
}
}
+
+ pSC = sc;
+ while (pSC != NULL)
+ {
+ network_spoolout_room(pSC);
+ pSC = pSC->next;
+ }
+
+ pSC = sc;
+ while (pSC != NULL)
+ {
+ sc = pSC->next;
+ free_spoolcontrol_struct(&pSC);
+ pSC = sc;
+ }
/* If there is anything in the inbound queue, process it */
if (!server_shutting_down) {
network_do_spoolin(working_ignetcfg,
/* Save the network map back to disk */
if (netmap_changed) {
StrBuf *MapStr = CtdlSerializeNetworkMap(the_netmap);
- CtdlPutSysConfig(IGNETMAP, SmashStrBuf(&MapStr));
+ char *pMapStr = SmashStrBuf(&MapStr);
+ CtdlPutSysConfig(IGNETMAP, pMapStr);
+ free(pMapStr);
}
/* combine singe message files into one spool entry per remote node. */
if (full_processing) {
last_run = time(NULL);
}
- DeleteHash(&RL.RoomsInterestedIn);
destroy_network_queue_room(RL.rplist);
- doing_queue = 0;
+ SaveChangedConfigs();
+
}