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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 678 - (show annotations) (download)
Tue Apr 27 21:06:53 2010 UTC (14 years ago) by torben
File size: 1220 byte(s)
undo previous unintentional commit
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 }
39
40 void EmbeddedHttp::startServer() {
41 Logger::logMessage("Starting mongoose embedded http engine");
42
43 m_context = mg_start();
44 mg_set_option(m_context, "ports", "8080");
45 mg_set_uri_callback(m_context, "/status", &show_secret, 0);
46
47 }
48
49
50 void EmbeddedHttp::stopServer() {
51 mg_stop(m_context);
52 }

  ViewVC Help
Powered by ViewVC 1.1.20