summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/mongoose/examples/array_vars
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/mongoose/examples/array_vars')
-rw-r--r--3rdparty/mongoose/examples/array_vars/Makefile21
-rw-r--r--3rdparty/mongoose/examples/array_vars/array_vars.c45
2 files changed, 66 insertions, 0 deletions
diff --git a/3rdparty/mongoose/examples/array_vars/Makefile b/3rdparty/mongoose/examples/array_vars/Makefile
new file mode 100644
index 00000000000..5ce2d1db6cb
--- /dev/null
+++ b/3rdparty/mongoose/examples/array_vars/Makefile
@@ -0,0 +1,21 @@
+# Copyright (c) 2014 Cesanta Software
+# All rights reserved
+
+PROG = array_vars
+CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
+SOURCES = $(PROG).c ../../mongoose.c
+
+all: $(PROG)
+
+run: $(PROG)
+ ./$(PROG)
+
+$(PROG): $(SOURCES) Makefile
+ $(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
+
+win:
+ wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
+ wine $(PROG).exe
+
+clean:
+ rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*
diff --git a/3rdparty/mongoose/examples/array_vars/array_vars.c b/3rdparty/mongoose/examples/array_vars/array_vars.c
new file mode 100644
index 00000000000..d631a7b0c79
--- /dev/null
+++ b/3rdparty/mongoose/examples/array_vars/array_vars.c
@@ -0,0 +1,45 @@
+// Copyright (c) 2014 Cesanta Software
+// All rights reserved
+//
+// This example demostrates how to use array get variables using mg_get_n_var
+// $Date: 2014-09-09 22:20:23 UTC $
+
+#include <stdio.h>
+#include <string.h>
+#include "mongoose.h"
+
+static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
+ switch (ev) {
+ case MG_AUTH: return MG_TRUE;
+ case MG_REQUEST:
+ {
+ mg_printf_data(conn, "Hello! Requested URI is [%s] ", conn->uri);
+ char buffer[1024];
+ int i, ret;
+ for(i=0; (ret = mg_get_var_n(conn, "foo[]", buffer, 1024, i)) > 0; i++)
+ mg_printf_data(conn, "\nfoo[%d] = %s", i, buffer);
+
+ return MG_TRUE;
+ }
+ 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;
+}