summaryrefslogtreecommitdiff
path: root/include/modules/httpd.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/modules/httpd.h')
-rw-r--r--include/modules/httpd.h61
1 files changed, 47 insertions, 14 deletions
diff --git a/include/modules/httpd.h b/include/modules/httpd.h
index 8df3c181b..9cbef9b78 100644
--- a/include/modules/httpd.h
+++ b/include/modules/httpd.h
@@ -1,23 +1,52 @@
/*
+ * Anope IRC Services
*
- * (C) 2012-2016 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2012-2016 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope 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 see <http://www.gnu.org/licenses/>.
*/
-#ifndef ANOPE_HTTPD_H
-#define ANOPE_HTTPD_H
+#pragma once
enum HTTPError
{
HTTP_ERROR_OK = 200,
+ HTTP_CREATED = 201,
HTTP_FOUND = 302,
HTTP_BAD_REQUEST = 400,
HTTP_PAGE_NOT_FOUND = 404,
+ HTTP_INTERNAL_SERVER_ERROR = 500,
HTTP_NOT_SUPPORTED = 505
};
+namespace httpd
+{
+
+enum class Method
+{
+ NONE,
+ GET,
+ POST,
+ PUT,
+ DELETE,
+ OPTIONS,
+ HEAD
+};
+
+} // namespace httpd
+
+
/* A message to someone */
struct HTTPReply
{
@@ -83,6 +112,7 @@ struct HTTPReply
/* A message from soneone */
struct HTTPMessage
{
+ httpd::Method method = httpd::Method::NONE;
std::map<Anope::string, Anope::string> headers;
std::map<Anope::string, Anope::string> cookies;
std::map<Anope::string, Anope::string> get_data;
@@ -112,7 +142,7 @@ class HTTPPage : public Base
* @param The HTTP header sent from the client to request the page
* @param The HTTP header that will be sent back to the client
*/
- virtual bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) = 0;
+ virtual bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_abstract;
};
class HTTPClient : public ClientSocket, public BinarySocket, public Base
@@ -131,8 +161,8 @@ class HTTPClient : public ClientSocket, public BinarySocket, public Base
return this->clientaddr.addr();
}
- virtual void SendError(HTTPError err, const Anope::string &msg) = 0;
- virtual void SendReply(HTTPReply *) = 0;
+ virtual void SendError(HTTPError err, const Anope::string &msg) anope_abstract;
+ virtual void SendReply(HTTPReply *) anope_abstract;
};
class HTTPProvider : public ListenSocket, public Service
@@ -140,11 +170,16 @@ class HTTPProvider : public ListenSocket, public Service
Anope::string ip;
unsigned short port;
bool ssl;
+
public:
+ static constexpr const char *NAME = "http";
+
Anope::string ext_ip;
std::vector<Anope::string> ext_headers;
- HTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, bool s) : ListenSocket(i, p, i.find(':') != Anope::string::npos), Service(c, "HTTPProvider", n), ip(i), port(p), ssl(s) { }
+ HTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, bool s)
+ : ListenSocket(i, p, i.find(':') != Anope::string::npos)
+ , Service(c, NAME, n), ip(i), port(p), ssl(s) { }
const Anope::string &GetIP() const
{
@@ -161,9 +196,9 @@ class HTTPProvider : public ListenSocket, public Service
return this->ssl;
}
- virtual bool RegisterPage(HTTPPage *page) = 0;
- virtual void UnregisterPage(HTTPPage *page) = 0;
- virtual HTTPPage* FindPage(const Anope::string &name) = 0;
+ virtual bool RegisterPage(HTTPPage *page) anope_abstract;
+ virtual void UnregisterPage(HTTPPage *page) anope_abstract;
+ virtual HTTPPage* FindPage(const Anope::string &name) anope_abstract;
};
namespace HTTPUtils
@@ -236,5 +271,3 @@ namespace HTTPUtils
return dst;
}
}
-
-#endif // ANOPE_HTTPD_H