]> code.citadel.org Git - citadel.git/blobdiff - citadel/event_client.h
finish rewriting of http client code
[citadel.git] / citadel / event_client.h
index 57d9204074b612ed4de2889e7ede7c92c4dbf8e1..49d1159783ba1a50380e9485a932d27adb012dea 100644 (file)
@@ -4,10 +4,14 @@
 #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, 
@@ -30,38 +34,44 @@ 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;
 
+       /* 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 */
+       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 */
@@ -72,15 +82,18 @@ struct AsyncIO {
 
        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 {
@@ -107,6 +120,25 @@ 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 <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);