]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/server/upload.c
webcit-ng: fixed the way HTTP uploads are fed into the MIME Parser.
[citadel.git] / webcit-ng / server / upload.c
index 101d7894882493363773602817a3ce1dcc5e8a91..8c3fd44e0c5d12c771cfcb549ee0ccaa748f28a2 100644 (file)
@@ -26,6 +26,9 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        syslog(LOG_DEBUG, "      length: %ld", length);
        syslog(LOG_DEBUG, "    encoding: %s", encoding);
        syslog(LOG_DEBUG, "          id: %s", cbid);
+       //fprintf(stderr, "\033[31m--------------------------------------------\n");
+       //write(content, length, 1, stderr);    // FIXME
+       //printf(stderr, "--------------------------------------------\033[0m\n");
 
        struct uploaded_file u;
 
@@ -40,12 +43,17 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        u.length = length;
 
        // Write the upload to a file that we can access later when the user saves the message.
+       // tmpfile() creates a file with zero links in the directory, so it will be deleted when it is closed.
        u.fp = tmpfile();
        if (!u.fp) {
                syslog(LOG_ERR, "upload: %m");
                return;
        }
-       fwrite(content, length, 1, u.fp);                       // this file will be deleted by the OS when it is closed
+       if (fwrite(content, length, 1, u.fp) != 1) {
+               syslog(LOG_ERR, "upload: %m");
+               fclose(u.fp);
+               return;
+       }
 
        // Add it to the list of uploads the server is holding.
        pthread_mutex_lock(&upload_list_mutex);
@@ -80,8 +88,8 @@ void upload_files(struct http_transaction *h, struct ctdlsession *c) {
        // Normally the browser will upload only one file per transaction, but that behavior is not guaranteed.
        JsonValue *j_uploads = NewJsonArray(HKEY(""));
 
-       // h->request_body will contain the upload(s) in MIME format
-       mime_parser(h->request_body, (h->request_body + h->request_body_length), *upload_handler, NULL, NULL, j_uploads, 0);
+       // h->request_body_with_synth_headers will contain the upload(s) in MIME format including headers
+       mime_parser(h->request_body_with_synth_headers, (h->request_body+h->request_body_length), *upload_handler, NULL, NULL, j_uploads, 0);
 
        // probably do something more clever here
        h->response_code = 200;