From: Wilfried Göesgens Date: Mon, 4 May 2009 20:10:56 +0000 (+0000) Subject: * serv_getln now is a wrapper around existing functionality. a new temporary var... X-Git-Tag: v7.86~1197 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=c1bfa993f32198515f9994cde602f7bcd4da35d8 * serv_getln now is a wrapper around existing functionality. a new temporary var in WC is used for performance reasons. * non-buffered IO is going away completely, thus we remove the buffered suffix from the function and all places that used it so far * set O_NONBLOCK on our server FD, hopefully this does what we want? --- diff --git a/webcit/calendar.c b/webcit/calendar.c index 57b98b400..48a0f1fc7 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -1063,12 +1063,12 @@ void load_ical_object(long msgnum, int unread, relevant_partnum[0] = '\0'; serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */ Buf = NewStrBuf(); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) != 1) { FreeStrBuf (&Buf); return; } - while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) { + while (!Done && (StrBuf_ServGetln(Buf)>=0)) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; diff --git a/webcit/downloads.c b/webcit/downloads.c index 2de8a4d13..5f4ee0647 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -251,7 +251,7 @@ void download_file(void) Buf = NewStrBuf(); StrBufUnescape(WCC->UrlFragment2, 1); serv_printf("OPEN %s", ChrPtr(WCC->UrlFragment2)); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 2) { StrBufCutLeft(Buf, 4); bytes = StrBufExtract_long(Buf, 0, '|'); @@ -260,7 +260,7 @@ void download_file(void) } read_server_binary(WCC->WBuf, bytes, Buf); serv_puts("CLOS"); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); http_transmit_thing(ChrPtr(ContentType), 0); } else { StrBufCutLeft(Buf, 4); @@ -358,7 +358,7 @@ void output_image(void) Buf = NewStrBuf(); serv_printf("OIMG %s|%s", bstr("name"), bstr("parm")); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 2) { StrBufCutLeft(Buf, 4); bytes = StrBufExtract_long(Buf, 0, '|'); @@ -367,7 +367,7 @@ void output_image(void) if (read_server_binary(WCC->WBuf, bytes, Buf) > 0) { serv_puts("CLOS"); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); MimeType = GuessMimeType (ChrPtr(WCC->WBuf), StrLength(WCC->WBuf)); /** Write it to the browser */ diff --git a/webcit/groupdav_propfind.c b/webcit/groupdav_propfind.c index 52103690b..00c8d5e3a 100644 --- a/webcit/groupdav_propfind.c +++ b/webcit/groupdav_propfind.c @@ -399,7 +399,7 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_ StrBuf_ServGetln(MsgNum); if (GetServerStatus(MsgNum, NULL) == 1) - while (BufLen = StrBuf_ServGetlnBuffered(MsgNum), strcmp(ChrPtr(MsgNum), "000")) { + while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000")) { msgs = realloc(msgs, ++num_msgs * sizeof(long)); msgs[num_msgs-1] = StrTol(MsgNum); } @@ -411,7 +411,7 @@ void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_ serv_printf("MSG0 %ld|3", msgs[i]); StrBuf_ServGetln(MsgNum); if (GetServerStatus(MsgNum, NULL) == 1) - while (BufLen = StrBuf_ServGetlnBuffered(MsgNum), strcmp(ChrPtr(MsgNum), "000")) + while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000")) { if (!strncasecmp(ChrPtr(MsgNum), "exti=", 5)) { strcpy(uid, &ChrPtr(MsgNum)[5]); diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index f4420d978..965f98f60 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -295,7 +295,7 @@ void do_generic(void) } case 1: while (!Done) { - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; diff --git a/webcit/messages.c b/webcit/messages.c index 2edbafcdf..055009199 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -67,7 +67,7 @@ int load_message(message_summary *Msg, /** begin everythingamundo table */ HdrToken = NewStrBuf(); - while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) { + while ((StrBuf_ServGetln(Buf)>=0) && !Done) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { @@ -381,7 +381,7 @@ message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSu serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */ - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 1) { FreeStrBuf(&Buf); return NULL; @@ -389,7 +389,7 @@ message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSu Msg = (message_summary*)malloc(sizeof(message_summary)); memset(Msg, 0, sizeof(message_summary)); - while (len = StrBuf_ServGetlnBuffered(Buf), + while (len = StrBuf_ServGetln(Buf), ((len != 3) || strcmp(ChrPtr(Buf), "000")== 0)){ buf = ChrPtr(Buf); @@ -436,13 +436,13 @@ int load_msg_ptrs(const char *servcmd, int with_headers) Buf = NewStrBuf(); serv_puts(servcmd); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) != 1) { FreeStrBuf(&Buf); return (nummsgs); } Buf2 = NewStrBuf(); - while (len = StrBuf_ServGetlnBuffered(Buf), + while (len = StrBuf_ServGetln(Buf), ((len != 3) || strcmp(ChrPtr(Buf), "000")!= 0)) { @@ -1574,7 +1574,7 @@ void mimepart(int force_download) Buf = NewStrBuf(); serv_printf("OPNA %s|%s", ChrPtr(WCC->UrlFragment2), ChrPtr(WCC->UrlFragment3)); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 2) { StrBufCutLeft(Buf, 4); bytes = StrBufExtract_long(Buf, 0, '|'); @@ -1584,7 +1584,7 @@ void mimepart(int force_download) read_server_binary(WCC->WBuf, bytes, Buf); serv_puts("CLOS"); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); CT = ChrPtr(ContentType); if (!force_download) { @@ -1620,7 +1620,7 @@ StrBuf *load_mimepart(long msgnum, char *partnum) Buf = NewStrBuf(); serv_printf("DLAT %ld|%s", msgnum, partnum); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 6) { StrBufCutLeft(Buf, 4); bytes = StrBufExtract_long(Buf, 0, '|'); @@ -1644,7 +1644,7 @@ void MimeLoadData(wc_mime_attachment *Mime) /* TODO: is there a chance the contenttype is different to the one we know? */ serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum)); Buf = NewStrBuf(); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 6) { bytes = extract_long(&(ChrPtr(Buf)[4]), 0); diff --git a/webcit/notes.c b/webcit/notes.c index bc5d78952..4870ea0b2 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -46,12 +46,12 @@ struct vnote *vnote_new_from_msg(long msgnum,int unread) relevant_partnum[0] = '\0'; serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */ Buf = NewStrBuf(); - StrBuf_ServGetlnBuffered(Buf); + StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) != 1) { FreeStrBuf (&Buf); return NULL; } - while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) { + while ((StrBuf_ServGetln(Buf)>=0) && !Done) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; diff --git a/webcit/preferences.c b/webcit/preferences.c index c134355ae..36cf40d4f 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -190,8 +190,8 @@ void ParsePref(HashList **List, StrBuf *ReadBuf) */ void load_preferences(void) { + int Done = 0; StrBuf *ReadBuf; - char buf[SIZ]; long msgnum = 0L; if (goto_config_room() != 0) return; /* oh well. */ @@ -203,8 +203,14 @@ void load_preferences(void) serv_puts("subj|__ WebCit Preferences __"); serv_puts("000"); } - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - msgnum = atol(buf); + while (!Done && + StrBuf_ServGetln(ReadBuf)) { + if ( (StrLength(ReadBuf)==3) && + !strcmp(ChrPtr(ReadBuf), "000")) { + Done = 1; + break; + } + msgnum = StrTol(ReadBuf); } if (msgnum > 0L) { @@ -307,28 +313,37 @@ void WritePrefsToServer(HashList *Hash) */ void save_preferences(void) { - char buf[SIZ]; + int Done; + StrBuf *ReadBuf; long msgnum = 0L; + ReadBuf = NewStrBuf(); if (goto_config_room() != 0) return; /* oh well. */ serv_puts("MSGS ALL|0|1"); - serv_getln(buf, sizeof buf); - if (buf[0] == '8') { + StrBuf_ServGetln(ReadBuf); + if (GetServerStatus(ReadBuf, NULL) == 8) { serv_puts("subj|__ WebCit Preferences __"); serv_puts("000"); } - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - msgnum = atol(buf); + while (!Done && + StrBuf_ServGetln(ReadBuf)) { + if ( (StrLength(ReadBuf)==3) && + !strcmp(ChrPtr(ReadBuf), "000")) { + Done = 1; + break; + } + msgnum = StrTol(ReadBuf); } if (msgnum > 0L) { serv_printf("DELE %ld", msgnum); - serv_getln(buf, sizeof buf); + StrBuf_ServGetln(ReadBuf); + GetServerStatus(ReadBuf, NULL); } serv_printf("ENT0 1||0|1|__ WebCit Preferences __|"); - serv_getln(buf, sizeof buf); - if (buf[0] == '4') { + StrBuf_ServGetln(ReadBuf); + if (GetServerStatus(ReadBuf, NULL) == 4) { WritePrefsToServer(WC->hash_prefs); serv_puts(""); @@ -337,7 +352,8 @@ void save_preferences(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(ReadBuf); + FreeStrBuf(&ReadBuf); } /** diff --git a/webcit/roomops.c b/webcit/roomops.c index 60b6f7176..936defa9b 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -72,22 +72,27 @@ int is_view_allowed_as_default(int which_view) /* * load the list of floors */ -void load_floorlist(void) +void load_floorlist(StrBuf *Buf) { int a; - char buf[SIZ]; + int Done = 0; for (a = 0; a < MAX_FLOORS; ++a) floorlist[a][0] = 0; serv_puts("LFLR"); - serv_getln(buf, sizeof buf); - if (buf[0] != '1') { + StrBuf_ServGetln(Buf); + if (GetServerStatus(Buf, NULL) != 1) { strcpy(floorlist[0], "Main Floor"); return; } - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', sizeof floorlist[0]); + while (!Done && (StrBuf_ServGetln(Buf)>=0)) { + if ( (StrLength(Buf)==3) && + !strcmp(ChrPtr(Buf), "000")) { + Done = 1; + break; + } + extract_token(floorlist[StrBufExtract_int(Buf, 0, '|')], ChrPtr(Buf), 1, '|', sizeof floorlist[0]); } } @@ -1157,6 +1162,7 @@ int set_roomflags(room_states *RoomOps) */ void display_editroom(void) { + StrBuf *Buf; char buf[SIZ]; char cmd[1024]; char node[256]; @@ -1184,7 +1190,9 @@ void display_editroom(void) tab = bstr("tab"); if (IsEmptyStr(tab)) tab = "admin"; - load_floorlist(); + Buf = NewStrBuf(); + load_floorlist(Buf); + FreeStrBuf(&Buf); output_headers(1, 1, 1, 0, 0, 0); wprintf("
"); @@ -2477,15 +2485,18 @@ void display_whok(void) */ void display_entroom(void) { + StrBuf *Buf; int i; char buf[SIZ]; + Buf = NewStrBuf(); serv_puts("CRE8 0"); serv_getln(buf, sizeof buf); if (buf[0] != '2') { strcpy(WC->ImportantMessage, &buf[4]); display_main_menu(); + FreeStrBuf(&Buf); return; } @@ -2508,7 +2519,7 @@ void display_entroom(void) wprintf(""); wprintf(_("Resides on floor: ")); wprintf(""); - load_floorlist(); + load_floorlist(Buf); wprintf("