the 'pager' and 'funambol' modules.
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;
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);
DBG_PRINT(file_crpt_file_cer);
DBG_PRINT(file_chkpwd);
DBG_PRINT(file_base64);
+ DBG_PRINT(file_funambol_msg);
}
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);
--- /dev/null
+/*
+ * 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
+
+
--- /dev/null
+/*
+ * \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
--- /dev/null
+/*
+* \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;
+}
+
+++ /dev/null
-/*
- * 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/\"><?xml version="1.0" encoding="UTF-8"?>\r\n");
- strcat(SOAPData, "<java version="1.5.0_10" class="java.beans.XMLDecoder"> \r\n");
- strcat(SOAPData, " <array class="com.funambol.framework.core.Alert" length="1">\r\n");
- strcat(SOAPData, " <void index="0">\r\n");
- strcat(SOAPData, " <object class="com.funambol.framework.core.Alert">\r\n");
- strcat(SOAPData, " <void property="cmdID">\r\n");
- strcat(SOAPData, " <object class="com.funambol.framework.core.CmdID"/>\r\n");
- strcat(SOAPData, " </void>");
- strcat(SOAPData, " <void property="data">\r\n");
- strcat(SOAPData, " <int>210</int>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " <void property="items">\r\n");
- strcat(SOAPData, " <void method="add">\r\n");
- strcat(SOAPData, " <object class="com.funambol.framework.core.Item">\r\n");
- strcat(SOAPData, " <void property="meta">\r\n");
- strcat(SOAPData, " <object class="com.funambol.framework.core.Meta">\r\n");
- strcat(SOAPData, " <void property="metInf">\r\n");
- strcat(SOAPData, " <void property="type">\r\n");
- strcat(SOAPData, " <string>application/vnd.omads-email+xml</string>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " </object>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " <void property="target">\r\n");
- strcat(SOAPData, " <object class="com.funambol.framework.core.Target">\r\n");
- strcat(SOAPData, " <void property="locURI">\r\n");
- strcat(SOAPData, " <string>");
- strcat(SOAPData, config.c_funambol_source);
- strcat(SOAPData, "</string>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " </object>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " </object>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " </object>\r\n");
- strcat(SOAPData, " </void>\r\n");
- strcat(SOAPData, " </array>\r\n");
- strcat(SOAPData, "</java>");
- 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$";
-}
+++ /dev/null
-void notify_funambol(long msgnum, void *userdata);
+++ /dev/null
-/*
- * \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 $";
-}
+++ /dev/null
-/**
- * \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);