summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-12-20 18:39:52 +0000
committerAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-12-20 18:39:52 +0000
commit7a7f1f8390f68f84350de63ff330184999264fcc (patch)
tree3990cde97ba0cd53db38114de9e4412b24930dd6 /src
parent861fe9e7b32c8e1e523cc774547e460c9ed67289 (diff)
Rewrote part of extensible, it will now automatically unallocate memory for us so we don't have to manually delete it everywhere anymore
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2711 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-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
7 files changed, 38 insertions, 195 deletions
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))
{