]>
jfr.im git - irc/quakenet/newserv.git/blob - nick/nickhelpers.c
4 #include "../lib/flags.h"
5 #include "../lib/irc_string.h"
6 #include "../irc/irc_config.h"
7 #include "../core/error.h"
8 #include "../lib/sstring.h"
12 #define hosthash(x) ((crc32i(x))%HOSTHASHSIZE)
13 #define realnamehash(x) ((crc32(x))%REALNAMEHASHSIZE)
15 unsigned int hostmarker
;
16 unsigned int realnamemarker
;
17 unsigned int nickmarker
;
19 host
*hosttable
[HOSTHASHSIZE
];
20 realname
*realnametable
[REALNAMEHASHSIZE
];
22 void initnickhelpers() {
23 memset(hosttable
,0,sizeof(hosttable
));
24 memset(realnametable
,0,sizeof(realnametable
));
27 host
*findhost(const char *hostname
) {
29 for (hp
=hosttable
[hosthash(hostname
)];hp
;hp
=(host
*)hp
->next
) {
30 if (!ircd_strcmp(hostname
,hp
->name
->content
))
36 host
*findorcreatehost(const char *hostname
) {
38 unsigned long thehash
=hosthash(hostname
);
40 for (hp
=hosttable
[thehash
];hp
;hp
=(host
*)hp
->next
)
41 if (!ircd_strcmp(hostname
,hp
->name
->content
)) {
47 hp
->name
=getsstring(hostname
,HOSTLEN
);
51 hp
->next
=(struct host
*)hosttable
[thehash
];
52 hosttable
[thehash
]=hp
;
57 void releasehost(host
*hp
) {
59 if (--(hp
->clonecount
)==0) {
60 for(mhp
=&(hosttable
[hosthash(hp
->name
->content
)]);*mhp
;mhp
=(host
**)&((*mhp
)->next
)) {
62 (*mhp
)=(host
*)hp
->next
;
63 freesstring(hp
->name
);
68 Error("nick",ERR_ERROR
,"Unable to remove host %s from hashtable",hp
->name
->content
);
72 realname
*findrealname(const char *name
) {
75 for (rnp
=realnametable
[realnamehash(name
)];rnp
;rnp
=(realname
*)rnp
->next
)
76 if (!strcmp(name
,rnp
->name
->content
))
82 realname
*findorcreaterealname(const char *name
) {
84 unsigned int thehash
=realnamehash(name
);
86 for (rnp
=realnametable
[thehash
];rnp
;rnp
=(realname
*)rnp
->next
)
87 if (!strcmp(name
,rnp
->name
->content
)) {
93 rnp
->name
=getsstring(name
,REALLEN
);
97 rnp
->next
=(struct realname
*)realnametable
[thehash
];
98 realnametable
[thehash
]=rnp
;
103 void releaserealname(realname
*rnp
) {
105 if (--(rnp
->usercount
)==0) {
106 for(mrnp
=&(realnametable
[realnamehash(rnp
->name
->content
)]);*mrnp
;mrnp
=(realname
**)&((*mrnp
)->next
)) {
108 (*mrnp
)=(realname
*)rnp
->next
;
109 freesstring(rnp
->name
);
114 Error("nick",ERR_ERROR
,"Unable to remove realname %s from hashtable",rnp
->name
->content
);
118 unsigned int nexthostmarker() {
124 /* If we wrapped to zero, zap the marker on all hosts */
125 for (i
=0;i
<HOSTHASHSIZE
;i
++)
126 for (hp
=hosttable
[i
];hp
;hp
=hp
->next
)
134 unsigned int nextrealnamemarker() {
139 if (!realnamemarker
) {
140 /* If we wrapped to zero, zap the marker on all records */
141 for (i
=0;i
<REALNAMEHASHSIZE
;i
++)
142 for (rnp
=realnametable
[i
];rnp
;rnp
=rnp
->next
)
147 return realnamemarker
;
150 unsigned int nextnickmarker() {
157 /* If we wrapped to zero, zap the marker on all records */
158 for (i
=0;i
<NICKHASHSIZE
;i
++)
159 for (np
=nicktable
[i
];np
;np
=np
->next
)