ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
(Generate patch)

Comparing:
ircd-hybrid/src/whowas.c (file contents), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid-8/src/whowas.c (file contents), Revision 1358 by michael, Sun Apr 22 13:49:23 2012 UTC

# Line 19 | Line 19
19   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
20   *  USA
21   *
22 < *  $Id: whowas.c,v 7.31 2005/09/19 06:15:21 metalrock Exp $
22 > *  $Id$
23   */
24  
25   #include "stdinc.h"
26 + #include "list.h"
27   #include "whowas.h"
28   #include "client.h"
28 #include "common.h"
29   #include "hash.h"
30   #include "irc_string.h"
31   #include "ircd.h"
# Line 34 | Line 34
34   #include "s_serv.h"
35   #include "s_user.h"
36   #include "send.h"
37 < #include "s_conf.h"
37 > #include "conf.h"
38   #include "memory.h"
39  
40 /* internally defined function */
41 static void add_whowas_to_clist(struct Whowas **, struct Whowas *);
42 static void del_whowas_from_clist(struct Whowas **, struct Whowas *);
43 static void add_whowas_to_list(struct Whowas **, struct Whowas *);
44 static void del_whowas_from_list(struct Whowas **, struct Whowas *);
40  
41 < struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
42 < struct Whowas *WHOWASHASH[HASHSIZE];
41 > static struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
42 > dlink_list WHOWASHASH[HASHSIZE];
43  
49 static unsigned int whowas_next = 0;
44  
45   void
46   add_history(struct Client *client_p, int online)
47   {
48 +  static unsigned int whowas_next = 0;
49    struct Whowas *who = &WHOWAS[whowas_next];
50  
51 <  assert(client_p != NULL);
51 >  assert(client_p && client_p->servptr);
52  
53 <  if (client_p == NULL)
54 <    return;
60 <
61 <  /* XXX when is this possible? Looks like it could happen
62 <   * (with a half registered client.)
63 <   * and what is the correct action here? - Dianora
64 <   */
65 <  if (client_p->servptr == NULL)
66 <    return;
53 >  if (++whowas_next == NICKNAMEHISTORYLENGTH)
54 >    whowas_next = 0;
55  
56    if (who->hashv != -1)
57    {
58      if (who->online)
59 <      del_whowas_from_clist(&(who->online->whowas),who);
60 <    del_whowas_from_list(&WHOWASHASH[who->hashv], who);
59 >      dlinkDelete(&who->cnode, &who->online->whowas);
60 >
61 >    dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
62    }
63  
64 <  who->hashv  = strhash(client_p->name);
64 >  who->hashv = strhash(client_p->name);
65    who->logoff = CurrentTime;
66  
78  /* NOTE: strcpy ok here, the sizes in the client struct MUST
79   * match the sizes in the whowas struct
80   */
67    strlcpy(who->name, client_p->name, sizeof(who->name));
68 <  strcpy(who->username, client_p->username);
69 <  strcpy(who->hostname, client_p->host);
70 <  strcpy(who->realname, client_p->info);
85 <
68 >  strlcpy(who->username, client_p->username, sizeof(who->username));
69 >  strlcpy(who->hostname, client_p->host, sizeof(who->hostname));
70 >  strlcpy(who->realname, client_p->info, sizeof(who->realname));
71    strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
72  
73    if (online)
74    {
75      who->online = client_p;
76 <    add_whowas_to_clist(&(client_p->whowas), who);
76 >    dlinkAdd(who, &who->cnode, &client_p->whowas);
77    }
78    else
79      who->online = NULL;
80  
81 <  add_whowas_to_list(&WHOWASHASH[who->hashv], who);
97 <  whowas_next++;
98 <
99 <  if (whowas_next == NICKNAMEHISTORYLENGTH)
100 <    whowas_next = 0;
81 >  dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
82   }
83  
84   void
85   off_history(struct Client *client_p)
86   {
87 <  struct Whowas *temp, *next;
87 >  dlink_node *ptr = NULL, *ptr_next = NULL;
88  
89 <  for (temp = client_p->whowas; temp; temp=next)
89 >  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head)
90    {
91 <    next = temp->cnext;
91 >    struct Whowas *temp = ptr->data;
92 >
93      temp->online = NULL;
94 <    del_whowas_from_clist(&(client_p->whowas), temp);
94 >    dlinkDelete(&temp->cnode, &client_p->whowas);
95    }
96   }
97  
98   struct Client *
99   get_history(const char *nick, time_t timelimit)
100   {
101 <  struct Whowas *temp;
101 >  dlink_node *ptr = NULL;
102  
103    timelimit = CurrentTime - timelimit;
122  temp = WHOWASHASH[strhash(nick)];
104  
105 <  for (; temp; temp = temp->next)
105 >  DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head)
106    {
107 <    if (irccmp(nick, temp->name))
108 <      continue;
107 >    struct Whowas *temp = ptr->data;
108 >
109      if (temp->logoff < timelimit)
110        continue;
111 <    return(temp->online);
111 >    if (irccmp(nick, temp->name))
112 >      continue;
113 >    return temp->online;
114    }
115  
116 <  return(NULL);
116 >  return NULL;
117   }
118  
119   void
120 < count_whowas_memory(int *wwu, unsigned long *wwum)
120 > count_whowas_memory(unsigned int *wwu, uint64_t *wwum)
121   {
122 <  struct Whowas *tmp;
122 >  const struct Whowas *tmp;
123    int i;
124 <  int u = 0;
125 <  unsigned long um = 0;
124 >  unsigned int u = 0;
125 >  uint64_t um = 0;
126  
127    /* count the number of used whowas structs in 'u'   */
128    /* count up the memory used of whowas structs in um */
129 <  for (i = 0, tmp = &WHOWAS[0]; i < NICKNAMEHISTORYLENGTH; i++, tmp++)
129 >  for (i = 0, tmp = &WHOWAS[0]; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp)
130    {
131      if (tmp->hashv != -1)
132      {
133 <      u++;
133 >      ++u;
134        um += sizeof(struct Whowas);
135      }
136    }
# Line 157 | Line 140 | count_whowas_memory(int *wwu, unsigned l
140   }
141  
142   void
143 < init_whowas(void)
161 < {
162 <  int i;
163 <
164 <  for (i = 0; i < NICKNAMEHISTORYLENGTH; i++)
165 <  {
166 <    memset(&WHOWAS[i], 0, sizeof(struct Whowas));
167 <    WHOWAS[i].hashv = -1;
168 <  }
169 <
170 <  for (i = 0; i < HASHSIZE; ++i)
171 <    WHOWASHASH[i] = NULL;        
172 < }
173 <
174 < static void
175 < add_whowas_to_clist(struct Whowas **bucket, struct Whowas *whowas)
143 > whowas_init(void)
144   {
145 <  whowas->cprev = NULL;
145 >  unsigned int idx;
146  
147 <  if ((whowas->cnext = *bucket) != NULL)
148 <    whowas->cnext->cprev = whowas;
181 <  *bucket = whowas;
182 < }
183 <
184 < static void
185 < del_whowas_from_clist(struct Whowas **bucket, struct Whowas *whowas)
186 < {
187 <  if (whowas->cprev)
188 <    whowas->cprev->cnext = whowas->cnext;
189 <  else
190 <    *bucket = whowas->cnext;
191 <  if (whowas->cnext)
192 <    whowas->cnext->cprev = whowas->cprev;
193 < }
194 <
195 < static void
196 < add_whowas_to_list(struct Whowas **bucket, struct Whowas *whowas)
197 < {
198 <  whowas->prev = NULL;
199 <
200 <  if ((whowas->next = *bucket) != NULL)
201 <    whowas->next->prev = whowas;
202 <  *bucket = whowas;
203 < }
204 <
205 < static void
206 < del_whowas_from_list(struct Whowas **bucket, struct Whowas *whowas)
207 < {
208 <  if (whowas->prev)
209 <    whowas->prev->next = whowas->next;
210 <  else
211 <    *bucket = whowas->next;
212 <  if (whowas->next)
213 <    whowas->next->prev = whowas->prev;
147 >  for (idx = 0; idx < NICKNAMEHISTORYLENGTH; ++idx)
148 >    WHOWAS[idx].hashv = -1;
149   }

Comparing:
ircd-hybrid/src/whowas.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid-8/src/whowas.c (property svn:keywords), Revision 1358 by michael, Sun Apr 22 13:49:23 2012 UTC

# Line 1 | Line 1
1 < "Id Revision"
1 > Id Revision

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)