1
0
mirror of https://github.com/anope/anope.git synced 2026-07-04 02:03:12 +02:00

Rewrote BuildStringList to use std::list instead of char**

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2632 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
Adam-
2009-11-08 18:00:54 +00:00
parent 608b63d979
commit 1c1312624d
19 changed files with 94 additions and 121 deletions
+12 -24
View File
@@ -19,6 +19,7 @@
#define EI extern DllExport
#include "slist.h"
#include "hashcomp.h"
E void ModuleRunTimeDirCleanUp();
@@ -348,28 +349,15 @@ E bool AddAkiller;
/**
* Modules Stuff
**/
E char **ModulesAutoload;
E int ModulesNumber;
E char **ModulesDelayedAutoload;
E int ModulesDelayedNumber;
E std::list<std::string> ModulesAutoLoad;
E char **HostServCoreModules;
E int HostServCoreNumber;
E char **MemoServCoreModules;
E int MemoServCoreNumber;
E char **BotServCoreModules;
E int BotServCoreNumber;
E char **OperServCoreModules;
E int OperServCoreNumber;
E char **NickServCoreModules;
E int NickServCoreNumber;
E char **ChanServCoreModules;
E int ChanServCoreNumber;
E std::list<std::string> EncModuleList;
E std::list<std::string> HostServCoreModules;
E std::list<std::string> MemoServCoreModules;
E std::list<std::string> BotServCoreModules;
E std::list<std::string> OperServCoreModules;
E std::list<std::string> NickServCoreModules;
E std::list<std::string> ChanServCoreModules;
E bool LimitSessions;
E unsigned DefSessionLimit;
@@ -405,8 +393,6 @@ E long unsigned int UserKey3;
E int convert_ircservices_44();
/**** encrypt.c ****/
E char **EncModuleList;
E int EncModulesNumber;
E void initEncryption();
E int enc_encrypt(const char *src, int len, char *dest, int size);
E int enc_encrypt_in_place(char *buf, int size);
@@ -593,7 +579,9 @@ E char *str_signed(unsigned char *str);
E void ntoa(struct in_addr addr, char *ipaddr, int len);
E char **buildStringList(const std::string &src, int *number);
E std::list<std::string> BuildStringList(const std::string &);
E std::list<ci::string> BuildStringList(const ci::string &);
E void binary_to_hex(unsigned char *bin, char *hex, int length);
E uint32 cidr_to_netmask(uint16 cidr);
+1 -2
View File
@@ -1049,10 +1049,9 @@ class CoreExport ModuleManager
static std::vector<Module *> EventHandlers[I_END];
/** Load up a list of modules.
* @param total_modules The number of modules to load
* @param module_list The list of modules to load
**/
static void LoadModuleList(int total_modules, char **module_list);
static void LoadModuleList(std::list<std::string> &ModList);
/** Loads a given module.
* @param m the module to load
+1 -1
View File
@@ -34,7 +34,7 @@ E void moduleAddBotServCmds();
/*************************************************************************/
/* *INDENT-OFF* */
void moduleAddBotServCmds() {
ModuleManager::LoadModuleList(BotServCoreNumber, BotServCoreModules);
ModuleManager::LoadModuleList(BotServCoreModules);
}
/* *INDENT-ON* */
/*************************************************************************/
+1 -1
View File
@@ -113,7 +113,7 @@ int levelinfo_maxwidth = 0;
/*************************************************************************/
void moduleAddChanServCmds() {
ModuleManager::LoadModuleList(ChanServCoreNumber, ChanServCoreModules);
ModuleManager::LoadModuleList(ChanServCoreModules);
}
/* *INDENT-ON* */
+30 -50
View File
@@ -199,39 +199,31 @@ char *SessionLimitDetailsLoc;
bool OSOpersOnly;
static std::string Modules;
char **ModulesAutoload;
int ModulesNumber;
std::list<std::string> ModulesAutoLoad;
/**
* Core Module Stuff
**/
char **EncModuleList;
char *EncModules;
int EncModulesNumber;
static std::string EncModules;
std::list<std::string> EncModuleList;
static char *HostCoreModules;
char **HostServCoreModules;
int HostServCoreNumber;
static std::string HostCoreModules;
std::list<std::string> HostServCoreModules;
static char *MemoCoreModules;
char **MemoServCoreModules;
int MemoServCoreNumber;
static std::string MemoCoreModules;
std::list<std::string> MemoServCoreModules;
static char *BotCoreModules;
char **BotServCoreModules;
int BotServCoreNumber;
static std::string BotCoreModules;
std::list<std::string> BotServCoreModules;
static char *OperCoreModules;
char **OperServCoreModules;
int OperServCoreNumber;
static std::string OperCoreModules;
std::list<std::string> OperServCoreModules;
static char *NickCoreModules;
char **NickServCoreModules;
int NickServCoreNumber;
static std::string NickCoreModules;
std::list<std::string> NickServCoreModules;
static char *ChanCoreModules;
char **ChanServCoreModules;
int ChanServCoreNumber;
static std::string ChanCoreModules;
std::list<std::string> ChanServCoreModules;
int DefConLevel;
static std::string DefCon1;
@@ -834,7 +826,7 @@ int ServerConfig::Read(bool bail)
{"networkinfo", "logbot", "no", new ValueContainerBool(&LogBot), DT_BOOLEAN, NoValidation},
{"networkinfo", "networkname", "", new ValueContainerChar(&NetworkName), DT_CHARPTR, ValidateNotEmpty},
{"networkinfo", "nicklen", "0", new ValueContainerUInt(&NickLen), DT_UINTEGER | DT_NORELOAD, ValidateNickLen},
{"options", "encryption", "", new ValueContainerChar(&EncModules), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"options", "encryption", "", new ValueContainerString(&EncModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
{"options", "userkey1", "0", new ValueContainerLUInt(&UserKey1), DT_LUINTEGER, NoValidation},
{"options", "userkey2", "0", new ValueContainerLUInt(&UserKey2), DT_LUINTEGER, NoValidation},
{"options", "userkey3", "0", new ValueContainerLUInt(&UserKey3), DT_LUINTEGER, NoValidation},
@@ -869,7 +861,7 @@ int ServerConfig::Read(bool bail)
{"nickserv", "database", "nick.db", new ValueContainerChar(&NickDBName), DT_CHARPTR, ValidateNotEmpty},
{"nickserv", "emailregistration", "no", new ValueContainerBool(&NSEmailReg), DT_BOOLEAN, NoValidation},
{"nickserv", "prenickdatabase", "", new ValueContainerChar(&PreNickDBName), DT_CHARPTR, ValidateEmailReg},
{"nickserv", "modules", "", new ValueContainerChar(&NickCoreModules), DT_CHARPTR, NoValidation},
{"nickserv", "modules", "", new ValueContainerString(&NickCoreModules), DT_STRING, NoValidation},
{"nickserv", "forceemail", "no", new ValueContainerBool(&NSForceEmail), DT_BOOLEAN, ValidateEmailReg},
{"nickserv", "defaults", "secure memosignon memoreceive", new ValueContainerString(&NSDefaults), DT_STRING, NoValidation},
{"nickserv", "defaultlanguage", "0", new ValueContainerUInt(&NSDefLanguage), DT_UINTEGER, ValidateLanguage},
@@ -899,7 +891,7 @@ int ServerConfig::Read(bool bail)
{"chanserv", "nick", "ChanServ", new ValueContainerChar(&s_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"chanserv", "description", "Channel Registration Service", new ValueContainerChar(&desc_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"chanserv", "database", "chan.db", new ValueContainerChar(&ChanDBName), DT_CHARPTR, ValidateNotEmpty},
{"chanserv", "modules", "", new ValueContainerChar(&ChanCoreModules), DT_CHARPTR, NoValidation},
{"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(&CSMaxReg), DT_UINTEGER, NoValidation},
{"chanserv", "expire", "14d", new ValueContainerTime(&CSExpire), DT_TIME, NoValidation},
@@ -913,7 +905,7 @@ int ServerConfig::Read(bool bail)
{"chanserv", "opersonly", "no", new ValueContainerBool(&CSOpersOnly), DT_BOOLEAN, NoValidation},
{"memoserv", "nick", "MemoServ", new ValueContainerChar(&s_MemoServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"memoserv", "description", "Memo Service", new ValueContainerChar(&desc_MemoServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"memoserv", "modules", "", new ValueContainerChar(&MemoCoreModules), DT_CHARPTR, NoValidation},
{"memoserv", "modules", "", new ValueContainerString(&MemoCoreModules), DT_STRING, NoValidation},
{"memoserv", "maxmemos", "0", new ValueContainerUInt(&MSMaxMemos), DT_UINTEGER, NoValidation},
{"memoserv", "senddelay", "0", new ValueContainerTime(&MSSendDelay), DT_TIME, NoValidation},
{"memoserv", "notifyall", "no", new ValueContainerBool(&MSNotifyAll), DT_BOOLEAN, NoValidation},
@@ -921,7 +913,7 @@ int ServerConfig::Read(bool bail)
{"botserv", "nick", "", new ValueContainerChar(&s_BotServ), DT_CHARPTR | DT_NORELOAD, NoValidation},
{"botserv", "description", "Bot Service", new ValueContainerChar(&desc_BotServ), DT_CHARPTR | DT_NORELOAD, ValidateBotServ},
{"botserv", "database", "bot.db", new ValueContainerChar(&BotDBName), DT_CHARPTR, ValidateBotServ},
{"botserv", "modules", "", new ValueContainerChar(&BotCoreModules), DT_CHARPTR, NoValidation},
{"botserv", "modules", "", new ValueContainerString(&BotCoreModules), DT_STRING, NoValidation},
{"botserv", "defaults", "", new ValueContainerString(&BSDefaults), DT_STRING, NoValidation},
{"botserv", "minusers", "0", new ValueContainerUInt(&BSMinUsers), DT_UINTEGER, ValidateBotServ},
{"botserv", "badwordsmax", "0", new ValueContainerUInt(&BSBadWordsMax), DT_UINTEGER, ValidateBotServ},
@@ -933,7 +925,7 @@ int ServerConfig::Read(bool bail)
{"hostserv", "nick", "", new ValueContainerChar(&s_HostServ), DT_CHARPTR | DT_NORELOAD, NoValidation},
{"hostserv", "description", "vHost Service", new ValueContainerChar(&desc_HostServ), DT_CHARPTR | DT_NORELOAD, ValidateHostServ},
{"hostserv", "database", "hosts.db", new ValueContainerChar(&HostDBName), DT_CHARPTR, ValidateHostServ},
{"hostserv", "modules", "", new ValueContainerChar(&HostCoreModules), DT_CHARPTR, NoValidation},
{"hostserv", "modules", "", new ValueContainerString(&HostCoreModules), DT_STRING, NoValidation},
{"operserv", "nick", "OperServ", new ValueContainerChar(&s_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"operserv", "description", "Operator Service", new ValueContainerChar(&desc_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"operserv", "globalnick", "Global", new ValueContainerChar(&s_GlobalNoticer), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
@@ -941,7 +933,7 @@ int ServerConfig::Read(bool bail)
{"operserv", "database", "oper.db", new ValueContainerChar(&OperDBName), DT_CHARPTR, ValidateNotEmpty},
{"operserv", "newsdatabase", "news.db", new ValueContainerChar(&NewsDBName), DT_CHARPTR, ValidateNotEmpty},
{"operserv", "exceptiondatabase", "exception.db", new ValueContainerChar(&ExceptionDBName), DT_CHARPTR, ValidateNotEmpty},
{"operserv", "modules", "", new ValueContainerChar(&OperCoreModules), DT_CHARPTR, NoValidation},
{"operserv", "modules", "", new ValueContainerString(&OperCoreModules), DT_STRING, NoValidation},
{"operserv", "superadmin", "no", new ValueContainerBool(&SuperAdmin), DT_BOOLEAN, NoValidation},
{"operserv", "logmaxusers", "no", new ValueContainerBool(&LogMaxUsers), DT_BOOLEAN, NoValidation},
{"operserv", "autokillexpiry", "0", new ValueContainerTime(&AutokillExpiry), DT_TIME, ValidateNotZero},
@@ -1909,26 +1901,14 @@ int read_config(int reload)
}
/* Modules Autoload building... :P */
ModulesAutoload = buildStringList(Modules, &ModulesNumber);
EncModuleList =
buildStringList(EncModules ? EncModules : "", &EncModulesNumber);
HostServCoreModules =
buildStringList(HostCoreModules ? HostCoreModules : "", &HostServCoreNumber);
MemoServCoreModules =
buildStringList(MemoCoreModules ? MemoCoreModules : "", &MemoServCoreNumber);
BotServCoreModules =
buildStringList(BotCoreModules ? BotCoreModules : "", &BotServCoreNumber);
OperServCoreModules =
buildStringList(OperCoreModules ? OperCoreModules : "", &OperServCoreNumber);
ChanServCoreModules =
buildStringList(ChanCoreModules ? ChanCoreModules : "", &ChanServCoreNumber);
NickServCoreModules =
buildStringList(NickCoreModules ? NickCoreModules : "", &NickServCoreNumber);
ModulesAutoLoad = BuildStringList(!Modules.empty() ? Modules : "");
EncModuleList = BuildStringList(!EncModules.empty() ? EncModules : "");
HostServCoreModules = BuildStringList(!HostCoreModules.empty() ? HostCoreModules : "");
MemoServCoreModules = BuildStringList(!MemoCoreModules.empty() ? MemoCoreModules : "");
BotServCoreModules = BuildStringList(!BotCoreModules.empty() ? BotCoreModules : "");
OperServCoreModules = BuildStringList(!OperCoreModules.empty() ? OperCoreModules : "");
ChanServCoreModules = BuildStringList(!ChanCoreModules.empty() ? ChanCoreModules : "");
NickServCoreModules = BuildStringList(!NickCoreModules.empty() ? NickCoreModules : "");
if (LimitSessions) {
if (MaxSessionKill && !SessionAutoKillExpiry)
+1 -1
View File
@@ -408,7 +408,7 @@ class EMD5 : public Module
/* if we are NOT the first module in the list,
* we want to re-encrypt the pass with the new encryption
*/
if (stricmp(EncModuleList[0], this->name.c_str()))
if (stricmp(EncModuleList.begin()->c_str(), this->name.c_str()))
{
enc_encrypt(plaintext, strlen(password), password, PASSMAX -1 );
}
+1 -1
View File
@@ -63,7 +63,7 @@ class ENone : public Module
/* if we are NOT the first module in the list,
* we want to re-encrypt the pass with the new encryption
*/
if (stricmp(EncModuleList[0], this->name.c_str()))
if (stricmp(EncModuleList.begin()->c_str(), this->name.c_str()))
{
enc_encrypt(plaintext, strlen(password), password, PASSMAX -1 );
}
+1 -1
View File
@@ -409,7 +409,7 @@ class EOld : public Module
/* when we are NOT the first module in the list,
* we want to re-encrypt the pass with the new encryption
*/
if (stricmp(EncModuleList[0], this->name.c_str()))
if (stricmp(EncModuleList.begin()->c_str(), this->name.c_str()))
{
enc_encrypt(plaintext, strlen(password), password, PASSMAX -1 );
}
+1 -1
View File
@@ -269,7 +269,7 @@ class ESHA1 : public Module
/* when we are NOT the first module in the list,
* we want to re-encrypt the pass with the new encryption
*/
if (stricmp(EncModuleList[0], this->name.c_str()))
if (stricmp(EncModuleList.begin()->c_str(), this->name.c_str()))
{
enc_encrypt(plaintext, strlen(password), password, PASSMAX -1 );
}
+1 -1
View File
@@ -31,7 +31,7 @@ E void moduleAddHostServCmds();
void moduleAddHostServCmds()
{
ModuleManager::LoadModuleList(HostServCoreNumber, HostServCoreModules);
ModuleManager::LoadModuleList(HostServCoreModules);
}
/*************************************************************************/
+2 -2
View File
@@ -387,7 +387,7 @@ int init_primary(int ac, char **av)
}
/* Add Encryption Modules */
ModuleManager::LoadModuleList(EncModulesNumber, EncModuleList);
ModuleManager::LoadModuleList(EncModuleList);
return 0;
}
@@ -493,7 +493,7 @@ int init_secondary(int ac, char **av)
/* load any custom modules */
if (!nothird)
ModuleManager::LoadModuleList(ModulesNumber, ModulesAutoload);
ModuleManager::LoadModuleList(ModulesAutoLoad);
/* Initialize random number generator */
rand_init();
+1 -1
View File
@@ -25,7 +25,7 @@ E void rsend_notify(User *u, Memo *m, const char *chan);
/*************************************************************************/
void moduleAddMemoServCmds() {
ModuleManager::LoadModuleList(MemoServCoreNumber, MemoServCoreModules);
ModuleManager::LoadModuleList(MemoServCoreModules);
}
/*************************************************************************/
+1 -1
View File
@@ -277,7 +277,7 @@ int m_stats(const char *source, int ac, const char **av)
int m_version(const char *source, int ac, const char **av)
{
if (source) ircdproto->SendNumeric(ServerName, 351, source, "Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags,
EncModuleList[0], version_build);
EncModuleList.begin()->c_str(), version_build);
return MOD_CONT;
}
+30 -21
View File
@@ -1031,6 +1031,36 @@ char *host_resolve(char *host)
/*************************************************************************/
/** Build a string list from a source string
* @param src The source string
* @return a list of strings
*/
std::list<std::string> BuildStringList(const std::string &src)
{
spacesepstream tokens(src);
std::string token;
std::list<std::string> Ret;
while (tokens.GetToken(token))
Ret.push_back(token);
return Ret;
}
std::list<ci::string> BuildStringList(const ci::string &src)
{
spacesepstream tokens(src);
ci::string token;
std::list<ci::string> Ret;
while (tokens.GetToken(token))
Ret.push_back(token);
return Ret;
}
/*************************************************************************/
/**
* Change an unsigned string to a signed string, overwriting the original
* string.
@@ -1074,27 +1104,6 @@ void ntoa(struct in_addr addr, char *ipaddr, int len)
bytes[3]);
}
/**
* Build a string list from a given source string.
* This is usually used for parsing out values from the config file, but could
* be used for other things.
**/
char **buildStringList(const std::string &src, int *number)
{
int i = 0;
char **list = NULL;
spacesepstream tokens(src);
std::string token;
while (tokens.GetToken(token)) {
i++;
list = static_cast<char **>(realloc(list, sizeof(char *) * i));
list[i - 1] = sstrdup(token.c_str());
}
*number = i; /* always zero it, even if we have no setters */
return list;
}
/*
* strlcat and strlcpy were ripped from openssh 2.5.1p2
* They had the following Copyright info:
+6 -9
View File
@@ -15,16 +15,13 @@
std::vector<Module *> ModuleManager::EventHandlers[I_END];
void ModuleManager::LoadModuleList(int total_modules, char **module_list)
void ModuleManager::LoadModuleList(std::list<std::string> &ModuleList)
{
int idx;
Module *m;
int status = 0;
for (idx = 0; idx < total_modules; idx++) {
m = findModule(module_list[idx]);
if (!m) {
status = ModuleManager::LoadModule(module_list[idx], NULL);
}
for (std::list<std::string>::iterator it = ModuleList.begin(); it != ModuleList.end(); ++it)
{
Module *m = findModule(it->c_str());
if (!m)
ModuleManager::LoadModule(*it, NULL);
}
}
+1 -1
View File
@@ -154,7 +154,7 @@ class NickServRelease : public Timer
/* *INDENT-OFF* */
void moduleAddNickServCmds()
{
ModuleManager::LoadModuleList(NickServCoreNumber, NickServCoreModules);
ModuleManager::LoadModuleList(NickServCoreModules);
}
/* *INDENT-ON* */
/*************************************************************************/
+1 -1
View File
@@ -57,7 +57,7 @@ SListOpts szopts = { 0, NULL, &is_szline_entry_equal, &free_szline_entry };
/*************************************************************************/
/* *INDENT-OFF* */
void moduleAddOperServCmds() {
ModuleManager::LoadModuleList(OperServCoreNumber, OperServCoreModules);
ModuleManager::LoadModuleList(OperServCoreModules);
}
/* *INDENT-ON* */
+1 -1
View File
@@ -346,7 +346,7 @@ class InspIRCdProto : public IRCDProto
me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL);
SendServer(me_server);
send_cmd(NULL, "BURST");
send_cmd(ServerName, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModuleList[0], version_build);
send_cmd(ServerName, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModuleList.begin()->c_str(), version_build);
}
/* CHGIDENT */
+1 -1
View File
@@ -356,7 +356,7 @@ class InspIRCdProto : public IRCDProto
me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, TS6SID);
SendServer(me_server);
send_cmd(TS6SID, "BURST");
send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModuleList[0], version_build);
send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModuleList.begin()->c_str(), version_build);
}
/* CHGIDENT */