]> jfr.im git - irc/quakenet/newserv.git/blob - trusts2/trusts_hash.c
Merge.
[irc/quakenet/newserv.git] / trusts2 / trusts_hash.c
1 #include "trusts.h"
2
3 trustgroup_t *trustgroupidtable[TRUSTS_HASH_GROUPSIZE];
4 trustgroup_t *trustgroupnametable[TRUSTS_HASH_GROUPSIZE];
5 trusthost_t *trusthostidtable[TRUSTS_HASH_HOSTSIZE];
6 trusthost_t *trusthostgroupidtable[TRUSTS_HASH_HOSTSIZE];
7 trustgroupidentcount_t *trustgroupidentcounttable[TRUSTS_HASH_IDENTSIZE];
8
9 void trusts_hash_init() {
10 memset(trustgroupidtable,0,sizeof(trustgroupidtable));
11 memset(trustgroupnametable,0,sizeof(trustgroupnametable));
12 memset(trusthostidtable,0,sizeof(trusthostidtable));
13 memset(trusthostgroupidtable,0,sizeof(trusthostgroupidtable));
14 }
15
16 void trusts_hash_fini() {
17 }
18
19 void trusts_addtrusthosttohash(trusthost_t *newhost)
20 {
21 unsigned int hash;
22 hash = trusts_gettrusthostidhash(newhost->id);
23 newhost->nextbyid = trusthostidtable[hash];
24 trusthostidtable[hash] = newhost;
25
26 hash = trusts_gettrusthostgroupidhash(newhost->trustgroup->id);
27 newhost->nextbygroupid = trusthostgroupidtable[hash];
28 trusthostgroupidtable[hash] = newhost;
29 }
30
31 void trusts_removetrusthostfromhash(trusthost_t *t)
32 {
33 trusthost_t **tgh;
34 int found = 0;
35 for(tgh=&(trusthostidtable[trusts_gettrusthostidhash(t->id)]);*tgh;tgh=(trusthost_t **)&((*tgh)->nextbyid)) {
36 if((*tgh)==t) {
37 (*tgh)=(trusthost_t *)t->nextbyid;
38 found = 1;
39 break;
40 }
41 }
42 if(!found)
43 Error("trusts",ERR_ERROR,"Unable to remove trusthost id %lu from hashtable", t->id);
44 found = 0;
45 for(tgh=&(trusthostgroupidtable[trusts_gettrusthostgroupidhash(t->trustgroup->id)]);*tgh;tgh=(trusthost_t **)&((*tgh)->nextbygroupid)) {
46 if((*tgh)==t) {
47 (*tgh)=(trusthost_t *)t->nextbygroupid;
48 found = 1;
49 break;
50 }
51 }
52 if(!found)
53 Error("trusts",ERR_ERROR,"Unable to remove trusthost groupid %lu from hashtable", t->trustgroup->id);
54 }
55
56 void trusts_addtrustgrouptohash(trustgroup_t *newgroup)
57 {
58 unsigned int hash;
59 hash = trusts_gettrustgroupidhash(newgroup->id);
60 newgroup->nextbyid = trustgroupidtable[hash];
61 trustgroupidtable[hash] = newgroup;
62 }
63
64 trustgroup_t* findtrustgroupbyid(int id) {
65 trustgroup_t* tl;
66
67 for(tl=trustgroupidtable[trusts_gettrustgroupidhash(id)]; tl; tl = (trustgroup_t *)tl->nextbyid) {
68 if(tl->id == id) {
69 return tl;
70 }
71 }
72 return NULL;
73 }
74
75 trustgroup_t* findtrustgroupbyownerid(int ownerid) {
76 trustgroup_t* tg;
77 int i;
78
79 for ( i = 0; i < TRUSTS_HASH_GROUPSIZE ; i++ ) {
80 for ( tg = trustgroupidtable[i]; tg; tg = tg -> nextbyid ) {
81 if(tg->ownerid == ownerid) {
82 return tg;
83 }
84 }
85 }
86 return NULL;
87 }
88
89
90 void trusts_removetrustgroupfromhash(trustgroup_t *t)
91 {
92 trustgroup_t **tg;
93 int found = 0;
94 for(tg=&(trustgroupidtable[trusts_gettrustgroupidhash(t->id)]);*tg;tg=(trustgroup_t **)&((*tg)->nextbyid)) {
95 if((*tg)==t) {
96 (*tg)=(trustgroup_t *)t->nextbyid;
97 found = 1;
98 break;
99 }
100 }
101 if (!found)
102 Error("trusts",ERR_ERROR,"Unable to remove trustgroup ID %lu from hashtable",t->id);
103 }
104
105 void trusts_addtrustgroupidenttohash(trustgroupidentcount_t *newident)
106 {
107 unsigned int hash;
108 hash = trusts_gettrustgroupidenthash(newident->ident->content);
109 newident->next = trustgroupidentcounttable[hash];
110 trustgroupidentcounttable[hash] = newident;
111 }
112
113 void trusts_removetrustgroupidentfromhash(trustgroupidentcount_t *t)
114 {
115 trustgroupidentcount_t **thi;
116 for(thi=&(trustgroupidentcounttable[trusts_gettrustgroupidenthash(t->ident->content)]);*thi;thi=(trustgroupidentcount_t **)&((*thi)->next)) {
117 if((*thi)==t) {
118 (*thi)=(trustgroupidentcount_t *)t->next;
119 return;
120 }
121 }
122 Error("trusts",ERR_ERROR,"Unable to remove trustgroup ident %s from group %lu from hashtable",t->ident->content, t->trustgroup->id);
123 }
124
125 trustgroupidentcount_t* findtrustgroupcountbyident(char *ident, trustgroup_t *t) {
126 trustgroupidentcount_t* tgi;
127
128 for(tgi=trustgroupidentcounttable[trusts_gettrustgroupidenthash(ident)]; tgi; tgi = (trustgroupidentcount_t *)tgi->next) {
129 if(tgi->trustgroup == t) {
130 if(strcmp(tgi->ident->content,ident)==0) {
131 return tgi;
132 }
133 }
134 }
135 return NULL;
136 }
137