#include <stdio.h>
#include <sys/poll.h>
#include <stdarg.h>
+#include <assert.h>
void csdb_updateauthinfo(reguser *rup) {
char eschost[2*HOSTLEN+1];
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) {
- dbquery("UPDATE chanserv.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) {
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' WHERE ID=%u",
+ "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,
rup->suspendtime, rup->lockuntil, escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail,
+ rup->lastpasschange,
rup->ID);
}
dbquery("INSERT INTO chanserv.users (ID, username, created, lastauth, lastemailchng, "
"flags, language, suspendby, suspendexp, suspendtime, lockuntil, password, email, lastuserhost, "
- "suspendreason, comment, info, lastemail) VALUES (%u,'%s',%lu,%lu,%lu,%u,%u,%u,%lu,%lu,%lu,'%s','%s',"
- "'%s','%s','%s','%s','%s')",
+ "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, rup->suspendtime, rup->lockuntil,
- escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail);
+ escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail,
+ rup->lastpasschange);
}
void csdb_chanlevhistory_insert(regchan *rcp, nick *np, reguser *trup, flag_t oldflags, flag_t newflags) {
reguser *rup=getreguserfromnick(np);
+ assert(rup != NULL);
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)
- dbescapestring(escoldpass, oldpass, strlen(oldpass));
+ dbescapestring(escoldpass, oldpass, CSMIN(strlen(oldpass), PASSLEN));
else
escoldpass[0]='\0';
if (newpass)
- dbescapestring(escnewpass, newpass, strlen(newpass));
+ dbescapestring(escnewpass, newpass, CSMIN(strlen(newpass), PASSLEN));
else
escnewpass[0]='\0';
if (oldemail)
- dbescapestring(escoldemail, oldemail->content, oldemail->length);
+ dbescapestring(escoldemail, oldemail, CSMIN(strlen(oldemail), EMAILLEN));
else
escoldemail[0]='\0';
if (newemail)
- dbescapestring(escnewemail, newemail->content, newemail->length);
+ dbescapestring(escnewemail, newemail, CSMIN(strlen(newemail), EMAILLEN));
else
escnewemail[0]='\0';
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=getnettime()-604800;
-
+void csdb_cleanuphistories(time_t expire_time) {
Error("chanserv", ERR_INFO, "Cleaning histories.");
- dbquery("DELETE FROM chanserv.authhistory WHERE authtime < %lu", expire_time);
- dbquery("DELETE FROM chanserv.chanlevhistory WHERE changetime < %lu", expire_time);
- dbquery("DELETE FROM chanserv.accounthistory WHERE changetime < %lu", expire_time);
+ 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_deletemaillock(maillock *mlp) {