/[projects]/smsdaemon/embedded-http/embeddedhttp.cpp
ViewVC logotype

Contents of /smsdaemon/embedded-http/embeddedhttp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 677 - (show annotations) (download)
Tue Apr 27 21:03:37 2010 UTC (14 years ago) by torben
File size: 1661 byte(s)
added /status command do embedded http engine
1
2 #include "embeddedhttp.h"
3
4 #include <stdio.h>
5 #include "mongoose.h"
6
7 #include "Logger.h"
8 #include "version.h"
9 #include "Common.h"
10 #include <sstream>
11
12
13 void show_secret(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) {
14 Common* cmn = Common::instance();
15
16
17 int tot_sec = time(0) - cmn->daemonStart;
18
19 int sec = tot_sec % 60;
20 int min = (tot_sec / 60) % 60;
21 int hour = (tot_sec / 3600) %24;
22 int days = tot_sec / (3600*24);
23
24 std::ostringstream os;
25 os << VERSION << std::endl;
26 os << SVNVERSION << std::endl;
27 os << "Status:" << std::endl;
28 os << "Recv: " << cmn->smsCounter.incomming << std::endl;
29 os << "Send: " << cmn->smsCounter.outgoing << std::endl;
30 os << "Uptime: " << days << "d, " << hour << ":" << min << ":" << sec;
31
32 mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n");
33 mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n");
34
35 mg_printf(conn, "%s", os.str().c_str() );
36 }
37
38 void show_index(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) {
39 mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n");
40 mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n");
41
42 mg_printf(conn, "%s", "<html><body><h2>smsdaemon</h2>\n");
43 mg_printf(conn, "%s", "<a href='/status'>smsdaemon status</a>\n");
44 mg_printf(conn, "%s", "</body></html>");
45 }
46
47 void EmbeddedHttp::startServer() {
48 Logger::logMessage("Starting mongoose embedded http engine");
49
50 m_context = mg_start();
51 mg_set_option(m_context, "ports", "8080");
52 mg_set_uri_callback(m_context, "/", &show_index, 0);
53 mg_set_uri_callback(m_context, "/status", &show_secret, 0);
54
55 }
56
57
58 void EmbeddedHttp::stopServer() {
59 mg_stop(m_context);
60 }

  ViewVC Help
Powered by ViewVC 1.1.20