diff options
Diffstat (limited to 'src')
43 files changed, 247 insertions, 480 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b390d164b..80207756c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,72 +2,48 @@ file(GLOB SRC_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") if(WIN32) - append_to_list(SRC_SRCS win32/dir/dir.cpp) - append_to_list(SRC_SRCS win32/socket.cpp) - append_to_list(SRC_SRCS win32/windows.cpp) - append_to_list(SRC_SRCS win32/dl/dl.cpp) - append_to_list(SRC_SRCS win32/pipe/pipe.cpp) - append_to_list(SRC_SRCS win32/pthread/pthread.cpp) - append_to_list(SRC_SRCS win32/sigaction/sigaction.cpp) -endif(WIN32) + list(APPEND SRC_SRCS win32/socket.cpp) + list(APPEND SRC_SRCS win32/windows.cpp) + list(APPEND SRC_SRCS win32/dl/dl.cpp) + list(APPEND SRC_SRCS win32/pipe/pipe.cpp) + list(APPEND SRC_SRCS win32/pthread/pthread.cpp) + list(APPEND SRC_SRCS win32/sigaction/sigaction.cpp) +endif() if(HAVE_EPOLL) - append_to_list(SRC_SRCS socketengines/socketengine_epoll.cpp) -else(HAVE_EPOLL) - if(HAVE_KQUEUE) - append_to_list(SRC_SRCS socketengines/socketengine_kqueue.cpp) - else(HAVE_KQUEUE) - if(HAVE_POLL) - append_to_list(SRC_SRCS socketengines/socketengine_poll.cpp) - else(HAVE_POLL) - append_to_list(SRC_SRCS socketengines/socketengine_select.cpp) - endif(HAVE_POLL) - endif(HAVE_KQUEUE) -endif(HAVE_EPOLL) + list(APPEND SRC_SRCS socketengines/socketengine_epoll.cpp) +elseif(HAVE_KQUEUE) + list(APPEND SRC_SRCS socketengines/socketengine_kqueue.cpp) +elseif(HAVE_POLL) + list(APPEND SRC_SRCS socketengines/socketengine_poll.cpp) +else() + list(APPEND SRC_SRCS socketengines/socketengine_select.cpp) +endif() -sort_list(SRC_SRCS) +list(SORT SRC_SRCS) # Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though) set_source_files_properties(${SRC_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") -# Create an empty list to store extra include directories -set(EXTRA_INCLUDES) -# Iterate through all the source files -foreach(SRC ${SRC_SRCS}) - # Temporary variable for the current source's include directories - set(TEMP_INCLUDES) - # Calculate the header file dependencies for the given source file - calculate_depends(${SRC} TEMP_INCLUDES) - # If there were some extra include directories, add them to the list - if(TEMP_INCLUDES) - append_to_list(EXTRA_INCLUDES ${TEMP_INCLUDES}) - endif(TEMP_INCLUDES) -endforeach(SRC) -# If there were extra include directories, remove the duplicates and add the directories to the include path -if(EXTRA_INCLUDES) - remove_list_duplicates(EXTRA_INCLUDES) - include_directories(${EXTRA_INCLUDES}) -endif(EXTRA_INCLUDES) - # Under Windows, we also include a resource file to the build if(WIN32) # Make sure that the resource file is seen as an RC file to be compiled with a resource compiler, not a C++ compiler set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc LANGUAGE RC) # Add the resource file to the list of sources - append_to_list(SRC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc) + list(APPEND SRC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc) # For MinGW, we have to change the compile flags if(MINGW) set(RC_CFLAGS "-DMINGW -Ocoff -I${Anope_SOURCE_DIR}/include") # If any sort of debugging is being enabled, add a _DEBUG define to the flags for the resource compiler if(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") set(RC_CFLAGS "${RC_CFLAGS} -D_DEBUG") - endif(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") + endif() set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc COMPILE_FLAGS "${RC_CFLAGS}") # For anything else, assumingly Visual Studio at this point, use a different set of compile flags - else(MINGW) + else() set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/win32/win32.rc COMPILE_FLAGS "/i\"${Anope_SOURCE_DIR}/include\"") - endif(MINGW) -endif(WIN32) + endif() +endif() # If compiling with Visual Studio, create a static library out of win32/win32_memory.cpp to be included with everything else, needed to override its override of new/delete operators if(MSVC) @@ -75,29 +51,36 @@ if(MSVC) add_library(win32_memory STATIC win32/win32_memory.cpp) set(WIN32_MEMORY win32_memory) set(EXTRA_LDFLAGS "/OPT:NOREF") # https://sourceware.org/bugzilla/show_bug.cgi?id=12633 -else(MSVC) +else() set(WIN32_MEMORY) -endif(MSVC) +endif() # Generate the Anope executable and set it's linker flags, also set it to export it's symbols even though it's not a module add_executable(${PROGRAM_NAME} ${SRC_SRCS}) set_target_properties(${PROGRAM_NAME} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS} ${EXTRA_LDFLAGS}" ENABLE_EXPORTS ON INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) + # On Windows, also link Anope to the wsock32 and Ws2_32 library, as well as set the version if(WIN32) - target_link_libraries(${PROGRAM_NAME} wsock32 Ws2_32 ${LINK_LIBS} ${GETTEXT_LIBRARIES} ${WIN32_MEMORY}) + target_link_libraries(${PROGRAM_NAME} wsock32 Ws2_32 ${LINK_LIBS} ${WIN32_MEMORY}) set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}") -else(WIN32) - target_link_libraries(${PROGRAM_NAME} ${LINK_LIBS} ${GETTEXT_LIBRARIES}) -endif(WIN32) +else() + target_link_libraries(${PROGRAM_NAME} ${LINK_LIBS}) +endif() + +# If being built with localisation we might need to link against libintl. +if(HAVE_LOCALIZATION AND Intl_LIBRARY) + target_link_libraries(${PROGRAM_NAME} ${Intl_LIBRARY}) +endif() + # Building the Anope executable requires the version.h header to be generated add_dependencies(${PROGRAM_NAME} headers) # Also require the language files if we have gettext -if(GETTEXT_FOUND) +if(HAVE_LOCALIZATION) add_dependencies(${PROGRAM_NAME} language) -endif(GETTEXT_FOUND) +endif() # Get the filename of the Anope executable as it is in on this system -get_target_property(SERVICES_BINARY ${PROGRAM_NAME} LOCATION) +set(SERVICES_BINARY "$<TARGET_FILE:${PROGRAM_NAME}>") get_filename_component(SERVICES_BINARY ${SERVICES_BINARY} NAME) # Add the Anope executable to the list of files for CPack to ignore add_to_cpack_ignored_files("${SERVICES_BINARY}$" TRUE) @@ -108,7 +91,7 @@ configure_file(${Anope_SOURCE_DIR}/include/sysconf.h.cmake ${Anope_BINARY_DIR}/i # Go into the following directories and run their CMakeLists.txt as well if(NOT DISABLE_TOOLS) add_subdirectory(tools) -endif(NOT DISABLE_TOOLS) +endif() # Set Anope to be installed to the bin directory install(TARGETS ${PROGRAM_NAME} diff --git a/src/account.cpp b/src/account.cpp index af8557956..65df38978 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -18,7 +18,7 @@ std::set<IdentifyRequest *> IdentifyRequest::Requests; -IdentifyRequest::IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass) : owner(o), account(acc), password(pass), dispatched(false), success(false) +IdentifyRequest::IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass) : owner(o), account(acc), password(pass) { Requests.insert(this); } diff --git a/src/base.cpp b/src/base.cpp index 824187efa..840d1d359 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -13,10 +13,6 @@ std::map<Anope::string, std::map<Anope::string, Service *> > Service::Services; std::map<Anope::string, std::map<Anope::string, Anope::string> > Service::Aliases; -Base::Base() : references(NULL) -{ -} - Base::~Base() { if (this->references != NULL) diff --git a/src/channels.cpp b/src/channels.cpp index d17cea7d7..a0afe6d39 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -304,7 +304,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *ocm, const Ano else if (this->HasMode(cm->name, param)) return; - this->modes.insert(std::make_pair(cm->name, param)); + this->modes.emplace(cm->name, param); if (param.empty() && cm->type != MODE_REGULAR) { @@ -912,7 +912,7 @@ bool Channel::CheckKick(User *user) return false; if (mask.empty()) - mask = this->ci->GetIdealBan(user); + mask = this->ci ? this->ci->GetIdealBan(user) : "*!*@" + user->GetDisplayedHost(); if (reason.empty()) reason = Language::Translate(user->Account(), CHAN_NOT_ALLOWED_TO_JOIN); diff --git a/src/command.cpp b/src/command.cpp index 6e4fa1aaa..4c511777a 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -122,10 +122,6 @@ Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t allow_unregistered = require_user = false; } -Command::~Command() -{ -} - void Command::SetDesc(const Anope::string &d) { this->desc = d; diff --git a/src/config.cpp b/src/config.cpp index f1d237a5d..0503340b0 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -19,7 +19,7 @@ using namespace Configuration; -File ServicesConf("services.conf", false); // Services configuration file name +File ServicesConf("anope.conf", false); // Configuration file name Conf *Config = NULL; Block::Block(const Anope::string &n) : name(n), linenum(-1) @@ -33,47 +33,32 @@ const Anope::string &Block::GetName() const int Block::CountBlock(const Anope::string &bname) { - if (!this) - return 0; - return blocks.count(bname); } Block* Block::GetBlock(const Anope::string &bname, int num) { - if (!this) - return NULL; - std::pair<block_map::iterator, block_map::iterator> it = blocks.equal_range(bname); for (int i = 0; it.first != it.second; ++it.first, ++i) if (i == num) return &it.first->second; - return NULL; + return &(Config->EmptyBlock); } bool Block::Set(const Anope::string &tag, const Anope::string &value) { - if (!this) - return false; - items[tag] = value; return true; } -const Block::item_map* Block::GetItems() const +const Block::item_map& Block::GetItems() const { - if (this) - return &items; - else - return NULL; + return items; } template<> const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const { - if (!this) - return def; - Anope::map<Anope::string>::const_iterator it = items.find(tag); if (it != items.end()) return it->second; @@ -116,7 +101,7 @@ template<typename T> static void ValidateNotZero(const Anope::string &block, con throw ConfigException("The value for <" + block + ":" + name + "> cannot be zero!"); } -Conf::Conf() : Block("") +Conf::Conf() : Block(""), EmptyBlock("") { ReadTimeout = 0; UsePrivmsg = DefPrivmsg = false; @@ -208,19 +193,33 @@ Conf::Conf() : Block("") { Block *uplink = this->GetBlock("uplink", i); - const Anope::string &host = uplink->Get<const Anope::string>("host"); - bool ipv6 = uplink->Get<bool>("ipv6"); - int port = uplink->Get<int>("port"); - const Anope::string &password = uplink->Get<const Anope::string>("password"); + int protocol; + const Anope::string &protocolstr = uplink->Get<const Anope::string>("protocol", "ipv4"); + if (protocolstr == "ipv4") + protocol = AF_INET; + else if (protocolstr == "ipv6") + protocol = AF_INET6; + else if (protocolstr == "unix") + protocol = AF_UNIX; + else + throw ConfigException("uplink:protocol must be set to ipv4, ipv6, or unix"); + const Anope::string &host = uplink->Get<const Anope::string>("host"); ValidateNotEmptyOrSpaces("uplink", "host", host); - ValidateNotZero("uplink", "port", port); - ValidateNotEmptyOrSpaces("uplink", "password", password); - if (password.find(' ') != Anope::string::npos || password[0] == ':') + int port = 0; + if (protocol != AF_UNIX) + { + ValidateNotZero("uplink", "port", port); + port = uplink->Get<int>("port"); + } + + const Anope::string &password = uplink->Get<const Anope::string>("password"); + ValidateNotEmptyOrSpaces("uplink", "password", password); + if (password[0] == ':') throw ConfigException("uplink:password is not valid"); - this->Uplinks.push_back(Uplink(host, port, password, ipv6)); + this->Uplinks.emplace_back(host, port, password, protocol); } for (int i = 0; i < this->CountBlock("module"); ++i) @@ -602,7 +601,7 @@ void Conf::Post(Conf *old) Block *Conf::GetModule(Module *m) { if (!m) - return NULL; + return &(Config->EmptyBlock); return GetModule(m->name); } @@ -654,10 +653,10 @@ Block *Conf::GetCommand(CommandSource &source) return b; } - return NULL; + return &(Config->EmptyBlock); } -File::File(const Anope::string &n, bool e) : name(n), executable(e), fp(NULL) +File::File(const Anope::string &n, bool e) : name(n), executable(e) { } @@ -846,7 +845,7 @@ void Conf::LoadConf(File &file) } Block *b = block_stack.empty() ? this : block_stack.top(); - block_map::iterator it = b->blocks.insert(std::make_pair(wordbuffer, Configuration::Block(wordbuffer))); + block_map::iterator it = b->blocks.emplace(wordbuffer, Configuration::Block(wordbuffer)); b = &it->second; b->linenum = linenumber; block_stack.push(b); diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index e839de4f9..409e125ac 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -91,7 +91,7 @@ bool ci::less::operator()(const Anope::string &s1, const Anope::string &s2) cons return s1.ci_str().compare(s2.ci_str()) < 0; } -sepstream::sepstream(const Anope::string &source, char separator, bool ae) : tokens(source), sep(separator), pos(0), allow_empty(ae) +sepstream::sepstream(const Anope::string &source, char separator, bool ae) : tokens(source), sep(separator), allow_empty(ae) { } diff --git a/src/init.cpp b/src/init.cpp index e3866abfc..5df2c1cce 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -23,10 +23,10 @@ #include <sys/wait.h> #include <sys/stat.h> -#include <errno.h> -#include <sys/types.h> -#include <pwd.h> +#include <cerrno> #include <grp.h> +#include <pwd.h> +#include <sys/types.h> #endif Anope::string Anope::ConfigDir = "conf", Anope::DataDir = "data", Anope::ModuleDir = "lib", Anope::LocaleDir = "locale", Anope::LogDir = "logs"; @@ -57,7 +57,7 @@ static void ParseCommandLineArguments(int ac, char **av) if (option.empty()) continue; - CommandLineArguments.push_back(std::make_pair(option, param)); + CommandLineArguments.emplace_back(option, param); } } @@ -411,7 +411,7 @@ void Anope::Init(int ac, char **av) Anope::LogDir = arg; } - /* Chdir to Services data directory. */ + /* Chdir to Anope data directory. */ if (chdir(Anope::ServicesDir.c_str()) < 0) { throw CoreException("Unable to chdir to " + Anope::ServicesDir + ": " + Anope::LastError()); @@ -493,7 +493,7 @@ void Anope::Init(int ac, char **av) catch (const ConfigException &ex) { Log(LOG_TERMINAL) << ex.GetReason(); - Log(LOG_TERMINAL) << "*** Support resources: Read through the services.conf self-contained"; + Log(LOG_TERMINAL) << "*** Support resources: Read through the anope.conf self-contained"; Log(LOG_TERMINAL) << "*** documentation. Read the documentation files found in the 'docs'"; Log(LOG_TERMINAL) << "*** folder. Visit our portal located at https://www.anope.org/. Join"; Log(LOG_TERMINAL) << "*** our support channel on /server irc.anope.org channel #anope."; diff --git a/src/language.cpp b/src/language.cpp index 8c39941b4..219bf846c 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -15,7 +15,7 @@ #include "config.h" #include "language.h" -#if GETTEXT_FOUND +#if HAVE_LOCALIZATION # include <libintl.h> #endif @@ -24,7 +24,7 @@ std::vector<Anope::string> Language::Domains; void Language::InitLanguages() { -#if GETTEXT_FOUND +#if HAVE_LOCALIZATION Log(LOG_DEBUG) << "Initializing Languages..."; Languages.clear(); @@ -73,7 +73,7 @@ const char *Language::Translate(const NickCore *nc, const char *string) return Translate(nc ? nc->language.c_str() : "", string); } -#if GETTEXT_FOUND +#if HAVE_LOCALIZATION #if defined(__GLIBC__) && defined(__USE_GNU_GETTEXT) extern "C" int _nl_msg_cat_cntr; diff --git a/src/logger.cpp b/src/logger.cpp index 937fb4d5d..807895396 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -74,11 +74,11 @@ const Anope::string &LogFile::GetName() const return this->filename; } -Log::Log(LogType t, const Anope::string &cat, BotInfo *b) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(t), category(cat) +Log::Log(LogType t, const Anope::string &cat, BotInfo *b) : bi(b), type(t), category(cat) { } -Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t) +Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), ci(_ci), type(t) { if (!c) throw CoreException("Invalid pointers passed to Log::Log"); @@ -87,35 +87,34 @@ Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.G throw CoreException("This constructor does not support this log type"); size_t sl = c->name.find('/'); - this->bi = NULL; if (sl != Anope::string::npos) this->bi = BotInfo::Find(c->name.substr(0, sl), true); this->category = c->name; } -Log::Log(User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc(NULL), c(NULL), source(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), m(NULL), type(LOG_CHANNEL), category(cat) +Log::Log(User *_u, Channel *ch, const Anope::string &cat) : u(_u), chan(ch), ci(chan ? *chan->ci : nullptr), type(LOG_CHANNEL), category(cat) { if (!chan) throw CoreException("Invalid pointers passed to Log::Log"); } -Log::Log(User *_u, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_USER), category(cat) +Log::Log(User *_u, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(_u), type(LOG_USER), category(cat) { if (!u) throw CoreException("Invalid pointers passed to Log::Log"); } -Log::Log(Server *serv, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), type(LOG_SERVER), category(cat) +Log::Log(Server *serv, const Anope::string &cat, BotInfo *_bi) : bi(_bi), s(serv), type(LOG_SERVER), category(cat) { if (!s) throw CoreException("Invalid pointer passed to Log::Log"); } -Log::Log(BotInfo *b, const Anope::string &cat) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_NORMAL), category(cat) +Log::Log(BotInfo *b, const Anope::string &cat) : bi(b), type(LOG_NORMAL), category(cat) { } -Log::Log(Module *mod, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(mod), type(LOG_MODULE), category(cat) +Log::Log(Module *mod, const Anope::string &cat, BotInfo *_bi) : bi(_bi), m(mod), type(LOG_MODULE), category(cat) { } @@ -227,7 +226,7 @@ Anope::string Log::BuildPrefix() const return buffer; } -LogInfo::LogInfo(int la, bool rio, bool ldebug) : bot(NULL), last_day(0), log_age(la), raw_io(rio), debug(ldebug) +LogInfo::LogInfo(int la, bool rio, bool ldebug) : log_age(la), raw_io(rio), debug(ldebug) { } diff --git a/src/mail.cpp b/src/mail.cpp index ee947c07f..c5e465666 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -13,7 +13,7 @@ #include "mail.h" #include "config.h" -Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, const Anope::string &a, const Anope::string &s, const Anope::string &m) : Thread(), sendmail_path(Config->GetBlock("mail")->Get<const Anope::string>("sendmailpath")), send_from(sf), mail_to(mailto), addr(a), subject(s), message(m), dont_quote_addresses(Config->GetBlock("mail")->Get<bool>("dontquoteaddresses")), success(false) +Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, const Anope::string &a, const Anope::string &s, const Anope::string &m) : Thread(), sendmail_path(Config->GetBlock("mail")->Get<const Anope::string>("sendmailpath")), send_from(sf), mail_to(mailto), addr(a), subject(s), message(m), dont_quote_addresses(Config->GetBlock("mail")->Get<bool>("dontquoteaddresses")) { } diff --git a/src/main.cpp b/src/main.cpp index 660e14519..4c48c45eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -/* Services -- main source file. +/* Anope -- main source file. * * (C) 2003-2022 Anope Team * Contact us at team@anope.org @@ -17,7 +17,7 @@ #include "uplink.h" #ifndef _WIN32 -#include <limits.h> +#include <climits> #else #include <process.h> #endif @@ -46,7 +46,7 @@ class UpdateTimer : public Timer public: UpdateTimer(time_t timeout) : Timer(timeout, Anope::CurTime, true) { } - void Tick(time_t) anope_override + void Tick(time_t) override { Anope::SaveDatabases(); } @@ -57,7 +57,7 @@ class ExpireTimer : public Timer public: ExpireTimer(time_t timeout) : Timer(timeout, Anope::CurTime, true) { } - void Tick(time_t) anope_override + void Tick(time_t) override { FOREACH_MOD(OnExpireTick, ()); } diff --git a/src/memos.cpp b/src/memos.cpp index 20d2ce8d3..278cc0157 100644 --- a/src/memos.cpp +++ b/src/memos.cpp @@ -76,7 +76,7 @@ Serializable* Memo::Unserialize(Serializable *obj, Serialize::Data &data) return m; } -MemoInfo::MemoInfo() : memomax(0), memos("Memo") +MemoInfo::MemoInfo() : memos("Memo") { } diff --git a/src/messages.cpp b/src/messages.cpp index 0d0882b2a..a8ff6f7a7 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -22,7 +22,7 @@ using namespace Message; -void Away::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Away::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { const Anope::string &msg = !params.empty() ? params[0] : ""; @@ -33,7 +33,7 @@ void Away::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) Log(source.GetUser(), "away") << "is no longer away"; } -void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { if (params.size() == 1) { @@ -47,14 +47,14 @@ void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) Servers::Capab.insert(params[i]); } -void Error::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Error::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { Log(LOG_TERMINAL) << "ERROR: " << params[0]; Anope::QuitReason = "Received ERROR from uplink: " + params[0]; Anope::Quitting = true; } -void Invite::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Invite::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { User *targ = User::Find(params[0]); Channel *c = Channel::Find(params[1]); @@ -65,7 +65,7 @@ void Invite::Run(MessageSource &source, const std::vector<Anope::string> ¶ms FOREACH_MOD(OnInvite, (source.GetUser(), c, targ)); } -void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { User *user = source.GetUser(); const Anope::string &channels = params[0]; @@ -92,7 +92,7 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) } std::list<SJoinUser> users; - users.push_back(std::make_pair(ChannelStatus(), user)); + users.emplace_back(ChannelStatus(), user); Channel *chan = Channel::Find(channel); SJoin(source, channel, chan ? chan->creation_time : Anope::CurTime, "", users); @@ -167,7 +167,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co } } -void Kick::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Kick::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { const Anope::string &channel = params[0]; const Anope::string &users = params[1]; @@ -184,7 +184,7 @@ void Kick::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) c->KickInternal(source, user, reason); } -void Kill::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Kill::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { User *u = User::Find(params[0]); BotInfo *bi; @@ -199,7 +199,7 @@ void Kill::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) if (last_time == Anope::CurTime) { - Anope::QuitReason = "Kill loop detected. Are Services U:Lined?"; + Anope::QuitReason = "Kill loop detected. Is Anope U:Lined?"; Anope::Quitting = true; return; } @@ -211,7 +211,7 @@ void Kill::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) u->KillInternal(source, params[1]); } -void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { Anope::string buf; for (unsigned i = 1; i < params.size(); ++i) @@ -234,7 +234,7 @@ void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string> } /* XXX We should cache the file somewhere not open/read/close it on every request */ -void MOTD::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void MOTD::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { Server *s = Server::Find(params[0]); if (s != Me) @@ -257,7 +257,7 @@ void MOTD::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) IRCD->SendNumeric(422, source.GetSource(), ":- MOTD file not found! Please contact your IRC administrator."); } -void Notice::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Notice::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { Anope::string message = params[1]; @@ -273,7 +273,7 @@ void Notice::Run(MessageSource &source, const std::vector<Anope::string> ¶ms } } -void Part::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Part::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { User *u = source.GetUser(); const Anope::string &reason = params.size() > 1 ? params[1] : ""; @@ -295,12 +295,12 @@ void Part::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) } } -void Ping::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Ping::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { IRCD->SendPong(params.size() > 1 ? params[1] : Me->GetSID(), params[0]); } -void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { const Anope::string &receiver = params[0]; Anope::string message = params[1]; @@ -373,7 +373,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m return; } -void Quit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Quit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { const Anope::string &reason = params[0]; User *user = source.GetUser(); @@ -383,7 +383,7 @@ void Quit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) user->Quit(reason); } -void SQuit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void SQuit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { Server *s = Server::Find(params[0]); @@ -404,7 +404,7 @@ void SQuit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); } -void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { User *u = source.GetUser(); @@ -455,7 +455,7 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) return; } -void Time::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Time::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { time_t t; time(&t); @@ -466,7 +466,7 @@ void Time::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) return; } -void Topic::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Topic::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { Channel *c = Channel::Find(params[0]); if (c) @@ -475,13 +475,13 @@ void Topic::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) return; } -void Version::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Version::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); IRCD->SendNumeric(351, source.GetSource(), "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Me->GetName().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)", Anope::VersionBuildString().c_str()); } -void Whois::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +void Whois::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) { User *u = User::Find(params[0]); diff --git a/src/misc.cpp b/src/misc.cpp index 99d5106a4..290bf8067 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -19,15 +19,15 @@ #include "regexpr.h" #include "sockets.h" -#include <errno.h> -#include <sys/types.h> +#include <cerrno> #include <sys/stat.h> +#include <sys/types.h> #ifndef _WIN32 #include <sys/socket.h> #include <netdb.h> #endif -NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(true), desc(descending) +NumberList::NumberList(const Anope::string &list, bool descending) : desc(descending) { Anope::string error; commasepstream sep(list); @@ -90,10 +90,6 @@ NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(tr } while (sep.GetToken(token)); } -NumberList::~NumberList() -{ -} - void NumberList::Process() { if (!is_valid) @@ -147,7 +143,7 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) std::set<Anope::string> breaks; for (unsigned i = 0; i < this->columns.size(); ++i) { - tcolumns.push_back(Language::Translate(this->nc, this->columns[i].c_str())); + tcolumns.emplace_back(Language::Translate(this->nc, this->columns[i].c_str())); lengths[this->columns[i]] = tcolumns[i].length(); } for (unsigned i = 0; i < this->entries.size(); ++i) @@ -214,7 +210,7 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) } } -InfoFormatter::InfoFormatter(NickCore *acc) : nc(acc), longest(0) +InfoFormatter::InfoFormatter(NickCore *acc) : nc(acc) { } @@ -238,7 +234,7 @@ Anope::string& InfoFormatter::operator[](const Anope::string &key) Anope::string tkey = Language::Translate(this->nc, key.c_str()); if (tkey.length() > this->longest) this->longest = tkey.length(); - this->replies.push_back(std::make_pair(tkey, "")); + this->replies.emplace_back(tkey, ""); return this->replies.back().second; } @@ -514,24 +510,6 @@ void Anope::Encrypt(const Anope::string &src, Anope::string &dest) static_cast<void>(MOD_RESULT); } -bool Anope::Decrypt(const Anope::string &src, Anope::string &dest) -{ - size_t pos = src.find(':'); - if (pos == Anope::string::npos) - { - Log() << "Error: Anope::Decrypt() called with invalid password string (" << src << ")"; - return false; - } - Anope::string hashm(src.begin(), src.begin() + pos); - - EventReturn MOD_RESULT; - FOREACH_RESULT(OnDecrypt, MOD_RESULT, (hashm, src, dest)); - if (MOD_RESULT == EVENT_ALLOW) - return true; - - return false; -} - Anope::string Anope::printf(const char *fmt, ...) { va_list args; @@ -639,7 +617,7 @@ Anope::string Anope::VersionBuildString() #endif Anope::string flags; -#ifdef DEBUG_BUILD +#if DEBUG_BUILD flags += "D"; #endif #ifdef VERSION_GIT diff --git a/src/modes.cpp b/src/modes.cpp index 2153fd3ac..150e0845b 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -46,9 +46,7 @@ struct StackerInfo /* Modes to be deleted */ std::list<std::pair<Mode *, Anope::string> > DelModes; /* Bot this is sent from */ - BotInfo *bi; - - StackerInfo() : bi(NULL) { } + BotInfo *bi = nullptr; /** Add a mode to this object * @param mode The mode @@ -58,10 +56,6 @@ struct StackerInfo void AddMode(Mode *mode, bool set, const Anope::string ¶m); }; -ChannelStatus::ChannelStatus() -{ -} - ChannelStatus::ChannelStatus(const Anope::string &m) : modes(m) { } @@ -118,10 +112,6 @@ Mode::Mode(const Anope::string &mname, ModeClass mcl, char mch, ModeType mt) : n { } -Mode::~Mode() -{ -} - bool Mode::CanSet(User *u) const { return true; @@ -307,7 +297,7 @@ void StackerInfo::AddMode(Mode *mode, bool set, const Anope::string ¶m) } /* Add this mode and its param to our list */ - list->push_back(std::make_pair(mode, param)); + list->emplace_back(mode, param); } static class ModePipe : public Pipe @@ -742,7 +732,7 @@ void ModeManager::StackerDel(Mode *m) } } -Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh), cidr_len(0), family(0) +Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh) { Anope::string n, u, h; diff --git a/src/module.cpp b/src/module.cpp index 2881c4e82..66e6b360b 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -11,7 +11,7 @@ #include "language.h" #include "account.h" -#ifdef GETTEXT_FOUND +#if HAVE_LOCALIZATION # include <libintl.h> #endif @@ -39,7 +39,7 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt ModuleManager::Modules.push_back(this); -#if GETTEXT_FOUND +#if HAVE_LOCALIZATION for (unsigned i = 0; i < Language::Languages.size(); ++i) { /* Remove .UTF-8 or any other suffix */ @@ -75,7 +75,7 @@ Module::~Module() if (it != ModuleManager::Modules.end()) ModuleManager::Modules.erase(it); -#if GETTEXT_FOUND +#if HAVE_LOCALIZATION std::vector<Anope::string>::iterator dit = std::find(Language::Domains.begin(), Language::Domains.end(), this->name); if (dit != Language::Domains.end()) Language::Domains.erase(dit); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 3317a6f09..0ef2421e6 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -15,11 +15,12 @@ #include <sys/types.h> #include <sys/stat.h> #ifndef _WIN32 -#include <dirent.h> #include <sys/types.h> #include <dlfcn.h> #endif +#include <filesystem> + std::list<Module *> ModuleManager::Modules; std::vector<Module *> ModuleManager::EventHandlers[I_SIZE]; @@ -29,25 +30,18 @@ void ModuleManager::CleanupRuntimeDirectory() Anope::string dirbuf = Anope::DataDir + "/runtime"; Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment, please wait"; - - DIR *dirp = opendir(dirbuf.c_str()); - if (!dirp) + try { - Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")"; - return; + for (const auto &entry : std::filesystem::directory_iterator(dirbuf.str())) + { + if (entry.is_regular_file()) + std::filesystem::remove(entry); + } } - - for (dirent *dp; (dp = readdir(dirp));) + catch (const std::filesystem::filesystem_error &err) { - if (!dp->d_ino) - continue; - if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs("..")) - continue; - Anope::string filebuf = dirbuf + "/" + dp->d_name; - unlink(filebuf.c_str()); + Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << "): " << err.what(); } - - closedir(dirp); } /** diff --git a/src/opertype.cpp b/src/opertype.cpp index 139b7909b..2dd756682 100644 --- a/src/opertype.cpp +++ b/src/opertype.cpp @@ -13,7 +13,7 @@ std::vector<Oper *> Oper::opers; -Oper::Oper(const Anope::string &n, OperType *o) : name(n), ot(o), require_oper(true) +Oper::Oper(const Anope::string &n, OperType *o) : name(n), ot(o) { opers.push_back(this); } diff --git a/src/process.cpp b/src/process.cpp index de7dc8ee4..b72a24f91 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -133,7 +133,6 @@ Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string MessageTokenizer::MessageTokenizer(const Anope::string &msg) : message(msg) - , position(0) { } diff --git a/src/protocol.cpp b/src/protocol.cpp index 19a0a82f0..708681d67 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -25,7 +25,7 @@ IRCDProto::IRCDProto(Module *creator, const Anope::string &p) : Service(creator, { DefaultPseudoclientModes = "+io"; CanSVSNick = CanSVSJoin = CanSetVHost = CanSetVIdent = CanSNLine = CanSQLine = CanSQLineChannel - = CanSZLine = CanSVSHold = CanSVSO = CanCertFP = RequiresID = AmbiguousID = false; + = CanSZLine = CanSVSHold = CanCertFP = CanSendTags = RequiresID = AmbiguousID = false; MaxModes = 3; MaxLine = 512; @@ -450,7 +450,7 @@ Anope::string IRCDProto::NormalizeMask(const Anope::string &mask) return Entry("", mask).GetNUHMask(); } -MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s(NULL) +MessageSource::MessageSource(const Anope::string &src) : source(src) { /* no source for incoming message is our uplink */ if (src.empty()) @@ -461,11 +461,11 @@ MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s this->u = User::Find(src); } -MessageSource::MessageSource(User *_u) : source(_u ? _u->nick : ""), u(_u), s(NULL) +MessageSource::MessageSource(User *_u) : source(_u ? _u->nick : ""), u(_u) { } -MessageSource::MessageSource(Server *_s) : source(_s ? _s->GetName() : ""), u(NULL), s(_s) +MessageSource::MessageSource(Server *_s) : source(_s ? _s->GetName() : ""), s(_s) { } @@ -507,10 +507,3 @@ unsigned IRCDMessage::GetParamCount() const { return this->param_count; } - -void IRCDMessage::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) -{ - // Most IRCds don't support message tags yet so use the tagless variant. - Run(source, params); -} - diff --git a/src/regchannel.cpp b/src/regchannel.cpp index c571d74e3..e248e06c0 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -355,7 +355,7 @@ NickCore *ChannelInfo::GetSuccessor() const BotInfo *ChannelInfo::WhoSends() const { - if (this && this->bi) + if (this->bi) return this->bi; BotInfo *ChanServ = Config->GetClient("ChanServ"); @@ -629,8 +629,7 @@ void ChannelInfo::ClearLevels() Anope::string ChannelInfo::GetIdealBan(User *u) const { - int bt = this ? this->bantype : -1; - switch (bt) + switch (this->bantype) { case 0: return "*!" + u->GetVIdent() + "@" + u->GetDisplayedHost(); diff --git a/src/serialize.cpp b/src/serialize.cpp index caca587b8..9c3619557 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -41,7 +41,7 @@ void Serialize::CheckTypes() } } -Serializable::Serializable(const Anope::string &serialize_type) : last_commit(0), last_commit_time(0), id(0), redis_ignore(0) +Serializable::Serializable(const Anope::string &serialize_type) { if (SerializableItems == NULL) SerializableItems = new std::list<Serializable *>(); @@ -55,7 +55,7 @@ Serializable::Serializable(const Anope::string &serialize_type) : last_commit(0) FOREACH_MOD(OnSerializableConstruct, (this)); } -Serializable::Serializable(const Serializable &other) : last_commit(0), last_commit_time(0), id(0), redis_ignore(0) +Serializable::Serializable(const Serializable &other) { SerializableItems->push_back(this); this->s_iter = SerializableItems->end(); @@ -112,7 +112,7 @@ const std::list<Serializable *> &Serializable::GetItems() return *SerializableItems; } -Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), unserialize(f), owner(o), timestamp(0) +Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), unserialize(f), owner(o) { TypeOrder.push_back(this->name); Types[this->name] = this; diff --git a/src/servers.cpp b/src/servers.cpp index db8cfce7c..35577df73 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -27,7 +27,7 @@ Anope::map<Server *> Servers::ByID; std::set<Anope::string> Servers::Capab; -Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Anope::string &desc, const Anope::string &ssid, bool jupe) : name(sname), hops(shops), description(desc), sid(ssid), uplink(up), users(0) +Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Anope::string &desc, const Anope::string &ssid, bool jupe) : name(sname), hops(shops), description(desc), sid(ssid), uplink(up) { syncing = true; juped = jupe; diff --git a/src/siphash.cpp b/src/siphash.cpp index 6a34d4d1d..cb0b3fd53 100644 --- a/src/siphash.cpp +++ b/src/siphash.cpp @@ -120,12 +120,12 @@ uint64_t Anope::SipHash24(const void *src, unsigned long src_sz, const char key[ uint64_t t = 0; uint8_t *pt = (uint8_t *)&t; uint8_t *m = (uint8_t *)in; switch (src_sz) { - case 7: pt[6] = m[6]; - case 6: pt[5] = m[5]; - case 5: pt[4] = m[4]; + case 7: pt[6] = m[6]; [[fallthrough]]; + case 6: pt[5] = m[5]; [[fallthrough]]; + case 5: pt[4] = m[4]; [[fallthrough]]; case 4: *((uint32_t*)&pt[0]) = *((uint32_t*)&m[0]); break; - case 3: pt[2] = m[2]; - case 2: pt[1] = m[1]; + case 3: pt[2] = m[2]; [[fallthrough]]; + case 2: pt[1] = m[1]; [[fallthrough]]; case 1: pt[0] = m[0]; } b |= _le64toh(t); diff --git a/src/socket_clients.cpp b/src/socket_clients.cpp index e8665df58..7258bdf0b 100644 --- a/src/socket_clients.cpp +++ b/src/socket_clients.cpp @@ -14,7 +14,7 @@ #include "logger.h" #include "sockets.h" -#include <errno.h> +#include <cerrno> void ConnectionSocket::Connect(const Anope::string &TargetHost, int Port) { diff --git a/src/socket_transport.cpp b/src/socket_transport.cpp index abee187d9..ffc5c03b2 100644 --- a/src/socket_transport.cpp +++ b/src/socket_transport.cpp @@ -13,14 +13,6 @@ #include "sockets.h" #include "socketengine.h" -BufferedSocket::BufferedSocket() -{ -} - -BufferedSocket::~BufferedSocket() -{ -} - bool BufferedSocket::ProcessRead() { char tbuffer[NET_BUFSIZE]; @@ -115,14 +107,6 @@ BinarySocket::DataBlock::~DataBlock() delete [] this->orig; } -BinarySocket::BinarySocket() -{ -} - -BinarySocket::~BinarySocket() -{ -} - bool BinarySocket::ProcessRead() { char tbuffer[NET_BUFSIZE]; diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index bf17b09c6..626cd51be 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -15,9 +15,9 @@ #include "socketengine.h" #include "config.h" +#include <cerrno> #include <sys/epoll.h> #include <ulimit.h> -#include <errno.h> static int EngineHandle; static std::vector<epoll_event> events; @@ -53,7 +53,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) memset(&ev, 0, sizeof(ev)); - ev.events = (s->flags[SF_READABLE] ? EPOLLIN : 0) | (s->flags[SF_WRITABLE] ? EPOLLOUT : 0); + ev.events = (s->flags[SF_READABLE] ? EPOLLIN : 0u) | (s->flags[SF_WRITABLE] ? EPOLLOUT : 0u); ev.data.fd = s->GetFD(); int mod; diff --git a/src/sockets.cpp b/src/sockets.cpp index b5edc0e6d..85bd41d8f 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -16,7 +16,7 @@ #ifndef _WIN32 #include <arpa/inet.h> -#include <errno.h> +#include <cerrno> #include <fcntl.h> #endif @@ -52,6 +52,8 @@ size_t sockaddrs::size() const return sizeof(sa4); case AF_INET6: return sizeof(sa6); + case AF_UNIX: + return sizeof(saun); default: break; } @@ -67,6 +69,8 @@ int sockaddrs::port() const return ntohs(sa4.sin_port); case AF_INET6: return ntohs(sa6.sin6_port); + case AF_UNIX: + return 0; default: break; } @@ -76,18 +80,51 @@ int sockaddrs::port() const Anope::string sockaddrs::addr() const { - char address[INET6_ADDRSTRLEN]; - switch (sa.sa_family) { case AF_INET: - if (inet_ntop(AF_INET, &sa4.sin_addr, address, sizeof(address))) - return address; + { + char v4address[INET_ADDRSTRLEN]; + if (inet_ntop(AF_INET, &sa4.sin_addr, v4address, sizeof(v4address))) + return v4address; break; + } case AF_INET6: - if (inet_ntop(AF_INET6, &sa6.sin6_addr, address, sizeof(address))) - return address; + { + char v6address[INET6_ADDRSTRLEN]; + if (inet_ntop(AF_INET6, &sa6.sin6_addr, v6address, sizeof(v6address))) + return v6address; break; + } + case AF_UNIX: + return saun.sun_path; + default: + break; + } + + return ""; +} + +Anope::string sockaddrs::str() const +{ + switch (sa.sa_family) + { + case AF_INET: + { + char v4address[INET_ADDRSTRLEN]; + if (!inet_ntop(AF_INET, &sa4.sin_addr, v4address, sizeof(v4address))) + strcpy(v4address, "0.0.0.0"); + return Anope::printf("%s:%u", v4address, sa4.sin_port); + } + case AF_INET6: + { + char v6address[INET6_ADDRSTRLEN]; + if (!inet_ntop(AF_INET6, &sa6.sin6_addr, v6address, sizeof(v6address))) + strcpy(v6address, "0:0:0:0:0:0:0:0"); + return Anope::printf("[%s]:%u", v6address, sa6.sin6_port); + } + case AF_UNIX: + return saun.sun_path; default: break; } @@ -187,6 +224,15 @@ void sockaddrs::pton(int type, const Anope::string &address, int pport) } break; } + case AF_UNIX: + { + if (address.length() < sizeof(saun.sun_path)) + { + saun.sun_family = AF_UNIX; + memcpy(&saun.sun_path, address.c_str(), address.length() + 1); + } + break; + } default: break; } @@ -306,7 +352,7 @@ bool cidr::match(const sockaddrs &other) byte = len % 8; if (byte) { - uint8_t m = ~0 << (8 - byte); + uint8_t m = ~0u << (8 - byte); return (*ip & m) == (*their_ip & m); } @@ -432,7 +478,7 @@ SocketFlag SocketIO::FinishAccept(ClientSocket *cs) void SocketIO::Bind(Socket *s, const Anope::string &ip, int port) { - s->bindaddr.pton(s->IsIPv6() ? AF_INET6 : AF_INET, ip, port); + s->bindaddr.pton(s->GetFamily(), ip, port); if (bind(s->GetFD(), &s->bindaddr.sa, s->bindaddr.size()) == -1) throw SocketException("Unable to bind to address: " + Anope::LastError()); } @@ -440,7 +486,7 @@ void SocketIO::Bind(Socket *s, const Anope::string &ip, int port) void SocketIO::Connect(ConnectionSocket *s, const Anope::string &target, int port) { s->flags[SF_CONNECTING] = s->flags[SF_CONNECTED] = false; - s->conaddr.pton(s->IsIPv6() ? AF_INET6 : AF_INET, target, port); + s->conaddr.pton(s->GetFamily(), target, port); int c = connect(s->GetFD(), &s->conaddr.sa, s->conaddr.size()); if (c == -1) { @@ -488,12 +534,12 @@ Socket::Socket() throw CoreException("Socket::Socket() ?"); } -Socket::Socket(int s, bool i, int type) +Socket::Socket(int s, int f, int type) { this->io = &NormalSocketIO; - this->ipv6 = i; + this->family = f; if (s == -1) - this->sock = socket(this->ipv6 ? AF_INET6 : AF_INET, type, 0); + this->sock = socket(this->family, type, 0); else this->sock = s; this->SetBlocking(false); @@ -510,14 +556,14 @@ Socket::~Socket() SocketEngine::Sockets.erase(this->sock); } -int Socket::GetFD() const +int Socket::GetFamily() const { - return sock; + return family; } -bool Socket::IsIPv6() const +int Socket::GetFD() const { - return ipv6; + return sock; } bool Socket::SetBlocking(bool state) @@ -567,10 +613,6 @@ ListenSocket::ListenSocket(const Anope::string &bindip, int port, bool i) throw SocketException("Unable to listen: " + Anope::LastError()); } -ListenSocket::~ListenSocket() -{ -} - bool ListenSocket::ProcessRead() { try diff --git a/src/threadengine.cpp b/src/threadengine.cpp index dba2f0237..c0385afbc 100644 --- a/src/threadengine.cpp +++ b/src/threadengine.cpp @@ -44,14 +44,6 @@ static void *entry_point(void *parameter) return NULL; } -Thread::Thread() : exit(false) -{ -} - -Thread::~Thread() -{ -} - void Thread::Join() { this->SetExitState(); diff --git a/src/timers.cpp b/src/timers.cpp index abb8bfeaf..cb4b8c0f9 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -80,7 +80,7 @@ Module *Timer::GetOwner() const void TimerManager::AddTimer(Timer *t) { - Timers.insert(std::make_pair(t->GetTimer(), t)); + Timers.emplace(t->GetTimer(), t); } void TimerManager::DelTimer(Timer *t) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 3e00b981d..0ef39cafd 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -1,6 +1,6 @@ # Find all the *.cpp files within the current source directory, and sort the list file(GLOB TOOLS_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") -sort_list(TOOLS_SRCS) +list(SORT TOOLS_SRCS) # Set all the files to use C++ as well as set their compile flags set_source_files_properties(${TOOLS_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") @@ -9,8 +9,6 @@ set_source_files_properties(${TOOLS_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS foreach(SRC ${TOOLS_SRCS}) # Convert the source file extension to have no extension string(REGEX REPLACE "\\.cpp$" "" EXE ${SRC}) - # Calculate the header file dependencies for the given source file - calculate_depends(${SRC}) # Only continue if this file isn't skipped if(NOT SKIP) # Generate the executable and set its linker flags, also set it to depend on the main Anope executable to be built beforehand @@ -20,20 +18,20 @@ foreach(SRC ${TOOLS_SRCS}) # Only for Windows, set anopesmtp to require the wsock32 library if(WIN32 AND ${EXE} STREQUAL anopesmtp) target_link_libraries(${EXE} wsock32) - endif(WIN32 AND ${EXE} STREQUAL anopesmtp) + endif() if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" AND ${EXE} STREQUAL anopesmtp) target_link_libraries(${EXE} socket nsl) - endif(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS" AND ${EXE} STREQUAL anopesmtp) + endif() # Set the executable to be installed to the bin directory under the main directory install(TARGETS ${EXE} DESTINATION ${BIN_DIR} ) # Add the executable to the list of files for CPack to ignore - get_target_property(EXE_BINARY ${EXE} LOCATION) + set(EXE_BINARY "$<TARGET_FILE:${EXE}>") get_filename_component(EXE_BINARY ${EXE_BINARY} NAME) add_to_cpack_ignored_files("${EXE_BINARY}$" TRUE) - endif(NOT SKIP) -endforeach(SRC) + endif() +endforeach() # If not on Windows, generate anoperc and install it along with mydbgen if(NOT WIN32) @@ -44,9 +42,9 @@ if(NOT WIN32) install (PROGRAMS geoipupdate.sh DESTINATION ${BIN_DIR} ) -endif(NOT WIN32) +endif() # On non-Windows platforms, if RUNGROUP is set, change the permissions of the tools directory if(NOT WIN32 AND RUNGROUP) install(CODE "execute_process(COMMAND ${CHMOD} 2770 \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin\")") -endif(NOT WIN32 AND RUNGROUP) +endif() diff --git a/src/tools/anoperc.in b/src/tools/anoperc.in index 4b90819c0..1f96d6294 100644 --- a/src/tools/anoperc.in +++ b/src/tools/anoperc.in @@ -1,6 +1,6 @@ #!/bin/sh # -# Configuration script for Services +# Configuration script for Anope # # (C) 2003-2022 Anope Team # Contact us at team@anope.org @@ -14,8 +14,8 @@ -ANOPEPID="@INSTDIR@/data/services.pid" -ANOPROG="@INSTDIR@/bin/services" +ANOPEPID="@INSTDIR@/data/anope.pid" +ANOPROG="@INSTDIR@/bin/anope" LOG="@INSTDIR@/logs/" ARCVERSION="2" diff --git a/src/tools/anopesmtp.cpp b/src/tools/anopesmtp.cpp index 358d55aaa..2ce6496b5 100644 --- a/src/tools/anopesmtp.cpp +++ b/src/tools/anopesmtp.cpp @@ -12,14 +12,6 @@ * *nix port by Trystan Scott Lee <trystan@nomadirc.net> */ -#include "sysconf.h" - -/* Some Linux boxes (or maybe glibc includes) require this for the - * prototype of strsignal(). */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #include <string> #include <vector> #include <cstdarg> @@ -46,15 +38,6 @@ #include <sys/types.h> -#ifdef _AIX -extern int strcasecmp(const char *, const char *); -extern int strncasecmp(const char *, const char *, size_t); -# if 0 /* These break on some AIX boxes (4.3.1 reported). */ -extern int socket(int, int, int); -extern int connect(int, struct sockaddr *, int); -# endif -#endif /* _AIX */ - /* Some SUN fixs */ #ifdef __sun /* Solaris specific code, types that do not exist in Solaris' diff --git a/src/uplink.cpp b/src/uplink.cpp index 03d8d99f1..db58d71b0 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -52,12 +52,12 @@ void Uplink::Connect() if (!Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost").empty()) UplinkSock->Bind(Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost")); FOREACH_MOD(OnPreServerConnect, ()); - Anope::string ip = Anope::Resolve(u.host, u.ipv6 ? AF_INET6 : AF_INET); + Anope::string ip = Anope::Resolve(u.host, u.protocol); Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << '/' << u.port << ") with protocol " << IRCD->GetProtocolName(); UplinkSock->Connect(ip, u.port); } -UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink].ipv6), ConnectionSocket(), BufferedSocket() +UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink].protocol), ConnectionSocket(), BufferedSocket() { error = false; UplinkSock = this; diff --git a/src/users.cpp b/src/users.cpp index 67612a612..bbb54a6c0 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -448,6 +448,11 @@ bool User::IsRecognized(bool check_secure) const return on_access; } +bool User::IsSecurelyConnected() const +{ + return HasMode("SSL") || HasExt("ssl"); +} + bool User::IsServicesOper() { if (!this->nc || !this->nc->IsServicesOper()) diff --git a/src/version.sh b/src/version.sh index be6b9e5b4..c79f66a2f 100644 --- a/src/version.sh +++ b/src/version.sh @@ -1,6 +1,6 @@ #!/bin/sh VERSION_MAJOR=2 -VERSION_MINOR=0 -VERSION_PATCH=13 +VERSION_MINOR=1 +VERSION_PATCH=0 VERSION_EXTRA="-git" diff --git a/src/win32/anope_windows.h b/src/win32/anope_windows.h index accf40e8e..3ccb34198 100644 --- a/src/win32/anope_windows.h +++ b/src/win32/anope_windows.h @@ -29,9 +29,7 @@ # define DllExport __declspec(dllimport) #endif -#define MARK_DEPRECATED - -#if GETTEXT_FOUND +#if HAVE_LOCALIZATION /* Undefine some functions libintl defines */ # undef snprintf # undef vsnprintf @@ -53,7 +51,6 @@ #define EINPROGRESS WSAEWOULDBLOCK #include "socket.h" -#include "dir/dir.h" #include "dl/dl.h" #include "pipe/pipe.h" #include "pthread/pthread.h" diff --git a/src/win32/dir/dir.cpp b/src/win32/dir/dir.cpp deleted file mode 100644 index 8c8cdf907..000000000 --- a/src/win32/dir/dir.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* POSIX emulation layer for Windows. - * - * (C) 2008-2022 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - */ - -#include "dir.h" -#include <stdio.h> - -DIR *opendir(const char *path) -{ - char real_path[MAX_PATH]; - _snprintf(real_path, sizeof(real_path), "%s/*", path); - - DIR *d = new DIR(); - d->handle = FindFirstFile(real_path, &d->data); - d->read_first = false; - - if (d->handle == INVALID_HANDLE_VALUE) - { - delete d; - return NULL; - } - - return d; -} - -dirent *readdir(DIR *d) -{ - if (d->read_first == false) - d->read_first = true; - else if (!FindNextFile(d->handle, &d->data)) - return NULL; - - d->ent.d_ino = 1; - d->ent.d_name = d->data.cFileName; - - return &d->ent; -} - -int closedir(DIR *d) -{ - FindClose(d->handle); - delete d; - return 0; -} diff --git a/src/win32/dir/dir.h b/src/win32/dir/dir.h deleted file mode 100644 index bfacdd456..000000000 --- a/src/win32/dir/dir.h +++ /dev/null @@ -1,27 +0,0 @@ -/* POSIX emulation layer for Windows. - * - * (C) 2008-2022 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - */ - -#include <windows.h> - -struct dirent -{ - int d_ino; - char *d_name; -}; - -struct DIR -{ - dirent ent; - HANDLE handle; - WIN32_FIND_DATA data; - bool read_first; -}; - -DIR *opendir(const char *); -dirent *readdir(DIR *); -int closedir(DIR *); diff --git a/src/win32/socket.cpp b/src/win32/socket.cpp index f1cbcc56c..8b95c7c93 100644 --- a/src/win32/socket.cpp +++ b/src/win32/socket.cpp @@ -48,87 +48,6 @@ int windows_accept(int fd, struct sockaddr *addr, int *addrlen) return i; } -/** This is inet_pton, but it works on Windows - * @param af The protocol type, AF_INET or AF_INET6 - * @param src The address - * @param dst Struct to put results in - * @return 1 on success, -1 on error - */ -int windows_inet_pton(int af, const char *src, void *dst) -{ - int address_length; - sockaddr_storage sa; - sockaddr_in *sin = reinterpret_cast<sockaddr_in *>(&sa); - sockaddr_in6 *sin6 = reinterpret_cast<sockaddr_in6 *>(&sa); - - switch (af) - { - case AF_INET: - address_length = sizeof(sockaddr_in); - break; - case AF_INET6: - address_length = sizeof(sockaddr_in6); - break; - default: - return -1; - } - - if (!WSAStringToAddress(static_cast<LPSTR>(const_cast<char *>(src)), af, NULL, reinterpret_cast<LPSOCKADDR>(&sa), &address_length)) - { - switch (af) - { - case AF_INET: - memcpy(dst, &sin->sin_addr, sizeof(in_addr)); - break; - case AF_INET6: - memcpy(dst, &sin6->sin6_addr, sizeof(in6_addr)); - break; - } - return 1; - } - - return 0; -} - -/** This is inet_ntop, but it works on Windows - * @param af The protocol type, AF_INET or AF_INET6 - * @param src Network address structure - * @param dst After converting put it here - * @param size sizeof the dest - * @return dst - */ -const char *windows_inet_ntop(int af, const void *src, char *dst, size_t size) -{ - int address_length; - DWORD string_length = size; - sockaddr_storage sa; - sockaddr_in *sin = reinterpret_cast<sockaddr_in *>(&sa); - sockaddr_in6 *sin6 = reinterpret_cast<sockaddr_in6 *>(&sa); - - memset(&sa, 0, sizeof(sa)); - - switch (af) - { - case AF_INET: - address_length = sizeof(sockaddr_in); - sin->sin_family = af; - memcpy(&sin->sin_addr, src, sizeof(in_addr)); - break; - case AF_INET6: - address_length = sizeof(sockaddr_in6); - sin6->sin6_family = af; - memcpy(&sin6->sin6_addr, src, sizeof(in6_addr)); - break; - default: - return NULL; - } - - if (!WSAAddressToString(reinterpret_cast<LPSOCKADDR>(&sa), address_length, NULL, dst, &string_length)) - return dst; - - return NULL; -} - int fcntl(int fd, int cmd, int arg) { if (cmd == F_GETFL) diff --git a/src/win32/socket.h b/src/win32/socket.h index 147289435..9634cd718 100644 --- a/src/win32/socket.h +++ b/src/win32/socket.h @@ -21,12 +21,8 @@ extern CoreExport int read(int fd, char *buf, size_t count); extern CoreExport int write(int fd, const char *buf, size_t count); extern CoreExport int windows_close(int fd); extern CoreExport int windows_accept(int fd, struct sockaddr *addr, int *addrlen); -extern CoreExport int windows_inet_pton(int af, const char *src, void *dst); -extern CoreExport const char *windows_inet_ntop(int af, const void *src, char *dst, size_t size); extern CoreExport int fcntl(int fd, int cmd, int arg); #ifndef WIN32_NO_OVERRIDE # define accept windows_accept -# define inet_pton windows_inet_pton -# define inet_ntop windows_inet_ntop #endif diff --git a/src/xline.cpp b/src/xline.cpp index 7c8034cf0..fb98f9b24 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -86,7 +86,7 @@ void XLine::Init() } } -XLine::XLine(const Anope::string &ma, const Anope::string &r, const Anope::string &uid) : Serializable("XLine"), mask(ma), by(Me->GetName()), created(0), expires(0), reason(r), id(uid) +XLine::XLine(const Anope::string &ma, const Anope::string &r, const Anope::string &uid) : Serializable("XLine"), mask(ma), by(Me->GetName()), reason(r), id(uid) { regex = NULL; manager = NULL; @@ -288,7 +288,7 @@ const std::vector<XLine *> &XLineManager::GetList() const void XLineManager::AddXLine(XLine *x) { if (!x->id.empty()) - XLinesByUID->insert(std::make_pair(x->id, x)); + XLinesByUID->emplace(x->id, x); this->xlines->push_back(x); x->manager = this; } |