diff options
Diffstat (limited to 'modules/extra')
-rw-r--r-- | modules/extra/httpd.h | 226 | ||||
-rw-r--r-- | modules/extra/ldap.h | 173 | ||||
-rw-r--r-- | modules/extra/sql.h | 216 | ||||
-rw-r--r-- | modules/extra/ssl.h | 9 | ||||
-rw-r--r-- | modules/extra/xmlrpc.h | 40 |
5 files changed, 0 insertions, 664 deletions
diff --git a/modules/extra/httpd.h b/modules/extra/httpd.h deleted file mode 100644 index 6127a51e0..000000000 --- a/modules/extra/httpd.h +++ /dev/null @@ -1,226 +0,0 @@ -#ifndef ANOPE_HTTPD_H -#define ANOPE_HTTPD_H - -enum HTTPError -{ - HTTP_ERROR_OK = 200, - HTTP_FOUND = 302, - HTTP_BAD_REQUEST = 400, - HTTP_PAGE_NOT_FOUND = 404, - HTTP_NOT_SUPPORTED = 505 -}; - -/* A message to someone */ -struct HTTPReply -{ - HTTPError error; - Anope::string content_type; - std::map<Anope::string, Anope::string> headers; - typedef std::list<std::pair<Anope::string, Anope::string> > cookie; - std::vector<cookie> cookies; - - HTTPReply() : error(HTTP_ERROR_OK), length(0) { } - - HTTPReply(const HTTPReply& other) : error(other.error), length(other.length) - { - content_type = other.content_type; - headers = other.headers; - cookies = other.cookies; - - for (unsigned i = 0; i < other.out.size(); ++i) - out.push_back(new Data(other.out[i]->buf, other.out[i]->len)); - } - - ~HTTPReply() - { - for (unsigned i = 0; i < out.size(); ++i) - delete out[i]; - out.clear(); - } - - struct Data - { - char *buf; - size_t len; - - Data(const char *b, size_t l) - { - this->buf = new char[l]; - memcpy(this->buf, b, l); - this->len = l; - } - - ~Data() - { - delete [] buf; - } - }; - - std::deque<Data *> out; - size_t length; - - void Write(const Anope::string &message) - { - this->out.push_back(new Data(message.c_str(), message.length())); - this->length += message.length(); - } - - void Write(const char *b, size_t l) - { - this->out.push_back(new Data(b, l)); - this->length += l; - } -}; - -/* A message from soneone */ -struct HTTPMessage -{ - std::map<Anope::string, Anope::string> headers; - std::map<Anope::string, Anope::string> cookies; - std::map<Anope::string, Anope::string> get_data; - std::map<Anope::string, Anope::string> post_data; - Anope::string content; -}; - -class HTTPClient; -class HTTPProvider; - -class HTTPPage : public Base -{ - Anope::string url; - Anope::string content_type; - - public: - HTTPPage(const Anope::string &u, const Anope::string &ct = "text/html") : url(u), content_type(ct) { } - - const Anope::string &GetURL() const { return this->url; } - - const Anope::string &GetContentType() const { return this->content_type; } - - /** Called when this page is requested - * @param The server this page is on - * @param The page name - * @param The client requesting the page - * @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; -}; - -class HTTPClient : public ClientSocket, public BinarySocket, public Base -{ - protected: - void WriteClient(const Anope::string &message) - { - BinarySocket::Write(message + "\r\n"); - } - - public: - HTTPClient(ListenSocket *l, int f, const sockaddrs &a) : ClientSocket(l, a), BinarySocket() { } - - virtual const Anope::string GetIP() - { - return this->clientaddr.addr(); - } - - virtual void SendError(HTTPError err, const Anope::string &msg) = 0; - virtual void SendReply(HTTPReply *) = 0; -}; - -class HTTPProvider : public ListenSocket, public Service -{ - Anope::string ip; - unsigned short port; - public: - 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) : ListenSocket(i, p, i.find(':') != Anope::string::npos), Service(c, "HTTPProvider", n), ip(i), port(p) { } - - const Anope::string &GetIP() const - { - return this->ip; - } - - unsigned short GetPort() const - { - return this->port; - } - - virtual bool RegisterPage(HTTPPage *page) = 0; - virtual void UnregisterPage(HTTPPage *page) = 0; - virtual HTTPPage* FindPage(const Anope::string &name) = 0; -}; - -namespace HTTPUtils -{ - inline Anope::string URLDecode(const Anope::string &url) - { - Anope::string decoded; - - for (unsigned i = 0; i < url.length(); ++i) - { - const char& c = url[i]; - - if (c == '%' && i + 2 < url.length()) - { - Anope::string dest; - Anope::Unhex(url.substr(i + 1, 2), dest); - decoded += dest; - i += 2; - } - else if (c == '+') - decoded += ' '; - else - decoded += c; - } - - return decoded; - } - - inline Anope::string URLEncode(const Anope::string &url) - { - Anope::string encoded; - - for (unsigned i = 0; i < url.length(); ++i) - { - const char& c = url[i]; - - if (isalnum(c) || c == '.' || c == '-' || c == '*' || c == '_') - encoded += c; - else if (c == ' ') - encoded += '+'; - else - encoded += "%" + Anope::Hex(c); - } - - return encoded; - } - - inline Anope::string Escape(const Anope::string &src) - { - Anope::string dst; - - for (unsigned i = 0; i < src.length(); ++i) - { - switch (src[i]) - { - case '<': - dst += "<"; - break; - case '>': - dst += ">"; - break; - case '"': - dst += """; - break; - default: - dst += src[i]; - } - } - - return dst; - } -} - -#endif // ANOPE_HTTPD_H diff --git a/modules/extra/ldap.h b/modules/extra/ldap.h deleted file mode 100644 index 65be27687..000000000 --- a/modules/extra/ldap.h +++ /dev/null @@ -1,173 +0,0 @@ -#ifndef ANOPE_LDAP_H -#define ANOPE_LDAP_H - -typedef int LDAPQuery; - -class LDAPException : public ModuleException -{ - public: - LDAPException(const Anope::string &reason) : ModuleException(reason) { } - - virtual ~LDAPException() throw() { } -}; - -struct LDAPModification -{ - enum LDAPOperation - { - LDAP_ADD, - LDAP_DEL, - LDAP_REPLACE - }; - - LDAPOperation op; - Anope::string name; - std::vector<Anope::string> values; -}; -typedef std::vector<LDAPModification> LDAPMods; - -struct LDAPAttributes : public std::map<Anope::string, std::vector<Anope::string> > -{ - size_t size(const Anope::string &attr) const - { - const std::vector<Anope::string>& array = this->getArray(attr); - return array.size(); - } - - const std::vector<Anope::string> keys() const - { - std::vector<Anope::string> k; - for (const_iterator it = this->begin(), it_end = this->end(); it != it_end; ++it) - k.push_back(it->first); - return k; - } - - const Anope::string &get(const Anope::string &attr) const - { - const std::vector<Anope::string>& array = this->getArray(attr); - if (array.empty()) - throw LDAPException("Empty attribute " + attr + " in LDAPResult::get"); - return array[0]; - } - - const std::vector<Anope::string>& getArray(const Anope::string &attr) const - { - const_iterator it = this->find(attr); - if (it == this->end()) - throw LDAPException("Unknown attribute " + attr + " in LDAPResult::getArray"); - return it->second; - } -}; - -struct LDAPResult -{ - std::vector<LDAPAttributes> messages; - Anope::string error; - - enum QueryType - { - QUERY_UNKNOWN, - QUERY_BIND, - QUERY_SEARCH, - QUERY_ADD, - QUERY_DELETE, - QUERY_MODIFY - }; - - QueryType type; - LDAPQuery id; - - LDAPResult() - { - this->type = QUERY_UNKNOWN; - this->id = -1; - } - - size_t size() const - { - return this->messages.size(); - } - - bool empty() const - { - return this->messages.empty(); - } - - const LDAPAttributes &get(size_t sz) const - { - if (sz >= this->messages.size()) - throw LDAPException("Index out of range"); - return this->messages[sz]; - } - - const Anope::string &getError() const - { - return this->error; - } -}; - -class LDAPInterface -{ - public: - Module *owner; - - LDAPInterface(Module *m) : owner(m) { } - virtual ~LDAPInterface() { } - - virtual void OnResult(const LDAPResult &r) = 0; - virtual void OnError(const LDAPResult &err) = 0; - virtual void OnDelete() { } -}; - -class LDAPProvider : public Service -{ - public: - LDAPProvider(Module *c, const Anope::string &n) : Service(c, "LDAPProvider", n) { } - - /** Attempt to bind to the LDAP server as an admin - * @param i The LDAPInterface the result is sent to - * @return The query ID - */ - virtual LDAPQuery BindAsAdmin(LDAPInterface *i) = 0; - - /** Bind to LDAP - * @param i The LDAPInterface the result is sent to - * @param who The binddn - * @param pass The password - * @return The query ID - */ - virtual LDAPQuery Bind(LDAPInterface *i, const Anope::string &who, const Anope::string &pass) = 0; - - /** Search ldap for the specified filter - * @param i The LDAPInterface the result is sent to - * @param base The base DN to search - * @param filter The filter to apply - * @return The query ID - */ - virtual LDAPQuery Search(LDAPInterface *i, const Anope::string &base, const Anope::string &filter) = 0; - - /** Add an entry to LDAP - * @param i The LDAPInterface the result is sent to - * @param dn The dn of the entry to add - * @param attributes The attributes - * @return The query ID - */ - virtual LDAPQuery Add(LDAPInterface *i, const Anope::string &dn, LDAPMods &attributes) = 0; - - /** Delete an entry from LDAP - * @param i The LDAPInterface the result is sent to - * @param dn The dn of the entry to delete - * @return The query ID - */ - virtual LDAPQuery Del(LDAPInterface *i, const Anope::string &dn) = 0; - - /** Modify an existing entry in LDAP - * @param i The LDAPInterface the result is sent to - * @param base The base DN to modify - * @param attributes The attributes to modify - * @return The query ID - */ - virtual LDAPQuery Modify(LDAPInterface *i, const Anope::string &base, LDAPMods &attributes) = 0; -}; - -#endif // ANOPE_LDAP_H diff --git a/modules/extra/sql.h b/modules/extra/sql.h deleted file mode 100644 index 1c8fdd3aa..000000000 --- a/modules/extra/sql.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - * (C) 2003-2013 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - */ - -namespace SQL -{ - - class Data : public Serialize::Data - { - public: - typedef std::map<Anope::string, std::stringstream *> Map; - Map data; - std::map<Anope::string, Type> types; - - ~Data() - { - Clear(); - } - - std::iostream& operator[](const Anope::string &key) anope_override - { - std::stringstream *&ss = data[key]; - if (!ss) - ss = new std::stringstream(); - return *ss; - } - - std::set<Anope::string> KeySet() const anope_override - { - std::set<Anope::string> keys; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - keys.insert(it->first); - return keys; - } - - size_t Hash() const anope_override - { - size_t hash = 0; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - if (!it->second->str().empty()) - hash ^= Anope::hash_cs()(it->second->str()); - return hash; - } - - std::map<Anope::string, std::iostream *> GetData() const - { - std::map<Anope::string, std::iostream *> d; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - d[it->first] = it->second; - return d; - } - - void Clear() - { - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - delete it->second; - this->data.clear(); - } - - void SetType(const Anope::string &key, Type t) anope_override - { - this->types[key] = t; - } - - Type GetType(const Anope::string &key) const anope_override - { - std::map<Anope::string, Type>::const_iterator it = this->types.find(key); - if (it != this->types.end()) - return it->second; - return DT_TEXT; - } - }; - - /** A SQL exception, can be thrown at various points - */ - class Exception : public ModuleException - { - public: - Exception(const Anope::string &reason) : ModuleException(reason) { } - - virtual ~Exception() throw() { } - }; - - /** A SQL query - */ - - struct QueryData - { - Anope::string data; - bool escape; - }; - - struct Query - { - Anope::string query; - std::map<Anope::string, QueryData> parameters; - - Query() { } - Query(const Anope::string &q) : query(q) { } - - Query& operator=(const Anope::string &q) - { - this->query = q; - this->parameters.clear(); - return *this; - } - - bool operator==(const Query &other) const - { - return this->query == other.query; - } - - inline bool operator!=(const Query &other) const - { - return !(*this == other); - } - - template<typename T> void SetValue(const Anope::string &key, const T& value, bool escape = true) - { - try - { - Anope::string string_value = stringify(value); - this->parameters[key].data = string_value; - this->parameters[key].escape = escape; - } - catch (const ConvertException &ex) { } - } - }; - - /** A result from a SQL query - */ - class Result - { - protected: - /* Rows, column, item */ - std::vector<std::map<Anope::string, Anope::string> > entries; - Query query; - Anope::string error; - public: - unsigned int id; - Anope::string finished_query; - - Result() : id(0) { } - Result(unsigned int i, const Query &q, const Anope::string &fq, const Anope::string &err = "") : query(q), error(err), id(i), finished_query(fq) { } - - inline operator bool() const { return this->error.empty(); } - - inline const unsigned int GetID() const { return this->id; } - inline const Query &GetQuery() const { return this->query; } - inline const Anope::string &GetError() const { return this->error; } - - int Rows() const { return this->entries.size(); } - - const std::map<Anope::string, Anope::string> &Row(size_t index) const - { - try - { - return this->entries.at(index); - } - catch (const std::out_of_range &) - { - throw Exception("Out of bounds access to SQLResult"); - } - } - - const Anope::string Get(size_t index, const Anope::string &col) const - { - const std::map<Anope::string, Anope::string> rows = this->Row(index); - - std::map<Anope::string, Anope::string>::const_iterator it = rows.find(col); - if (it == rows.end()) - throw Exception("Unknown column name in SQLResult: " + col); - - return it->second; - } - }; - - /* An interface used by modules to retrieve the results - */ - class Interface - { - public: - Module *owner; - - Interface(Module *m) : owner(m) { } - virtual ~Interface() { } - - virtual void OnResult(const Result &r) = 0; - virtual void OnError(const Result &r) = 0; - }; - - /** Class providing the SQL service, modules call this to execute queries - */ - class Provider : public Service - { - public: - Provider(Module *c, const Anope::string &n) : Service(c, "SQL::Provider", n) { } - - virtual void Run(Interface *i, const Query &query) = 0; - - virtual Result RunQuery(const Query &query) = 0; - - virtual std::vector<Query> CreateTable(const Anope::string &table, const Data &data) = 0; - - virtual Query BuildInsert(const Anope::string &table, unsigned int id, Data &data) = 0; - - virtual Query GetTables(const Anope::string &prefix) = 0; - - virtual Anope::string FromUnixtime(time_t) = 0; - }; - -} - diff --git a/modules/extra/ssl.h b/modules/extra/ssl.h deleted file mode 100644 index 6eb97582c..000000000 --- a/modules/extra/ssl.h +++ /dev/null @@ -1,9 +0,0 @@ - -class SSLService : public Service -{ - public: - SSLService(Module *o, const Anope::string &n) : Service(o, "SSLService", n) { } - - virtual void Init(Socket *s) = 0; -}; - diff --git a/modules/extra/xmlrpc.h b/modules/extra/xmlrpc.h deleted file mode 100644 index d5a5ea4a7..000000000 --- a/modules/extra/xmlrpc.h +++ /dev/null @@ -1,40 +0,0 @@ -#include "httpd.h" - -class XMLRPCRequest -{ - std::map<Anope::string, Anope::string> replies; - - public: - Anope::string name; - Anope::string id; - std::deque<Anope::string> data; - HTTPReply& r; - - XMLRPCRequest(HTTPReply &_r) : r(_r) { } - inline void reply(const Anope::string &dname, const Anope::string &ddata) { this->replies.insert(std::make_pair(dname, ddata)); } - inline const std::map<Anope::string, Anope::string> &get_replies() { return this->replies; } -}; - -class XMLRPCServiceInterface; - -class XMLRPCEvent -{ - public: - virtual ~XMLRPCEvent() { } - virtual bool Run(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) = 0; -}; - -class XMLRPCServiceInterface : public Service -{ - public: - XMLRPCServiceInterface(Module *creator, const Anope::string &sname) : Service(creator, "XMLRPCServiceInterface", sname) { } - - virtual void Register(XMLRPCEvent *event) = 0; - - virtual void Unregister(XMLRPCEvent *event) = 0; - - virtual Anope::string Sanitize(const Anope::string &string) = 0; - - virtual void Reply(XMLRPCRequest &request) = 0; -}; - |