From 0fe6b0d99b3ac102a1c4e6adbe2e54a290e5a5ba Mon Sep 17 00:00:00 2001
From: Joel Sherrill
Date: Mon, 23 Nov 2009 14:31:53 +0000
Subject: 2009-11-23 Joel Sherrill
* Makefile, goahead_index.html, init.c, shttpd_ext.c,
shttpd_index.html: Add Mongoose HTTPD support.
* mongoose_ext.c, mongoose_index.html: New files.
---
http/ChangeLog | 6 ++++
http/Makefile | 16 ++++++++--
http/goahead_index.html | 2 +-
http/init.c | 28 ++++++++++++++++++
http/mongoose_ext.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
http/mongoose_index.html | 22 ++++++++++++++
http/shttpd_ext.c | 5 ++++
http/shttpd_index.html | 1 -
8 files changed, 152 insertions(+), 5 deletions(-)
create mode 100644 http/mongoose_ext.c
create mode 100644 http/mongoose_index.html
diff --git a/http/ChangeLog b/http/ChangeLog
index ccb9c8a..9400f44 100644
--- a/http/ChangeLog
+++ b/http/ChangeLog
@@ -1,3 +1,9 @@
+2009-11-23 Joel Sherrill
+
+ * Makefile, goahead_index.html, init.c, shttpd_ext.c,
+ shttpd_index.html: Add Mongoose HTTPD support.
+ * mongoose_ext.c, mongoose_index.html: New files.
+
2009-05-13 Joel Sherrill
* Makefile, init.c, system.h: Allow overrides from invoking
diff --git a/http/Makefile b/http/Makefile
index 550310d..135b290 100644
--- a/http/Makefile
+++ b/http/Makefile
@@ -8,7 +8,7 @@ PGM=${ARCH}/$(SAMPLE).exe
MANAGERS=all
# C source names, if any, go here -- minus the .c
-C_PIECES=init FilesystemImage shttpd_ext
+C_PIECES=init FilesystemImage shttpd_ext mongoose_ext
C_FILES=$(C_PIECES:%=%.c)
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
@@ -42,7 +42,8 @@ LD_PATHS +=
## FYI GoAhead requires POSIX to be enabled
USE_GOAHEAD=no
-USE_SIMPLE=yes
+USE_SIMPLE=no
+USE_MONGOOSE=yes
USE_FTPD=yes
ifeq ($(USE_GOAHEAD),yes)
HTTPD = GoAhead Web Server
@@ -56,6 +57,12 @@ ifeq ($(USE_SIMPLE),yes)
override LD_LIBS += -lshttpd
endif
+ifeq ($(USE_MONGOOSE),yes)
+ HTTPD = Mongoose HTTPD Web Server
+ CFLAGS += -DUSE_MONGOOSE_HTTPD
+ override LD_LIBS += -lmghttpd
+endif
+
ifeq ($(USE_FTPD),yes)
CFLAGS += -DUSE_FTPD
override LD_LIBS += -lftpd
@@ -87,13 +94,16 @@ FilesystemImage: $(ARCH) stamp-index-html \
FilesystemImage.c: $(ARCH) FilesystemImage
$(PROJECT_ROOT)/bin/rtems-bin2c FilesystemImage FilesystemImage
-rootfs/index.html: shttpd_index.html goahead_index.html
+rootfs/index.html: shttpd_index.html goahead_index.html mongoose_index.html
ifeq ($(USE_SIMPLE),yes)
cp shttpd_index.html rootfs/index.html
endif
ifeq ($(USE_GOHEAD),yes)
cp goahead_index.html rootfs/index.html
endif
+ifeq ($(USE_MONGOOSE),yes)
+ cp mongoose_index.html rootfs/index.html
+endif
stamp-index-html: rootfs/index.html
ifeq ($(USE_SIMPLE),yes)
diff --git a/http/goahead_index.html b/http/goahead_index.html
index 064a5c6..01c9555 100644
--- a/http/goahead_index.html
+++ b/http/goahead_index.html
@@ -1,5 +1,5 @@
-RTEMS @SERVER@ Test Page
+RTEMS GoAhead Test Page
RTEMS GoAhead Test Page
diff --git a/http/init.c b/http/init.c
index 9e5d0fc..8db7967 100644
--- a/http/init.c
+++ b/http/init.c
@@ -82,6 +82,14 @@
bool Simple_HTTPD_enabled = false;
#endif
+#if defined(USE_MONGOOSE_HTTPD)
+ #include
+
+ void example_mongoose_addpages(
+ struct mg_context *server
+ );
+#endif
+
#define bool2string(_b) ((_b) ? "true" : "false")
#if defined(USE_SIMPLE_HTTPD)
@@ -145,6 +153,18 @@ rtems_task Init(
#endif
+ #if defined(USE_MONGOOSE_HTTPD)
+ {
+ struct mg_context *WebServer;
+ printf( "Initializing Mongoose HTTPD\n" );
+ WebServer = mg_start();
+
+ mg_set_option(WebServer, "root", "/" );
+ mg_set_option(WebServer, "ports", "80" );
+ example_mongoose_addpages( WebServer );
+
+ }
+ #endif
status = rtems_task_delete( RTEMS_SELF );
}
@@ -162,6 +182,14 @@ rtems_task Init(
#define CONFIGURE_MAXIMUM_SEMAPHORES 20
#define CONFIGURE_MAXIMUM_TASKS 20
+#if defined(USE_MONGOOSE_HTTPD)
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 10
+#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 30
+#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10
+#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (32 * 1024)
+#define CONFIGURE_UNIFIED_WORK_AREAS
+#endif
+
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
diff --git a/http/mongoose_ext.c b/http/mongoose_ext.c
new file mode 100644
index 0000000..9e6932f
--- /dev/null
+++ b/http/mongoose_ext.c
@@ -0,0 +1,77 @@
+/* SHTTPD Extensions
+ *
+ * $Id$
+ */
+
+
+#if defined(USE_MONGOOSE_HTTPD)
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#define START_HTML_BODY \
+ "HTTP/1.1 200 OK\r\n" \
+ "Content-Type: text/html\r\n\r\n" \
+ "\r\n"
+
+#define END_HTML_BODY \
+ "\r\n"
+
+void example_mongoose_callback(
+ struct mg_connection *conn,
+ const struct mg_request_info *request_info,
+ void *user_data
+)
+{
+ const char *query;
+
+ query = mg_get_var(conn, "action" );
+ if ( !query )
+ query = "";
+ /* fprintf( stderr, "RTEMS Request -%s-\n", query ); */
+
+ mg_printf( conn, START_HTML_BODY "" );
+ if ( !strcmp( query, "cpuuse_report" ) ) {
+ rtems_cpu_usage_report_with_plugin(
+ conn,
+ (rtems_printk_plugin_t) mg_printf
+ );
+ } else if ( !strcmp( query, "cpuuse_reset" ) ) {
+ rtems_cpu_usage_reset();
+ mg_printf(
+ conn,
+ " CPU Usage data reset -- return to the previous page
"
+ );
+ } else if ( !strcmp( query, "stackuse_report" ) ) {
+ rtems_stack_checker_report_usage_with_plugin(
+ conn,
+ (rtems_printk_plugin_t) mg_printf
+ );
+ } else {
+ mg_printf(
+ conn,
+ START_HTML_BODY
+ " Unknown Request
"
+ " URI: %s"
+ " Arguments: %s
",
+ mg_get_var(conn, "REQUEST_URI"),
+ query
+ );
+ }
+ mg_printf( conn, "
" END_HTML_BODY );
+ /*arg->flags |= SHTTPD_END_OF_OUTPUT; */
+}
+
+void example_mongoose_addpages(
+ struct mg_context *server
+)
+{
+ mg_set_uri_callback( server, "/queries*", example_mongoose_callback, NULL );
+}
+
+#endif
diff --git a/http/mongoose_index.html b/http/mongoose_index.html
new file mode 100644
index 0000000..6aa44fd
--- /dev/null
+++ b/http/mongoose_index.html
@@ -0,0 +1,22 @@
+
+RTEMS Mongoose Server Test Page
+
+
+RTEMS Mongoose Test Page
+
+
+
+
+Congratulations, you have successfully loaded your first page
+from the Mongoose webserver running on RTEMS.
+
+This RTEMS program includes some dynamic web pages. Check
+out the following links for examples:
+
+
+
+
diff --git a/http/shttpd_ext.c b/http/shttpd_ext.c
index dadc1be..898bbc8 100644
--- a/http/shttpd_ext.c
+++ b/http/shttpd_ext.c
@@ -30,10 +30,13 @@ void example_shttpd_callback(struct shttpd_arg *arg)
/* fprintf( stderr, "RTEMS Request -%s-\n", query ); */
if ( !strcmp( query, "cpuuse_report" ) ) {
+
+ shttpd_printf( arg, "" );
rtems_cpu_usage_report_with_plugin(
arg,
(rtems_printk_plugin_t) shttpd_printf
);
+ shttpd_printf( arg, "
" );
} else if ( !strcmp( query, "cpuuse_reset" ) ) {
rtems_cpu_usage_reset();
shttpd_printf(
@@ -43,10 +46,12 @@ void example_shttpd_callback(struct shttpd_arg *arg)
END_HTML_BODY
);
} else if ( !strcmp( query, "stackuse_report" ) ) {
+ shttpd_printf( arg, "" );
rtems_stack_checker_report_usage_with_plugin(
arg,
(rtems_printk_plugin_t) shttpd_printf
);
+ shttpd_printf( arg, "
" );
} else {
shttpd_printf(
arg,
diff --git a/http/shttpd_index.html b/http/shttpd_index.html
index 2050141..f995bb5 100644
--- a/http/shttpd_index.html
+++ b/http/shttpd_index.html
@@ -29,6 +29,5 @@ out the following links for examples:
CPU Usage -- Reset
Stack Usage -- Report
-
--
cgit v1.2.3