1 #ifndef __EVENT_CLIENT_H__
2 #define __EVENT_CLIENT_H__
6 #include <sys/socket.h>
8 #include <arpa/nameser.h>
10 #include <curl/curl.h>
12 typedef struct AsyncIO AsyncIO;
14 typedef enum _eNextState {
26 typedef eNextState (*IO_CallBack)(AsyncIO *IO);
27 typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO);
28 typedef void (*ParseDNSAnswerCb)(AsyncIO*, unsigned char*, int);
29 typedef void (*FreeDNSReply)(void *DNSData);
31 typedef struct _DNSQueryParts {
32 ParseDNSAnswerCb DNS_CB;
36 void *VParsedDNSReply;
37 FreeDNSReply DNSReplyFree;
41 typedef struct _evcurl_request_data
44 struct curl_slist *headers;
45 char errdesc[CURL_ERROR_SIZE];
50 long PlainPostDataLen;
55 } evcurl_request_data;
60 /* connection related */
63 /* read/send related... */
69 ev_cleanup abort_by_shutdown; /* server wants to go down... */
70 ev_timer conn_fail, /* connection establishing timed out */
71 rw_timeout; /* timeout while sending data */
72 ev_idle unwind_stack, /* get c-ares out of the stack */
73 conn_fail_immediate; /* unwind stack, but fail immediately. */
74 ev_io recv_event, /* receive data from the client */
75 send_event, /* send more data to the client */
76 conn_event; /* Connection successfully established */
78 StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
80 /* Citadel application callbacks... */
81 IO_CallBack ReadDone, /* Theres new data to read... */
82 SendDone, /* we may send more data */
83 Terminate, /* shutting down... */
84 Timeout, /* Timeout handler; may also be connection timeout */
85 ConnFail, /* What to do when one connection failed? */
86 ShutdownAbort;/* we're going down. make your piece. */
88 IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
93 struct ares_options DNSOptions;
94 ares_channel DNSChannel;
95 DNSQueryParts *DNSQuery;
97 evcurl_request_data HttpReq;
99 /* Saving / loading a message async from / to disk */
101 struct CtdlMessage *AsyncMsg;
102 struct recptypes *AsyncRcp;
103 /* Custom data; its expected to contain AsyncIO so we can save malloc()s... */
104 void *Data; /* application specific data */
105 void *CitContext; /* Citadel Session context... */
108 typedef struct _IOAddHandler {
113 void FreeAsyncIOContents(AsyncIO *IO);
115 void NextDBOperation(AsyncIO *IO, IO_CallBack CB);
116 int QueueDBOperation(AsyncIO *IO, IO_CallBack CB);
117 int QueueEventContext(AsyncIO *IO, IO_CallBack CB);
118 int ShutDownEventQueue(void);
120 eNextState InitEventIO(AsyncIO *IO,
123 double first_rw_timeout,
125 void IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents);
127 int QueueQuery(ns_type Type, const char *name, AsyncIO *IO, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
128 void QueueGetHostByName(AsyncIO *IO, const char *Hostname, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
130 void QueryCbDone(AsyncIO *IO);
132 void StopClient(AsyncIO *IO);
134 void StopClientWatchers(AsyncIO *IO);
136 void SetNextTimeout(AsyncIO *IO, double timeout);
138 void InitC_ares_dns(AsyncIO *IO);
140 #include <curl/curl.h>
144 sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \
146 CtdlLogPrintf(CTDL_ERR, "error setting option " #s " on curl handle: %s", curl_easy_strerror(sta)); \
150 int evcurl_init(AsyncIO *IO,
153 IO_CallBack CallBack,
154 IO_CallBack Terminate);
156 void evcurl_handle_start(AsyncIO *IO);
158 #endif /* __EVENT_CLIENT_H__ */