summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-10-30 18:58:11 -0400
committerAdam <Adam@anope.org>2016-10-30 18:58:11 -0400
commitbe4083106b245053992e2b15c4c75aa74f5d39de (patch)
treef2257da53d82139a7f09a2211abb49ffa1a46f01 /include
parentc06cc40d27e5cb83424d89cb19571eb42392abe6 (diff)
Add new RESTful JSON API and documentation
Diffstat (limited to 'include')
-rw-r--r--include/modules/httpd.h20
-rw-r--r--include/serialize.h25
2 files changed, 43 insertions, 2 deletions
diff --git a/include/modules/httpd.h b/include/modules/httpd.h
index ce28e0622..9cbef9b78 100644
--- a/include/modules/httpd.h
+++ b/include/modules/httpd.h
@@ -22,12 +22,31 @@
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
{
@@ -93,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;
diff --git a/include/serialize.h b/include/serialize.h
index 8f35e61c6..f10563507 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -95,7 +95,7 @@ class CoreExport Serialize::Object : public Extensible, public virtual Base
std::map<TypeBase *, std::vector<Edge>> edges;
- std::vector<Edge> GetRefs(TypeBase *);
+ std::vector<Edge> GetEdges(TypeBase *);
public:
Object(TypeBase *type);
@@ -128,6 +128,8 @@ class CoreExport Serialize::Object : public Extensible, public virtual Base
template<typename T>
std::vector<T> GetRefs();
+ std::vector<Object *> GetRefs(Serialize::TypeBase *);
+
/**
* Get the value of a field on this object.
*/
@@ -867,6 +869,25 @@ T Serialize::New()
return static_cast<T>(type->Create());
}
+inline std::vector<Serialize::Object *> Serialize::Object::GetRefs(Serialize::TypeBase *type)
+{
+ std::vector<Serialize::TypeBase *> types = GetTypes(type->GetName());
+ std::vector<Object *> objs;
+
+ if (types.empty())
+ {
+ Log(LOG_DEBUG) << "GetRefs for unknown type on #" << this->id << " type " << s_type->GetName() << " named " << type->GetName();
+ return objs;
+ }
+
+ for (Serialize::TypeBase *t : types)
+ for (const Serialize::Edge &edge : GetEdges(t))
+ if (!edge.direction)
+ objs.push_back(edge.other);
+
+ return objs;
+}
+
template<typename T>
std::vector<T> Serialize::Object::GetRefs()
{
@@ -881,7 +902,7 @@ std::vector<T> Serialize::Object::GetRefs()
}
for (Serialize::TypeBase *t : types)
- for (const Serialize::Edge &edge : GetRefs(t))
+ for (const Serialize::Edge &edge : GetEdges(t))
if (!edge.direction)
objs.push_back(anope_dynamic_static_cast<T>(edge.other));