Applied Matt's new patch. Adds 'extnotify' and removes
authorArt Cancro <ajc@citadel.org>
Sun, 20 Jan 2008 04:43:25 +0000 (04:43 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 20 Jan 2008 04:43:25 +0000 (04:43 +0000)
the 'pager' and 'funambol' modules.

citadel/citadel_dirs.c
citadel/citadel_dirs.h
citadel/modules/extnotify/extnotify.h [new file with mode: 0644]
citadel/modules/extnotify/extnotify_main.c [new file with mode: 0644]
citadel/modules/extnotify/funambol65.c [new file with mode: 0644]
citadel/modules/funambol/serv_funambol.c [deleted file]
citadel/modules/funambol/serv_funambol.h [deleted file]
citadel/modules/pager/serv_pager.c [deleted file]
citadel/serv_pager.h [deleted file]

index 54da76ff3425087b9b51f332ae328900fcec3ab5..bade7734acf9f0060f1c62a2d59458f678a82226 100644 (file)
@@ -66,6 +66,7 @@ char file_crpt_file_csr[PATH_MAX]="";
 char file_crpt_file_cer[PATH_MAX]="";
 char file_chkpwd[PATH_MAX]="";
 char file_base64[PATH_MAX]="";
+char file_funambol_msg[PATH_MAX] = "";
 
 int home_specified = 0;
 
@@ -245,7 +246,12 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
                 ctdl_spool_dir
 #endif
                );
-
+                
+        snprintf(file_funambol_msg,
+                sizeof file_funambol_msg,
+                "%sfunambol_newmail_soap.xml",
+                ctdl_spool_dir);
+        
        DBG_PRINT(ctdl_bio_dir);
        DBG_PRINT(ctdl_bb_dir);
        DBG_PRINT(ctdl_data_dir);
@@ -282,6 +288,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char  *ctd
        DBG_PRINT(file_crpt_file_cer);
        DBG_PRINT(file_chkpwd);
        DBG_PRINT(file_base64);
+       DBG_PRINT(file_funambol_msg);
 }
 
 
index 8a9e280f9062cb5eadcb50af29f0dbe4557c8fcb..490884efb8f03c6e30cad5646ac3b80d771bdb9c 100644 (file)
@@ -50,6 +50,8 @@ extern char file_crpt_file_cer[PATH_MAX];
 extern char file_chkpwd[PATH_MAX];
 extern char file_base64[PATH_MAX];
 
+extern char file_funambol_msg[PATH_MAX];
+
 extern void calc_dirs_n_files(int relh, int home, const char *relhome,const char  *ctdldir, int dbg);
 
 
diff --git a/citadel/modules/extnotify/extnotify.h b/citadel/modules/extnotify/extnotify.h
new file mode 100644 (file)
index 0000000..e25650e
--- /dev/null
@@ -0,0 +1,28 @@
+/* 
+ * File:   extnotify.h
+ * Author: Mathew McBride <matt@mcbridematt.dhs.org> / <matt@comalies>
+ *
+ * Created on January 13, 2008, 9:34 PM
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define FUNAMBOL_CONFIG_TEXT "funambol"
+#define PAGER_CONFIG_MESSAGE "__ Push email settings __"
+#define PAGER_CONFIG_TEXT  "textmessage"    
+
+#define FUNAMBOL_WS "/funambol/services/admin"
+
+int notify_funambol_server(char *user);
+
+char *extNotify_getPrefs(long configMsgNum, char *configMsg);
+long extNotify_getConfigMessage(char *username);
+void process_notify(long msgnum, void *usrdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+
diff --git a/citadel/modules/extnotify/extnotify_main.c b/citadel/modules/extnotify/extnotify_main.c
new file mode 100644 (file)
index 0000000..3381995
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * \file extnotify_main.c
+ * @author Mathew McBride
+ *
+ * This module implements an external pager hook for when notifcation
+ * of a new email is wanted.
+ * Based on bits of serv_funambol
+ * Contact: <matt@mcbridematt.dhs.org> / <matt@comalies>
+ */
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <sys/wait.h>
+#include <string.h>
+#include <limits.h>
+#include <sys/socket.h>
+#include <libcitadel.h>
+#include "citadel.h"
+#include "server.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "control.h"
+#include "room_ops.h"
+#include "user_ops.h"
+#include "policy.h"
+#include "database.h"
+#include "msgbase.h"
+#include "internet_addressing.h"
+#include "domain.h"
+#include "clientsocket.h"
+#include "extnotify.h"
+
+#include "ctdl_module.h"
+
+/*! \brief Create the notify message queue. We use the exact same room
+ *                     as the Funambol module.
+ *
+ *     Run at server startup, creates FNBL_QUEUE_ROOM if it doesn't exist
+ *     and sets as system room.
+ */
+void create_extnotify_queue(void) {
+    struct ctdlroom qrbuf;
+    
+    create_room(FNBL_QUEUE_ROOM, 3, "", 0, 1, 0, VIEW_MAILBOX);
+    
+    /*
+     * Make sure it's set to be a "system room" so it doesn't show up
+     * in the <K>nown rooms list for Aides.
+     */
+    if (lgetroom(&qrbuf, FNBL_QUEUE_ROOM) == 0) {
+        qrbuf.QRflags2 |= QR2_SYSTEM;
+        lputroom(&qrbuf);
+    }
+}
+/*!
+ * \brief Run through the pager room queue
+ */
+void do_extnotify_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_DEBUG, "serv_extnotify: 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, process_notify, NULL);
+    
+    lprintf(CTDL_DEBUG, "serv_extnotify: queue run completed\n");
+    doing_queue = 0;
+}
+/*!
+ * \brief Process messages in the external notification queue
+ */
+void process_notify(long msgnum, void *usrdata) {
+    struct CtdlMessage *msg;
+    msg = CtdlFetchMessage(msgnum, 1);
+    if ( msg->cm_fields['W'] == NULL) {
+        goto nuke;
+    }
+    
+    long configMsgNum = extNotify_getConfigMessage(msg->cm_fields['W']);
+    char configMsg[SIZ];
+    
+    extNotify_getPrefs(configMsgNum, &configMsg);
+    
+    /* Check to see if:
+     * 1. The user has configured paging / They have and disabled it
+     * AND 2. There is an external pager program
+     * 3. A Funambol server has been entered
+     *
+     */
+    if (configMsgNum == -1 || strncasecmp(configMsg, "none", 4) == 0 &&
+    IsEmptyStr(config.c_pager_program) && IsEmptyStr(config.c_funambol_host)) {
+        lprintf(CTDL_DEBUG, "No external notifiers configured on system/user");
+        goto nuke;
+    }
+    // Can Funambol take the message?
+    int fnblAllowed = strncasecmp(configMsg, FUNAMBOL_CONFIG_TEXT, strlen(FUNAMBOL_CONFIG_TEXT));
+    int extPagerAllowed = strncasecmp(configMsg, PAGER_CONFIG_TEXT, strlen(PAGER_CONFIG_TEXT)); 
+    if (fnblAllowed == 0) {
+        notify_funambol_server(msg->cm_fields['W']);
+    } else if (extPagerAllowed == 0) {
+       char *number = strtok(configMsg, "textmessage\n");
+       int commandSiz = sizeof(config.c_pager_program) + strlen(number) + strlen(msg->cm_fields['W']) + 5;
+       char *command = malloc(commandSiz);
+       snprintf(command, commandSiz, "%s %s -u %s", config.c_pager_program, number, msg->cm_fields['W']);
+       system(command);
+       free(command);
+    }
+    nuke:
+    CtdlFreeMessage(msg);
+    memset(configMsg, 0, sizeof(configMsg));
+    long todelete[1];
+    todelete[0] = msgnum;
+    CtdlDeleteMessages(FNBL_QUEUE_ROOM, todelete, 1, "");
+}
+
+/*! \brief Checks to see what notification option the user has set
+ *
+ */
+char *extNotify_getPrefs(long configMsgNum, char *configMsg) {
+    // Do a simple string search to see if 'funambol' is selected as the
+    // type. This string would be at the very top of the message contents.
+    if (configMsgNum == -1) {
+        lprintf(CTDL_ERR, "extNotify_isAllowedByPrefs was passed a non-existant config message id\n");
+        return "none";
+    }
+    struct CtdlMessage *prefMsg;
+    prefMsg = CtdlFetchMessage(configMsgNum, 1);
+    strncpy(configMsg, prefMsg->cm_fields['M'], strlen(prefMsg->cm_fields['M']));
+    CtdlFreeMessage(prefMsg);
+    return configMsg;
+}
+/*! \brief Get configuration message for pager/funambol system from the
+ *                     users "My Citadel Config" room
+ */
+long extNotify_getConfigMessage(char *username) {
+    struct ctdlroom qrbuf; // scratch for room
+    struct ctdluser user; // ctdl user instance
+    char configRoomName[ROOMNAMELEN];
+    struct CtdlMessage *msg;
+    struct cdbdata *cdbfr;
+    long *msglist = NULL;
+    int num_msgs = 0;
+    long confMsgNum = -1;
+    // Get the user
+    getuser(&user, username);
+    
+    MailboxName(configRoomName, sizeof configRoomName, &user, USERCONFIGROOM);
+    // Fill qrbuf
+    getroom(&qrbuf, configRoomName);
+    /* Do something really, really stoopid here. Raid the room on ourselves,
+     * loop through the messages manually and find it. I don't want
+     * to use a CtdlForEachMessage callback here, as we would be
+     * already in one */
+    cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long));
+    if (cdbfr != NULL) {
+        msglist = (long *) cdbfr->ptr;
+        cdbfr->ptr = NULL;     /* CtdlForEachMessage() now owns this memory */
+        num_msgs = cdbfr->len / sizeof(long);
+        cdb_free(cdbfr);
+    } else {
+        lprintf(CTDL_DEBUG, "extNotify_getConfigMessage: No config messages found\n");
+        return -1;     /* No messages at all?  No further action. */
+    }
+    int a;
+    for (a = 0; a < num_msgs; ++a) {
+        msg = CtdlFetchMessage(msglist[a], 1);
+        if (msg != NULL) {
+            if (msg->cm_fields['U'] != NULL && strncasecmp(msg->cm_fields['U'], PAGER_CONFIG_MESSAGE,
+                    strlen(PAGER_CONFIG_MESSAGE)) == 0) {
+                confMsgNum = msglist[a];
+            }
+            CtdlFreeMessage(msg);
+        }
+    }
+    return confMsgNum;
+    
+}
+CTDL_MODULE_INIT(extnotify)
+{
+       if (!threading)
+       {
+               create_extnotify_queue();
+               CtdlRegisterSessionHook(do_extnotify_queue, EVT_TIMER);
+       }
+       /* return our Subversion id for the Log */
+        return "$Id:  $";
+}
\ No newline at end of file
diff --git a/citadel/modules/extnotify/funambol65.c b/citadel/modules/extnotify/funambol65.c
new file mode 100644 (file)
index 0000000..6b394e5
--- /dev/null
@@ -0,0 +1,119 @@
+/* 
+* \file funambol65.c
+* @author Mathew McBride
+* 
+* This module facilitates notifications to a Funambol server
+* for push email
+*
+* Based on bits of the previous serv_funambol
+* Contact: <matt@mcbridematt.dhs.org> / <matt@comalies>
+*/
+#include "extnotify.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <time.h>
+#include <libcitadel.h>
+
+#include "citadel_dirs.h"
+#include "clientsocket.h"
+#include "sysdep.h"
+#include "sysconfig.h"
+#include "config.h"
+#include "sysdep_decls.h"
+
+/*
+* \brief Sends a message to the Funambol server notifying 
+* of new mail for a user
+* Returns 0 if unsuccessful
+*/
+int notify_funambol_server(char *user) {
+       char port[1024];
+       int sock = -1;
+       char *buf;
+       char *SOAPMessage;
+       char *SOAPHeader;
+       char *funambolCreds;
+       FILE *template;
+       FILE *fnblConf;
+       
+       sprintf(port, "%d", config.c_funambol_port);
+       sock = sock_connect(config.c_funambol_host, port, "tcp");
+       if (sock >= 0) 
+               lprintf(CTDL_DEBUG, "Connected to Funambol!\n");
+       else 
+               goto bail;
+       // Load the template SOAP message
+       template = fopen(file_funambol_msg, "r");
+       buf = malloc(SIZ);
+       memset(buf, 0, SIZ);
+       SOAPMessage = malloc(3072);
+       memset(SOAPMessage, 0, 3072);
+       while(fgets(buf, SIZ, template) != NULL) {
+               strcat(SOAPMessage, buf);
+       }
+       fclose(template);
+       
+       if (strlen(SOAPMessage) < 0) {
+               printf("Cannot load template file\r\n");
+               goto bail;
+       }
+       // Do substitutions
+       help_subst(SOAPMessage, "^notifyuser", user);
+       help_subst(SOAPMessage, "^syncsource", config.c_funambol_source);
+       
+       /* Build the HTTP request header */
+       SOAPHeader  = malloc(SIZ);
+       memset(SOAPHeader, 0, SIZ);
+       sprintf(SOAPHeader, "POST %s HTTP/1.0\r\nContent-type: text/xml; charset=utf-8\r\n",
+               FUNAMBOL_WS);
+       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",
+               REV_LEVEL,
+               config.c_funambol_host,
+               config.c_funambol_port
+               );
+       strcat(SOAPHeader,buf);
+       strcat(SOAPHeader,"Pragma: no-cache\r\nSOAPAction: \"\"\r\n");
+       sprintf(buf, "Content-Length: %d \r\n",
+               strlen(SOAPMessage));
+       strcat(SOAPHeader, buf);
+       
+       funambolCreds = malloc(strlen(config.c_funambol_auth)*2);
+       memset(funambolCreds, 0, strlen(config.c_funambol_auth)*2);
+
+       CtdlEncodeBase64(funambolCreds, config.c_funambol_auth, strlen(config.c_funambol_auth), 0);
+       
+       
+       sprintf(buf, "Authorization: Basic %s\r\n\r\n",
+               funambolCreds);
+       strcat(SOAPHeader, buf);
+       
+       int written_header = sock_write(sock, SOAPHeader, strlen(SOAPHeader));
+       int written_body = sock_write(sock, SOAPMessage, strlen(SOAPMessage));
+       sock_shutdown(sock, SHUT_WR);
+       
+       /* Response */
+       lprintf(CTDL_DEBUG, "Awaiting response\n");
+        if (sock_getln(sock, buf, SIZ) < 0) {
+                goto bail;
+        }
+        lprintf(CTDL_DEBUG, "<%s\n", buf);
+       if (strncasecmp(buf, "HTTP/1.1 200 OK", strlen("HTTP/1.1 200 OK"))) {
+               
+               goto bail;
+       }
+       lprintf(CTDL_DEBUG, "Funambol notified\n");
+       
+bail:
+       close(sock);
+       free(funambolCreds);
+       free(SOAPMessage);
+       free(buf);
+       free(SOAPHeader);
+       return 0;
+}
+
diff --git a/citadel/modules/funambol/serv_funambol.c b/citadel/modules/funambol/serv_funambol.c
deleted file mode 100644 (file)
index e60c64a..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * This module implements a notifier for Funambol push email.
- * Based on bits of serv_spam, serv_smtp
- */
-
-#define FUNAMBOL_WS       "/funambol/services/admin"
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <pwd.h>
-#include <errno.h>
-#include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#include <sys/wait.h>
-#include <string.h>
-#include <limits.h>
-#include <sys/socket.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "server.h"
-#include "citserver.h"
-#include "support.h"
-#include "config.h"
-#include "control.h"
-#include "room_ops.h"
-#include "user_ops.h"
-#include "database.h"
-#include "msgbase.h"
-#include "internet_addressing.h"
-#include "domain.h"
-#include "clientsocket.h"
-
-#include "serv_funambol.h"
-#include "serv_pager.h"
-
-
-#include "ctdl_module.h"
-
-#define FUNAMBOL_CONFIG_TEXT "funambol"
-
-/*
- * Create the notify message queue
- */
-void create_notify_queue(void) {
-       struct ctdlroom qrbuf;
-
-       create_room(FNBL_QUEUE_ROOM, 3, "", 0, 1, 0, VIEW_MAILBOX);
-
-       /*
-        * Make sure it's set to be a "system room" so it doesn't show up
-        * in the <K>nown rooms list for Aides.
-        */
-       if (lgetroom(&qrbuf, FNBL_QUEUE_ROOM) == 0) {
-               qrbuf.QRflags2 |= QR2_SYSTEM;
-               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;
-}
-
-/*! \brief Sends a message to the Funambol server 
- *                     to notify of new email
- * 
- * Connect to the Funambol server via HTTP and send a SOAP request
- * to notify of new email
- */
-void notify_funambol(long msgnum, void *userdata) {
-       struct CtdlMessage *msg;
-       int sock = (-1);
-       char buf[SIZ];
-       char SOAPHeader[SIZ];
-       char SOAPData[SIZ];
-       char port[SIZ];
-       /* W means 'Wireless'... */
-       msg = CtdlFetchMessage(msgnum, 1);
-       if ( msg->cm_fields['W'] == NULL) {
-               lprintf(CTDL_ERR, "serv_funambol: msg->cm-fields['W'] is NULL\n");
-               goto nuke;
-       }
-       long configMsgNum = pager_getConfigMessage(msg->cm_fields['W']);
-       int allowed = funambol_isAllowedByPrefs(configMsgNum);
-       if (allowed != 0) {
-               lprintf(CTDL_DEBUG, "serv_funambol: User does not want Funambol push. Aborting\n");
-               return;
-       }
-       /* Are we allowed to push? */
-       if (IsEmptyStr(config.c_funambol_host)) {
-               return;
-       } else {
-               lprintf(CTDL_INFO, "Push enabled\n");
-       }
-       // Does the user want it?
-       sprintf(port, "%d", config.c_funambol_port);
-                lprintf(CTDL_INFO, "Connecting to Funambol at <%s>\n", config.c_funambol_host);
-                sock = sock_connect(config.c_funambol_host, port, "tcp");
-                if (sock >= 0) lprintf(CTDL_DEBUG, "Connected!\n");
-
-       if (sock < 0) {
-               /* If the service isn't running, pass for now */
-               goto nuke;
-       }
-       
-       /* Build a SOAP message, delicately, by hand */
-       sprintf(SOAPData, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
-       strcat(SOAPData, "<soapenv:Body><sendNotificationMessages soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
-       strcat(SOAPData, "<arg0 xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">");
-       strcat(SOAPData, msg->cm_fields['W']);
-       strcat(SOAPData, "</arg0>");
-       strcat(SOAPData, "<arg1 xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n");
-       strcat(SOAPData, "&lt;java version=&quot;1.5.0_10&quot; class=&quot;java.beans.XMLDecoder&quot;&gt; \r\n");
-       strcat(SOAPData, " &lt;array class=&quot;com.funambol.framework.core.Alert&quot; length=&quot;1&quot;&gt;\r\n");
-       strcat(SOAPData, "  &lt;void index=&quot;0&quot;&gt;\r\n");
-       strcat(SOAPData, "   &lt;object class=&quot;com.funambol.framework.core.Alert&quot;&gt;\r\n");
-       strcat(SOAPData, "    &lt;void property=&quot;cmdID&quot;>\r\n");
-       strcat(SOAPData, "     &lt;object class=&quot;com.funambol.framework.core.CmdID&quot;/&gt;\r\n");
-       strcat(SOAPData, "    &lt;/void&gt;");
-       strcat(SOAPData, "    &lt;void property=&quot;data&quot;&gt;\r\n");
-       strcat(SOAPData, "     &lt;int&gt;210&lt;/int&gt;\r\n");
-       strcat(SOAPData, "    &lt;/void&gt;\r\n");
-       strcat(SOAPData, "    &lt;void property=&quot;items&quot;&gt;\r\n");
-        strcat(SOAPData, "     &lt;void method=&quot;add&quot;&gt;\r\n"); 
-       strcat(SOAPData, "      &lt;object class=&quot;com.funambol.framework.core.Item&quot;&gt;\r\n"); 
-       strcat(SOAPData, "       &lt;void property=&quot;meta&quot;&gt;\r\n"); 
-       strcat(SOAPData, "        &lt;object class=&quot;com.funambol.framework.core.Meta&quot;&gt;\r\n"); 
-       strcat(SOAPData, "         &lt;void property=&quot;metInf&quot;&gt;\r\n");
-       strcat(SOAPData, "          &lt;void property=&quot;type&quot;&gt;\r\n");
-       strcat(SOAPData, "           &lt;string&gt;application/vnd.omads-email+xml&lt;/string&gt;\r\n");
-       strcat(SOAPData, "          &lt;/void&gt;\r\n"); 
-       strcat(SOAPData, "         &lt;/void&gt;\r\n"); 
-       strcat(SOAPData, "        &lt;/object&gt;\r\n"); 
-       strcat(SOAPData, "       &lt;/void&gt;\r\n"); 
-       strcat(SOAPData, "       &lt;void property=&quot;target&quot;&gt;\r\n"); 
-       strcat(SOAPData, "        &lt;object class=&quot;com.funambol.framework.core.Target&quot;&gt;\r\n");
-       strcat(SOAPData, "         &lt;void property=&quot;locURI&quot;&gt;\r\n");
-       strcat(SOAPData, "          &lt;string&gt;");
-       strcat(SOAPData, config.c_funambol_source);
-       strcat(SOAPData, "&lt;/string&gt;\r\n");
-       strcat(SOAPData, "         &lt;/void&gt;\r\n");
-       strcat(SOAPData, "        &lt;/object&gt;\r\n");
-       strcat(SOAPData, "       &lt;/void&gt;\r\n");
-       strcat(SOAPData, "      &lt;/object&gt;\r\n");
-       strcat(SOAPData, "     &lt;/void&gt;\r\n");
-       strcat(SOAPData, "    &lt;/void&gt;\r\n");
-       strcat(SOAPData, "   &lt;/object&gt;\r\n");
-       strcat(SOAPData, "  &lt;/void&gt;\r\n");
-       strcat(SOAPData, " &lt;/array&gt;\r\n");
-       strcat(SOAPData, "&lt;/java&gt;");
-       strcat(SOAPData,"</arg1><arg2 href=\"#id0\"/></sendNotificationMessages><multiRef id=\"id0\" soapenc:root=\"0\"\r\n");
-       strcat(SOAPData,"soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"soapenc:int\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">1</multiRef></soapenv:Body></soapenv:Envelope>");
-       
-       /* Command */
-       lprintf(CTDL_DEBUG, "Transmitting command\n");
-       sprintf(SOAPHeader, "POST %s HTTP/1.0\r\nContent-type: text/xml; charset=utf-8\r\n",
-               FUNAMBOL_WS);
-       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",
-               REV_LEVEL,
-               config.c_funambol_host,
-               config.c_funambol_port
-               );
-               strcat(SOAPHeader,buf);
-       strcat(SOAPHeader,"Pragma: no-cache\r\nSOAPAction: \"\"\r\n");
-       sprintf(buf, "Content-Length: " SIZE_T_FMT "\r\n",
-               strlen(SOAPData));
-       strcat(SOAPHeader, buf);
-       sprintf(buf, "Authorization: Basic %s\r\n\r\n",
-               config.c_funambol_auth);
-       strcat(SOAPHeader, buf);
-       
-       sock_write(sock, SOAPHeader, strlen(SOAPHeader));
-       sock_write(sock, SOAPData, strlen(SOAPData));
-       sock_shutdown(sock, SHUT_WR);
-       
-       /* Response */
-       lprintf(CTDL_DEBUG, "Awaiting response\n");
-        if (sock_getln(sock, buf, sizeof buf) < 0) {
-                goto bail;
-        }
-        lprintf(CTDL_DEBUG, "<%s\n", buf);
-       if (strncasecmp(buf, "HTTP/1.1 200 OK", strlen("HTTP/1.1 200 OK"))) {
-               
-               goto bail;
-       }
-       lprintf(CTDL_DEBUG, "Funambol notified\n");
-       /* We should allow retries here but for now purge after one go */
-       bail:           
-       close(sock);
-       nuke:
-       CtdlFreeMessage(msg);
-       long todelete[1];
-       todelete[0] = msgnum;
-       CtdlDeleteMessages(FNBL_QUEUE_ROOM, todelete, 1, "");
-}
-/*! \brief Checks a preference message to see if Funambol push is configured by user
- *
- */
-int funambol_isAllowedByPrefs(long configMsgNum) {
-       // Do a simple string search to see if 'funambol' is selected as the 
-       // type. This string would be at the very top of the message contents.
-       if (configMsgNum == -1) {
-               lprintf(CTDL_ERR, "funambol_isAllowedByPrefs was passed a non-existant config message id\n");
-               return -1;
-       }
-       struct CtdlMessage *prefMsg;
-       prefMsg = CtdlFetchMessage(configMsgNum, 1);
-       char *msgContents = prefMsg->cm_fields['M'];
-       return strncasecmp(msgContents, FUNAMBOL_CONFIG_TEXT, strlen(FUNAMBOL_CONFIG_TEXT));
-}
-
-CTDL_MODULE_INIT(funambol)
-{
-       if (!threading)
-       {
-               create_notify_queue();
-               CtdlRegisterSessionHook(do_notify_queue, EVT_TIMER);
-       }
-       /* return our Subversion id for the Log */
-        return "$Id$";
-}
diff --git a/citadel/modules/funambol/serv_funambol.h b/citadel/modules/funambol/serv_funambol.h
deleted file mode 100644 (file)
index 209fb9b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-void notify_funambol(long msgnum, void *userdata);
diff --git a/citadel/modules/pager/serv_pager.c b/citadel/modules/pager/serv_pager.c
deleted file mode 100644 (file)
index 3570856..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * \file serv_pager.c
- * @author Mathew McBride
- * 
- * This module implements an external pager hook for when notifcation
- * of a new email is wanted.
- * Based on bits of serv_funambol
- * Contact: <matt@mcbridematt.dhs.org> / <matt@comalies>
- */
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <pwd.h>
-#include <errno.h>
-#include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#include <sys/wait.h>
-#include <string.h>
-#include <limits.h>
-#include <sys/socket.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "server.h"
-#include "citserver.h"
-#include "support.h"
-#include "config.h"
-#include "control.h"
-#include "room_ops.h"
-#include "user_ops.h"
-#include "policy.h"
-#include "database.h"
-#include "msgbase.h"
-#include "internet_addressing.h"
-#include "domain.h"
-#include "clientsocket.h"
-#include "serv_pager.h"
-
-#include "ctdl_module.h"
-
-#define PAGER_CONFIG_MESSAGE "__ Push email settings __"
-#define PAGER_CONFIG_TEXT  "textmessage"
-
-/*! \brief Create the notify message queue. We use the exact same room 
- *                     as the Funambol module. 
- *
- *     Run at server startup, creates FNBL_QUEUE_ROOM if it doesn't exist
- *     and sets as system room. 
- */
-void create_pager_queue(void) {
-       struct ctdlroom qrbuf;
-
-       create_room(FNBL_QUEUE_ROOM, 3, "", 0, 1, 0, VIEW_MAILBOX);
-
-       /*
-        * Make sure it's set to be a "system room" so it doesn't show up
-        * in the <K>nown rooms list for Aides.
-        */
-       if (lgetroom(&qrbuf, FNBL_QUEUE_ROOM) == 0) {
-               qrbuf.QRflags2 |= QR2_SYSTEM;
-               lputroom(&qrbuf);
-       }
-}
-/*! 
- * \brief Run through the pager room queue
- */
-void do_pager_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_DEBUG, "serv_pager: 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_pager, NULL);
-
-       lprintf(CTDL_DEBUG, "serv_pager: queue run completed\n");
-       doing_queue = 0;
-}
-
-/*!
- * \brief Call the external pager tool as set by the administrator
- * @param msgnum The message number of the 'hint' message passed from do_pager_queue
- * @param userdata userdata struct as passed by CtdlForEachMessage
- *
- */
-void notify_pager(long msgnum, void *userdata) {
-       struct CtdlMessage *msg;
-       
-       /* W means 'wireless', which contains the unix name */
-       msg = CtdlFetchMessage(msgnum, 1);
-       if ( msg->cm_fields['W'] == NULL) {
-               goto nuke;
-       }
-       /* Are we allowed to push? */
-       if (IsEmptyStr(config.c_pager_program)) {
-               return;
-       } else if (IsEmptyStr(config.c_pager_program) && IsEmptyStr(config.c_funambol_host)) {
-               goto nuke;
-       } else {
-               lprintf(CTDL_INFO, "Pager alerter enabled\n");  
-       }
-
-       /* Get the configuration. We might be allowed system wide but the user
-               may have configured otherwise */
-       long configMsgNum = pager_getConfigMessage(msg->cm_fields['W']);
-       int allowed = pager_isPagerAllowedByPrefs(configMsgNum);
-       if (allowed != 0 && pager_doesUserWant(configMsgNum) == 0) {
-               goto nuke;
-       } else if (allowed != 0) {
-               return;
-       }
-       char *num = pager_getUserPhoneNumber(configMsgNum);
-       char command[SIZ];
-       snprintf(command, sizeof command, "%s %s -u %s", config.c_pager_program, num, msg->cm_fields['W']);
-       system(command);
-       
-       nuke:
-       CtdlFreeMessage(msg);
-       long todelete[1];
-       todelete[0] = msgnum;
-       CtdlDeleteMessages(FNBL_QUEUE_ROOM, todelete, 1, "");
-}
-/*! \brief Get configuration message for pager/funambol system from the 
- *                     users "My Citadel Config" room
- */
-long pager_getConfigMessage(char *username) {
-       struct ctdlroom qrbuf; // scratch for room
-       struct ctdluser user; // ctdl user instance
-       char configRoomName[ROOMNAMELEN];
-       struct CtdlMessage *msg;
-       struct cdbdata *cdbfr;
-       long *msglist = NULL;
-       int num_msgs = 0;
-       long confMsgNum = -1;
-       // Get the user
-       getuser(&user, username);
-       
-       MailboxName(configRoomName, sizeof configRoomName, &user, USERCONFIGROOM);
-       // Fill qrbuf
-       getroom(&qrbuf, configRoomName);
-       /* Do something really, really stoopid here. Raid the room on ourselves,
-               loop through the messages manually and find it. I don't want 
-               to use a CtdlForEachMessage callback here, as we would be 
-               already in one */
-       cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long));
-       if (cdbfr != NULL) {
-               msglist = (long *) cdbfr->ptr;
-               cdbfr->ptr = NULL;      /* CtdlForEachMessage() now owns this memory */
-               num_msgs = cdbfr->len / sizeof(long);
-               cdb_free(cdbfr);
-       } else {
-               lprintf(CTDL_DEBUG, "pager_getConfigMessage: No config messages found\n");
-               return -1;      /* No messages at all?  No further action. */
-       }
-       int a;
-       for (a = 0; a < num_msgs; ++a) {
-                               msg = CtdlFetchMessage(msglist[a], 1);
-                               if (msg != NULL) {
-                                       if (msg->cm_fields['U'] != NULL && strncasecmp(msg->cm_fields['U'], PAGER_CONFIG_MESSAGE, 
-                                               strlen(PAGER_CONFIG_MESSAGE)) == 0) {
-                                               confMsgNum = msglist[a];
-                                       }
-                                       CtdlFreeMessage(msg);
-                               }
-       }
-       return confMsgNum;
-
-}
-int pager_isPagerAllowedByPrefs(long configMsgNum) {
-       // Do a simple string search to see if 'textmessage' is selected as the 
-       // type. This string would be at the very top of the message contents.
-       if (configMsgNum == -1) {
-               return -1;
-       }
-       struct CtdlMessage *prefMsg;
-       prefMsg = CtdlFetchMessage(configMsgNum, 1);
-       char *msgContents = prefMsg->cm_fields['M'];
-       return strncasecmp(msgContents, PAGER_CONFIG_TEXT, strlen(PAGER_CONFIG_TEXT));
-}
-int pager_doesUserWant(long configMsgNum) {
-       if (configMsgNum == -1) {
-               return -1;
-       }
-       struct CtdlMessage *prefMsg;
-       prefMsg = CtdlFetchMessage(configMsgNum, 1);
-       char *msgContents = prefMsg->cm_fields['M'];
-       return strncasecmp(msgContents, "none", 4);
-}
-       /* warning: fetching twice gravely inefficient, will fix some time */
-char *pager_getUserPhoneNumber(long configMsgNum) {
-       if (configMsgNum == -1) {
-               return NULL;
-       }
-       struct CtdlMessage *prefMsg;
-       prefMsg = CtdlFetchMessage(configMsgNum, 1);
-       char *msgContents = prefMsg->cm_fields['M'];
-       char *lines = strtok(msgContents, "textmessage\n");
-       return lines;
-}
-CTDL_MODULE_INIT(pager)
-{
-       if (!threading)
-       {
-               create_pager_queue();
-               CtdlRegisterSessionHook(do_pager_queue, EVT_TIMER);
-       }
-       
-       /* return our Subversion id for the Log */
-        return "$Id: serv_pager.c $";
-}
diff --git a/citadel/serv_pager.h b/citadel/serv_pager.h
deleted file mode 100644 (file)
index 40a3b88..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/** 
- * \file serv_pager.h
- * @author Mathew McBride 
- *
- * Header file for serv_pager
- * Note some of these functions are also used by serv_funambol, so
- * this file needs to live in the top dir
- */
-void notify_pager(long msgnum, void *userdata);
-long pager_getConfigMessage(char *username);
-int pager_isPagerAllowedByPrefs(long configMsgNum);
-char *pager_getUserPhoneNumber(long configMsgNum);
-int pager_isPagerAllowedByPrefs(long configMsgNum);
-int pager_doesUserWant(long configMsgNum);