-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);
- }
+eNotifyType extNotify_getConfigMessage(char *username,
+ char **PagerNumber,
+ char **FreeMe)
+{
+ struct ctdlroom qrbuf; // scratch for room
+ struct ctdluser user; // ctdl user instance
+ char configRoomName[ROOMNAMELEN];
+ struct CtdlMessage *msg = NULL;
+ struct cdbdata *cdbfr;
+ long *msglist = NULL;
+ int num_msgs = 0;
+ int a;
+ char *configMsg;
+ long clen;
+ char *pch;
+
+ // Get the user
+ CtdlGetUser(&user, username);
+
+ CtdlMailboxName(configRoomName,
+ sizeof(configRoomName),
+ &user,
+ USERCONFIGROOM);
+ // Fill qrbuf
+ CtdlGetRoom(&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 {
+ syslog(LOG_DEBUG,
+ "extNotify_getConfigMessage: "
+ "No config messages found\n");
+ return eNone; /* No messages at all? No further action. */
+ }
+ for (a = 0; a < num_msgs; ++a) {
+ msg = CtdlFetchMessage(msglist[a], 1);
+ if (msg != NULL) {
+ if (!CM_IsEmpty(msg, eMsgSubject) &&
+ (strncasecmp(msg->cm_fields[eMsgSubject],
+ PAGER_CONFIG_MESSAGE,
+ strlen(PAGER_CONFIG_MESSAGE)) == 0))
+ {
+ break;
+ }
+ CM_Free(msg);
+ msg = NULL;
+ }
+ }
+
+ free(msglist);
+ if (msg == NULL)
+ return eNone;
+
+ // 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.
+
+ CM_GetAsField(msg, eMesageText, &configMsg, &clen);
+ CM_Free(msg);
+
+ /* here we would find the pager number... */
+ pch = strchr(configMsg, '\n');
+ if (pch != NULL)
+ {
+ *pch = '\0';
+ pch ++;
+ }
+
+ /* 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 (!strncasecmp(configMsg, "none", 4))
+ {
+ free(configMsg);
+ return eNone;
+ }
+
+ if (!strncasecmp(configMsg, HKEY(PAGER_CONFIG_HTTP)))
+ {
+ free(configMsg);
+ return eHttpMessages;
+ }
+ if (!strncasecmp(configMsg, HKEY(FUNAMBOL_CONFIG_TEXT)))
+ {
+ free(configMsg);
+ return eFunambol;
+ }
+ else if (!strncasecmp(configMsg, HKEY(PAGER_CONFIG_SYSTEM)))
+ {
+ // whats the pager number?
+ if (!pch || (*pch == '\0'))
+ {
+ free(configMsg);
+
+ return eNone;
+ }
+ while (isspace(*pch))
+ pch ++;
+ *PagerNumber = pch;
+ while (isdigit(*pch) || (*pch == '+'))
+ pch++;
+ *pch = '\0';
+ *FreeMe = configMsg;
+ return eTextMessage;
+ }
+
+ free(configMsg);
+ return eNone;