mirror of
https://github.com/lammertb/libhttp.git
synced 2025-07-31 08:24:23 +03:00
Alternative to mg_upload (Step 7/?)
This commit is contained in:
@ -156,7 +156,12 @@ FileHandler(struct mg_connection *conn, void *cbdata)
|
|||||||
|
|
||||||
|
|
||||||
struct mg_form_data_handler {
|
struct mg_form_data_handler {
|
||||||
int (*field_found)(const char *key, const char *value);
|
int (*field_found)(const char *key, const char *value, void *user_data);
|
||||||
|
int (*file_found)(const char *key,
|
||||||
|
const char *filename,
|
||||||
|
int *disposition,
|
||||||
|
void *user_data);
|
||||||
|
void *user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -166,12 +171,13 @@ FormHandler(struct mg_connection *conn, void *cbdata)
|
|||||||
/* Handler may access the request info using mg_get_request_info */
|
/* Handler may access the request info using mg_get_request_info */
|
||||||
const struct mg_request_info *req_info = mg_get_request_info(conn);
|
const struct mg_request_info *req_info = mg_get_request_info(conn);
|
||||||
int ret;
|
int ret;
|
||||||
struct mg_form_data_handler fdh = {0};
|
struct mg_form_data_handler fdh = {0, 0, 0};
|
||||||
|
|
||||||
/* TODO: Checks before calling handle_form_data ? */
|
/* TODO: Checks before calling handle_form_data ? */
|
||||||
(void)req_info;
|
(void)req_info;
|
||||||
|
|
||||||
ret = handle_form_data(conn, &fdh);
|
/* TODO: Handle the return value */
|
||||||
|
ret = mg_handle_form_data(conn, &fdh);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -39,18 +39,24 @@ mirror_body___dev_helper(struct mg_connection *conn)
|
|||||||
|
|
||||||
|
|
||||||
struct mg_form_data_handler {
|
struct mg_form_data_handler {
|
||||||
int (*field_found)(const char *key, const char *value);
|
int (*field_found)(const char *key, const char *value, void *user_data);
|
||||||
|
int (*file_found)(const char *key,
|
||||||
|
const char *filename,
|
||||||
|
int *disposition,
|
||||||
|
void *user_data);
|
||||||
|
void *user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
handle_form_data(struct mg_connection *conn, struct mg_form_data_handler *fdh)
|
mg_handle_form_data(struct mg_connection *conn,
|
||||||
|
struct mg_form_data_handler *fdh)
|
||||||
{
|
{
|
||||||
const char *content_type;
|
const char *content_type;
|
||||||
const char *boundary;
|
const char *boundary;
|
||||||
|
const char *data;
|
||||||
int has_body_data =
|
int has_body_data =
|
||||||
(conn->request_info.content_length > 0) || (conn->is_chunked);
|
(conn->request_info.content_length > 0) || (conn->is_chunked);
|
||||||
char *data;
|
|
||||||
|
|
||||||
/* There are three ways to encode data from a HTML form:
|
/* There are three ways to encode data from a HTML form:
|
||||||
* 1) method: GET (default)
|
* 1) method: GET (default)
|
||||||
|
@ -102,7 +102,7 @@
|
|||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Submit to callback:</legend>
|
<legend>Submit to callback:</legend>
|
||||||
This will only work in the embedded_c example.
|
This will work in the embedded_c example. It will call mg_handle_form_data to parse the request.
|
||||||
<br>
|
<br>
|
||||||
<input type="submit" value="Submit (form default)">
|
<input type="submit" value="Submit (form default)">
|
||||||
<input type="submit" value="Submit (GET)" formmethod="GET">
|
<input type="submit" value="Submit (GET)" formmethod="GET">
|
||||||
|
Reference in New Issue
Block a user