+
+void trust_dotrustlog_real(DBConn *dbconn, void *arg) {
+ nick *np=getnickbynumeric((unsigned long)arg);
+ DBResult *pgres;
+ unsigned long logid, trustid, userid, type;
+ time_t timestamp;
+ char *message;
+ char timebuf[30];
+ int header=0;
+
+ if(!dbconn)
+ return;
+
+ pgres=dbgetresult(dbconn);
+
+ if (!dbquerysuccessful(pgres)) {
+ Error("trusts", ERR_ERROR, "Error loading trusts log data.");
+ dbclear(pgres);
+ return;
+ }
+
+ if (dbnumfields(pgres) != 6) {
+ Error("trusts", ERR_ERROR, "trusts log data format error.");
+ dbclear(pgres);
+ return;
+ }
+
+ if (!np) {
+ dbclear(pgres);
+ return;
+ }
+
+ while(dbfetchrow(pgres)) {
+ logid=strtoul(dbgetvalue(pgres, 0), NULL, 10);
+ trustid=strtoul(dbgetvalue(pgres, 1), NULL, 10);
+ timestamp=strtoul(dbgetvalue(pgres, 2), NULL, 10);
+ userid=strtoul(dbgetvalue(pgres, 3), NULL, 10);
+ type=strtoul(dbgetvalue(pgres, 4), NULL, 10);
+ message=dbgetvalue(pgres, 5);
+
+ if (!header) {
+ header=1;
+ controlreply(np, "Display trustlog for trust %lu", trustid);
+ controlreply(np, "ID Time OperID Type Message");
+ }
+ strftime(timebuf, 30, "%d/%m/%y %H:%M", localtime(×tamp));
+ controlreply(np, "%-3lu %s %-7lu %-2lu %s", logid, timebuf, userid, type, message);
+ }
+
+ if (!header) {
+ controlreply(np, "No trust log entries found.");
+ } else {
+ controlreply(np, "End Of List.");
+ }
+ dbclear(pgres);
+}
+
+
+void trustsdb_retrievetrustlog(nick *np, unsigned int trustid, time_t starttime) {
+ dbasyncquery(trust_dotrustlog_real, (void *)np->numeric, "SELECT * FROM trusts.log WHERE trustid=%u AND timestamp>%lu order by timestamp desc limit 1000", trustid, starttime);
+ Error("trusts", ERR_ERROR, "SELECT * FROM trusts.log WHERE trustid=%u AND timestamp>%lu order by timestamp desc limit 1000", trustid, starttime);
+}