Commit 22cb0efd authored by Alexander Alashkin's avatar Alexander Alashkin Committed by Marko Mikulicic

Implement FW upload via POST

    PUBLISHED_FROM=6167cc57df932f6c113d03096eba0af0b456c3c3
parent a68d3d63
...@@ -4961,7 +4961,7 @@ static void mg_call_endpoint_handler(struct mg_connection *nc, int ev, ...@@ -4961,7 +4961,7 @@ static void mg_call_endpoint_handler(struct mg_connection *nc, int ev,
#ifdef MG_ENABLE_HTTP_STREAMING_MULTIPART #ifdef MG_ENABLE_HTTP_STREAMING_MULTIPART
static void mg_multipart_continue(struct mg_connection *nc, struct mbuf *io, static void mg_multipart_continue(struct mg_connection *nc, struct mbuf *io,
int req_len, int ev, void *ev_data); int ev, void *ev_data);
static void mg_multipart_begin(struct mg_connection *nc, static void mg_multipart_begin(struct mg_connection *nc,
struct http_message *hm, struct mbuf *io, struct http_message *hm, struct mbuf *io,
...@@ -5020,6 +5020,14 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -5020,6 +5020,14 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
if (ev == MG_EV_RECV) { if (ev == MG_EV_RECV) {
struct mg_str *s; struct mg_str *s;
#ifdef MG_ENABLE_HTTP_STREAMING_MULTIPART
if (nc->strm_state.len != 0) {
mg_multipart_continue(nc, io, ev, ev_data);
return;
}
#endif /* MG_ENABLE_HTTP_STREAMING_MULTIPART */
req_len = mg_parse_http(io->buf, io->len, hm, is_req); req_len = mg_parse_http(io->buf, io->len, hm, is_req);
if (req_len > 0 && if (req_len > 0 &&
...@@ -5028,11 +5036,8 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -5028,11 +5036,8 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_handle_chunked(nc, hm, io->buf + req_len, io->len - req_len); mg_handle_chunked(nc, hm, io->buf + req_len, io->len - req_len);
} }
if ( /* TODO(alashkin): refactor this ifelseifelseifelseifelse */
#ifdef MG_ENABLE_HTTP_STREAMING_MULTIPART if ((req_len < 0 ||
nc->strm_state.len == 0 &&
#endif /* MG_ENABLE_HTTP_STREAMING_MULTIPART */
(req_len < 0 ||
(req_len == 0 && io->len >= MG_MAX_HTTP_REQUEST_SIZE))) { (req_len == 0 && io->len >= MG_MAX_HTTP_REQUEST_SIZE))) {
DBG(("invalid request")); DBG(("invalid request"));
nc->flags |= MG_F_CLOSE_IMMEDIATELY; nc->flags |= MG_F_CLOSE_IMMEDIATELY;
...@@ -5066,10 +5071,6 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -5066,10 +5071,6 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
websocket_handler(nc, MG_EV_RECV, ev_data); websocket_handler(nc, MG_EV_RECV, ev_data);
} }
#endif /* MG_DISABLE_HTTP_WEBSOCKET */ #endif /* MG_DISABLE_HTTP_WEBSOCKET */
#ifdef MG_ENABLE_HTTP_STREAMING_MULTIPART
} else if (nc->strm_state.len != 0) {
mg_multipart_continue(nc, io, req_len, ev, ev_data);
#endif /* MG_ENABLE_HTTP_STREAMING_MULTIPART */
} else if (hm->message.len <= io->len) { } else if (hm->message.len <= io->len) {
int trigger_ev = nc->listener ? MG_EV_HTTP_REQUEST : MG_EV_HTTP_REPLY; int trigger_ev = nc->listener ? MG_EV_HTTP_REQUEST : MG_EV_HTTP_REPLY;
...@@ -5201,12 +5202,13 @@ exit_mp: ...@@ -5201,12 +5202,13 @@ exit_mp:
} }
static void mg_multipart_continue(struct mg_connection *nc, struct mbuf *io, static void mg_multipart_continue(struct mg_connection *nc, struct mbuf *io,
int req_len, int ev, void *ev_data) { int ev, void *ev_data) {
/* Continue to stream multipart */ /* Continue to stream multipart */
struct stream_info si; struct stream_info si;
mg_event_handler_t handler; mg_event_handler_t handler;
struct mg_http_multipart_part mp; struct mg_http_multipart_part mp;
const char *boundary; const char *boundary;
int req_len;
mg_parse_stream_info(&nc->strm_state, &si); mg_parse_stream_info(&nc->strm_state, &si);
handler = get_endpoint_handler(nc->listener, &si.endpoint); handler = get_endpoint_handler(nc->listener, &si.endpoint);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment