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 FreeStrBuf(&NW->IO.ErrMsg);
161 FreeAsyncIOContents(&NW->IO);
165 #define NWC_DBG_SEND() EVN_syslog(LOG_DEBUG, ": > %s", ChrPtr(NW->IO.SendBuf.Buf))
166 #define NWC_DBG_READ() EVN_syslog(LOG_DEBUG, ": < %s\n", ChrPtr(NW->IO.IOBuf))
167 #define NWC_OK (strncasecmp(ChrPtr(NW->IO.IOBuf), "+OK", 3) == 0)
169 eNextState FinalizeNetworker(AsyncIO *IO)
171 AsyncNetworker *NW = (AsyncNetworker *)IO->Data;
173 network_talking_to(SKEY(NW->node), NTT_REMOVE);
175 DeleteNetworker(IO->Data);
179 eNextState NWC_ReadGreeting(AsyncNetworker *NW)
181 char connected_to[SIZ];
182 AsyncIO *IO = &NW->IO;
184 /* Read the server greeting */
185 /* Check that the remote is who we think it is and warn the Aide if not */
186 extract_token (connected_to, ChrPtr(NW->IO.IOBuf), 1, ' ', sizeof connected_to);
187 if (strcmp(connected_to, ChrPtr(NW->node)) != 0)
189 if (NW->IO.ErrMsg == NULL)
190 NW->IO.ErrMsg = NewStrBuf();
191 StrBufPrintf(NW->IO.ErrMsg,
192 "Connected to node \"%s\" but I was expecting to connect to node \"%s\".",
193 connected_to, ChrPtr(NW->node));
194 EVN_syslog(LOG_ERR, "%s\n", ChrPtr(NW->IO.ErrMsg));
195 CtdlAideMessage(ChrPtr(NW->IO.ErrMsg), "Network error");
196 return eAbort;/// todo: aide message in anderer queue speichern
201 eNextState NWC_SendAuth(AsyncNetworker *NW)
203 AsyncIO *IO = &NW->IO;
204 /* We're talking to the correct node. Now identify ourselves. */
205 StrBufPrintf(NW->IO.SendBuf.Buf, "NETP %s|%s\n",
212 eNextState NWC_ReadAuthReply(AsyncNetworker *NW)
214 AsyncIO *IO = &NW->IO;
216 if (ChrPtr(NW->IO.IOBuf)[0] == '2')
222 if (NW->IO.ErrMsg == NULL)
223 NW->IO.ErrMsg = NewStrBuf();
224 StrBufPrintf(NW->IO.ErrMsg,
225 "Connected to node \"%s\" but my secret wasn't accurate.",
227 EVN_syslog(LOG_ERR, "%s\n", ChrPtr(NW->IO.ErrMsg));
228 CtdlAideMessage(ChrPtr(NW->IO.ErrMsg), "Network error");
234 eNextState NWC_SendNDOP(AsyncNetworker *NW)
236 AsyncIO *IO = &NW->IO;
237 NW->tempFileName = NewStrBuf();
238 NW->SpoolFileName = NewStrBuf();
239 StrBufPrintf(NW->SpoolFileName,
243 time(NULL),// TODO: get time from libev
245 StrBufStripSlashes(NW->SpoolFileName, 1);
246 StrBufPrintf(NW->tempFileName,
250 time(NULL),// TODO: get time from libev
252 StrBufStripSlashes(NW->tempFileName, 1);
253 /* We're talking to the correct node. Now identify ourselves. */
254 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("NDOP\n"));
259 eNextState NWC_ReadNDOPReply(AsyncNetworker *NW)
261 AsyncIO *IO = &NW->IO;
264 if (ChrPtr(NW->IO.IOBuf)[0] == '2')
267 NW->IO.IOB.TotalSentAlready = 0;
268 TotalSendSize = atol (ChrPtr(NW->IO.IOBuf) + 4);
269 EVN_syslog(LOG_DEBUG, "Expecting to transfer %ld bytes\n", NW->IO.IOB.TotalSendSize);
270 if (TotalSendSize <= 0) {
271 NW->State = eNUOP - 1;
275 fd = open(ChrPtr(NW->tempFileName),
276 O_EXCL|O_CREAT|O_NONBLOCK|O_WRONLY,
281 "cannot open %s: %s\n",
282 ChrPtr(NW->tempFileName),
285 NW->State = eQUIT - 1;
288 FDIOBufferInit(&NW->IO.IOB, &NW->IO.RecvBuf, fd, TotalSendSize);
298 eNextState NWC_SendREAD(AsyncNetworker *NW)
300 AsyncIO *IO = &NW->IO;
303 if (NW->IO.IOB.TotalSentAlready < NW->IO.IOB.TotalSendSize)
306 * If shutting down we can exit here and unlink the temp file.
307 * this shouldn't loose us any messages.
309 if (server_shutting_down)
311 FDIOBufferDelete(&NW->IO.IOB);
312 unlink(ChrPtr(NW->tempFileName));
315 StrBufPrintf(NW->IO.SendBuf.Buf, "READ %ld|%ld\n",
316 NW->IO.IOB.TotalSentAlready,
317 NW->IO.IOB.TotalSendSize);
319 ((NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready > IGNET_PACKET_SIZE)
320 ? IGNET_PACKET_SIZE :
321 (NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready))
330 rc = NWC_DispatchWriteDone(&NW->IO);
337 eNextState NWC_ReadREADState(AsyncNetworker *NW)
339 AsyncIO *IO = &NW->IO;
341 if (ChrPtr(NW->IO.IOBuf)[0] == '6')
343 NW->IO.IOB.ChunkSendRemain =
344 NW->IO.IOB.ChunkSize = atol(ChrPtr(NW->IO.IOBuf)+4);
349 eNextState NWC_ReadREADBlobDone(AsyncNetworker *NW);
350 eNextState NWC_ReadREADBlob(AsyncNetworker *NW)
353 AsyncIO *IO = &NW->IO;
355 if (NW->IO.IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
359 FDIOBufferDelete(&NW->IO.IOB);
361 if (link(ChrPtr(NW->tempFileName), ChrPtr(NW->SpoolFileName)) != 0) {
362 EVN_syslog(LOG_ALERT,
363 "Could not link %s to %s: %s\n",
364 ChrPtr(NW->tempFileName),
365 ChrPtr(NW->SpoolFileName),
369 unlink(ChrPtr(NW->tempFileName));
370 rc = NWC_DispatchWriteDone(&NW->IO);
376 NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
377 return eSendReply; //NWC_DispatchWriteDone(&NW->IO);
381 eNextState NWC_ReadREADBlobDone(AsyncNetworker *NW)
384 AsyncIO *IO = &NW->IO;
385 /* we don't have any data to debug print here. */
386 if (NW->IO.IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
390 FDIOBufferDelete(&NW->IO.IOB);
392 if (link(ChrPtr(NW->tempFileName), ChrPtr(NW->SpoolFileName)) != 0) {
393 EVN_syslog(LOG_ALERT,
394 "Could not link %s to %s: %s\n",
395 ChrPtr(NW->tempFileName),
396 ChrPtr(NW->SpoolFileName),
400 unlink(ChrPtr(NW->tempFileName));
401 rc = NWC_DispatchWriteDone(&NW->IO);
407 NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
408 return NWC_DispatchWriteDone(&NW->IO);
411 eNextState NWC_SendCLOS(AsyncNetworker *NW)
413 AsyncIO *IO = &NW->IO;
414 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("CLOS\n"));
419 eNextState NWC_ReadCLOSReply(AsyncNetworker *NW)
421 AsyncIO *IO = &NW->IO;
423 if (ChrPtr(NW->IO.IOBuf)[0] != '2')
424 return eTerminateConnection;
429 eNextState NWC_SendNUOP(AsyncNetworker *NW)
431 AsyncIO *IO = &NW->IO;
437 StrBufPrintf(NW->SpoolFileName,
441 StrBufStripSlashes(NW->SpoolFileName, 1);
443 fd = open(ChrPtr(NW->SpoolFileName), O_RDONLY);
445 if (errno != ENOENT) {
447 "cannot open %s: %s\n",
448 ChrPtr(NW->SpoolFileName),
452 rc = NWC_SendQUIT(NW);
457 if (fstat(fd, &statbuf) == -1) {
458 EVN_syslog(LOG_CRIT, "FSTAT FAILED %s [%s]--\n",
459 ChrPtr(NW->SpoolFileName),
461 if (fd > 0) close(fd);
464 TotalSendSize = statbuf.st_size;
465 if (TotalSendSize == 0) {
466 EVNM_syslog(LOG_DEBUG,
467 "Nothing to send.\n");
469 rc = NWC_SendQUIT(NW);
473 FDIOBufferInit(&NW->IO.IOB, &NW->IO.SendBuf, fd, TotalSendSize);
475 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("NUOP\n"));
480 eNextState NWC_ReadNUOPReply(AsyncNetworker *NW)
482 AsyncIO *IO = &NW->IO;
484 if (ChrPtr(NW->IO.IOBuf)[0] != '2')
489 eNextState NWC_SendWRIT(AsyncNetworker *NW)
491 AsyncIO *IO = &NW->IO;
492 StrBufPrintf(NW->IO.SendBuf.Buf, "WRIT %ld\n",
493 NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready);
497 eNextState NWC_ReadWRITReply(AsyncNetworker *NW)
499 AsyncIO *IO = &NW->IO;
501 if (ChrPtr(NW->IO.IOBuf)[0] != '7')
506 NW->IO.IOB.ChunkSendRemain =
507 NW->IO.IOB.ChunkSize = atol(ChrPtr(NW->IO.IOBuf)+4);
511 eNextState NWC_SendBlobDone(AsyncNetworker *NW)
513 AsyncIO *IO = &NW->IO;
515 if (IO->IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
519 FDIOBufferDelete(&IO->IOB);
520 rc = NWC_DispatchWriteDone(IO);
526 IO->IOB.ChunkSendRemain = IO->IOB.ChunkSize;
527 rc = NWC_DispatchWriteDone(IO);
533 eNextState NWC_SendUCLS(AsyncNetworker *NW)
535 AsyncIO *IO = &NW->IO;
536 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("UCLS 1\n"));
541 eNextState NWC_ReadUCLS(AsyncNetworker *NW)
543 AsyncIO *IO = &NW->IO;
546 EVN_syslog(LOG_NOTICE, "Sent %ld octets to <%s>\n", NW->IO.IOB.ChunkSize, ChrPtr(NW->node));
547 if (ChrPtr(NW->IO.IOBuf)[0] == '2') {
548 EVN_syslog(LOG_DEBUG, "Removing <%s>\n", ChrPtr(NW->SpoolFileName));
549 unlink(ChrPtr(NW->SpoolFileName));
554 eNextState NWC_SendQUIT(AsyncNetworker *NW)
556 AsyncIO *IO = &NW->IO;
557 StrBufPlain(NW->IO.SendBuf.Buf, HKEY("QUIT\n"));
563 eNextState NWC_ReadQUIT(AsyncNetworker *NW)
565 AsyncIO *IO = &NW->IO;
572 NWClientHandler NWC_ReadHandlers[] = {
585 long NWC_ConnTimeout = 100;
587 const long NWC_SendTimeouts[] = {
597 const ConstStr NWC[] = {
598 {HKEY("Connection broken during ")},
599 {HKEY("Connection broken during ")},
600 {HKEY("Connection broken during ")},
601 {HKEY("Connection broken during ")},
602 {HKEY("Connection broken during ")},
603 {HKEY("Connection broken during ")},
604 {HKEY("Connection broken during ")},
605 {HKEY("Connection broken during ")}
608 NWClientHandler NWC_SendHandlers[] = {
613 NWC_ReadREADBlobDone,
622 const long NWC_ReadTimeouts[] = {
638 eNextState nwc_get_one_host_ip_done(AsyncIO *IO)
640 AsyncNetworker *NW = IO->Data;
641 struct hostent *hostent;
645 hostent = NW->HostLookup.VParsedDNSReply;
646 if ((NW->HostLookup.DNSStatus == ARES_SUCCESS) &&
647 (hostent != NULL) ) {
648 memset(&NW->IO.ConnectMe->Addr, 0, sizeof(struct in6_addr));
649 if (NW->IO.ConnectMe->IPv6) {
650 memcpy(&NW->IO.ConnectMe->Addr.sin6_addr.s6_addr,
651 &hostent->h_addr_list[0],
652 sizeof(struct in6_addr));
654 NW->IO.ConnectMe->Addr.sin6_family = hostent->h_addrtype;
655 NW->IO.ConnectMe->Addr.sin6_port = htons(atol(ChrPtr(NW->port)));//// TODO use the one from the URL.
658 struct sockaddr_in *addr = (struct sockaddr_in*) &NW->IO.ConnectMe->Addr;
659 /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
660 // addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]);
661 memcpy(&addr->sin_addr.s_addr,
662 hostent->h_addr_list[0],
665 addr->sin_family = hostent->h_addrtype;
666 addr->sin_port = htons(504);/// default citadel port
669 return nwc_connect_ip(IO);
676 eNextState nwc_get_one_host_ip(AsyncIO *IO)
678 AsyncNetworker *NW = IO->Data;
680 * here we start with the lookup of one host.
683 EVN_syslog(LOG_DEBUG, "NWC: %s\n", __FUNCTION__);
685 EVN_syslog(LOG_DEBUG,
686 "NWC client[%ld]: looking up %s-Record %s : %d ...\n",
688 (NW->IO.ConnectMe->IPv6)? "aaaa": "a",
689 NW->IO.ConnectMe->Host,
690 NW->IO.ConnectMe->Port);
692 QueueQuery((NW->IO.ConnectMe->IPv6)? ns_t_aaaa : ns_t_a,
693 NW->IO.ConnectMe->Host,
696 nwc_get_one_host_ip_done);
697 IO->NextState = eReadDNSReply;
698 return IO->NextState;
701 * @brief lineread Handler; understands when to read more POP3 lines, and when this is a one-lined reply.
703 eReadState NWC_ReadServerStatus(AsyncIO *IO)
705 // AsyncNetworker *NW = IO->Data;
706 eReadState Finished = eBufferNotEmpty;
708 switch (IO->NextState) {
713 case eTerminateConnection:
715 Finished = eReadFail;
721 Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
733 eNextState NWC_FailNetworkConnection(AsyncIO *IO)
738 void NWC_SetTimeout(eNextState NextTCPState, AsyncNetworker *NW)
740 AsyncIO *IO = &NW->IO;
741 double Timeout = 0.0;
743 EVN_syslog(LOG_DEBUG, "%s - %d\n", __FUNCTION__, NextTCPState);
745 switch (NextTCPState) {
751 Timeout = NWC_ReadTimeouts[NW->State];
762 case eTerminateConnection:
765 case eReadMore://// TODO
769 EVN_syslog(LOG_DEBUG,
774 SetNextTimeout(&NW->IO, Timeout*100);
779 eNextState NWC_DispatchReadDone(AsyncIO *IO)
781 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
782 AsyncNetworker *NW = IO->Data;
785 rc = NWC_ReadHandlers[NW->State](NW);
788 NWC_SetTimeout(rc, NW);
791 eNextState NWC_DispatchWriteDone(AsyncIO *IO)
793 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
794 AsyncNetworker *NW = IO->Data;
797 rc = NWC_SendHandlers[NW->State](NW);
798 NWC_SetTimeout(rc, NW);
802 /*****************************************************************************/
803 /* Networker CLIENT ERROR CATCHERS */
804 /*****************************************************************************/
805 eNextState NWC_Terminate(AsyncIO *IO)
807 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
808 FinalizeNetworker(IO);
812 eNextState NWC_TerminateDB(AsyncIO *IO)
814 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
815 FinalizeNetworker(IO);
819 eNextState NWC_Timeout(AsyncIO *IO)
821 AsyncNetworker *NW = IO->Data;
822 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
824 if (NW->IO.ErrMsg == NULL)
825 NW->IO.ErrMsg = NewStrBuf();
826 StrBufPrintf(NW->IO.ErrMsg, "Timeout while talking to %s \r\n", ChrPtr(NW->host));
827 return NWC_FailNetworkConnection(IO);
829 eNextState NWC_ConnFail(AsyncIO *IO)
831 AsyncNetworker *NW = IO->Data;
833 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
834 if (NW->IO.ErrMsg == NULL)
835 NW->IO.ErrMsg = NewStrBuf();
836 StrBufPrintf(NW->IO.ErrMsg, "failed to connect %s \r\n", ChrPtr(NW->host));
838 return NWC_FailNetworkConnection(IO);
840 eNextState NWC_DNSFail(AsyncIO *IO)
842 AsyncNetworker *NW = IO->Data;
844 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
845 if (NW->IO.ErrMsg == NULL)
846 NW->IO.ErrMsg = NewStrBuf();
847 StrBufPrintf(NW->IO.ErrMsg, "failed to look up %s \r\n", ChrPtr(NW->host));
849 return NWC_FailNetworkConnection(IO);
851 eNextState NWC_Shutdown(AsyncIO *IO)
853 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
855 FinalizeNetworker(IO);
860 eNextState nwc_connect_ip(AsyncIO *IO)
862 AsyncNetworker *NW = IO->Data;
864 EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
865 EVN_syslog(LOG_NOTICE, "Connecting to <%s> at %s:%s\n",
870 return EvConnectSock(IO,
876 static int NetworkerCount = 0;
877 void RunNetworker(AsyncNetworker *NW)
879 NW->n = NetworkerCount++;
880 network_talking_to(SKEY(NW->node), NTT_ADD);
881 syslog(LOG_DEBUG, "NW[%s][%ld]: polling\n", ChrPtr(NW->node), NW->n);
882 ParseURL(&NW->IO.ConnectMe, NW->Url, 504);
884 InitIOStruct(&NW->IO,
887 NWC_ReadServerStatus,
889 NWC_DispatchWriteDone,
890 NWC_DispatchReadDone,
897 safestrncpy(((CitContext *)NW->IO.CitContext)->cs_host,
899 sizeof(((CitContext *)NW->IO.CitContext)->cs_host));
901 if (NW->IO.ConnectMe->IsIP) {
902 QueueEventContext(&NW->IO,
905 else { /* uneducated admin has chosen to add DNS to the equation... */
906 QueueEventContext(&NW->IO,
907 nwc_get_one_host_ip);
912 * Poll other Citadel nodes and transfer inbound/outbound network data.
913 * Set "full" to nonzero to force a poll of every node, or to zero to poll
914 * only nodes to which we have data to send.
916 void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
921 StrBuf *SpoolFileName;
928 if ((working_ignetcfg == NULL) || (*working_ignetcfg == '\0')) {
929 syslog(LOG_DEBUG, "network: no neighbor nodes are configured - not polling.\n");
932 become_session(&networker_client_CC);
934 CfgData = NewStrBufPlain(working_ignetcfg, -1);
935 SpoolFileName = NewStrBufPlain(ctdl_netout_dir, -1);
936 Line = NewStrBufPlain(NULL, StrLength(CfgData));
941 /* Use the string tokenizer to grab one line at a time */
942 StrBufSipLine(Line, CfgData, &CfgPtr);
943 Done = CfgPtr == StrBufNOTNULL;
944 if (StrLength(Line) > 0)
946 if(server_shutting_down)
947 return;/* TODO free stuff*/
950 NW = (AsyncNetworker*)malloc(sizeof(AsyncNetworker));
951 memset(NW, 0, sizeof(AsyncNetworker));
953 NW->node = NewStrBufPlain(NULL, StrLength(Line));
954 NW->host = NewStrBufPlain(NULL, StrLength(Line));
955 NW->port = NewStrBufPlain(NULL, StrLength(Line));
956 NW->secret = NewStrBufPlain(NULL, StrLength(Line));
958 StrBufExtract_NextToken(NW->node, Line, &lptr, '|');
959 StrBufExtract_NextToken(NW->secret, Line, &lptr, '|');
960 StrBufExtract_NextToken(NW->host, Line, &lptr, '|');
961 StrBufExtract_NextToken(NW->port, Line, &lptr, '|');
962 if ( (StrLength(NW->node) != 0) &&
963 (StrLength(NW->secret) != 0) &&
964 (StrLength(NW->host) != 0) &&
965 (StrLength(NW->port) != 0))
970 StrBufAppendBufPlain(SpoolFileName, HKEY("/"), 0);
971 StrBufAppendBuf(SpoolFileName, NW->node, 0);
972 StrBufStripSlashes(SpoolFileName, 1);
974 if (access(ChrPtr(SpoolFileName), R_OK) == 0) {
980 (StrLength(NW->host) > 0) &&
981 strcmp("0.0.0.0", ChrPtr(NW->host)))
983 NW->Url = NewStrBufPlain(NULL, StrLength(Line));
984 StrBufPrintf(NW->Url, "citadel://:%s@%s:%s",
988 if (!network_talking_to(SKEY(NW->node), NTT_CHECK))
997 FreeStrBuf(&SpoolFileName);
998 FreeStrBuf(&CfgData);
1004 void network_do_clientqueue(void)
1006 char *working_ignetcfg;
1007 int full_processing = 1;
1008 static time_t last_run = 0L;
1011 * Run the full set of processing tasks no more frequently
1012 * than once every n seconds
1014 if ( (time(NULL) - last_run) < config.c_net_freq ) {
1015 full_processing = 0;
1016 syslog(LOG_DEBUG, "Network full processing in %ld seconds.\n",
1017 config.c_net_freq - (time(NULL)- last_run)
1021 working_ignetcfg = load_working_ignetcfg();
1023 * Poll other Citadel nodes. Maybe. If "full_processing" is set
1024 * then we poll everyone. Otherwise we only poll nodes we have stuff
1027 network_poll_other_citadel_nodes(full_processing, working_ignetcfg);
1028 if (working_ignetcfg)
1029 free(working_ignetcfg);
1035 * Module entry point
1037 CTDL_MODULE_INIT(network_client)
1041 CtdlFillSystemContext(&networker_client_CC, "CitNetworker");
1043 CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER);
1045 return "network_client";