diff --git a/examples/embedded_c/embedded_c.c b/examples/embedded_c/embedded_c.c index 6d83c63d..8ed391f8 100644 --- a/examples/embedded_c/embedded_c.c +++ b/examples/embedded_c/embedded_c.c @@ -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 }; diff --git a/src/civetweb.c b/src/civetweb.c index 1f6ba9ee..6981e0de 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -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; diff --git a/src/handle_form.inl b/src/handle_form.inl index 160fd8c6..b947fda5 100644 --- a/src/handle_form.inl +++ b/src/handle_form.inl @@ -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;