summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/extensible.h233
-rw-r--r--include/services.h118
-rw-r--r--src/core/ns_resetpass.c51
-rw-r--r--src/modules/os_info.c81
-rw-r--r--src/protocol/bahamut.c25
-rw-r--r--src/protocol/inspircd11.c24
-rw-r--r--src/protocol/ratbox.c24
-rw-r--r--src/protocol/unreal32.c24
-rw-r--r--src/users.c4
9 files changed, 272 insertions, 312 deletions
diff --git a/include/extensible.h b/include/extensible.h
new file mode 100644
index 000000000..beee04bd8
--- /dev/null
+++ b/include/extensible.h
@@ -0,0 +1,233 @@
+/*
+ *
+ * Copyright (C) 2008-2009 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ *
+ *
+ * $Id$
+ *
+ */
+
+/** Dummy base class we use to cast everything to/from
+ */
+class ExtensibleItemBase
+{
+ public:
+ ExtensibleItemBase() { }
+ virtual ~ExtensibleItemBase() { }
+};
+
+/** Class used to represent an extensible item that doesn't hold a pointer
+ */
+template<typename T> class ExtensibleItemRegular : public ExtensibleItemBase
+{
+ protected:
+ T Item;
+
+ public:
+ ExtensibleItemRegular(T item) : Item(item) { }
+ virtual ~ExtensibleItemRegular() { }
+ T GetItem() const { return Item; }
+};
+
+/** Class used to represent an extensible item that holds a pointer
+ */
+template<typename T> class ExtensibleItemPointer : public ExtensibleItemBase
+{
+ protected:
+ T *Item;
+
+ public:
+ ExtensibleItemPointer(T *item) : Item(item) { }
+ virtual ~ExtensibleItemPointer() { delete Item; }
+ T *GetItem() const { return Item; }
+};
+
+/** Class used to represent an extensible item that holds a pointer to an arrray
+ */
+template<typename T> class ExtensibleItemPointerArray : public ExtensibleItemBase
+{
+ protected:
+ T *Item;
+
+ public:
+ ExtensibleItemPointerArray(T *item) : Item(item) { }
+ virtual ~ExtensibleItemPointerArray() { delete [] Item; }
+ T *GetItem() const { return Item; }
+};
+
+class CoreExport Extensible
+{
+ private:
+ std::map<std::string, ExtensibleItemBase *> Extension_Items;
+
+ public:
+ /** Default constructor, does nothing
+ */
+ Extensible() { }
+
+ /** Default destructor, deletes all of the extensible items in this object
+ * then clears the map
+ */
+ virtual ~Extensible()
+ {
+ for (std::map<std::string, ExtensibleItemBase *>::iterator it = Extension_Items.begin(); it != Extension_Items.end(); ++it)
+ {
+ delete it->second;
+ }
+ Extension_Items.clear();
+ }
+
+ /** Extend an Extensible class.
+ *
+ * @param key The key parameter is an arbitary string which identifies the extension data
+ * @param p This parameter is a pointer to an ExtensibleItem or ExtensibleItemBase derived class
+ *
+ * You must provide a key to store the data as via the parameter 'key'.
+ * The data will be inserted into the map. If the data already exists, you may not insert it
+ * twice, Extensible::Extend will return false in this case.
+ *
+ * @return Returns true on success, false if otherwise
+ */
+ bool Extend(const std::string &key, ExtensibleItemBase *p)
+ {
+ bool Ret = this->Extension_Items.insert(std::make_pair(key, p)).second;
+ if (!Ret)
+ delete p;
+ return Ret;
+ }
+
+ /** Extend an Extensible class.
+ *
+ * @param key The key parameter is an arbitary string which identifies the extension data
+ *
+ * You must provide a key to store the data as via the parameter 'key', this single-parameter
+ * version takes no 'data' parameter, this is used purely for boolean values.
+ * The key will be inserted into the map with a NULL 'data' pointer. If the key already exists
+ * then you may not insert it twice, Extensible::Extend will return false in this case.
+ *
+ * @return Returns true on success, false if otherwise
+ */
+ bool Extend(const std::string &key)
+ {
+ /* This will only add an item if it doesnt already exist,
+ * the return value is a std::pair of an iterator to the
+ * element, and a bool saying if it was actually inserted.
+ */
+ return this->Extend(key, new ExtensibleItemRegular<char *>(NULL));
+ }
+
+ /** Shrink an Extensible class.
+ *
+ * @param key The key parameter is an arbitary string which identifies the extension data
+ *
+ * You must provide a key name. The given key name will be removed from the classes data. If
+ * you provide a nonexistent key (case is important) then the function will return false.
+ * @return Returns true on success.
+ */
+ bool Shrink(const std::string &key)
+ {
+ std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key);
+ if (it != this->Extension_Items.end())
+ {
+ delete it->second;
+ /* map::size_type map::erase( const key_type& key );
+ * returns the number of elements removed, std::map
+ * is single-associative so this should only be 0 or 1
+ */
+ return this->Extension_Items.erase(key);
+ }
+
+ return false;
+ }
+
+ /** Get an extension item that is not a pointer.
+ *
+ * @param key The key parameter is an arbitary string which identifies the extension data
+ * @param p If you provide a non-existent key, this value will be 0. Otherwise a copy to the item you requested will be placed in this templated parameter.
+ * @return Returns true if the item was found and false if it was nor, regardless of wether 'p' is NULL. This allows you to store NULL values in Extensible.
+ */
+ template<typename T> bool GetExtRegular(const std::string &key, T &p)
+ {
+ std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key);
+
+ if (it != this->Extension_Items.end())
+ {
+ p = dynamic_cast<ExtensibleItemRegular<T> *>(it->second)->GetItem();
+ return true;
+ }
+
+ p = 0;
+ return false;
+ }
+
+ /** Get an extension item that is a pointer.
+ *
+ * @param key The key parameter is an arbitary string which identifies the extension data
+ * * @param p If you provide a non-existent key, this value will be NULL. Otherwise a pointer to the item you requested will be placed in this templated parameter.
+ * @return Returns true if the item was found and false if it was nor, regardless of wether 'p' is NULL. This allows you to store NULL values in Extensible.
+ */
+ template<typename T> bool GetExtPointer(const std::string &key, T *&p)
+ {
+ std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key);
+
+ if (it != this->Extension_Items.end())
+ {
+ p = dynamic_cast<ExtensibleItemPointer<T> *>(it->second)->GetItem();
+ return true;
+ }
+
+ p = NULL;
+ return false;
+ }
+
+ /** Get an extension item that is a pointer to an array
+ *
+ * @param key The key parameter is an arbitary string which identifies the extension data
+ * @param p If you provide a non-existent key, this value will be NULL. Otherwise a pointer to the item you requested will be placed in this templated parameter.
+ * @return Returns true if the item was found and false if it was nor, regardless of wether 'p' is NULL. This allows you to store NULL values in Extensible.
+ */
+ template<typename T> bool GetExtArray(const std::string &key, T *&p)
+ {
+ std::map<std::string, ExtensibleItemBase *>::iterator it = this->Extension_Items.find(key);
+
+ if (it != this->Extension_Items.end())
+ {
+ p = dynamic_cast<ExtensibleItemPointerArray<T> *>(it->second)->GetItem();
+ return true;
+ }
+
+ p = NULL;
+ return false;
+ }
+
+ /** Get an extension item.
+ *
+ * @param key The key parameter is an arbitary string which identifies the extension data
+ * @return Returns true if the item was found and false if it was not.
+ *
+ * This single-parameter version only checks if the key exists, it does nothing with
+ * the 'data' field and is probably only useful in conjunction with the single-parameter
+ * version of Extend().
+ */
+ bool GetExt(const std::string &key)
+ {
+ return (this->Extension_Items.find(key) != this->Extension_Items.end());
+ }
+
+ /** Get a list of all extension items names.
+ * @param list A deque of strings to receive the list
+ * @return This function writes a list of all extension items stored
+ * in this object by name into the given deque and returns void.
+ */
+ void GetExtList(std::deque<std::string> &list)
+ {
+ for (std::map<std::string, ExtensibleItemBase *>::iterator i = Extension_Items.begin(); i != Extension_Items.end(); ++i)
+ {
+ list.push_back(i->first);
+ }
+ }
+
+};
+
diff --git a/include/services.h b/include/services.h
index d184cd3f4..a3dabaaf5 100644
--- a/include/services.h
+++ b/include/services.h
@@ -301,123 +301,6 @@ class ModuleException : public CoreException
virtual ~ModuleException() throw() {}
};
-/** Class with the ability to be extended with key:value pairs.
- * Thanks to InspIRCd for this.
- */
-class CoreExport Extensible
-{
- private:
- std::map<std::string, void *> Extension_Items;
-
- public:
- /** Extend an Extensible class.
- *
- * @param key The key parameter is an arbitary string which identifies the extension data
- * @param p This parameter is a pointer to any data you wish to associate with the object
- *
- * You must provide a key to store the data as via the parameter 'key' and store the data
- * in the templated parameter 'p'.
- * The data will be inserted into the map. If the data already exists, you may not insert it
- * twice, Extensible::Extend will return false in this case.
- *
- * @return Returns true on success, false if otherwise
- */
- template<typename T> bool Extend(const std::string &key, T *p)
- {
- /* This will only add an item if it doesnt already exist,
- * the return value is a std::pair of an iterator to the
- * element, and a bool saying if it was actually inserted.
- */
- return this->Extension_Items.insert(std::make_pair(key, p)).second;
- }
-
- /** Extend an Extensible class.
- *
- * @param key The key parameter is an arbitary string which identifies the extension data
- *
- * You must provide a key to store the data as via the parameter 'key', this single-parameter
- * version takes no 'data' parameter, this is used purely for boolean values.
- * The key will be inserted into the map with a NULL 'data' pointer. If the key already exists
- * then you may not insert it twice, Extensible::Extend will return false in this case.
- *
- * @return Returns true on success, false if otherwise
- */
- bool Extend(const std::string &key)
- {
- /* This will only add an item if it doesnt already exist,
- * the return value is a std::pair of an iterator to the
- * element, and a bool saying if it was actually inserted.
- */
- return this->Extension_Items.insert(std::make_pair(key, static_cast<char *>(NULL))).second;
- }
-
- /** Shrink an Extensible class.
- *
- * @param key The key parameter is an arbitary string which identifies the extension data
- *
- * You must provide a key name. The given key name will be removed from the classes data. If
- * you provide a nonexistent key (case is important) then the function will return false.
- * @return Returns true on success.
- */
- bool Shrink(const std::string &key)
- {
- /* map::size_type map::erase( const key_type& key );
- * returns the number of elements removed, std::map
- * is single-associative so this should only be 0 or 1
- */
- return this->Extension_Items.erase(key);
- }
-
- /** Get an extension item.
- *
- * @param key The key parameter is an arbitary string which identifies the extension data
- * @param p If you provide a non-existent key, this value will be NULL. Otherwise a pointer to the item you requested will be placed in this templated parameter.
- * @return Returns true if the item was found and false if it was nor, regardless of wether 'p' is NULL. This allows you to store NULL values in Extensible.
- */
- template<typename T> bool GetExt(const std::string &key, T *&p)
- {
- std::map<std::string, void *>::iterator iter = this->Extension_Items.find(key); /* Find the item */
- if(iter != this->Extension_Items.end())
- {
- p = static_cast<T *>(iter->second); /* Item found */
- return true;
- }
- else
- {
- p = NULL; /* Item not found */
- return false;
- }
- }
-
- /** Get an extension item.
- *
- * @param key The key parameter is an arbitary string which identifies the extension data
- * @return Returns true if the item was found and false if it was not.
- *
- * This single-parameter version only checks if the key exists, it does nothing with
- * the 'data' field and is probably only useful in conjunction with the single-parameter
- * version of Extend().
- */
- bool GetExt(const std::string &key)
- {
- return (this->Extension_Items.find(key) != this->Extension_Items.end());
- }
-
- /** Get a list of all extension items names.
- * @param list A deque of strings to receive the list
- * @return This function writes a list of all extension items stored
- * in this object by name into the given deque and returns void.
- */
- void GetExtList(std::deque<std::string> &list)
- {
- for (std::map<std::string, void *>::iterator i = Extension_Items.begin(); i != Extension_Items.end(); ++i)
- {
- list.push_back(i->first);
- }
- }
-
-};
-
/** Class with the ability to keep flags on items, they should extend from this
* where T is an enum.
*/
@@ -485,6 +368,7 @@ typedef struct hostcore_ HostCore;
typedef struct exception_ Exception;
typedef struct session_ Session;
+#include "extensible.h"
#include "bots.h"
#include "opertype.h"
#include "modes.h"
diff --git a/src/core/ns_resetpass.c b/src/core/ns_resetpass.c
index 81bbc2655..e8396398c 100644
--- a/src/core/ns_resetpass.c
+++ b/src/core/ns_resetpass.c
@@ -61,22 +61,11 @@ class CommandNSResetPass : public Command
fprintf(mail->pipe, "\n.\n");
MailEnd(mail);
- char *c;
- time_t *t;
- if (na->nc->GetExt("ns_resetpass_code", c))
- {
- delete [] c;
- na->nc->Shrink("ns_resetpass_code");
- }
- if (na->nc->GetExt("ns_resetpass_time", t))
- {
- delete t;
- na->nc->Shrink("ns_resetpass_time");
- }
+ na->nc->Shrink("ns_resetpass_code");
+ na->nc->Shrink("ns_resetpass_time");
- na->nc->Extend("ns_resetpass_code", sstrdup(passcode));
- t = new time_t(time(NULL));
- na->nc->Extend("ns_resetpass_time", t);
+ na->nc->Extend("ns_resetpass_code", new ExtensibleItemPointerArray<char>(sstrdup(passcode)));
+ na->nc->Extend("ns_resetpass_time", new ExtensibleItemRegular<time_t>(time(NULL)));
alog("%s: %s!%s@%s used RESETPASS on %s (%s)", Config.s_NickServ, u->nick, u->GetIdent().c_str(), u->host, na->nick, na->nc->display);
notice_lang(Config.s_NickServ, u, NICK_RESETPASS_COMPLETE, na->nick);
@@ -111,8 +100,8 @@ class NSResetPass : public Module
this->AddCommand(NICKSERV, new CommandNSResetPass());
- Implementation i[] = { I_OnNickServHelp, I_OnDelCore, I_OnPreCommand };
- ModuleManager::Attach(i, this, 3);
+ Implementation i[] = { I_OnNickServHelp, I_OnPreCommand };
+ ModuleManager::Attach(i, this, 2);
}
void OnNickServHelp(User *u)
@@ -120,37 +109,19 @@ class NSResetPass : public Module
notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_RESETPASS);
}
- void OnDelCore(NickCore *nc)
+ EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> &params)
{
+ time_t t;
char *c;
- time_t *t;
- if (nc->GetExt("ns_resetpass_code", c))
- {
- delete [] c;
- nc->Shrink("ns_resetpass_code");
- }
- if (nc->GetExt("ns_resetpass_time", t))
- {
- delete t;
- nc->Shrink("ns_resetpass_time");
- }
- }
-
- EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> &params)
- {
if (service == Config.s_NickServ && command == "CONFIRM" && !params.empty())
{
NickAlias *na = findnick(u->nick);
- char *c;
- time_t *t;
- if (na && na->nc->GetExt("ns_resetpass_code", c) && na->nc->GetExt("ns_resetpass_time", t))
+ if (na && na->nc->GetExtArray("ns_resetpass_code", c) && na->nc->GetExtRegular<time_t>("ns_resetpass_time", t))
{
- if (*t < time(NULL) - 3600)
+ if (t < time(NULL) - 3600)
{
- delete [] c;
- delete t;
na->nc->Shrink("ns_resetpass_code");
na->nc->Shrink("ns_resetpass_time");
notice_lang(Config.s_NickServ, u, NICK_CONFIRM_EXPIRED);
@@ -160,8 +131,6 @@ class NSResetPass : public Module
std::string passcode = params[0].c_str();
if (passcode == c)
{
- delete [] c;
- delete t;
na->nc->Shrink("ns_resetpass_code");
na->nc->Shrink("ns_resetpass_time");
diff --git a/src/modules/os_info.c b/src/modules/os_info.c
index 194e2e8ee..a4b2cffc4 100644
--- a/src/modules/os_info.c
+++ b/src/modules/os_info.c
@@ -56,7 +56,6 @@ class CommandNSOInfo : public Command
{
const char *nick = params[1].c_str();
const char *info = params.size() > 2 ? params[2].c_str() : NULL;
- char *c;
NickAlias *na = NULL;
if (!info)
@@ -67,13 +66,9 @@ class CommandNSOInfo : public Command
if ((na = findnick(nick))) /* ok we've found the user */
{
- if (na->nc->GetExt("os_info", c))
- {
- delete [] c;
- na->nc->Shrink("os_info");
- }
+ na->nc->Shrink("os_info");
/* Add the module data to the user */
- na->nc->Extend("os_info", sstrdup(info));
+ na->nc->Extend("os_info", new ExtensibleItemPointerArray<char>(sstrdup(info)));
me->NoticeLang(Config.s_NickServ, u, OINFO_ADD_SUCCESS, nick);
}
@@ -90,12 +85,7 @@ class CommandNSOInfo : public Command
if ((na = findnick(nick))) /* ok we've found the user */
{
- char *c;
- if (na->nc->GetExt("os_info", c))
- {
- delete [] c;
- na->nc->Shrink("os_info");
- }
+ na->nc->Shrink("os_info");
me->NoticeLang(Config.s_NickServ, u, OINFO_DEL_SUCCESS, nick);
@@ -143,7 +133,6 @@ class CommandCSOInfo : public Command
{
const char *chan = params[0].c_str();
const char *info = params.size() > 2 ? params[2].c_str() : NULL;
- char *c;
ChannelInfo *ci = cs_findchan(chan);
if (!info)
@@ -152,13 +141,9 @@ class CommandCSOInfo : public Command
return MOD_CONT;
}
- if (ci->GetExt("os_info", c))
- {
- delete [] c;
- ci->Shrink("os_info");
- }
+ ci->Shrink("os_info");
/* Add the module data to the channel */
- ci->Extend("os_info", sstrdup(info));
+ ci->Extend("os_info", new ExtensibleItemPointerArray<char>(sstrdup(info)));
me->NoticeLang(Config.s_ChanServ, u, OCINFO_ADD_SUCCESS, chan);
return MOD_CONT;
@@ -170,12 +155,7 @@ class CommandCSOInfo : public Command
ChannelInfo *ci = cs_findchan(chan);
/* Del the module data from the channel */
- char *c;
- if (ci->GetExt("os_info", c))
- {
- delete [] c;
- ci->Shrink("os_info");
- }
+ ci->Shrink("os_info");
me->NoticeLang(Config.s_ChanServ, u, OCINFO_DEL_SUCCESS, chan);
return MOD_CONT;
@@ -230,8 +210,6 @@ class OSInfo : public Module
ModuleManager::Attach(I_OnPostCommand, this);
ModuleManager::Attach(I_OnSaveDatabase, this);
ModuleManager::Attach(I_OnBackupDatabase, this);
- ModuleManager::Attach(I_OnDelCore, this);
- ModuleManager::Attach(I_OnDelChan, this);
mLoadData();
ModuleManager::Attach(I_OnReload, this);
@@ -457,7 +435,6 @@ class OSInfo : public Module
{
int i;
NickCore *nc;
- char *c;
ChannelInfo *ci;
OnSaveDatabase();
@@ -467,11 +444,7 @@ class OSInfo : public Module
/* Remove the nick Cores */
for (nc = nclists[i]; nc; nc = nc->next)
{
- if (nc->GetExt("os_info", c));
- {
- delete [] c;
- nc->Shrink("os_info");
- }
+ nc->Shrink("os_info");
}
}
@@ -479,11 +452,7 @@ class OSInfo : public Module
{
for (ci = chanlists[i]; ci; ci = ci->next)
{
- if (ci->GetExt("os_info", c))
- {
- delete [] c;
- ci->Shrink("os_info");
- }
+ ci->Shrink("os_info");
}
}
@@ -515,7 +484,7 @@ class OSInfo : public Module
{
/* If we have any info on this user */
char *c;
- if (na->nc->GetExt("os_info", c))
+ if (na->nc->GetExtArray("os_info", c))
u->SendMessage(Config.s_NickServ, " OperInfo: %s", c);
}
}
@@ -531,7 +500,7 @@ class OSInfo : public Module
{
/* If we have any info on this channel */
char *c;
- if (ci->GetExt("os_info", c))
+ if (ci->GetExtArray("os_info", c))
u->SendMessage(Config.s_ChanServ, " OperInfo: %s", c);
}
}
@@ -561,7 +530,7 @@ class OSInfo : public Module
{
/* If we have any info on this user */
char *c;
- if (nc->GetExt("os_info", c))
+ if (nc->GetExtArray("os_info", c))
fprintf(out, "N %s %s\n", nc->display, c);
}
}
@@ -572,7 +541,7 @@ class OSInfo : public Module
{
/* If we have any info on this channel */
char *c;
- if (ci->GetExt("os_info", c))
+ if (ci->GetExtArray("os_info", c))
fprintf(out, "C %s %s\n", ci->name, c);
}
}
@@ -585,28 +554,6 @@ class OSInfo : public Module
ModuleDatabaseBackup(OSInfoDBName);
}
- void OnDelCore(NickCore *nc)
- {
- char *c;
-
- if (nc->GetExt("os_info", c))
- {
- delete [] c;
- nc->Shrink("os_info");
- }
- }
-
- void OnDelChan(ChannelInfo *ci)
- {
- char *c;
-
- if (ci->GetExt("os_info", c))
- {
- delete [] c;
- ci->Shrink("os_info");
- }
- }
-
void OnNickServHelp(User *u)
{
this->NoticeLang(Config.s_NickServ, u, OINFO_HELP_CMD);
@@ -663,12 +610,12 @@ int mLoadData()
if (!stricmp(type, "C"))
{
if ((ci = cs_findchan(name)))
- ci->Extend("os_info", sstrdup(info));
+ ci->Extend("os_info", new ExtensibleItemPointerArray<char>(sstrdup(info)));
}
else if (!stricmp(type, "N"))
{
if ((na = findnick(name)))
- na->nc->Extend("os_info", sstrdup(info));
+ na->nc->Extend("os_info", new ExtensibleItemPointerArray<char>(sstrdup(info)));
}
delete [] info;
}
diff --git a/src/protocol/bahamut.c b/src/protocol/bahamut.c
index 6ec072b87..aee8b6f22 100644
--- a/src/protocol/bahamut.c
+++ b/src/protocol/bahamut.c
@@ -325,7 +325,7 @@ class BahamutIRCdProto : public IRCDProto
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15], *c;
+ char svidbuf[15];
if (!u->nc)
return;
@@ -333,13 +333,8 @@ class BahamutIRCdProto : public IRCDProto
srand(time(NULL));
snprintf(svidbuf, sizeof(svidbuf), "%d", rand());
- if (u->nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- u->nc->Shrink("authenticationtoken");
- }
-
- u->nc->Extend("authenticationtoken", sstrdup(svidbuf));
+ u->nc->Shrink("authenticationtoken");
+ u->nc->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf)));
BotInfo *bi = findbot(Config.s_NickServ);
u->SetMode(bi, UMODE_REGISTERED);
@@ -712,20 +707,6 @@ class ProtoBahamut : public Module
moduleAddModes();
pmodule_ircd_proto(&ircd_proto);
- moduleAddIRCDMsgs();
-
- ModuleManager::Attach(I_OnDelCore, this);
- }
-
- void OnDelCore(NickCore *nc)
- {
- char *c;
-
- if (nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- nc->Shrink("authenticationtoken");
- }
}
};
diff --git a/src/protocol/inspircd11.c b/src/protocol/inspircd11.c
index 1eb6ba56e..cdeb58797 100644
--- a/src/protocol/inspircd11.c
+++ b/src/protocol/inspircd11.c
@@ -350,20 +350,15 @@ class InspIRCdProto : public IRCDProto
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15], *c;
+ char svidbuf[15];
if (!u->nc)
return;
snprintf(svidbuf, sizeof(svidbuf), "%ld", static_cast<long>(u->timestamp));
- if (u->nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- u->nc->Shrink("authenticationtoken");
- }
-
- u->nc->Extend("authenticationtoken", sstrdup(svidbuf));
+ u->nc->Shrink("authenticationtoken");
+ u->nc->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf)));
}
} ircd_proto;
@@ -1050,19 +1045,6 @@ class ProtoInspIRCd : public Module
pmodule_ircd_proto(&ircd_proto);
moduleAddIRCDMsgs();
-
- ModuleManager::Attach(I_OnDelCore, this);
- }
-
- void OnDelCore(NickCore *nc)
- {
- char *c;
-
- if (nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- nc->Shrink("authenticationtoken");
- }
}
};
diff --git a/src/protocol/ratbox.c b/src/protocol/ratbox.c
index f10c86206..f10a4abcd 100644
--- a/src/protocol/ratbox.c
+++ b/src/protocol/ratbox.c
@@ -323,20 +323,15 @@ class RatboxProto : public IRCDTS6Proto
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15], *c;
+ char svidbuf[15];
if (!u->nc)
return;
snprintf(svidbuf, sizeof(svidbuf), "%ld", static_cast<long>(u->timestamp));
- if (u->nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- u->nc->Shrink("authenticationtoken");
- }
-
- u->nc->Extend("authenticationtoken", sstrdup(svidbuf));
+ u->nc->Shrink("authenticationtoken");
+ u->nc->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(svidbuf));
}
} ircd_proto;
@@ -852,8 +847,6 @@ class ProtoRatbox : public Module
pmodule_ircd_proto(&ircd_proto);
moduleAddIRCDMsgs();
-
- ModuleManager::Attach(I_OnDelCore, this);
}
~ProtoRatbox()
@@ -861,17 +854,6 @@ class ProtoRatbox : public Module
delete [] TS6SID;
}
- void OnDelCore(NickCore *nc)
- {
- char *c;
-
- if (nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- nc->Shrink("authenticationtoken");
- }
- }
-
};
MODULE_INIT(ProtoRatbox)
diff --git a/src/protocol/unreal32.c b/src/protocol/unreal32.c
index 7dc55a452..085107e5c 100644
--- a/src/protocol/unreal32.c
+++ b/src/protocol/unreal32.c
@@ -449,7 +449,7 @@ class UnrealIRCdProto : public IRCDProto
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15], *c;
+ char svidbuf[15];
if (!u->nc)
return;
@@ -457,13 +457,8 @@ class UnrealIRCdProto : public IRCDProto
srand(time(NULL));
snprintf(svidbuf, sizeof(svidbuf), "%d", rand());
- if (u->nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- u->nc->Shrink("authenticationtoken");
- }
-
- u->nc->Extend("authenticationtoken", sstrdup(svidbuf));
+ u->nc->Shrink("authenticationtoken");
+ u->nc->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf)));
BotInfo *bi = findbot(Config.s_NickServ);
u->SetMode(bi, UMODE_REGISTERED);
@@ -1170,19 +1165,6 @@ class ProtoUnreal : public Module
pmodule_ircd_proto(&ircd_proto);
moduleAddIRCDMsgs();
-
- ModuleManager::Attach(I_OnDelCore, this);
- }
-
- void OnDelCore(NickCore *nc)
- {
- char *c;
-
- if (nc->GetExt("authenticationtoken", c))
- {
- delete [] c;
- nc->Shrink("authenticationtoken");
- }
}
};
diff --git a/src/users.c b/src/users.c
index 5783dfb56..1a02e5344 100644
--- a/src/users.c
+++ b/src/users.c
@@ -341,12 +341,12 @@ void User::SendMessage(const char *source, const std::string &msg)
*/
void User::CheckAuthenticationToken(const char *svid)
{
- const char *c = NULL;
+ char *c;
NickAlias *na;
if ((na = findnick(this->nick)))
{
- if (na->nc && na->nc->GetExt("authenticationtoken", c))
+ if (na->nc && na->nc->GetExtArray("authenticationtoken", c))
{
if (svid && c && !strcmp(svid, c))
{