1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2014 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2016 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
37 |
|
dlink_list WHOWASHASH[HASHSIZE]; |
38 |
|
|
39 |
|
|
40 |
+ |
/*! \brief Initializes whowas table |
41 |
+ |
*/ |
42 |
|
void |
43 |
|
whowas_init(void) |
44 |
|
{ |
46 |
|
WHOWAS[i].hashv = -1; |
47 |
|
} |
48 |
|
|
49 |
+ |
/*! \brief Adds the currently defined name of the client to history. |
50 |
+ |
* Usually called before changing to a new name (nick). |
51 |
+ |
* Client must be a fully registered user. |
52 |
+ |
* \param client_p pointer to Client struct to add |
53 |
+ |
* \param online either 1 if it's a nick change or 0 on client exit |
54 |
+ |
*/ |
55 |
|
void |
56 |
|
whowas_add_history(struct Client *client_p, const int online) |
57 |
|
{ |
58 |
|
static unsigned int whowas_next = 0; |
59 |
< |
struct Whowas *const who = &WHOWAS[whowas_next]; |
59 |
> |
struct Whowas *const whowas = &WHOWAS[whowas_next]; |
60 |
|
|
61 |
|
assert(IsClient(client_p)); |
62 |
|
|
63 |
|
if (++whowas_next == NICKNAMEHISTORYLENGTH) |
64 |
|
whowas_next = 0; |
65 |
|
|
66 |
< |
if (who->hashv != -1) |
66 |
> |
if (whowas->hashv != -1) |
67 |
|
{ |
68 |
< |
if (who->online) |
69 |
< |
dlinkDelete(&who->cnode, &who->online->whowas); |
68 |
> |
if (whowas->online) |
69 |
> |
dlinkDelete(&whowas->cnode, &whowas->online->whowas); |
70 |
|
|
71 |
< |
dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]); |
71 |
> |
dlinkDelete(&whowas->tnode, &WHOWASHASH[whowas->hashv]); |
72 |
|
} |
73 |
|
|
74 |
< |
who->hashv = strhash(client_p->name); |
75 |
< |
who->shide = IsHidden(client_p->servptr) != 0; |
76 |
< |
who->logoff = CurrentTime; |
77 |
< |
|
78 |
< |
strlcpy(who->name, client_p->name, sizeof(who->name)); |
79 |
< |
strlcpy(who->username, client_p->username, sizeof(who->username)); |
80 |
< |
strlcpy(who->hostname, client_p->host, sizeof(who->hostname)); |
81 |
< |
strlcpy(who->realname, client_p->info, sizeof(who->realname)); |
82 |
< |
strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername)); |
74 |
> |
whowas->hashv = strhash(client_p->name); |
75 |
> |
whowas->shide = IsHidden(client_p->servptr) != 0; |
76 |
> |
whowas->logoff = CurrentTime; |
77 |
> |
|
78 |
> |
strlcpy(whowas->account, client_p->account, sizeof(whowas->account)); |
79 |
> |
strlcpy(whowas->name, client_p->name, sizeof(whowas->name)); |
80 |
> |
strlcpy(whowas->username, client_p->username, sizeof(whowas->username)); |
81 |
> |
strlcpy(whowas->hostname, client_p->host, sizeof(whowas->hostname)); |
82 |
> |
strlcpy(whowas->sockhost, client_p->sockhost, sizeof(whowas->sockhost)); |
83 |
> |
strlcpy(whowas->realname, client_p->info, sizeof(whowas->realname)); |
84 |
> |
strlcpy(whowas->servername, client_p->servptr->name, sizeof(whowas->servername)); |
85 |
|
|
86 |
|
if (online) |
87 |
|
{ |
88 |
< |
who->online = client_p; |
89 |
< |
dlinkAdd(who, &who->cnode, &client_p->whowas); |
88 |
> |
whowas->online = client_p; |
89 |
> |
dlinkAdd(whowas, &whowas->cnode, &client_p->whowas); |
90 |
|
} |
91 |
|
else |
92 |
< |
who->online = NULL; |
92 |
> |
whowas->online = NULL; |
93 |
|
|
94 |
< |
dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]); |
94 |
> |
dlinkAdd(whowas, &whowas->tnode, &WHOWASHASH[whowas->hashv]); |
95 |
|
} |
96 |
|
|
97 |
+ |
/*! \brief This must be called when the client structure is about to |
98 |
+ |
* be released. History mechanism keeps pointers to client |
99 |
+ |
* structures and it must know when they cease to exist. |
100 |
+ |
* \param client_p pointer to Client struct |
101 |
+ |
*/ |
102 |
|
void |
103 |
|
whowas_off_history(struct Client *client_p) |
104 |
|
{ |
105 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
91 |
< |
|
92 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head) |
105 |
> |
while (client_p->whowas.head) |
106 |
|
{ |
107 |
< |
struct Whowas *temp = ptr->data; |
107 |
> |
struct Whowas *whowas = client_p->whowas.head->data; |
108 |
|
|
109 |
< |
temp->online = NULL; |
110 |
< |
dlinkDelete(&temp->cnode, &client_p->whowas); |
109 |
> |
whowas->online = NULL; |
110 |
> |
dlinkDelete(&whowas->cnode, &client_p->whowas); |
111 |
|
} |
112 |
|
} |
113 |
|
|
114 |
+ |
/*! \brief Returns the current client that was using the given |
115 |
+ |
* nickname within the timelimit. Returns NULL, if no |
116 |
+ |
* one found... |
117 |
+ |
* \param name name of the nick |
118 |
+ |
* \param timelimit maximum age for a client since log-off |
119 |
+ |
*/ |
120 |
|
struct Client * |
121 |
< |
whowas_get_history(const char *nick, time_t timelimit) |
121 |
> |
whowas_get_history(const char *name, uintmax_t timelimit) |
122 |
|
{ |
123 |
< |
dlink_node *ptr = NULL; |
123 |
> |
dlink_node *node = NULL; |
124 |
|
|
125 |
|
timelimit = CurrentTime - timelimit; |
126 |
|
|
127 |
< |
DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head) |
127 |
> |
DLINK_FOREACH(node, WHOWASHASH[strhash(name)].head) |
128 |
|
{ |
129 |
< |
struct Whowas *temp = ptr->data; |
129 |
> |
struct Whowas *whowas = node->data; |
130 |
|
|
131 |
< |
if (temp->logoff < timelimit) |
131 |
> |
if (whowas->logoff < timelimit) |
132 |
|
continue; |
133 |
< |
if (irccmp(nick, temp->name)) |
133 |
> |
if (irccmp(name, whowas->name)) |
134 |
|
continue; |
135 |
< |
return temp->online; |
135 |
> |
return whowas->online; |
136 |
|
} |
137 |
|
|
138 |
|
return NULL; |
139 |
|
} |
140 |
|
|
141 |
+ |
/*! \brief For debugging. Counts related structures stored in whowas array |
142 |
+ |
*/ |
143 |
|
void |
144 |
< |
whowas_count_memory(unsigned int *const count, uint64_t *const bytes) |
144 |
> |
whowas_count_memory(unsigned int *const count, size_t *const bytes) |
145 |
|
{ |
146 |
< |
const struct Whowas *tmp = &WHOWAS[0]; |
146 |
> |
const struct Whowas *whowas = &WHOWAS[0]; |
147 |
|
|
148 |
< |
for (unsigned int i = 0; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp) |
148 |
> |
for (unsigned int i = 0; i < NICKNAMEHISTORYLENGTH; ++i, ++whowas) |
149 |
|
{ |
150 |
< |
if (tmp->hashv != -1) |
150 |
> |
if (whowas->hashv != -1) |
151 |
|
{ |
152 |
|
(*count)++; |
153 |
|
(*bytes) += sizeof(struct Whowas); |