]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/database/chanservdb.c
3 * Handles the SQL stuff for the channel service.
6 #include "../chanserv.h"
7 #include "../../core/config.h"
8 #include "../../lib/sstring.h"
9 #include "../../parser/parser.h"
10 #include "../../core/events.h"
11 #include "../../core/nsmalloc.h"
12 #include "../../lib/strlfunc.h"
13 #include "../../dbapi/dbapi.h"
28 unsigned int lastchannelID
;
29 unsigned int lastuserID
;
30 unsigned int lastbanID
;
31 unsigned int lastdomainID
;
32 unsigned int lastmaillockID
;
34 /* Local prototypes */
35 void csdb_handlestats(int hooknum
, void *arg
);
36 void loadmessages_part1(DBConn
*, void *);
37 void loadmessages_part2(DBConn
*, void *);
38 void loadcommandsummary_real(DBConn
*, void *);
40 /* User loading functions */
41 void loadsomeusers(DBConn
*, void *);
42 void loadusersdone(DBConn
*, void *);
44 /* Channel loading functions */
45 void loadsomechannels(DBConn
*, void *);
46 void loadchannelsdone(DBConn
*, void *);
48 /* Chanuser loading functions */
49 void loadchanusersinit(DBConn
*, void *);
50 void loadsomechanusers(DBConn
*, void *);
51 void loadchanusersdone(DBConn
*, void *);
53 /* Chanban loading functions */
54 void loadsomechanbans(DBConn
*, void *);
55 void loadchanbansdone(DBConn
*, void *);
57 /* Mail Domain loading functions */
58 void loadsomemaildomains(DBConn
*, void *);
59 void loadmaildomainsdone(DBConn
*, void *);
61 /* Mail lock loading functions */
62 void loadsomemaillocks(DBConn
*, void *);
63 void loadmaillocksdone(DBConn
*, void *);
65 /* Free sstrings in the structures */
66 void csdb_freestuff();
68 static void setuptables() {
69 /* Set up the tables */
72 dbcreatequery("CREATE TABLE chanserv.users ("
74 "username VARCHAR(16) NOT NULL,"
75 "created INT NOT NULL,"
76 "lastauth INT NOT NULL,"
77 "lastemailchng INT NOT NULL,"
79 "language INT NOT NULL,"
80 "suspendby INT NOT NULL,"
81 "suspendexp INT NOT NULL,"
82 "suspendtime INT NOT NULL,"
83 "lockuntil INT NOT NULL,"
84 "password VARCHAR(11) NOT NULL,"
86 "lastemail VARCHAR(100),"
87 "lastuserhost VARCHAR(75),"
88 "suspendreason VARCHAR(250),"
89 "comment VARCHAR(250),"
93 dbcreatequery("CREATE INDEX user_username_index ON chanserv.users (username)");
96 dbcreatequery("CREATE TABLE chanserv.channels ("
98 "name VARCHAR(250) NOT NULL,"
100 "forcemodes INT NOT NULL,"
101 "denymodes INT NOT NULL,"
102 "chanlimit INT NOT NULL,"
103 "autolimit INT NOT NULL,"
104 "banstyle INT NOT NULL,"
105 "created INT NOT NULL,"
106 "lastactive INT NOT NULL,"
107 "statsreset INT NOT NULL,"
108 "banduration INT NOT NULL,"
109 "founder INT NOT NULL,"
110 "addedby INT NOT NULL,"
111 "suspendby INT NOT NULL,"
112 "suspendtime INT NOT NULL,"
113 "chantype SMALLINT NOT NULL,"
114 "totaljoins INT NOT NULL,"
115 "tripjoins INT NOT NULL,"
116 "maxusers INT NOT NULL,"
117 "tripusers INT NOT NULL,"
118 "welcome VARCHAR(500),"
119 "topic VARCHAR(250),"
120 "chankey VARCHAR(23),"
121 "suspendreason VARCHAR(250),"
122 "comment VARCHAR(250),"
124 "PRIMARY KEY (ID))");
127 dbcreatequery("CREATE TABLE chanserv.chanusers ("
128 "userID INT NOT NULL,"
129 "channelID INT NOT NULL,"
130 "flags INT NOT NULL,"
131 "changetime INT NOT NULL,"
132 "usetime INT NOT NULL,"
133 "info VARCHAR(100) NOT NULL,"
134 "PRIMARY KEY (userID, channelID))");
136 dbcreatequery("CREATE INDEX chanusers_userID_index on chanserv.chanusers (userID)");
137 dbcreatequery("CREATE INDEX chanusers_channelID_index on chanserv.chanusers (channelID)");
139 dbcreatequery("CREATE TABLE chanserv.bans ("
140 "banID INT NOT NULL," /* Unique number for the ban to make
141 DELETEs process in finite time.. */
142 "channelID INT NOT NULL,"
143 "userID INT NOT NULL," /* Who set the ban.. */
144 "hostmask VARCHAR(100) NOT NULL," /* needs to be at least USERLEN+NICKLEN+HOSTLEN+2 */
145 "expiry INT NOT NULL,"
146 "reason VARCHAR(200),"
147 "PRIMARY KEY(banID))");
149 dbcreatequery("CREATE INDEX bans_channelID_index on chanserv.bans (channelID)");
151 dbcreatequery("CREATE TABLE chanserv.languages ("
152 "languageID INT NOT NULL,"
153 "code VARCHAR(2) NOT NULL,"
154 "name VARCHAR(30) NOT NULL)");
156 dbcreatequery("CREATE TABLE chanserv.messages ("
157 "languageID INT NOT NULL,"
158 "messageID INT NOT NULL,"
159 "message VARCHAR(250) NOT NULL,"
160 "PRIMARY KEY (languageID, messageID))");
162 dbcreatequery("CREATE TABLE chanserv.help ("
163 "commandID INT NOT NULL,"
164 "command VARCHAR(30) NOT NULL,"
165 "languageID INT NOT NULL,"
166 "summary VARCHAR(200) NOT NULL,"
167 "fullinfo TEXT NOT NULL,"
168 "PRIMARY KEY (commandID, languageID))");
170 dbcreatequery("CREATE TABLE chanserv.email ("
171 "userID INT NOT NULL,"
172 "emailtype INT NOT NULL,"
173 "prevEmail VARCHAR(100),"
175 "PRIMARY KEY (mailID))");
177 dbcreatequery("CREATE TABLE chanserv.maildomain ("
179 "name VARCHAR NOT NULL,"
180 "domainlimit INT NOT NULL,"
181 "actlimit INT NOT NULL,"
182 "flags INT NOT NULL,"
183 "PRIMARY KEY (ID))");
185 dbcreatequery("CREATE TABLE chanserv.authhistory ("
186 "userID INT NOT NULL,"
187 "nick VARCHAR(15) NOT NULL,"
188 "username VARCHAR(10) NOT NULL,"
189 "host VARCHAR(63) NOT NULL,"
190 "authtime INT NOT NULL,"
191 "disconnecttime INT NOT NULL,"
192 "numeric INT NOT NULL,"
193 "quitreason VARCHAR(100) ,"
194 "PRIMARY KEY (userID, authtime))");
196 dbcreatequery("CREATE INDEX authhistory_userID_index on chanserv.authhistory(userID)");
197 dbcreatequery("CREATE TABLE chanserv.chanlevhistory ("
198 "userID INT NOT NULL,"
199 "channelID INT NOT NULL,"
200 "targetID INT NOT NULL,"
201 "changetime INT NOT NULL,"
202 "authtime INT NOT NULL,"
203 "oldflags INT NOT NULL,"
204 "newflags INT NOT NULL)");
206 dbcreatequery("CREATE INDEX chanlevhistory_userID_index on chanserv.chanlevhistory(userID)");
207 dbcreatequery("CREATE INDEX chanlevhistory_channelID_index on chanserv.chanlevhistory(channelID)");
208 dbcreatequery("CREATE INDEX chanlevhistory_targetID_index on chanserv.chanlevhistory(targetID)");
210 dbcreatequery("CREATE TABLE chanserv.accounthistory ("
211 "userID INT NOT NULL,"
212 "changetime INT NOT NULL,"
213 "authtime INT NOT NULL,"
214 "oldpassword VARCHAR(11),"
215 "newpassword VARCHAR(11),"
216 "oldemail VARCHAR(100),"
217 "newemail VARCHAR(100),"
218 "PRIMARY KEY (userID, changetime))");
220 dbcreatequery("CREATE INDEX accounthistory_userID_index on chanserv.accounthistory(userID)");
222 dbcreatequery("CREATE TABLE chanserv.maillocks ("
224 "pattern VARCHAR NOT NULL,"
225 "reason VARCHAR NOT NULL,"
226 "createdby INT NOT NULL,"
227 "created INT NOT NULL,"
228 "PRIMARY KEY (ID))");
232 chanservext
=registerchanext("chanserv");
233 chanservaext
=registerauthnameext("chanserv");
235 /* Set up the allocators and hashes */
239 /* And the messages */
242 if (dbconnected() && (chanservext
!=-1) && (chanservaext
!=-1)) {
243 registerhook(HOOK_CORE_STATSREQUEST
, csdb_handlestats
);
247 lastuserID
=lastchannelID
=lastdomainID
=0;
249 dbloadtable("chanserv.users",NULL
,loadsomeusers
,loadusersdone
);
250 dbloadtable("chanserv.channels",NULL
,loadsomechannels
,loadchannelsdone
);
251 dbloadtable("chanserv.chanusers",loadchanusersinit
,loadsomechanusers
,loadchanusersdone
);
252 dbloadtable("chanserv.bans",NULL
,loadsomechanbans
,loadchanbansdone
);
253 dbloadtable("chanserv.maildomain",NULL
, loadsomemaildomains
,loadmaildomainsdone
);
254 dbloadtable("chanserv.maillocks",NULL
, loadsomemaillocks
,loadmaillocksdone
);
261 deregisterhook(HOOK_CORE_STATSREQUEST
, csdb_handlestats
);
266 releasechanext(chanservext
);
268 if (chanservaext
!=-1)
269 releaseauthnameext(chanservaext
);
271 nsfreeall(POOL_CHANSERVDB
);
272 dbdetach("chanserv");
275 void csdb_handlestats(int hooknum
, void *arg
) {
276 /* long level=(long)arg; */
278 /* Keeping options open here */
281 void chanservdbclose() {
283 deregisterhook(HOOK_CORE_STATSREQUEST
, csdb_handlestats
);
289 * Loads some users in from the SQL DB
292 void loadsomeusers(DBConn
*dbconn
, void *arg
) {
298 pgres
=dbgetresult(dbconn
);
300 if (!dbquerysuccessful(pgres
)) {
301 Error("chanserv",ERR_ERROR
,"Error loading user DB");
305 if (dbnumfields(pgres
)!=18) {
306 Error("chanserv",ERR_ERROR
,"User DB format error");
310 while(dbfetchrow(pgres
)) {
313 rup
->ID
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
314 strncpy(rup
->username
,dbgetvalue(pgres
,1),NICKLEN
); rup
->username
[NICKLEN
]='\0';
315 rup
->created
=strtoul(dbgetvalue(pgres
,2),NULL
,10);
316 rup
->lastauth
=strtoul(dbgetvalue(pgres
,3),NULL
,10);
317 rup
->lastemailchange
=strtoul(dbgetvalue(pgres
,4),NULL
,10);
318 rup
->flags
=strtoul(dbgetvalue(pgres
,5),NULL
,10);
319 rup
->languageid
=strtoul(dbgetvalue(pgres
,6),NULL
,10);
320 rup
->suspendby
=strtoul(dbgetvalue(pgres
,7),NULL
,10);
321 rup
->suspendexp
=strtoul(dbgetvalue(pgres
,8),NULL
,10);
322 rup
->suspendtime
=strtoul(dbgetvalue(pgres
,9),NULL
,10);
323 rup
->lockuntil
=strtoul(dbgetvalue(pgres
,10),NULL
,10);
324 strncpy(rup
->password
,dbgetvalue(pgres
,11),PASSLEN
); rup
->password
[PASSLEN
]='\0';
325 rup
->email
=getsstring(dbgetvalue(pgres
,12),100);
327 rup
->domain
=findorcreatemaildomain(rup
->email
->content
);
328 addregusertomaildomain(rup
, rup
->domain
);
330 strlcpy(mailbuf
, rup
->email
->content
, sizeof(mailbuf
));
331 if((local
=strchr(mailbuf
, '@'))) {
333 rup
->localpart
=getsstring(mailbuf
,EMAILLEN
);
341 rup
->lastemail
=getsstring(dbgetvalue(pgres
,13),100);
342 rup
->lastuserhost
=getsstring(dbgetvalue(pgres
,14),75);
343 rup
->suspendreason
=getsstring(dbgetvalue(pgres
,15),250);
344 rup
->comment
=getsstring(dbgetvalue(pgres
,16),250);
345 rup
->info
=getsstring(dbgetvalue(pgres
,17),100);
350 addregusertohash(rup
);
352 if (rup
->ID
> lastuserID
) {
360 void loadusersdone(DBConn
*conn
, void *arg
) {
361 Error("chanserv",ERR_INFO
,"Load users done (highest ID was %d)",lastuserID
);
365 * Channel loading functions
368 void loadsomechannels(DBConn
*dbconn
, void *arg
) {
373 time_t now
=time(NULL
);
375 pgres
=dbgetresult(dbconn
);
377 if (!dbquerysuccessful(pgres
)) {
378 Error("chanserv",ERR_ERROR
,"Error loading channel DB");
382 if (dbnumfields(pgres
)!=27) {
383 Error("chanserv",ERR_ERROR
,"Channel DB format error");
387 while(dbfetchrow(pgres
)) {
388 cip
=findorcreatechanindex(dbgetvalue(pgres
,1));
389 if (cip
->exts
[chanservext
]) {
390 Error("chanserv",ERR_WARNING
,"%s in database twice - this WILL cause problems later.",cip
->name
->content
);
394 cip
->exts
[chanservext
]=rcp
;
396 rcp
->ID
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
398 rcp
->flags
=strtoul(dbgetvalue(pgres
,2),NULL
,10);
399 rcp
->status
=0; /* Non-DB field */
401 rcp
->lastcountersync
=now
;
404 rcp
->forcemodes
=strtoul(dbgetvalue(pgres
,3),NULL
,10);
405 rcp
->denymodes
=strtoul(dbgetvalue(pgres
,4),NULL
,10);
406 rcp
->limit
=strtoul(dbgetvalue(pgres
,5),NULL
,10);
407 rcp
->autolimit
=strtoul(dbgetvalue(pgres
,6),NULL
,10);
408 rcp
->banstyle
=strtoul(dbgetvalue(pgres
,7),NULL
,10);
409 rcp
->created
=strtoul(dbgetvalue(pgres
,8),NULL
,10);
410 rcp
->lastactive
=strtoul(dbgetvalue(pgres
,9),NULL
,10);
411 rcp
->statsreset
=strtoul(dbgetvalue(pgres
,10),NULL
,10);
412 rcp
->banduration
=strtoul(dbgetvalue(pgres
,11),NULL
,10);
413 rcp
->founder
=strtol(dbgetvalue(pgres
,12),NULL
,10);
414 rcp
->addedby
=strtol(dbgetvalue(pgres
,13),NULL
,10);
415 rcp
->suspendby
=strtol(dbgetvalue(pgres
,14),NULL
,10);
416 rcp
->suspendtime
=strtol(dbgetvalue(pgres
,15),NULL
,10);
417 rcp
->chantype
=strtoul(dbgetvalue(pgres
,16),NULL
,10);
418 rcp
->totaljoins
=strtoul(dbgetvalue(pgres
,17),NULL
,10);
419 rcp
->tripjoins
=strtoul(dbgetvalue(pgres
,18),NULL
,10);
420 rcp
->maxusers
=strtoul(dbgetvalue(pgres
,19),NULL
,10);
421 rcp
->tripusers
=strtoul(dbgetvalue(pgres
,20),NULL
,10);
422 rcp
->welcome
=getsstring(dbgetvalue(pgres
,21),500);
423 rcp
->topic
=getsstring(dbgetvalue(pgres
,22),TOPICLEN
);
424 rcp
->key
=getsstring(dbgetvalue(pgres
,23),KEYLEN
);
425 rcp
->suspendreason
=getsstring(dbgetvalue(pgres
,24),250);
426 rcp
->comment
=getsstring(dbgetvalue(pgres
,25),250);
427 rcp
->checksched
=NULL
;
428 rcp
->ltimestamp
=strtoul(dbgetvalue(pgres
,26),NULL
,10);
429 memset(rcp
->regusers
,0,REGCHANUSERHASHSIZE
*sizeof(reguser
*));
431 if (rcp
->ID
> lastchannelID
)
432 lastchannelID
=rcp
->ID
;
434 if (CIsAutoLimit(rcp
))
437 for (j
=0;j
<CHANOPHISTORY
;j
++) {
438 rcp
->chanopnicks
[j
][0]='\0';
439 rcp
->chanopaccts
[j
]=0;
447 void loadchannelsdone(DBConn
*dbconn
, void *arg
) {
448 Error("chanserv",ERR_INFO
,"Channel load done (highest ID was %d)",lastchannelID
);
451 void loadchanusersinit(DBConn
*dbconn
, void *arg
) {
456 allchans
=(regchan
**)malloc((lastchannelID
+1)*sizeof(regchan
*));
457 memset(allchans
,0,(lastchannelID
+1)*sizeof(regchan
*));
458 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
459 for (cip
=chantable
[i
];cip
;cip
=cip
->next
) {
460 if (cip
->exts
[chanservext
]) {
461 rcp
=(regchan
*)cip
->exts
[chanservext
];
462 allchans
[rcp
->ID
]=rcp
;
468 void loadsomechanusers(DBConn
*dbconn
, void *arg
) {
477 /* Set up the allchans array */
478 pgres
=dbgetresult(dbconn
);
480 if (!dbquerysuccessful(pgres
)) {
481 Error("chanserv",ERR_ERROR
,"Error loading chanusers.");
485 if (dbnumfields(pgres
)!=6) {
486 Error("chanserv",ERR_ERROR
,"Chanusers format error");
490 while(dbfetchrow(pgres
)) {
491 uid
=strtol(dbgetvalue(pgres
,0),NULL
,10);
492 cid
=strtol(dbgetvalue(pgres
,1),NULL
,10);
494 if (!(anp
=findauthname(uid
)) || !(rup
=anp
->exts
[chanservaext
])) {
495 Error("chanserv",ERR_WARNING
,"Skipping channeluser for unknown user %d",uid
);
499 if (cid
>lastchannelID
|| !(rcp
=allchans
[cid
])) {
500 Error("chanserv",ERR_WARNING
,"Skipping channeluser for unknown chan %d",cid
);
504 if (rup
==NULL
|| rcp
==NULL
) {
505 Error("chanserv",ERR_ERROR
,"Can't add user %s on channel %s",
506 dbgetvalue(pgres
,0),dbgetvalue(pgres
,1));
508 rcup
=getregchanuser();
511 rcup
->flags
=strtol(dbgetvalue(pgres
,2),NULL
,10);
512 rcup
->changetime
=strtol(dbgetvalue(pgres
,3),NULL
,10);
513 rcup
->usetime
=strtol(dbgetvalue(pgres
,4),NULL
,10);
514 rcup
->info
=getsstring(dbgetvalue(pgres
,5),100);
515 addregusertochannel(rcup
);
523 void loadchanusersdone(DBConn
*dbconn
, void *arg
) {
524 Error("chanserv",ERR_INFO
,"Channel user load done.");
527 void loadsomechanbans(DBConn
*dbconn
, void *arg
) {
535 pgres
=dbgetresult(dbconn
);
537 if (!dbquerysuccessful(pgres
)) {
538 Error("chanserv",ERR_ERROR
,"Error loading bans.");
542 if (dbnumfields(pgres
)!=6) {
543 Error("chanserv",ERR_ERROR
,"Ban format error");
549 while(dbfetchrow(pgres
)) {
550 bid
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
551 cid
=strtoul(dbgetvalue(pgres
,1),NULL
,10);
552 uid
=strtoul(dbgetvalue(pgres
,2),NULL
,10);
553 expiry
=strtoul(dbgetvalue(pgres
,4),NULL
,10);
555 if (cid
>lastchannelID
|| !(rcp
=allchans
[cid
])) {
556 Error("chanserv",ERR_WARNING
,"Skipping ban for unknown chan %d",cid
);
564 rbp
->reason
=getsstring(dbgetvalue(pgres
,5),200);
565 rbp
->cbp
=makeban(dbgetvalue(pgres
,3));
578 void loadchanbansdone(DBConn
*dbconn
, void *arg
) {
581 Error("chanserv",ERR_INFO
,"Channel ban load done, highest ID was %d",lastbanID
);
584 triggerhook(HOOK_CHANSERV_DBLOADED
, NULL
);
587 void loadmessages() {
588 dbasyncquery(loadmessages_part1
, NULL
, "SELECT * from chanserv.languages");
591 void loadmessages_part1(DBConn
*dbconn
, void *arg
) {
595 /* Firstly, clear up any stale messages */
596 for (i
=0;i
<MAXLANG
;i
++) {
597 if (cslanguages
[i
]) {
598 freesstring(cslanguages
[i
]->name
);
599 free(cslanguages
[i
]);
601 for (j
=0;j
<MAXMESSAGES
;j
++) {
602 if (csmessages
[i
][j
]) {
603 freesstring(csmessages
[i
][j
]);
604 csmessages
[i
][j
]=NULL
;
609 pgres
=dbgetresult(dbconn
);
611 if (!dbquerysuccessful(pgres
)) {
612 Error("chanserv",ERR_ERROR
,"Error loading language list.");
616 if (dbnumfields(pgres
)!=3) {
617 Error("chanserv",ERR_ERROR
,"Language list format error.");
621 while(dbfetchrow(pgres
)) {
622 j
=strtol(dbgetvalue(pgres
,0),NULL
,10);
623 if (j
<MAXLANG
&& j
>=0) {
624 cslanguages
[j
]=(cslang
*)malloc(sizeof(cslang
));
626 strncpy(cslanguages
[j
]->code
,dbgetvalue(pgres
,1),2); cslanguages
[j
]->code
[2]='\0';
627 cslanguages
[j
]->name
=getsstring(dbgetvalue(pgres
,2),30);
634 Error("chanserv",ERR_ERROR
,"Found too many languages (%d > %d)",i
,MAXLANG
);
636 dbasyncquery(loadmessages_part2
, NULL
, "SELECT * from chanserv.messages");
639 void loadmessages_part2(DBConn
*dbconn
, void *arg
) {
643 pgres
=dbgetresult(dbconn
);
645 if (!dbquerysuccessful(pgres
)) {
646 Error("chanserv",ERR_ERROR
,"Error loading message list.");
650 if (dbnumfields(pgres
)!=3) {
651 Error("chanserv",ERR_ERROR
,"Message list format error.");
655 while(dbfetchrow(pgres
)) {
656 k
=strtol(dbgetvalue(pgres
,0),NULL
,10);
657 j
=strtol(dbgetvalue(pgres
,1),NULL
,10);
659 if (k
<0 || k
>= MAXLANG
) {
660 Error("chanserv",ERR_WARNING
,"Language ID out of range on message: %d",k
);
664 if (j
<0 || j
>= MAXMESSAGES
) {
665 Error("chanserv",ERR_WARNING
,"Message ID out of range on message: %d",j
);
669 csmessages
[k
][j
]=getsstring(dbgetvalue(pgres
,2),250);
675 void loadcommandsummary(Command
*cmd
) {
676 dbasyncquery(loadcommandsummary_real
, (void *)cmd
,
677 "SELECT languageID,summary from chanserv.help where lower(command) = lower('%s')",cmd
->command
->content
);
680 void loadcommandsummary_real(DBConn
*dbconn
, void *arg
) {
686 /* Clear up old text first */
688 for (i
=0;i
<MAXLANG
;i
++) {
690 freesstring(cs
->bylang
[i
]);
693 pgres
=dbgetresult(dbconn
);
695 if (!dbquerysuccessful(pgres
)) {
696 Error("chanserv",ERR_ERROR
,"Error loading command summary.");
700 if (dbnumfields(pgres
)!=2) {
701 Error("chanserv",ERR_ERROR
,"Command summary format error.");
706 while(dbfetchrow(pgres
)) {
707 j
=strtol(dbgetvalue(pgres
,0),NULL
,10);
708 if (j
<MAXLANG
&& j
>=0) {
709 cs
->bylang
[j
]=getsstring(dbgetvalue(pgres
,1),200);
716 void csdb_freestuff() {
718 chanindex
*cip
, *ncip
;
724 maillock
*mlp
, *nmlp
;
726 for (i
=0;i
<REGUSERHASHSIZE
;i
++) {
727 for (rup
=regusernicktable
[i
];rup
;rup
=rup
->nextbyname
) {
728 freesstring(rup
->email
);
729 freesstring(rup
->localpart
);
730 freesstring(rup
->lastemail
);
731 freesstring(rup
->lastuserhost
);
732 freesstring(rup
->suspendreason
);
733 freesstring(rup
->comment
);
734 freesstring(rup
->info
);
736 for (rcup
=rup
->knownon
;rcup
;rcup
=rcup
->nextbyuser
)
737 freesstring(rcup
->info
);
741 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
742 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
744 if ((rcp
=cip
->exts
[chanservext
])) {
745 freesstring(rcp
->welcome
);
746 freesstring(rcp
->topic
);
747 freesstring(rcp
->key
);
748 freesstring(rcp
->suspendreason
);
749 freesstring(rcp
->comment
);
750 for (rbp
=rcp
->bans
;rbp
;rbp
=rbp
->next
) {
751 freesstring(rbp
->reason
);
752 freechanban(rbp
->cbp
);
754 cip
->exts
[chanservext
]=NULL
;
755 releasechanindex(cip
);
760 for (i
=0; i
<MAILDOMAINHASHSIZE
; i
++) {
761 for (mdp
=maildomainnametable
[i
]; mdp
; mdp
=mdp
->nextbyname
)
762 freesstring(mdp
->name
);
765 for(mlp
=maillocks
;mlp
;mlp
=nmlp
) {
772 void loadsomemaildomains(DBConn
*dbconn
,void *arg
) {
776 pgres
=dbgetresult(dbconn
);
778 if (!dbquerysuccessful(pgres
)) {
779 Error("chanserv",ERR_ERROR
,"Error loading maildomain DB");
783 if (dbnumfields(pgres
)!=5) {
784 Error("chanserv",ERR_ERROR
,"Mail Domain DB format error");
790 while(dbfetchrow(pgres
)) {
791 domain
=dbgetvalue(pgres
,1);
792 mdp
=findorcreatemaildomain(domain
); //@@@ LEN
794 mdp
->ID
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
795 mdp
->limit
=strtoul(dbgetvalue(pgres
,2),NULL
,10);
796 mdp
->actlimit
=strtoul(dbgetvalue(pgres
,3),NULL
,10);
797 mdp
->flags
=strtoul(dbgetvalue(pgres
,4),NULL
,10);
799 if (mdp
->ID
> lastdomainID
) {
800 lastdomainID
=mdp
->ID
;
807 void loadmaildomainsdone(DBConn
*dbconn
, void *arg
) {
808 Error("chanserv",ERR_INFO
,"Load Mail Domains done (highest ID was %d)",lastdomainID
);
811 void loadsomemaillocks(DBConn
*dbconn
,void *arg
) {
814 pgres
=dbgetresult(dbconn
);
816 if (!dbquerysuccessful(pgres
)) {
817 Error("chanserv",ERR_ERROR
,"Error loading maillock DB");
821 if (dbnumfields(pgres
)!=5) {
822 Error("chanserv",ERR_ERROR
,"Maillock DB format error");
828 while(dbfetchrow(pgres
)) {
830 mlp
->id
=strtoul(dbgetvalue(pgres
,0),NULL
,10);
831 mlp
->pattern
=getsstring(dbgetvalue(pgres
,1), 300);
832 mlp
->reason
=getsstring(dbgetvalue(pgres
,2), 300);
833 mlp
->createdby
=strtoul(dbgetvalue(pgres
,3),NULL
,10);
834 mlp
->created
=strtoul(dbgetvalue(pgres
,4),NULL
,10);
838 if (mlp
->id
> lastmaillockID
)
839 lastmaillockID
=mlp
->id
;
845 void loadmaillocksdone(DBConn
*dbconn
, void *arg
) {
846 Error("chanserv",ERR_INFO
,"Load Mail Locks done (highest ID was %d)",lastmaillockID
);