* create struct, so we can transport hostlists in and errormessages out
authorWilfried Göesgens <willi@citadel.org>
Tue, 14 Jul 2009 23:13:22 +0000 (23:13 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 14 Jul 2009 23:13:22 +0000 (23:13 +0000)
* report failed notifications to aide _after_ sending all notifications of this chunk.

citadel/modules/extnotify/extnotify.h
citadel/modules/extnotify/extnotify_main.c
citadel/modules/extnotify/funambol65.c

index 0639acbd5bd9031c6f848f488ecf2c4247dc0b65..870619601792efaf0bebc169e6332d8cf08c7375 100644 (file)
@@ -16,12 +16,20 @@ extern "C" {
 
 #define FUNAMBOL_WS "/funambol/services/admin"
 
+typedef struct _NotifyContext {
+       StrBuf **NotifyHostList;
+       HashList *NotifyErrors;
+} NotifyContext;
+
 int notify_http_server(char *remoteurl, 
                       const char* template, 
                       long tlen, 
                       char *user,
                       char *msgid, 
-                      long MsgNum);
+                      long MsgNum, 
+                      NotifyContext *Ctx);
+
+void ExtNotify_PutErrorMessage(NotifyContext *Ctx, StrBuf *ErrMsg);
 
 void extNotify_getPrefs(long configMsgNum, char *configMsg);
 long extNotify_getConfigMessage(char *username);
index e06c07e182ae6837ce542b294327415c69bff88e..387b138c8969c31223387fb356cdde288737ca1d 100644 (file)
 
 #include "ctdl_module.h"
 
+
+
+void ExtNotify_PutErrorMessage(NotifyContext *Ctx, StrBuf *ErrMsg)
+{
+       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);
+}
+
+
+
+
 StrBuf* GetNHBuf(int i, int allocit, StrBuf **NotifyHostList)
 {
        if ((NotifyHostList[i] == NULL) && (allocit != 0))
@@ -125,9 +144,10 @@ void create_extnotify_queue(void) {
 /*!
  * \brief Run through the pager room queue
  */
-void do_extnotify_queue(void) {
+void do_extnotify_queue(void) 
+{
+       NotifyContext Ctx;
        static int doing_queue = 0;
-       StrBuf **NotifyHosts;
        int i = 0;
     
        /*
@@ -144,16 +164,37 @@ void do_extnotify_queue(void) {
         */
        CtdlLogPrintf(CTDL_DEBUG, "serv_extnotify: processing notify queue\n");
     
-       NotifyHosts = GetNotifyHosts();
+       memset(&Ctx, 0, sizeof(NotifyContext));
+       Ctx.NotifyHostList = GetNotifyHosts();
        if (getroom(&CC->room, FNBL_QUEUE_ROOM) != 0) {
                CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", FNBL_QUEUE_ROOM);
                return;
        }
        CtdlForEachMessage(MSGS_ALL, 0L, NULL,
-                          SPOOLMIME, NULL, process_notify, NotifyHosts);
+                          SPOOLMIME, NULL, process_notify, &Ctx);
+
+       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");
+               }
 
-       while ((NotifyHosts != NULL) && (NotifyHosts[i] != NULL))
-               FreeStrBuf(&NotifyHosts[i]);
+               DeleteHashPos(&It);
+               DeleteHash(&Ctx.NotifyErrors);
+       }
 
        CtdlLogPrintf(CTDL_DEBUG, "serv_extnotify: queue run completed\n");
        doing_queue = 0;
@@ -163,6 +204,7 @@ void do_extnotify_queue(void) {
  */
 void process_notify(long NotifyMsgnum, void *usrdata) 
 {
+       NotifyContext *Ctx;
        long msgnum;
        long todelete[1];
        int fnblAllowed;
@@ -171,11 +213,10 @@ void process_notify(long NotifyMsgnum, void *usrdata)
        char *pch;
        long configMsgNum;
        char configMsg[SIZ];
-       StrBuf **NotifyHostList;        
        struct CtdlMessage *msg;
 
+       Ctx = (NotifyContext*) usrdata;
 
-       NotifyHostList = (StrBuf**) usrdata;
        msg = CtdlFetchMessage(NotifyMsgnum, 1);
        if ( msg->cm_fields['W'] == NULL) {
                goto nuke;
@@ -221,7 +262,8 @@ void process_notify(long NotifyMsgnum, void *usrdata)
                                   strlen(file_funambol_msg),/*GNA*/
                                   msg->cm_fields['W'], 
                                   msg->cm_fields['I'],
-                                  msgnum);
+                                  msgnum, 
+                                  Ctx);
        } else if (extPagerAllowedHttp == 0) {
                int i = 0;
                StrBuf *URL;
@@ -232,9 +274,9 @@ void process_notify(long NotifyMsgnum, void *usrdata)
                while(1)
                {
 
-                       URL = GetNHBuf(i*2, 0, NotifyHostList);
+                       URL = GetNHBuf(i*2, 0, Ctx->NotifyHostList);
                        if (URL==NULL) break;
-                       File = GetNHBuf(i*2 + 1, 0, NotifyHostList);
+                       File = GetNHBuf(i*2 + 1, 0, Ctx->NotifyHostList);
                        if (File==NULL) break;
 
                        if (StrLength(File)>0)
@@ -250,7 +292,8 @@ void process_notify(long NotifyMsgnum, void *usrdata)
                                           StrLength(FileBuf),
                                           msg->cm_fields['W'], 
                                           msg->cm_fields['I'],
-                                          msgnum);
+                                          msgnum, 
+                                          Ctx);
                        i++;
                }
                FreeStrBuf(&FileBuf);
index 30d6d0fe2f8cfd246aa1e3f5ca11fd7146af214c..e14d135558b901e5d8182ba0bb644edc36bb1f8a 100644 (file)
@@ -8,7 +8,6 @@
 * Based on bits of the previous serv_funambol
 * Contact: <matt@mcbridematt.dhs.org> / <matt@comalies>
 */
-#include "extnotify.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -29,6 +28,8 @@
 #include "msgbase.h"
 #include "ctdl_module.h"
 
+#include "extnotify.h"
+
 /*
 * \brief Sends a message to the Funambol server notifying 
 * of new mail for a user
@@ -38,7 +39,8 @@ int notify_http_server(char *remoteurl,
                       const char* template, long tlen, 
                       char *user,
                       char *msgid, 
-                      long MsgNum) 
+                      long MsgNum, 
+                      NotifyContext *Ctx) 
 {
        char curl_errbuf[CURL_ERROR_SIZE];
        char *pchs, *pche;
@@ -187,11 +189,7 @@ int notify_http_server(char *remoteurl,
                }
                else 
                        StrBufAppendBufPlain(ErrMsg, HKEY("\n\nThere was no Serverreply.\n\n"), 0);
-/* TODO: this will change the floor we're in :(
-               quickie_message("Citadel", NULL, NULL, AIDEROOM, ChrPtr(ErrMsg), FMT_FIXED, 
-                               "Failed to notify external service about inbound mail");
-*/
-               FreeStrBuf(&ErrMsg);
+               ExtNotify_PutErrorMessage(Ctx, ErrMsg);
        }
 
        CtdlLogPrintf(CTDL_DEBUG, "Funambol notified\n");