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