summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/CMakeLists.txt48
-rw-r--r--include/access.h36
-rw-r--r--include/account.h138
-rw-r--r--include/anope.h257
-rw-r--r--include/base.h37
-rw-r--r--include/bots.h25
-rw-r--r--include/channels.h36
-rw-r--r--include/commands.h48
-rw-r--r--include/config.h72
-rw-r--r--include/convert.h132
-rw-r--r--include/defs.h2
-rw-r--r--include/extensible.h104
-rw-r--r--include/hashcomp.h41
-rw-r--r--include/language.h83
-rw-r--r--include/lists.h27
-rw-r--r--include/logger.h41
-rw-r--r--include/mail.h14
-rw-r--r--include/memo.h18
-rw-r--r--include/messages.h139
-rw-r--r--include/modes.h117
-rw-r--r--include/module.h5
-rw-r--r--include/modules.h338
-rw-r--r--include/modules/bs_badwords.h14
-rw-r--r--include/modules/bs_kick.h10
-rw-r--r--include/modules/cs_entrymsg.h17
-rw-r--r--include/modules/cs_log.h17
-rw-r--r--include/modules/cs_mode.h10
-rw-r--r--include/modules/dns.h49
-rw-r--r--include/modules/encryption.h138
-rw-r--r--include/modules/hs_request.h23
-rw-r--r--include/modules/httpd.h62
-rw-r--r--include/modules/info.h49
-rw-r--r--include/modules/ldap.h31
-rw-r--r--include/modules/ns_cert.h27
-rw-r--r--include/modules/os_forbid.h22
-rw-r--r--include/modules/os_ignore.h17
-rw-r--r--include/modules/os_news.h15
-rw-r--r--include/modules/os_oper.h46
-rw-r--r--include/modules/os_session.h41
-rw-r--r--include/modules/pseudoclients/chanserv.h10
-rw-r--r--include/modules/pseudoclients/global.h71
-rw-r--r--include/modules/pseudoclients/memoserv.h10
-rw-r--r--include/modules/pseudoclients/nickserv.h11
-rw-r--r--include/modules/redis.h17
-rw-r--r--include/modules/rpc.h128
-rw-r--r--include/modules/sasl.h32
-rw-r--r--include/modules/set_misc.h7
-rw-r--r--include/modules/sql.h93
-rw-r--r--include/modules/ssl.h7
-rw-r--r--include/modules/suspend.h6
-rw-r--r--include/modules/xmlrpc.h47
-rw-r--r--include/numeric.h35
-rw-r--r--include/opertype.h19
-rw-r--r--include/protocol.h294
-rw-r--r--include/pstdint.h800
-rw-r--r--include/regchannel.h37
-rw-r--r--include/regexpr.h23
-rw-r--r--include/serialize.h109
-rw-r--r--include/servers.h20
-rw-r--r--include/service.h49
-rw-r--r--include/services.h63
-rw-r--r--include/socketengine.h9
-rw-r--r--include/sockets.h137
-rw-r--r--include/sysconf.h.cmake85
-rw-r--r--include/threadengine.h79
-rw-r--r--include/timers.h38
-rw-r--r--include/uplink.h60
-rw-r--r--include/users.h62
-rw-r--r--include/version.cpp22
-rw-r--r--include/xline.h27
70 files changed, 2250 insertions, 2503 deletions
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index a434be6e1..763826344 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -3,7 +3,7 @@ set_source_files_properties(version.cpp PROPERTIES LANGUAGE CXX COMPILE_FLAGS "$
# Generate version-bin executable to modify version.h, setting it's linker flags as well
add_executable(version-bin version.cpp)
set_target_properties(version-bin PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
-get_target_property(version_BINARY version-bin LOCATION)
+set(version_BINARY "$<TARGET_FILE:version-bin>")
# Modify version.h from the above executable, with dependencies to version.cpp
# and all of the source files in the main build
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h ${CMAKE_CURRENT_BINARY_DIR}/build.h
@@ -16,49 +16,7 @@ add_to_cpack_ignored_files("${version_BINARY}$" TRUE)
if(NOT WIN32)
add_to_cpack_ignored_files("version.h$" TRUE)
add_to_cpack_ignored_files("build.h$" TRUE)
-endif(NOT WIN32)
-
-set(PCH_SOURCES_GCH "")
-if(USE_PCH AND CMAKE_COMPILER_IS_GNUCXX)
- string(REPLACE " " ";" PCH_CXXFLAGS "${CXXFLAGS} ${CMAKE_CXX_FLAGS}")
-
- file(GLOB PCH_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
- sort_list(PCH_SOURCES)
-
- foreach(PCH_SOURCE ${PCH_SOURCES})
- find_includes(${PCH_SOURCE} INCLUDES)
- set(INCLUDES_LIST)
- append_to_list(INCLUDES_LIST ${PCH_SOURCE})
- foreach(INCLUDE ${INCLUDES})
- # Extract the filename from the #include line
- extract_include_filename(${INCLUDE} FILENAME QUOTE_TYPE)
- if(QUOTE_TYPE STREQUAL "quotes")
- find_in_list(PCH_SOURCES "${FILENAME}" FOUND)
- if(NOT FOUND EQUAL -1)
- append_to_list(INCLUDES_LIST ${FILENAME})
- endif(NOT FOUND EQUAL -1)
- endif(QUOTE_TYPE STREQUAL "quotes")
- endforeach(INCLUDE)
-
- set(PCH_EXTRAFLAGS "")
- if(DEBUG_BUILD)
- set(PCH_EXTRAFLAGS "-g")
- endif(DEBUG_BUILD)
- if(PCH_SOURCE STREQUAL "module.h")
- set(PCH_EXTRAFLAGS ${PCH_EXTRAFLAGS} -fPIC)
- endif(PCH_SOURCE STREQUAL "module.h")
- if(GETTEXT_INCLUDE)
- set(PCH_GETTEXT_INCLUDE "-I${GETTEXT_INCLUDE}")
- endif(GETTEXT_INCLUDE)
-
- set(PCH_SOURCES_GCH "${PCH_SOURCES_GCH};${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch")
- add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch
- COMMAND ${CMAKE_CXX_COMPILER} ARGS ${PCH_CXXFLAGS} ${PCH_EXTRAFLAGS}
- ${PCH_GETTEXT_INCLUDE} -I${CMAKE_CURRENT_BINARY_DIR} -I${Anope_SOURCE_DIR}/modules/pseudoclients ${CMAKE_CURRENT_SOURCE_DIR}/${PCH_SOURCE} -o ${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch
- DEPENDS ${INCLUDES_LIST} VERBATIM
- )
- endforeach(PCH_SOURCE ${PCH_SOURCES})
-endif(USE_PCH AND CMAKE_COMPILER_IS_GNUCXX)
+endif()
# Add a custom target to the above file
-add_custom_target(headers DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version.h ${CMAKE_CURRENT_BINARY_DIR}/build.h ${PCH_SOURCES_GCH})
+add_custom_target(headers DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version.h ${CMAKE_CURRENT_BINARY_DIR}/build.h)
diff --git a/include/access.h b/include/access.h
index 6b9a2ec63..ad420d785 100644
--- a/include/access.h
+++ b/include/access.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef ACCESS_H
-#define ACCESS_H
+#pragma once
#include "services.h"
#include "anope.h"
@@ -28,7 +27,7 @@ enum
* backing each ChanAccess determines whether that ChanAccess has a given
* privilege.
*/
-struct CoreExport Privilege
+struct CoreExport Privilege final
{
Anope::string name;
Anope::string desc;
@@ -39,10 +38,10 @@ struct CoreExport Privilege
bool operator==(const Privilege &other) const;
};
-class CoreExport PrivilegeManager
+class CoreExport PrivilegeManager final
{
static std::vector<Privilege> Privileges;
- public:
+public:
static void AddPrivilege(Privilege p);
static void RemovePrivilege(Privilege &p);
static Privilege *FindPrivilege(const Anope::string &name);
@@ -53,9 +52,10 @@ class CoreExport PrivilegeManager
/* A provider of access. Only used for creating ChanAccesses, as
* they contain pure virtual functions.
*/
-class CoreExport AccessProvider : public Service
+class CoreExport AccessProvider
+ : public Service
{
- public:
+public:
AccessProvider(Module *owner, const Anope::string &name);
virtual ~AccessProvider();
@@ -64,20 +64,21 @@ class CoreExport AccessProvider : public Service
*/
virtual ChanAccess *Create() = 0;
- private:
+private:
static std::list<AccessProvider *> Providers;
- public:
+public:
static const std::list<AccessProvider *>& GetProviders();
};
/* Represents one entry of an access list on a channel. */
-class CoreExport ChanAccess : public Serializable
+class CoreExport ChanAccess
+ : public Serializable
{
Anope::string mask;
/* account this access entry is for, if any */
Serialize::Reference<NickCore> nc;
- public:
+public:
typedef std::vector<ChanAccess *> Path;
/* The provider that created this access entry */
@@ -85,6 +86,7 @@ class CoreExport ChanAccess : public Serializable
/* Channel this access entry is on */
Serialize::Reference<ChannelInfo> ci;
Anope::string creator;
+ Anope::string description;
time_t last_seen;
time_t created;
@@ -95,8 +97,8 @@ class CoreExport ChanAccess : public Serializable
const Anope::string &Mask() const;
NickCore *GetAccount() const;
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
static const unsigned int MAX_DEPTH = 4;
@@ -105,7 +107,7 @@ class CoreExport ChanAccess : public Serializable
* @param nc The account
* @param next Next channel to check if any
*/
- virtual bool Matches(const User *u, const NickCore *nc, ChannelInfo* &next) const;
+ virtual bool Matches(const User *u, const NickCore *nc, ChannelInfo *&next) const;
/** Check if this access entry has the given privilege.
* @param name The privilege name
@@ -133,9 +135,9 @@ class CoreExport ChanAccess : public Serializable
/* A group of access entries. This is used commonly, for example with ChannelInfo::AccessFor,
* to show what access a user has on a channel because users can match multiple access entries.
*/
-class CoreExport AccessGroup
+class CoreExport AccessGroup final
{
- public:
+public:
/* access entries + paths */
std::vector<ChanAccess::Path> paths;
/* Channel these access entries are on */
@@ -170,5 +172,3 @@ class CoreExport AccessGroup
inline bool empty() const { return paths.empty(); }
};
-
-#endif
diff --git a/include/account.h b/include/account.h
index d84a53dca..487a79b00 100644
--- a/include/account.h
+++ b/include/account.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef ACCOUNT_H
-#define ACCOUNT_H
+#pragma once
#include "extensible.h"
#include "serialize.h"
@@ -18,23 +17,25 @@
#include "memo.h"
#include "base.h"
-typedef Anope::hash_map<NickAlias *> nickalias_map;
-typedef Anope::hash_map<NickCore *> nickcore_map;
-typedef TR1NS::unordered_map<uint64_t, NickCore *> nickcoreid_map;
+typedef Anope::unordered_map<NickAlias *> nickalias_map;
+typedef Anope::unordered_map<NickCore *> nickcore_map;
+typedef std::unordered_map<uint64_t, NickCore *> nickcoreid_map;
extern CoreExport Serialize::Checker<nickalias_map> NickAliasList;
extern CoreExport Serialize::Checker<nickcore_map> NickCoreList;
-extern CoreExport nickcoreid_map NickCoreIdList;
+extern CoreExport Serialize::Checker<nickcoreid_map> NickCoreIdList;
/* A registered nickname.
* It matters that Base is here before Extensible (it is inherited by Serializable)
*/
-class CoreExport NickAlias : public Serializable, public Extensible
+class CoreExport NickAlias final
+ : public Serializable
+ , public Extensible
{
Anope::string vhost_ident, vhost_host, vhost_creator;
- time_t vhost_created;
+ time_t vhost_created = 0;
- public:
+public:
Anope::string nick;
Anope::string last_quit;
Anope::string last_realname;
@@ -42,8 +43,9 @@ class CoreExport NickAlias : public Serializable, public Extensible
Anope::string last_usermask;
/* Last uncloaked usermask, requires nickserv/auspex to see */
Anope::string last_realhost;
- time_t time_registered;
- time_t last_seen;
+ time_t time_registered = Anope::CurTime;
+ time_t last_seen = Anope::CurTime;
+
/* Account this nick is tied to. Multiple nicks can be tied to a single account. */
Serialize::Reference<NickCore> nc;
@@ -54,8 +56,8 @@ class CoreExport NickAlias : public Serializable, public Extensible
NickAlias(const Anope::string &nickname, NickCore *nickcore);
~NickAlias();
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
/** Set a vhost for the user
* @param ident The ident
@@ -63,36 +65,41 @@ class CoreExport NickAlias : public Serializable, public Extensible
* @param creator Who created the vhost
* @param time When the vhost was created
*/
- void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime);
+ void SetVHost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime);
/** Remove a users vhost
**/
- void RemoveVhost();
+ void RemoveVHost();
/** Check if the user has a vhost
* @return true or false
*/
- bool HasVhost() const;
+ bool HasVHost() const;
/** Retrieve the vhost ident
* @return the ident
*/
- const Anope::string &GetVhostIdent() const;
+ const Anope::string &GetVHostIdent() const;
/** Retrieve the vhost host
* @return the host
*/
- const Anope::string &GetVhostHost() const;
+ const Anope::string &GetVHostHost() const;
+
+ /** Retrieve the vhost mask
+ * @param the mask
+ */
+ Anope::string GetVHostMask() const;
/** Retrieve the vhost creator
* @return the creator
*/
- const Anope::string &GetVhostCreator() const;
+ const Anope::string &GetVHostCreator() const;
/** Retrieve when the vhost was created
* @return the time it was created
*/
- time_t GetVhostCreated() const;
+ time_t GetVHostCreated() const;
/** Finds a registered nick
* @param nick The nick to lookup
@@ -105,13 +112,15 @@ class CoreExport NickAlias : public Serializable, public Extensible
* account's display.
* It matters that Base is here before Extensible (it is inherited by Serializable)
*/
-class CoreExport NickCore : public Serializable, public Extensible
+class CoreExport NickCore final
+ : public Serializable
+ , public Extensible
{
/* Channels which reference this core in some way (this is on their access list, akick list, is founder, successor, etc) */
Serialize::Checker<std::map<ChannelInfo *, int> > chanaccess;
/* Unique identifier for the account. */
uint64_t id;
- public:
+public:
/* Name of the account. Find(display)->nc == this. */
Anope::string display;
/* User password in form of hashm:data */
@@ -119,9 +128,10 @@ class CoreExport NickCore : public Serializable, public Extensible
Anope::string email;
/* Locale name of the language of the user. Empty means default language */
Anope::string language;
- /* Access list, contains user@host masks of users who get certain privileges based
- * on if NI_SECURE is set and what (if any) kill protection is enabled. */
- std::vector<Anope::string> access;
+ /* Last time an email was sent to this user */
+ time_t lastmail = 0;
+ /* The time this account was registered */
+ time_t time_registered = Anope::CurTime;
MemoInfo memos;
std::map<Anope::string, Anope::string> last_modes;
@@ -131,14 +141,14 @@ class CoreExport NickCore : public Serializable, public Extensible
Serialize::Checker<std::vector<NickAlias *> > aliases;
/* Set if this user is a services operator. o->ot must exist. */
- Oper *o;
+ Oper *o = nullptr;
/* Unsaved data */
+ /** The display nick for this account. */
+ NickAlias *na = nullptr;
/* Number of channels registered by this account */
- uint16_t channelcount;
- /* Last time an email was sent to this user */
- time_t lastmail;
+ uint16_t channelcount = 0;
/* Users online now logged into this account */
std::list<User *> users;
@@ -149,79 +159,27 @@ class CoreExport NickCore : public Serializable, public Extensible
NickCore(const Anope::string &nickdisplay, uint64_t nickid = 0);
~NickCore();
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
/** Changes the display for this account
* @param na The new display, must be grouped to this account.
*/
- void SetDisplay(const NickAlias *na);
+ void SetDisplay(NickAlias *na);
/** Checks whether this account is a services oper or not.
* @return True if this account is a services oper, false otherwise.
*/
virtual bool IsServicesOper() const;
- /** Add an entry to the nick's access list
- *
- * @param entry The nick!ident@host entry to add to the access list
- *
- * Adds a new entry into the access list.
- */
- void AddAccess(const Anope::string &entry);
-
- /** Get an entry from the nick's access list by index
- *
- * @param entry Index in the access list vector to retrieve
- * @return The access list entry of the given index if within bounds, an empty string if the vector is empty or the index is out of bounds
- *
- * Retrieves an entry from the access list corresponding to the given index.
- */
- Anope::string GetAccess(unsigned entry) const;
-
- /** Get the number of entries on the access list for this account.
- */
- unsigned GetAccessCount() const;
-
/** Retrieves the account id for this user */
uint64_t GetId();
- /** Find an entry in the nick's access list
- *
- * @param entry The nick!ident@host entry to search for
- * @return True if the entry is found in the access list, false otherwise
- *
- * Search for an entry within the access list.
- */
- bool FindAccess(const Anope::string &entry);
-
- /** Erase an entry from the nick's access list
- *
- * @param entry The nick!ident@host entry to remove
- *
- * Removes the specified access list entry from the access list.
- */
- void EraseAccess(const Anope::string &entry);
-
- /** Clears the entire nick's access list
- *
- * Deletes all the memory allocated in the access list vector and then clears the vector.
- */
- void ClearAccess();
-
- /** Is the given user on this accounts access list?
- *
- * @param u The user
- *
- * @return true if the user is on the access list
- */
- bool IsOnAccess(const User *u) const;
-
/** Finds an account
* @param nick The account name to find
* @return The account, if it exists
*/
- static NickCore* Find(const Anope::string &nick);
+ static NickCore *Find(const Anope::string &nick);
void AddChannelReference(ChannelInfo *ci);
void RemoveChannelReference(ChannelInfo *ci);
@@ -240,16 +198,16 @@ class CoreExport IdentifyRequest
Anope::string password;
std::set<Module *> holds;
- bool dispatched;
- bool success;
+ bool dispatched = false;
+ bool success = false;
static std::set<IdentifyRequest *> Requests;
- protected:
+protected:
IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass);
virtual ~IdentifyRequest();
- public:
+public:
/* One of these is called when the request goes through */
virtual void OnSuccess() = 0;
virtual void OnFail() = 0;
@@ -286,5 +244,3 @@ class CoreExport IdentifyRequest
static void ModuleUnload(Module *m);
};
-
-#endif // ACCOUNT_H
diff --git a/include/anope.h b/include/anope.h
index 4f599763d..1a9cdd0dd 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef ANOPE_H
-#define ANOPE_H
+#pragma once
#include <signal.h>
@@ -23,15 +22,15 @@ namespace Anope
* allow us to only require one type of string everywhere that can be converted
* at any time to a specific type of string.
*/
- class CoreExport string
+ class CoreExport string final
{
- private:
+ private:
/**
* The actual string is stored in an std::string as it can be converted to
* ci::string, or a C-style string at any time.
*/
std::string _string;
- public:
+ public:
/**
* Extras.
*/
@@ -40,6 +39,7 @@ namespace Anope
typedef std::string::reverse_iterator reverse_iterator;
typedef std::string::const_reverse_iterator const_reverse_iterator;
typedef std::string::size_type size_type;
+ typedef std::string::value_type value_type;
static const size_type npos = static_cast<size_type>(-1);
/**
@@ -54,9 +54,7 @@ namespace Anope
string(const ci::string &_str) : _string(_str.c_str()) { }
string(const string &_str, size_type pos, size_type n = npos) : _string(_str._string, pos, n) { }
template <class InputIterator> string(InputIterator first, InputIterator last) : _string(first, last) { }
-#if __cplusplus >= 201103L
string(const string &) = default;
-#endif
/**
* Assignment operators, so any type of string can be assigned to this class.
@@ -143,8 +141,8 @@ namespace Anope
*/
inline void push_back(char c) { return this->_string.push_back(c); }
- inline string& append(const string &s) { this->_string.append(s.str()); return *this; }
- inline string& append(const char *s, size_t n) { this->_string.append(s, n); return *this; }
+ inline string &append(const string &s) { this->_string.append(s.str()); return *this; }
+ inline string &append(const char *s, size_t n) { this->_string.append(s, n); return *this; }
/**
* Resizes the string content to n characters.
@@ -162,21 +160,21 @@ namespace Anope
* Trim leading and trailing white spaces from the string.
*/
- inline string& ltrim(const Anope::string &what = " \t\r\n")
+ inline string &ltrim(const Anope::string &what = " \t\r\n")
{
while (!this->_string.empty() && what.find(this->_string[0]) != Anope::string::npos)
this->_string.erase(this->_string.begin());
return *this;
}
- inline string& rtrim(const Anope::string &what = " \t\r\n")
+ inline string &rtrim(const Anope::string &what = " \t\r\n")
{
while (!this->_string.empty() && what.find(this->_string[this->_string.length() - 1]) != Anope::string::npos)
this->_string.erase(this->_string.length() - 1);
return *this;
}
- inline string& trim(const Anope::string &what = " \t\r\n")
+ inline string &trim(const Anope::string &what = " \t\r\n")
{
this->ltrim(what);
this->rtrim(what);
@@ -213,6 +211,10 @@ namespace Anope
inline size_type find_last_not_of(const string &_str, size_type pos = npos) const { return this->_string.find_last_not_of(_str._string, pos); }
inline size_type find_last_not_of_ci(const string &_str, size_type pos = npos) const { return ci::string(this->_string.c_str()).find_last_not_of(ci::string(_str._string.c_str()), pos); }
+ inline int compare(size_t pos, size_t len, const string &str) const { return ci::string(this->_string.c_str()).compare(pos, len, ci::string(str.c_str())); }
+ inline int compare(size_t pos, size_t len, const string &str, size_t subpos, size_type sublen = npos) const { return ci::string(this->_string.c_str()).compare(pos, len, ci::string(str.c_str()), subpos, sublen); }
+ inline int compare(size_t pos, size_t len, const char *s, size_type n = npos) const { return ci::string(this->_string.c_str()).compare(pos, len, s, n); }
+
/**
* Determine if string consists of only numbers.
*/
@@ -257,8 +259,8 @@ namespace Anope
inline string lower() const
{
Anope::string new_string = *this;
- for (size_type i = 0; i < new_string.length(); ++i)
- new_string[i] = Anope::tolower(new_string[i]);
+ for (auto &chr : new_string)
+ chr = Anope::tolower(chr);
return new_string;
}
@@ -268,8 +270,8 @@ namespace Anope
inline string upper() const
{
Anope::string new_string = *this;
- for (size_type i = 0; i < new_string.length(); ++i)
- new_string[i] = Anope::toupper(new_string[i]);
+ for (auto &chr : new_string)
+ chr = Anope::toupper(chr);
return new_string;
}
@@ -311,23 +313,23 @@ namespace Anope
inline const string operator+(const char *_str, const string &str) { string tmp(_str); tmp += str; return tmp; }
inline const string operator+(const std::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; }
- struct hash_ci
+ struct hash_ci final
{
inline size_t operator()(const string &s) const
{
- return TR1NS::hash<std::string>()(s.lower().str());
+ return std::hash<std::string>()(s.lower().str());
}
};
- struct hash_cs
+ struct hash_cs final
{
inline size_t operator()(const string &s) const
{
- return TR1NS::hash<std::string>()(s.str());
+ return std::hash<std::string>()(s.str());
}
};
- struct compare
+ struct compare final
{
inline bool operator()(const string &s1, const string &s2) const
{
@@ -335,9 +337,14 @@ namespace Anope
}
};
- template<typename T> class map : public std::map<string, T, ci::less> { };
- template<typename T> class multimap : public std::multimap<string, T, ci::less> { };
- template<typename T> class hash_map : public TR1NS::unordered_map<string, T, hash_ci, compare> { };
+ template<typename T>
+ using map = std::map<string, T, ci::less>;
+
+ template<typename T>
+ using multimap = std::multimap<string, T, ci::less>;
+
+ template<typename T>
+ using unordered_map = std::unordered_map<string, T, hash_ci, compare>;
#ifndef REPRODUCIBLE_BUILD
static const char *const compiled = __TIME__ " " __DATE__;
@@ -360,6 +367,7 @@ namespace Anope
* Use this unless you need very specific time checks
*/
extern CoreExport time_t CurTime;
+ extern CoreExport long long CurTimeNs;
/** The debug level we are running at.
*/
@@ -367,13 +375,13 @@ namespace Anope
/** Other command line options.
*/
- extern CoreExport bool ReadOnly, NoFork, NoThird, NoExpire, ProtocolDebug;
+ extern CoreExport bool ReadOnly, NoFork, NoThird, NoPID, NoExpire, ProtocolDebug;
- /** The root of the services installation. Usually ~/services
+ /** The root of the Anope installation. Usually ~/anope
*/
extern CoreExport Anope::string ServicesDir;
- /** Services binary name (eg services)
+ /** Anope binary name (eg anope)
*/
extern CoreExport Anope::string ServicesBin;
@@ -387,7 +395,7 @@ namespace Anope
/** The uplink we are currently connected to
*/
- extern CoreExport int CurrentUplink;
+ extern CoreExport size_t CurrentUplink;
/** Various methods to determine the Anope version running
*/
@@ -419,7 +427,7 @@ namespace Anope
* initializing language support, loading modules, and loading databases.
* @throws CoreException if something bad went wrong
*/
- extern void Init(int ac, char **av);
+ extern bool Init(int ac, char **av);
/** Calls the save database event
*/
@@ -463,22 +471,7 @@ namespace Anope
* @param src The source string to encrypt
* @param dest The destination where the encrypted string is placed
*/
- extern CoreExport void Encrypt(const Anope::string &src, Anope::string &dest);
-
- /** Decrypts what is in 'src' to 'dest'.
- * @param src The source string to decrypt
- * @param dest The destination where the decrypted string is placed
- * @return true if decryption was successful. This is usually not the case
- * as most encryption methods we use are one way.
- */
- extern CoreExport bool Decrypt(const Anope::string &src, Anope::string &dest);
-
- /** Hashes a buffer with SipHash-2-4
- * @param src The start of the buffer to hash
- * @param src_sz The total number of bytes in the buffer
- * @param key A 16 byte key to hash the buffer with.
- */
- extern CoreExport uint64_t SipHash24(const void *src, unsigned long src_sz, const char key[16]);
+ extern CoreExport bool Encrypt(const Anope::string &src, Anope::string &dest);
/** Returns a sequence of data formatted as the format argument specifies.
** After the format parameter, the function expects at least as many
@@ -487,7 +480,7 @@ namespace Anope
* @param ... any number of parameters
* @return a Anope::string
*/
- extern CoreExport string printf(const char *fmt, ...);
+ extern CoreExport string printf(const char *fmt, ...) ATTR_FORMAT(1, 2);
/** Return the last error code
* @return The error code
@@ -497,7 +490,7 @@ namespace Anope
/** Return the last error, uses errno/GetLastError() to determine this
* @return An error message
*/
- extern CoreExport const string LastError();
+ extern CoreExport string LastError();
/** Determines if a path is a file
*/
@@ -536,10 +529,18 @@ namespace Anope
*/
extern CoreExport Anope::string NormalizeBuffer(const Anope::string &);
- /** Main processing routine. Parses the message and takes the appropriate action.
- * @param Raw message from the uplink
+ /** Parses a raw message from the uplink and calls its command handler.
+ * @param message Raw message from the uplink
+ */
+ extern void Process(const Anope::string &message);
+
+ /** Calls the command handler for an already parsed message.
+ * @param source Source of the message.
+ * @param command Command name.
+ * @param params Any extra parameters.
+ * @param tags IRCv3 message tags.
*/
- extern void Process(const Anope::string &);
+ extern CoreExport void ProcessInternal(MessageSource &src, const Anope::string &command, const std::vector<Anope::string> &params, const Anope::map<Anope::string> & tags);
/** Does a blocking dns query and returns the first IP.
* @param host host to look up
@@ -559,6 +560,54 @@ namespace Anope
* @param len The length of the string returned
*/
extern CoreExport Anope::string Random(size_t len);
+
+ /** Generate a random number. */
+ extern CoreExport int RandomNumber();
+
+ /** Calculates the levenshtein distance between two strings.
+ * @param s1 The first string.
+ * @param s2 The second string.
+ */
+ extern CoreExport size_t Distance(const Anope::string &s1, const Anope::string &s2);
+
+ /** Update the current time. */
+ extern CoreExport void UpdateTime();
+
+ /** Expands a path fragment that is relative to the base directory.
+ * @param base The base directory that it is relative to.
+ * @param fragment The fragment to expand.
+ */
+ extern CoreExport Anope::string Expand(const Anope::string &base, const Anope::string &fragment);
+
+ /** Expands a config path. */
+ inline auto ExpandConfig(const Anope::string &path) { return Expand(ConfigDir, path); }
+
+ /** Expands a data path. */
+ inline auto ExpandData(const Anope::string &path) { return Expand(DataDir, path); }
+
+ /** Expands a locale path. */
+ inline auto ExpandLocale(const Anope::string &path) { return Expand(LocaleDir, path); }
+
+ /** Expands a log path. */
+ inline auto ExpandLog(const Anope::string &path) { return Expand(LogDir, path); }
+
+ /** Expands a module path. */
+ inline auto ExpandModule(const Anope::string &path) { return Expand(ModuleDir, path); }
+
+ /** Formats a CTCP message for sending to a client.
+ * @param name The name of the CTCP.
+ * @param body If present then the body of the CTCP.
+ * @return A formatted CTCP ready to send to a client.
+ */
+ extern CoreExport Anope::string FormatCTCP(const Anope::string &name, const Anope::string &body = "");
+
+ /** Parses a CTCP message received from a client.
+ * @param text The raw message to parse.
+ * @param name The location to store the name of the CTCP.
+ * @param body The location to store body of the CTCP if one is present.
+ * @return True if the message was a well formed CTCP; otherwise, false.
+ */
+ extern CoreExport bool ParseCTCP(const Anope::string &text, Anope::string &name, Anope::string &body);
}
/** sepstream allows for splitting token separated lists.
@@ -568,7 +617,7 @@ namespace Anope
*/
class CoreExport sepstream
{
- private:
+private:
/** Original string.
*/
Anope::string tokens;
@@ -577,15 +626,18 @@ class CoreExport sepstream
char sep;
/** Current string position
*/
- size_t pos;
+ size_t pos = 0;
/** If set then GetToken() can return an empty string
*/
bool allow_empty;
- public:
+public:
/** Create a sepstream and fill it with the provided data
*/
sepstream(const Anope::string &source, char separator, bool allowempty = false);
+ /** Retrieves the underlying string. */
+ const auto &GetString() const { return tokens; }
+
/** Fetch the next token from the stream
* @param token The next token from the stream is placed here
* @return True if tokens still remain, false if there are none left
@@ -602,7 +654,7 @@ class CoreExport sepstream
/** Gets every token from this stream
* @param token Tokens are pushed back here
*/
- template<typename T> void GetTokens(T& token)
+ template<typename T> void GetTokens(T &token)
{
token.clear();
Anope::string t;
@@ -625,7 +677,7 @@ class CoreExport sepstream
/** Fetch the entire remaining stream, without tokenizing
* @return The remaining part of the stream
*/
- const Anope::string GetRemaining();
+ Anope::string GetRemaining();
/** Returns true if the end of the stream has been reached
* @return True if the end of the stream has been reached, otherwise false
@@ -635,9 +687,10 @@ class CoreExport sepstream
/** A derived form of sepstream, which separates on commas
*/
-class commasepstream : public sepstream
+class commasepstream final
+ : public sepstream
{
- public:
+public:
/** Initialize with comma separator
*/
commasepstream(const Anope::string &source, bool allowempty = false) : sepstream(source, ',', allowempty) { }
@@ -645,9 +698,10 @@ class commasepstream : public sepstream
/** A derived form of sepstream, which separates on spaces
*/
-class spacesepstream : public sepstream
+class spacesepstream final
+ : public sepstream
{
- public:
+public:
/** Initialize with space separator
*/
spacesepstream(const Anope::string &source) : sepstream(source, ' ') { }
@@ -659,19 +713,17 @@ class spacesepstream : public sepstream
* be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
* attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
*/
-class CoreException : public std::exception
+class CoreExport CoreException
+ : public std::exception
{
- protected:
+protected:
/** Holds the error message to be displayed
*/
Anope::string err;
/** Source of the exception
*/
Anope::string source;
- public:
- /** Default constructor, just uses the error message 'Core threw an exception'.
- */
- CoreException() : err("Core threw an exception"), source("The core") { }
+public:
/** This constructor can be used to specify an error message before throwing.
*/
CoreException(const Anope::string &message) : err(message), source("The core") { }
@@ -683,7 +735,7 @@ class CoreException : public std::exception
* Actually no, it does nothing. Never mind.
* @throws Nothing!
*/
- virtual ~CoreException() throw() { }
+ virtual ~CoreException() noexcept = default;
/** Returns the reason for the exception.
* The module should probably put something informative here as the user will see this upon failure.
*/
@@ -698,13 +750,10 @@ class CoreException : public std::exception
}
};
-class ModuleException : public CoreException
+class CoreExport ModuleException
+ : public CoreException
{
- public:
- /** Default constructor, just uses the error message 'Module threw an exception'.
- */
- ModuleException() : CoreException("Module threw an exception", "A Module") { }
-
+public:
/** This constructor can be used to specify an error message before throwing.
*/
ModuleException(const Anope::string &message) : CoreException(message, "A Module") { }
@@ -712,69 +761,9 @@ class ModuleException : public CoreException
* Actually no, it does nothing. Never mind.
* @throws Nothing!
*/
- virtual ~ModuleException() throw() { }
+ virtual ~ModuleException() noexcept = default;
};
-class ConvertException : public CoreException
-{
- public:
- ConvertException(const Anope::string &reason = "") : CoreException(reason) { }
-
- virtual ~ConvertException() throw() { }
-};
-
-/** Convert something to a string
- */
-template<typename T> inline Anope::string stringify(const T &x)
-{
- std::ostringstream stream;
-
- if (!(stream << x))
- throw ConvertException("Stringify fail");
-
- return stream.str();
-}
-
-template<typename T> inline void convert(const Anope::string &s, T &x, Anope::string &leftover, bool failIfLeftoverChars = true)
-{
- leftover.clear();
- std::istringstream i(s.str());
- char c;
- if (!(i >> x))
- throw ConvertException("Convert fail");
- if (failIfLeftoverChars)
- {
- if (i.get(c))
- throw ConvertException("Convert fail");
- }
- else
- {
- std::string left;
- getline(i, left);
- leftover = left;
- }
-}
-
-template<typename T> inline void convert(const Anope::string &s, T &x, bool failIfLeftoverChars = true)
-{
- Anope::string Unused;
- convert(s, x, Unused, failIfLeftoverChars);
-}
-
-template<typename T> inline T convertTo(const Anope::string &s, Anope::string &leftover, bool failIfLeftoverChars = true)
-{
- T x;
- convert(s, x, leftover, failIfLeftoverChars);
- return x;
-}
-
-template<typename T> inline T convertTo(const Anope::string &s, bool failIfLeftoverChars = true)
-{
- T x;
- convert(s, x, failIfLeftoverChars);
- return x;
-}
-
/** Casts to be used instead of dynamic_cast, this uses dynamic_cast
* for debug builds and static_cast on release builds
* to speed up the program because dynamic_cast relies on RTTI.
@@ -795,4 +784,4 @@ template<typename T, typename O> inline T anope_dynamic_static_cast(O ptr)
}
#endif
-#endif // ANOPE_H
+#include "convert.h"
diff --git a/include/base.h b/include/base.h
index 20a48e225..cfac283f5 100644
--- a/include/base.h
+++ b/include/base.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef BASE_H
-#define BASE_H
+#pragma once
#include "services.h"
@@ -16,9 +15,8 @@
class CoreExport Base
{
/* References to this base class */
- std::set<ReferenceBase *> *references;
- public:
- Base();
+ std::set<ReferenceBase *> *references = nullptr;
+public:
virtual ~Base();
/** Adds a reference to this object. Eg, when a Reference
@@ -32,12 +30,12 @@ class CoreExport Base
class ReferenceBase
{
- protected:
- bool invalid;
- public:
- ReferenceBase() : invalid(false) { }
+protected:
+ bool invalid = false;
+public:
+ ReferenceBase() = default;
ReferenceBase(const ReferenceBase &other) : invalid(other.invalid) { }
- virtual ~ReferenceBase() { }
+ virtual ~ReferenceBase() = default;
inline void Invalidate() { this->invalid = true; }
};
@@ -45,14 +43,13 @@ class ReferenceBase
* no longer be valid once the object it refers is destructed.
*/
template<typename T>
-class Reference : public ReferenceBase
+class Reference
+ : public ReferenceBase
{
- protected:
- T *ref;
- public:
- Reference() : ref(NULL)
- {
- }
+protected:
+ T *ref = nullptr;
+public:
+ Reference() = default;
Reference(T *obj) : ref(obj)
{
@@ -106,14 +103,14 @@ class Reference : public ReferenceBase
return NULL;
}
- inline T* operator->()
+ inline T *operator->()
{
if (operator bool())
return this->ref;
return NULL;
}
- inline T* operator*()
+ inline T *operator*()
{
if (operator bool())
return this->ref;
@@ -139,5 +136,3 @@ class Reference : public ReferenceBase
return false;
}
};
-
-#endif // BASE_H
diff --git a/include/bots.h b/include/bots.h
index e0f8f60dd..5a9c54a3e 100644
--- a/include/bots.h
+++ b/include/bots.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef BOTS_H
-#define BOTS_H
+#pragma once
#include "users.h"
#include "anope.h"
@@ -20,16 +19,20 @@ typedef Anope::map<BotInfo *> botinfo_map;
extern CoreExport Serialize::Checker<botinfo_map> BotListByNick, BotListByUID;
/* A service bot (NickServ, ChanServ, a BotServ bot, etc). */
-class CoreExport BotInfo : public User, public Serializable
+class CoreExport BotInfo final
+ : public User
+ , public Serializable
{
/* Channels this bot is assigned to */
Serialize::Checker<std::set<ChannelInfo *> > channels;
- public:
+public:
time_t created;
/* Last time this bot said something (via privmsg) */
time_t lastmsg;
/* Map of actual command names -> service name/permission required */
CommandInfo::map commands;
+ /* The server-side alias used to message this bot. */
+ Anope::string alias;
/* Modes the bot should have as configured in service:modes */
Anope::string botmodes;
/* Channels the bot should be in as configured in service:channels */
@@ -55,7 +58,7 @@ class CoreExport BotInfo : public User, public Serializable
virtual ~BotInfo();
void Serialize(Serialize::Data &data) const;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
void GenerateUID();
@@ -107,8 +110,9 @@ class CoreExport BotInfo : public User, public Serializable
/** Called when a user messages this bot
* @param u The user
* @param message The users' message
+ * @params tags Message tags
*/
- virtual void OnMessage(User *u, const Anope::string &message);
+ virtual void OnMessage(User *u, const Anope::string &message, const Anope::map<Anope::string> &tags);
/** Link a command name to a command in services
* @param cname The command name
@@ -116,7 +120,7 @@ class CoreExport BotInfo : public User, public Serializable
* @param permission Permission required to execute the command, if any
* @return The commandinfo for the newly created command
*/
- CommandInfo& SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission = "");
+ CommandInfo &SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission = "");
/** Get command info for a command
* @param cname The command name
@@ -124,12 +128,13 @@ class CoreExport BotInfo : public User, public Serializable
*/
CommandInfo *GetCommand(const Anope::string &cname);
+ /** Get the command that users can use to send a message to this bot. */
+ Anope::string GetQueryCommand() const;
+
/** Find a bot by nick
* @param nick The nick
* @param nick_only True to only look by nick, and not by UID
* @return The bot, if it exists
*/
- static BotInfo* Find(const Anope::string &nick, bool nick_only = false);
+ static BotInfo *Find(const Anope::string &nick, bool nick_only = false);
};
-
-#endif // BOTS_H
diff --git a/include/channels.h b/include/channels.h
index 6cb612103..8bea70fc9 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -6,20 +6,20 @@
* Please read COPYING and README for further details.
*/
-#ifndef CHANNELS_H
-#define CHANNELS_H
+#pragma once
#include "anope.h"
#include "extensible.h"
#include "modes.h"
#include "serialize.h"
-typedef Anope::hash_map<Channel *> channel_map;
+typedef Anope::unordered_map<Channel *> channel_map;
extern CoreExport channel_map ChannelList;
/* A user container, there is one of these per user per channel. */
-struct ChanUserContainer : public Extensible
+struct ChanUserContainer final
+ : public Extensible
{
User *user;
Channel *chan;
@@ -29,18 +29,20 @@ struct ChanUserContainer : public Extensible
ChanUserContainer(User *u, Channel *c) : user(u), chan(c) { }
};
-class CoreExport Channel : public Base, public Extensible
+class CoreExport Channel final
+ : public Base
+ , public Extensible
{
static std::vector<Channel *> deleting;
- public:
+public:
typedef std::multimap<Anope::string, Anope::string> ModeList;
- private:
+private:
/** A map of channel modes with their parameters set on this channel
*/
ModeList modes;
- public:
+public:
/* Channel name */
Anope::string name;
/* Set if this channel is registered. ci->c == this. Contains information relevant to the registered channel */
@@ -74,14 +76,14 @@ class CoreExport Channel : public Base, public Extensible
int16_t chanserv_modecount; /* Number of check_mode()'s this sec */
int16_t bouncy_modes; /* Did we fail to set modes here? */
- private:
+private:
/** Constructor
* @param name The channel name
* @param ts The time the channel was created
*/
Channel(const Anope::string &nname, time_t ts = Anope::CurTime);
- public:
+public:
/** Destructor
*/
~Channel();
@@ -108,7 +110,7 @@ class CoreExport Channel : public Base, public Extensible
* @param status The status to give the user, if any
* @return The UserContainer for the user
*/
- ChanUserContainer* JoinUser(User *u, const ChannelStatus *status);
+ ChanUserContainer *JoinUser(User *u, const ChannelStatus *status);
/** Remove a user internally from the channel
* @param u The user
@@ -205,14 +207,15 @@ class CoreExport Channel : public Base, public Extensible
* @param enforce_mlock Should mlock be enforced on this mode change
* @param cmodes The modes to set
*/
- void SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...);
+ void SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...) ATTR_FORMAT(4, 5);
+ void SetModes(BotInfo *bi, bool enforce_mlock, const Anope::string &cmodes);
/** Set a string of modes internally on a channel
* @param source The setter
* @param mode the modes
* @param enforce_mlock true to enforce mlock
*/
- void SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts = 0, bool enforce_mlock = true);
+ void SetModesInternal(MessageSource &source, const Anope::string &modes, const std::vector<Anope::string> &params, time_t ts = 0, bool enforce_mlock = true);
/** Does the given user match the given list? (CMODE_BAN, CMODE_EXCEPT, etc, a list mode)
* @param u The user
@@ -234,7 +237,8 @@ class CoreExport Channel : public Base, public Extensible
* @param reason The reason for the kick
* @return true if the kick was successful, false if a module blocked the kick
*/
- bool Kick(BotInfo *bi, User *u, const char *reason = NULL, ...);
+ bool Kick(BotInfo *bi, User *u, const char *reason = NULL, ...) ATTR_FORMAT(4, 5);
+ bool Kick(BotInfo *bi, User *u, const Anope::string &reason);
/** Get all modes set on this channel, excluding status modes.
* @return a map of modes and their optional parameters.
@@ -298,7 +302,7 @@ class CoreExport Channel : public Base, public Extensible
* @param name The channel to find
* @return The channel, if found
*/
- static Channel* Find(const Anope::string &name);
+ static Channel *Find(const Anope::string &name);
/** Finds or creates a channel
* @param name The channel name
@@ -311,5 +315,3 @@ class CoreExport Channel : public Base, public Extensible
static void DeleteChannels();
};
-
-#endif // CHANNELS_H
diff --git a/include/commands.h b/include/commands.h
index c466e2b18..56ffa4c6f 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -9,25 +9,22 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef COMMAND_H
-#define COMMAND_H
+#pragma once
#include "service.h"
#include "anope.h"
#include "channels.h"
-struct CommandGroup
+struct CommandGroup final
{
Anope::string name, description;
};
/* Used in BotInfo::commands */
-struct CommandInfo
+struct CommandInfo final
{
typedef Anope::map<CommandInfo> map;
- CommandInfo() : hide(false), prepend_channel(false) { }
-
/* Service name of the command */
Anope::string name;
/* Permission required to execute the command */
@@ -35,9 +32,9 @@ struct CommandInfo
/* Group this command is in */
Anope::string group;
/* whether or not to hide this command in help output */
- bool hide;
+ bool hide = false;
/* Only used with fantasy */
- bool prepend_channel;
+ bool prepend_channel = false;
};
/* Where the replies from commands go to. User inherits from this and is the normal
@@ -45,18 +42,19 @@ struct CommandInfo
*/
struct CoreExport CommandReply
{
- virtual ~CommandReply() { }
+ virtual ~CommandReply() = default;
virtual void SendMessage(BotInfo *source, const Anope::string &msg) = 0;
+ virtual void SendMessage(CommandSource &source, const Anope::string &msg);
};
/* The source for a command */
-class CoreExport CommandSource
+class CoreExport CommandSource final
{
/* The nick executing the command */
Anope::string nick;
/* User executing the command, may be NULL */
Reference<User> u;
- public:
+public:
/* The account executing the command */
Reference<NickCore> nc;
/* for web clients */
@@ -64,15 +62,17 @@ class CoreExport CommandSource
/* Where the reply should go */
CommandReply *reply;
/* Channel the command was executed on (fantasy) */
- Reference<Channel> c;
+ Reference<Channel> c = nullptr;
/* The service this command is on */
Reference<BotInfo> service;
/* The actual name of the command being executed */
Anope::string command;
/* The permission of the command being executed */
Anope::string permission;
+ /* The unique identifier of the executing message. */
+ Anope::string msgid;
- CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply, BotInfo *bi);
+ CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply, BotInfo *bi, const Anope::string &m = "");
const Anope::string &GetNick() const;
User *GetUser();
@@ -80,7 +80,8 @@ class CoreExport CommandSource
AccessGroup AccessFor(ChannelInfo *ci);
bool IsFounder(ChannelInfo *ci);
- void Reply(const char *message, ...);
+ void Reply(const char *message, ...) ATTR_FORMAT(2, 3);
+ void Reply(int count, const char *singular, const char *plural, ...) ATTR_FORMAT(4, 5);
void Reply(const Anope::string &message);
bool HasCommand(const Anope::string &cmd);
@@ -91,7 +92,8 @@ class CoreExport CommandSource
/** Every services command is a class, inheriting from Command.
*/
-class CoreExport Command : public Service
+class CoreExport Command
+ : public Service
{
Anope::string desc;
std::vector<Anope::string> syntax;
@@ -100,7 +102,7 @@ class CoreExport Command : public Service
/* Command requires that a user is executing it */
bool require_user;
- public:
+public:
/* Maximum parameters accepted by this command */
size_t max_params;
/* Minimum parameters required to use this command */
@@ -109,7 +111,7 @@ class CoreExport Command : public Service
/* Module which owns us */
Module *module;
- protected:
+protected:
/** Create a new command.
* @param owner The owner of the command
* @param sname The command name
@@ -119,10 +121,10 @@ class CoreExport Command : public Service
*/
Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params = 0);
- public:
- virtual ~Command();
+public:
+ virtual ~Command() = default;
- protected:
+protected:
void SetDesc(const Anope::string &d);
void ClearSyntax();
@@ -132,7 +134,7 @@ class CoreExport Command : public Service
void AllowUnregistered(bool b);
void RequireUser(bool b);
- public:
+public:
bool AllowUnregistered() const;
bool RequireUser() const;
@@ -181,7 +183,5 @@ class CoreExport Command : public Service
* @param name If found, is set to the command name, eg REGISTER
* @return true if the given command service exists
*/
- static bool FindCommandFromService(const Anope::string &command_service, BotInfo* &bi, Anope::string &name);
+ static bool FindCommandFromService(const Anope::string &command_service, BotInfo *&bi, Anope::string &name);
};
-
-#endif // COMMANDS_H
diff --git a/include/config.h b/include/config.h
index d671bec0d..2f4f1b953 100644
--- a/include/config.h
+++ b/include/config.h
@@ -9,14 +9,12 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef CONFIG_H
-#define CONFIG_H
+#pragma once
#include "account.h"
#include "regchannel.h"
#include "users.h"
#include "opertype.h"
-#include <stack>
namespace Configuration
{
@@ -26,11 +24,11 @@ namespace Configuration
{
friend struct Configuration::Conf;
- public:
+ public:
typedef Anope::map<Anope::string> item_map;
typedef Anope::multimap<Block> block_map;
- private:
+ private:
Anope::string name;
item_map items;
block_map blocks;
@@ -39,37 +37,23 @@ namespace Configuration
/* Represents a missing tag. */
static Block EmptyBlock;
- public:
+ public:
Block(const Anope::string &);
const Anope::string &GetName() const;
int CountBlock(const Anope::string &name) const;
- const Block* GetBlock(const Anope::string &name, int num = 0) const;
- Block* GetMutableBlock(const Anope::string &name, int num = 0);
+ const Block *GetBlock(const Anope::string &name, int num = 0) const;
+ Block *GetMutableBlock(const Anope::string &name, int num = 0);
- template<typename T> inline T Get(const Anope::string &tag) const
+ template<typename T> T Get(const Anope::string &tag, const Anope::string &def = "") const
{
- return this->Get<T>(tag, "");
- }
- /* VS 2008 has an issue with having a default argument here (def = ""), which is why the above
- * function exists.
- */
- template<typename T> T Get(const Anope::string &tag, const Anope::string &def) const
- {
- const Anope::string &value = this->Get<const Anope::string>(tag, def);
- if (!value.empty())
- try
- {
- return convertTo<T>(value);
- }
- catch (const ConvertException &) { }
- return T();
+ return Anope::TryConvert<T>(this->Get<const Anope::string>(tag, def)).value_or(T());
}
bool Set(const Anope::string &tag, const Anope::string &value);
- const item_map* GetItems() const;
+ const item_map &GetItems() const;
};
- template<> CoreExport const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const;
+ template<> CoreExport const Anope::string Block::Get(const Anope::string &tag, const Anope::string &def) const;
template<> CoreExport time_t Block::Get(const Anope::string &tag, const Anope::string &def) const;
template<> CoreExport bool Block::Get(const Anope::string &tag, const Anope::string &def) const;
} // namespace Internal
@@ -79,12 +63,12 @@ namespace Configuration
/** Represents a configuration file
*/
- class File
+ class File final
{
Anope::string name;
bool executable;
- FILE *fp;
- public:
+ FILE *fp = nullptr;
+ public:
File(const Anope::string &, bool);
~File();
const Anope::string &GetName() const;
@@ -99,25 +83,22 @@ namespace Configuration
struct Uplink;
- struct CoreExport Conf : Block
+ struct CoreExport Conf final
+ : Block
{
/* options:readtimeout */
time_t ReadTimeout;
- /* options:useprivmsg */
- bool UsePrivmsg;
/* If we should default to privmsging clients */
bool DefPrivmsg;
/* Default language */
Anope::string DefLanguage;
/* options:timeoutcheck */
time_t TimeoutCheck;
- /* options:usestrictprivmsg */
- bool UseStrictPrivmsg;
+ /* options:servicealias */
+ bool ServiceAlias;
/* networkinfo:nickchars */
Anope::string NickChars;
- /* either "/msg " or "/" */
- Anope::string StrictPrivmsg;
/* List of uplink servers to try and connect to */
std::vector<Uplink> Uplinks;
/* A vector of our logfile options */
@@ -145,7 +126,7 @@ namespace Configuration
void LoadConf(File &file);
void Post(Conf *old);
- Block *GetModule(Module *);
+ Block *GetModule(const Module *);
Block *GetModule(const Anope::string &name);
BotInfo *GetClient(const Anope::string &name);
@@ -153,15 +134,15 @@ namespace Configuration
const Block *GetCommand(CommandSource &);
};
- struct Uplink
+ struct Uplink final
{
Anope::string host;
unsigned port;
Anope::string password;
- bool ipv6;
+ int protocol;
- Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { }
- inline bool operator==(const Uplink &other) const { return host == other.host && port == other.port && password == other.password && ipv6 == other.ipv6; }
+ Uplink(const Anope::string &_host, int _port, const Anope::string &_password, int _protocol) : host(_host), port(_port), password(_password), protocol(_protocol) { }
+ inline bool operator==(const Uplink &other) const { return host == other.host && port == other.port && password == other.password && protocol == other.protocol; }
inline bool operator!=(const Uplink &other) const { return !(*this == other); }
};
}
@@ -172,9 +153,10 @@ namespace Configuration
* be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
* attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
*/
-class ConfigException : public CoreException
+class CoreExport ConfigException final
+ : public CoreException
{
- public:
+public:
/** Default constructor, just uses the error message 'Config threw an exception'.
*/
ConfigException() : CoreException("Config threw an exception", "Config Parser") { }
@@ -185,10 +167,8 @@ class ConfigException : public CoreException
* Actually no, it does nothing. Never mind.
* @throws Nothing!
*/
- virtual ~ConfigException() throw() { }
+ virtual ~ConfigException() noexcept = default;
};
extern Configuration::File ServicesConf;
extern CoreExport Configuration::Conf *Config;
-
-#endif // CONFIG_H
diff --git a/include/convert.h b/include/convert.h
new file mode 100644
index 000000000..7f83e73c0
--- /dev/null
+++ b/include/convert.h
@@ -0,0 +1,132 @@
+/*
+ *
+ * (C) 2003-2025 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#pragma once
+
+#include <optional>
+
+namespace Anope
+{
+ /** Attempts to convert a string to any type.
+ * @param in The value to convert.
+ * @param leftover If non-nullptr then the location to store leftover data.
+ */
+ template<typename T>
+ inline std::optional<T> TryConvert(const Anope::string &in, Anope::string *leftover = nullptr)
+ {
+ std::istringstream tmp(in.str());
+ T out;
+ if (!(tmp >> out))
+ return std::nullopt;
+
+ if (leftover)
+ {
+ leftover->clear();
+ std::getline(tmp, leftover->str());
+ }
+ else
+ {
+ char extra;
+ if (tmp >> extra)
+ return std::nullopt;
+ }
+ return out;
+ }
+
+ /** Converts a string to any type.
+ * @param in The value to convert.
+ * @param def The default to use if the conversion failed.
+ * @param leftover If non-nullptr then the location to store leftover data.
+ */
+ template<typename T>
+ inline T Convert(const Anope::string &in, T def, Anope::string *leftover = nullptr)
+ {
+ return TryConvert<T>(in, leftover).value_or(def);
+ }
+
+ /** Attempts to convert any type to a string.
+ * @param in The value to convert.
+ */
+ template <class T>
+ inline std::optional<Anope::string> TryString(const T &in)
+ {
+ std::ostringstream tmp;
+ if (!(tmp << in))
+ return std::nullopt;
+ return tmp.str();
+ }
+
+ /** No-op function that returns the string that was passed to it.
+ * @param in The string to return.
+ */
+ inline const string &ToString(const string &in)
+ {
+ return in;
+ }
+
+ /** Converts a std::string to a string.
+ * @param in The value to convert.
+ */
+ inline string ToString(const std::string &in)
+ {
+ return in;
+ }
+
+ /** Converts a char array to a string.
+ * @param in The value to convert.
+ */
+ inline string ToString(const char *in)
+ {
+ return string(in);
+ }
+
+ /** Converts a char to a string.
+ * @param in The value to convert.
+ */
+ inline string ToString(char in)
+ {
+ return string(1, static_cast<string::value_type>(in));
+ }
+
+ /** Converts an unsigned char to a string.
+ * @param in The value to convert.
+ */
+ inline string ToString(unsigned char in)
+ {
+ return string(1, static_cast<string::value_type>(in));
+ }
+
+ /** Converts a bool to a string.
+ * @param in The value to convert.
+ */
+ inline string ToString(bool in)
+ {
+ return (in ? "1" : "0");
+ }
+
+ /** Converts a type that std::to_string is implemented for to a string.
+ * @param in The value to convert.
+ */
+ template<typename Stringable>
+ inline std::enable_if_t<std::is_arithmetic_v<Stringable>, string> ToString(const Stringable &in)
+ {
+ return std::to_string(in);
+ }
+
+ /** Converts any type to a string.
+ * @param in The value to convert.
+ */
+ template <class T>
+ inline std::enable_if_t<!std::is_arithmetic_v<T>, string> ToString(const T &in)
+ {
+ return TryString(in).value_or(Anope::string());
+ }
+}
diff --git a/include/defs.h b/include/defs.h
index b49ca79ca..c130a11df 100644
--- a/include/defs.h
+++ b/include/defs.h
@@ -9,6 +9,8 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
class AccessGroup;
class AutoKick;
class BotInfo;
diff --git a/include/extensible.h b/include/extensible.h
index 40f2ecdec..d143b0c81 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef EXTENSIBLE_H
-#define EXTENSIBLE_H
+#pragma once
#include "anope.h"
#include "serialize.h"
@@ -16,15 +15,16 @@
class Extensible;
-class CoreExport ExtensibleBase : public Service
+class CoreExport ExtensibleBase
+ : public Service
{
- protected:
+protected:
std::map<Extensible *, void *> items;
ExtensibleBase(Module *m, const Anope::string &n);
~ExtensibleBase();
- public:
+public:
virtual void Unset(Extensible *obj) = 0;
/* called when an object we are keep track of is serializing */
@@ -34,19 +34,19 @@ class CoreExport ExtensibleBase : public Service
class CoreExport Extensible
{
- public:
+public:
std::set<ExtensibleBase *> extension_items;
virtual ~Extensible();
void UnsetExtensibles();
- template<typename T> T* GetExt(const Anope::string &name) const;
+ template<typename T> T *GetExt(const Anope::string &name) const;
bool HasExt(const Anope::string &name) const;
- template<typename T> T* Extend(const Anope::string &name, const T &what);
- template<typename T> T* Extend(const Anope::string &name);
- template<typename T> T* Require(const Anope::string &name);
+ template<typename T> T *Extend(const Anope::string &name, const T &what);
+ template<typename T> T *Extend(const Anope::string &name);
+ template<typename T> T *Require(const Anope::string &name);
template<typename T> void Shrink(const Anope::string &name);
static void ExtensibleSerialize(const Extensible *, const Serializable *, Serialize::Data &data);
@@ -54,12 +54,13 @@ class CoreExport Extensible
};
template<typename T>
-class BaseExtensibleItem : public ExtensibleBase
+class BaseExtensibleItem
+ : public ExtensibleBase
{
- protected:
+protected:
virtual T *Create(Extensible *) = 0;
- public:
+public:
BaseExtensibleItem(Module *m, const Anope::string &n) : ExtensibleBase(m, n) { }
~BaseExtensibleItem()
@@ -76,24 +77,24 @@ class BaseExtensibleItem : public ExtensibleBase
}
}
- T* Set(Extensible *obj, const T &value)
+ T *Set(Extensible *obj, const T &value)
{
- T* t = Set(obj);
+ T *t = Set(obj);
if (t)
*t = value;
return t;
}
- T* Set(Extensible *obj)
+ T *Set(Extensible *obj)
{
- T* t = Create(obj);
+ T *t = Create(obj);
Unset(obj);
items[obj] = t;
obj->extension_items.insert(this);
return t;
}
- void Unset(Extensible *obj) anope_override
+ void Unset(Extensible *obj) override
{
T *value = Get(obj);
items.erase(obj);
@@ -101,7 +102,7 @@ class BaseExtensibleItem : public ExtensibleBase
delete value;
}
- T* Get(const Extensible *obj) const
+ T *Get(const Extensible *obj) const
{
std::map<Extensible *, void *>::const_iterator it = items.find(const_cast<Extensible *>(obj));
if (it != items.end())
@@ -114,9 +115,9 @@ class BaseExtensibleItem : public ExtensibleBase
return items.find(const_cast<Extensible *>(obj)) != items.end();
}
- T* Require(Extensible *obj)
+ T *Require(Extensible *obj)
{
- T* t = Get(obj);
+ T *t = Get(obj);
if (t)
return t;
@@ -125,54 +126,57 @@ class BaseExtensibleItem : public ExtensibleBase
};
template<typename T>
-class ExtensibleItem : public BaseExtensibleItem<T>
+class ExtensibleItem
+ : public BaseExtensibleItem<T>
{
- protected:
- T* Create(Extensible *obj) anope_override
+protected:
+ T *Create(Extensible *obj) override
{
return new T(obj);
}
- public:
+public:
ExtensibleItem(Module *m, const Anope::string &n) : BaseExtensibleItem<T>(m, n) { }
};
template<typename T>
-class PrimitiveExtensibleItem : public BaseExtensibleItem<T>
+class PrimitiveExtensibleItem
+ : public BaseExtensibleItem<T>
{
- protected:
- T* Create(Extensible *obj) anope_override
+protected:
+ T *Create(Extensible *obj) override
{
return new T();
}
- public:
+public:
PrimitiveExtensibleItem(Module *m, const Anope::string &n) : BaseExtensibleItem<T>(m, n) { }
};
template<>
class PrimitiveExtensibleItem<bool> : public BaseExtensibleItem<bool>
{
- protected:
- bool* Create(Extensible *) anope_override
+protected:
+ bool *Create(Extensible *) override
{
return NULL;
}
- public:
+public:
PrimitiveExtensibleItem(Module *m, const Anope::string &n) : BaseExtensibleItem<bool>(m, n) { }
};
template<typename T>
-class SerializableExtensibleItem : public PrimitiveExtensibleItem<T>
+class SerializableExtensibleItem
+ : public PrimitiveExtensibleItem<T>
{
- public:
+public:
SerializableExtensibleItem(Module *m, const Anope::string &n) : PrimitiveExtensibleItem<T>(m, n) { }
- void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
+ void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
{
- T* t = this->Get(e);
- data[this->name] << *t;
+ T *t = this->Get(e);
+ data.Store(this->name, *t);
}
- void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
+ void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
{
T t;
if (data[this->name] >> t)
@@ -185,16 +189,15 @@ class SerializableExtensibleItem : public PrimitiveExtensibleItem<T>
template<>
class SerializableExtensibleItem<bool> : public PrimitiveExtensibleItem<bool>
{
- public:
+public:
SerializableExtensibleItem(Module *m, const Anope::string &n) : PrimitiveExtensibleItem<bool>(m, n) { }
- void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override
+ void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
{
- data.SetType(this->name, Serialize::Data::DT_INT);
- data[this->name] << this->HasExt(e);
+ data.Store(this->name, this->HasExt(e));
}
- void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override
+ void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
{
bool b = false;
data[this->name] >> b;
@@ -206,13 +209,14 @@ class SerializableExtensibleItem<bool> : public PrimitiveExtensibleItem<bool>
};
template<typename T>
-struct ExtensibleRef : ServiceReference<BaseExtensibleItem<T> >
+struct ExtensibleRef final
+ : ServiceReference<BaseExtensibleItem<T> >
{
ExtensibleRef(const Anope::string &n) : ServiceReference<BaseExtensibleItem<T> >("Extensible", n) { }
};
template<typename T>
-T* Extensible::GetExt(const Anope::string &name) const
+T *Extensible::GetExt(const Anope::string &name) const
{
ExtensibleRef<T> ref(name);
if (ref)
@@ -223,16 +227,16 @@ T* Extensible::GetExt(const Anope::string &name) const
}
template<typename T>
-T* Extensible::Extend(const Anope::string &name, const T &what)
+T *Extensible::Extend(const Anope::string &name, const T &what)
{
- T* t = Extend<T>(name);
+ T *t = Extend<T>(name);
if (t)
*t = what;
return t;
}
template<typename T>
-T* Extensible::Extend(const Anope::string &name)
+T *Extensible::Extend(const Anope::string &name)
{
ExtensibleRef<T> ref(name);
if (ref)
@@ -243,7 +247,7 @@ T* Extensible::Extend(const Anope::string &name)
}
template<typename T>
-T* Extensible::Require(const Anope::string &name)
+T *Extensible::Require(const Anope::string &name)
{
if (HasExt(name))
return GetExt<T>(name);
@@ -260,5 +264,3 @@ void Extensible::Shrink(const Anope::string &name)
else
Log(LOG_DEBUG) << "Shrink for nonexistent type " << name << " on " << static_cast<void *>(this);
}
-
-#endif // EXTENSIBLE_H
diff --git a/include/hashcomp.h b/include/hashcomp.h
index 68e4ad014..6f7720cf3 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -6,19 +6,11 @@
* Please read COPYING and README for further details.
*/
-#ifndef HASHCOMP_H
-#define HASHCOMP_H
+#pragma once
#include <string>
#include <locale>
-
-#if defined _LIBCPP_VERSION || defined _WIN32
#include <unordered_map>
-#define TR1NS std
-#else
-#include <tr1/unordered_map>
-#define TR1NS std::tr1
-#endif
#include "services.h"
@@ -29,16 +21,17 @@ namespace Anope
/* Casemap in use by Anope. ci::string's comparison functions use this (and thus Anope::string) */
extern std::locale casemap;
- extern void CaseMapRebuild();
- extern unsigned char tolower(unsigned char);
- extern unsigned char toupper(unsigned char);
+ extern CoreExport void CaseMapRebuild();
+ extern CoreExport unsigned char tolower(unsigned char);
+ extern CoreExport unsigned char toupper(unsigned char);
/* ASCII case insensitive ctype. */
template<typename char_type>
- class ascii_ctype : public std::ctype<char_type>
+ class ascii_ctype
+ : public std::ctype<char_type>
{
- public:
- char_type do_toupper(char_type c) const anope_override
+ public:
+ char_type do_toupper(char_type c) const override
{
if (c >= 'a' && c <= 'z')
return c - 32;
@@ -46,7 +39,7 @@ namespace Anope
return c;
}
- char_type do_tolower(char_type c) const anope_override
+ char_type do_tolower(char_type c) const override
{
if (c >= 'A' && c <= 'Z')
return c + 32;
@@ -57,10 +50,11 @@ namespace Anope
/* rfc1459 case insensitive ctype, { = [, } = ], and | = \ */
template<typename char_type>
- class rfc1459_ctype : public ascii_ctype<char_type>
+ class rfc1459_ctype final
+ : public ascii_ctype<char_type>
{
- public:
- char_type do_toupper(char_type c) const anope_override
+ public:
+ char_type do_toupper(char_type c) const override
{
if (c == '{' || c == '}' || c == '|')
return c - 32;
@@ -68,7 +62,7 @@ namespace Anope
return ascii_ctype<char_type>::do_toupper(c);
}
- char_type do_tolower(char_type c) const anope_override
+ char_type do_tolower(char_type c) const override
{
if (c == '[' || c == ']' || c == '\\')
return c + 32;
@@ -86,7 +80,8 @@ namespace ci
* This class is used to implement ci::string, a case-insensitive, ASCII-
* comparing string class.
*/
- struct CoreExport ci_char_traits : std::char_traits<char>
+ struct CoreExport ci_char_traits final
+ : std::char_traits<char>
{
/** Check if two chars match.
* @param c1st First character
@@ -131,7 +126,7 @@ namespace ci
*/
typedef std::basic_string<char, ci_char_traits, std::allocator<char> > string;
- struct CoreExport less
+ struct CoreExport less final
{
/** Compare two Anope::strings as ci::strings and find which one is less
* @param s1 The first string
@@ -195,5 +190,3 @@ inline bool operator!=(const std::string &leftval, const ci::string &rightval)
{
return !(leftval.c_str() == rightval);
}
-
-#endif // HASHCOMP_H
diff --git a/include/language.h b/include/language.h
index 826c44670..f9934e642 100644
--- a/include/language.h
+++ b/include/language.h
@@ -6,12 +6,14 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
#include "anope.h"
namespace Language
{
- /* Languages we support as configured in services.conf. They are
+ /* Languages we support as configured in anope.conf. They are
* added to this list if we detect a language exists in the correct
* location for each language.
*/
@@ -53,27 +55,65 @@ namespace Language
*/
extern CoreExport const char *Translate(const NickCore *nc, const char *string);
- /** Translatesa string to the given language.
+ /** Translates a string to the given language.
* @param lang The language to translate to
* @param string The string to translate
* @return The translated string if found, else the original string.
*/
extern CoreExport const char *Translate(const char *lang, const char *string);
+ /** Translates a plural string to the default language.
+ * @param count The number of items the string is counting.
+ * @param singular The string to translate if there is one of \p count
+ * @param plural The string to translate if there is multiple of \p count
+ * @return The translated string if found, else the original string.
+ */
+ extern CoreExport const char *Translate(int count, const char *singular, const char *plural);
+
+ /** Translates a plural string to the language of the given user.
+ * @param u The user to translate the string for
+ * @param count The number of items the string is counting.
+ * @param singular The string to translate if there is one of \p count
+ * @param plural The string to translate if there is multiple of \p count
+ * @return The translated string if found, else the original string.
+ */
+ extern CoreExport const char *Translate(User *u, int count, const char *singular, const char *plural);
+
+ /** Translates a plural string to the language of the given account.
+ * @param nc The account to translate the string for
+ * @param count The number of items the string is counting.
+ * @param singular The string to translate if there is one of \p count
+ * @param plural The string to translate if there is multiple of \p count
+ * @return The translated string if count, else the original string
+ */
+ extern CoreExport const char *Translate(const NickCore *nc, int count, const char *singular, const char *plural);
+
+ /** Translates a plural string to the given language.
+ * @param lang The language to translate to
+ * @param count The number of items the string is counting.
+ * @param singular The string to translate if there is one of \p count
+ * @param plural The string to translate if there is multiple of \p count
+ * @return The translated string if found, else the original string.
+ */
+ extern CoreExport const char *Translate(const char *lang, int count, const char *singular, const char *plural);
+
} // namespace Language
/* Commonly used language strings */
-#define MORE_INFO _("\002%s%s HELP %s\002 for more information.")
+#define CONFIRM_DROP _("Please confirm that you want to drop \002%s\002 with \002%s DROP %s %s\002")
+#define SERVICE_UNAVAILABLE _("Sorry, %s is temporarily unavailable.")
+#define MORE_INFO _("\002%s HELP %s\002 for more information.")
#define BAD_USERHOST_MASK _("Mask must be in the form \037user\037@\037host\037.")
#define BAD_EXPIRY_TIME _("Invalid expiry time.")
#define USERHOST_MASK_TOO_WIDE _("%s coverage is too wide; Please use a more specific mask.")
-#define READ_ONLY_MODE _("Services are in read-only mode!")
+#define READ_ONLY_MODE _("Services are temporarily in read-only mode.")
#define PASSWORD_INCORRECT _("Password incorrect.")
#define ACCESS_DENIED _("Access denied.")
-#define MORE_OBSCURE_PASSWORD _("Please try again with a more obscure password. Passwords should be at least\n" \
- "five characters long, should not be something easily guessed\n" \
- "(e.g. your real name or your nick), and cannot contain the space or tab characters.")
-#define PASSWORD_TOO_LONG _("Your password is too long. It must not exceed %u characters.")
+#define MORE_OBSCURE_PASSWORD _("Please try again with a more obscure password. Passwords should not be\n" \
+ "something that could be easily guessed (e.g. your real name or your nick) and\n" \
+ "cannot contain the space or tab characters.\n")
+#define PASSWORD_TOO_SHORT _("Your password is too short. It must be longer than %u characters.")
+#define PASSWORD_TOO_LONG _("Your password is too long. It must be shorter than %u characters.")
#define NICK_NOT_REGISTERED _("Your nick isn't registered.")
#define NICK_X_NOT_REGISTERED _("Nick \002%s\002 isn't registered.")
#define NICK_X_NOT_IN_USE _("Nick \002%s\002 isn't currently in use.")
@@ -83,20 +123,18 @@ namespace Language
#define CHAN_X_NOT_REGISTERED _("Channel \002%s\002 isn't registered.")
#define CHAN_X_NOT_IN_USE _("Channel \002%s\002 doesn't exist.")
#define NICK_IDENTIFY_REQUIRED _("You must be logged into an account to use that command.")
-#define MAIL_X_INVALID _("\002%s\002 is not a valid e-mail address.")
+#define MAIL_X_INVALID _("\002%s\002 is not a valid email address.")
#define UNKNOWN _("<unknown>")
#define NO_EXPIRE _("does not expire")
#define LIST_INCORRECT_RANGE _("Incorrect range specified. The correct syntax is \002#\037from\037-\037to\037\002.")
-#define NICK_IS_REGISTERED _("This nick is owned by someone else. Please choose another.\n" \
- "(If this is your nick, type \002%s%s IDENTIFY \037password\037\002.)")
#define NICK_IS_SECURE _("This nickname is registered and protected. If it is your\n" \
- "nick, type \002%s%s IDENTIFY \037password\037\002. Otherwise,\n" \
+ "nick, type \002%s IDENTIFY \037password\037\002. Otherwise,\n" \
"please choose a different nick.")
#define FORCENICKCHANGE_NOW _("This nickname has been registered; you may not use it.")
#define NICK_CANNOT_BE_REGISTERED _("Nickname \002%s\002 may not be registered.")
#define NICK_ALREADY_REGISTERED _("Nickname \002%s\002 is already registered!")
#define NICK_SET_DISPLAY_CHANGED _("The new display is now \002%s\002.")
-#define NICK_CONFIRM_INVALID _("Invalid passcode has been entered, please check the e-mail again, and retry.")
+#define NICK_CONFIRM_INVALID _("Invalid passcode has been entered, please check the email again, and retry.")
#define CHAN_NOT_ALLOWED_TO_JOIN _("You are not permitted to be on this channel.")
#define CHAN_X_INVALID _("Channel %s is not a valid channel.")
#define CHAN_REACHED_CHANNEL_LIMIT _("Sorry, you have already reached your limit of \002%d\002 channels.")
@@ -105,23 +143,22 @@ namespace Language
#define CHAN_SETTING_CHANGED _("%s for %s set to %s.")
#define CHAN_SETTING_UNSET _("%s for %s unset.")
#define CHAN_ACCESS_LEVEL_RANGE _("Access level must be between %d and %d inclusive.")
-#define CHAN_INFO_HEADER _("Information for channel \002%s\002:")
+#define CHAN_INFO_HEADER _("Information about channel \002%s\002:")
#define CHAN_EXCEPTED _("\002%s\002 matches an except on %s and cannot be banned until the except has been removed.")
#define MEMO_NEW_X_MEMO_ARRIVED _("There is a new memo on channel %s.\n" \
- "Type \002%s%s READ %s %d\002 to read it.")
+ "Type \002%s READ %s %zu\002 to read it.")
#define MEMO_NEW_MEMO_ARRIVED _("You have a new memo from %s.\n" \
- "Type \002%s%s READ %d\002 to read it.")
+ "Type \002%s READ %zu\002 to read it.")
#define MEMO_HAVE_NO_MEMOS _("You have no memos.")
#define MEMO_X_HAS_NO_MEMOS _("%s has no memos.")
-#define MEMO_SEND_DISABLED _("Sorry, memo sending is temporarily disabled.")
#define MEMO_HAVE_NO_NEW_MEMOS _("You have no new memos.")
#define MEMO_X_HAS_NO_NEW_MEMOS _("%s has no new memos.")
#define BOT_DOES_NOT_EXIST _("Bot \002%s\002 does not exist.")
#define BOT_NOT_ASSIGNED _("You must assign a bot to the channel before using this command.")
#define BOT_NOT_ON_CHANNEL _("Bot is not on channel \002%s\002.")
-#define HOST_SET_ERROR _("A vHost must be in the format of a valid hostname.")
-#define HOST_SET_IDENT_ERROR _("A vHost ident must be in the format of a valid ident.")
-#define HOST_SET_TOOLONG _("Error! The vHost is too long, please use a hostname shorter than %d characters.")
-#define HOST_SET_IDENTTOOLONG _("Error! The vHost ident is too long, please use an ident shorter than %d characters.")
-#define HOST_NOT_ASSIGNED _("Please contact an Operator to get a vHost assigned to this nick.")
-#define HOST_NO_VIDENT _("Your IRCd does not support vIdent's, if this is incorrect, please report this as a possible bug")
+#define HOST_SET_ERROR _("A vhost must be in the format of a valid hostname.")
+#define HOST_SET_IDENT_ERROR _("A vident must be in the format of a valid ident.")
+#define HOST_SET_TOOLONG _("Error! The vhost is too long, please use a hostname shorter than %zu characters.")
+#define HOST_SET_IDENTTOOLONG _("Error! The vident is too long, please use an ident shorter than %zu characters.")
+#define HOST_NOT_ASSIGNED _("Please contact an Operator to get a vhost assigned to this nick.")
+#define HOST_NO_VIDENT _("Your IRCd does not support vidents. If this is incorrect please report this as a possible bug.")
diff --git a/include/lists.h b/include/lists.h
index 039ab7758..7bba44907 100644
--- a/include/lists.h
+++ b/include/lists.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef LISTS_H
-#define LISTS_H
+#pragma once
#include "services.h"
#include "anope.h"
@@ -24,13 +23,13 @@
*/
class CoreExport NumberList
{
- private:
- bool is_valid;
+private:
+ bool is_valid = true;
std::set<unsigned> numbers;
bool desc;
- public:
+public:
/** Processes a numbered list
* @param list The list
* @param descending True to make HandleNumber get called with numbers in descending order
@@ -39,7 +38,7 @@ class CoreExport NumberList
/** Destructor, does nothing
*/
- virtual ~NumberList();
+ virtual ~NumberList() = default;
/** Should be called after the constructors are done running. This calls the callbacks.
*/
@@ -61,15 +60,15 @@ class CoreExport NumberList
/** This class handles formatting LIST/VIEW replies.
*/
-class CoreExport ListFormatter
+class CoreExport ListFormatter final
{
- public:
+public:
typedef std::map<Anope::string, Anope::string> ListEntry;
- private:
+private:
NickCore *nc;
std::vector<Anope::string> columns;
std::vector<ListEntry> entries;
- public:
+public:
ListFormatter(NickCore *nc);
ListFormatter &AddColumn(const Anope::string &name);
void AddEntry(const ListEntry &entry);
@@ -79,16 +78,14 @@ class CoreExport ListFormatter
/** This class handles formatting INFO replies
*/
-class CoreExport InfoFormatter
+class CoreExport InfoFormatter final
{
NickCore *nc;
std::vector<std::pair<Anope::string, Anope::string> > replies;
- unsigned longest;
- public:
+ unsigned longest = 0;
+public:
InfoFormatter(NickCore *nc);
void Process(std::vector<Anope::string> &);
Anope::string &operator[](const Anope::string &key);
void AddOption(const Anope::string &opt);
};
-
-#endif // LISTS_H
diff --git a/include/logger.h b/include/logger.h
index 83b967f76..b73526afe 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef LOGGER_H
-#define LOGGER_H
+#pragma once
#include "anope.h"
#include "defs.h"
@@ -38,7 +37,7 @@ enum LogType
LOG_DEBUG_4
};
-struct LogFile
+struct LogFile final
{
Anope::string filename;
std::ofstream stream;
@@ -49,27 +48,27 @@ struct LogFile
};
/* Represents a single log message */
-class CoreExport Log
+class CoreExport Log final
{
- public:
+public:
/* Bot that should log this message */
- BotInfo *bi;
+ BotInfo *bi = nullptr;
/* For commands, the user executing the command, but might not always exist */
- User *u;
+ User *u = nullptr;
/* For commands, the account executing the command, but will not always exist */
- NickCore *nc;
+ NickCore *nc = nullptr;
/* For commands, the command being executed */
- Command *c;
+ Command *c = nullptr;
/* For commands, the command source */
- CommandSource *source;
+ CommandSource *source = nullptr;
/* Used for LOG_CHANNEL */
- Channel *chan;
+ Channel *chan = nullptr;
/* For commands, the channel the command was executed on, will not always exist */
- const ChannelInfo *ci;
+ const ChannelInfo *ci = nullptr;
/* For LOG_SERVER */
- Server *s;
+ Server *s = nullptr;
/* For LOG_MODULE */
- Module *m;
+ Module *m = nullptr;
LogType type;
Anope::string category;
@@ -95,11 +94,11 @@ class CoreExport Log
~Log();
- private:
+private:
Anope::string FormatSource() const;
Anope::string FormatCommand() const;
- public:
+public:
Anope::string BuildPrefix() const;
template<typename T> Log &operator<<(T val)
@@ -110,13 +109,13 @@ class CoreExport Log
};
/* Configured in the configuration file, actually does the message logging */
-class CoreExport LogInfo
+class CoreExport LogInfo final
{
- public:
- BotInfo *bot;
+public:
+ BotInfo *bot = nullptr;
std::vector<Anope::string> targets;
std::vector<LogFile *> logfiles;
- int last_day;
+ int last_day = 0;
std::vector<Anope::string> sources;
int log_age;
std::vector<Anope::string> admin;
@@ -140,5 +139,3 @@ class CoreExport LogInfo
/* Logs the message l if configured to */
void ProcessMessage(const Log *l);
};
-
-#endif // LOGGER_H
diff --git a/include/mail.h b/include/mail.h
index 347f3bc5b..0a25da3bf 100644
--- a/include/mail.h
+++ b/include/mail.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef MAIL_H
-#define MAIL_H
+#pragma once
#include "anope.h"
#include "threadengine.h"
@@ -23,9 +22,10 @@ namespace Mail
extern CoreExport bool Validate(const Anope::string &email);
/* A email message being sent */
- class Message : public Thread
+ class Message final
+ : public Thread
{
- private:
+ private:
Anope::string error;
Anope::string sendmail_path;
Anope::string send_from;
@@ -36,7 +36,7 @@ namespace Mail
Anope::string content_type;
bool dont_quote_addresses;
- public:
+ public:
/** Construct this message. Once constructed call Thread::Start to launch the mail sending.
* @param sf Config->SendFrom
* @param mailto Name of person being mailed (u->nick, nc->display, etc)
@@ -49,9 +49,7 @@ namespace Mail
~Message();
/* Called from within the thread to actually send the mail */
- void Run() anope_override;
+ void Run() override;
};
} // namespace Mail
-
-#endif // MAIL_H
diff --git a/include/memo.h b/include/memo.h
index d98492e2c..dca35ea8e 100644
--- a/include/memo.h
+++ b/include/memo.h
@@ -9,23 +9,23 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef MEMO_H
-#define MEMO_H
+#pragma once
#include "anope.h"
#include "serialize.h"
-class CoreExport Memo : public Serializable
+class CoreExport Memo final
+ : public Serializable
{
- public:
+public:
MemoInfo *mi;
bool unread;
bool receipt;
Memo();
~Memo();
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
Anope::string owner;
/* When it was sent */
@@ -37,9 +37,9 @@ class CoreExport Memo : public Serializable
/* Memo info structures. Since both nicknames and channels can have memos,
* we encapsulate memo data in a MemoInfo to make it easier to handle.
*/
-struct CoreExport MemoInfo
+struct CoreExport MemoInfo final
{
- int16_t memomax;
+ int16_t memomax = 0;
Serialize::Checker<std::vector<Memo *> > memos;
std::vector<Anope::string> ignores;
@@ -51,5 +51,3 @@ struct CoreExport MemoInfo
static MemoInfo *GetMemoInfo(const Anope::string &targ, bool &is_chan);
};
-
-#endif // MEMO_H
diff --git a/include/messages.h b/include/messages.h
index 7fffce5a0..510f66361 100644
--- a/include/messages.h
+++ b/include/messages.h
@@ -9,6 +9,8 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
#include "protocol.h"
/* Common IRCD messages.
@@ -19,39 +21,44 @@
namespace Message
{
- struct CoreExport Away : IRCDMessage
+ struct CoreExport Away
+ : IRCDMessage
{
- Away(Module *creator, const Anope::string &mname = "AWAY") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Away(Module *creator, const Anope::string &mname = "AWAY") : IRCDMessage(creator, mname, 0) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Capab : IRCDMessage
+ struct CoreExport Capab
+ : IRCDMessage
{
- Capab(Module *creator, const Anope::string &mname = "CAPAB") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Capab(Module *creator, const Anope::string &mname = "CAPAB") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Error : IRCDMessage
+ struct CoreExport Error
+ : IRCDMessage
{
Error(Module *creator, const Anope::string &mname = "ERROR") : IRCDMessage(creator, mname, 1) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Invite : IRCDMessage
+ struct CoreExport Invite
+ : IRCDMessage
{
- Invite(Module *creator, const Anope::string &mname = "INVITE") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Invite(Module *creator, const Anope::string &mname = "INVITE") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Join : IRCDMessage
+ struct CoreExport Join
+ : IRCDMessage
{
- Join(Module *creator, const Anope::string &mname = "JOIN") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Join(Module *creator, const Anope::string &mname = "JOIN") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
typedef std::pair<ChannelStatus, User *> SJoinUser;
@@ -59,115 +66,131 @@ namespace Message
* @param source The source of the SJOIN
* @param chan The channel the users are joining to
* @param ts The TS for the channel
- * @param modes The modes sent with the SJOIN, if any
+ * @param modes The mode letters sent with the SJOIN, if any
+ * @param modeparams The mode parameters sent with the SJOIN, if any
* @param users The users and their status, if any
*/
- static void SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::list<SJoinUser> &users);
+ static void SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::vector<Anope::string> &modeparams, const std::list<SJoinUser> &users);
};
- struct CoreExport Kick : IRCDMessage
+ struct CoreExport Kick
+ : IRCDMessage
{
- Kick(Module *creator, const Anope::string &mname = "KICK") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Kick(Module *creator, const Anope::string &mname = "KICK") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Kill : IRCDMessage
+ struct CoreExport Kill
+ : IRCDMessage
{
Kill(Module *creator, const Anope::string &mname = "KILL") : IRCDMessage(creator, mname, 2) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Mode : IRCDMessage
+ struct CoreExport Mode
+ : IRCDMessage
{
- Mode(Module *creator, const Anope::string &mname = "MODE") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Mode(Module *creator, const Anope::string &mname = "MODE") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport MOTD : IRCDMessage
+ struct CoreExport MOTD
+ : IRCDMessage
{
MOTD(Module *creator, const Anope::string &mname = "MOTD") : IRCDMessage(creator, mname, 1) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Notice : IRCDMessage
+ struct CoreExport Notice
+ : IRCDMessage
{
- Notice(Module *creator, const Anope::string &mname = "NOTICE") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ Notice(Module *creator, const Anope::string &mname = "NOTICE") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Part : IRCDMessage
+ struct CoreExport Part
+ : IRCDMessage
{
- Part(Module *creator, const Anope::string &mname = "PART") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Part(Module *creator, const Anope::string &mname = "PART") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Ping : IRCDMessage
+ struct CoreExport Ping
+ : IRCDMessage
{
- Ping(Module *creator, const Anope::string &mname = "PING") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Ping(Module *creator, const Anope::string &mname = "PING") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Privmsg : IRCDMessage
+ struct CoreExport Privmsg
+ : IRCDMessage
{
- Privmsg(Module *creator, const Anope::string &mname = "PRIVMSG") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ Privmsg(Module *creator, const Anope::string &mname = "PRIVMSG") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Quit : IRCDMessage
+ struct CoreExport Quit
+ : IRCDMessage
{
- Quit(Module *creator, const Anope::string &mname = "QUIT") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ Quit(Module *creator, const Anope::string &mname = "QUIT") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport SQuit : IRCDMessage
+ struct CoreExport SQuit
+ : IRCDMessage
{
SQuit(Module *creator, const Anope::string &mname = "SQUIT") : IRCDMessage(creator, mname, 2) { }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Stats : IRCDMessage
+ struct CoreExport Stats
+ : IRCDMessage
{
- Stats(Module *creator, const Anope::string &mname = "STATS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Stats(Module *creator, const Anope::string &mname = "STATS") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Time : IRCDMessage
+ struct CoreExport Time
+ : IRCDMessage
{
- Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Topic : IRCDMessage
+ struct CoreExport Topic
+ : IRCDMessage
{
- Topic(Module *creator, const Anope::string &mname = "TOPIC") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); }
+ Topic(Module *creator, const Anope::string &mname = "TOPIC") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Version : IRCDMessage
+ struct CoreExport Version
+ : IRCDMessage
{
- Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
- struct CoreExport Whois : IRCDMessage
+ struct CoreExport Whois
+ : IRCDMessage
{
- Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_SOFT_LIMIT); }
- void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override;
+ void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override;
};
} // namespace Message
diff --git a/include/modes.h b/include/modes.h
index dd35c533f..db84a64fe 100644
--- a/include/modes.h
+++ b/include/modes.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef MODES_H
-#define MODES_H
+#pragma once
#include "anope.h"
#include "base.h"
@@ -36,9 +35,10 @@ enum ModeClass
/** This class is the basis of all modes in Anope
*/
-class CoreExport Mode : public Base
+class CoreExport Mode
+ : public Base
{
- public:
+public:
/* Mode name */
Anope::string name;
/* Class of mode this is (user/channel) */
@@ -55,7 +55,7 @@ class CoreExport Mode : public Base
* @param type The mode type
*/
Mode(const Anope::string &mname, ModeClass mclass, char mc, ModeType type);
- virtual ~Mode();
+ virtual ~Mode() = default;
/** Can a user set this mode, used for mlock
* @param u The user
@@ -65,9 +65,10 @@ class CoreExport Mode : public Base
/** This class is a user mode, all user modes use this/inherit from this
*/
-class CoreExport UserMode : public Mode
+class CoreExport UserMode
+ : public Mode
{
- public:
+public:
/** constructor
* @param name The mode name
* @param mc The mode char
@@ -75,9 +76,10 @@ class CoreExport UserMode : public Mode
UserMode(const Anope::string &name, char mc);
};
-class CoreExport UserModeParam : public UserMode
+class CoreExport UserModeParam
+ : public UserMode
{
- public:
+public:
/** constructor
* @param name The mode name
* @param mc The mode char
@@ -93,9 +95,10 @@ class CoreExport UserModeParam : public UserMode
/** This class is a channel mode, all channel modes use this/inherit from this
*/
-class CoreExport ChannelMode : public Mode
+class CoreExport ChannelMode
+ : public Mode
{
- public:
+public:
/* channel modes that can possibly unwrap this mode */
std::vector<ChannelMode *> listeners;
@@ -105,7 +108,7 @@ class CoreExport ChannelMode : public Mode
*/
ChannelMode(const Anope::string &name, char mc);
- bool CanSet(User *u) const anope_override;
+ bool CanSet(User *u) const override;
virtual void Check() { }
@@ -124,9 +127,10 @@ class CoreExport ChannelMode : public Mode
/** This is a mode for lists, eg b/e/I. These modes should inherit from this
*/
-class CoreExport ChannelModeList : public ChannelMode
+class CoreExport ChannelModeList
+ : public ChannelMode
{
- public:
+public:
/** constructor
* @param name The mode name
* @param mc The mode char
@@ -162,9 +166,10 @@ class CoreExport ChannelModeList : public ChannelMode
/** This is a mode with a parameter, eg +k/l. These modes should use/inherit from this
*/
-class CoreExport ChannelModeParam : public ChannelMode
+class CoreExport ChannelModeParam
+ : public ChannelMode
{
- public:
+public:
/** constructor
* @param name The mode name
* @param mc The mode char
@@ -184,9 +189,10 @@ class CoreExport ChannelModeParam : public ChannelMode
/** This is a mode that is a channel status, eg +v/h/o/a/q.
*/
-class CoreExport ChannelModeStatus : public ChannelMode
+class CoreExport ChannelModeStatus
+ : public ChannelMode
{
- public:
+public:
/* The symbol, eg @ % + */
char symbol;
/* The "level" of the mode, used to compare with other modes.
@@ -207,29 +213,33 @@ class CoreExport ChannelModeStatus : public ChannelMode
* but we still have a representation for it.
*/
template<typename T>
-class CoreExport ChannelModeVirtual : public T
+class CoreExport ChannelModeVirtual
+ : public T
{
- Anope::string base;
+private:
ChannelMode *basech;
- public:
+protected:
+ Anope::string base;
+
+public:
ChannelModeVirtual(const Anope::string &mname, const Anope::string &basename);
~ChannelModeVirtual();
- void Check() anope_override;
+ void Check() override;
- ChannelMode *Wrap(Anope::string &param) anope_override;
+ ChannelMode *Wrap(Anope::string &param) override;
- ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) anope_override = 0;
+ ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) override = 0;
};
/* The status a user has on a channel (+v, +h, +o) etc */
-class CoreExport ChannelStatus
+class CoreExport ChannelStatus final
{
Anope::string modes;
- public:
- ChannelStatus();
+public:
+ ChannelStatus() = default;
ChannelStatus(const Anope::string &modes);
void AddMode(char c);
void DelMode(char c);
@@ -240,51 +250,56 @@ class CoreExport ChannelStatus
Anope::string BuildModePrefixList() const;
};
-class CoreExport UserModeOperOnly : public UserMode
+class CoreExport UserModeOperOnly
+ : public UserMode
{
- public:
+public:
UserModeOperOnly(const Anope::string &mname, char um) : UserMode(mname, um) { }
- bool CanSet(User *u) const anope_override;
+ bool CanSet(User *u) const override;
};
-class CoreExport UserModeNoone : public UserMode
+class CoreExport UserModeNoone
+ : public UserMode
{
- public:
+public:
UserModeNoone(const Anope::string &mname, char um) : UserMode(mname, um) { }
- bool CanSet(User *u) const anope_override;
+ bool CanSet(User *u) const override;
};
/** Channel mode +k (key)
*/
-class CoreExport ChannelModeKey : public ChannelModeParam
+class CoreExport ChannelModeKey
+ : public ChannelModeParam
{
- public:
+public:
ChannelModeKey(char mc) : ChannelModeParam("KEY", mc) { }
- bool IsValid(Anope::string &value) const anope_override;
+ bool IsValid(Anope::string &value) const override;
};
/** This class is used for oper only channel modes
*/
-class CoreExport ChannelModeOperOnly : public ChannelMode
+class CoreExport ChannelModeOperOnly
+ : public ChannelMode
{
- public:
+public:
ChannelModeOperOnly(const Anope::string &mname, char mc) : ChannelMode(mname, mc) { }
/* Opers only */
- bool CanSet(User *u) const anope_override;
+ bool CanSet(User *u) const override;
};
/** This class is used for channel modes only servers may set
*/
-class CoreExport ChannelModeNoone : public ChannelMode
+class CoreExport ChannelModeNoone
+ : public ChannelMode
{
- public:
+public:
ChannelModeNoone(const Anope::string &mname, char mc) : ChannelMode(mname, mc) { }
- bool CanSet(User *u) const anope_override;
+ bool CanSet(User *u) const override;
};
/** This is the mode manager
@@ -293,9 +308,9 @@ class CoreExport ChannelModeNoone : public ChannelMode
* This also contains a mode stacker that will combine multiple modes and set
* them on a channel or user at once
*/
-class CoreExport ModeManager
+class CoreExport ModeManager final
{
- public:
+public:
/* Number of generic channel and user modes we are tracking */
static unsigned GenericChannelModes;
@@ -389,13 +404,13 @@ class CoreExport ModeManager
/** Represents a mask set on a channel (b/e/I)
*/
-class CoreExport Entry
+class CoreExport Entry final
{
Anope::string name;
Anope::string mask;
- public:
- unsigned short cidr_len;
- int family;
+public:
+ unsigned short cidr_len = 0;
+ int family = 0;
Anope::string nick, user, host, real;
/** Constructor
@@ -407,9 +422,9 @@ class CoreExport Entry
/** Get the banned mask for this entry
* @return The mask
*/
- const Anope::string GetMask() const;
+ Anope::string GetMask() const;
- const Anope::string GetNUHMask() const;
+ Anope::string GetNUHMask() const;
/** Check if this entry matches a user
* @param u The user
@@ -418,5 +433,3 @@ class CoreExport Entry
*/
bool Matches(User *u, bool full = false) const;
};
-
-#endif // MODES_H
diff --git a/include/module.h b/include/module.h
index 1f140491b..ea500abea 100644
--- a/include/module.h
+++ b/include/module.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef MODULE_H
-#define MODULE_H
+#pragma once
#include "access.h"
#include "account.h"
@@ -50,5 +49,3 @@
#include "modules/pseudoclients/global.h"
#include "modules/pseudoclients/memoserv.h"
#include "modules/pseudoclients/nickserv.h"
-
-#endif // MODULE_H
diff --git a/include/modules.h b/include/modules.h
index 9f8cf6bf5..12637b1b4 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -9,11 +9,10 @@
* Based on the original code of Services by Andy Church.
*/
-#include "serialize.h"
-#ifndef MODULES_H
-#define MODULES_H
+#pragma once
+#include "serialize.h"
#include "base.h"
#include "modes.h"
#include "timers.h"
@@ -25,32 +24,7 @@
* and functions needed to make a module loadable by the OS.
* It defines the class factory and external AnopeInit and AnopeFini functions.
*/
-#ifdef _WIN32
-# define MODULE_INIT(x) \
- extern "C" DllExport Module *AnopeInit(const Anope::string &, const Anope::string &); \
- extern "C" Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \
- { \
- return new x(modname, creator); \
- } \
- BOOLEAN WINAPI DllMain(HINSTANCE, DWORD, LPVOID) \
- { \
- return TRUE; \
- } \
- extern "C" DllExport void AnopeFini(x *); \
- extern "C" void AnopeFini(x *m) \
- { \
- delete m; \
- } \
- extern "C" DllExport ModuleVersionC AnopeVersion() \
- { \
- ModuleVersionC ver; \
- ver.version_major = VERSION_MAJOR; \
- ver.version_minor = VERSION_MINOR; \
- ver.version_patch = VERSION_PATCH; \
- return ver; \
- }
-#else
-# define MODULE_INIT(x) \
+#define MODULE_INIT(x) \
extern "C" DllExport Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \
{ \
return new x(modname, creator); \
@@ -67,7 +41,6 @@
ver.version_patch = VERSION_PATCH; \
return ver; \
}
-#endif
/**
* This #define allows us to call a method in all
@@ -189,7 +162,7 @@ enum
};
typedef unsigned short ModType;
-struct ModuleVersionC
+struct ModuleVersionC final
{
int version_major, version_minor, version_patch;
};
@@ -197,14 +170,14 @@ struct ModuleVersionC
/** Returned by Module::GetVersion, used to see what version of Anope
* a module is compiled against.
*/
-class ModuleVersion
+class ModuleVersion final
{
- private:
+private:
int version_major;
int version_minor;
int version_patch;
- public:
+public:
ModuleVersion(const ModuleVersionC &);
/** Get the major version of Anope this was built against
@@ -223,15 +196,21 @@ class ModuleVersion
int GetPatch() const;
};
-class NotImplementedException : public CoreException { };
+class CoreExport NotImplementedException final
+ : public CoreException
+{
+public:
+ NotImplementedException() : CoreException("") { }
+};
/** Every module in Anope is actually a class.
*/
-class CoreExport Module : public Extensible
+class CoreExport Module
+ : public Extensible
{
- private:
+private:
bool permanent;
- public:
+public:
/** The module name (e.g. os_modload)
*/
Anope::string name;
@@ -311,7 +290,7 @@ class CoreExport Module : public Extensible
* @param cu The user, channel, and status of the user being kicked
* @param kickmsg The reason for the kick.
*/
- virtual void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) { throw NotImplementedException(); }
+ virtual void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a user has been kicked from a channel.
* @param source The kicker
@@ -320,13 +299,13 @@ class CoreExport Module : public Extensible
* @param status The status the kicked user had on the channel before they were kicked
* @param kickmsg The reason for the kick.
*/
- virtual void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) { throw NotImplementedException(); }
+ virtual void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
- /** Called when Services' configuration is being (re)loaded.
+ /** Called when the configuration is being (re)loaded.
* @param conf The config that is being built now and will replace the global Config object
* @throws A ConfigException to abort the config (re)loading process.
*/
- virtual void OnReload(Configuration::Conf *conf) { throw NotImplementedException(); }
+ virtual void OnReload(Configuration::Conf *conf) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called before a bot is assigned to a channel.
* @param sender The user assigning the bot
@@ -334,35 +313,35 @@ class CoreExport Module : public Extensible
* @param bi The bot being assigned.
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the assign.
*/
- virtual EventReturn OnPreBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { throw NotImplementedException(); }
+ virtual EventReturn OnPreBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) ATTR_NOT_NULL(2, 3, 4) { throw NotImplementedException(); }
/** Called when a bot is assigned ot a channel
*/
- virtual void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { throw NotImplementedException(); }
+ virtual void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) ATTR_NOT_NULL(2, 3, 4) { throw NotImplementedException(); }
/** Called before a bot is unassigned from a channel.
* @param sender The user unassigning the bot
* @param ci The channel the bot is being removed from
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the unassign.
*/
- virtual EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a new user connects to the network.
* @param u The connecting user.
* @param exempt set to true/is true if the user should be excepted from bans etc
*/
- virtual void OnUserConnect(User *u, bool &exempt) { throw NotImplementedException(); }
+ virtual void OnUserConnect(User *u, bool &exempt) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a new server connects to the network.
* @param s The server that has connected to the network
*/
- virtual void OnNewServer(Server *s) { throw NotImplementedException(); }
+ virtual void OnNewServer(Server *s) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called after a user changed the nick
* @param u The user.
* @param oldnick The old nick of the user
*/
- virtual void OnUserNickChange(User *u, const Anope::string &oldnick) { throw NotImplementedException(); }
+ virtual void OnUserNickChange(User *u, const Anope::string &oldnick) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when someone uses the generic/help command
* @param source Command source
@@ -383,14 +362,14 @@ class CoreExport Module : public Extensible
* @param params The parameters the user is sending
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
- virtual EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) { throw NotImplementedException(); }
+ virtual EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called after a command has been executed.
* @param source The source of the command
* @param command The command the user executed
* @param params The parameters the user sent
*/
- virtual void OnPostCommand(CommandSource &source, Command *command, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
+ virtual void OnPostCommand(CommandSource &source, Command *command, const std::vector<Anope::string> &params) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when the databases are saved
*/
@@ -404,7 +383,6 @@ class CoreExport Module : public Extensible
/** Called when anope needs to check passwords against encryption
*/
virtual EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { throw NotImplementedException(); }
- virtual EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { throw NotImplementedException(); }
/** Called on fantasy command
* @param source The source of the command
@@ -413,7 +391,7 @@ class CoreExport Module : public Extensible
* @param params The params
* @return EVENT_STOP to halt processing and not run the command, EVENT_ALLOW to allow the command to be executed
*/
- virtual EventReturn OnBotFantasy(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
+ virtual EventReturn OnBotFantasy(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> &params) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called on fantasy command without access
* @param source The source of the command
@@ -422,31 +400,31 @@ class CoreExport Module : public Extensible
* @param params The params
* @return EVENT_STOP to halt processing and not run the command, EVENT_ALLOW to allow the command to be executed
*/
- virtual EventReturn OnBotNoFantasyAccess(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> &params) { throw NotImplementedException(); }
+ virtual EventReturn OnBotNoFantasyAccess(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> &params) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called when a bot places a ban
* @param u User being banned
* @param ci Channel the ban is placed on
* @param mask The mask being banned
*/
- virtual void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) { throw NotImplementedException(); }
+ virtual void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called before a badword is added to the badword list
* @param ci The channel
* @param bw The badword
*/
- virtual void OnBadWordAdd(ChannelInfo *ci, const BadWord *bw) { throw NotImplementedException(); }
+ virtual void OnBadWordAdd(ChannelInfo *ci, const BadWord *bw) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called before a badword is deleted from a channel
* @param ci The channel
* @param bw The badword
*/
- virtual void OnBadWordDel(ChannelInfo *ci, const BadWord *bw) { throw NotImplementedException(); }
+ virtual void OnBadWordDel(ChannelInfo *ci, const BadWord *bw) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a bot is created or destroyed
*/
- virtual void OnCreateBot(BotInfo *bi) { throw NotImplementedException(); }
- virtual void OnDelBot(BotInfo *bi) { throw NotImplementedException(); }
+ virtual void OnCreateBot(BotInfo *bi) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
+ virtual void OnDelBot(BotInfo *bi) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called before a bot kicks a user
* @param bi The bot sending the kick
@@ -455,13 +433,13 @@ class CoreExport Module : public Extensible
* @param reason The reason
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
- virtual EventReturn OnBotKick(BotInfo *bi, Channel *c, User *u, const Anope::string &reason) { throw NotImplementedException(); }
+ virtual EventReturn OnBotKick(BotInfo *bi, Channel *c, User *u, const Anope::string &reason) ATTR_NOT_NULL(2, 3, 4) { throw NotImplementedException(); }
/** Called before a user parts a channel
* @param u The user
* @param c The channel
*/
- virtual void OnPrePartChannel(User *u, Channel *c) {}
+ virtual void OnPrePartChannel(User *u, Channel *c) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a user parts a channel
* @param u The user
@@ -469,14 +447,14 @@ class CoreExport Module : public Extensible
* @param channel The channel name
* @param msg The part reason
*/
- virtual void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) { throw NotImplementedException(); }
+ virtual void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a user leaves a channel.
* From either parting, being kicked, or quitting/killed!
* @param u The user
* @param c The channel
*/
- virtual void OnLeaveChannel(User *u, Channel *c) { throw NotImplementedException(); }
+ virtual void OnLeaveChannel(User *u, Channel *c) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called after a user joins a channel
* If this event triggers the user is allowed to be in the channel, and will
@@ -485,7 +463,7 @@ class CoreExport Module : public Extensible
* @param u The user
* @param channel The channel
*/
- virtual void OnJoinChannel(User *u, Channel *c) { throw NotImplementedException(); }
+ virtual void OnJoinChannel(User *u, Channel *c) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a new topic is set
* @param source The user changing the topic, if any
@@ -493,18 +471,18 @@ class CoreExport Module : public Extensible
* @param setter The user who set the new topic, if there is no source
* @param topic The new topic
*/
- virtual void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) { throw NotImplementedException(); }
+ virtual void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called before a channel expires
* @param ci The channel
* @param expire Set to true to allow the chan to expire
*/
- virtual void OnPreChanExpire(ChannelInfo *ci, bool &expire) { throw NotImplementedException(); }
+ virtual void OnPreChanExpire(ChannelInfo *ci, bool &expire) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called before a channel expires
* @param ci The channel
*/
- virtual void OnChanExpire(ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual void OnChanExpire(ChannelInfo *ci) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called before Anope connects to its uplink
*/
@@ -516,7 +494,7 @@ class CoreExport Module : public Extensible
/** Called when we are almost done synching with the uplink, just before we send the EOB
*/
- virtual void OnPreUplinkSync(Server *serv) { throw NotImplementedException(); }
+ virtual void OnPreUplinkSync(Server *serv) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when Anope disconnects from its uplink, before it tries to reconnect
*/
@@ -534,12 +512,12 @@ class CoreExport Module : public Extensible
* @param na The nick
* @param expire Set to true to allow the nick to expire
*/
- virtual void OnPreNickExpire(NickAlias *na, bool &expire) { throw NotImplementedException(); }
+ virtual void OnPreNickExpire(NickAlias *na, bool &expire) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a nick drops
* @param na The nick
*/
- virtual void OnNickExpire(NickAlias *na) { throw NotImplementedException(); }
+ virtual void OnNickExpire(NickAlias *na) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when defcon level changes
* @param level The level
@@ -550,13 +528,13 @@ class CoreExport Module : public Extensible
* @param ex The exception
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
- virtual EventReturn OnExceptionAdd(Exception *ex) { throw NotImplementedException(); }
+ virtual EventReturn OnExceptionAdd(Exception *ex) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called before an exception is deleted
* @param source The source deleting it
* @param ex The exception
*/
- virtual void OnExceptionDel(CommandSource &source, Exception *ex) { throw NotImplementedException(); }
+ virtual void OnExceptionDel(CommandSource &source, Exception *ex) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called before a XLine is added
* @param source The source of the XLine
@@ -564,31 +542,31 @@ class CoreExport Module : public Extensible
* @param xlm The xline manager it was added to
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
- virtual EventReturn OnAddXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { throw NotImplementedException(); }
+ virtual EventReturn OnAddXLine(CommandSource &source, const XLine *x, XLineManager *xlm) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called before a XLine is deleted
* @param source The source of the XLine
* @param x The XLine
* @param xlm The xline manager it was deleted from
*/
- virtual void OnDelXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { throw NotImplementedException(); }
+ virtual void OnDelXLine(CommandSource &source, const XLine *x, XLineManager *xlm) ATTR_NOT_NULL(4) { throw NotImplementedException(); }
/** Called when a user is checked for whether they are a services oper
* @param u The user
* @return EVENT_ALLOW to allow, anything else to deny
*/
- virtual EventReturn IsServicesOper(User *u) { throw NotImplementedException(); }
+ virtual EventReturn IsServicesOper(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a server quits
* @param server The server
*/
- virtual void OnServerQuit(Server *server) { throw NotImplementedException(); }
+ virtual void OnServerQuit(Server *server) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user quits, or is killed
* @param u The user
* @param msg The quit message
*/
- virtual void OnUserQuit(User *u, const Anope::string &msg) { throw NotImplementedException(); }
+ virtual void OnUserQuit(User *u, const Anope::string &msg) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user is quit, before and after being internally removed from
* This is different from OnUserQuit, which takes place at the time of the quit.
@@ -596,43 +574,43 @@ class CoreExport Module : public Extensible
* all lists (channels, user list, etc)
* @param u The user
*/
- virtual void OnPreUserLogoff(User *u) { throw NotImplementedException(); }
- virtual void OnPostUserLogoff(User *u) { throw NotImplementedException(); }
+ virtual void OnPreUserLogoff(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
+ virtual void OnPostUserLogoff(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a new bot is made
* @param bi The bot
*/
- virtual void OnBotCreate(BotInfo *bi) { throw NotImplementedException(); }
+ virtual void OnBotCreate(BotInfo *bi) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a bot is changed
* @param bi The bot
*/
- virtual void OnBotChange(BotInfo *bi) { throw NotImplementedException(); }
+ virtual void OnBotChange(BotInfo *bi) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a bot is deleted
* @param bi The bot
*/
- virtual void OnBotDelete(BotInfo *bi) { throw NotImplementedException(); }
+ virtual void OnBotDelete(BotInfo *bi) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called after an access entry is deleted from a channel
* @param ci The channel
* @param source The source of the command
* @param access The access entry that was removed
*/
- virtual void OnAccessDel(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { throw NotImplementedException(); }
+ virtual void OnAccessDel(ChannelInfo *ci, CommandSource &source, ChanAccess *access) ATTR_NOT_NULL(2, 4) { throw NotImplementedException(); }
/** Called when access is added
* @param ci The channel
* @param source The source of the command
* @param access The access changed
*/
- virtual void OnAccessAdd(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { throw NotImplementedException(); }
+ virtual void OnAccessAdd(ChannelInfo *ci, CommandSource &source, ChanAccess *access) ATTR_NOT_NULL(2, 4) { throw NotImplementedException(); }
/** Called when the access list is cleared
* @param ci The channel
* @param u The user who cleared the access
*/
- virtual void OnAccessClear(ChannelInfo *ci, CommandSource &source) { throw NotImplementedException(); }
+ virtual void OnAccessClear(ChannelInfo *ci, CommandSource &source) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a level for a channel is changed
* @param source The source of the command
@@ -640,63 +618,63 @@ class CoreExport Module : public Extensible
* @param priv The privilege changed
* @param what The new level
*/
- virtual void OnLevelChange(CommandSource &source, ChannelInfo *ci, const Anope::string &priv, int16_t what) { throw NotImplementedException(); }
+ virtual void OnLevelChange(CommandSource &source, ChannelInfo *ci, const Anope::string &priv, int16_t what) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called right before a channel is dropped
* @param source The user dropping the channel
* @param ci The channel
*/
- virtual EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a channel is registered
* @param ci The channel
*/
- virtual void OnChanRegistered(ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual void OnChanRegistered(ChannelInfo *ci) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a channel is suspended
* @param ci The channel
*/
- virtual void OnChanSuspend(ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual void OnChanSuspend(ChannelInfo *ci) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a channel is unsuspended
* @param ci The channel
*/
- virtual void OnChanUnsuspend(ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual void OnChanUnsuspend(ChannelInfo *ci) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a channel is being created, for any reason
* @param ci The channel
*/
- virtual void OnCreateChan(ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual void OnCreateChan(ChannelInfo *ci) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a channel is being deleted, for any reason
* @param ci The channel
*/
- virtual void OnDelChan(ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual void OnDelChan(ChannelInfo *ci) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a new channel is created
* Note that this channel may not be introduced to the uplink at this point.
* @param c The channel
*/
- virtual void OnChannelCreate(Channel *c) { throw NotImplementedException(); }
+ virtual void OnChannelCreate(Channel *c) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a channel is deleted
* @param c The channel
*/
- virtual void OnChannelDelete(Channel *c) { throw NotImplementedException(); }
+ virtual void OnChannelDelete(Channel *c) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called after adding an akick to a channel
* @param source The source of the command
* @param ci The channel
* @param ak The akick
*/
- virtual void OnAkickAdd(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) { throw NotImplementedException(); }
+ virtual void OnAkickAdd(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called before removing an akick from a channel
* @param source The source of the command
* @param ci The channel
* @param ak The akick
*/
- virtual void OnAkickDel(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) { throw NotImplementedException(); }
+ virtual void OnAkickDel(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called after a user join a channel when we decide whether to kick them or not
* @param u The user
@@ -706,7 +684,7 @@ class CoreExport Module : public Extensible
* @param reason The reason for the kick
* @return EVENT_STOP to prevent the user from joining by kicking/banning the user
*/
- virtual EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) { throw NotImplementedException(); }
+ virtual EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a user requests info for a channel
* @param source The user requesting info
@@ -714,126 +692,109 @@ class CoreExport Module : public Extensible
* @param info Data to show the user requesting information
* @param show_hidden true if we should show the user everything
*/
- virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) { throw NotImplementedException(); }
+ virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Checks if access has the channel privilege 'priv'.
* @param access THe access struct
* @param priv The privilege being checked for
* @return EVENT_ALLOW for yes, EVENT_STOP to stop all processing
*/
- virtual EventReturn OnCheckPriv(const ChanAccess *access, const Anope::string &priv) { throw NotImplementedException(); }
+ virtual EventReturn OnCheckPriv(const ChanAccess *access, const Anope::string &priv) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Check whether an access group has a privilege
* @param group The group
* @param priv The privilege
* @return MOD_ALLOW to allow, MOD_STOP to stop
*/
- virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) { throw NotImplementedException(); }
+ virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a nick is dropped
* @param source The source of the command
* @param na The nick
*/
- virtual void OnNickDrop(CommandSource &source, NickAlias *na) { throw NotImplementedException(); }
+ virtual void OnNickDrop(CommandSource &source, NickAlias *na) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a user groups their nick
* @param u The user grouping
* @param target The target they're grouping to
*/
- virtual void OnNickGroup(User *u, NickAlias *target) { throw NotImplementedException(); }
+ virtual void OnNickGroup(User *u, NickAlias *target) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a user identifies to a nick
* @param u The user
*/
- virtual void OnNickIdentify(User *u) { throw NotImplementedException(); }
+ virtual void OnNickIdentify(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user is logged into an account
* @param u The user
*/
- virtual void OnUserLogin(User *u) { throw NotImplementedException(); }
+ virtual void OnUserLogin(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a nick logs out
* @param u The nick
*/
- virtual void OnNickLogout(User *u) { throw NotImplementedException(); }
+ virtual void OnNickLogout(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a nick is registered
* @param user The user registering the nick, of any
* @param The nick
* @param pass The password of the newly registered nick
*/
- virtual void OnNickRegister(User *user, NickAlias *na, const Anope::string &pass) { throw NotImplementedException(); }
+ virtual void OnNickRegister(User *user, NickAlias *na, const Anope::string &pass) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a nick is confirmed. This will never be called if registration confirmation is not enabled.
* @param user The user confirming the nick
- * @param The account being confirmed
+ * @param nc The account being confirmed
*/
- virtual void OnNickConfirm(User *user, NickCore *) { throw NotImplementedException(); }
+ virtual void OnNickConfirm(User *user, NickCore *nc) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a nick is suspended
* @param na The nick alias
*/
- virtual void OnNickSuspend(NickAlias *na) { throw NotImplementedException(); }
+ virtual void OnNickSuspend(NickAlias *na) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a nick is unsuspended
* @param na The nick alias
*/
- virtual void OnNickUnsuspended(NickAlias *na) { throw NotImplementedException(); }
+ virtual void OnNickUnsuspended(NickAlias *na) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called on delnick()
* @ param na pointer to the nickalias
*/
- virtual void OnDelNick(NickAlias *na) { throw NotImplementedException(); }
+ virtual void OnDelNick(NickAlias *na) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a nickcore is created
* @param nc The nickcore
*/
- virtual void OnNickCoreCreate(NickCore *nc) { throw NotImplementedException(); }
+ virtual void OnNickCoreCreate(NickCore *nc) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called on delcore()
* @param nc pointer to the NickCore
*/
- virtual void OnDelCore(NickCore *nc) { throw NotImplementedException(); }
+ virtual void OnDelCore(NickCore *nc) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called on change_core_display()
* @param nc pointer to the NickCore
* @param newdisplay the new display
*/
- virtual void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) { throw NotImplementedException(); }
-
- /** called from NickCore::ClearAccess()
- * @param nc pointer to the NickCore
- */
- virtual void OnNickClearAccess(NickCore *nc) { throw NotImplementedException(); }
-
- /** Called when a user adds an entry to their access list
- * @param nc The nick
- * @param entry The entry
- */
- virtual void OnNickAddAccess(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
-
- /** Called from NickCore::EraseAccess()
- * @param nc pointer to the NickCore
- * @param entry The access mask
- */
- virtual void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
+ virtual void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** called from NickCore::ClearCert()
* @param nc pointer to the NickCore
*/
- virtual void OnNickClearCert(NickCore *nc) { throw NotImplementedException(); }
+ virtual void OnNickClearCert(NickCore *nc) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user adds an entry to their cert list
* @param nc The nick
* @param entry The entry
*/
- virtual void OnNickAddCert(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
+ virtual void OnNickAddCert(NickCore *nc, const Anope::string &entry) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called from NickCore::EraseCert()
* @param nc pointer to the NickCore
* @param entry The fingerprint
*/
- virtual void OnNickEraseCert(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); }
+ virtual void OnNickEraseCert(NickCore *nc, const Anope::string &entry) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user requests info for a nick
* @param source The user requesting info
@@ -841,55 +802,55 @@ class CoreExport Module : public Extensible
* @param info Data to show the user requesting information
* @param show_hidden true if we should show the user everything
*/
- virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) { throw NotImplementedException(); }
+ virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a user uses botserv/info on a bot or channel.
*/
- virtual void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) { throw NotImplementedException(); }
+ virtual void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) ATTR_NOT_NULL(4) { throw NotImplementedException(); }
/** Check whether a username and password is correct
* @param u The user trying to identify, if applicable.
* @param req The login request
*/
- virtual void OnCheckAuthentication(User *u, IdentifyRequest *req) { throw NotImplementedException(); }
+ virtual void OnCheckAuthentication(User *u, IdentifyRequest *req) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a user does /ns update
* @param u The user
*/
- virtual void OnNickUpdate(User *u) { throw NotImplementedException(); }
+ virtual void OnNickUpdate(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when we get informed about a users SSL fingerprint
* when we call this, the fingerprint should already be stored in the user struct
* @param u pointer to the user
*/
- virtual void OnFingerprint(User *u) { throw NotImplementedException(); }
+ virtual void OnFingerprint(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user becomes (un)away
* @param message The message, is .empty() if unaway
*/
- virtual void OnUserAway(User *u, const Anope::string &message) { throw NotImplementedException(); }
+ virtual void OnUserAway(User *u, const Anope::string &message) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user invites one of our users to a channel
* @param source The user doing the inviting
* @param c The channel the user is inviting to
* @param targ The user being invited
*/
- virtual void OnInvite(User *source, Channel *c, User *targ) { throw NotImplementedException(); }
+ virtual void OnInvite(User *source, Channel *c, User *targ) ATTR_NOT_NULL(2, 3, 4) { throw NotImplementedException(); }
/** Called when a vhost is deleted
* @param na The nickalias of the vhost
*/
- virtual void OnDeleteVhost(NickAlias *na) { throw NotImplementedException(); }
+ virtual void OnDeleteVHost(NickAlias *na) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a vhost is set
* @param na The nickalias of the vhost
*/
- virtual void OnSetVhost(NickAlias *na) { throw NotImplementedException(); }
+ virtual void OnSetVHost(NickAlias *na) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a users host changes
* @param u The user
*/
- virtual void OnSetDisplayedHost(User *) { throw NotImplementedException(); }
+ virtual void OnSetDisplayedHost(User *u) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a memo is sent
* @param source The source of the memo
@@ -897,14 +858,14 @@ class CoreExport Module : public Extensible
* @param mi Memo info for target
* @param m The memo
*/
- virtual void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) { throw NotImplementedException(); }
+ virtual void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) ATTR_NOT_NULL(4, 5) { throw NotImplementedException(); }
/** Called when a memo is deleted
* @param target The target the memo is being deleted from (nick or channel)
* @param mi The memo info
* @param m The memo
*/
- virtual void OnMemoDel(const Anope::string &target, MemoInfo *mi, const Memo *m) { throw NotImplementedException(); }
+ virtual void OnMemoDel(const Anope::string &target, MemoInfo *mi, const Memo *m) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called when a mode is set on a channel
* @param c The channel
@@ -913,7 +874,7 @@ class CoreExport Module : public Extensible
* @param param The mode param, if there is one
* @return EVENT_STOP to make mlock/secureops etc checks not happen
*/
- virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) { throw NotImplementedException(); }
+ virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) ATTR_NOT_NULL(2, 4) { throw NotImplementedException(); }
/** Called when a mode is unset on a channel
* @param c The channel
@@ -922,94 +883,97 @@ class CoreExport Module : public Extensible
* @param param The mode param, if there is one
* @return EVENT_STOP to make mlock/secureops etc checks not happen
*/
- virtual EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) { throw NotImplementedException(); }
+ virtual EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string &param) ATTR_NOT_NULL(2, 4) { throw NotImplementedException(); }
/** Called when a mode is set on a user
* @param setter who/what is setting the mode
* @param u The user
* @param mname The mode name
*/
- virtual void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) { throw NotImplementedException(); }
+ virtual void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a mode is unset from a user
* @param setter who/what is setting the mode
* @param u The user
* @param mname The mode name
*/
- virtual void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) { throw NotImplementedException(); }
+ virtual void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a channel mode is introduced into Anope
* @param cm The mode
*/
- virtual void OnChannelModeAdd(ChannelMode *cm) { throw NotImplementedException(); }
+ virtual void OnChannelModeAdd(ChannelMode *cm) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a user mode is introduced into Anope
* @param um The mode
*/
- virtual void OnUserModeAdd(UserMode *um) { throw NotImplementedException(); }
+ virtual void OnUserModeAdd(UserMode *um) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a mode is about to be mlocked
* @param ci The channel the mode is being locked on
* @param lock The mode lock
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
*/
- virtual EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) { throw NotImplementedException(); }
+ virtual EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a mode is about to be unlocked
* @param ci The channel the mode is being unlocked from
* @param lock The mode lock
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
*/
- virtual EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) { throw NotImplementedException(); }
+ virtual EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called after a module is loaded
* @param u The user loading the module, can be NULL
* @param m The module
*/
- virtual void OnModuleLoad(User *u, Module *m) { throw NotImplementedException(); }
+ virtual void OnModuleLoad(User *u, Module *m) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called before a module is unloaded
* @param u The user, can be NULL
* @param m The module
*/
- virtual void OnModuleUnload(User *u, Module *m) { throw NotImplementedException(); }
+ virtual void OnModuleUnload(User *u, Module *m) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a server is synced
* @param s The server, can be our uplink server
*/
- virtual void OnServerSync(Server *s) { throw NotImplementedException(); }
+ virtual void OnServerSync(Server *s) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when we sync with our uplink
* @param s Our uplink
*/
- virtual void OnUplinkSync(Server *s) { throw NotImplementedException(); }
+ virtual void OnUplinkSync(Server *s) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when we receive a PRIVMSG for one of our clients
* @param u The user sending the PRIVMSG
* @param bi The target of the PRIVMSG
* @param message The message
+ * @param tags Message tags
* @return EVENT_STOP to halt processing
*/
- virtual EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) { throw NotImplementedException(); }
+ virtual EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message, const Anope::map<Anope::string> &tags) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when we receive a NOTICE for one of our clients
* @param u The user sending the NOTICE
* @param bi The target of the NOTICE
+ * @param tags Message tags
* @param message The message
*/
- virtual void OnBotNotice(User *u, BotInfo *bi, Anope::string &message) { throw NotImplementedException(); }
+ virtual void OnBotNotice(User *u, BotInfo *bi, Anope::string &message, const Anope::map<Anope::string> &tags) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when we receive a PRIVMSG for a registered channel we are in
* @param u The source of the message
* @param c The channel
* @param msg The message
+ * @param tags Message tags
*/
- virtual void OnPrivmsg(User *u, Channel *c, Anope::string &msg) { throw NotImplementedException(); }
+ virtual void OnPrivmsg(User *u, Channel *c, Anope::string &msg, const Anope::map<Anope::string> &tags) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a message is logged
* @param l The log message
*/
- virtual void OnLog(Log *l) { throw NotImplementedException(); }
+ virtual void OnLog(Log *l) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a log message is actually logged to a given log info
* The message has already passed validation checks by the LogInfo
@@ -1017,13 +981,13 @@ class CoreExport Module : public Extensible
* @param l The log message
* @param msg The final formatted message, derived from 'l'
*/
- virtual void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) { throw NotImplementedException(); }
+ virtual void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
/** Called when a DNS request (question) is received.
* @param req The dns request
* @param reply The reply that will be sent
*/
- virtual void OnDnsRequest(DNS::Query &req, DNS::Query *reply) { throw NotImplementedException(); }
+ virtual void OnDnsRequest(DNS::Query &req, DNS::Query *reply) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a channels modes are being checked to see if they are allowed,
* mostly to ensure mlock/+r are set.
@@ -1036,7 +1000,7 @@ class CoreExport Module : public Extensible
* for a newly created channel to set the correct modes, topic,
* set.
*/
- virtual void OnChannelSync(Channel *c) { throw NotImplementedException(); }
+ virtual void OnChannelSync(Channel *c) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called to set the correct modes on the user on the given channel
* @param user The user
@@ -1045,13 +1009,13 @@ class CoreExport Module : public Extensible
* @param give_modes If giving modes is desired
* @param take_modes If taking modes is desired
*/
- virtual void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) { throw NotImplementedException(); }
+ virtual void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
- virtual void OnSerializeCheck(Serialize::Type *) { throw NotImplementedException(); }
- virtual void OnSerializableConstruct(Serializable *) { throw NotImplementedException(); }
- virtual void OnSerializableDestruct(Serializable *) { throw NotImplementedException(); }
- virtual void OnSerializableUpdate(Serializable *) { throw NotImplementedException(); }
- virtual void OnSerializeTypeCreate(Serialize::Type *) { throw NotImplementedException(); }
+ virtual void OnSerializeCheck(Serialize::Type *st) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
+ virtual void OnSerializableConstruct(Serializable *st) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
+ virtual void OnSerializableDestruct(Serializable *st) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
+ virtual void OnSerializableUpdate(Serializable *st) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
+ virtual void OnSerializeTypeCreate(Serialize::Type *st) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called when a chanserv/set command is used
* @param source The source of the command
@@ -1060,7 +1024,7 @@ class CoreExport Module : public Extensible
* @param setting The setting passed to the command. Probably ON/OFF.
* @return EVENT_ALLOW to bypass access checks, EVENT_STOP to halt immediately.
*/
- virtual EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) { throw NotImplementedException(); }
+ virtual EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called when a nickserv/set command is used.
* @param source The source of the command
@@ -1069,23 +1033,24 @@ class CoreExport Module : public Extensible
* @param setting The setting passed to the command. Probably ON/OFF.
* @return EVENT_STOP to halt immediately
*/
- virtual EventReturn OnSetNickOption(CommandSource &source, Command *cmd, NickCore *nc, const Anope::string &setting) { throw NotImplementedException(); }
+ virtual EventReturn OnSetNickOption(CommandSource &source, Command *cmd, NickCore *nc, const Anope::string &setting) ATTR_NOT_NULL(3, 4) { throw NotImplementedException(); }
/** Called whenever a message is received from the uplink
* @param source The source of the message
* @param command The command being executed
* @param params Parameters
+ * @param tags Tags
* @return EVENT_STOP to prevent the protocol module from processing this message
*/
- virtual EventReturn OnMessage(MessageSource &source, Anope::string &command, std::vector<Anope::string> &param) { throw NotImplementedException(); }
+ virtual EventReturn OnMessage(MessageSource &source, Anope::string &command, std::vector<Anope::string> &params, Anope::map<Anope::string> &tagss) { throw NotImplementedException(); }
/** Called to determine if a channel mode can be set by a user
* @param u The user
* @param cm The mode
*/
- virtual EventReturn OnCanSet(User *u, const ChannelMode *cm) { throw NotImplementedException(); }
+ virtual EventReturn OnCanSet(User *u, const ChannelMode *cm) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
- virtual EventReturn OnCheckDelete(Channel *) { throw NotImplementedException(); }
+ virtual EventReturn OnCheckDelete(Channel *c) ATTR_NOT_NULL(2) { throw NotImplementedException(); }
/** Called every options:expiretimeout seconds. Should be used to expire nicks,
* channels, etc.
@@ -1098,14 +1063,7 @@ class CoreExport Module : public Extensible
* @param na The nick they are on
* @return EVENT_STOP to force the user off of the nick
*/
- virtual EventReturn OnNickValidate(User *u, NickAlias *na) { throw NotImplementedException(); }
-
- /** Called when a certain user has to be unbanned on a certain channel.
- * May be used to send protocol-specific messages.
- * @param u The user to be unbanned
- * @param c The channel that user has to be unbanned on
- */
- virtual void OnChannelUnban(User *u, ChannelInfo *ci) { throw NotImplementedException(); }
+ virtual EventReturn OnNickValidate(User *u, NickAlias *na) ATTR_NOT_NULL(2, 3) { throw NotImplementedException(); }
};
enum Implementation
@@ -1123,23 +1081,23 @@ enum Implementation
I_OnCreateChan, I_OnDelChan, I_OnChannelCreate, I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick,
I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv, I_OnNickDrop, I_OnNickGroup, I_OnNickIdentify,
I_OnUserLogin, I_OnNickLogout, I_OnNickRegister, I_OnNickConfirm, I_OnNickSuspend, I_OnNickUnsuspended, I_OnDelNick, I_OnNickCoreCreate,
- I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearCert,
+ I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickClearCert,
I_OnNickAddCert, I_OnNickEraseCert, I_OnNickInfo, I_OnBotInfo, I_OnCheckAuthentication, I_OnNickUpdate,
- I_OnFingerprint, I_OnUserAway, I_OnInvite, I_OnDeleteVhost, I_OnSetVhost, I_OnSetDisplayedHost, I_OnMemoSend, I_OnMemoDel,
+ I_OnFingerprint, I_OnUserAway, I_OnInvite, I_OnDeleteVHost, I_OnSetVHost, I_OnSetDisplayedHost, I_OnMemoSend, I_OnMemoDel,
I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd,
I_OnMLock, I_OnUnMLock, I_OnModuleLoad, I_OnModuleUnload, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnBotNotice,
I_OnPrivmsg, I_OnLog, I_OnLogMessage, I_OnDnsRequest, I_OnCheckModes, I_OnChannelSync, I_OnSetCorrectModes,
I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate,
I_OnSerializeTypeCreate, I_OnSetChannelOption, I_OnSetNickOption, I_OnMessage, I_OnCanSet, I_OnCheckDelete,
- I_OnExpireTick, I_OnNickValidate, I_OnChannelUnban,
+ I_OnExpireTick, I_OnNickValidate,
I_SIZE
};
/** Used to manage modules.
*/
-class CoreExport ModuleManager
+class CoreExport ModuleManager final
{
- public:
+public:
/** Event handler hooks.
*/
static std::vector<Module *> EventHandlers[I_SIZE];
@@ -1222,7 +1180,7 @@ class CoreExport ModuleManager
*/
static void UnloadAll();
- private:
+private:
/** Call the module_delete function to safely delete the module
* @param m the module to delete
* @return MOD_ERR_OK on success, anything else on fail
@@ -1234,5 +1192,3 @@ class CoreExport ModuleManager
*/
static ModuleVersion GetVersion(void *handle);
};
-
-#endif // MODULES_H
diff --git a/include/modules/bs_badwords.h b/include/modules/bs_badwords.h
index db5e6c461..ae78df8b1 100644
--- a/include/modules/bs_badwords.h
+++ b/include/modules/bs_badwords.h
@@ -9,6 +9,8 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
/** Flags for badwords
*/
enum BadWordType
@@ -30,27 +32,27 @@ struct BadWord
Anope::string word;
BadWordType type;
- virtual ~BadWord() { }
- protected:
- BadWord() { }
+ virtual ~BadWord() = default;
+protected:
+ BadWord() = default;
};
struct BadWords
{
- virtual ~BadWords() { }
+ virtual ~BadWords() = default;
/** Add a badword to the badword list
* @param word The badword
* @param type The type (SINGLE START END)
* @return The badword
*/
- virtual BadWord* AddBadWord(const Anope::string &word, BadWordType type) = 0;
+ virtual BadWord *AddBadWord(const Anope::string &word, BadWordType type) = 0;
/** Get a badword structure by index
* @param index The index
* @return The badword
*/
- virtual BadWord* GetBadWord(unsigned index) const = 0;
+ virtual BadWord *GetBadWord(unsigned index) const = 0;
/** Get how many badwords are on this channel
* @return The number of badwords in the vector
diff --git a/include/modules/bs_kick.h b/include/modules/bs_kick.h
index e9bcc7fdf..8ad44aab5 100644
--- a/include/modules/bs_kick.h
+++ b/include/modules/bs_kick.h
@@ -9,6 +9,8 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
/* Indices for TTB (Times To Ban) */
enum
{
@@ -35,10 +37,10 @@ struct KickerData
bool dontkickops, dontkickvoices;
- protected:
- KickerData() { }
+protected:
+ KickerData() = default;
- public:
- virtual ~KickerData() { }
+public:
+ virtual ~KickerData() = default;
virtual void Check(ChannelInfo *ci) = 0;
};
diff --git a/include/modules/cs_entrymsg.h b/include/modules/cs_entrymsg.h
index a7ec337e0..2672f8ac0 100644
--- a/include/modules/cs_entrymsg.h
+++ b/include/modules/cs_entrymsg.h
@@ -6,6 +6,8 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
struct EntryMsg
{
Anope::string chan;
@@ -13,22 +15,23 @@ struct EntryMsg
Anope::string message;
time_t when;
- virtual ~EntryMsg() { }
- protected:
- EntryMsg() { }
+ virtual ~EntryMsg() = default;
+protected:
+ EntryMsg() = default;
};
-struct EntryMessageList : Serialize::Checker<std::vector<EntryMsg *> >
+struct EntryMessageList
+ : Serialize::Checker<std::vector<EntryMsg *> >
{
- protected:
+protected:
EntryMessageList() : Serialize::Checker<std::vector<EntryMsg *> >("EntryMsg") { }
- public:
+public:
virtual ~EntryMessageList()
{
for (unsigned i = (*this)->size(); i > 0; --i)
delete (*this)->at(i - 1);
}
- virtual EntryMsg* Create() = 0;
+ virtual EntryMsg *Create() = 0;
};
diff --git a/include/modules/cs_log.h b/include/modules/cs_log.h
index 1615c5b9f..f9549126b 100644
--- a/include/modules/cs_log.h
+++ b/include/modules/cs_log.h
@@ -9,6 +9,8 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
struct LogSetting
{
Anope::string chan;
@@ -22,21 +24,22 @@ struct LogSetting
Anope::string creator;
time_t created;
- virtual ~LogSetting() { }
- protected:
- LogSetting() { }
+ virtual ~LogSetting() = default;
+protected:
+ LogSetting() = default;
};
-struct LogSettings : Serialize::Checker<std::vector<LogSetting *> >
+struct LogSettings
+ : Serialize::Checker<std::vector<LogSetting *> >
{
typedef std::vector<LogSetting *>::iterator iterator;
- protected:
+protected:
LogSettings() : Serialize::Checker<std::vector<LogSetting *> >("LogSetting")
{
}
- public:
- virtual ~LogSettings() { }
+public:
+ virtual ~LogSettings() = default;
virtual LogSetting *Create() = 0;
};
diff --git a/include/modules/cs_mode.h b/include/modules/cs_mode.h
index 9ef04da68..f3668c004 100644
--- a/include/modules/cs_mode.h
+++ b/include/modules/cs_mode.h
@@ -9,6 +9,8 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
struct ModeLock
{
Anope::string ci;
@@ -18,16 +20,16 @@ struct ModeLock
Anope::string setter;
time_t created;
- virtual ~ModeLock() { }
- protected:
- ModeLock() { }
+ virtual ~ModeLock() = default;
+protected:
+ ModeLock() = default;
};
struct ModeLocks
{
typedef std::vector<ModeLock *> ModeList;
- virtual ~ModeLocks() { }
+ virtual ~ModeLocks() = default;
/** Check if a mode is mlocked
* @param mode The mode
diff --git a/include/modules/dns.h b/include/modules/dns.h
index 1aee0623e..1ab18a20f 100644
--- a/include/modules/dns.h
+++ b/include/modules/dns.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef DNS_H
-#define DNS_H
+#pragma once
namespace DNS
{
@@ -73,14 +72,14 @@ namespace DNS
struct Question
{
Anope::string name;
- QueryType type;
- unsigned short qclass;
+ QueryType type = QUERY_NONE;
+ unsigned short qclass = 0;
- Question() : type(QUERY_NONE), qclass(0) { }
+ Question() = default;
Question(const Anope::string &n, QueryType t, unsigned short c = 1) : name(n), type(t), qclass(c) { }
inline bool operator==(const Question & other) const { return name == other.name && type == other.type && qclass == other.qclass; }
- struct hash
+ struct hash final
{
size_t operator()(const Question &q) const
{
@@ -89,14 +88,15 @@ namespace DNS
};
};
- struct ResourceRecord : Question
+ struct ResourceRecord final
+ : Question
{
- unsigned int ttl;
+ unsigned int ttl = 0;
Anope::string rdata;
time_t created;
- ResourceRecord(const Anope::string &n, QueryType t, unsigned short c = 1) : Question(n, t, c), ttl(0), created(Anope::CurTime) { }
- ResourceRecord(const Question &q) : Question(q), ttl(0), created(Anope::CurTime) { }
+ ResourceRecord(const Anope::string &n, QueryType t, unsigned short c = 1) : Question(n, t, c), created(Anope::CurTime) { }
+ ResourceRecord(const Question &q) : Question(q), created(Anope::CurTime) { }
};
struct Query
@@ -114,11 +114,12 @@ namespace DNS
/** DNS manager
*/
- class Manager : public Service
+ class Manager
+ : public Service
{
- public:
+ public:
Manager(Module *creator) : Service(creator, "DNS::Manager", "dns/manager") { }
- virtual ~Manager() { }
+ virtual ~Manager() = default;
virtual void Process(Request *req) = 0;
virtual void RemoveRequest(Request *req) = 0;
@@ -132,19 +133,27 @@ namespace DNS
/** A DNS query.
*/
- class Request : public Timer, public Question
+ class Request
+ : public Timer
+ , public Question
{
Manager *manager;
- public:
+ public:
/* Use result cache if available */
bool use_cache;
/* Request id */
- unsigned short id;
+ unsigned short id = 0;
/* Creator of this request */
Module *creator;
- Request(Manager *mgr, Module *c, const Anope::string &addr, QueryType qt, bool cache = false) : Timer(0), Question(addr, qt), manager(mgr),
- use_cache(cache), id(0), creator(c) { }
+ Request(Manager *mgr, Module *c, const Anope::string &addr, QueryType qt, bool cache = false)
+ : Timer(0)
+ , Question(addr, qt)
+ , manager(mgr)
+ , use_cache(cache)
+ , creator(c)
+ {
+ }
virtual ~Request()
{
@@ -164,7 +173,7 @@ namespace DNS
/** Used to time out the query, xalls OnError and lets the TimerManager
* delete this request.
*/
- void Tick(time_t) anope_override
+ void Tick() override
{
Log(LOG_DEBUG_2) << "Resolver: timeout for query " << this->name;
Query rr(*this);
@@ -174,5 +183,3 @@ namespace DNS
};
} // namespace DNS
-
-#endif // DNS_H
diff --git a/include/modules/encryption.h b/include/modules/encryption.h
index 7f8988c09..9c5b58627 100644
--- a/include/modules/encryption.h
+++ b/include/modules/encryption.h
@@ -9,27 +9,139 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
namespace Encryption
{
- typedef std::pair<const unsigned char *, size_t> Hash;
- typedef std::pair<const uint32_t *, size_t> IV;
-
+ /** Base class for encryption contexts. */
class Context
{
- public:
- virtual ~Context() { }
+ public:
+ virtual ~Context() = default;
+
+ /** Updates the encryption context with the specified data.
+ * @param str The data to update the context with.
+ */
+ inline void Update(const Anope::string &str)
+ {
+ Update(reinterpret_cast<const unsigned char *>(str.c_str()), str.length());
+ }
+
+ /** Updates the encryption context with the specified data.
+ * @param data The data to update the context with.
+ * @param len The length of the data.
+ */
virtual void Update(const unsigned char *data, size_t len) = 0;
- virtual void Finalize() = 0;
- virtual Hash GetFinalizedHash() = 0;
+
+ /** Finalises the encryption context and returns the digest. */
+ virtual Anope::string Finalize() = 0;
+ };
+
+ /** Provider of encryption contexts. */
+ class Provider
+ : public Service
+ {
+ public:
+ /** The byte size of the block cipher. */
+ const size_t block_size;
+
+ /** The byte size of the resulting digest. */
+ const size_t digest_size;
+
+ /** Creates a provider of encryption contexts.
+ * @param creator The module that created this provider.
+ * @param algorithm The name of the encryption algorithm.
+ * @param bs The byte size of the block cipher.
+ * @param ds The byte size of the resulting digest.
+ */
+ Provider(Module *creator, const Anope::string &algorithm, size_t bs, size_t ds)
+ : Service(creator, "Encryption::Provider", algorithm)
+ , block_size(bs)
+ , digest_size(ds)
+ {
+ }
+
+ virtual ~Provider() = default;
+
+ /** Checks whether a plain text value matches a hash created by this provider. */
+ virtual bool Compare(const Anope::string &hash, const Anope::string &plain)
+ {
+ return !hash.empty() && hash.equals_cs(ToPrintable(Encrypt(plain)));
+ }
+
+ /** Called on initialising a encryption provider to check it works properly. */
+ void Check(const Anope::map<Anope::string> &checks)
+ {
+ for (const auto &[hash, plain] : checks)
+ {
+ if (!Compare(hash, plain))
+ throw ModuleException("BUG: unable to generate " + this->name + " hashes safely! Please report this!");
+ }
+ Log(LOG_DEBUG) << "The " << this->name << " encryption provider appears to be working correctly.";
+ }
+
+ /** Creates a new encryption context. */
+ virtual std::unique_ptr<Context> CreateContext() = 0;
+
+ /** Quickly encrypts the specified values and returns the digest. */
+ template<typename... Args>
+ Anope::string Encrypt(Args &&...args)
+ {
+ auto context = CreateContext();
+ context->Update(std::forward<Args>(args)...);
+ return context->Finalize();
+ }
+
+ /** Calculates the RFC 2104 hash-based message authentication code for the specified data. */
+ inline Anope::string HMAC(const Anope::string &key, const Anope::string &data)
+ {
+ if (!block_size)
+ return {};
+
+ auto keybuf = key.length() > block_size ? Encrypt(key) : key;
+ keybuf.resize(block_size);
+
+ Anope::string hmac1;
+ Anope::string hmac2;
+ for (size_t i = 0; i < block_size; ++i)
+ {
+ hmac1.push_back(static_cast<char>(keybuf[i] ^ 0x5C));
+ hmac2.push_back(static_cast<char>(keybuf[i] ^ 0x36));
+ }
+ hmac2.append(data);
+ hmac1.append(Encrypt(hmac2));
+
+ return Encrypt(hmac1);
+ }
+
+ /** Converts a hash to its printable form. */
+ virtual Anope::string ToPrintable(const Anope::string &hash)
+ {
+ return Anope::Hex(hash);
+ }
};
- class Provider : public Service
+ /** Helper template for creating simple providers of encryption contexts. */
+ template <typename T>
+ class SimpleProvider final
+ : public Provider
{
- public:
- Provider(Module *creator, const Anope::string &sname) : Service(creator, "Encryption::Provider", sname) { }
- virtual ~Provider() { }
+ public:
+ /** Creates a simple provider of encryption contexts.
+ * @param creator The module that created this provider.
+ * @param algorithm The name of the encryption algorithm.
+ * @param bs The byte size of the block cipher.
+ * @param ds The byte size of the resulting digest.
+ */
+ SimpleProvider(Module *creator, const Anope::string &algorithm, size_t bs, size_t ds)
+ : Provider(creator, algorithm, bs, ds)
+ {
+ }
- virtual Context *CreateContext(IV * = NULL) = 0;
- virtual IV GetDefaultIV() = 0;
+ /** @copydoc Encryption::Provider::CreateContext. */
+ std::unique_ptr<Context> CreateContext() override
+ {
+ return std::make_unique<T>();
+ }
};
}
diff --git a/include/modules/hs_request.h b/include/modules/hs_request.h
new file mode 100644
index 000000000..a1805a298
--- /dev/null
+++ b/include/modules/hs_request.h
@@ -0,0 +1,23 @@
+/*
+ *
+ * (C) 2003-2025 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#pragma once
+
+class HostRequest
+{
+protected:
+ HostRequest() = default;
+
+public:
+ Anope::string nick;
+ Anope::string ident;
+ Anope::string host;
+ time_t time = 0;
+
+ virtual ~HostRequest() = default;
+};
diff --git a/include/modules/httpd.h b/include/modules/httpd.h
index bd2bde4a0..5b555fbab 100644
--- a/include/modules/httpd.h
+++ b/include/modules/httpd.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef ANOPE_HTTPD_H
-#define ANOPE_HTTPD_H
+#pragma once
enum HTTPError
{
@@ -19,34 +18,35 @@ enum HTTPError
};
/* A message to someone */
-struct HTTPReply
+struct HTTPReply final
{
- HTTPError error;
+ HTTPError error = HTTP_ERROR_OK;
Anope::string content_type;
std::map<Anope::string, Anope::string, ci::less> headers;
typedef std::list<std::pair<Anope::string, Anope::string> > cookie;
std::vector<cookie> cookies;
- HTTPReply() : error(HTTP_ERROR_OK), length(0) { }
+ HTTPReply() = default;
+ HTTPReply &operator=(const HTTPReply &) = default;
- HTTPReply(const HTTPReply& other) : error(other.error), length(other.length)
+ 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));
+ for (const auto &datum : other.out)
+ out.push_back(new Data(datum->buf, datum->len));
}
~HTTPReply()
{
- for (unsigned i = 0; i < out.size(); ++i)
- delete out[i];
+ for (const auto *datum : out)
+ delete datum;
out.clear();
}
- struct Data
+ struct Data final
{
char *buf;
size_t len;
@@ -65,7 +65,7 @@ struct HTTPReply
};
std::deque<Data *> out;
- size_t length;
+ size_t length = 0;
void Write(const Anope::string &message)
{
@@ -81,7 +81,7 @@ struct HTTPReply
};
/* A message from someone */
-struct HTTPMessage
+struct HTTPMessage final
{
std::map<Anope::string, Anope::string> headers;
std::map<Anope::string, Anope::string> cookies;
@@ -93,12 +93,13 @@ struct HTTPMessage
class HTTPClient;
class HTTPProvider;
-class HTTPPage : public Base
+class HTTPPage
+ : public virtual Base
{
Anope::string url;
Anope::string content_type;
- public:
+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; }
@@ -115,15 +116,18 @@ class HTTPPage : public Base
virtual bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) = 0;
};
-class HTTPClient : public ClientSocket, public BinarySocket, public Base
+class HTTPClient
+ : public ClientSocket
+ , public BinarySocket
+ , public Base
{
- protected:
+protected:
void WriteClient(const Anope::string &message)
{
BinarySocket::Write(message + "\r\n");
}
- public:
+public:
HTTPClient(ListenSocket *l, int f, const sockaddrs &a) : ClientSocket(l, a), BinarySocket() { }
virtual const Anope::string GetIP()
@@ -135,12 +139,14 @@ class HTTPClient : public ClientSocket, public BinarySocket, public Base
virtual void SendReply(HTTPReply *) = 0;
};
-class HTTPProvider : public ListenSocket, public Service
+class HTTPProvider
+ : public ListenSocket
+ , public Service
{
Anope::string ip;
unsigned short port;
bool ssl;
- public:
+public:
std::vector<Anope::string> ext_ips;
std::vector<Anope::string> ext_headers;
@@ -163,7 +169,7 @@ class HTTPProvider : public ListenSocket, public Service
virtual bool RegisterPage(HTTPPage *page) = 0;
virtual void UnregisterPage(HTTPPage *page) = 0;
- virtual HTTPPage* FindPage(const Anope::string &name) = 0;
+ virtual HTTPPage *FindPage(const Anope::string &name) = 0;
};
namespace HTTPUtils
@@ -174,7 +180,7 @@ namespace HTTPUtils
for (unsigned i = 0; i < url.length(); ++i)
{
- const char& c = url[i];
+ const char &c = url[i];
if (c == '%' && i + 2 < url.length())
{
@@ -196,10 +202,8 @@ namespace HTTPUtils
{
Anope::string encoded;
- for (unsigned i = 0; i < url.length(); ++i)
+ for (const auto c : url)
{
- const char& c = url[i];
-
if (isalnum(c) || c == '.' || c == '-' || c == '*' || c == '_')
encoded += c;
else if (c == ' ')
@@ -215,9 +219,9 @@ namespace HTTPUtils
{
Anope::string dst;
- for (unsigned i = 0; i < src.length(); ++i)
+ for (const auto c : src)
{
- switch (src[i])
+ switch (c)
{
case '<':
dst += "&lt;";
@@ -232,12 +236,10 @@ namespace HTTPUtils
dst += "&amp;";
break;
default:
- dst += src[i];
+ dst += c;
}
}
return dst;
}
}
-
-#endif // ANOPE_HTTPD_H
diff --git a/include/modules/info.h b/include/modules/info.h
new file mode 100644
index 000000000..c38cf0b72
--- /dev/null
+++ b/include/modules/info.h
@@ -0,0 +1,49 @@
+/*
+ *
+ * (C) 2003-2025 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#pragma once
+
+class OperInfo
+{
+protected:
+ OperInfo() = default;
+
+ OperInfo(const Anope::string &t, const Anope::string &i, const Anope::string &a, time_t c)
+ : target(t)
+ , info(i)
+ , adder(a)
+ , created(c)
+ {
+ }
+
+public:
+ Anope::string target;
+ Anope::string info;
+ Anope::string adder;
+ time_t created = 0;
+
+ virtual ~OperInfo() = default;
+};
+
+class OperInfoList
+ : public Serialize::Checker<std::vector<OperInfo *>>
+{
+public:
+ OperInfoList()
+ : Serialize::Checker<std::vector<OperInfo *>>("OperInfo")
+ {
+ }
+
+ virtual ~OperInfoList()
+ {
+ for (auto *info : *(*this))
+ delete info;
+ }
+
+ virtual OperInfo *Create() = 0;
+};
diff --git a/include/modules/ldap.h b/include/modules/ldap.h
index cc5a21b34..f982ea1ca 100644
--- a/include/modules/ldap.h
+++ b/include/modules/ldap.h
@@ -6,18 +6,17 @@
* Please read COPYING and README for further details.
*/
-#ifndef ANOPE_LDAP_H
-#define ANOPE_LDAP_H
+#pragma once
-class LDAPException : public ModuleException
+class DllExport LDAPException : public ModuleException
{
- public:
+public:
LDAPException(const Anope::string &reason) : ModuleException(reason) { }
- virtual ~LDAPException() throw() { }
+ virtual ~LDAPException() noexcept = default;
};
-struct LDAPModification
+struct LDAPModification final
{
enum LDAPOperation
{
@@ -32,7 +31,8 @@ struct LDAPModification
};
typedef std::vector<LDAPModification> LDAPMods;
-struct LDAPAttributes : public std::map<Anope::string, std::vector<Anope::string> >
+struct LDAPAttributes final
+ : public std::map<Anope::string, std::vector<Anope::string>>
{
size_t size(const Anope::string &attr) const
{
@@ -43,8 +43,8 @@ struct LDAPAttributes : public std::map<Anope::string, std::vector<Anope::string
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);
+ for (const auto &[key, _] : *this)
+ k.push_back(key);
return k;
}
@@ -75,7 +75,7 @@ enum QueryType
QUERY_MODIFY
};
-struct LDAPResult
+struct LDAPResult final
{
std::vector<LDAPAttributes> messages;
Anope::string error;
@@ -112,20 +112,21 @@ struct LDAPResult
class LDAPInterface
{
- public:
+public:
Module *owner;
LDAPInterface(Module *m) : owner(m) { }
- virtual ~LDAPInterface() { }
+ virtual ~LDAPInterface() = default;
virtual void OnResult(const LDAPResult &r) = 0;
virtual void OnError(const LDAPResult &err) = 0;
virtual void OnDelete() { }
};
-class LDAPProvider : public Service
+class LDAPProvider
+ : public Service
{
- public:
+public:
LDAPProvider(Module *c, const Anope::string &n) : Service(c, "LDAPProvider", n) { }
/** Attempt to bind to the LDAP server as an admin
@@ -167,5 +168,3 @@ class LDAPProvider : public Service
*/
virtual void Modify(LDAPInterface *i, const Anope::string &base, LDAPMods &attributes) = 0;
};
-
-#endif // ANOPE_LDAP_H
diff --git a/include/modules/ns_cert.h b/include/modules/ns_cert.h
index 3fbe6b087..9462d66a0 100644
--- a/include/modules/ns_cert.h
+++ b/include/modules/ns_cert.h
@@ -9,12 +9,14 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
struct NSCertList
{
- protected:
- NSCertList() { }
- public:
- virtual ~NSCertList() { }
+protected:
+ NSCertList() = default;
+public:
+ virtual ~NSCertList() = default;
/** Add an entry to the nick's certificate list
*
@@ -52,6 +54,15 @@ struct NSCertList
*/
virtual void EraseCert(const Anope::string &entry) = 0;
+ /** Replaces a fingerprint in the nick's certificate list
+ *
+ * @param oldentry The old fingerprint to remove
+ * @param newentry The new fingerprint to add
+ *
+ * Replaces the specified fingerprint in the cert list.
+ */
+ virtual void ReplaceCert(const Anope::string &oldentry, const Anope::string &newentry) = 0;
+
/** Clears the entire nick's cert list
*
* Deletes all the memory allocated in the certificate list vector and then clears the vector.
@@ -61,10 +72,12 @@ struct NSCertList
virtual void Check() = 0;
};
-class CertService : public Service
+class CertService
+ : public Service
{
- public:
+public:
CertService(Module *c) : Service(c, "CertService", "certs") { }
- virtual NickCore* FindAccountFromCert(const Anope::string &cert) = 0;
+ virtual NickCore *FindAccountFromCert(const Anope::string &cert) = 0;
+ virtual void ReplaceCert(const Anope::string &oldcert, const Anope::string &newcert) = 0;
};
diff --git a/include/modules/os_forbid.h b/include/modules/os_forbid.h
index da3f8f62c..5c2f9d05c 100644
--- a/include/modules/os_forbid.h
+++ b/include/modules/os_forbid.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef OS_FORBID_H
-#define OS_FORBID_H
+#pragma once
enum ForbidType
{
@@ -23,25 +22,26 @@ struct ForbidData
Anope::string mask;
Anope::string creator;
Anope::string reason;
- time_t created;
- time_t expires;
+ time_t created = 0;
+ time_t expires = 0;
ForbidType type;
- virtual ~ForbidData() { }
- protected:
- ForbidData() : created(0), expires(0) { }
+ virtual ~ForbidData() = default;
+protected:
+ ForbidData() = default;
};
-class ForbidService : public Service
+class ForbidService
+ : public Service
{
- public:
+public:
ForbidService(Module *m) : Service(m, "ForbidService", "forbid") { }
virtual void AddForbid(ForbidData *d) = 0;
virtual void RemoveForbid(ForbidData *d) = 0;
- virtual ForbidData* CreateForbid() = 0;
+ virtual ForbidData *CreateForbid() = 0;
virtual ForbidData *FindForbid(const Anope::string &mask, ForbidType type) = 0;
@@ -51,5 +51,3 @@ class ForbidService : public Service
};
static ServiceReference<ForbidService> forbid_service("ForbidService", "forbid");
-
-#endif
diff --git a/include/modules/os_ignore.h b/include/modules/os_ignore.h
index a36d8264d..8a60a044f 100644
--- a/include/modules/os_ignore.h
+++ b/include/modules/os_ignore.h
@@ -9,24 +9,27 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
struct IgnoreData
{
Anope::string mask;
Anope::string creator;
Anope::string reason;
- time_t time; /* When do we stop ignoring them? */
+ time_t time = 0; /* When do we stop ignoring them? */
- virtual ~IgnoreData() { }
- protected:
- IgnoreData() : time(0) { }
+ virtual ~IgnoreData() = default;
+protected:
+ IgnoreData() = default;
};
-class IgnoreService : public Service
+class IgnoreService
+ : public Service
{
- protected:
+protected:
IgnoreService(Module *c) : Service(c, "IgnoreService", "ignore") { }
- public:
+public:
virtual void AddIgnore(IgnoreData *) = 0;
virtual void DelIgnore(IgnoreData *) = 0;
diff --git a/include/modules/os_news.h b/include/modules/os_news.h
index 2c488babf..815c71db6 100644
--- a/include/modules/os_news.h
+++ b/include/modules/os_news.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef OS_NEWS
-#define OS_NEWS
+#pragma once
enum NewsType
{
@@ -16,14 +15,15 @@ enum NewsType
NEWS_OPER
};
-struct NewsMessages
+struct NewsMessages final
{
NewsType type;
Anope::string name;
const char *msgs[10];
};
-struct NewsItem : Serializable
+struct NewsItem
+ : Serializable
{
NewsType type;
Anope::string text;
@@ -33,9 +33,10 @@ struct NewsItem : Serializable
NewsItem() : Serializable("NewsItem") { }
};
-class NewsService : public Service
+class NewsService
+ : public Service
{
- public:
+public:
NewsService(Module *m) : Service(m, "NewsService", "news") { }
virtual NewsItem *CreateNewsItem() = 0;
@@ -48,5 +49,3 @@ class NewsService : public Service
};
static ServiceReference<NewsService> news_service("NewsService", "news");
-
-#endif // OS_NEWS
diff --git a/include/modules/os_oper.h b/include/modules/os_oper.h
new file mode 100644
index 000000000..154b6af08
--- /dev/null
+++ b/include/modules/os_oper.h
@@ -0,0 +1,46 @@
+/*
+ *
+ * (C) 2011-2025 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#pragma once
+
+struct MyOper final
+ : Oper
+ , Serializable
+{
+ MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { }
+
+ void Serialize(Serialize::Data &data) const override
+ {
+ data.Store("name", this->name);
+ data.Store("type", this->ot->GetName());
+ }
+
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
+ {
+ Anope::string stype, sname;
+
+ data["type"] >> stype;
+ data["name"] >> sname;
+
+ OperType *ot = OperType::Find(stype);
+ if (ot == NULL)
+ return NULL;
+ NickCore *nc = NickCore::Find(sname);
+ if (nc == NULL)
+ return NULL;
+
+ MyOper *myo;
+ if (obj)
+ myo = anope_dynamic_static_cast<MyOper *>(obj);
+ else
+ myo = new MyOper(nc->display, ot);
+ nc->o = myo;
+ Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName();
+ return myo;
+ }
+};
diff --git a/include/modules/os_session.h b/include/modules/os_session.h
index 0bdec8a2b..0f25f669e 100644
--- a/include/modules/os_session.h
+++ b/include/modules/os_session.h
@@ -6,19 +6,19 @@
* Please read COPYING and README for further details.
*/
-#ifndef OS_SESSION_H
-#define OS_SESSION_H
+#pragma once
-struct Session
+struct Session final
{
cidr addr; /* A cidr (sockaddrs + len) representing this session */
- unsigned count; /* Number of clients with this host */
- unsigned hits; /* Number of subsequent kills for a host */
+ unsigned count = 1; /* Number of clients with this host */
+ unsigned hits = 0; /* Number of subsequent kills for a host */
- Session(const sockaddrs &ip, int len) : addr(ip, len), count(1), hits(0) { }
+ Session(const sockaddrs &ip, int len) : addr(ip, len) { }
};
-struct Exception : Serializable
+struct Exception final
+ : Serializable
{
Anope::string mask; /* Hosts to which this exception applies */
unsigned limit; /* Session limit for exception */
@@ -28,14 +28,15 @@ struct Exception : Serializable
time_t expires; /* Time when it expires. 0 == no expiry */
Exception() : Serializable("Exception") { }
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
-class SessionService : public Service
+class SessionService
+ : public Service
{
- public:
- typedef TR1NS::unordered_map<cidr, Session *, cidr::hash> SessionMap;
+public:
+ typedef std::unordered_map<cidr, Session *, cidr::hash> SessionMap;
typedef std::vector<Exception *> ExceptionVector;
SessionService(Module *m) : Service(m, "SessionService", "session") { }
@@ -61,15 +62,15 @@ static ServiceReference<SessionService> session_service("SessionService", "sessi
void Exception::Serialize(Serialize::Data &data) const
{
- data["mask"] << this->mask;
- data["limit"] << this->limit;
- data["who"] << this->who;
- data["reason"] << this->reason;
- data["time"] << this->time;
- data["expires"] << this->expires;
+ data.Store("mask", this->mask);
+ data.Store("limit", this->limit);
+ data.Store("who", this->who);
+ data.Store("reason", this->reason);
+ data.Store("time", this->time);
+ data.Store("expires", this->expires);
}
-Serializable* Exception::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *Exception::Unserialize(Serializable *obj, Serialize::Data &data)
{
if (!session_service)
return NULL;
@@ -90,5 +91,3 @@ Serializable* Exception::Unserialize(Serializable *obj, Serialize::Data &data)
session_service->AddException(ex);
return ex;
}
-
-#endif
diff --git a/include/modules/pseudoclients/chanserv.h b/include/modules/pseudoclients/chanserv.h
index 7e32da755..5bef94340 100644
--- a/include/modules/pseudoclients/chanserv.h
+++ b/include/modules/pseudoclients/chanserv.h
@@ -6,12 +6,12 @@
* Please read COPYING and README for further details.
*/
-#ifndef CHANSERV_H
-#define CHANSERV_H
+#pragma once
-class ChanServService : public Service
+class ChanServService
+ : public Service
{
- public:
+public:
ChanServService(Module *m) : Service(m, "ChanServService", "ChanServ")
{
}
@@ -21,5 +21,3 @@ class ChanServService : public Service
*/
virtual void Hold(Channel *c) = 0;
};
-
-#endif // CHANSERV_H
diff --git a/include/modules/pseudoclients/global.h b/include/modules/pseudoclients/global.h
index 77da218ba..01149d48e 100644
--- a/include/modules/pseudoclients/global.h
+++ b/include/modules/pseudoclients/global.h
@@ -6,25 +6,70 @@
* Please read COPYING and README for further details.
*/
-#ifndef GLOBAL_H
-#define GLOBAL_H
+#pragma once
-class GlobalService : public Service
+#define GLOBAL_NO_MESSAGE _("You do not have any messages queued and did not specify a message to send.")
+#define GLOBAL_QUEUE_CONFLICT _("You can not send a single message while you have messages queued.")
+
+class GlobalService
+ : public Service
{
- public:
- GlobalService(Module *m) : Service(m, "GlobalService", "Global")
+public:
+ GlobalService(Module *m)
+ : Service(m, "GlobalService", "Global")
{
}
/** Retrieves the bot which sends global messages unless otherwise specified. */
- virtual Reference<BotInfo> GetDefaultSender() = 0;
+ virtual Reference<BotInfo> GetDefaultSender() const = 0;
- /** Send out a global message to all users
- * @param sender Our client which should send the global
- * @param source The sender of the global
- * @param message The message
+ /** Clears any queued messages for the specified account.
+ * @param nc The account to clear queued messages for.
*/
- virtual void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) = 0;
-};
+ virtual void ClearQueue(NickCore *nc) = 0;
+
+ /** Retrieves the size of the messages queue for the specified user.
+ * @param nc The account to count queued messages for.
+ */
+ inline size_t CountQueue(NickCore* nc) const
+ {
+ auto *q = GetQueue(nc);
+ return q ? q->size() : 0;
+ }
+
+ /** Retrieves the messages queue for the specified user.
+ * @param nc The account to retrieve queued messages for.
+ */
+ virtual const std::vector<Anope::string> *GetQueue(NickCore* nc) const = 0;
-#endif // GLOBAL_H
+ /** Queues a message to be sent later.
+ * @param nc The account to queue the message for.
+ * @param message The message to queue.
+ * @return The new number of messages in the queue.
+ */
+ virtual size_t Queue(NickCore *nc, const Anope::string &message) = 0;
+
+ /** Sends a single message to all users on the network.
+ * @param message The message to send.
+ * @param source If non-nullptr then the source of the message.
+ * @param sender If non-nullptr then the bot to send the message from.
+ * @param server If non-nullptr then the server to send messages to.
+ * @return If the message was sent then true; otherwise, false.
+ */
+ virtual bool SendSingle(const Anope::string &message, CommandSource *source = nullptr, BotInfo *sender = nullptr, Server *server = nullptr) = 0;
+
+ /** Sends a message queue to all users on the network.
+ * @param source The source of the message.
+ * @param sender If non-nullptr then the bot to send the message from.
+ * @param server If non-nullptr then the server to send messages to.
+ * @return If the message queue was sent then true; otherwise, false.
+ */
+ virtual bool SendQueue(CommandSource &source, BotInfo *sender = nullptr, Server *server = nullptr) = 0;
+
+ /** Unqueues a message from the message queue.
+ * @param nc The account to unqueue the message from.
+ * @param idx The index of the item to remove.
+ * @return Whether the message was removed from the queue.
+ */
+ virtual bool Unqueue(NickCore *nc, size_t idx) = 0;
+};
diff --git a/include/modules/pseudoclients/memoserv.h b/include/modules/pseudoclients/memoserv.h
index bca26df43..c1ff4af7d 100644
--- a/include/modules/pseudoclients/memoserv.h
+++ b/include/modules/pseudoclients/memoserv.h
@@ -6,12 +6,12 @@
* Please read COPYING and README for further details.
*/
-#ifndef MEMOSERV_H
-#define MEMOSERV_H
+#pragma once
-class MemoServService : public Service
+class MemoServService
+ : public Service
{
- public:
+public:
enum MemoResult
{
MEMO_SUCCESS,
@@ -37,5 +37,3 @@ class MemoServService : public Service
*/
virtual void Check(User *u) = 0;
};
-
-#endif // MEMOSERV_H
diff --git a/include/modules/pseudoclients/nickserv.h b/include/modules/pseudoclients/nickserv.h
index 14502e7a8..2c659501e 100644
--- a/include/modules/pseudoclients/nickserv.h
+++ b/include/modules/pseudoclients/nickserv.h
@@ -6,12 +6,12 @@
* Please read COPYING and README for further details.
*/
-#ifndef NICKSERV_H
-#define NICKSERV_H
+#pragma once
-class NickServService : public Service
+class NickServService
+ : public Service
{
- public:
+public:
NickServService(Module *m) : Service(m, "NickServService", "NickServ")
{
}
@@ -19,6 +19,5 @@ class NickServService : public Service
virtual void Validate(User *u) = 0;
virtual void Collide(User *u, NickAlias *na) = 0;
virtual void Release(NickAlias *na) = 0;
+ virtual bool IsGuestNick(const Anope::string &nick) const = 0;
};
-
-#endif // NICKSERV_H
diff --git a/include/modules/redis.h b/include/modules/redis.h
index 346738492..6683997e0 100644
--- a/include/modules/redis.h
+++ b/include/modules/redis.h
@@ -6,9 +6,11 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
namespace Redis
{
- struct Reply
+ struct Reply final
{
enum Type
{
@@ -30,8 +32,8 @@ namespace Redis
i = 0;
bulk.clear();
multi_bulk_size = 0;
- for (unsigned j = 0; j < multi_bulk.size(); ++j)
- delete multi_bulk[j];
+ for (const auto *reply : multi_bulk)
+ delete reply;
multi_bulk.clear();
}
@@ -43,19 +45,20 @@ namespace Redis
class Interface
{
- public:
+ public:
Module *owner;
Interface(Module *m) : owner(m) { }
- virtual ~Interface() { }
+ virtual ~Interface() = default;
virtual void OnResult(const Reply &r) = 0;
virtual void OnError(const Anope::string &error) { Log(owner) << error; }
};
- class Provider : public Service
+ class Provider
+ : public Service
{
- public:
+ public:
Provider(Module *c, const Anope::string &n) : Service(c, "Redis::Provider", n) { }
virtual bool IsSocketDead() = 0;
diff --git a/include/modules/rpc.h b/include/modules/rpc.h
new file mode 100644
index 000000000..35db305c7
--- /dev/null
+++ b/include/modules/rpc.h
@@ -0,0 +1,128 @@
+/*
+ *
+ * (C) 2010-2025 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#pragma once
+
+#include "httpd.h"
+
+#include <variant>
+
+class RPCBlock
+{
+public:
+ /** Represents possible types of RPC value. */
+ using RPCValue = std::variant<RPCBlock, Anope::string, std::nullptr_t, bool, double, int64_t, uint64_t>;
+
+ /** Retrieves the list of RPC replies. */
+ inline const auto &GetReplies() const { return this->replies; }
+
+ template <typename Stringable>
+ inline RPCBlock &Reply(const Anope::string &key, const Stringable &value)
+ {
+ this->replies.emplace(key, Anope::ToString(value));
+ return *this;
+ }
+
+ inline RPCBlock &ReplyBlock(const Anope::string &key)
+ {
+ auto it = this->replies.emplace(key, RPCBlock());
+ return std::get<RPCBlock>(it.first->second);
+ }
+
+ inline RPCBlock &ReplyBool(const Anope::string &key, bool value)
+ {
+ this->replies.emplace(key, value);
+ return *this;
+ }
+
+ inline RPCBlock &ReplyFloat(const Anope::string &key, double value)
+ {
+ this->replies.emplace(key, value);
+ return *this;
+ }
+
+ inline RPCBlock &ReplyInt(const Anope::string &key, int64_t value)
+ {
+ this->replies.emplace(key, value);
+ return *this;
+ }
+
+ inline RPCBlock &ReplyNull(const Anope::string &key)
+ {
+ this->replies.emplace(key, nullptr);
+ return *this;
+ }
+
+ inline RPCBlock &ReplyUInt(const Anope::string &key, uint64_t value)
+ {
+ this->replies.emplace(key, value);
+ return *this;
+ }
+
+private:
+ Anope::map<RPCValue> replies;
+};
+
+class RPCRequest final
+ : public RPCBlock
+{
+private:
+ std::optional<std::pair<int64_t, Anope::string>> error;
+
+public:
+ Anope::string name;
+ Anope::string id;
+ std::deque<Anope::string> data;
+ HTTPReply &reply;
+
+ RPCRequest(HTTPReply &r)
+ : reply(r)
+ {
+ }
+
+ inline void Error(uint64_t errcode, const Anope::string &errstr)
+ {
+ this->error.emplace(errcode, errstr);
+ }
+
+ inline const auto &GetError() const { return this->error; }
+};
+
+class RPCServiceInterface;
+
+class RPCEvent
+{
+private:
+ Anope::string event;
+
+protected:
+ RPCEvent(const Anope::string& e)
+ : event(e)
+ {
+ }
+
+public:
+ virtual ~RPCEvent() = default;
+
+ const auto &GetEvent() const { return event; }
+
+ virtual bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) = 0;
+};
+
+class RPCServiceInterface
+ : public Service
+{
+public:
+ RPCServiceInterface(Module *creator, const Anope::string &sname) : Service(creator, "RPCServiceInterface", sname) { }
+
+ virtual bool Register(RPCEvent *event) = 0;
+
+ virtual bool Unregister(RPCEvent *event) = 0;
+
+ virtual void Reply(RPCRequest &request) = 0;
+};
diff --git a/include/modules/sasl.h b/include/modules/sasl.h
index bbd0f2f3d..e5786b524 100644
--- a/include/modules/sasl.h
+++ b/include/modules/sasl.h
@@ -6,30 +6,32 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
namespace SASL
{
- struct Message
+ struct Message final
{
Anope::string source;
Anope::string target;
Anope::string type;
- Anope::string data;
- Anope::string ext;
+ std::vector<Anope::string> data;
};
class Mechanism;
struct Session;
- class Service : public ::Service
+ class Service
+ : public ::Service
{
- public:
+ public:
Service(Module *o) : ::Service(o, "SASL::Service", "sasl") { }
virtual void ProcessMessage(const Message &) = 0;
virtual Anope::string GetAgent() = 0;
- virtual Session* GetSession(const Anope::string &uid) = 0;
+ virtual Session *GetSession(const Anope::string &uid) = 0;
virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data) = 0;
@@ -58,14 +60,15 @@ namespace SASL
};
/* PLAIN, EXTERNAL, etc */
- class Mechanism : public ::Service
+ class Mechanism
+ : public ::Service
{
- public:
+ public:
Mechanism(Module *o, const Anope::string &sname) : Service(o, "SASL::Mechanism", sname) { }
- virtual Session* CreateSession(const Anope::string &uid) { return new Session(this, uid); }
+ virtual Session *CreateSession(const Anope::string &uid) { return new Session(this, uid); }
- virtual void ProcessMessage(Session *session, const Message &) = 0;
+ virtual bool ProcessMessage(Session *session, const Message &) = 0;
virtual ~Mechanism()
{
@@ -74,15 +77,16 @@ namespace SASL
}
};
- class IdentifyRequest : public ::IdentifyRequest
+ class IdentifyRequest
+ : public ::IdentifyRequest
{
Anope::string uid;
Anope::string hostname, ip;
- public:
+ public:
IdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass, const Anope::string &h, const Anope::string &i) : ::IdentifyRequest(m, acc, pass), uid(id), hostname(h), ip(i) { }
- void OnSuccess() anope_override
+ void OnSuccess() override
{
if (!sasl)
return;
@@ -108,7 +112,7 @@ namespace SASL
}
}
- void OnFail() anope_override
+ void OnFail() override
{
if (!sasl)
return;
diff --git a/include/modules/set_misc.h b/include/modules/set_misc.h
index 38fa08818..2b93543c6 100644
--- a/include/modules/set_misc.h
+++ b/include/modules/set_misc.h
@@ -6,12 +6,15 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
struct MiscData
{
Anope::string object;
Anope::string name;
Anope::string data;
- MiscData() { }
- virtual ~MiscData() { }
+ virtual ~MiscData() = default;
+protected:
+ MiscData() = default;
};
diff --git a/include/modules/sql.h b/include/modules/sql.h
index 9c5e4fc4b..81af2e597 100644
--- a/include/modules/sql.h
+++ b/include/modules/sql.h
@@ -6,22 +6,27 @@
* Please read COPYING and README for further details.
*/
+#pragma once
+
+#include <stdexcept>
+
namespace SQL
{
- class Data : public Serialize::Data
+ class Data final
+ : public Serialize::Data
{
- public:
+ public:
typedef std::map<Anope::string, std::stringstream *> Map;
Map data;
- std::map<Anope::string, Type> types;
+ std::map<Anope::string, Serialize::DataType> types;
~Data()
{
Clear();
}
- std::iostream& operator[](const Anope::string &key) anope_override
+ std::iostream &operator[](const Anope::string &key) override
{
std::stringstream *&ss = data[key];
if (!ss)
@@ -29,72 +34,66 @@ namespace SQL
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() const 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());
+ for (const auto &[_, value] : this->data)
+ {
+ if (!value->str().empty())
+ hash ^= Anope::hash_cs()(value->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;
+ for (const auto &[key, value] : this->data)
+ d[key] = value;
return d;
}
void Clear()
{
- for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it)
- delete it->second;
+ for (const auto &[_, value] : this->data)
+ delete value;
this->data.clear();
}
- void SetType(const Anope::string &key, Type t) anope_override
+ void SetType(const Anope::string &key, Serialize::DataType dt) override
{
- this->types[key] = t;
+ this->types[key] = dt;
}
- Type GetType(const Anope::string &key) const anope_override
+ Serialize::DataType GetType(const Anope::string &key) const override
{
- std::map<Anope::string, Type>::const_iterator it = this->types.find(key);
+ auto it = this->types.find(key);
if (it != this->types.end())
return it->second;
- return DT_TEXT;
+ return Serialize::DataType::TEXT;
}
};
/** A SQL exception, can be thrown at various points
*/
- class Exception : public ModuleException
+ class DllExport Exception : public ModuleException
{
- public:
+ public:
Exception(const Anope::string &reason) : ModuleException(reason) { }
- virtual ~Exception() throw() { }
+ virtual ~Exception() noexcept = default;
};
/** A SQL query
*/
- struct QueryData
+ struct QueryData final
{
Anope::string data;
bool escape;
};
- struct Query
+ struct Query final
{
Anope::string query;
std::map<Anope::string, QueryData> parameters;
@@ -102,7 +101,7 @@ namespace SQL
Query() { }
Query(const Anope::string &q) : query(q) { }
- Query& operator=(const Anope::string &q)
+ Query &operator=(const Anope::string &q)
{
this->query = q;
this->parameters.clear();
@@ -119,15 +118,14 @@ namespace SQL
return !(*this == other);
}
- template<typename T> void SetValue(const Anope::string &key, const T& value, bool escape = true)
+ 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) { }
+ auto str = Anope::TryString(value);
+ if (!str.has_value())
+ return;
+
+ this->parameters[key].data = str.value();
+ this->parameters[key].escape = escape;
}
};
@@ -135,16 +133,16 @@ namespace SQL
*/
class Result
{
- protected:
+ protected:
/* Rows, column, item */
std::vector<std::map<Anope::string, Anope::string> > entries;
Query query;
Anope::string error;
- public:
- unsigned int id;
+ public:
+ unsigned int id = 0;
Anope::string finished_query;
- Result() : id(0) { }
+ Result() = default;
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(); }
@@ -183,11 +181,11 @@ namespace SQL
*/
class Interface
{
- public:
+ public:
Module *owner;
Interface(Module *m) : owner(m) { }
- virtual ~Interface() { }
+ virtual ~Interface() = default;
virtual void OnResult(const Result &r) = 0;
virtual void OnError(const Result &r) = 0;
@@ -195,9 +193,10 @@ namespace SQL
/** Class providing the SQL service, modules call this to execute queries
*/
- class Provider : public Service
+ class Provider
+ : public Service
{
- public:
+ public:
Provider(Module *c, const Anope::string &n) : Service(c, "SQL::Provider", n) { }
virtual void Run(Interface *i, const Query &query) = 0;
diff --git a/include/modules/ssl.h b/include/modules/ssl.h
index 744cd46dd..a6dda0c52 100644
--- a/include/modules/ssl.h
+++ b/include/modules/ssl.h
@@ -6,9 +6,12 @@
* Please read COPYING and README for further details.
*/
-class SSLService : public Service
+#pragma once
+
+class SSLService
+ : public Service
{
- public:
+public:
SSLService(Module *o, const Anope::string &n) : Service(o, "SSLService", n) { }
virtual void Init(Socket *s) = 0;
diff --git a/include/modules/suspend.h b/include/modules/suspend.h
index 92523f7cf..f973baea4 100644
--- a/include/modules/suspend.h
+++ b/include/modules/suspend.h
@@ -9,11 +9,13 @@
* Based on the original code of Services by Andy Church.
*/
+#pragma once
+
struct SuspendInfo
{
Anope::string what, by, reason;
time_t when, expires;
- SuspendInfo() { }
- virtual ~SuspendInfo() { }
+ SuspendInfo() = default;
+ virtual ~SuspendInfo() = default;
};
diff --git a/include/modules/xmlrpc.h b/include/modules/xmlrpc.h
deleted file mode 100644
index 01847d3f0..000000000
--- a/include/modules/xmlrpc.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- *
- * (C) 2010-2025 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-#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;
-};
diff --git a/include/numeric.h b/include/numeric.h
new file mode 100644
index 000000000..2ee295278
--- /dev/null
+++ b/include/numeric.h
@@ -0,0 +1,35 @@
+/*
+ *
+ * (C) 2003-2025 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#pragma once
+
+enum
+{
+ RPL_STATSLINKINFO = 211,
+ RPL_ENDOFSTATS = 219,
+ RPL_STATSUPTIME = 242,
+ RPL_STATSOLINE = 243,
+ RPL_STATSCONN = 250,
+ RPL_WHOISREGNICK = 307,
+ RPL_WHOISUSER = 311,
+ RPL_WHOISSERVER = 312,
+ RPL_WHOISOPERATOR = 313,
+ RPL_WHOISIDLE = 317,
+ RPL_ENDOFWHOIS = 318,
+ RPL_VERSION = 351,
+ RPL_MOTD = 372,
+ RPL_MOTDSTART = 375,
+ RPL_ENDOFMOTD = 376,
+ RPL_YOUREOPER = 381,
+ RPL_TIME = 391,
+ ERR_NOSUCHNICK = 401,
+ ERR_NOMOTD = 422,
+};
diff --git a/include/opertype.h b/include/opertype.h
index 9f04ebcce..16b52a34a 100644
--- a/include/opertype.h
+++ b/include/opertype.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef OPERTYPE_H
-#define OPERTYPE_H
+#pragma once
#include "services.h"
#include "account.h"
@@ -22,9 +21,9 @@ struct CoreExport Oper
/* The type of operator this operator is */
OperType *ot;
/* Whether the user must be an IRC operator (umode +o) to be considered a services operator */
- bool require_oper;
+ bool require_oper = true;
Anope::string password;
- Anope::string certfp;
+ std::vector<Anope::string> certfp;
/* Hosts allowed to use this operator block */
std::vector<Anope::string> hosts;
Anope::string vhost;
@@ -41,9 +40,9 @@ struct CoreExport Oper
static Oper *Find(const Anope::string &name);
};
-class CoreExport OperType
+class CoreExport OperType final
{
- private:
+private:
/** The name of this opertype, e.g. "sra".
*/
Anope::string name;
@@ -66,7 +65,7 @@ class CoreExport OperType
/** Set of opertypes we inherit from
*/
std::set<OperType *> inheritances;
- public:
+public:
/** Modes to set when someone identifies using this opertype
*/
Anope::string modes;
@@ -116,12 +115,10 @@ class CoreExport OperType
/** Gets the icommands for this opertype
* @return A list of commands
*/
- const std::list<Anope::string> GetCommands() const;
+ std::list<Anope::string> GetCommands() const;
/** Gets the privileges for this opertype
* @return A list of privileges
*/
- const std::list<Anope::string> GetPrivs() const;
+ std::list<Anope::string> GetPrivs() const;
};
-
-#endif // OPERTYPE_H
diff --git a/include/protocol.h b/include/protocol.h
index 029c67446..c92939be6 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -9,75 +9,141 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef PROTOCOL_H
-#define PROTOCOL_H
+#pragma once
#include "services.h"
#include "anope.h"
#include "service.h"
#include "modes.h"
+/** Thrown when a protocol error happens. */
+class CoreExport ProtocolException final
+ : public ModuleException
+{
+public:
+ ProtocolException(const Anope::string &message)
+ : ModuleException(message)
+ {
+ }
+};
+
/* Encapsulates the IRCd protocol we are speaking. */
-class CoreExport IRCDProto : public Service
+class CoreExport IRCDProto
+ : public Service
{
Anope::string proto_name;
- protected:
+protected:
IRCDProto(Module *creator, const Anope::string &proto_name);
- public:
+public:
+ /** Retrieves the protocol name. */
+ const Anope::string &GetProtocolName() const { return proto_name; }
+
virtual ~IRCDProto();
- virtual void SendSVSKillInternal(const MessageSource &, User *, const Anope::string &);
- virtual void SendModeInternal(const MessageSource &, const Channel *, const Anope::string &);
- virtual void SendModeInternal(const MessageSource &, User *, const Anope::string &);
- virtual void SendKickInternal(const MessageSource &, const Channel *, User *, const Anope::string &);
- virtual void SendNoticeInternal(const MessageSource &, const Anope::string &dest, const Anope::string &msg);
- virtual void SendPrivmsgInternal(const MessageSource &, const Anope::string &dest, const Anope::string &buf);
- virtual void SendQuitInternal(User *, const Anope::string &buf);
- virtual void SendPartInternal(User *, const Channel *chan, const Anope::string &buf);
- virtual void SendGlobopsInternal(const MessageSource &, const Anope::string &buf);
- virtual void SendCTCPInternal(const MessageSource &, const Anope::string &dest, const Anope::string &buf);
- virtual void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf);
-
- const Anope::string &GetProtocolName();
- virtual bool Parse(const Anope::string &, Anope::map<Anope::string> &, Anope::string &, Anope::string &, std::vector<Anope::string> &);
- virtual Anope::string Format(const Anope::string &source, const Anope::string &message);
+ virtual void SendNotice(const MessageSource &source, const Anope::string &dest, const Anope::string &msg, const Anope::map<Anope::string> &tags = {});
+ virtual void SendPrivmsg(const MessageSource &source, const Anope::string &dest, const Anope::string &msg, const Anope::map<Anope::string> &tags = {});
+ virtual void SendTagmsg(const MessageSource &source, const Anope::string &dest, const Anope::map<Anope::string> &tags);
+
+ /** Parses an incoming message from the IRC server.
+ * @param message The message to parse.
+ * @param tags The location to store tags.
+ * @param source The location to store the source.
+ * @param command The location to store the command name.
+ * @param params The location to store the parameters.
+ * @return If the message was well formed then true; otherwise, false.
+ */
+ virtual bool Parse(const Anope::string &message, Anope::map<Anope::string> &tags, Anope::string &source, Anope::string &command, std::vector<Anope::string> &params);
+
+ /* Formats an outgoing message so it can be sent to the IRC server.
+ * @param message The location to store the formatted message.
+ * @param tags IRCv3 message tags.
+ * @param source Source of the message.
+ * @param command Command name.
+ * @param params Any extra parameters.
+ * @return If the message was formatted then true; otherwise, false.
+ */
+ virtual bool Format(Anope::string &message, const Anope::map<Anope::string> &tags, const MessageSource &source, const Anope::string &command, const std::vector<Anope::string> &params);
/* Modes used by default by our clients */
- Anope::string DefaultPseudoclientModes;
+ Anope::string DefaultPseudoclientModes = "+io";
+
/* Can we force change a users's nick? */
- bool CanSVSNick;
+ bool CanSVSNick = false;
+
/* Can we force join or part users? */
- bool CanSVSJoin;
- /* Can we set vhosts/vidents on users? */
- bool CanSetVHost, CanSetVIdent;
+ bool CanSVSJoin = false;
+
+ /** Can we force servers to remove opers? */
+ bool CanSVSNOOP = false;
+
+ /* Can we set vhosts on users? */
+ bool CanSetVHost = false;
+
+ /* Can we set vidents on users? */
+ bool CanSetVIdent = false;
+
/* Can we ban specific gecos from being used? */
- bool CanSNLine;
+ bool CanSNLine = false;
+
/* Can we ban specific nicknames from being used? */
- bool CanSQLine;
+ bool CanSQLine = false;
+
/* Can we ban specific channel names from being used? */
- bool CanSQLineChannel;
+ bool CanSQLineChannel = false;
+
/* Can we ban by IP? */
- bool CanSZLine;
+ bool CanSZLine = false;
+
/* Can we place temporary holds on specific nicknames? */
- bool CanSVSHold;
- /* See os_oline */
- bool CanSVSO;
+ bool CanSVSHold = false;
+
/* See ns_cert */
- bool CanCertFP;
+ bool CanCertFP = false;
+
/* Whether this IRCd requires unique IDs for each user or server. See TS6/P10. */
- bool RequiresID;
+ bool RequiresID = false;
+
/* If this IRCd has unique ids, whether the IDs and nicknames are ambiguous */
- bool AmbiguousID;
- /* The maximum number of modes we are allowed to set with one MODE command */
- unsigned MaxModes;
+ bool AmbiguousID = false;
+
+ /** Can we ask the server to unban a user? */
+ bool CanClearBans = false;
+
+ /** Can we send tag messages? */
+ bool CanTagMessage = false;
+
+ /* The maximum length of a channel name. */
+ size_t MaxChannel = 0;
+
+ /* The maximum length of a hostname. */
+ size_t MaxHost = 0;
+
/* The maximum number of bytes a line may have */
- unsigned MaxLine;
+ size_t MaxLine = 512;
+
+ /* The maximum number of modes we are allowed to set with one MODE command */
+ size_t MaxModes = 3;
+
+ /* The maximum length of a nickname. */
+ size_t MaxNick = 0;
+
+ /* The maximum length of a username. */
+ size_t MaxUser = 0;
+
/* Retrieves the next free UID or SID */
virtual Anope::string UID_Retrieve();
virtual Anope::string SID_Retrieve();
+ /** Extracts a timestamp from a string. */
+ virtual time_t ExtractTimestamp(const Anope::string &str);
+
+ /** Sends an error to the uplink before disconnecting.
+ * @param reason The error message.
+ */
+ virtual void SendError(const Anope::string &reason);
+
/** Sets the server in NOOP mode. If NOOP mode is enabled, no users
* will be able to oper on the server.
* @param s The server
@@ -96,8 +162,8 @@ class CoreExport IRCDProto : public Service
* @param vident The ident to set
* @param vhost The vhost to set
*/
- virtual void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) { }
- virtual void SendVhostDel(User *) { }
+ virtual void SendVHost(User *u, const Anope::string &vident, const Anope::string &vhost) { }
+ virtual void SendVHostDel(User *) { }
/** Sets an akill. This is a recursive function that can be called multiple times
* for the same xline, but for different users, if the xline is not one that can be
@@ -125,29 +191,38 @@ class CoreExport IRCDProto : public Service
/** Kills a user
* @param source Who is doing the kill
* @param user The user to be killed
- * @param fmt Kill reason
+ * @param msg Kill reason
*/
- virtual void SendSVSKill(const MessageSource &source, User *user, const char *fmt, ...);
-
- virtual void SendMode(const MessageSource &source, const Channel *dest, const char *fmt, ...);
- virtual void SendMode(const MessageSource &source, User *u, const char *fmt, ...);
+ virtual void SendSVSKill(const MessageSource &source, User *user, const Anope::string &msg);
+
+ virtual void SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector<Anope::string> &values);
+ template <typename... Args>
+ void SendMode(const MessageSource &source, Channel *chan, const Anope::string &modes, Args &&...args)
+ {
+ SendModeInternal(source, chan, modes, { Anope::ToString(args)... });
+ }
+
+ virtual void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values);
+ template <typename... Args>
+ void SendMode(const MessageSource &source, User *u, const Anope::string &modes, Args &&...args)
+ {
+ SendModeInternal(source, u, modes, { Anope::ToString(args)... });
+ }
/** Introduces a client to the rest of the network
* @param u The client to introduce
*/
virtual void SendClientIntroduction(User *u) = 0;
- virtual void SendKick(const MessageSource &source, const Channel *chan, User *user, const char *fmt, ...);
-
- virtual void SendNotice(const MessageSource &source, const Anope::string &dest, const char *fmt, ...);
- virtual void SendPrivmsg(const MessageSource &source, const Anope::string &dest, const char *fmt, ...);
- virtual void SendAction(const MessageSource &source, const Anope::string &dest, const char *fmt, ...);
- virtual void SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...);
+ virtual void SendKick(const MessageSource &source, const Channel *chan, User *user, const Anope::string &msg);
virtual void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) = 0;
virtual void SendGlobalPrivmsg(BotInfo *bi, const Server *desc, const Anope::string &msg) = 0;
- virtual void SendQuit(User *u, const char *fmt, ...);
+ virtual void SendContextNotice(BotInfo *bi, User *target, Channel *context, const Anope::string &msg);
+ virtual void SendContextPrivmsg(BotInfo *bi, User *target, Channel *context, const Anope::string &msg);
+
+ virtual void SendQuit(User *u, const Anope::string &msg);
virtual void SendPing(const Anope::string &servname, const Anope::string &who);
virtual void SendPong(const Anope::string &servname, const Anope::string &who);
@@ -159,15 +234,15 @@ class CoreExport IRCDProto : public Service
* stacker to be set "soon".
*/
virtual void SendJoin(User *u, Channel *c, const ChannelStatus *status) = 0;
- virtual void SendPart(User *u, const Channel *chan, const char *fmt, ...);
+ virtual void SendPart(User *u, const Channel *chan, const Anope::string &msg);
/** Force joins a user that isn't ours to a channel.
* @param bi The source of the message
* @param u The user to join
* @param chan The channel to join the user to
- * @param param Channel key?
+ * @param key Channel key
*/
- virtual void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) { }
+ virtual void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &key) { }
/** Force parts a user that isn't ours from a channel.
* @param source The source of the message
@@ -178,11 +253,7 @@ class CoreExport IRCDProto : public Service
virtual void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &param) { }
virtual void SendInvite(const MessageSource &source, const Channel *c, User *u);
- virtual void SendGlobops(const MessageSource &source, const char *fmt, ...);
-
- /** Sets oper flags on a user, currently only supported by Unreal
- */
- virtual void SendSVSO(BotInfo *, const Anope::string &, const Anope::string &) { }
+ virtual void SendGlobops(const MessageSource &source, const Anope::string &msg);
/** Sends a nick change of one of our clients.
*/
@@ -213,7 +284,12 @@ class CoreExport IRCDProto : public Service
virtual void SendServer(const Server *) = 0;
virtual void SendSquit(Server *, const Anope::string &message);
- virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...);
+ virtual void SendNumericInternal(int numeric, const Anope::string &dest, const std::vector<Anope::string> &params);
+ template <typename... Args>
+ void SendNumeric(int numeric, const Anope::string &dest, Args &&...args)
+ {
+ SendNumericInternal(numeric, dest, { Anope::ToString(args)... });
+ }
virtual void SendLogin(User *u, NickAlias *na) = 0;
virtual void SendLogout(User *u) = 0;
@@ -221,40 +297,43 @@ class CoreExport IRCDProto : public Service
/** Send a channel creation message to the uplink.
* On most TS6 IRCds this is a SJOIN with no nick
*/
- virtual void SendChannel(Channel *c) { }
+ virtual void SendChannel(Channel *c) = 0;
/** Make the user an IRC operator
* Normally this is a simple +o, though some IRCds require us to send the oper type
*/
virtual void SendOper(User *u);
+ virtual void SendClearBans(const MessageSource &user, Channel *c, User* u) { }
+
virtual void SendSASLMechanisms(std::vector<Anope::string> &) { }
virtual void SendSASLMessage(const SASL::Message &) { }
- virtual void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) { }
+ virtual void SendSVSLogin(const Anope::string &uid, NickAlias *na) { }
virtual bool IsNickValid(const Anope::string &);
virtual bool IsChannelValid(const Anope::string &);
virtual bool IsIdentValid(const Anope::string &);
virtual bool IsHostValid(const Anope::string &);
virtual bool IsExtbanValid(const Anope::string &) { return false; }
+ virtual bool IsTagValid(const Anope::string &, const Anope::string &) { return false; }
/** Retrieve the maximum number of list modes settable on this channel
* Defaults to Config->ListSize
*/
- virtual unsigned GetMaxListFor(Channel *c);
- virtual unsigned GetMaxListFor(Channel *c, ChannelMode *cm);
+ virtual size_t GetMaxListFor(Channel *c, ChannelMode *cm);
virtual Anope::string NormalizeMask(const Anope::string &mask);
+
};
-class CoreExport MessageSource
+class CoreExport MessageSource final
{
Anope::string source;
- User *u;
- Server *s;
+ User *u = nullptr;
+ Server *s = nullptr;
- public:
- MessageSource(const Anope::string &);
+public:
+ explicit MessageSource(const Anope::string &);
MessageSource(User *u);
MessageSource(Server *s);
const Anope::string &GetName() const;
@@ -264,39 +343,70 @@ class CoreExport MessageSource
Server *GetServer() const;
};
-enum IRCDMessageFlag
-{
- IRCDMESSAGE_SOFT_LIMIT,
- IRCDMESSAGE_REQUIRE_SERVER,
- IRCDMESSAGE_REQUIRE_USER
-};
-class CoreExport IRCDMessage : public Service
+/** Base class for protocol module message handlers. */
+class CoreExport IRCDMessage
+ : public Service
{
- Anope::string name;
- unsigned param_count;
- std::set<IRCDMessageFlag> flags;
- public:
- IRCDMessage(Module *owner, const Anope::string &n, unsigned p = 0);
- unsigned GetParamCount() const;
- virtual void Run(MessageSource &, const std::vector<Anope::string> &params) = 0;
- virtual void Run(MessageSource &, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags);
-
- void SetFlag(IRCDMessageFlag f) { flags.insert(f); }
- bool HasFlag(IRCDMessageFlag f) const { return flags.count(f); }
+public:
+ /** An enumeration of potential flags a command can have. */
+ enum Flag
+ : uint8_t
+ {
+ /** The parameter count is a minimum instead of an exact limit. */
+ FLAG_SOFT_LIMIT,
+
+ /** The message must come from a server. */
+ FLAG_REQUIRE_SERVER,
+
+ /** The message must come from a user. */
+ FLAG_REQUIRE_USER,
+
+ /** The highest flag possible. */
+ FLAG_MAX,
+ };
+
+private:
+ /** The name of the message (e.g. PRIVMSG). */
+ const Anope::string name;
+
+ /** The number of parameters this command takes. */
+ const size_t param_count;
+
+ /** The flags that are set on the command. */
+ std::bitset<FLAG_MAX> flags;
+
+public:
+ IRCDMessage(Module *o, const Anope::string &n, size_t pc = 0);
+
+ /** Retrieves the parameter count. */
+ inline size_t GetParamCount() const { return param_count; }
+
+ /** Runs the handler for this message.
+ * @param source Entity that sent the message.
+ * @param params Message parameters
+ * @param tags Message tags
+ */
+ virtual void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) = 0;
+
+ /** Sets the flags for this message. */
+ inline void SetFlag(Flag flag, bool value = true) { flags.set(flag, value); }
+
+ /** Determines if a flag is set. */
+ inline bool HasFlag(Flag flag) const { return flags[flag]; }
};
/** MessageTokenizer allows tokens in the IRC wire format to be read from a string */
-class CoreExport MessageTokenizer
+class CoreExport MessageTokenizer final
{
private:
/** The message we are parsing tokens from. */
Anope::string message;
/** The current position within the message. */
- Anope::string::size_type position;
+ Anope::string::size_type position = 0;
- public:
+public:
/** Create a tokenstream and fill it with the provided data. */
MessageTokenizer(const Anope::string &msg);
@@ -314,5 +424,3 @@ private:
};
extern CoreExport IRCDProto *IRCD;
-
-#endif // PROTOCOL_H
diff --git a/include/pstdint.h b/include/pstdint.h
deleted file mode 100644
index b034ae086..000000000
--- a/include/pstdint.h
+++ /dev/null
@@ -1,800 +0,0 @@
-/* A portable stdint.h
- ****************************************************************************
- * BSD License:
- ****************************************************************************
- *
- * Copyright (c) 2005-2011 Paul Hsieh
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************
- *
- * Version 0.1.12
- *
- * The ANSI C standard committee, for the C99 standard, specified the
- * inclusion of a new standard include file called stdint.h. This is
- * a very useful and long desired include file which contains several
- * very precise definitions for integer scalar types that is
- * critically important for making portable several classes of
- * applications including cryptography, hashing, variable length
- * integer libraries and so on. But for most developers its likely
- * useful just for programming sanity.
- *
- * The problem is that most compiler vendors have decided not to
- * implement the C99 standard, and the next C++ language standard
- * (which has a lot more mindshare these days) will be a long time in
- * coming and its unknown whether or not it will include stdint.h or
- * how much adoption it will have. Either way, it will be a long time
- * before all compilers come with a stdint.h and it also does nothing
- * for the extremely large number of compilers available today which
- * do not include this file, or anything comparable to it.
- *
- * So that's what this file is all about. Its an attempt to build a
- * single universal include file that works on as many platforms as
- * possible to deliver what stdint.h is supposed to. A few things
- * that should be noted about this file:
- *
- * 1) It is not guaranteed to be portable and/or present an identical
- * interface on all platforms. The extreme variability of the
- * ANSI C standard makes this an impossibility right from the
- * very get go. Its really only meant to be useful for the vast
- * majority of platforms that possess the capability of
- * implementing usefully and precisely defined, standard sized
- * integer scalars. Systems which are not intrinsically 2s
- * complement may produce invalid constants.
- *
- * 2) There is an unavoidable use of non-reserved symbols.
- *
- * 3) Other standard include files are invoked.
- *
- * 4) This file may come in conflict with future platforms that do
- * include stdint.h. The hope is that one or the other can be
- * used with no real difference.
- *
- * 5) In the current version, if your platform can't represent
- * int32_t, int16_t and int8_t, it just dumps out with a compiler
- * error.
- *
- * 6) 64 bit integers may or may not be defined. Test for their
- * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
- * Note that this is different from the C99 specification which
- * requires the existence of 64 bit support in the compiler. If
- * this is not defined for your platform, yet it is capable of
- * dealing with 64 bits then it is because this file has not yet
- * been extended to cover all of your system's capabilities.
- *
- * 7) (u)intptr_t may or may not be defined. Test for its presence
- * with the test: #ifdef PTRDIFF_MAX. If this is not defined
- * for your platform, then it is because this file has not yet
- * been extended to cover all of your system's capabilities, not
- * because its optional.
- *
- * 8) The following might not been defined even if your platform is
- * capable of defining it:
- *
- * WCHAR_MIN
- * WCHAR_MAX
- * (u)int64_t
- * PTRDIFF_MIN
- * PTRDIFF_MAX
- * (u)intptr_t
- *
- * 9) The following have not been defined:
- *
- * WINT_MIN
- * WINT_MAX
- *
- * 10) The criteria for defining (u)int_least(*)_t isn't clear,
- * except for systems which don't have a type that precisely
- * defined 8, 16, or 32 bit types (which this include file does
- * not support anyways). Default definitions have been given.
- *
- * 11) The criteria for defining (u)int_fast(*)_t isn't something I
- * would trust to any particular compiler vendor or the ANSI C
- * committee. It is well known that "compatible systems" are
- * commonly created that have very different performance
- * characteristics from the systems they are compatible with,
- * especially those whose vendors make both the compiler and the
- * system. Default definitions have been given, but its strongly
- * recommended that users never use these definitions for any
- * reason (they do *NOT* deliver any serious guarantee of
- * improved performance -- not in this file, nor any vendor's
- * stdint.h).
- *
- * 12) The following macros:
- *
- * PRINTF_INTMAX_MODIFIER
- * PRINTF_INT64_MODIFIER
- * PRINTF_INT32_MODIFIER
- * PRINTF_INT16_MODIFIER
- * PRINTF_LEAST64_MODIFIER
- * PRINTF_LEAST32_MODIFIER
- * PRINTF_LEAST16_MODIFIER
- * PRINTF_INTPTR_MODIFIER
- *
- * are strings which have been defined as the modifiers required
- * for the "d", "u" and "x" printf formats to correctly output
- * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
- * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
- * PRINTF_INTPTR_MODIFIER is not defined for some systems which
- * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
- * defined if INT64_MAX is not defined. These are an extension
- * beyond what C99 specifies must be in stdint.h.
- *
- * In addition, the following macros are defined:
- *
- * PRINTF_INTMAX_HEX_WIDTH
- * PRINTF_INT64_HEX_WIDTH
- * PRINTF_INT32_HEX_WIDTH
- * PRINTF_INT16_HEX_WIDTH
- * PRINTF_INT8_HEX_WIDTH
- * PRINTF_INTMAX_DEC_WIDTH
- * PRINTF_INT64_DEC_WIDTH
- * PRINTF_INT32_DEC_WIDTH
- * PRINTF_INT16_DEC_WIDTH
- * PRINTF_INT8_DEC_WIDTH
- *
- * Which specifies the maximum number of characters required to
- * print the number of that type in either hexadecimal or decimal.
- * These are an extension beyond what C99 specifies must be in
- * stdint.h.
- *
- * Compilers tested (all with 0 warnings at their highest respective
- * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
- * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
- * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
- *
- * This file should be considered a work in progress. Suggestions for
- * improvements, especially those which increase coverage are strongly
- * encouraged.
- *
- * Acknowledgements
- *
- * The following people have made significant contributions to the
- * development and testing of this file:
- *
- * Chris Howie
- * John Steele Scott
- * Dave Thorup
- * John Dill
- *
- */
-
-#include <stddef.h>
-#include <limits.h>
-#include <signal.h>
-
-/*
- * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
- * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
- */
-
-#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
-#include <stdint.h>
-#define _PSTDINT_H_INCLUDED
-# ifndef PRINTF_INT64_MODIFIER
-# define PRINTF_INT64_MODIFIER "ll"
-# endif
-# ifndef PRINTF_INT32_MODIFIER
-# define PRINTF_INT32_MODIFIER "l"
-# endif
-# ifndef PRINTF_INT16_MODIFIER
-# define PRINTF_INT16_MODIFIER "h"
-# endif
-# ifndef PRINTF_INTMAX_MODIFIER
-# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
-# endif
-# ifndef PRINTF_INT64_HEX_WIDTH
-# define PRINTF_INT64_HEX_WIDTH "16"
-# endif
-# ifndef PRINTF_INT32_HEX_WIDTH
-# define PRINTF_INT32_HEX_WIDTH "8"
-# endif
-# ifndef PRINTF_INT16_HEX_WIDTH
-# define PRINTF_INT16_HEX_WIDTH "4"
-# endif
-# ifndef PRINTF_INT8_HEX_WIDTH
-# define PRINTF_INT8_HEX_WIDTH "2"
-# endif
-# ifndef PRINTF_INT64_DEC_WIDTH
-# define PRINTF_INT64_DEC_WIDTH "20"
-# endif
-# ifndef PRINTF_INT32_DEC_WIDTH
-# define PRINTF_INT32_DEC_WIDTH "10"
-# endif
-# ifndef PRINTF_INT16_DEC_WIDTH
-# define PRINTF_INT16_DEC_WIDTH "5"
-# endif
-# ifndef PRINTF_INT8_DEC_WIDTH
-# define PRINTF_INT8_DEC_WIDTH "3"
-# endif
-# ifndef PRINTF_INTMAX_HEX_WIDTH
-# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
-# endif
-# ifndef PRINTF_INTMAX_DEC_WIDTH
-# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
-# endif
-
-/*
- * Something really weird is going on with Open Watcom. Just pull some of
- * these duplicated definitions from Open Watcom's stdint.h file for now.
- */
-
-# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
-# if !defined (INT64_C)
-# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
-# endif
-# if !defined (UINT64_C)
-# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
-# endif
-# if !defined (INT32_C)
-# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
-# endif
-# if !defined (UINT32_C)
-# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
-# endif
-# if !defined (INT16_C)
-# define INT16_C(x) (x)
-# endif
-# if !defined (UINT16_C)
-# define UINT16_C(x) (x)
-# endif
-# if !defined (INT8_C)
-# define INT8_C(x) (x)
-# endif
-# if !defined (UINT8_C)
-# define UINT8_C(x) (x)
-# endif
-# if !defined (UINT64_MAX)
-# define UINT64_MAX 18446744073709551615ULL
-# endif
-# if !defined (INT64_MAX)
-# define INT64_MAX 9223372036854775807LL
-# endif
-# if !defined (UINT32_MAX)
-# define UINT32_MAX 4294967295UL
-# endif
-# if !defined (INT32_MAX)
-# define INT32_MAX 2147483647L
-# endif
-# if !defined (INTMAX_MAX)
-# define INTMAX_MAX INT64_MAX
-# endif
-# if !defined (INTMAX_MIN)
-# define INTMAX_MIN INT64_MIN
-# endif
-# endif
-#endif
-
-#ifndef _PSTDINT_H_INCLUDED
-#define _PSTDINT_H_INCLUDED
-
-#ifndef SIZE_MAX
-# define SIZE_MAX (~(size_t)0)
-#endif
-
-/*
- * Deduce the type assignments from limits.h under the assumption that
- * integer sizes in bits are powers of 2, and follow the ANSI
- * definitions.
- */
-
-#ifndef UINT8_MAX
-# define UINT8_MAX 0xff
-#endif
-#ifndef uint8_t
-# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
- typedef unsigned char uint8_t;
-# define UINT8_C(v) ((uint8_t) v)
-# else
-# error "Platform not supported"
-# endif
-#endif
-
-#ifndef INT8_MAX
-# define INT8_MAX 0x7f
-#endif
-#ifndef INT8_MIN
-# define INT8_MIN INT8_C(0x80)
-#endif
-#ifndef int8_t
-# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
- typedef signed char int8_t;
-# define INT8_C(v) ((int8_t) v)
-# else
-# error "Platform not supported"
-# endif
-#endif
-
-#ifndef UINT16_MAX
-# define UINT16_MAX 0xffff
-#endif
-#ifndef uint16_t
-#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
- typedef unsigned int uint16_t;
-# ifndef PRINTF_INT16_MODIFIER
-# define PRINTF_INT16_MODIFIER ""
-# endif
-# define UINT16_C(v) ((uint16_t) (v))
-#elif (USHRT_MAX == UINT16_MAX)
- typedef unsigned short uint16_t;
-# define UINT16_C(v) ((uint16_t) (v))
-# ifndef PRINTF_INT16_MODIFIER
-# define PRINTF_INT16_MODIFIER "h"
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-#ifndef INT16_MAX
-# define INT16_MAX 0x7fff
-#endif
-#ifndef INT16_MIN
-# define INT16_MIN INT16_C(0x8000)
-#endif
-#ifndef int16_t
-#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
- typedef signed int int16_t;
-# define INT16_C(v) ((int16_t) (v))
-# ifndef PRINTF_INT16_MODIFIER
-# define PRINTF_INT16_MODIFIER ""
-# endif
-#elif (SHRT_MAX == INT16_MAX)
- typedef signed short int16_t;
-# define INT16_C(v) ((int16_t) (v))
-# ifndef PRINTF_INT16_MODIFIER
-# define PRINTF_INT16_MODIFIER "h"
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-#ifndef UINT32_MAX
-# define UINT32_MAX (0xffffffffUL)
-#endif
-#ifndef uint32_t
-#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
- typedef unsigned long uint32_t;
-# define UINT32_C(v) v ## UL
-# ifndef PRINTF_INT32_MODIFIER
-# define PRINTF_INT32_MODIFIER "l"
-# endif
-#elif (UINT_MAX == UINT32_MAX)
- typedef unsigned int uint32_t;
-# ifndef PRINTF_INT32_MODIFIER
-# define PRINTF_INT32_MODIFIER ""
-# endif
-# define UINT32_C(v) v ## U
-#elif (USHRT_MAX == UINT32_MAX)
- typedef unsigned short uint32_t;
-# define UINT32_C(v) ((unsigned short) (v))
-# ifndef PRINTF_INT32_MODIFIER
-# define PRINTF_INT32_MODIFIER ""
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-#ifndef INT32_MAX
-# define INT32_MAX (0x7fffffffL)
-#endif
-#ifndef INT32_MIN
-# define INT32_MIN INT32_C(0x80000000)
-#endif
-#ifndef int32_t
-#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
- typedef signed long int32_t;
-# define INT32_C(v) v ## L
-# ifndef PRINTF_INT32_MODIFIER
-# define PRINTF_INT32_MODIFIER "l"
-# endif
-#elif (INT_MAX == INT32_MAX)
- typedef signed int int32_t;
-# define INT32_C(v) v
-# ifndef PRINTF_INT32_MODIFIER
-# define PRINTF_INT32_MODIFIER ""
-# endif
-#elif (SHRT_MAX == INT32_MAX)
- typedef signed short int32_t;
-# define INT32_C(v) ((short) (v))
-# ifndef PRINTF_INT32_MODIFIER
-# define PRINTF_INT32_MODIFIER ""
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-/*
- * The macro stdint_int64_defined is temporarily used to record
- * whether or not 64 integer support is available. It must be
- * defined for any 64 integer extensions for new platforms that are
- * added.
- */
-
-#undef stdint_int64_defined
-#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
-# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
-# define stdint_int64_defined
- typedef long long int64_t;
- typedef unsigned long long uint64_t;
-# define UINT64_C(v) v ## ULL
-# define INT64_C(v) v ## LL
-# ifndef PRINTF_INT64_MODIFIER
-# define PRINTF_INT64_MODIFIER "ll"
-# endif
-# endif
-#endif
-
-#if !defined (stdint_int64_defined)
-# if defined(__GNUC__)
-# define stdint_int64_defined
- __extension__ typedef long long int64_t;
- __extension__ typedef unsigned long long uint64_t;
-# define UINT64_C(v) v ## ULL
-# define INT64_C(v) v ## LL
-# ifndef PRINTF_INT64_MODIFIER
-# define PRINTF_INT64_MODIFIER "ll"
-# endif
-# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
-# define stdint_int64_defined
- typedef long long int64_t;
- typedef unsigned long long uint64_t;
-# define UINT64_C(v) v ## ULL
-# define INT64_C(v) v ## LL
-# ifndef PRINTF_INT64_MODIFIER
-# define PRINTF_INT64_MODIFIER "ll"
-# endif
-# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
-# define stdint_int64_defined
- typedef __int64 int64_t;
- typedef unsigned __int64 uint64_t;
-# define UINT64_C(v) v ## UI64
-# define INT64_C(v) v ## I64
-# ifndef PRINTF_INT64_MODIFIER
-# define PRINTF_INT64_MODIFIER "I64"
-# endif
-# endif
-#endif
-
-#if !defined (LONG_LONG_MAX) && defined (INT64_C)
-# define LONG_LONG_MAX INT64_C (9223372036854775807)
-#endif
-#ifndef ULONG_LONG_MAX
-# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
-#endif
-
-#if !defined (INT64_MAX) && defined (INT64_C)
-# define INT64_MAX INT64_C (9223372036854775807)
-#endif
-#if !defined (INT64_MIN) && defined (INT64_C)
-# define INT64_MIN INT64_C (-9223372036854775808)
-#endif
-#if !defined (UINT64_MAX) && defined (INT64_C)
-# define UINT64_MAX UINT64_C (18446744073709551615)
-#endif
-
-/*
- * Width of hexadecimal for number field.
- */
-
-#ifndef PRINTF_INT64_HEX_WIDTH
-# define PRINTF_INT64_HEX_WIDTH "16"
-#endif
-#ifndef PRINTF_INT32_HEX_WIDTH
-# define PRINTF_INT32_HEX_WIDTH "8"
-#endif
-#ifndef PRINTF_INT16_HEX_WIDTH
-# define PRINTF_INT16_HEX_WIDTH "4"
-#endif
-#ifndef PRINTF_INT8_HEX_WIDTH
-# define PRINTF_INT8_HEX_WIDTH "2"
-#endif
-
-#ifndef PRINTF_INT64_DEC_WIDTH
-# define PRINTF_INT64_DEC_WIDTH "20"
-#endif
-#ifndef PRINTF_INT32_DEC_WIDTH
-# define PRINTF_INT32_DEC_WIDTH "10"
-#endif
-#ifndef PRINTF_INT16_DEC_WIDTH
-# define PRINTF_INT16_DEC_WIDTH "5"
-#endif
-#ifndef PRINTF_INT8_DEC_WIDTH
-# define PRINTF_INT8_DEC_WIDTH "3"
-#endif
-
-/*
- * Ok, lets not worry about 128 bit integers for now. Moore's law says
- * we don't need to worry about that until about 2040 at which point
- * we'll have bigger things to worry about.
- */
-
-#ifdef stdint_int64_defined
- typedef int64_t intmax_t;
- typedef uint64_t uintmax_t;
-# define INTMAX_MAX INT64_MAX
-# define INTMAX_MIN INT64_MIN
-# define UINTMAX_MAX UINT64_MAX
-# define UINTMAX_C(v) UINT64_C(v)
-# define INTMAX_C(v) INT64_C(v)
-# ifndef PRINTF_INTMAX_MODIFIER
-# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
-# endif
-# ifndef PRINTF_INTMAX_HEX_WIDTH
-# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
-# endif
-# ifndef PRINTF_INTMAX_DEC_WIDTH
-# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
-# endif
-#else
- typedef int32_t intmax_t;
- typedef uint32_t uintmax_t;
-# define INTMAX_MAX INT32_MAX
-# define UINTMAX_MAX UINT32_MAX
-# define UINTMAX_C(v) UINT32_C(v)
-# define INTMAX_C(v) INT32_C(v)
-# ifndef PRINTF_INTMAX_MODIFIER
-# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
-# endif
-# ifndef PRINTF_INTMAX_HEX_WIDTH
-# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
-# endif
-# ifndef PRINTF_INTMAX_DEC_WIDTH
-# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
-# endif
-#endif
-
-/*
- * Because this file currently only supports platforms which have
- * precise powers of 2 as bit sizes for the default integers, the
- * least definitions are all trivial. Its possible that a future
- * version of this file could have different definitions.
- */
-
-#ifndef stdint_least_defined
- typedef int8_t int_least8_t;
- typedef uint8_t uint_least8_t;
- typedef int16_t int_least16_t;
- typedef uint16_t uint_least16_t;
- typedef int32_t int_least32_t;
- typedef uint32_t uint_least32_t;
-# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
-# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
-# define UINT_LEAST8_MAX UINT8_MAX
-# define INT_LEAST8_MAX INT8_MAX
-# define UINT_LEAST16_MAX UINT16_MAX
-# define INT_LEAST16_MAX INT16_MAX
-# define UINT_LEAST32_MAX UINT32_MAX
-# define INT_LEAST32_MAX INT32_MAX
-# define INT_LEAST8_MIN INT8_MIN
-# define INT_LEAST16_MIN INT16_MIN
-# define INT_LEAST32_MIN INT32_MIN
-# ifdef stdint_int64_defined
- typedef int64_t int_least64_t;
- typedef uint64_t uint_least64_t;
-# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
-# define UINT_LEAST64_MAX UINT64_MAX
-# define INT_LEAST64_MAX INT64_MAX
-# define INT_LEAST64_MIN INT64_MIN
-# endif
-#endif
-#undef stdint_least_defined
-
-/*
- * The ANSI C committee pretending to know or specify anything about
- * performance is the epitome of misguided arrogance. The mandate of
- * this file is to *ONLY* ever support that absolute minimum
- * definition of the fast integer types, for compatibility purposes.
- * No extensions, and no attempt to suggest what may or may not be a
- * faster integer type will ever be made in this file. Developers are
- * warned to stay away from these types when using this or any other
- * stdint.h.
- */
-
-typedef int_least8_t int_fast8_t;
-typedef uint_least8_t uint_fast8_t;
-typedef int_least16_t int_fast16_t;
-typedef uint_least16_t uint_fast16_t;
-typedef int_least32_t int_fast32_t;
-typedef uint_least32_t uint_fast32_t;
-#define UINT_FAST8_MAX UINT_LEAST8_MAX
-#define INT_FAST8_MAX INT_LEAST8_MAX
-#define UINT_FAST16_MAX UINT_LEAST16_MAX
-#define INT_FAST16_MAX INT_LEAST16_MAX
-#define UINT_FAST32_MAX UINT_LEAST32_MAX
-#define INT_FAST32_MAX INT_LEAST32_MAX
-#define INT_FAST8_MIN INT_LEAST8_MIN
-#define INT_FAST16_MIN INT_LEAST16_MIN
-#define INT_FAST32_MIN INT_LEAST32_MIN
-#ifdef stdint_int64_defined
- typedef int_least64_t int_fast64_t;
- typedef uint_least64_t uint_fast64_t;
-# define UINT_FAST64_MAX UINT_LEAST64_MAX
-# define INT_FAST64_MAX INT_LEAST64_MAX
-# define INT_FAST64_MIN INT_LEAST64_MIN
-#endif
-
-#undef stdint_int64_defined
-
-/*
- * Whatever piecemeal, per compiler thing we can do about the wchar_t
- * type limits.
- */
-
-#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
-# include <wchar.h>
-# ifndef WCHAR_MIN
-# define WCHAR_MIN 0
-# endif
-# ifndef WCHAR_MAX
-# define WCHAR_MAX ((wchar_t)-1)
-# endif
-#endif
-
-/*
- * Whatever piecemeal, per compiler/platform thing we can do about the
- * (u)intptr_t types and limits.
- */
-
-#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
-# define STDINT_H_UINTPTR_T_DEFINED
-#endif
-
-#ifndef STDINT_H_UINTPTR_T_DEFINED
-# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
-# define stdint_intptr_bits 64
-# elif defined (__WATCOMC__) || defined (__TURBOC__)
-# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
-# define stdint_intptr_bits 16
-# else
-# define stdint_intptr_bits 32
-# endif
-# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
-# define stdint_intptr_bits 32
-# elif defined (__INTEL_COMPILER)
-/* TODO -- what did Intel do about x86-64? */
-# endif
-
-# ifdef stdint_intptr_bits
-# define stdint_intptr_glue3_i(a,b,c) a##b##c
-# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
-# ifndef PRINTF_INTPTR_MODIFIER
-# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
-# endif
-# ifndef PTRDIFF_MAX
-# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
-# endif
-# ifndef PTRDIFF_MIN
-# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
-# endif
-# ifndef UINTPTR_MAX
-# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
-# endif
-# ifndef INTPTR_MAX
-# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
-# endif
-# ifndef INTPTR_MIN
-# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
-# endif
-# ifndef INTPTR_C
-# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
-# endif
-# ifndef UINTPTR_C
-# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
-# endif
- typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
- typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
-# else
-/* TODO -- This following is likely wrong for some platforms, and does
- nothing for the definition of uintptr_t. */
- typedef ptrdiff_t intptr_t;
-# endif
-# define STDINT_H_UINTPTR_T_DEFINED
-#endif
-
-/*
- * Assumes sig_atomic_t is signed and we have a 2s complement machine.
- */
-
-#ifndef SIG_ATOMIC_MAX
-# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
-#endif
-
-#endif
-
-#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
-
-/*
- * Please compile with the maximum warning settings to make sure macros are not
- * defined more than once.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#define glue3_aux(x,y,z) x ## y ## z
-#define glue3(x,y,z) glue3_aux(x,y,z)
-
-#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
-#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
-
-#define DECL(us,bits) glue3(DECL,us,) (bits)
-
-#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
-
-int main () {
- DECL(I,8)
- DECL(U,8)
- DECL(I,16)
- DECL(U,16)
- DECL(I,32)
- DECL(U,32)
-#ifdef INT64_MAX
- DECL(I,64)
- DECL(U,64)
-#endif
- intmax_t imax = INTMAX_C(0);
- uintmax_t umax = UINTMAX_C(0);
- char str0[256], str1[256];
-
- sprintf (str0, "%d %x\n", 0, ~0);
-
- sprintf (str1, "%d %x\n", i8, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
- sprintf (str1, "%u %x\n", u8, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
- sprintf (str1, "%d %x\n", i16, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
- sprintf (str1, "%u %x\n", u16, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
- sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
- sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
-#ifdef INT64_MAX
- sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
-#endif
- sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
- sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
- if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
-
- TESTUMAX(8);
- TESTUMAX(16);
- TESTUMAX(32);
-#ifdef INT64_MAX
- TESTUMAX(64);
-#endif
-
- return EXIT_SUCCESS;
-}
-
-#endif
diff --git a/include/regchannel.h b/include/regchannel.h
index 0e1ca0bce..9a7bf9880 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -6,8 +6,7 @@
* Please read COPYING and README for further details.
*/
-#ifndef REGCHANNEL_H
-#define REGCHANNEL_H
+#pragma once
#include "memo.h"
#include "modes.h"
@@ -17,14 +16,15 @@
#include "serialize.h"
#include "bots.h"
-typedef Anope::hash_map<ChannelInfo *> registered_channel_map;
+typedef Anope::unordered_map<ChannelInfo *> registered_channel_map;
extern CoreExport Serialize::Checker<registered_channel_map> RegisteredChannelList;
/* AutoKick data. */
-class CoreExport AutoKick : public Serializable
+class CoreExport AutoKick final
+ : public Serializable
{
- public:
+public:
/* Channel this autokick is on */
Serialize::Reference<ChannelInfo> ci;
@@ -38,24 +38,26 @@ class CoreExport AutoKick : public Serializable
AutoKick();
~AutoKick();
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
};
/* It matters that Base is here before Extensible (it is inherited by Serializable)
*/
-class CoreExport ChannelInfo : public Serializable, public Extensible
+class CoreExport ChannelInfo final
+ : public Serializable
+ , public Extensible
{
/* channels who reference this one */
Anope::map<int> references;
- private:
+private:
Serialize::Reference<NickCore> founder; /* Channel founder */
Serialize::Reference<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */
Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */
Serialize::Checker<std::vector<AutoKick *> > akick; /* List of users to kickban */
Anope::map<int16_t> levels;
- public:
+public:
friend class ChanAccess;
friend class AutoKick;
@@ -93,9 +95,10 @@ class CoreExport ChannelInfo : public Serializable, public Extensible
ChannelInfo(const ChannelInfo &ci);
~ChannelInfo();
+ ChannelInfo &operator=(const ChannelInfo &) = default;
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
/** Change the founder of the channel
* @params nc The new founder
@@ -166,7 +169,7 @@ class CoreExport ChannelInfo : public Serializable, public Extensible
* @param t The time the akick was added, defaults to now
* @param lu The time the akick was last used, defaults to never
*/
- AutoKick* AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
+ AutoKick *AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
/** Add an akick entry to the channel by reason
* @param user The user who added the akick
@@ -175,13 +178,13 @@ class CoreExport ChannelInfo : public Serializable, public Extensible
* @param t The time the akick was added, defaults to now
* @param lu The time the akick was last used, defaults to never
*/
- AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
+ AutoKick *AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
/** Get an entry from the channel akick list
* @param index The index in the akick vector
* @return The akick structure, or NULL if not found
*/
- AutoKick* GetAkick(unsigned index) const;
+ AutoKick *GetAkick(unsigned index) const;
/** Get the size of the akick vector for this channel
* @return The akick vector size
@@ -235,7 +238,7 @@ class CoreExport ChannelInfo : public Serializable, public Extensible
* @param name channel name to lookup
* @return the ChannelInfo associated with the channel
*/
- static ChannelInfo* Find(const Anope::string &name);
+ static ChannelInfo *Find(const Anope::string &name);
void AddChannelReference(const Anope::string &what);
void RemoveChannelReference(const Anope::string &what);
@@ -248,5 +251,3 @@ class CoreExport ChannelInfo : public Serializable, public Extensible
* @return true or false
*/
extern CoreExport bool IsFounder(const User *user, const ChannelInfo *ci);
-
-#endif // REGCHANNEL_H
diff --git a/include/regexpr.h b/include/regexpr.h
index fde1501c1..aecf38f5f 100644
--- a/include/regexpr.h
+++ b/include/regexpr.h
@@ -9,37 +9,36 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef REGEXPR_H
-#define REGEXPR_H
+#pragma once
#include "services.h"
#include "anope.h"
#include "service.h"
-class RegexException : public CoreException
+class CoreExport RegexException final
+ : public CoreException
{
- public:
+public:
RegexException(const Anope::string &reason = "") : CoreException(reason) { }
- virtual ~RegexException() throw() { }
+ virtual ~RegexException() noexcept = default;
};
class CoreExport Regex
{
Anope::string expression;
- protected:
+protected:
Regex(const Anope::string &expr) : expression(expr) { }
- public:
- virtual ~Regex() { }
+public:
+ virtual ~Regex() = default;
const Anope::string &GetExpression() { return expression; }
virtual bool Matches(const Anope::string &str) = 0;
};
-class CoreExport RegexProvider : public Service
+class CoreExport RegexProvider
+ : public Service
{
- public:
+public:
RegexProvider(Module *o, const Anope::string &n) : Service(o, "Regex", n) { }
virtual Regex *Compile(const Anope::string &) = 0;
};
-
-#endif // REGEXPR_H
diff --git a/include/serialize.h b/include/serialize.h
index a0842a3f0..1459a1ebd 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef SERIALIZE_H
-#define SERIALIZE_H
+#pragma once
#include <sstream>
@@ -19,23 +18,44 @@
namespace Serialize
{
+ enum class DataType
+ : uint8_t
+ {
+ BOOL,
+ FLOAT,
+ INT,
+ TEXT,
+ UINT,
+ };
+
class Data
{
- public:
- enum Type
- {
- DT_TEXT,
- DT_INT
- };
+ public:
+ virtual ~Data() = default;
+
+ virtual std::iostream &operator[](const Anope::string &key) = 0;
- virtual ~Data() { }
+ template <typename T>
+ void Store(const Anope::string &key, const T &value)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<T>>;
+
+ if constexpr (std::is_same_v<Type, bool>)
+ SetType(key, DataType::BOOL);
+ else if constexpr (std::is_floating_point_v<Type>)
+ SetType(key, DataType::FLOAT);
+ else if constexpr (std::is_integral_v<Type> && std::is_signed_v<Type>)
+ SetType(key, DataType::INT);
+ else if constexpr (std::is_integral_v<Type> && std::is_unsigned_v<Type>)
+ SetType(key, DataType::UINT);
+
+ this->operator[](key) << value;
+ }
- virtual std::iostream& operator[](const Anope::string &key) = 0;
- virtual std::set<Anope::string> KeySet() const { throw CoreException("Not supported"); }
virtual size_t Hash() const { throw CoreException("Not supported"); }
- virtual void SetType(const Anope::string &key, Type t) { }
- virtual Type GetType(const Anope::string &key) const { return DT_TEXT; }
+ virtual void SetType(const Anope::string &key, DataType dt) { }
+ virtual DataType GetType(const Anope::string &key) const { return DataType::TEXT; }
};
extern void RegisterTypes();
@@ -50,9 +70,10 @@ namespace Serialize
* abstract data types (Serialize::Data), and then reconstructed or
* updated later at any time.
*/
-class CoreExport Serializable : public virtual Base
+class CoreExport Serializable
+ : public virtual Base
{
- private:
+private:
/* A list of every serializable item in Anope.
* Some of these are static and constructed at runtime,
* so this list must be on the heap, as it is not always
@@ -65,24 +86,24 @@ class CoreExport Serializable : public virtual Base
/* Iterator into serializable_items */
std::list<Serializable *>::iterator s_iter;
/* The hash of the last serialized form of this object committed to the database */
- size_t last_commit;
+ size_t last_commit = 0;
/* The last time this object was committed to the database */
- time_t last_commit_time;
+ time_t last_commit_time = 0;
- protected:
+protected:
Serializable(const Anope::string &serialize_type);
Serializable(const Serializable &);
Serializable &operator=(const Serializable &);
- public:
+public:
virtual ~Serializable();
/* Unique ID (per type, not globally) for this object */
- uint64_t id;
+ uint64_t id = 0;
/* Only used by redis, to ignore updates */
- unsigned short redis_ignore;
+ unsigned short redis_ignore = 0;
/** Marks the object as potentially being updated "soon".
*/
@@ -97,7 +118,7 @@ class CoreExport Serializable : public virtual Base
/** Get the type of serializable object this is
* @return The serializable object type
*/
- Serialize::Type* GetSerializableType() const { return this->s_type; }
+ Serialize::Type *GetSerializableType() const { return this->s_type; }
virtual void Serialize(Serialize::Data &data) const = 0;
@@ -108,9 +129,10 @@ class CoreExport Serializable : public virtual Base
* of class that inherits from Serializable. Used for unserializing objects
* of this type, as it requires a function pointer to a static member function.
*/
-class CoreExport Serialize::Type : public Base
+class CoreExport Serialize::Type final
+ : public Base
{
- typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &);
+ typedef Serializable *(*unserialize_func)(Serializable *obj, Serialize::Data &);
static std::vector<Anope::string> TypeOrder;
static std::map<Anope::string, Serialize::Type *> Types;
@@ -127,9 +149,9 @@ class CoreExport Serialize::Type : public Base
* this timestamp. if curtime == timestamp then we have the most up to date
* version of every object of this type.
*/
- time_t timestamp;
+ time_t timestamp = 0;
- public:
+public:
/* Map of Serializable::id to Serializable objects */
std::map<uint64_t, Serializable *> objects;
@@ -167,7 +189,7 @@ class CoreExport Serialize::Type : public Base
*/
void UpdateTimestamp();
- Module* GetOwner() const { return this->owner; }
+ Module *GetOwner() const { return this->owner; }
static Serialize::Type *Find(const Anope::string &name);
@@ -187,7 +209,7 @@ class Serialize::Checker
{
Anope::string name;
T obj;
- mutable ::Reference<Serialize::Type> type;
+ mutable ::Reference<Serialize::Type> type = nullptr;
inline void Check() const
{
@@ -197,26 +219,26 @@ class Serialize::Checker
type->Check();
}
- public:
- Checker(const Anope::string &n) : name(n), type(NULL) { }
+public:
+ Checker(const Anope::string &n) : name(n) { }
- inline const T* operator->() const
+ inline const T *operator->() const
{
this->Check();
return &this->obj;
}
- inline T* operator->()
+ inline T *operator->()
{
this->Check();
return &this->obj;
}
- inline const T& operator*() const
+ inline const T &operator*() const
{
this->Check();
return this->obj;
}
- inline T& operator*()
+ inline T &operator*()
{
this->Check();
return this->obj;
@@ -241,15 +263,14 @@ class Serialize::Checker
* destructed.
*/
template<typename T>
-class Serialize::Reference : public ReferenceBase
+class Serialize::Reference final
+ : public ReferenceBase
{
- protected:
- T *ref;
+protected:
+ T *ref = nullptr;
- public:
- Reference() : ref(NULL)
- {
- }
+public:
+ Reference() = default;
Reference(T *obj) : ref(obj)
{
@@ -305,7 +326,7 @@ class Serialize::Reference : public ReferenceBase
return NULL;
}
- inline T* operator*() const
+ inline T *operator*() const
{
if (!this->invalid)
{
@@ -318,7 +339,7 @@ class Serialize::Reference : public ReferenceBase
return NULL;
}
- inline T* operator->() const
+ inline T *operator->() const
{
if (!this->invalid)
{
@@ -331,5 +352,3 @@ class Serialize::Reference : public ReferenceBase
return NULL;
}
};
-
-#endif // SERIALIZE_H
diff --git a/include/servers.h b/include/servers.h
index cc97c25ec..5c78cc979 100644
--- a/include/servers.h
+++ b/include/servers.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef SERVERS_H
-#define SERVERS_H
+#pragma once
#include "services.h"
#include "anope.h"
@@ -26,7 +25,7 @@ namespace Servers
* the only server whose uplink *is* Me that is not a juped server.
* @return Our uplink, or NULL if not uplinked to anything
*/
- extern CoreExport Server* GetUplink();
+ extern CoreExport Server *GetUplink();
/* Server maps by name and id */
extern CoreExport Anope::map<Server *> ByName;
@@ -38,9 +37,10 @@ namespace Servers
/** Class representing a server
*/
-class CoreExport Server : public Extensible
+class CoreExport Server final
+ : public Extensible
{
- private:
+private:
/* Server name */
Anope::string name;
/* Hops between services and server */
@@ -62,7 +62,7 @@ class CoreExport Server : public Extensible
/* Reason this server was quit */
Anope::string quit_reason;
- public:
+public:
/** Constructor
* @param uplink The uplink this server is from, is only NULL when creating Me
* @param name The server name
@@ -73,14 +73,14 @@ class CoreExport Server : public Extensible
*/
Server(Server *uplink, const Anope::string &name, unsigned hops, const Anope::string &description, const Anope::string &sid = "", bool jupe = false);
- private:
+private:
/** Destructor
*/
~Server();
- public:
+public:
/* Number of users on the server */
- unsigned users;
+ unsigned users = 0;
/** Delete this server with a reason
* @param reason The reason
@@ -183,5 +183,3 @@ class CoreExport Server : public Extensible
*/
static Server *Find(const Anope::string &name, bool name_only = false);
};
-
-#endif // SERVERS_H
diff --git a/include/service.h b/include/service.h
index ee5168b85..ad1d12f92 100644
--- a/include/service.h
+++ b/include/service.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef SERVICE_H
-#define SERVICE_H
+#pragma once
#include "services.h"
#include "anope.h"
@@ -21,7 +20,8 @@
* such as commands, use this. This is also used for modules
* that publish a service (m_ssl_openssl, etc).
*/
-class CoreExport Service : public virtual Base
+class CoreExport Service
+ : public virtual Base
{
static std::map<Anope::string, std::map<Anope::string, Service *> > Services;
static std::map<Anope::string, std::map<Anope::string, Anope::string> > Aliases;
@@ -42,7 +42,7 @@ class CoreExport Service : public virtual Base
return NULL;
}
- public:
+public:
static Service *FindService(const Anope::string &t, const Anope::string &n)
{
std::map<Anope::string, std::map<Anope::string, Service *> >::const_iterator it = Services.find(t);
@@ -59,13 +59,27 @@ class CoreExport Service : public virtual Base
static std::vector<Anope::string> GetServiceKeys(const Anope::string &t)
{
std::vector<Anope::string> keys;
- std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = Services.find(t);
+ const auto it = Services.find(t);
if (it != Services.end())
- for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
- keys.push_back(it2->first);
+ {
+ for (const auto &[key, _] : it->second)
+ keys.push_back(key);
+ }
return keys;
}
+ static std::vector<Service *> GetServices(const Anope::string &t)
+ {
+ std::vector<Service *> values;
+ const auto it = Services.find(t);
+ if (it != Services.end())
+ {
+ for (const auto &[_, value] : it->second)
+ values.push_back(value);
+ }
+ return values;
+ }
+
static void AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v)
{
std::map<Anope::string, Anope::string> &smap = Aliases[t];
@@ -98,10 +112,8 @@ class CoreExport Service : public virtual Base
void Register()
{
- std::map<Anope::string, Service *> &smap = Services[this->type];
- if (smap.find(this->name) != smap.end())
+ if (!Services[this->type].emplace(this->name, this).second)
throw ModuleException("Service " + this->type + " with name " + this->name + " already exists");
- smap[this->name] = this;
}
void Unregister()
@@ -113,16 +125,17 @@ class CoreExport Service : public virtual Base
}
};
-/** Like Reference, but used to refer to Services.
+/** Like Reference, but used to refer to a Service.
*/
template<typename T>
-class ServiceReference : public Reference<T>
+class ServiceReference
+ : public Reference<T>
{
Anope::string type;
Anope::string name;
- public:
- ServiceReference() { }
+public:
+ ServiceReference() = default;
ServiceReference(const Anope::string &t, const Anope::string &n) : type(t), name(n)
{
@@ -138,7 +151,7 @@ class ServiceReference : public Reference<T>
this->invalid = true;
}
- operator bool() anope_override
+ operator bool() override
{
if (this->invalid)
{
@@ -159,10 +172,10 @@ class ServiceReference : public Reference<T>
}
};
-class ServiceAlias
+class ServiceAlias final
{
Anope::string t, f;
- public:
+public:
ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to) : t(type), f(from)
{
Service::AddAlias(type, from, to);
@@ -173,5 +186,3 @@ class ServiceAlias
Service::DelAlias(t, f);
}
};
-
-#endif // SERVICE_H
diff --git a/include/services.h b/include/services.h
index 722636379..7f0752d11 100644
--- a/include/services.h
+++ b/include/services.h
@@ -9,60 +9,43 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef SERVICES_H
-#define SERVICES_H
-
-#include "sysconf.h"
-
-#define BUFSIZE 1024
+#pragma once
+#include <cstdarg>
+#include <cstddef>
+#include <cstdint>
#include <cstdio>
#include <cstdlib>
-#include <cstdarg>
-#include <stdexcept>
-
-#include <string.h>
-#if HAVE_STRINGS_H
-# include <strings.h>
-#endif
+#include <cstring>
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
-/* Pull in the various bits of STL */
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <map>
+#include <algorithm>
+#include <bitset>
+#include <deque>
#include <exception>
+#include <fstream>
+#include <iostream>
#include <list>
-#include <vector>
-#include <deque>
-#include <bitset>
+#include <map>
#include <set>
-#include <algorithm>
-#include <iterator>
+#include <sstream>
+#include <vector>
+
+#ifndef _WIN32
+# include <unistd.h>
+#endif
#include "defs.h"
+#include "sysconf.h"
-#define _(x) x
+#define BUFSIZE 1024
-#if defined __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L
-# define anope_override override
-# define anope_final final
-#else
-# define anope_override
-# define anope_final
-#endif
+#define _(x) x
+#define N_(x, y) x, y
#ifndef _WIN32
-# define DllExport
-# define CoreExport
-# define MARK_DEPRECATED __attribute((deprecated))
+# define DllExport __attribute__ ((visibility ("default")))
+# define CoreExport __attribute__ ((visibility ("default")))
# define anope_close close
#else
# include "anope_windows.h"
#endif
-
-#endif // SERVICES_H
diff --git a/include/socketengine.h b/include/socketengine.h
index e5b30ec92..83eaa3705 100644
--- a/include/socketengine.h
+++ b/include/socketengine.h
@@ -9,16 +9,15 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef SOCKETENGINE_H
-#define SOCKETENGINE_H
+#pragma once
#include "services.h"
#include "sockets.h"
-class CoreExport SocketEngine
+class CoreExport SocketEngine final
{
static const int DefaultSize = 2; // Uplink, mode stacker
- public:
+public:
/* Map of sockets */
static std::map<int, Socket *> Sockets;
@@ -46,5 +45,3 @@ class CoreExport SocketEngine
static bool IgnoreErrno();
};
-
-#endif // SOCKETENGINE_H
diff --git a/include/sockets.h b/include/sockets.h
index dcdb49a5e..e9b40685c 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -9,17 +9,22 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef SOCKETS_H
-#define SOCKETS_H
+#pragma once
#ifndef _WIN32
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/un.h>
#endif
#include "anope.h"
+// This has to be after anope.h
+#ifdef _WIN32
+# include <afunix.h>
+#endif
+
#define NET_BUFSIZE 65535
/** A sockaddr union used to combine IPv4 and IPv6 sockaddrs
@@ -29,6 +34,7 @@ union CoreExport sockaddrs
sockaddr sa;
sockaddr_in sa4;
sockaddr_in6 sa6;
+ sockaddr_un saun;
/** Construct the object, sets everything to 0
*/
@@ -57,6 +63,11 @@ union CoreExport sockaddrs
*/
Anope::string addr() const;
+ /** Gets the endpoint represented by this addr.
+ * @return The endpoint.
+ */
+ Anope::string str() const;
+
/** Get the reverse address represented by this addr
* @return The reverse address
*/
@@ -92,12 +103,12 @@ union CoreExport sockaddrs
void ntop(int type, const void *src);
};
-class CoreExport cidr
+class CoreExport cidr final
{
sockaddrs addr;
Anope::string cidr_ip;
unsigned short cidr_len;
- public:
+public:
cidr(const Anope::string &ip);
cidr(const Anope::string &ip, unsigned char len);
cidr(const sockaddrs &ip, unsigned char len);
@@ -109,15 +120,16 @@ class CoreExport cidr
bool operator==(const cidr &other) const;
bool operator!=(const cidr &other) const;
- struct CoreExport hash
+ struct CoreExport hash final
{
size_t operator()(const cidr &s) const;
};
};
-class SocketException : public CoreException
+class CoreExport SocketException final
+ : public CoreException
{
- public:
+public:
/** Constructor for socket exceptions
* @param message Error message
*/
@@ -126,7 +138,7 @@ class SocketException : public CoreException
/** Destructor
* @throws Nothing
*/
- virtual ~SocketException() throw() { }
+ virtual ~SocketException() noexcept = default;
};
enum SocketFlag
@@ -143,8 +155,8 @@ enum SocketFlag
class CoreExport SocketIO
{
- public:
- virtual ~SocketIO() { }
+public:
+ virtual ~SocketIO() = default;
/** Receive something from the buffer
* @param s The socket
@@ -152,15 +164,15 @@ class CoreExport SocketIO
* @param sz How much to read
* @return Number of bytes received
*/
- virtual int Recv(Socket *s, char *buf, size_t sz);
+ virtual ssize_t Recv(Socket *s, char *buf, size_t sz);
/** Write something to the socket
* @param s The socket
* @param buf The data to write
* @param size The length of the data
*/
- virtual int Send(Socket *s, const char *buf, size_t sz);
- int Send(Socket *s, const Anope::string &buf);
+ virtual ssize_t Send(Socket *s, const char *buf, size_t sz);
+ ssize_t Send(Socket *s, const Anope::string &buf);
/** Accept a connection from a socket
* @param s The socket
@@ -201,13 +213,14 @@ class CoreExport SocketIO
class CoreExport Socket
{
- protected:
+protected:
/* Socket FD */
int sock;
- /* Is this an IPv6 socket? */
- bool ipv6;
- public:
+ /* The family of this socket FD */
+ int family;
+
+public:
std::bitset<SF_SIZE> flags;
/* Sockaddrs for bind() (if it's bound) */
@@ -222,25 +235,25 @@ class CoreExport Socket
/** Constructor, possibly creates the socket and adds it to the engine
* @param sock The socket to use, -1 if we need to create our own
- * @param ipv6 true if using ipv6
+ * @param family The family of the socket
* @param type The socket type, defaults to SOCK_STREAM
*/
- Socket(int sock, bool ipv6 = false, int type = SOCK_STREAM);
+ Socket(int sock, int family = AF_INET, int type = SOCK_STREAM);
/** Destructor, closes the socket and removes it from the engine
*/
virtual ~Socket();
+ /** Get the socket family for this socket
+ * @return the family
+ */
+ int GetFamily() const;
+
/** Get the socket FD for this socket
* @return the fd
*/
int GetFD() const;
- /** Check if this socket is IPv6
- * @return true or false
- */
- bool IsIPv6() const;
-
/** Mark a socket as (non)blocking
* @param state true to enable blocking, false to disable blocking
* @return true if the socket is now blocking
@@ -274,9 +287,10 @@ class CoreExport Socket
virtual void ProcessError();
};
-class CoreExport BufferedSocket : public virtual Socket
+class CoreExport BufferedSocket
+ : public virtual Socket
{
- protected:
+protected:
/* Things read from the socket */
Anope::string read_buffer;
/* Things to be written to the socket */
@@ -284,31 +298,30 @@ class CoreExport BufferedSocket : public virtual Socket
/* How much data was received from this socket on this recv() */
int recv_len;
- public:
- BufferedSocket();
- virtual ~BufferedSocket();
+public:
+ virtual ~BufferedSocket() = default;
/** Called when there is something to be received for this socket
* @return true on success, false to drop this socket
*/
- bool ProcessRead() anope_override;
+ bool ProcessRead() override;
/** Called when the socket is ready to be written to
* @return true on success, false to drop this socket
*/
- bool ProcessWrite() anope_override;
+ bool ProcessWrite() override;
/** Gets the new line from the input buffer, if any
*/
- const Anope::string GetLine();
+ Anope::string GetLine();
/** Write to the socket
* @param message The message
*/
- protected:
+protected:
virtual void Write(const char *buffer, size_t l);
- public:
- void Write(const char *message, ...);
+public:
+ void Write(const char *message, ...) ATTR_FORMAT(2, 3);
void Write(const Anope::string &message);
/** Get the length of the read buffer
@@ -322,10 +335,11 @@ class CoreExport BufferedSocket : public virtual Socket
int WriteBufferLen() const;
};
-class CoreExport BinarySocket : public virtual Socket
+class CoreExport BinarySocket
+ : public virtual Socket
{
- protected:
- struct DataBlock
+protected:
+ struct DataBlock final
{
char *orig;
char *buf;
@@ -338,26 +352,25 @@ class CoreExport BinarySocket : public virtual Socket
/* Data to be written out */
std::deque<DataBlock *> write_buffer;
- public:
- BinarySocket();
- virtual ~BinarySocket();
+public:
+ virtual ~BinarySocket() = default;
/** Called when there is something to be received for this socket
* @return true on success, false to drop this socket
*/
- bool ProcessRead() anope_override;
+ bool ProcessRead() override;
/** Called when the socket is ready to be written to
* @return true on success, false to drop this socket
*/
- bool ProcessWrite() anope_override;
+ bool ProcessWrite() override;
/** Write data to the socket
* @param buffer The data to write
* @param l The length of the data; if 0 then this function returns without doing anything
*/
virtual void Write(const char *buffer, size_t l);
- void Write(const char *message, ...);
+ void Write(const char *message, ...) ATTR_FORMAT(2, 3);
void Write(const Anope::string &message);
/** Called with data from the socket
@@ -368,16 +381,17 @@ class CoreExport BinarySocket : public virtual Socket
virtual bool Read(const char *buffer, size_t l);
};
-class CoreExport ListenSocket : public virtual Socket
+class CoreExport ListenSocket
+ : public virtual Socket
{
- public:
+public:
/** Constructor
* @param bindip The IP to bind to
* @param port The port to listen on
* @param ipv6 true for ipv6
*/
ListenSocket(const Anope::string &bindip, int port, bool ipv6);
- virtual ~ListenSocket();
+ virtual ~ListenSocket() = default;
/** Process what has come in from the connection
* @return false to destroy this socket
@@ -392,9 +406,10 @@ class CoreExport ListenSocket : public virtual Socket
virtual ClientSocket *OnAccept(int fd, const sockaddrs &addr) = 0;
};
-class CoreExport ConnectionSocket : public virtual Socket
+class CoreExport ConnectionSocket
+ : public virtual Socket
{
- public:
+public:
/* Sockaddrs for connection ip/port */
sockaddrs conaddr;
@@ -408,12 +423,12 @@ class CoreExport ConnectionSocket : public virtual Socket
* Used to determine whether or not this socket is connected yet.
* @return true to continue to call ProcessRead/ProcessWrite, false to not continue
*/
- bool Process() anope_override;
+ bool Process() override;
/** Called when there is an error for this socket
* @return true on success, false to drop this socket
*/
- void ProcessError() anope_override;
+ void ProcessError() override;
/** Called on a successful connect
*/
@@ -425,9 +440,10 @@ class CoreExport ConnectionSocket : public virtual Socket
virtual void OnError(const Anope::string &error);
};
-class CoreExport ClientSocket : public virtual Socket
+class CoreExport ClientSocket
+ : public virtual Socket
{
- public:
+public:
/* Listen socket this connection came from */
ListenSocket *ls;
/* Clients address */
@@ -443,12 +459,12 @@ class CoreExport ClientSocket : public virtual Socket
* Used to determine whether or not this socket is connected yet.
* @return true to continue to call ProcessRead/ProcessWrite, false to not continue
*/
- bool Process() anope_override;
+ bool Process() override;
/** Called when there is an error for this socket
* @return true on success, false to drop this socket
*/
- void ProcessError() anope_override;
+ void ProcessError() override;
/** Called when a client has been accepted() successfully.
*/
@@ -459,9 +475,10 @@ class CoreExport ClientSocket : public virtual Socket
virtual void OnError(const Anope::string &error);
};
-class CoreExport Pipe : public Socket
+class CoreExport Pipe
+ : public Socket
{
- public:
+public:
/** The FD of the write pipe
* this->sock is the readfd
*/
@@ -472,7 +489,7 @@ class CoreExport Pipe : public Socket
/** Called when data is to be read, reads the data then calls OnNotify
*/
- bool ProcessRead() anope_override;
+ bool ProcessRead() override;
/** Write data to this pipe
* @param data The data to write
@@ -486,7 +503,7 @@ class CoreExport Pipe : public Socket
* @param sz The size of the buffer
* @return The amount of data read
*/
- int Read(char *data, size_t sz);
+ ssize_t Read(char *data, size_t sz);
/** Mark the write end of this pipe (non)blocking
* @param state true to enable blocking, false to disable blocking
@@ -507,5 +524,3 @@ class CoreExport Pipe : public Socket
extern CoreExport uint32_t TotalRead;
extern CoreExport uint32_t TotalWritten;
extern CoreExport SocketIO NormalSocketIO;
-
-#endif // SOCKET_H
diff --git a/include/sysconf.h.cmake b/include/sysconf.h.cmake
index 5f0e275c3..71290dfca 100644
--- a/include/sysconf.h.cmake
+++ b/include/sysconf.h.cmake
@@ -1,47 +1,58 @@
-#ifndef _SYSCONF_H_
-#define _SYSCONF_H_
+/*
+ *
+ * (C) 2003-2025 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
-#cmakedefine DEBUG_BUILD
+#pragma once
+// The default umask to use for files.
#cmakedefine DEFUMASK @DEFUMASK@
-#cmakedefine HAVE_CSTDINT 1
-#cmakedefine HAVE_STDINT_H 1
-#cmakedefine HAVE_STDDEF_H 1
-#cmakedefine HAVE_STRCASECMP 1
-#cmakedefine HAVE_STRICMP 1
-#cmakedefine HAVE_STRINGS_H 1
-#cmakedefine HAVE_UMASK 1
-#cmakedefine HAVE_EVENTFD 1
-#cmakedefine HAVE_EPOLL 1
-#cmakedefine HAVE_POLL 1
-#cmakedefine GETTEXT_FOUND 1
-
-#ifdef HAVE_CSTDINT
-# include <cstdint>
-#else
-# ifdef HAVE_STDINT_H
-# include <stdint.h>
-# else
-# include "pstdint.h"
-# endif
-#endif
-#ifdef HAVE_STDDEF_H
-# include <stddef.h>
-#endif
+
+// The extension used for module file extensions.
+#define DLL_EXT "@CMAKE_SHARED_LIBRARY_SUFFIX@"
+
+// Whether Anope was built in debug mode.
+#cmakedefine01 DEBUG_BUILD
+
+// The default config directory.
+#define DEFAULT_CONF_DIR "@CONF_DIR@"
+
+// The default data directory.
+#define DEFAULT_DATA_DIR "@DATA_DIR@"
+
+// The default locale directory.
+#define DEFAULT_LOCALE_DIR "@LOCALE_DIR@"
+
+// The default log directory.
+#define DEFAULT_LOG_DIR "@LOG_DIR@"
+
+// The default module directory.
+#define DEFAULT_MODULE_DIR "@MODULE_DIR@"
+
+// Whether the clock_gettime() function is available.
+#cmakedefine01 HAVE_CLOCK_GETTIME
+
+// Whether Anope was built with localization support.
+#cmakedefine01 HAVE_LOCALIZATION
+
+// Whether the umask() function is available.
+#cmakedefine01 HAVE_UMASK
#ifdef _WIN32
# define popen _popen
# define pclose _pclose
-# define ftruncate _chsize
-# ifdef MSVCPP
-# define PATH_MAX MAX_PATH
-# endif
-# define MAXPATHLEN MAX_PATH
-# define bzero(buf, size) memset(buf, 0, size)
-# ifdef MSVCPP
-# define strcasecmp stricmp
-# endif
-# define sleep(x) Sleep(x * 1000)
#endif
+#if defined __GNUC__
+# define ATTR_FORMAT(STRINGPOS, FIRSTPOS) __attribute__((format(printf, STRINGPOS, FIRSTPOS)))
+# define ATTR_NOT_NULL(...) __attribute__((nonnull(__VA_ARGS__)))
+#else
+# define ATTR_FORMAT(STRINGPOS, FIRSTPOS)
+# define ATTR_NOT_NULL(...)
#endif
diff --git a/include/threadengine.h b/include/threadengine.h
index c7c88d157..b8184d8a8 100644
--- a/include/threadengine.h
+++ b/include/threadengine.h
@@ -9,29 +9,28 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef THREADENGINE_H
-#define THREADENGINE_H
+#pragma once
#include "sockets.h"
#include "extensible.h"
-class CoreExport Thread : public Pipe, public Extensible
+#include <thread>
+
+class CoreExport Thread
+ : public Pipe
+ , public Extensible
{
- private:
+private:
/* Set to true to tell the thread to finish and we are waiting for it */
- bool exit;
+ bool exit = false;
- public:
+public:
/* Handle for this thread */
- pthread_t handle;
-
- /** Threads constructor
- */
- Thread();
+ std::unique_ptr<std::thread> handle;
/** Threads destructor
*/
- virtual ~Thread();
+ virtual ~Thread() = default;
/** Join to the thread, sets the exit state to true
*/
@@ -62,59 +61,3 @@ class CoreExport Thread : public Pipe, public Extensible
*/
virtual void Run() = 0;
};
-
-class CoreExport Mutex
-{
- protected:
- /* A mutex, used to keep threads in sync */
- pthread_mutex_t mutex;
-
- public:
- /** Constructor
- */
- Mutex();
-
- /** Destructor
- */
- ~Mutex();
-
- /** Attempt to lock the mutex, will hang until a lock can be achieved
- */
- void Lock();
-
- /** Unlock the mutex, it must be locked first
- */
- void Unlock();
-
- /** Attempt to lock the mutex, will return true on success and false on fail
- * Does not block
- * @return true or false
- */
- bool TryLock();
-};
-
-class CoreExport Condition : public Mutex
-{
- private:
- /* A condition */
- pthread_cond_t cond;
-
- public:
- /** Constructor
- */
- Condition();
-
- /** Destructor
- */
- ~Condition();
-
- /** Called to wakeup the waiter
- */
- void Wakeup();
-
- /** Called to wait for a Wakeup() call
- */
- void Wait();
-};
-
-#endif // THREADENGINE_H
diff --git a/include/timers.h b/include/timers.h
index 2764ccc56..f4ee47b75 100644
--- a/include/timers.h
+++ b/include/timers.h
@@ -9,49 +9,42 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef TIMERS_H
-#define TIMERS_H
+#pragma once
#include "anope.h"
class CoreExport Timer
{
- private:
+private:
/** The owner of the timer, if any
*/
- Module *owner;
-
- /** The time this was created
- */
- time_t settime;
+ Module *owner = nullptr;
/** The triggering time
*/
time_t trigger;
- /** Numer of seconds between triggers
+ /** Number of seconds between triggers
*/
- long secs;
+ time_t secs;
/** True if this is a repeating timer
*/
bool repeat;
- public:
+public:
/** Constructor, initializes the triggering time
* @param time_from_now The number of seconds from now to trigger the timer
- * @param now The time now
* @param repeating Repeat this timer every time_from_now if this is true
*/
- Timer(long time_from_now, time_t now = Anope::CurTime, bool repeating = false);
+ Timer(time_t time_from_now, bool repeating = false);
/** Constructor, initializes the triggering time
* @param creator The creator of the timer
* @param time_from_now The number of seconds from now to trigger the timer
- * @param now The time now
* @param repeating Repeat this timer every time_from_now if this is true
*/
- Timer(Module *creator, long time_from_now, time_t now = Anope::CurTime, bool repeating = false);
+ Timer(Module *creator, time_t time_from_now, bool repeating = false);
/** Destructor, removes the timer from the list
*/
@@ -82,11 +75,6 @@ class CoreExport Timer
*/
long GetSecs() const;
- /** Returns the time this timer was created
- * @return The time this timer was created
- */
- time_t GetSetTime() const;
-
/** Returns the owner of this timer, if any
* @return The owner of the timer
*/
@@ -95,19 +83,19 @@ class CoreExport Timer
/** Called when the timer ticks
* This should be overridden with something useful
*/
- virtual void Tick(time_t ctime) = 0;
+ virtual void Tick() = 0;
};
/** This class manages sets of Timers, and triggers them at their defined times.
* This will ensure timers are not missed, as well as removing timers that have
* expired and allowing the addition of new ones.
*/
-class CoreExport TimerManager
+class CoreExport TimerManager final
{
/** A list of timers
*/
static std::multimap<time_t, Timer *> Timers;
- public:
+public:
/** Add a timer to the list
* @param t A Timer derived class to add
*/
@@ -121,11 +109,9 @@ class CoreExport TimerManager
/** Tick all pending timers
* @param ctime The current time
*/
- static void TickTimers(time_t ctime = Anope::CurTime);
+ static void TickTimers();
/** Deletes all timers owned by the given module
*/
static void DeleteTimersFor(Module *m);
};
-
-#endif // TIMERS_H
diff --git a/include/uplink.h b/include/uplink.h
index 035ab5b27..ffa389345 100644
--- a/include/uplink.h
+++ b/include/uplink.h
@@ -9,45 +9,53 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef UPLINK_H
-#define UPLINK_H
+#pragma once
#include "sockets.h"
#include "protocol.h"
+#include "servers.h"
namespace Uplink
{
extern void Connect();
+ extern CoreExport void SendInternal(const Anope::map<Anope::string> &, const MessageSource &, const Anope::string &, const std::vector<Anope::string> &);
+
+ template<typename... Args>
+ void Send(const Anope::map<Anope::string> &tags, const MessageSource &source, const Anope::string &command, Args &&...args)
+ {
+ SendInternal(tags, source, command, { Anope::ToString(args)... });
+ }
+
+ template<typename... Args>
+ void Send(const Anope::map<Anope::string> &tags, const Anope::string &command, Args &&...args)
+ {
+ SendInternal(tags, Me, command, { Anope::ToString(args)... });
+ }
+
+ template<typename... Args>
+ void Send(const MessageSource &source, const Anope::string &command, Args &&...args)
+ {
+ SendInternal({}, source, command, { Anope::ToString(args)... });
+ }
+
+ template<typename... Args>
+ void Send(const Anope::string &command, Args &&...args)
+ {
+ SendInternal({}, Me, command, { Anope::ToString(args)... });
+ }
}
/* This is the socket to our uplink */
-class UplinkSocket : public ConnectionSocket, public BufferedSocket
+class UplinkSocket final
+ : public ConnectionSocket
+ , public BufferedSocket
{
- public:
+public:
bool error;
UplinkSocket();
~UplinkSocket();
- bool ProcessRead() anope_override;
- void OnConnect() anope_override;
- void OnError(const Anope::string &) anope_override;
-
- /* A message sent over the uplink socket */
- class CoreExport Message
- {
- MessageSource source;
- std::stringstream buffer;
-
- public:
- Message();
- Message(const MessageSource &);
- ~Message();
- template<typename T> Message &operator<<(const T &val)
- {
- this->buffer << val;
- return *this;
- }
- };
+ bool ProcessRead() override;
+ void OnConnect() override;
+ void OnError(const Anope::string &) override;
};
extern CoreExport UplinkSocket *UplinkSock;
-
-#endif // UPLINK_H
diff --git a/include/users.h b/include/users.h
index c8f05ca2c..7fd096c8c 100644
--- a/include/users.h
+++ b/include/users.h
@@ -9,8 +9,7 @@
* Based on the original code of Services by Andy Church.
*/
-#ifndef USERS_H
-#define USERS_H
+#pragma once
#include "anope.h"
#include "modes.h"
@@ -20,7 +19,7 @@
#include "account.h"
#include "sockets.h"
-typedef Anope::hash_map<User *> user_map;
+typedef Anope::unordered_map<User *> user_map;
extern CoreExport user_map UserListByNick, UserListByUID;
@@ -29,21 +28,22 @@ extern CoreExport unsigned MaxUserCount;
extern CoreExport time_t MaxUserTime;
/* Online user and channel data. */
-class CoreExport User : public virtual Base, public Extensible, public CommandReply
+class CoreExport User
+ : public virtual Base
+ , public Extensible
+ , public CommandReply
{
/* true if the user was quit or killed */
bool quit;
/* Users that are in the process of quitting */
static std::list<User *> quitting_users;
- public:
+public:
typedef std::map<Anope::string, Anope::string> ModeList;
- protected:
+protected:
Anope::string vident;
Anope::string ident;
Anope::string uid;
- /* If the user is on the access list of the nick they're on */
- bool on_access;
/* Map of user modes and the params this user has (if any) */
ModeList modes;
/* NickCore account the user is currently logged in as, if they are logged in */
@@ -55,7 +55,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
time_t invalid_pw_time;
- public: // XXX: exposing a tiny bit too much
+public: // XXX: exposing a tiny bit too much
/* User's current nick */
Anope::string nick;
@@ -91,7 +91,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
/* Last time this user sent an email */
time_t lastmail;
- protected:
+protected:
/** Create a new user object, initialising necessary fields and
* adds it to the hash
*
@@ -107,14 +107,14 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
* @param suid The unique identifier of the user.
* @param nc The account the user is identified as, if any
*/
- User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc);
+ User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const std::vector<Anope::string> &smodeparams, const Anope::string &suid, NickCore *nc);
/** Destroy a user.
*/
virtual ~User();
- public:
- static User* OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc);
+public:
+ static User *OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc, const std::vector<Anope::string> &smodeparams = {});
/** Update the nickname of a user record accordingly, should be
* called from ircd protocol.
@@ -189,8 +189,10 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
* @param fmt Format of the Message
* @param ... any number of parameters
*/
- void SendMessage(BotInfo *source, const char *fmt, ...);
- void SendMessage(BotInfo *source, const Anope::string &msg) anope_override;
+ void SendMessage(BotInfo *source, const char *fmt, ...) ATTR_FORMAT(3, 4);
+ void SendMessage(BotInfo *source, int count, const char *singular, const char *plural, ...) ATTR_FORMAT(5, 6);
+ void SendMessage(BotInfo *source, const Anope::string &msg) override;
+ void SendMessage(CommandSource &source, const Anope::string &msg) override;
/** Identify the user to a nick.
* updates last_seen, logs the user in,
@@ -214,17 +216,21 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
*/
NickCore *Account() const;
+ /** Get the account nick the user is logged in using
+ * @return The account nick or NULL
+ */
+ NickAlias *AccountNick() const;
+
/** Check if the user is identified for their nick
* @param check_nick True to check if the user is identified to the nickname they are on too
* @return true or false
*/
bool IsIdentified(bool check_nick = false) const;
- /** Check if the user is recognized for their nick (on the nicks access list)
- * @param check_secure Only returns true if the user has secure off
- * @return true or false
+ /** Check if the user is connected securely.
+ * @return True if the user is connected securely; otherwise, false.
*/
- bool IsRecognized(bool check_secure = true) const;
+ bool IsSecurelyConnected() const;
/** Check if the user is a services oper
* @return true if they are an oper
@@ -243,8 +249,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
*/
bool HasPriv(const Anope::string &privstr);
- /** Update the last usermask stored for a user, and check to see if they are recognized
- */
+ /** Update the last usermask stored for a user. */
void UpdateHost();
/** Check if the user has a mode
@@ -298,13 +303,15 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
* @param bi The client setting the modes
* @param umodes The modes
*/
- void SetModes(BotInfo *bi, const char *umodes, ...);
+ void SetModes(BotInfo *bi, const char *umodes, ...) ATTR_FORMAT(3, 4);
+ void SetModes(BotInfo *bi, const Anope::string &umodes);
/** Set a string of modes on a user internally
* @param setter who/what is setting the mode
- * @param umodes The modes
+ * @param umodes The mode letters
+ * @param umodeparams The mode values
*/
- void SetModesInternal(const MessageSource &source, const char *umodes, ...);
+ void SetModesInternal(const MessageSource &source, const Anope::string &umodes, const std::vector<Anope::string> &umodeparams = {});
/** Get modes set for this user.
* @return A string of modes set on the user
@@ -359,16 +366,17 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
*/
bool BadPassword();
+ /** Determines whether this user should receive a PRIVMSG instead of a NOTICE. */
+ bool ShouldPrivmsg() const;
+
/** Finds a user by nick, or possibly UID
* @param name The nick, or possibly UID, to lookup
* @param nick_only set to true to only look up by nick, not UID
* @return the user, if they exist
*/
- static User* Find(const Anope::string &name, bool nick_only = false);
+ static User *Find(const Anope::string &name, bool nick_only = false);
/** Quits all users who are pending to be quit
*/
static void QuitUsers();
};
-
-#endif // USERS_H
diff --git a/include/version.cpp b/include/version.cpp
index 4a11a6e11..d87bebb18 100644
--- a/include/version.cpp
+++ b/include/version.cpp
@@ -42,7 +42,7 @@ static std::string get_git_hash(const std::string &git_dir)
}
fd.close();
- return "g" + filebuf.substr(0, 7);
+ return filebuf.substr(0, 7);
}
static bool read_version_sh(const std::string &version_sh, std::map<std::string, std::string> &versions)
@@ -105,8 +105,9 @@ static bool write_build_h(const std::string &buildh, const std::string &git_vers
return false;
}
- fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << std::endl;
- fd << build << std::endl;
+ fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << std::endl
+ << "#pragma once" << std::endl
+ << build << std::endl;
if (!git_version.empty())
fd << "#define VERSION_GIT \"" << git_version << "\"" << std::endl;
fd.close();
@@ -144,9 +145,10 @@ static bool write_version_h(const std::string &versionh, const std::map<std::str
if (!fd.is_open())
return false;
- for (std::map<std::string, std::string>::const_iterator it = versions.begin(); it != versions.end(); ++it)
+ fd << "#pragma once" << std::endl;
+ for (const auto &[key, value] : versions)
{
- fd << "#define " << it->first << " " << it->second << std::endl;
+ fd << "#define " << key << " " << value << std::endl;
}
fd.close();
@@ -170,19 +172,19 @@ int main(int argc, char *argv[])
std::map<std::string, std::string> versions, old_versions;
if (!read_version_sh(version_sh, versions))
- return -1;
+ return EXIT_FAILURE;
std::string git_version = get_git_hash(git_dir);
if (!write_build_h(buildh, git_version))
- return -1;
+ return EXIT_FAILURE;
read_version_h(versionh, old_versions);
if (versions == old_versions)
- return 0;
+ return EXIT_SUCCESS;
if (!write_version_h(versionh, versions))
- return -1;
+ return EXIT_FAILURE;
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/include/xline.h b/include/xline.h
index b02aeedd1..ebd88e928 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -6,25 +6,25 @@
* Please read COPYING and README for further details.
*/
-#ifndef XLINE_H
-#define XLINE_H
+#pragma once
#include "serialize.h"
#include "service.h"
#include "sockets.h"
/* An Xline, eg, anything added with operserv/akill, or any of the operserv/sxline commands */
-class CoreExport XLine : public Serializable
+class CoreExport XLine final
+ : public Serializable
{
void Init();
Anope::string nick, user, host, real;
- public:
+public:
cidr *c;
Anope::string mask;
Regex *regex;
Anope::string by;
- time_t created;
- time_t expires;
+ time_t created = 0;
+ time_t expires = 0;
Anope::string reason;
XLineManager *manager;
Anope::string id;
@@ -44,19 +44,20 @@ class CoreExport XLine : public Serializable
bool HasNickOrReal() const;
bool IsRegex() const;
- void Serialize(Serialize::Data &data) const anope_override;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+ void Serialize(Serialize::Data &data) const override;
+ static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
/* Managers XLines. There is one XLineManager per type of XLine. */
-class CoreExport XLineManager : public Service
+class CoreExport XLineManager
+ : public Service
{
char type;
/* List of XLines in this XLineManager */
Serialize::Checker<std::vector<XLine *> > xlines;
/* Akills can have the same IDs, sometimes */
static Serialize::Checker<std::multimap<Anope::string, XLine *, ci::less> > XLinesByUID;
- public:
+public:
/* List of XLine managers we check users against in XLineManager::CheckAll */
static std::list<XLineManager *> XLineManagers;
@@ -124,7 +125,7 @@ class CoreExport XLineManager : public Service
* @param index The index
* @return The XLine, or NULL if the index is out of bounds
*/
- XLine* GetEntry(unsigned index);
+ XLine *GetEntry(unsigned index);
/** Clear the XLine vector
* Note: This does not remove the XLines from the IRCd
@@ -144,7 +145,7 @@ class CoreExport XLineManager : public Service
* @param mask The mask
* @return The XLine the user matches, or NULL
*/
- XLine* HasEntry(const Anope::string &mask);
+ XLine *HasEntry(const Anope::string &mask);
/** Check a user against all of the xlines in this XLineManager
* @param u The user
@@ -180,5 +181,3 @@ class CoreExport XLineManager : public Service
*/
virtual void SendDel(XLine *x) = 0;
};
-
-#endif // XLINE_H