|
@@ -40,7 +40,7 @@ url_encoded_field_found(const struct mg_connection *conn,
|
|
mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
|
|
mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
|
|
|
|
|
|
if (((size_t)key_dec_len >= (size_t)sizeof(key_dec)) || (key_dec_len < 0)) {
|
|
if (((size_t)key_dec_len >= (size_t)sizeof(key_dec)) || (key_dec_len < 0)) {
|
|
- return MG_FORM_FIELD_STORAGE_SKIP;
|
|
|
|
|
|
+ return MG_FORM_FIELD_STORAGE_SKIP;
|
|
}
|
|
}
|
|
|
|
|
|
if (filename) {
|
|
if (filename) {
|
|
@@ -54,7 +54,7 @@ url_encoded_field_found(const struct mg_connection *conn,
|
|
|| (filename_dec_len < 0)) {
|
|
|| (filename_dec_len < 0)) {
|
|
/* Log error message and skip this field. */
|
|
/* Log error message and skip this field. */
|
|
mg_cry(conn, "%s: Cannot decode filename", __func__);
|
|
mg_cry(conn, "%s: Cannot decode filename", __func__);
|
|
- return MG_FORM_FIELD_STORAGE_SKIP;
|
|
|
|
|
|
+ return MG_FORM_FIELD_STORAGE_SKIP;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
filename_dec[0] = 0;
|
|
filename_dec[0] = 0;
|
|
@@ -63,16 +63,16 @@ url_encoded_field_found(const struct mg_connection *conn,
|
|
ret =
|
|
ret =
|
|
fdh->field_found(key_dec, filename_dec, path, path_len, fdh->user_data);
|
|
fdh->field_found(key_dec, filename_dec, path, path_len, fdh->user_data);
|
|
|
|
|
|
- if ((ret & 0xF) == MG_FORM_FIELD_STORAGE_GET) {
|
|
|
|
|
|
+ if ((ret & 0xF) == MG_FORM_FIELD_STORAGE_GET) {
|
|
if (fdh->field_get == NULL) {
|
|
if (fdh->field_get == NULL) {
|
|
mg_cry(conn, "%s: Function \"Get\" not available", __func__);
|
|
mg_cry(conn, "%s: Function \"Get\" not available", __func__);
|
|
- return MG_FORM_FIELD_STORAGE_SKIP;
|
|
|
|
|
|
+ return MG_FORM_FIELD_STORAGE_SKIP;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if ((ret & 0xF) == MG_FORM_FIELD_STORAGE_STORE) {
|
|
|
|
|
|
+ if ((ret & 0xF) == MG_FORM_FIELD_STORAGE_STORE) {
|
|
if (fdh->field_store == NULL) {
|
|
if (fdh->field_store == NULL) {
|
|
mg_cry(conn, "%s: Function \"Store\" not available", __func__);
|
|
mg_cry(conn, "%s: Function \"Store\" not available", __func__);
|
|
- return MG_FORM_FIELD_STORAGE_SKIP;
|
|
|
|
|
|
+ return MG_FORM_FIELD_STORAGE_SKIP;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -99,7 +99,7 @@ url_encoded_field_get(const struct mg_connection *conn,
|
|
"%s: Not enough memory (required: %lu)",
|
|
"%s: Not enough memory (required: %lu)",
|
|
__func__,
|
|
__func__,
|
|
(unsigned long)(value_len + 1));
|
|
(unsigned long)(value_len + 1));
|
|
- return MG_FORM_FIELD_STORAGE_ABORT;
|
|
|
|
|
|
+ return MG_FORM_FIELD_STORAGE_ABORT;
|
|
}
|
|
}
|
|
|
|
|
|
mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
|
|
mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
|
|
@@ -232,16 +232,16 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
|
|
|
/* In every "field_found" callback we ask what to do with the
|
|
/* In every "field_found" callback we ask what to do with the
|
|
* data ("field_storage"). This could be:
|
|
* data ("field_storage"). This could be:
|
|
- * MG_FORM_FIELD_STORAGE_SKIP (0):
|
|
|
|
- * ignore the value of this field
|
|
|
|
- * MG_FORM_FIELD_STORAGE_GET (1):
|
|
|
|
- * read the data and call the get callback function
|
|
|
|
- * MG_FORM_FIELD_STORAGE_STORE (2):
|
|
|
|
- * store the data in a file
|
|
|
|
- * MG_FORM_FIELD_STORAGE_READ (3):
|
|
|
|
- * let the user read the data (for parsing long data on the fly)
|
|
|
|
- * MG_FORM_FIELD_STORAGE_ABORT (flag):
|
|
|
|
- * stop parsing
|
|
|
|
|
|
+ * MG_FORM_FIELD_STORAGE_SKIP (0):
|
|
|
|
+ * ignore the value of this field
|
|
|
|
+ * MG_FORM_FIELD_STORAGE_GET (1):
|
|
|
|
+ * read the data and call the get callback function
|
|
|
|
+ * MG_FORM_FIELD_STORAGE_STORE (2):
|
|
|
|
+ * store the data in a file
|
|
|
|
+ * MG_FORM_FIELD_STORAGE_READ (3):
|
|
|
|
+ * let the user read the data (for parsing long data on the fly)
|
|
|
|
+ * MG_FORM_FIELD_STORAGE_ABORT (flag):
|
|
|
|
+ * stop parsing
|
|
*/
|
|
*/
|
|
memset(path, 0, sizeof(path));
|
|
memset(path, 0, sizeof(path));
|
|
field_count++;
|
|
field_count++;
|
|
@@ -264,12 +264,12 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
next = val + vallen;
|
|
next = val + vallen;
|
|
}
|
|
}
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
/* Call callback */
|
|
/* Call callback */
|
|
url_encoded_field_get(
|
|
url_encoded_field_get(
|
|
conn, data, (size_t)keylen, val, (size_t)vallen, fdh);
|
|
conn, data, (size_t)keylen, val, (size_t)vallen, fdh);
|
|
}
|
|
}
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
/* Store the content to a file */
|
|
/* Store the content to a file */
|
|
if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
|
|
if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
|
|
fstore.access.fp = NULL;
|
|
fstore.access.fp = NULL;
|
|
@@ -308,7 +308,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /* if (field_storage == MG_FORM_FIELD_STORAGE_READ) { */
|
|
|
|
|
|
+ /* if (field_storage == MG_FORM_FIELD_STORAGE_READ) { */
|
|
/* The idea of "field_storage=read" is to let the API user read
|
|
/* The idea of "field_storage=read" is to let the API user read
|
|
* data chunk by chunk and to some data processing on the fly.
|
|
* data chunk by chunk and to some data processing on the fly.
|
|
* This should avoid the need to store data in the server:
|
|
* This should avoid the need to store data in the server:
|
|
@@ -321,8 +321,8 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
*/
|
|
*/
|
|
/* } */
|
|
/* } */
|
|
|
|
|
|
- if ((field_storage & MG_FORM_FIELD_STORAGE_ABORT)
|
|
|
|
- == MG_FORM_FIELD_STORAGE_ABORT) {
|
|
|
|
|
|
+ if ((field_storage & MG_FORM_FIELD_STORAGE_ABORT)
|
|
|
|
+ == MG_FORM_FIELD_STORAGE_ABORT) {
|
|
/* Stop parsing the request */
|
|
/* Stop parsing the request */
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -399,13 +399,13 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
sizeof(path) - 1,
|
|
sizeof(path) - 1,
|
|
fdh);
|
|
fdh);
|
|
|
|
|
|
- if ((field_storage & MG_FORM_FIELD_STORAGE_ABORT)
|
|
|
|
- == MG_FORM_FIELD_STORAGE_ABORT) {
|
|
|
|
|
|
+ if ((field_storage & MG_FORM_FIELD_STORAGE_ABORT)
|
|
|
|
+ == MG_FORM_FIELD_STORAGE_ABORT) {
|
|
/* Stop parsing the request */
|
|
/* Stop parsing the request */
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
|
|
if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
|
|
fstore.access.fp = NULL;
|
|
fstore.access.fp = NULL;
|
|
}
|
|
}
|
|
@@ -428,7 +428,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
next = val + vallen;
|
|
next = val + vallen;
|
|
}
|
|
}
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
#if 0
|
|
#if 0
|
|
if (!end_of_key_value_pair_found && !all_data_read) {
|
|
if (!end_of_key_value_pair_found && !all_data_read) {
|
|
/* This callback will deliver partial contents */
|
|
/* This callback will deliver partial contents */
|
|
@@ -808,7 +808,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
boundary,
|
|
boundary,
|
|
bl);
|
|
bl);
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
/* Store the content to a file */
|
|
/* Store the content to a file */
|
|
if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
|
|
if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fstore) == 0) {
|
|
fstore.access.fp = NULL;
|
|
fstore.access.fp = NULL;
|
|
@@ -830,7 +830,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
* in the buffer. */
|
|
* in the buffer. */
|
|
towrite -= bl + 4;
|
|
towrite -= bl + 4;
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
unencoded_field_get(conn,
|
|
unencoded_field_get(conn,
|
|
((get_block > 0) ? NULL : nbeg),
|
|
((get_block > 0) ? NULL : nbeg),
|
|
((get_block > 0)
|
|
((get_block > 0)
|
|
@@ -842,7 +842,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
get_block++;
|
|
get_block++;
|
|
}
|
|
}
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
if (fstore.access.fp) {
|
|
if (fstore.access.fp) {
|
|
|
|
|
|
/* Store the content of the buffer. */
|
|
/* Store the content of the buffer. */
|
|
@@ -886,7 +886,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
|
|
|
towrite = (size_t)(next - hend);
|
|
towrite = (size_t)(next - hend);
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_GET) {
|
|
/* Call callback */
|
|
/* Call callback */
|
|
unencoded_field_get(conn,
|
|
unencoded_field_get(conn,
|
|
((get_block > 0) ? NULL : nbeg),
|
|
((get_block > 0) ? NULL : nbeg),
|
|
@@ -897,7 +897,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
fdh);
|
|
fdh);
|
|
}
|
|
}
|
|
|
|
|
|
- if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
|
|
|
|
+ if (field_storage == MG_FORM_FIELD_STORAGE_STORE) {
|
|
|
|
|
|
if (fstore.access.fp) {
|
|
if (fstore.access.fp) {
|
|
n = (size_t)fwrite(hend, 1, towrite, fstore.access.fp);
|
|
n = (size_t)fwrite(hend, 1, towrite, fstore.access.fp);
|
|
@@ -926,8 +926,8 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if ((field_storage & MG_FORM_FIELD_STORAGE_ABORT)
|
|
|
|
- == MG_FORM_FIELD_STORAGE_ABORT) {
|
|
|
|
|
|
+ if ((field_storage & MG_FORM_FIELD_STORAGE_ABORT)
|
|
|
|
+ == MG_FORM_FIELD_STORAGE_ABORT) {
|
|
/* Stop parsing the request */
|
|
/* Stop parsing the request */
|
|
break;
|
|
break;
|
|
}
|
|
}
|