]>
jfr.im git - irc/quakenet/newserv.git/blob - authext/authext.c
2 #include "../core/nsmalloc.h"
3 #include "../core/error.h"
4 #include "../lib/sstring.h"
5 #include "../lib/irc_string.h"
6 #include "../nick/nick.h"
12 #define authnamehash(x) ((x)%AUTHNAMEHASHSIZE)
13 #define authnamehashbyname(x) (crc32i(x)%AUTHNAMEHASHSIZE)
15 authname
*freeauthnames
;
16 authname
*authnametable
[AUTHNAMEHASHSIZE
];
18 /* internal access only */
19 static authname
*authnametablebyname
[AUTHNAMEHASHSIZE
];
21 sstring
*authnameextnames
[MAXAUTHNAMEEXTS
];
25 memset(authnametable
,0,sizeof(authnametable
));
26 memset(authnametablebyname
,0,sizeof(authnametablebyname
));
30 nsfreeall(POOL_AUTHEXT
);
33 authname
*newauthname(void) {
37 if (freeauthnames
==NULL
) {
38 freeauthnames
=(authname
*)nsmalloc(POOL_AUTHEXT
, ALLOCUNIT
*sizeof(authname
));
39 for (i
=0;i
<(ALLOCUNIT
-1);i
++) {
40 freeauthnames
[i
].next
=&(freeauthnames
[i
+1]);
42 freeauthnames
[ALLOCUNIT
-1].next
=NULL
;
46 freeauthnames
=anp
->next
;
51 void freeauthname (authname
*anp
) {
52 anp
->next
=freeauthnames
;
56 int registerauthnameext(const char *name
) {
59 if (findauthnameext(name
)!=-1) {
60 Error("nick",ERR_WARNING
,"Tried to register duplicate authname extension %s",name
);
64 for (i
=0;i
<MAXAUTHNAMEEXTS
;i
++) {
65 if (authnameextnames
[i
]==NULL
) {
66 authnameextnames
[i
]=getsstring(name
,100);
71 Error("nick",ERR_WARNING
,"Tried to register too many authname extensions: %s",name
);
75 int findauthnameext(const char *name
) {
78 for (i
=0;i
<MAXAUTHNAMEEXTS
;i
++) {
79 if (authnameextnames
[i
]!=NULL
&& !ircd_strcmp(name
,authnameextnames
[i
]->content
)) {
87 void releaseauthnameext(int index
) {
91 freesstring(authnameextnames
[index
]);
92 authnameextnames
[index
]=NULL
;
94 for (i
=0;i
<AUTHNAMEHASHSIZE
;i
++) {
95 for (anp
=authnametable
[i
];anp
;anp
=anp
->next
) {
96 anp
->exts
[index
]=NULL
;
100 /* the contents of authnametablebyname should be identical */
103 authname
*findauthname(unsigned long userid
) {
109 for (anp
=authnametable
[authnamehash(userid
)];anp
;anp
=(authname
*)anp
->next
)
110 if (userid
==anp
->userid
)
116 authname
*findauthnamebyname(const char *name
) {
122 for (anp
=authnametable
[authnamehashbyname(name
)];anp
;anp
=(authname
*)anp
->nextbyname
)
123 if (!ircd_strcmp(anp
->nicks
->authname
, name
))
129 authname
*findorcreateauthname(unsigned long userid
, const char *name
) {
131 unsigned int thehash
=authnamehash(userid
), secondhash
= authnamehashbyname(name
);
136 for (anp
=authnametable
[thehash
];anp
;anp
=(authname
*)anp
->next
)
137 if (userid
==anp
->userid
)
145 memset(anp
->exts
, 0, MAXAUTHNAMEEXTS
* sizeof(void *));
146 anp
->next
=(struct authname
*)authnametable
[thehash
];
147 authnametable
[thehash
]=anp
;
149 anp
->namebucket
=secondhash
;
150 anp
->nextbyname
=(struct authname
*)authnametablebyname
[secondhash
];
151 authnametablebyname
[secondhash
]=anp
;
156 void releaseauthname(authname
*anp
) {
159 if (anp
->usercount
==0) {
162 for(i
=0;i
<MAXAUTHNAMEEXTS
;i
++)
163 if(anp
->exts
[i
]!=NULL
)
167 for(manp
=&(authnametable
[authnamehash(anp
->userid
)]);*manp
;manp
=(authname
**)&((*manp
)->next
)) {
169 (*manp
)=(authname
*)anp
->next
;
175 Error("nick",ERR_ERROR
,"Unable to remove authname %lu from hashtable",anp
->userid
);
179 for(manp
=&(authnametablebyname
[anp
->namebucket
]);*manp
;manp
=(authname
**)&((*manp
)->nextbyname
)) {
181 (*manp
)=(authname
*)anp
->nextbyname
;
187 Error("nick",ERR_STOP
,"Unable to remove authname %lu from byname hashtable, TABLES ARE INCONSISTENT -- DYING",anp
->userid
);
191 unsigned int nextauthnamemarker(void) {
194 static unsigned int authnamemarker
=0;
197 if (!authnamemarker
) {
198 /* If we wrapped to zero, zap the marker on all records */
199 for (i
=0;i
<AUTHNAMEHASHSIZE
;i
++)
200 for (anp
=authnametable
[i
];anp
;anp
=anp
->next
)
205 return authnamemarker
;
208 authname
*getauthbyname(const char *name
) {
209 authname
*a
= findauthnamebyname(name
);