/[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 677 by torben, Tue Apr 27 21:03:37 2010 UTC revision 683 by torben, Wed Apr 28 08:51:24 2010 UTC
# Line 7  Line 7 
7  #include "Logger.h"  #include "Logger.h"
8  #include "version.h"  #include "version.h"
9  #include "Common.h"  #include "Common.h"
10    #include "ConfigFile.h"
11  #include <sstream>  #include <sstream>
12    #include <iomanip>
13    #include <stdlib.h>
14    
15  void show_secret(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) {  void show_secret(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) {
16          Common* cmn = Common::instance();          Common* cmn = Common::instance();
# Line 27  void show_secret(struct mg_connection *c Line 29  void show_secret(struct mg_connection *c
29          os << "Status:" << std::endl;          os << "Status:" << std::endl;
30          os << "Recv: " << cmn->smsCounter.incomming << std::endl;          os << "Recv: " << cmn->smsCounter.incomming << std::endl;
31          os << "Send: " << cmn->smsCounter.outgoing << std::endl;          os << "Send: " << cmn->smsCounter.outgoing << std::endl;
32          os << "Uptime: " << days << "d, " << hour << ":" << min << ":" << sec;          os << "Uptime: " << days << "d, ";
33            os << std::setw(2) << std::setfill('0') << hour << ":";
34            os << std::setw(2) << min << ":" ;
35            os << std::setw(2) << sec;
36    
37          mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n");          mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n");
38          mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n");          mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n");
# Line 37  void show_secret(struct mg_connection *c Line 42  void show_secret(struct mg_connection *c
42    
43  void show_index(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) {  void show_index(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) {
44          mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n");          mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n");
45          mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n");          mg_printf(conn, "%s", "Content-Type: text/html\r\n\r\n");
46                    
47          mg_printf(conn, "%s", "<html><body><h2>smsdaemon</h2>\n");          mg_printf(conn, "%s", "<html><body><h2>smsdaemon</h2>\n");
48          mg_printf(conn, "%s", "<a href='/status'>smsdaemon status</a>\n");          mg_printf(conn, "%s", "<a href='/status'>smsdaemon status</a>\n");
# Line 45  void show_index(struct mg_connection *co Line 50  void show_index(struct mg_connection *co
50  }  }
51    
52  void EmbeddedHttp::startServer() {  void EmbeddedHttp::startServer() {
53          Logger::logMessage("Starting mongoose embedded http engine");          std::string portStr = Common::instance()->GetConfigfile()->GetValue("smsdaemon", "httpport");
54            int port = atoi( portStr.c_str() );
         m_context = mg_start();  
         mg_set_option(m_context, "ports", "8080");  
         mg_set_uri_callback(m_context, "/", &show_index, 0);  
         mg_set_uri_callback(m_context, "/status", &show_secret, 0);  
55    
56            if (port > 0) {
57                    std::ostringstream oss;
58                    oss << "Starting mongoose embedded http engine (listenin on port " << port << ")";
59                    Logger::logMessage( oss.str() );
60    
61                    oss.str(""); //empty string stream
62                    oss << port;
63    
64                    m_context = mg_start();
65                    mg_set_option(m_context, "ports", oss.str().c_str() );
66                    mg_set_uri_callback(m_context, "/", &show_index, 0);
67                    mg_set_uri_callback(m_context, "/status", &show_secret, 0);
68            } else {
69                    Logger::logMessage( "Mongoose http disabled" );
70                    m_context = 0;
71            }
72  }  }
73    
74    
75  void EmbeddedHttp::stopServer() {  void EmbeddedHttp::stopServer() {
76          mg_stop(m_context);          if (m_context != 0) {
77                    mg_stop(m_context);
78            }
79  }  }

Legend:
Removed from v.677  
changed lines
  Added in v.683

  ViewVC Help
Powered by ViewVC 1.1.20