summaryrefslogtreecommitdiffstats
path: root/http/mongoose_ext.c
blob: 9545059517b633688a9189834113dc7b742ef229 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*  Mongoose HTTPD Extensions
 */


#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