]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/usercmds/accounthistory.c
fix bug in G stats
[irc/quakenet/newserv.git] / chanserv / usercmds / accounthistory.c
index 501ac16636882177640e8495a1031d92437a6107..33ba70f02bc8fc4b3f9300d3095655ed36c6c375 100644 (file)
@@ -7,74 +7,75 @@
  * CMDDESC: View password/email history for an account.
  * CMDFUNC: csa_doaccounthistory
  * CMDPROTO: int csa_doaccounthistory(void *source, int cargc, char **cargv);
+ * CMDHELP: Usage: accounthistory <account>
+ * CMDHELP: Shows password/email history for the specified account.
  */
 
 #include "../chanserv.h"
 #include "../../lib/irc_string.h"
-#include "../../pqsql/pqsql.h"
+#include "../../dbapi/dbapi.h"
 
-#include <libpq-fe.h>
 #include <stdio.h>
 #include <string.h>
 
-void csdb_doaccounthistory_real(PGconn *dbconn, void *arg) {
+void csdb_doaccounthistory_real(DBConn *dbconn, void *arg) {
   nick *np=getnickbynumeric((unsigned long)arg);
   reguser *rup;
   unsigned int userID;
   char *oldpass, *newpass, *oldemail, *newemail;
   time_t changetime, authtime;
-  PGresult *pgres;
-  int i, num, count=0;
-  struct tm *tmp;
-  char tbuf[15];
+  DBResult *pgres;
+  int count=0;
+  char tbuf[TIMELEN];
 
-  pgres=PQgetResult(dbconn);
+  if(!dbconn)
+    return;
+
+  pgres=dbgetresult(dbconn);
 
-  if (PQresultStatus(pgres) != PGRES_TUPLES_OK) {
+  if (!dbquerysuccessful(pgres)) {
     Error("chanserv", ERR_ERROR, "Error loading account history data.");
     return;
   }
 
-  if (PQnfields(pgres) != 7) {
+  if (dbnumfields(pgres) != 7) {
     Error("chanserv", ERR_ERROR, "Account history data format error.");
-    PQclear(pgres);
+    dbclear(pgres);
     return;
   }
 
-  num=PQntuples(pgres);
-
   if (!np) {
-    PQclear(pgres);
+    dbclear(pgres);
     return;
   }
 
   if (!(rup=getreguserfromnick(np)) || !UHasOperPriv(rup)) {
     Error("chanserv", ERR_ERROR, "No reguser pointer or oper privs in account history.");
-    PQclear(pgres);
+    dbclear(pgres);
     return;
   }
 
-  chanservsendmessage(np, "Number: Time:           Old password:  New password:  Old email:                     New email:");
-  for (i=0; i<num; i++) {
-    userID=strtoul(PQgetvalue(pgres, i, 0), NULL, 10);
-    changetime=strtoul(PQgetvalue(pgres, i, 1), NULL, 10);
-    authtime=strtoul(PQgetvalue(pgres, i, 2), NULL, 10);
-    oldpass=PQgetvalue(pgres, i, 3);
-    newpass=PQgetvalue(pgres, i, 4);
-    oldemail=PQgetvalue(pgres, i, 5);
-    newemail=PQgetvalue(pgres, i, 6);
-    tmp=localtime(&changetime);
-    strftime(tbuf, 15, "%d/%m/%y %H:%M", tmp);
-    chanservsendmessage(np, "#%-6d %-15s %-14s %-14s %-30s %s", ++count, tbuf, oldpass, newpass, oldemail, newemail);
+  /* @TIMELEN */
+  chanservsendmessage(np, "Number: Time:               Old password:  New password:  Old email:                     New email:");
+  while(dbfetchrow(pgres)) {
+    userID=strtoul(dbgetvalue(pgres, 0), NULL, 10);
+    changetime=strtoul(dbgetvalue(pgres, 1), NULL, 10);
+    authtime=strtoul(dbgetvalue(pgres, 2), NULL, 10);
+    oldpass=dbgetvalue(pgres, 3);
+    newpass=dbgetvalue(pgres, 4);
+    oldemail=dbgetvalue(pgres, 5);
+    newemail=dbgetvalue(pgres, 6);
+    q9strftime(tbuf, sizeof(tbuf), changetime);
+    chanservsendmessage(np, "#%-6d %-19s %-14s %-14s %-30s %s", ++count, tbuf, oldpass, newpass, oldemail, newemail); /* @TIMELEN */
   }
   chanservstdmessage(np, QM_ENDOFLIST);
 
-  PQclear(pgres);
+  dbclear(pgres);
 }
 
 void csdb_retreiveaccounthistory(nick *np, reguser *rup, int limit) {
-  pqasyncquery(csdb_doaccounthistory_real, (void *)np->numeric,
-    "SELECT userID, changetime, authtime, oldpassword, newpassword, oldemail, newemail from accounthistory where "
+  q9u_asyncquery(csdb_doaccounthistory_real, (void *)np->numeric,
+    "SELECT userID, changetime, authtime, oldpassword, newpassword, oldemail, newemail from chanserv.accounthistory where "
     "userID=%u order by changetime desc limit %d", rup->ID, limit);
 }