--- smsdaemon/embedded-http/embeddedhttp.cpp 2010/04/28 07:38:39 680 +++ smsdaemon/embedded-http/embeddedhttp.cpp 2010/04/29 18:18:18 695 @@ -9,9 +9,10 @@ #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) { +void show_status(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) { Common* cmn = Common::instance(); @@ -28,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"); @@ -41,10 +45,26 @@ 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"); + mg_printf(conn, "%s", "smsdaemon status
\n"); + mg_printf(conn, "%s", "smsdaemon log
\n"); + mg_printf(conn, "%s", ""); } +static void show_404(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", "Oops. File not found! "); +} + +void show_log(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", Logger::getLog().c_str() ); +} + void EmbeddedHttp::startServer() { std::string portStr = Common::instance()->GetConfigfile()->GetValue("smsdaemon", "httpport"); int port = atoi( portStr.c_str() ); @@ -59,8 +79,14 @@ m_context = mg_start(); mg_set_option(m_context, "ports", oss.str().c_str() ); + mg_set_option(m_context, "root", "/nosuchpatch"); //set root to non-existant path to disable normal file serving - only callbacks are now serviced + mg_set_uri_callback(m_context, "/", &show_index, 0); - mg_set_uri_callback(m_context, "/status", &show_secret, 0); + mg_set_uri_callback(m_context, "/status", &show_status, 0); + mg_set_uri_callback(m_context, "/log", &show_log, 0); + mg_set_error_callback(m_context, 404, show_404, NULL); + + } else { Logger::logMessage( "Mongoose http disabled" ); m_context = 0;