diff options
| -rw-r--r-- | Changes.conf | 11 | ||||
| -rw-r--r-- | data/example.conf | 90 | ||||
| -rw-r--r-- | include/Makefile | 2 | ||||
| -rw-r--r-- | include/account.h | 4 | ||||
| -rw-r--r-- | include/config.h | 3 | ||||
| -rw-r--r-- | include/configreader.h | 18 | ||||
| -rw-r--r-- | include/datafiles.h | 25 | ||||
| -rw-r--r-- | include/extern.h | 2 | ||||
| -rw-r--r-- | include/modules.h | 105 | ||||
| -rw-r--r-- | include/pseudo.h | 1 | ||||
| -rw-r--r-- | src/Makefile | 5 | ||||
| -rw-r--r-- | src/chanserv.c | 7 | ||||
| -rw-r--r-- | src/config.c | 34 | ||||
| -rw-r--r-- | src/core/db_plain.cpp | 1148 | ||||
| -rw-r--r-- | src/core/ns_forbid.c | 4 | ||||
| -rw-r--r-- | src/core/ns_identify.c | 3 | ||||
| -rw-r--r-- | src/core/os_ignore.c | 58 | ||||
| -rw-r--r-- | src/core/os_modlist.c | 25 | ||||
| -rw-r--r-- | src/core/os_news.c | 42 | ||||
| -rw-r--r-- | src/datafiles.c | 203 | ||||
| -rw-r--r-- | src/init.c | 12 | ||||
| -rw-r--r-- | src/main.c | 4 | ||||
| -rw-r--r-- | src/modulemanager.cpp | 6 | ||||
| -rw-r--r-- | src/modules/hs_request.c | 150 | ||||
| -rw-r--r-- | src/modules/os_ignore_db.c | 490 | ||||
| -rw-r--r-- | src/modules/os_info.c | 193 | ||||
| -rw-r--r-- | src/regchannel.cpp | 11 | ||||
| -rw-r--r-- | src/tools/db-convert.c | 110 | ||||
| -rw-r--r-- | src/tools/db-convert.h | 19 | ||||
| -rw-r--r-- | src/users.c | 6 |
30 files changed, 1570 insertions, 1221 deletions
diff --git a/Changes.conf b/Changes.conf index f084f452d..f4319af25 100644 --- a/Changes.conf +++ b/Changes.conf @@ -3,11 +3,22 @@ Anope Version 1.9.2 ** ADDED CONFIGURATION DIRECTIVES ** options:enablelogchannel added to auto turn on the logchannel on startup options:mlock added to configure the default mlock modes on new channels +options:database added for the database modules ** MODIFIED CONFIGURATION DIRECTIVES ** chanserv:modules added cs_unban ** DELETED CONFIGURATION DIRECTIVES ** +nickserv:database deleted because of new database system +nickserv:prenickdatabase deleted because of new database system +chanserv:database deleted because of the new database system +botserv:database deleted because of the new database system +hostserv:database deleted because of the new database system +operserv:database deleted because of the new database system +operserv:newsdatabase deleted because of the new database system +operserv:exceptiondatabase deleted because of the new database system +hs_request:database deleted because of the new database system +os_ignore:database deleted because of the new database system Anope Version 1.9.1 ------------------- diff --git a/data/example.conf b/data/example.conf index a0313947f..7299b5f04 100644 --- a/data/example.conf +++ b/data/example.conf @@ -238,7 +238,7 @@ networkinfo options { /* - * The encryption module to use when dealing with passwords. This determines how + * The encryption modules are used when dealing with passwords. This determines how * the passwords are stored in the databases, and does not add any security as * far as transmitting passwords over the network goes. * @@ -264,6 +264,12 @@ options encryption = "enc_none enc_sha1 enc_md5 enc_old" /* + * The database modules are used for saving and loading databases for Anope. + * Currently, there is only one database module - db_plain + */ + database = "db_plain" + + /* * These keys are used to initiate the random number generator. These numbers * MUST be random as you want your passcodes to be random. Don't give these * keys to anyone! Keep them private! @@ -702,19 +708,6 @@ nickserv description = "Nickname Registration Service" /* - * The filename of the NickServ database. The path is relative to the services - * executable. If not given, defaults to "nick.db". - */ - database = "nick.db" - - /* - * The filename of the NickServ Pre-Nick database. The path is relative to the - * services executable. This directive is only required if the e-mail registration - * option is enabled. - */ - #prenickdatabase = "prenick.db" - - /* * The core modules to load for NickServ. This is a space separated list that corresponds * to the base names of the modules for NickServ. This directive is optional, but highly recommended. */ @@ -890,12 +883,6 @@ chanserv description = "Channel Registration Service" /* - * The filename of the ChanServ database. The path is relative to the services - * executable. If not given, defaults to "chan.db". - */ - database = "chan.db" - - /* * The core modules to load for ChanServ. This is a space separated list that corresponds * to the base names of the modules for ChanServ. This directive is optional, but highly recommended. */ @@ -1073,12 +1060,6 @@ botserv description = "Bot Service" /* - * The filename of the BotServ database. The path is relative to the services - * executable. If not given, defaults to "bot.db". - */ - database = "bot.db" - - /* * The core modules to load for BotServ. This is a space separated list that corresponds * to the base names of the modules for BotServ. This directive is optional, but highly recommended. */ @@ -1172,12 +1153,6 @@ hostserv description = "vHost Service" /* - * The filename of the HostServ database. The path is relative to the services - * executable. If not given, defaults to "hosts.db". - */ - database = "hosts.db" - - /* * The core modules to load for HostServ. This is a space separated list that corresponds * to the base names of the modules for HostServ. This directive is optional, but highly recommended. */ @@ -1215,24 +1190,6 @@ operserv globaldescription = "Global Noticer" /* - * The filename of the OperServ database. The path is relative to the services - * executable. If not given, defaults to "oper.db". - */ - database = "oper.db" - - /* - * The filename of OperServ's News database. The path is relative to the services - * executable. If not given, defaults to "news.db". - */ - newsdatabase = "news.db" - - /* - * The filename of OperServ's Session Exception database. The path is relative to the services - * executable. If not given, defaults to "exception.db". - */ - exceptiondatabase = "exception.db" - - /* * The core modules to load for OperServ. This is a space separated list that corresponds * to the base names of the modules for OperServ. This directive is optional, but highly recommended. */ @@ -1529,22 +1486,6 @@ hs_request * If set, Services will send a memo to all Host Setters when a new vHost is requested. */ #memosetters = yes - - /* - * The filename of the vHost request database. The path is relative to the services - * executable. If not given, defaults to "hs_request.db". - */ - #database = "hs_request.db" -} - -ns_maxemail -{ - /* - * The limit to how many registered nicks can use the same e-mail address. If set to 0 or left - * commented, there will be no limit enforced when registering new accounts or using - * /msg NickServ SET EMAIL. - */ - #maxemails = 1 } ns_noop_convert @@ -1556,20 +1497,13 @@ ns_noop_convert #database = "autoop.db" } -os_ignore +ns_maxemail { /* - * The filename of the Services' ignore database. The path is relative to the services - * executable. If not given, defaults to "os_ignore.db". + * The limit to how many registered nicks can use the same e-mail address. If set to 0 or left + * commented, there will be no limit enforced when registering new accounts or using + * /msg NickServ SET EMAIL. */ - #database = "os_ignore.db" + #maxemails = 1 } -os_info -{ - /* - * The filename of the oper information database. The path is relative to the services - * executable. If not given, defaults to "os_info.db". - */ - #database = "os_info.db" -} diff --git a/include/Makefile b/include/Makefile index 13c5b8b2c..3d8067aa6 100644 --- a/include/Makefile +++ b/include/Makefile @@ -10,7 +10,7 @@ services.h: sysconf.h config.h extern.h extern.h: slist.h touch $@ -pseudo.h: commands.h timers.h datafiles.h slist.h +pseudo.h: commands.h timers.h slist.h touch $@ clean: diff --git a/include/account.h b/include/account.h index e20b70fe4..dc0d21c7d 100644 --- a/include/account.h +++ b/include/account.h @@ -58,8 +58,8 @@ enum NickCoreFlag NI_SUSPENDED, /* Autoop nickname in channels */ NI_AUTOOP, - /* Nick won't expire */ - NI_NOEXPIRE, + /* This nickcore is forbidden, which means the nickalias for it is aswell */ + NI_FORBIDDEN, NI_END }; diff --git a/include/config.h b/include/config.h index f9d8f4370..a5151e071 100644 --- a/include/config.h +++ b/include/config.h @@ -25,6 +25,9 @@ /* Name of configuration file (in Services directory) */ #define SERVICES_CONF "services.conf" +/* Name of anope datbase */ +#define DATABASE_FILE "anope.db" + /* Name of log file (in Services directory) */ #define LOG_FILENAME "services.log" diff --git a/include/configreader.h b/include/configreader.h index 97403b5fa..c9db6cb89 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -432,8 +432,6 @@ class ServerConfig /* Global realname */ char *desc_GlobalNoticer; - /* Name of the hostserv database */ - char *HostDBName; /* HostServ Name */ char *s_HostServ; /* HostServ realname */ @@ -443,18 +441,6 @@ class ServerConfig char *PIDFilename; /* MOTD filename */ char *MOTDFilename; - /* NickServ DB name */ - char *NickDBName; - /* DB name for nicks being registered */ - char *PreNickDBName; - /* Channel DB name */ - char *ChanDBName; - /* Botserv DB name */ - char *BotDBName; - /* OperServ db name */ - char *OperDBName; - /* News DB name */ - char *NewsDBName; /* True if its ok to not be able to save backs */ bool NoBackupOkay; @@ -695,8 +681,6 @@ class ServerConfig unsigned MaxSessionLimit; /* How long session akills should last */ time_t SessionAutoKillExpiry; - /* DB name for exceptions */ - char *ExceptionDBName; /* Reason to use for session kills */ char *SessionLimitExceeded; /* Optional second reason */ @@ -708,6 +692,8 @@ class ServerConfig std::list<std::string> ModulesAutoLoad; /* Encryption modules */ std::list<std::string> EncModuleList; + /* Database modules */ + std::list<std::string> DBModuleList; /* HostServ Core Modules */ std::list<std::string> HostServCoreModules; /* MemoServ Core Modules */ diff --git a/include/datafiles.h b/include/datafiles.h deleted file mode 100644 index fe8cb3d12..000000000 --- a/include/datafiles.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Database file descriptor structure and file handling routine prototypes. - * - * (C) 2003-2009 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for furhter details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * $Id$ - * - */ - -#ifndef DATAFILES_H -#define DATAFILES_H - -#ifndef _WIN32 -#include <sys/param.h> -#define DeleteFile unlink -#endif - - - -#endif /* DATAFILES_H */ diff --git a/include/extern.h b/include/extern.h index 10c4028b4..f570c39ff 100644 --- a/include/extern.h +++ b/include/extern.h @@ -393,8 +393,6 @@ E void SetDefaultMLock(); /**** modules.c ****/ E void modules_unload_all(bool unload_proto); /* Read warnings near function source */ -E void ModuleDatabaseBackup(const char *dbname); -E void ModuleRemoveBackups(const char *dbname); /**** nickserv.c ****/ diff --git a/include/modules.h b/include/modules.h index f4d9700f3..129e2666d 100644 --- a/include/modules.h +++ b/include/modules.h @@ -186,7 +186,7 @@ enum CommandReturn const char *ano_moderr(); #endif -typedef enum { CORE,PROTOCOL,THIRD,SUPPORTED,QATESTED,ENCRYPTION } MODType; +typedef enum { CORE,PROTOCOL,THIRD,SUPPORTED,QATESTED,ENCRYPTION,DATABASE } MODType; typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation; /*************************************************************************/ @@ -561,11 +561,15 @@ class CoreExport Module */ virtual void OnPostLoadDatabases() { } - /** Called when anope saves databases. - * NOTE: This event is deprecated pending new database handling. - * XXX. + /** Called when the databases are saved + * @return EVENT_CONTINUE to let other modules continue saving, EVENT_STOP to stop + */ + virtual EventReturn OnSaveDatabase() { return EVENT_CONTINUE; } + + /** Called when the databases are loaded + * @return EVENT_CONTINUE to let other modules continue saving, EVENT_STOP to stop */ - virtual void OnSaveDatabase() MARK_DEPRECATED { } + virtual EventReturn OnLoadDatabase() { return EVENT_CONTINUE; } /** Called when anope backs up databases. * NOTE: This event is deprecated pending new database handling. @@ -684,6 +688,73 @@ class CoreExport Module */ virtual void OnDatabaseExpire() MARK_DEPRECATED { } + /** Called when the flatfile dbs are being written + * @param Write A callback to the function used to insert a line into the database + */ + virtual void OnDatabaseWrite(void (*Write)(const std::string &)) { } + + /** Called when a line is read from the database + * @param params The params from the database + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing + */ + virtual EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + + /** Called when nickcore metadata is read from the database + * @param nc The nickcore + * @param key The metadata key + * @param params The params from the database + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing + */ + virtual EventReturn OnDatabaseReadMetadata(NickCore *nc, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + + /** Called when nickcore metadata is read from the database + * @param na The nickalias + * @param key The metadata key + * @param params The params from the database + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing + */ + virtual EventReturn OnDatabaseReadMetadata(NickAlias *na, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + + /** Called when botinfo metadata is read from the database + * @param bi The botinfo + * @param key The metadata key + * @param params The params from the database + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing + */ + virtual EventReturn OnDatabaseReadMetadata(BotInfo *bi, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + + /** Called when chaninfo metadata is read from the database + * @param ci The chaninfo + * @param key The metadata key + * @param params The params from the database + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to stop processing + */ + virtual EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const std::string &key, const std::vector<std::string> ¶ms) { return EVENT_CONTINUE; } + + /** Called when we are writing metadata for a nickcore + * @param WriteMetata A callback function used to insert the metadata + * @param nc The nickcore + */ + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickCore *nc) { } + + /** Called when we are wrting metadata for a nickalias + * @param WriteMetata A callback function used to insert the metadata + * @param na The nick alias + */ + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickAlias *na) { } + + /** Called when we are writing metadata for a botinfo + * @param WriteMetata A callback function used to insert the metadata + * @param bi The botinfo + */ + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), BotInfo *bi) { } + + /** Called when are are writing metadata for a channelinfo + * @param WriteMetata A callback function used to insert the metadata + * @param bi The channelinfo + */ + virtual void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), ChannelInfo *ci) { } + /** Called before services restart */ virtual void OnPreRestart() { } @@ -983,6 +1054,18 @@ class CoreExport Module */ virtual EventReturn OnUnMLock(ChannelModeName Name) { return EVENT_CONTINUE; } + /** Called after a module is loaded + * @param u The user loading the module, can be NULL + * @param m The module + */ + virtual void OnModuleLoad(User *u, Module *m) { } + + /** Called before a module is unloaded + * @param u The user, can be NULL + * @param m The module + */ + virtual void OnModuleUnload(User *u, Module *m) { } + }; @@ -1019,9 +1102,17 @@ enum Implementation /* OperServ */ I_OnOperServHelp, I_OnDefconLevel, + /* Database */ + I_OnPostLoadDatabases, I_OnSaveDatabase, I_OnLoadDatabase, I_OnBackupDatabase, + I_OnDatabaseExpire, + I_OnDatabaseWrite, I_OnDatabaseRead, I_OnDatabaseReadMetadata, I_OnDatabaseWriteMetadata, + + /* Modules */ + I_OnModuleLoad, I_OnModuleUnload, + /* Other */ - I_OnReload, I_OnPreServerConnect, I_OnNewServer, I_OnServerConnect, I_OnPreCommandRun, I_OnPreCommand, I_OnPostCommand, I_OnPostLoadDatabases, I_OnSaveDatabase, I_OnBackupDatabase, - I_OnPreDatabaseExpire, I_OnDatabaseExpire, I_OnPreRestart, I_OnRestart, I_OnPreShutdown, I_OnShutdown, I_OnSignal, + I_OnReload, I_OnPreServerConnect, I_OnNewServer, I_OnServerConnect, I_OnPreCommandRun, I_OnPreCommand, I_OnPostCommand, + I_OnPreDatabaseExpire, I_OnPreRestart, I_OnRestart, I_OnPreShutdown, I_OnShutdown, I_OnSignal, I_OnServerQuit, I_OnTopicUpdated, I_OnEncrypt, I_OnEncryptInPlace, I_OnEncryptCheckLen, I_OnDecrypt, I_OnCheckPassword, I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd, diff --git a/include/pseudo.h b/include/pseudo.h index 65e5e81e7..d356aa953 100644 --- a/include/pseudo.h +++ b/include/pseudo.h @@ -15,5 +15,4 @@ #include "commands.h" #include "language.h" #include "timers.h" -#include "datafiles.h" #include "slist.h" diff --git a/src/Makefile b/src/Makefile index 8257d8cdf..90705ce29 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o command.o commands.o compat.o \ - config.o datafiles.o encrypt.o hashcomp.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \ + config.o encrypt.o hashcomp.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \ memory.o memoserv.o messages.o misc.o modules.o nickserv.o operserv.o \ process.o protocol.o send.o servers.o sessions.o slist.o sockutil.o opertype.o users.o module.o modulemanager.o configreader.o \ wildcard.o nickcore.o nickalias.o timers.o modes.o regchannel.o @@ -7,7 +7,7 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o command.o comm INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \ ../include/pseudo.h ../include/sysconf.h ../include/config.h \ ../include/messages.h ../include/services.h \ - ../include/timers.h ../include/datafiles.h ../include/extern.h \ + ../include/timers.h ../include/extern.h \ ../include/modules.h ../include/slist.h ../include/hashcomp.h MAKEARGS = 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'ANOPELIBS=${ANOPELIBS}' \ @@ -47,7 +47,6 @@ command.o: command.cpp $(INCLUDES) commands.o: commands.c $(INCLUDES) compat.o: compat.c $(INCLUDES) config.o: config.c $(INCLUDES) -datafiles.o: datafiles.c $(INCLUDES) encrypt.o: encrypt.c $(INCLUDES) init.o: init.c $(INCLUDES) ircd.o: ircd.c $(INCLUDES) diff --git a/src/chanserv.c b/src/chanserv.c index dc5345ed6..c0f8ac9bb 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -719,12 +719,9 @@ int check_kick(User * user, const char *chan, time_t chants) if (c) { - c->RemoveMode(NULL, CMODE_BAN, mask); - } - - c->SetMode(NULL, CMODE_BAN, mask); - if (c) + c->SetMode(NULL, CMODE_BAN, mask); ircdproto->SendKick(whosends(ci), c, user, "%s", reason); + } return 1; } diff --git a/src/config.c b/src/config.c index aa7577cbf..85eeed357 100644 --- a/src/config.c +++ b/src/config.c @@ -22,6 +22,7 @@ ServerConfig Config; static std::string Modules; static std::string EncModules; +static std::string DBModules; static std::string HostCoreModules; static std::string MemoCoreModules; static std::string BotCoreModules; @@ -180,12 +181,7 @@ bool ValidateEmailReg(ServerConfig *, const char *tag, const char *value, ValueI { if (Config.NSEmailReg) { - if (std::string(value) == "prenickdatabase") - { - if (data.GetValue().empty()) - throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when e-mail registrations are enabled!"); - } - else if (std::string(value) == "preregexpire") + if (std::string(value) == "preregexpire") { if (!data.GetInteger()) throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when e-mail registration are enabled!"); @@ -240,7 +236,7 @@ bool ValidateBotServ(ServerConfig *, const char *tag, const char *value, ValueIt { if (Config.s_BotServ) { - if (std::string(value) == "description" || std::string(value) == "database") + if (std::string(value) == "description") { if (data.GetValue().empty()) throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when BotServ is enabled!"); @@ -258,7 +254,7 @@ bool ValidateHostServ(ServerConfig *, const char *tag, const char *value, ValueI { if (Config.s_HostServ) { - if (std::string(value) == "description" || std::string(value) == "database") + if (std::string(value) == "description") { if (data.GetValue().empty()) throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when HostServ is enabled!"); @@ -613,6 +609,7 @@ int ServerConfig::Read(bool bail) {"networkinfo", "networkname", "", new ValueContainerChar(&Config.NetworkName), DT_CHARPTR, ValidateNotEmpty}, {"networkinfo", "nicklen", "0", new ValueContainerUInt(&Config.NickLen), DT_UINTEGER | DT_NORELOAD, ValidateNickLen}, {"options", "encryption", "", new ValueContainerString(&EncModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, + {"options", "database", "", new ValueContainerString(&DBModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"options", "userkey1", "0", new ValueContainerLUInt(&Config.UserKey1), DT_LUINTEGER, NoValidation}, {"options", "userkey2", "0", new ValueContainerLUInt(&Config.UserKey2), DT_LUINTEGER, NoValidation}, {"options", "userkey3", "0", new ValueContainerLUInt(&Config.UserKey3), DT_LUINTEGER, NoValidation}, @@ -645,9 +642,7 @@ int ServerConfig::Read(bool bail) {"options", "mlock", "+nrt", new ValueContainerString(&Config.MLock), DT_STRING, NoValidation}, {"nickserv", "nick", "NickServ", new ValueContainerChar(&Config.s_NickServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, {"nickserv", "description", "Nickname Registration Service", new ValueContainerChar(&Config.desc_NickServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"nickserv", "database", "nick.db", new ValueContainerChar(&Config.NickDBName), DT_CHARPTR, ValidateNotEmpty}, {"nickserv", "emailregistration", "no", new ValueContainerBool(&Config.NSEmailReg), DT_BOOLEAN, NoValidation}, - {"nickserv", "prenickdatabase", "", new ValueContainerChar(&Config.PreNickDBName), DT_CHARPTR, ValidateEmailReg}, {"nickserv", "modules", "", new ValueContainerString(&NickCoreModules), DT_STRING, NoValidation}, {"nickserv", "forceemail", "no", new ValueContainerBool(&Config.NSForceEmail), DT_BOOLEAN, ValidateEmailReg}, {"nickserv", "defaults", "secure memosignon memoreceive", new ValueContainerString(&NSDefaults), DT_STRING, NoValidation}, @@ -677,7 +672,6 @@ int ServerConfig::Read(bool bail) {"mail", "dontquoteaddresses", "no", new ValueContainerBool(&Config.DontQuoteAddresses), DT_BOOLEAN, NoValidation}, {"chanserv", "nick", "ChanServ", new ValueContainerChar(&Config.s_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, {"chanserv", "description", "Channel Registration Service", new ValueContainerChar(&Config.desc_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"chanserv", "database", "chan.db", new ValueContainerChar(&Config.ChanDBName), DT_CHARPTR, ValidateNotEmpty}, {"chanserv", "modules", "", new ValueContainerString(&ChanCoreModules), DT_STRING, NoValidation}, {"chanserv", "defaults", "keeptopic secure securefounder signkick", new ValueContainerString(&CSDefaults), DT_STRING, NoValidation}, {"chanserv", "maxregistered", "0", new ValueContainerUInt(&Config.CSMaxReg), DT_UINTEGER, NoValidation}, @@ -699,7 +693,6 @@ int ServerConfig::Read(bool bail) {"memoserv", "memoreceipt", "0", new ValueContainerUInt(&Config.MSMemoReceipt), DT_UINTEGER, NoValidation}, {"botserv", "nick", "", new ValueContainerChar(&Config.s_BotServ), DT_CHARPTR | DT_NORELOAD, NoValidation}, {"botserv", "description", "Bot Service", new ValueContainerChar(&Config.desc_BotServ), DT_CHARPTR | DT_NORELOAD, ValidateBotServ}, - {"botserv", "database", "bot.db", new ValueContainerChar(&Config.BotDBName), DT_CHARPTR, ValidateBotServ}, {"botserv", "modules", "", new ValueContainerString(&BotCoreModules), DT_STRING, NoValidation}, {"botserv", "defaults", "", new ValueContainerString(&BSDefaults), DT_STRING, NoValidation}, {"botserv", "minusers", "0", new ValueContainerUInt(&Config.BSMinUsers), DT_UINTEGER, ValidateBotServ}, @@ -711,15 +704,11 @@ int ServerConfig::Read(bool bail) {"botserv", "fantasycharacter", "!", new ValueContainerChar(&Config.BSFantasyCharacter), DT_CHARPTR, NoValidation}, {"hostserv", "nick", "", new ValueContainerChar(&Config.s_HostServ), DT_CHARPTR | DT_NORELOAD, NoValidation}, {"hostserv", "description", "vHost Service", new ValueContainerChar(&Config.desc_HostServ), DT_CHARPTR | DT_NORELOAD, ValidateHostServ}, - {"hostserv", "database", "hosts.db", new ValueContainerChar(&Config.HostDBName), DT_CHARPTR, ValidateHostServ}, {"hostserv", "modules", "", new ValueContainerString(&HostCoreModules), DT_STRING, NoValidation}, {"operserv", "nick", "OperServ", new ValueContainerChar(&Config.s_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, {"operserv", "description", "Operator Service", new ValueContainerChar(&Config.desc_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, {"operserv", "globalnick", "Global", new ValueContainerChar(&Config.s_GlobalNoticer), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, {"operserv", "globaldescription", "Global Noticer", new ValueContainerChar(&Config.desc_GlobalNoticer), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty}, - {"operserv", "database", "oper.db", new ValueContainerChar(&Config.OperDBName), DT_CHARPTR, ValidateNotEmpty}, - {"operserv", "newsdatabase", "news.db", new ValueContainerChar(&Config.NewsDBName), DT_CHARPTR, ValidateNotEmpty}, - {"operserv", "exceptiondatabase", "exception.db", new ValueContainerChar(&Config.ExceptionDBName), DT_CHARPTR, ValidateNotEmpty}, {"operserv", "modules", "", new ValueContainerString(&OperCoreModules), DT_STRING, NoValidation}, {"operserv", "superadmin", "no", new ValueContainerBool(&Config.SuperAdmin), DT_BOOLEAN, NoValidation}, {"operserv", "logmaxusers", "no", new ValueContainerBool(&Config.LogMaxUsers), DT_BOOLEAN, NoValidation}, @@ -1689,6 +1678,7 @@ int read_config(int reload) /* Modules Autoload building... :P */ Config.ModulesAutoLoad = BuildStringList(!Modules.empty() ? Modules : ""); Config.EncModuleList = BuildStringList(!EncModules.empty() ? EncModules : ""); + Config.DBModuleList = BuildStringList(!DBModules.empty() ? DBModules : ""); Config.HostServCoreModules = BuildStringList(!HostCoreModules.empty() ? HostCoreModules : ""); Config.MemoServCoreModules = BuildStringList(!MemoCoreModules.empty() ? MemoCoreModules : ""); Config.BotServCoreModules = BuildStringList(!BotCoreModules.empty() ? BotCoreModules : ""); @@ -1775,18 +1765,6 @@ int read_config(int reload) } } - /** - * If they try to enable any email registration option, - * make sure they have everything else they need too... - * - * rob - **/ - if (!Config.NSEmailReg) { - delete [] Config.PreNickDBName; - Config.PreNickDBName = NULL; - Config.NSRExpire = 0; - } - SetDefaultMLock(); if (!retval) { diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp new file mode 100644 index 000000000..b551d0b5c --- /dev/null +++ b/src/core/db_plain.cpp @@ -0,0 +1,1148 @@ +/* + * + * (C) 2003-2009 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. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +std::fstream db; + +/** Enum used for what METADATA type we are reading + */ +enum MDType +{ + MD_NONE, + MD_NC, + MD_NA, + MD_BI, + MD_CH +}; + +/* Character for newlines, in my research I have concluded it is significantly faster + * to use \n instead of std::endl because std::endl also flushes the buffer, which + * is not necessary here + */ +static const char endl = '\n'; + +/** Read from the database and call the events + * @param m If specified it only calls the read events for the specific module + */ +static void ReadDatabase(Module *m = NULL) +{ + std::string buf; + EventReturn MOD_RESULT; + MDType Type = MD_NONE; + + db.open(DATABASE_FILE, std::ios_base::in); + + if (!db.is_open()) + { + ircdproto->SendGlobops(NULL, "Unable to open %s for reading!", DATABASE_FILE); + return; + } + + while (std::getline(db, buf)) + { + if (buf.empty()) + continue; + + spacesepstream sep(buf); + std::vector<std::string> params; + while (sep.GetToken(buf)) + { + if (buf[0] == ':') + { + buf.erase(buf.begin()); + if (!buf.empty()) + params.push_back(buf + " " + sep.GetRemaining()); + } + else + params.push_back(buf); + } + + if (m) + MOD_RESULT = m->OnDatabaseRead(params); + else + { + FOREACH_RESULT(I_OnDatabaseRead, OnDatabaseRead(params)); + } + if (MOD_RESULT == EVENT_STOP) + continue; + + std::string mdbuf; + NickCore *nc; + NickAlias *na; + BotInfo *bi; + ChannelInfo *ci; + if (!params.empty()) + { + if (params[0] == "NC") + { + nc = findcore(params[1].c_str()); + Type = MD_NC; + } + else if (params[0] == "NA") + { + na = findnick(params[2].c_str()); + Type = MD_NA; + } + else if (params[0] == "BI") + { + bi = findbot(params[1].c_str()); + Type = MD_BI; + } + else if (params[0] == "CH") + { + ci = cs_findchan(params[1].c_str()); + Type = MD_CH; + } + else if (params[0] == "MD") + { + std::string key = params[1]; + params.erase(params.begin()); + params.erase(params.begin()); + + if (nc && Type == MD_NC) + { + try + { + if (m) |
