Browse Source

ktree - add an optional ktree display and disabled code in ckdb

master
kanoi 11 years ago
parent
commit
091832c4c4
  1. 66
      src/ckdb.c
  2. 43
      src/ktree.c
  3. 1
      src/ktree.h

66
src/ckdb.c

@ -956,6 +956,22 @@ static void setnow(tv_t *now)
now->tv_usec = spec.tv_nsec / 1000; now->tv_usec = spec.tv_nsec / 1000;
} }
static void dsp_transfer(K_ITEM *item, FILE *stream)
{
TRANSFER *t = NULL;
if (!stream)
LOGERR("%s() called with (null) stream", __func__);
if (!item)
fprintf(stream, "%s() called with (null) item\n", __func__);
t = DATA_TRANSFER(item);
fprintf(stream, " name='%s' data='%s' malloc=%c\n",
t->name, t->data,
(t->value == t->data) ? 'N' : 'Y');
}
// order by name asc // order by name asc
static double cmp_transfer(K_ITEM *a, K_ITEM *b) static double cmp_transfer(K_ITEM *a, K_ITEM *b)
{ {
@ -3087,6 +3103,25 @@ void poolstats_reload()
PQfinish(conn); PQfinish(conn);
} }
static void dsp_userstats(K_ITEM *item, FILE *stream)
{
USERSTATS *u = NULL;
char *createdate_buf;
if (!stream)
LOGERR("%s() called with (null) stream", __func__);
if (!item)
fprintf(stream, "%s() called with (null) item\n", __func__);
u = DATA_USERSTATS(item);
createdate_buf = tv_to_buf(&(u->createdate), NULL, 0);
fprintf(stream, " pi='%s' uid=%"PRId64" Hs=%f Hs5m=%f Hs1hr=%f Hs24hr=%f cd=%s\n",
u->poolinstance, u->userid, u->hashrate, u->hashrate5m,
u->hashrate1hr, u->hashrate24hr, createdate_buf);
free(createdate_buf);
}
// order by poolinstance asc,userid asc,createdate asc // order by poolinstance asc,userid asc,createdate asc
static double cmp_userstats(K_ITEM *a, K_ITEM *b) static double cmp_userstats(K_ITEM *a, K_ITEM *b)
{ {
@ -3254,6 +3289,7 @@ static void setup_data()
transfer_list = k_new_list("Transfer", sizeof(TRANSFER), ALLOC_TRANSFER, LIMIT_TRANSFER, true); transfer_list = k_new_list("Transfer", sizeof(TRANSFER), ALLOC_TRANSFER, LIMIT_TRANSFER, true);
transfer_store = k_new_store(transfer_list); transfer_store = k_new_store(transfer_list);
transfer_root = new_ktree(); transfer_root = new_ktree();
transfer_list->dsp_func = dsp_transfer;
users_list = k_new_list("Users", sizeof(USERS), ALLOC_USERS, LIMIT_USERS, true); users_list = k_new_list("Users", sizeof(USERS), ALLOC_USERS, LIMIT_USERS, true);
users_store = k_new_store(users_list); users_store = k_new_store(users_list);
@ -3295,6 +3331,7 @@ static void setup_data()
userstats_list = k_new_list("UserStats", sizeof(USERSTATS), ALLOC_USERSTATS, LIMIT_USERSTATS, true); userstats_list = k_new_list("UserStats", sizeof(USERSTATS), ALLOC_USERSTATS, LIMIT_USERSTATS, true);
userstats_store = k_new_store(userstats_list); userstats_store = k_new_store(userstats_list);
userstats_root = new_ktree(); userstats_root = new_ktree();
userstats_list->dsp_func = dsp_userstats;
getdata(); getdata();
@ -4007,6 +4044,33 @@ static char *cmd_homepage(char *cmd, char *id, __maybe_unused tv_t *now, __maybe
return buf; return buf;
} }
static __maybe_unused char *cmd_dsp(char *cmd, char *id, __maybe_unused tv_t *now,
__maybe_unused char *by, __maybe_unused char *code,
__maybe_unused char *inet)
{
__maybe_unused K_ITEM *i_file;
__maybe_unused char reply[1024] = "";
__maybe_unused size_t siz = sizeof(reply);
LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
// WARNING: This is a gaping security hole - only use in development
LOGDEBUG("%s.disabled.dsp", id);
return strdup("disabled.dsp");
/*
i_file = require_name("file", 1, NULL, reply, siz);
if (!i_file)
return strdup(reply);
// Only one implemented so far
dsp_ktree(userstats_list, userstats_root, DATA_TRANSFER(i_file)->data);
LOGDEBUG("%s.ok.dsp.file='%s'", id, DATA_TRANSFER(i_file)->data);
return strdup("ok.dsp");
*/
}
enum cmd_values { enum cmd_values {
CMD_UNSET, CMD_UNSET,
CMD_REPLY, // Means something was wrong - send back reply CMD_REPLY, // Means something was wrong - send back reply
@ -4021,6 +4085,7 @@ enum cmd_values {
CMD_NEWID, CMD_NEWID,
CMD_PAYMENTS, CMD_PAYMENTS,
CMD_HOMEPAGE, CMD_HOMEPAGE,
CMD_DSP,
CMD_END CMD_END
}; };
@ -4048,6 +4113,7 @@ static struct CMDS {
{ CMD_NEWID, "newid", cmd_newid, ACCESS_SYSTEM }, { CMD_NEWID, "newid", cmd_newid, ACCESS_SYSTEM },
{ CMD_PAYMENTS, "payments", cmd_payments, ACCESS_WEB }, { CMD_PAYMENTS, "payments", cmd_payments, ACCESS_WEB },
{ CMD_HOMEPAGE, "homepage", cmd_homepage, ACCESS_WEB }, { CMD_HOMEPAGE, "homepage", cmd_homepage, ACCESS_WEB },
{ CMD_DSP, "dsp", cmd_dsp, ACCESS_SYSTEM },
{ CMD_END, NULL, NULL, NULL } { CMD_END, NULL, NULL, NULL }
}; };

43
src/ktree.c

@ -124,6 +124,49 @@ void dump_ktree(K_TREE *root, char *(*dsp_funct)(K_ITEM *))
printf(" Empty ktree\n"); printf(" Empty ktree\n");
} }
void dsp_ktree(K_LIST *list, K_TREE *root, char *filename)
{
K_TREE_CTX ctx[1];
K_ITEM *item;
FILE *stream;
struct tm *tm;
time_t now_t;
char stamp[128];
now_t = time(NULL);
tm = localtime(&now_t);
snprintf(stamp, sizeof(stamp),
"[%d-%02d-%02d %02d:%02d:%02d]",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
stream = fopen(filename, "w");
if (!stream)
fprintf(stderr, "%s %s() failed to open '%s' (%d) %s",
stamp, __func__, filename, errno, strerror(errno));
fprintf(stream, "%s Dump of ktree '%s':\n", stamp, list->name);
if (root->isNil == No)
{
item = first_in_ktree(root, ctx);
while (item)
{
list->dsp_func(item, stream);
item = next_in_ktree(ctx);
}
fprintf(stream, "End\n");
}
else
fprintf(stream, "Empty ktree\n");
fclose(stream);
}
static int nilTest(K_TREE *node, char *msg, int depth, int count, K_TREE *nil2) static int nilTest(K_TREE *node, char *msg, int depth, int count, K_TREE *nil2)
{ {
if (node->isNil == Yo || node == nil2) if (node->isNil == Yo || node == nil2)

1
src/ktree.h

@ -31,6 +31,7 @@ typedef void *K_TREE_CTX;
extern K_TREE *new_ktree(); extern K_TREE *new_ktree();
extern void dump_ktree(K_TREE *root, char *(*dsp_funct)(K_ITEM *)); extern void dump_ktree(K_TREE *root, char *(*dsp_funct)(K_ITEM *));
extern void dsp_ktree(K_LIST *list, K_TREE *root, char *filename);
extern K_ITEM *first_in_ktree(K_TREE *root, K_TREE_CTX *ctx); extern K_ITEM *first_in_ktree(K_TREE *root, K_TREE_CTX *ctx);
extern K_ITEM *last_in_ktree(K_TREE *root, K_TREE_CTX *ctx); extern K_ITEM *last_in_ktree(K_TREE *root, K_TREE_CTX *ctx);
extern K_ITEM *next_in_ktree(K_TREE_CTX *ctx); extern K_ITEM *next_in_ktree(K_TREE_CTX *ctx);

Loading…
Cancel
Save