* start migrating important message to strbuf; have both meanwhile.
authorWilfried Göesgens <willi@citadel.org>
Tue, 28 Apr 2009 21:29:17 +0000 (21:29 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 28 Apr 2009 21:29:17 +0000 (21:29 +0000)
* evaluate result of gotoroom; this needs to be done elsewhere too.
* fix roomname thing in useredit

webcit/auth.c
webcit/context_loop.c
webcit/event.c
webcit/roomops.c
webcit/useredit.c
webcit/vcard_edit.c
webcit/webcit.c
webcit/webcit.h

index dd240fb09a710464b00e35527c917df0993ed82a..3f4a4e7833757e6e915c7eb6585d8bfbc03dbafe 100644 (file)
@@ -114,11 +114,11 @@ void display_openid_name_request(const StrBuf *claimed_id, const StrBuf *usernam
 void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_response)
 {
        wcsession *WCC = WC;
-       char buf[SIZ];
+       StrBuf *Buf;
        StrBuf *FloorDiv;
        StrBuf *Language = NULL;
 
-       WC->logged_in = 1;
+       WCC->logged_in = 1;
 
        if (WCC->wc_fullname == NULL)
                WCC->wc_fullname = NewStrBufPlain(NULL, StrLength(serv_response));
@@ -146,13 +146,19 @@ void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_respo
 
        load_preferences();
 
+       Buf = NewStrBuf();
        serv_puts("CHEK");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '2') {
-               WC->new_mail = extract_int(&buf[4], 0);
-               WC->need_regi = extract_int(&buf[4], 1);
-               WC->need_vali = extract_int(&buf[4], 2);
-               extract_token(WC->cs_inet_email, &buf[4], 3, '|', sizeof WC->cs_inet_email);
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 2) {
+               const char *pch;
+
+               pch = ChrPtr(Buf) + 4;
+               WCC->new_mail = StrBufExtractNext_long(Buf, &pch, '|');
+               WCC->need_regi = StrBufExtractNext_long(Buf, &pch, '|');
+               WCC->need_vali = StrBufExtractNext_long(Buf, &pch, '|');
+               if (WCC->cs_inet_email == NULL)
+                       WCC->cs_inet_email  = NewStrBuf();
+               StrBufExtract_NextToken(WCC->cs_inet_email, Buf, &pch, '|');
        }
        if (havebstr("language"))
                set_preference("language", NewStrBufDup(SBSTR("language")), 1);
@@ -164,7 +170,8 @@ void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_respo
                }
        }
        get_preference("floordiv_expanded", &FloorDiv);
-       WC->floordiv_expanded = FloorDiv;
+       WCC->floordiv_expanded = FloorDiv;
+       FreeStrBuf(&Buf);
 }
 
 
index c844f65a74075df3f876029f66cd12ea26239dc2..a85c87b8ef186c5c67fb530c7323954b6c280da8 100644 (file)
@@ -52,6 +52,8 @@ void DestroySession(wcsession **sessions_to_kill)
        FreeStrBuf(&((*sessions_to_kill)->wc_roomname));
        FreeStrBuf(&((*sessions_to_kill)->httpauth_user));
        FreeStrBuf(&((*sessions_to_kill)->httpauth_pass));
+       FreeStrBuf(&((*sessions_to_kill)->ImportantMsg));
+       FreeStrBuf(&((*sessions_to_kill)->cs_inet_email));
        free((*sessions_to_kill));
        (*sessions_to_kill) = NULL;
 }
@@ -537,6 +539,8 @@ void context_loop(int *sock)
        pthread_mutex_lock(&TheSession->SessionMutex);          /* bind */
        pthread_setspecific(MyConKey, (void *)TheSession);
        
+       if (TheSession->ImportantMsg == NULL)
+               TheSession->ImportantMsg = NewStrBuf();
        TheSession->urlstrings = NewHash(1,NULL);
        TheSession->vars = NewHash(1,NULL);
        TheSession->http_sock = *sock;
index 468422a9abbd9c2c8bb009fb1d882ebda5c60319..26dd217bd100725d506de64b3ff980463f25414f 100644 (file)
@@ -293,7 +293,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
         */
        if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
           == NULL) {
-               sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
+               sprintf(organizer_string, "MAILTO:%s", ChrPtr(WC->cs_inet_email));
                icalcomponent_add_property(vevent,
                        icalproperty_new_organizer(organizer_string)
                );
index b01446a3f3562bbb55c6246919697d4170a74371..60b6f7176392379392044b7268fc5de9ae9496e4 100644 (file)
@@ -794,7 +794,12 @@ long gotoroom(const StrBuf *gname)
        if  (GetServerStatus(Buf, &err) != 2) {
                serv_puts("GOTO _BASEROOM_");
                StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, &err) != 2) {
+               /* 
+                * well, we know that this is the fallback case, 
+                * but we're interested that the first command 
+                * didn't work out in first place.
+                */
+               if (GetServerStatus(Buf, NULL) != 2) {
                        FreeStrBuf(&Buf);
                        return err;
                }
index 02aea240ea596d133049299a0a32907da2bcbb02..baffe100547074d5db9cf04ae306e8defcf83268 100644 (file)
@@ -473,20 +473,22 @@ TRYAGAIN:
 void display_edit_address_book_entry(const char *username, long usernum) {
        message_summary *VCMsg = NULL;
        wc_mime_attachment *VCAtt = NULL;
-       char roomname[SIZ];
+       StrBuf *roomname;
        StrBuf *Buf;
        char error_message[SIZ];
        long vcard_msgnum = (-1L);
 
        /** Locate the user's config room, creating it if necessary */
        Buf = NewStrBuf();
-       serv_printf("GOTO %010ld.%s||1", usernum, USERCONFIGROOM);
+       roomname = NewStrBuf();
+       StrBufPrintf(roomname, "%010ld.%s", usernum, USERCONFIGROOM);
+       serv_printf("GOTO %s||1", ChrPtr(roomname));
        StrBuf_ServGetlnBuffered(Buf);
        if (GetServerStatus(Buf, NULL) != 2) {
-               serv_printf("CRE8 1|%010ld.%s|5|||1|", usernum, USERCONFIGROOM);
+               serv_printf("CRE8 1|%s|5|||1|", ChrPtr(roomname));
                StrBuf_ServGetlnBuffered(Buf);
                GetServerStatus(Buf, NULL);
-               serv_printf("GOTO %010ld.%s||1", usernum, USERCONFIGROOM);
+               serv_printf("GOTO %s||1", ChrPtr(roomname));
                StrBuf_ServGetlnBuffered(Buf);
                if (GetServerStatus(Buf, NULL) != 2) {
                        StrBufCutLeft(Buf, 4);
@@ -495,6 +497,7 @@ void display_edit_address_book_entry(const char *username, long usernum) {
                                "%s<br /><br />\n", ChrPtr(Buf));
                        select_user_to_edit(error_message, username);
                        FreeStrBuf(&Buf);
+                       FreeStrBuf(&roomname);
                        return;
                }
        }
@@ -508,6 +511,7 @@ void display_edit_address_book_entry(const char *username, long usernum) {
                        _("An error occurred while trying to create or edit this address book entry.")
                        );
                select_user_to_edit(error_message, username);
+               FreeStrBuf(&roomname);
                return;
        }
 
@@ -515,7 +519,8 @@ void display_edit_address_book_entry(const char *username, long usernum) {
                      VCMsg,
                      VCAtt,
                      "select_user_to_edit", 
-                     roomname);
+                     ChrPtr(roomname));
+       FreeStrBuf(&roomname);
 }
 
 
index 38ab46357d2ff037e8266ca6b18fca7e8b459521..db61561cf84a24bb0a2fecfa400bc77c966a859d 100644 (file)
@@ -122,8 +122,7 @@ void fetch_ab_name(message_summary *Msg, char **namebuf) {
        memset(&summ, 0, sizeof(summ));
        //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
 
-       sprintf(buf, "MSG0 %ld|0", Msg->msgnum);        /** unfortunately we need the mime info now */
-       serv_puts(buf);
+       serv_printf(buf, "MSG0 %ld|0", Msg->msgnum);    /** unfortunately we need the mime info now */
        serv_getln(buf, sizeof buf);
        if (buf[0] != '1') return;
 
@@ -1085,6 +1084,7 @@ void edit_vcard(void) {
  *  parse edited vcard from the browser
  */
 void submit_vcard(void) {
+       wcsession *WCC = WC;
        struct vCard *v;
        char *serialized_vcard;
        char buf[SIZ];
@@ -1097,7 +1097,31 @@ void submit_vcard(void) {
        }
 
        if (havebstr("force_room")) {
-               gotoroom(sbstr("force_room"));
+               if (gotoroom(sbstr("force_room")) != 200) {
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            _("Unable to enter the room to save your message"),
+                                            -1, 0);
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            HKEY(": "), 0);
+                       StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            HKEY("; "), 0);
+                                              
+                       StrBufAppendBufPlain(WCC->ImportantMsg,
+                                            _("Aborting."),
+                                            -1, 0);
+                       /// todo: call the master dispatcher again...
+                       if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
+                               select_user_to_edit(NULL, NULL);
+                       }
+                       else if (!strcmp(bstr("return_to"), "do_welcome")) {
+                               do_welcome();
+                       }
+                       else {
+                               readloop(readnew);
+                       }
+                       return;
+               }
        }
 
        sprintf(buf, "ENT0 1|||4||");
@@ -1116,9 +1140,9 @@ void submit_vcard(void) {
        v = VCardLoad(Buf);     /** Start with the extra fields */
        FreeStrBuf(&Buf);
        if (v == NULL) {
-               safestrncpy(WC->ImportantMessage,
+               safestrncpy(WCC->ImportantMessage,
                        _("An error has occurred."),
-                       sizeof WC->ImportantMessage
+                       sizeof WCC->ImportantMessage
                );
                edit_vcard();
                return;
@@ -1162,9 +1186,9 @@ void submit_vcard(void) {
        serialized_vcard = vcard_serialize(v);
        vcard_free(v);
        if (serialized_vcard == NULL) {
-               safestrncpy(WC->ImportantMessage,
+               safestrncpy(WCC->ImportantMessage,
                        _("An error has occurred."),
-                       sizeof WC->ImportantMessage
+                       sizeof WCC->ImportantMessage
                );
                edit_vcard();
                return;
index d7beab0c3bd9ca85d17ca3082f3fe0b96740f667..31d5197b6a8934b0498fd1bd9d180495bda4bd94 100644 (file)
@@ -168,21 +168,34 @@ void output_headers(      int do_httpheaders,     /* 1 = output HTTP headers
                do_template("head", NULL);
 
                /* check for ImportantMessages (these display in a div overlaying the main screen) */
-               if (!IsEmptyStr(WC->ImportantMessage)) {
+               if (!IsEmptyStr(WCC->ImportantMessage)) {
                        wprintf("<div id=\"important_message\">\n"
                                "<span class=\"imsg\">");
-                       escputs(WC->ImportantMessage);
+                       StrEscAppend(WCC->WBuf, NULL, WCC->ImportantMessage, 0, 0);
                        wprintf("</span><br />\n"
                                "</div>\n"
                        );
-                       StrBufAppendPrintf(WCC->trailing_javascript,
-                               "setTimeout('hide_imsg_popup()', 5000); \n"
+                       StrBufAppendBufPlain(WCC->trailing_javascript,
+                                            HKEY("setTimeout('hide_imsg_popup()', 5000);       \n"), 
+                                            0
                        );
                        WCC->ImportantMessage[0] = 0;
                }
-
+               else if (StrLength(WCC->ImportantMsg) > 0) {
+                       wprintf("<div id=\"important_message\">\n"
+                               "<span class=\"imsg\">");
+                       StrEscAppend(WCC->WBuf, WCC->ImportantMsg, NULL, 0, 0);
+                       wprintf("</span><br />\n"
+                               "</div>\n"
+                       );
+                       StrBufAppendBufPlain(WCC->trailing_javascript,
+                                            HKEY("setTimeout('hide_imsg_popup()', 5000);       \n"),
+                                            0
+                       );
+                       FlushStrBuf(WCC->ImportantMsg);
+               }
                if ( (WCC->logged_in) && (!unset_cookies) ) {
-                 //DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
+                       /*DoTemplate(HKEY("iconbar"), NULL, &NoCtx);*/
                        page_popup();
                }
 
@@ -1107,7 +1120,8 @@ int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        if (WCC != NULL)
-               return (!IsEmptyStr(WCC->ImportantMessage));
+               return ((!IsEmptyStr(WCC->ImportantMessage)) || 
+                       (StrLength(WCC->ImportantMsg) > 0));
        else
                return 0;
 }
@@ -1117,12 +1131,14 @@ void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP)
        wcsession *WCC = WC;
        
        if (WCC != NULL) {
-/*
-               StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType,
-                                    WCC->ImportantMessage, 0);
-*/
-               StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
-               WCC->ImportantMessage[0] = '\0';
+               if (!IsEmptyStr(WCC->ImportantMessage)) {
+                       StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
+                       WCC->ImportantMessage[0] = '\0';
+               }
+               else if (StrLength(WCC->ImportantMsg) > 0) {
+                       StrEscAppend(Target, WCC->ImportantMsg, NULL, 0, 0);
+                       FlushStrBuf(WCC->ImportantMsg);
+               }
        }
 }
 
index e1ac1864416137a6145a322fab6f4f9ce0e470e6..04cff4edd561da04dbf6906bfcf5a22c06197f1d 100644 (file)
@@ -370,6 +370,7 @@ struct wcsession {
 
        StrBuf *trailing_javascript;            /**< extra javascript to be appended to page */
        char ImportantMessage[SIZ];             /**< ??? todo */
+       StrBuf *ImportantMsg;
 
 /* accounting */
        StrBuf *wc_username;                    /**< login name of current user */
@@ -386,7 +387,7 @@ struct wcsession {
        int need_vali;                          /**< New users require validation. */
 
 /* Preferences */
-       char cs_inet_email[256];                /**< User's preferred Internet addr. */
+       StrBuf *cs_inet_email;                  /**< User's preferred Internet addr. */
        char reply_to[512];                     /**< reply-to address */
        HashList *hash_prefs;                   /**< WebCit preferences for this user */
        StrBuf *DefaultCharset;                 /**< Charset the user preferes */