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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 675 by torben, Tue Apr 27 20:07:12 2010 UTC revision 676 by torben, Tue Apr 27 21:00:01 2010 UTC
# Line 4  Line 4 
4  #include <stdio.h>  #include <stdio.h>
5  #include "mongoose.h"  #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() {  void EmbeddedHttp::startServer() {
41          mg_start();          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() {  void EmbeddedHttp::stopServer() {
51            mg_stop(m_context);
52  }  }

Legend:
Removed from v.675  
changed lines
  Added in v.676

  ViewVC Help
Powered by ViewVC 1.1.20