Commit 698e7fee authored by frtabu's avatar frtabu

display array fix

parent 291533dd
......@@ -84,6 +84,7 @@ typedef int(*qcmdfunc_t)(char*, int, telnet_printfunc_t prnt,void *arg);
#define TELNETSRV_CMDFLAG_TELNETONLY (1<<2) // Only for telnet client connections
#define TELNETSRV_CMDFLAG_WEBSRVONLY (1<<3) // Only for web server connections
#define TELNETSRV_CMDFLAG_CONFEXEC (1<<4) // Ask for confirm before exec
#define TELNETSRV_CMDFLAG_GETWEBTBLDATA (1<<8) // When called from web server, use the get table data variant of the function
typedef struct cmddef {
char cmdname[TELNET_CMD_MAXSIZE];
char helpstr[TELNET_HELPSTR_SIZE];
......
......@@ -198,7 +198,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
logsdata->numcols=4;
logsdata->numlines=0;
snprintf(logsdata->columns[0].coltitle,TELNET_CMD_MAXSIZE,"component");
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING;
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING | TELNET_CHECKVAL_RDONLY;
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");
......@@ -223,7 +223,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
logsdata->numcols=3;
logsdata->numlines=0;
snprintf(logsdata->columns[0].coltitle,TELNET_CMD_MAXSIZE,"module");
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING;
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING | TELNET_CHECKVAL_RDONLY;
snprintf(logsdata->columns[1].coltitle,TELNET_CMD_MAXSIZE,"debug");
logsdata->columns[1].coltype = TELNET_CHECKVAL_BOOL;
snprintf(logsdata->columns[2].coltitle,TELNET_CMD_MAXSIZE,"dump");
......@@ -242,7 +242,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
logsdata->numcols=2;
logsdata->numlines=0;
snprintf(logsdata->columns[0].coltitle,TELNET_CMD_MAXSIZE,"option");
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING;
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING | TELNET_CHECKVAL_RDONLY;
snprintf(logsdata->columns[1].coltitle,TELNET_CMD_MAXSIZE,"enabled");
logsdata->columns[1].coltype = TELNET_CHECKVAL_BOOL;
......
......@@ -77,8 +77,8 @@ telnetshell_cmddef_t proc_cmdarray[] = {
{"show","loglvl|thread|config", proccmd_show,{(webfunc_t)proccmd_websrv_getdata},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"log","(enter help for details)", proccmd_log, {NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"show loglvl","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"show logopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"show dbgopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"show logopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBTBLDATA,NULL},
{"show dbgopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBTBLDATA,NULL},
{"thread","(enter help for details)", proccmd_thread,{(webfunc_t)proccmd_websrv_getdata},0,NULL},
{"exit","", proccmd_exit,{NULL},TELNETSRV_CMDFLAG_CONFEXEC,NULL},
{"","",NULL},
......
......@@ -155,7 +155,7 @@ void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata)
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)
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]));
......@@ -165,45 +165,43 @@ void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata)
}
json_array_append_new(jdata,kv);
}
json_t *jbody=json_pack("{s:o,s:o}","display",json_string(""),"logs",jdata);
json_t *jbody=json_pack("{s:[o],s:o}","display",json_null(),"logs",jdata);
websrv_jbody(response,jbody);
}
/*--------------------------------------------------------------------------------------------------*/
/* format a json response from a result table returned from a call to a telnet server command */
void websrv_gettbldata_response(struct _u_response * response,webdatadef_t * wdata) {
/* json_t *jcols = json_array();
json_t *jcols = json_array();
json_t *jdata = json_array();
char *coltype;
for (int i=0; i<wdata->numcols; i++) {
json_t *jval;
if(wdata->columns[j].coltype & TELNET_CHECKVAL_BOOL)
if(wdata->columns[i].coltype & TELNET_CHECKVAL_BOOL)
coltype="boolean";
else if (wdata->columns[j].coltype == TELNET_VARTYPE_STRING)
else if (wdata->columns[i].coltype & TELNET_VARTYPE_STRING)
coltype="string";
else
coltype="number";
json_t acol=json_pack("{name:s,type:s,modifiable:b}",wdata->columns[j].coltitle,coltype,);
json_t *acol=json_pack("{name:s,type:s,modifiable:b}",wdata->columns[i].coltitle,coltype,
( wdata->columns[i].coltype & TELNET_CHECKVAL_RDONLY)?0:1 );
json_array_append_new(jcols,acol);
}
for (int i=0; i<wdata->numlines ; i++) {
json_t *kv=json_object();
for (int j=0; j<wdata->numcols; j++) {
json_t *jval;
json_t *jval;
for (int j=0; j<wdata->numcols; j++) {
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)
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((long)(wdata->lines[i].val[j]));
json_object_set_new(kv, wdata->columns[j].coltitle, jval);
json_array_append_new(jdata,jval);
}
json_array_append_new(jdata,kv);
}
json_t *jbody=json_pack("{s:o,s:o}","columns",,"rows",);
websrv_jbody(response,jbody);*/
json_t *jbody=json_pack("{s:o,s:o}","columns",jcols,"rows",jdata);
websrv_jbody(response,jbody);
}
/*----------------------------------------------------------------------------------------------------------*/
/* callbacks and utility functions to stream a file */
......@@ -437,11 +435,17 @@ int websrv_callback_set_softmodemvar(const struct _u_request * request, struct _
/* callback processing module url (<address>/oaisoftmodem/module/commands), post method */
int websrv_processwebfunc(struct _u_response * response, cmdparser_t * modulestruct ,telnetshell_cmddef_t *cmd) {
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->cmdname,websrvparams.dbglvl,(webdatadef_t *)&wdata);
websrv_getdata_response(response,&wdata);
} else if (cmd->cmdflags & TELNETSRV_CMDFLAG_GETWEBTBLDATA) {
webdatadef_t wdata;
memset(&wdata,0,sizeof(wdata));
cmd->webfunc_getdata(cmd->cmdname,websrvparams.dbglvl,(webdatadef_t *)&wdata);
websrv_gettbldata_response(response,&wdata);
} else {
websrv_printf_start(response,16384);
cmd->cmdfunc("",websrvparams.dbglvl,websrv_printf);
......
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