#include "event_client.h"
#include "extnotify.h"
+eNextState EvaluateResult(AsyncIO *IO);
+
/*
* \brief Sends a message to the Funambol server notifying
* of new mail for a user
char *contenttype = NULL;
StrBuf *ReplyBuf;
CURL *chnd;
+ AsyncIO *IO;
+
+ IO = (AsyncIO*) malloc(sizeof(AsyncIO));
+ memset(IO, 0, sizeof(AsyncIO));
+ IO->CitContext = CC;
snprintf(msgnumstr, 128, "%ld", MsgNum);
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");
+ IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers, "SOAPAction: \"\"");
+ IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers, contenttype);
+ IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers, "Accept: application/soap+xml, application/mime, multipart/related, text/*");
+ IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers, "Pragma: no-cache");
/* Now specify the POST binary data */
- Ctx->HTTPData.PlainPostData = SOAPMessage;
- Ctx->HTTPData.PlainPostDataLen = strlen(SOAPMessage);
+ IO->HttpReq.PlainPostData = SOAPMessage;
+ 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");
+ IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers, "Accept: application/soap+xml, application/mime, multipart/related, text/*");
+ IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers, "Pragma: no-cache");
}
- ParseURL(&Ctx->HTTPData.URL, NewStrBufPlain (remoteurl, -1), 80);
- CurlPrepareURL(Ctx->HTTPData.URL);
- int CallBack;
- if (! evcurl_init(&Ctx->HTTPData,
- Ctx,
+ ParseURL(&IO->ConnectMe, NewStrBufPlain (remoteurl, -1), 80);
+ CurlPrepareURL(IO->ConnectMe);
+ if (! evcurl_init(IO,
+// Ctx,
+ NULL,
"Citadel ExtNotify",
- CallBack))
+ EvaluateResult))
{
CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
goto abort;
}
- chnd = Ctx->HTTPData.chnd;
+ chnd = IO->HttpReq.chnd;
OPT(SSL_VERIFYPEER, 0);
OPT(SSL_VERIFYHOST, 0);
/*
OPT(INTERFACE, config.c_ip_addr);
}
- evcurl_handle_start(&Ctx->HTTPData);
+ evcurl_handle_start(IO);
return 0;
abort:
}
-
-int EvaluateResult(NotifyContext *Ctx, int res, int b)
+eNextState EvaluateResult(AsyncIO *IO)
{
- if (res) {
+
+ if (IO->HttpReq.httpcode != 200) {
StrBuf *ErrMsg;
- CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n",
- res,
- Ctx->HTTPData.errdesc);
+ CtdlLogPrintf(CTDL_ALERT, "libcurl error %ld: %s\n",
+ IO->HttpReq.httpcode,
+ IO->HttpReq.errdesc);
ErrMsg = NewStrBufPlain(HKEY("Error sending your Notification\n"));
- StrBufAppendPrintf(ErrMsg, "\nlibcurl error %d: %s\n",
- res,
- Ctx->HTTPData.errdesc);
-/// StrBufAppendBufPlain(ErrMsg, curl_errbuf, -1, 0);
+ StrBufAppendPrintf(ErrMsg, "\nlibcurl error %ld: \n\t\t%s\n",
+ IO->HttpReq.httpcode,
+ IO->HttpReq.errdesc);
StrBufAppendBufPlain(ErrMsg, HKEY("\nWas Trying to send: \n"), 0);
- StrBufAppendBufPlain(ErrMsg, Ctx->HTTPData.URL->PlainUrl, -1, 0);
- if (Ctx->HTTPData.PlainPostDataLen > 0) {
+ StrBufAppendBufPlain(ErrMsg, IO->ConnectMe->PlainUrl, -1, 0);
+ if (IO->HttpReq.PlainPostDataLen > 0) {
StrBufAppendBufPlain(ErrMsg, HKEY("\nThe Post document was: \n"), 0);
StrBufAppendBufPlain(ErrMsg,
- Ctx->HTTPData.PlainPostData,
- Ctx->HTTPData.PlainPostDataLen, 0);
+ IO->HttpReq.PlainPostData,
+ IO->HttpReq.PlainPostDataLen, 0);
StrBufAppendBufPlain(ErrMsg, HKEY("\n\n"), 0);
}
- if (StrLength(Ctx->HTTPData.ReplyData) > 0) {
+ if (StrLength(IO->HttpReq.ReplyData) > 0) {
StrBufAppendBufPlain(ErrMsg, HKEY("\n\nThe Serverreply was: \n\n"), 0);
- StrBufAppendBuf(ErrMsg, Ctx->HTTPData.ReplyData, 0);
+ StrBufAppendBuf(ErrMsg, IO->HttpReq.ReplyData, 0);
}
else
StrBufAppendBufPlain(ErrMsg, HKEY("\n\nThere was no Serverreply.\n\n"), 0);
}
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);