mirror of
https://github.com/lammertb/libhttp.git
synced 2025-12-22 04:02:04 +03:00
Alternative to mg_upload (Step 32/?)
This commit is contained in:
@@ -383,7 +383,6 @@ mg_handle_form_data(struct mg_connection *conn,
|
||||
fclose(fstore);
|
||||
}
|
||||
|
||||
|
||||
/* Proceed to next entry */
|
||||
used = next - buf;
|
||||
memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
|
||||
@@ -400,9 +399,11 @@ mg_handle_form_data(struct mg_connection *conn,
|
||||
const char *boundary;
|
||||
size_t bl;
|
||||
int r;
|
||||
ptrdiff_t used;
|
||||
struct mg_request_info part_header;
|
||||
char *hbuf, *hend, *fbeg, *fend, *nbeg, *nend;
|
||||
const char *content_disp;
|
||||
const char *next;
|
||||
|
||||
memset(&part_header, 0, sizeof(part_header));
|
||||
|
||||
@@ -415,6 +416,8 @@ mg_handle_form_data(struct mg_connection *conn,
|
||||
boundary = content_type + 30;
|
||||
bl = strlen(boundary);
|
||||
|
||||
do {
|
||||
|
||||
r = mg_read(conn,
|
||||
buf + (size_t)buf_fill,
|
||||
sizeof(buf) - 1 - (size_t)buf_fill);
|
||||
@@ -484,7 +487,8 @@ mg_handle_form_data(struct mg_connection *conn,
|
||||
fbeg += 10;
|
||||
fend = strchr(fbeg, '\"');
|
||||
if (!fend) {
|
||||
/* Malformed request (the filename field is optional, but if it
|
||||
/* Malformed request (the filename field is optional, but if
|
||||
* it
|
||||
* exists, it needs to be terminated correctly). */
|
||||
return 0;
|
||||
}
|
||||
@@ -505,8 +509,7 @@ mg_handle_form_data(struct mg_connection *conn,
|
||||
sizeof(path) - 1,
|
||||
fdh);
|
||||
|
||||
do {
|
||||
const char *next = strstr(hbuf, "--");
|
||||
next = strstr(hbuf, "--");
|
||||
while (next && (strncmp(next + 2, boundary, bl))) {
|
||||
/* found "--" not followed by boundary: look for next "--" */
|
||||
next = strstr(next + 1, "--");
|
||||
@@ -528,6 +531,7 @@ mg_handle_form_data(struct mg_connection *conn,
|
||||
(size_t)(next - hend),
|
||||
fdh);
|
||||
}
|
||||
|
||||
if (disposition == FORM_DISPOSITION_STORE) {
|
||||
/* Store the content to a file */
|
||||
FILE *f = fopen(path, "wb");
|
||||
@@ -544,7 +548,13 @@ mg_handle_form_data(struct mg_connection *conn,
|
||||
/* Stop parsing the request */
|
||||
return 0;
|
||||
}
|
||||
} while (0 /* TODO */);
|
||||
|
||||
/* Remove from the buffer */
|
||||
used = next - buf;
|
||||
memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
|
||||
buf_fill -= used;
|
||||
|
||||
} while (1 /* TODO */);
|
||||
|
||||
/* TODO: handle multipart request */
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user