summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c3
-rw-r--r--src/modules/hs_request.c91
-rw-r--r--src/modules/os_ignore_db.c130
-rw-r--r--src/modules/os_info.c112
4 files changed, 145 insertions, 191 deletions
diff --git a/src/main.c b/src/main.c
index 6515bd7a0..0abc2f360 100644
--- a/src/main.c
+++ b/src/main.c
@@ -134,7 +134,7 @@ extern void expire_all()
void save_databases()
{
- send_event(EVENT_DB_SAVING, 1, EVENT_START);
+ FOREACH_MOD(I_OnSaveDatabase, OnSaveDatabase())
if (debug)
alog("debug: Saving FFF databases");
backup_databases();
@@ -152,7 +152,6 @@ void save_databases()
save_os_dbase();
save_news();
save_exceptions();
- send_event(EVENT_DB_SAVING, 1, EVENT_STOP);
}
/*************************************************************************/
diff --git a/src/modules/hs_request.c b/src/modules/hs_request.c
index d9c992a0d..c86fe331e 100644
--- a/src/modules/hs_request.c
+++ b/src/modules/hs_request.c
@@ -60,9 +60,7 @@ int my_isvalidchar(const char c);
void my_memo_lang(User *u, char *name, int z, int number, ...);
void req_send_memos(User *u, char *vHost);
-void hsreq_save_db();
void hsreq_load_db();
-int hsreqevt_db_saving(int argc, char **argv);
int hsreqevt_db_backup(int argc, char **argv);
void my_load_config();
@@ -455,8 +453,7 @@ class HSRequest : public Module
this->AddCommand(NICKSERV, new CommandNSDrop(), MOD_HEAD);
- hook = createEventHook(EVENT_DB_SAVING, hsreqevt_db_saving);
- this->AddEventHook(hook);
+ ModuleManager::Attach(I_OnSaveDatabase, this);
hook = createEventHook(EVENT_DB_BACKUP, hsreqevt_db_backup);
this->AddEventHook(hook);
@@ -730,7 +727,7 @@ class HSRequest : public Module
~HSRequest()
{
- hsreq_save_db();
+ OnSaveDatabase();
/* Clean up all open host requests */
while (hs_request_head)
@@ -738,6 +735,39 @@ class HSRequest : public Module
delete [] HSRequestDBName;
}
+
+ void OnSaveDatabase()
+ {
+ FILE *fp;
+ const char *db_filename;
+ const char *vident;
+ HostCore *current;
+
+ if (HSRequestDBName)
+ db_filename = HSRequestDBName;
+ else
+ db_filename = HSREQ_DEFAULT_DBNAME;
+
+ fp = fopen(db_filename, "w");
+ if (!fp)
+ {
+ alog("[hs_request] Unable to open database ('%s') for writing", db_filename);
+ return;
+ }
+
+ current = hs_request_head;
+ while (current)
+ {
+ vident = current->vIdent ? current->vIdent : "(null)";
+ fprintf(fp, "%s:%s:%s:%X:%s\n", current->nick, vident, current->vHost, static_cast<uint32>(current->time), current->creator);
+ current = current->next;
+ }
+
+ fclose(fp);
+
+ if (debug)
+ alog("[hs_request] Succesfully saved database");
+ }
};
void my_memo_lang(User *u, char *name, int z, int number, ...)
@@ -845,21 +875,21 @@ void hs_help(User * u)
void hsreq_load_db()
{
FILE *fp;
- const char *filename;
+ const char *db_filename;
char readbuf[1024];
char *nick, *vident, *vhost, *creator, *tmp;
int32 tmp_time;
char *buf;
if (HSRequestDBName)
- filename = HSRequestDBName;
+ db_filename = HSRequestDBName;
else
- filename = HSREQ_DEFAULT_DBNAME;
+ db_filename = HSREQ_DEFAULT_DBNAME;
- fp = fopen(filename, "r");
+ fp = fopen(db_filename, "r");
if (!fp)
{
- alog("[hs_request] Unable to open database ('%s') for reading", filename);
+ alog("[hs_request] Unable to open database ('%s') for reading", db_filename);
return;
}
@@ -906,47 +936,6 @@ void hsreq_load_db()
alog("[hs_request] Succesfully loaded database");
}
-void hsreq_save_db()
-{
- FILE *fp;
- const char *filename;
- const char *vident;
- HostCore *current;
-
- if (HSRequestDBName)
- filename = HSRequestDBName;
- else
- filename = HSREQ_DEFAULT_DBNAME;
-
- fp = fopen(filename, "w");
- if (!fp)
- {
- alog("[hs_request] Unable to open database ('%s') for writing", filename);
- return;
- }
-
- current = hs_request_head;
- while (current)
- {
- vident = current->vIdent ? current->vIdent : "(null)";
- fprintf(fp, "%s:%s:%s:%X:%s\n", current->nick, vident, current->vHost, static_cast<uint32>(current->time), current->creator);
- current = current->next;
- }
-
- fclose(fp);
-
- if (debug)
- alog("[hs_request] Succesfully saved database");
-}
-
-int hsreqevt_db_saving(int argc, char **argv)
-{
- if (argc >= 1 && !stricmp(argv[0], EVENT_START))
- hsreq_save_db();
-
- return MOD_CONT;
-}
-
int hsreqevt_db_backup(int argc, char **argv)
{
if (argc >= 1 && !stricmp(argv[0], EVENT_START))
diff --git a/src/modules/os_ignore_db.c b/src/modules/os_ignore_db.c
index bfb2bf903..f7f6da0ff 100644
--- a/src/modules/os_ignore_db.c
+++ b/src/modules/os_ignore_db.c
@@ -67,10 +67,8 @@ int new_write_db_entry(const char *key, DBFile *dbptr, const char *fmt, ...);
int new_write_db_endofblock(DBFile *dbptr);
void fill_db_ptr(DBFile *dbptr, int version, int core_version, char service[256], char filename[256]);
-int save_ignoredb(int argc, char **argv);
int backup_ignoredb(int argc, char **argv);
void load_ignore_db();
-void save_ignore_db();
void load_config();
/* ------------------------------------------------------------------------------- */
@@ -87,9 +85,7 @@ class OSIgnoreDB : public Module
this->SetVersion(VERSION);
this->SetType(SUPPORTED);
- hook = createEventHook(EVENT_DB_SAVING, save_ignoredb);
- if (this->AddEventHook(hook) != MOD_ERR_OK)
- throw ModuleException("os_ignore_db: Can't hook to EVENT_DB_SAVING event");
+ ModuleManager::Attach(I_OnSaveDatabase, this);
hook = createEventHook(EVENT_DB_BACKUP, backup_ignoredb);
if (this->AddEventHook(hook) != MOD_ERR_OK)
@@ -104,7 +100,7 @@ class OSIgnoreDB : public Module
~OSIgnoreDB()
{
/* Save the ignore database before bailing out.. */
- save_ignore_db();
+ OnSaveDatabase();
if (IgnoreDB)
delete [] IgnoreDB;
@@ -114,6 +110,62 @@ class OSIgnoreDB : public Module
{
load_config();
}
+
+ void OnSaveDatabase()
+ {
+ DBFile *dbptr = new DBFile;
+ time_t now;
+ IgnoreData *ign, *next;
+
+ now = time(NULL);
+ fill_db_ptr(dbptr, 0, IGNOREDBVERSION, s_OperServ, IgnoreDB);
+
+ /* time to backup the old db */
+ rename(IgnoreDB, dbptr->temp_name);
+
+ if (new_open_db_write(dbptr)) {
+ rename(dbptr->temp_name, IgnoreDB);
+ delete dbptr;
+ return; /* Bang, an error occurred */
+ }
+
+ /* Store the version of the DB in the DB as well...
+ * This will make stuff a lot easier if the database scheme needs to modified. */
+ new_write_db_entry("IGNORE_DB_VERSION", dbptr, "%d", IGNOREDBVERSION);
+ new_write_db_endofblock(dbptr);
+
+ /* Go over the entire ignorelist, check whether each entry is still valid
+ * and write it to the database if it is.*/
+ for (ign = ignore; ign; ign = next) {
+ next = ign->next;
+
+ if (ign->time != 0 && ign->time <= now) {
+ if (debug)
+ alog("[os_ignore_db] debug: Expiring ignore entry %s", ign->mask);
+ if (ign->prev)
+ ign->prev->next = ign->next;
+ else if (ignore == ign)
+ ignore = ign->next;
+ if (ign->next)
+ ign->next->prev = ign->prev;
+ delete [] ign->mask;
+ delete ign;
+ ign = NULL;
+ } else {
+ new_write_db_entry("m", dbptr, "%s", ign->mask);
+ new_write_db_entry("t", dbptr, "%d", ign->time);
+ new_write_db_endofblock(dbptr);
+ }
+ }
+
+ if (dbptr) {
+ new_close_db(dbptr->fptr, NULL, NULL); /* close file */
+ remove(dbptr->temp_name); /* saved successfully, no need to keep the old one */
+ delete dbptr; /* free the db struct */
+ }
+ }
+
+
};
@@ -133,18 +185,6 @@ void load_config() {
alog("[os_ignore_db] debug: Set config vars: OSIgnoreDBName='%s'", IgnoreDB);
}
-
-/**
- * When anope saves her databases, we do the same.
- **/
-int save_ignoredb(int argc, char **argv) {
- if ((argc >= 1) && (!stricmp(argv[0], "stop")))
- save_ignore_db();
-
- return MOD_CONT;
-}
-
-
/**
* When anope backs her databases up, we do the same.
**/
@@ -257,60 +297,6 @@ void load_ignore_db() {
}
-void save_ignore_db() {
- DBFile *dbptr = new DBFile;
- time_t now;
- IgnoreData *ign, *next;
-
- now = time(NULL);
- fill_db_ptr(dbptr, 0, IGNOREDBVERSION, s_OperServ, IgnoreDB);
-
- /* time to backup the old db */
- rename(IgnoreDB, dbptr->temp_name);
-
- if (new_open_db_write(dbptr)) {
- rename(dbptr->temp_name, IgnoreDB);
- delete dbptr;
- return; /* Bang, an error occurred */
- }
-
- /* Store the version of the DB in the DB as well...
- * This will make stuff a lot easier if the database scheme needs to modified. */
- new_write_db_entry("IGNORE_DB_VERSION", dbptr, "%d", IGNOREDBVERSION);
- new_write_db_endofblock(dbptr);
-
- /* Go over the entire ignorelist, check whether each entry is still valid
- * and write it to the database if it is.*/
- for (ign = ignore; ign; ign = next) {
- next = ign->next;
-
- if (ign->time != 0 && ign->time <= now) {
- if (debug)
- alog("[os_ignore_db] debug: Expiring ignore entry %s", ign->mask);
- if (ign->prev)
- ign->prev->next = ign->next;
- else if (ignore == ign)
- ignore = ign->next;
- if (ign->next)
- ign->next->prev = ign->prev;
- delete [] ign->mask;
- delete ign;
- ign = NULL;
- } else {
- new_write_db_entry("m", dbptr, "%s", ign->mask);
- new_write_db_entry("t", dbptr, "%d", ign->time);
- new_write_db_endofblock(dbptr);
- }
- }
-
- if (dbptr) {
- new_close_db(dbptr->fptr, NULL, NULL); /* close file */
- remove(dbptr->temp_name); /* saved successfully, no need to keep the old one */
- delete dbptr; /* free the db struct */
- }
-}
-
-
/* ------------------------------------------------------------------------------- */
/**************************************************************************
diff --git a/src/modules/os_info.c b/src/modules/os_info.c
index 5a9edbed9..22d45a61b 100644
--- a/src/modules/os_info.c
+++ b/src/modules/os_info.c
@@ -46,7 +46,6 @@ void mMainChanHelp(User *u);
void mMainNickHelp(User *u);
int mLoadData();
-int mSaveData(int argc, char **argv);
int mBackupData(int argc, char **argv);
int mLoadConfig();
@@ -304,8 +303,7 @@ class OSInfo : public Module
status = this->AddCommand(CHANSERV, new CommandCSOInfo(), MOD_HEAD);
status = this->AddCommand(CHANSERV, new CommandCSInfo(), MOD_TAIL);
- hook = createEventHook(EVENT_DB_SAVING, mSaveData);
- status = this->AddEventHook(hook);
+ ModuleManager::Attach(I_OnSaveDatabase, this);
hook = createEventHook(EVENT_DB_BACKUP, mBackupData);
status = this->AddEventHook(hook);
@@ -532,8 +530,7 @@ class OSInfo : public Module
~OSInfo()
{
- char *av[1];
-
+ OnSaveDatabase();
for (int i = 0; i < 1024; ++i)
{
/* Remove the nick Cores */
@@ -547,9 +544,8 @@ class OSInfo : public Module
}
}
}
- av[0] = sstrdup(EVENT_START);
- mSaveData(1, av);
- delete [] av[0];
+
+ // XXX: shouldn't we also shrink ChanInfo?
if (OSInfoDBName)
delete [] OSInfoDBName;
@@ -563,6 +559,48 @@ class OSInfo : public Module
if (ret)
alog("os_info.c: ERROR: An error has occured while reloading the configuration file");
}
+
+ void OnSaveDatabase()
+ {
+ ChannelInfo *ci = NULL;
+ NickCore *nc = NULL;
+ int i = 0;
+ int ret = 0;
+ FILE *out;
+
+ if (!(out = fopen(OSInfoDBName, "w")))
+ {
+ alog("os_info: ERROR: can not open the database file!");
+ ircdproto->SendGlobops(s_OperServ, "os_info: ERROR: can not open the database file!");
+ ret = 1;
+ }
+ else
+ {
+ for (i = 0; i < 1024; ++i)
+ {
+ for (nc = nclists[i]; nc; nc = nc->next)
+ {
+ /* If we have any info on this user */
+ char *c;
+ if (nc->GetExt("os_info", c))
+ fprintf(out, "N %s %s\n", nc->display, c);
+ }
+ }
+
+ for (i = 0; i < 256; ++i)
+ {
+ for (ci = chanlists[i]; ci; ci = ci->next)
+ {
+ /* 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);
+ }
+ }
+ fclose(out);
+ }
+ }
+
};
/*************************************************************************/
@@ -629,64 +667,6 @@ int mLoadData()
}
/**
- * Save all our data to our db file
- * First walk through the nick CORE list, and any nick core which has
- * oper info attached to it, write to the file.
- * Next do the same again for ChannelInfos
- * @return 0 for success
- **/
-int mSaveData(int argc, char **argv)
-{
- ChannelInfo *ci = NULL;
- NickCore *nc = NULL;
- int i = 0;
- int ret = 0;
- FILE *out;
-
- if (argc >= 1)
- {
- if (!stricmp(argv[0], EVENT_START))
- {
- if (!(out = fopen(OSInfoDBName, "w")))
- {
- alog("os_info: ERROR: can not open the database file!");
- ircdproto->SendGlobops(s_OperServ, "os_info: ERROR: can not open the database file!");
- ret = 1;
- }
- else
- {
- for (i = 0; i < 1024; ++i)
- {
- for (nc = nclists[i]; nc; nc = nc->next)
- {
- /* If we have any info on this user */
- char *c;
- if (nc->GetExt("os_info", c))
- fprintf(out, "N %s %s\n", nc->display, c);
- }
- }
-
- for (i = 0; i < 256; ++i)
- {
- for (ci = chanlists[i]; ci; ci = ci->next)
- {
- /* 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);
- }
- }
- fclose(out);
- }
- }
- else
- ret = 0;
- }
-
- return ret;
-}
-
-/**
* Backup our databases using the commands provided by Anope
* @return MOD_CONT
**/