]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd_config.cpp
Merge pull request #1337 from SaberUK/master+merge
[user/henk/code/inspircd.git] / src / modules / m_httpd_config.cpp
index f79f0c2a4a1f0cb7e4496b7987aaa02806990eeb..6fd7f405013e6fcc22092bd4c32ac5833bb5712b 100644 (file)
@@ -1,28 +1,35 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
  *
- * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "inspircd.h"
-#include "httpd.h"
-#include "protocol.h"
 
-/* $ModDesc: Provides statistics over HTTP via m_httpd.so */
+#include "inspircd.h"
+#include "modules/httpd.h"
 
-class ModuleHttpConfig : public Module
+class ModuleHttpConfig : public Module, public HTTPRequestEventListener
 {
+       HTTPdAPI API;
+
  public:
-       ModuleHttpConfig()      {
-               Implementation eventlist[] = { I_OnEvent };
-               ServerInstance->Modules->Attach(eventlist, this, 1);
+       ModuleHttpConfig()
+               : HTTPRequestEventListener(this)
+               , API(this)
+       {
        }
 
        std::string Sanitize(const std::string &str)
@@ -59,14 +66,12 @@ class ModuleHttpConfig : public Module
                return ret;
        }
 
-       void OnEvent(Event& event)
+       ModResult HandleRequest(HTTPRequest* http)
        {
                std::stringstream data("");
 
-               if (event.id == "httpd_url")
                {
-                       ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
-                       HTTPRequest* http = (HTTPRequest*)&event;
+                       ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event");
 
                        if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
                        {
@@ -87,20 +92,23 @@ class ModuleHttpConfig : public Module
                                data << "</body></html>";
                                /* Send the document back to m_httpd */
                                HTTPDocumentResponse response(this, *http, &data, 200);
-                               response.headers.SetHeader("X-Powered-By", "m_httpd_config.so");
+                               response.headers.SetHeader("X-Powered-By", MODNAME);
                                response.headers.SetHeader("Content-Type", "text/html");
-                               response.Send();
+                               API->SendResponse(response);
+                               return MOD_RES_DENY; // Handled
                        }
                }
+               return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleHttpConfig()
+       ModResult OnHTTPRequest(HTTPRequest& req) CXX11_OVERRIDE
        {
+               return HandleRequest(&req);
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides configuration over HTTP via m_httpd.so", VF_VENDOR);
+               return Version("Allows for the server configuration to be viewed over HTTP via m_httpd.so", VF_VENDOR);
        }
 };