#include <string.h>
-#define hosthash(x) ((crc32i(x))%HOSTHASHSIZE)
-#define realnamehash(x) ((crc32(x))%REALNAMEHASHSIZE)
-#define authnamehash(x) ((x)%AUTHNAMEHASHSIZE)
+#define hosthash(x) ((irc_crc32i(x))%HOSTHASHSIZE)
+#define realnamehash(x) ((irc_crc32(x))%REALNAMEHASHSIZE)
host *hosttable[HOSTHASHSIZE];
realname *realnametable[REALNAMEHASHSIZE];
-authname *authnametable[AUTHNAMEHASHSIZE];
void initnickhelpers() {
memset(hosttable,0,sizeof(hosttable));
memset(realnametable,0,sizeof(realnametable));
- memset(authnametable,0,sizeof(authnametable));
+}
+
+void fininickhelpers() {
+ host *hnp, *hnpn;
+ realname *rnp, *rnpn;
+ int i;
+
+ for(i=0;i<HOSTHASHSIZE;i++) {
+ for(hnp=hosttable[i];hnp;hnp=hnpn) {
+ hnpn=hnp->next;
+ freesstring(hnp->name);
+ freehost(hnp);
+ }
+ hosttable[i]=NULL;
+ }
+
+ for(i=0;i<REALNAMEHASHSIZE;i++) {
+ for(rnp=realnametable[i];rnp;rnp=rnpn) {
+ rnpn=rnp->next;
+ freesstring(rnp->name);
+ freerealname(rnp);
+ }
+ realnametable[i]=NULL;
+ }
}
host *findhost(const char *hostname) {
}
}
-authname *findauthname(unsigned long userid) {
- authname *anp;
-
- if(!userid)
- return NULL;
-
- for (anp=authnametable[authnamehash(userid)];anp;anp=(authname *)anp->next)
- if (userid==anp->userid)
- return anp;
-
- return NULL;
-}
-
-authname *findorcreateauthname(unsigned long userid) {
- authname *anp;
- unsigned int thehash=authnamehash(userid);
-
- if(!userid)
- return NULL;
-
- for (anp=authnametable[thehash];anp;anp=(authname *)anp->next)
- if (userid==anp->userid)
- return anp;
-
- anp=newauthname();
- anp->userid=userid;
- anp->usercount=0;
- anp->marker=0;
- anp->nicks=NULL;
- memset(anp->exts, 0, MAXAUTHNAMEEXTS * sizeof(void *));
- anp->next=(struct authname *)authnametable[thehash];
- authnametable[thehash]=anp;
-
- return anp;
-}
-
-void releaseauthname(authname *anp) {
- authname **manp;
- int i;
- if (anp->usercount==0) {
- for(i=0;i<MAXAUTHNAMEEXTS;i++)
- if(anp->exts[i]!=NULL)
- return;
-
- for(manp=&(authnametable[authnamehash(anp->userid)]);*manp;manp=(authname **)&((*manp)->next)) {
- if ((*manp)==anp) {
- (*manp)=(authname *)anp->next;
- freeauthname(anp);
- return;
- }
- }
- Error("nick",ERR_ERROR,"Unable to remove authname %lu from hashtable",anp->userid);
- }
-}
-
unsigned int nexthostmarker() {
int i;
host *hp;
return realnamemarker;
}
-unsigned int nextauthnamemarker() {
- int i;
- authname *anp;
- static unsigned int authnamemarker=0;
-
- authnamemarker++;
- if (!authnamemarker) {
- /* If we wrapped to zero, zap the marker on all records */
- for (i=0;i<AUTHNAMEHASHSIZE;i++)
- for (anp=authnametable[i];anp;anp=anp->next)
- anp->marker=0;
- authnamemarker++;
- }
-
- return authnamemarker;
-}
-
unsigned int nextnickmarker() {
int i;
nick *np;