2 * The interface to the actual database
5 #include "authtracker.h"
6 #include "../../pqsql/pqsql.h"
7 #include "../../nick/nick.h"
8 #include "../../core/error.h"
14 void at_logquit(unsigned long userid
, time_t accountts
, time_t when
, char *reason
) {
15 char lreason
[100], escreason
[205];
16 strncpy(lreason
,reason
,99);
19 PQescapeString(escreason
, lreason
, strlen(lreason
));
21 pqquery("UPDATE authhistory SET disconnecttime=%lu, quitreason='%s' WHERE userID=%lu AND authtime=%lu",
22 when
, escreason
, userid
, accountts
);
25 void at_lognewsession(unsigned int userid
, nick
*np
) {
26 char escnick
[NICKLEN
*2+1];
27 char escuser
[USERLEN
*2+1];
28 char eschost
[HOSTLEN
*2+1];
30 PQescapeString(escnick
, np
->nick
, strlen(np
->nick
));
31 PQescapeString(escuser
, np
->ident
, strlen(np
->ident
));
32 PQescapeString(eschost
, np
->host
->name
->content
, np
->host
->name
->length
);
34 pqquery("INSERT INTO authhistory (userID, nick, username, host, authtime, disconnecttime, numeric) "
35 "VALUES (%lu, '%s', '%s', '%s', %lu, %lu, %u)",
36 userid
, escnick
, escuser
, eschost
, np
->accountts
, 0UL, np
->numeric
);
39 static void real_at_finddanglingsessions(PGconn
*dbconn
, void *arg
) {
43 pgres
=PQgetResult(dbconn
);
45 if (PQresultStatus(pgres
) != PGRES_TUPLES_OK
) {
46 Error("chanserv",ERR_ERROR
,"Error loading dangling sessions.");
50 if (PQnfields(pgres
)!=3) {
51 Error("authtracker",ERR_ERROR
,"Dangling sessions format error");
59 strtoul(PQgetvalue(pgres
,i
,0),NULL
,10), /* numeric */
60 strtoul(PQgetvalue(pgres
,i
,1),NULL
,10), /* userID */
61 strtoul(PQgetvalue(pgres
,i
,2),NULL
,10), /* authtime */
72 void at_finddanglingsessions() {
73 pqasyncquery(real_at_finddanglingsessions
, NULL
,
74 "SELECT numeric,userID,authtime FROM authhistory WHERE disconnecttime=0");