diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-11-23 14:31:53 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-11-23 14:31:53 +0000 |
commit | 0fe6b0d99b3ac102a1c4e6adbe2e54a290e5a5ba (patch) | |
tree | 1e91e58320648bfb2ed253b9bf858e3040c5eeca | |
parent | 2009-11-13 Joel Sherrill <joel.sherrill@OARcorp.com> (diff) | |
download | network-demos-0fe6b0d99b3ac102a1c4e6adbe2e54a290e5a5ba.tar.bz2 |
2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile, goahead_index.html, init.c, shttpd_ext.c,
shttpd_index.html: Add Mongoose HTTPD support.
* mongoose_ext.c, mongoose_index.html: New files.
-rw-r--r-- | http/ChangeLog | 6 | ||||
-rw-r--r-- | http/Makefile | 16 | ||||
-rw-r--r-- | http/goahead_index.html | 2 | ||||
-rw-r--r-- | http/init.c | 28 | ||||
-rw-r--r-- | http/mongoose_ext.c | 77 | ||||
-rw-r--r-- | http/mongoose_index.html | 22 | ||||
-rw-r--r-- | http/shttpd_ext.c | 5 | ||||
-rw-r--r-- | http/shttpd_index.html | 1 |
8 files changed, 152 insertions, 5 deletions
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 <joel.sherrill@oarcorp.com> + + * 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 <joel.sherrill@oarcorp.com> * 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 @@ <HTML> -<HEAD><TITLE>RTEMS @SERVER@ Test Page</TITLE></HEAD> +<HEAD><TITLE>RTEMS GoAhead Test Page</TITLE></HEAD> <BODY BGCOLOR="FFFFFF"> <center> <H1>RTEMS GoAhead Test Page</H1> 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 <mghttpd/mongoose.h> + + 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 <rtems.h> +#include <stdio.h> +#include <mghttpd/mongoose.h> +#include <rtems/cpuuse.h> +#include <rtems/stackchk.h> + +#include <stdio.h> + +#define START_HTML_BODY \ + "HTTP/1.1 200 OK\r\n" \ + "Content-Type: text/html\r\n\r\n" \ + "<html><body>\r\n" + +#define END_HTML_BODY \ + "</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 "<pre>" ); + 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, + " <p><big>CPU Usage data reset -- return to the previous page</big></p>" + ); + } 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 + " <h2>Unknown Request</h2>" + " <h3>URI: %s</br>" + " Arguments: %s</h3>", + mg_get_var(conn, "REQUEST_URI"), + query + ); + } + mg_printf( conn, "</pre>" 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 @@ +<HTML> +<HEAD><TITLE>RTEMS Mongoose Server Test Page</TITLE></HEAD> +<BODY BGCOLOR="FFFFFF"> +<center> +<H1>RTEMS Mongoose Test Page</H1> +</center> +<A HREF="http://www.rtems.org"> + <IMG align=center BORDER=0 SRC="rtems_logo.jpg" ALT="RTEMS"> </A> + +<P><big>Congratulations, you have successfully loaded your first page +from the Mongoose webserver running on RTEMS.</big></P> +</P> +This RTEMS program includes some dynamic web pages. Check +out the following links for examples: +</P> +<UL> + <LI><A HREF="queries?action=cpuuse_report">CPU Usage -- Report</LI> + <LI><A HREF="queries?action=cpuuse_reset">CPU Usage -- Reset</LI> + <LI><A HREF="queries?action=stackuse_report">Stack Usage -- Report</LI> +</UL> + +</BODY></HTML> 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, "<pre>" ); rtems_cpu_usage_report_with_plugin( arg, (rtems_printk_plugin_t) shttpd_printf ); + shttpd_printf( arg, "</pre>" ); } 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, "<pre>" ); rtems_stack_checker_report_usage_with_plugin( arg, (rtems_printk_plugin_t) shttpd_printf ); + shttpd_printf( arg, "</pre>" ); } 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: <LI><A HREF="queries?cpuuse_reset">CPU Usage -- Reset</LI> <LI><A HREF="queries?stackuse_report">Stack Usage -- Report</LI> </UL> -</big> </BODY></HTML> |