]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/extnotify/extnotify_main.c
* migrate extnotify to libcurl
[citadel.git] / citadel / modules / extnotify / extnotify_main.c
index 20d40a04ef57fe1a82b92baa73af83a316a0edea..0e2731d1a757b9b605a2d68e11d99f9d97ee93d3 100644 (file)
@@ -90,16 +90,16 @@ void do_extnotify_queue(void) {
     /*
      * Go ahead and run the queue
      */
-    lprintf(CTDL_DEBUG, "serv_extnotify: processing notify queue\n");
+    CtdlLogPrintf(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);
+        CtdlLogPrintf(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");
+    CtdlLogPrintf(CTDL_DEBUG, "serv_extnotify: queue run completed\n");
     doing_queue = 0;
 }
 /*!
@@ -115,7 +115,7 @@ void process_notify(long msgnum, void *usrdata) {
     long configMsgNum = extNotify_getConfigMessage(msg->cm_fields['W']);
     char configMsg[SIZ];
     
-    extNotify_getPrefs(configMsgNum, &configMsg);
+    extNotify_getPrefs(configMsgNum, &configMsg[0]);
     
     /* Check to see if:
      * 1. The user has configured paging / They have and disabled it
@@ -123,25 +123,48 @@ void process_notify(long msgnum, void *usrdata) {
      * 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");
+    if ((configMsgNum == -1) || 
+       ((strncasecmp(configMsg, "none", 4) == 0) &&
+        IsEmptyStr(config.c_pager_program) && 
+        IsEmptyStr(config.c_funambol_host))) {
+        CtdlLogPrintf(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)); 
+    int fnblAllowed = strncasecmp(configMsg, HKEY(FUNAMBOL_CONFIG_TEXT));
+    int extPagerAllowedHttp = strncasecmp(configMsg, HKEY(PAGER_CONFIG_HTTP)); 
+    int extPagerAllowedSystem = strncasecmp(configMsg, HKEY(PAGER_CONFIG_SYSTEM));
     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);
+           char remoteurl[SIZ];
+           snprintf(remoteurl, SIZ, "http://%s@%s:%d/%s",
+                    config.c_funambol_auth,
+                    config.c_funambol_host,
+                    config.c_funambol_port,
+                    FUNAMBOL_WS);
+           notify_http_server(remoteurl, 
+                              file_funambol_msg,
+                              strlen(file_funambol_msg),/*GNA*/
+                              msg->cm_fields['W'], 
+                                  msg->cm_fields['I'],
+                                  msgnum);
+    } else if (extPagerAllowedHttp) {
+/*
+           notify_http_server(remoteurl, 
+                              file_funambol_msg,
+                              strlen(file_funambol_msg),/ *GNA* /
+                              msg->cm_fields['W'], 
+                                  msg->cm_fields['I'],
+                                  msgnum);
+*/
+    } else if (extPagerAllowedSystem == 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:
+nuke:
     CtdlFreeMessage(msg);
     memset(configMsg, 0, sizeof(configMsg));
     long todelete[1];
@@ -152,18 +175,17 @@ void process_notify(long msgnum, void *usrdata) {
 /*! \brief Checks to see what notification option the user has set
  *
  */
-char *extNotify_getPrefs(long configMsgNum, char *configMsg) {
+void 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";
+        CtdlLogPrintf(CTDL_ERR, "extNotify_isAllowedByPrefs was passed a non-existant config message id\n");
+        return;
     }
     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
@@ -194,7 +216,7 @@ long extNotify_getConfigMessage(char *username) {
         num_msgs = cdbfr->len / sizeof(long);
         cdb_free(cdbfr);
     } else {
-        lprintf(CTDL_DEBUG, "extNotify_getConfigMessage: No config messages found\n");
+        CtdlLogPrintf(CTDL_DEBUG, "extNotify_getConfigMessage: No config messages found\n");
         return -1;     /* No messages at all?  No further action. */
     }
     int a;
@@ -219,5 +241,5 @@ CTDL_MODULE_INIT(extnotify)
                CtdlRegisterSessionHook(do_extnotify_queue, EVT_TIMER);
        }
        /* return our Subversion id for the Log */
-        return "$Id:  $";
+        return "$Id$";
 }