From: Wilfried Goesgens Date: Thu, 28 Jul 2011 23:16:12 +0000 (+0000) Subject: buybuy plaintext important message. X-Git-Tag: v8.11~534 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=814d4bec141c8374ef72a60aeeded0d696483c5e buybuy plaintext important message. --- diff --git a/webcit/auth.c b/webcit/auth.c index 994c00c97..6c71b9aeb 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -780,6 +780,7 @@ void display_reg(int during_login) */ void display_changepw(void) { + wcsession *WCC = WC; WCTemplputParams SubTP; char buf[SIZ]; StrBuf *Buf; @@ -793,10 +794,10 @@ void display_changepw(void) FreeStrBuf(&Buf); - if (!IsEmptyStr(WC->ImportantMessage)) { + if (StrLength(WCC->ImportantMsg) > 0) { wc_printf("" - "%s
\n", WC->ImportantMessage); - safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage); + "%s
\n", ChrPtr(WCC->ImportantMsg)); + FlushStrBuf(WCC->ImportantMsg); } serv_puts("MESG changepw"); @@ -835,13 +836,11 @@ void display_changepw(void) */ void changepw(void) { - char buf[SIZ]; + StrBuf *Line; char newpass1[32], newpass2[32]; if (!havebstr("change_action")) { - safestrncpy(WC->ImportantMessage, - _("Cancelled. Password was not changed."), - sizeof WC->ImportantMessage); + AppendImportantMessage(_("Cancelled. Password was not changed."), -1); display_main_menu(); return; } @@ -850,36 +849,37 @@ void changepw(void) safestrncpy(newpass2, bstr("newpass2"), sizeof newpass2); if (strcasecmp(newpass1, newpass2)) { - safestrncpy(WC->ImportantMessage, - _("They don't match. Password was not changed."), - sizeof WC->ImportantMessage); + AppendImportantMessage(_("They don't match. Password was not changed."), -1); display_changepw(); return; } if (IsEmptyStr(newpass1)) { - safestrncpy(WC->ImportantMessage, - _("Blank passwords are not allowed."), - sizeof WC->ImportantMessage); + AppendImportantMessage(_("Blank passwords are not allowed."), -1); display_changepw(); return; } + Line = NewStrBuf(); serv_printf("SETP %s", newpass1); - serv_getln(buf, sizeof buf); - sprintf(WC->ImportantMessage, "%s", &buf[4]); - if (buf[0] == '2') { + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 0) == 2) { if (WC->wc_password == NULL) - WC->wc_password = NewStrBufPlain(buf, -1); + WC->wc_password = NewStrBufPlain( + ChrPtr(Line) + 4, + StrLength(Line) - 4); else { FlushStrBuf(WC->wc_password); - StrBufAppendBufPlain(WC->wc_password, buf, -1, 0); + StrBufAppendBufPlain(WC->wc_password, + ChrPtr(Line) + 4, + StrLength(Line) - 4, 0); } display_main_menu(); } else { display_changepw(); } + FreeStrBuf(&Line); } diff --git a/webcit/downloads.c b/webcit/downloads.c index a130c6392..993b075b2 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -299,20 +299,19 @@ void download_file(void) void delete_file(void) { const StrBuf *MimeType; - StrBuf *Buf; + StrBuf *Line; char buf[256]; safestrncpy(buf, bstr("file"), sizeof buf); unescape_input(buf); serv_printf("DELF %s", buf); - Buf = NewStrBuf(); - StrBuf_ServGetln(Buf); - GetServerStatus(Buf, NULL); - StrBufCutLeft(Buf, 4); - strcpy(WC->ImportantMessage, ChrPtr(Buf)); + + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 0); + MimeType = DoTemplate(HKEY("files"), NULL, &NoCtx); http_transmit_thing(ChrPtr(MimeType), 0); - FreeStrBuf(&Buf); + FreeStrBuf(&Line); } @@ -321,7 +320,7 @@ void upload_file(void) { const StrBuf *RetMimeType; const char *MimeType; - char buf[1024]; + StrBuf *Line; long bytes_transmitted = 0; long blocksize; const StrBuf *Desc; @@ -335,13 +334,12 @@ void upload_file(void) ChrPtr(WCC->upload_filename), MimeType, ChrPtr(Desc)); - - serv_getln(buf, sizeof buf); - if (buf[0] != '2') - { - strcpy(WCC->ImportantMessage, &buf[4]); + Line = NewStrBuf(); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { RetMimeType = DoTemplate(HKEY("files"), NULL, &NoCtx); http_transmit_thing(ChrPtr(RetMimeType), 0); + FreeStrBuf(&Line); return; } @@ -353,20 +351,22 @@ void upload_file(void) blocksize = (WCC->upload_length - bytes_transmitted); } serv_printf("WRIT %ld", blocksize); - serv_getln(buf, sizeof buf); - if (buf[0] == '7') - { - blocksize = atoi(&buf[4]); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 0, 0) == 7) { + blocksize = atoi(ChrPtr(Line) + 4); serv_write(&ChrPtr(WCC->upload)[bytes_transmitted], blocksize); bytes_transmitted += blocksize; } + else + break; } serv_puts("UCLS 1"); - serv_getln(buf, sizeof buf); - strcpy(WCC->ImportantMessage, &buf[4]); + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 0); RetMimeType = DoTemplate(HKEY("files"), NULL, &NoCtx); http_transmit_thing(ChrPtr(RetMimeType), 0); + FreeStrBuf(&Line); } diff --git a/webcit/event.c b/webcit/event.c index b0f41ca2d..6ae2a5ac3 100644 --- a/webcit/event.c +++ b/webcit/event.c @@ -1170,7 +1170,7 @@ STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDE } } if (buf[0] == '2') { - strcpy(WC->ImportantMessage, &buf[4]); + StrBufAppendBufPlain(WC->ImportantMsg, buf, -1, 4); } icalmemory_free_ring (); icalcomponent_free(encaps); diff --git a/webcit/graphics.c b/webcit/graphics.c index 2a2a856a5..ee8e80bd6 100644 --- a/webcit/graphics.c +++ b/webcit/graphics.c @@ -24,23 +24,27 @@ extern void output_static(const char* What); void display_graphics_upload(char *filename) { - char buf[SIZ]; + StrBuf *Line; - snprintf(buf, SIZ, "UIMG 0||%s", filename); - serv_puts(buf); - serv_getln(buf, sizeof buf); - if (buf[0] != '2') { - strcpy(WC->ImportantMessage, &buf[4]); + Line = NewStrBuf(); + serv_printf("UIMG 0||%s", filename); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { display_main_menu(); return; } - output_headers(1, 0, 0, 0, 1, 0); - do_template("files_graphicsupload"); - end_burst(); + else + { + output_headers(1, 0, 0, 0, 1, 0); + do_template("files_graphicsupload"); + end_burst(); + } + FreeStrBuf(&Line); } void do_graphics_upload(char *filename) { + StrBuf *Line; const char *MimeType; wcsession *WCC = WC; char buf[SIZ]; @@ -50,38 +54,36 @@ void do_graphics_upload(char *filename) bytes_remaining = WCC->upload_length; if (havebstr("cancel_button")) { - strcpy(WC->ImportantMessage, - _("Graphics upload has been cancelled.")); + AppendImportantMessage(_("Graphics upload has been cancelled."), -1); display_main_menu(); return; } if (WCC->upload_length == 0) { - strcpy(WC->ImportantMessage, - _("You didn't upload a file.")); + AppendImportantMessage(_("You didn't upload a file."), -1); display_main_menu(); return; } MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining); - snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename); - serv_puts(buf); + serv_printf("UIMG 1|%s|%s", MimeType, filename); - serv_getln(buf, sizeof buf); - if (buf[0] != '2') { - strcpy(WCC->ImportantMessage, &buf[4]); + Line = NewStrBuf(); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { display_main_menu(); + FreeStrBuf(&Line); return; } while (bytes_remaining) { thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining); serv_printf("WRIT %d", thisblock); - serv_getln(buf, sizeof buf); - if (buf[0] != '7') { - strcpy(WCC->ImportantMessage, &buf[4]); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) { serv_puts("UCLS 0"); - serv_getln(buf, sizeof buf); + StrBuf_ServGetln(Line); display_main_menu(); + FreeStrBuf(&Line); return; } thisblock = extract_int(&buf[4], 0); @@ -91,11 +93,13 @@ void do_graphics_upload(char *filename) } serv_puts("UCLS 1"); - serv_getln(buf, sizeof buf); - if (buf[0] != 'x') { - display_success(&buf[4]); - return; + StrBuf_ServGetln(Line); + if (*ChrPtr(Line) != 'x') { + display_success(ChrPtr(Line) + 4); + } + FreeStrBuf(&Line); + } diff --git a/webcit/inetconf.c b/webcit/inetconf.c index a370634bc..f4e59fe68 100644 --- a/webcit/inetconf.c +++ b/webcit/inetconf.c @@ -156,7 +156,7 @@ void new_save_inetconf(void) { GetHash(WCC->InetCfg, CKEY(CfgNames[i]), &vHash); Hash = (HashList*) vHash; if (Hash == NULL) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index 8942e9390..cbf9dc38f 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -106,20 +106,16 @@ void do_generic(void) */ void display_shutdown(void) { - char buf[SIZ]; + StrBuf *Line; char *when; + Line = NewStrBuf(); when=bstr("when"); if (strcmp(when, "now") == 0){ serv_printf("DOWN 1"); - serv_getln(buf, sizeof buf); - if (atol(buf) == 500) - { /* upsie. maybe the server is not running as daemon? */ - - safestrncpy(WC->ImportantMessage, - &buf[4], - sizeof WC->ImportantMessage); - } + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 5); + begin_burst(); output_headers(1, 0, 0, 0, 1, 0); DoTemplate(HKEY("aide_display_serverrestart"), NULL, &NoCtx); @@ -143,7 +139,9 @@ void display_shutdown(void) else { serv_printf("SEXP broadcast|%s", message); - serv_getln(buf, sizeof buf); /* TODO: should we care? */ + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 0); + begin_burst(); output_headers(1, 0, 0, 0, 1, 0); DoTemplate(HKEY("aide_display_serverrestart_page"), NULL, &NoCtx); @@ -152,19 +150,15 @@ void display_shutdown(void) } else if (!strcmp(when, "idle")) { serv_printf("SCDN 3"); - serv_getln(buf, sizeof buf); + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 2); - if (atol(buf) == 500) - { /* upsie. maybe the server is not running as daemon? */ - safestrncpy(WC->ImportantMessage, - &buf[4], - sizeof WC->ImportantMessage); - } begin_burst(); output_headers(1, 0, 0, 0, 1, 0); DoTemplate(HKEY("aide_display_menu"), NULL, &NoCtx); end_burst(); } + FreeStrBuf(&Line); } void diff --git a/webcit/messages.c b/webcit/messages.c index f96b4ffae..560e031f4 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -995,12 +995,11 @@ void post_message(void) } if (!strcasecmp(bstr("submit_action"), "cancel")) { - sprintf(WCC->ImportantMessage, - _("Cancelled. Message was not posted.")); + AppendImportantMessage(_("Cancelled. Message was not posted."), -1); } else if (lbstr("postseq") == dont_post) { - sprintf(WCC->ImportantMessage, + AppendImportantMessage( _("Automatically cancelled because you have already " - "saved this message.")); + "saved this message."), -1); } else { const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s"; StrBuf *Recp = NULL; @@ -1277,12 +1276,39 @@ void remove_attachment(void) { } +long FourHash(const char *key, long length) +{ + int i; + long ret = 0; + const unsigned char *ptr = (const unsigned char*)key; + + for (i = 0; i < 4; i++, ptr ++) + ret = (ret << 8) | + ( ((*ptr >= 'a') && + (*ptr <= 'z'))? + *ptr - 'a' + 'A': + *ptr); + + return ret; +} + +long l_subj; +long l_wefw; +long l_msgn; +long l_from; +long l_rcpt; +long l_cccc; +long l_node; +long l_rfca; + /* * display the message entry screen */ void display_enter(void) { - char buf[SIZ]; + StrBuf *Line; + long Result; + int rc; const StrBuf *display_name = NULL; int recipient_required = 0; int subject_required = 0; @@ -1303,21 +1329,24 @@ void display_enter(void) } /* First test to see whether this is a room that requires recipients to be entered */ + Line = NewStrBuf(); serv_puts("ENT0 0"); - serv_getln(buf, sizeof buf); + StrBuf_ServGetln(Line); + rc = GetServerStatusMsg(Line, &Result, 0, 2); - if (!strncmp(buf, "570", 3)) { /* 570 means that we need a recipient here */ + if (Result == 570) { /* 570 means that we need a recipient here */ recipient_required = 1; } - else if (buf[0] != '2') { /* Any other error means that we cannot continue */ - sprintf(WCC->ImportantMessage, "%s", &buf[4]); + else if (rc != 2) { /* Any other error means that we cannot continue */ + rc = GetServerStatusMsg(Line, &Result, 0, 2); readloop(readnew, eUseDefault); + FreeStrBuf(&Line); return; } /* Is the server strongly recommending that the user enter a message subject? */ - if ((buf[3] != '\0') && (buf[4] != '\0')) { - subject_required = extract_int(&buf[4], 1); + if (StrLength(Line) > 4) { + subject_required = extract_int(ChrPtr(Line) + 4, 1); } /* @@ -1326,6 +1355,7 @@ void display_enter(void) */ if (WCC->CurRoom.defview == VIEW_ADDRESSBOOK) { do_edit_vcard(-1, "", NULL, NULL, "", ChrPtr(WCC->CurRoom.name)); + FreeStrBuf(&Line); return; } @@ -1335,6 +1365,7 @@ void display_enter(void) */ if (WCC->CurRoom.defview == VIEW_CALENDAR) { display_edit_event(); + FreeStrBuf(&Line); return; } @@ -1344,6 +1375,7 @@ void display_enter(void) */ if (WCC->CurRoom.defview == VIEW_TASKS) { display_edit_task(); + FreeStrBuf(&Line); return; } @@ -1354,87 +1386,106 @@ void display_enter(void) */ replying_to = lbstr("replying_to"); if (replying_to > 0) { - char wefw[1024] = ""; - char msgn[256] = ""; - char from[256] = ""; - char node[256] = ""; - char rfca[256] = ""; - char rcpt[SIZ] = ""; - char cccc[SIZ] = ""; + long len; + StrBuf *wefw = NULL; + StrBuf *msgn = NULL; + StrBuf *from = NULL; + StrBuf *node = NULL; + StrBuf *rfca = NULL; + StrBuf *rcpt = NULL; + StrBuf *cccc = NULL; serv_printf("MSG0 %ld|1", replying_to); - serv_getln(buf, sizeof buf); - if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - - if ( (!strncasecmp(buf, "subj=", 5)) && (strlen(buf) > 5) ) { - StrBuf *subj = NewStrBuf(); - if (!strcasecmp(bstr("replying_mode"), "forward")) { - if (strncasecmp(&buf[5], "Fw:", 3)) { - StrBufAppendBufPlain(subj, HKEY("Fw: "), 0); + + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 0, 0) == 1) + while (len = StrBuf_ServGetln(Line), + (len >= 0) && + ((len != 3) || + strcmp(ChrPtr(Line), "000"))) + { + long which = 0; + if ((StrLength(Line) > 4) && + (ChrPtr(Line)[5] == '=')) + which = FourHash(ChrPtr(Line), 4); + + if (which == l_subj) + { + StrBuf *subj = NewStrBuf(); + if (!strcasecmp(bstr("replying_mode"), "forward")) { + if (strncasecmp(ChrPtr(Line) + 5, "Fw:", 3)) { + StrBufAppendBufPlain(subj, HKEY("Fw: "), 0); + } } - } - else { - if (strncasecmp(&buf[5], "Re:", 3)) { - StrBufAppendBufPlain(subj, HKEY("Re: "), 0); + else { + if (strncasecmp(ChrPtr(Line) + 5, "Re:", 3)) { + StrBufAppendBufPlain(subj, HKEY("Re: "), 0); + } } + StrBufAppendBufPlain(subj, + ChrPtr(Line) + 5, + StrLength(Line) - 5, 0); + PutBstr(HKEY("subject"), subj); } - StrBufAppendBufPlain(subj, &buf[5], -1, 0); - PutBstr(HKEY("subject"), subj); - } - else if (!strncasecmp(buf, "wefw=", 5)) { - int rrtok; - int rrlen; - safestrncpy(wefw, &buf[5], sizeof wefw); - - /* Trim down excessively long lists of thread references. We eliminate the - * second one in the list so that the thread root remains intact. - */ - rrtok = num_tokens(wefw, '|'); - rrlen = strlen(wefw); - if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) { - remove_token(wefw, 1, '|'); + else if (which == l_wefw) + { + int rrtok; + int rrlen; + + wefw = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5); + + /* Trim down excessively long lists of thread references. We eliminate the + * second one in the list so that the thread root remains intact. + */ + rrtok = num_tokens(ChrPtr(wefw), '|'); + rrlen = StrLength(wefw); + if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) { + StrBufRemove_token(wefw, 1, '|'); + } } - } - else if (!strncasecmp(buf, "msgn=", 5)) { - safestrncpy(msgn, &buf[5], sizeof msgn); - } - - else if (!strncasecmp(buf, "from=", 5)) { - safestrncpy(from, &buf[5], sizeof from); - for (i=0; i 0) { + StrBufAppendBuf(refs, msgn, 0); } PutBstr(HKEY("references"), refs); } @@ -1445,16 +1496,22 @@ void display_enter(void) if ( (!strcasecmp(bstr("replying_mode"), "reply")) || (!strcasecmp(bstr("replying_mode"), "replyall")) ) { - StrBuf *to_rcpt = NewStrBuf(); - if (!IsEmptyStr(rfca)) { - StrBufAppendPrintf(to_rcpt, "%s <%s>", from, rfca); + StrBuf *to_rcpt; + if (StrLength(rfca) > 0) { + to_rcpt = NewStrBuf(); + StrBufAppendBuf(to_rcpt, from, 0); + StrBufAppendBufPlain(to_rcpt, HKEY(" <"), 0); + StrBufAppendBuf(to_rcpt, rfca, 0); + StrBufAppendBufPlain(to_rcpt, HKEY(">"), 0); } else { - StrBufAppendPrintf(to_rcpt, "%s", from); - if ( (!IsEmptyStr(node)) - && (strcasecmp(node, ChrPtr(WC->serv_info->serv_nodename))) + to_rcpt = from; + from = NULL; + if ( (StrLength(node) > 0) + && (strcasecmp(ChrPtr(node), ChrPtr(WC->serv_info->serv_nodename))) ) { - StrBufAppendPrintf(to_rcpt, " @ %s", node); + StrBufAppendBufPlain(to_rcpt, HKEY(" @ "), 0); + StrBufAppendBuf(to_rcpt, node, 0); } } PutBstr(HKEY("recp"), to_rcpt); @@ -1465,21 +1522,29 @@ void display_enter(void) */ if ( (!strcasecmp(bstr("replying_mode"), "replyall")) ) { - StrBuf *cc_rcpt = NewStrBuf(); - if (!IsEmptyStr(rcpt)) { - StrBufAppendPrintf(cc_rcpt, "%s", rcpt); - } - if ( (!IsEmptyStr(rcpt)) && (!IsEmptyStr(cccc)) ) { - StrBufAppendPrintf(cc_rcpt, ", "); - } - if (!IsEmptyStr(cccc)) { - StrBufAppendPrintf(cc_rcpt, "%s", cccc); + StrBuf *cc_rcpt = rcpt; + rcpt = NULL; + if (StrLength(cccc) > 0) { + if (cc_rcpt != NULL) { + StrBufAppendPrintf(cc_rcpt, ", "); + StrBufAppendBuf(cc_rcpt, cccc, 0); + } else { + cc_rcpt = cccc; + cccc = NULL; + } } - PutBstr(HKEY("cc"), cc_rcpt); + if (cc_rcpt != NULL) + PutBstr(HKEY("cc"), cc_rcpt); } - - } - + FreeStrBuf(&wefw); + FreeStrBuf(&msgn); + FreeStrBuf(&from); + FreeStrBuf(&node); + FreeStrBuf(&rfca); + FreeStrBuf(&rcpt); + FreeStrBuf(&cccc); + } + FreeStrBuf(&Line); /* * Otherwise proceed normally. * Do a custom room banner with no navbar... @@ -1515,20 +1580,23 @@ void display_enter(void) ChrPtr(Bcc), ChrPtr(Wikipage)); serv_puts(ChrPtr(CmdBuf)); - serv_getln(buf, sizeof buf); - FreeStrBuf(&CmdBuf); + StrBuf_ServGetln(CmdBuf); + + rc = GetServerStatusMsg(CmdBuf, &Result, 0, 0); - if (!strncmp(buf, "570", 3)) { /* 570 means we have an invalid recipient listed */ + if (Result == 570) { /* 570 means we have an invalid recipient listed */ if (havebstr("recp") && havebstr("cc" ) && havebstr("bcc" )) { recipient_bad = 1; /* TODO: and now????? */ } } - else if (buf[0] != '2') { /* Any other error means that we cannot continue */ - wc_printf("%s
\n", &buf[4]); /* TODO -> important message */ + else if (rc != 2) { /* Any other error means that we cannot continue */ + wc_printf("%s
\n", ChrPtr(CmdBuf) +4); /* TODO -> important message */ + FreeStrBuf(&CmdBuf); return; } + FreeStrBuf(&CmdBuf); } if (recipient_required) PutBstr(HKEY("__RCPTREQUIRED"), NewStrBufPlain(HKEY("1"))); @@ -1549,10 +1617,10 @@ void display_enter(void) void delete_msg(void) { long msgid; - char buf[SIZ]; - + StrBuf *Line; + msgid = lbstr("msgid"); - + Line = NewStrBuf(); if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */ serv_printf("DELE %ld", msgid); } @@ -1560,8 +1628,9 @@ void delete_msg(void) serv_printf("MOVE %ld|_TRASH_|0", msgid); } - serv_getln(buf, sizeof buf); - sprintf(WC->ImportantMessage, "%s", &buf[4]); + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 0); + readloop(readnew, eUseDefault); } @@ -1572,17 +1641,18 @@ void delete_msg(void) void move_msg(void) { long msgid; - char buf[SIZ]; msgid = lbstr("msgid"); if (havebstr("move_button")) { - sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room")); - serv_puts(buf); - serv_getln(buf, sizeof buf); - sprintf(WC->ImportantMessage, "%s", &buf[4]); + StrBuf *Line; + serv_printf("MOVE %ld|%s", msgid, bstr("target_room")); + Line = NewStrBuf(); + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 0); + FreeStrBuf(&Line); } else { - sprintf(WC->ImportantMessage, (_("The message was not moved."))); + AppendImportantMessage(_("The message was not moved."), -1); } readloop(readnew, eUseDefault); @@ -1894,6 +1964,16 @@ InitModule_MSG /* json */ WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0); + + l_subj = FourHash("subj", 4); + l_wefw = FourHash("wefw", 4); + l_msgn = FourHash("msgn", 4); + l_from = FourHash("from", 4); + l_rcpt = FourHash("rcpt", 4); + l_cccc = FourHash("cccc", 4); + l_node = FourHash("node", 4); + l_rfca = FourHash("rfca", 4); + return ; } diff --git a/webcit/netconf.c b/webcit/netconf.c index a62c96526..8683879ff 100644 --- a/webcit/netconf.c +++ b/webcit/netconf.c @@ -155,7 +155,7 @@ void edit_node(void) { Index = sbstr("index"); NewNode = HttpGetNewNode(); if ((NewNode == NULL) || (Index == NULL)) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } @@ -182,7 +182,7 @@ void display_edit_node(void) Index = sbstr("index"); if (Index == NULL) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } @@ -190,7 +190,7 @@ void display_edit_node(void) NodeConfig = load_netconf(NULL, &NoCtx); if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); DeleteHash(&NodeConfig); return; @@ -238,7 +238,7 @@ void delete_node(void) Index = sbstr("index"); if (Index == NULL) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } @@ -246,7 +246,7 @@ void delete_node(void) NodeConfig = load_netconf(NULL, &NoCtx); if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); DeleteHash(&NodeConfig); return; diff --git a/webcit/openid.c b/webcit/openid.c index 316859f8b..eaaa40100 100644 --- a/webcit/openid.c +++ b/webcit/openid.c @@ -111,14 +111,14 @@ void openid_attach(void) { * Detach an OpenID from the currently logged-in account */ void openid_detach(void) { - char buf[1024]; + StrBuf *Line; if (havebstr("id_to_detach")) { serv_printf("OIDD %s", bstr("id_to_detach")); - serv_getln(buf, sizeof buf); - if (buf[0] != '2') { - strcpy(WC->ImportantMessage, &buf[4]); - } + Line = NewStrBuf(); + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 2); + FreeStrBuf(&Line); } display_openids(); diff --git a/webcit/paging.c b/webcit/paging.c index 190aa58c6..efece86ba 100644 --- a/webcit/paging.c +++ b/webcit/paging.c @@ -76,32 +76,23 @@ void display_page(void) void page_user(void) { char recp[256]; - char buf[256]; + StrBuf *Line; safestrncpy(recp, bstr("recp"), sizeof recp); if (!havebstr("send_button")) { - safestrncpy(WC->ImportantMessage, - _("Message was not sent."), - sizeof WC->ImportantMessage - ); + AppendImportantMessage(_("Message was not sent."), -1); } else { + Line = NewStrBuf(); serv_printf("SEXP %s|-", recp); - serv_getln(buf, sizeof buf); - - if (buf[0] == '4') { + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 0, 0) == 4) { + char buf[256]; text_to_server(bstr("msgtext")); serv_puts("000"); stresc(buf, 256, recp, 0, 0); - snprintf(WC->ImportantMessage, - sizeof WC->ImportantMessage, - "%s%s.", - _("Message has been sent to "), - buf - ); - } - else { - safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage); + AppendImportantMessage(buf, -1); + AppendImportantMessage(_("Message has been sent to "), -1); } } diff --git a/webcit/preferences.c b/webcit/preferences.c index 5f8022304..bae72a33a 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -860,9 +860,7 @@ void GetPreferences(HashList *Setting) void set_preferences(void) { if (!havebstr("change_button")) { - safestrncpy(WC->ImportantMessage, - _("Cancelled. No settings were changed."), - sizeof WC->ImportantMessage); + AppendImportantMessage(_("Cancelled. No settings were changed."), -1); display_main_menu(); return; } diff --git a/webcit/roomops.c b/webcit/roomops.c index b93a4910d..f16fb7f58 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -354,16 +354,12 @@ void ParseGoto(folder *room, StrBuf *Line) */ void delete_room(void) { - char buf[SIZ]; - + StrBuf *Line; serv_puts("KILL 1"); - serv_getln(buf, sizeof buf); - - if (buf[0] != '2') { - strcpy(WC->ImportantMessage, &buf[4]); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { display_main_menu(); - return; } else { StrBuf *Buf; @@ -372,6 +368,7 @@ void delete_room(void) smart_goto(Buf); FreeStrBuf(&Buf); } + FreeStrBuf(&Line); } /* @@ -706,8 +703,7 @@ void editroom(void) int succ1, succ2; if (!havebstr("ok_button")) { - strcpy(WC->ImportantMessage, - _("Cancelled. Changes were not saved.")); + AppendImportantMessage(_("Cancelled. Changes were not saved."), -1); http_transmit_thing(ChrPtr(do_template("room_edit")), 0); return; } @@ -914,7 +910,7 @@ void do_invt_kick(void) */ void entroom(void) { - char buf[SIZ]; + StrBuf *Line; const StrBuf *er_name; const StrBuf *er_type; const StrBuf *er_password; @@ -924,8 +920,7 @@ void entroom(void) wcsession *WCC = WC; if (!havebstr("ok_button")) { - strcpy(WC->ImportantMessage, - _("Cancelled. No new room was created.")); + AppendImportantMessage(_("Cancelled. No new room was created."), -1); display_main_menu(); return; } @@ -953,9 +948,10 @@ void entroom(void) 0, er_view); - serv_getln(buf, sizeof buf); - if (buf[0] != '2') { - strcpy(WCC->ImportantMessage, &buf[4]); + Line = NewStrBuf(); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { + FreeStrBuf(&Line); display_main_menu(); return; } @@ -963,7 +959,8 @@ void entroom(void) gotoroom(er_name); serv_printf("VIEW %d", er_view); - serv_getln(buf, sizeof buf); + StrBuf_ServGetln(Line); + FreeStrBuf(&Line); /* TODO: should we care about errors? */ WCC->CurRoom.view = er_view; if ( (WCC != NULL) && ( (WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) ) { @@ -971,7 +968,7 @@ void entroom(void) } else { smart_goto(WCC->CurRoom.name); } - + FreeStrBuf(&Line); } @@ -998,25 +995,24 @@ void change_view(void) { * Set the message expire policy for this room and/or floor */ void set_room_policy(void) { - char buf[SIZ]; + StrBuf *Line; if (!havebstr("ok_button")) { - strcpy(WC->ImportantMessage, - _("Cancelled. Changes were not saved.")); + AppendImportantMessage(_("Cancelled. Changes were not saved."), -1); http_transmit_thing(ChrPtr(do_template("room_edit")), 0); return; } + Line = NewStrBuf(); serv_printf("SPEX roompolicy|%d|%d", ibstr("roompolicy"), ibstr("roomvalue")); - serv_getln(buf, sizeof buf); - strcpy(WC->ImportantMessage, &buf[4]); - + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 0); if (WC->axlevel >= 6) { - strcat(WC->ImportantMessage, "
\n"); serv_printf("SPEX floorpolicy|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue")); - serv_getln(buf, sizeof buf); - strcat(WC->ImportantMessage, &buf[4]); + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 0); } + FreeStrBuf(&Line); ReloadCurrentRoom(); http_transmit_thing(ChrPtr(do_template("room_edit")), 0); } diff --git a/webcit/sieve.c b/webcit/sieve.c index dd4e3e93a..f4fc58925 100644 --- a/webcit/sieve.c +++ b/webcit/sieve.c @@ -380,8 +380,7 @@ void save_sieve(void) { char buf[256]; if (!havebstr("save_button")) { - strcpy(WC->ImportantMessage, - _("Cancelled. Changes were not saved.")); + AppendImportantMessage(_("Cancelled. Changes were not saved."), -1); display_main_menu(); return; } @@ -437,7 +436,7 @@ void save_sieve(void) { } } - strcpy(WC->ImportantMessage, _("Your changes have been saved.")); + AppendImportantMessage(_("Your changes have been saved."), -1); display_main_menu(); return; } diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index f893b4833..a5af54783 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -269,20 +269,23 @@ void siteconfig(void) { wcsession *WCC = WC; int i; - char buf[256]; + StrBuf *Line; if (strlen(bstr("ok_button")) == 0) { display_aide_menu(); return; } + Line = NewStrBuf(); serv_printf("CONF set"); - serv_getln(buf, sizeof buf); - if (buf[0] != '4') { - safestrncpy(WCC->ImportantMessage, &buf[4], sizeof WCC->ImportantMessage); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 4) != 4) { display_aide_menu(); + FreeStrBuf(&Line); return; } + FreeStrBuf(&Line); + for (i=0; i < (sizeof(ServerConfig) / sizeof(CfgMapping)); i ++) { switch (ServerConfig[i].type) { @@ -310,8 +313,7 @@ void siteconfig(void) FreeStrBuf(&WCC->serv_info->serv_default_cal_zone); WCC->serv_info->serv_default_cal_zone = NewStrBufDup(sbstr("c_default_cal_zone")); - safestrncpy(WCC->ImportantMessage, _("Your system configuration has been updated."), - sizeof WCC->ImportantMessage); + AppendImportantMessage(_("Your system configuration has been updated."), -1); DeleteHash(&WCC->ServCfg); display_aide_menu(); } diff --git a/webcit/sysmsgs.c b/webcit/sysmsgs.c index aae67d930..5ae61336c 100644 --- a/webcit/sysmsgs.c +++ b/webcit/sysmsgs.c @@ -30,13 +30,13 @@ void display_edit(char *description, char *check_cmd, char *read_cmd, char *save_cmd, int with_room_banner) { - char buf[SIZ]; + StrBuf *Line; serv_puts(check_cmd); - serv_getln(buf, sizeof buf); - if (buf[0] != '2') { - safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { + FreeStrBuf(&Line); display_main_menu(); return; } @@ -59,8 +59,8 @@ void display_edit(char *description, char *check_cmd, wc_printf("
\n"); wc_printf("", _("Save changes")); @@ -70,6 +70,7 @@ void display_edit(char *description, char *check_cmd, do_template("box_end"); wDumpContent(1); + FreeStrBuf(&Line); } @@ -81,31 +82,30 @@ void display_edit(char *description, char *check_cmd, */ void save_edit(char *description, char *enter_cmd, int regoto) { - char buf[SIZ]; + StrBuf *Line; if (!havebstr("save_button")) { - sprintf(WC->ImportantMessage, - _("Cancelled. %s was not saved."), - description); + AppendImportantMessage(_("Cancelled. %s was not saved."), -1); display_main_menu(); return; } + Line = NewStrBuf(); serv_puts(enter_cmd); - serv_getln(buf, sizeof buf); - if (buf[0] != '4') { - safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 0) != 4) { + FreeStrBuf(&Line); display_main_menu(); return; } + FreeStrBuf(&Line); text_to_server(bstr("msgtext")); serv_puts("000"); if (regoto) { smart_goto(WC->CurRoom.name); } else { - sprintf(WC->ImportantMessage, - _("%s has been saved."), - description); + AppendImportantMessage(description, -1); + AppendImportantMessage(_(" has been saved."), -1); display_main_menu(); return; } diff --git a/webcit/useredit.c b/webcit/useredit.c index 57aaae864..5a83ed104 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -795,7 +795,7 @@ void create_user(void) { serv_printf("CREU %s", username); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, &FullState) == 2) { - sprintf(WC->ImportantMessage, _("A new user has been created.")); + AppendImportantMessage(_("A new user has been created."), -1); display_edituser(username, 1); } else if (FullState == 570) { diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index ca76ec374..1e1e22297 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -1302,10 +1302,7 @@ void submit_vcard(void) { v = VCardLoad(Buf); /* Start with the extra fields */ FreeStrBuf(&Buf); if (v == NULL) { - safestrncpy(WCC->ImportantMessage, - _("An error has occurred."), - sizeof WCC->ImportantMessage - ); + AppendImportantMessage(_("An error has occurred."), -1); edit_vcard(); return; } @@ -1348,10 +1345,7 @@ void submit_vcard(void) { serialized_vcard = vcard_serialize(v); vcard_free(v); if (serialized_vcard == NULL) { - safestrncpy(WCC->ImportantMessage, - _("An error has occurred."), - sizeof WCC->ImportantMessage - ); + AppendImportantMessage(_("An error has occurred."), -1); edit_vcard(); return; } diff --git a/webcit/webcit.c b/webcit/webcit.c index e61243e6a..90a3db6a3 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -202,20 +202,7 @@ void output_headers( int do_httpheaders, /* 1 = output HTTP headers */ do_template("head"); /* check for ImportantMessages (these display in a div overlaying the main screen) */ - if (!IsEmptyStr(WCC->ImportantMessage)) { - wc_printf("
\n" - ""); - StrEscAppend(WCC->WBuf, NULL, WCC->ImportantMessage, 0, 0); - wc_printf("
\n" - "
\n" - ); - StrBufAppendBufPlain(WCC->trailing_javascript, - HKEY("setTimeout('hide_imsg_popup()', 5000); \n"), - 0 - ); - WCC->ImportantMessage[0] = 0; - } - else if (StrLength(WCC->ImportantMsg) > 0) { + if (StrLength(WCC->ImportantMsg) > 0) { wc_printf("
\n" ""); StrEscAppend(WCC->WBuf, WCC->ImportantMsg, NULL, 0, 0); @@ -334,7 +321,7 @@ void url_do_template(void) { /* * convenience function to indicate success */ -void display_success(char *successmessage) +void display_success(const char *successmessage) { convenience_page("007700", "OK", successmessage); } @@ -364,8 +351,6 @@ void authorization_required(void) if (WCC->ImportantMsg != NULL) message = ChrPtr(WCC->ImportantMsg); - else if (WCC->ImportantMessage != NULL) - message = WCC->ImportantMessage; wc_printf(_("The resource you requested requires a valid username and password. " "You could not be logged in: %s\n"), message); @@ -926,8 +911,7 @@ int ConditionalImportantMesage(StrBuf *Target, WCTemplputParams *TP) { wcsession *WCC = WC; if (WCC != NULL) - return ((!IsEmptyStr(WCC->ImportantMessage)) || - (StrLength(WCC->ImportantMsg) > 0)); + return (StrLength(WCC->ImportantMsg) > 0); else return 0; } @@ -937,11 +921,7 @@ void tmplput_importantmessage(StrBuf *Target, WCTemplputParams *TP) wcsession *WCC = WC; if (WCC != NULL) { - if (!IsEmptyStr(WCC->ImportantMessage)) { - StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0); - WCC->ImportantMessage[0] = '\0'; - } - else if (StrLength(WCC->ImportantMsg) > 0) { + 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 ff7cb680e..cb2e19b83 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -513,7 +513,7 @@ struct wcsession { StrBuf *WFBuf; /* Wildfire error logging buffer */ StrBuf *trailing_javascript; /* extra javascript to be appended to page */ - char ImportantMessage[SIZ]; +/* char ImportantMessage[SIZ];*/ StrBuf *ImportantMsg; HashList *Directory; /* Parts of the directory URL in snippets */ const Floor *CurrentFloor; /* when Parsing REST, which floor are we on? */ @@ -734,7 +734,7 @@ void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf); void display_vcard(StrBuf *Target, wc_mime_attachment *Mime, char alpha, int full, char **storename, long msgnum); -void display_success(char *); +void display_success(const char *successmessage); void shutdown_sessions(void);