]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/database/chanservdb_hash.c
3 * Handles insertion and retrieval of various data structures
4 * from their respective hashes. Hopefully it's obvious from
5 * the name of each function what it does.
10 #include "../chanserv.h"
11 #include "../../lib/irc_string.h"
13 reguser
*regusernicktable
[REGUSERHASHSIZE
];
15 maildomain
*maildomainnametable
[MAILDOMAINHASHSIZE
];
16 maildomain
*maildomainIDtable
[MAILDOMAINHASHSIZE
];
18 #define regusernickhash(x) ((crc32i(x))%REGUSERHASHSIZE)
19 #define maildomainnamehash(x) ((crc32i(x))%MAILDOMAINHASHSIZE)
20 #define maildomainIDhash(x) ((x)%MAILDOMAINHASHSIZE)
22 void chanservhashinit() {
23 memset(regusernicktable
,0,REGUSERHASHSIZE
*sizeof(reguser
*));
24 memset(maildomainnametable
,0,MAILDOMAINHASHSIZE
*sizeof(maildomain
*));
25 memset(maildomainIDtable
,0,MAILDOMAINHASHSIZE
*sizeof(maildomain
*));
28 void addregusertohash(reguser
*rup
) {
32 hash
=regusernickhash(rup
->username
);
34 rup
->nextbyname
=regusernicktable
[hash
];
35 regusernicktable
[hash
]=rup
;
37 anp
=findorcreateauthname(rup
->ID
);
38 anp
->exts
[chanservaext
]=rup
;
41 reguser
*findreguserbynick(const char *nick
) {
42 unsigned int hashnick
;
45 hashnick
=regusernickhash(nick
);
46 for (rup
=regusernicktable
[hashnick
];rup
;rup
=rup
->nextbyname
) {
47 if (!ircd_strcmp(nick
,rup
->username
)) {
56 reguser
*findreguserbyID(unsigned int ID
) {
61 return (reguser
*)anp
->exts
[chanservaext
];
67 * findreguserbyemail()
69 reguser
*findreguserbyemail(const char *email
) {
73 for (i
=0;i
<REGUSERHASHSIZE
;i
++) {
74 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
) {
75 if (rup
->email
&& !strcasecmp(email
,rup
->email
->content
)) {
84 void removereguserfromhash(reguser
*rup
) {
91 hash
=regusernickhash(rup
->username
);
94 for (ruh
=&(regusernicktable
[hash
]);*ruh
;ruh
=&((*ruh
)->nextbyname
)) {
96 *ruh
=(rup
->nextbyname
);
103 Error("chanserv",ERR_ERROR
,"Unable to remove reguser %s from nickhash",
107 anp
=findauthname(rup
->ID
);
110 anp
->exts
[chanservaext
]=NULL
;
111 releaseauthname(anp
);
113 Error("chanserv",ERR_ERROR
,"Unable to remove reguser %s from ID hash",rup
->username
);
117 void addregusertochannel(regchanuser
*rcup
) {
118 rcup
->nextbyuser
=(rcup
->user
->knownon
);
119 rcup
->nextbychan
=(rcup
->chan
->regusers
[(rcup
->user
->ID
)%REGCHANUSERHASHSIZE
]);
121 rcup
->user
->knownon
=rcup
;
122 rcup
->chan
->regusers
[(rcup
->user
->ID
)%REGCHANUSERHASHSIZE
]=rcup
;
125 regchanuser
*findreguseronchannel(regchan
*rcp
, reguser
*rup
) {
128 for (rcup
=rcp
->regusers
[(rup
->ID
)%REGCHANUSERHASHSIZE
];rcup
;rcup
=rcup
->nextbychan
) {
129 if (rcup
->user
==rup
) {
138 void delreguserfromchannel(regchan
*rcp
, reguser
*rup
) {
142 for (rcuh
=&(rcp
->regusers
[(rup
->ID
)%REGCHANUSERHASHSIZE
]);*rcuh
;
143 rcuh
=&((*rcuh
)->nextbychan
)) {
144 if ((*rcuh
)->user
==rup
) {
146 freesstring((*rcuh
)->info
);
148 *rcuh
=(*rcuh
)->nextbychan
;
155 Error("chanserv",ERR_ERROR
,"Unable to remove user %s from channel %s",
156 rup
->username
,rcp
->index
->name
->content
);
160 for (rcuh
=&(rup
->knownon
);*rcuh
;rcuh
=&((*rcuh
)->nextbyuser
)) {
161 if ((*rcuh
)->chan
==rcp
) {
162 /* Found the channel */
163 *rcuh
=(*rcuh
)->nextbyuser
;
168 Error("chanserv",ERR_ERROR
,"Unable to remove channel %s from user %s",
169 rcp
->index
->name
->content
,rup
->username
);
172 void addmaildomaintohash(maildomain
*mdp
) {
175 hash
=maildomainnamehash(mdp
->name
->content
);
177 mdp
->nextbyname
=maildomainnametable
[hash
];
178 maildomainnametable
[hash
]=mdp
;
180 hash
=maildomainIDhash(mdp
->ID
);
182 mdp
->nextbyID
=maildomainIDtable
[hash
];
183 maildomainIDtable
[hash
]=mdp
;
186 maildomain
*findmaildomainbyID(unsigned int ID
) {
190 hash
=maildomainIDhash(ID
);
191 for (mdp
=maildomainIDtable
[hash
]; mdp
; mdp
=mdp
->nextbyID
)
198 maildomain
*findmaildomainbydomain(char *domain
) {
202 hash
=maildomainnamehash(domain
);
203 for (mdp
=maildomainnametable
[hash
]; mdp
; mdp
=mdp
->nextbyname
)
204 if (!strcasecmp(mdp
->name
->content
, domain
))
210 maildomain
*findnearestmaildomain(char *domain
) {
211 maildomain
*m
= findmaildomainbydomain(domain
);
214 if(!m
&& (p
=strchr(domain
, '.')))
215 return findnearestmaildomain(++p
);
220 maildomain
*findmaildomainbyemail(char *email
) {
223 if (!(domain
=strchr(email
, '@')))
228 return findmaildomainbydomain(domain
);
231 maildomain
*findorcreatemaildomain(char *email
) {
233 char *domain
,*pdomain
;
236 if (!(domain
=strchr(email
, '@')))
241 if( domain
[0] == '.' )
244 hash
=maildomainnamehash(domain
);
245 for (mdp
=maildomainnametable
[hash
]; mdp
; mdp
=mdp
->nextbyname
)
246 if (!strcasecmp(mdp
->name
->content
, domain
))
251 mdp
->name
=getsstring(domain
, EMAILLEN
);
254 mdp
->actlimit
=MD_DEFAULTACTLIMIT
;
255 mdp
->flags
=MDFLAG_DEFAULT
;
257 addmaildomaintohash(mdp
);
259 pdomain
=strchr(domain
, '.');
263 mdp
->parent
= findorcreatemaildomain(pdomain
);
271 void removemaildomainfromhash(maildomain
*mdp
) {
276 hash
=maildomainnamehash(mdp
->name
->content
);
279 for (mdh
=&(maildomainnametable
[hash
]);*mdh
;mdh
=&((*mdh
)->nextbyname
)) {
281 *mdh
=(mdp
->nextbyname
);
288 Error("chanserv",ERR_ERROR
,"Unable to remove maildomain %s from namehash",
292 hash
=maildomainIDhash(mdp
->ID
);
295 for (mdh
=&(maildomainIDtable
[hash
]);*mdh
;mdh
=&((*mdh
)->nextbyID
)) {
297 *mdh
=(mdp
->nextbyID
);
304 Error("chanserv",ERR_ERROR
,"Unable to remove maildomain %s from ID hash",mdp
->name
->content
);
308 void addregusertomaildomain(reguser
*rup
, maildomain
*mdp
) {
310 rup
->nextbydomain
=mdp
->users
;
312 for(smdp
=mdp
;smdp
;smdp
=smdp
->parent
) {
317 void delreguserfrommaildomain(reguser
*rup
, maildomain
*mdp
) {
319 reguser
*ruh
, *pruh
=NULL
;
325 for (ruh
=mdp
->users
; ruh
; ruh
=ruh
->nextbydomain
) {
329 pruh
->nextbydomain
=ruh
->nextbydomain
;
331 mdp
->users
=ruh
->nextbydomain
;
339 Error("chanserv",ERR_ERROR
,"Unable to remove user %s from maildomain %s",
340 rup
->username
, mdp
->name
->content
);
344 for(smdp
=mdp
;smdp
;smdp
=smdp
->parent
) {
348 freesstring(rup
->localpart
);
351 if (!mdp
->count
&& !MDHasLimit(mdp
)) {
352 removemaildomainfromhash(mdp
);