]>
Commit | Line | Data |
---|---|---|
84563ebd | 1 | /* |
2 | * The interface to the actual database | |
3 | */ | |
4 | ||
5 | #include "authtracker.h" | |
ee8cd7d0 | 6 | #include "../../dbapi/dbapi.h" |
84563ebd | 7 | #include "../../nick/nick.h" |
8 | #include "../../core/error.h" | |
9 | ||
84563ebd | 10 | #include <string.h> |
11 | #include <stdlib.h> | |
12 | ||
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); | |
16 | lreason[99]='\0'; | |
17 | ||
ee8cd7d0 | 18 | dbescapestring(escreason, lreason, strlen(lreason)); |
84563ebd | 19 | |
15a92284 | 20 | dbquery("UPDATE chanserv.authhistory SET disconnecttime=%lu, quitreason=E'%s' WHERE userID=%lu AND authtime=%lu", |
84563ebd | 21 | when, escreason, userid, accountts); |
22 | } | |
23 | ||
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]; | |
28 | ||
ee8cd7d0 CP |
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); | |
84563ebd | 32 | |
ee8cd7d0 | 33 | dbquery("INSERT INTO chanserv.authhistory (userID, nick, username, host, authtime, disconnecttime, numeric) " |
16739dbe | 34 | "VALUES (%u, E'%s', E'%s', E'%s', %lu, %lu, %lu)", |
6cfc3444 | 35 | userid, escnick, escuser, eschost, np->accountts, 0UL, np->numeric); |
84563ebd | 36 | } |
37 | ||
ee8cd7d0 CP |
38 | static void real_at_finddanglingsessions(DBConn *dbconn, void *arg) { |
39 | DBResult *pgres; | |
b3565978 CP |
40 | |
41 | if(!dbconn) | |
42 | return; | |
43 | ||
ee8cd7d0 | 44 | pgres=dbgetresult(dbconn); |
84563ebd | 45 | |
ee8cd7d0 | 46 | if (!dbquerysuccessful(pgres)) { |
84563ebd | 47 | Error("chanserv",ERR_ERROR,"Error loading dangling sessions."); |
48 | return; | |
49 | } | |
50 | ||
ee8cd7d0 | 51 | if (dbnumfields(pgres)!=3) { |
84563ebd | 52 | Error("authtracker",ERR_ERROR,"Dangling sessions format error"); |
ee8cd7d0 | 53 | dbclear(pgres); |
84563ebd | 54 | return; |
55 | } | |
56 | ||
ee8cd7d0 | 57 | while(dbfetchrow(pgres)) { |
84563ebd | 58 | at_lostnick( |
ee8cd7d0 CP |
59 | strtoul(dbgetvalue(pgres,0),NULL,10), /* numeric */ |
60 | strtoul(dbgetvalue(pgres,1),NULL,10), /* userID */ | |
61 | strtoul(dbgetvalue(pgres,2),NULL,10), /* authtime */ | |
84563ebd | 62 | time(NULL), |
63 | AT_RESTART | |
64 | ); | |
65 | } | |
66 | ||
ee8cd7d0 | 67 | dbclear(pgres); |
84563ebd | 68 | |
69 | at_dbloaded(0, NULL); | |
70 | } | |
71 | ||
72 | void at_finddanglingsessions() { | |
ee8cd7d0 | 73 | dbasyncqueryi(authtrackerdb, real_at_finddanglingsessions, NULL, |
522e2b8c | 74 | "SELECT numeric,userID,authtime FROM chanserv.authhistory WHERE disconnecttime=0"); |
84563ebd | 75 | |
76 | } |