3 // Copyright (c) 1996-2022 by the citadel.org team
5 // This program is open source software. Use, duplication, or
6 // disclosure are subject to the GNU General Public License v3.
10 // This function is called by the MIME parser to handle data uploaded by the browser.
11 void upload_handler(char *name, char *filename, char *partnum, char *disp,
12 void *content, char *cbtype, char *cbcharset,
13 size_t length, char *encoding, char *cbid, void *userdata)
15 syslog(LOG_DEBUG, "upload_handler()");
16 syslog(LOG_DEBUG, " name: %s", name);
17 syslog(LOG_DEBUG, " filename: %s", filename);
18 syslog(LOG_DEBUG, " part number: %s", partnum);
19 syslog(LOG_DEBUG, " disposition: %s", disp);
20 syslog(LOG_DEBUG, "content type: %s", cbtype);
21 syslog(LOG_DEBUG, " char set: %s", cbcharset);
22 syslog(LOG_DEBUG, " length: %ld", length);
23 syslog(LOG_DEBUG, " encoding: %s", encoding);
24 syslog(LOG_DEBUG, " id: %s", cbid);
26 // Write the upload to a file that we can pull later when the user saves the message.
27 char tempfile[PATH_MAX];
28 snprintf(tempfile, sizeof tempfile, "/tmp/ctdl_upload_XXXXXX");
29 int fd = mkstemp(tempfile);
31 syslog(LOG_ERR, "upload: %s: %m", tempfile);
34 write(fd, content, length);
39 void upload_files(struct http_transaction *h, struct ctdlsession *c) {
40 // FIXME reject uploads if we're not logged in
42 // h->request_body will contain the upload(s) in MIME format
43 mime_parser(h->request_body, (h->request_body + h->request_body_length), *upload_handler, NULL, NULL, NULL, 0);
45 // probably do something more clever here
46 h->response_code = 200;
47 h->response_string = strdup("OK");
48 add_response_header(h, strdup("Content-type"), strdup("application/json"));
49 h->response_body = "{}";
50 h->response_body_length = strlen(h->response_body);