2 * The interface to the actual database
5 #include "authtracker.h"
6 #include "../../dbapi/dbapi.h"
7 #include "../../nick/nick.h"
8 #include "../../core/error.h"
13 void at_logquit(unsigned long userid
, time_t accountts
, time_t when
, char *reason
) {
14 char lreason
[100], escreason
[205];
15 strncpy(lreason
,reason
,99);
18 dbescapestring(escreason
, lreason
, strlen(lreason
));
20 dbquery("UPDATE chanserv.authhistory SET disconnecttime=%lu, quitreason=E'%s' WHERE userID=%lu AND authtime=%lu",
21 when
, escreason
, userid
, accountts
);
24 void at_lognewsession(unsigned int userid
, nick
*np
) {
25 char escnick
[NICKLEN
*2+1];
26 char escuser
[USERLEN
*2+1];
27 char eschost
[HOSTLEN
*2+1];
29 dbescapestring(escnick
, np
->nick
, strlen(np
->nick
));
30 dbescapestring(escuser
, np
->ident
, strlen(np
->ident
));
31 dbescapestring(eschost
, np
->host
->name
->content
, np
->host
->name
->length
);
33 dbquery("INSERT INTO chanserv.authhistory (userID, nick, username, host, authtime, disconnecttime, numeric) "
34 "VALUES (%u, E'%s', E'%s', E'%s', %lu, %lu, %lu)",
35 userid
, escnick
, escuser
, eschost
, np
->accountts
, 0UL, np
->numeric
);
38 static void real_at_finddanglingsessions(DBConn
*dbconn
, void *arg
) {
44 pgres
=dbgetresult(dbconn
);
46 if (!dbquerysuccessful(pgres
)) {
47 Error("chanserv",ERR_ERROR
,"Error loading dangling sessions.");
51 if (dbnumfields(pgres
)!=3) {
52 Error("authtracker",ERR_ERROR
,"Dangling sessions format error");
57 while(dbfetchrow(pgres
)) {
59 strtoul(dbgetvalue(pgres
,0),NULL
,10), /* numeric */
60 strtoul(dbgetvalue(pgres
,1),NULL
,10), /* userID */
61 strtoul(dbgetvalue(pgres
,2),NULL
,10), /* authtime */
72 void at_finddanglingsessions() {
73 dbasyncqueryi(authtrackerdb
, real_at_finddanglingsessions
, NULL
,
74 "SELECT numeric,userID,authtime FROM chanserv.authhistory WHERE disconnecttime=0");