]>
jfr.im git - irc/quakenet/newserv.git/blob - channel/channelindex.c
4 #include "../irc/irc_config.h"
5 #include "../lib/irc_string.h"
9 #define channelhash(x) (crc32i(x)%CHANNELHASHSIZE)
11 chanindex
*chantable
[CHANNELHASHSIZE
];
12 sstring
*extnames
[MAXCHANNELEXTS
];
14 unsigned int channelmarker
;
16 void initchannelindex() {
17 memset(chantable
,0,sizeof(chantable
));
18 memset(extnames
,0,sizeof(extnames
));
22 chanindex
*findchanindex(const char *name
) {
24 int hash
=channelhash(name
);
26 for (cip
=chantable
[hash
];cip
;cip
=cip
->next
) {
27 if (!ircd_strcmp(cip
->name
->content
,name
)) {
35 chanindex
*findorcreatechanindex(const char *name
) {
37 int hash
=channelhash(name
);
40 for (cip
=chantable
[hash
];cip
;cip
=cip
->next
) {
41 if (!ircd_strcmp(cip
->name
->content
,name
)) {
48 cip
->name
=getsstring(name
,CHANNELLEN
);
51 cip
->next
=chantable
[hash
];
54 for(i
=0;i
<MAXCHANNELEXTS
;i
++) {
61 void releasechanindex(chanindex
*cip
) {
66 /* If any module is still using the channel, do nothing */
67 /* Same if the channel is still present on the network */
69 if (cip
->channel
!=NULL
) {
73 for (i
=0;i
<MAXCHANNELEXTS
;i
++) {
74 if (cip
->exts
[i
]!=NULL
) {
79 /* Now remove the index record from the index. */
80 hash
=channelhash(cip
->name
->content
);
82 for(cih
=&(chantable
[hash
]);*cih
;cih
=&((*cih
)->next
)) {
85 freesstring(cip
->name
);
91 Error("channel",ERR_ERROR
,"Tried to release chanindex record for %s not found in hash",cip
->name
->content
);
94 int registerchanext(const char *name
) {
97 if (findchanext(name
)!=-1) {
98 Error("channel",ERR_WARNING
,"Tried to register duplicate extension %s",name
);
102 for (i
=0;i
<MAXCHANNELEXTS
;i
++) {
103 if (extnames
[i
]==NULL
) {
104 extnames
[i
]=getsstring(name
,100);
109 Error("channel",ERR_WARNING
,"Tried to register too many extensions: %s",name
);
113 int findchanext(const char *name
) {
116 for (i
=0;i
<MAXCHANNELEXTS
;i
++) {
117 if (extnames
[i
]!=NULL
&& !ircd_strcmp(name
,extnames
[i
]->content
)) {
125 void releasechanext(int index
) {
127 chanindex
*cip
,*ncip
;
129 freesstring(extnames
[index
]);
130 extnames
[index
]=NULL
;
132 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
133 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
134 /* CAREFUL: deleting items from chains you're walking is bad */
136 if (cip
->exts
[index
]!=NULL
) {
137 cip
->exts
[index
]=NULL
;
138 releasechanindex(cip
);
144 unsigned int nextchanmarker() {
149 if (!channelmarker
) {
150 /* If we wrapped to zero, zap the marker on all records */
151 for (i
=0;i
<CHANNELHASHSIZE
;i
++)
152 for (cip
=chantable
[i
];cip
;cip
=cip
->next
)
157 return channelmarker
;