summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorcyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2009-03-23 21:05:29 +0000
committercyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2009-03-23 21:05:29 +0000
commitb3eeb815b6e01456b0c987305454bc9b5a5f5a14 (patch)
treef3832a89e3a123fe4c57223bf1b18294be9f0edd /src/core
parentda43e02228dfddc921946a94ae3790a35559b1d5 (diff)
Replace manually allocated array for NickCore's access list with an std::vector, cleans up the code and provides a more sane interface, also fixes bug #1023 in the process.
Also add missing help for NS ACCESS. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2201 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ns_access.c72
-rw-r--r--src/core/ns_register.c15
2 files changed, 29 insertions, 58 deletions
diff --git a/src/core/ns_access.c b/src/core/ns_access.c
index 329d5110a..5766a4028 100644
--- a/src/core/ns_access.c
+++ b/src/core/ns_access.c
@@ -23,10 +23,9 @@ class CommandNSAccess : public Command
CommandReturn DoServAdminList(User *u, std::vector<std::string> &params, NickCore *nc)
{
const char *mask = params.size() > 2 ? params[2].c_str() : NULL;
- char **access;
- int i;
+ unsigned i;
- if (!nc->accesscount)
+ if (nc->access.empty())
{
notice_lang(s_NickServ, u, NICK_ACCESS_LIST_X_EMPTY, nc->display);
return MOD_CONT;
@@ -47,11 +46,12 @@ class CommandNSAccess : public Command
}
notice_lang(s_NickServ, u, NICK_ACCESS_LIST_X, params[1].c_str());
- for (access = nc->access, i = 0; i < nc->accesscount; ++access, ++i)
+ for (i = 0; i < nc->access.size(); ++i)
{
- if (mask && !Anope::Match(*access, mask, true))
+ std::string access = nc->GetAccess(i);
+ if (mask && !Anope::Match(access, mask, true))
continue;
- u->SendMessage(s_NickServ, " %s", *access);
+ u->SendMessage(s_NickServ, " %s", access.c_str());
}
return MOD_CONT;
@@ -59,33 +59,25 @@ class CommandNSAccess : public Command
CommandReturn DoAdd(User *u, std::vector<std::string> &params, NickCore *nc, const char *mask)
{
- char **access;
- int i;
-
if (!mask)
{
this->OnSyntaxError(u);
return MOD_CONT;
}
- if (nc->accesscount >= NSAccessMax)
+ if (nc->access.size() >= NSAccessMax)
{
notice_lang(s_NickServ, u, NICK_ACCESS_REACHED_LIMIT, NSAccessMax);
return MOD_CONT;
}
- for (access = nc->access, i = 0; i < nc->accesscount; ++access, ++i)
+ if (nc->FindAccess(mask))
{
- if (!strcmp(*access, mask))
- {
- notice_lang(s_NickServ, u, NICK_ACCESS_ALREADY_PRESENT, *access);
- return MOD_CONT;
- }
+ notice_lang(s_NickServ, u, NICK_ACCESS_ALREADY_PRESENT, *access);
+ return MOD_CONT;
}
- ++nc->accesscount;
- nc->access = static_cast<char **>(srealloc(nc->access, sizeof(char *) * nc->accesscount));
- nc->access[nc->accesscount - 1] = sstrdup(mask);
+ nc->AddAccess(mask);
notice_lang(s_NickServ, u, NICK_ACCESS_ADDED, mask);
return MOD_CONT;
@@ -93,59 +85,41 @@ class CommandNSAccess : public Command
CommandReturn DoDel(User *u, std::vector<std::string> &params, NickCore *nc, const char *mask)
{
- char **access;
- int i;
-
if (!mask)
{
this->OnSyntaxError(u);
return MOD_CONT;
}
- for (access = nc->access, i = 0; i < nc->accesscount; ++access, ++i)
- {
- if (!stricmp(*access, mask))
- break;
- }
- if (i == nc->accesscount)
+ if (!nc->FindAccess(mask))
{
notice_lang(s_NickServ, u, NICK_ACCESS_NOT_FOUND, mask);
return MOD_CONT;
}
- notice_lang(s_NickServ, u, NICK_ACCESS_DELETED, *access);
- delete [] *access;
- --nc->accesscount;
- if (i < nc->accesscount) /* if it wasn't the last entry... */
- memmove(access, access + 1, (nc->accesscount - i) * sizeof(char *));
- if (nc->accesscount) /* if there are any entries left... */
- nc->access = static_cast<char **>(srealloc(nc->access, nc->accesscount * sizeof(char *)));
- else
- {
- free(nc->access);
- nc->access = NULL;
- }
+ notice_lang(s_NickServ, u, NICK_ACCESS_DELETED, mask);
+ nc->EraseAccess(mask);
return MOD_CONT;
}
CommandReturn DoList(User *u, std::vector<std::string> &params, NickCore *nc, const char *mask)
{
- char **access;
- int i;
+ unsigned i;
- if (!nc->accesscount)
+ if (nc->access.empty())
{
notice_lang(s_NickServ, u, NICK_ACCESS_LIST_EMPTY, u->nick);
return MOD_CONT;
}
notice_lang(s_NickServ, u, NICK_ACCESS_LIST);
- for (access = nc->access, i = 0; i < nc->accesscount; ++access, ++i)
+ for (i = 0; i < nc->access.size(); ++i)
{
- if (mask && !Anope::Match(*access, mask, true))
+ std::string access = nc->GetAccess(i);
+ if (mask && !Anope::Match(access, mask, true))
continue;
- u->SendMessage(s_NickServ, " %s", *access);
+ u->SendMessage(s_NickServ, " %s", access.c_str());
}
return MOD_CONT;
@@ -187,6 +161,12 @@ class CommandNSAccess : public Command
return MOD_CONT;
}
+ bool OnHelp(User *u, std::string &subcommand)
+ {
+ notice_help(s_NickServ, u, NICK_HELP_ACCESS);
+ return true;
+ }
+
void OnSyntaxError(User *u)
{
syntax_error(s_NickServ, u, "ACCESS", NICK_ACCESS_SYNTAX);
diff --git a/src/core/ns_register.c b/src/core/ns_register.c
index dc59caecb..826c58c66 100644
--- a/src/core/ns_register.c
+++ b/src/core/ns_register.c
@@ -71,16 +71,7 @@ class CommandNSConfirm : public Command
na->time_registered = na->last_seen = time(NULL);
if (NSAddAccessOnReg)
- {
- na->nc->accesscount = 1;
- na->nc->access = static_cast<char **>(scalloc(sizeof(char *), 1));
- na->nc->access[0] = create_mask(u);
- }
- else
- {
- na->nc->accesscount = 0;
- na->nc->access = NULL;
- }
+ na->nc->AddAccess(create_mask(u));
na->nc->language = NSDefLanguage;
if (nr->email)
@@ -91,7 +82,7 @@ class CommandNSConfirm : public Command
u->nc = na->nc;
alog("%s: '%s' registered by %s@%s (e-mail: %s)", s_NickServ, u->nick, u->GetIdent().c_str(), u->host, nr->email ? nr->email : "none");
if (NSAddAccessOnReg)
- notice_lang(s_NickServ, u, NICK_REGISTERED, u->nick, na->nc->access[0]);
+ notice_lang(s_NickServ, u, NICK_REGISTERED, u->nick, na->nc->GetAccess(0).c_str());
else
notice_lang(s_NickServ, u, NICK_REGISTERED_NO_MASK, u->nick);
send_event(EVENT_NICK_REGISTERED, 1, u->nick);
@@ -311,7 +302,7 @@ class CommandNSRegister : public CommandNSConfirm
this->OnSyntaxError(u);
else if (time(NULL) < u->lastnickreg + NSRegDelay)
notice_lang(s_NickServ, u, NICK_REG_PLEASE_WAIT, NSRegDelay);
- else if ((na = findnick(u->nick)))
+ else if ((na = findnick(u->nick)))
{
/* i.e. there's already such a nick regged */
if (na->status & NS_FORBIDDEN)