Back to index

webcit  8.12-dfsg
pushemail.c
Go to the documentation of this file.
00001 /*
00002  * Edits a users push email settings 
00003  * Author: Mathew McBride <matt@mcbridematt.dhs.org>
00004  */
00005 #include "webcit.h"
00006 
00007 void display_pushemail(void) 
00008 {
00009        folder Room;
00010        int Done = 0;
00011        StrBuf *Buf;
00012        long vector[8] = {8, 0, 0, 1, 2, 3, 4, 5};
00013        WCTemplputParams SubTP;
00014        char mobnum[20];
00015 
00016        memset(&SubTP, 0, sizeof(WCTemplputParams));
00017        SubTP.Filter.ContextType = CTX_LONGVECTOR;
00018        SubTP.Context = &vector;
00019        vector[0] = 16;
00020 
00021        /* Find any existing settings*/
00022        Buf = NewStrBuf();
00023        memset(&Room, 0, sizeof(folder));
00024        if (goto_config_room(Buf, &Room) == 0) {
00025               int msgnum = 0;
00026               serv_puts("MSGS ALL|0|1");
00027               StrBuf_ServGetln(Buf);
00028               if (GetServerStatus(Buf, NULL) == 8) {
00029                      serv_puts("subj|__ Push email settings __");
00030                      serv_puts("000");
00031                      while (!Done &&
00032                             StrBuf_ServGetln(Buf) >= 0) {
00033                             if ( (StrLength(Buf)==3) && 
00034                                  !strcmp(ChrPtr(Buf), "000")) {
00035                                    Done = 1;
00036                                    break;
00037                             }
00038                             msgnum = StrTol(Buf);
00039                      }
00040               }
00041               if (msgnum > 0L) {
00042               serv_printf("MSG0 %d", msgnum);
00043               StrBuf_ServGetln(Buf);
00044               if (GetServerStatus(Buf, NULL) == 1) {
00045                      int i =0;
00046                      Done = 0;
00047                      while (!Done &&
00048                             StrBuf_ServGetln(Buf) >= 0) {
00049                             if (( (StrLength(Buf)==3) && 
00050                                   !strcmp(ChrPtr(Buf), "000"))||
00051                                 ((StrLength(Buf)==4) && 
00052                                  !strcmp(ChrPtr(Buf), "text")))
00053                             {
00054                                    Done = 1;
00055                                    break;
00056                             }
00057                      }
00058                      if (!strcmp(ChrPtr(Buf), "text")) {
00059                             Done = 0;
00060                             while (!Done &&
00061                                    StrBuf_ServGetln(Buf) >= 0) {
00062                                    if ( (StrLength(Buf)==3) && 
00063                                         !strcmp(ChrPtr(Buf), "000")) {
00064                                           Done = 1;
00065                                           break;
00066                                    }
00067                                    if (strncasecmp(ChrPtr(Buf), "none", 4) == 0) {
00068                                           vector[1] = 0;
00069                                    } else if (strncasecmp(ChrPtr(Buf), "textmessage", 11) == 0) {
00070                                           vector[1] = 1;
00071                                           i++;
00072                                    } else if (strncasecmp(ChrPtr(Buf), "funambol", 8) == 0) {
00073                                           vector[1] = 2;
00074                                    } else if (strncasecmp(ChrPtr(Buf), "httpmessage", 12) == 0) {
00075                                           vector[1] = 3;
00076                                    } else if (i == 1) {
00077                                           strncpy(mobnum, ChrPtr(Buf), 20);
00078                                           i++;
00079                                    }
00080                             }      
00081                      }
00082               }
00083               }
00084               serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
00085               StrBuf_ServGetln(Buf);
00086               GetServerStatus(Buf, NULL);
00087        }
00088        FlushFolder(&Room);
00089        output_headers(1, 1, 1, 0, 0, 0);
00090        DoTemplate(HKEY("prefs_pushemail"), NULL, &SubTP);
00091        wDumpContent(1);
00092        FreeStrBuf(&Buf);
00093 }
00094 
00095 void save_pushemail(void) 
00096 {
00097        folder Room;
00098        int Done = 0;
00099        StrBuf *Buf;
00100        char buf[SIZ];
00101        int msgnum = 0;
00102        char *pushsetting = bstr("pushsetting");
00103        char *sms = NULL;
00104 
00105        if (strncasecmp(pushsetting, "textmessage", 11) == 0) {
00106               sms = bstr("user_sms_number");
00107        }
00108        Buf = NewStrBuf();
00109        memset(&Room, 0, sizeof(folder));
00110        if (goto_config_room(Buf, &Room) != 0) {
00111               FreeStrBuf(&Buf);
00112               FlushFolder(&Room);
00113               return;       /* oh well. */
00114        }
00115        FlushFolder(&Room);
00116 
00117        serv_puts("MSGS ALL|0|1");
00118        StrBuf_ServGetln(Buf);
00119        if (GetServerStatus(Buf, NULL) == 8) {
00120               serv_puts("subj|__ Push email settings __");
00121               serv_puts("000");
00122        } else {
00123               printf("Junk in save_pushemail buffer!: %s\n", buf);
00124               FreeStrBuf(&Buf);
00125               return;
00126        }
00127 
00128        while (!Done &&
00129               StrBuf_ServGetln(Buf) >= 0) {
00130               if ( (StrLength(Buf)==3) && 
00131                    !strcmp(ChrPtr(Buf), "000")) {
00132                      Done = 1;
00133                      break;
00134               }
00135               msgnum = StrTol(Buf);
00136        }
00137 
00138        if (msgnum > 0L) {
00139               serv_printf("DELE %d", msgnum);
00140               StrBuf_ServGetln(Buf);
00141               GetServerStatus(Buf, NULL);
00142        }
00143 
00144        serv_printf("ENT0 1||0|1|__ Push email settings __|");
00145        StrBuf_ServGetln(Buf);
00146        if (GetServerStatus(Buf, NULL) == 4) {
00147               serv_puts(pushsetting);
00148               if (sms != NULL) {
00149               serv_puts(sms);
00150               } 
00151               serv_puts("");
00152               serv_puts("000");
00153        }
00154 
00156        serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
00157        StrBuf_ServGetln(Buf);
00158        GetServerStatus(Buf, NULL);
00159        http_redirect("display_pushemail");
00160        FreeStrBuf(&Buf);
00161 }
00162 
00163 void 
00164 InitModule_PUSHMAIL
00165 (void)
00166 {
00167        WebcitAddUrlHandler(HKEY("display_pushemail"), "", 0, display_pushemail, 0);
00168        WebcitAddUrlHandler(HKEY("save_pushemail"), "", 0, save_pushemail, 0);
00169 }