1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-07-31 08:24:23 +03:00

Alternative to mg_upload (Step 27/?)

This commit is contained in:
bel
2016-01-18 21:29:14 +01:00
parent ac0860f6bc
commit 18aaa35145
3 changed files with 36 additions and 5 deletions

View File

@ -162,7 +162,7 @@ enum {
FORM_DISPOSITION_SKIP = 0x0,
FORM_DISPOSITION_GET = 0x1,
FORM_DISPOSITION_STORE = 0x2,
FORM_DISPOSITION_READ = 0x3,
/* FORM_DISPOSITION_READ = 0x3, not in the first step */
FORM_DISPOSITION_ABORT = 0x10
};

View File

@ -6462,7 +6462,7 @@ parse_http_headers(char **buf, struct mg_request_info *ri)
char *dp = *buf;
while ((*dp != ':') && (*dp != '\r') && (*dp != 0)) {
dp++;
}
}
if (!*dp) {
/* neither : nor \r\n. This is not a valid field. */
break;

View File

@ -224,7 +224,6 @@ mg_handle_form_data(struct mg_connection *conn,
}
if (disposition == FORM_DISPOSITION_STORE) {
/* Store the content to a file */
/* TODO: Get "path" from callback" */
FILE *f = fopen(path, "wb");
if (f != NULL) {
size_t n = (size_t)fwrite(val, 1, (size_t)vallen, f);
@ -250,7 +249,7 @@ mg_handle_form_data(struct mg_connection *conn,
* sense, since the data is already stored in memory, as it is
* part of the query string.
*/
/* TODO */
/* TODO, or not TODO, that is the question */
}
if ((disposition & FORM_DISPOSITION_ABORT)
== FORM_DISPOSITION_ABORT) {
@ -320,6 +319,18 @@ mg_handle_form_data(struct mg_connection *conn,
disposition = url_encoded_field_found(
buf, (size_t)keylen, NULL, 0, path, sizeof(path) - 1, fdh);
if (disposition == FORM_DISPOSITION_GET) {
/* TODO */
}
if (disposition == FORM_DISPOSITION_STORE) {
/* TODO */
}
if ((disposition & FORM_DISPOSITION_ABORT)
== FORM_DISPOSITION_ABORT) {
/* Stop parsing the request */
break;
}
/* Proceed to next entry */
used = next - buf;
memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
@ -424,6 +435,10 @@ mg_handle_form_data(struct mg_connection *conn,
* exists, it needs to be terminated correctly). */
return 0;
}
/* TODO: check Content-Type */
/* Content-Type: application/octet-stream */
} else {
fend = fbeg;
}
@ -437,8 +452,24 @@ mg_handle_form_data(struct mg_connection *conn,
sizeof(path) - 1,
fdh);
if (disposition == FORM_DISPOSITION_GET) {
/* TODO */
}
if (disposition == FORM_DISPOSITION_STORE) {
/* Store the content to a file */
FILE *f = fopen(path, "wb");
if (f != NULL) {
/* Content-Type: application/octet-stream */
/* TODO: store from part_header to next boundary */
fclose(f);
} else {
mg_cry(conn, "%s: Cannot create file %s", __func__, path);
}
}
if ((disposition & FORM_DISPOSITION_ABORT) == FORM_DISPOSITION_ABORT) {
/* Stop parsing the request */
/* TODO: break; */
}
/* TODO: handle multipart request */
return 0;