]>
Commit | Line | Data |
---|---|---|
b263aa79 | 1 | /* |
2 | * chanservdb_updates.c: | |
3 | * Handle all the update requests for the database. | |
4 | */ | |
5 | ||
183b8e2f | 6 | #include "chanserv.h" |
ee8cd7d0 | 7 | #include "../dbapi/dbapi.h" |
183b8e2f P |
8 | #include "../core/config.h" |
9 | #include "../lib/sstring.h" | |
10 | #include "../parser/parser.h" | |
11 | #include "../core/events.h" | |
b263aa79 | 12 | |
13 | #include <string.h> | |
b263aa79 | 14 | #include <stdio.h> |
15 | #include <sys/poll.h> | |
16 | #include <stdarg.h> | |
ea4a0a50 | 17 | #include <assert.h> |
b263aa79 | 18 | |
19 | void csdb_updateauthinfo(reguser *rup) { | |
80d2de64 | 20 | char eschost[2*HOSTLEN+1]; |
b263aa79 | 21 | |
ee8cd7d0 CP |
22 | dbescapestring(eschost,rup->lastuserhost->content,rup->lastuserhost->length); |
23 | dbquery("UPDATE chanserv.users SET lastauth=%lu,lastuserhost='%s' WHERE ID=%u", | |
b263aa79 | 24 | rup->lastauth,eschost,rup->ID); |
25 | } | |
26 | ||
27 | void csdb_updatelastjoin(regchanuser *rcup) { | |
ee8cd7d0 | 28 | dbquery("UPDATE chanserv.chanusers SET usetime=%lu WHERE userID=%u and channelID=%u", |
b263aa79 | 29 | rcup->usetime, rcup->user->ID, rcup->chan->ID); |
30 | } | |
31 | ||
32 | void csdb_updatetopic(regchan *rcp) { | |
33 | char esctopic[TOPICLEN*2+5]; | |
34 | ||
35 | if (rcp->topic) { | |
ee8cd7d0 | 36 | dbescapestring(esctopic,rcp->topic->content,rcp->topic->length); |
b263aa79 | 37 | } else { |
38 | esctopic[0]='\0'; | |
39 | } | |
ee8cd7d0 | 40 | dbquery("UPDATE chanserv.channels SET topic='%s' WHERE ID=%u",esctopic,rcp->ID); |
b263aa79 | 41 | } |
42 | ||
43 | void csdb_updatechannel(regchan *rcp) { | |
80d2de64 P |
44 | char escwelcome[WELCOMELEN*2+1]; |
45 | char esctopic[TOPICLEN*2+1]; | |
b263aa79 | 46 | char esckey[70]; |
47 | char escreason[510]; | |
48 | char esccomment[510]; | |
49 | char escname[1000]; | |
50 | ||
ee8cd7d0 | 51 | dbescapestring(escname, rcp->index->name->content, rcp->index->name->length); |
b263aa79 | 52 | |
53 | if (rcp->welcome) | |
ee8cd7d0 | 54 | dbescapestring(escwelcome, rcp->welcome->content, |
b263aa79 | 55 | rcp->welcome->length); |
56 | else | |
57 | escwelcome[0]='\0'; | |
58 | ||
59 | if (rcp->topic) | |
ee8cd7d0 | 60 | dbescapestring(esctopic, rcp->topic->content, rcp->topic->length); |
b263aa79 | 61 | else |
62 | esctopic[0]='\0'; | |
63 | ||
64 | if (rcp->key) | |
ee8cd7d0 | 65 | dbescapestring(esckey, rcp->key->content, rcp->key->length); |
b263aa79 | 66 | else |
67 | esckey[0]='\0'; | |
68 | ||
69 | if (rcp->suspendreason) | |
ee8cd7d0 | 70 | dbescapestring(escreason, rcp->suspendreason->content, |
b263aa79 | 71 | rcp->suspendreason->length); |
72 | else | |
73 | escreason[0]='\0'; | |
74 | ||
75 | if (rcp->comment) | |
ee8cd7d0 | 76 | dbescapestring(esccomment, rcp->comment->content, |
b263aa79 | 77 | rcp->comment->length); |
78 | else | |
79 | esccomment[0]='\0'; | |
80 | ||
ee8cd7d0 | 81 | dbquery("UPDATE chanserv.channels SET name='%s', flags=%d, forcemodes=%d," |
b263aa79 | 82 | "denymodes=%d, chanlimit=%d, autolimit=%d, banstyle=%d," |
83 | "lastactive=%lu,statsreset=%lu, banduration=%lu, founder=%u," | |
e086bfee | 84 | "addedby=%u, suspendby=%u, suspendtime=%lu, chantype=%d, totaljoins=%u," |
b263aa79 | 85 | "tripjoins=%u, maxusers=%u, tripusers=%u," |
86 | "welcome='%s', topic='%s', chankey='%s', suspendreason='%s'," | |
16739dbe | 87 | "comment='%s', lasttimestamp=%jd WHERE ID=%u",escname,rcp->flags,rcp->forcemodes, |
b263aa79 | 88 | rcp->denymodes,rcp->limit,rcp->autolimit, rcp->banstyle, |
89 | rcp->lastactive,rcp->statsreset,rcp->banduration, | |
88d191e3 | 90 | rcp->founder, rcp->addedby, rcp->suspendby, rcp->suspendtime, |
b263aa79 | 91 | rcp->chantype,rcp->totaljoins,rcp->tripjoins, |
92 | rcp->maxusers,rcp->tripusers, | |
58a4da4a | 93 | escwelcome,esctopic,esckey,escreason,esccomment,(intmax_t)rcp->ltimestamp,rcp->ID); |
b263aa79 | 94 | } |
95 | ||
7b002e5b CP |
96 | #define CHANNELCOUNTER_BUFSIZE 512 |
97 | #define CHANNELCOUNTER_MAX 512 | |
98 | ||
99 | static int channelcounter_count = 0; | |
100 | static char channelcounter_bufs[CHANNELCOUNTER_MAX][CHANNELCOUNTER_BUFSIZE]; | |
101 | ||
102 | void csdb_flushchannelcounters(void *arg) { | |
103 | int i; | |
104 | ||
105 | if(!channelcounter_count) | |
106 | return; | |
107 | ||
108 | dbquery("BEGIN TRANSACTION;"); | |
109 | ||
110 | for(i=0;i<channelcounter_count;i++) | |
111 | dbquery("%s", channelcounter_bufs[i]); | |
112 | ||
113 | dbquery("COMMIT;"); | |
114 | ||
115 | channelcounter_count = 0; | |
116 | } | |
117 | ||
b263aa79 | 118 | void csdb_updatechannelcounters(regchan *rcp) { |
7b002e5b CP |
119 | if(channelcounter_count == CHANNELCOUNTER_MAX) |
120 | csdb_flushchannelcounters(NULL); | |
121 | ||
122 | snprintf(channelcounter_bufs[channelcounter_count], CHANNELCOUNTER_BUFSIZE - 1, "UPDATE chanserv.channels SET " | |
b263aa79 | 123 | "lastactive=%lu, totaljoins=%u," |
124 | "tripjoins=%u, maxusers=%u, tripusers=%u " | |
125 | "WHERE ID=%u", | |
126 | rcp->lastactive, | |
127 | rcp->totaljoins,rcp->tripjoins, | |
128 | rcp->maxusers,rcp->tripusers, | |
129 | rcp->ID); | |
7b002e5b CP |
130 | |
131 | channelcounter_count++; | |
b263aa79 | 132 | } |
133 | ||
134 | void csdb_updatechanneltimestamp(regchan *rcp) { | |
ee8cd7d0 | 135 | dbquery("UPDATE chanserv.channels SET " |
16739dbe | 136 | "lasttimestamp=%jd WHERE ID=%u", |
58a4da4a | 137 | (intmax_t)rcp->ltimestamp, rcp->ID); |
b263aa79 | 138 | } |
139 | ||
140 | void csdb_createchannel(regchan *rcp) { | |
80d2de64 P |
141 | char escwelcome[WELCOMELEN*2+1]; |
142 | char esctopic[TOPICLEN*2+1]; | |
b263aa79 | 143 | char esckey[70]; |
144 | char escreason[510]; | |
145 | char esccomment[510]; | |
146 | char escname[510]; | |
147 | ||
ee8cd7d0 | 148 | dbescapestring(escname, rcp->index->name->content, rcp->index->name->length); |
b263aa79 | 149 | |
150 | if (rcp->welcome) | |
ee8cd7d0 | 151 | dbescapestring(escwelcome, rcp->welcome->content, |
b263aa79 | 152 | rcp->welcome->length); |
153 | else | |
154 | escwelcome[0]='\0'; | |
155 | ||
156 | if (rcp->topic) | |
ee8cd7d0 | 157 | dbescapestring(esctopic, rcp->topic->content, rcp->topic->length); |
b263aa79 | 158 | else |
159 | esctopic[0]='\0'; | |
160 | ||
161 | if (rcp->key) | |
ee8cd7d0 | 162 | dbescapestring(esckey, rcp->key->content, rcp->key->length); |
b263aa79 | 163 | else |
164 | esckey[0]='\0'; | |
165 | ||
166 | if (rcp->suspendreason) | |
ee8cd7d0 | 167 | dbescapestring(escreason, rcp->suspendreason->content, |
b263aa79 | 168 | rcp->suspendreason->length); |
169 | else | |
170 | escreason[0]='\0'; | |
171 | ||
172 | if (rcp->comment) | |
ee8cd7d0 | 173 | dbescapestring(esccomment, rcp->comment->content, |
b263aa79 | 174 | rcp->comment->length); |
175 | else | |
176 | esccomment[0]='\0'; | |
177 | ||
ee8cd7d0 | 178 | dbquery("INSERT INTO chanserv.channels (ID, name, flags, forcemodes, denymodes," |
b263aa79 | 179 | "chanlimit, autolimit, banstyle, created, lastactive, statsreset, " |
88d191e3 | 180 | "banduration, founder, addedby, suspendby, suspendtime, chantype, totaljoins, tripjoins," |
b263aa79 | 181 | "maxusers, tripusers, welcome, topic, chankey, suspendreason, " |
182 | "comment, lasttimestamp) VALUES (%u,'%s',%d,%d,%d,%d,%d,%d,%lu,%lu,%lu,%lu,%u," | |
16739dbe | 183 | "%u,%u,%lu,%d,%u,%u,%u,%u,'%s','%s','%s','%s','%s',%jd)", |
b263aa79 | 184 | rcp->ID, escname, rcp->flags,rcp->forcemodes, |
185 | rcp->denymodes,rcp->limit,rcp->autolimit, rcp->banstyle, rcp->created, | |
186 | rcp->lastactive,rcp->statsreset,rcp->banduration, | |
88d191e3 | 187 | rcp->founder, rcp->addedby, rcp->suspendby, rcp->suspendtime, |
b263aa79 | 188 | rcp->chantype,rcp->totaljoins,rcp->tripjoins, |
189 | rcp->maxusers,rcp->tripusers, | |
58a4da4a | 190 | escwelcome,esctopic,esckey,escreason,esccomment,(intmax_t)rcp->ltimestamp); |
b263aa79 | 191 | } |
192 | ||
193 | void csdb_deletechannel(regchan *rcp) { | |
ee8cd7d0 CP |
194 | dbquery("DELETE FROM chanserv.channels WHERE ID=%u",rcp->ID); |
195 | dbquery("DELETE FROM chanserv.chanusers WHERE channelID=%u",rcp->ID); | |
196 | dbquery("DELETE FROM chanserv.bans WHERE channelID=%u",rcp->ID); | |
b263aa79 | 197 | } |
198 | ||
199 | void csdb_deleteuser(reguser *rup) { | |
ee8cd7d0 CP |
200 | dbquery("DELETE FROM chanserv.users WHERE ID=%u",rup->ID); |
201 | dbquery("DELETE FROM chanserv.chanusers WHERE userID=%u",rup->ID); | |
b263aa79 | 202 | } |
203 | ||
204 | void csdb_updateuser(reguser *rup) { | |
205 | char escpassword[25]; | |
b263aa79 | 206 | char escemail[210]; |
207 | char esclastuserhost[160]; | |
208 | char escreason[510]; | |
209 | char esccomment[510]; | |
210 | char escinfo[210]; | |
9708f78f CP |
211 | char esclastemail[210]; |
212 | ||
ee8cd7d0 | 213 | dbescapestring(escpassword, rup->password, strlen(rup->password)); |
b263aa79 | 214 | |
215 | if (rup->email) | |
ee8cd7d0 | 216 | dbescapestring(escemail, rup->email->content, rup->email->length); |
b263aa79 | 217 | else |
218 | escemail[0]='\0'; | |
219 | ||
9708f78f | 220 | if (rup->lastemail) |
ee8cd7d0 | 221 | dbescapestring(esclastemail, rup->lastemail->content, rup->lastemail->length); |
9708f78f CP |
222 | else |
223 | esclastemail[0]='\0'; | |
224 | ||
b263aa79 | 225 | if (rup->lastuserhost) |
ee8cd7d0 | 226 | dbescapestring(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length); |
b263aa79 | 227 | else |
228 | esclastuserhost[0]='\0'; | |
229 | ||
230 | if (rup->suspendreason) | |
ee8cd7d0 | 231 | dbescapestring(escreason, rup->suspendreason->content, rup->suspendreason->length); |
b263aa79 | 232 | else |
233 | escreason[0]='\0'; | |
234 | ||
235 | if (rup->comment) | |
ee8cd7d0 | 236 | dbescapestring(esccomment, rup->comment->content, rup->comment->length); |
b263aa79 | 237 | else |
238 | esccomment[0]='\0'; | |
239 | ||
240 | if (rup->info) | |
ee8cd7d0 | 241 | dbescapestring(escinfo, rup->info->content, rup->info->length); |
b263aa79 | 242 | else |
243 | escinfo[0]='\0'; | |
244 | ||
ee8cd7d0 | 245 | dbquery("UPDATE chanserv.users SET lastauth=%lu, lastemailchng=%lu, flags=%u," |
b438f642 | 246 | "language=%u, suspendby=%u, suspendexp=%lu, suspendtime=%lu, lockuntil=%lu, password='%s', email='%s'," |
86d2bc73 CP |
247 | "lastuserhost='%s', suspendreason='%s', comment='%s', info='%s', lastemail='%s', lastpasschng=%lu " |
248 | " WHERE ID=%u", | |
b263aa79 | 249 | rup->lastauth, rup->lastemailchange, rup->flags, rup->languageid, rup->suspendby, rup->suspendexp, |
9708f78f | 250 | rup->suspendtime, rup->lockuntil, escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail, |
86d2bc73 | 251 | rup->lastpasschange, |
b263aa79 | 252 | rup->ID); |
253 | } | |
254 | ||
255 | void csdb_createuser(reguser *rup) { | |
256 | char escpassword[25]; | |
b263aa79 | 257 | char escemail[210]; |
258 | char esclastuserhost[160]; | |
259 | char escreason[510]; | |
260 | char esccomment[510]; | |
261 | char escusername[35]; | |
262 | char escinfo[210]; | |
9708f78f | 263 | char esclastemail[210]; |
b263aa79 | 264 | |
ee8cd7d0 CP |
265 | dbescapestring(escusername, rup->username, strlen(rup->username)); |
266 | dbescapestring(escpassword, rup->password, strlen(rup->password)); | |
b263aa79 | 267 | |
268 | if (rup->email) | |
ee8cd7d0 | 269 | dbescapestring(escemail, rup->email->content, rup->email->length); |
b263aa79 | 270 | else |
271 | escemail[0]='\0'; | |
272 | ||
9708f78f | 273 | if (rup->lastemail) |
ee8cd7d0 | 274 | dbescapestring(esclastemail, rup->lastemail->content, rup->lastemail->length); |
9708f78f CP |
275 | else |
276 | esclastemail[0]='\0'; | |
277 | ||
b263aa79 | 278 | if (rup->lastuserhost) |
ee8cd7d0 | 279 | dbescapestring(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length); |
b263aa79 | 280 | else |
281 | esclastuserhost[0]='\0'; | |
282 | ||
283 | if (rup->suspendreason) | |
ee8cd7d0 | 284 | dbescapestring(escreason, rup->suspendreason->content, rup->suspendreason->length); |
b263aa79 | 285 | else |
286 | escreason[0]='\0'; | |
287 | ||
288 | if (rup->comment) | |
ee8cd7d0 | 289 | dbescapestring(esccomment, rup->comment->content, rup->comment->length); |
b263aa79 | 290 | else |
291 | esccomment[0]='\0'; | |
292 | ||
293 | if (rup->info) | |
ee8cd7d0 | 294 | dbescapestring(escinfo, rup->info->content, rup->info->length); |
b263aa79 | 295 | else |
296 | escinfo[0]='\0'; | |
297 | ||
ee8cd7d0 | 298 | dbquery("INSERT INTO chanserv.users (ID, username, created, lastauth, lastemailchng, " |
b438f642 | 299 | "flags, language, suspendby, suspendexp, suspendtime, lockuntil, password, email, lastuserhost, " |
86d2bc73 CP |
300 | "suspendreason, comment, info, lastemail, lastpasschng)" |
301 | "VALUES (%u,'%s',%lu,%lu,%lu,%u,%u,%u,%lu,%lu,%lu,'%s','%s','%s','%s','%s','%s','%s',%lu)", | |
b263aa79 | 302 | rup->ID, escusername, rup->created, rup->lastauth, rup->lastemailchange, rup->flags, |
b438f642 | 303 | rup->languageid, rup->suspendby, rup->suspendexp, rup->suspendtime, rup->lockuntil, |
86d2bc73 CP |
304 | escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail, |
305 | rup->lastpasschange); | |
b263aa79 | 306 | } |
307 | ||
308 | ||
309 | void csdb_updatechanuser(regchanuser *rcup) { | |
310 | char escinfo[210]; | |
311 | ||
312 | if (rcup->info) | |
ee8cd7d0 | 313 | dbescapestring(escinfo, rcup->info->content, rcup->info->length); |
b263aa79 | 314 | else |
315 | escinfo[0]='\0'; | |
316 | ||
ee8cd7d0 | 317 | dbquery("UPDATE chanserv.chanusers SET flags=%u, changetime=%lu, " |
b263aa79 | 318 | "usetime=%lu, info='%s' WHERE channelID=%u and userID=%u", |
319 | rcup->flags, rcup->changetime, rcup->usetime, escinfo, rcup->chan->ID,rcup->user->ID); | |
320 | } | |
321 | ||
322 | void csdb_createchanuser(regchanuser *rcup) { | |
323 | char escinfo[210]; | |
324 | ||
325 | if (rcup->info) | |
ee8cd7d0 | 326 | dbescapestring(escinfo, rcup->info->content, rcup->info->length); |
b263aa79 | 327 | else |
328 | escinfo[0]='\0'; | |
329 | ||
ee8cd7d0 | 330 | dbquery("INSERT INTO chanserv.chanusers VALUES(%u, %u, %u, %lu, %lu, '%s')", |
b263aa79 | 331 | rcup->user->ID, rcup->chan->ID, rcup->flags, rcup->changetime, |
332 | rcup->usetime, escinfo); | |
333 | } | |
334 | ||
335 | void csdb_deletechanuser(regchanuser *rcup) { | |
ee8cd7d0 | 336 | dbquery("DELETE FROM chanserv.chanusers WHERE channelid=%u AND userID=%u", |
b263aa79 | 337 | rcup->chan->ID, rcup->user->ID); |
338 | } | |
339 | ||
340 | void csdb_createban(regchan *rcp, regban *rbp) { | |
341 | char escreason[500]; | |
342 | char banstr[100]; | |
343 | char escban[200]; | |
344 | ||
345 | strcpy(banstr,bantostring(rbp->cbp)); | |
ee8cd7d0 | 346 | dbescapestring(escban,banstr,strlen(banstr)); |
b263aa79 | 347 | |
348 | if (rbp->reason) | |
ee8cd7d0 | 349 | dbescapestring(escreason, rbp->reason->content, rbp->reason->length); |
b263aa79 | 350 | else |
351 | escreason[0]='\0'; | |
352 | ||
ee8cd7d0 | 353 | dbquery("INSERT INTO chanserv.bans (banID, channelID, userID, hostmask, " |
b263aa79 | 354 | "expiry, reason) VALUES (%u,%u,%u,'%s',%lu,'%s')", rbp->ID, rcp->ID, |
355 | rbp->setby, escban, rbp->expiry, escreason); | |
356 | } | |
357 | ||
3fbc2554 CP |
358 | void csdb_updateban(regchan *rcp, regban *rbp) { |
359 | char escreason[500]; | |
360 | char banstr[100]; | |
361 | char escban[200]; | |
362 | ||
363 | strcpy(banstr,bantostring(rbp->cbp)); | |
ee8cd7d0 | 364 | dbescapestring(escban,banstr,strlen(banstr)); |
3fbc2554 CP |
365 | |
366 | if (rbp->reason) | |
ee8cd7d0 | 367 | dbescapestring(escreason, rbp->reason->content, rbp->reason->length); |
3fbc2554 CP |
368 | else |
369 | escreason[0]='\0'; | |
370 | ||
ee8cd7d0 | 371 | dbquery("UPDATE chanserv.bans set channelID=%u, userID=%u, hostmask='%s', expiry=%lu, reason='%s' " |
3fbc2554 CP |
372 | "WHERE banID=%u", rcp->ID, rbp->setby, escban, rbp->expiry, escreason, rbp->ID); |
373 | } | |
374 | ||
b263aa79 | 375 | void csdb_deleteban(regban *rbp) { |
ee8cd7d0 | 376 | dbquery("DELETE FROM chanserv.bans WHERE banID=%u", rbp->ID); |
b263aa79 | 377 | } |
378 | ||
379 | void csdb_createmail(reguser *rup, int type) { | |
380 | char sqlquery[6000]; | |
381 | char escemail[210]; | |
382 | ||
383 | if (type == QMAIL_NEWEMAIL) { | |
384 | if (rup->email) { | |
ee8cd7d0 | 385 | dbescapestring(escemail, rup->email->content, rup->email->length); |
522e2b8c | 386 | sprintf(sqlquery, "INSERT INTO chanserv.email (userID, emailType, prevEmail) " |
b263aa79 | 387 | "VALUES (%u,%u,'%s')", rup->ID, type, escemail); |
388 | } | |
389 | } else { | |
522e2b8c | 390 | sprintf(sqlquery, "INSERT INTO chanserv.email (userID, emailType) VALUES (%u,%u)", rup->ID, type); |
b263aa79 | 391 | } |
392 | ||
ee8cd7d0 | 393 | dbquery("%s", sqlquery); |
183b8e2f P |
394 | } |
395 | ||
396 | void csdb_deletemaildomain(maildomain *mdp) { | |
ee8cd7d0 | 397 | dbquery("DELETE FROM chanserv.maildomain WHERE ID=%u", mdp->ID); |
183b8e2f P |
398 | } |
399 | ||
400 | void csdb_createmaildomain(maildomain *mdp) { | |
401 | char escdomain[210]; | |
ee8cd7d0 | 402 | dbescapestring(escdomain, mdp->name->content, mdp->name->length); |
183b8e2f | 403 | |
ee8cd7d0 | 404 | dbquery("INSERT INTO chanserv.maildomain (id, name, domainlimit, actlimit, flags) VALUES(%u, '%s', %u, %u, %u)", mdp->ID,escdomain,mdp->limit,mdp->actlimit,mdp->flags); |
183b8e2f P |
405 | } |
406 | ||
407 | void csdb_updatemaildomain(maildomain *mdp) { | |
408 | char escdomain[210]; | |
ee8cd7d0 | 409 | dbescapestring(escdomain, mdp->name->content, mdp->name->length); |
183b8e2f | 410 | |
ee8cd7d0 | 411 | dbquery("UPDATE chanserv.maildomain SET domainlimit=%u, actlimit=%u, flags=%u, name='%s' WHERE ID=%u", mdp->limit,mdp->actlimit,mdp->flags,escdomain,mdp->ID); |
183b8e2f P |
412 | } |
413 | ||
183b8e2f P |
414 | void csdb_chanlevhistory_insert(regchan *rcp, nick *np, reguser *trup, flag_t oldflags, flag_t newflags) { |
415 | reguser *rup=getreguserfromnick(np); | |
ea4a0a50 | 416 | assert(rup != NULL); |
183b8e2f | 417 | |
ee8cd7d0 | 418 | dbquery("INSERT INTO chanserv.chanlevhistory (userID, channelID, targetID, changetime, authtime, " |
183b8e2f P |
419 | "oldflags, newflags) VALUES (%u, %u, %u, %lu, %lu, %u, %u)", rup->ID, rcp->ID, trup->ID, getnettime(), np->accountts, |
420 | oldflags, newflags); | |
421 | } | |
422 | ||
0f32b411 | 423 | void csdb_accounthistory_insert(nick *np, char *oldpass, char *newpass, char *oldemail, char *newemail) { |
183b8e2f | 424 | reguser *rup=getreguserfromnick(np); |
5f4ba446 CP |
425 | char escoldpass[PASSLEN*2+5]; |
426 | char escnewpass[PASSLEN*2+5]; | |
427 | char escoldemail[EMAILLEN*2+5]; | |
428 | char escnewemail[EMAILLEN*2+5]; | |
183b8e2f P |
429 | |
430 | if (!rup || UHasOperPriv(rup)) | |
431 | return; | |
432 | ||
433 | if (oldpass) | |
5f4ba446 | 434 | dbescapestring(escoldpass, oldpass, CSMIN(strlen(oldpass), PASSLEN)); |
183b8e2f P |
435 | else |
436 | escoldpass[0]='\0'; | |
437 | ||
438 | if (newpass) | |
5f4ba446 | 439 | dbescapestring(escnewpass, newpass, CSMIN(strlen(newpass), PASSLEN)); |
183b8e2f P |
440 | else |
441 | escnewpass[0]='\0'; | |
442 | ||
443 | if (oldemail) | |
5f4ba446 | 444 | dbescapestring(escoldemail, oldemail, CSMIN(strlen(oldemail), EMAILLEN)); |
183b8e2f P |
445 | else |
446 | escoldemail[0]='\0'; | |
447 | if (newemail) | |
5f4ba446 | 448 | dbescapestring(escnewemail, newemail, CSMIN(strlen(newemail), EMAILLEN)); |
183b8e2f P |
449 | else |
450 | escnewemail[0]='\0'; | |
451 | ||
ee8cd7d0 | 452 | dbquery("INSERT INTO chanserv.accounthistory (userID, changetime, authtime, oldpassword, newpassword, oldemail, " |
183b8e2f P |
453 | "newemail) VALUES (%u, %lu, %lu, '%s', '%s', '%s', '%s')", rup->ID, getnettime(), np->accountts, escoldpass, escnewpass, |
454 | escoldemail, escnewemail); | |
183b8e2f P |
455 | } |
456 | ||
86a73ca1 | 457 | void csdb_cleanuphistories(time_t expire_time) { |
183b8e2f | 458 | Error("chanserv", ERR_INFO, "Cleaning histories."); |
86a73ca1 | 459 | dbquery("DELETE FROM chanserv.authhistory WHERE disconnecttime < %lu AND disconnecttime <> 0", expire_time); |
460 | dbquery("DELETE FROM chanserv.chanlevhistory WHERE authtime < %lu", expire_time); | |
461 | dbquery("DELETE FROM chanserv.accounthistory WHERE authtime < %lu", expire_time); | |
183b8e2f P |
462 | } |
463 | ||
97390b65 | 464 | void csdb_deletemaillock(maillock *mlp) { |
ee8cd7d0 | 465 | dbquery("DELETE FROM chanserv.maillocks WHERE ID=%u", mlp->id); |
97390b65 CP |
466 | } |
467 | ||
468 | void csdb_createmaillock(maillock *mlp) { | |
469 | char escpattern[1024], escreason[1024]; | |
470 | ||
ee8cd7d0 | 471 | dbescapestring(escpattern, mlp->pattern->content, mlp->pattern->length); |
97390b65 CP |
472 | |
473 | if (mlp->reason) | |
ee8cd7d0 | 474 | dbescapestring(escreason, mlp->reason->content, mlp->reason->length); |
97390b65 CP |
475 | else |
476 | escreason[0]='\0'; | |
477 | ||
16739dbe | 478 | dbquery("INSERT INTO chanserv.maillocks (id, pattern, reason, createdby, created) VALUES(%u, '%s', '%s', %u, %jd)", |
58a4da4a | 479 | mlp->id,escpattern,escreason,mlp->createdby,(intmax_t)mlp->created); |
97390b65 CP |
480 | } |
481 | ||
482 | void csdb_updatemaillock(maillock *mlp) { | |
483 | char escpattern[1024], escreason[1024]; | |
484 | ||
ee8cd7d0 | 485 | dbescapestring(escpattern, mlp->pattern->content, mlp->pattern->length); |
97390b65 CP |
486 | |
487 | if (mlp->reason) | |
ee8cd7d0 | 488 | dbescapestring(escreason, mlp->reason->content, mlp->reason->length); |
97390b65 CP |
489 | else |
490 | escreason[0]='\0'; | |
491 | ||
58a4da4a | 492 | dbquery("UPDATE chanserv.maillocks SET pattern='%s', reason='%s', createdby=%u, created=%jd WHERE ID=%u", escpattern, escreason, mlp->createdby, (intmax_t)mlp->created, mlp->id); |
97390b65 CP |
493 | } |
494 |