From 95a9d30497849472db7135888eb2df1fc4a721b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Wed, 8 Jul 2009 22:17:35 +0000 Subject: [PATCH] * migrate more of the upload handling to strbuf * fix groupdav uploading --- webcit/cookie_conversion.c | 2 +- webcit/downloads.c | 4 ++-- webcit/graphics.c | 13 +++++++------ webcit/groupdav_put.c | 4 ++-- webcit/messages.c | 5 ++--- webcit/paramhandling.c | 26 +++++++++++--------------- webcit/webcit.c | 5 ++++- webcit/webcit.h | 4 ++-- 8 files changed, 31 insertions(+), 32 deletions(-) diff --git a/webcit/cookie_conversion.c b/webcit/cookie_conversion.c index 58a5742f9..1a3465d34 100644 --- a/webcit/cookie_conversion.c +++ b/webcit/cookie_conversion.c @@ -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; diff --git a/webcit/downloads.c b/webcit/downloads.c index ba8d03a1d..03b7b8fc7 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -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; } } diff --git a/webcit/graphics.c b/webcit/graphics.c index 9e1170df6..f283f3473 100644 --- a/webcit/graphics.c +++ b/webcit/graphics.c @@ -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; } diff --git a/webcit/groupdav_put.c b/webcit/groupdav_put.c index bacd77e0d..31074c9d8 100644 --- a/webcit/groupdav_put.c +++ b/webcit/groupdav_put.c @@ -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 */ diff --git a/webcit/messages.c b/webcit/messages.c index 96b35a69a..47f6f41c5 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -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; } diff --git a/webcit/paramhandling.c b/webcit/paramhandling.c index 613c2cfd9..c00f9de03 100644 --- a/webcit/paramhandling.c +++ b/webcit/paramhandling.c @@ -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)); + } } diff --git a/webcit/webcit.c b/webcit/webcit.c index 1f9fd521d..e89d2e97b 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -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); diff --git a/webcit/webcit.h b/webcit/webcit.h index b1f619ea0..287d0558c 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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, -- 2.30.2