]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_funambol.c
mk_module_init.sh now tests to see if echo supports -e and -E
[citadel.git] / citadel / serv_funambol.c
index cc9e0a192e930efcb54ac7a5f2f2239ebd7c4b76..561be098664567f7c88a7d2eb3364b23573836cd 100644 (file)
 #include <sys/socket.h>
 #include "citadel.h"
 #include "server.h"
-#include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
 #include "control.h"
-#include "serv_extensions.h"
 #include "room_ops.h"
 #include "user_ops.h"
 #include "policy.h"
 #include "domain.h"
 #include "clientsocket.h"
 #include "serv_funambol.h"
+
+
+
+#include "ctdl_module.h"
+
+
 /*
  * Create the notify message queue
  */
@@ -64,10 +68,38 @@ void create_notify_queue(void) {
                lputroom(&qrbuf);
        }
 }
+void do_notify_queue(void) {
+       static int doing_queue = 0;
+
+       /*
+        * This is a simple concurrency check to make sure only one queue run
+        * is done at a time.  We could do this with a mutex, but since we
+        * don't really require extremely fine granularity here, we'll do it
+        * with a static variable instead.
+        */
+       if (doing_queue) return;
+       doing_queue = 1;
+
+       /* 
+        * Go ahead and run the queue
+        */
+       lprintf(CTDL_INFO, "serv_funambol: processing notify queue\n");
+
+       if (getroom(&CC->room, FNBL_QUEUE_ROOM) != 0) {
+               lprintf(CTDL_ERR, "Cannot find room <%s>\n", FNBL_QUEUE_ROOM);
+               return;
+       }
+       CtdlForEachMessage(MSGS_ALL, 0L, NULL,
+               SPOOLMIME, NULL, notify_funambol, NULL);
+
+       lprintf(CTDL_INFO, "serv_funambol: queue run completed\n");
+       doing_queue = 0;
+}
+
 /*
  * Connect to the Funambol server and scan a message.
  */
-int notify_funambol(long msgnum, void *userdata) {
+void notify_funambol(long msgnum, void *userdata) {
        struct CtdlMessage *msg;
        int sock = (-1);
        char buf[SIZ];
@@ -77,11 +109,11 @@ int notify_funambol(long msgnum, void *userdata) {
        /* W means 'Wireless'... */
        msg = CtdlFetchMessage(msgnum, 1);
        if ( msg->cm_fields['W'] == NULL) {
-               return(0);
+               goto nuke;
        }
        /* Are we allowed to push? */
        if ( strlen(config.c_funambol_host) == 0) {
-               return (0);
+               goto nuke;
        } else {
                lprintf(CTDL_INFO, "Push enabled\n");
        }
@@ -93,7 +125,7 @@ int notify_funambol(long msgnum, void *userdata) {
 
        if (sock < 0) {
                /* If the service isn't running, pass for now */
-               return(0);
+               return;
        }
        
        /* Build a SOAP message, delicately, by hand */
@@ -146,9 +178,8 @@ int notify_funambol(long msgnum, void *userdata) {
        
        /* Command */
        lprintf(CTDL_DEBUG, "Transmitting command\n");
-       sprintf(buf, "POST %s HTTP/1.0\r\nContent-type: text/xml; charset=utf-8\r\n",
+       sprintf(SOAPHeader, "POST %s HTTP/1.0\r\nContent-type: text/xml; charset=utf-8\r\n",
                FUNAMBOL_WS);
-       strcat(SOAPHeader,buf);
        strcat(SOAPHeader,"Accept: application/soap+xml, application/dime, multipart/related, text/*\r\n");
        sprintf(buf, "User-Agent: %s/%d\r\nHost: %s:%d\r\nCache-control: no-cache\r\n",
                "Citadel",
@@ -181,48 +212,22 @@ int notify_funambol(long msgnum, void *userdata) {
        }
        lprintf(CTDL_DEBUG, "Funambol notified\n");
        /* We should allow retries here but for now purge after one go */
-       bail:   
+       bail:           
+       close(sock);
+       nuke:
        CtdlFreeMessage(msg);
        long todelete[1];
        todelete[0] = msgnum;
-       CtdlDeleteMessages(FNBL_QUEUE_ROOM, todelete, 1, "");   
-       close(sock);
-       return 0;
+       CtdlDeleteMessages(FNBL_QUEUE_ROOM, todelete, 1, "");
 }
 
 
-void do_notify_queue(void) {
-       static int doing_queue = 0;
-
-       /*
-        * This is a simple concurrency check to make sure only one queue run
-        * is done at a time.  We could do this with a mutex, but since we
-        * don't really require extremely fine granularity here, we'll do it
-        * with a static variable instead.
-        */
-       if (doing_queue) return;
-       doing_queue = 1;
-
-       /* 
-        * Go ahead and run the queue
-        */
-       lprintf(CTDL_INFO, "serv_funambol: processing notify queue\n");
-
-       if (getroom(&CC->room, FNBL_QUEUE_ROOM) != 0) {
-               lprintf(CTDL_ERR, "Cannot find room <%s>\n", FNBL_QUEUE_ROOM);
-               return;
-       }
-       CtdlForEachMessage(MSGS_ALL, 0L, NULL,
-               SPOOLMIME, NULL, notify_funambol, NULL);
-
-       lprintf(CTDL_INFO, "serv_funambol: queue run completed\n");
-       doing_queue = 0;
-}
-
 
-char *serv_funambol_init(void)
+CTDL_MODULE_INIT(funambol)
 {
        create_notify_queue();
        CtdlRegisterSessionHook(do_notify_queue, EVT_TIMER);
-        return "$Id: serv_funambol.c $";
+
+       /* return our Subversion id for the Log */
+        return "$Id$";
 }