Perform uploads via a (eventually to be hidden) iframe
authorArt Cancro <ajc@citadel.org>
Fri, 10 Dec 2010 21:18:58 +0000 (16:18 -0500)
committerArt Cancro <ajc@citadel.org>
Fri, 10 Dec 2010 21:18:58 +0000 (16:18 -0500)
webcit/messages.c
webcit/static/t/attachments_pane.html [deleted file]
webcit/static/t/edit_message.html
webcit/static/t/edit_message/attachments_pane.html [new file with mode: 0644]

index 88faa7b2e323783abc36a34c4c847449ce13f80c..eefc48039ee729b497df35c97ad4cf905bbce752 100644 (file)
@@ -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()<br>\n");
+
+       if (WCC->upload_length <= 0) {
+               lprintf(9, "ERROR no attachment was uploaded\n");
+               wc_printf("ERROR no attachment was uploaded<br>\n");
+               return;
+       }
+
+       lprintf(9, "Client is uploading %d bytes\n", WCC->upload_length);
+       wc_printf("Client is uploading %d bytes<br>\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 (file)
index bb38634..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<div align="right">
-<a href="javascript:hide_attachments_form();">
-<?_("Close window")>&nbsp;<img src="static/closewindow.gif"></div>
-</a>
-<h2><img src="static/diskette_24x.gif">&nbsp;<?_("Attachments:")></h2>
-
-<ul>
-<?ITERATE("MSG:ATTACHNAMES", ="edit_message_section_attach_select")>
-</ul>
-
-<?_("Attach file:")>
-<input name="attachfile" class="attachfile" size=16 type="file">
-&nbsp;&nbsp;<input type="submit" name="attach_button" value="<?_("Add")>">
-&nbsp;&nbsp;<input type="submit" name="remove_attach_button" value="<?_("Remove")>">
-
-
index 2a07b04ddcf994f62334623ab2abd1268f7386d7..9a534043e1e8300527ac745499fdca3a80a5f27d 100644 (file)
        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 (file)
index 0000000..0bd4c10
--- /dev/null
@@ -0,0 +1,23 @@
+<div align="right">
+<a href="javascript:hide_attachments_form();">
+<?_("Close window")>&nbsp;<img src="static/closewindow.gif"></div>
+</a>
+<h2><img src="static/diskette_24x.gif">&nbsp;<?_("Attachments:")></h2>
+
+<ul>
+<li>FIXME this is teh not done
+<?ITERATE("MSG:ATTACHNAMES", ="edit_message_section_attach_select")>
+<li>FIXME <?_("Add")> <?_("Remove")>
+</ul>
+
+<iframe id="upload_target" name="upload_target" src="" style="width:100;height:100;border:4px solid #fff;">
+Missing iframe support?  Teh b0rwser will not work!!!1
+</iframe>
+
+<form name="upload_attachment_form" id="upload_attachment_form" accept-charset="UTF-8" enctype="multipart/form-data" method="POST" action="upload_attachment" target="upload_target">
+<input type="hidden" name="nonce" value="<?NONCE>">
+
+<input type="hidden" name="submit_action" value="">
+<?_("Attach file:")>
+<input name="attachfile" id="attachfile" class="attachfile" size=40 type="file" onChange="document.upload_attachment_form.submit(); $('attachfile').value='';">
+</form>