]>
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 host
*hosttable
[HOSTHASHSIZE
];
16 realname
*realnametable
[REALNAMEHASHSIZE
];
18 void initnickhelpers() {
19 memset(hosttable
,0,sizeof(hosttable
));
20 memset(realnametable
,0,sizeof(realnametable
));
23 void fininickhelpers() {
28 for(i
=0;i
<HOSTHASHSIZE
;i
++) {
29 for(hnp
=hosttable
[i
];hnp
;hnp
=hnpn
) {
31 freesstring(hnp
->name
);
37 for(i
=0;i
<REALNAMEHASHSIZE
;i
++) {
38 for(rnp
=realnametable
[i
];rnp
;rnp
=rnpn
) {
40 freesstring(rnp
->name
);
43 realnametable
[i
]=NULL
;
47 host
*findhost(const char *hostname
) {
49 for (hp
=hosttable
[hosthash(hostname
)];hp
;hp
=(host
*)hp
->next
) {
50 if (!ircd_strcmp(hostname
,hp
->name
->content
))
56 host
*findorcreatehost(const char *hostname
) {
58 unsigned long thehash
=hosthash(hostname
);
60 for (hp
=hosttable
[thehash
];hp
;hp
=(host
*)hp
->next
)
61 if (!ircd_strcmp(hostname
,hp
->name
->content
)) {
67 hp
->name
=getsstring(hostname
,HOSTLEN
);
71 hp
->next
=(struct host
*)hosttable
[thehash
];
72 hosttable
[thehash
]=hp
;
77 void releasehost(host
*hp
) {
79 if (--(hp
->clonecount
)==0) {
80 for(mhp
=&(hosttable
[hosthash(hp
->name
->content
)]);*mhp
;mhp
=(host
**)&((*mhp
)->next
)) {
82 (*mhp
)=(host
*)hp
->next
;
83 freesstring(hp
->name
);
88 Error("nick",ERR_ERROR
,"Unable to remove host %s from hashtable",hp
->name
->content
);
92 realname
*findrealname(const char *name
) {
95 for (rnp
=realnametable
[realnamehash(name
)];rnp
;rnp
=(realname
*)rnp
->next
)
96 if (!strcmp(name
,rnp
->name
->content
))
102 realname
*findorcreaterealname(const char *name
) {
104 unsigned int thehash
=realnamehash(name
);
106 for (rnp
=realnametable
[thehash
];rnp
;rnp
=(realname
*)rnp
->next
)
107 if (!strcmp(name
,rnp
->name
->content
)) {
113 rnp
->name
=getsstring(name
,REALLEN
);
117 rnp
->next
=(struct realname
*)realnametable
[thehash
];
118 realnametable
[thehash
]=rnp
;
123 void releaserealname(realname
*rnp
) {
125 if (--(rnp
->usercount
)==0) {
126 for(mrnp
=&(realnametable
[realnamehash(rnp
->name
->content
)]);*mrnp
;mrnp
=(realname
**)&((*mrnp
)->next
)) {
128 (*mrnp
)=(realname
*)rnp
->next
;
129 freesstring(rnp
->name
);
134 Error("nick",ERR_ERROR
,"Unable to remove realname %s from hashtable",rnp
->name
->content
);
138 unsigned int nexthostmarker() {
141 static unsigned int hostmarker
=0;
145 /* If we wrapped to zero, zap the marker on all hosts */
146 for (i
=0;i
<HOSTHASHSIZE
;i
++)
147 for (hp
=hosttable
[i
];hp
;hp
=hp
->next
)
155 unsigned int nextrealnamemarker() {
158 static unsigned int realnamemarker
=0;
161 if (!realnamemarker
) {
162 /* If we wrapped to zero, zap the marker on all records */
163 for (i
=0;i
<REALNAMEHASHSIZE
;i
++)
164 for (rnp
=realnametable
[i
];rnp
;rnp
=rnp
->next
)
169 return realnamemarker
;
172 unsigned int nextnickmarker() {
175 static unsigned int nickmarker
=0;
180 /* If we wrapped to zero, zap the marker on all records */
181 for (i
=0;i
<NICKHASHSIZE
;i
++)
182 for (np
=nicktable
[i
];np
;np
=np
->next
)