X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fevent_client.h;h=828ee0cb5a236b3fe073444dd7234232846e81c3;hb=192056a6112602350c1f8a73eae2e134a31c7ba2;hp=4bd86bd9f52171e8b6a5742ad0503a6a467232a8;hpb=38a230bb609bfee1103ccb21111171dd56b96b6f;p=citadel.git diff --git a/citadel/event_client.h b/citadel/event_client.h index 4bd86bd9f..828ee0cb5 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -1,16 +1,32 @@ +#ifndef __EVENT_CLIENT_H__ +#define __EVENT_CLIENT_H__ +#define EV_COMPAT3 0 #include #include #include #include #include #include +#include typedef struct AsyncIO AsyncIO; typedef enum _eNextState { + eSendDNSQuery, + eReadDNSReply, + + eDBQuery, + + eConnect, eSendReply, eSendMore, + eSendFile, + eReadMessage, + eReadMore, + eReadPayload, + eReadFile, + eTerminateConnection, eAbort }eNextState; @@ -20,6 +36,21 @@ typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO); typedef void (*ParseDNSAnswerCb)(AsyncIO*, unsigned char*, int); typedef void (*FreeDNSReply)(void *DNSData); + +typedef struct __ReadAsyncMsg { + StrBuf *MsgBuf; + size_t maxlen; /* maximum message length */ + + const char *terminator; /* token signalling EOT */ + long tlen; + int dodot; + + int flushing; /* if we read maxlen, read until nothing more arives and ignore this. */ + + int crlf; /* CRLF newlines instead of LF */ +} ReadAsyncMsg; + + typedef struct _DNSQueryParts { ParseDNSAnswerCb DNS_CB; IO_CallBack PostDNS; @@ -30,58 +61,77 @@ typedef struct _DNSQueryParts { void *Data; } DNSQueryParts; +typedef struct _evcurl_request_data +{ + CURL *chnd; + struct curl_slist *headers; + char errdesc[CURL_ERROR_SIZE]; -struct AsyncIO { - StrBuf *Host; - char service[32]; + int attached; - /* To cycle through several possible services... * / - struct addrinfo *res; - struct addrinfo *curr_ai; - */ + char *PlainPostData; + long PlainPostDataLen; + StrBuf *PostData; - /* connection related */ - int IP6; - struct sockaddr_in6 *Addr; + StrBuf *ReplyData; + long httpcode; +} evcurl_request_data; - int sock; - unsigned short dport; +struct AsyncIO { eNextState NextState; - - ev_cleanup abort_by_shutdown; - - ev_timer conn_fail, - rw_timeout; - ev_idle unwind_stack; - ev_io recv_event, - send_event, - conn_event; - StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */ + /* connection related */ + ParsedURL *ConnectMe; + /* read/send related... */ StrBuf *IOBuf; IOBuffer SendBuf, RecvBuf; + FDIOBuffer IOB; /* when sending from / reading into files, this is used. */ + + /* our events... */ + ev_cleanup abort_by_shutdown, /* server wants to go down... */ + db_abort_by_shutdown; /* server wants to go down... */ + ev_timer conn_fail, /* connection establishing timed out */ + rw_timeout; /* timeout while sending data */ + ev_idle unwind_stack, /* get c-ares out of the stack */ + db_unwind_stack, /* wait for next db operation... */ + conn_fail_immediate; /* unwind stack, but fail immediately. */ + ev_io recv_event, /* receive data from the client */ + send_event, /* send more data to the client */ + conn_event; /* Connection successfully established */ + + StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */ + /* Citadel application callbacks... */ IO_CallBack ReadDone, /* Theres new data to read... */ SendDone, /* we may send more data */ Terminate, /* shutting down... */ Timeout, /* Timeout handler; may also be connection timeout */ ConnFail, /* What to do when one connection failed? */ - ShutdownAbort;/* we're going down. make your piece. */ + DNSFail, /* the dns lookup didn't work out. */ + ShutdownAbort,/* we're going down. make your piece. */ + NextDBOperation; /* Perform Database IO */ IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */ + /* DNS Related */ ev_io dns_recv_event, dns_send_event; struct ares_options DNSOptions; ares_channel DNSChannel; DNSQueryParts *DNSQuery; + + evcurl_request_data HttpReq; + /* Saving / loading a message async from / to disk */ + ReadAsyncMsg *ReadMsg; + struct CtdlMessage *AsyncMsg; + struct recptypes *AsyncRcp; /* Custom data; its expected to contain AsyncIO so we can save malloc()s... */ - DeleteHashDataFunc DeleteData; /* so if we have to destroy you, what to do... */ - void *Data; /* application specific data */ + void *Data; /* application specific data */ + void *CitContext; /* Citadel Session context... */ }; typedef struct _IOAddHandler { @@ -91,7 +141,10 @@ typedef struct _IOAddHandler { void FreeAsyncIOContents(AsyncIO *IO); -int QueueEventContext(AsyncIO *IO, IO_CallBack CB); +eNextState NextDBOperation(AsyncIO *IO, IO_CallBack CB); +eNextState QueueDBOperation(AsyncIO *IO, IO_CallBack CB); +eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB); +eNextState QueueCurlContext(AsyncIO *IO); int ShutDownEventQueue(void); eNextState InitEventIO(AsyncIO *IO, @@ -108,6 +161,30 @@ void QueryCbDone(AsyncIO *IO); void StopClient(AsyncIO *IO); +void StopClientWatchers(AsyncIO *IO); + void SetNextTimeout(AsyncIO *IO, double timeout); void InitC_ares_dns(AsyncIO *IO); + +#include + +#define OPT(s, v) \ + do { \ + sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \ + if (sta) { \ + syslog(LOG_ERR, "error setting option " #s " on curl handle: %s", curl_easy_strerror(sta)); \ + } } while (0) + + +int evcurl_init(AsyncIO *IO, + void *CustomData, + const char* Desc, + IO_CallBack CallBack, + IO_CallBack Terminate); + +eNextState ReAttachIO(AsyncIO *IO, + void *pData, + int ReadFirst); + +#endif /* __EVENT_CLIENT_H__ */