10 #ifndef CHI_HTTPADMIN_DEF
11 #define CHI_HTTPADMIN_DEF
18 #include "external/vpiotr-mongoose-cpp/mongoose.h"
21 #include "external/vpiotr-mongoose-cpp/mongoose.c"
25 static const char *ajax_reply_start =
28 "Content-Type: application/x-javascript\r\n"
31 static const char *options[] = {
32 "document_root",
"conf/adminhtml",
33 "listening_ports",
"3333",
39 const char *name,
char *dst,
size_t dst_len) {
40 const char *qs = request_info->query_string;
41 mg_get_var(qs, strlen(qs == NULL ?
"" : qs), name, dst, dst_len);
51 get_qsvar(request_info,
"callback", cb,
sizeof(cb));
53 mg_printf(conn,
"%s(", cb);
56 return cb[0] ==
'\0' ? 0 : 1;
59 template <
typename ENGINE>
64 ENGINE * engine = (ENGINE*) request_info->user_data;
66 mg_printf(conn,
"%s", ajax_reply_start);
67 is_jsonp = handle_jsonp(conn, request_info);
70 std::string json_info = engine->get_info_json();
71 const char * cstr = json_info.c_str();
72 int len = (int)strlen(cstr);
79 if ((num_written = mg_write(conn, cstr, (
size_t)len)) != len)
86 mg_printf(conn,
"%s",
")");
93 template <
typename ENGINE>
94 static void *event_handler(
enum mg_event event,
97 void *processed = (
void*)
"yes";
99 if (event == MG_NEW_REQUEST) {
100 if (strcmp(request_info->uri,
"/ajax/getinfo") == 0) {
101 ajax_send_message<ENGINE>(conn, request_info);
102 }
else if (strcmp(request_info->uri,
"/ajax/getinfo2") == 0) {
117 template <
typename ENGINE>
118 void start_httpadmin(ENGINE * engine) {
121 ctx = mg_start(&event_handler<ENGINE>, (
void*)engine, options);
123 std::cout <<
"Started HTTP admin server. " << std::endl;