]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authtracker/authtracker_query.c
CHANSERV: remove E type escapes
[irc/quakenet/newserv.git] / chanserv / authtracker / authtracker_query.c
1 /*
2 * The interface to the actual database
3 */
4
5 #include "authtracker.h"
6 #include "../../dbapi/dbapi.h"
7 #include "../../nick/nick.h"
8 #include "../../core/error.h"
9
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
18 dbescapestring(escreason, lreason, strlen(lreason));
19
20 dbquery("UPDATE chanserv.authhistory SET disconnecttime=%lu, quitreason='%s' WHERE userID=%lu AND authtime=%lu",
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
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);
32
33 dbquery("INSERT INTO chanserv.authhistory (userID, nick, username, host, authtime, disconnecttime, numeric) "
34 "VALUES (%u, '%s', '%s', '%s', %lu, %lu, %lu)",
35 userid, escnick, escuser, eschost, np->accountts, 0UL, np->numeric);
36 }
37
38 static void real_at_finddanglingsessions(DBConn *dbconn, void *arg) {
39 DBResult *pgres;
40
41 if(!dbconn)
42 return;
43
44 pgres=dbgetresult(dbconn);
45
46 if (!dbquerysuccessful(pgres)) {
47 Error("chanserv",ERR_ERROR,"Error loading dangling sessions.");
48 return;
49 }
50
51 if (dbnumfields(pgres)!=3) {
52 Error("authtracker",ERR_ERROR,"Dangling sessions format error");
53 dbclear(pgres);
54 return;
55 }
56
57 while(dbfetchrow(pgres)) {
58 at_lostnick(
59 strtoul(dbgetvalue(pgres,0),NULL,10), /* numeric */
60 strtoul(dbgetvalue(pgres,1),NULL,10), /* userID */
61 strtoul(dbgetvalue(pgres,2),NULL,10), /* authtime */
62 time(NULL),
63 AT_RESTART
64 );
65 }
66
67 dbclear(pgres);
68
69 at_dbloaded(0, NULL);
70 }
71
72 void at_finddanglingsessions() {
73 dbasyncqueryi(authtrackerdb, real_at_finddanglingsessions, NULL,
74 "SELECT numeric,userID,authtime FROM chanserv.authhistory WHERE disconnecttime=0");
75
76 }