summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-02-17 19:39:25 -0500
committerAdam <Adam@anope.org>2014-02-17 19:39:25 -0500
commitef7dc94f8891e1dba8ac3dcad5966d1025b6226a (patch)
tree621a5ed520f08b6ff8e5cecac6c9a6b752f36736 /modules
parent7b4eec97480bace2621b8caa4b17f0ea50aa1f98 (diff)
Move most of the implementation details out of os_forbid.h, fixes crashing if a module adding a forbid is unloaded without removing the forbid
Diffstat (limited to 'modules')
-rw-r--r--modules/commands/os_forbid.cpp54
-rw-r--r--modules/database/db_old.cpp4
2 files changed, 54 insertions, 4 deletions
diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp
index c1fe1af8b..11215ab05 100644
--- a/modules/commands/os_forbid.cpp
+++ b/modules/commands/os_forbid.cpp
@@ -14,6 +14,51 @@
static ServiceReference<NickServService> nickserv("NickServService", "NickServ");
+struct ForbidDataImpl : ForbidData, Serializable
+{
+ ForbidDataImpl() : Serializable("ForbidData") { }
+ void Serialize(Serialize::Data &data) const anope_override;
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+};
+
+void ForbidDataImpl::Serialize(Serialize::Data &data) const
+{
+ data["mask"] << this->mask;
+ data["creator"] << this->creator;
+ data["reason"] << this->reason;
+ data["created"] << this->created;
+ data["expires"] << this->expires;
+ data["type"] << this->type;
+}
+
+Serializable* ForbidDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+{
+ if (!forbid_service)
+ return NULL;
+
+ ForbidDataImpl *fb;
+ if (obj)
+ fb = anope_dynamic_static_cast<ForbidDataImpl *>(obj);
+ else
+ fb = new ForbidDataImpl();
+
+ data["mask"] >> fb->mask;
+ data["creator"] >> fb->creator;
+ data["reason"] >> fb->reason;
+ data["created"] >> fb->created;
+ data["expires"] >> fb->expires;
+ unsigned int t;
+ data["type"] >> t;
+ fb->type = static_cast<ForbidType>(t);
+
+ if (t > FT_SIZE - 1)
+ return NULL;
+
+ if (!obj)
+ forbid_service->AddForbid(fb);
+ return fb;
+}
+
class MyForbidService : public ForbidService
{
Serialize::Checker<std::vector<ForbidData *>[FT_SIZE - 1]> forbid_data;
@@ -43,6 +88,11 @@ class MyForbidService : public ForbidService
delete d;
}
+ ForbidData *CreateForbid() anope_override
+ {
+ return new ForbidDataImpl();
+ }
+
ForbidData *FindForbid(const Anope::string &mask, ForbidType ftype) anope_override
{
for (unsigned i = this->forbids(ftype).size(); i > 0; --i)
@@ -157,7 +207,7 @@ class CommandOSForbid : public Command
bool created = false;
if (d == NULL)
{
- d = new ForbidData();
+ d = new ForbidDataImpl();
created = true;
}
@@ -379,7 +429,7 @@ class OSForbid : public Module
public:
OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- forbidService(this), forbiddata_type("ForbidData", ForbidData::Unserialize), commandosforbid(this)
+ forbidService(this), forbiddata_type("ForbidData", ForbidDataImpl::Unserialize), commandosforbid(this)
{
}
diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp
index 8c322d02e..ddc488084 100644
--- a/modules/database/db_old.cpp
+++ b/modules/database/db_old.cpp
@@ -622,7 +622,7 @@ static void LoadNicks()
if (!forbid)
continue;
- ForbidData *d = new ForbidData();
+ ForbidData *d = forbid->CreateForbid();
d->mask = nc->display;
d->creator = last_usermask;
d->reason = last_realname;
@@ -1031,7 +1031,7 @@ static void LoadChannels()
if (!forbid)
continue;
- ForbidData *d = new ForbidData();
+ ForbidData *d = forbid->CreateForbid();
d->mask = ci->name;
d->creator = forbidby;
d->reason = forbidreason;