]> code.citadel.org Git - citadel.git/commitdiff
GroupDAV 'GET' operation now loads the message into
authorArt Cancro <ajc@citadel.org>
Thu, 29 Mar 2007 03:43:48 +0000 (03:43 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 29 Mar 2007 03:43:48 +0000 (03:43 +0000)
memory prior to output.  This accomplishes nothing useful yet; it is
preparation for feeding it to the MIME parser so we can strip out
the irrelevant parts.

webcit/groupdav_get.c

index d773fe29bf923701f236e0c99b9718e53f4eece5..56aff429e8d094d319224c63ae333b0ccaef4992 100644 (file)
@@ -111,18 +111,46 @@ void groupdav_get(char *dav_pathname) {
                return;
        }
 
+       /* We got it; a message is now arriving from the server.  Read it in. */
+
+       char *msgtext = NULL;
+       size_t msglen = 0;
+       size_t msgalloc = 0;
+       int linelen;
+
+       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+               linelen = strlen(buf);
+               if ((msglen + linelen + 3) > msgalloc) {
+                       msgalloc = ( (msgalloc > 0) ? (msgalloc * 2) : 1024 );
+                       msgtext = realloc(msgtext, msgalloc);
+               }
+               strcpy(&msgtext[msglen], buf);
+               msglen += linelen;
+               strcpy(&msgtext[msglen], "\n");
+               msglen += 1;
+       }
+       msgtext[msglen] = 0;
+
+       /* Now do something with it.  FIXME boil it down to only the part we need */
+
+       char *ptr = msgtext;
+       char *endptr = &msgtext[msglen];
+
        wprintf("HTTP/1.1 200 OK\r\n");
        groupdav_common_headers();
        wprintf("etag: \"%ld\"\r\n", dav_msgnum);
-       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+
+       do {
+               ptr = memreadline(ptr, buf, sizeof buf);
+
                if (in_body) {
                        wprintf("%s\r\n", buf);
                }
                else if (!strncasecmp(buf, "Date: ", 6)) {
                        wprintf("%s\r\n", buf);
                }
-               else if (!strncasecmp(buf, "Content-type: ", 14)) {
-                       wprintf("%s", buf);
+               else if (!strncasecmp(buf, "Content-type:", 13)) {
+                       /* wprintf("%s", buf); */
                        if (bmstrcasestr(buf, "charset=")) {
                                wprintf("%s\r\n", buf);
                        }
@@ -138,6 +166,9 @@ void groupdav_get(char *dav_pathname) {
                        in_body = 1;
                        begin_burst();
                }
-       }
+       } while (ptr < endptr);
+
        end_burst();
+
+       free(msgtext);
 }