diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/channels.h | 6 | ||||
-rw-r--r-- | include/inspircd.h | 5 | ||||
-rw-r--r-- | include/inspsocket.h | 119 | ||||
-rw-r--r-- | include/iohook.h | 3 | ||||
-rw-r--r-- | include/modules.h | 7 | ||||
-rw-r--r-- | include/modules/ldap.h | 47 | ||||
-rw-r--r-- | include/modules/ssl.h | 25 |
7 files changed, 166 insertions, 46 deletions
diff --git a/include/channels.h b/include/channels.h index 2b7c5d025..4d1d14c13 100644 --- a/include/channels.h +++ b/include/channels.h @@ -305,12 +305,6 @@ class CoreExport Channel : public Extensible, public InviteBase<Channel> */ const char* ChanModes(bool showkey); - /** Spool the NAMES list for this channel to the given user - * @param user The user to spool the NAMES list to - * @param isinside If true, the user is inside the channel, if not then false - */ - void UserList(User* user, bool isinside = true); - /** Get the value of a users prefix on this channel. * @param user The user to look up * @return The module or core-defined value of the users prefix. diff --git a/include/inspircd.h b/include/inspircd.h index b90c0c797..d41d2919b 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -502,11 +502,6 @@ class CoreExport InspIRCd static const char* Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2); static const char* Format(va_list &vaList, const char* formatString) CUSTOM_PRINTF(2, 0); - /** Send an error notice to all local users, opered and unopered - * @param s The error string to send - */ - void SendError(const std::string &s); - /** Return true if a nickname is valid * @param n A nickname to verify * @return True if the nick is valid diff --git a/include/inspsocket.h b/include/inspsocket.h index 221b92cc6..53eca2e91 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -103,14 +103,119 @@ class CoreExport SocketTimeout : public Timer */ class CoreExport StreamSocket : public EventHandler { + public: + /** Socket send queue + */ + class SendQueue + { + public: + /** One element of the queue, a continuous buffer + */ + typedef std::string Element; + + /** Sequence container of buffers in the queue + */ + typedef std::deque<Element> Container; + + /** Container iterator + */ + typedef Container::const_iterator const_iterator; + + SendQueue() : nbytes(0) { } + + /** Return whether the queue is empty + * @return True if the queue is empty, false otherwise + */ + bool empty() const { return (nbytes == 0); } + + /** Get the number of individual buffers in the queue + * @return Number of individual buffers in the queue + */ + Container::size_type size() const { return data.size(); } + + /** Get the number of queued bytes + * @return Size in bytes of the data in the queue + */ + size_t bytes() const { return nbytes; } + + /** Get the first buffer of the queue + * @return A reference to the first buffer in the queue + */ + const Element& front() const { return data.front(); } + + /** Get an iterator to the first buffer in the queue. + * The returned iterator cannot be used to make modifications to the queue, + * for that purpose the member functions push_*(), pop_front(), erase_front() and clear() can be used. + * @return Iterator referring to the first buffer in the queue, or end() if there are no elements. + */ + const_iterator begin() const { return data.begin(); } + + /** Get an iterator to the (theoretical) buffer one past the end of the queue. + * @return Iterator referring to one element past the end of the container + */ + const_iterator end() const { return data.end(); } + + /** Remove the first buffer in the queue + */ + void pop_front() + { + nbytes -= data.front().length(); + data.pop_front(); + } + + /** Remove bytes from the beginning of the first buffer + * @param n Number of bytes to remove + */ + void erase_front(Element::size_type n) + { + nbytes -= n; + data.front().erase(0, n); + } + + /** Insert a new buffer at the beginning of the queue + * @param newdata Data to add + */ + void push_front(const Element& newdata) + { + data.push_front(newdata); + nbytes += newdata.length(); + } + + /** Insert a new buffer at the end of the queue + * @param newdata Data to add + */ + void push_back(const Element& newdata) + { + data.push_back(newdata); + nbytes += newdata.length(); + } + + /** Clear the queue + */ + void clear() + { + data.clear(); + nbytes = 0; + } + + private: + /** Private send queue. Note that individual strings may be shared. + */ + Container data; + + /** Length, in bytes, of the sendq + */ + size_t nbytes; + }; + + private: /** The IOHook that handles raw I/O for this socket, or NULL */ IOHook* iohook; - /** Private send queue. Note that individual strings may be shared + /** Send queue of the socket */ - std::deque<std::string> sendq; - /** Length, in bytes, of the sendq */ - size_t sendq_len; + SendQueue sendq; + /** Error - if nonempty, the socket is dead, and this is the reason. */ std::string error; @@ -126,7 +231,7 @@ class CoreExport StreamSocket : public EventHandler protected: std::string recvq; public: - StreamSocket() : iohook(NULL), sendq_len(0) {} + StreamSocket() : iohook(NULL) { } IOHook* GetIOHook() const; void AddIOHook(IOHook* hook); void DelIOHook(); @@ -169,7 +274,9 @@ class CoreExport StreamSocket : public EventHandler */ bool GetNextLine(std::string& line, char delim = '\n'); /** Useful for implementing sendq exceeded */ - inline size_t getSendQSize() const { return sendq_len; } + size_t getSendQSize() const { return sendq.size(); } + + SendQueue& GetSendQ() { return sendq; } /** * Close the socket, remove from socket engine, etc diff --git a/include/iohook.h b/include/iohook.h index ce7ca2a1b..cf27fcb0c 100644 --- a/include/iohook.h +++ b/include/iohook.h @@ -66,11 +66,10 @@ class IOHook : public classbase * Called when a hooked stream has data to write, or when the socket * engine returns it as writable * @param sock The socket in question - * @param sendq Data to send to the socket * @return 1 if the sendq has been completely emptied, 0 if there is * still data to send, and -1 if there was an error */ - virtual int OnStreamSocketWrite(StreamSocket* sock, std::string& sendq) = 0; + virtual int OnStreamSocketWrite(StreamSocket* sock) = 0; /** Called immediately before any socket is closed. When this event is called, shutdown() * has not yet been called on the socket. diff --git a/include/modules.h b/include/modules.h index 3cf780284..c938e6a9d 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1068,6 +1068,13 @@ class CoreExport ModuleManager : public fakederef<ModuleManager> */ ServiceList* NewServices; + /** Expands the name of a module by prepending "m_" and appending ".so". + * No-op if the name already has the ".so" extension. + * @param modname Module name to expand + * @return Module name starting with "m_" and ending with ".so" + */ + static std::string ExpandModName(const std::string& modname); + /** Simple, bog-standard, boring constructor. */ ModuleManager(); diff --git a/include/modules/ldap.h b/include/modules/ldap.h index 75ab16077..aeb3aa335 100644 --- a/include/modules/ldap.h +++ b/include/modules/ldap.h @@ -1,8 +1,8 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2013 Adam <Adam@anope.org> - * Copyright (C) 2003-2013 Anope Team <team@anope.org> + * Copyright (C) 2015 Adam <Adam@anope.org> + * Copyright (C) 2003-2015 Anope Team <team@anope.org> * * 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 @@ -78,22 +78,22 @@ struct LDAPAttributes : public std::map<std::string, std::vector<std::string> > } }; +enum QueryType +{ + QUERY_UNKNOWN, + QUERY_BIND, + QUERY_SEARCH, + QUERY_ADD, + QUERY_DELETE, + QUERY_MODIFY, + QUERY_COMPARE +}; + struct LDAPResult { std::vector<LDAPAttributes> messages; std::string error; - enum QueryType - { - QUERY_UNKNOWN, - QUERY_BIND, - QUERY_SEARCH, - QUERY_ADD, - QUERY_DELETE, - QUERY_MODIFY, - QUERY_COMPARE - }; - QueryType type; LDAPQuery id; @@ -145,55 +145,48 @@ class LDAPProvider : public DataProvider /** Attempt to bind to the LDAP server as a manager * @param i The LDAPInterface the result is sent to - * @return The query ID */ - virtual LDAPQuery BindAsManager(LDAPInterface *i) = 0; + virtual void BindAsManager(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 std::string& who, const std::string& pass) = 0; + virtual void Bind(LDAPInterface* i, const std::string& who, const std::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 std::string& base, const std::string& filter) = 0; + virtual void Search(LDAPInterface* i, const std::string& base, const std::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 std::string& dn, LDAPMods& attributes) = 0; + virtual void Add(LDAPInterface* i, const std::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 std::string& dn) = 0; + virtual void Del(LDAPInterface* i, const std::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 std::string& base, LDAPMods& attributes) = 0; + virtual void Modify(LDAPInterface* i, const std::string& base, LDAPMods& attributes) = 0; /** Compare an attribute in LDAP with our value * @param i The LDAPInterface the result is sent to * @param dn DN to use for comparing * @param attr Attr of DN to compare with * @param val value to compare attr of dn - * @return the query ID */ - virtual LDAPQuery Compare(LDAPInterface* i, const std::string& dn, const std::string& attr, const std::string& val) = 0; + virtual void Compare(LDAPInterface* i, const std::string& dn, const std::string& attr, const std::string& val) = 0; }; diff --git a/include/modules/ssl.h b/include/modules/ssl.h index 0f58e0b7b..67bfc7b2e 100644 --- a/include/modules/ssl.h +++ b/include/modules/ssl.h @@ -138,6 +138,31 @@ class SSLIOHook : public IOHook */ reference<ssl_cert> certificate; + /** Reduce elements in a send queue by appending later elements to the first element until there are no more + * elements to append or a desired length is reached + * @param sendq SendQ to work on + * @param targetsize Target size of the front element + */ + static void FlattenSendQueue(StreamSocket::SendQueue& sendq, size_t targetsize) + { + if ((sendq.size() <= 1) || (sendq.front().length() >= targetsize)) + return; + + // Avoid multiple repeated SSL encryption invocations + // This adds a single copy of the queue, but avoids + // much more overhead in terms of system calls invoked + // by an IOHook. + std::string tmp; + tmp.reserve(std::min(targetsize, sendq.bytes())+1); + do + { + tmp.append(sendq.front()); + sendq.pop_front(); + } + while (!sendq.empty() && tmp.length() < targetsize); + sendq.push_front(tmp); + } + public: SSLIOHook(IOHookProvider* hookprov) : IOHook(hookprov) |