2 * This module handles shared rooms, inter-Citadel mail, and outbound
3 * mailing list processing.
5 * Copyright (c) 2000-2011 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * ** NOTE ** A word on the S_NETCONFIGS semaphore:
22 * This is a fairly high-level type of critical section. It ensures that no
23 * two threads work on the netconfigs files at the same time. Since we do
24 * so many things inside these, here are the rules:
25 * 1. begin_critical_section(S_NETCONFIGS) *before* begin_ any others.
26 * 2. Do *not* perform any I/O with the client during these sections.
41 #include <sys/types.h>
43 #if TIME_WITH_SYS_TIME
44 # include <sys/time.h>
48 # include <sys/time.h>
56 # if HAVE_SYS_SYSCALL_H
57 # include <sys/syscall.h>
64 #include <libcitadel.h>
67 #include "citserver.h"
73 #include "internet_addressing.h"
74 #include "serv_network.h"
75 #include "clientsocket.h"
77 #include "citadel_dirs.h"
86 #include "netconfig.h"
87 #include "ctdl_module.h"
89 struct CitContext networker_client_CC;
91 #define NODE ChrPtr(((AsyncNetworker*)IO->Data)->node)
92 #define N ((AsyncNetworker*)IO->Data)->n
94 #define EVN_syslog(LEVEL, FORMAT, ...) \
96 "IO[%ld]CC[%d]NW[%s][%ld]" FORMAT, \
97 IO->ID, CCID, NODE, N, __VA_ARGS__)
99 #define EVNM_syslog(LEVEL, FORMAT) \
101 "IO[%ld]CC[%d]NW[%s][%ld]" FORMAT, \
102 IO->ID, CCID, NODE, N)
104 #define EVNCS_syslog(LEVEL, FORMAT, ...) \
105 syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \
106 IO->ID, NODE, N, __VA_ARGS__)
108 #define EVNCSM_syslog(LEVEL, FORMAT) \
109 syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \
113 typedef enum _eNWCState {
128 typedef struct _async_networker {
130 DNSQueryParts HostLookup;
133 StrBuf *SpoolFileName;
134 StrBuf *tempFileName;
142 typedef eNextState(*NWClientHandler)(AsyncNetworker* NW);
143 eNextState nwc_get_one_host_ip(AsyncIO *IO);
145 eNextState nwc_connect_ip(AsyncIO *IO);
147 eNextState NWC_SendQUIT(AsyncNetworker *NW);
148 eNextState NWC_DispatchWriteDone(AsyncIO *IO);
150 void DeleteNetworker(void *vptr)
152 AsyncNetworker *NW = (AsyncNetworker *)vptr;
153 FreeStrBuf(&NW->SpoolFileName);
154 FreeStrBuf(&NW->tempFileName);
155 FreeStrBuf(&NW->node);
156 FreeStrBuf(&NW->host);
157 FreeStrBuf(&NW->port);
158 FreeStrBuf(&NW->secret);
159 FreeStrBuf(&NW->Url);
160 FreeAsyncIOContents(&NW->IO);
164 #define NWC_DBG_SEND() EVN_syslog(LOG_DEBUG, ": > %s", ChrPtr(NW->IO.SendBuf.Buf))
165 #define NWC_DBG_READ() EVN_syslog(LOG_DEBUG, ": < %s\n", ChrPtr(NW->IO.IOBuf))
166 #define NWC_OK (strncasecmp(ChrPtr(NW->IO.IOBuf), "+OK", 3) == 0)
168 eNextState FinalizeNetworker(AsyncIO *IO)
170 AsyncNetworker *NW = (AsyncNetworker *)IO->Data;
172 network_talking_to(SKEY(NW->node), NTT_REMOVE);
174 DeleteNetworker(IO->Data);
178 eNextState NWC_ReadGreeting(AsyncNetworker *NW)
180 char connected_to[SIZ];
181 AsyncIO *IO = &NW->IO;
183 /* Read the server greeting */
184 /* Check that the remote is who we think it is and warn the Aide if not */
185 extract_token (connected_to, ChrPtr(NW->IO.IOBuf), 1, ' ', sizeof connected_to);
186 if (strcmp(connected_to, ChrPtr(NW->node)) != 0)
188 StrBufPrintf(NW->IO.ErrMsg,
189 "Connected to node \"%s\" but I was expecting to connect to node \"%s\".",
190 connected_to, ChrPtr(NW->node));
191 EVN_syslog(LOG_ERR, "%s\n", ChrPtr(NW->IO.ErrMsg));
192 CtdlAideMessage(ChrPtr(NW->IO.ErrMsg), "Network error");
193 return eAbort;/// todo: aide message in anderer queue speichern
198 eNextState NWC_SendAuth(AsyncNetworker *NW)
200 AsyncIO *IO = &NW->IO;
201 /* We're talking to the correct node. Now identify ourselves. */
202 StrBufPrintf(NW->IO.SendBuf.Buf, "NETP %s|%s\n",
209 eNextState NWC_ReadAuthReply(AsyncNetworker *NW)
211 AsyncIO *IO = &NW->IO;
213 if (ChrPtr(NW->IO.IOBuf)[0] == '2')
219 StrBufPrintf(NW->IO.ErrMsg,
220 "Connected to node \"%s\" but my secret wasn't accurate.",
222 EVN_syslog(LOG_ERR, "%s\n", ChrPtr(NW->IO.ErrMsg));
223 CtdlAideMessage(ChrPtr(NW->IO.ErrMsg), "Network error");
229 eNextState NWC_SendNDOP(AsyncNetworker *NW)
231 AsyncIO *IO = &NW->IO;
232 NW->tempFileName = NewStrBuf();
233 NW->SpoolFileName = NewStrBuf();
234 StrBufPrintf(NW->tempFileName,
238 time(NULL),// TODO: get time from libev
240 StrBufPrintf(NW->SpoolFileName,
244 time(NULL),// TODO: get time from libev
247 /* We're talking to the correct node. Now identify ourselves. */
248 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("NDOP\n"));
253 eNextState NWC_ReadNDOPReply(AsyncNetworker *NW)
255 AsyncIO *IO = &NW->IO;
258 if (ChrPtr(NW->IO.IOBuf)[0] == '2')
261 NW->IO.IOB.TotalSentAlready = 0;
262 TotalSendSize = atol (ChrPtr(NW->IO.IOBuf) + 4);
263 EVN_syslog(LOG_DEBUG, "Expecting to transfer %ld bytes\n", NW->IO.IOB.TotalSendSize);
264 if (TotalSendSize <= 0) {
265 NW->State = eNUOP - 1;
269 fd = open(ChrPtr(NW->SpoolFileName),
270 O_EXCL|O_CREAT|O_NONBLOCK|O_WRONLY,
275 "cannot open %s: %s\n",
276 ChrPtr(NW->SpoolFileName),
279 NW->State = eQUIT - 1;
282 FDIOBufferInit(&NW->IO.IOB, &NW->IO.RecvBuf, fd, TotalSendSize);
292 eNextState NWC_SendREAD(AsyncNetworker *NW)
294 AsyncIO *IO = &NW->IO;
297 if (NW->IO.IOB.TotalSentAlready < NW->IO.IOB.TotalSendSize)
300 * If shutting down we can exit here and unlink the temp file.
301 * this shouldn't loose us any messages.
303 if (server_shutting_down)
305 FDIOBufferDelete(&NW->IO.IOB);
306 unlink(ChrPtr(NW->tempFileName));
309 StrBufPrintf(NW->IO.SendBuf.Buf, "READ %ld|%ld\n",
310 NW->IO.IOB.TotalSentAlready,
311 NW->IO.IOB.TotalSendSize);
313 ((NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready > IGNET_PACKET_SIZE)
314 ? IGNET_PACKET_SIZE :
315 (NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready))
324 rc = NWC_DispatchWriteDone(&NW->IO);
331 eNextState NWC_ReadREADState(AsyncNetworker *NW)
333 AsyncIO *IO = &NW->IO;
335 if (ChrPtr(NW->IO.IOBuf)[0] == '6')
337 NW->IO.IOB.ChunkSendRemain =
338 NW->IO.IOB.ChunkSize = atol(ChrPtr(NW->IO.IOBuf)+4);
343 eNextState NWC_ReadREADBlobDone(AsyncNetworker *NW);
344 eNextState NWC_ReadREADBlob(AsyncNetworker *NW)
346 AsyncIO *IO = &NW->IO;
348 if (NW->IO.IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
352 FDIOBufferDelete(&NW->IO.IOB);
354 if (link(ChrPtr(NW->SpoolFileName), ChrPtr(NW->tempFileName)) != 0) {
355 EVN_syslog(LOG_ALERT,
356 "Could not link %s to %s: %s\n",
357 ChrPtr(NW->tempFileName),
358 ChrPtr(NW->SpoolFileName),
362 unlink(ChrPtr(NW->tempFileName));
363 return NWC_DispatchWriteDone(&NW->IO);
367 NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
368 return NWC_DispatchWriteDone(&NW->IO);
372 eNextState NWC_ReadREADBlobDone(AsyncNetworker *NW)
374 AsyncIO *IO = &NW->IO;
376 if (NW->IO.IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
380 FDIOBufferDelete(&NW->IO.IOB);
382 if (link(ChrPtr(NW->SpoolFileName), ChrPtr(NW->tempFileName)) != 0) {
383 EVN_syslog(LOG_ALERT,
384 "Could not link %s to %s: %s\n",
385 ChrPtr(NW->tempFileName),
386 ChrPtr(NW->SpoolFileName),
390 unlink(ChrPtr(NW->tempFileName));
391 return NWC_DispatchWriteDone(&NW->IO);
395 NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
396 return NWC_DispatchWriteDone(&NW->IO);
399 eNextState NWC_SendCLOS(AsyncNetworker *NW)
401 AsyncIO *IO = &NW->IO;
402 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("CLOS\n"));
407 eNextState NWC_ReadCLOSReply(AsyncNetworker *NW)
409 AsyncIO *IO = &NW->IO;
411 if (ChrPtr(NW->IO.IOBuf)[0] != '2')
412 return eTerminateConnection;
417 eNextState NWC_SendNUOP(AsyncNetworker *NW)
419 AsyncIO *IO = &NW->IO;
425 StrBufPrintf(NW->tempFileName,
429 fd = open(ChrPtr(NW->tempFileName), O_RDONLY);
431 if (errno != ENOENT) {
433 "cannot open %s: %s\n",
434 ChrPtr(NW->tempFileName),
438 rc = NWC_SendQUIT(NW);
443 if (fstat(fd, &statbuf) == -1) {
444 EVN_syslog(LOG_CRIT, "FSTAT FAILED %s [%s]--\n",
445 ChrPtr(NW->tempFileName),
447 if (fd > 0) close(fd);
450 TotalSendSize = statbuf.st_size;
451 if (TotalSendSize == 0) {
452 EVNM_syslog(LOG_DEBUG,
453 "Nothing to send.\n");
455 rc = NWC_SendQUIT(NW);
459 FDIOBufferInit(&NW->IO.IOB, &NW->IO.SendBuf, fd, TotalSendSize);
461 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("NUOP\n"));
466 eNextState NWC_ReadNUOPReply(AsyncNetworker *NW)
468 AsyncIO *IO = &NW->IO;
470 if (ChrPtr(NW->IO.IOBuf)[0] != '2')
475 eNextState NWC_SendWRIT(AsyncNetworker *NW)
477 AsyncIO *IO = &NW->IO;
478 StrBufPrintf(NW->IO.SendBuf.Buf, "WRIT %ld\n",
479 NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready);
483 eNextState NWC_ReadWRITReply(AsyncNetworker *NW)
485 AsyncIO *IO = &NW->IO;
487 if (ChrPtr(NW->IO.IOBuf)[0] != '7')
492 NW->IO.IOB.ChunkSendRemain =
493 NW->IO.IOB.ChunkSize = atol(ChrPtr(NW->IO.IOBuf)+4);
497 eNextState NWC_SendBlobDone(AsyncNetworker *NW)
499 AsyncIO *IO = &NW->IO;
501 if (IO->IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
505 FDIOBufferDelete(&IO->IOB);
506 rc = NWC_DispatchWriteDone(IO);
512 IO->IOB.ChunkSendRemain = IO->IOB.ChunkSize;
513 return NWC_DispatchWriteDone(IO);
517 eNextState NWC_SendUCLS(AsyncNetworker *NW)
519 AsyncIO *IO = &NW->IO;
520 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("UCLS 1\n"));
525 eNextState NWC_ReadUCLS(AsyncNetworker *NW)
527 AsyncIO *IO = &NW->IO;
530 EVN_syslog(LOG_NOTICE, "Sent %ld octets to <%s>\n", NW->IO.IOB.ChunkSize, ChrPtr(NW->node));
531 if (ChrPtr(NW->IO.IOBuf)[0] == '2') {
532 EVN_syslog(LOG_DEBUG, "Removing <%s>\n", ChrPtr(NW->tempFileName));
533 unlink(ChrPtr(NW->tempFileName));
538 eNextState NWC_SendQUIT(AsyncNetworker *NW)
540 AsyncIO *IO = &NW->IO;
541 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("QUIT\n"));
547 eNextState NWC_ReadQUIT(AsyncNetworker *NW)
549 AsyncIO *IO = &NW->IO;
556 NWClientHandler NWC_ReadHandlers[] = {
569 long NWC_ConnTimeout = 100;
571 const long NWC_SendTimeouts[] = {
581 const ConstStr NWC[] = {
582 {HKEY("Connection broken during ")},
583 {HKEY("Connection broken during ")},
584 {HKEY("Connection broken during ")},
585 {HKEY("Connection broken during ")},
586 {HKEY("Connection broken during ")},
587 {HKEY("Connection broken during ")},
588 {HKEY("Connection broken during ")},
589 {HKEY("Connection broken during ")}
592 NWClientHandler NWC_SendHandlers[] = {
597 NWC_ReadREADBlobDone,
606 const long NWC_ReadTimeouts[] = {
622 eNextState nwc_get_one_host_ip_done(AsyncIO *IO)
624 AsyncNetworker *NW = IO->Data;
625 struct hostent *hostent;
629 hostent = NW->HostLookup.VParsedDNSReply;
630 if ((NW->HostLookup.DNSStatus == ARES_SUCCESS) &&
631 (hostent != NULL) ) {
632 memset(&NW->IO.ConnectMe->Addr, 0, sizeof(struct in6_addr));
633 if (NW->IO.ConnectMe->IPv6) {
634 memcpy(&NW->IO.ConnectMe->Addr.sin6_addr.s6_addr,
635 &hostent->h_addr_list[0],
636 sizeof(struct in6_addr));
638 NW->IO.ConnectMe->Addr.sin6_family = hostent->h_addrtype;
639 NW->IO.ConnectMe->Addr.sin6_port = htons(atol(ChrPtr(NW->port)));//// TODO use the one from the URL.
642 struct sockaddr_in *addr = (struct sockaddr_in*) &NW->IO.ConnectMe->Addr;
643 /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
644 // addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]);
645 memcpy(&addr->sin_addr.s_addr,
646 hostent->h_addr_list[0],
649 addr->sin_family = hostent->h_addrtype;
650 addr->sin_port = htons(504);/// default citadel port
653 return nwc_connect_ip(IO);
660 eNextState nwc_get_one_host_ip(AsyncIO *IO)
662 AsyncNetworker *NW = IO->Data;
664 * here we start with the lookup of one host.
667 EVN_syslog(LOG_DEBUG, "NWC: %s\n", __FUNCTION__);
669 EVN_syslog(LOG_DEBUG,
670 "NWC client[%ld]: looking up %s-Record %s : %d ...\n",
672 (NW->IO.ConnectMe->IPv6)? "aaaa": "a",
673 NW->IO.ConnectMe->Host,
674 NW->IO.ConnectMe->Port);
676 QueueQuery((NW->IO.ConnectMe->IPv6)? ns_t_aaaa : ns_t_a,
677 NW->IO.ConnectMe->Host,
680 nwc_get_one_host_ip_done);
681 IO->NextState = eReadDNSReply;
682 return IO->NextState;
685 * @brief lineread Handler; understands when to read more POP3 lines, and when this is a one-lined reply.
687 eReadState NWC_ReadServerStatus(AsyncIO *IO)
689 // AsyncNetworker *NW = IO->Data;
690 eReadState Finished = eBufferNotEmpty;
692 switch (IO->NextState) {
697 case eTerminateConnection:
699 Finished = eReadFail;
705 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
717 eNextState NWC_FailNetworkConnection(AsyncIO *IO)
722 void NWC_SetTimeout(eNextState NextTCPState, AsyncNetworker *NW)
724 AsyncIO *IO = &NW->IO;
725 double Timeout = 0.0;
727 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
729 switch (NextTCPState) {
735 Timeout = NWC_ReadTimeouts[NW->State];
746 case eTerminateConnection:
749 case eReadMore://// TODO
752 SetNextTimeout(&NW->IO, Timeout);
756 eNextState NWC_DispatchReadDone(AsyncIO *IO)
758 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
759 AsyncNetworker *NW = IO->Data;
762 rc = NWC_ReadHandlers[NW->State](NW);
765 NWC_SetTimeout(rc, NW);
768 eNextState NWC_DispatchWriteDone(AsyncIO *IO)
770 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
771 AsyncNetworker *NW = IO->Data;
774 rc = NWC_SendHandlers[NW->State](NW);
775 NWC_SetTimeout(rc, NW);
779 /*****************************************************************************/
780 /* Networker CLIENT ERROR CATCHERS */
781 /*****************************************************************************/
782 eNextState NWC_Terminate(AsyncIO *IO)
784 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
785 FinalizeNetworker(IO);
789 eNextState NWC_Timeout(AsyncIO *IO)
791 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
793 return NWC_FailNetworkConnection(IO);
795 eNextState NWC_ConnFail(AsyncIO *IO)
797 /// AsyncNetworker *NW = IO->Data;
799 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
800 //// StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); todo
801 return NWC_FailNetworkConnection(IO);
803 eNextState NWC_DNSFail(AsyncIO *IO)
805 /// AsyncNetworker *NW = IO->Data;
807 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
808 //// StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); todo
809 return NWC_FailNetworkConnection(IO);
811 eNextState NWC_Shutdown(AsyncIO *IO)
813 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
814 //// pop3aggr *pMsg = IO->Data;
816 FinalizeNetworker(IO);
821 eNextState nwc_connect_ip(AsyncIO *IO)
823 AsyncNetworker *NW = IO->Data;
825 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
826 EVN_syslog(LOG_NOTICE, "Connecting to <%s> at %s:%s\n",
831 return EvConnectSock(IO,
837 static int NetworkerCount = 0;
838 void RunNetworker(AsyncNetworker *NW)
840 AsyncIO *IO = &NW->IO;
842 NW->n = NetworkerCount++;
843 network_talking_to(SKEY(NW->node), NTT_ADD);
844 syslog(LOG_DEBUG, "NW[%s][%ld]: polling\n", ChrPtr(NW->node), NW->n);
845 ParseURL(&NW->IO.ConnectMe, NW->Url, 504);
847 InitIOStruct(&NW->IO,
850 NWC_ReadServerStatus,
852 NWC_DispatchWriteDone,
853 NWC_DispatchReadDone,
859 safestrncpy(((CitContext *)NW->IO.CitContext)->cs_host,
861 sizeof(((CitContext *)NW->IO.CitContext)->cs_host));
863 if (NW->IO.ConnectMe->IsIP) {
864 QueueEventContext(&NW->IO,
867 else { /* uneducated admin has chosen to add DNS to the equation... */
868 QueueEventContext(&NW->IO,
869 nwc_get_one_host_ip);
874 * Poll other Citadel nodes and transfer inbound/outbound network data.
875 * Set "full" to nonzero to force a poll of every node, or to zero to poll
876 * only nodes to which we have data to send.
878 void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
889 if ((working_ignetcfg == NULL) || (*working_ignetcfg == '\0')) {
890 syslog(LOG_DEBUG, "network: no neighbor nodes are configured - not polling.\n");
893 become_session(&networker_client_CC);
895 CfgData = NewStrBufPlain(working_ignetcfg, -1);
896 Line = NewStrBufPlain(NULL, StrLength(CfgData));
901 /* Use the string tokenizer to grab one line at a time */
902 StrBufSipLine(Line, CfgData, &CfgPtr);
903 Done = CfgPtr == StrBufNOTNULL;
904 if (StrLength(Line) > 0)
906 if(server_shutting_down)
907 return;/* TODO free stuff*/
910 NW = (AsyncNetworker*)malloc(sizeof(AsyncNetworker));
911 memset(NW, 0, sizeof(AsyncNetworker));
913 NW->node = NewStrBufPlain(NULL, StrLength(Line));
914 NW->host = NewStrBufPlain(NULL, StrLength(Line));
915 NW->port = NewStrBufPlain(NULL, StrLength(Line));
916 NW->secret = NewStrBufPlain(NULL, StrLength(Line));
918 StrBufExtract_NextToken(NW->node, Line, &lptr, '|');
919 StrBufExtract_NextToken(NW->secret, Line, &lptr, '|');
920 StrBufExtract_NextToken(NW->host, Line, &lptr, '|');
921 StrBufExtract_NextToken(NW->port, Line, &lptr, '|');
922 if ( (StrLength(NW->node) != 0) &&
923 (StrLength(NW->secret) != 0) &&
924 (StrLength(NW->host) != 0) &&
925 (StrLength(NW->port) != 0))
930 NW->SpoolFileName = NewStrBufPlain(ctdl_netout_dir, -1);
931 StrBufAppendBufPlain(NW->SpoolFileName, HKEY("/"), 0);
932 StrBufAppendBuf(NW->SpoolFileName, NW->node, 0);
933 if (access(ChrPtr(NW->SpoolFileName), R_OK) == 0) {
939 (StrLength(NW->host) > 0) &&
940 strcmp("0.0.0.0", ChrPtr(NW->host)))
942 NW->Url = NewStrBufPlain(NULL, StrLength(Line));
943 StrBufPrintf(NW->Url, "citadel://:%s@%s:%s",
947 if (!network_talking_to(SKEY(NW->node), NTT_CHECK))
956 FreeStrBuf(&CfgData);
962 void network_do_clientqueue(void)
964 char *working_ignetcfg;
965 int full_processing = 1;
966 static time_t last_run = 0L;
969 * Run the full set of processing tasks no more frequently
970 * than once every n seconds
972 if ( (time(NULL) - last_run) < config.c_net_freq ) {
974 syslog(LOG_DEBUG, "Network full processing in %ld seconds.\n",
975 config.c_net_freq - (time(NULL)- last_run)
979 working_ignetcfg = load_working_ignetcfg();
981 * Poll other Citadel nodes. Maybe. If "full_processing" is set
982 * then we poll everyone. Otherwise we only poll nodes we have stuff
985 network_poll_other_citadel_nodes(full_processing, working_ignetcfg);
986 if (working_ignetcfg)
987 free(working_ignetcfg);
995 CTDL_MODULE_INIT(network_client)
999 CtdlFillSystemContext(&networker_client_CC, "CitNetworker");
1001 CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER);
1003 return "network_client";