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);
442 if (fstat(fd, &statbuf) == -1) {
443 EVN_syslog(LOG_CRIT, "FSTAT FAILED %s [%s]--\n",
444 ChrPtr(NW->tempFileName),
446 if (fd > 0) close(fd);
449 TotalSendSize = statbuf.st_size;
450 if (TotalSendSize == 0) {
451 EVNM_syslog(LOG_DEBUG,
452 "Nothing to send.\n");
454 rc = NWC_SendQUIT(NW);
458 FDIOBufferInit(&NW->IO.IOB, &NW->IO.SendBuf, fd, TotalSendSize);
460 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("NUOP\n"));
465 eNextState NWC_ReadNUOPReply(AsyncNetworker *NW)
467 AsyncIO *IO = &NW->IO;
469 if (ChrPtr(NW->IO.IOBuf)[0] != '2')
474 eNextState NWC_SendWRIT(AsyncNetworker *NW)
476 AsyncIO *IO = &NW->IO;
477 StrBufPrintf(NW->IO.SendBuf.Buf, "WRIT %ld\n",
478 NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready);
482 eNextState NWC_ReadWRITReply(AsyncNetworker *NW)
484 AsyncIO *IO = &NW->IO;
486 if (ChrPtr(NW->IO.IOBuf)[0] != '7')
491 NW->IO.IOB.ChunkSendRemain =
492 NW->IO.IOB.ChunkSize = atol(ChrPtr(NW->IO.IOBuf)+4);
496 eNextState NWC_SendBlobDone(AsyncNetworker *NW)
498 AsyncIO *IO = &NW->IO;
500 if (NW->IO.IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
504 FDIOBufferDelete(&NW->IO.IOB);
505 rc = NWC_DispatchWriteDone(&NW->IO);
511 NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
512 return NWC_DispatchWriteDone(&NW->IO);
516 eNextState NWC_SendUCLS(AsyncNetworker *NW)
518 AsyncIO *IO = &NW->IO;
519 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("UCLS 1\n"));
524 eNextState NWC_ReadUCLS(AsyncNetworker *NW)
526 AsyncIO *IO = &NW->IO;
529 EVN_syslog(LOG_NOTICE, "Sent %ld octets to <%s>\n", NW->IO.IOB.ChunkSize, ChrPtr(NW->node));
530 if (ChrPtr(NW->IO.IOBuf)[0] == '2') {
531 EVN_syslog(LOG_DEBUG, "Removing <%s>\n", ChrPtr(NW->tempFileName));
532 unlink(ChrPtr(NW->tempFileName));
537 eNextState NWC_SendQUIT(AsyncNetworker *NW)
539 AsyncIO *IO = &NW->IO;
540 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("QUIT\n"));
546 eNextState NWC_ReadQUIT(AsyncNetworker *NW)
548 AsyncIO *IO = &NW->IO;
555 NWClientHandler NWC_ReadHandlers[] = {
568 long NWC_ConnTimeout = 100;
570 const long NWC_SendTimeouts[] = {
580 const ConstStr NWC[] = {
581 {HKEY("Connection broken during ")},
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 ")}
591 NWClientHandler NWC_SendHandlers[] = {
596 NWC_ReadREADBlobDone,
605 const long NWC_ReadTimeouts[] = {
621 eNextState nwc_get_one_host_ip_done(AsyncIO *IO)
623 AsyncNetworker *NW = IO->Data;
624 struct hostent *hostent;
628 hostent = NW->HostLookup.VParsedDNSReply;
629 if ((NW->HostLookup.DNSStatus == ARES_SUCCESS) &&
630 (hostent != NULL) ) {
631 memset(&NW->IO.ConnectMe->Addr, 0, sizeof(struct in6_addr));
632 if (NW->IO.ConnectMe->IPv6) {
633 memcpy(&NW->IO.ConnectMe->Addr.sin6_addr.s6_addr,
634 &hostent->h_addr_list[0],
635 sizeof(struct in6_addr));
637 NW->IO.ConnectMe->Addr.sin6_family = hostent->h_addrtype;
638 NW->IO.ConnectMe->Addr.sin6_port = htons(atol(ChrPtr(NW->port)));//// TODO use the one from the URL.
641 struct sockaddr_in *addr = (struct sockaddr_in*) &NW->IO.ConnectMe->Addr;
642 /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
643 // addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]);
644 memcpy(&addr->sin_addr.s_addr,
645 hostent->h_addr_list[0],
648 addr->sin_family = hostent->h_addrtype;
649 addr->sin_port = htons(504);/// default citadel port
652 return nwc_connect_ip(IO);
659 eNextState nwc_get_one_host_ip(AsyncIO *IO)
661 AsyncNetworker *NW = IO->Data;
663 * here we start with the lookup of one host.
666 EVN_syslog(LOG_DEBUG, "NWC: %s\n", __FUNCTION__);
668 EVN_syslog(LOG_DEBUG,
669 "NWC client[%ld]: looking up %s-Record %s : %d ...\n",
671 (NW->IO.ConnectMe->IPv6)? "aaaa": "a",
672 NW->IO.ConnectMe->Host,
673 NW->IO.ConnectMe->Port);
675 QueueQuery((NW->IO.ConnectMe->IPv6)? ns_t_aaaa : ns_t_a,
676 NW->IO.ConnectMe->Host,
679 nwc_get_one_host_ip_done);
680 IO->NextState = eReadDNSReply;
681 return IO->NextState;
684 * @brief lineread Handler; understands when to read more POP3 lines, and when this is a one-lined reply.
686 eReadState NWC_ReadServerStatus(AsyncIO *IO)
688 // AsyncNetworker *NW = IO->Data;
689 eReadState Finished = eBufferNotEmpty;
691 switch (IO->NextState) {
696 case eTerminateConnection:
698 Finished = eReadFail;
704 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
716 eNextState NWC_FailNetworkConnection(AsyncIO *IO)
721 void NWC_SetTimeout(eNextState NextTCPState, AsyncNetworker *NW)
723 AsyncIO *IO = &NW->IO;
724 double Timeout = 0.0;
726 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
728 switch (NextTCPState) {
734 Timeout = NWC_ReadTimeouts[NW->State];
745 case eTerminateConnection:
748 case eReadMore://// TODO
751 SetNextTimeout(&NW->IO, Timeout);
755 eNextState NWC_DispatchReadDone(AsyncIO *IO)
757 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
758 AsyncNetworker *NW = IO->Data;
761 rc = NWC_ReadHandlers[NW->State](NW);
764 NWC_SetTimeout(rc, NW);
767 eNextState NWC_DispatchWriteDone(AsyncIO *IO)
769 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
770 AsyncNetworker *NW = IO->Data;
773 rc = NWC_SendHandlers[NW->State](NW);
774 NWC_SetTimeout(rc, NW);
778 /*****************************************************************************/
779 /* Networker CLIENT ERROR CATCHERS */
780 /*****************************************************************************/
781 eNextState NWC_Terminate(AsyncIO *IO)
783 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
784 FinalizeNetworker(IO);
788 eNextState NWC_Timeout(AsyncIO *IO)
790 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
792 return NWC_FailNetworkConnection(IO);
794 eNextState NWC_ConnFail(AsyncIO *IO)
796 /// AsyncNetworker *NW = IO->Data;
798 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
799 //// StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); todo
800 return NWC_FailNetworkConnection(IO);
802 eNextState NWC_DNSFail(AsyncIO *IO)
804 /// AsyncNetworker *NW = IO->Data;
806 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
807 //// StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); todo
808 return NWC_FailNetworkConnection(IO);
810 eNextState NWC_Shutdown(AsyncIO *IO)
812 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
813 //// pop3aggr *pMsg = IO->Data;
815 FinalizeNetworker(IO);
820 eNextState nwc_connect_ip(AsyncIO *IO)
822 AsyncNetworker *NW = IO->Data;
824 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
825 EVN_syslog(LOG_NOTICE, "Connecting to <%s> at %s:%s\n",
830 return EvConnectSock(IO,
836 static int NetworkerCount = 0;
837 void RunNetworker(AsyncNetworker *NW)
839 AsyncIO *IO = &NW->IO;
841 NW->n = NetworkerCount++;
842 network_talking_to(SKEY(NW->node), NTT_ADD);
843 EVN_syslog(LOG_DEBUG, "network: polling <%s>\n", ChrPtr(NW->node));
844 ParseURL(&NW->IO.ConnectMe, NW->Url, 504);
846 InitIOStruct(&NW->IO,
849 NWC_ReadServerStatus,
851 NWC_DispatchWriteDone,
852 NWC_DispatchReadDone,
858 safestrncpy(((CitContext *)NW->IO.CitContext)->cs_host,
860 sizeof(((CitContext *)NW->IO.CitContext)->cs_host));
862 if (NW->IO.ConnectMe->IsIP) {
863 QueueEventContext(&NW->IO,
866 else { /* uneducated admin has chosen to add DNS to the equation... */
867 QueueEventContext(&NW->IO,
868 nwc_get_one_host_ip);
873 * Poll other Citadel nodes and transfer inbound/outbound network data.
874 * Set "full" to nonzero to force a poll of every node, or to zero to poll
875 * only nodes to which we have data to send.
877 void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
888 if ((working_ignetcfg == NULL) || (*working_ignetcfg == '\0')) {
889 syslog(LOG_DEBUG, "network: no neighbor nodes are configured - not polling.\n");
892 become_session(&networker_client_CC);
894 CfgData = NewStrBufPlain(working_ignetcfg, -1);
895 Line = NewStrBufPlain(NULL, StrLength(CfgData));
900 /* Use the string tokenizer to grab one line at a time */
901 StrBufSipLine(Line, CfgData, &CfgPtr);
902 Done = CfgPtr == StrBufNOTNULL;
903 if (StrLength(Line) > 0)
905 if(server_shutting_down)
906 return;/* TODO free stuff*/
909 NW = (AsyncNetworker*)malloc(sizeof(AsyncNetworker));
910 memset(NW, 0, sizeof(AsyncNetworker));
912 NW->node = NewStrBufPlain(NULL, StrLength(Line));
913 NW->host = NewStrBufPlain(NULL, StrLength(Line));
914 NW->port = NewStrBufPlain(NULL, StrLength(Line));
915 NW->secret = NewStrBufPlain(NULL, StrLength(Line));
917 StrBufExtract_NextToken(NW->node, Line, &lptr, '|');
918 StrBufExtract_NextToken(NW->secret, Line, &lptr, '|');
919 StrBufExtract_NextToken(NW->host, Line, &lptr, '|');
920 StrBufExtract_NextToken(NW->port, Line, &lptr, '|');
921 if ( (StrLength(NW->node) != 0) &&
922 (StrLength(NW->secret) != 0) &&
923 (StrLength(NW->host) != 0) &&
924 (StrLength(NW->port) != 0))
929 NW->SpoolFileName = NewStrBufPlain(ctdl_netout_dir, -1);
930 StrBufAppendBufPlain(NW->SpoolFileName, HKEY("/"), 0);
931 StrBufAppendBuf(NW->SpoolFileName, NW->node, 0);
932 if (access(ChrPtr(NW->SpoolFileName), R_OK) == 0) {
937 if (poll && (StrLength (NW->host) > 0) && (!strcmp(ChrPtr(NW->host), "0.0.0.0")))
939 NW->Url = NewStrBufPlain(NULL, StrLength(Line));
940 StrBufPrintf(NW->Url, "citadel://:%s@%s:%s",
944 if (!network_talking_to(SKEY(NW->node), NTT_CHECK))
953 FreeStrBuf(&CfgData);
959 void network_do_clientqueue(void)
961 char *working_ignetcfg;
962 int full_processing = 1;
963 static time_t last_run = 0L;
966 * Run the full set of processing tasks no more frequently
967 * than once every n seconds
969 if ( (time(NULL) - last_run) < config.c_net_freq ) {
971 syslog(LOG_DEBUG, "Network full processing in %ld seconds.\n",
972 config.c_net_freq - (time(NULL)- last_run)
976 working_ignetcfg = load_working_ignetcfg();
978 * Poll other Citadel nodes. Maybe. If "full_processing" is set
979 * then we poll everyone. Otherwise we only poll nodes we have stuff
982 network_poll_other_citadel_nodes(full_processing, working_ignetcfg);
983 if (working_ignetcfg)
984 free(working_ignetcfg);
992 CTDL_MODULE_INIT(network_client)
996 CtdlFillSystemContext(&networker_client_CC, "CitNetworker");
998 CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER);
1000 return "network_client";