* migrate more of the upload handling to strbuf
authorWilfried Göesgens <willi@citadel.org>
Wed, 8 Jul 2009 22:17:35 +0000 (22:17 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 8 Jul 2009 22:17:35 +0000 (22:17 +0000)
* fix groupdav uploading

webcit/cookie_conversion.c
webcit/downloads.c
webcit/graphics.c
webcit/groupdav_put.c
webcit/messages.c
webcit/paramhandling.c
webcit/webcit.c
webcit/webcit.h

index 58a5742f93903d759537f37e2a5083271f760035..1a3465d3443d624234e3be88d1e8ca8a787dded5 100644 (file)
@@ -10,7 +10,7 @@ typedef unsigned char byte;         /* Byte type used by cookie_to_stuff() */
  * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
  */
 void stuff_to_cookie(char *cookie, size_t clen, int session,
-               StrBuf *user, StrBuf *pass, StrBuf *room, char *language)
+               StrBuf *user, StrBuf *pass, StrBuf *room, const char *language)
 {
        char buf[SIZ];
        int i;
index ba8d03a1d69e11c20b421a7dbda2208cbf80e19d..03b7b8fc72397eaf02c3ed4fe558f75d5877a973 100644 (file)
@@ -307,7 +307,7 @@ void upload_file(void)
        long blocksize;
        wcsession *WCC = WC;     /* stack this for faster access (WC is a function) */
 
-       MimeType = GuessMimeType(WCC->upload, WCC->upload_length); 
+       MimeType = GuessMimeType(ChrPtr(WCC->upload), WCC->upload_length); 
        serv_printf("UOPN %s|%s|%s", WCC->upload_filename, MimeType, bstr("description"));
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2')
@@ -331,7 +331,7 @@ void upload_file(void)
                if (buf[0] == '7')
                {
                        blocksize = atoi(&buf[4]);
-                       serv_write(&WCC->upload[bytes_transmitted], blocksize);
+                       serv_write(&ChrPtr(WCC->upload)[bytes_transmitted], blocksize);
                        bytes_transmitted += blocksize;
                }
        }
index 9e1170df66dbcfd3840cc8581881cdf387f0aab4..f283f34733874a3444e11da418a3f02714c28e5b 100644 (file)
@@ -67,11 +67,12 @@ void display_graphics_upload(char *description, char *filename, char *uplurl)
 void do_graphics_upload(char *filename)
 {
        const char *MimeType;
+       wcsession *WCC = WC;
        char buf[SIZ];
        int bytes_remaining;
        int pos = 0;
        int thisblock;
-       bytes_remaining = WC->upload_length;
+       bytes_remaining = WCC->upload_length;
 
        if (havebstr("cancel_button")) {
                strcpy(WC->ImportantMessage,
@@ -80,20 +81,20 @@ void do_graphics_upload(char *filename)
                return;
        }
 
-       if (WC->upload_length == 0) {
+       if (WCC->upload_length == 0) {
                strcpy(WC->ImportantMessage,
                        _("You didn't upload a file."));
                display_main_menu();
                return;
        }
        
-       MimeType = GuessMimeType(&WC->upload[0], bytes_remaining);
+       MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
        snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
        serv_puts(buf);
 
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
-               strcpy(WC->ImportantMessage, &buf[4]);
+               strcpy(WCC->ImportantMessage, &buf[4]);
                display_main_menu();
                return;
        }
@@ -102,14 +103,14 @@ void do_graphics_upload(char *filename)
                serv_printf("WRIT %d", thisblock);
                serv_getln(buf, sizeof buf);
                if (buf[0] != '7') {
-                       strcpy(WC->ImportantMessage, &buf[4]);
+                       strcpy(WCC->ImportantMessage, &buf[4]);
                        serv_puts("UCLS 0");
                        serv_getln(buf, sizeof buf);
                        display_main_menu();
                        return;
                }
                thisblock = extract_int(&buf[4], 0);
-               serv_write(&WC->upload[pos], thisblock);
+               serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
                pos = pos + thisblock;
                bytes_remaining = bytes_remaining - thisblock;
        }
index bacd77e0d3b12c1c0e7e0bfca9bbf375e3a214da..31074c9d8522ffada0410e4d9ac3403c71b5c85a 100644 (file)
@@ -38,7 +38,7 @@ void groupdav_put_bigics(void)
                return;
        }
 
-       serv_write(WCC->upload, WCC->upload_length);
+       serv_putbuf(WCC->upload);
        serv_printf("\n000");
 
        /* Report success and not much else. */
@@ -152,7 +152,7 @@ void groupdav_put(void)
 
        /* Send the content to the Citadel server */
        serv_printf("Content-type: %s\n\n", WCC->upload_content_type);
-       serv_puts(WCC->upload);
+       serv_putbuf(WCC->upload);
        serv_puts("\n000");
 
        /* Fetch the reply from the Citadel server */
index 96b35a69a06856086cd68b646399c8be9ed1b58b..47f6f41c5eafb2e90c4efa992a7b57d1637f5268 100644 (file)
@@ -1317,10 +1317,9 @@ void post_message(void)
                 * Transfer control of this memory from the upload struct
                 * to the attachment struct.
                 */
-               att->Data = NewStrBufPlain(WCC->upload, WCC->upload_length);
-               free(WCC->upload);
-               WCC->upload_length = 0;
+               att->Data = WCC->upload;
                WCC->upload = NULL;
+               WCC->upload_length = 0;
                display_enter();
                return;
        }
index 613c2cfd9dd2c9c38ebdd883f3fd5967c4310857..c00f9de03121235e67c675b2276cbecb1d690e73 100644 (file)
@@ -292,12 +292,13 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
                        void *content, char *cbtype, char *cbcharset,
                        size_t length, char *encoding, char *cbid, void *userdata)
 {
+       wcsession *WCC = WC;
        urlcontent *u;
 #ifdef DEBUG_URLSTRINGS
        lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
 #endif
-       if (WC->Hdr->urlstrings == NULL)
-               WC->Hdr->urlstrings = NewHash(1, NULL);
+       if (WCC->Hdr->urlstrings == NULL)
+               WCC->Hdr->urlstrings = NewHash(1, NULL);
 
        /* Form fields */
        if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
@@ -306,7 +307,7 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
                safestrncpy(u->url_key, name, sizeof(u->url_key));
                u->url_data = NewStrBufPlain(content, length);
                
-               Put(WC->Hdr->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
+               Put(WCC->Hdr->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
 #ifdef DEBUG_URLSTRINGS
                lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n", 
                        u->url_key, 
@@ -317,18 +318,13 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
 
        /** Uploaded files */
        if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
-               WC->upload = malloc(length);
-               if (WC->upload != NULL) {
-                       WC->upload_length = length;
-                       safestrncpy(WC->upload_filename, filename,
-                                       sizeof(WC->upload_filename));
-                       safestrncpy(WC->upload_content_type, cbtype,
-                                       sizeof(WC->upload_content_type));
-                       memcpy(WC->upload, content, length);
-               }
-               else {
-                       lprintf(3, "malloc() failed: %s\n", strerror(errno));
-               }
+               WCC->upload = NewStrBufPlain(content, length);
+               WCC->upload_length = length;
+               safestrncpy(WCC->upload_filename, filename,
+                           sizeof(WC->upload_filename));
+               safestrncpy(WCC->upload_content_type, cbtype,
+                           sizeof(WC->upload_content_type));
+               
        }
 
 }
index 1f9fd521d1db58d8e4b8a4bd0bc4475dfa42eda5..e89d2e97bf130e839ee8d75e3ed3394f95288740 100644 (file)
@@ -549,6 +549,9 @@ void ReadPostData(void)
                        WCC->Hdr->HR.ContentLength + 
                        body_start;
                mime_parser(ChrPtr(content), content_end, *upload_handler, NULL, NULL, NULL, 0);
+       } else if (WCC->Hdr->HR.ContentLength > 0) {
+               WCC->upload = content;
+               content = NULL;
        }
        FreeStrBuf(&content);
 }
@@ -833,7 +836,7 @@ SessionDetachModule_WEBCIT
 {
        DeleteHash(&sess->Hdr->urlstrings);// TODO?
        if (sess->upload_length > 0) {
-               free(sess->upload);
+               FreeStrBuf(&sess->upload);
                sess->upload_length = 0;
        }
        FreeStrBuf(&sess->trailing_javascript);
index b1f619ea0a9dcd49db3d846f4cf0c4de149e82e6..287d0558cd61438c8f6702883433e961570e6b05 100644 (file)
@@ -529,7 +529,7 @@ struct wcsession {
 /* Uploading; mime attachments for composing messages */
        HashList *attachments;                  /**< list of attachments for 'enter message' */
        int upload_length;                      /**< content length of http-uploaded data */
-       char *upload;                           /**< pointer to http-uploaded data */
+       StrBuf *upload;                         /**< pointer to http-uploaded data */
        char upload_filename[PATH_MAX];         /**< filename of http-uploaded data */
        char upload_content_type[256];          /**< content type of http-uploaded data */
 
@@ -640,7 +640,7 @@ void stuff_to_cookie(char *cookie, size_t clen,
                StrBuf *user,
                StrBuf *pass,
                StrBuf *room,
-               char *language
+               const char *language
 );
 void cookie_to_stuff(StrBuf *cookie,
                int *session,