summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-12-14 00:56:58 +0000
committerAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-12-14 00:56:58 +0000
commitd4af97a7a7bac9fb6dba1b223700fcdc614ae024 (patch)
treed07a57e1b5d9129b6b24c68a6f7635de41ea92dd /src
parent710355fd2c40c4babfd627b6f09296c12b227e19 (diff)
Ripped out old databases
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2699 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r--src/botserv.c120
-rw-r--r--src/chanserv.c471
-rw-r--r--src/core/os_news.c93
-rw-r--r--src/datafiles.c563
-rw-r--r--src/hostserv.c117
-rw-r--r--src/init.c39
-rw-r--r--src/main.c14
-rw-r--r--src/nickserv.c362
-rw-r--r--src/operserv.c199
-rw-r--r--src/sessions.c94
10 files changed, 5 insertions, 2067 deletions
diff --git a/src/botserv.c b/src/botserv.c
index ab20b0852..9a8229d6c 100644
--- a/src/botserv.c
+++ b/src/botserv.c
@@ -461,126 +461,6 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
/*************************************************************************/
-/* Load/save data files. */
-
-
-#define SAFE(x) do { \
- if ((x) < 0) { \
- if (!forceload) \
- fatal("Read error on %s", Config.BotDBName); \
- failed = 1; \
- break; \
- } \
-} while (0)
-
-void load_bs_dbase()
-{
- dbFILE *f;
- int c, ver;
- uint16 tmp16;
- uint32 tmp32;
- BotInfo *bi;
- int failed = 0;
-
- if (!(f = open_db(Config.s_BotServ, Config.BotDBName, "r", BOT_VERSION)))
- return;
-
- ver = get_file_version(f);
-
- while (!failed && (c = getc_db(f)) != 0) {
- char *s;
-
- if (c != 1)
- fatal("Invalid format in %s %d", Config.BotDBName, c);
-
- SAFE(read_string(&s, f));
- bi = new BotInfo(s);
- delete [] s;
- SAFE(read_string(&bi->user, f));
- SAFE(read_string(&bi->host, f));
- SAFE(read_string(&bi->real, f));
- if (ver >= 10) {
- SAFE(read_int16(&tmp16, f));
- //bi->flags |= tmp16;
- }
- SAFE(read_int32(&tmp32, f));
- bi->created = tmp32;
- SAFE(read_int16(&tmp16, f));
- bi->chancount = tmp16;
-
- /* Fixes bug #1080, services bot names may have been
- * changed in the config and different from database
- * names
- */
- if (Config.s_ChanServ && bi->HasFlag(BI_CHANSERV) && strcmp(bi->nick, Config.s_ChanServ))
- bi->ChangeNick(Config.s_ChanServ);
- else if (Config.s_BotServ && bi->HasFlag(BI_BOTSERV) && strcmp(bi->nick, Config.s_BotServ))
- bi->ChangeNick(Config.s_BotServ);
- else if (Config.s_HostServ && bi->HasFlag(BI_HOSTSERV) && strcmp(bi->nick, Config.s_HostServ))
- bi->ChangeNick(Config.s_HostServ);
- else if (Config.s_OperServ && bi->HasFlag(BI_OPERSERV) && strcmp(bi->nick, Config.s_OperServ))
- bi->ChangeNick(Config.s_OperServ);
- else if (Config.s_MemoServ && bi->HasFlag(BI_MEMOSERV) && strcmp(bi->nick, Config.s_MemoServ))
- bi->ChangeNick(Config.s_MemoServ);
- else if (Config.s_NickServ && bi->HasFlag(BI_NICKSERV) && strcmp(bi->nick, Config.s_NickServ))
- bi->ChangeNick(Config.s_NickServ);
- else if (Config.s_GlobalNoticer && bi->HasFlag(BI_GLOBAL) && strcmp(bi->nick, Config.s_GlobalNoticer))
- bi->ChangeNick(Config.s_GlobalNoticer);
- }
-
- close_db(f);
-}
-
-#undef SAFE
-
-/*************************************************************************/
-
-#define SAFE(x) do { \
- if ((x) < 0) { \
- restore_db(f); \
- log_perror("Write error on %s", Config.BotDBName); \
- if (time(NULL) - lastwarn > Config.WarningTimeout) { \
- ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.BotDBName, \
- strerror(errno)); \
- lastwarn = time(NULL); \
- } \
- return; \
- } \
-} while (0)
-
-void save_bs_dbase()
-{
- dbFILE *f;
- BotInfo *bi;
- static time_t lastwarn = 0;
- int i;
-
- if (!(f = open_db(Config.s_BotServ, Config.BotDBName, "w", BOT_VERSION)))
- return;
-
- for (i = 0; i < 256; i++) {
- for (bi = botlists[i]; bi; bi = bi->next) {
- SAFE(write_int8(1, f));
- SAFE(write_string(bi->nick, f));
- SAFE(write_string(bi->user, f));
- SAFE(write_string(bi->host, f));
- SAFE(write_string(bi->real, f));
- //SAFE(write_int16(bi->flags, f));
- SAFE(write_int16(0, f));
- SAFE(write_int32(bi->created, f));
- SAFE(write_int16(bi->chancount, f));
- }
- }
- SAFE(write_int8(0, f));
-
- close_db(f);
-
-}
-
-#undef SAFE
-
-/*************************************************************************/
-
/* Inserts a bot in the bot list. I can't be much explicit mh? */
void insert_bot(BotInfo * bi)
diff --git a/src/chanserv.c b/src/chanserv.c
index b09f9e808..c85efc259 100644
--- a/src/chanserv.c
+++ b/src/chanserv.c
@@ -303,477 +303,6 @@ void chanserv(User * u, char *buf)
/*************************************************************************/
-/* Load/save data files. */
-
-
-#define SAFE(x) do { \
- if ((x) < 0) { \
- if (!forceload) \
- fatal("Read error on %s", Config.ChanDBName); \
- failed = 1; \
- break; \
- } \
-} while (0)
-
-void load_cs_dbase()
-{
- dbFILE *f;
- int ver, c;
- unsigned i, j;
- ChannelInfo *ci, **last, *prev;
- int failed = 0;
-
- if (!(f = open_db(Config.s_ChanServ, Config.ChanDBName, "r", CHAN_VERSION)))
- return;
-
- ver = get_file_version(f);
-
- if (ver != 16)
- fatal("Invalid database version! (I only understand %d)", CHAN_VERSION);
-
- for (i = 0; i < 256 && !failed; i++) {
- uint16 tmp16;
- uint32 tmp32;
- unsigned int read;
- int n_levels;
- char *s;
- NickAlias *na;
-
- last = &chanlists[i];
- prev = NULL;
- while ((c = getc_db(f)) != 0) {
- if (c != 1)
- fatal("Invalid format in %s", Config.ChanDBName);
- char channame[CHANMAX];
- SAFE(read = read_buffer(channame, f));
- ci = new ChannelInfo(channame);
- *last = ci;
- last = &ci->next;
- ci->prev = prev;
- prev = ci;
- SAFE(read_string(&s, f));
- if (s) {
- ci->founder = findcore(s);
- delete [] s;
- } else
- ci->founder = NULL;
- if (ver >= 7) {
- SAFE(read_string(&s, f));
- if (s) {
- if (ver >= 13)
- ci->successor = findcore(s);
- else {
- na = findnick(s);
- if (na)
- ci->successor = na->nc;
- else
- ci->successor = NULL;
- }
- delete [] s;
- } else
- ci->successor = NULL;
- } else {
- ci->successor = NULL;
- }
-
- char nothing[PASSMAX];
- SAFE(read = read_buffer(nothing, f)); // XXX founder pass was removed.. just here so it works
-
- SAFE(read_string(&ci->desc, f));
- if (!ci->desc)
- ci->desc = sstrdup("");
- SAFE(read_string(&ci->url, f));
- SAFE(read_string(&ci->email, f));
- SAFE(read_int32(&tmp32, f));
- ci->time_registered = tmp32;
- SAFE(read_int32(&tmp32, f));
- ci->last_used = tmp32;
- SAFE(read_string(&ci->last_topic, f));
- SAFE(read = read_buffer(ci->last_topic_setter, f));
- SAFE(read_int32(&tmp32, f));
- ci->last_topic_time = tmp32;
- //SAFE(read_int32(&ci->flags, f));
- SAFE(read_int32(&tmp32, f));
-
- /* Leaveops cleanup */
-// if (ver <= 13 && (ci->HasFlag()0x00000020))
-// ci->UnsetFlag()0x00000020;
- /* Temporary flags cleanup */
- ci->UnsetFlag(CI_INHABIT);
-
- SAFE(read_string(&ci->forbidby, f));
- SAFE(read_string(&ci->forbidreason, f));
- SAFE(read_int16(&tmp16, f));
- ci->bantype = tmp16;
- SAFE(read_int16(&tmp16, f));
- n_levels = tmp16;
- ci->levels = new int16[CA_SIZE];
- reset_levels(ci);
- for (j = 0; j < n_levels; j++) {
- SAFE(read_int16(&tmp16, f));
- if (j < CA_SIZE)
- ci->levels[j] = static_cast<int16>(tmp16);
- }
-
- uint16 accesscount = 0;
- SAFE(read_int16(&accesscount, f));
- if (accesscount) {
- for (j = 0; j < accesscount; j++) {
- uint16 in_use = 0;
- SAFE(read_int16(&in_use, f));
- if (in_use) {
- uint16 level;
- SAFE(read_int16(&level, f));
- NickCore *nc;
- SAFE(read_string(&s, f));
- if (s) {
- nc = findcore(s);
- delete [] s;
- }
- else
- nc = NULL;
- uint32 last_seen;
- SAFE(read_int32(&last_seen, f));
- //SAFE(read_string(&s, f));
- if (nc)
- {
- //std::string creator = s ? s : "";
- std::string creator = "";
- ci->AddAccess(nc, level, creator, last_seen);
- }
- }
- }
- }
-
- uint16 akickcount = 0;
- NickCore *nc;
- SAFE(read_int16(&akickcount, f));
- if (akickcount) {
- for (j = 0; j < akickcount; ++j)
- {
- uint16 flags;
- SAFE(read_int16(&flags, f));
- SAFE(read_string(&s, f));
- char *akickreason;
- SAFE(read_string(&akickreason, f));
- char *akickcreator;
- SAFE(read_string(&akickcreator, f));
- SAFE(read_int32(&tmp32, f));
-
- if (flags & AK_ISNICK)
- {
- nc = findcore(s);
- if (!nc)
- continue;
- ci->AddAkick(akickcreator, nc, akickreason ? akickreason : "", tmp32);
- }
- else
- ci->AddAkick(akickcreator, s, akickreason ? akickreason : "", tmp32);
- }
- }
-
- //SAFE(read_int32(&ci->mlock_on, f));
- //SAFE(read_int32(&ci->mlock_off, f));
- // Clearly this doesn't work
- SAFE(read_int32(&tmp32, f));
- SAFE(read_int32(&tmp32, f));
-
- SAFE(read_int32(&tmp32, f));
- if (tmp32)
- {
- std::ostringstream limit;
- limit << tmp32;
- ci->SetMLock(CMODE_LIMIT, true, limit.str());
- }
-
- SAFE(read_string(&s, f));
- if (s)
- {
- ci->SetMLock(CMODE_KEY, true, std::string(s));
- delete [] s;
- }
-
- SAFE(read_string(&s, f));
- if (s)
- {
- ci->SetMLock(CMODE_FLOOD, true, std::string(s));
- delete [] s;
- }
-
- SAFE(read_string(&s, f));
- if (s)
- {
- ci->SetMLock(CMODE_REDIRECT, true, std::string(s));
- delete [] s;
- }
-
- SAFE(read_int16(&tmp16, f));
- if (tmp16) ci->memos.memos.resize(tmp16);
- SAFE(read_int16(&tmp16, f));
- ci->memos.memomax = static_cast<int16>(tmp16);
- if (!ci->memos.memos.empty()) {
- for (j = 0; j < ci->memos.memos.size(); j++) {
- ci->memos.memos[j] = new Memo;
- Memo *memo = ci->memos.memos[j];
- SAFE(read_int32(&memo->number, f));
- //SAFE(read_int16(&memo->flags, f));
- SAFE(read_int16(&tmp16, f));
- SAFE(read_int32(&tmp32, f));
- memo->time = tmp32;
- SAFE(read = read_buffer(memo->sender, f));
- SAFE(read_string(&memo->text, f));
- }
- }
-
- SAFE(read_string(&ci->entry_message, f));
-
- ci->c = NULL;
-
- /* BotServ options */
- int n_ttb;
-
- SAFE(read_string(&s, f));
- if (s) {
- ci->bi = findbot(s);
- delete [] s;
- } else
- ci->bi = NULL;
-
- SAFE(read_int32(&tmp32, f));
- //ci->botflags = tmp32;
- SAFE(read_int16(&tmp16, f));
- n_ttb = tmp16;
- ci->ttb = new int16[2 * TTB_SIZE];
- for (j = 0; j < n_ttb; j++) {
- SAFE(read_int16(&tmp16, f));
- if (j < TTB_SIZE)
- ci->ttb[j] = static_cast<int16>(tmp16);
- }
- for (j = n_ttb; j < TTB_SIZE; j++)
- ci->ttb[j] = 0;
- SAFE(read_int16(&tmp16, f));
- ci->capsmin = tmp16;
- SAFE(read_int16(&tmp16, f));
- ci->capspercent = tmp16;
- SAFE(read_int16(&tmp16, f));
- ci->floodlines = tmp16;
- SAFE(read_int16(&tmp16, f));
- ci->floodsecs = tmp16;
- SAFE(read_int16(&tmp16, f));
- ci->repeattimes = tmp16;
-
- SAFE(read_int16(&tmp16, f));
- if (tmp16) {
- for (j = 0; j < tmp16; j++) {
- uint16 inuse;
- SAFE(read_int16(&inuse, f));
- //if (ci->badwords[j].in_use) {
- char *badword;
- SAFE(read_string(&badword, f));
- //SAFE(read_int16(&ci->badwords[j].type, f));
- SAFE(read_int16(&tmp16, f));
- //ci->badwords[j].type = BW_ANY; // for now
- ci->AddBadWord(badword, BW_ANY);
- delete [] badword;
- // }
- }
- }
- } /* while (getc_db(f) != 0) */
-
- *last = NULL;
-
- } /* for (i) */
-
- close_db(f);
-
- /* Check for non-forbidden channels with no founder.
- Makes also other essential tasks. */
- for (i = 0; i < 256; i++) {
- ChannelInfo *next;
- for (ci = chanlists[i]; ci; ci = next) {
- next = ci->next;
- if (!(ci->HasFlag(CI_FORBIDDEN)) && !ci->founder) {
- alog("%s: database load: Deleting founderless channel %s",
- Config.s_ChanServ, ci->name);
- delete ci;
- continue;
- }
- }
- }
-}
-
-#undef SAFE
-
-/*************************************************************************/
-
-#define SAFE(x) do { \
- if ((x) < 0) { \
- restore_db(f); \
- log_perror("Write error on %s", Config.ChanDBName); \
- if (time(NULL) - lastwarn > Config.WarningTimeout) { \
- ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.ChanDBName, \
- strerror(errno)); \
- lastwarn = time(NULL); \
- } \
- return; \
- } \
-} while (0)
-
-void save_cs_dbase()
-{
- dbFILE *f;
- unsigned i, j;
- ChannelInfo *ci;
- static time_t lastwarn = 0;
- std::string param;
-
- if (!(f = open_db(Config.s_ChanServ, Config.ChanDBName, "w", CHAN_VERSION)))
- return;
-
- for (i = 0; i < 256; i++) {
- int16 tmp16;
- unsigned int written;
-
- for (ci = chanlists[i]; ci; ci = ci->next) {
- SAFE(write_int8(1, f));
- SAFE(written = write_buffer(ci->name, f));
- if (ci->founder)
- SAFE(write_string(ci->founder->display, f));
- else
- SAFE(write_string(NULL, f));
- if (ci->successor)
- SAFE(write_string(ci->successor->display, f));
- else
- SAFE(write_string(NULL, f));
-
- char nothing[PASSMAX]; /* founder passwords were removed! */
- strcpy(nothing, "nothing\0");
- SAFE(written = write_buffer(nothing, f));
-
- SAFE(write_string(ci->desc, f));
- SAFE(write_string(ci->url, f));
- SAFE(write_string(ci->email, f));
- SAFE(write_int32(ci->time_registered, f));
- SAFE(write_int32(ci->last_used, f));
- SAFE(write_string(ci->last_topic, f));
- SAFE(written = write_buffer(ci->last_topic_setter, f));
- SAFE(write_int32(ci->last_topic_time, f));
- //SAFE(write_int32(ci->flags, f));
- SAFE(write_int32(0, f));
- SAFE(write_string(ci->forbidby, f));
- SAFE(write_string(ci->forbidreason, f));
- SAFE(write_int16(ci->bantype, f));
-
- tmp16 = CA_SIZE;
- SAFE(write_int16(tmp16, f));
- for (j = 0; j < CA_SIZE; j++)
- SAFE(write_int16(ci->levels[j], f));
-
- SAFE(write_int16(ci->GetAccessCount(), f));
- for (j = 0; j < ci->GetAccessCount(); j++) {
- ChanAccess *access = ci->GetAccess(j);
- if (!access->in_use)
- continue;
- SAFE(write_int16(access->in_use, f));
- SAFE(write_int16(access->level, f));
- SAFE(write_string(access->nc->display, f));
- SAFE(write_int32(access->last_seen, f));
- //SAFE(write_string(access->creator.c_str(), f));
- }
-
- SAFE(write_int16(ci->GetAkickCount(), f));
- for (j = 0; j < ci->GetAkickCount(); ++j)
- {
- AutoKick *akick = ci->GetAkick(j);
- //SAFE(write_int16(akick->flags, f));
- SAFE(write_int16(0, f));
- if (akick->HasFlag(AK_ISNICK))
- SAFE(write_string(akick->nc->display, f));
- else
- SAFE(write_string(akick->mask.c_str(), f));
- SAFE(write_string(akick->reason.c_str(), f));
- SAFE(write_string(akick->creator.c_str(), f));
- SAFE(write_int32(akick->addtime, f));
- }
-
- //SAFE(write_int32(ci->mlock_on, f));
- //SAFE(write_int32(ci->mlock_off, f));
- // Clearly this doesnt work
- SAFE(write_int32(NULL, f));
- SAFE(write_int32(NULL, f));
-
- ci->GetParam(CMODE_LIMIT, &param);
- SAFE(write_int32(param.empty() ? NULL : atoi(param.c_str()), f));
-
- ci->GetParam(CMODE_KEY, &param);
- SAFE(write_string(param.empty() ? NULL : param.c_str(), f));
-
- ci->GetParam(CMODE_FLOOD, &param);
- SAFE(write_string(param.empty() ? NULL : param.c_str(), f));
-
- ci->GetParam(CMODE_REDIRECT, &param);
- SAFE(write_string(param.empty() ? NULL : param.c_str(), f));
-
- SAFE(write_int16(ci->memos.memos.size(), f));
- SAFE(write_int16(ci->memos.memomax, f));
- for (j = 0; j < ci->memos.memos.size(); j++) {
- Memo *memo = ci->memos.memos[j];
- SAFE(write_int32(memo->number, f));
- SAFE(write_int16(0, f));
- //SAFE(write_int16(memo->flags, f));
- SAFE(write_int32(memo->time, f));
- SAFE(written = write_buffer(memo->sender, f));
- SAFE(write_string(memo->text, f));
- }
-
- SAFE(write_string(ci->entry_message, f));
-
- if (ci->bi)
- SAFE(write_string(ci->bi->nick, f));
- else
- SAFE(write_string(NULL, f));
-
- //SAFE(write_int32(ci->botflags, f));
- SAFE(write_int32(0, f));
-
- tmp16 = TTB_SIZE;
- SAFE(write_int16(tmp16, f));
- for (j = 0; j < TTB_SIZE; j++)
- SAFE(write_int16(ci->ttb[j], f));
-
- SAFE(write_int16(ci->capsmin, f));
- SAFE(write_int16(ci->capspercent, f));
- SAFE(write_int16(ci->floodlines, f));
- SAFE(write_int16(ci->floodsecs, f));
- SAFE(write_int16(ci->repeattimes, f));
-
- //SAFE(write_int16(ci->bwcount, f));
- SAFE(write_int16(ci->GetBadWordCount(), f));
- for (j = 0; j < ci->GetBadWordCount(); j++) {
- BadWord *bw = ci->GetBadWord(j);
- /*SAFE(write_int16(ci->badwords[j].in_use, f));
- if (ci->badwords[j].in_use) {
- SAFE(write_string(ci->badwords[j].word, f));
- SAFE(write_int16(ci->badwords[j].type, f));
- }*/
- SAFE(write_int16(1, f));
- SAFE(write_string(bw->word.c_str(), f));
- SAFE(write_int16(0, f));
- }
- } /* for (chanlists[i]) */
-
- SAFE(write_int8(0, f));
-
- } /* for (i) */
-
- close_db(f);
-
-}
-
-#undef SAFE
-
-/*************************************************************************/
-
/* Check the current modes on a channel; if they conflict with a mode lock,
* fix them.
*/
diff --git a/src/core/os_news.c b/src/core/os_news.c
index e2cf52538..05006501d 100644
--- a/src/core/os_news.c
+++ b/src/core/os_news.c
@@ -14,7 +14,6 @@
/*************************************************************************/
#include "module.h"
-#include "pseudo.h" // Remove once new dbs are added
/* List of messages for each news type. This simplifies message sending. */
@@ -77,93 +76,6 @@ struct newsmsgs msgarray[] = {
}
};
-#define SAFE(x) do { \
- if ((x) < 0) { \
- if (!forceload) \
- fatal("Read error on %s", Config.NewsDBName); \
- break; \
- } \
-} while (0)
-
-void load_news()
-{
- dbFILE *f;
- int i;
- uint16 n, type;
- uint32 tmp32;
- NewsItem *news;
- char *text;
-
- if (!(f = open_db(Config.s_OperServ, Config.NewsDBName, "r", NEWS_VERSION)))
- return;
- switch (i = get_file_version(f)) {
- case 9:
- case 8:
- case 7:
- SAFE(read_int16(&n, f));
- if (!n) {
- close_db(f);
- return;
- }
- for (i = 0; i < n; i++) {
- news = new NewsItem;
-
- SAFE(read_int16(&type, f));
- news->type = static_cast<NewsType>(type);
- SAFE(read_int32(&news->num, f));
- SAFE(read_string(&text, f));
- news->Text = text;
- delete [] text;
- SAFE(read_buffer(news->who, f));
- SAFE(read_int32(&tmp32, f));
- news->time = tmp32;
-
- News.push_back(news);
- }
- break;
-
- default:
- fatal("Unsupported version (%d) on %s", i, Config.NewsDBName);
- } /* switch (ver) */
-
- close_db(f);
-}
-
-#undef SAFE
-
-#define SAFE(x) do { \
- if ((x) < 0) { \
- restore_db(f); \
- log_perror("Write error on %s", Config.NewsDBName); \
- if (time(NULL) - lastwarn > Config.WarningTimeout) { \
- ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.NewsDBName, \
- strerror(errno)); \
- lastwarn = time(NULL); \
- } \
- return; \
- } \
-} while (0)
-
-void save_news()
-{
- dbFILE *f;
- static time_t lastwarn = 0;
-
- if (!(f = open_db(Config.s_OperServ, Config.NewsDBName, "w", NEWS_VERSION)))
- return;
- SAFE(write_int16(News.size(), f));
- for (unsigned i = 0; i < News.size(); i++) {
- SAFE(write_int16(News[i]->type, f));
- SAFE(write_int32(News[i]->num, f));
- SAFE(write_string(News[i]->Text.c_str(), f));
- SAFE(write_buffer(News[i]->who, f));
- SAFE(write_int32(News[i]->time, f));
- }
- close_db(f);
-}
-
-#undef SAFE
-
static void DisplayNews(User *u, NewsType Type)
{
int msg;
@@ -495,7 +407,6 @@ class OSNews : public Module
~OSNews()
{
- save_news();
}
void OnOperServHelp(User *u)
@@ -521,14 +432,10 @@ class OSNews : public Module
void OnSaveDatabase()
{
- /* This needs to be destroyed when new dbs are added... */
- save_news();
}
void OnPostLoadDatabases()
{
- /* This needs to be destroyed when new dbs are added... */
- load_news();
}
};
diff --git a/src/datafiles.c b/src/datafiles.c
index a051704be..920c0e5ef 100644
--- a/src/datafiles.c
+++ b/src/datafiles.c
@@ -23,529 +23,6 @@ static time_t lastwarn = 0;
/*************************************************************************/
/**
- * Return the version number on the file. Return 0 if there is no version
- * number or the number doesn't make sense (i.e. less than 1 or greater
- * than FILE_VERSION).
- * @param f dbFile Struct Member
- * @return int 0 if failure, 1 > is the version number
- */
-int get_file_version(dbFILE * f)
-{
- FILE *fp = f->fp;
- int version =
- fgetc(fp) << 24 | fgetc(fp) << 16 | fgetc(fp) << 8 | fgetc(fp);
- if (ferror(fp)) {
- log_perror("Error reading version number on %s", f->filename);
- return 0;
- } else if (feof(fp)) {
- alog("Error reading version number on %s: End of file detected",
- f->filename);
- return 0;
- } else if (version < 1) {
- alog("Invalid version number (%d) on %s", version, f->filename);
- return 0;
- }
- return version;
-}
-
-/*************************************************************************/
-
-/**
- * Write the current version number to the file.
- * @param f dbFile Struct Member
- * @return 0 on error, 1 on success.
- */
-int write_file_version(dbFILE * f, uint32 version)
-{
- FILE *fp = f->fp;
- if (fputc(version >> 24 & 0xFF, fp) < 0 ||
- fputc(version >> 16 & 0xFF, fp) < 0 ||
- fputc(version >> 8 & 0xFF, fp) < 0 ||
- fputc(version & 0xFF, fp) < 0) {
- log_perror("Error writing version number on %s", f->filename);
- return 0;
- }
- return 1;
-}
-
-/*************************************************************************/
-
-/**
- * Open the database for reading
- * @param service If error whom to return the error as
- * @param filename File to open as the database
- * @return dbFile struct
- */
-static dbFILE *open_db_read(const char *service, const char *filename)
-{
- dbFILE *f;
- FILE *fp;
-
- f = new dbFILE;
- if (!f) {
- log_perror("Can't read %s database %s", service, filename);
- if (time(NULL) - lastwarn > Config.WarningTimeout) {
- ircdproto->SendGlobops(NULL,
- "Write error on %s: Memory allocation failed",
- filename);
- lastwarn = time(NULL);
- }
- return NULL;
- }
- strscpy(f->filename, filename, sizeof(f->filename));
- f->mode = 'r';
- fp = fopen(f->filename, "rb");
- if (!fp) {
- int errno_save = errno;
- if (errno != ENOENT)
- log_perror("Can not read %s database %s", service,
- f->filename);
- if (time(NULL) - lastwarn > Config.WarningTimeout) {
- ircdproto->SendGlobops(NULL, "Write error on %s: %s", f->filename,
- strerror(errno));
- lastwarn = time(NULL);
- }
- delete f;
- errno = errno_save;
- return NULL;
- }
- f->fp = fp;
- f->backupfp = NULL;
- return f;
-}
-
-/*************************************************************************/
-
-/**
- * Open the database for writting
- * @param service If error whom to return the error as
- * @param filename File to open as the database
- * @param version Database Version
- * @return dbFile struct
- */
-static dbFILE *open_db_write(const char *service, const char *filename,
- uint32 version)
-{
- dbFILE *f;
- int fd;
-#ifdef _WIN32
- char buffer[_MAX_PATH];
- char win32filename[MAXPATHLEN];
-
- /* Get the current working directory: */
- if (_getcwd(buffer, _MAX_PATH) == NULL) {
- alog("Warning: Unable to set Current working directory");
- }
-#endif
-
- f = new dbFILE;
- if (!f) {
- log_perror("Can not read %s database %s", service, filename);
- return NULL;
- }
- strscpy(f->filename, filename, sizeof(f->filename));
-#ifndef _WIN32
- filename = f->filename;
-#else
- snprintf(win32filename, sizeof(win32filename), "%s\\%s", buffer,
- f->filename);
- filename = win32filename;
-#endif
- f->mode = 'w';
-
- *f->backupname = 0;
- snprintf(f->backupname, sizeof(f->backupname), "%s.save", filename);
- if (!*f->backupname || strcmp(f->backupname, filename) == 0) {
- int errno_save = errno;
- alog("Opening %s database %s for write: Filename too long",
- service, filename);
- delete f;
- errno = errno_save;
- return NULL;
- }
-#ifndef _WIN32
- unlink(filename);
-#else
- DeleteFile(filename);
-#endif
- f->backupfp = fopen(filename, "rb");
-#ifdef _WIN32
- if (!MoveFileExA(filename, f->backupname, MOVEFILE_COPY_ALLOWED)
- && GetLastError() != ENOENT) {
- int errno_save = GetLastError();
-#else
- if (rename(filename, f->backupname) < 0 && errno != ENOENT) {
- int errno_save = errno;
-#endif
-
- static int walloped = 0;
- if (!walloped) {
- walloped++;
- ircdproto->SendGlobops(NULL, "Can not back up %s database %s",
- service, filename);
- }
-#ifdef _WIN32
- if (debug) {
- if (errno == ENOENT) {
- alog("debug: Error %d (ENOENT) : the file or directory does not exist", errno);
- } else if (errno == EACCES) {
- alog("debug: Error %d (EACCES) : error while attempting to access file", errno);
- } else {
- alog("debug: Error %d", errno);
- }
- }
-#else
- if (debug) {
- alog("debug: Error %d", errno);
- }
-#endif
- errno = errno_save;
- log_perror("Can not back up %s database %s", service, filename);
- if (!Config.NoBackupOkay) {
- if (f->backupfp)
- fclose(f->backupfp);
- delete f;
- errno = errno_save;
- return NULL;
- }
- *f->backupname = 0;
- }
-#ifndef _WIN32
- unlink(filename);
-#else
- DeleteFile(filename);
-#endif
- /* Use open() to avoid people sneaking a new file in under us */
-#ifndef _WIN32
- fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
-#else
- fd = open(filename, O_WRONLY | O_CREAT | O_EXCL | _O_BINARY, 0666);
-#endif
- f->fp = fdopen(fd, "wb"); /* will fail and return NULL if fd < 0 */
- if (!f->fp || !write_file_version(f, version)) {
- int errno_save = errno;
- static int walloped = 0;
- if (!walloped) {
- walloped++;
- ircdproto->SendGlobops(NULL, "Can't write to %s database %s",
- service, filename);
- }
- errno = errno_save;
- log_perror("Can't write to %s database %s", service, filename);
- if (f->fp) {
- fclose(f->fp);
-#ifndef _WIN32
- unlink(filename);
-#else
- DeleteFile(filename);
-#endif
- }
- if (*f->backupname && rename(f->backupname, filename) < 0)
- log_perror("Cannot restore backup copy of %s", filename);
-
- /* Then the Lord said unto Moses, thou shalt free what thou hast malloced
- * -- codemastr */
- delete f;
- errno = errno_save;
- return NULL;
- }
- return f;
-}
-
-/*************************************************************************/
-
-/**
- * Open a database file for reading (*mode == 'r') or writing (*mode == 'w').
- * Return the stream pointer, or NULL on error. When opening for write, it
- * is an error for rename() to return an error (when backing up the original
- * file) other than ENOENT, if NO_BACKUP_OKAY is not defined; it is an error
- * if the version number cannot be written to the file; and it is a fatal
- * error if opening the file for write fails and the backup was successfully
- * made but cannot be restored.
- * @param service If error whom to return the error as
- * @param filename File to open as the database
- * @param mode Mode for writting or reading
- * @param version Database Version
- * @return dbFile struct
- */
-dbFILE *open_db(const char *service, const char *filename,
- const char *mode, uint32 version)
-{
- if (*mode == 'r') {
- return open_db_read(service, filename);
- } else if (*mode == 'w') {
- return open_db_write(service, filename, version);
- } else {
- errno = EINVAL;
- return NULL;
- }
-}
-
-/*************************************************************************/
-
-/**
- * Restore the database file to its condition before open_db(). This is
- * identical to close_db() for files open for reading; however, for files
- * open for writing, we first attempt to restore any backup file before
- * closing files.
- * @param dbFile struct
- * @return void
- */
-void restore_db(dbFILE * f)
-{
- int errno_save = errno;
-
- if (f->mode == 'w') {
- int ok = 0; /* Did we manage to restore the old file? */
- errno = errno_save = 0;
- if (*f->backupname && strcmp(f->backupname, f->filename) != 0) {
- if (rename(f->backupname, f->filename) == 0)
- ok = 1;
- }
- if (!ok && f->backupfp) {
- char buf[1024];
- unsigned int i;
- ok = 1;
- if (fseek(f->fp, 0, SEEK_SET) < 0)
- ok = 0;
- while (ok && (i = fread(buf, 1, sizeof(buf), f->backupfp)) > 0) {
- if (fwrite(buf, 1, i, f->fp) != i)
- ok = 0;
- }
- if (ok) {
- fflush(f->fp);
- ftruncate(fileno(f->fp), ftell(f->fp));
- }
- }
- if (!ok && errno > 0)
- log_perror("Unable to restore backup of %s", f->filename);
- errno_save = errno;
- if (f->backupfp)
- fclose(f->backupfp);
- if (*f->backupname)
-#ifndef _WIN32
- unlink(f->backupname);
-#else
- DeleteFile(f->backupname);
-#endif
- }
- fclose(f->fp);
- if (!errno_save)
- errno_save = errno;
- delete f;
- errno = errno_save;
-}
-
-/*************************************************************************/
-
-/**
- * Close a database file. If the file was opened for write, remove the
- * backup we (may have) created earlier.
- * @param dbFile struct
- * @return void
- */
-void close_db(dbFILE * f)
-{
- if (f->mode == 'w' && *f->backupname
- && strcmp(f->backupname, f->filename) != 0) {
- if (f->backupfp)
- fclose(f->backupfp);
-#ifndef _WIN32
- unlink(f->backupname);
-#else
- DeleteFile(f->backupname);
-#endif
- }
- fclose(f->fp);
- delete f;
-}
-
-/*************************************************************************/
-
-/**