-typedef struct __roomlists {
- RoomProcList *rplist;
-} roomlists;
-
-
-/*
- * When we do network processing, it's accomplished in two passes; one to
- * gather a list of rooms and one to actually do them. It's ok that rplist
- * is global; we have a mutex that keeps it safe.
- */
-struct RoomProcList *rplist = NULL;
-
-
-/*
- * 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;
-
- /* Load the netconfig for this room */
- pRNCFG = CtdlGetNetCfgForRoom(CCC->room.QRnumber);
- if (pRNCFG == NULL) { // no netconfig at all?
- return -1;
- }
- if (pRNCFG->NetConfigs[ignet_push_share] == NULL) // no ignet push shares?
- {
- FreeRoomNetworkStruct(&pRNCFG);
- return -1;
- }
-
- /* Search for an ignet_oush_share configuration bearing the target node's name */
- for (pCfgLine = pRNCFG->NetConfigs[ignet_push_share]; pCfgLine != NULL; pCfgLine = pCfgLine->next)
- {
- if (!strcmp(ChrPtr(pCfgLine->Value[0]), target_node))
- break;
- }
-
- /* If we aren't sharing with that node, bail out */
- if (pCfgLine == NULL)
- {
- FreeRoomNetworkStruct(&pRNCFG);
- return -1;
- }
-
- /* If we got here, we're good to go ... make up a dummy spoolconfig and roll with it */
-
- begin_critical_section(S_NETCONFIGS);
- 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, &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>", 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);
- }
-}
-
-RoomProcList *CreateRoomProcListEntry(struct ctdlroom *qrbuf, OneRoomNetCfg *OneRNCFG)
-{
- int i;
- struct RoomProcList *ptr;
-
- ptr = (struct RoomProcList *) malloc(sizeof (struct RoomProcList));
- if (ptr == NULL) {
- return NULL;
- }
-
- ptr->namelen = strlen(qrbuf->QRname);
- if (ptr->namelen > ROOMNAMELEN) {
- ptr->namelen = ROOMNAMELEN - 1;
- }
-
- memcpy (ptr->name, qrbuf->QRname, ptr->namelen);
- ptr->name[ptr->namelen] = '\0';
- ptr->QRNum = qrbuf->QRnumber;
-
- for (i = 0; i < ptr->namelen; i++)
- {
- ptr->lcname[i] = tolower(ptr->name[i]);
- }
-
- ptr->lcname[ptr->namelen] = '\0';
- ptr->key = hashlittle(ptr->lcname, ptr->namelen, 9872345);
- return ptr;
-}
-
-/*
- * Batch up and send all outbound traffic from the current room
- */
-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);
-
- if (ptr != NULL)
- {
- ptr->next = RP->rplist;
- RP->rplist = ptr;
- }
-}
-
-/*
- * Batch up and send all outbound traffic from the current room
- */
-int network_room_handler(struct ctdlroom *qrbuf)
-{
- struct RoomProcList *ptr;
- OneRoomNetCfg *RNCfg;
-
- if (qrbuf->QRdefaultview == VIEW_QUEUE) {
- return 1;
- }
-
- RNCfg = CtdlGetNetCfgForRoom(qrbuf->QRnumber);
- if (RNCfg == NULL) {
- return 1;
- }
-
- if (!HaveSpoolConfig(RNCfg)) {
- FreeRoomNetworkStruct(&RNCfg);
- return 1;
- }
-
- ptr = CreateRoomProcListEntry(qrbuf, RNCfg);
- if (ptr == NULL) {
- FreeRoomNetworkStruct(&RNCfg);
- return 1;
- }
-
- begin_critical_section(S_RPLIST);
- ptr->next = rplist;
- rplist = ptr;
- end_critical_section(S_RPLIST);
- FreeRoomNetworkStruct(&RNCfg);
- return 1;
-}
-
-void destroy_network_queue_room(RoomProcList *rplist)
-{
- struct RoomProcList *cur, *p;
-
- cur = rplist;
- while (cur != NULL)
- {
- p = cur->next;
- free (cur);
- cur = p;
- }
-}
-
-void destroy_network_queue_room_locked (void)
-{
- begin_critical_section(S_RPLIST);
- destroy_network_queue_room(rplist);
- end_critical_section(S_RPLIST);
-}
-
-