From: Christian Hofstaedtler Date: Sun, 20 Oct 2013 15:06:05 +0000 (+0200) Subject: webserver: drop d_that X-Git-Tag: rec-3.6.0-rc1~354^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f6154a3b359b4de50e3934e907206470a3a8de03;p=pdns webserver: drop d_that --- diff --git a/pdns/webserver.cc b/pdns/webserver.cc index df0cc6390..9d3ba539c 100644 --- a/pdns/webserver.cc +++ b/pdns/webserver.cc @@ -50,7 +50,7 @@ int WebServer::B64Decode(const std::string& strInput, std::string& strOutput) // registerHandler("/", &index); // registerHandler("/foo", &foo); // registerHandler("/foo//", &foobarbaz); -void WebServer::registerHandler(const string& url, HandlerFunction *handler) +void WebServer::registerHandler(const string& url, HandlerFunction handler) { std::size_t pos = 0, lastpos = 0; @@ -112,18 +112,13 @@ bool WebServer::route(const std::string& url, std::map continue; } - *handler = reg->handler; + *handler = ®->handler; return true; } } return false; } -void WebServer::setCaller(void *that) -{ - d_that=that; -} - static void *WebServerConnectionThreadStart(void *p) { connectionThreadData* data = static_cast(p); pthread_detach(pthread_self()); @@ -238,7 +233,7 @@ try { map urlArgs; if (route(baseUrl, urlArgs, &handler)) { bool custom=false; - string ret=(*handler)(method, post, varmap, d_that, &custom); + string ret=(*handler)(method, post, varmap, &custom); if(!custom) { client->putLine("HTTP/1.1 200 OK\n"); diff --git a/pdns/webserver.hh b/pdns/webserver.hh index ffaf0cb38..48fcda1cc 100644 --- a/pdns/webserver.hh +++ b/pdns/webserver.hh @@ -86,16 +86,14 @@ public: void serveConnection(Session* client); - void setCaller(void *that); - - typedef string HandlerFunction(const string& method, const string& post, const map&varmap, void *that, bool *custom); + typedef boost::function&varmap, bool *custom)> HandlerFunction; struct HandlerRegistration { std::list urlParts; std::list paramNames; - HandlerFunction *handler; + HandlerFunction handler; }; - void registerHandler(const string& url, HandlerFunction *handler); + void registerHandler(const string& url, HandlerFunction handler); private: static char B64Decode1(char cInChar); @@ -105,7 +103,6 @@ private: string d_listenaddress; int d_port; std::list d_handlers; - void* d_that; string d_password; Server* d_server; }; diff --git a/pdns/ws.cc b/pdns/ws.cc index db4a97f09..711f21e34 100644 --- a/pdns/ws.cc +++ b/pdns/ws.cc @@ -186,9 +186,8 @@ string StatWebServer::makePercentage(const double& val) return (boost::format("%.01f%%") % val).str(); } -string StatWebServer::indexfunction(const string& method, const string& post, const map &varmap, void *ptr, bool *custom) +string StatWebServer::indexfunction(const string& method, const string& post, const map &varmap, bool *custom) { - StatWebServer *sws=static_cast(ptr); maprvarmap=varmap; if(!rvarmap["resetring"].empty()){ *custom=true; @@ -226,29 +225,29 @@ string StatWebServer::indexfunction(const string& method, const string& post, co "
"<d_queries.get1()<<", "<< - sws->d_queries.get5()<<", "<< - sws->d_queries.get10()<<". Max queries/second: "<d_queries.getMax()<< + d_queries.get1()<<", "<< + d_queries.get5()<<", "<< + d_queries.get10()<<". Max queries/second: "<"<d_cachemisses.get10()+sws->d_cachehits.get10()>0) + if(d_cachemisses.get10()+d_cachehits.get10()>0) ret<<"Cache hitrate, 1, 5, 10 minute averages: "<< - makePercentage((sws->d_cachehits.get1()*100.0)/((sws->d_cachehits.get1())+(sws->d_cachemisses.get1())))<<", "<< - makePercentage((sws->d_cachehits.get5()*100.0)/((sws->d_cachehits.get5())+(sws->d_cachemisses.get5())))<<", "<< - makePercentage((sws->d_cachehits.get10()*100.0)/((sws->d_cachehits.get10())+(sws->d_cachemisses.get10())))<< + makePercentage((d_cachehits.get1()*100.0)/((d_cachehits.get1())+(d_cachemisses.get1())))<<", "<< + makePercentage((d_cachehits.get5()*100.0)/((d_cachehits.get5())+(d_cachemisses.get5())))<<", "<< + makePercentage((d_cachehits.get10()*100.0)/((d_cachehits.get10())+(d_cachemisses.get10())))<< "
"<d_qcachemisses.get10()+sws->d_qcachehits.get10()>0) + if(d_qcachemisses.get10()+d_qcachehits.get10()>0) ret<<"Backend query cache hitrate, 1, 5, 10 minute averages: "<d_qcachehits.get1()*100.0)/((sws->d_qcachehits.get1())+(sws->d_qcachemisses.get1())))<<", "<< - makePercentage((sws->d_qcachehits.get5()*100.0)/((sws->d_qcachehits.get5())+(sws->d_qcachemisses.get5())))<<", "<< - makePercentage((sws->d_qcachehits.get10()*100.0)/((sws->d_qcachehits.get10())+(sws->d_qcachemisses.get10())))<< + makePercentage((d_qcachehits.get1()*100.0)/((d_qcachehits.get1())+(d_qcachemisses.get1())))<<", "<< + makePercentage((d_qcachehits.get5()*100.0)/((d_qcachehits.get5())+(d_qcachemisses.get5())))<<", "<< + makePercentage((d_qcachehits.get10()*100.0)/((d_qcachehits.get10())+(d_qcachemisses.get10())))<< "
"<d_qcachemisses.get1()<<", "<< - sws->d_qcachemisses.get5()<<", "<< - sws->d_qcachemisses.get10()<<". Max queries/second: "<d_qcachemisses.getMax()<< + d_qcachemisses.get1()<<", "<< + d_qcachemisses.get5()<<", "<< + d_qcachemisses.get10()<<". Max queries/second: "<"<
"<::const_iterator i=entries.begin();i!=entries.end();++i) printtable(ret,*i,S.getRingTitle(*i)); - sws->printvars(ret); + printvars(ret); if(arg().mustDo("webserver-print-arguments")) - sws->printargs(ret); + printargs(ret); } else printtable(ret,rvarmap["ring"],S.getRingTitle(rvarmap["ring"]),100); @@ -604,7 +603,7 @@ static string jsonDispatch(const string& method, const string& post, varmap_t& v return returnJSONError("No or unknown command given"); } -string StatWebServer::jsonstat(const string& method, const string& post, const map &varmap, void *ptr, bool *custom) +string StatWebServer::jsonstat(const string& method, const string& post, const map &varmap, bool *custom) { *custom=1; // indicates we build the response string ret="HTTP/1.1 200 OK\r\n" @@ -640,7 +639,7 @@ string StatWebServer::jsonstat(const string& method, const string& post, const m return ret; } -string StatWebServer::cssfunction(const string& method, const string& post, const map &varmap, void *ptr, bool *custom) +string StatWebServer::cssfunction(const string& method, const string& post, const map &varmap, bool *custom) { *custom=1; // indicates we build the response ostringstream ret; @@ -683,11 +682,10 @@ string StatWebServer::cssfunction(const string& method, const string& post, cons void StatWebServer::launch() { try { - d_ws->setCaller(this); - d_ws->registerHandler("/",&indexfunction); - d_ws->registerHandler("/style.css",&cssfunction); + d_ws->registerHandler("/", boost::bind(&StatWebServer::indexfunction, this, _1, _2, _3, _4)); + d_ws->registerHandler("/style.css", boost::bind(&StatWebServer::cssfunction, this, _1, _2, _3, _4)); if(::arg().mustDo("experimental-json-interface")) - d_ws->registerHandler("/jsonstat", &jsonstat); + d_ws->registerHandler("/jsonstat", boost::bind(&StatWebServer::jsonstat, this, _1, _2, _3, _4)); d_ws->go(); } catch(...) { diff --git a/pdns/ws.hh b/pdns/ws.hh index db123fb40..907ae5547 100644 --- a/pdns/ws.hh +++ b/pdns/ws.hh @@ -86,9 +86,9 @@ public: private: static void *threadHelper(void *); static void *statThreadHelper(void *p); - static string indexfunction(const string& method, const string& post, const map &varmap, void *ptr, bool *custom); - static string cssfunction(const string& method, const string& post, const map &varmap, void *ptr, bool *custom); - static string jsonstat(const string& method, const string& post, const map &varmap, void *ptr, bool *custom); + string indexfunction(const string& method, const string& post, const map &varmap, bool *custom); + string cssfunction(const string& method, const string& post, const map &varmap, bool *custom); + string jsonstat(const string& method, const string& post, const map &varmap, bool *custom); void printvars(ostringstream &ret); void printargs(ostringstream &ret); void launch();