[srvx-commits] CVS: services/src saxdb.c,1.23,1.24
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-12-18 04:44:57
|
Update of /cvsroot/srvx/services/src
In directory sc8-pr-cvs1:/tmp/cvs-serv7266/src
Modified Files:
saxdb.c
Log Message:
add a "?stats databases"
Index: saxdb.c
===================================================================
RCS file: /cvsroot/srvx/services/src/saxdb.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** saxdb.c 14 Dec 2002 02:07:22 -0000 1.23
--- saxdb.c 18 Dec 2002 04:44:53 -0000 1.24
***************
*** 20,23 ****
--- 20,24 ----
#include "conf.h"
+ #include "hash.h"
#include "modcmd.h"
#include "saxdb.h"
***************
*** 400,403 ****
--- 401,452 ----
}
+ static MODCMD_FUNC(cmd_stats_databases) {
+ struct helpfile_table tbl;
+ dict_iterator_t it;
+ unsigned int ii;
+
+ (void)argv;
+ tbl.length = dict_size(saxdbs) + 1;
+ tbl.width = 5;
+ tbl.flags = TABLE_NO_FREE;
+ tbl.contents = calloc(tbl.length, sizeof(tbl.contents[0]));
+ tbl.contents[0] = calloc(tbl.width, sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "Database";
+ tbl.contents[0][1] = "Filename/Section";
+ tbl.contents[0][2] = "Interval";
+ tbl.contents[0][3] = "Last Written";
+ tbl.contents[0][4] = "Last Duration";
+ for (ii=1, it=dict_first(saxdbs); it; it=iter_next(it), ++ii) {
+ struct saxdb *db = iter_data(it);
+ char *buf = malloc(INTERVALLEN*3);
+ tbl.contents[ii] = calloc(tbl.width, sizeof(tbl.contents[ii][0]));
+ tbl.contents[ii][0] = db->name;
+ tbl.contents[ii][1] = db->mondo_section ? db->mondo_section : db->filename;
+ if (db->write_interval) {
+ intervalString(buf, db->write_interval);
+ } else {
+ strcpy(buf+INTERVALLEN, "Never");
+ }
+ tbl.contents[ii][2] = buf;
+ if (db->last_write) {
+ intervalString(buf+INTERVALLEN, now - db->last_write);
+ intervalString(buf+INTERVALLEN*2, db->last_write_duration);
+ } else {
+ strcpy(buf+INTERVALLEN, "Never");
+ strcpy(buf+INTERVALLEN*2, "Never");
+ }
+ tbl.contents[ii][3] = buf+INTERVALLEN;
+ tbl.contents[ii][4] = buf+INTERVALLEN*2;
+ }
+ table_send(cmd->parent->bot, user->nick, 0, 0, tbl);
+ free(tbl.contents[0]);
+ for (ii=1; ii<tbl.length; ++ii) {
+ free((char*)tbl.contents[ii][2]);
+ free(tbl.contents[ii]);
+ }
+ free(tbl.contents);
+ return 0;
+ }
+
static void
saxdb_cleanup(void) {
***************
*** 438,441 ****
--- 487,491 ----
modcmd_register(saxdb_module, "write", cmd_write, 2, MODCMD_REQUIRE_AUTHED, "access", "800", NULL);
modcmd_register(saxdb_module, "writeall", cmd_writeall, 0, MODCMD_REQUIRE_AUTHED, "access", "800", NULL);
+ modcmd_register(saxdb_module, "stats databases", cmd_stats_databases, 0, 0, NULL);
}
|