summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/db_plain.cpp29
-rw-r--r--src/core/hs_del.c3
-rw-r--r--src/core/hs_delall.c3
-rw-r--r--src/core/hs_group.c37
-rw-r--r--src/core/hs_list.c125
-rw-r--r--src/core/hs_off.c9
-rw-r--r--src/core/hs_on.c28
-rw-r--r--src/core/hs_set.c3
-rw-r--r--src/core/hs_setall.c46
-rw-r--r--src/core/ns_info.c17
-rw-r--r--src/hostserv.c381
-rw-r--r--src/modules/hs_request.c159
-rw-r--r--src/nickalias.cpp2
-rw-r--r--src/tools/db-convert.c55
-rw-r--r--src/tools/db-convert.h20
-rw-r--r--src/users.c2
16 files changed, 318 insertions, 601 deletions
diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp
index 4648378a8..5862e679c 100644
--- a/src/core/db_plain.cpp
+++ b/src/core/db_plain.cpp
@@ -63,8 +63,10 @@ static void ReadDatabase(Module *m = NULL)
if (buf[0] == ':')
{
buf.erase(buf.begin());
- if (!buf.empty())
+ if (!buf.empty() && !sep.StreamEnd())
params.push_back(buf + " " + sep.GetRemaining());
+ else if (!buf.empty())
+ params.push_back(buf);
}
else
params.push_back(buf);
@@ -457,15 +459,6 @@ static void LoadChanInfo(const std::vector<std::string> &params)
alog("[db_plain]: loaded channel %s", ci->name);
}
-static void LoadHostInfo(const std::vector<std::string> &params)
-{
- if (!findnick(params[0].c_str()))
- return;
- addHostCore(params[0].c_str(), params[4].empty() ? NULL : const_cast<char *>(params[4].c_str()), const_cast<char *>(params[3].c_str()), params[1].c_str(), strtol(params[2].c_str(), NULL, 10)); // XXX
- if (debug > 1)
- alog("[db_plain]: loaded vhost for %s", params[0].c_str());
-}
-
static void LoadOperInfo(const std::vector<std::string> &params)
{
if (params[0] == "STATS")
@@ -538,8 +531,6 @@ class DBPlain : public Module
LoadBotInfo(otherparams);
else if (key == "CH")
LoadChanInfo(otherparams);
- else if (key == "HI")
- LoadHostInfo(otherparams);
else if (key == "OS")
LoadOperInfo(otherparams);
@@ -617,6 +608,10 @@ class DBPlain : public Module
na->SetFlag(NS_NO_EXPIRE);
}
}
+ else if (key == "VHOST")
+ {
+ na->hostinfo.SetVhost(params.size() > 3 ? params[3] : "", params[2], params[0], strtol(params[1].c_str(), NULL, 10));
+ }
return EVENT_CONTINUE;
}
@@ -927,6 +922,10 @@ class DBPlain : public Module
{
db << "MD FLAGS" << (na->HasFlag(NS_FORBIDDEN) ? " FORBIDDEN" : "") << (na->HasFlag(NS_NO_EXPIRE) ? " NOEXPIRE " : "") << endl;
}
+ if (na->hostinfo.HasVhost())
+ {
+ db << "MD VHOST " << na->hostinfo.GetCreator() << " " << na->hostinfo.GetTime() << " " << na->hostinfo.GetHost() << " :" << na->hostinfo.GetIdent() << endl;
+ }
FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, na));
}
@@ -1083,12 +1082,6 @@ class DBPlain : public Module
}
}
- HostCore *hc;
- for (hc = hostCoreListHead(); hc; hc = hc->next)
- {
- db << "HI " << hc->nick << " " << hc->creator << " " << hc->time << " " << hc->vHost << " :" << hc->vIdent << endl;
- }
-
for (i = 0; i < akills.count; ++i)
{
Akill *ak = static_cast<Akill *>(akills.list[i]);
diff --git a/src/core/hs_del.c b/src/core/hs_del.c
index 3c2661197..69d9b8524 100644
--- a/src/core/hs_del.c
+++ b/src/core/hs_del.c
@@ -34,7 +34,8 @@ class CommandHSDel : public Command
return MOD_CONT;
}
alog("vHost for user \002%s\002 deleted by oper \002%s\002", nick, u->nick);
- delHostCore(nick);
+ FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na));
+ na->hostinfo.RemoveVhost();
notice_lang(Config.s_HostServ, u, HOST_DEL, nick);
}
else
diff --git a/src/core/hs_delall.c b/src/core/hs_delall.c
index bd874f30f..89a227207 100644
--- a/src/core/hs_delall.c
+++ b/src/core/hs_delall.c
@@ -35,11 +35,12 @@ class CommandHSDelAll : public Command
notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick);
return MOD_CONT;
}
+ FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na));
nc = na->nc;
for (i = 0; i < nc->aliases.count; ++i)
{
na = static_cast<NickAlias *>(nc->aliases.list[i]);
- delHostCore(na->nick);
+ na->hostinfo.RemoveVhost();
}
alog("vHosts for all nicks in group \002%s\002 deleted by oper \002%s\002", nc->display, u->nick);
notice_lang(Config.s_HostServ, u, HOST_DELALL, nc->display);
diff --git a/src/core/hs_group.c b/src/core/hs_group.c
index 4a2ef6036..335044221 100644
--- a/src/core/hs_group.c
+++ b/src/core/hs_group.c
@@ -26,39 +26,14 @@ class CommandHSGroup : public Command
CommandReturn Execute(User *u, const std::vector<ci::string> &params)
{
- HostCore *tmp;
- char *vHost = NULL;
- char *vIdent = NULL;
- char *creator = NULL;
- HostCore *head = NULL;
- time_t time;
- bool found = false;
-
- head = hostCoreListHead();
-
- tmp = findHostCore(head, u->nick, &found);
- if (found)
+ NickAlias *na = findnick(u->nick);
+ if (na && u->nc == na->nc && na->hostinfo.HasVhost())
{
- if (!tmp)
- tmp = head; /* incase first in list */
- else if (tmp->next) /* we dont want the previous entry were not inserting! */
- tmp = tmp->next; /* jump to the next */
-
- vHost = sstrdup(tmp->vHost);
- if (tmp->vIdent)
- vIdent = sstrdup(tmp->vIdent);
- creator = sstrdup(tmp->creator);
- time = tmp->time;
-
- do_hs_sync(u->nc, vIdent, vHost, creator, time);
- if (tmp->vIdent)
- notice_lang(Config.s_HostServ, u, HOST_IDENT_GROUP, u->nc->display, vIdent, vHost);
+ HostServSyncVhosts(na);
+ if (!na->hostinfo.GetIdent().empty())
+ notice_lang(Config.s_HostServ, u, HOST_IDENT_GROUP, u->nc->display, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
else
- notice_lang(Config.s_HostServ, u, HOST_GROUP, u->nc->display, vHost);
- delete [] vHost;
- if (vIdent)
- delete [] vIdent;
- delete [] creator;
+ notice_lang(Config.s_HostServ, u, HOST_GROUP, u->nc->display, na->hostinfo.GetHost().c_str());
}
else
notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED);
diff --git a/src/core/hs_list.c b/src/core/hs_list.c
index 6d36f00dd..4943c2e3c 100644
--- a/src/core/hs_list.c
+++ b/src/core/hs_list.c
@@ -24,83 +24,55 @@ class CommandHSList : public Command
CommandReturn Execute(User *u, const std::vector<ci::string> &params)
{
- const char *key = params.size() ? params[0].c_str() : NULL;
- struct tm *tm;
- char buf[BUFSIZE];
- int counter = 1;
- int from = 0, to = 0;
- char *tmp = NULL;
- char *s = NULL;
+ ci::string key = params.size() ? params[0] : "";
+ int from = 0, to = 0, counter = 1;
unsigned display_counter = 0;
- HostCore *head = NULL;
- HostCore *current;
-
- head = hostCoreListHead();
+ tm *tm;
+ char buf[BUFSIZE];
- current = head;
- if (!current)
- notice_lang(Config.s_HostServ, u, HOST_EMPTY);
- else
+ /**
+ * Do a check for a range here, then in the next loop
+ * we'll only display what has been requested..
+ **/
+ if (!key.empty() && key[0] == '#')
{
- /**
- * Do a check for a range here, then in the next loop
- * we'll only display what has been requested..
- **/
- if (key)
+ size_t tmp = key.find('-');
+ if (tmp == ci::string::npos || tmp == key.size() || tmp == 1)
+ {
+ notice_lang(Config.s_HostServ, u, LIST_INCORRECT_RANGE);
+ return MOD_CONT;
+ }
+ for (unsigned i = 1; i < key.size(); ++i)
{
- if (key[0] == '#')
+ if (!isdigit(key[i]) && i != tmp)
{
- tmp = myStrGetOnlyToken((key + 1), '-', 0); /* Read FROM out */
- if (!tmp)
- {
- notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE);
- return MOD_CONT;
- }
- for (s = tmp; *s; ++s)
- {
- if (!isdigit(*s))
- {
- delete [] tmp;
- notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE);
- return MOD_CONT;
- }
- }
- from = atoi(tmp);
- delete [] tmp;
- tmp = myStrGetTokenRemainder(key, '-', 1); /* Read TO out */
- if (!tmp)
- {
- notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE);
- return MOD_CONT;
- }
- for (s = tmp; *s; ++s)
- {
- if (!isdigit(*s))
- {
- delete [] tmp;
- notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE);
- return MOD_CONT;
- }
- }
- to = atoi(tmp);
- delete [] tmp;
- key = NULL;
+ notice_lang(Config.s_HostServ, u, LIST_INCORRECT_RANGE);
+ return MOD_CONT;
}
+ from = atoi(key.substr(1, tmp - 1).c_str());
+ to = atoi(key.substr(tmp + 1, key.size()).c_str());
}
+ }
- while (current)
+ for (int j = 0; j < 1024; ++j)
+ {
+ for (NickAlias *na = nalists[j]; na; na = na->next)
{
- if (key)
+ if (!na->hostinfo.HasVhost())
+ continue;
+
+ if (!key.empty() && key[0] != '#')
{
- if ((Anope::Match(current->nick, key, false) || Anope::Match(current->vHost, key, false)) && display_counter < Config.NSListMax)
+ if ((Anope::Match(na->nick, key) || Anope::Match(na->hostinfo.GetHost(), key.c_str())) && display_counter < Config.NSListMax)
{
++display_counter;
- tm = localtime(&current->time);
+ time_t time = na->hostinfo.GetTime();
+ tm = localtime(&time);
strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
- if (current->vIdent)
- notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf);
+ if (!na->hostinfo.GetIdent().empty())
+ notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf);
else
- notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf);
+ notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick, na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf);
}
}
else
@@ -112,26 +84,27 @@ class CommandHSList : public Command
if (((counter >= from && counter <= to) || (!from && !to)) && display_counter < Config.NSListMax)
{
++display_counter;
- tm = localtime(&current->time);
+ time_t time = na->hostinfo.GetTime();
+ tm = localtime(&time);
strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
- if (current->vIdent)
- notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf);
+ if (!na->hostinfo.GetIdent().empty())
+ notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf);
else
- notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf);
+ notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick, na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf);
}
}
++counter;
- current = current->next;
- }
- if (key)
- notice_lang(Config.s_HostServ, u, HOST_LIST_KEY_FOOTER, key, display_counter);
- else {
- if (from)
- notice_lang(Config.s_HostServ, u, HOST_LIST_RANGE_FOOTER, from, to);
- else
- notice_lang(Config.s_HostServ, u, HOST_LIST_FOOTER, display_counter);
}
}
+ if (!key.empty())
+ notice_lang(Config.s_HostServ, u, HOST_LIST_KEY_FOOTER, key.c_str(), display_counter);
+ else
+ {
+ if (from)
+ notice_lang(Config.s_HostServ, u, HOST_LIST_RANGE_FOOTER, from, to);
+ else
+ notice_lang(Config.s_HostServ, u, HOST_LIST_FOOTER, display_counter);
+ }
return MOD_CONT;
}
diff --git a/src/core/hs_off.c b/src/core/hs_off.c
index 84f4527ee..b5953e92c 100644
--- a/src/core/hs_off.c
+++ b/src/core/hs_off.c
@@ -24,12 +24,9 @@ class CommandHSOff : public Command
CommandReturn Execute(User *u, const std::vector<ci::string> &params)
{
- char *vhost;
- char *vident = NULL;
-
- vhost = getvHost(u->nick);
- vident = getvIdent(u->nick);
- if (!vhost && !vident)
+ NickAlias *na = findnick(u->nick);
+
+ if (!na || !na->hostinfo.HasVhost())
notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED);
else
{
diff --git a/src/core/hs_on.c b/src/core/hs_on.c
index aaddbf28d..8ccf65ff6 100644
--- a/src/core/hs_on.c
+++ b/src/core/hs_on.c
@@ -24,33 +24,29 @@ class CommandHSOn : public Command
CommandReturn Execute(User *u, const std::vector<ci::string> &params)
{
- char *vHost;
- char *vIdent = NULL;
-
- vHost = getvHost(u->nick);
- vIdent = getvIdent(u->nick);
- if (!vHost)
- notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED);
- else
+ NickAlias *na = findnick(u->nick);
+ if (na && u->nc == na->nc && na->hostinfo.HasVhost())
{
- if (vIdent)
- notice_lang(Config.s_HostServ, u, HOST_IDENT_ACTIVATED, vIdent, vHost);
+ if (!na->hostinfo.GetIdent().empty())
+ notice_lang(Config.s_HostServ, u, HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
else
- notice_lang(Config.s_HostServ, u, HOST_ACTIVATED, vHost);
- ircdproto->SendVhost(u, vIdent, vHost);
+ notice_lang(Config.s_HostServ, u, HOST_ACTIVATED, na->hostinfo.GetHost().c_str());
+ ircdproto->SendVhost(u, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
if (ircd->vhost)
{
if (u->vhost)
delete [] u->vhost;
- u->vhost = sstrdup(vHost);
+ u->vhost = sstrdup(na->hostinfo.GetHost().c_str());
}
if (ircd->vident)
{
- if (vIdent)
- u->SetVIdent(vIdent);
+ if (!na->hostinfo.GetIdent().empty())
+ u->SetVIdent(na->hostinfo.GetIdent());
}
- set_lastmask(u);
+ u->UpdateHost();
}
+ else
+ notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED);
return MOD_CONT;
}
diff --git a/src/core/hs_set.c b/src/core/hs_set.c
index 75c3b85ec..cd5ce0552 100644
--- a/src/core/hs_set.c
+++ b/src/core/hs_set.c
@@ -122,7 +122,8 @@ class CommandHSSet : public Command
alog("vHost for user \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
else
alog("vHost for user \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
- addHostCore(nick, vIdent, hostmask, u->nick, tmp_time);
+ na->hostinfo.SetVhost(vIdent ? vIdent : "", hostmask, u->nick);
+ FOREACH_MOD(I_OnSetVhost, OnSetVhost(na));
if (vIdent)
notice_lang(Config.s_HostServ, u, HOST_IDENT_SET, nick, vIdent, hostmask);
else
diff --git a/src/core/hs_setall.c b/src/core/hs_setall.c
index 7ab5420cd..ab21075da 100644
--- a/src/core/hs_setall.c
+++ b/src/core/hs_setall.c
@@ -15,8 +15,6 @@
#include "module.h"
-extern int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time);
-
class CommandHSSetAll : public Command
{
public:
@@ -36,6 +34,17 @@ class CommandHSSetAll : public Command
char *vIdent = NULL;
+ if (!(na = findnick(nick)))
+ {
+ notice_lang(Config.s_HostServ, u, HOST_NOREG, nick);
+ return MOD_CONT;
+ }
+ else if (na->HasFlag(NS_FORBIDDEN))
+ {
+ notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick);
+ return MOD_CONT;
+ }
+
vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */
if (vIdent)
{
@@ -107,30 +116,17 @@ class CommandHSSetAll : public Command
tmp_time = time(NULL);
- if ((na = findnick(nick)))
- {
- if (na->HasFlag(NS_FORBIDDEN))
- {
- notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick);
- if (vIdent) {
- delete [] vIdent;
- delete [] rawhostmask;
- }
- delete [] hostmask;
- return MOD_CONT;
- }
- if (vIdent && ircd->vident)
- alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
- else
- alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
- do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time);
- if (vIdent)
- notice_lang(Config.s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, hostmask);
- else
- notice_lang(Config.s_HostServ, u, HOST_SETALL, nick, hostmask);
- }
+ if (vIdent && ircd->vident)
+ alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
else
- notice_lang(Config.s_HostServ, u, HOST_NOREG, nick);
+ alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
+ na->hostinfo.SetVhost(vIdent ? vIdent : "", hostmask, u->nick);
+ HostServSyncVhosts(na);
+ FOREACH_MOD(I_OnSetVhost, OnSetVhost(na));
+ if (vIdent)
+ notice_lang(Config.s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, hostmask);
+ else
+ notice_lang(Config.s_HostServ, u, HOST_SETALL, nick, hostmask);
if (vIdent)
{
delete [] vIdent;
diff --git a/src/core/ns_info.c b/src/core/ns_info.c
index 56fa79c71..6161a05ff 100644
--- a/src/core/ns_info.c
+++ b/src/core/ns_info.c
@@ -140,17 +140,12 @@ class CommandNSInfo : public Command
if (show_hidden)
{
- if (Config.s_HostServ && ircd->vhost) {
- if (getvHost(na->nick) != NULL) {
- if (ircd->vident && getvIdent(na->nick) != NULL) {
- notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST2,
- getvIdent(na->nick),
- getvHost(na->nick));
- } else {
- notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST,
- getvHost(na->nick));
- }
- }
+ if (Config.s_HostServ && ircd->vhost && na->hostinfo.HasVhost())
+ {
+ if (ircd->vident && !na->hostinfo.GetIdent().empty())
+ notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST2, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
+ else
+ notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST, na->hostinfo.GetHost().c_str());
}
if (na->nc->greet)
notice_lang(Config.s_NickServ, u, NICK_INFO_GREET, na->nc->greet);
diff --git a/src/hostserv.c b/src/hostserv.c
index 8be8ddc39..55a6abb27 100644
--- a/src/hostserv.c
+++ b/src/hostserv.c
@@ -18,8 +18,6 @@
#define HASH(nick) ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31))
-HostCore *head = NULL; /* head of the HostCore list */
-
E int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask,
char *creator, time_t time);
@@ -42,19 +40,22 @@ void moduleAddHostServCmds()
void get_hostserv_stats(long *nrec, long *memuse)
{
long count = 0, mem = 0;
- HostCore *hc;
-
- for (hc = head; hc; hc = hc->next) {
- count++;
- mem += sizeof(*hc);
- if (hc->nick)
- mem += strlen(hc->nick) + 1;
- if (hc->vIdent)
- mem += strlen(hc->vIdent) + 1;
- if (hc->vHost)
- mem += strlen(hc->vHost) + 1;
- if (hc->creator)
- mem += strlen(hc->creator) + 1;
+
+ for (int i = 0; i < 1024; ++i)
+ {
+ for (NickAlias *na = nalists[i]; na; na = na->next)
+ {
+ if (!na->hostinfo.HasVhost())
+ continue;
+
+ if (!na->hostinfo.GetIdent().empty())
+ mem += na->hostinfo.GetIdent().size();
+ if (!na->hostinfo.GetHost().empty())
+ mem += na->hostinfo.GetHost().size();
+ if (!na->hostinfo.GetCreator().empty())
+ mem += na->hostinfo.GetCreator().size();
+ ++count;
+ }
}
*nrec = count;
@@ -104,314 +105,116 @@ void hostserv(User * u, char *buf)
}
}
-/*************************************************************************/
-/* Start of Linked List routines */
-/*************************************************************************/
-
-HostCore *hostCoreListHead()
-{
- return head;
-}
-
-/**
- * Create HostCore list member
- * @param next HostCore next slot
- * @param nick Nick to add
- * @param vIdent Virtual Ident
- * @param vHost Virtual Host
- * @param creator Person whom set the vhost
- * @param time Time the vhost was Set
- * @return HostCore
+/** Set a vhost for the user
+ * @param ident The ident
+ * @param host The host
+ * @param creator Who created the vhost
+ * @param time When the vhost was craated
*/
-HostCore *createHostCorelist(HostCore * next, const char *nick, char *vIdent,
- char *vHost, const char *creator, int32 tmp_time)
+void HostInfo::SetVhost(const std::string &ident, const std::string &host, const std::string &creator, time_t time)
{
-
- next = new HostCore;
- if (next == NULL) {
- ircdproto->SendGlobops(findbot(Config.s_HostServ),
- "Unable to allocate memory to create the vHost LL, problems i sense..");
- } else {
- next->nick = new char[strlen(nick) + 1];
- next->vHost = new char[strlen(vHost) + 1];
- next->creator = new char[strlen(creator) + 1];
- if (vIdent)
- next->vIdent = new char[strlen(vIdent) + 1];
- if ((next->nick == NULL) || (next->vHost == NULL)
- || (next->creator == NULL)) {
- ircdproto->SendGlobops(findbot(Config.s_HostServ),
- "Unable to allocate memory to create the vHost LL, problems i sense..");
- return NULL;
- }
- strlcpy(next->nick, nick, strlen(nick) + 1);
- strlcpy(next->vHost, vHost, strlen(vHost) + 1);
- strlcpy(next->creator, creator, strlen(creator) + 1);
- if (vIdent) {
- if ((next->vIdent == NULL)) {
- ircdproto->SendGlobops(findbot(Config.s_HostServ),
- "Unable to allocate memory to create the vHost LL, problems i sense..");
- return NULL;
- }
- strlcpy(next->vIdent, vIdent, strlen(vIdent) + 1);
- } else {
- next->vIdent = NULL;
- }
- next->time = tmp_time;
- next->next = NULL;
- return next;
- }
- return NULL;
+ Ident = ident;
+ Host = host;
+ Creator = creator;
+ Time = time;
}
-/*************************************************************************/
-/**
- * Returns either NULL for the head, or the location of the *PREVIOUS*
- * record, this is where we need to insert etc..
- * @param head HostCore head
- * @param nick Nick to find
- * @param found If found
- * @return HostCore
- */
-HostCore *findHostCore(HostCore * phead, const char *nick, bool* found)
-{
- HostCore *previous, *current;
-
- *found = false;
- current = phead;
- previous = current;
-
- if (!nick) {
- return NULL;
- }
- FOREACH_MOD(I_OnFindHostCore, OnFindHostCore(nick));
- while (current != NULL) {
- if (stricmp(nick, current->nick) == 0) {
- *found = true;
- break;
- } else if (stricmp(nick, current->nick) < 0) {
- /* we know were not gonna find it now.... */
- break;
- } else {
- previous = current;
- current = current->next;
- }
- }
- if (current == phead) {
- return NULL;
- } else {
- return previous;
- }
-}
-
-/*************************************************************************/
-HostCore *insertHostCore(HostCore * phead, HostCore * prev, const char *nick,
- char *vIdent, char *vHost, const char *creator,
- int32 tmp_time)
+/** Remove a users vhost
+ **/
+void HostInfo::RemoveVhost()
{
-
- HostCore *newCore, *tmp;
-
- if (!nick || !vHost || !creator) {
- return NULL;
- }
-
- newCore = new HostCore;
- if (newCore == NULL) {
- ircdproto->SendGlobops(findbot(Config.s_HostServ),
- "Unable to allocate memory to insert into the vHost LL, problems i sense..");
- return NULL;
- } else {
- newCore->nick = new char[strlen(nick) + 1];
- newCore->vHost = new char[strlen(vHost) + 1];
- newCore->creator = new char[strlen(creator) + 1];
- if (vIdent)
- newCore->vIdent = new char[strlen(vIdent) + 1];
- if ((newCore->nick == NULL) || (newCore->vHost == NULL)
- || (newCore->creator == NULL)) {
- ircdproto->SendGlobops(findbot(Config.s_HostServ),
- "Unable to allocate memory to create the vHost LL, problems i sense..");
- return NULL;
- }
- strlcpy(newCore->nick, nick, strlen(nick) + 1);
- strlcpy(newCore->vHost, vHost, strlen(vHost) + 1);
- strlcpy(newCore->creator, creator, strlen(creator) + 1);
- if (vIdent) {
- if ((newCore->vIdent == NULL)) {
- ircdproto->SendGlobops(findbot(Config.s_HostServ),
- "Unable to allocate memory to create the vHost LL, problems i sense..");
- return NULL;
- }
- strlcpy(newCore->vIdent, vIdent, strlen(vIdent) + 1);
- } else {
- newCore->vIdent = NULL;
- }
- newCore->time = tmp_time;
- if (prev == NULL) {
- tmp = phead;
- phead = newCore;
- newCore->next = tmp;
- } else {
- tmp = prev->next;
- prev->next = newCore;
- newCore->next = tmp;
- }
- }
- FOREACH_MOD(I_OnInsertHostCore, OnInsertHostCore(newCore));
- return phead;
+ Ident.clear();
+ Host.clear();
+ Creator.clear();
+ Time = 0;
}
-/*************************************************************************/
-HostCore *deleteHostCore(HostCore * phead, HostCore * prev)
+/** Check if the user has a vhost
+ * @return true or false
+ */
+bool HostInfo::HasVhost() const
{
-
- HostCore *tmp;
-
- if (prev == NULL) {
- tmp = phead;
- phead = phead->next;
- } else {
- tmp = prev->next;
- prev->next = tmp->next;
- }
- FOREACH_MOD(I_OnDeleteHostCore, OnDeleteHostCore(tmp));
- delete [] tmp->vHost;
- delete [] tmp->nick;
- delete [] tmp->creator;
- if (tmp->vIdent) {
- delete [] tmp->vIdent;
- }
- delete tmp;
- return phead;
+ return !Host.empty();
}
-/*************************************************************************/
-void addHostCore(const char *nick, char *vIdent, char *vhost, const char *creator,
- int32 tmp_time)
+/** Retrieve the vhost ident
+ * @return the ident
+ */
+const std::string &HostInfo::GetIdent() const
{
- HostCore *tmp;
- bool found = false;
-
- if (head == NULL) {
- head =
- createHostCorelist(head, nick, vIdent, vhost, creator,
- tmp_time);
- } else {
- tmp = findHostCore(head, nick, &found);
- if (!found) {
- head =
- insertHostCore(head, tmp, nick, vIdent, vhost, creator,
- tmp_time);
- } else {
- head = deleteHostCore(head, tmp); /* delete the old entry */
- addHostCore(nick, vIdent, vhost, creator, tmp_time); /* recursive call to add new entry */
- }
- }
+ return Ident;
}
-/*************************************************************************/
-char *getvHost(char *nick)
+/** Retrieve the vhost host
+ * @return the host
+ */
+const std::string &HostInfo::GetHost() const
{
- HostCore *tmp;
- bool found = false;
- tmp = findHostCore(head, nick, &found);
- if (found) {
- if (tmp == NULL)
- return head->vHost;
- else
- return tmp->next->vHost;
- }
- return NULL;
+ return Host;
}
-/*************************************************************************/
-char *getvIdent(char *nick)
+/** Retrieve the vhost creator
+ * @return the creator
+ */
+const std::string &HostInfo::GetCreator() const
{
- HostCore *tmp;
- bool found = false;
- tmp = findHostCore(head, nick, &found);
- if (found) {
- if (tmp == NULL)
- return head->vIdent;
- else
- return tmp->next->vIdent;
- }
- return NULL;
+ return Creator;
}
-/*************************************************************************/
-void delHostCore(const char *nick)
+/** Retrieve when the vhost was crated
+ * @return the time it was created
+ */
+const time_t HostInfo::GetTime() const
{
- HostCore *tmp;
- bool found = false;
- tmp = findHostCore(head, nick, &found);
- if (found) {
- head = deleteHostCore(head, tmp);
- }
-
+ return Time;
}
/*************************************************************************/
-/* End of Linked List routines */
-/*************************************************************************/
-
-/*************************************************************************/
/* Start of Generic Functions */
/*************************************************************************/
-int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask, char *creator,
- time_t time)
+/** Sync all vhosts in a group to the same thing
+ * @param na The nick with the vhost wanting to by synced
+ */
+void HostServSyncVhosts(NickAlias *na)
{
- int i;
- NickAlias *na;
-
- for (i = 0; i < nc->aliases.count; i++) {
- na = static_cast<NickAlias *>(nc->aliases.list[i]);
- addHostCore(na->nick, vIdent, hostmask, creator, time);
- }
- return MOD_CONT;
-}
+ if (!na || !na->hostinfo.HasVhost())
+ return;
-/*************************************************************************/
-int do_on_id(User * u)
-{ /* we've assumed that the user exists etc.. */
- char *vHost; /* as were only gonna call this from nsid routine */
- char *vIdent;
- vHost = getvHost(u->nick);
- vIdent = getvIdent(u->nick);
- if (vHost != NULL) {
- if (vIdent) {
- notice_lang(Config.s_HostServ, u, HOST_IDENT_ACTIVATED, vIdent,
- vHost);
- } else {
- notice_lang(Config.s_HostServ, u, HOST_ACTIVATED, vHost);
- }
- ircdproto->SendVhost(u, vIdent, vHost);
- if (ircd->vhost)
- {
- if (u->vhost)
- delete [] u->vhost;
- u->vhost = sstrdup(vHost);
- }
- if (ircd->vident) {
- if (vIdent)
- u->SetVIdent(vIdent);
- }
- set_lastmask(u);
+ for (int i = 0; i < na->nc->aliases.count; i++)
+ {
+ NickAlias *nick = static_cast<NickAlias *>(na->nc->aliases.list[i]);
+ nick->hostinfo.SetVhost(na->hostinfo.GetIdent(), na->hostinfo.GetHost(), na->hostinfo.GetCreator());
}
- return MOD_CONT;
}
/*************************************************************************/
-/*
- * Sets the last_usermak properly. Using virtual ident and/or host
- */
-void set_lastmask(User * u)
+void do_on_id(User *u)
{
+ if (!u)
+ return;
NickAlias *na = findnick(u->nick);
- if (na->last_usermask)
- delete [] na->last_usermask;
+ if (!na || !na->hostinfo.HasVhost())
+ return;
+
+ ircdproto->SendVhost(u, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
+ if (ircd->vhost)
+ {
+ if (u->vhost)
+ delete [] u->vhost;
+ u->vhost = sstrdup(na->hostinfo.GetHost().c_str());
+ }
+ if (ircd->vident && !na->hostinfo.GetIdent().empty())
+ {
+ u->SetVIdent(na->hostinfo.GetIdent());
+ }
+ u->UpdateHost();
- std::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost();
- na->last_usermask = sstrdup(last_usermask.c_str());
+ if (!na->hostinfo.GetIdent().empty())
+ notice_lang(Config.s_HostServ, u, HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
+ else
+ notice_lang(Config.s_HostServ, u, HOST_ACTIVATED, na->hostinfo.GetHost().c_str());
}
+
+
diff --git a/src/modules/hs_request.c b/src/modules/hs_request.c
index 5255649f7..ba317bb20 100644
--- a/src/modules/hs_request.c
+++ b/src/modules/hs_request.c
@@ -50,7 +50,7 @@ int HSRequestMemoSetters = 0;
#define LNG_WAITING_SYNTAX 19
#define LNG_HELP_WAITING 20
-void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, int32 tmp_time);
+void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, time_t tmp_time);
int my_isvalidchar(const char c);
void my_memo_lang(User *u, const char *name, int z, int number, ...);
void req_send_memos(User *u, char *vIdent,