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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 679 - (hide annotations) (download)
Tue Apr 27 21:12:11 2010 UTC (14 years, 1 month ago) by torben
File size: 1660 byte(s)
added index.html equivalent function
1 torben 675
2     #include "embeddedhttp.h"
3    
4     #include <stdio.h>
5     #include "mongoose.h"
6    
7 torben 676 #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 torben 679 mg_printf(conn, "%s", os.str().c_str() );
36     }
37 torben 676
38 torben 679 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/html\r\n\r\n");
41 torben 676
42 torben 679 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 torben 676 }
46    
47 torben 675 void EmbeddedHttp::startServer() {
48 torben 676 Logger::logMessage("Starting mongoose embedded http engine");
49    
50     m_context = mg_start();
51     mg_set_option(m_context, "ports", "8080");
52 torben 679 mg_set_uri_callback(m_context, "/", &show_index, 0);
53 torben 676 mg_set_uri_callback(m_context, "/status", &show_secret, 0);
54    
55 torben 675 }
56    
57    
58     void EmbeddedHttp::stopServer() {
59 torben 676 mg_stop(m_context);
60 torben 675 }

  ViewVC Help
Powered by ViewVC 1.1.20