* remove more serv_readln etc...
authorWilfried Göesgens <willi@citadel.org>
Mon, 4 May 2009 22:22:10 +0000 (22:22 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 4 May 2009 22:22:10 +0000 (22:22 +0000)
webcit/auth.c
webcit/preferences.c
webcit/pushemail.c
webcit/webcit.h

index 56228f7b7fc41033aa698d6be51307f94d4a42b9..5d24144f1fbf30ba9b40ce9dad60f2d3fc45aab4 100644 (file)
@@ -740,16 +740,20 @@ void validate(void)
  */
 void display_reg(int during_login)
 {
+       StrBuf *Buf;
        message_summary *VCMsg;
        wc_mime_attachment *VCAtt;
        long vcard_msgnum;
 
-       if (goto_config_room() != 0) {
+       Buf = NewStrBuf();
+       if (goto_config_room(Buf) != 0) {
                if (during_login) do_welcome();
                else display_main_menu();
+               FreeStrBuf(&Buf);
                return;
        }
 
+       FreeStrBuf(&Buf);
        vcard_msgnum = locate_user_vcard_in_this_room(&VCMsg, &VCAtt);
        if (vcard_msgnum < 0L) {
                if (during_login) do_welcome();
index 36cf40d4f763fca031f0db317f6b61f3a9e39539..1ea2dac99ce3faffad773ee8285fed0d31965a44 100644 (file)
@@ -147,12 +147,18 @@ void GetPrefTypes(HashList *List)
 
 void ParsePref(HashList **List, StrBuf *ReadBuf)
 {
+       int Done = 0;
        Preference *Data = NULL;
        Preference *LastData = NULL;
                                
-       while (StrBuf_ServGetln(ReadBuf), 
-              strcmp(ChrPtr(ReadBuf), "000")) 
+       while (!Done && StrBuf_ServGetln(ReadBuf))
        {
+               if ( (StrLength(ReadBuf)==3) && 
+                    !strcmp(ChrPtr(ReadBuf), "000")) {
+                       Done = 1;
+                       break;
+               }
+
                if ((ChrPtr(ReadBuf)[0] == ' ') &&
                    (Data != NULL)) {
                        StrBufAppendBuf(Data->Val, ReadBuf, 1);
@@ -194,9 +200,12 @@ void load_preferences(void)
        StrBuf *ReadBuf;
        long msgnum = 0L;
        
-       if (goto_config_room() != 0) return;    /* oh well. */
-
        ReadBuf = NewStrBuf();
+       if (goto_config_room(ReadBuf) != 0) {
+               FreeStrBuf(&ReadBuf);
+               return; /* oh well. */
+       }
+
        serv_puts("MSGS ALL|0|1");
        StrBuf_ServGetln(ReadBuf);
        if (GetServerStatus(ReadBuf, NULL) == 8) {
@@ -238,17 +247,19 @@ void load_preferences(void)
  * \brief Goto the user's configuration room, creating it if necessary.
  * \return 0 on success or nonzero upon failure.
  */
-int goto_config_room(void) {
-       char buf[SIZ];
-
+int goto_config_room(StrBuf *Buf) 
+{
        serv_printf("GOTO %s", USERCONFIGROOM);
-       serv_getln(buf, sizeof buf);
-       if (buf[0] != '2') { /* try to create the config room if not there */
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
                serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
-               serv_getln(buf, sizeof buf);
+               StrBuf_ServGetln(Buf);
+               GetServerStatus(Buf, NULL);
+
                serv_printf("GOTO %s", USERCONFIGROOM);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] != '2') return(1);
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) != 2) 
+                       return(1);
        }
        return(0);
 }
@@ -318,7 +329,10 @@ void save_preferences(void)
        long msgnum = 0L;
        
        ReadBuf = NewStrBuf();
-       if (goto_config_room() != 0) return;    /* oh well. */
+       if (goto_config_room(ReadBuf) != 0) {
+               FreeStrBuf(&ReadBuf);
+               return; /* oh well. */
+       }
        serv_puts("MSGS ALL|0|1");
        StrBuf_ServGetln(ReadBuf);
        if (GetServerStatus(ReadBuf, NULL) == 8) {
index 5c55ddc390224c2ae53f7cf32b01acd04f28ab5e..bc6a340dfc5a596102bf0a4b591fa108b9c11dd1 100644 (file)
  */
 #include "webcit.h"
 
-void display_pushemail(void) {
-       char buf[SIZ];
+void display_pushemail(void) 
+{
+       int Done = 0;
+       StrBuf *Buf;
        int is_none = 0;
        int is_pager = 0;
        int is_funambol = 0;
        char mobnum[20];
 
        /* Find any existing settings*/
-       if (goto_config_room() == 0) {
+       Buf = NewStrBuf();
+       if (goto_config_room(Buf) == 0) {
                int msgnum = 0;
                serv_puts("MSGS ALL|0|1");
-               serv_getln(buf, sizeof(buf));
-               if (buf[0] == '8') {
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 8) {
                        serv_puts("subj|__ Push email settings __");
                        serv_puts("000");
-                       while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                               msgnum = atol(buf);
+                       while (!Done &&
+                              StrBuf_ServGetln(Buf)) {
+                               if ( (StrLength(Buf)==3) && 
+                                    !strcmp(ChrPtr(Buf), "000")) {
+                                       Done = 1;
+                                       break;
+                               }
+                               msgnum = StrTol(Buf);
                        }
-                       
                }
                if (msgnum > 0L) {
                serv_printf("MSG0 %d", msgnum);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '1') {
+               StrBuf_ServGetln(Buf);
+               if (GetServerStatus(Buf, NULL) == 1) {
                        int i =0;
-                       while (serv_getln(buf, sizeof buf),
-                               (strcmp(buf, "text") && strcmp(buf, "000"))) {
+                       Done = 0;
+                       while (!Done &&
+                              StrBuf_ServGetln(Buf)) {
+                               if (( (StrLength(Buf)==3) && 
+                                     !strcmp(ChrPtr(Buf), "000"))||
+                                   ((StrLength(Buf)==4) && 
+                                    !strcmp(ChrPtr(Buf), "text")))
+                               {
+                                       Done = 1;
+                                       break;
+                               }
                        }
-                       if (!strcmp(buf, "text")) {
-                               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { 
-                                       if (strncasecmp(buf, "none", 4) == 0) {
+                       if (!strcmp(ChrPtr(Buf), "text")) {
+                               Done = 0;
+                               while (!Done &&
+                                      StrBuf_ServGetln(Buf)) {
+                                       if ( (StrLength(Buf)==3) && 
+                                            !strcmp(ChrPtr(Buf), "000")) {
+                                               Done = 1;
+                                               break;
+                                       }
+                                       if (strncasecmp(ChrPtr(Buf), "none", 4) == 0) {
                                                is_none = 1;
-                                       } else if (strncasecmp(buf, "textmessage", 11) == 0) {
+                                       } else if (strncasecmp(ChrPtr(Buf), "textmessage", 11) == 0) {
                                                is_pager = 1;
                                                i++;
-                                       } else if (strncasecmp(buf, "funambol", 8) == 0) {
+                                       } else if (strncasecmp(ChrPtr(Buf), "funambol", 8) == 0) {
                                                is_funambol = 1;
                                        } else if (i == 1) {
-                                               strncpy(mobnum, buf, 20);
+                                               strncpy(mobnum, ChrPtr(Buf), 20);
                                                i++;
                                        }
                                }       
                        }
                }
                }
-               // TODO: do in a saner fashion. 
-               svput("PUSH_NONE", WCS_STRING, " "); // defaults
+               /* TODO: do in a saner fashion. */
+               svput("PUSH_NONE", WCS_STRING, " "); /* defaults */
                svput("PUSH_TEXT", WCS_STRING, " ");
                svput("PUSH_FNBL", WCS_STRING, " ");
                svput("SMSNUM", WCS_STRING, " ");
-       if (is_none) {
-               svput("PUSH_NONE", WCS_STRING, "checked=\"checked\"");
-       } else if (is_pager) {
-               svput("PUSH_TEXT", WCS_STRING, "checked=\"checked\"");
-               svprintf(HKEY("SMSNUM"), WCS_STRING, "value=\"%s\"", mobnum);
-       } else if (is_funambol) {
-               svput("PUSH_FNBL", WCS_STRING, "checked=\"checked\"");
-       }
-       serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
-       serv_getln(buf, sizeof  buf);
+               if (is_none) {
+                       svput("PUSH_NONE", WCS_STRING, "checked=\"checked\"");
+               } else if (is_pager) {
+                       svput("PUSH_TEXT", WCS_STRING, "checked=\"checked\"");
+                       svprintf(HKEY("SMSNUM"), WCS_STRING, "value=\"%s\"", mobnum);
+               } else if (is_funambol) {
+                       svput("PUSH_FNBL", WCS_STRING, "checked=\"checked\"");
+               }
+               serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
+               StrBuf_ServGetln(Buf);
+               GetServerStatus(Buf, NULL);
        }
        output_headers(1, 1, 2, 0, 0, 0);
        do_template("pushemail", NULL);
 /*do_template("endbox"); */
        wDumpContent(1);
+       FreeStrBuf(&Buf);
 }
 
-void save_pushemail(void) {
+void save_pushemail(void) 
+{
+       int Done = 0;
+       StrBuf *Buf;
        char buf[SIZ];
        int msgnum = 0;
        char *pushsetting = bstr("pushsetting");
        char *sms = NULL;
+
        if (strncasecmp(pushsetting, "textmessage", 11) == 0) {
                sms = bstr("user_sms_number");
        }
-       if (goto_config_room() != 0) return;    /* oh well. */
+       Buf = NewStrBuf();
+       if (goto_config_room(Buf) != 0) {
+               FreeStrBuf(&Buf);
+               return; /* oh well. */
+       }
        serv_puts("MSGS ALL|0|1");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '8') {
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 8) {
                serv_puts("subj|__ Push email settings __");
                serv_puts("000");
        } else {
                printf("Junk in save_pushemail buffer!: %s\n", buf);
                return;
        }
-       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-               msgnum = atol(buf);
+
+       while (!Done &&
+              StrBuf_ServGetln(Buf)) {
+               if ( (StrLength(Buf)==3) && 
+                    !strcmp(ChrPtr(Buf), "000")) {
+                       Done = 1;
+                       break;
+               }
+               msgnum = StrTol(Buf);
        }
 
        if (msgnum > 0L) {
                serv_printf("DELE %d", msgnum);
-               serv_getln(buf, sizeof buf);
+               StrBuf_ServGetln(Buf);
+               GetServerStatus(Buf, NULL);
        }
 
        serv_printf("ENT0 1||0|1|__ Push email settings __|");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '4') {
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 4) {
                serv_puts(pushsetting);
                if (sms != NULL) {
                serv_puts(sms);
@@ -111,7 +153,8 @@ void save_pushemail(void) {
 
        /** Go back to the room we're supposed to be in */
        serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
-       serv_getln(buf, sizeof buf);
+       StrBuf_ServGetln(Buf);
+       GetServerStatus(Buf, NULL);
        http_redirect("display_pushemail");
 }
 
index 2d64f5dca98d73ffe85bd9419bd65c3b507005fe..55490f89a752549c3adb10ae4dff58d5dcb35c02 100644 (file)
@@ -717,7 +717,7 @@ int read_server_binary(StrBuf *Ret, size_t total_len, StrBuf *Buf);
 int StrBuf_ServGetBLOB(StrBuf *buf, long BlobSize);
 int StrBuf_ServGetBLOBBuffered(StrBuf *buf, long BlobSize);
 int read_server_text(StrBuf *Buf, long *nLines);
-int goto_config_room(void);
+int goto_config_room(StrBuf *Buf);
 long locate_user_vcard_in_this_room(message_summary **VCMsg,
                                    wc_mime_attachment **VCAtt);
 void sleeeeeeeeeep(int);