Back to index

citadel  8.12
Classes | Defines | Typedefs | Enumerations | Functions
extnotify.h File Reference
#include "../eventclient/serv_curl.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _NotifyContext

Defines

#define PAGER_CONFIG_MESSAGE   "__ Push email settings __"
#define FUNAMBOL_CONFIG_TEXT   "funambol"
#define PAGER_CONFIG_SYSTEM   "textmessage"
#define PAGER_CONFIG_HTTP   "httpmessage"
#define FUNAMBOL_WS   "/funambol/services/admin"

Typedefs

typedef enum _eNotifyType eNotifyType
typedef struct _NotifyContext NotifyContext

Enumerations

enum  _eNotifyType { eNone, eFunambol, eHttpMessages, eTextMessage }

Functions

int notify_http_server (char *remoteurl, const char *template, long tlen, char *user, char *msgid, long MsgNum, NotifyContext *Ctx)
void ExtNotify_PutErrorMessage (NotifyContext *Ctx, StrBuf *ErrMsg)

Class Documentation

struct _NotifyContext

Definition at line 36 of file extnotify.h.

Class Members
AsyncIO IO
int nNotifyHosts
HashList * NotifyErrors
StrBuf ** NotifyHostList

Define Documentation

#define FUNAMBOL_CONFIG_TEXT   "funambol"

Definition at line 23 of file extnotify.h.

#define FUNAMBOL_WS   "/funambol/services/admin"

Definition at line 34 of file extnotify.h.

#define PAGER_CONFIG_HTTP   "httpmessage"

Definition at line 25 of file extnotify.h.

#define PAGER_CONFIG_MESSAGE   "__ Push email settings __"

Definition at line 22 of file extnotify.h.

#define PAGER_CONFIG_SYSTEM   "textmessage"

Definition at line 24 of file extnotify.h.


Typedef Documentation

typedef enum _eNotifyType eNotifyType
typedef struct _NotifyContext NotifyContext

Enumeration Type Documentation

Enumerator:
eNone 
eFunambol 
eHttpMessages 
eTextMessage 

Definition at line 26 of file extnotify.h.


Function Documentation

void ExtNotify_PutErrorMessage ( NotifyContext Ctx,
StrBuf *  ErrMsg 
)

Definition at line 73 of file extnotify_main.c.

{
       int nNext;
       if (Ctx->NotifyErrors == NULL)
              Ctx->NotifyErrors = NewHash(1, Flathash);

       nNext = GetCount(Ctx->NotifyErrors) + 1;
       Put(Ctx->NotifyErrors,
           (char*)&nNext,
           sizeof(int),
           ErrMsg,
           HFreeStrBuf);
}
int notify_http_server ( char *  remoteurl,
const char *  template,
long  tlen,
char *  user,
char *  msgid,
long  MsgNum,
NotifyContext Ctx 
)

Definition at line 60 of file funambol65.c.

{
       CURLcode sta;
       char msgnumstr[128];
       char *buf = NULL;
       char *SOAPMessage = NULL;
       char *contenttype = NULL;
       StrBuf *ReplyBuf;
       StrBuf *Buf;
       CURL *chnd;
       AsyncIO *IO;

       IO = (AsyncIO*) malloc(sizeof(AsyncIO));
       memset(IO, 0, sizeof(AsyncIO));

       if (! InitcURLIOStruct(IO,
                            NULL, /* we don't have personal data anymore. */
                            "Citadel ExtNotify",
                            EvaluateResult,
                            ExtNotifyTerminate,
                            ExtNotifyTerminateDB,
                            ExtNotifyShutdownAbort))
       {
              syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
              goto abort;
       }

       snprintf(msgnumstr, 128, "%ld", MsgNum);

       if (tlen > 0) {
              /* Load the template message. Get mallocs done too */
              int fd;
              struct stat statbuf;
              const char *mimetype;
              const char *Err = NULL;

              fd = open(template, O_RDONLY);
              if ((fd < 0) ||
                  (fstat(fd, &statbuf) == -1))
              {
                     char buf[SIZ];

                     snprintf(buf, SIZ,
                             "Cannot load template file %s [%s] "
                             "won't send notification\r\n",
                             file_funambol_msg,
                             strerror(errno));
                     syslog(LOG_ERR, "%s", buf);
                     // TODO: once an hour!
                     CtdlAideMessage(
                            buf,
                            "External notifier: "
                            "unable to find/stat message template!");
                     goto abort;
              }

              Buf = NewStrBufPlain(NULL, statbuf.st_size + 1);
              if (StrBufReadBLOB(Buf, &fd, 1, statbuf.st_size, &Err) < 0) {
                     char buf[SIZ];

                     close(fd);

                     snprintf(buf, SIZ,
                             "Cannot load template file %s [%s] "
                             "won't send notification\r\n",
                             file_funambol_msg,
                             Err);
                     syslog(LOG_ERR, "%s", buf);
                     // TODO: once an hour!
                     CtdlAideMessage(
                            buf,
                            "External notifier: "
                            "unable to load message template!");
                     goto abort;
              }
              close(fd);

              mimetype = GuessMimeByFilename(template, tlen);

              SOAPMessage = SmashStrBuf(&Buf);

              // Do substitutions
              help_subst(SOAPMessage, "^notifyuser", user);
              help_subst(SOAPMessage, "^syncsource",
                        config.c_funambol_source);
              help_subst(SOAPMessage, "^msgid", msgid);
              help_subst(SOAPMessage, "^msgnum", msgnumstr);

              /* pass our list of custom made headers */

              contenttype=(char*) malloc(40+strlen(mimetype));
              sprintf(contenttype,
                     "Content-Type: %s; charset=utf-8",
                     mimetype);

              IO->HttpReq.headers = curl_slist_append(
                     IO->HttpReq.headers,
                     "SOAPAction: \"\"");

              IO->HttpReq.headers = curl_slist_append(
                     IO->HttpReq.headers,
                     contenttype);
              free(contenttype);
              contenttype = NULL;
              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 */
              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);

              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");
       }

       Buf = NewStrBufPlain (remoteurl, -1);
       ParseURL(&IO->ConnectMe, Buf, 80);
       FreeStrBuf(&Buf); /* TODO: this is uncool... */
       CurlPrepareURL(IO->ConnectMe);

       chnd = IO->HttpReq.chnd;
       OPT(SSL_VERIFYPEER, 0);
       OPT(SSL_VERIFYHOST, 0);

       QueueCurlContext(IO);

       return 0;
abort:

       if (contenttype) free(contenttype);
       if (SOAPMessage != NULL) free(SOAPMessage);
       if (buf != NULL) free(buf);
       FreeStrBuf (&ReplyBuf);
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function: