#include <netdb.h>
#include <arpa/nameser.h>
#include <ares.h>
+#include <curl/curl.h>
typedef struct AsyncIO AsyncIO;
typedef enum _eNextState {
+ eSendDNSQuery,
+ eReadDNSReply,
+ eConnect,
eSendReply,
eSendMore,
eReadMessage,
void *Data;
} DNSQueryParts;
+typedef struct _evcurl_request_data
+{
+ CURL *chnd;
+ struct curl_slist *headers;
+ char errdesc[CURL_ERROR_SIZE];
+
+ int attached;
+
+ char *PlainPostData;
+ long PlainPostDataLen;
+ StrBuf *PostData;
+
+ StrBuf *ReplyData;
+ long httpcode;
+} evcurl_request_data;
struct AsyncIO {
+ eNextState NextState;
/* connection related */
ParsedURL *ConnectMe;
-/*
- int IP6;
- struct sockaddr_in6 *Addr;
- unsigned short dport;
-
-*/
- int sock;
- 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. */
-
/* read/send related... */
StrBuf *IOBuf;
IOBuffer SendBuf,
RecvBuf;
+ /* our events... */
+ ev_cleanup 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 */
+ 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 */
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;
/* 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 {
void StopClient(AsyncIO *IO);
+void StopClientWatchers(AsyncIO *IO);
+
void SetNextTimeout(AsyncIO *IO, double timeout);
void InitC_ares_dns(AsyncIO *IO);
+
+#include <curl/curl.h>
+
+#define OPT(s, v) \
+ do { \
+ sta = curl_easy_setopt(chnd, (CURLOPT_##s), (v)); \
+ if (sta) { \
+ CtdlLogPrintf(CTDL_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);
+
+void evcurl_handle_start(AsyncIO *IO);