3 #include <sys/socket.h>
5 #include <arpa/nameser.h>
9 typedef struct AsyncIO AsyncIO;
11 typedef enum _eNextState {
22 typedef eNextState (*IO_CallBack)(AsyncIO *IO);
23 typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO);
24 typedef void (*ParseDNSAnswerCb)(AsyncIO*, unsigned char*, int);
25 typedef void (*FreeDNSReply)(void *DNSData);
27 typedef struct _DNSQueryParts {
28 ParseDNSAnswerCb DNS_CB;
32 void *VParsedDNSReply;
33 FreeDNSReply DNSReplyFree;
37 typedef struct _evcurl_request_data
40 struct curl_slist *headers;
41 char errdesc[CURL_ERROR_SIZE];
46 long PlainPostDataLen;
51 } evcurl_request_data;
56 /* connection related */
59 /* read/send related... */
65 ev_cleanup abort_by_shutdown; /* server wants to go down... */
66 ev_timer conn_fail, /* connection establishing timed out */
67 rw_timeout; /* timeout while sending data */
68 ev_idle unwind_stack, /* get c-ares out of the stack */
69 conn_fail_immediate; /* unwind stack, but fail immediately. */
70 ev_io recv_event, /* receive data from the client */
71 send_event, /* send more data to the client */
72 conn_event; /* Connection successfully established */
74 StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
76 /* Citadel application callbacks... */
77 IO_CallBack ReadDone, /* Theres new data to read... */
78 SendDone, /* we may send more data */
79 Terminate, /* shutting down... */
80 Timeout, /* Timeout handler; may also be connection timeout */
81 ConnFail, /* What to do when one connection failed? */
82 ShutdownAbort;/* we're going down. make your piece. */
84 IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
89 struct ares_options DNSOptions;
90 ares_channel DNSChannel;
91 DNSQueryParts *DNSQuery;
93 evcurl_request_data HttpReq;
95 /* Saving / loading a message async from / to disk */
97 struct CtdlMessage *AsyncMsg;
98 struct recptypes AsyncRcp;
99 /* Custom data; its expected to contain AsyncIO so we can save malloc()s... */
100 void *Data; /* application specific data */
101 void *CitContext; /* Citadel Session context... */
104 typedef struct _IOAddHandler {
109 void FreeAsyncIOContents(AsyncIO *IO);
111 int QueueEventContext(AsyncIO *IO, IO_CallBack CB);
112 int ShutDownEventQueue(void);
114 eNextState InitEventIO(AsyncIO *IO,
117 double first_rw_timeout,
119 void IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents);
121 int QueueQuery(ns_type Type, const char *name, AsyncIO *IO, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
122 void QueueGetHostByName(AsyncIO *IO, const char *Hostname, DNSQueryParts *QueryParts, IO_CallBack PostDNS);
124 void QueryCbDone(AsyncIO *IO);
126 void StopClient(AsyncIO *IO);
128 void StopClientWatchers(AsyncIO *IO);
130 void SetNextTimeout(AsyncIO *IO, double timeout);
132 void InitC_ares_dns(AsyncIO *IO);
134 #include <curl/curl.h>
138 sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \
140 CtdlLogPrintf(CTDL_ERR, "error setting option " #s " on curl handle: %s", curl_easy_strerror(sta)); \
144 int evcurl_init(AsyncIO *IO,
147 IO_CallBack CallBack);
149 void evcurl_handle_start(AsyncIO *IO);