Back to index

citadel  8.12
Classes | Defines | Typedefs | Enumerations | Functions | Variables
serv_networkclient.c File Reference
#include "sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <signal.h>
#include <pwd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <time.h>
#include <sys/wait.h>
#include <string.h>
#include <limits.h>
#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
#include "citserver.h"
#include "support.h"
#include "config.h"
#include "user_ops.h"
#include "database.h"
#include "msgbase.h"
#include "internet_addressing.h"
#include "serv_network.h"
#include "clientsocket.h"
#include "file_ops.h"
#include "citadel_dirs.h"
#include "threads.h"
#include "snprintf.h"
#include "context.h"
#include "netconfig.h"
#include "ctdl_module.h"

Go to the source code of this file.

Classes

struct  _async_networker

Defines

#define NODE   ChrPtr(((AsyncNetworker*)IO->Data)->node)
#define N   ((AsyncNetworker*)IO->Data)->n
#define DBGLOG(LEVEL)   if ((LEVEL != LOG_DEBUG) || (NetworkClientDebugEnabled != 0))
#define EVN_syslog(LEVEL, FORMAT,...)
#define EVNM_syslog(LEVEL, FORMAT)
#define EVNCS_syslog(LEVEL, FORMAT,...)
#define EVNCSM_syslog(LEVEL, FORMAT)
#define NWC_DBG_SEND()   EVN_syslog(LOG_DEBUG, ": > %s", ChrPtr(NW->IO.SendBuf.Buf))
#define NWC_DBG_READ()   EVN_syslog(LOG_DEBUG, ": < %s\n", ChrPtr(NW->IO.IOBuf))
#define NWC_OK   (strncasecmp(ChrPtr(NW->IO.IOBuf), "+OK", 3) == 0)

Typedefs

typedef enum _eNWCState eNWCState
typedef struct _async_networker AsyncNetworker
typedef eNextState(* NWClientHandler )(AsyncNetworker *NW)

Enumerations

enum  _eNWCState {
  eeGreating, eAuth, eNDOP, eREAD,
  eReadBLOB, eCLOS, eNUOP, eWRIT,
  eWriteBLOB, eUCLS, eQUIT
}

Functions

eNextState nwc_get_one_host_ip (AsyncIO *IO)
eNextState nwc_connect_ip (AsyncIO *IO)
eNextState NWC_SendQUIT (AsyncNetworker *NW)
eNextState NWC_DispatchWriteDone (AsyncIO *IO)
void DeleteNetworker (void *vptr)
eNextState FinalizeNetworker (AsyncIO *IO)
eNextState NWC_ReadGreeting (AsyncNetworker *NW)
eNextState NWC_SendAuth (AsyncNetworker *NW)
eNextState NWC_ReadAuthReply (AsyncNetworker *NW)
eNextState NWC_SendNDOP (AsyncNetworker *NW)
eNextState NWC_ReadNDOPReply (AsyncNetworker *NW)
eNextState NWC_SendREAD (AsyncNetworker *NW)
eNextState NWC_ReadREADState (AsyncNetworker *NW)
eNextState NWC_ReadREADBlobDone (AsyncNetworker *NW)
eNextState NWC_ReadREADBlob (AsyncNetworker *NW)
eNextState NWC_SendCLOS (AsyncNetworker *NW)
eNextState NWC_ReadCLOSReply (AsyncNetworker *NW)
eNextState NWC_SendNUOP (AsyncNetworker *NW)
eNextState NWC_ReadNUOPReply (AsyncNetworker *NW)
eNextState NWC_SendWRIT (AsyncNetworker *NW)
eNextState NWC_ReadWRITReply (AsyncNetworker *NW)
eNextState NWC_SendBlobDone (AsyncNetworker *NW)
eNextState NWC_SendUCLS (AsyncNetworker *NW)
eNextState NWC_ReadUCLS (AsyncNetworker *NW)
eNextState NWC_ReadQUIT (AsyncNetworker *NW)
eNextState nwc_get_one_host_ip_done (AsyncIO *IO)
eReadState NWC_ReadServerStatus (AsyncIO *IO)
 lineread Handler; understands when to read more POP3 lines, and when this is a one-lined reply.
eNextState NWC_FailNetworkConnection (AsyncIO *IO)
void NWC_SetTimeout (eNextState NextTCPState, AsyncNetworker *NW)
eNextState NWC_DispatchReadDone (AsyncIO *IO)
eNextState NWC_Terminate (AsyncIO *IO)
eNextState NWC_TerminateDB (AsyncIO *IO)
eNextState NWC_Timeout (AsyncIO *IO)
eNextState NWC_ConnFail (AsyncIO *IO)
eNextState NWC_DNSFail (AsyncIO *IO)
eNextState NWC_Shutdown (AsyncIO *IO)
void RunNetworker (AsyncNetworker *NW)
void network_poll_other_citadel_nodes (int full_poll, HashList *ignetcfg)
void network_do_clientqueue (void)
void LogDebugEnableNetworkClient (const int n)
 CTDL_MODULE_INIT (network_client)

Variables

int NetworkClientDebugEnabled = 0
NWClientHandler NWC_ReadHandlers []
long NWC_ConnTimeout = 100
const long NWC_SendTimeouts []
const ConstStr NWC []
NWClientHandler NWC_SendHandlers []
const long NWC_ReadTimeouts []
static int NetworkerCount = 0

Class Documentation

struct _async_networker

Definition at line 132 of file serv_networkclient.c.

Collaboration diagram for _async_networker:
Class Members
StrBuf * host
DNSQueryParts HostLookup
AsyncIO IO
long n
StrBuf * node
StrBuf * port
StrBuf * secret
StrBuf * SpoolFileName
eNWCState State
StrBuf * tempFileName
StrBuf * Url

Define Documentation

#define DBGLOG (   LEVEL)    if ((LEVEL != LOG_DEBUG) || (NetworkClientDebugEnabled != 0))

Definition at line 96 of file serv_networkclient.c.

#define EVN_syslog (   LEVEL,
  FORMAT,
  ... 
)
Value:
DBGLOG(LEVEL) syslog(LEVEL, \
              "IO[%ld]CC[%d]NW[%s][%ld]" FORMAT, \
              IO->ID, CCID, NODE, N, __VA_ARGS__)

Definition at line 98 of file serv_networkclient.c.

#define EVNCS_syslog (   LEVEL,
  FORMAT,
  ... 
)
Value:
DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \
              IO->ID, NODE, N, __VA_ARGS__)

Definition at line 108 of file serv_networkclient.c.

#define EVNCSM_syslog (   LEVEL,
  FORMAT 
)
Value:
DBGLOG(LEVEL) syslog(LEVEL, "IO[%ld]NW[%s][%ld]" FORMAT, \
              IO->ID, NODE, N)

Definition at line 112 of file serv_networkclient.c.

#define EVNM_syslog (   LEVEL,
  FORMAT 
)
Value:
DBGLOG(LEVEL) syslog(LEVEL, \
              "IO[%ld]CC[%d]NW[%s][%ld]" FORMAT, \
              IO->ID, CCID, NODE, N)

Definition at line 103 of file serv_networkclient.c.

#define N   ((AsyncNetworker*)IO->Data)->n

Definition at line 92 of file serv_networkclient.c.

#define NODE   ChrPtr(((AsyncNetworker*)IO->Data)->node)

Definition at line 91 of file serv_networkclient.c.

#define NWC_DBG_READ ( )    EVN_syslog(LOG_DEBUG, ": < %s\n", ChrPtr(NW->IO.IOBuf))

Definition at line 174 of file serv_networkclient.c.

#define NWC_DBG_SEND ( )    EVN_syslog(LOG_DEBUG, ": > %s", ChrPtr(NW->IO.SendBuf.Buf))

Definition at line 173 of file serv_networkclient.c.

#define NWC_OK   (strncasecmp(ChrPtr(NW->IO.IOBuf), "+OK", 3) == 0)

Definition at line 175 of file serv_networkclient.c.


Typedef Documentation

typedef enum _eNWCState eNWCState

Definition at line 146 of file serv_networkclient.c.


Enumeration Type Documentation

enum _eNWCState
Enumerator:
eeGreating 
eAuth 
eNDOP 
eREAD 
eReadBLOB 
eCLOS 
eNUOP 
eWRIT 
eWriteBLOB 
eUCLS 
eQUIT 

Definition at line 117 of file serv_networkclient.c.


Function Documentation

CTDL_MODULE_INIT ( network_client  )

Definition at line 1040 of file serv_networkclient.c.

{
       if (!threading)
       {
              CtdlFillSystemContext(&networker_client_CC, "CitNetworker");
              
              CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER, PRIO_SEND + 10);
              CtdlRegisterDebugFlagHook(HKEY("networkclient"), LogDebugEnableNetworkClient, &NetworkClientDebugEnabled);

       }
       return "networkclient";
}

Here is the call graph for this function:

void DeleteNetworker ( void *  vptr)

Definition at line 154 of file serv_networkclient.c.

{
       AsyncNetworker *NW = (AsyncNetworker *)vptr;
        FreeStrBuf(&NW->SpoolFileName);
        FreeStrBuf(&NW->tempFileName);
       FreeStrBuf(&NW->node);
       FreeStrBuf(&NW->host);
       FreeStrBuf(&NW->port);
       FreeStrBuf(&NW->secret);
       FreeStrBuf(&NW->Url);
       FreeStrBuf(&NW->IO.ErrMsg);
       FreeAsyncIOContents(&NW->IO);
       if (NW->HostLookup.VParsedDNSReply != NULL) {
              NW->HostLookup.DNSReplyFree(NW->HostLookup.VParsedDNSReply);
              NW->HostLookup.VParsedDNSReply = NULL;
       }
       free(NW);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 177 of file serv_networkclient.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void LogDebugEnableNetworkClient ( const int  n)

Definition at line 1033 of file serv_networkclient.c.

Here is the caller graph for this function:

void network_do_clientqueue ( void  )

Definition at line 1006 of file serv_networkclient.c.

{
       HashList *working_ignetcfg;
       int full_processing = 1;
       static time_t last_run = 0L;

       /*
        * Run the full set of processing tasks no more frequently
        * than once every n seconds
        */
       if ( (time(NULL) - last_run) < config.c_net_freq ) {
              full_processing = 0;
              syslog(LOG_DEBUG, "Network full processing in %ld seconds.\n",
                     config.c_net_freq - (time(NULL)- last_run)
              );
       }

       working_ignetcfg = load_ignetcfg();
       /*
        * Poll other Citadel nodes.  Maybe.  If "full_processing" is set
        * then we poll everyone.  Otherwise we only poll nodes we have stuff
        * to send to.
        */
       network_poll_other_citadel_nodes(full_processing, working_ignetcfg);
       DeleteHash(&working_ignetcfg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void network_poll_other_citadel_nodes ( int  full_poll,
HashList *  ignetcfg 
)

Definition at line 931 of file serv_networkclient.c.

{
       const char *key;
       long len;
       HashPos *Pos;
       void *vCfg;
       AsyncNetworker *NW;
       StrBuf *SpoolFileName;
       
       int poll = 0;
       
       if (GetCount(ignetcfg) ==0) {
              syslog(LOG_DEBUG, "network: no neighbor nodes are configured - not polling.\n");
              return;
       }
       become_session(&networker_client_CC);

       SpoolFileName = NewStrBufPlain(ctdl_netout_dir, -1);

       Pos = GetNewHashPos(ignetcfg, 0);

       while (GetNextHashPos(ignetcfg, Pos, &len, &key, &vCfg))
       {
              /* Use the string tokenizer to grab one line at a time */
              if(server_shutting_down)
                     return;/* TODO free stuff*/
              NodeConf *pNode = (NodeConf*) vCfg;
              poll = 0;
              NW = (AsyncNetworker*)malloc(sizeof(AsyncNetworker));
              memset(NW, 0, sizeof(AsyncNetworker));
              
              NW->node = NewStrBufDup(pNode->NodeName);
              NW->host = NewStrBufDup(pNode->Host);
              NW->port = NewStrBufDup(pNode->Port);
              NW->secret = NewStrBufDup(pNode->Secret);
              
              if ( (StrLength(NW->node) != 0) && 
                   (StrLength(NW->secret) != 0) &&
                   (StrLength(NW->host) != 0) &&
                   (StrLength(NW->port) != 0))
              {
                     poll = full_poll;
                     if (poll == 0)
                     {
                            StrBufAppendBufPlain(SpoolFileName, HKEY("/"), 0);
                            StrBufAppendBuf(SpoolFileName, NW->node, 0);
                            StrBufStripSlashes(SpoolFileName, 1);
                            
                            if (access(ChrPtr(SpoolFileName), R_OK) == 0) {
                                   poll = 1;
                            }
                     }
              }
              if (poll && 
                  (StrLength(NW->host) > 0) && 
                  strcmp("0.0.0.0", ChrPtr(NW->host)))
              {
                     NW->Url = NewStrBuf();
                     StrBufPrintf(NW->Url, "citadel://:%s@%s:%s", 
                                 ChrPtr(NW->secret),
                                 ChrPtr(NW->host),
                                 ChrPtr(NW->port));
                     if (!network_talking_to(SKEY(NW->node), NTT_CHECK))
                     {
                            RunNetworker(NW);
                            continue;
                     }
              }
              DeleteNetworker(NW);
       }
       FreeStrBuf(&SpoolFileName);
       DeleteHashPos(&Pos);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 875 of file serv_networkclient.c.

{
       AsyncNetworker *NW = IO->Data;

       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
       EVN_syslog(LOG_NOTICE, "Connecting to <%s> at %s:%s\n", 
                 ChrPtr(NW->node), 
                 ChrPtr(NW->host),
                 ChrPtr(NW->port));
       
       return EvConnectSock(IO,
                          NWC_ConnTimeout,
                          NWC_ReadTimeouts[0],
                          1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 844 of file serv_networkclient.c.

{
       AsyncNetworker *NW = IO->Data;

       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
       if (NW->IO.ErrMsg == NULL)
              NW->IO.ErrMsg = NewStrBuf();
       StrBufPrintf(NW->IO.ErrMsg, "failed to connect %s \r\n", ChrPtr(NW->host));

       return NWC_FailNetworkConnection(IO);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 794 of file serv_networkclient.c.

{
       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
       AsyncNetworker *NW = IO->Data;
       eNextState rc;

       rc = NWC_ReadHandlers[NW->State](NW);
       if (rc != eReadMore)
              NW->State++;
       NWC_SetTimeout(rc, NW);
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 806 of file serv_networkclient.c.

{
       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
       AsyncNetworker *NW = IO->Data;
       eNextState rc;

       rc = NWC_SendHandlers[NW->State](NW);
       NWC_SetTimeout(rc, NW);
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 855 of file serv_networkclient.c.

{
       AsyncNetworker *NW = IO->Data;

       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
       if (NW->IO.ErrMsg == NULL)
              NW->IO.ErrMsg = NewStrBuf();
       StrBufPrintf(NW->IO.ErrMsg, "failed to look up %s \r\n", ChrPtr(NW->host));

       return NWC_FailNetworkConnection(IO);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 748 of file serv_networkclient.c.

{
       return eAbort;
}

Here is the caller graph for this function:

Definition at line 691 of file serv_networkclient.c.

{
       AsyncNetworker *NW = IO->Data;
       /* 
        * here we start with the lookup of one host.
        */ 

       EVN_syslog(LOG_DEBUG, "NWC: %s\n", __FUNCTION__);

       EVN_syslog(LOG_DEBUG, 
                 "NWC client[%ld]: looking up %s-Record %s : %d ...\n", 
                 NW->n, 
                 (NW->IO.ConnectMe->IPv6)? "aaaa": "a",
                 NW->IO.ConnectMe->Host, 
                 NW->IO.ConnectMe->Port);

       QueueQuery((NW->IO.ConnectMe->IPv6)? ns_t_aaaa : ns_t_a, 
                 NW->IO.ConnectMe->Host, 
                 &NW->IO, 
                 &NW->HostLookup, 
                 nwc_get_one_host_ip_done);
       IO->NextState = eReadDNSReply;
       return IO->NextState;
}

Here is the call graph for this function:

Here is the caller graph for this function:

default citadel port

Definition at line 653 of file serv_networkclient.c.

{
       AsyncNetworker *NW = IO->Data;
       struct hostent *hostent;

       QueryCbDone(IO);

       hostent = NW->HostLookup.VParsedDNSReply;
       if ((NW->HostLookup.DNSStatus == ARES_SUCCESS) && 
           (hostent != NULL) ) {
              memset(&NW->IO.ConnectMe->Addr, 0, sizeof(struct in6_addr));
              if (NW->IO.ConnectMe->IPv6) {
                     memcpy(&NW->IO.ConnectMe->Addr.sin6_addr.s6_addr, 
                            &hostent->h_addr_list[0],
                            sizeof(struct in6_addr));
                     
                     NW->IO.ConnectMe->Addr.sin6_family = hostent->h_addrtype;
                     NW->IO.ConnectMe->Addr.sin6_port   = htons(atol(ChrPtr(NW->port)));
              }
              else {
                     struct sockaddr_in *addr = (struct sockaddr_in*) &NW->IO.ConnectMe->Addr;
                     /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
//                   addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]);
                     memcpy(&addr->sin_addr.s_addr, 
                            hostent->h_addr_list[0], 
                            sizeof(uint32_t));
                     
                     addr->sin_family = hostent->h_addrtype;
                     addr->sin_port   = htons(504);
                     
              }
              return nwc_connect_ip(IO);
       }
       else
              return eAbort;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 220 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();
       if (ChrPtr(NW->IO.IOBuf)[0] == '2')
       {
              return eSendReply;
       }
       else
       {
              if (NW->IO.ErrMsg == NULL)
                     NW->IO.ErrMsg = NewStrBuf();
              StrBufPrintf(NW->IO.ErrMsg,
                          "Connected to node \"%s\" but my secret wasn't accurate.",
                          ChrPtr(NW->node));
              EVN_syslog(LOG_ERR, "%s\n", ChrPtr(NW->IO.ErrMsg));
              CtdlAideMessage(ChrPtr(NW->IO.ErrMsg), "Network error");
              
              return eAbort;
       }
}

Definition at line 428 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();
       FDIOBufferDelete(&IO->IOB);
       if (ChrPtr(NW->IO.IOBuf)[0] != '2')
              return eTerminateConnection;
       return eSendReply;
}

todo: aide message in anderer queue speichern

Definition at line 187 of file serv_networkclient.c.

{
       char connected_to[SIZ];
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();
       /* Read the server greeting */
       /* Check that the remote is who we think it is and warn the Aide if not */
       extract_token (connected_to, ChrPtr(NW->IO.IOBuf), 1, ' ', sizeof connected_to);
       if (strcmp(connected_to, ChrPtr(NW->node)) != 0)
       {
              if (NW->IO.ErrMsg == NULL)
                     NW->IO.ErrMsg = NewStrBuf();
              StrBufPrintf(NW->IO.ErrMsg,
                          "Connected to node \"%s\" but I was expecting to connect to node \"%s\".",
                          connected_to, ChrPtr(NW->node));
              EVN_syslog(LOG_ERR, "%s\n", ChrPtr(NW->IO.ErrMsg));
              CtdlAideMessage(ChrPtr(NW->IO.ErrMsg), "Network error");
              return eAbort;
       }
       return eSendReply;
}

Definition at line 267 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       int TotalSendSize;
       NWC_DBG_READ();
       if (ChrPtr(NW->IO.IOBuf)[0] == '2')
       {

              NW->IO.IOB.TotalSentAlready = 0;
              TotalSendSize = atol (ChrPtr(NW->IO.IOBuf) + 4);
              EVN_syslog(LOG_DEBUG, "Expecting to transfer %d bytes\n", TotalSendSize);
              if (TotalSendSize <= 0) {
                     NW->State = eNUOP - 1;
              }
              else {
                     int fd;
                     fd = open(ChrPtr(NW->tempFileName), 
                              O_EXCL|O_CREAT|O_NONBLOCK|O_WRONLY, 
                              S_IRUSR|S_IWUSR);
                     if (fd < 0)
                     {
                            EVN_syslog(LOG_CRIT,
                                   "cannot open %s: %s\n", 
                                   ChrPtr(NW->tempFileName), 
                                   strerror(errno));

                            NW->State = eQUIT - 1;
                            return eAbort;
                     }
                     FDIOBufferInit(&NW->IO.IOB, &NW->IO.RecvBuf, fd, TotalSendSize);
              }
              return eSendReply;
       }
       else
       {
              return eAbort;
       }
}

Here is the call graph for this function:

Definition at line 491 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();
       if (ChrPtr(NW->IO.IOBuf)[0] != '2') {
              FDIOBufferDelete(&IO->IOB);
              return eAbort;
       }
       return eSendReply;
}

Definition at line 578 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();

       return eAbort;
}

Definition at line 360 of file serv_networkclient.c.

{
       eNextState rc;
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();
       if (NW->IO.IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
       {
              NW->State ++;

              FDIOBufferDelete(&NW->IO.IOB);

              if (link(ChrPtr(NW->tempFileName), ChrPtr(NW->SpoolFileName)) != 0) {
                     EVN_syslog(LOG_ALERT, 
                            "Could not link %s to %s: %s\n",
                            ChrPtr(NW->tempFileName), 
                            ChrPtr(NW->SpoolFileName), 
                            strerror(errno));
              }
       
              unlink(ChrPtr(NW->tempFileName));
              rc = NWC_DispatchWriteDone(&NW->IO);
              NW->State --;
              return rc;
       }
       else {
              NW->State --;
              NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
              return eSendReply; //NWC_DispatchWriteDone(&NW->IO);
       }
}

Here is the call graph for this function:

Definition at line 391 of file serv_networkclient.c.

{
       eNextState rc;
       AsyncIO *IO = &NW->IO;
/* we don't have any data to debug print here. */
       if (NW->IO.IOB.TotalSentAlready >= NW->IO.IOB.TotalSendSize)
       {
              NW->State ++;

              FDIOBufferDelete(&NW->IO.IOB);
              if (link(ChrPtr(NW->tempFileName), ChrPtr(NW->SpoolFileName)) != 0) {
                     EVN_syslog(LOG_ALERT, 
                            "Could not link %s to %s: %s\n",
                            ChrPtr(NW->tempFileName), 
                            ChrPtr(NW->SpoolFileName), 
                            strerror(errno));
              }
       
              unlink(ChrPtr(NW->tempFileName));
              rc = NWC_DispatchWriteDone(&NW->IO);
              NW->State --;
              return rc;
       }
       else {
              NW->State --;
              NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
              return NWC_DispatchWriteDone(&NW->IO);
       }
}

Here is the call graph for this function:

Definition at line 346 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();
       if (ChrPtr(NW->IO.IOBuf)[0] == '6')
       {
              NW->IO.IOB.ChunkSendRemain = 
                     NW->IO.IOB.ChunkSize = atol(ChrPtr(NW->IO.IOBuf)+4);
              return eReadFile;
       }
       FDIOBufferDelete(&IO->IOB);
       return eAbort;
}
eReadState NWC_ReadServerStatus ( AsyncIO IO)

lineread Handler; understands when to read more POP3 lines, and when this is a one-lined reply.

Definition at line 718 of file serv_networkclient.c.

{
//     AsyncNetworker *NW = IO->Data;
       eReadState Finished = eBufferNotEmpty; 

       switch (IO->NextState) {
       case eSendDNSQuery:
       case eReadDNSReply:
       case eDBQuery:
       case eConnect:
       case eTerminateConnection:
       case eAbort:
              Finished = eReadFail;
              break;
       case eSendReply: 
       case eSendMore:
       case eReadMore:
       case eReadMessage: 
              Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
              break;
       case eReadFile:
       case eSendFile:
       case eReadPayload:
              break;
       }
       return Finished;
}

Here is the caller graph for this function:

Definition at line 555 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();

       EVN_syslog(LOG_NOTICE, "Sent %ld octets to <%s>\n", NW->IO.IOB.ChunkSize, ChrPtr(NW->node));
       if (ChrPtr(NW->IO.IOBuf)[0] == '2') {
              EVN_syslog(LOG_DEBUG, "Removing <%s>\n", ChrPtr(NW->SpoolFileName));
              unlink(ChrPtr(NW->SpoolFileName));
       }
       FDIOBufferDelete(&IO->IOB);
       return eSendReply;
}

Definition at line 510 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NWC_DBG_READ();
       if (ChrPtr(NW->IO.IOBuf)[0] != '7')
       {
              FDIOBufferDelete(&IO->IOB);
              return eAbort;
       }

       NW->IO.IOB.ChunkSendRemain = 
              NW->IO.IOB.ChunkSize = atol(ChrPtr(NW->IO.IOBuf)+4);
       return eSendFile;
}

Definition at line 209 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       /* We're talking to the correct node.  Now identify ourselves. */
       StrBufPrintf(NW->IO.SendBuf.Buf, "NETP %s|%s\n", 
                   config.c_nodename, 
                   ChrPtr(NW->secret));
       NWC_DBG_SEND();
       return eSendReply;
}

Definition at line 525 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       eNextState rc;
       if (NW->IO.IOB.TotalSentAlready >= IO->IOB.TotalSendSize)
       {
              NW->State ++;

              FDIOBufferDelete(&IO->IOB);
              rc =  NWC_DispatchWriteDone(IO);
              NW->State --;
              return rc;
       }
       else {
              NW->State --;
              IO->IOB.ChunkSendRemain = IO->IOB.ChunkSize;
              rc = NWC_DispatchWriteDone(IO);
              NW->State --;
              return rc;
       }
}

Here is the call graph for this function:

Definition at line 420 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       StrBufPlain(NW->IO.SendBuf.Buf, HKEY("CLOS\n"));
       NWC_DBG_SEND();
       return eSendReply;
}

Definition at line 242 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       NW->tempFileName = NewStrBuf();
       NW->SpoolFileName = NewStrBuf();
       StrBufPrintf(NW->SpoolFileName,
                   "%s/%s.%lx%x",
                   ctdl_netin_dir,
                   ChrPtr(NW->node),
                   time(NULL),// TODO: get time from libev
                   rand());
       StrBufStripSlashes(NW->SpoolFileName, 1);
       StrBufPrintf(NW->tempFileName, 
                   "%s/%s.%lx%x",
                   ctdl_nettmp_dir,
                   ChrPtr(NW->node),
                   time(NULL),// TODO: get time from libev
                   rand());
       StrBufStripSlashes(NW->tempFileName, 1);
       /* We're talking to the correct node.  Now identify ourselves. */
       StrBufPlain(NW->IO.SendBuf.Buf, HKEY("NDOP\n"));
       NWC_DBG_SEND();
       return eSendReply;
}

Definition at line 439 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       eNextState rc;
       long TotalSendSize;
       struct stat statbuf;
       int fd;

       StrBufPrintf(NW->SpoolFileName,
                   "%s/%s",
                   ctdl_netout_dir,
                   ChrPtr(NW->node));
       StrBufStripSlashes(NW->SpoolFileName, 1);

       fd = open(ChrPtr(NW->SpoolFileName), O_EXCL|O_NONBLOCK|O_RDONLY);
       if (fd < 0) {
              if (errno != ENOENT) {
                     EVN_syslog(LOG_CRIT,
                            "cannot open %s: %s\n", 
                            ChrPtr(NW->SpoolFileName), 
                            strerror(errno));
              }
              NW->State = eQUIT;
              rc = NWC_SendQUIT(NW);
              NWC_DBG_SEND();
              return rc;
       }

       if (fstat(fd, &statbuf) == -1) {
              EVN_syslog(LOG_CRIT, "FSTAT FAILED %s [%s]--\n", 
                        ChrPtr(NW->SpoolFileName), 
                        strerror(errno));
              if (fd > 0) close(fd);
              return eAbort;
       }
       TotalSendSize = statbuf.st_size;
       if (TotalSendSize == 0) {
              EVNM_syslog(LOG_DEBUG,
                     "Nothing to send.\n");
              NW->State = eQUIT;
              rc = NWC_SendQUIT(NW);
              NWC_DBG_SEND();
              if (fd > 0) close(fd);
              return rc;
       }
       FDIOBufferInit(&NW->IO.IOB, &NW->IO.SendBuf, fd, TotalSendSize);

       StrBufPlain(NW->IO.SendBuf.Buf, HKEY("NUOP\n"));
       NWC_DBG_SEND();
       return eSendReply;

}

Here is the call graph for this function:

Definition at line 569 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       StrBufPlain(NW->IO.SendBuf.Buf, HKEY("QUIT\n"));

       NWC_DBG_SEND();
       return eSendReply;
}

Here is the caller graph for this function:

Definition at line 306 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       eNextState rc;

       if (NW->IO.IOB.TotalSentAlready < NW->IO.IOB.TotalSendSize)
       {
              /*
               * If shutting down we can exit here and unlink the temp file.
               * this shouldn't loose us any messages.
               */
              if (server_shutting_down)
              {
                     FDIOBufferDelete(&NW->IO.IOB);
                     unlink(ChrPtr(NW->tempFileName));
                     FDIOBufferDelete(&IO->IOB);
                     return eAbort;
              }
              StrBufPrintf(NW->IO.SendBuf.Buf, "READ %ld|%ld\n",
                          NW->IO.IOB.TotalSentAlready,
                          NW->IO.IOB.TotalSendSize);
/*
                          ((NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready > IGNET_PACKET_SIZE)
                           ? IGNET_PACKET_SIZE : 
                           (NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready))
                     );
*/
              NWC_DBG_SEND();
              return eSendReply;
       }
       else 
       {
              NW->State = eCLOS;
              rc = NWC_DispatchWriteDone(&NW->IO);
              NWC_DBG_SEND();

              return rc;
       }
}

Here is the call graph for this function:

Definition at line 547 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       StrBufPlain(NW->IO.SendBuf.Buf, HKEY("UCLS 1\n"));
       NWC_DBG_SEND();
       return eSendReply;

}

Definition at line 502 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       StrBufPrintf(NW->IO.SendBuf.Buf, "WRIT %ld\n", 
                   NW->IO.IOB.TotalSendSize - NW->IO.IOB.TotalSentAlready);
       NWC_DBG_SEND();
       return eSendReply;
}
void NWC_SetTimeout ( eNextState  NextTCPState,
AsyncNetworker NW 
)

Definition at line 753 of file serv_networkclient.c.

{
       AsyncIO *IO = &NW->IO;
       double Timeout = 0.0;

       EVN_syslog(LOG_DEBUG, "%s - %d\n", __FUNCTION__, NextTCPState);

       switch (NextTCPState) {
       case eSendReply:
       case eSendMore:
              break;
       case eReadFile:
       case eReadMessage:
              Timeout = NWC_ReadTimeouts[NW->State];
              break;
       case eReadPayload:
              Timeout = 100000;
              /* TODO!!! */
              break;
       case eSendDNSQuery:
       case eReadDNSReply:
       case eConnect:
       case eSendFile:
//TODO
       case eTerminateConnection:
       case eDBQuery:
       case eAbort:
       case eReadMore:
              return;
       }
       if (Timeout > 0) {
              EVN_syslog(LOG_DEBUG, 
                        "%s - %d %f\n",
                        __FUNCTION__,
                        NextTCPState,
                        Timeout);
              SetNextTimeout(&NW->IO, Timeout*100);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 866 of file serv_networkclient.c.

{
       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);

       FinalizeNetworker(IO);
       return eAbort;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 820 of file serv_networkclient.c.

{
       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
       FinalizeNetworker(IO);
       return eAbort;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 827 of file serv_networkclient.c.

{
       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
       FinalizeNetworker(IO);
       return eAbort;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 834 of file serv_networkclient.c.

{
       AsyncNetworker *NW = IO->Data;
       EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);

       if (NW->IO.ErrMsg == NULL)
              NW->IO.ErrMsg = NewStrBuf();
       StrBufPrintf(NW->IO.ErrMsg, "Timeout while talking to %s \r\n", ChrPtr(NW->host));
       return NWC_FailNetworkConnection(IO);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void RunNetworker ( AsyncNetworker NW)

Definition at line 892 of file serv_networkclient.c.

{
       NW->n = NetworkerCount++;
       network_talking_to(SKEY(NW->node), NTT_ADD);
       syslog(LOG_DEBUG, "NW[%s][%ld]: polling\n", ChrPtr(NW->node), NW->n);
       ParseURL(&NW->IO.ConnectMe, NW->Url, 504);

       InitIOStruct(&NW->IO,
                   NW,
                   eReadMessage,
                   NWC_ReadServerStatus,
                   NWC_DNSFail,
                   NWC_DispatchWriteDone,
                   NWC_DispatchReadDone,
                   NWC_Terminate,
                   NWC_TerminateDB,
                   NWC_ConnFail,
                   NWC_Timeout,
                   NWC_Shutdown);

       safestrncpy(((CitContext *)NW->IO.CitContext)->cs_host, 
                  ChrPtr(NW->host),
                  sizeof(((CitContext *)NW->IO.CitContext)->cs_host)); 

       if (NW->IO.ConnectMe->IsIP) {
              QueueEventContext(&NW->IO,
                              nwc_connect_ip);
       }
       else { /* uneducated admin has chosen to add DNS to the equation... */
              QueueEventContext(&NW->IO,
                              nwc_get_one_host_ip);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 94 of file serv_networkclient.c.

int NetworkerCount = 0 [static]

Definition at line 891 of file serv_networkclient.c.

const ConstStr NWC[]
Initial value:
 {
       {HKEY("Connection broken during ")},
       {HKEY("Connection broken during ")},
       {HKEY("Connection broken during ")},
       {HKEY("Connection broken during ")},
       {HKEY("Connection broken during ")},
       {HKEY("Connection broken during ")},
       {HKEY("Connection broken during ")},
       {HKEY("Connection broken during ")}
}

Definition at line 612 of file serv_networkclient.c.

long NWC_ConnTimeout = 100

Definition at line 600 of file serv_networkclient.c.

const long NWC_ReadTimeouts[]
Initial value:
 {
       100,
       100,
       100,
       100,
       100,
       100,
       100,
       100,
       100,
       100
}

Definition at line 637 of file serv_networkclient.c.

const long NWC_SendTimeouts[]
Initial value:
 {
       100,
       100,
       100,
       100,
       100,
       100,
       100,
       100
}

Definition at line 602 of file serv_networkclient.c.