X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fextnotify%2Fextnotify_main.c;fp=citadel%2Fmodules%2Fextnotify%2Fextnotify_main.c;h=123a8771b704cbb2e0c6b4b4da70dbf7c187d9a8;hb=66f72c07b70ed9500c49e8ff3c3f895e5269d339;hp=3029322950dc79f66fdd7a2909d8911cf31c8c44;hpb=25743b6534e474b532dfe17167ce925bd94e163c;p=citadel.git diff --git a/citadel/modules/extnotify/extnotify_main.c b/citadel/modules/extnotify/extnotify_main.c index 302932295..123a8771b 100644 --- a/citadel/modules/extnotify/extnotify_main.c +++ b/citadel/modules/extnotify/extnotify_main.c @@ -77,10 +77,10 @@ void ExtNotify_PutErrorMessage(NotifyContext *Ctx, StrBuf *ErrMsg) Ctx->NotifyErrors = NewHash(1, Flathash); nNext = GetCount(Ctx->NotifyErrors) + 1; - Put(Ctx->NotifyErrors, - (char*)&nNext, - sizeof(int), - ErrMsg, + Put(Ctx->NotifyErrors, + (char*)&nNext, + sizeof(int), + ErrMsg, HFreeStrBuf); } @@ -107,20 +107,24 @@ int GetNotifyHosts(NotifyContext *Ctx) if (Ctx->nNotifyHosts < 1) return 0; - Ctx->NotifyHostList = malloc(sizeof(StrBuf*) * 2 * (Ctx->nNotifyHosts + 1)); - memset(Ctx->NotifyHostList, 0, sizeof(StrBuf*) * 2 * (Ctx->nNotifyHosts + 1)); - + Ctx->NotifyHostList = malloc(sizeof(StrBuf*) * + 2 * + (Ctx->nNotifyHosts + 1)); + memset(Ctx->NotifyHostList, 0, + sizeof(StrBuf*) * 2 * (Ctx->nNotifyHosts + 1)); + NotifyBuf = NewStrBufPlain(NotifyHostsBuf, -1); /* get all configured notifiers's */ - for (notify=0; notifynNotifyHosts; notify++) { - + for (notify=0; notifynNotifyHosts; notify++) { + Host = GetNHBuf(notify * 2, 1, Ctx->NotifyHostList); StrBufExtract_NextToken(Host, NotifyBuf, &NextHost, '|'); pchs = ChrPtr(Host); pche = strchr(pchs, ':'); if (pche == NULL) { - syslog(LOG_ERR, - "extnotify: filename of notification template not found in %s.\n", + syslog(LOG_ERR, + "extnotify: filename of notification " + "template not found in %s.\n", pchs); continue; } @@ -137,7 +141,9 @@ int GetNotifyHosts(NotifyContext *Ctx) /*! \brief Get configuration message for pager/funambol system from the * users "My Citadel Config" room */ -eNotifyType extNotify_getConfigMessage(char *username, char **PagerNumber, char **FreeMe) +eNotifyType extNotify_getConfigMessage(char *username, + char **PagerNumber, + char **FreeMe) { struct ctdlroom qrbuf; // scratch for room struct ctdluser user; // ctdl user instance @@ -152,8 +158,11 @@ eNotifyType extNotify_getConfigMessage(char *username, char **PagerNumber, char // Get the user CtdlGetUser(&user, username); - - CtdlMailboxName(configRoomName, sizeof configRoomName, &user, USERCONFIGROOM); + + CtdlMailboxName(configRoomName, + sizeof(configRoomName), + &user, + USERCONFIGROOM); // Fill qrbuf CtdlGetRoom(&qrbuf, configRoomName); /* Do something really, really stoopid here. Raid the room on ourselves, @@ -163,26 +172,31 @@ eNotifyType extNotify_getConfigMessage(char *username, char **PagerNumber, char cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long)); if (cdbfr != NULL) { msglist = (long *) cdbfr->ptr; - cdbfr->ptr = NULL; /* CtdlForEachMessage() now owns this memory */ + 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"); + 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 ((msg->cm_fields['U'] != NULL) && - (strncasecmp(msg->cm_fields['U'], PAGER_CONFIG_MESSAGE, - strlen(PAGER_CONFIG_MESSAGE)) == 0)) { + if ((msg->cm_fields['U'] != NULL) && + (strncasecmp(msg->cm_fields['U'], + PAGER_CONFIG_MESSAGE, + strlen(PAGER_CONFIG_MESSAGE)) == 0)) + { break; } CtdlFreeMessage(msg); msg = NULL; } } - + free(msglist); if (msg == NULL) return eNone; @@ -230,10 +244,10 @@ eNotifyType extNotify_getConfigMessage(char *username, char **PagerNumber, char if (!pch || (*pch == '\0')) { free(configMsg); - + return eNone; } - while (isspace(*pch)) + while (isspace(*pch)) pch ++; *PagerNumber = pch; while (isdigit(*pch) || (*pch == '+')) @@ -251,7 +265,7 @@ eNotifyType extNotify_getConfigMessage(char *username, char **PagerNumber, char /* * Process messages in the external notification queue */ -void process_notify(long NotifyMsgnum, void *usrdata) +void process_notify(long NotifyMsgnum, void *usrdata) { NotifyContext *Ctx; long msgnum = 0; @@ -267,12 +281,15 @@ void process_notify(long NotifyMsgnum, void *usrdata) Ctx = (NotifyContext*) usrdata; msg = CtdlFetchMessage(NotifyMsgnum, 1); - if ( msg->cm_fields['2'] != NULL) + if ( msg->cm_fields['2'] != NULL) { - Type = extNotify_getConfigMessage(msg->cm_fields['2'], &PagerNo, &FreeMe); - + Type = extNotify_getConfigMessage( + msg->cm_fields['2'], + &PagerNo, + &FreeMe); + pch = strstr(msg->cm_fields['M'], "msgid|"); - if (pch != NULL) + if (pch != NULL) msgnum = atol(pch + sizeof("msgid")); switch (Type) @@ -284,12 +301,12 @@ void process_notify(long NotifyMsgnum, void *usrdata) config.c_funambol_port, FUNAMBOL_WS); - notify_http_server(remoteurl, + notify_http_server(remoteurl, file_funambol_msg, strlen(file_funambol_msg),/*GNA*/ - msg->cm_fields['2'], + msg->cm_fields['2'], msg->cm_fields['I'], - msgnum, + msgnum, NULL); break; case eHttpMessages: @@ -299,42 +316,53 @@ void process_notify(long NotifyMsgnum, void *usrdata) char URLBuf[SIZ]; StrBuf *File; StrBuf *FileBuf = NewStrBuf(); - + for (i = 0; i < Ctx->nNotifyHosts; i++) { URL = GetNHBuf(i*2, 0, Ctx->NotifyHostList); if (URL==NULL) break; - File = GetNHBuf(i*2 + 1, 0, Ctx->NotifyHostList); + File = GetNHBuf(i*2 + 1, 0, + Ctx->NotifyHostList); if (File==NULL) break; if (StrLength(File)>0) - StrBufPrintf(FileBuf, "%s/%s", - ctdl_shared_dir, + StrBufPrintf(FileBuf, "%s/%s", + ctdl_shared_dir, ChrPtr(File)); else FlushStrBuf(FileBuf); memcpy(URLBuf, ChrPtr(URL), StrLength(URL) + 1); - notify_http_server(URLBuf, + notify_http_server(URLBuf, ChrPtr(FileBuf), StrLength(FileBuf), - msg->cm_fields['2'], + msg->cm_fields['2'], msg->cm_fields['I'], - msgnum, + msgnum, NULL); } FreeStrBuf(&FileBuf); - } + } break; case eTextMessage: { int commandSiz; char *command; - commandSiz = sizeof(config.c_pager_program) + strlen(PagerNo) + strlen(msg->cm_fields['2']) + 5; + commandSiz = sizeof(config.c_pager_program) + + strlen(PagerNo) + + strlen(msg->cm_fields['2']) + 5; + command = malloc(commandSiz); - snprintf(command, commandSiz, "%s %s -u %s", config.c_pager_program, PagerNo, msg->cm_fields['2']); + + snprintf(command, + commandSiz, + "%s %s -u %s", + config.c_pager_program, + PagerNo, + msg->cm_fields['2']); + system(command); free(command); } @@ -354,26 +382,29 @@ void process_notify(long NotifyMsgnum, void *usrdata) * \brief Run through the pager room queue * Checks to see what notification option the user has set */ -void do_extnotify_queue(void) +void do_extnotify_queue(void) { NotifyContext Ctx; static int doing_queue = 0; int i = 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 (IsEmptyStr(config.c_pager_program) && + if (IsEmptyStr(config.c_pager_program) && IsEmptyStr(config.c_funambol_host)) { - syslog(LOG_ERR, "No external notifiers configured on system/user\n"); + syslog(LOG_ERR, + "No external notifiers configured on system/user\n"); return; } - if (doing_queue) return; + if (doing_queue) + return; + doing_queue = 1; become_session(&extnotify_queue_CC); @@ -386,7 +417,7 @@ void do_extnotify_queue(void) syslog(LOG_DEBUG, "serv_extnotify: processing notify queue\n"); memset(&Ctx, 0, sizeof(NotifyContext)); - if ((GetNotifyHosts(&Ctx) > 0) && + if ((GetNotifyHosts(&Ctx) > 0) && (CtdlGetRoom(&CC->room, FNBL_QUEUE_ROOM) != 0)) { syslog(LOG_ERR, "Cannot find room <%s>\n", FNBL_QUEUE_ROOM); @@ -420,11 +451,11 @@ void do_extnotify_queue(void) */ void create_extnotify_queue(void) { struct ctdlroom qrbuf; - + CtdlCreateRoom(FNBL_QUEUE_ROOM, 3, "", 0, 1, 0, VIEW_MAILBOX); - CtdlFillSystemContext(&extnotify_queue_CC, "Extnotify"); - + CtdlFillSystemContext(&extnotify_queue_CC, "Extnotify"); + /* * Make sure it's set to be a "system room" so it doesn't show up * in the nown rooms list for Aides. @@ -444,5 +475,5 @@ CTDL_MODULE_INIT(extnotify) CtdlRegisterSessionHook(do_extnotify_queue, EVT_TIMER); } /* return our module name for the log */ - return "extnotify"; + return "extnotify"; }