#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "monitor_client.h" class HTMLConfigExporter : public ConfigExporter { std::string select_; public: std::ostringstream os_; HTMLConfigExporter(const std::string& select) : select_(select), os_() { } ~HTMLConfigExporter() { } void config(const Config *c) { if (select_ == "") os_ << "

Configuration

"; else os_ << "

Configuration - " << select_ << " [up]

"; os_ << ""; c->marshall(this); os_ << "
"; } void field(const ConfigValue *cv, const std::string& name) { os_ << "" << name << "" << cv->type_->name() << ""; cv->marshall(this); os_ << ""; } void object(const ConfigClass *cc, const ConfigObject *co) { if (select_ != "" && select_ != co->name()) return; os_ << "objectclassfieldtypevalue"; os_ << "name() << "\">" << co->name() << "" << cc->name() << ""; cc->marshall(this, co); } void value(const ConfigValue *cv, const std::string& val) { ConfigTypePointer *ct = dynamic_cast(cv->type_); if (ct != NULL) { ConfigObject *co; if (ct->get(cv, &co)) { if (co == NULL) os_ << "None"; else os_ << "name() << "\">" << co->name() << ""; return; } } os_ << "" << val << ""; } }; void MonitorClient::handle_request(const std::string& method, const std::string& uri, HTTPProtocol::Request) { if (method != "GET") { pipe_->send_response(HTTPProtocol::BadRequest, "Unsupported method."); return; } if (uri[0] != '/') { pipe_->send_response(HTTPProtocol::NotFound, "Invalid URI."); return; } std::vector path_components = Buffer(uri).split('/', false); std::string select; if (!path_components.empty()) { switch (path_components.size()) { case 2: if (!path_components[0].equal("object")) { pipe_->send_response(HTTPProtocol::NotFound, "Unsupported URI class."); return; } path_components[1].extract(select); break; default: pipe_->send_response(HTTPProtocol::NotFound, "Wrong number of path components in URI."); return; } } HTMLConfigExporter exporter(select); exporter.config(config_); pipe_->send_response(HTTPProtocol::OK, "WANProxy Configuration Monitor" + exporter.os_.str() + "", "text/html"); }