summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/ns_access.c72
-rw-r--r--src/core/ns_register.c15
-rw-r--r--src/nickcore.cpp104
-rw-r--r--src/nickserv.c61
4 files changed, 127 insertions, 125 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)
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index af4680f45..6dadc9217 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -1,34 +1,70 @@
-#include "services.h"
-
-NickCore::NickCore()
-{
- next = prev = NULL;
- display = email = greet = url = NULL;
- ot = NULL;
- pass[0] = '\0';
- icq = flags = 0;
- language = accesscount = channelcount = 0;
- lastmail = 0;
-}
-
-bool NickCore::HasCommand(const std::string &cmdstr) const
-{
- if (!this->ot)
- {
- // No opertype.
- return false;
- }
-
- return this->ot->HasCommand(cmdstr);
-}
-
-bool NickCore::HasPriv(const std::string &privstr) const
-{
- if (!this->ot)
- {
- // No opertype.
- return false;
- }
-
- return this->ot->HasPriv(privstr);
-}
+#include "services.h"
+
+NickCore::NickCore()
+{
+ next = prev = NULL;
+ display = email = greet = url = NULL;
+ ot = NULL;
+ pass[0] = '\0';
+ icq = flags = 0;
+ language = channelcount = 0;
+ lastmail = 0;
+}
+
+bool NickCore::HasCommand(const std::string &cmdstr) const
+{
+ if (!this->ot)
+ {
+ // No opertype.
+ return false;
+ }
+
+ return this->ot->HasCommand(cmdstr);
+}
+
+bool NickCore::HasPriv(const std::string &privstr) const
+{
+ if (!this->ot)
+ {
+ // No opertype.
+ return false;
+ }
+
+ return this->ot->HasPriv(privstr);
+}
+
+void NickCore::AddAccess(const std::string &entry)
+{
+ access.push_back(entry);
+}
+
+std::string NickCore::GetAccess(unsigned entry)
+{
+ if (access.empty() || entry >= access.size())
+ return "";
+ return access[entry];
+}
+
+bool NickCore::FindAccess(const std::string &entry)
+{
+ for (unsigned i = 0; i < access.size(); ++i)
+ if (access[i] == entry)
+ return true;
+
+ return false;
+}
+
+void NickCore::EraseAccess(const std::string &entry)
+{
+ for (unsigned i = 0; i < access.size(); ++i)
+ if (access[i] == entry)
+ {
+ access.erase(access.begin() + i);
+ break;
+ }
+}
+
+void NickCore::ClearAccess()
+{
+ access.clear();
+}
diff --git a/src/nickserv.c b/src/nickserv.c
index 45db1be87..366f9ee43 100644
--- a/src/nickserv.c
+++ b/src/nickserv.c
@@ -79,7 +79,6 @@ void get_core_stats(long *nrec, long *memuse)
long count = 0, mem = 0;
int i, j;
NickCore *nc;
- char **accptr;
for (i = 0; i < 1024; i++)
{
@@ -100,13 +99,9 @@ void get_core_stats(long *nrec, long *memuse)
if (nc->greet)
mem += strlen(nc->greet) + 1;
- mem += sizeof(char *) * nc->accesscount;
- for (accptr = nc->access, j = 0; j < nc->accesscount;
- accptr++, j++)
- {
- if (*accptr)
- mem += strlen(*accptr) + 1;
- }
+ mem += sizeof(std::string) * nc->access.size();
+ for (j = 0; j < nc->access.size(); ++j)
+ mem += nc->GetAccess(j).length() + 1;
mem += nc->memos.memos.size() * sizeof(Memo);
for (j = 0; j < nc->memos.memos.size(); j++)
@@ -280,14 +275,20 @@ void load_ns_dbase()
if (nc->flags & NI_SERVICES_OPER)
slist_add(&servopers, nc);
- SAFE(read_int16(&nc->accesscount, f));
- if (nc->accesscount)
+ uint16 accesscount;
+ SAFE(read_int16(&accesscount, f));
+ if (accesscount)
{
- char **access;
- access = static_cast<char **>(scalloc(sizeof(char *) * nc->accesscount, 1));
- nc->access = access;
- for (j = 0; j < nc->accesscount; j++, access++)
- SAFE(read_string(access, f));
+ for (j = 0; j < accesscount; ++j)
+ {
+ char *access;
+ SAFE(read_string(&access, f));
+ if (access)
+ {
+ nc->AddAccess(access);
+ delete [] access;
+ }
+ }
}
SAFE(read_int16(&tmp16, f));
@@ -415,7 +416,6 @@ void save_ns_dbase()
int i, j;
NickAlias *na;
NickCore *nc;
- char **access;
static time_t lastwarn = 0;
if (!(f = open_db(s_NickServ, NickDBName, "w", NICK_VERSION)))
@@ -438,10 +438,12 @@ void save_ns_dbase()
SAFE(write_int32(nc->flags, f));
SAFE(write_int16(nc->language, f));
- SAFE(write_int16(nc->accesscount, f));
- for (j = 0, access = nc->access; j < nc->accesscount;
- j++, access++)
- SAFE(write_string(*access, f));
+ SAFE(write_int16(nc->access.size(), f));
+ for (j = 0; j < nc->access.size(); ++j)
+ {
+ std::string access = nc->GetAccess(j);
+ SAFE(write_string(access.c_str(), f));
+ }
SAFE(write_int16(nc->memos.memos.size(), f));
SAFE(write_int16(nc->memos.memomax, f));
@@ -848,7 +850,7 @@ int is_on_access(User * u, NickCore * nc)
char *buf;
char *buf2 = NULL;
- if (nc->accesscount == 0)
+ if (nc->access.empty())
return 0;
buf = new char[u->GetIdent().length() + strlen(u->host) + 2];
@@ -862,10 +864,11 @@ int is_on_access(User * u, NickCore * nc)
}
}
- for (i = 0; i < nc->accesscount; i++)
+ for (i = 0; i < nc->access.size(); i++)
{
- if (Anope::Match(buf, nc->access[i], false)
- || (ircd->vhost ? Anope::Match(buf2, nc->access[i], false) : 0))
+ std::string access = nc->GetAccess(i);
+ if (Anope::Match(buf, access, false)
+ || (ircd->vhost ? Anope::Match(buf2, access, false) : 0))
{
delete [] buf;
if (ircd->vhost)
@@ -1049,15 +1052,7 @@ static int delcore(NickCore * nc)
if (nc->url)
delete [] nc->url;
- if (nc->access)
- {
- for (i = 0; i < nc->accesscount; i++)
- {
- if (nc->access[i])
- delete [] nc->access[i];
- }
- free(nc->access);
- }
+ nc->ClearAccess();
if (!nc->memos.memos.empty())
{