From 8556d0cdf7058be2c519bd4d8e7006ea9e913527 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 10 Jan 2015 13:30:30 +0100 Subject: Added integral source of mongoose (nw) --- .../mongoose/examples/file_upload/file_upload.c | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 3rdparty/mongoose/examples/file_upload/file_upload.c (limited to '3rdparty/mongoose/examples/file_upload/file_upload.c') diff --git a/3rdparty/mongoose/examples/file_upload/file_upload.c b/3rdparty/mongoose/examples/file_upload/file_upload.c new file mode 100644 index 00000000000..f0c6a1a4238 --- /dev/null +++ b/3rdparty/mongoose/examples/file_upload/file_upload.c @@ -0,0 +1,59 @@ +// Copyright (c) 2004-2012 Sergey Lyubka +// This file is a part of mongoose project, http://github.com/valenok/mongoose + +#include +#include +#include "mongoose.h" + +static int send_index_page(struct mg_connection *conn) { + const char *data; + int data_len, ofs = 0; + char var_name[100], file_name[100]; + + mg_printf_data(conn, "%s", + "Upload example." + "
" + "
" + "" + "
"); + + while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs, + var_name, sizeof(var_name), + file_name, sizeof(file_name), + &data, &data_len)) > 0) { + mg_printf_data(conn, "var: %s, file_name: %s, size: %d bytes
", + var_name, file_name, data_len); + } + + mg_printf_data(conn, "%s", ""); + + return MG_TRUE; +} + +static int ev_handler(struct mg_connection *conn, enum mg_event ev) { + switch (ev) { + case MG_AUTH: return MG_TRUE; + case MG_REQUEST: return send_index_page(conn); + default: return MG_FALSE; + } +} + +int main(void) { + struct mg_server *server; + + // Create and configure the server + server = mg_create_server(NULL, ev_handler); + mg_set_option(server, "listening_port", "8080"); + + // Serve request. Hit Ctrl-C to terminate the program + printf("Starting on port %s\n", mg_get_option(server, "listening_port")); + for (;;) { + mg_poll_server(server, 1000); + } + + // Cleanup, and free server instance + mg_destroy_server(&server); + + return 0; +} -- cgit v1.2.3-70-g09d2