* serv_getln now is a wrapper around existing functionality. a new temporary var...
authorWilfried Göesgens <willi@citadel.org>
Mon, 4 May 2009 20:10:56 +0000 (20:10 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 4 May 2009 20:10:56 +0000 (20:10 +0000)
* 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?

14 files changed:
webcit/calendar.c
webcit/downloads.c
webcit/groupdav_propfind.c
webcit/mainmenu.c
webcit/messages.c
webcit/notes.c
webcit/preferences.c
webcit/roomops.c
webcit/serv_func.c
webcit/tcp_sockets.c
webcit/vcard_edit.c
webcit/webcit.c
webcit/webcit.h
webcit/who.c

index 57b98b4001492a8fd3e333f0199e81366c3446fa..48a0f1fc793461630d2a70e8d70a03643e94f9c4 100644 (file)
@@ -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;
index 2de8a4d130a7a51ed86a1708c60439df8218ff2a..5f4ee0647535982ed9ed78e5bcd3f5fbb5fe5daa 100644 (file)
@@ -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 */
index 52103690bb60047d637837a541388c9b071b34ea..00c8d5e3a18745aef716bdf941ee6d532f292143 100644 (file)
@@ -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]);
index f4420d978805626864bd98c32889894656f656f7..965f98f603deeb04d5bb6575327496afdc9b3535 100644 (file)
@@ -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;
index 2edbafcdf07ad841d47dae30460d4a7cabb2bfe9..055009199cf6cfc05193dc627fe1e6424e1ea8ae 100644 (file)
@@ -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);
                                     
index bc5d78952ebcc4282dac57654f66dffac2e61b1d..4870ea0b2b26e46a4d5118f8d218f2ab4186befe 100644 (file)
@@ -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;
index c134355aefaead9bcffe5e8067c4c0ad0ab738bc..36cf40d4f763fca031f0db317f6b61f3a9e39539 100644 (file)
@@ -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);
 }
 
 /**
index 60b6f7176392379392044b7268fc5de9ae9496e4..936defa9bbaba468eb880df8a6c8b4d19b275ef7 100644 (file)
@@ -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("<div class=\"fix_scrollbar_bug\">");
@@ -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("<tr class=\"odd\"><td>");
        wprintf(_("Resides on floor: "));
        wprintf("</td><td>");
-        load_floorlist(); 
+        load_floorlist(Buf); 
         wprintf("<select name=\"er_floor\" size=\"1\">\n");
         for (i = 0; i < 128; ++i)
                 if (!IsEmptyStr(floorlist[i])) {
@@ -2617,6 +2628,7 @@ void display_entroom(void)
        do_template("endbox", NULL);
 
        wDumpContent(1);
+       FreeStrBuf(&Buf);
 }
 
 
@@ -3448,6 +3460,7 @@ void burn_folder_cache(time_t age)
  */
 
 void list_all_rooms_by_floor(const char *viewpref) {
+       StrBuf *Buf;
        char buf[SIZ];
        int swap = 0;
        struct folder *fold = NULL;
@@ -3471,10 +3484,11 @@ void list_all_rooms_by_floor(const char *viewpref) {
                do_iconbar_view(WC->cache_fold, WC->cache_max_folders, WC->cache_num_floors);
                return;
        }
+       Buf = NewStrBuf();
 
        /** Grab the floor table so we know how to build the list... */
-       load_floorlist();
-
+       load_floorlist(Buf);
+       FreeStrBuf(&Buf);
        /** Start with the mailboxes */
        max_folders = 1;
        alloc_folders = 1;
index 50dd83b52b9212bfc6bce34ce01b4793b26fe8bf..7dbc16c940d10037122e841f8e2df9d115492a78 100644 (file)
@@ -458,7 +458,7 @@ int read_server_binary(StrBuf *Ret, size_t total_len, StrBuf *Buf)
                        }
                }
                serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
-               if (StrBuf_ServGetlnBuffered(Buf) > 0)
+               if (StrBuf_ServGetln(Buf) > 0)
                {
                        if (GetServerStatus(Buf, NULL) == 6)
                        {
index f4bb02d580b752af6482c5c3028b022b0e472ed9..89a30a38b390e6a059184ca23c60e445c1154fba 100644 (file)
@@ -63,6 +63,7 @@ int uds_connectsock(char *sockpath)
  */
 int tcp_connectsock(char *host, char *service)
 {
+        int fdflags;
        struct hostent *phe;
        struct servent *pse;
        struct protoent *ppe;
@@ -110,31 +111,14 @@ int tcp_connectsock(char *host, char *service)
        alarm(0);
        signal(SIGALRM, SIG_IGN);
 
+       fdflags = fcntl(s, F_GETFL);
+       fdflags = fdflags | O_NONBLOCK;
+       fcntl(s, F_SETFD, fdflags);
        return (s);
 }
 
 
 
-int StrBuf_ServGetln(StrBuf *buf)
-{
-       wcsession *WCC = WC;
-       const char *ErrStr;
-       int rc;
-
-       WCC->ReadPos = NULL;
-       rc = StrBufTCP_read_line(buf, &WCC->serv_sock, 0, &ErrStr);
-       if (rc < 0)
-       {
-               lprintf(1, "Server connection broken: %s\n",
-                       ErrStr);
-               wc_backtrace();
-               WCC->serv_sock = (-1);
-               WCC->connected = 0;
-               WCC->logged_in = 0;
-       }
-       return rc;
-}
-
 /*
  *  input string from pipe
  */
@@ -142,15 +126,15 @@ int serv_getln(char *strbuf, int bufsize)
 {
        wcsession *WCC = WC;
        int len;
-       
-       WCC->ReadPos = NULL;
 
+       *strbuf = '\0';
        StrBuf_ServGetln(WCC->MigrateReadLineBuf);
        len = StrLength(WCC->MigrateReadLineBuf);
        if (len > bufsize)
                len = bufsize - 1;
        memcpy(strbuf, ChrPtr(WCC->MigrateReadLineBuf), len);
-       strbuf[len] = 0;
+       FlushStrBuf(WCC->MigrateReadLineBuf);
+       strbuf[len] = '\0';
 #ifdef SERV_TRACE
        lprintf(9, "%3d>%s\n", WC->serv_sock, strbuf);
 #endif
@@ -158,7 +142,7 @@ int serv_getln(char *strbuf, int bufsize)
 }
 
 
-int StrBuf_ServGetlnBuffered(StrBuf *buf)
+int StrBuf_ServGetln(StrBuf *buf)
 {
        wcsession *WCC = WC;
        const char *ErrStr;
index d823624dfde260e8568b7d5c212183a2830e8f99..39e0cac1aba81c6417461e6a79faf2fcdb60da51 100644 (file)
@@ -778,7 +778,7 @@ void do_edit_vcard(long msgnum, char *partnum,
                        }
                        Buf = NewStrBuf();
                        serv_printf(buf, "DLAT %ld|%s", msgnum, partnum);
-                       StrBuf_ServGetlnBuffered(Buf);
+                       StrBuf_ServGetln(Buf);
                        if (GetServerStatus(Buf, NULL) != 6) {
                                convenience_page("770000", "Error", &(ChrPtr(Buf)[4]));
                                return;
index dcef892e63f61d50ca48e42036c09b7f512ecf78..9b3a926fbb67b05249ae56812e71e7ad5cd34468 100644 (file)
@@ -476,7 +476,7 @@ void ajax_servcmd(void)
                }
        case 1:
                while (!Done) {
-                       StrBuf_ServGetlnBuffered(Buf);
+                       StrBuf_ServGetln(Buf);
                        if ( (StrLength(Buf)==3) && 
                             !strcmp(ChrPtr(Buf), "000")) {
                                Done = 1;
index a2bc143358a66e1109af76dec8733448eda25433..2d64f5dca98d73ffe85bd9419bd65c3b507005fe 100644 (file)
@@ -543,7 +543,6 @@ int uds_connectsock(char *);
 int tcp_connectsock(char *, char *);
 int serv_getln(char *strbuf, int bufsize);
 int StrBuf_ServGetln(StrBuf *buf);
-int StrBuf_ServGetlnBuffered(StrBuf *buf);
 int GetServerStatus(StrBuf *Line, long* FullState);
 void serv_puts(const char *string);
 void who(void);
@@ -617,7 +616,7 @@ void serv_gets(char *strbuf);
 void serv_write(const char *buf, int nbytes);
 void serv_putbuf(const StrBuf *string);
 void serv_printf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
-void load_floorlist(void);
+void load_floorlist(StrBuf *Buf);
 void shutdown_sessions(void);
 void do_housekeeping(void);
 void smart_goto(const StrBuf *);
index 9f0e3d3d63c76ccef3aaa61a7147aca17978d513..1c19f775796badd2400a7fe9ed6315ced801cff6 100644 (file)
@@ -49,9 +49,9 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf)
        const char *Pos;
 
        serv_puts("RWHO");
-       StrBuf_ServGetlnBuffered(Buf);
+       StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) {
-               while (BufLen = StrBuf_ServGetlnBuffered(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
                        if (BufLen <= 0)
                            continue;
                        Pos = NULL;
@@ -219,7 +219,7 @@ HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP)
        Buf = NewStrBuf();
 
        serv_puts("TIME");
-       StrBuf_ServGetlnBuffered(Buf);
+       StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL)  == 2) {
                const char *pos = ChrPtr(Buf) + 4;
                now = StrBufExtractNext_long(Buf, &pos, '|');