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:
@ -162,7 +162,7 @@ enum {
|
|||||||
FORM_DISPOSITION_SKIP = 0x0,
|
FORM_DISPOSITION_SKIP = 0x0,
|
||||||
FORM_DISPOSITION_GET = 0x1,
|
FORM_DISPOSITION_GET = 0x1,
|
||||||
FORM_DISPOSITION_STORE = 0x2,
|
FORM_DISPOSITION_STORE = 0x2,
|
||||||
FORM_DISPOSITION_READ = 0x3,
|
/* FORM_DISPOSITION_READ = 0x3, not in the first step */
|
||||||
FORM_DISPOSITION_ABORT = 0x10
|
FORM_DISPOSITION_ABORT = 0x10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6462,7 +6462,7 @@ parse_http_headers(char **buf, struct mg_request_info *ri)
|
|||||||
char *dp = *buf;
|
char *dp = *buf;
|
||||||
while ((*dp != ':') && (*dp != '\r') && (*dp != 0)) {
|
while ((*dp != ':') && (*dp != '\r') && (*dp != 0)) {
|
||||||
dp++;
|
dp++;
|
||||||
}
|
}
|
||||||
if (!*dp) {
|
if (!*dp) {
|
||||||
/* neither : nor \r\n. This is not a valid field. */
|
/* neither : nor \r\n. This is not a valid field. */
|
||||||
break;
|
break;
|
||||||
|
@ -224,7 +224,6 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
}
|
}
|
||||||
if (disposition == FORM_DISPOSITION_STORE) {
|
if (disposition == FORM_DISPOSITION_STORE) {
|
||||||
/* Store the content to a file */
|
/* Store the content to a file */
|
||||||
/* TODO: Get "path" from callback" */
|
|
||||||
FILE *f = fopen(path, "wb");
|
FILE *f = fopen(path, "wb");
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
size_t n = (size_t)fwrite(val, 1, (size_t)vallen, f);
|
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
|
* sense, since the data is already stored in memory, as it is
|
||||||
* part of the query string.
|
* part of the query string.
|
||||||
*/
|
*/
|
||||||
/* TODO */
|
/* TODO, or not TODO, that is the question */
|
||||||
}
|
}
|
||||||
if ((disposition & FORM_DISPOSITION_ABORT)
|
if ((disposition & FORM_DISPOSITION_ABORT)
|
||||||
== FORM_DISPOSITION_ABORT) {
|
== FORM_DISPOSITION_ABORT) {
|
||||||
@ -320,6 +319,18 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
disposition = url_encoded_field_found(
|
disposition = url_encoded_field_found(
|
||||||
buf, (size_t)keylen, NULL, 0, path, sizeof(path) - 1, fdh);
|
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 */
|
/* 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);
|
||||||
@ -424,6 +435,10 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
* exists, it needs to be terminated correctly). */
|
* exists, it needs to be terminated correctly). */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: check Content-Type */
|
||||||
|
/* Content-Type: application/octet-stream */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fend = fbeg;
|
fend = fbeg;
|
||||||
}
|
}
|
||||||
@ -437,8 +452,24 @@ mg_handle_form_data(struct mg_connection *conn,
|
|||||||
sizeof(path) - 1,
|
sizeof(path) - 1,
|
||||||
fdh);
|
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 */
|
/* TODO: handle multipart request */
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user