Commit 80bf0358 authored by frtabu's avatar frtabu

test table reslt with log command

parent 86f36e80
......@@ -50,7 +50,7 @@
/* definitions to store 2 dim table, used to store command results before */
/* displaying them either on console or web page */
#define TELNET_MAXLINE_NUM 50
#define TELNET_MAXLINE_NUM 100
#define TELNET_MAXCOL_NUM 5
typedef struct col {
......@@ -108,6 +108,8 @@ typedef struct telnetsrv_qmsg {
/*structure to be used when adding a module to the telnet server */
/* This is the first parameter of the add_telnetcmd function, which can be used */
/* to add a set of new variables which can be got/set from the telnet server shell */
/* var type: bits 0-3, type value (1 to 15)
* type modifier, bits 4-31 */
#define TELNET_VARTYPE_INT32 1
#define TELNET_VARTYPE_INT16 2
#define TELNET_VARTYPE_INT64 3
......@@ -116,8 +118,8 @@ typedef struct telnetsrv_qmsg {
#define TELNET_VARTYPE_INT8 6
#define TELNET_VARTYPE_UINT 7
#define TELNET_CHECKVAL_RDONLY 1
#define TELNET_CHECKVAL_BOOL 2
#define TELNET_CHECKVAL_RDONLY 16
#define TELNET_CHECKVAL_BOOL 32
typedef struct variabledef {
char varname[TELNET_CMD_MAXSIZE];
char vartype;
......
......@@ -196,16 +196,24 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
if (strcasestr(cmdbuff,"loglvl") != NULL) {
webdatadef_t *logsdata = ( webdatadef_t *) data;
logsdata->numcols=4;
logsdata->numlines=0;
snprintf(logsdata->columns[0].coltitle,TELNET_CMD_MAXSIZE,"component");
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING;
snprintf(logsdata->columns[1].coltitle,TELNET_CMD_MAXSIZE,"level");
logsdata->columns[1].coltype = TELNET_VARTYPE_STRING;
snprintf(logsdata->columns[2].coltitle,TELNET_CMD_MAXSIZE,"enabled");
logsdata->columns[2].coltype = TELNET_CHECKVAL_BOOL;
snprintf(logsdata->columns[3].coltitle,TELNET_CMD_MAXSIZE,"output");
logsdata->columns[3].coltype = TELNET_VARTYPE_STRING;
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
if (g_log->log_component[i].name != NULL) {
logsdata->numlines++;
logsdata->lines[i].val[0]= (char *)(g_log->log_component[i].name);
logsdata->lines[i].val[1]=map_int_to_str(log_level_names,(g_log->log_component[i].level>=0)?g_log->log_component[i].level:g_log->log_component[i].savedlevel);
logsdata->lines[i].val[2]=(g_log->log_component[i].level>=0)?"true":"false";
logsdata->lines[i].val[2]=(g_log->log_component[i].level>=0)?0xFFFFFFFF:NULL;
logsdata->lines[i].val[3]=(g_log->log_component[i].filelog>0)?g_log->log_component[i].filelog_name:"stdout";
}
}
......
......@@ -66,6 +66,7 @@ void register_module_endpoints(cmdparser_t *module) ;
void websrv_printjson(char * label, json_t *jsonobj){
char *jstr = json_dumps(jsonobj,0);
LOG_I(UTIL,"[websrv] %s:%s\n", label, (jstr==NULL)?"??\n":jstr);
free(jstr);
}
/*-----------------------------------*/
/* build a json body in a response */
......@@ -146,7 +147,24 @@ void websrv_printf_end(int httpstatus ) {
/*--------------------------------------------------------------------------------------------------*/
/* format a json response from a result table returned from a call to a telnet server command */
void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata) {
json_t *jbody = json_array();
for (int i=0; i<wdata->numlines ; i++) {
json_t *kv=json_object();
for (int j=0; j<wdata->numcols; j++) {
json_t *jval;
if(wdata->columns[j].coltype & TELNET_CHECKVAL_BOOL)
jval=json_boolean(wdata->lines[i].val[j]);
else if (wdata->columns[j].coltype == TELNET_VARTYPE_STRING)
jval=json_string(wdata->lines[i].val[j]);
// else if (wdata->columns[j].coltype == TELNET_VARTYPE_DOUBLE)
// jval=json_real((double)(wdata->lines[i].val[j]));
else
jval=json_integer((int)(wdata->lines[i].val[j]));
json_object_set_new(kv, wdata->columns[j].coltitle, jval);
}
json_array_append_new(jbody,kv);
}
websrv_jbody(response,jbody);
}
/*----------------------------------------------------------------------------------------------------------*/
/* callbacks and utility functions to stream a file */
......@@ -382,6 +400,7 @@ int websrv_processwebfunc(struct _u_response * response, cmdparser_t * modulestr
LOG_I(UTIL,"[websrv] : executing command %s %s\n",modulestruct->module,cmd->cmdname);
if ( cmd->cmdflags & TELNETSRV_CMDFLAG_GETWEBDATA ) {
webdatadef_t wdata;
memset(&wdata,0,sizeof(wdata));
cmd->webfunc_getdata(cmd->helpstr,websrvparams.dbglvl,(webdatadef_t *)&wdata);
websrv_getdata_response(response,&wdata);
} else {
......
......@@ -91,8 +91,8 @@
static int rfsimu_setchanmod_cmd(char *buff, int debug, telnet_printfunc_t prnt, void *arg);
static telnetshell_cmddef_t rfsimu_cmdarray[] = {
{"setmodel","<model name> <model type>",(cmdfunc_t)rfsimu_setchanmod_cmd,NULL,TELNETSRV_CMDFLAG_PUSHINTPOOLQ},
{"","",NULL,NULL,0},
{"setmodel","<model name> <model type>",(cmdfunc_t)rfsimu_setchanmod_cmd,{NULL},TELNETSRV_CMDFLAG_PUSHINTPOOLQ,NULL},
{"","",NULL,{NULL},0,NULL},
};
static telnetshell_vardef_t rfsimu_vardef[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment