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);
|
fclose(fstore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Proceed to next entry */
|
/* Proceed to next entry */
|
||||||
used = next - buf;
|
used = next - buf;
|
||||||
memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
|
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;
|
const char *boundary;
|
||||||
size_t bl;
|
size_t bl;
|
||||||
int r;
|
int r;
|
||||||
|
ptrdiff_t used;
|
||||||
struct mg_request_info part_header;
|
struct mg_request_info part_header;
|
||||||
char *hbuf, *hend, *fbeg, *fend, *nbeg, *nend;
|
char *hbuf, *hend, *fbeg, *fend, *nbeg, *nend;
|
||||||
const char *content_disp;
|
const char *content_disp;
|
||||||
|
const char *next;
|
||||||
|
|
||||||
memset(&part_header, 0, sizeof(part_header));
|
memset(&part_header, 0, sizeof(part_header));
|
||||||
|
|
||||||
@@ -415,6 +416,8 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
boundary = content_type + 30;
|
boundary = content_type + 30;
|
||||||
bl = strlen(boundary);
|
bl = strlen(boundary);
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
r = mg_read(conn,
|
r = mg_read(conn,
|
||||||
buf + (size_t)buf_fill,
|
buf + (size_t)buf_fill,
|
||||||
sizeof(buf) - 1 - (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;
|
fbeg += 10;
|
||||||
fend = strchr(fbeg, '\"');
|
fend = strchr(fbeg, '\"');
|
||||||
if (!fend) {
|
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). */
|
* exists, it needs to be terminated correctly). */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -505,8 +509,7 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
sizeof(path) - 1,
|
sizeof(path) - 1,
|
||||||
fdh);
|
fdh);
|
||||||
|
|
||||||
do {
|
next = strstr(hbuf, "--");
|
||||||
const char *next = strstr(hbuf, "--");
|
|
||||||
while (next && (strncmp(next + 2, boundary, bl))) {
|
while (next && (strncmp(next + 2, boundary, bl))) {
|
||||||
/* found "--" not followed by boundary: look for next "--" */
|
/* found "--" not followed by boundary: look for next "--" */
|
||||||
next = strstr(next + 1, "--");
|
next = strstr(next + 1, "--");
|
||||||
@@ -528,6 +531,7 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
(size_t)(next - hend),
|
(size_t)(next - hend),
|
||||||
fdh);
|
fdh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disposition == FORM_DISPOSITION_STORE) {
|
if (disposition == FORM_DISPOSITION_STORE) {
|
||||||
/* Store the content to a file */
|
/* Store the content to a file */
|
||||||
FILE *f = fopen(path, "wb");
|
FILE *f = fopen(path, "wb");
|
||||||
@@ -544,7 +548,13 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
/* Stop parsing the request */
|
/* Stop parsing the request */
|
||||||
return 0;
|
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 */
|
/* TODO: handle multipart request */
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user