*/
#include "chanserv.h"
-#include "../pqsql/pqsql.h"
+#include "../dbapi/dbapi.h"
#include "../core/config.h"
#include "../lib/sstring.h"
#include "../parser/parser.h"
#include "../core/events.h"
#include <string.h>
-#include <libpq-fe.h>
#include <stdio.h>
#include <sys/poll.h>
#include <stdarg.h>
+#include <assert.h>
void csdb_updateauthinfo(reguser *rup) {
char eschost[2*HOSTLEN+1];
- PQescapeString(eschost,rup->lastuserhost->content,rup->lastuserhost->length);
- pqquery("UPDATE users SET lastauth=%lu,lastuserhost='%s' WHERE ID=%u",
+ dbescapestring(eschost,rup->lastuserhost->content,rup->lastuserhost->length);
+ dbquery("UPDATE chanserv.users SET lastauth=%lu,lastuserhost='%s' WHERE ID=%u",
rup->lastauth,eschost,rup->ID);
}
void csdb_updatelastjoin(regchanuser *rcup) {
- pqquery("UPDATE chanusers SET usetime=%lu WHERE userID=%u and channelID=%u",
+ dbquery("UPDATE chanserv.chanusers SET usetime=%lu WHERE userID=%u and channelID=%u",
rcup->usetime, rcup->user->ID, rcup->chan->ID);
}
char esctopic[TOPICLEN*2+5];
if (rcp->topic) {
- PQescapeString(esctopic,rcp->topic->content,rcp->topic->length);
+ dbescapestring(esctopic,rcp->topic->content,rcp->topic->length);
} else {
esctopic[0]='\0';
}
- pqquery("UPDATE channels SET topic='%s' WHERE ID=%u",esctopic,rcp->ID);
+ dbquery("UPDATE chanserv.channels SET topic='%s' WHERE ID=%u",esctopic,rcp->ID);
}
void csdb_updatechannel(regchan *rcp) {
char esccomment[510];
char escname[1000];
- PQescapeString(escname, rcp->index->name->content, rcp->index->name->length);
+ dbescapestring(escname, rcp->index->name->content, rcp->index->name->length);
if (rcp->welcome)
- PQescapeString(escwelcome, rcp->welcome->content,
+ dbescapestring(escwelcome, rcp->welcome->content,
rcp->welcome->length);
else
escwelcome[0]='\0';
if (rcp->topic)
- PQescapeString(esctopic, rcp->topic->content, rcp->topic->length);
+ dbescapestring(esctopic, rcp->topic->content, rcp->topic->length);
else
esctopic[0]='\0';
if (rcp->key)
- PQescapeString(esckey, rcp->key->content, rcp->key->length);
+ dbescapestring(esckey, rcp->key->content, rcp->key->length);
else
esckey[0]='\0';
if (rcp->suspendreason)
- PQescapeString(escreason, rcp->suspendreason->content,
+ dbescapestring(escreason, rcp->suspendreason->content,
rcp->suspendreason->length);
else
escreason[0]='\0';
if (rcp->comment)
- PQescapeString(esccomment, rcp->comment->content,
+ dbescapestring(esccomment, rcp->comment->content,
rcp->comment->length);
else
esccomment[0]='\0';
- pqquery("UPDATE channels SET name='%s', flags=%d, forcemodes=%d,"
+ dbquery("UPDATE chanserv.channels SET name='%s', flags=%d, forcemodes=%d,"
"denymodes=%d, chanlimit=%d, autolimit=%d, banstyle=%d,"
"lastactive=%lu,statsreset=%lu, banduration=%lu, founder=%u,"
- "addedby=%u, suspendby=%u, chantype=%d, totaljoins=%u,"
+ "addedby=%u, suspendby=%u, suspendtime=%lu, chantype=%d, totaljoins=%u,"
"tripjoins=%u, maxusers=%u, tripusers=%u,"
"welcome='%s', topic='%s', chankey='%s', suspendreason='%s',"
- "comment='%s', lasttimestamp=%d WHERE ID=%u",escname,rcp->flags,rcp->forcemodes,
+ "comment='%s', lasttimestamp=%jd WHERE ID=%u",escname,rcp->flags,rcp->forcemodes,
rcp->denymodes,rcp->limit,rcp->autolimit, rcp->banstyle,
rcp->lastactive,rcp->statsreset,rcp->banduration,
- rcp->founder, rcp->addedby, rcp->suspendby,
+ rcp->founder, rcp->addedby, rcp->suspendby, rcp->suspendtime,
rcp->chantype,rcp->totaljoins,rcp->tripjoins,
rcp->maxusers,rcp->tripusers,
- escwelcome,esctopic,esckey,escreason,esccomment,rcp->ltimestamp,rcp->ID);
+ escwelcome,esctopic,esckey,escreason,esccomment,(intmax_t)rcp->ltimestamp,rcp->ID);
+}
+
+#define CHANNELCOUNTER_BUFSIZE 512
+#define CHANNELCOUNTER_MAX 512
+
+static int channelcounter_count = 0;
+static char channelcounter_bufs[CHANNELCOUNTER_MAX][CHANNELCOUNTER_BUFSIZE];
+
+void csdb_flushchannelcounters(void *arg) {
+ int i;
+
+ if(!channelcounter_count)
+ return;
+
+ dbquery("BEGIN TRANSACTION;");
+
+ for(i=0;i<channelcounter_count;i++)
+ dbquery("%s", channelcounter_bufs[i]);
+
+ dbquery("COMMIT;");
+
+ channelcounter_count = 0;
}
void csdb_updatechannelcounters(regchan *rcp) {
- pqquery("UPDATE channels SET "
+ if(channelcounter_count == CHANNELCOUNTER_MAX)
+ csdb_flushchannelcounters(NULL);
+
+ snprintf(channelcounter_bufs[channelcounter_count], CHANNELCOUNTER_BUFSIZE - 1, "UPDATE chanserv.channels SET "
"lastactive=%lu, totaljoins=%u,"
"tripjoins=%u, maxusers=%u, tripusers=%u "
"WHERE ID=%u",
rcp->totaljoins,rcp->tripjoins,
rcp->maxusers,rcp->tripusers,
rcp->ID);
+
+ channelcounter_count++;
}
void csdb_updatechanneltimestamp(regchan *rcp) {
- pqquery("UPDATE channels SET "
- "lasttimestamp=%u WHERE ID=%u",
- rcp->ltimestamp, rcp->ID);
+ dbquery("UPDATE chanserv.channels SET "
+ "lasttimestamp=%jd WHERE ID=%u",
+ (intmax_t)rcp->ltimestamp, rcp->ID);
}
void csdb_createchannel(regchan *rcp) {
char esccomment[510];
char escname[510];
- PQescapeString(escname, rcp->index->name->content, rcp->index->name->length);
+ dbescapestring(escname, rcp->index->name->content, rcp->index->name->length);
if (rcp->welcome)
- PQescapeString(escwelcome, rcp->welcome->content,
+ dbescapestring(escwelcome, rcp->welcome->content,
rcp->welcome->length);
else
escwelcome[0]='\0';
if (rcp->topic)
- PQescapeString(esctopic, rcp->topic->content, rcp->topic->length);
+ dbescapestring(esctopic, rcp->topic->content, rcp->topic->length);
else
esctopic[0]='\0';
if (rcp->key)
- PQescapeString(esckey, rcp->key->content, rcp->key->length);
+ dbescapestring(esckey, rcp->key->content, rcp->key->length);
else
esckey[0]='\0';
if (rcp->suspendreason)
- PQescapeString(escreason, rcp->suspendreason->content,
+ dbescapestring(escreason, rcp->suspendreason->content,
rcp->suspendreason->length);
else
escreason[0]='\0';
if (rcp->comment)
- PQescapeString(esccomment, rcp->comment->content,
+ dbescapestring(esccomment, rcp->comment->content,
rcp->comment->length);
else
esccomment[0]='\0';
- pqquery("INSERT INTO channels (ID, name, flags, forcemodes, denymodes,"
+ dbquery("INSERT INTO chanserv.channels (ID, name, flags, forcemodes, denymodes,"
"chanlimit, autolimit, banstyle, created, lastactive, statsreset, "
- "banduration, founder, addedby, suspendby, chantype, totaljoins, tripjoins,"
+ "banduration, founder, addedby, suspendby, suspendtime, chantype, totaljoins, tripjoins,"
"maxusers, tripusers, welcome, topic, chankey, suspendreason, "
"comment, lasttimestamp) VALUES (%u,'%s',%d,%d,%d,%d,%d,%d,%lu,%lu,%lu,%lu,%u,"
- "%u,%u,%d,%u,%u,%u,%u,'%s','%s','%s','%s','%s',%d)",
+ "%u,%u,%lu,%d,%u,%u,%u,%u,'%s','%s','%s','%s','%s',%jd)",
rcp->ID, escname, rcp->flags,rcp->forcemodes,
rcp->denymodes,rcp->limit,rcp->autolimit, rcp->banstyle, rcp->created,
rcp->lastactive,rcp->statsreset,rcp->banduration,
- rcp->founder, rcp->addedby, rcp->suspendby,
+ rcp->founder, rcp->addedby, rcp->suspendby, rcp->suspendtime,
rcp->chantype,rcp->totaljoins,rcp->tripjoins,
rcp->maxusers,rcp->tripusers,
- escwelcome,esctopic,esckey,escreason,esccomment,rcp->ltimestamp);
+ escwelcome,esctopic,esckey,escreason,esccomment,(intmax_t)rcp->ltimestamp);
}
void csdb_deletechannel(regchan *rcp) {
- pqquery("DELETE FROM channels WHERE ID=%u",rcp->ID);
- pqquery("DELETE FROM chanusers WHERE channelID=%u",rcp->ID);
- pqquery("DELETE FROM bans WHERE channelID=%u",rcp->ID);
+ dbquery("DELETE FROM chanserv.channels WHERE ID=%u",rcp->ID);
+ dbquery("DELETE FROM chanserv.chanusers WHERE channelID=%u",rcp->ID);
+ dbquery("DELETE FROM chanserv.bans WHERE channelID=%u",rcp->ID);
}
void csdb_deleteuser(reguser *rup) {
- pqquery("DELETE FROM users WHERE ID=%u",rup->ID);
- pqquery("DELETE FROM chanusers WHERE userID=%u",rup->ID);
+ dbquery("DELETE FROM chanserv.users WHERE ID=%u",rup->ID);
+ dbquery("DELETE FROM chanserv.chanusers WHERE userID=%u",rup->ID);
}
void csdb_updateuser(reguser *rup) {
char escreason[510];
char esccomment[510];
char escinfo[210];
-
- PQescapeString(escpassword, rup->password, strlen(rup->password));
+ char esclastemail[210];
+
+ dbescapestring(escpassword, rup->password, strlen(rup->password));
if (rup->email)
- PQescapeString(escemail, rup->email->content, rup->email->length);
+ dbescapestring(escemail, rup->email->content, rup->email->length);
else
escemail[0]='\0';
+ if (rup->lastemail)
+ dbescapestring(esclastemail, rup->lastemail->content, rup->lastemail->length);
+ else
+ esclastemail[0]='\0';
+
if (rup->lastuserhost)
- PQescapeString(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length);
+ dbescapestring(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length);
else
esclastuserhost[0]='\0';
if (rup->suspendreason)
- PQescapeString(escreason, rup->suspendreason->content, rup->suspendreason->length);
+ dbescapestring(escreason, rup->suspendreason->content, rup->suspendreason->length);
else
escreason[0]='\0';
if (rup->comment)
- PQescapeString(esccomment, rup->comment->content, rup->comment->length);
+ dbescapestring(esccomment, rup->comment->content, rup->comment->length);
else
esccomment[0]='\0';
if (rup->info)
- PQescapeString(escinfo, rup->info->content, rup->info->length);
+ dbescapestring(escinfo, rup->info->content, rup->info->length);
else
escinfo[0]='\0';
- pqquery("UPDATE users SET lastauth=%lu, lastemailchng=%lu, flags=%u,"
- "language=%u, suspendby=%u, suspendexp=%lu, password='%s', email='%s',"
- "lastuserhost='%s', suspendreason='%s', comment='%s', info='%s', lockuntil=%lu WHERE ID=%u",
+ dbquery("UPDATE chanserv.users SET lastauth=%lu, lastemailchng=%lu, flags=%u,"
+ "language=%u, suspendby=%u, suspendexp=%lu, suspendtime=%lu, lockuntil=%lu, password='%s', email='%s',"
+ "lastuserhost='%s', suspendreason='%s', comment='%s', info='%s', lastemail='%s', lastpasschng=%lu "
+ " WHERE ID=%u",
rup->lastauth, rup->lastemailchange, rup->flags, rup->languageid, rup->suspendby, rup->suspendexp,
- escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, rup->lockuntil
+ rup->suspendtime, rup->lockuntil, escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail,
+ rup->lastpasschange,
rup->ID);
}
char esccomment[510];
char escusername[35];
char escinfo[210];
+ char esclastemail[210];
- PQescapeString(escusername, rup->username, strlen(rup->username));
- PQescapeString(escpassword, rup->password, strlen(rup->password));
+ dbescapestring(escusername, rup->username, strlen(rup->username));
+ dbescapestring(escpassword, rup->password, strlen(rup->password));
if (rup->email)
- PQescapeString(escemail, rup->email->content, rup->email->length);
+ dbescapestring(escemail, rup->email->content, rup->email->length);
else
escemail[0]='\0';
+ if (rup->lastemail)
+ dbescapestring(esclastemail, rup->lastemail->content, rup->lastemail->length);
+ else
+ esclastemail[0]='\0';
+
if (rup->lastuserhost)
- PQescapeString(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length);
+ dbescapestring(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length);
else
esclastuserhost[0]='\0';
if (rup->suspendreason)
- PQescapeString(escreason, rup->suspendreason->content, rup->suspendreason->length);
+ dbescapestring(escreason, rup->suspendreason->content, rup->suspendreason->length);
else
escreason[0]='\0';
if (rup->comment)
- PQescapeString(esccomment, rup->comment->content, rup->comment->length);
+ dbescapestring(esccomment, rup->comment->content, rup->comment->length);
else
esccomment[0]='\0';
if (rup->info)
- PQescapeString(escinfo, rup->info->content, rup->info->length);
+ dbescapestring(escinfo, rup->info->content, rup->info->length);
else
escinfo[0]='\0';
- pqquery("INSERT INTO users (ID, username, created, lastauth, lastemailchng, "
- "flags, language, suspendby, suspendexp, password, email, lastuserhost, "
- "suspendreason, comment, info, lockuntil) VALUES (%u,'%s',%lu,%lu,%lu,%u,%u,%u,%lu,'%s','%s',"
- "'%s','%s','%s','%s',%lu)",
+ dbquery("INSERT INTO chanserv.users (ID, username, created, lastauth, lastemailchng, "
+ "flags, language, suspendby, suspendexp, suspendtime, lockuntil, password, email, lastuserhost, "
+ "suspendreason, comment, info, lastemail, lastpasschng)"
+ "VALUES (%u,'%s',%lu,%lu,%lu,%u,%u,%u,%lu,%lu,%lu,'%s','%s','%s','%s','%s','%s','%s',%lu)",
rup->ID, escusername, rup->created, rup->lastauth, rup->lastemailchange, rup->flags,
- rup->languageid, rup->suspendby, rup->suspendexp,
- escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, rup->lockuntil);
+ rup->languageid, rup->suspendby, rup->suspendexp, rup->suspendtime, rup->lockuntil,
+ escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail,
+ rup->lastpasschange);
}
char escinfo[210];
if (rcup->info)
- PQescapeString(escinfo, rcup->info->content, rcup->info->length);
+ dbescapestring(escinfo, rcup->info->content, rcup->info->length);
else
escinfo[0]='\0';
- pqquery("UPDATE chanusers SET flags=%u, changetime=%lu, "
+ dbquery("UPDATE chanserv.chanusers SET flags=%u, changetime=%lu, "
"usetime=%lu, info='%s' WHERE channelID=%u and userID=%u",
rcup->flags, rcup->changetime, rcup->usetime, escinfo, rcup->chan->ID,rcup->user->ID);
}
char escinfo[210];
if (rcup->info)
- PQescapeString(escinfo, rcup->info->content, rcup->info->length);
+ dbescapestring(escinfo, rcup->info->content, rcup->info->length);
else
escinfo[0]='\0';
- pqquery("INSERT INTO chanusers VALUES(%u, %u, %u, %lu, %lu, '%s')",
+ dbquery("INSERT INTO chanserv.chanusers VALUES(%u, %u, %u, %lu, %lu, '%s')",
rcup->user->ID, rcup->chan->ID, rcup->flags, rcup->changetime,
rcup->usetime, escinfo);
}
void csdb_deletechanuser(regchanuser *rcup) {
- pqquery("DELETE FROM chanusers WHERE channelid=%u AND userID=%u",
+ dbquery("DELETE FROM chanserv.chanusers WHERE channelid=%u AND userID=%u",
rcup->chan->ID, rcup->user->ID);
}
char escban[200];
strcpy(banstr,bantostring(rbp->cbp));
- PQescapeString(escban,banstr,strlen(banstr));
+ dbescapestring(escban,banstr,strlen(banstr));
if (rbp->reason)
- PQescapeString(escreason, rbp->reason->content, rbp->reason->length);
+ dbescapestring(escreason, rbp->reason->content, rbp->reason->length);
else
escreason[0]='\0';
- pqquery("INSERT INTO bans (banID, channelID, userID, hostmask, "
+ dbquery("INSERT INTO chanserv.bans (banID, channelID, userID, hostmask, "
"expiry, reason) VALUES (%u,%u,%u,'%s',%lu,'%s')", rbp->ID, rcp->ID,
rbp->setby, escban, rbp->expiry, escreason);
}
char escban[200];
strcpy(banstr,bantostring(rbp->cbp));
- PQescapeString(escban,banstr,strlen(banstr));
+ dbescapestring(escban,banstr,strlen(banstr));
if (rbp->reason)
- PQescapeString(escreason, rbp->reason->content, rbp->reason->length);
+ dbescapestring(escreason, rbp->reason->content, rbp->reason->length);
else
escreason[0]='\0';
- pqquery("UPDATE bans set channelID=%u, userID=%u, hostmask='%s', expiry=%lu, reason='%s' "
+ dbquery("UPDATE chanserv.bans set channelID=%u, userID=%u, hostmask='%s', expiry=%lu, reason='%s' "
"WHERE banID=%u", rcp->ID, rbp->setby, escban, rbp->expiry, escreason, rbp->ID);
}
void csdb_deleteban(regban *rbp) {
- pqquery("DELETE FROM bans WHERE banID=%u", rbp->ID);
+ dbquery("DELETE FROM chanserv.bans WHERE banID=%u", rbp->ID);
}
void csdb_createmail(reguser *rup, int type) {
if (type == QMAIL_NEWEMAIL) {
if (rup->email) {
- PQescapeString(escemail, rup->email->content, rup->email->length);
- sprintf(sqlquery, "INSERT INTO email (userID, emailType, prevEmail) "
+ dbescapestring(escemail, rup->email->content, rup->email->length);
+ sprintf(sqlquery, "INSERT INTO chanserv.email (userID, emailType, prevEmail) "
"VALUES (%u,%u,'%s')", rup->ID, type, escemail);
}
} else {
- sprintf(sqlquery, "INSERT INTO email (userID, emailType) VALUES (%u,%u)", rup->ID, type);
+ sprintf(sqlquery, "INSERT INTO chanserv.email (userID, emailType) VALUES (%u,%u)", rup->ID, type);
}
- pqquery("%s", sqlquery);
+ dbquery("%s", sqlquery);
}
void csdb_deletemaildomain(maildomain *mdp) {
- pqquery("DELETE FROM maildomain WHERE ID=%u", mdp->ID);
+ dbquery("DELETE FROM chanserv.maildomain WHERE ID=%u", mdp->ID);
}
void csdb_createmaildomain(maildomain *mdp) {
char escdomain[210];
- PQescapeString(escdomain, mdp->name->content, mdp->name->length);
+ dbescapestring(escdomain, mdp->name->content, mdp->name->length);
- pqquery("INSERT INTO maildomain (id, name, domainlimit, actlimit, flags) VALUES(%u, '%s', %u, %u, %u)", mdp->ID,escdomain,mdp->limit,mdp->actlimit,mdp->flags);
+ 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);
}
void csdb_updatemaildomain(maildomain *mdp) {
char escdomain[210];
- PQescapeString(escdomain, mdp->name->content, mdp->name->length);
+ dbescapestring(escdomain, mdp->name->content, mdp->name->length);
- pqquery("UPDATE maildomain SET domainlimit=%u, actlimit=%u, flags=%u, name='%s' WHERE ID=%u", mdp->limit,mdp->actlimit,mdp->flags,escdomain,mdp->ID);
+ 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);
}
void csdb_chanlevhistory_insert(regchan *rcp, nick *np, reguser *trup, flag_t oldflags, flag_t newflags) {
reguser *rup=getreguserfromnick(np);
+ assert(rup != NULL);
- pqquery("INSERT INTO chanlevhistory (userID, channelID, targetID, changetime, authtime, "
+ dbquery("INSERT INTO chanserv.chanlevhistory (userID, channelID, targetID, changetime, authtime, "
"oldflags, newflags) VALUES (%u, %u, %u, %lu, %lu, %u, %u)", rup->ID, rcp->ID, trup->ID, getnettime(), np->accountts,
oldflags, newflags);
}
-void csdb_accounthistory_insert(nick *np, char *oldpass, char *newpass, sstring *oldemail, sstring *newemail) {
+void csdb_accounthistory_insert(nick *np, char *oldpass, char *newpass, char *oldemail, char *newemail) {
reguser *rup=getreguserfromnick(np);
- char escoldpass[30];
- char escnewpass[30];
- char escoldemail[130];
- char escnewemail[130];
+ char escoldpass[PASSLEN*2+5];
+ char escnewpass[PASSLEN*2+5];
+ char escoldemail[EMAILLEN*2+5];
+ char escnewemail[EMAILLEN*2+5];
if (!rup || UHasOperPriv(rup))
return;
if (oldpass)
- PQescapeString(escoldpass, oldpass, strlen(oldpass));
+ dbescapestring(escoldpass, oldpass, CSMIN(strlen(oldpass), PASSLEN));
else
escoldpass[0]='\0';
if (newpass)
- PQescapeString(escnewpass, newpass, strlen(newpass));
+ dbescapestring(escnewpass, newpass, CSMIN(strlen(newpass), PASSLEN));
else
escnewpass[0]='\0';
if (oldemail)
- PQescapeString(escoldemail, oldemail->content, oldemail->length);
+ dbescapestring(escoldemail, oldemail, CSMIN(strlen(oldemail), EMAILLEN));
else
escoldemail[0]='\0';
if (newemail)
- PQescapeString(escnewemail, newemail->content, newemail->length);
+ dbescapestring(escnewemail, newemail, CSMIN(strlen(newemail), EMAILLEN));
else
escnewemail[0]='\0';
- pqquery("INSERT INTO accounthistory (userID, changetime, authtime, oldpassword, newpassword, oldemail, "
+ dbquery("INSERT INTO chanserv.accounthistory (userID, changetime, authtime, oldpassword, newpassword, oldemail, "
"newemail) VALUES (%u, %lu, %lu, '%s', '%s', '%s', '%s')", rup->ID, getnettime(), np->accountts, escoldpass, escnewpass,
escoldemail, escnewemail);
+}
- if (newemail)
- freesstring(newemail);
+void csdb_cleanuphistories(time_t expire_time) {
+ Error("chanserv", ERR_INFO, "Cleaning histories.");
+ dbquery("DELETE FROM chanserv.authhistory WHERE disconnecttime < %lu AND disconnecttime <> 0", expire_time);
+ dbquery("DELETE FROM chanserv.chanlevhistory WHERE authtime < %lu", expire_time);
+ dbquery("DELETE FROM chanserv.accounthistory WHERE authtime < %lu", expire_time);
}
-void csdb_cleanuphistories() {
- time_t expire_time=getnettime()-604800;
+void csdb_deletemaillock(maillock *mlp) {
+ dbquery("DELETE FROM chanserv.maillocks WHERE ID=%u", mlp->id);
+}
- Error("chanserv", ERR_INFO, "Cleaning histories.");
- pqquery("DELETE FROM authhistory WHERE authtime < %lu", expire_time);
- pqquery("DELETE FROM chanlevhistory WHERE changetime < %lu", expire_time);
- pqquery("DELETE FROM accounthistory WHERE changetime < %lu", expire_time);
+void csdb_createmaillock(maillock *mlp) {
+ char escpattern[1024], escreason[1024];
+
+ dbescapestring(escpattern, mlp->pattern->content, mlp->pattern->length);
+
+ if (mlp->reason)
+ dbescapestring(escreason, mlp->reason->content, mlp->reason->length);
+ else
+ escreason[0]='\0';
+
+ dbquery("INSERT INTO chanserv.maillocks (id, pattern, reason, createdby, created) VALUES(%u, '%s', '%s', %u, %jd)",
+ mlp->id,escpattern,escreason,mlp->createdby,(intmax_t)mlp->created);
+}
+
+void csdb_updatemaillock(maillock *mlp) {
+ char escpattern[1024], escreason[1024];
+
+ dbescapestring(escpattern, mlp->pattern->content, mlp->pattern->length);
+
+ if (mlp->reason)
+ dbescapestring(escreason, mlp->reason->content, mlp->reason->length);
+ else
+ escreason[0]='\0';
+
+ 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);
}