--- smsdaemon/embedded-http/embeddedhttp.cpp 2010/04/27 20:07:12 675 +++ smsdaemon/embedded-http/embeddedhttp.cpp 2010/04/27 21:00:01 676 @@ -4,11 +4,49 @@ #include #include "mongoose.h" +#include "Logger.h" +#include "version.h" +#include "Common.h" +#include + + +void show_secret(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) { + Common* cmn = Common::instance(); + + + int tot_sec = time(0) - cmn->daemonStart; + + int sec = tot_sec % 60; + int min = (tot_sec / 60) % 60; + int hour = (tot_sec / 3600) %24; + int days = tot_sec / (3600*24); + + std::ostringstream os; + os << VERSION << std::endl; + os << SVNVERSION << std::endl; + 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; + + 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", os.str().c_str() ); + + +} + void EmbeddedHttp::startServer() { - mg_start(); + Logger::logMessage("Starting mongoose embedded http engine"); + + m_context = mg_start(); + mg_set_option(m_context, "ports", "8080"); + mg_set_uri_callback(m_context, "/status", &show_secret, 0); + } void EmbeddedHttp::stopServer() { - + mg_stop(m_context); }