summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-19 00:48:29 +0000
committercyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-19 00:48:29 +0000
commit0f069f0e8becfd1770a6ce396ead7aa67e3bde06 (patch)
treeede474534d89b32bcdcc24d58e5cca6c427d6176 /src
parent1a2fdff0c653562ebde967850875e5445bc0c5ae (diff)
Converted modules to use ConfigReader to access new config parser.
Added all module directives to new config. Removed references to old config parser (not sure if I got them all, though). git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1756 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r--src/config.c244
-rw-r--r--src/modules.c93
-rw-r--r--src/modules/hs_request.c34
-rw-r--r--src/modules/ns_maxemail.c17
-rw-r--r--src/modules/ns_noop_convert.c22
-rw-r--r--src/modules/os_ignore_db.c61
-rw-r--r--src/modules/os_info.c25
7 files changed, 59 insertions, 437 deletions
diff --git a/src/config.c b/src/config.c
index 1bc0005cd..036144553 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1420,18 +1420,6 @@ bool ValueItem::GetBool()
/*************************************************************************/
-/* Deprecated directive (dep_) and value checking (chk_) functions: */
-
-/* Hey, there are no left! -GD */
-
-/*************************************************************************/
-
-/* Yay, no more core directives using the old config! -- CyberBotX
-Directive directives[] = {
-};*/
-
-/*************************************************************************/
-
/* Print an error message to the log (and the console, if open). */
void error(int linenum, const char *message, ...)
@@ -1458,185 +1446,6 @@ void error(int linenum, const char *message, ...)
/*************************************************************************/
-/* Parse a configuration line. Return 1 on success; otherwise, print an
- * appropriate error message and return 0. Destroys the buffer by side
- * effect.
- */
-
-int parse_directive(Directive * d, char *dir, int ac, char *av[MAXPARAMS],
- int linenum, int reload, char *s)
-{
- int retval = 1;
- int i;
- long val;
- int myoptind;
-
- if (stricmp(dir, d->name) != 0)
- return 1;
- myoptind = 0;
- for (i = 0; i < MAXPARAMS && d->params[i].type != PARAM_NONE; i++) {
- if (reload && !(d->params[i].flags & PARAM_RELOAD))
- continue;
-
- if (d->params[i].type == PARAM_SET) {
- *(int *) d->params[i].ptr = 1;
- continue;
- }
-
- /* Should we remove PARAM_DEPRECATED because it's
- * useless right now? -GD */
- if (d->params[i].type == PARAM_DEPRECATED) {
- void (*func) (void);
- error(linenum, "Deprecated directive `%s' used", d->name);
- func = (void (*)(void)) (d->params[i].ptr);
- func(); /* For clarity */
- continue;
- }
- if (myoptind >= ac) {
- if (!(d->params[i].flags & PARAM_OPTIONAL)) {
- error(linenum, "Not enough parameters for `%s'", d->name);
- retval = 0;
- }
- break;
- }
- switch (d->params[i].type) {
- case PARAM_INT:
- val = strtol(av[myoptind++], &s, 0);
- if (*s) {
- error(linenum,
- "%s: Expected an integer for parameter %d",
- d->name, myoptind);
- retval = 0;
- break;
- }
- *(int *) d->params[i].ptr = val;
- break;
- case PARAM_POSINT:
- val = strtol(av[myoptind++], &s, 0);
- if (*s || val <= 0) {
- error(linenum,
- "%s: Expected a positive integer for parameter %d",
- d->name, myoptind);
- retval = 0;
- break;
- }
- if (errno == ERANGE && val == LONG_MAX) {
- /* well the true top off is 2,147,483,647 but lets not give them the real top */
- error(linenum,
- "%s: paramter %d is to large, reduce this value (0 to 2,147,483,646)",
- d->name, myoptind);
- }
- *(int *) d->params[i].ptr = val;
- break;
- case PARAM_PORT:
- val = strtol(av[myoptind++], &s, 0);
- if (*s) {
- error(linenum,
- "%s: Expected a port number for parameter %d",
- d->name, myoptind);
- retval = 0;
- break;
- }
- if (val < 1 || val > 65535) {
- error(linenum,
- "Port numbers must be in the range 1..65535");
- retval = 0;
- break;
- }
- *(int *) d->params[i].ptr = val;
- break;
- case PARAM_STRING:
-/* if (reload && *(char **)d->params[i].ptr)
- free(*(char **)d->params[i].ptr); */
- *(char **) d->params[i].ptr = sstrdup(av[myoptind++]);
- if (!d->params[i].ptr) {
- error(linenum, "%s: Out of memory", d->name);
- return 0;
- }
- break;
- case PARAM_TIME:
- val = dotime(av[myoptind++]);
- if (val < 0) {
- error(linenum,
- "%s: Expected a time value for parameter %d",
- d->name, myoptind);
- retval = 0;
- break;
- }
- *(int *) d->params[i].ptr = val;
- break;
- default:
- error(linenum, "%s: Unknown type %d for param %d",
- d->name, d->params[i].type, i + 1);
- retval = 0; /* don't bother continuing--something's bizarre */
- break;
- }
- }
- return retval;;
-}
-
-
-int parse(char *buf, int linenum, int reload)
-{
- char *s, *t, *dir;
- unsigned int n;
- int retval = 1;
- int ac = 0;
- char *av[MAXPARAMS];
-
- dir = strtok(buf, " \t\r\n");
- s = strtok(NULL, "");
- if (s) {
- while (isspace(*s))
- s++;
- while (*s) {
- if (ac >= MAXPARAMS) {
- error(linenum, "Warning: too many parameters (%d max)",
- MAXPARAMS);
- break;
- }
- t = s;
- if (*s == '"') {
- t++;
- s++;
- while (*s && *s != '"') {
- if (*s == '\\' && s[1] != 0)
- s++;
- s++;
- }
- if (!*s)
- error(linenum,
- "Warning: unterminated double-quoted string");
- else
- *s++ = 0;
- } else {
- s += strcspn(s, " \t\r\n");
- if (*s)
- *s++ = 0;
- }
- av[ac++] = t;
- while (isspace(*s))
- s++;
- }
- }
-
- if (!dir)
- return 1;
-
- /*for (n = 0; n < lenof(directives); n++) {
- Directive *d = &directives[n];
- retval = parse_directive(d, dir, ac, av, linenum, reload, s);
- if (!retval) {
- break;
- }
- }*/
-
- return retval;
-}
-
-
-/*************************************************************************/
-
#define CHECK(v) do { \
if (!v) { \
error(0, #v " missing"); \
@@ -1662,59 +1471,12 @@ int parse(char *buf, int linenum, int reload)
int read_config(int reload)
{
- FILE *config;
- int linenum = 0, retval = 1;
- char buf[1024], *s;
+ int retval = 1;
+ char *s;
int defconCount = 0;
- /*if (reload) {
- unsigned int i, n;*/
-
- /* Reset all the reloadable settings */
-
- /*for (n = 0; n < lenof(directives); n++) {
- Directive *d = &directives[n];
-
- for (i = 0; i < MAXPARAMS && d->params[i].type != PARAM_NONE;
- i++) {
- if (!(d->params[i].flags & PARAM_RELOAD))
- continue;
-
- if (d->params[i].type == PARAM_SET
- || d->params[i].type == PARAM_INT
- || d->params[i].type == PARAM_POSINT
- || d->params[i].type == PARAM_TIME) {
- *(int *) d->params[i].ptr = 0;
- } else if (d->params[i].type == PARAM_STRING) {
- if (*(char **) d->params[i].ptr)
- free(*(char **) d->params[i].ptr);
- (*(char **) d->params[i].ptr) = NULL;
- }
- }
- }
- }*/
-
retval = serverConfig.Read(reload ? false : true);
if (!retval) return 0; // Temporary until most of the below is modified to use the new parser -- CyberBotX
- config = fopen(SERVICES_CONF, "r");
- if (!config) {
- log_perror("Can't open " SERVICES_CONF);
- if (!nofork && isatty(2)) {
- if (!reload)
- perror("Can't open " SERVICES_CONF);
- else
- alog("Can't open %s", SERVICES_CONF);
- }
- return 0;
- }
- while (fgets(buf, sizeof(buf), config)) {
- linenum++;
- if (*buf == '#' || *buf == '\r' || *buf == '\n')
- continue;
- if (!parse(buf, linenum, reload))
- retval = 0;
- }
- fclose(config);
if (!reload) {
if (LocalHost) {
@@ -1722,7 +1484,7 @@ int read_config(int reload)
for (; curr_uplink != end_uplink; ++curr_uplink) {
Uplink *this_uplink = *curr_uplink;
if (!stricmp(LocalHost, this_uplink->host) && LocalPort == this_uplink->port) {
- printf("\n<serverinfo:localhost> matches an <uplink:host> entry (%s)\nand <serverinfo:localport> matches an <uplink:port> entry (%s).\nThis will fail, you must make sure they are different.\n", this_uplink->host, this_uplink->port);
+ printf("\n<serverinfo:localhost> matches an <uplink:host> entry (%s)\nand <serverinfo:localport> matches an <uplink:port> entry (%d).\nThis will fail, you must make sure they are different.\n", this_uplink->host, this_uplink->port);
retval = 0;
}
}
diff --git a/src/modules.c b/src/modules.c
index 34025a9af..492745497 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -1225,99 +1225,6 @@ void updateProtectDetails(const char *level_info_protect_word,
}
/**
- * Deal with modules who want to lookup config directives!
- * @param h The Directive to lookup in the config file
- * @return 1 on success, 0 on error
- **/
-int moduleGetConfigDirective(Directive * d)
-{
- FILE *config;
- char *dir = NULL;
- char buf[1024];
- char *directive;
- int linenum = 0;
- int ac = 0;
- char *av[MAXPARAMS];
- char *str = NULL;
- char *s = NULL;
- char *t = NULL;
- int retval = 1;
-
- config = fopen(SERVICES_CONF, "r");
- if (!config) {
- alog("Can't open %s", SERVICES_CONF);
- return 0;
- }
- while (fgets(buf, sizeof(buf), config)) {
- linenum++;
- if (*buf == '#' || *buf == '\r' || *buf == '\n') {
- continue;
- }
- dir = myStrGetOnlyToken(buf, '\t', 0);
- if (dir) {
- str = myStrGetTokenRemainder(buf, '\t', 1);
- } else {
- dir = myStrGetOnlyToken(buf, ' ', 0);
- if (dir || (dir = myStrGetOnlyToken(buf, '\n', 0))) {
- str = myStrGetTokenRemainder(buf, ' ', 1);
- } else {
- continue;
- }
- }
- if (dir) {
- directive = normalizeBuffer(dir);
- } else {
- continue;
- }
-
- if (stricmp(directive, d->name) == 0) {
- if (str) {
- s = str;
- while (isspace(*s))
- s++;
- while (*s) {
- if (ac >= MAXPARAMS) {
- alog("module error: too many config. params");
- break;
- }
- t = s;
- if (*s == '"') {
- t++;
- s++;
- while (*s && *s != '"') {
- if (*s == '\\' && s[1] != 0)
- s++;
- s++;
- }
- if (!*s)
- alog("module error: Warning: unterminated double-quoted string");
- else
- *s++ = 0;
- } else {
- s += strcspn(s, " \t\r\n");
- if (*s)
- *s++ = 0;
- }
- av[ac++] = t;
- while (isspace(*s))
- s++;
- }
- }
- retval = parse_directive(d, directive, ac, av, linenum, 0, s);
- }
- if (directive) {
- free(directive);
- }
- }
- if (dir)
- free(dir);
- if (str)
- free(str);
- fclose(config);
- return retval;
-}
-
-/**
* Send a notice to the user in the correct language, or english.
* @param source Who sends the notice
* @param u The user to send the message to
diff --git a/src/modules/hs_request.c b/src/modules/hs_request.c
index e9ad605a8..5eb7cc7f3 100644
--- a/src/modules/hs_request.c
+++ b/src/modules/hs_request.c
@@ -110,7 +110,7 @@ class HSRequest : public Module
c = createCommand("list", hs_do_list_out, is_services_oper, -1, -1, -1, -1, -1);
this->AddCommand(HOSTSERV, c, MOD_HEAD);
- c = createCommand("drop", ns_do_drop, NULL, -1, -1, -1, -1, -1);
+ c = createCommand("drop", ns_do_drop, NULL, -1, -1, -1, -1, -1);
this->AddCommand(NICKSERV, c, MOD_HEAD);
hook = createEventHook(EVENT_DB_SAVING, hsreqevt_db_saving);
@@ -945,29 +945,15 @@ int hsreqevt_db_backup(int argc, char **argv)
void my_load_config(void)
{
- int i;
- char *tmp = NULL;
-
- Directive confvalues[][1] = {
- {{"HSRequestMemoUser",
- {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoUser}}}},
- {{"HSRequestMemoOper",
- {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoOper}}}},
- {{"HSRequestMemoSetters",
- {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoSetters}}}},
- {{"HSRequestDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}}}
- };
-
- for (i = 0; i < 4; i++)
- moduleGetConfigDirective(confvalues[i]);
-
- if (tmp) {
- if (HSRequestDBName)
- free(HSRequestDBName);
- HSRequestDBName = sstrdup(tmp);
- } else {
- HSRequestDBName = sstrdup(HSREQ_DEFAULT_DBNAME);
- }
+ ConfigReader config;
+ HSRequestMemoUser = config.ReadFlag("hs_request", "memouser", "no", 0);
+ HSRequestMemoOper = config.ReadFlag("hs_request", "memooper", "no", 0);
+ HSRequestMemoSetters = config.ReadFlag("hs_request", "memosetters", "no", 0);
+ std::string tmp = config.ReadValue("hs_request", "database", HSREQ_DEFAULT_DBNAME, 0);
+
+ if (HSRequestDBName)
+ free(HSRequestDBName);
+ HSRequestDBName = sstrdup(tmp.c_str());
if (debug)
alog("debug: [hs_request] Set config vars: MemoUser=%d MemoOper=%d MemoSetters=%d DBName='%s'", HSRequestMemoUser, HSRequestMemoOper, HSRequestMemoSetters, HSRequestDBName);
diff --git a/src/modules/ns_maxemail.c b/src/modules/ns_maxemail.c
index b2f82eb41..29773dfe5 100644
--- a/src/modules/ns_maxemail.c
+++ b/src/modules/ns_maxemail.c
@@ -1,12 +1,12 @@
/* ns_maxemail.c - Limit the amount of times an email address
* can be used for a NickServ account.
- *
+ *
* (C) 2003-2008 Anope Team
* Contact us at info@anope.org
- *
+ *
* Included in the Anope module pack since Anope 1.7.9
* Anope Coder: GeniusDex <geniusdex@anope.org>
- *
+ *
* Please read COPYING and README for further details.
*
* Send any bug reports to the Anope Coder, as he will be able
@@ -168,10 +168,10 @@ int my_ns_set(User * u)
cur_buffer = moduleGetLastBuffer();
set = myStrGetToken(cur_buffer, ' ', 0);
-
+
if (!set)
return MOD_CONT;
-
+
if (stricmp(set, "email") != 0) {
free(set);
return MOD_CONT;
@@ -198,11 +198,8 @@ int my_event_reload(int argc, char **argv)
void my_load_config(void)
{
- Directive confvalues[] = {
- {"NSEmailMax", {{PARAM_INT, PARAM_RELOAD, &NSEmailMax}}}
- };
-
- moduleGetConfigDirective(confvalues);
+ ConfigReader config;
+ NSEmailMax = config.ReadInteger("ns_maxemail", "maxemails", "0", 0, false);
if (debug)
alog("debug: [ns_maxemail] NSEmailMax set to %d", NSEmailMax);
diff --git a/src/modules/ns_noop_convert.c b/src/modules/ns_noop_convert.c
index 6a2a29b09..bc9a59d02 100644
--- a/src/modules/ns_noop_convert.c
+++ b/src/modules/ns_noop_convert.c
@@ -88,7 +88,7 @@ class NSNOOPConvert : public Module
/*************************************************************************/
-/**
+/**
* Load data from the db file, and populate the autoop setting
* @return 0 for success
**/
@@ -126,31 +126,21 @@ int mLoadData(void)
/*************************************************************************/
-/**
+/**
* Load the configuration directives from Services configuration file.
* @return 0 for success
**/
int mLoadConfig(int argc, char **argv)
{
- char *tmp = NULL;
-
- Directive d[] = {
- {"NSAutoOPDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}},
- };
-
- moduleGetConfigDirective(d);
+ ConfigReader config;
+ std::string tmp = config.ReadValue("ns_noop_convert", "database", DEFAULT_DB_NAME, 0);
if (NSAutoOPDBName)
free(NSAutoOPDBName);
- if (tmp) {
- NSAutoOPDBName = tmp;
- } else {
- NSAutoOPDBName = sstrdup(DEFAULT_DB_NAME);
- alog("ns_noop: NSAutoOPDBName is not defined in Services configuration file, using default %s", NSAutoOPDBName);
- }
+ NSAutoOPDBName = sstrdup(tmp.c_str());
- if (!NSAutoOPDBName) {
+ if (tmp.empty()) {
alog("ns_noop: FATAL: Can't read required configuration directives!");
return MOD_STOP;
} else {
diff --git a/src/modules/os_ignore_db.c b/src/modules/os_ignore_db.c
index 064dfa380..2984b3b20 100644
--- a/src/modules/os_ignore_db.c
+++ b/src/modules/os_ignore_db.c
@@ -76,11 +76,11 @@ int reload_config(int argc, char **argv);
/* ------------------------------------------------------------------------------- */
-class OSIgnoreDB : public Module
-{
- public:
- OSIgnoreDB(const std::string &modname, const std::string &creator) : Module(modname, creator)
- {
+class OSIgnoreDB : public Module
+{
+ public:
+ OSIgnoreDB(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ {
EvtHook *hook;
IgnoreDB = NULL;
@@ -89,53 +89,44 @@ class OSIgnoreDB : public Module
this->SetType(SUPPORTED);
hook = createEventHook(EVENT_RELOAD, reload_config);
- if (this->AddEventHook(hook) != MOD_ERR_OK)
+ if (this->AddEventHook(hook) != MOD_ERR_OK)
throw ModuleException("os_ignore_db: Can't hook to EVENT_RELOAD event");
-
+
hook = createEventHook(EVENT_DB_SAVING, save_ignoredb);
- if (this->AddEventHook(hook) != MOD_ERR_OK)
+ if (this->AddEventHook(hook) != MOD_ERR_OK)
throw ModuleException("os_ignore_db: Can't hook to EVENT_DB_SAVING event");
hook = createEventHook(EVENT_DB_BACKUP, backup_ignoredb);
- if (this->AddEventHook(hook) != MOD_ERR_OK)
+ if (this->AddEventHook(hook) != MOD_ERR_OK)
throw ModuleException("os_ignore_db: Can't hook to EVENT_DB_BACKUP event");
load_config();
/* Load the ignore database and re-add them to anopes ignorelist. */
load_ignore_db();
- }
-
- ~OSIgnoreDB()
- {
+ }
+
+ ~OSIgnoreDB()
+ {
/* Save the ignore database before bailing out.. */
save_ignore_db();
if (IgnoreDB)
- free(IgnoreDB);
- }
+ free(IgnoreDB);
+ }
};
-
-
+
+
/* ------------------------------------------------------------------------------- */
void load_config(void) {
- int i;
-
- Directive confvalues[][1] = {
- {{"OSIgnoreDBName", {{PARAM_STRING, PARAM_RELOAD, &IgnoreDB}}}},
- };
+ ConfigReader config;
+ std::string tmp = config.ReadValue("os_ignore", "database", DefIgnoreDB, 0);
if (IgnoreDB)
free(IgnoreDB);
- IgnoreDB = NULL;
-
- for (i = 0; i < 1; i++)
- moduleGetConfigDirective(confvalues[i]);
-
- if (!IgnoreDB)
- IgnoreDB = sstrdup(DefIgnoreDB);
+ IgnoreDB = sstrdup(tmp.c_str());
if (debug)
alog("[os_ignore_db] debug: Set config vars: OSIgnoreDBName='%s'", IgnoreDB);
@@ -215,14 +206,14 @@ void load_ignore_db(void) {
free(dbptr);
return;
} else if (retval == DB_READ_BLOCKEND) { /* DB_READ_BLOCKEND */
- /* Check if we have everything to add the ignore..
+ /* Check if we have everything to add the ignore..
* We shouldn't bother with already expired ignores either.. */
if (mask && (expiry_time > time(NULL) || expiry_time == 0)) {
/* We should check for double entries.. */
for (ign = ignore; ign; ign = ign->next)
if (!stricmp(ign->mask, mask))
break;
-
+
if (!ign) {
/* Create a fresh entry.. */
ign = (IgnoreData *)scalloc(sizeof(*ign), 1);
@@ -236,7 +227,7 @@ void load_ignore_db(void) {
if (debug)
alog("[os_ignore_db] debug: Added new ignore entry for %s", mask);
} else {
- /* Update time on existing entry.
+ /* Update time on existing entry.
* The longest expiry time survives.. */
if (expiry_time == 0 || ign->time == 0)
ign->time = 0;
@@ -244,7 +235,7 @@ void load_ignore_db(void) {
ign->time = expiry_time;
}
}
-
+
if (mask) free(mask);
mask = NULL;
expiry_time = time(NULL);
@@ -532,6 +523,6 @@ void fill_db_ptr(DBFile *dbptr, int version, int core_version,
strcpy(dbptr->filename, filename);
snprintf(dbptr->temp_name, 261, "%s.temp", filename);
return;
-}
+}
-MODULE_INIT("os_ignore_db", OSIgnoreDB)
+MODULE_INIT("os_ignore_db", OSIgnoreDB)
diff --git a/src/modules/os_info.c b/src/modules/os_info.c
index 4adc4e0a2..731573f37 100644
--- a/src/modules/os_info.c
+++ b/src/modules/os_info.c
@@ -323,7 +323,7 @@ class OSInfo : public Module
~OSInfo()
{
char *av[1];
-
+
for (int i = 0; i < 1024; i++)
{
/* Remove the nick Cores */
@@ -336,7 +336,7 @@ class OSInfo : public Module
nc->Shrink("os_modinfo");
}
}
- }
+ }
av[0] = sstrdup(EVENT_START);
mSaveData(1, av);
free(av[0]);
@@ -401,7 +401,7 @@ int myAddNickInfo(User * u)
free(c);
na->nc->Shrink("os_info");
}
-
+
moduleNoticeLang(s_NickServ, u, OINFO_DEL_SUCCESS, nick);
/* NickCore not found! */
} else {
@@ -666,7 +666,7 @@ int mSaveData(int argc, char **argv)
/* If we have any info on this channel */
char *c;
if (ci->GetExt("os_info", c))
- {
+ {
fprintf(out, "C %s %s\n", ci->name, c);
}
}
@@ -698,24 +698,13 @@ int mBackupData(int argc, char **argv)
**/
int mLoadConfig(void)
{
- char *tmp = NULL;
-
- Directive directivas[] = {
- {"OSInfoDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}},
- };
-
- Directive *d = &directivas[0];
- moduleGetConfigDirective(d);
+ ConfigReader config;
+ std::string tmp = config.ReadValue("os_info", "database", DEFAULT_DB_NAME, 0);
if (OSInfoDBName)
free(OSInfoDBName);
- if (tmp) {
- OSInfoDBName = tmp;
- } else {
- OSInfoDBName = sstrdup(DEFAULT_DB_NAME);
- alog("os_info: OSInfoDBName is not defined in Services configuration file, using default %s", OSInfoDBName);
- }
+ OSInfoDBName = sstrdup(tmp.c_str());
alog("os_info: Directive OSInfoDBName loaded (%s)...", OSInfoDBName);