]>
jfr.im git - irc/quakenet/newserv.git/blob - channel/channelindex.c
4 #include "../irc/irc_config.h"
5 #include "../lib/irc_string.h"
8 #define channelhash(x) (crc32i(x)%CHANNELHASHSIZE)
10 chanindex
*chantable
[CHANNELHASHSIZE
];
11 sstring
*extnames
[MAXCHANNELEXTS
];
13 unsigned int channelmarker
;
15 void initchannelindex() {
16 memset(chantable
,0,sizeof(chantable
));
17 memset(extnames
,0,sizeof(extnames
));
21 chanindex
*findchanindex(const char *name
) {
23 int hash
=channelhash(name
);
25 for (cip
=chantable
[hash
];cip
;cip
=cip
->next
) {
26 if (!ircd_strcmp(cip
->name
->content
,name
)) {
34 chanindex
*findorcreatechanindex(const char *name
) {
36 int hash
=channelhash(name
);
39 for (cip
=chantable
[hash
];cip
;cip
=cip
->next
) {
40 if (!ircd_strcmp(cip
->name
->content
,name
)) {
47 cip
->name
=getsstring(name
,CHANNELLEN
);
50 cip
->next
=chantable
[hash
];
53 for(i
=0;i
<MAXCHANNELEXTS
;i
++) {
60 void releasechanindex(chanindex
*cip
) {
65 /* If any module is still using the channel, do nothing */
66 /* Same if the channel is still present on the network */
68 if (cip
->channel
!=NULL
) {
72 for (i
=0;i
<MAXCHANNELEXTS
;i
++) {
73 if (cip
->exts
[i
]!=NULL
) {
78 /* Now remove the index record from the index. */
79 hash
=channelhash(cip
->name
->content
);
81 for(cih
=&(chantable
[hash
]);*cih
;cih
=&((*cih
)->next
)) {
84 freesstring(cip
->name
);
90 Error("channel",ERR_ERROR
,"Tried to release chanindex record for %s not found in hash",cip
->name
->content
);
93 int registerchanext(const char *name
) {
96 if (findchanext(name
)!=-1) {
97 Error("channel",ERR_WARNING
,"Tried to register duplicate extension %s",name
);
101 for (i
=0;i
<MAXCHANNELEXTS
;i
++) {
102 if (extnames
[i
]==NULL
) {
103 extnames
[i
]=getsstring(name
,100);
108 Error("channel",ERR_WARNING
,"Tried to register too many extensions: %s",name
);
112 int findchanext(const char *name
) {
115 for (i
=0;i
<MAXCHANNELEXTS
;i
++) {
116 if (extnames
[i
]!=NULL
&& !ircd_strcmp(name
,extnames
[i
]->content
)) {
124 void releasechanext(int index
) {
126 chanindex
*cip
,*ncip
;
128 freesstring(extnames
[index
]);
129 extnames
[index
]=NULL
;
131 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
132 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
133 /* CAREFUL: deleting items from chains you're walking is bad */
135 if (cip
->exts
[index
]!=NULL
) {
136 cip
->exts
[index
]=NULL
;
137 releasechanindex(cip
);
143 unsigned int nextchanmarker() {
148 if (!channelmarker
) {
149 /* If we wrapped to zero, zap the marker on all records */
150 for (i
=0;i
<CHANNELHASHSIZE
;i
++)
151 for (cip
=chantable
[i
];cip
;cip
=cip
->next
)
156 return channelmarker
;