summaryrefslogtreecommitdiff
path: root/src/core/ns_access.c
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/ns_access.c
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/ns_access.c')
-rw-r--r--src/core/ns_access.c72
1 files changed, 26 insertions, 46 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);