--- smsdaemon/embedded-http/embeddedhttp.cpp 2010/04/27 21:03:37 677 +++ smsdaemon/embedded-http/embeddedhttp.cpp 2010/04/28 08:51:24 683 @@ -7,8 +7,10 @@ #include "Logger.h" #include "version.h" #include "Common.h" +#include "ConfigFile.h" #include - +#include +#include void show_secret(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) { Common* cmn = Common::instance(); @@ -27,7 +29,10 @@ os << "Status:" << std::endl; os << "Recv: " << cmn->smsCounter.incomming << std::endl; os << "Send: " << cmn->smsCounter.outgoing << std::endl; - os << "Uptime: " << days << "d, " << hour << ":" << min << ":" << sec; + os << "Uptime: " << days << "d, "; + os << std::setw(2) << std::setfill('0') << hour << ":"; + os << std::setw(2) << min << ":" ; + os << std::setw(2) << sec; mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n"); mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n"); @@ -37,7 +42,7 @@ void show_index(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) { mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n"); - mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n"); + mg_printf(conn, "%s", "Content-Type: text/html\r\n\r\n"); mg_printf(conn, "%s", "

smsdaemon

\n"); mg_printf(conn, "%s", "smsdaemon status\n"); @@ -45,16 +50,30 @@ } void EmbeddedHttp::startServer() { - Logger::logMessage("Starting mongoose embedded http engine"); - - 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); + std::string portStr = Common::instance()->GetConfigfile()->GetValue("smsdaemon", "httpport"); + int port = atoi( portStr.c_str() ); + if (port > 0) { + std::ostringstream oss; + oss << "Starting mongoose embedded http engine (listenin on port " << port << ")"; + Logger::logMessage( oss.str() ); + + oss.str(""); //empty string stream + oss << port; + + m_context = mg_start(); + mg_set_option(m_context, "ports", oss.str().c_str() ); + mg_set_uri_callback(m_context, "/", &show_index, 0); + mg_set_uri_callback(m_context, "/status", &show_secret, 0); + } else { + Logger::logMessage( "Mongoose http disabled" ); + m_context = 0; + } } void EmbeddedHttp::stopServer() { - mg_stop(m_context); + if (m_context != 0) { + mg_stop(m_context); + } }