diff options
Diffstat (limited to 'src')
47 files changed, 544 insertions, 1333 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/access.cpp b/src/access.cpp index 68fd0777d..063280809 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -62,9 +62,13 @@ static struct Privilege::Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r) { if (this->desc.empty()) - for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j) - if (descriptions[j].name.equals_ci(name)) - this->desc = descriptions[j].desc; + { + for (const auto &description : descriptions) + { + if (description.name.equals_ci(name)) + this->desc = description.desc; + } + } } bool Privilege::operator==(const Privilege &other) const @@ -94,10 +98,10 @@ void PrivilegeManager::RemovePrivilege(Privilege &p) if (it != Privileges.end()) Privileges.erase(it); - for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit) + for (const auto &[_, ci] : *RegisteredChannelList) { - cit->second->QueueUpdate(); - cit->second->RemoveLevel(p.name); + ci->QueueUpdate(); + ci->RemoveLevel(p.name); } } @@ -211,6 +215,7 @@ void ChanAccess::Serialize(Serialize::Data &data) const data["ci"] << this->ci->name; data["mask"] << this->Mask(); data["creator"] << this->creator; + data["description"] << this->description; data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created; data["data"] << this->AccessSerialize(); @@ -238,6 +243,7 @@ Serializable* ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data) data["mask"] >> m; access->SetMask(m, ci); data["creator"] >> access->creator; + data["description"] >> access->description; data["last_seen"] >> access->last_seen; data["created"] >> access->created; @@ -268,9 +274,8 @@ bool ChanAccess::Matches(const User *u, const NickCore *acc, ChannelInfo* &next) if (acc) { - for (unsigned i = 0; i < acc->aliases->size(); ++i) + for (auto *na : *acc->aliases) { - const NickAlias *na = acc->aliases->at(i); if (Anope::Match(na->nick, this->mask)) return true; } @@ -340,10 +345,8 @@ static bool HasPriv(const ChanAccess::Path &path, const Anope::string &name) if (path.empty()) return false; - for (unsigned int i = 0; i < path.size(); ++i) + for (auto *access : path) { - ChanAccess *access = path[i]; - EventReturn MOD_RESULT; FOREACH_RESULT(OnCheckPriv, MOD_RESULT, (access, name)); @@ -390,9 +393,9 @@ static ChanAccess *HighestInPath(const ChanAccess::Path &path) { ChanAccess *highest = NULL; - for (unsigned int i = 0; i < path.size(); ++i) - if (highest == NULL || *path[i] > *highest) - highest = path[i]; + for (auto *ca : path) + if (highest == NULL || *ca > *highest) + highest = ca; return highest; } @@ -401,9 +404,9 @@ const ChanAccess *AccessGroup::Highest() const { ChanAccess *highest = NULL; - for (unsigned int i = 0; i < paths.size(); ++i) + for (const auto &path : paths) { - ChanAccess *hip = HighestInPath(paths[i]); + ChanAccess *hip = HighestInPath(path); if (highest == NULL || *hip > *highest) highest = hip; diff --git a/src/account.cpp b/src/account.cpp index dc5d68d28..df05eb046 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 82a45c633..31b85a41c 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -13,16 +13,12 @@ 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) { - for (std::set<ReferenceBase *>::iterator it = this->references->begin(), it_end = this->references->end(); it != it_end; ++it) - (*it)->Invalidate(); + for (auto *reference : *this->references) + reference->Invalidate(); delete this->references; } } diff --git a/src/bots.cpp b/src/bots.cpp index 6e78cd5d2..3a658ee17 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -131,8 +131,8 @@ void BotInfo::OnKill() IRCD->SendClientIntroduction(this); this->introduced = true; - for (User::ChanUserList::const_iterator cit = this->chans.begin(), cit_end = this->chans.end(); cit != cit_end; ++cit) - IRCD->SendJoin(this, cit->second->chan, &cit->second->status); + for (const auto &[_, chan] : this->chans) + IRCD->SendJoin(this, chan->chan, &chan->status); } void BotInfo::SetNewNick(const Anope::string &newnick) diff --git a/src/channels.cpp b/src/channels.cpp index 8a1f89081..5c6ba55e7 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -71,25 +71,23 @@ void Channel::Reset() { this->modes.clear(); - for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : this->users) { - ChanUserContainer *uc = it->second; - ChannelStatus f = uc->status; uc->status.Clear(); /* reset modes for my clients */ if (uc->user->server == Me) { - for (size_t i = 0; i < f.Modes().length(); ++i) - this->SetMode(NULL, ModeManager::FindChannelModeByChar(f.Modes()[i]), uc->user->GetUID(), false); + for (auto mode : f.Modes()) + this->SetMode(NULL, ModeManager::FindChannelModeByChar(mode), uc->user->GetUID(), false); /* Modes might not exist yet, so be sure the status is really reset */ uc->status = f; } } - for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) - this->SetCorrectModes(it->second->user, true); + for (auto &[_, cuc] : this->users) + this->SetCorrectModes(cuc->user, true); // If the channel is syncing now, do not force a sync due to Reset(), as we are probably iterating over users in Message::SJoin // A sync will come soon @@ -203,10 +201,12 @@ size_t Channel::HasMode(const Anope::string &mname, const Anope::string ¶m) { if (param.empty()) return modes.count(mname); - std::vector<Anope::string> v = this->GetModeList(mname); - for (unsigned int i = 0; i < v.size(); ++i) - if (v[i].equals_ci(param)) + + for (const auto &mode : this->GetModeList(mname)) + { + if (mode.equals_ci(param)) return 1; + } return 0; } @@ -214,22 +214,22 @@ Anope::string Channel::GetModes(bool complete, bool plus) { Anope::string res, params; - for (std::multimap<Anope::string, Anope::string>::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) + for (const auto &[mode, value] : this->modes) { - ChannelMode *cm = ModeManager::FindChannelModeByName(it->first); + ChannelMode *cm = ModeManager::FindChannelModeByName(mode); if (!cm || cm->type == MODE_LIST) continue; res += cm->mchar; - if (complete && !it->second.empty()) + if (complete && !value.empty()) { ChannelModeParam *cmp = NULL; if (cm->type == MODE_PARAM) cmp = anope_dynamic_static_cast<ChannelModeParam *>(cm); if (plus || !cmp || !cmp->minus_no_arg) - params += " " + it->second; + params += " " + value; } } @@ -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) { @@ -728,10 +728,9 @@ bool Channel::MatchesList(User *u, const Anope::string &mode) if (!this->HasMode(mode)) return false; - std::vector<Anope::string> v = this->GetModeList(mode); - for (unsigned i = 0; i < v.size(); ++i) + for (const auto &entry : this->GetModeList(mode)) { - Entry e(mode, v[i]); + Entry e(mode, entry); if (e.Matches(u)) return true; } @@ -845,9 +844,8 @@ void Channel::SetCorrectModes(User *user, bool give_modes) bool giving = give_modes; /* whether or not we have given a mode */ bool given = false; - for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) + for (auto *cm : ModeManager::GetStatusChannelModesByRank()) { - ChannelModeStatus *cm = ModeManager::GetStatusChannelModesByRank()[i]; bool has_priv = u_access.HasPriv("AUTO" + cm->name); if (give_modes && has_priv) @@ -880,10 +878,9 @@ bool Channel::Unban(User *u, const Anope::string &mode, bool full) bool ret = false; - std::vector<Anope::string> v = this->GetModeList(mode); - for (unsigned int i = 0; i < v.size(); ++i) + for (const auto &entry : this->GetModeList(mode)) { - Entry ban(mode, v[i]); + Entry ban(mode, entry); if (ban.Matches(u, full)) { this->RemoveMode(NULL, mode, ban.GetMask()); @@ -967,10 +964,8 @@ void Channel::QueueForDeletion() void Channel::DeleteChannels() { - for (unsigned int i = 0; i < deleting.size(); ++i) + for (auto *c : deleting) { - Channel *c = deleting[i]; - if (c->CheckDelete()) delete c; } diff --git a/src/command.cpp b/src/command.cpp index d51836b22..4205fc4a6 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; @@ -292,15 +288,10 @@ bool Command::FindCommandFromService(const Anope::string &command_service, BotIn { bot = NULL; - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - BotInfo *bi = it->second; - - for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit) + for (const auto &[c_name, info] : bi->commands) { - const Anope::string &c_name = cit->first; - const CommandInfo &info = cit->second; - if (info.name != command_service) continue; diff --git a/src/config.cpp b/src/config.cpp index 8413e59f5..08b82bbc2 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -21,7 +21,7 @@ using Configuration::File; using Configuration::Conf; using Configuration::Internal::Block; -File ServicesConf("services.conf", false); // Services configuration file name +File ServicesConf("anope.conf", false); // Configuration file name Conf *Config = NULL; Block Block::EmptyBlock(""); @@ -66,9 +66,9 @@ bool Block::Set(const Anope::string &tag, const Anope::string &value) return true; } -const Block::item_map* Block::GetItems() const +const Block::item_map &Block::GetItems() const { - return &items; + return items; } template<> const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const @@ -154,9 +154,11 @@ Conf::Conf() : Block("") {"networkinfo", "chanlen"}, }; - for (unsigned i = 0; i < sizeof(noreload) / sizeof(noreload[0]); ++i) - if (this->GetBlock(noreload[i].block)->Get<const Anope::string>(noreload[i].name) != Config->GetBlock(noreload[i].block)->Get<const Anope::string>(noreload[i].name)) - throw ConfigException("<" + noreload[i].block + ":" + noreload[i].name + "> can not be modified once set"); + for (const auto &tag : noreload) + { + if (this->GetBlock(tag.block)->Get<const Anope::string>(tag.name) != Config->GetBlock(tag.block)->Get<const Anope::string>(tag.name)) + throw ConfigException("<" + tag.block + ":" + tag.name + "> can not be modified once set"); + } } const Block *serverinfo = this->GetBlock("serverinfo"), *options = this->GetBlock("options"), @@ -186,8 +188,8 @@ Conf::Conf() : Block("") if (mail->Get<bool>("usemail")) { Anope::string check[] = { "sendmailpath", "sendfrom", "registration_subject", "registration_message", "emailchange_subject", "emailchange_message", "memo_subject", "memo_message" }; - for (unsigned i = 0; i < sizeof(check) / sizeof(Anope::string); ++i) - ValidateNotEmpty("mail", check[i], mail->Get<const Anope::string>(check[i])); + for (const auto &field : check) + ValidateNotEmpty("mail", field, mail->Get<const Anope::string>(field)); } this->ReadTimeout = options->Get<time_t>("readtimeout"); @@ -207,19 +209,33 @@ Conf::Conf() : Block("") { const 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) + { + port = uplink->Get<int>("port"); + ValidateNotZero("uplink", "port", 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) @@ -262,10 +278,8 @@ Conf::Conf() : Block("") /* Strip leading ' ' after , */ if (str.length() > 1 && str[0] == ' ') str.erase(str.begin()); - for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) + for (auto *ot2 : this->MyOperTypes) { - OperType *ot2 = this->MyOperTypes[j]; - if (ot2->GetName().equals_ci(str)) { Log() << "Inheriting commands and privs from " << ot2->GetName() << " to " << ot->GetName(); @@ -294,9 +308,11 @@ Conf::Conf() : Block("") ValidateNotEmpty("oper", "type", type); OperType *ot = NULL; - for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) - if (this->MyOperTypes[j]->GetName() == type) - ot = this->MyOperTypes[j]; + for (auto *opertype : this->MyOperTypes) + { + if (opertype->GetName() == type) + ot = opertype; + } if (ot == NULL) throw ConfigException("Oper block for " + nname + " has invalid oper type " + type); @@ -310,8 +326,8 @@ Conf::Conf() : Block("") this->Opers.push_back(o); } - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->conf = false; + for (const auto &[_, bi] : *BotListByNick) + bi->conf = false; for (int i = 0; i < this->CountBlock("service"); ++i) { const Block *service = this->GetBlock("service", i); @@ -359,28 +375,30 @@ Conf::Conf() : Block("") /* Remove all existing modes */ ChanUserContainer *cu = c->FindUser(bi); if (cu != NULL) - for (size_t j = 0; j < cu->status.Modes().length(); ++j) - c->RemoveMode(bi, ModeManager::FindChannelModeByChar(cu->status.Modes()[j]), bi->GetUID()); + { + for (auto mode : cu->status.Modes()) + c->RemoveMode(bi, ModeManager::FindChannelModeByChar(mode), bi->GetUID()); + } /* Set the new modes */ - for (unsigned j = 0; j < want_modes.length(); ++j) + for (char want_mode : want_modes) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(want_mode); if (cm == NULL) - cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j])); + cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_mode)); if (cm && cm->type == MODE_STATUS) c->SetMode(bi, cm, bi->GetUID()); } } - for (unsigned k = 0; k < oldchannels.size(); ++k) + for (const auto &oldchannel : oldchannels) { - size_t ch = oldchannels[k].find('#'); - Anope::string chname = oldchannels[k].substr(ch != Anope::string::npos ? ch : 0); + size_t ch = oldchannel.find('#'); + Anope::string chname = oldchannel.substr(ch != Anope::string::npos ? ch : 0); bool found = false; - for (unsigned j = 0; j < bi->botchannels.size(); ++j) + for (const auto &botchannel : bi->botchannels) { - ch = bi->botchannels[j].find('#'); - Anope::string ochname = bi->botchannels[j].substr(ch != Anope::string::npos ? ch : 0); + ch = botchannel.find('#'); + Anope::string ochname = botchannel.substr(ch != Anope::string::npos ? ch : 0); if (chname.equals_ci(ochname)) found = true; @@ -422,8 +440,8 @@ Conf::Conf() : Block("") this->LogInfos.push_back(l); } - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->commands.clear(); + for (const auto &[_, bi] : *BotListByNick) + bi->commands.clear(); for (int i = 0; i < this->CountBlock("command"); ++i) { const Block *command = this->GetBlock("command", i); @@ -500,17 +518,14 @@ Conf::Conf() : Block("") if (Config) /* Clear existing conf opers */ - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - NickCore *nc = it->second; if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) nc->o = NULL; } /* Apply new opers */ - for (unsigned i = 0; i < this->Opers.size(); ++i) + for (auto *o : this->Opers) { - Oper *o = this->Opers[i]; - NickAlias *na = NickAlias::Find(o->name); if (!na) continue; @@ -550,21 +565,27 @@ Conf::Conf() : Block("") Conf::~Conf() { - for (unsigned i = 0; i < MyOperTypes.size(); ++i) - delete MyOperTypes[i]; - for (unsigned i = 0; i < Opers.size(); ++i) - delete Opers[i]; + for (const auto *opertype : MyOperTypes) + delete opertype; + + for (const auto *oper : Opers) + delete oper; } void Conf::Post(Conf *old) { /* Apply module changes */ - for (unsigned i = 0; i < old->ModulesAutoLoad.size(); ++i) - if (std::find(this->ModulesAutoLoad.begin(), this->ModulesAutoLoad.end(), old->ModulesAutoLoad[i]) == this->ModulesAutoLoad.end()) - ModuleManager::UnloadModule(ModuleManager::FindModule(old->ModulesAutoLoad[i]), NULL); - for (unsigned i = 0; i < this->ModulesAutoLoad.size(); ++i) - if (std::find(old->ModulesAutoLoad.begin(), old->ModulesAutoLoad.end(), this->ModulesAutoLoad[i]) == old->ModulesAutoLoad.end()) - ModuleManager::LoadModule(this->ModulesAutoLoad[i], NULL); + for (const auto &mod : old->ModulesAutoLoad) + { + if (std::find(this->ModulesAutoLoad.begin(), this->ModulesAutoLoad.end(), mod) == this->ModulesAutoLoad.end()) + ModuleManager::UnloadModule(ModuleManager::FindModule(mod), NULL); + } + + for (const auto &mod : this->ModulesAutoLoad) + { + if (std::find(old->ModulesAutoLoad.begin(), old->ModulesAutoLoad.end(), mod) == old->ModulesAutoLoad.end()) + ModuleManager::LoadModule(mod, NULL); + } /* Apply opertype changes, as non-conf opers still point to the old oper types */ for (unsigned i = Oper::opers.size(); i > 0; --i) @@ -577,9 +598,11 @@ void Conf::Post(Conf *old) OperType *ot = o->ot; o->ot = NULL; - for (unsigned j = 0; j < MyOperTypes.size(); ++j) - if (ot->GetName() == MyOperTypes[j]->GetName()) - o->ot = MyOperTypes[j]; + for (auto *opertype : MyOperTypes) + { + if (ot->GetName() == opertype->GetName()) + o->ot = opertype; + } if (o->ot == NULL) { @@ -659,7 +682,7 @@ const Block *Conf::GetCommand(CommandSource &source) return &Block::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) { } @@ -848,7 +871,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/extensible.cpp b/src/extensible.cpp index 05ab7c5ac..06ffeeb3f 100644 --- a/src/extensible.cpp +++ b/src/extensible.cpp @@ -52,10 +52,9 @@ void Extensible::ExtensibleSerialize(const Extensible *e, const Serializable *s, void Extensible::ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) { - for (std::set<ExtensibleBase *>::iterator it = extensible_items.begin(); it != extensible_items.end(); ++it) + for (auto *extensible_item : extensible_items) { - ExtensibleBase *eb = *it; - eb->ExtensibleUnserialize(e, s, data); + extensible_item->ExtensibleUnserialize(e, s, data); } } diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 79c205298..db53e0fc3 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 082f39b96..a0c46cb2f 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); } } @@ -71,11 +71,11 @@ static bool GetCommandLineArgument(const Anope::string &name, char shortname, An { param.clear(); - for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = CommandLineArguments.begin(), it_end = CommandLineArguments.end(); it != it_end; ++it) + for (const auto &[argument, value] : CommandLineArguments) { - if (it->first.equals_ci(name) || (it->first.length() == 1 && it->first[0] == shortname)) + if (argument.equals_ci(name) || (argument.length() == 1 && argument[0] == shortname)) { - param = it->second; + param = argument; return true; } } @@ -258,14 +258,10 @@ static void setuidgid() gid = g->gr_gid; } - for (unsigned i = 0; i < Config->LogInfos.size(); ++i) + for (const auto &li : Config->LogInfos) { - LogInfo& li = Config->LogInfos[i]; - - for (unsigned j = 0; j < li.logfiles.size(); ++j) + for (const auto *lf : li.logfiles) { - LogFile* lf = li.logfiles[j]; - errno = 0; if (chown(lf->filename.c_str(), uid, gid) != 0) Log() << "Unable to change the ownership of " << lf->filename << " to " << uid << "/" << gid << ": " << Anope::LastError(); @@ -411,7 +407,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()); @@ -479,7 +475,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."; @@ -489,9 +485,9 @@ void Anope::Init(int ac, char **av) /* Create me */ Configuration::Block *block = Config->GetBlock("serverinfo"); Me = new Server(NULL, block->Get<const Anope::string>("name"), 0, block->Get<const Anope::string>("description"), block->Get<const Anope::string>("id")); - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - it->second->server = Me; + bi->server = Me; ++Me->users; } @@ -547,8 +543,8 @@ void Anope::Init(int ac, char **av) Anope::string sid = IRCD->SID_Retrieve(); if (Me->GetSID() == Me->GetName()) Me->SetSID(sid); - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->GenerateUID(); + for (const auto &[_, bi] : *BotListByNick) + bi->GenerateUID(); } /* Load up databases */ @@ -560,8 +556,8 @@ void Anope::Init(int ac, char **av) FOREACH_MOD(OnPostInit, ()); - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) - it->second->Sync(); + for (const auto &[_, ci] : ChannelList) + ci->Sync(); Serialize::CheckTypes(); } diff --git a/src/language.cpp b/src/language.cpp index 73263d97e..3b3066510 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 49cbc05b2..fb4b4bea8 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 = Config->GetClient(c->name.substr(0, sl)); 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) { } @@ -131,9 +130,13 @@ Log::~Log() FOREACH_MOD(OnLog, (this)); if (Config) - for (unsigned i = 0; i < Config->LogInfos.size(); ++i) - if (Config->LogInfos[i].HasType(this->type, this->category)) - Config->LogInfos[i].ProcessMessage(this); + { + for (auto &li : Config->LogInfos) + { + if (li.HasType(this->type, this->category)) + li.ProcessMessage(this); + } + } } Anope::string Log::FormatSource() const @@ -227,14 +230,14 @@ 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) { } LogInfo::~LogInfo() { - for (unsigned i = 0; i < this->logfiles.size(); ++i) - delete this->logfiles[i]; + for (const auto *logfile : this->logfiles) + delete logfile; this->logfiles.clear(); } @@ -281,16 +284,15 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const if (list == NULL) return false; - for (unsigned i = 0; i < list->size(); ++i) + for (auto value : *list) { - Anope::string cat = list->at(i); bool inverse = false; - if (cat[0] == '~') + if (value[0] == '~') { - cat.erase(cat.begin()); + value.erase(value.begin()); inverse = true; } - if (Anope::Match(type, cat)) + if (Anope::Match(type, value)) { return !inverse; } @@ -301,14 +303,12 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const void LogInfo::OpenLogFiles() { - for (unsigned i = 0; i < this->logfiles.size(); ++i) - delete this->logfiles[i]; + for (const auto *logfile : this->logfiles) + delete logfile; this->logfiles.clear(); - for (unsigned i = 0; i < this->targets.size(); ++i) + for (const auto &target : this->targets) { - const Anope::string &target = this->targets[i]; - if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos) continue; @@ -353,10 +353,8 @@ void LogInfo::ProcessMessage(const Log *l) FOREACH_MOD(OnLogMessage, (this, l, buffer)); - for (unsigned i = 0; i < this->targets.size(); ++i) + for (const auto &target : this->targets) { - const Anope::string &target = this->targets[i]; - if (!target.empty() && target[0] == '#') { if (UplinkSock && l->type <= LOG_NORMAL && Me && Me->IsSynced()) @@ -394,11 +392,10 @@ void LogInfo::ProcessMessage(const Log *l) this->OpenLogFiles(); if (this->log_age) - for (unsigned i = 0; i < this->targets.size(); ++i) + { + for (const auto &target : this->targets) { - const Anope::string &target = this->targets[i]; - - if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos) + if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos) continue; Anope::string oldlog = CreateLogName(target, Anope::CurTime - 86400 * this->log_age); @@ -408,11 +405,11 @@ void LogInfo::ProcessMessage(const Log *l) Log(LOG_DEBUG) << "Deleted old logfile " << oldlog; } } + } } - for (unsigned i = 0; i < this->logfiles.size(); ++i) + for (auto *lf : this->logfiles) { - LogFile *lf = this->logfiles[i]; lf->stream << GetTimeStamp() << " " << buffer << std::endl; } } diff --git a/src/mail.cpp b/src/mail.cpp index ca6edcffa..3f24e3a54 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -16,13 +16,13 @@ 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) + , send_from(sf) + , mail_to(mailto) , addr(a) , subject(s) , message(m) , content_type(Config->GetBlock("mail")->Get<const Anope::string>("content_type", "text/plain; charset=UTF-8")) , dont_quote_addresses(Config->GetBlock("mail")->Get<bool>("dontquoteaddresses")) - , success(false) { } @@ -144,13 +144,15 @@ bool Mail::Validate(const Anope::string &email) return false; /* Check for forbidden characters in the name */ - for (unsigned i = 0, end = copy.length(); i < end; ++i) + for (auto chr : copy) { - if (copy[i] <= 31 || copy[i] >= 127) + if (chr <= 31 || chr >= 127) return false; - for (unsigned int j = 0; j < 13; ++j) - if (copy[i] == specials[j]) + for (auto special : specials) + { + if (chr == special) return false; + } } /* Check for forbidden characters in the domain */ @@ -158,9 +160,11 @@ bool Mail::Validate(const Anope::string &email) { if (domain[i] <= 31 || domain[i] >= 127) return false; - for (unsigned int j = 0; j < 13; ++j) - if (domain[i] == specials[j]) + for (auto special : specials) + { + if (domain[i] == special) return false; + } if (domain[i] == '.') { if (!i || i == end - 1) diff --git a/src/main.cpp b/src/main.cpp index e951df0d3..b41c591d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -/* Services -- main source file. +/* Anope -- main source file. * * (C) 2003-2023 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 333094caf..03cd7f77d 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") { } @@ -113,9 +113,11 @@ void MemoInfo::Del(unsigned index) bool MemoInfo::HasIgnore(User *u) { - for (unsigned i = 0; i < this->ignores.size(); ++i) - if (u->nick.equals_ci(this->ignores[i]) || (u->Account() && u->Account()->display.equals_ci(this->ignores[i])) || Anope::Match(u->GetMask(), Anope::string(this->ignores[i]))) + for (const auto &ignore : this->ignores) + { + if (u->nick.equals_ci(ignore) || (u->Account() && u->Account()->display.equals_ci(ignore)) || Anope::Match(u->GetMask(), Anope::string(ignore))) return true; + } return false; } diff --git a/src/messages.cpp b/src/messages.cpp index 84124f5e8..2aaae177f 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) { @@ -43,18 +43,20 @@ void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) Servers::Capab.insert(token); } else - for (unsigned i = 0; i < params.size(); ++i) - Servers::Capab.insert(params[i]); + { + for (const auto ¶m : params) + Servers::Capab.insert(param); + } } -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 +67,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 +94,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); @@ -127,10 +129,8 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co */ c->SetModesInternal(source, modes, ts, !c->syncing); - for (std::list<SJoinUser>::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it) + for (const auto &[status, u] : users) { - const ChannelStatus &status = it->first; - User *u = it->second; keep_their_modes = ts <= c->creation_time; // OnJoinChannel can call modules which can modify this channel's ts if (c->FindUser(u)) @@ -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(); @@ -426,10 +426,8 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); else { - for (unsigned i = 0; i < Oper::opers.size(); ++i) + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - const NickAlias *na = NickAlias::Find(o->name); if (na) IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().replace_all_cs(" ", "_").c_str()); @@ -455,7 +453,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 +464,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 +473,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 7e68686a2..39c688ea6 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) @@ -106,8 +102,8 @@ void NumberList::Process() } else { - for (std::set<unsigned>::iterator it = numbers.begin(), it_end = numbers.end(); it != it_end; ++it) - this->HandleNumber(*it); + for (unsigned int number : numbers) + this->HandleNumber(number); } } @@ -145,29 +141,30 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) std::vector<Anope::string> tcolumns; std::map<Anope::string, size_t> lengths; std::set<Anope::string> breaks; - for (unsigned i = 0; i < this->columns.size(); ++i) + for (const auto &column : this->columns) { - tcolumns.push_back(Language::Translate(this->nc, this->columns[i].c_str())); - lengths[this->columns[i]] = tcolumns[i].length(); + tcolumns.emplace_back(Language::Translate(this->nc, column.c_str())); + lengths[column] = column.length(); } - for (unsigned i = 0; i < this->entries.size(); ++i) + for (auto &entry : this->entries) { - ListEntry &e = this->entries[i]; - for (unsigned j = 0; j < this->columns.size(); ++j) - if (e[this->columns[j]].length() > lengths[this->columns[j]]) - lengths[this->columns[j]] = e[this->columns[j]].length(); + for (const auto &column : this->columns) + { + if (entry[column].length() > lengths[column]) + lengths[column] = entry[column].length(); + } } - unsigned length = 0; - for (std::map<Anope::string, size_t>::iterator it = lengths.begin(), it_end = lengths.end(); it != it_end; ++it) + unsigned total_length = 0; + for (const auto &[column, length] : lengths) { /* Break lines at 80 chars */ - if (length > 80) + if (total_length > 80) { - breaks.insert(it->first); - length = 0; + breaks.insert(column); + total_length = 0; } else - length += it->second; + total_length += length; } /* Only put a list header if more than 1 column */ @@ -191,10 +188,8 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) buffer.push_back(s); } - for (unsigned i = 0; i < this->entries.size(); ++i) + for (auto &entry : this->entries) { - ListEntry &e = this->entries[i]; - Anope::string s; for (unsigned j = 0; j < this->columns.size(); ++j) { @@ -205,16 +200,16 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) } else if (!s.empty()) s += " "; - s += e[this->columns[j]]; + s += entry[this->columns[j]]; if (j + 1 != this->columns.size()) - for (unsigned k = e[this->columns[j]].length(); k < lengths[this->columns[j]]; ++k) + for (unsigned k = entry[this->columns[j]].length(); k < lengths[this->columns[j]]; ++k) s += " "; } buffer.push_back(s); } } -InfoFormatter::InfoFormatter(NickCore *acc) : nc(acc), longest(0) +InfoFormatter::InfoFormatter(NickCore *acc) : nc(acc) { } @@ -222,12 +217,12 @@ void InfoFormatter::Process(std::vector<Anope::string> &buffer) { buffer.clear(); - for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = this->replies.begin(), it_end = this->replies.end(); it != it_end; ++it) + for (const auto &[key, value] : this->replies) { Anope::string s; - for (unsigned i = it->first.length(); i < this->longest; ++i) + for (unsigned i = key.length(); i < this->longest; ++i) s += " "; - s += it->first + ": " + Language::Translate(this->nc, it->second.c_str()); + s += key + ": " + Language::Translate(this->nc, value.c_str()); buffer.push_back(s); } @@ -238,7 +233,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; } @@ -246,11 +241,11 @@ void InfoFormatter::AddOption(const Anope::string &opt) { Anope::string options = Language::Translate(this->nc, "Options"); Anope::string *optstr = NULL; - for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = this->replies.begin(), it_end = this->replies.end(); it != it_end; ++it) + for (auto &[option, value] : this->replies) { - if (it->first == options) + if (option == options) { - optstr = &it->second; + optstr = &value; break; } } @@ -514,24 +509,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 +616,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 5f950df57..6c46302de 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) { } @@ -101,9 +95,9 @@ Anope::string ChannelStatus::BuildModePrefixList() const { Anope::string ret; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (cm != NULL && cm->type == MODE_STATUS) { ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm); @@ -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; @@ -154,9 +144,9 @@ ChannelMode *ChannelMode::Wrap(Anope::string ¶m) ChannelMode *ChannelMode::Unwrap(Anope::string ¶m) { - for (unsigned i = 0; i < listeners.size(); ++i) + for (auto *listener : listeners) { - ChannelMode *cm = listeners[i]->Unwrap(this, param); + ChannelMode *cm = listener->Unwrap(this, param); if (cm != this) return cm; } @@ -307,13 +297,13 @@ 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 { public: - void OnNotify() + void OnNotify() override { ModeManager::ProcessModes(); } @@ -456,8 +446,8 @@ bool ModeManager::AddChannelMode(ChannelMode *cm) FOREACH_MOD(OnChannelModeAdd, (cm)); - for (unsigned int i = 0; i < ChannelModes.size(); ++i) - ChannelModes[i]->Check(); + for (auto *cmode : ChannelModes) + cmode->Check(); return true; } @@ -600,10 +590,8 @@ static struct StatusSort void ModeManager::RebuildStatusModes() { ChannelModesByStatus.clear(); - for (unsigned j = 0; j < ChannelModesIdx.size(); ++j) + for (auto *cm : ChannelModesIdx) { - ChannelMode *cm = ChannelModesIdx[j]; - if (cm && cm->type == MODE_STATUS && std::find(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), cm) == ChannelModesByStatus.end()) ChannelModesByStatus.push_back(anope_dynamic_static_cast<ChannelModeStatus *>(cm)); } @@ -640,30 +628,22 @@ void ModeManager::ProcessModes() { if (!UserStackerObjects.empty()) { - for (std::map<User *, StackerInfo *>::const_iterator it = UserStackerObjects.begin(), it_end = UserStackerObjects.end(); it != it_end; ++it) + for (const auto &[u, s] : UserStackerObjects) { - User *u = it->first; - StackerInfo *s = it->second; - - std::list<Anope::string> ModeStrings = BuildModeStrings(s); - for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(s->bi, u, "%s", lit->c_str()); - delete it->second; + for (const auto &modestr : BuildModeStrings(s)) + IRCD->SendMode(s->bi, u, "%s", modestr.c_str()); + delete s; } UserStackerObjects.clear(); } if (!ChannelStackerObjects.empty()) { - for (std::map<Channel *, StackerInfo *>::const_iterator it = ChannelStackerObjects.begin(), it_end = ChannelStackerObjects.end(); it != it_end; ++it) + for (const auto &[c, s] : ChannelStackerObjects) { - Channel *c = it->first; - StackerInfo *s = it->second; - - std::list<Anope::string> ModeStrings = BuildModeStrings(s); - for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(s->bi, c, "%s", lit->c_str()); - delete it->second; + for (const auto &modestr : BuildModeStrings(s)) + IRCD->SendMode(s->bi, c, "%s", modestr.c_str()); + delete s; } ChannelStackerObjects.clear(); } @@ -676,9 +656,8 @@ static void StackerDel(std::map<T *, StackerInfo *> &map, T *obj) if (it != map.end()) { StackerInfo *si = it->second; - std::list<Anope::string> ModeStrings = BuildModeStrings(si); - for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(si->bi, obj, "%s", lit->c_str()); + for (const auto &modestr : BuildModeStrings(si)) + IRCD->SendMode(si->bi, obj, "%s", modestr.c_str()); delete si; map.erase(it); @@ -742,7 +721,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 2da365270..7722c7748 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,12 +39,12 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt ModuleManager::Modules.push_back(this); -#if GETTEXT_FOUND - for (unsigned i = 0; i < Language::Languages.size(); ++i) +#if HAVE_LOCALIZATION + for (const auto &language : Language::Languages) { /* Remove .UTF-8 or any other suffix */ Anope::string lang; - sepstream(Language::Languages[i], '.').GetToken(lang); + sepstream(language, '.').GetToken(lang); if (Anope::IsFile(Anope::LocaleDir + "/" + lang + "/LC_MESSAGES/" + modname + ".mo")) { @@ -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 f5f93a937..38ed130f7 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); } /** @@ -273,8 +267,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) Log(LOG_DEBUG) << "Module " << modname << " loaded."; /* Attach module to all events */ - for (unsigned i = 0; i < I_SIZE; ++i) - EventHandlers[i].push_back(m); + for (auto &mods : EventHandlers) + mods.push_back(m); m->Prioritize(); @@ -313,10 +307,8 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u) Module *ModuleManager::FindModule(const Anope::string &name) { - for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + for (auto *m : Modules) { - Module *m = *it; - if (m->name.equals_ci(name)) return m; } @@ -326,10 +318,8 @@ Module *ModuleManager::FindModule(const Anope::string &name) Module *ModuleManager::FindFirstOf(ModType type) { - for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + for (auto *m : Modules) { - Module *m = *it; - if (m->type & type) return m; } @@ -395,9 +385,8 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) void ModuleManager::DetachAll(Module *mod) { - for (unsigned i = 0; i < I_SIZE; ++i) + for (auto &mods : EventHandlers) { - std::vector<Module *> &mods = EventHandlers[i]; std::vector<Module *>::iterator it2 = std::find(mods.begin(), mods.end(), mod); if (it2 != mods.end()) mods.erase(it2); @@ -510,16 +499,17 @@ void ModuleManager::UnloadAll() { std::vector<Anope::string> modules; for (size_t i = 1, j = 0; i != MT_END; j |= i, i <<= 1) - for (std::list<Module *>::iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + { + for (auto *m : Modules) { - Module *m = *it; if ((m->type & j) == m->type) modules.push_back(m->name); } + } - for (unsigned i = 0; i < modules.size(); ++i) + for (auto &module : modules) { - Module *m = FindModule(modules[i]); + Module *m = FindModule(module); if (m != NULL) UnloadModule(m, NULL); } diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 4c14d8591..9d292bbf3 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -78,11 +78,11 @@ void NickCore::Serialize(Serialize::Data &data) const data["pass"] << this->pass; data["email"] << this->email; data["language"] << this->language; - for (unsigned i = 0; i < this->access.size(); ++i) - data["access"] << this->access[i] << " "; + for (const auto &mask : this->access) + data["access"] << mask << " "; data["memomax"] << this->memos.memomax; - for (unsigned i = 0; i < this->memos.ignores.size(); ++i) - data["memoignores"] << this->memos.ignores[i] << " "; + for (const auto &ignore : this->memos.ignores) + data["memoignores"] << ignore << " "; Extensible::ExtensibleSerialize(this, this, data); } @@ -171,8 +171,8 @@ void NickCore::SetDisplay(const NickAlias *na) FOREACH_MOD(OnChangeCoreDisplay, (this, na->nick)); /* this affects the serialized aliases */ - for (unsigned i = 0; i < aliases->size(); ++i) - aliases->at(i)->QueueUpdate(); + for (auto *alias : *aliases) + alias->QueueUpdate(); /* Remove the core from the list */ NickCoreList->erase(this->display); @@ -207,9 +207,11 @@ unsigned NickCore::GetAccessCount() const bool NickCore::FindAccess(const Anope::string &entry) { - for (unsigned i = 0, end = this->access.size(); i < end; ++i) - if (this->access[i] == entry) + for (const auto &mask : this->access) + { + if (mask == entry) return true; + } return false; } @@ -263,8 +265,8 @@ void NickCore::RemoveChannelReference(ChannelInfo *ci) void NickCore::GetChannelReferences(std::deque<ChannelInfo *> &queue) { queue.clear(); - for (std::map<ChannelInfo *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it) - queue.push_back(it->first); + for (const auto &[ci, _] : *this->chanaccess) + queue.push_back(ci); } NickCore* NickCore::Find(const Anope::string &nick) @@ -300,8 +302,8 @@ uint64_t NickCore::GetId() { // Generate a random key for SipHash. char key[16]; - for (size_t i = 0; i < sizeof(key); ++i) - key[i] = rand() % CHAR_MAX; + for (auto &chr : key) + chr = rand() % CHAR_MAX; uint64_t newid = Anope::SipHash24(secretid.c_str(), secretid.length(), key); nickcoreid_map::const_iterator it = NickCoreIdList.find(newid); diff --git a/src/opertype.cpp b/src/opertype.cpp index fb92ca488..e7708f99f 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); } @@ -27,10 +27,8 @@ Oper::~Oper() Oper *Oper::Find(const Anope::string &name) { - for (unsigned i = 0; i < opers.size(); ++i) + for (auto *o : opers) { - Oper *o = opers[i]; - if (o->name.equals_ci(name)) return o; } @@ -40,10 +38,8 @@ Oper *Oper::Find(const Anope::string &name) OperType *OperType::Find(const Anope::string &name) { - for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) + for (auto *ot : Config->MyOperTypes) { - OperType *ot = Config->MyOperTypes[i]; - if (ot->GetName() == name) return ot; } @@ -57,19 +53,15 @@ OperType::OperType(const Anope::string &nname) : name(nname) bool OperType::HasCommand(const Anope::string &cmdstr) const { - for (std::list<Anope::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it) + for (const auto &command : this->commands) { - const Anope::string &s = *it; - - if (!s.find('~') && Anope::Match(cmdstr, s.substr(1))) + if (!command.find('~') && Anope::Match(cmdstr, command.substr(1))) return false; - else if (Anope::Match(cmdstr, s)) + else if (Anope::Match(cmdstr, command)) return true; } - for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit) + for (auto *ot : this->inheritances) { - OperType *ot = *iit; - if (ot->HasCommand(cmdstr)) return true; } @@ -79,19 +71,15 @@ bool OperType::HasCommand(const Anope::string &cmdstr) const bool OperType::HasPriv(const Anope::string &privstr) const { - for (std::list<Anope::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it) + for (const auto &priv : this->privs) { - const Anope::string &s = *it; - - if (!s.find('~') && Anope::Match(privstr, s.substr(1))) + if (!priv.find('~') && Anope::Match(privstr, priv.substr(1))) return false; - else if (Anope::Match(privstr, s)) + else if (Anope::Match(privstr, priv)) return true; } - for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit) + for (auto *ot : this->inheritances) { - OperType *ot = *iit; - if (ot->HasPriv(privstr)) return true; } @@ -123,12 +111,10 @@ void OperType::Inherits(OperType *ot) const std::list<Anope::string> OperType::GetCommands() const { std::list<Anope::string> cmd_list = this->commands; - for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it) + for (auto *ot : this->inheritances) { - OperType *ot = *it; - std::list<Anope::string> cmds = ot->GetCommands(); - for (std::list<Anope::string>::const_iterator it2 = cmds.begin(), it2_end = cmds.end(); it2 != it2_end; ++it2) - cmd_list.push_back(*it2); + for (const auto &cmd : ot->GetCommands()) + cmd_list.push_back(cmd); } return cmd_list; } @@ -136,12 +122,10 @@ const std::list<Anope::string> OperType::GetCommands() const const std::list<Anope::string> OperType::GetPrivs() const { std::list<Anope::string> priv_list = this->privs; - for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it) + for (auto *ot : this->inheritances) { - OperType *ot = *it; - std::list<Anope::string> priv = ot->GetPrivs(); - for (std::list<Anope::string>::const_iterator it2 = priv.begin(), it2_end = priv.end(); it2 != it2_end; ++it2) - priv_list.push_back(*it2); + for (const auto &priv : ot->GetPrivs()) + priv_list.push_back(priv); } return priv_list; } diff --git a/src/process.cpp b/src/process.cpp index 3a21943f3..261849bae 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 f27866212..090187819 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; @@ -389,10 +389,8 @@ bool IRCDProto::IsIdentValid(const Anope::string &ident) if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) return false; - for (unsigned i = 0; i < ident.length(); ++i) + for (auto c : ident) { - const char &c = ident[i]; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') continue; @@ -416,11 +414,11 @@ bool IRCDProto::IsHostValid(const Anope::string &host) return false; int dots = 0; - for (unsigned i = 0; i < host.length(); ++i) + for (auto chr : host) { - if (host[i] == '.') + if (chr == '.') ++dots; - if (vhostchars.find_first_of(host[i]) == Anope::string::npos) + if (vhostchars.find_first_of(chr) == Anope::string::npos) return false; } @@ -450,7 +448,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 +459,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 +505,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 984da55ab..966f3e1b4 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -194,16 +194,16 @@ void ChannelInfo::Serialize(Serialize::Data &data) const data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype; { Anope::string levels_buffer; - for (Anope::map<int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it) - levels_buffer += it->first + " " + stringify(it->second) + " "; + for (const auto &[name, level] : this->levels) + levels_buffer += name + " " + stringify(level) + " "; data["levels"] << levels_buffer; } if (this->bi) data["bi"] << this->bi->nick; data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire; data["memomax"] << this->memos.memomax; - for (unsigned i = 0; i < this->memos.ignores.size(); ++i) - data["memoignores"] << this->memos.ignores[i] << " "; + for (const auto &ignore : this->memos.ignores) + data["memoignores"] << ignore << " "; Extensible::ExtensibleSerialize(this, this, data); } @@ -443,12 +443,10 @@ AccessGroup ChannelInfo::AccessFor(const User *u, bool updateLastUsed) if (updateLastUsed) this->last_used = Anope::CurTime; - for (unsigned i = 0; i < group.paths.size(); ++i) + for (auto &p : group.paths) { - ChanAccess::Path &p = group.paths[i]; - - for (unsigned int j = 0; j < p.size(); ++j) - p[j]->last_seen = Anope::CurTime; + for (auto *ca : p) + ca->last_seen = Anope::CurTime; } } @@ -688,6 +686,6 @@ void ChannelInfo::RemoveChannelReference(const Anope::string &what) void ChannelInfo::GetChannelReferences(std::deque<Anope::string> &chans) { chans.clear(); - for (Anope::map<int>::iterator it = references.begin(); it != references.end(); ++it) - chans.push_back(it->first); + for (auto &[chan, _] : references) + chans.push_back(chan); } diff --git a/src/serialize.cpp b/src/serialize.cpp index 873d304b1..03d9ed626 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -34,14 +34,13 @@ void Serialize::RegisterTypes() void Serialize::CheckTypes() { - for (std::map<Anope::string, Serialize::Type *>::const_iterator it = Serialize::Type::GetTypes().begin(), it_end = Serialize::Type::GetTypes().end(); it != it_end; ++it) + for (const auto &[_, t] : Serialize::Type::GetTypes()) { - Serialize::Type *t = it->second; t->Check(); } } -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 +54,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 +111,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; @@ -124,13 +123,13 @@ Type::~Type() { /* null the type of existing serializable objects of this type */ if (Serializable::SerializableItems != NULL) - for (std::list<Serializable *>::iterator it = Serializable::SerializableItems->begin(); it != Serializable::SerializableItems->end(); ++it) + { + for (auto *s : *Serializable::SerializableItems) { - Serializable *s = *it; - if (s->s_type == this) s->s_type = NULL; } + } std::vector<Anope::string>::iterator it = std::find(TypeOrder.begin(), TypeOrder.end(), this->name); if (it != TypeOrder.end()) diff --git a/src/servers.cpp b/src/servers.cpp index 23ea18139..e8547015a 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; @@ -48,27 +48,26 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano if (Me == this->uplink && !juped) { /* Now do mode related stuff as we know what modes exist .. */ - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (auto &[_, bi] : *BotListByNick) { - BotInfo *bi = it->second; Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : IRCD->DefaultPseudoclientModes; bi->SetModesInternal(bi, modes.c_str()); - for (unsigned i = 0; i < bi->botchannels.size(); ++i) + for (const auto &botchannel : bi->botchannels) { - size_t h = bi->botchannels[i].find('#'); + size_t h = botchannel.find('#'); if (h == Anope::string::npos) continue; - Anope::string chname = bi->botchannels[i].substr(h); + Anope::string chname = botchannel.substr(h); Channel *c = Channel::Find(chname); if (c && c->FindUser(bi)) { - Anope::string want_modes = bi->botchannels[i].substr(0, h); - for (unsigned j = 0; j < want_modes.length(); ++j) + Anope::string want_modes = botchannel.substr(0, h); + for (char want_mode : want_modes) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(want_mode); if (cm == NULL) - cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j])); + cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_mode)); if (cm && cm->type == MODE_STATUS) { MessageSource ms = bi; @@ -81,19 +80,15 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano IRCD->SendBOB(); - for (unsigned i = 0; i < Me->GetLinks().size(); ++i) + for (auto *link : Me->GetLinks()) { - Server *s = Me->GetLinks()[i]; - - if (s->juped) - IRCD->SendServer(s); + if (link->juped) + IRCD->SendServer(link); } /* We make the bots go online */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; - BotInfo *bi = BotInfo::Find(u->GetUID()); if (bi) { @@ -106,22 +101,22 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano bi->introduced = true; } - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) + for (const auto &[_, c] : ChannelList) { - Channel *c = it->second; - if (c->users.empty()) IRCD->SendChannel(c); else - for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit) - IRCD->SendJoin(cit->second->user, c, &cit->second->status); + { + for (const auto &[_, uc] : c->users) + IRCD->SendJoin(uc->user, c, &uc->status); + } - for (Channel::ModeList::const_iterator it2 = c->GetModes().begin(); it2 != c->GetModes().end(); ++it2) + for (const auto &[mode, value] : c->GetModes()) { - ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first); + ChannelMode *cm = ModeManager::FindChannelModeByName(mode); if (!cm || cm->type != MODE_LIST) continue; - ModeManager::StackerAdd(c->WhoSends(), c, cm, true, it2->second); + ModeManager::StackerAdd(c->WhoSends(), c, cm, true, value); } if (!c->topic.empty() && !c->topic_setter.empty()) @@ -139,10 +134,8 @@ Server::~Server() { Log(this, "quit") << "quit from " << (this->uplink ? this->uplink->GetName() : "no uplink") << " for " << this->quit_reason; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; - if (u->server == this) { u->Quit(this->quit_reason); @@ -259,8 +252,8 @@ void Server::Sync(bool sync_links) if (sync_links && !this->links.empty()) { - for (unsigned i = 0, j = this->links.size(); i < j; ++i) - this->links[i]->Sync(true); + for (auto *link : this->links) + link->Sync(true); } bool me = this->GetUplink() && this->GetUplink() == Me; @@ -309,9 +302,11 @@ bool Server::IsULined() const if (this == Me) return true; - for (unsigned i = 0; i < Config->Ulines.size(); ++i) - if (Config->Ulines[i].equals_ci(this->GetName())) + for (const auto &uline : Config->Ulines) + { + if (uline.equals_ci(this->GetName())) return true; + } return false; } @@ -353,8 +348,10 @@ Server *Server::Find(const Anope::string &name, bool name_only) Server* Servers::GetUplink() { - for (unsigned i = 0; Me && i < Me->GetLinks().size(); ++i) - if (!Me->GetLinks()[i]->IsJuped()) - return Me->GetLinks()[i]; + for (auto *link : Me->GetLinks()) + { + if (!link->IsJuped()) + return link; + } return NULL; } diff --git a/src/siphash.cpp b/src/siphash.cpp index c98147131..f4b0b0b62 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 da5057b19..5a992a4a3 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 a7aef0b70..b10bf2f0a 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 e0c978010..0d5f4e005 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 153eadf7f..277ec2d14 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 cecec9f22..d3d843794 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 cc2a93693..1ba88f67e 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..5aa833ea9 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,31 +9,22 @@ 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 add_executable(${EXE} ${SRC}) set_target_properties(${EXE} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}") add_dependencies(${EXE} ${PROGRAM_NAME}) - # 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) - 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) # 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 +35,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 823f99d5e..5a68b01f1 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-2023 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 deleted file mode 100644 index 686627e6f..000000000 --- a/src/tools/anopesmtp.cpp +++ /dev/null @@ -1,535 +0,0 @@ -/* smtp stuff handler for win32. - * - * (C) 2003-2023 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. - * - * Written by Dominick Meglio <codemastr@unrealircd.com> - * *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> -#include <cstdio> -#include <cstdlib> -#include <cstring> -#include <ctime> -#include <cerrno> -#include <iostream> -#include <fstream> - -#ifndef _WIN32 -# include <unistd.h> -# include <netdb.h> -# include <netinet/in.h> -# include <sys/socket.h> -# include <arpa/inet.h> -# include <sys/time.h> -#else -# include <winsock.h> -# define WIN32_LEAN_AND_MEAN -# include <windows.h> -#endif - -#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' - * * sys/types.h - * **/ -# ifndef INADDR_NONE -# define INADDR_NONE (-1) -# endif -#endif - -#ifdef _WIN32 -typedef SOCKET ano_socket_t; -#define ano_sockclose(fd) closesocket(fd) -#define ano_sockread(fd, buf, len) recv(fd, buf, len, 0) -#define ano_sockwrite(fd, buf, len) send(fd, buf, len, 0) -#else -typedef int ano_socket_t; -#define ano_sockclose(fd) close(fd) -#define ano_sockread(fd, buf, len) read(fd, buf, len) -#define ano_sockwrite(fd, buf, len) write(fd, buf, len) -#define SOCKET_ERROR -1 -#endif - -/* Data structures */ -struct smtp_message -{ - std::vector<std::string> smtp_headers; - std::vector<std::string> smtp_body; - std::string from; - std::string to; - ano_socket_t sock; -}; - -int smtp_debug = 0; - -struct smtp_message smail; - -static std::string get_logname(struct tm *tm = NULL) -{ - char timestamp[32]; - - if (!tm) - { - time_t t = time(NULL); - tm = localtime(&t); - } - - strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm); - std::string name = std::string("anopesmtp.") + timestamp; - return name; -} - -/* TimeStamp for Email Header */ -static std::string GetTimeStamp() -{ - char tbuf[256]; - time_t t = time(NULL); - struct tm *tm = gmtime(&t); - - strftime(tbuf, sizeof(tbuf) - 1, "%a, %d %b %Y %H:%M:%S +0000", tm); - - return tbuf; -} - -/* Log stuff to the log file with a datestamp. Note that errno is - * preserved by this routine and log_perror(). - */ - -void alog(const char *fmt, ...) -{ - if (!smtp_debug || !fmt) - return; - - std::fstream file; - file.open(get_logname().c_str(), std::ios_base::out | std::ios_base::app); - - if (!file.is_open()) - return; - - va_list args; - va_start(args, fmt); - - time_t t = time(NULL); - struct tm *tm = localtime(&t); - - char buf[256]; - strftime(buf, sizeof(buf) - 1, "[%b %d %H:%M:%S %Y] ", tm); - file << buf; - vsnprintf(buf, sizeof(buf), fmt, args); - file << buf << std::endl; - va_end(args); - va_end(args); - - file.close(); -} - -/* Remove a trailing \r\n */ -std::string strip(const std::string &buf) -{ - std::string newbuf = buf; - char c = newbuf[newbuf.size() - 1]; - while (c == '\n' || c == '\r') - { - newbuf.erase(newbuf.end() - 1); - c = newbuf[newbuf.size() - 1]; - } - return newbuf; -} - -/* Is the buffer a header? */ -bool smtp_is_header(const std::string &buf) -{ - size_t tmp = buf.find(' '); - - if (tmp == std::string::npos) - return false; - - if (tmp > 0 && buf[tmp - 1] == ':') - return true; - return false; -} - -/* Parse a header into a name and value */ -void smtp_parse_header(const std::string &buf, std::string &header, std::string &value) -{ - std::string newbuf = strip(buf); - - size_t space = newbuf.find(' '); - if (space != std::string::npos) - { - header = newbuf.substr(0, space); - value = newbuf.substr(space + 1); - } - else - { - header = newbuf; - value = ""; - } -} - -/* Have we reached the end of input? */ -bool smtp_is_end(const std::string &buf) -{ - if (buf[0] == '.') - if (buf[1] == '\r' || buf[1] == '\n') - return true; - - return false; -} - -/* Set who the email is to */ -void smtp_set_to(const std::string &to) -{ - smail.to = to; - size_t c = smail.to.rfind('<'); - if (c != std::string::npos && c + 1 < smail.to.size()) - { - smail.to = smail.to.substr(c + 1); - smail.to.erase(smail.to.end() - 1); - } -} - -/* Establish a connection to the SMTP server */ -int smtp_connect(const char *host, unsigned short port) -{ - struct sockaddr_in addr; - - if ((smail.sock = socket(AF_INET, SOCK_STREAM, 0)) == SOCKET_ERROR) - return 0; - - if ((addr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) - { - struct hostent *hent; - if (!(hent = gethostbyname(host))) - return 0; - memcpy(&addr.sin_addr, hent->h_addr, hent->h_length); - } - addr.sin_family = AF_INET; - addr.sin_port = htons(port ? port : 25); - if (connect(smail.sock, reinterpret_cast<struct sockaddr *>(&addr), sizeof(struct sockaddr_in)) == SOCKET_ERROR) - { - ano_sockclose(smail.sock); - return 0; - } - - return 1; -} - -/* Send a line of text */ -int smtp_send(const char *text) -{ - int result = ano_sockwrite(smail.sock, text, strlen(text)); - - alog("SMTP: sent %s",text); - - if (result == SOCKET_ERROR) - ano_sockclose(smail.sock); - - return result; -} - -/* Read a line of text */ -int smtp_read(char *buf, int len) -{ - int result; - - memset(buf, 0, len); - result = ano_sockread(smail.sock, buf, len); - - if (result == SOCKET_ERROR) - ano_sockclose(smail.sock); - - return result; -} - -/* Retrieve a response code */ -int smtp_get_code(const std::string &text) -{ - size_t tmp = text.find(' '); - - if (tmp == std::string::npos) - return 0; - - return atol(text.substr(0, tmp).c_str()); -} - -/* Send the email */ -int smtp_send_email() -{ - char buf[1024]; - if (!smtp_read(buf, 1024)) - { - alog("SMTP: error reading buffer"); - return 0; - } - - int code = smtp_get_code(buf); - if (code != 220) - { - alog("SMTP: error expected code 220 got %d",code); - return 0; - } - - if (!smtp_send("HELO anope\r\n")) - { - alog("SMTP: error writing to socket"); - return 0; - } - - if (!smtp_read(buf, 1024)) - { - alog("SMTP: error reading buffer"); - return 0; - } - - code = smtp_get_code(buf); - if (code != 250) - { - alog("SMTP: error expected code 250 got %d",code); - return 0; - } - - strcpy(buf, "MAIL FROM: <"); - strcat(buf, smail.from.c_str()); - strcat(buf, ">\r\n"); - - if (!smtp_send(buf)) - { - alog("SMTP: error writing to socket"); - return 0; - } - - if (!smtp_read(buf, 1024)) - { - alog("SMTP: error reading buffer"); - return 0; - } - - code = smtp_get_code(buf); - if (code != 250) - return 0; - - strcpy(buf, "RCPT TO: <"); - strcat(buf, smail.to.c_str()); - strcat(buf, ">\r\n"); - - if (!smtp_send(buf)) - { - alog("SMTP: error writing to socket"); - return 0; - } - - if (!smtp_read(buf, 1024)) - { - alog("SMTP: error reading buffer"); - return 0; - } - - code = smtp_get_code(buf); - if (smtp_get_code(buf) != 250) - { - alog("SMTP: error expected code 250 got %d",code); - return 0; - } - - if (!smtp_send("DATA\r\n")) - { - alog("SMTP: error writing to socket"); - return 0; - } - - if (!smtp_read(buf, 1024)) - { - alog("SMTP: error reading buffer"); - return 0; - } - - code = smtp_get_code(buf); - if (code != 354) - { - alog("SMTP: error expected code 354 got %d",code); - return 0; - } - - for (std::vector<std::string>::const_iterator it = smail.smtp_headers.begin(), it_end = smail.smtp_headers.end(); it != it_end; ++it) - if (!smtp_send(it->c_str())) - { - alog("SMTP: error writing to socket"); - return 0; - } - - if (!smtp_send("\r\n")) - { - alog("SMTP: error writing to socket"); - return 0; - } - - bool skip_done = false; - for (std::vector<std::string>::const_iterator it = smail.smtp_body.begin(), it_end = smail.smtp_body.end(); it != it_end; ++it) - if (skip_done) - { - if (!smtp_send(it->c_str())) - { - alog("SMTP: error writing to socket"); - return 0; - } - } - else - skip_done = true; - - if (!smtp_send("\r\n.\r\n")) - { - alog("SMTP: error writing to socket"); - return 0; - } - - if (!smtp_read(buf, 1024)) - { - alog("SMTP: error reading buffer"); - return 0; - } - - code = smtp_get_code(buf); - if (code != 250) - { - alog("SMTP: error expected code 250 got %d",code); - return 0; - } - - return 1; -} - -void smtp_disconnect() -{ - char buf[1024]; - - if (!smtp_send("QUIT\r\n")) - { - alog("SMTP: error writing to socket"); - } - - if (!smtp_read(buf, 1024)) - { - alog("SMTP: error reading buffer"); - } - - int code = smtp_get_code(buf); - if (code != 221) - { - alog("SMTP: error expected code 221 got %d",code); - } - - ano_sockclose(smail.sock); -} - -int main(int argc, char *argv[]) -{ - /* Win32 stuff */ -#ifdef _WIN32 - WSADATA wsa; -#endif - - if (argc == 1) - return 0; - - if (argc == 3 && !strcmp(argv[2], "--debug")) - smtp_debug = 1; - - char *server = strtok(argv[1], ":"), *aport; - short port; - if ((aport = strtok(NULL, ""))) - port = atoi(aport); - else - port = 25; - - if (!server) - { - alog("No Server"); - /* Bad, bad, bad. This was a return from main with no value! -GD */ - return 0; - } - else - alog("SMTP: server %s port %d",server,port); - - /* The WSAStartup function initiates use of WS2_32.DLL by a process. */ - /* guessing we can skip it under *nix */ -#ifdef _WIN32 - if (WSAStartup(MAKEWORD(1, 1), &wsa)) - return 0; -#endif - - char buf[8192]; - bool headers_done = false; - /* Read the message and parse it */ - while (fgets(buf, 8192, stdin)) - { - if (smtp_is_header(buf) && !headers_done) - { - smail.smtp_headers.push_back(strip(buf) + "\r\n"); - std::string header, value; - smtp_parse_header(buf, header, value); - if (header == "From:") - { - alog("SMTP: from: %s", value.c_str()); - smail.from = value; - } - else if (header == "To:") - { - alog("SMTP: to: %s", value.c_str()); - smtp_set_to(value); - } - else if (smtp_is_end(buf)) - break; - else - { - smail.smtp_headers.push_back("Date: " + GetTimeStamp() + "\r\n"); - headers_done = true; - smail.smtp_body.push_back(strip(buf) + "\r\n"); - } - } - else - smail.smtp_body.push_back(strip(buf) + "\r\n"); - } - - if (!smtp_connect(server, port)) - { - alog("SMTP: failed to connect to %s:%d", server, port); - return 0; - } - if (!smtp_send_email()) - { - alog("SMTP: error during sending of mail"); - return 0; - } - smtp_disconnect(); - - return 1; -} diff --git a/src/uplink.cpp b/src/uplink.cpp index b0ce92b33..67599c2d6 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -22,7 +22,7 @@ class ReconnectTimer : public Timer public: ReconnectTimer(int wait) : Timer(wait) { } - void Tick(time_t) + void Tick(time_t) override { try { @@ -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; @@ -79,10 +79,8 @@ UplinkSocket::~UplinkSocket() { FOREACH_MOD(OnServerDisconnect, ()); - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; - if (u->server == Me) { /* Don't use quitmsg here, it may contain information you don't want people to see */ diff --git a/src/users.cpp b/src/users.cpp index 09529bb5f..ce22828a9 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()) @@ -463,9 +468,8 @@ bool User::IsServicesOper() bool match = false; Anope::string match_host = this->GetIdent() + "@" + this->host; Anope::string match_ip = this->GetIdent() + "@" + this->ip.addr(); - for (unsigned i = 0; i < this->nc->o->hosts.size(); ++i) + for (const auto &userhost : this->nc->o->hosts) { - const Anope::string &userhost = this->nc->o->hosts[i]; if (Anope::Match(match_host, userhost) || Anope::Match(match_ip, userhost)) { match = true; @@ -624,11 +628,11 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...) spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0, end = modebuf.length(); i < end; ++i) + for (auto mode : modebuf) { UserMode *um; - switch (modebuf[i]) + switch (mode) { case '+': add = 1; @@ -639,7 +643,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...) default: if (add == -1) continue; - um = ModeManager::FindUserModeByChar(modebuf[i]); + um = ModeManager::FindUserModeByChar(mode); if (!um) continue; } @@ -671,11 +675,11 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ... spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0, end = modebuf.length(); i < end; ++i) + for (auto mode : modebuf) { UserMode *um; - switch (modebuf[i]) + switch (mode) { case '+': add = 1; @@ -686,7 +690,7 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ... default: if (add == -1) continue; - um = ModeManager::FindUserModeByChar(modebuf[i]); + um = ModeManager::FindUserModeByChar(mode); if (!um) continue; } @@ -707,16 +711,16 @@ Anope::string User::GetModes() const { Anope::string m, params; - for (ModeList::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) + for (const auto &[mode, value] : this->modes) { - UserMode *um = ModeManager::FindUserModeByName(it->first); + UserMode *um = ModeManager::FindUserModeByName(mode); if (um == NULL) continue; m += um->mchar; - if (!it->second.empty()) - params += " " + it->second; + if (!value.empty()) + params += " " + value; } return m + params; @@ -847,7 +851,7 @@ User* User::Find(const Anope::string &name, bool nick_only) void User::QuitUsers() { - for (std::list<User *>::iterator it = quitting_users.begin(), it_end = quitting_users.end(); it != it_end; ++it) - delete *it; + for (const auto *quitting_user : quitting_users) + delete quitting_user; quitting_users.clear(); } diff --git a/src/version.sh b/src/version.sh index c4597b675..c79f66a2f 100644 --- a/src/version.sh +++ b/src/version.sh @@ -1,6 +1,6 @@ #!/bin/sh VERSION_MAJOR=2 -VERSION_MINOR=0 -VERSION_PATCH=15 +VERSION_MINOR=1 +VERSION_PATCH=0 VERSION_EXTRA="-git" diff --git a/src/win32/anope_windows.h b/src/win32/anope_windows.h index 53cb91115..691f731d0 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 a3e731a5f..000000000 --- a/src/win32/dir/dir.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* POSIX emulation layer for Windows. - * - * (C) 2008-2023 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 80af8dd8d..000000000 --- a/src/win32/dir/dir.h +++ /dev/null @@ -1,27 +0,0 @@ -/* POSIX emulation layer for Windows. - * - * (C) 2008-2023 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 864546b94..b14023779 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 3a6ea2f3c..6d63d748f 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 e86c22084..1e39e9840 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; @@ -224,10 +224,8 @@ void XLineManager::UnregisterXLineManager(XLineManager *xlm) void XLineManager::CheckAll(User *u) { - for (std::list<XLineManager *>::iterator it = XLineManagers.begin(), it_end = XLineManagers.end(); it != it_end; ++it) + for (auto *xlm : XLineManagers) { - XLineManager *xlm = *it; - if (xlm->CheckAllXLines(u)) break; } @@ -288,7 +286,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; } @@ -361,9 +359,8 @@ void XLineManager::Clear() std::vector<XLine *> xl; this->xlines->swap(xl); - for (unsigned i = 0; i < xl.size(); ++i) + for (auto *x : xl) { - XLine *x = xl[i]; if (!x->id.empty()) XLinesByUID->erase(x->id); delete x; @@ -427,10 +424,8 @@ XLine* XLineManager::HasEntry(const Anope::string &mask) it->second->QueueUpdate(); return it->second; } - for (unsigned i = 0, end = this->xlines->size(); i < end; ++i) + for (auto *x : *this->xlines) { - XLine *x = this->xlines->at(i); - if (x->mask.equals_ci(mask)) { x->QueueUpdate(); |