-
-
-/*
- * Check the use table. This is a list of messages which have recently
- * arrived on the system. It is maintained and queried to prevent the same
- * message from being entered into the database multiple times if it happens
- * to arrive multiple times by accident.
- */
-int network_usetable(struct CtdlMessage *msg)
-{
- StrBuf *msgid;
- struct CitContext *CCC = CC;
- time_t now;
-
- /* Bail out if we can't generate a message ID */
- if ((msg == NULL) || CM_IsEmpty(msg, emessageId))
- {
- return(0);
- }
-
- /* Generate the message ID */
- msgid = NewStrBufPlain(msg->cm_fields[emessageId], -1);
- if (haschar(ChrPtr(msgid), '@') == 0) {
- StrBufAppendBufPlain(msgid, HKEY("@"), 0);
- if (!CM_IsEmpty(msg, eNodeName)) {
- StrBufAppendBufPlain(msgid, msg->cm_fields[eNodeName], -1, 0);
- }
- else {
- FreeStrBuf(&msgid);
- return(0);
- }
- }
- now = time(NULL);
- if (CheckIfAlreadySeen("Networker Import",
- msgid,
- now, 0,
- eCheckUpdate,
- CCC->cs_pid, 0) != 0)
- {
- FreeStrBuf(&msgid);
- return(1);
- }
- FreeStrBuf(&msgid);
-
- return(0);
-}
-
-
-
-/*
- * Send the *entire* contents of the current room to one specific network node,
- * ignoring anything we know about which messages have already undergone
- * network processing. This can be used to bring a new node into sync.
- */
-int network_sync_to(char *target_node, long len)
-{
- struct CitContext *CCC = CC;
- 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);
- pRNCFG = CtdlGetNetCfgForRoom(CCC->room.QRnumber);
- if ((pRNCFG == NULL) ||
- (pRNCFG->NetConfigs[ignet_push_share] == NULL))
- {
- return -1;
- }
-
- pCfgLine = pRNCFG->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));
- 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);
-
- sc.working_ignetcfg = CtdlLoadIgNetCfg();
- sc.the_netmap = CtdlReadNetworkMap();
-
- /* Send ALL messages */
- num_spooled = CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
- network_spool_msg, &sc);
-
- /* Concise cleanup because we know there's only one node in the sc */
- 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);
- return(num_spooled);
-}
-
-
-/*
- * Implements the NSYN command
- */
-void cmd_nsyn(char *argbuf) {
- int num_spooled;
- long len;
- char target_node[256];
-
- if (CtdlAccessCheck(ac_aide)) return;
-
- len = extract_token(target_node, argbuf, 0, '|', sizeof target_node);
- num_spooled = network_sync_to(target_node, len);
- 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);
- }
-}
-