diff options
author | Adam <Adam@anope.org> | 2016-11-09 18:35:15 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-11-09 18:35:15 -0500 |
commit | be17c8118762c7c928239a026359e4fa0fd36f00 (patch) | |
tree | 41d21cac0d392d82541227f470ceaf67d1d7e4d4 | |
parent | 32b311b183443e11d26f13cd425e12406ffbfa76 (diff) |
Change default database to sqlite, begin 2.0 db_flatfile support
-rw-r--r-- | data/anope.example.conf | 43 | ||||
-rw-r--r-- | data/modules.example.conf | 4 | ||||
-rw-r--r-- | include/modules/botserv/badwords.h | 2 | ||||
-rw-r--r-- | include/modules/operserv/dns.h | 4 | ||||
-rw-r--r-- | include/modules/operserv/forbid.h | 2 | ||||
-rw-r--r-- | include/modules/operserv/news.h | 2 | ||||
-rw-r--r-- | modules/botserv/badwords.cpp | 4 | ||||
-rw-r--r-- | modules/database/flatfile.cpp | 838 | ||||
-rw-r--r-- | modules/database/sql.cpp | 2 | ||||
-rw-r--r-- | modules/nickserv/cert.cpp | 2 | ||||
-rw-r--r-- | modules/operserv/dns.cpp | 8 | ||||
-rw-r--r-- | modules/operserv/forbid.cpp | 4 | ||||
-rw-r--r-- | modules/operserv/news.cpp | 4 |
13 files changed, 744 insertions, 175 deletions
diff --git a/data/anope.example.conf b/data/anope.example.conf index 8c9be4f64..29b8e2481 100644 --- a/data/anope.example.conf +++ b/data/anope.example.conf @@ -1058,11 +1058,13 @@ mail } /* - * [RECOMMENDED] db_flatfile + * [DEPRECATED] db_flatfile * - * This is the default flatfile database format. + * This is the default database format from Anope 2.0. This module only loads these databases, + * and will NOT save them. You should only use this to upgrade old databases to a newer database + * format. */ -module +#module { name = "database/flatfile" @@ -1070,40 +1072,15 @@ module * The database name db_flatfile should use */ database = "anope.db" - - /* - * Sets the number of days backups of databases are kept. If you don't give it, - * or if you set it to 0, Anope won't backup the databases. - * - * NOTE: Anope must run 24 hours a day for this feature to work. - * - * This directive is optional, but recommended. - */ - keepbackups = 3 - - /* - * Allows Anope to continue file write operations (i.e. database saving) - * even if the original file cannot be backed up. Enabling this option may - * allow Anope to continue operation under conditions where it might - * otherwise fail, such as a nearly-full disk. - * - * NOTE: Enabling this option can cause irrecoverable data loss under some - * conditions, so make CERTAIN you know what you're doing when you enable it! - * - * This directive is optional, and you are discouraged against enabling it. - */ - #nobackupokay = yes } /* - * db_sql - * - * db_sql allows saving and loading databases using one of the SQL engines. - * This module reads and writes to SQL in real time. Changes to the SQL tables - * will be immediately reflected into Anope. + * [RECOMMENDED] db_sql * + * db_sql allows using one of the SQL engines as a database backend, and is + * the default database module. */ -#module +module { name = "database/sql" @@ -1116,7 +1093,7 @@ module /* * An optional prefix to prepended to the name of each created table. */ - #prefix = "anope_db_" + #prefix = "anope_" } /* diff --git a/data/modules.example.conf b/data/modules.example.conf index b75fcd550..0f22a7c72 100644 --- a/data/modules.example.conf +++ b/data/modules.example.conf @@ -647,7 +647,7 @@ module { name = "help" } * * This module allows other modules to use SQLite. */ -#module +module { name = "sqlite" @@ -658,7 +658,7 @@ module { name = "help" } name = "sqlite/main" /* The database name, it will be created if it does not exist. */ - database = "anope.db" + database = "anope.sqlite3" } } diff --git a/include/modules/botserv/badwords.h b/include/modules/botserv/badwords.h index 09f8040ae..2371aaecc 100644 --- a/include/modules/botserv/badwords.h +++ b/include/modules/botserv/badwords.h @@ -48,7 +48,7 @@ class BadWord : public Serialize::Object virtual void SetWord(const Anope::string &) anope_abstract; virtual BadWordType GetType() anope_abstract; - virtual void SetType(const BadWordType &) anope_abstract; + virtual void SetType(BadWordType) anope_abstract; }; class BadWords : public Service diff --git a/include/modules/operserv/dns.h b/include/modules/operserv/dns.h index af413a92c..33e717a0f 100644 --- a/include/modules/operserv/dns.h +++ b/include/modules/operserv/dns.h @@ -44,10 +44,10 @@ class DNSServer : public Serialize::Object virtual void SetName(const Anope::string &) anope_abstract; virtual unsigned int GetLimit() anope_abstract; - virtual void SetLimit(const unsigned int &) anope_abstract; + virtual void SetLimit(unsigned int) anope_abstract; virtual bool GetPooled() anope_abstract; - virtual void SetPool(const bool &) anope_abstract; + virtual void SetPool(bool) anope_abstract; }; class DNSZoneMembership : public Serialize::Object diff --git a/include/modules/operserv/forbid.h b/include/modules/operserv/forbid.h index 2b87d707d..34f5cdc13 100644 --- a/include/modules/operserv/forbid.h +++ b/include/modules/operserv/forbid.h @@ -50,7 +50,7 @@ class ForbidData : public Serialize::Object virtual void SetExpires(const time_t &) anope_abstract; virtual ForbidType GetType() anope_abstract; - virtual void SetType(const ForbidType &) anope_abstract; + virtual void SetType(ForbidType) anope_abstract; }; class ForbidService : public Service diff --git a/include/modules/operserv/news.h b/include/modules/operserv/news.h index 46c720d3d..c6bbe5cbc 100644 --- a/include/modules/operserv/news.h +++ b/include/modules/operserv/news.h @@ -34,7 +34,7 @@ class NewsItem : public Serialize::Object using Serialize::Object::Object; virtual NewsType GetNewsType() anope_abstract; - virtual void SetNewsType(const NewsType &) anope_abstract; + virtual void SetNewsType(NewsType) anope_abstract; virtual Anope::string GetText() anope_abstract; virtual void SetText(const Anope::string &) anope_abstract; diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp index 998ccc7f8..1348c8aff 100644 --- a/modules/botserv/badwords.cpp +++ b/modules/botserv/badwords.cpp @@ -39,7 +39,7 @@ class BadWordImpl : public BadWord void SetWord(const Anope::string &w) override; BadWordType GetType() override; - void SetType(const BadWordType &t) override; + void SetType(BadWordType t) override; }; class BadWordsType : public Serialize::Type<BadWordImpl> @@ -82,7 +82,7 @@ BadWordType BadWordImpl::GetType() return Get(&BadWordsType::type); } -void BadWordImpl::SetType(const BadWordType &t) +void BadWordImpl::SetType(BadWordType t) { Set(&BadWordsType::type, t); } diff --git a/modules/database/flatfile.cpp b/modules/database/flatfile.cpp index 7e2d5e949..a130ed0ed 100644 --- a/modules/database/flatfile.cpp +++ b/modules/database/flatfile.cpp @@ -18,194 +18,786 @@ */ #include "module.h" +#include "modules/botserv/badwords.h" +#include "modules/chanserv/access.h" +#include "modules/chanserv/entrymsg.h" +#include "modules/chanserv/log.h" +#include "modules/chanserv/set_misc.h" +#include "modules/chanserv/suspend.h" +#include "modules/nickserv/access.h" +#include "modules/nickserv/ajoin.h" +#include "modules/nickserv/cert.h" +#include "modules/nickserv/set_misc.h" +#include "modules/nickserv/suspend.h" +#include "modules/operserv/forbid.h" +#include "modules/operserv/news.h" +#include "modules/operserv/info.h" class DBFlatFile : public Module , public EventHook<Event::LoadDatabase> - , public EventHook<Event::SaveDatabase> { - /* Day the last backup was on */ - int last_day; - /* Backup file names */ - std::map<Anope::string, std::list<Anope::string> > backups; - bool loaded; - - void BackupDatabase() + void LoadAccount(const Anope::string &type, std::map<Anope::string, Anope::string> &data) { - tm *tm = localtime(&Anope::CurTime); + NickServ::Account *account = Serialize::New<NickServ::Account *>(); - if (tm->tm_mday != last_day) - { - last_day = tm->tm_mday; + if (account == nullptr) + return; - std::set<Anope::string> dbs; - dbs.insert(Config->GetModule(this)->Get<Anope::string>("database", "anope.db")); + account->SetDisplay(data["display"]); + account->SetPassword(data["pass"]); + account->SetEmail(data["email"]); + account->SetLanguage(data["language"]); - for (Serialize::TypeBase *stype : Serialize::TypeBase::GetTypes()) + spacesepstream sep = data["access"]; + for (Anope::string token; sep.GetToken(token);) + { + NickAccess *access = Serialize::New<NickAccess *>(); + if (access != nullptr) { - if (stype->GetOwner()) - dbs.insert("module_" + stype->GetOwner()->name + ".db"); + access->SetAccount(account); + access->SetMask(token); } + } + MemoServ::MemoInfo *memos = account->GetMemos(); + if (memos != nullptr) + { + try + { + int16_t memomax = convertTo<int16_t>(data["memomax"]); + memos->SetMemoMax(memomax); + } + catch (const ConvertException &) { } + } - for (std::set<Anope::string>::const_iterator it = dbs.begin(), it_end = dbs.end(); it != it_end; ++it) + sep = data["memoignore"]; + for (Anope::string token; memos && sep.GetToken(token);) + { + MemoServ::Ignore *ign = Serialize::New<MemoServ::Ignore *>(); + if (ign != nullptr) { - const Anope::string &oldname = Anope::DataDir + "/" + *it; - Anope::string newname = Anope::DataDir + "/backups/" + *it + "-" + stringify(tm->tm_year + 1900) + Anope::printf("-%02i-", tm->tm_mon + 1) + Anope::printf("%02i", tm->tm_mday); + ign->SetMemoInfo(memos); + ign->SetMask(token); + } + } - /* Backup already exists or no database to backup */ - if (Anope::IsFile(newname) || !Anope::IsFile(oldname)) - continue; + sep = data["cert"]; + for (Anope::string token; sep.GetToken(token);) + { + NSCertEntry *e = Serialize::New<NSCertEntry *>(); + if (e != nullptr) + { + e->SetAccount(account); + e->SetCert(token); + } + } - Log(LOG_DEBUG) << "db_flatfile: Attempting to rename " << *it << " to " << newname; - if (rename(oldname.c_str(), newname.c_str())) - { - Anope::string err = Anope::LastError(); - Log(this) << "Unable to back up database " << *it << " (" << err << ")!"; + // last_modes + } - if (!Config->GetModule(this)->Get<bool>("nobackupokay")) - { - Anope::Quitting = true; - Anope::QuitReason = "Unable to back up database " + *it + " (" + err + ")"; - } + void LoadNick(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + NickServ::Account *acc = NickServ::FindAccount(data["nc"]); + if (acc == nullptr) + return; - continue; - } + NickServ::Nick *nick = Serialize::New<NickServ::Nick *>(); + + if (nick == nullptr) + return; - backups[*it].push_back(newname); + nick->SetNick(data["nick"]); + nick->SetLastQuit(data["last_quit"]); + nick->SetLastRealname(data["last_realname"]); + nick->SetLastUsermask(data["last_usermask"]); + nick->SetLastRealhost(data["last_realhost"]); + try + { + nick->SetTimeRegistered(convertTo<time_t>(data["time_registered"])); + } + catch (const ConvertException &) { } + try + { + nick->SetLastSeen(convertTo<time_t>(data["last_seen"])); + } + catch (const ConvertException &) { } + nick->SetAccount(acc); - unsigned keepbackups = Config->GetModule(this)->Get<unsigned>("keepbackups"); - if (keepbackups > 0 && backups[*it].size() > keepbackups) + if (data["vhost_host"].empty() == false) + { + HostServ::VHost *vhost = Serialize::New<HostServ::VHost *>(); + if (vhost != nullptr) + { + vhost->SetOwner(acc); + vhost->SetIdent(data["vhost_ident"]); + vhost->SetHost(data["vhost_host"]); + vhost->SetCreator(data["vhost_creator"]); + try { - unlink(backups[*it].front().c_str()); - backups[*it].pop_front(); + vhost->SetCreated(convertTo<time_t>(data["vhost_time"])); } + catch (const ConvertException &) { } } } } - public: - DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) - , EventHook<Event::LoadDatabase>(this) - , EventHook<Event::SaveDatabase>(this) - , last_day(0) - , loaded(false) + void LoadNSSuspend(const Anope::string &type, std::map<Anope::string, Anope::string> &data) { + NickServ::Nick *nick = NickServ::FindNick(data["nick"]); + if (nick == nullptr) + return; + + NSSuspendInfo *si = Serialize::New<NSSuspendInfo *>(); + if (si == nullptr) + return; + + si->SetAccount(nick->GetAccount()); + si->SetBy(data["by"]); + si->SetReason(data["reason"]); + try + { + si->SetWhen(convertTo<time_t>(data["time"])); + } + catch (const ConvertException &) { } + try + { + si->SetExpires(convertTo<time_t>(data["expires"])); + } + catch (const ConvertException &) { } } - EventReturn OnLoadDatabase() override + void LoadAJoin(const Anope::string &type, std::map<Anope::string, Anope::string> &data) { - const Anope::string &db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<Anope::string>("database", "anope.db"); + NickServ::Nick *nick = NickServ::FindNick(data["nick"]); - std::fstream fd(db_name.c_str(), std::ios_base::in | std::ios_base::binary); - if (!fd.is_open()) + if (nick == nullptr) + return; + + AutoJoin *entry = Serialize::New<AutoJoin *>(); + if (entry == nullptr) + return; + + entry->SetOwner(nick->GetAccount()); + entry->SetChannel(data["channel"]); + entry->SetKey(data["key"]); + } + + void LoadNSMiscData(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + NickServ::Nick *nick = NickServ::FindNick(data["nc"]); + + if (nick == nullptr) + return; + + NSMiscData *d = Serialize::New<NSMiscData *>(); + if (d == nullptr) + return; + + d->SetAccount(nick->GetAccount()); + d->SetName(data["name"]); + d->SetData(data["data"]); + } + + void LoadChannel(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *chan = Serialize::New<ChanServ::Channel *>(); + + if (chan == nullptr) + return; + + chan->SetName(data["name"]); + chan->SetFounder(NickServ::FindAccount(data["founder"])); + chan->SetSuccessor(NickServ::FindAccount(data["successor"])); + chan->SetDesc(data["description"]); + try { - Log(this) << "Unable to open " << db_name << " for reading!"; - return EVENT_STOP; + chan->SetTimeRegistered(convertTo<time_t>(data["time_registered"])); + } + catch (const ConvertException &) { } + try + { + chan->SetLastUsed(convertTo<time_t>(data["last_used"])); + } + catch (const ConvertException &) { } + chan->SetLastTopic(data["last_topic"]); + chan->SetLastTopicSetter(data["last_topic_setter"]); + try + { + chan->SetLastTopicTime(convertTo<time_t>(data["last_topic_time"])); + } + catch (const ConvertException &) { } + try + { + chan->SetBanType(convertTo<int16_t>(data["bantype"])); } + catch (const ConvertException &) { } - Serialize::TypeBase *type = nullptr; - Serialize::Object *obj = nullptr; - for (Anope::string buf; std::getline(fd, buf.str());) + spacesepstream sep = data["levels"]; + for (Anope::string lname, lvalue; sep.GetToken(lname) && sep.GetToken(lvalue);) { - if (buf.find("OBJECT ") == 0) + try { - Anope::string t = buf.substr(7); - if (obj) - Log(LOG_DEBUG) << "obj != null but got OBJECT"; - if (type) - Log(LOG_DEBUG) << "type != null but got OBJECT"; - type = Serialize::TypeBase::Find(t); - obj = nullptr; + chan->SetLevel(lname, convertTo<int16_t>(lvalue)); } - else if (buf.find("ID ") == 0) - { - if (!type || obj) - continue; + catch (const ConvertException &) { } + } - try - { - Serialize::ID id = convertTo<Serialize::ID>(buf.substr(3)); - obj = type->Require(id); - } - catch (const ConvertException &) - { - Log(LOG_DEBUG) << "Unable to parse object id " << buf.substr(3); - } + if (data["bi"].empty() == false) + { + ServiceBot *sb = ServiceBot::Find(data["bi"], true); + if (sb != nullptr) + chan->SetBI(sb->bi); + } + + try + { + chan->SetBanExpire(convertTo<time_t>(data["banexpire"])); + } + catch (const ConvertException &) { } + + MemoServ::MemoInfo *memos = chan->GetMemos(); + if (memos != nullptr) + { + try + { + int16_t memomax = convertTo<int16_t>(data["memomax"]); + memos->SetMemoMax(memomax); } - else if (buf.find("DATA ") == 0) + catch (const ConvertException &) { } + } + + sep = data["memoignore"]; + for (Anope::string token; memos && sep.GetToken(token);) + { + MemoServ::Ignore *ign = Serialize::New<MemoServ::Ignore *>(); + if (ign != nullptr) { - if (!type) - continue; + ign->SetMemoInfo(memos); + ign->SetMask(token); + } + } - if (!obj) - obj = type->Create(); + // last modes + // kicker data - size_t sp = buf.find(' ', 5); // Skip DATA - if (sp == Anope::string::npos) - continue; + // exts + } - Anope::string key = buf.substr(5, sp - 5), value = buf.substr(sp + 1); + void LoadBot(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + if (ServiceBot::Find(data["nick"], true)) + return; + + BotInfo *bot = Serialize::New<BotInfo *>(); + if (bot == nullptr) + return; + + bot->SetNick(data["nick"]); + bot->SetUser(data["user"]); + bot->SetHost(data["host"]); + bot->SetRealName(data["realname"]); + try + { + bot->SetCreated(convertTo<time_t>(data["created"])); + } + catch (const ConvertException &) { } + bot->SetOperOnly(data["oper_only"] != "0"); - Serialize::FieldBase *field = type->GetField(key); - if (field) - field->UnserializeFromString(obj, value); - } - else if (buf.find("END") == 0) - { - type = nullptr; - obj = nullptr; - } + ServiceBot *sb = new ServiceBot(bot->GetNick(), bot->GetUser(), bot->GetHost(), bot->GetRealName()); + + sb->bi = bot; + bot->bot = sb; + } + + void LoadChanAccess(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; + + Anope::string mask = data["mask"]; + if (mask.find('#') == 0) + return; + + Anope::string provider = data["provider"]; + ChanServ::ChanAccess *access; + + if (provider == "access/access") + access = Serialize::New<AccessChanAccess *>(); + else if (provider == "access/xop") + access = Serialize::New<XOPChanAccess *>(); + else if (provider == "access/flags") + access = Serialize::New<FlagsChanAccess *>(); + else + return; + + if (access == nullptr) + return; + + access->SetChannel(channel); + access->SetCreator(data["creator"]); + try + { + access->SetLastSeen(convertTo<time_t>(data["last_seen"])); } + catch (const ConvertException &) { } + try + { + access->SetCreated(convertTo<time_t>(data["created"])); + } + catch (const ConvertException &) { } + access->SetMask(mask); - fd.close(); + NickServ::Nick *nick = NickServ::FindNick(mask); + if (nick != nullptr) + access->SetObj(nick->GetAccount()); - loaded = true; - return EVENT_STOP; + access->AccessUnserialize(data["data"]); } + void LoadModeLock(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; + + ModeLock *ml = Serialize::New<ModeLock *>(); + ml->SetChannel(channel); + ml->SetSet(data["set"] == "1"); + ml->SetName(data["name"]); + ml->SetParam(data["param"]); + ml->SetSetter(data["setter"]); + try + { + ml->SetCreated(convertTo<time_t>(data["created"])); + } + catch (const ConvertException &) { } + } - void OnSaveDatabase() override + void LoadAutoKick(const Anope::string &type, std::map<Anope::string, Anope::string> &data) { - BackupDatabase(); + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; - Anope::string db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<Anope::string>("database", "anope.db"); + NickServ::Nick *nick = nullptr; + if (data["nc"].empty() == false) + { + nick = NickServ::FindNick(data["nc"]); + + if (nick == nullptr) + return; + } - if (Anope::IsFile(db_name)) - rename(db_name.c_str(), (db_name + ".tmp").c_str()); + time_t added = 0, lastused = 0; - std::fstream f(db_name.c_str(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); + try + { + added = convertTo<time_t>(data["addtime"]); + } + catch (const ConvertException &) { } - if (!f.is_open()) + try { - Log(this) << "Unable to open " << db_name << " for writing"; + lastused = convertTo<time_t>(data["last_used"]); } + catch (const ConvertException &) { } + + if (nick != nullptr) + channel->AddAkick(data["creator"], nick->GetAccount(), data["reason"], added, lastused); else + channel->AddAkick(data["creator"], data["mask"], data["reason"], added, lastused); + } + + void LoadBadWord(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; + + BadWord *bw = Serialize::New<BadWord *>(); + if (bw == nullptr) + return; + + bw->SetChannel(channel); + bw->SetWord(data["word"]); + try { - for (std::pair<Serialize::ID, Serialize::Object *> p : Serialize::objects) - { - Serialize::Object *object = p.second; - Serialize::TypeBase *s_type = object->GetSerializableType(); - - f << "OBJECT " << s_type->GetName() << "\n"; - f << "ID " << object->id << "\n"; - for (Serialize::FieldBase *field : s_type->GetFields()) - if (field->HasFieldS(object)) // for ext - f << "DATA " << field->serialize_name << " " << field->SerializeToString(object) << "\n"; - f << "END\n"; - } + bw->SetType(static_cast<BadWordType>(convertTo<int>(data["type"]))); } + catch (const ConvertException &) { } + } - if (!f.is_open() || !f.good()) + void LoadCSSuspend(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; + + CSSuspendInfo *si = Serialize::New<CSSuspendInfo *>(); + if (si == nullptr) + return; + + si->SetChannel(channel); + si->SetBy(data["by"]); + si->SetReason(data["reason"]); + try { - f.close(); - rename((db_name + ".tmp").c_str(), db_name.c_str()); + si->SetWhen(convertTo<time_t>(data["time"])); } - else + catch (const ConvertException &) { } + try + { + si->SetExpires(convertTo<time_t>(data["expires"])); + } + catch (const ConvertException &) { } + } + + void LoadEntrymsg(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; + + EntryMsg *msg = Serialize::New<EntryMsg *>(); + if (msg == nullptr) + return; + + msg->SetChannel(channel); + msg->SetCreator(data["creator"]); + msg->SetMessage(data["message"]); + } + + void LoadLogSetting(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; + + LogSetting *log = Serialize::New<LogSetting *>(); + if (log == nullptr) + return; + + log->SetChannel(channel); + log->SetServiceName(data["service_name"]); + log->SetCommandService(data["command_service"]); + log->SetCommandName(data["command_name"]); + log->SetMethod(data["method"]); + log->SetExtra(data["extra"]); + try + { + log->SetCreated(convertTo<time_t>(data["created"])); + } + catch (const ConvertException &) { } + log->SetCreator(data["creator"]); + } + + void LoadCSMiscData(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ChanServ::Channel *channel = ChanServ::Find(data["ci"]); + if (channel == nullptr) + return; + + CSMiscData *d = Serialize::New<CSMiscData *>(); + if (d == nullptr) + return; + + d->SetChannel(channel); + d->SetName(data["name"]); + d->SetData(data["data"]); + } + + void LoadForbid(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + ForbidData *d = Serialize::New<ForbidData *>(); + if (d == nullptr) + return; + + d->SetMask(data["mask"]); + d->SetCreator(data["creator"]); + d->SetReason(data["reason"]); + try + { + d->SetCreated(convertTo<time_t>(data["created"])); + } + catch (const ConvertException &) { } + try + { + d->SetExpires(convertTo<time_t>(data["expires"])); + } + catch (const ConvertException &) { } + try + { + d->SetType(static_cast<ForbidType>(convertTo<int>(data["type"]))); + } + catch (const ConvertException &) { } + } + + void LoadNews(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + NewsItem *ni = Serialize::New<NewsItem *>(); + if (ni == nullptr) + return; + + try + { + ni->SetNewsType(static_cast<NewsType>(convertTo<int>(data["type"]))); + } + catch (const ConvertException &) { } + ni->SetText(data["text"]); + try + { + ni->SetTime(convertTo<time_t>(data["time"])); + } + catch (const ConvertException &) { } + ni->SetWho(data["who"]); + } + + void LoadOperInfo(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + Serialize::Object *target = NickServ::FindAccount(data["target"]); + if (target == nullptr) + target = ChanServ::Find(data["target"]); + + if (target == nullptr) + return; + + OperInfo *o = Serialize::New<OperInfo *>(); + if (o == nullptr) + return; + + o->SetTarget(target); + o->SetInfo(data["info"]); + o->SetCreator(data["adder"]); + try + { + o->SetCreated(convertTo<time_t>(data["created"])); + } + catch (const ConvertException &) { } + } + + void LoadXLine(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + XLine *x = Serialize::New<XLine *>(); + if (x == nullptr) + return; + + x->SetMask(data["mask"]); + x->SetBy(data["by"]); + try + { + x->SetExpires(convertTo<time_t>(data["expires"])); + } + catch (const ConvertException &) { } + try + { + x->SetCreated(convertTo<time_t>(data["created"])); + } + catch (const ConvertException &) { } + x->SetReason(data["reason"]); + x->SetID(data["uid"]); + x->SetType(data["manager"]); + } + + void LoadOper(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { +#warning "oper needs account ref" +#if 0 + data["name"] << this->name; + data["type"] << this->ot->GetName(); + Oper *o = Serialize::New<Oper *>(); + o->SetName(na->GetAccount()->GetDisplay()); + o->SetType(ot); + o->SetRequireOper(true); +#endif + } + + void LoadDNSZone(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { +#if 0 + DNSZone *z = Serialize::New<DNSZone *>(); + z->SetName(data["name"]); + + unsigned int count = 0; + while (data["server" + stringify(count)].empty() == false) + { + DNSZoneMembership *mem = Serialize::New<DNSZoneMembership *>(); + mem->SetZone(z); + mem->SetServer(s); + + ++count; + } +// data["name"] << name; +// unsigned count = 0; +// for (std::set<Anope::string, ci::less>::iterator it = servers.begin(), it_end = servers.end(); it != it_end; ++it) +// data["server" + stringify(count++)] << *it; +#endif + } + + void LoadDNSServer(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { +#if 0 + s = Serialize::New<DNSServer *>(); + s->SetName(data["server_name"]); + + data["server_name"] << server_name; + for (unsigned i = 0; i < ips.size(); ++i) + data["ip" + stringify(i)] << ips[i]; + try + { + s->SetLimit(convertTo<unsigned>(data["limit"])); + } + catch (const ConvertException &) { } + try + { + s->SetPooled(data["pooled"] == "1"); + } + catch (const ConvertException &) { } + + unsigned int count = 0; + while (data["zone" + stringify(count)].empty() == false) + { + } +// for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it) +// data["zone" + stringify(count++)] << *it; +#endif + } + + void LoadMemo(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + MemoServ::MemoInfo *mi = nullptr; + + Anope::string owner = data["owner"]; + + NickServ::Nick *nick = NickServ::FindNick(owner); + ChanServ::Channel *chan = ChanServ::Find(owner); + if (nick != nullptr) + mi = nick->GetAccount()->GetMemos(); + else if (chan != nullptr) + mi = chan->GetMemos(); + + if (mi == nullptr) + return; + + MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>(); + if (m == nullptr) + return; + + m->SetMemoInfo(mi); + m->SetSender(data["sender"]); + try + { + m->SetTime(convertTo<time_t>(data["time"])); + } + catch (const ConvertException &) { } + m->SetText(data["text"]); + m->SetUnread(data["unread"] == "1"); + // receipt + } + + void LoadType(const Anope::string &type, std::map<Anope::string, Anope::string> &data) + { + if (type == "NickCore") + LoadAccount(type, data); + else if (type == "NickAlias") + LoadNick(type, data); + else if (type == "NSSuspend") + LoadNSSuspend(type, data); + else if (type == "AJoinEntry") + LoadAJoin(type, data); + else if (type == "NSMiscData") + LoadNSMiscData(type, data); + + else if (type == "BotInfo") + LoadBot(type, data); + else if (type == "BadWord") + LoadBadWord(type, data); + + else if (type == "ChannelInfo") + LoadChannel(type, data); + else if (type == "ChanAccess") + LoadChanAccess(type, data); + else if (type == "ModeLock") + LoadModeLock(type, data); + else if (type == "AutoKick") + LoadAutoKick(type, data); + else if (type == "CSSuspendInfo") + LoadCSSuspend(type, data); + else if (type == "EntryMsg") + LoadEntrymsg(type, data); + else if (type == "LogSetting") + LoadLogSetting(type, data); + else if (type == "CSMiscData") + LoadCSMiscData(type, data); + + else if (type == "ForbidData") + LoadForbid(type, data); + else if (type == "NewsItem") + LoadNews(type, data); + else if (type == "OperInfo") + LoadOperInfo(type, data); + else if (type == "XLine") + LoadXLine(type, data); + else if (type == "Oper") + LoadOper(type, data); + else if (type == "DNSZone") + LoadDNSZone(type, data); + else if (type == "DNSServer") + LoadDNSServer(type, data); + + else if (type == "Memo") + LoadMemo(type, data); + } + + public: + DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>(this) + { + + } + + EventReturn OnLoadDatabase() override + { + const Anope::string &db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<Anope::string>("database", "anope.db"); + + std::fstream fd(db_name.c_str(), std::ios_base::in | std::ios_base::binary); + if (!fd.is_open()) + { + Log(this) << "Unable to open " << db_name << " for reading!"; + return EVENT_STOP; + } + + Anope::string type; + std::map<Anope::string, Anope::string> data; + for (Anope::string buf; std::getline(fd, buf.str());) { - f.close(); - unlink((db_name + ".tmp").c_str()); + if (buf.find("OBJECT ") == 0) + { + type = buf.substr(7); + } + else if (buf.find("DATA ") == 0) + { + size_t sp = buf.find(' ', 5); // Skip DATA + if (sp == Anope::string::npos) + continue; + + Anope::string key = buf.substr(5, sp - 5), value = buf.substr(sp + 1); + + data[key] = value; + } + else if (buf.find("END") == 0) + { + LoadType(type, data); + + type.empty(); + data.empty(); + } } + + fd.close(); + + return EVENT_STOP; } }; diff --git a/modules/database/sql.cpp b/modules/database/sql.cpp index 50447c005..e1b766b57 100644 --- a/modules/database/sql.cpp +++ b/modules/database/sql.cpp @@ -99,7 +99,7 @@ class DBSQL : public Module, public Pipe { Configuration::Block *block = conf->GetModule(this); this->SQL = ServiceReference<Provider>(block->Get<Anope::string>("engine")); - this->prefix = block->Get<Anope::string>("prefix", "anope_db_"); + this->prefix = block->Get<Anope::string>("prefix", "anope_"); inited = false; } diff --git a/modules/nickserv/cert.cpp b/modules/nickserv/cert.cpp index 93804d3ed..3f3ea3a5a 100644 --- a/modules/nickserv/cert.cpp +++ b/modules/nickserv/cert.cpp @@ -187,7 +187,7 @@ class CommandNSCert : public Command e->SetAccount(nc); e->SetCert(certfp); - // XXX fire events +#warning "events?" Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to ADD certificate fingerprint " << certfp << " to " << nc->GetDisplay(); source.Reply(_("\002{0}\002 added to the certificate list of \002{1}\002."), certfp, nc->GetDisplay()); diff --git a/modules/operserv/dns.cpp b/modules/operserv/dns.cpp index 9afec4304..e607b1712 100644 --- a/modules/operserv/dns.cpp +++ b/modules/operserv/dns.cpp @@ -94,10 +94,10 @@ class DNSServerImpl : public DNSServer void SetName(const Anope::string &) override; unsigned int GetLimit() override; - void SetLimit(const unsigned int &) override; + void SetLimit(unsigned int) override; bool GetPooled() override; - void SetPool(const bool &) override; + void SetPool(bool) override; bool Active() { @@ -169,7 +169,7 @@ unsigned int DNSServerImpl::GetLimit() return Get(&DNSServerType::limit); } -void DNSServerImpl::SetLimit(const unsigned int &l) +void DNSServerImpl::SetLimit(unsigned int l) { Set(&DNSServerType::limit, l); } @@ -179,7 +179,7 @@ bool DNSServerImpl::GetPooled() return Get(&DNSServerType::pooled); } -void DNSServerImpl::SetPool(const bool &p) +void DNSServerImpl::SetPool(bool p) { Set(&DNSServerType::pooled, p); } diff --git a/modules/operserv/forbid.cpp b/modules/operserv/forbid.cpp index e706083e0..36ef12870 100644 --- a/modules/operserv/forbid.cpp +++ b/modules/operserv/forbid.cpp @@ -50,7 +50,7 @@ class ForbidDataImpl : public ForbidData void SetExpires(const time_t &) override; ForbidType GetType() override; - void SetType(const ForbidType &) override; + void SetType(ForbidType) override; }; class ForbidDataType : public Serialize::Type<ForbidDataImpl> @@ -126,7 +126,7 @@ ForbidType ForbidDataImpl::GetType() return Get(&ForbidDataType::type); } -void ForbidDataImpl::SetType(const ForbidType &t) +void ForbidDataImpl::SetType(ForbidType t) { Set(&ForbidDataType::type, t); } diff --git a/modules/operserv/news.cpp b/modules/operserv/news.cpp index 91e5a175a..a99063c19 100644 --- a/modules/operserv/news.cpp +++ b/modules/operserv/news.cpp @@ -86,7 +86,7 @@ class NewsItemImpl : public NewsItem NewsItemImpl(Serialize::TypeBase *type, Serialize::ID id) : NewsItem(type, id) { } NewsType GetNewsType() override; - void SetNewsType(const NewsType &) override; + void SetNewsType(NewsType) override; Anope::string GetText() override; void SetText(const Anope::string &) override; @@ -120,7 +120,7 @@ NewsType NewsItemImpl::GetNewsType() return Get(&NewsItemType::type); } -void NewsItemImpl::SetNewsType(const NewsType &t) +void NewsItemImpl::SetNewsType(NewsType t) { Set(&NewsItemType::type, t); } |