summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-02 08:20:59 +0000
committerAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-02 08:20:59 +0000
commita819cb0cc0f54a042a088dfba9c1f6b817928641 (patch)
tree7931a9d81367c184ca2550a1819ef685e3e0c927 /src
parent3617d7978899f830d952d9bac70ed14bb0cc0fd6 (diff)
Rewrote the vhost code, and moved it to be part of nickalias instead of in its own list. This also fixes being able to steal other users vhosts with /hs on
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2724 5417fbe8-f217-4b02-8779-1006273d7864
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, char *vHost);
@@ -58,7 +58,14 @@ void req_send_memos(User *u, char *vIdent, char *vHost);
void my_load_config();
void my_add_languages();
-HostCore *hs_request_head;
+struct HostRequest
+{
+ std::string ident;
+ std::string host;
+ time_t time;
+};
+
+std::map<std::string, HostRequest *> Requests;
static Module *me;
@@ -75,7 +82,6 @@ class CommandHSRequest : public Command
const char *rawhostmask = params[0].c_str();
char hostmask[HOSTMAX];
NickAlias *na;
- int32 tmp_time;
char *s;
char *vIdent = NULL;
time_t now = time(NULL);
@@ -144,7 +150,6 @@ class CommandHSRequest : public Command
return MOD_CONT;
}
- tmp_time = time(NULL);
if ((na = findnick(nick)))
{
if (HSRequestMemoOper || HSRequestMemoSetters)
@@ -161,7 +166,7 @@ class CommandHSRequest : public Command
return MOD_CONT;
}
}
- my_add_host_request(nick, vIdent, hostmask, u->nick, tmp_time);
+ my_add_host_request(nick, vIdent, hostmask, u->nick, now);
me->NoticeLang(Config.s_HostServ, u, LNG_REQUESTED);
req_send_memos(u, vIdent, hostmask);
@@ -197,39 +202,26 @@ class CommandHSRequest : public Command
class CommandHSActivate : public Command
{
public:
- CommandHSActivate() : Command("ACTIVATE", 1, 1)
+ CommandHSActivate() : Command("ACTIVATE", 1, 1, "hostserv/set")
{
}
CommandReturn Execute(User *u, const std::vector<ci::string> &params)
{
- if (!u->nc->HasPriv("hostserv/set"))
- {
- notice_lang(Config.s_HostServ, u, ACCESS_DENIED);
- return MOD_CONT;
- }
-
const char *nick = params[0].c_str();
NickAlias *na;
- HostCore *tmp, *hc;
- bool found = false;
if ((na = findnick(nick)))
{
- tmp = findHostCore(hs_request_head, nick, &found);
- if (found)
+ std::map<std::string, HostRequest *>::iterator it = Requests.find(na->nick);
+ if (it != Requests.end())
{
- if (!tmp)
- hc = hs_request_head;
- else
- hc = tmp->next;
-
- addHostCore(hc->nick, hc->vIdent, hc->vHost, u->nick, time(NULL));
+ na->hostinfo.SetVhost(it->second->ident, it->second->host, u->nick, it->second->time);
+ Requests.erase(it);
if (HSRequestMemoUser)
- my_memo_lang(u, hc->nick, 2, LNG_ACTIVATE_MEMO);
+ my_memo_lang(u, na->nick, 2, LNG_ACTIVATE_MEMO);
- hs_request_head = deleteHostCore(hs_request_head, tmp);
me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATED, nick);
alog("Host Request for %s activated by %s", nick, u->nick);
}
@@ -262,40 +254,26 @@ class CommandHSActivate : public Command
class CommandHSReject : public Command
{
public:
- CommandHSReject() : Command("REJECT", 1, 2)
+ CommandHSReject() : Command("REJECT", 1, 2, "hostserv/set")
{
}
CommandReturn Execute(User *u, const std::vector<ci::string> &params)
{
- if (!u->nc->HasPriv("hostserv/set"))
- {
- notice_lang(Config.s_HostServ, u, ACCESS_DENIED);
- return MOD_CONT;
- }
-
const char *nick = params[0].c_str();
const char *reason = params.size() > 1 ? params[1].c_str() : NULL;
- HostCore *tmp, *hc;
- bool found = false;
- tmp = findHostCore(hs_request_head, nick, &found);
- if (found)
+ std::map<std::string, HostRequest *>::iterator it = Requests.find(nick);
+ if (it != Requests.end())
{
- if (!tmp)
- hc = hs_request_head;
- else
- hc = tmp->next;
-
if (HSRequestMemoUser)
{
if (reason)
- my_memo_lang(u, hc->nick, 2, LNG_REJECT_MEMO_REASON, reason);
+ my_memo_lang(u, nick, 2, LNG_REJECT_MEMO_REASON, reason);
else
- my_memo_lang(u, hc->nick, 2, LNG_REJECT_MEMO);
+ my_memo_lang(u, nick, 2, LNG_REJECT_MEMO);
}
- hs_request_head = deleteHostCore(hs_request_head, tmp);
me->NoticeLang(Config.s_HostServ, u, LNG_REJECTED, nick);
alog("Host Request for %s rejected by %s (%s)", nick, u->nick, reason ? reason : "");
}
@@ -327,41 +305,33 @@ class HSListBase : public Command
protected:
CommandReturn DoList(User *u)
{
- if (!u->nc->HasPriv("hostserv/set"))
- {
- notice_lang(Config.s_HostServ, u, ACCESS_DENIED);
- return MOD_CONT;
- }
-
- struct tm *tm;
char buf[BUFSIZE];
int counter = 1;
int from = 0, to = 0;
unsigned display_counter = 0;
- HostCore *current;
+ tm *tm;
- current = hs_request_head;
- while (current)
+ for (std::map<std::string, HostRequest *>::iterator it = Requests.begin(); it != Requests.end(); ++it)
{
+ HostRequest *hr = it->second;
if (((counter >= from && counter <= to) || (!from && !to)) && display_counter < Config.NSListMax)
{
++display_counter;
- tm = localtime(&current->time);
+ tm = localtime(&hr->time);
strftime(buf, sizeof(buf), getstring(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 (!hr->ident.empty())
+ notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, it->first.c_str(), hr->ident.c_str(), hr->host.c_str(), it->first.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, it->first.c_str(), hr->host.c_str(), it->first.c_str(), buf);
}
++counter;
- current = current->next;
}
notice_lang(Config.s_HostServ, u, HOST_LIST_FOOTER, display_counter);
return MOD_CONT;
}
public:
- HSListBase(const std::string &cmd, int min, int max) : Command(cmd, min, max)
+ HSListBase(const std::string &cmd, int min, int max) : Command(cmd, min, max, "hostserv/set")
{
}
@@ -410,7 +380,6 @@ class HSRequest : public Module
this->SetType(SUPPORTED);
my_load_config();
- hs_request_head = NULL;
const char* langtable_en_us[] = {
/* LNG_REQUEST_SYNTAX */
@@ -674,11 +643,12 @@ class HSRequest : public Module
~HSRequest()
{
- OnSaveDatabase();
-
/* Clean up all open host requests */
- while (hs_request_head)
- hs_request_head = deleteHostCore(hs_request_head, NULL);
+ while (!Requests.empty())
+ {
+ delete Requests.begin()->second;
+ Requests.erase(Requests.begin());
+ }
}
EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> &params)
@@ -702,12 +672,18 @@ class HSRequest : public Module
{
if (command == "DROP")
{
- bool found = false;
NickAlias *na = findnick(u->nick);
- HostCore *tmp = findHostCore(hs_request_head, u->nick, &found);
- if (found && na)
- hs_request_head = deleteHostCore(hs_request_head, tmp);
+ if (na)
+ {
+ std::map<std::string, HostRequest *>::iterator it = Requests.find(na->nick);
+
+ if (it != Requests.end())
+ {
+ delete it->second;
+ Requests.erase(it);
+ }
+ }
}
}
@@ -722,9 +698,10 @@ class HSRequest : public Module
EventReturn OnDatabaseRead(const std::vector<std::string> &params)
{
- if (params[0] == "HS_REQUEST" && params.size() >= 6)
+ if (params[0] == "HS_REQUEST" && params.size() >= 5)
{
- my_add_host_request(const_cast<char *>(params[1].c_str()), const_cast<char *>(params[2].c_str()), const_cast<char *>(params[3].c_str()), const_cast<char *>(params[4].c_str()), strtol(params[5].c_str(), NULL, 10));
+ char *vident = params[2] == "(null)" ? NULL : const_cast<char *>(params[2].c_str());
+ my_add_host_request(const_cast<char *>(params[1].c_str()), vident, const_cast<char *>(params[3].c_str()), const_cast<char *>(params[1].c_str()), strtol(params[4].c_str(), NULL, 10));
return EVENT_STOP;
}
@@ -734,20 +711,19 @@ class HSRequest : public Module
void OnDatabaseWrite(void (*Write)(const std::string &))
{
- for (HostCore *current = hs_request_head; current; current = current->next)
+ for (std::map<std::string, HostRequest *>::iterator it = Requests.begin(); it != Requests.end(); ++it)
{
- const char *vident = current->vIdent ? current->vIdent : "(null)";
+ HostRequest *hr = it->second;
std::string buf = "HS_REQUEST ";
- // We really need a better + operator to make this easier ...
- buf += current->nick;
- buf += " ";
- buf += vident;
+ buf += it->first;
buf += " ";
- buf += current->vHost;
+ buf += hr->ident.empty() ? "(null)" : hr->ident;
buf += " ";
- buf += current->time;
+ buf += hr->host;
buf += " ";
- buf += current->creator;
+ char tsbuf[16];
+ snprintf(tsbuf, sizeof(tsbuf), "%ld", hr->time);
+ buf += tsbuf;
Write(buf);
}
}
@@ -824,23 +800,16 @@ void req_send_memos(User *u, char *vIdent, char *vHost)
}
}
-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)
{
- HostCore *tmp;
- bool found = false;
-
- if (!hs_request_head)
- hs_request_head = createHostCorelist(hs_request_head, nick, vIdent, vhost, creator, tmp_time);
- else {
- tmp = findHostCore(hs_request_head, nick, &found);
- if (!found)
- hs_request_head = insertHostCore(hs_request_head, tmp, nick, vIdent, vhost, creator, tmp_time);
- else
- {
- hs_request_head = deleteHostCore(hs_request_head, tmp); /* delete the old entry */
- my_add_host_request(nick, vIdent, vhost, creator, tmp_time); /* recursive call to add new entry */
- }
- }
+ HostRequest *hr = new HostRequest;
+ hr->ident = vIdent ? vIdent : "";
+ hr->host = vhost;
+ hr->time = tmp_time;
+ std::map<std::string, HostRequest *>::iterator it = Requests.find(nick);
+ if (it != Requests.end())
+ Requests.erase(it);
+ Requests.insert(std::make_pair(nick, hr));
}
int my_isvalidchar(const char c)
diff --git a/src/nickalias.cpp b/src/nickalias.cpp
index b2950c2e8..9d4678209 100644
--- a/src/nickalias.cpp
+++ b/src/nickalias.cpp
@@ -72,8 +72,6 @@ NickAlias::~NickAlias()
u->nc = NULL;
}
- delHostCore(this->nick); /* delete any vHost's for this nick */
-
/* Accept nicks that have no core, because of database load functions */
if (this->nc)
{
diff --git a/src/tools/db-convert.c b/src/tools/db-convert.c
index fbef58eed..c70f41ecd 100644
--- a/src/tools/db-convert.c
+++ b/src/tools/db-convert.c
@@ -324,6 +324,28 @@ int main(int argc, char *argv[])
}
}
+ head = NULL;
+ if ((f = open_db_read("HostServ", "hosts.db", 3)))
+ {
+ int c;
+ HostCore *hc;
+
+ while ((c = getc_db(f)) == 1)
+ {
+ hc = (HostCore *)calloc(1, sizeof(HostCore));
+ READ(read_string(&hc->nick, f));
+ READ(read_string(&hc->vIdent, f));
+ READ(read_string(&hc->vHost, f));
+ READ(read_string(&hc->creator, f));
+ READ(read_int32(&hc->time, f));
+
+ hc->next = head;
+ head = hc;
+ }
+
+ close_db(f);
+ }
+
/* Nick cores */
for (i = 0; i < 1024; i++)
{
@@ -432,6 +454,12 @@ int main(int argc, char *argv[])
<< ((na->status & NS_FORBIDDEN) ? " FORBIDDEN" : "")
<< ((na->status & NS_NO_EXPIRE) ? " NOEXPIRE" : "") << std::endl;
}
+
+ HostCore *hc = findHostCore(na->nick);
+ if (hc)
+ {
+ fs << "MD VHOST " << hc->creator << " " << hc->time << " " << hc->vHost << " :" << hc->vIdent << std::endl;
+ }
}
}
}
@@ -891,33 +919,6 @@ int main(int argc, char *argv[])
} /* for (chanlists[i]) */
} /* for (i) */
- /* Section IV: Hosts */
- /* IVa: First database */
- if ((f = open_db_read("HostServ", "hosts.db", 3))) {
- int c;
- int32 time;
- char *nick, *vIdent, *vHost, *creator;
-
- std::cout << "Converting hosts..." << std::endl;
-
- while ((c = getc_db(f)) == 1) {
- READ(read_string(&nick, f));
- READ(read_string(&vIdent, f));
- READ(read_string(&vHost, f));
- READ(read_string(&creator, f));
- READ(read_int32(&time, f));
- if (vIdent)
- std::cout << "Writing vHost for " << nick << " (" << vIdent << "@" << vHost << ")" << std::endl;
- else
- std::cout << "Writing vHost for " << nick << " (" << vHost << ")" << std::endl;
- // because vIdent can sometimes be empty, we put it at the end of the list
- fs << "HI " << nick << " " << creator << " " << time << " " << vHost << " :"
- << (vIdent ? vIdent : "") << std::endl;
- free(nick); if (vIdent) free(vIdent); free(vHost); free(creator);
- }
- close_db(f);
- } // host database
-
/*********************************/
/* OPERSERV Section */
/*********************************/
diff --git a/src/tools/db-convert.h b/src/tools/db-convert.h
index 6ffcdffdb..1ebeec9f4 100644
--- a/src/tools/db-convert.h
+++ b/src/tools/db-convert.h
@@ -68,6 +68,7 @@ typedef struct nickalias_ NickAlias;
typedef struct nickcore_ NickCore;
typedef struct chaninfo_ ChannelInfo;
typedef struct badword_ BadWord;
+typedef struct hostcore_ HostCore;
struct memo_ {
uint32 number; /* Index number -- not necessarily array position! */
@@ -189,6 +190,14 @@ struct badword_ {
uint16 type;
};
+struct hostcore_ {
+ HostCore *next;
+ char *nick;
+ char *vIdent;
+ char *vHost;
+ char *creator;
+ int32 time;
+};
dbFILE *open_db_write(const char *service, const char *filename, int version);
dbFILE *open_db_read(const char *service, const char *filename, int version);
@@ -216,6 +225,7 @@ void close_db(dbFILE * f);
ChannelInfo *chanlists[256];
NickAlias *nalists[1024];
NickCore *nclists[1024];
+HostCore *head = NULL;
int b64_encode(char *src, size_t srclength, char *target, size_t targsize);
@@ -774,7 +784,15 @@ void alpha_insert_chan(ChannelInfo * ci)
ptr->prev = ci;
}
-
+HostCore *findHostCore(char *nick)
+{
+ for (HostCore *hc = head; head; head = head->next)
+ {
+ if (nick && hc->nick && !mystricmp(hc->nick, nick))
+ return hc;
+ }
+ return NULL;
+}
static char *int_to_base64(long);
static long base64_to_int(char *);
diff --git a/src/users.c b/src/users.c
index 7e715d547..0197b08d5 100644
--- a/src/users.c
+++ b/src/users.c
@@ -457,7 +457,7 @@ User *finduser(const std::string &nick)
while (user && ci_nick != user->nick)
user = user->next;
if (debug >= 3)
- alog("debug: finduser(%s) -> 0x%p", nick, static_cast<void *>(user));
+ alog("debug: finduser(%s) -> 0x%p", nick.c_str(), static_cast<void *>(user));
FOREACH_MOD(I_OnFindUser, OnFindUser(user));
return user;
}