[8c6b033] | 1 | /* SHTTPD Extensions |
---|
| 2 | * |
---|
| 3 | * $Id$ |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | #if defined(USE_SIMPLE_HTTPD) |
---|
| 8 | |
---|
| 9 | #include <rtems.h> |
---|
| 10 | #include <shttpd/shttpd.h> |
---|
| 11 | #include <rtems/cpuuse.h> |
---|
| 12 | #include <rtems/stackchk.h> |
---|
| 13 | |
---|
| 14 | #include <stdio.h> |
---|
| 15 | |
---|
| 16 | #define START_HTML_BODY \ |
---|
| 17 | "HTTP/1.1 200 OK\r\n" \ |
---|
| 18 | "Content-Type: text/html\r\n\r\n" \ |
---|
| 19 | "<html><body>\r\n" |
---|
| 20 | |
---|
| 21 | #define END_HTML_BODY \ |
---|
| 22 | |
---|
| 23 | void example_shttpd_callback(struct shttpd_arg *arg) |
---|
| 24 | { |
---|
| 25 | const char *query; |
---|
| 26 | |
---|
| 27 | query = shttpd_get_env(arg, "QUERY_STRING" ); |
---|
| 28 | if ( !query ) |
---|
| 29 | query = ""; |
---|
| 30 | /* fprintf( stderr, "RTEMS Request -%s-\n", query ); */ |
---|
| 31 | |
---|
| 32 | if ( !strcmp( query, "cpuuse_report" ) ) { |
---|
[0fe6b0d] | 33 | |
---|
| 34 | shttpd_printf( arg, "<pre>" ); |
---|
[b80aaa9] | 35 | rtems_cpu_usage_report_with_plugin( |
---|
| 36 | arg, |
---|
| 37 | (rtems_printk_plugin_t) shttpd_printf |
---|
| 38 | ); |
---|
[0fe6b0d] | 39 | shttpd_printf( arg, "</pre>" ); |
---|
[8c6b033] | 40 | } else if ( !strcmp( query, "cpuuse_reset" ) ) { |
---|
| 41 | rtems_cpu_usage_reset(); |
---|
| 42 | shttpd_printf( |
---|
| 43 | arg, |
---|
| 44 | START_HTML_BODY |
---|
| 45 | " <p><big>CPU Usage data reset -- return to the previous page</big></p>" |
---|
| 46 | END_HTML_BODY |
---|
| 47 | ); |
---|
| 48 | } else if ( !strcmp( query, "stackuse_report" ) ) { |
---|
[0fe6b0d] | 49 | shttpd_printf( arg, "<pre>" ); |
---|
[b80aaa9] | 50 | rtems_stack_checker_report_usage_with_plugin( |
---|
| 51 | arg, |
---|
| 52 | (rtems_printk_plugin_t) shttpd_printf |
---|
| 53 | ); |
---|
[0fe6b0d] | 54 | shttpd_printf( arg, "</pre>" ); |
---|
[8c6b033] | 55 | } else { |
---|
| 56 | shttpd_printf( |
---|
| 57 | arg, |
---|
| 58 | START_HTML_BODY |
---|
| 59 | " <h2>Unknown Request</h2>" |
---|
| 60 | " <h3>URI: %s</br>" |
---|
| 61 | " Arguments: %s</h3>" |
---|
| 62 | END_HTML_BODY, |
---|
| 63 | shttpd_get_env(arg, "REQUEST_URI"), |
---|
| 64 | query |
---|
| 65 | ); |
---|
| 66 | } |
---|
| 67 | arg->flags |= SHTTPD_END_OF_OUTPUT; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void example_shttpd_addpages(struct shttpd_ctx *ctx) |
---|
| 71 | { |
---|
| 72 | shttpd_register_uri( ctx, "/queries*", example_shttpd_callback, NULL ); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | #endif |
---|