From 4e52f9f0b9d0193aa490b86e8d114c70a9759fb8 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 10 Dec 2010 16:18:58 -0500 Subject: [PATCH] Perform uploads via a (eventually to be hidden) iframe --- webcit/messages.c | 120 ++++++++++-------- webcit/static/t/attachments_pane.html | 16 --- webcit/static/t/edit_message.html | 2 +- .../t/edit_message/attachments_pane.html | 23 ++++ 4 files changed, 90 insertions(+), 71 deletions(-) delete mode 100644 webcit/static/t/attachments_pane.html create mode 100644 webcit/static/t/edit_message/attachments_pane.html diff --git a/webcit/messages.c b/webcit/messages.c index 88faa7b2e..eefc48039 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1005,7 +1005,6 @@ void post_message(void) char buf[1024]; StrBuf *encoded_subject = NULL; static long dont_post = (-1L); - wc_mime_attachment *att; int is_anonymous = 0; const StrBuf *display_name = NULL; wcsession *WCC = WC; @@ -1023,59 +1022,6 @@ void post_message(void) } } - if (WCC->upload_length > 0) { - const char *pch; - int n; - const char *newn; - long newnlen; - void *v; - - /* There's an attachment. Save it to this struct... */ - lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length); - att = malloc(sizeof(wc_mime_attachment)); - memset(att, 0, sizeof(wc_mime_attachment )); - att->length = WCC->upload_length; - att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1); - att->FileName = NewStrBufDup(WCC->upload_filename); - - if (WCC->attachments == NULL) { - WCC->attachments = NewHash(1, Flathash); - } - - /* And add it to the list. */ - n = 0; - if ((GetCount(WCC->attachments) > 0) && - GetHashAt(WCC->attachments, - GetCount(WCC->attachments) -1, - &newnlen, &newn, &v)) - n = *((int*) newn) + 1; - Put(WCC->attachments, IKEY(n), att, DestroyMime); - - /* - * Mozilla sends a simple filename, which is what we want, - * but Satan's Browser sends an entire pathname. Reduce - * the path to just a filename if we need to. - */ - pch = strrchr(ChrPtr(att->FileName), '/'); - if (pch != NULL) { - StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1); - } - pch = strrchr(ChrPtr(att->FileName), '\\'); - if (pch != NULL) { - StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1); - } - - /* - * Transfer control of this memory from the upload struct - * to the attachment struct. - */ - att->Data = WCC->upload; - WCC->upload = NULL; - WCC->upload_length = 0; - - /* and keep going, because we don't do attachments in two posts anymore */ - } - if (!strcasecmp(bstr("submit_action"), "cancel")) { sprintf(WCC->ImportantMessage, _("Cancelled. Message was not posted.")); @@ -1257,6 +1203,71 @@ void post_message(void) } +/* + * Client is uploading an attachment + */ +void upload_attachment(void) { + wcsession *WCC = WC; + const char *pch; + int n; + const char *newn; + long newnlen; + void *v; + wc_mime_attachment *att; + + lprintf(9, "upload_attachment()\n"); + wc_printf("upload_attachment()
\n"); + + if (WCC->upload_length <= 0) { + lprintf(9, "ERROR no attachment was uploaded\n"); + wc_printf("ERROR no attachment was uploaded
\n"); + return; + } + + lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length); + wc_printf("Client is uploading %d bytes
\n", WCC->upload_length); + att = malloc(sizeof(wc_mime_attachment)); + memset(att, 0, sizeof(wc_mime_attachment )); + att->length = WCC->upload_length; + att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1); + att->FileName = NewStrBufDup(WCC->upload_filename); + + if (WCC->attachments == NULL) { + WCC->attachments = NewHash(1, Flathash); + } + + /* And add it to the list. */ + n = 0; + if ((GetCount(WCC->attachments) > 0) && + GetHashAt(WCC->attachments, + GetCount(WCC->attachments) -1, + &newnlen, &newn, &v)) + n = *((int*) newn) + 1; + Put(WCC->attachments, IKEY(n), att, DestroyMime); + + /* + * Mozilla sends a simple filename, which is what we want, + * but Satan's Browser sends an entire pathname. Reduce + * the path to just a filename if we need to. + */ + pch = strrchr(ChrPtr(att->FileName), '/'); + if (pch != NULL) { + StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1); + } + pch = strrchr(ChrPtr(att->FileName), '\\'); + if (pch != NULL) { + StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1); + } + + /* + * Transfer control of this memory from the upload struct + * to the attachment struct. + */ + att->Data = WCC->upload; + WCC->upload = NULL; + WCC->upload_length = 0; +} + /* @@ -1787,6 +1798,7 @@ InitModule_MSG WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL); WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL|PROHIBIT_STARTPAGE); WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL|PROHIBIT_STARTPAGE); + WebcitAddUrlHandler(HKEY("upload_attachment"), "", 0, upload_attachment, AJAX); /* json */ WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0); diff --git a/webcit/static/t/attachments_pane.html b/webcit/static/t/attachments_pane.html deleted file mode 100644 index bb3863483..000000000 --- a/webcit/static/t/attachments_pane.html +++ /dev/null @@ -1,16 +0,0 @@ -
- - 
- -

 

- - - - - -  "> -  "> - - diff --git a/webcit/static/t/edit_message.html b/webcit/static/t/edit_message.html index 2a07b04dd..9a534043e 100644 --- a/webcit/static/t/edit_message.html +++ b/webcit/static/t/edit_message.html @@ -163,7 +163,7 @@ function show_attachments_form() { $('attachments_form').style.display = 'block'; - p = 'template=attachments_pane&r=' + CtdlRandomString(); + p = 'template=edit_message_attachments_pane&r=' + CtdlRandomString(); new Ajax.Updater( 'attachments_form', 'do_template', diff --git a/webcit/static/t/edit_message/attachments_pane.html b/webcit/static/t/edit_message/attachments_pane.html new file mode 100644 index 000000000..0bd4c10d0 --- /dev/null +++ b/webcit/static/t/edit_message/attachments_pane.html @@ -0,0 +1,23 @@ +
+ + 
+ +

 

+ + + + + +
+ + + + + +
-- 2.30.2