diff options
author | Adam <Adam@anope.org> | 2011-04-28 22:44:34 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-05-16 04:09:32 -0400 |
commit | 583954d3a1db658281a9afb7b7dd6773726c8c11 (patch) | |
tree | 6a00865d5738c6d0bc42efb35f3f468c5876eb3e /src | |
parent | 8fb1604f649bec6f356770daf5df6bb8ab811bbf (diff) |
Use module type to determine what type each module is instead of its location in the configuration file.
Diffstat (limited to 'src')
-rw-r--r-- | src/base.cpp | 9 | ||||
-rw-r--r-- | src/bots.cpp | 2 | ||||
-rw-r--r-- | src/config.cpp | 8 | ||||
-rw-r--r-- | src/encrypt.cpp | 31 | ||||
-rw-r--r-- | src/init.cpp | 27 | ||||
-rw-r--r-- | src/messages.cpp | 4 | ||||
-rw-r--r-- | src/module.cpp | 23 | ||||
-rw-r--r-- | src/modulemanager.cpp | 64 | ||||
-rw-r--r-- | src/modules.cpp | 75 | ||||
-rw-r--r-- | src/protocol.cpp | 3 | ||||
-rw-r--r-- | src/servers.cpp | 141 |
11 files changed, 119 insertions, 268 deletions
diff --git a/src/base.cpp b/src/base.cpp index 537770bcd..82c9ae8b4 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -11,8 +11,6 @@ Base::~Base() { (*it)->Invalidate(); } - - FOREACH_MOD(I_OnObjectDestroy, OnObjectDestroy(this)); } void Base::AddReference(dynamic_reference_base *r) @@ -25,3 +23,10 @@ void Base::DelReference(dynamic_reference_base *r) this->References.erase(r); } +void Base::operator delete(void *ptr) +{ + Base *b = static_cast<Base *>(ptr); + FOREACH_MOD(I_OnDeleteObject, OnDeleteObject(b)); + ::operator delete(b); +} + diff --git a/src/bots.cpp b/src/bots.cpp index c67456ba4..51be95db9 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -39,7 +39,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A { LogInfo *l = Config->LogInfos[i]; - if (!ircd->join2msg && !l->Inhabit) + if (ircd && !ircd->join2msg && !l->Inhabit) continue; for (std::list<Anope::string>::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit) diff --git a/src/config.cpp b/src/config.cpp index 0ce28d34e..288e33685 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -18,8 +18,6 @@ ConfigurationFile services_conf("services.conf", false); // Services configurati ServerConfig *Config = NULL; static Anope::string Modules; -static Anope::string EncModules; -static Anope::string DBModules; static Anope::string UlineServers; static Anope::string OSNotifications; static Anope::string BSDefaults; @@ -200,8 +198,6 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C /* Modules Autoload building... :P */ this->ModulesAutoLoad = BuildStringList(Modules); - this->EncModuleList = BuildStringList(EncModules); - this->DBModuleList = BuildStringList(DBModules); if (this->LimitSessions) { @@ -1003,7 +999,6 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"serverinfo", "name", "", new ValueContainerString(&conf->ServerName), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty}, {"serverinfo", "description", "", new ValueContainerString(&conf->ServerDesc), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"serverinfo", "localhost", "", new ValueContainerString(&conf->LocalHost), DT_HOSTNAME | DT_NORELOAD, NoValidation}, - {"serverinfo", "type", "", new ValueContainerString(&conf->IRCDModule), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"serverinfo", "id", "", new ValueContainerString(&conf->Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation}, {"serverinfo", "ident", "", new ValueContainerString(&conf->ServiceUser), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"serverinfo", "hostname", "", new ValueContainerString(&conf->ServiceHost), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, @@ -1013,10 +1008,7 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"networkinfo", "nicklen", "31", new ValueContainerUInt(&conf->NickLen), DT_UINTEGER | DT_NORELOAD, ValidateNickLen}, {"networkinfo", "userlen", "10", new ValueContainerUInt(&conf->UserLen), DT_UINTEGER | DT_NORELOAD, NoValidation}, {"networkinfo", "hostlen", "64", new ValueContainerUInt(&conf->HostLen), DT_UINTEGER | DT_NORELOAD, NoValidation}, - {"options", "encryption", "", new ValueContainerString(&EncModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"options", "passlen", "32", new ValueContainerUInt(&conf->PassLen), DT_UINTEGER | DT_NORELOAD, NoValidation}, - {"options", "database", "", new ValueContainerString(&DBModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, - {"options", "socketengine", "", new ValueContainerString(&conf->SocketEngine), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"options", "userkey1", "0", new ValueContainerLUInt(&conf->UserKey1), DT_LUINTEGER, NoValidation}, {"options", "userkey2", "0", new ValueContainerLUInt(&conf->UserKey2), DT_LUINTEGER, NoValidation}, {"options", "userkey3", "0", new ValueContainerLUInt(&conf->UserKey3), DT_LUINTEGER, NoValidation}, diff --git a/src/encrypt.cpp b/src/encrypt.cpp index 2414bf7bc..0f3bd3d79 100644 --- a/src/encrypt.cpp +++ b/src/encrypt.cpp @@ -14,26 +14,22 @@ /******************************************************************************/ -/** - * Encrypt string `src' of length `len', placing the result in buffer - * `dest' of size `size'. Returns 0 on success, -1 on error. - **/ -int enc_encrypt(const Anope::string &src, Anope::string &dest) +/** Encrypt the string src into dest + * @param src The source string + * @param dest The destination strnig + */ +void enc_encrypt(const Anope::string &src, Anope::string &dest) { EventReturn MOD_RESULT; FOREACH_RESULT(I_OnEncrypt, OnEncrypt(src, dest)); - if (MOD_RESULT == EVENT_ALLOW) - return 0; - return -1; } -/** - * Decrypt encrypted string `src' into buffer `dest' of length `len'. - * Returns 1 (not 0) on success, -1 if the encryption algorithm does not - * allow decryption, and -1 if another failure occurred (e.g. destination - * buffer too small). - **/ -int enc_decrypt(const Anope::string &src, Anope::string &dest) +/** Decrypt the encrypted string src into dest + * @param src The encrypted string + * @param desc The destination string + * @return true on success + */ +bool enc_decrypt(const Anope::string &src, Anope::string &dest) { size_t pos = src.find(':'); if (pos == Anope::string::npos) @@ -46,7 +42,8 @@ int enc_decrypt(const Anope::string &src, Anope::string &dest) EventReturn MOD_RESULT; FOREACH_RESULT(I_OnDecrypt, OnDecrypt(hashm, src, dest)); if (MOD_RESULT == EVENT_ALLOW) - return 1; - return -1; + return true; + + return false; } diff --git a/src/init.cpp b/src/init.cpp index 039067191..ad95e4d4b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -334,19 +334,9 @@ void Init(int ac, char **av) /* Initialize the socket engine */ SocketEngine::Init(); - /* Add IRCD Protocol Module; exit if there are errors */ - if (protocol_module_init()) - throw FatalException("Unable to load protocol module"); - /* Create me */ Me = new Server(NULL, Config->ServerName, 0, Config->ServerDesc, Config->Numeric); - /* Add Encryption Modules */ - ModuleManager::LoadModuleList(Config->EncModuleList); - - /* Add Database Modules */ - ModuleManager::LoadModuleList(Config->DBModuleList); - DNSEngine = new DNSManager(); #ifndef _WIN32 @@ -385,7 +375,7 @@ void Init(int ac, char **av) write_pidfile(); /* Announce ourselves to the logfile. */ - Log() << "Anope " << Anope::Version() << " (ircd protocol: " << ircd->name << ") starting up" << (debug || readonly ? " (options:" : "") << (debug ? " debug" : "") << (readonly ? " readonly" : "") << (debug || readonly ? ")" : ""); + Log() << "Anope " << Anope::Version() << " starting up" << (debug || readonly ? " (options:" : "") << (debug ? " debug" : "") << (readonly ? " readonly" : "") << (debug || readonly ? ")" : ""); start_time = Anope::CurTime; /* Set signal handlers. Catch certain signals to let us do things or @@ -401,14 +391,21 @@ void Init(int ac, char **av) Log(LOG_DEBUG) << "Loading Languages..."; InitLanguages(); - /* load any custom modules */ - if (!nothird) - ModuleManager::LoadModuleList(Config->ModulesAutoLoad); - /* Initialize random number generator */ rand_init(); add_entropy_userkeys(); + /* load modules */ + ModuleManager::LoadModuleList(Config->ModulesAutoLoad); + + Module *protocol = ModuleManager::FindFirstOf(PROTOCOL); + if (protocol == NULL) + throw FatalException("You must load a protocol module!"); + else if (ModuleManager::FindFirstOf(ENCRYPTION) == NULL) + throw FatalException("You must load at least one encryption module"); + + Log() << "Using IRCd protocol " << protocol->name; + /* Load up databases */ Log() << "Loading databases..."; EventReturn MOD_RESULT; diff --git a/src/messages.cpp b/src/messages.cpp index 192859e6f..f8d893eca 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -83,8 +83,8 @@ bool OnTime(const Anope::string &source, const std::vector<Anope::string> &) bool OnVersion(const Anope::string &source, const std::vector<Anope::string> &) { - if (!source.empty()) - ircdproto->SendNumeric(Config->ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, Config->EncModuleList.begin()->c_str(), Anope::VersionBuildString().c_str()); + Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); + ircdproto->SendNumeric(Config->ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, enc ? enc->name.c_str() : "unknown", Anope::VersionBuildString().c_str()); return true; } diff --git a/src/module.cpp b/src/module.cpp index eadfbf4d1..929984e2e 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -12,21 +12,19 @@ # include <libintl.h> #endif -Module::Module(const Anope::string &mname, const Anope::string &creator) +Module::Module(const Anope::string &modname, const Anope::string &, ModType modtype) : name(modname), type(modtype) { - this->name = mname; /* Our name */ - this->type = THIRD; this->handle = NULL; - this->permanent = false; - - if (FindModule(this->name)) - throw CoreException("Module already exists!"); - this->created = Anope::CurTime; - this->SetVersion(Anope::Version()); + if (ModuleManager::FindModule(this->name)) + throw CoreException("Module already exists!"); + + if (nothird && modtype == THIRD) + throw ModuleException("Third party modules may not be loaded"); + Modules.push_back(this); #if GETTEXT_FOUND @@ -37,6 +35,8 @@ Module::Module(const Anope::string &mname, const Anope::string &creator) Module::~Module() { + if (DNSEngine) + DNSEngine->Cleanup(this); /* Detach all event hooks for this module */ ModuleManager::DetachAll(this); /* Clear any active callbacks this module has */ @@ -47,11 +47,6 @@ Module::~Module() Modules.erase(it); } -void Module::SetType(MODType ntype) -{ - this->type = ntype; -} - void Module::SetPermanent(bool state) { this->permanent = state; diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index ac6316728..e2f837f0f 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -126,24 +126,6 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out return MOD_ERR_OK; } -static bool IsOneOfModuleTypeLoaded(MODType mt) -{ - int pmods = 0; - - for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) - if ((*it)->type == mt) - ++pmods; - - /* - * 2, because module constructors now add modules to the hash.. so 1 (original module) - * and 2 (this module). -- w00t - */ - if (pmods == 2) - return true; - - return false; -} - /* This code was found online at http://www.linuxjournal.com/article/3687#comment-26593 * * This function will take a pointer from either dlsym or GetProcAddress and cast it in @@ -176,12 +158,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) /* Don't skip return value checking! -GD */ ModuleReturn ret = moduleCopyFile(modname, pbuf); if (ret != MOD_ERR_OK) - { - /* XXX: This used to assign filename here, but I don't think that was correct.. - * even if it was, it makes life very fucking difficult, so. - */ return ret; - } ano_modclearerr(); @@ -246,7 +223,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) else if (v.GetBuild() == Anope::VersionBuild()) Log(LOG_DEBUG) << "Module " << modname << " compiled against current version of Anope " << v.GetBuild(); - if (m->type == PROTOCOL && IsOneOfModuleTypeLoaded(PROTOCOL)) + if (m->type == PROTOCOL && ModuleManager::FindFirstOf(PROTOCOL) != m) { DeleteModule(m); Log() << "You cannot load two protocol modules"; @@ -260,13 +237,38 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) ModuleReturn ModuleManager::UnloadModule(Module *m, User *u) { + if (!m) + return MOD_ERR_PARAMS; + FOREACH_MOD(I_OnModuleUnload, OnModuleUnload(u, m)); - if (DNSEngine) - DNSEngine->Cleanup(m); + return DeleteModule(m); +} - DeleteModule(m); - return MOD_ERR_OK; +Module *ModuleManager::FindModule(const Anope::string &name) +{ + for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + { + Module *m = *it; + + if (m->name.equals_ci(name)) + return m; + } + + return NULL; +} + +Module *ModuleManager::FindFirstOf(ModType type) +{ + for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + { + Module *m = *it; + + if (m->type == type) + return m; + } + + return NULL; } void ModuleManager::RequireVersion(int major, int minor, int patch, int build) @@ -298,10 +300,10 @@ void ModuleManager::RequireVersion(int major, int minor, int patch, int build) throw ModuleException("This module requires version " + stringify(major) + "." + stringify(minor) + "." + stringify(patch) + "-" + build + " - this is " + Anope::Version()); } -void ModuleManager::DeleteModule(Module *m) +ModuleReturn ModuleManager::DeleteModule(Module *m) { if (!m || !m->handle) - return; + return MOD_ERR_PARAMS; ano_module_t handle = m->handle; Anope::string filename = m->filename; @@ -322,6 +324,8 @@ void ModuleManager::DeleteModule(Module *m) if (!filename.empty()) DeleteFile(filename.c_str()); + + return MOD_ERR_OK; } bool ModuleManager::Attach(Implementation i, Module *mod) diff --git a/src/modules.cpp b/src/modules.cpp index 3e62cd2fb..f77b28676 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -14,77 +14,6 @@ message_map MessageMap; std::list<Module *> Modules; -Anope::string ModuleGetErrStr(int status) -{ - Anope::string module_err_str[] = { - "Module, Okay - No Error", /* MOD_ERR_OK */ - "Module Error, Allocating memory", /* MOD_ERR_MEMORY */ - "Module Error, Not enough parameters", /* MOD_ERR_PARAMS */ - "Module Error, Already loaded", /* MOD_ERR_EXISTS */ - "Module Error, File does not exist", /* MOD_ERR_NOEXIST */ - "Module Error, No User", /* MOD_ERR_NOUSER */ - "Module Error, Error during load time or module returned MOD_STOP", /* MOD_ERR_NOLOAD */ - "Module Error, Unable to unload", /* MOD_ERR_NOUNLOAD */ - "Module Error, Incorrect syntax", /* MOD_ERR_SYNTAX */ - "Module Error, Unable to delete", /* MOD_ERR_NODELETE */ - "Module Error, Unknown Error occuried", /* MOD_ERR_UNKOWN */ - "Module Error, File I/O Error", /* MOD_ERR_FILE_IO */ - "Module Error, No Service found for request", /* MOD_ERR_NOSERVICE */ - "Module Error, No module name for request" /* MOD_ERR_NO_MOD_NAME */ - }; - return module_err_str[status]; -} - -/************************************************/ - -/** - * Load the ircd protocol module up - **/ -int protocol_module_init() -{ - int ret = 0; - - Log() << "Loading IRCD Protocol Module: [" << Config->IRCDModule << "]"; - ret = ModuleManager::LoadModule(Config->IRCDModule, NULL); - - if (ret == MOD_ERR_OK) - { - FindModule(Config->IRCDModule)->SetType(PROTOCOL); - /* This is really NOT the correct place to do config checks, but - * as we only have the ircd struct filled here, we have to over - * here. -GD - */ - if (ircd->ts6) - { - if (Config->Numeric.empty()) - { - Log() << "This IRCd protocol requires a server id to be set in Anope's configuration."; - ret = -1; - } - } - } - - return ret; -} - -/** - * Search the list of loaded modules for the given name. - * @param name the name of the module to find - * @return a pointer to the module found, or NULL - */ -Module *FindModule(const Anope::string &name) -{ - for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) - { - Module *m = *it; - - if (m->name.equals_ci(name)) - return m; - } - - return NULL; -} - /** Message constructor, adds the message to Anope * @param n The message name * @param f A callback function @@ -115,10 +44,10 @@ Message::~Message() } } -/** Find message in the message table +/** Find a message in the message table * @param name The name of the message were looking for * @return NULL if we cant find it, or a pointer to the Message if we can - **/ + */ std::vector<Message *> Anope::FindMessage(const Anope::string &name) { std::vector<Message *> messages; diff --git a/src/protocol.cpp b/src/protocol.cpp index d923f914e..4724559fb 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -434,7 +434,8 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope } else if (message.substr(0, 9).equals_ci("\1VERSION\1")) { - ircdproto->SendCTCP(bi, u->nick, "VERSION Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, Config->EncModuleList.begin()->c_str(), Anope::VersionBuildString().c_str()); + Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); + ircdproto->SendCTCP(bi, u->nick, "VERSION Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, enc ? enc->name.c_str() : "unknown", Anope::VersionBuildString().c_str()); } } diff --git a/src/servers.cpp b/src/servers.cpp index 096be0c9c..5b4058476 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -313,132 +313,63 @@ void do_server(const Anope::string &source, const Anope::string &servername, uns FOREACH_MOD(I_OnNewServer, OnNewServer(newserver)); } -/*************************************************************************/ - -/* TS6 UID generator common code. - * - * Derived from atheme-services, uid.c (hg 2954:116d46894b4c). - * -nenolod - */ -static bool ts6_uid_initted = false; -static char ts6_new_uid[10]; - -static void ts6_uid_increment(unsigned slot) -{ - if (slot != Config->Numeric.length()) - { - if (ts6_new_uid[slot] == 'Z') - ts6_new_uid[slot] = '0'; - else if (ts6_new_uid[slot] == '9') - { - ts6_new_uid[slot] = 'A'; - ts6_uid_increment(slot - 1); - } - else - ++ts6_new_uid[slot]; - } - else - { - if (ts6_new_uid[slot] == 'Z') - for (slot = 3; slot < 9; ++slot) - ts6_new_uid[slot] = 'A'; - else - ++ts6_new_uid[slot]; - } -} - /** Recieve the next UID in our list * @return The UID */ -const char *ts6_uid_retrieve() +const Anope::string ts6_uid_retrieve() { - if (!ircd->ts6) - { + if (!ircd || !ircd->ts6) return ""; - } - if (!ts6_uid_initted) - { - snprintf(ts6_new_uid, 10, "%sAAAAAA", Config->Numeric.c_str()); - ts6_uid_initted = true; - } - - ts6_uid_increment(8); - return ts6_new_uid; -} + static Anope::string current_uid = "AAAAAA"; + static unsigned current_len = current_uid.length() - 1; -/*******************************************************************/ - -/* - * TS6 SID generator code, provided by DukePyrolator - */ - -static bool ts6_sid_initted = false; -static char ts6_new_sid[4]; - -static void ts6_sid_increment(unsigned pos) -{ - /* - * An SID must be exactly 3 characters long, starts with a digit, - * and the other two characters are A-Z or digits - * The rules for generating an SID go like this... - * --> ABCDEFGHIJKLMNOPQRSTUVWXYZ --> 0123456789 --> WRAP - */ - if (!pos) + while (finduser(Config->Numeric + current_uid) != NULL) { - /* At pos 0, if we hit '9', we've run out of available SIDs, - * reset the SID to the smallest possible value and try again. */ - if (ts6_new_sid[pos] == '9') - { - ts6_new_sid[0] = '0'; - ts6_new_sid[1] = 'A'; - ts6_new_sid[2] = 'A'; - } + char &curChar = current_uid[current_len]; + if (curChar == 'Z') + curChar = '0'; + else if (curChar != '9') + ++curChar; else - // But if we haven't, just keep incrementing merrily. - ++ts6_new_sid[0]; - } - else - { - if (ts6_new_sid[pos] == 'Z') - ts6_new_sid[pos] = '0'; - else if (ts6_new_sid[pos] == '9') { - ts6_new_sid[pos] = 'A'; - ts6_sid_increment(pos - 1); + curChar = 'A'; + if (--current_len == 0) + current_len = current_uid.length(); } - else - ++ts6_new_sid[pos]; + } + + return Config->Numeric + current_uid; } /** Return the next SID in our list * @return The SID */ -const char *ts6_sid_retrieve() +const Anope::string ts6_sid_retrieve() { - if (!ircd->ts6) - { + if (!ircd || !ircd->ts6) return ""; - } - if (!ts6_sid_initted) - { - // Initialize ts6_new_sid with the services server SID - snprintf(ts6_new_sid, 4, "%s", Config->Numeric.c_str()); - ts6_sid_initted = true; - } + static Anope::string current_sid = Config->Numeric; + static unsigned current_len = current_sid.length() - 1; - while (1) + while (Server::Find(current_sid) != NULL) { - // Check if the new SID is used by a known server - if (!Server::Find(ts6_new_sid)) - // return the new SID - return ts6_new_sid; - - // Add one to the last SID - ts6_sid_increment(2); + char &curChar = current_sid[current_len]; + if (curChar == 'Z') + curChar = '0'; + else if (curChar != '9') + ++curChar; + else + { + curChar = 'A'; + if (--current_len == 0) + current_len = current_sid.length(); + } + } - /* not reached */ - return ""; + + return current_sid; } + |