From 20fecd19b462c6aee88abcc6243666a1bc2b9fee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 28 Apr 2009 21:29:17 +0000 Subject: [PATCH] * start migrating important message to strbuf; have both meanwhile. * evaluate result of gotoroom; this needs to be done elsewhere too. * fix roomname thing in useredit --- webcit/auth.c | 25 ++++++++++++++++--------- webcit/context_loop.c | 4 ++++ webcit/event.c | 2 +- webcit/roomops.c | 7 ++++++- webcit/useredit.c | 15 ++++++++++----- webcit/vcard_edit.c | 38 +++++++++++++++++++++++++++++++------- webcit/webcit.c | 42 +++++++++++++++++++++++++++++------------- webcit/webcit.h | 3 ++- 8 files changed, 99 insertions(+), 37 deletions(-) diff --git a/webcit/auth.c b/webcit/auth.c index dd240fb09..3f4a4e783 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -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); } diff --git a/webcit/context_loop.c b/webcit/context_loop.c index c844f65a7..a85c87b8e 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -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; diff --git a/webcit/event.c b/webcit/event.c index 468422a9a..26dd217bd 100644 --- a/webcit/event.c +++ b/webcit/event.c @@ -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) ); diff --git a/webcit/roomops.c b/webcit/roomops.c index b01446a3f..60b6f7176 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -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; } diff --git a/webcit/useredit.c b/webcit/useredit.c index 02aea240e..baffe1005 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -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

\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); } diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index 38ab46357..db61561cf 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -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; diff --git a/webcit/webcit.c b/webcit/webcit.c index d7beab0c3..31d5197b6 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -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("
\n" ""); - escputs(WC->ImportantMessage); + StrEscAppend(WCC->WBuf, NULL, WCC->ImportantMessage, 0, 0); wprintf("
\n" "
\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("
\n" + ""); + StrEscAppend(WCC->WBuf, WCC->ImportantMsg, NULL, 0, 0); + wprintf("
\n" + "
\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); + } } } diff --git a/webcit/webcit.h b/webcit/webcit.h index e1ac18644..04cff4edd 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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 */ -- 2.30.2