diff options
| author | Adam <Adam@anope.org> | 2015-10-27 13:21:24 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2015-10-27 13:21:24 -0400 |
| commit | 162fdbe5815bbdf187f549fefac94ff476d72e62 (patch) | |
| tree | 1c58968fd29dd90ef8ab6dc0f3013d88b313ce4e /modules | |
| parent | c6a92296d4175a2d2276c2d5a46894af3d9085f4 (diff) | |
Beginning of new module dependency stuff, seems to compile and link. Move some of the madness in chanserv.h to the module.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | modules/commands/cs_access.cpp | 19 | ||||
| -rw-r--r-- | modules/commands/cs_flags.cpp | 17 | ||||
| -rw-r--r-- | modules/commands/cs_xop.cpp | 17 | ||||
| -rw-r--r-- | modules/pseudoclients/chanserv/chanaccess.cpp | 127 | ||||
| -rw-r--r-- | modules/pseudoclients/chanserv/chanaccess.h | 30 | ||||
| -rw-r--r-- | modules/pseudoclients/chanserv/chanaccesstype.h | 21 | ||||
| -rw-r--r-- | modules/pseudoclients/chanserv/channel.h | 2 | ||||
| -rw-r--r-- | modules/pseudoclients/chanserv/chanserv.cpp | 52 |
9 files changed, 228 insertions, 67 deletions
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 9078f2654..522ceb674 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -18,7 +18,7 @@ macro(build_modules SRC) file(RELATIVE_PATH FNAME ${SRC} ${MODULE_SRC}) # Convert the real source file extension to have a .so extension - string(REGEX REPLACE "\\.cpp$" ".so" SO ${FNAME}) + string(REGEX REPLACE "\\.cpp$" "" SO ${FNAME}) # Reset linker flags set(TEMP_LDFLAGS) @@ -40,7 +40,7 @@ macro(build_modules SRC) else(WIN32) set(WIN32_NO_LIBS) endif(WIN32) - set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) + set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX ".so" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) add_dependencies(${SO} ${PROGRAM_NAME}) if(GETTEXT_FOUND) add_dependencies(${SO} module_language) @@ -55,6 +55,7 @@ macro(build_modules SRC) target_link_libraries(${SO} ${PROGRAM_NAME}) endif(APPLE) endif(WIN32) + calculate_dependencies(${MODULE_SRC}) # Set the module to be installed to the module directory under the data directory install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules) endif(CPP) @@ -68,7 +69,7 @@ macro(build_subdir) list(SORT MODULES_SUBDIR_SRCS) GET_FILENAME_COMPONENT(FOLDER_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - set(SO "${FOLDER_NAME}.so") + set(SO "${FOLDER_NAME}") # 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(${MODULES_SUBDIR_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") @@ -81,6 +82,7 @@ macro(build_subdir) set(TEMP_DEPENDENCIES) # Calculate the library dependencies for the given source file calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES) + calculate_dependencies(${SRC}) # Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append if(TEMP_DEPENDENCIES) @@ -107,7 +109,7 @@ macro(build_subdir) # Generate the module and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand add_library(${SO} MODULE ${MODULES_SUBDIR_SRCS}) - set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) + set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" SUFFIX ".so" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) add_dependencies(${SO} ${PROGRAM_NAME}) if(GETTEXT_FOUND) add_dependencies(${SO} module_language) diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 6f1f0f1f0..982d5763f 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -9,15 +9,19 @@ * Based on the original code of Services by Andy Church. */ +/* Dependencies: chanserv */ + #include "module.h" #include "modules/chanserv.h" #include "modules/cs_access.h" +#include "../pseudoclients/chanserv/chanaccess.h" +#include "../pseudoclients/chanserv/chanaccesstype.h" -class AccessChanAccess : public ChanServ::ChanAccess +class AccessChanAccess : public ChanAccessImpl { public: - AccessChanAccess(Serialize::TypeBase *type) : ChanServ::ChanAccess(type) { } - AccessChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::ChanAccess(type, id) { } + AccessChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { } + AccessChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { } int GetLevel(); void SetLevel(const int &); @@ -43,6 +47,7 @@ class AccessChanAccess : public ChanServ::ChanAccess } } +#if 0 bool operator>(ChanServ::ChanAccess &other) override { if (this->GetSerializableType() != other.GetSerializableType()) @@ -58,9 +63,10 @@ class AccessChanAccess : public ChanServ::ChanAccess else return this->GetLevel() < anope_dynamic_static_cast<AccessChanAccess *>(&other)->GetLevel(); } +#endif }; -class AccessChanAccessType : public Serialize::Type<AccessChanAccess, ChanServ::ChanAccessType> +class AccessChanAccessType : public Serialize::Type<AccessChanAccess, ChanAccessType> { public: Serialize::Field<AccessChanAccess, int> level; @@ -920,4 +926,9 @@ class CSAccess : public Module } }; +template<> void ModuleInfo<CSAccess>(ModuleDef *def) +{ + def->Depends("chanserv"); +} + MODULE_INIT(CSAccess) diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index c8ef11796..88cc501ac 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -9,16 +9,20 @@ * Based on the original code of Services by Andy Church. */ +/* Dependencies: chanserv */ + #include "module.h" #include "modules/cs_access.h" +#include "../pseudoclients/chanserv/chanaccess.h" +#include "../pseudoclients/chanserv/chanaccesstype.h" static std::map<Anope::string, char> defaultFlags; -class FlagsChanAccess : public ChanServ::ChanAccess +class FlagsChanAccess : public ChanAccessImpl { public: - FlagsChanAccess(Serialize::TypeBase *type) : ChanServ::ChanAccess(type) { } - FlagsChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::ChanAccess(type, id) { } + FlagsChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { } + FlagsChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { } Anope::string GetFlags(); void SetFlags(const Anope::string &); @@ -57,7 +61,7 @@ class FlagsChanAccess : public ChanServ::ChanAccess } }; -class FlagsChanAccessType : public Serialize::Type<FlagsChanAccess, ChanServ::ChanAccessType> +class FlagsChanAccessType : public Serialize::Type<FlagsChanAccess, ChanAccessType> { public: Serialize::Field<FlagsChanAccess, Anope::string> flags; @@ -518,4 +522,9 @@ class CSFlags : public Module } }; +template<> void ModuleInfo<CSFlags>(ModuleDef *def) +{ + def->Depends("chanserv"); +} + MODULE_INIT(CSFlags) diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 0de467f4f..891ac77e7 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -9,8 +9,12 @@ * Based on the original code of Services by Andy Church. */ +/* Dependencies: chanserv */ + #include "module.h" #include "modules/cs_access.h" +#include "../pseudoclients/chanserv/chanaccess.h" +#include "../pseudoclients/chanserv/chanaccesstype.h" namespace { @@ -18,11 +22,11 @@ namespace std::map<Anope::string, std::vector<Anope::string> > permissions; } -class XOPChanAccess : public ChanServ::ChanAccess +class XOPChanAccess : public ChanAccessImpl { public: - XOPChanAccess(Serialize::TypeBase *type) : ChanServ::ChanAccess(type) { } - XOPChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::ChanAccess(type, id) { } + XOPChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { } + XOPChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { } Anope::string GetType(); void SetType(const Anope::string &); @@ -81,7 +85,7 @@ class XOPChanAccess : public ChanServ::ChanAccess }; -class XOPChanAccessType : public Serialize::Type<XOPChanAccess, ChanServ::ChanAccessType> +class XOPChanAccessType : public Serialize::Type<XOPChanAccess, ChanAccessType> { public: Serialize::Field<XOPChanAccess, Anope::string> type; @@ -648,4 +652,9 @@ class CSXOP : public Module } }; +template<> void ModuleInfo<CSXOP>(ModuleDef *def) +{ + def->Depends("chanserv"); +} + MODULE_INIT(CSXOP) diff --git a/modules/pseudoclients/chanserv/chanaccess.cpp b/modules/pseudoclients/chanserv/chanaccess.cpp new file mode 100644 index 000000000..1601260c2 --- /dev/null +++ b/modules/pseudoclients/chanserv/chanaccess.cpp @@ -0,0 +1,127 @@ +#include "module.h" +#include "chanaccess.h" +#include "chanaccesstype.h" + +ChanServ::Channel *ChanAccessImpl::GetChannel() +{ + return Get(&ChanAccessType::ci); +} + +void ChanAccessImpl::SetChannel(ChanServ::Channel *ci) +{ + Object::Set(&ChanAccessType::ci, ci); +} + +Anope::string ChanAccessImpl::GetCreator() +{ + return Get(&ChanAccessType::creator); +} + +void ChanAccessImpl::SetCreator(const Anope::string &c) +{ + Object::Set(&ChanAccessType::creator, c); +} + +time_t ChanAccessImpl::GetLastSeen() +{ + return Get(&ChanAccessType::last_seen); +} + +void ChanAccessImpl::SetLastSeen(const time_t &t) +{ + Object::Set(&ChanAccessType::last_seen, t); +} + +time_t ChanAccessImpl::GetCreated() +{ + return Get(&ChanAccessType::created); +} + +void ChanAccessImpl::SetCreated(const time_t &t) +{ + Object::Set(&ChanAccessType::created, t); +} + +Anope::string ChanAccessImpl::GetMask() +{ + return Get(&ChanAccessType::mask); +} + +void ChanAccessImpl::SetMask(const Anope::string &n) +{ + Object::Set(&ChanAccessType::mask, n); +} + +Serialize::Object *ChanAccessImpl::GetObj() +{ + return Get(&ChanAccessType::obj); +} + +void ChanAccessImpl::SetObj(Serialize::Object *o) +{ + Object::Set(&ChanAccessType::obj, o); +} + +Anope::string ChanAccessImpl::Mask() +{ + if (NickServ::Account *acc = GetAccount()) + return acc->GetDisplay(); + + return GetMask(); +} + +NickServ::Account *ChanAccessImpl::GetAccount() +{ + if (!GetObj() || GetObj()->GetSerializableType() != NickServ::account) + return nullptr; + + return anope_dynamic_static_cast<NickServ::Account *>(GetObj()); +} + +bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p) +{ + if (this->GetAccount()) + return this->GetAccount() == acc; + + if (u) + { + bool is_mask = this->Mask().find_first_of("!@?*") != Anope::string::npos; + if (is_mask && Anope::Match(u->nick, this->Mask())) + return true; + else if (Anope::Match(u->GetDisplayedMask(), this->Mask())) + return true; + } + + if (acc) + for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>(NickServ::nick)) + if (Anope::Match(na->GetNick(), this->Mask())) + return true; + + if (IRCD->IsChannelValid(this->Mask())) + { + ChanServ::Channel *tci = ChanServ::Find(this->Mask()); + if (tci) + { + for (unsigned i = 0; i < tci->GetAccessCount(); ++i) + { + ChanServ::ChanAccess *a = tci->GetAccess(i); + std::pair<ChanServ::ChanAccess *, ChanServ::ChanAccess *> pair = std::make_pair(this, a); + + std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(this); + for (; range.first != range.second; ++range.first) + if (range.first->first == pair.first && range.first->second == pair.second) + goto cont; + + p.first.insert(pair); + if (a->Matches(u, acc, p)) + p.second.insert(pair); + + cont:; + } + + return p.second.count(this) > 0; + } + } + + return false; +} diff --git a/modules/pseudoclients/chanserv/chanaccess.h b/modules/pseudoclients/chanserv/chanaccess.h new file mode 100644 index 000000000..bb65f79c5 --- /dev/null +++ b/modules/pseudoclients/chanserv/chanaccess.h @@ -0,0 +1,30 @@ + +class ChanAccessImpl : public ChanServ::ChanAccess +{ + public: + ChanAccessImpl(Serialize::TypeBase *type) : ChanServ::ChanAccess(type) { } + ChanAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::ChanAccess(type, id) { } + + ChanServ::Channel *GetChannel() override; + void SetChannel(ChanServ::Channel *ci) override; + + Anope::string GetCreator() override; + void SetCreator(const Anope::string &c) override; + + time_t GetLastSeen() override; + void SetLastSeen(const time_t &t) override; + + time_t GetCreated() override; + void SetCreated(const time_t &t) override; + + Anope::string GetMask() override; + void SetMask(const Anope::string &) override; + + Serialize::Object *GetObj() override; + void SetObj(Serialize::Object *) override; + + Anope::string Mask() override; + NickServ::Account *GetAccount() override; + + bool Matches(const User *u, NickServ::Account *acc, Path &p) override; +}; diff --git a/modules/pseudoclients/chanserv/chanaccesstype.h b/modules/pseudoclients/chanserv/chanaccesstype.h new file mode 100644 index 000000000..ca8dc1b79 --- /dev/null +++ b/modules/pseudoclients/chanserv/chanaccesstype.h @@ -0,0 +1,21 @@ + +class ChanAccessType : public Serialize::AbstractType +{ + public: + Serialize::ObjectField<ChanServ::ChanAccess, ChanServ::Channel *> ci; + Serialize::Field<ChanServ::ChanAccess, Anope::string> mask; + Serialize::ObjectField<ChanServ::ChanAccess, Serialize::Object *> obj; + Serialize::Field<ChanServ::ChanAccess, Anope::string> creator; + Serialize::Field<ChanServ::ChanAccess, time_t> last_seen; + Serialize::Field<ChanServ::ChanAccess, time_t> created; + + ChanAccessType(Module *me, const Anope::string &name) : Serialize::AbstractType(me, name) + , ci(this, "ci", true) + , mask(this, "mask") + , obj(this, "obj", true) + , creator(this, "creator") + , last_seen(this, "last_seen") + , created(this, "created") + { + } +}; diff --git a/modules/pseudoclients/chanserv/channel.h b/modules/pseudoclients/chanserv/channel.h index 995972ece..18a4be5d6 100644 --- a/modules/pseudoclients/chanserv/channel.h +++ b/modules/pseudoclients/chanserv/channel.h @@ -3,11 +3,9 @@ class ChannelImpl : public ChanServ::Channel { public: - //using ChanServ::Channel::Channel; ChannelImpl(Serialize::TypeBase *type) : ChanServ::Channel(type) { } ChannelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Channel(type, id) { } ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname); - /*ChannelImpl(const ChanServ::Channel &ci);*/ ~ChannelImpl(); void Delete() override; diff --git a/modules/pseudoclients/chanserv/chanserv.cpp b/modules/pseudoclients/chanserv/chanserv.cpp index 5dd83188f..420051252 100644 --- a/modules/pseudoclients/chanserv/chanserv.cpp +++ b/modules/pseudoclients/chanserv/chanserv.cpp @@ -19,6 +19,8 @@ #include "channeltype.h" #include "leveltype.h" #include "modetype.h" +#include "chanaccesstype.h" +#include "chanaccess.h" class ChanServCore : public Module , public ChanServ::ChanServService @@ -52,7 +54,7 @@ class ChanServCore : public Module std::vector<ChanServ::Privilege> Privileges; ChanServ::registered_channel_map registered_channels; ChannelType channel_type; - ChanServ::ChanAccessType chanaccess_type; + ChanAccessType chanaccess_type; LevelType level_type; CSModeType mode_type; @@ -189,54 +191,6 @@ class ChanServCore : public Module Privileges.clear(); } - bool Matches(ChanServ::ChanAccess *access, const User *u, NickServ::Account *acc, ChanServ::ChanAccess::Path &p) override - { - if (access->GetAccount()) - return access->GetAccount() == acc; - - if (u) - { - bool is_mask = access->Mask().find_first_of("!@?*") != Anope::string::npos; - if (is_mask && Anope::Match(u->nick, access->Mask())) - return true; - else if (Anope::Match(u->GetDisplayedMask(), access->Mask())) - return true; - } - - if (acc) - for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>(NickServ::nick)) - if (Anope::Match(na->GetNick(), access->Mask())) - return true; - - if (IRCD->IsChannelValid(access->Mask())) - { - ChanServ::Channel *tci = Find(access->Mask()); - if (tci) - { - for (unsigned i = 0; i < tci->GetAccessCount(); ++i) - { - ChanServ::ChanAccess *a = tci->GetAccess(i); - std::pair<ChanServ::ChanAccess *, ChanServ::ChanAccess *> pair = std::make_pair(access, a); - - std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(access); - for (; range.first != range.second; ++range.first) - if (range.first->first == pair.first && range.first->second == pair.second) - goto cont; - - p.first.insert(pair); - if (a->Matches(u, acc, p)) - p.second.insert(pair); - - cont:; - } - - return p.second.count(access) > 0; - } - } - - return false; - } - void OnReload(Configuration::Conf *conf) override { const Anope::string &channick = conf->GetModule(this)->Get<Anope::string>("client"); |
