]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/extnotify/funambol65.c
Migrate http context struct into the AsyncIO struct; streamline other structs.
[citadel.git] / citadel / modules / extnotify / funambol65.c
index 0e88c91ff4881c8013f4a16acee8f1ae9f4145d9..628eaf82add590eaa13324e1023ae7efb39c8769 100644 (file)
@@ -44,6 +44,7 @@
 #include "msgbase.h"
 #include "ctdl_module.h"
 
+#include "event_client.h"
 #include "extnotify.h"
 
 /*
@@ -66,6 +67,7 @@ int notify_http_server(char *remoteurl,
        StrBuf *ReplyBuf;
        CURL *chnd;
 
+       snprintf(msgnumstr, 128, "%ld", MsgNum);
 
        if (tlen > 0) {
                /* Load the template message. Get mallocs done too */
@@ -86,8 +88,6 @@ int notify_http_server(char *remoteurl,
                }
                mimetype = GuessMimeByFilename(template, tlen);
 
-               snprintf(msgnumstr, 128, "%ld", MsgNum);
-
                buf = malloc(SIZ);
                memset(buf, 0, SIZ);
                SOAPMessage = malloc(3072);
@@ -120,28 +120,28 @@ int notify_http_server(char *remoteurl,
                contenttype=(char*) malloc(40+strlen(mimetype));
                sprintf(contenttype,"Content-Type: %s; charset=utf-8", mimetype);
 
-               Ctx->HTTPData.headers = curl_slist_append(Ctx->HTTPData.headers, "SOAPAction: \"\"");
-               Ctx->HTTPData.headers = curl_slist_append(Ctx->HTTPData.headers, contenttype);
-               Ctx->HTTPData.headers = curl_slist_append(Ctx->HTTPData.headers, "Accept: application/soap+xml, application/mime, multipart/related, text/*");
-               Ctx->HTTPData.headers = curl_slist_append(Ctx->HTTPData.headers, "Pragma: no-cache");
+               Ctx->IO.HttpReq.headers = curl_slist_append(Ctx->IO.HttpReq.headers, "SOAPAction: \"\"");
+               Ctx->IO.HttpReq.headers = curl_slist_append(Ctx->IO.HttpReq.headers, contenttype);
+               Ctx->IO.HttpReq.headers = curl_slist_append(Ctx->IO.HttpReq.headers, "Accept: application/soap+xml, application/mime, multipart/related, text/*");
+               Ctx->IO.HttpReq.headers = curl_slist_append(Ctx->IO.HttpReq.headers, "Pragma: no-cache");
 
                /* Now specify the POST binary data */
-               Ctx->HTTPData.PlainPostData = SOAPMessage;
-               Ctx->HTTPData.PlainPostDataLen = strlen(SOAPMessage);
+               Ctx->IO.HttpReq.PlainPostData = SOAPMessage;
+               Ctx->IO.HttpReq.PlainPostDataLen = strlen(SOAPMessage);
        }
        else {
                help_subst(remoteurl, "^notifyuser", user);
                help_subst(remoteurl, "^syncsource", config.c_funambol_source);
                help_subst(remoteurl, "^msgid", msgid);
                help_subst(remoteurl, "^msgnum", msgnumstr);
-               Ctx->HTTPData.headers = curl_slist_append(Ctx->HTTPData.headers, "Accept: application/soap+xml, application/mime, multipart/related, text/*");
-               Ctx->HTTPData.headers = curl_slist_append(Ctx->HTTPData.headers, "Pragma: no-cache");
+               Ctx->IO.HttpReq.headers = curl_slist_append(Ctx->IO.HttpReq.headers, "Accept: application/soap+xml, application/mime, multipart/related, text/*");
+               Ctx->IO.HttpReq.headers = curl_slist_append(Ctx->IO.HttpReq.headers, "Pragma: no-cache");
        }
 
-       ParseURL(&Ctx->HTTPData.URL, NewStrBufPlain (remoteurl, -1), 80);
-       CurlPrepareURL(Ctx->HTTPData.URL);
+       ParseURL(&Ctx->IO.ConnectMe, NewStrBufPlain (remoteurl, -1), 80);
+       CurlPrepareURL(Ctx->IO.ConnectMe);
        int CallBack;
-       if (! evcurl_init(&Ctx->HTTPData
+       if (! evcurl_init(&Ctx->IO
                          Ctx, 
                          "Citadel ExtNotify",
                          CallBack))
@@ -149,7 +149,7 @@ int notify_http_server(char *remoteurl,
                CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
                goto abort;
        }
-       chnd = Ctx->HTTPData.chnd;
+       chnd = Ctx->IO.HttpReq.chnd;
        OPT(SSL_VERIFYPEER, 0);
        OPT(SSL_VERIFYHOST, 0);
 /*
@@ -166,7 +166,7 @@ int notify_http_server(char *remoteurl,
                OPT(INTERFACE, config.c_ip_addr);
        }
 
-       evcurl_handle_start(&Ctx->HTTPData);
+       evcurl_handle_start(&Ctx->IO);
 
        return 0;
 abort:
@@ -188,24 +188,24 @@ int EvaluateResult(NotifyContext *Ctx, int res, int b)
 
                CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", 
                              res, 
-                             Ctx->HTTPData.errdesc);
+                             Ctx->IO.HttpReq.errdesc);
                ErrMsg = NewStrBufPlain(HKEY("Error sending your Notification\n"));
                StrBufAppendPrintf(ErrMsg, "\nlibcurl error %d: %s\n", 
                                   res, 
-                                  Ctx->HTTPData.errdesc);
+                                  Ctx->IO.HttpReq.errdesc);
 ///            StrBufAppendBufPlain(ErrMsg, curl_errbuf, -1, 0);
                StrBufAppendBufPlain(ErrMsg, HKEY("\nWas Trying to send: \n"), 0);
-               StrBufAppendBufPlain(ErrMsg, Ctx->HTTPData.URL->PlainUrl, -1, 0);
-               if (Ctx->HTTPData.PlainPostDataLen > 0) {
+               StrBufAppendBufPlain(ErrMsg, Ctx->IO.ConnectMe->PlainUrl, -1, 0);
+               if (Ctx->IO.HttpReq.PlainPostDataLen > 0) {
                        StrBufAppendBufPlain(ErrMsg, HKEY("\nThe Post document was: \n"), 0);
                        StrBufAppendBufPlain(ErrMsg, 
-                                            Ctx->HTTPData.PlainPostData, 
-                                            Ctx->HTTPData.PlainPostDataLen, 0);
+                                            Ctx->IO.HttpReq.PlainPostData, 
+                                            Ctx->IO.HttpReq.PlainPostDataLen, 0);
                        StrBufAppendBufPlain(ErrMsg, HKEY("\n\n"), 0);                  
                }
-               if (StrLength(Ctx->HTTPData.ReplyData) > 0) {                   
+               if (StrLength(Ctx->IO.HttpReq.ReplyData) > 0) {                 
                        StrBufAppendBufPlain(ErrMsg, HKEY("\n\nThe Serverreply was: \n\n"), 0);
-                       StrBufAppendBuf(ErrMsg, Ctx->HTTPData.ReplyData, 0);
+                       StrBufAppendBuf(ErrMsg, Ctx->IO.HttpReq.ReplyData, 0);
                }
                else 
                        StrBufAppendBufPlain(ErrMsg, HKEY("\n\nThere was no Serverreply.\n\n"), 0);
@@ -214,6 +214,30 @@ int EvaluateResult(NotifyContext *Ctx, int res, int b)
        }
 
        CtdlLogPrintf(CTDL_DEBUG, "Funambol notified\n");
+/*
+       while ((Ctx.NotifyHostList != NULL) && (Ctx.NotifyHostList[i] != NULL))
+               FreeStrBuf(&Ctx.NotifyHostList[i]);
+
+       if (Ctx.NotifyErrors != NULL)
+       {
+               long len;
+               const char *Key;
+               HashPos *It;
+               void *vErr;
+               StrBuf *ErrMsg;
+
+               It = GetNewHashPos(Ctx.NotifyErrors, 0);
+               while (GetNextHashPos(Ctx.NotifyErrors, It, &len, &Key, &vErr) && 
+                      (vErr != NULL)) {
+                       ErrMsg = (StrBuf*) vErr;
+                       quickie_message("Citadel", NULL, NULL, AIDEROOM, ChrPtr(ErrMsg), FMT_FIXED, 
+                                       "Failed to notify external service about inbound mail");
+               }
+
+               DeleteHashPos(&It);
+               DeleteHash(&Ctx.NotifyErrors);
+       }
+*/
 
 ////   curl_slist_free_all (headers);
 ///    curl_easy_cleanup(curl);