diff options
| author | Adam <Adam@anope.org> | 2011-11-08 17:29:16 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2011-11-08 17:29:16 -0500 |
| commit | b5ff856f47d8e54d12c568462a06351633c29610 (patch) | |
| tree | a4e2f96c59ee49aa5e6cacdfd30db6155151ad36 /modules/database | |
| parent | 97b9055f92f21cd91af44a3d5dacce0024536cff (diff) | |
Windows
Diffstat (limited to 'modules/database')
| -rw-r--r-- | modules/database/db_flatfile.cpp | 57 | ||||
| -rw-r--r-- | modules/database/db_plain.cpp | 4 | ||||
| -rw-r--r-- | modules/database/db_sql.cpp | 42 | ||||
| -rw-r--r-- | modules/database/db_sql_live_read.cpp | 110 | ||||
| -rw-r--r-- | modules/database/db_sql_live_write.cpp | 2 |
5 files changed, 104 insertions, 111 deletions
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index 639d6e1e8..c3b8cbf75 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -21,14 +21,6 @@ class DBFlatFile : public Module /* Backup file names */ std::list<Anope::string> Backups; - SerializableBase *find(const Anope::string &sname) - { - for (unsigned i = 0; i < serialized_types.size(); ++i) - if (serialized_types[i]->serialize_name() == sname) - return serialized_types[i]; - return NULL; - } - public: DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE) { @@ -75,7 +67,7 @@ class DBFlatFile : public Module if (Config->KeepBackups > 0 && Backups.size() > static_cast<unsigned>(Config->KeepBackups)) { - DeleteFile(Backups.front().c_str()); + unlink(Backups.front().c_str()); Backups.pop_front(); } } @@ -98,9 +90,9 @@ class DBFlatFile : public Module return EVENT_CONTINUE; } - SerializableBase *sb = NULL; - SerializableBase::serialized_data data; - std::multimap<SerializableBase *, SerializableBase::serialized_data> objects; + SerializeType *st = NULL; + Serializable::serialized_data data; + std::multimap<SerializeType *, Serializable::serialized_data> objects; for (Anope::string buf, token; std::getline(db, buf.str());) { spacesepstream sep(buf); @@ -110,29 +102,30 @@ class DBFlatFile : public Module if (token == "OBJECT" && sep.GetToken(token)) { - sb = this->find(token); + st = SerializeType::Find(token); data.clear(); } - else if (token == "DATA" && sb != NULL && sep.GetToken(token)) + else if (token == "DATA" && st != NULL && sep.GetToken(token)) data[token] << sep.GetRemaining(); - else if (token == "END" && sb != NULL) + else if (token == "END" && st != NULL) { - objects.insert(std::make_pair(sb, data)); + objects.insert(std::make_pair(st, data)); - sb = NULL; + st = NULL; data.clear(); } } - for (unsigned i = 0; i < serialized_types.size(); ++i) + const std::vector<Anope::string> type_order = SerializeType::GetTypeOrder(); + for (unsigned i = 0; i < type_order.size(); ++i) { - SerializableBase *stype = serialized_types[i]; + SerializeType *stype = SerializeType::Find(type_order[i]); - std::multimap<SerializableBase *, SerializableBase::serialized_data>::iterator it = objects.find(stype), it_end = objects.upper_bound(stype); + std::multimap<SerializeType *, Serializable::serialized_data>::iterator it = objects.find(stype), it_end = objects.upper_bound(stype); if (it == objects.end()) continue; for (; it != it_end; ++it) - it->first->alloc(it->second); + it->first->Create(it->second); } db.close(); @@ -158,17 +151,17 @@ class DBFlatFile : public Module return EVENT_CONTINUE; } - if (serialized_items != NULL) - for (std::list<SerializableBase *>::iterator it = serialized_items->begin(), it_end = serialized_items->end(); it != it_end; ++it) - { - SerializableBase *base = *it; - SerializableBase::serialized_data data = base->serialize(); + const std::list<Serializable *> &items = Serializable::GetItems(); + for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) + { + Serializable *base = *it; + Serializable::serialized_data data = base->serialize(); - db << "OBJECT " << base->serialize_name() << "\n"; - for (SerializableBase::serialized_data::iterator dit = data.begin(), dit_end = data.end(); dit != dit_end; ++dit) - db << "DATA " << dit->first << " " << dit->second.astr() << "\n"; - db << "END\n"; - } + db << "OBJECT " << base->GetSerializeName() << "\n"; + for (Serializable::serialized_data::iterator dit = data.begin(), dit_end = data.end(); dit != dit_end; ++dit) + db << "DATA " << dit->first << " " << dit->second.astr() << "\n"; + db << "END\n"; + } db.close(); @@ -181,7 +174,7 @@ class DBFlatFile : public Module rename(tmp_db.c_str(), DatabaseFile.c_str()); } else - DeleteFile(tmp_db.c_str()); + unlink(tmp_db.c_str()); return EVENT_CONTINUE; } diff --git a/modules/database/db_plain.cpp b/modules/database/db_plain.cpp index 387d5ca61..c28d064cd 100644 --- a/modules/database/db_plain.cpp +++ b/modules/database/db_plain.cpp @@ -596,7 +596,6 @@ class DBPlain : public Module OnReload(); LastDay = 0; - Serializable<Exception>::Alloc.Register("Exception"); } ~DBPlain() @@ -637,7 +636,7 @@ class DBPlain : public Module unsigned KeepBackups = Config->KeepBackups; if (KeepBackups && Backups.size() > KeepBackups) { - DeleteFile(Backups.front().c_str()); + unlink(Backups.front().c_str()); Backups.pop_front(); } } @@ -655,7 +654,6 @@ class DBPlain : public Module /* No need to ever reload this again, although this should never be trigged again */ ModuleManager::Detach(I_OnLoadDatabase, this); - //ModuleManager::Detach(I_OnDatabaseReadMetadata, this); return EVENT_STOP; } diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 8b2b0e26d..e083204d4 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -60,9 +60,9 @@ class DBSQL : public Module } } - void AlterTable(const Anope::string &table, std::set<Anope::string> &data, const SerializableBase::serialized_data &newd) + void AlterTable(const Anope::string &table, std::set<Anope::string> &data, const Serializable::serialized_data &newd) { - for (SerializableBase::serialized_data::const_iterator it = newd.begin(), it_end = newd.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = newd.begin(), it_end = newd.end(); it != it_end; ++it) { if (data.count(it->first) > 0) continue; @@ -81,20 +81,20 @@ class DBSQL : public Module } } - void Insert(const Anope::string &table, const SerializableBase::serialized_data &data) + void Insert(const Anope::string &table, const Serializable::serialized_data &data) { Anope::string query_text = "INSERT INTO `" + table + "` ("; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += "`" + it->first + "`,"; query_text.erase(query_text.end() - 1); query_text += ") VALUES ("; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += "@" + it->first + "@,"; query_text.erase(query_text.end() - 1); query_text += ")"; SQLQuery query(query_text); - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query.setValue(it->first, it->second.astr()); this->RunBackground(query); @@ -126,32 +126,33 @@ class DBSQL : public Module return EVENT_CONTINUE; } - if (serialized_items == NULL) + const std::list<Serializable *> &items = Serializable::GetItems(); + if (items.empty()) return EVENT_CONTINUE; this->DropAll(); std::map<Anope::string, std::set<Anope::string> > table_layout; - for (std::list<SerializableBase *>::iterator it = serialized_items->begin(), it_end = serialized_items->end(); it != it_end; ++it) + for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) { - SerializableBase *base = *it; - SerializableBase::serialized_data data = base->serialize(); + Serializable *base = *it; + Serializable::serialized_data data = base->serialize(); if (data.empty()) continue; - std::set<Anope::string> &layout = table_layout[base->serialize_name()]; + std::set<Anope::string> &layout = table_layout[base->GetSerializeName()]; if (layout.empty()) { - this->RunBackground(this->sql->CreateTable(base->serialize_name(), data)); + this->RunBackground(this->sql->CreateTable(base->GetSerializeName(), data)); - for (SerializableBase::serialized_data::iterator it2 = data.begin(), it2_end = data.end(); it2 != it2_end; ++it2) + for (Serializable::serialized_data::iterator it2 = data.begin(), it2_end = data.end(); it2 != it2_end; ++it2) layout.insert(it2->first); } else - this->AlterTable(base->serialize_name(), layout, data); + this->AlterTable(base->GetSerializeName(), layout, data); - this->Insert(base->serialize_name(), data); + this->Insert(base->GetSerializeName(), data); } return EVENT_CONTINUE; } @@ -164,20 +165,21 @@ class DBSQL : public Module return EVENT_CONTINUE; } - for (std::vector<SerializableBase *>::iterator it = serialized_types.begin(), it_end = serialized_types.end(); it != it_end; ++it) + const std::vector<Anope::string> type_order = SerializeType::GetTypeOrder(); + for (unsigned i = 0; i < type_order.size(); ++i) { - SerializableBase *sb = *it; + SerializeType *sb = SerializeType::Find(type_order[i]); - SQLQuery query("SELECT * FROM `" + sb->serialize_name() + "`"); + SQLQuery query("SELECT * FROM `" + sb->GetName() + "`"); SQLResult res = this->sql->RunQuery(query); for (int i = 0; i < res.Rows(); ++i) { - SerializableBase::serialized_data data; + Serializable::serialized_data data; const std::map<Anope::string, Anope::string> &row = res.Row(i); for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit) data[rit->first] << rit->second; - sb->alloc(data); + sb->Create(data); } } diff --git a/modules/database/db_sql_live_read.cpp b/modules/database/db_sql_live_read.cpp index b908949ab..9dfc68c69 100644 --- a/modules/database/db_sql_live_read.cpp +++ b/modules/database/db_sql_live_read.cpp @@ -55,7 +55,7 @@ class DBMySQL : public Module } } - void Insert(const Anope::string &table, const SerializableBase::serialized_data &data) + void Insert(const Anope::string &table, const Serializable::serialized_data &data) { if (tables.count(table) == 0 && SQL) { @@ -64,33 +64,33 @@ class DBMySQL : public Module } Anope::string query_text = "INSERT INTO `" + table + "` ("; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += "`" + it->first + "`,"; query_text.erase(query_text.end() - 1); query_text += ") VALUES ("; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += "@" + it->first + "@,"; query_text.erase(query_text.end() - 1); query_text += ") ON DUPLICATE KEY UPDATE "; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += it->first + "=VALUES(" + it->first + "),"; query_text.erase(query_text.end() - 1); SQLQuery query(query_text); - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query.setValue(it->first, it->second.astr()); this->RunQuery(query); } - void Delete(const Anope::string &table, const SerializableBase::serialized_data &data) + void Delete(const Anope::string &table, const Serializable::serialized_data &data) { Anope::string query_text = "DELETE FROM `" + table + "` WHERE "; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += "`" + it->first + "` = @" + it->first + "@"; SQLQuery query(query_text); - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query.setValue(it->first, it->second.astr()); this->RunQuery(query); @@ -158,20 +158,20 @@ class DBMySQL : public Module { NickAlias *na = findnick(source.u->nick); if (!na) - this->Insert(na->nc->serialize_name(), na->nc->serialize()); + this->Insert(na->nc->GetSerializeName(), na->nc->serialize()); } else if (command->name.find("nickserv/saset/") == 0) { NickAlias *na = findnick(params[1]); if (!na) - this->Insert(na->nc->serialize_name(), na->nc->serialize()); + this->Insert(na->nc->GetSerializeName(), na->nc->serialize()); } else if (command->name.find("chanserv/set") == 0 || command->name.find("chanserv/saset") == 0) { ChannelInfo *ci = params.size() > 0 ? cs_findchan(params[0]) : NULL; if (!ci) - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); } else if (command->name == "botserv/kick" && params.size() > 2) { @@ -180,7 +180,7 @@ class DBMySQL : public Module return; if (!ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration")) return; - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); } else if (command->name == "botserv/set" && params.size() > 1) { @@ -189,9 +189,9 @@ class DBMySQL : public Module if (!ci) bi = findbot(params[0]); if (bi && params[1].equals_ci("PRIVATE") && u->HasPriv("botserv/set/private")) - this->Insert(bi->serialize_name(), bi->serialize()); + this->Insert(bi->GetSerializeName(), bi->serialize()); else if (ci && !ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration")) - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); } else if (command->name == "memoserv/ignore" && params.size() > 0) { @@ -200,40 +200,40 @@ class DBMySQL : public Module { NickCore *nc = u->Account(); if (nc) - this->Insert(nc->serialize_name(), nc->serialize()); + this->Insert(nc->GetSerializeName(), nc->serialize()); } else { ChannelInfo *ci = cs_findchan(target); if (ci && ci->AccessFor(u).HasPriv("MEMO")) - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); } } } void OnNickAddAccess(NickCore *nc, const Anope::string &entry) { - this->Insert(nc->serialize_name(), nc->serialize()); + this->Insert(nc->GetSerializeName(), nc->serialize()); } void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) { - this->Insert(nc->serialize_name(), nc->serialize()); + this->Insert(nc->GetSerializeName(), nc->serialize()); } void OnNickClearAccess(NickCore *nc) { - this->Insert(nc->serialize_name(), nc->serialize()); + this->Insert(nc->GetSerializeName(), nc->serialize()); } void OnDelCore(NickCore *nc) { - this->Delete(nc->serialize_name(), nc->serialize()); + this->Delete(nc->GetSerializeName(), nc->serialize()); } void OnNickForbidden(NickAlias *na) { - this->Insert(na->serialize_name(), na->serialize()); + this->Insert(na->GetSerializeName(), na->serialize()); } void OnNickGroup(User *u, NickAlias *) @@ -243,12 +243,12 @@ class DBMySQL : public Module void InsertAlias(NickAlias *na) { - this->Insert(na->serialize_name(), na->serialize()); + this->Insert(na->GetSerializeName(), na->serialize()); } void InsertCore(NickCore *nc) { - this->Insert(nc->serialize_name(), nc->serialize()); + this->Insert(nc->GetSerializeName(), nc->serialize()); } void OnNickRegister(NickAlias *na) @@ -259,42 +259,42 @@ class DBMySQL : public Module void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) { - SerializableBase::serialized_data data = nc->serialize(); - this->Delete(nc->serialize_name(), data); + Serializable::serialized_data data = nc->serialize(); + this->Delete(nc->GetSerializeName(), data); data.erase("display"); data["display"] << newdisplay; - this->Insert(nc->serialize_name(), data); + this->Insert(nc->GetSerializeName(), data); for (std::list<NickAlias *>::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it) { NickAlias *na = *it; data = na->serialize(); - this->Delete(na->serialize_name(), data); + this->Delete(na->GetSerializeName(), data); data.erase("nc"); data["nc"] << newdisplay; - this->Insert(na->serialize_name(), data); + this->Insert(na->GetSerializeName(), data); } } void OnNickSuspend(NickAlias *na) { - this->Insert(na->serialize_name(), na->serialize()); + this->Insert(na->GetSerializeName(), na->serialize()); } void OnDelNick(NickAlias *na) { - this->Delete(na->serialize_name(), na->serialize()); + this->Delete(na->GetSerializeName(), na->serialize()); } void OnAccessAdd(ChannelInfo *ci, User *, ChanAccess *access) { - this->Insert(access->serialize_name(), access->serialize()); + this->Insert(access->GetSerializeName(), access->serialize()); } void OnAccessDel(ChannelInfo *ci, User *u, ChanAccess *access) { - this->Delete(access->serialize_name(), access->serialize()); + this->Delete(access->GetSerializeName(), access->serialize()); } void OnAccessClear(ChannelInfo *ci, User *u) @@ -305,49 +305,49 @@ class DBMySQL : public Module void OnLevelChange(User *u, ChannelInfo *ci, const Anope::string &priv, int16_t what) { - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); } void OnDelChan(ChannelInfo *ci) { - this->Delete(ci->serialize_name(), ci->serialize()); + this->Delete(ci->GetSerializeName(), ci->serialize()); } void OnChanRegistered(ChannelInfo *ci) { - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); } void OnChanSuspend(ChannelInfo *ci) { - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); } void OnAkickAdd(ChannelInfo *ci, AutoKick *ak) { - this->Insert(ak->serialize_name(), ak->serialize()); + this->Insert(ak->GetSerializeName(), ak->serialize()); } void OnAkickDel(ChannelInfo *ci, AutoKick *ak) { - this->Delete(ak->serialize_name(), ak->serialize()); + this->Delete(ak->GetSerializeName(), ak->serialize()); } EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) { - this->Insert(lock->serialize_name(), lock->serialize()); + this->Insert(lock->GetSerializeName(), lock->serialize()); return EVENT_CONTINUE; } EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) { - this->Delete(lock->serialize_name(), lock->serialize()); + this->Delete(lock->GetSerializeName(), lock->serialize()); return EVENT_CONTINUE; } void OnBotCreate(BotInfo *bi) { - this->Insert(bi->serialize_name(), bi->serialize()); + this->Insert(bi->GetSerializeName(), bi->serialize()); } void OnBotChange(BotInfo *bi) @@ -357,76 +357,76 @@ class DBMySQL : public Module void OnBotDelete(BotInfo *bi) { - this->Delete(bi->serialize_name(), bi->serialize()); + this->Delete(bi->GetSerializeName(), bi->serialize()); } EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); return EVENT_CONTINUE; } EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) { - this->Insert(ci->serialize_name(), ci->serialize()); + this->Insert(ci->GetSerializeName(), ci->serialize()); return EVENT_CONTINUE; } void OnBadWordAdd(ChannelInfo *ci, BadWord *bw) { - this->Insert(bw->serialize_name(), bw->serialize()); + this->Insert(bw->GetSerializeName(), bw->serialize()); } void OnBadWordDel(ChannelInfo *ci, BadWord *bw) { - this->Delete(bw->serialize_name(), bw->serialize()); + this->Delete(bw->GetSerializeName(), bw->serialize()); } void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) { - this->Insert(m->serialize_name(), m->serialize()); + this->Insert(m->GetSerializeName(), m->serialize()); } void OnMemoDel(const NickCore *nc, MemoInfo *mi, Memo *m) { - this->Delete(m->serialize_name(), m->serialize()); + this->Delete(m->GetSerializeName(), m->serialize()); } void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, Memo *m) { - this->Delete(m->serialize_name(), m->serialize()); + this->Delete(m->GetSerializeName(), m->serialize()); } EventReturn OnExceptionAdd(Exception *ex) { - this->Insert(ex->serialize_name(), ex->serialize()); + this->Insert(ex->GetSerializeName(), ex->serialize()); return EVENT_CONTINUE; } void OnExceptionDel(User *, Exception *ex) { - this->Delete(ex->serialize_name(), ex->serialize()); + this->Delete(ex->GetSerializeName(), ex->serialize()); } EventReturn OnAddXLine(XLine *x, XLineManager *xlm) { - this->Insert(x->serialize_name(), x->serialize()); + this->Insert(x->GetSerializeName(), x->serialize()); return EVENT_CONTINUE; } void OnDelXLine(User *, XLine *x, XLineManager *xlm) { - this->Delete(x->serialize_name(), x->serialize()); + this->Delete(x->GetSerializeName(), x->serialize()); } void OnDeleteVhost(NickAlias *na) { - this->Insert(na->serialize_name(), na->serialize()); + this->Insert(na->GetSerializeName(), na->serialize()); } void OnSetVhost(NickAlias *na) { - this->Insert(na->serialize_name(), na->serialize()); + this->Insert(na->GetSerializeName(), na->serialize()); } }; diff --git a/modules/database/db_sql_live_write.cpp b/modules/database/db_sql_live_write.cpp index 5d15d14d3..21b45bdb4 100644 --- a/modules/database/db_sql_live_write.cpp +++ b/modules/database/db_sql_live_write.cpp @@ -3,7 +3,7 @@ class SQLCache : public Timer { - typedef std::map<Anope::string, time_t, std::less<ci::string> > cache_map; + typedef std::map<Anope::string, time_t, ci::less> cache_map; cache_map cache; public: |
