4 #include <sys/socket.h>
6 #include <arpa/nameser.h>
10 typedef struct AsyncIO AsyncIO;
12 typedef enum _eNextState {
23 typedef eNextState (*IO_CallBack)(AsyncIO *IO);
24 typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO);
25 typedef void (*ParseDNSAnswerCb)(AsyncIO*, unsigned char*, int);
26 typedef void (*FreeDNSReply)(void *DNSData);
28 typedef struct _DNSQueryParts {
29 ParseDNSAnswerCb DNS_CB;
33 void *VParsedDNSReply;
34 FreeDNSReply DNSReplyFree;
38 typedef struct _evcurl_request_data
41 struct curl_slist *headers;
42 char errdesc[CURL_ERROR_SIZE];
47 long PlainPostDataLen;
52 } evcurl_request_data;
57 /* connection related */
60 /* read/send related... */
66 ev_cleanup abort_by_shutdown; /* server wants to go down... */
67 ev_timer conn_fail, /* connection establishing timed out */
68 rw_timeout; /* timeout while sending data */
69 ev_idle unwind_stack, /* get c-ares out of the stack */
70 conn_fail_immediate; /* unwind stack, but fail immediately. */
71 ev_io recv_event, /* receive data from the client */
72 send_event, /* send more data to the client */
73 conn_event; /* Connection successfully established */
75 StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
77 /* Citadel application callbacks... */
78 IO_CallBack ReadDone, /* Theres new data to read... */
79 SendDone, /* we may send more data */
80 Terminate, /* shutting down... */
81 Timeout, /* Timeout handler; may also be connection timeout */
82 ConnFail, /* What to do when one connection failed? */
83 ShutdownAbort;/* we're going down. make your piece. */
85 IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
90 struct ares_options DNSOptions;
91 ares_channel DNSChannel;
92 DNSQueryParts *DNSQuery;
94 evcurl_request_data HttpReq;
96 /* Saving / loading a message async from / to disk */
98 struct CtdlMessage *AsyncMsg;
99 struct recptypes *AsyncRcp;
100 /* Custom data; its expected to contain AsyncIO so we can save malloc()s... */
101 void *Data; /* application specific data */
102 void *CitContext; /* Citadel Session context... */
105 typedef struct _IOAddHandler {
110 void FreeAsyncIOContents(AsyncIO *IO);
112 void NextDBOperation(AsyncIO *IO, IO_CallBack CB);
113 int QueueDBOperation(AsyncIO *IO, IO_CallBack CB);
114 int QueueEventContext(AsyncIO *IO, IO_CallBack CB);
115 int ShutDownEventQueue(void);
117 eNextState InitEventIO(AsyncIO *IO,
120 double first_rw_timeout,
122 void IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents);
124 int QueueQuery(ns_type Type, const char *name, AsyncIO *IO, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
125 void QueueGetHostByName(AsyncIO *IO, const char *Hostname, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
127 void QueryCbDone(AsyncIO *IO);
129 void StopClient(AsyncIO *IO);
131 void StopClientWatchers(AsyncIO *IO);
133 void SetNextTimeout(AsyncIO *IO, double timeout);
135 void InitC_ares_dns(AsyncIO *IO);
137 #include <curl/curl.h>
141 sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \
143 CtdlLogPrintf(CTDL_ERR, "error setting option " #s " on curl handle: %s", curl_easy_strerror(sta)); \
147 int evcurl_init(AsyncIO *IO,
150 IO_CallBack CallBack);
152 void evcurl_handle_start(AsyncIO *IO);