Commit 86f36e80 authored by frtabu's avatar frtabu

implementation of log command

parent 273ce8cb
...@@ -108,10 +108,10 @@ telnetshell_vardef_t telnet_vardef[] = { ...@@ -108,10 +108,10 @@ telnetshell_vardef_t telnet_vardef[] = {
}; };
telnetshell_cmddef_t telnet_cmdarray[] = { telnetshell_cmddef_t telnet_cmdarray[] = {
{"redirlog","[here,file,off]",setoutput,wsetoutput,0,NULL}, {"redirlog","[here,file,off]",setoutput,{wsetoutput},0,NULL},
{"param","[prio]",setparam,wsetparam,0,NULL}, {"param","[prio]",setparam,{wsetparam},0,NULL},
{"history","[list,reset]",history_cmd,NULL,0,NULL}, {"history","[list,reset]",history_cmd,{NULL},0,NULL},
{"","",NULL,NULL,0,NULL}, {"","",NULL,{NULL},0,NULL},
}; };
......
...@@ -48,6 +48,27 @@ ...@@ -48,6 +48,27 @@
#define CMDSTATUS_VARNOTFOUND 3 #define CMDSTATUS_VARNOTFOUND 3
#define CMDSTATUS_NOTFOUND 4 #define CMDSTATUS_NOTFOUND 4
/* 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_MAXCOL_NUM 5
typedef struct col {
char coltitle[TELNET_CMD_MAXSIZE];
unsigned int coltype;
} acol_t;
typedef struct line {
char *val[TELNET_MAXCOL_NUM];
} aline_t;
typedef struct webdatadef {
char tblname[TELNET_HELPSTR_SIZE];
int numlines;
int numcols;
acol_t columns[TELNET_MAXCOL_NUM];
aline_t lines[TELNET_MAXLINE_NUM];
} webdatadef_t;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* structure to be used when adding a module to the telnet server */ /* structure to be used when adding a module to the telnet server */
/* This is the second parameter of the add_telnetcmd function, which can be used */ /* This is the second parameter of the add_telnetcmd function, which can be used */
...@@ -55,14 +76,21 @@ ...@@ -55,14 +76,21 @@
typedef void(*telnet_printfunc_t)(const char* format, ...); typedef void(*telnet_printfunc_t)(const char* format, ...);
typedef int(*cmdfunc_t)(char*, int, telnet_printfunc_t prnt); typedef int(*cmdfunc_t)(char*, int, telnet_printfunc_t prnt);
typedef int(*webfunc_t)(char *cmdbuff, int debug, telnet_printfunc_t prnt, ... ); typedef int(*webfunc_t)(char *cmdbuff, int debug, telnet_printfunc_t prnt, ... );
typedef int(*webfunc_getdata_t)(char *cmdbuff, int debug, void *data);
typedef int(*qcmdfunc_t)(char*, int, telnet_printfunc_t prnt,void *arg); typedef int(*qcmdfunc_t)(char*, int, telnet_printfunc_t prnt,void *arg);
#define TELNETSRV_CMDFLAG_PUSHINTPOOLQ (1<<0) // ask the telnet server to push the command in a thread pool queue #define TELNETSRV_CMDFLAG_PUSHINTPOOLQ (1<<0) // ask the telnet server to push the command in a thread pool queue
#define TELNETSRV_CMDFLAG_GETWEBDATA (1<<1) // When called from web server, use the getdata variant of the function
#define TELNETSRV_CMDFLAG_TELNETONLY (1<<2) // Only for telnet client connections
#define TELNETSRV_CMDFLAG_WEBSRVONLY (1<<3) // Only for web server connections
typedef struct cmddef { typedef struct cmddef {
char cmdname[TELNET_CMD_MAXSIZE]; char cmdname[TELNET_CMD_MAXSIZE];
char helpstr[TELNET_HELPSTR_SIZE]; char helpstr[TELNET_HELPSTR_SIZE];
cmdfunc_t cmdfunc; cmdfunc_t cmdfunc;
webfunc_t webfunc; union {
webfunc_t webfunc;
webfunc_getdata_t webfunc_getdata;
};
unsigned int cmdflags; unsigned int cmdflags;
void *qptr; void *qptr;
} telnetshell_cmddef_t; } telnetshell_cmddef_t;
......
...@@ -110,8 +110,8 @@ int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt) { ...@@ -110,8 +110,8 @@ int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt) {
telnetshell_cmddef_t phy_cmdarray[] = { telnetshell_cmddef_t phy_cmdarray[] = {
{"disp","[phycnt,uedump,uestat UE<x>]", dump_phyvars,NULL,0,NULL}, {"disp","[phycnt,uedump,uestat UE<x>]", dump_phyvars,{NULL},0,NULL},
{"","",NULL,NULL,0,NULL}, {"","",NULL,{NULL},0,NULL},
}; };
......
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
int loader_show_cmd(char *buff, int debug, telnet_printfunc_t prnt); int loader_show_cmd(char *buff, int debug, telnet_printfunc_t prnt);
telnetshell_cmddef_t loader_cmdarray[] = { telnetshell_cmddef_t loader_cmdarray[] = {
{"show","[params,modules]",loader_show_cmd,(webfunc_t)loader_show_cmd,0,NULL}, {"show","[params,modules]",loader_show_cmd,{(webfunc_t)loader_show_cmd},0,NULL},
{"","",NULL}, {"","",NULL,{NULL},0,NULL},
}; };
......
...@@ -191,6 +191,27 @@ struct dirent *entry; ...@@ -191,6 +191,27 @@ struct dirent *entry;
closedir(proc_dir); closedir(proc_dir);
} /* print_threads */ } /* print_threads */
int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
if (strcasestr(cmdbuff,"loglvl") != NULL) {
webdatadef_t *logsdata = ( webdatadef_t *) data;
logsdata->numcols=4;
snprintf(logsdata->columns[0].coltitle,TELNET_CMD_MAXSIZE,"component");
snprintf(logsdata->columns[1].coltitle,TELNET_CMD_MAXSIZE,"level");
snprintf(logsdata->columns[2].coltitle,TELNET_CMD_MAXSIZE,"enabled");
snprintf(logsdata->columns[3].coltitle,TELNET_CMD_MAXSIZE,"output");
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
if (g_log->log_component[i].name != NULL) {
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[3]=(g_log->log_component[i].filelog>0)?g_log->log_component[i].filelog_name:"stdout";
}
}
}
return 0;
}
int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt) int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt)
{ {
......
...@@ -45,6 +45,7 @@ extern int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt); ...@@ -45,6 +45,7 @@ extern int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt);
extern int proccmd_thread(char *buf, int debug, telnet_printfunc_t prnt); extern int proccmd_thread(char *buf, int debug, telnet_printfunc_t prnt);
extern int proccmd_exit(char *buf, int debug, telnet_printfunc_t prnt); extern int proccmd_exit(char *buf, int debug, telnet_printfunc_t prnt);
extern int proccmd_log(char *buf, int debug, telnet_printfunc_t prnt); extern int proccmd_log(char *buf, int debug, telnet_printfunc_t prnt);
extern int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data);
telnetshell_vardef_t proc_vardef[] = { telnetshell_vardef_t proc_vardef[] = {
{"",0,0,NULL} {"",0,0,NULL}
}; };
...@@ -73,9 +74,9 @@ telnetshell_vardef_t proc_vardef[] = { ...@@ -73,9 +74,9 @@ telnetshell_vardef_t proc_vardef[] = {
telnetshell_cmddef_t proc_cmdarray[] = { telnetshell_cmddef_t proc_cmdarray[] = {
{"show","loglvl|thread|config", proccmd_show}, {"show","loglvl|thread|config", proccmd_show,{(webfunc_t)proccmd_websrv_getdata},TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"log","(enter help for details)", proccmd_log}, {"log","(enter help for details)", proccmd_log, {NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"thread","(enter help for details)", proccmd_thread}, {"thread","(enter help for details)", proccmd_thread,{(webfunc_t)proccmd_websrv_getdata},0,NULL},
{"exit","", proccmd_exit}, {"exit","", proccmd_exit},
{"","",NULL}, {"","",NULL},
}; };
......
...@@ -143,7 +143,11 @@ void websrv_printf_end(int httpstatus ) { ...@@ -143,7 +143,11 @@ void websrv_printf_end(int httpstatus ) {
pthread_mutex_unlock(&(websrv_printf_buff.mutex)); pthread_mutex_unlock(&(websrv_printf_buff.mutex));
} }
/*--------------------------------------------------------------------------------------------------*/
/* 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) {
}
/*----------------------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------------------*/
/* callbacks and utility functions to stream a file */ /* callbacks and utility functions to stream a file */
char * websrv_read_file(const char * filename) { char * websrv_read_file(const char * filename) {
...@@ -376,9 +380,15 @@ int websrv_callback_set_softmodemvar(const struct _u_request * request, struct _ ...@@ -376,9 +380,15 @@ int websrv_callback_set_softmodemvar(const struct _u_request * request, struct _
/* callback processing module url (<address>/oaisoftmodem/module/commands), post method */ /* callback processing module url (<address>/oaisoftmodem/module/commands), post method */
int websrv_processwebfunc(struct _u_response * response, cmdparser_t * modulestruct ,telnetshell_cmddef_t *cmd) { 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); LOG_I(UTIL,"[websrv] : executing command %s %s\n",modulestruct->module,cmd->cmdname);
websrv_printf_start(response,16384); if ( cmd->cmdflags & TELNETSRV_CMDFLAG_GETWEBDATA ) {
cmd->cmdfunc("",websrvparams.dbglvl,websrv_printf); webdatadef_t wdata;
websrv_printf_end(200); cmd->webfunc_getdata(cmd->helpstr,websrvparams.dbglvl,(webdatadef_t *)&wdata);
websrv_getdata_response(response,&wdata);
} else {
websrv_printf_start(response,16384);
cmd->cmdfunc("",websrvparams.dbglvl,websrv_printf);
websrv_printf_end(200);
}
return 200; return 200;
} }
...@@ -408,7 +418,7 @@ int websrv_callback_exec_softmodemcmd(const struct _u_request * request, struct ...@@ -408,7 +418,7 @@ int websrv_callback_exec_softmodemcmd(const struct _u_request * request, struct
httpstatus=501; httpstatus=501;
msg="Unknown command in request body"; msg="Unknown command in request body";
for ( telnetshell_cmddef_t *cmd = modulestruct->cmd ; cmd->cmdfunc != NULL ;cmd++) { for ( telnetshell_cmddef_t *cmd = modulestruct->cmd ; cmd->cmdfunc != NULL ;cmd++) {
if (( strcmp(cmd->cmdname,vname) == 0) && cmd->webfunc != NULL){ if ( strcmp(cmd->cmdname,vname) == 0 && (( cmd->cmdflags & TELNETSRV_CMDFLAG_TELNETONLY) == 0) ){
httpstatus=websrv_processwebfunc(response,modulestruct,cmd); httpstatus=websrv_processwebfunc(response,modulestruct,cmd);
break; break;
} }
......
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
static int coding_setmod_cmd(char *buff, int debug, telnet_printfunc_t prnt); static int coding_setmod_cmd(char *buff, int debug, telnet_printfunc_t prnt);
static telnetshell_cmddef_t coding_cmdarray[] = { static telnetshell_cmddef_t coding_cmdarray[] = {
{"mode","[sse,avx2,stdc,none]",coding_setmod_cmd,NULL,0,NULL}, {"mode","[sse,avx2,stdc,none]",coding_setmod_cmd,{NULL},0,NULL},
{"","",NULL,NULL,0,NULL}, {"","",NULL,{NULL},0,NULL},
}; };
telnetshell_vardef_t coding_vardef[] = { telnetshell_vardef_t coding_vardef[] = {
{"maxiter",TELNET_VARTYPE_INT32,0,&max_turbo_iterations}, {"maxiter",TELNET_VARTYPE_INT32,0,&max_turbo_iterations},
......
...@@ -48,10 +48,10 @@ static int channelmod_show_cmd(char *buff, int debug, telnet_printfunc_t prnt); ...@@ -48,10 +48,10 @@ static int channelmod_show_cmd(char *buff, int debug, telnet_printfunc_t prnt);
static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt); static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt);
static int channelmod_print_help(char *buff, int debug, telnet_printfunc_t prnt); static int channelmod_print_help(char *buff, int debug, telnet_printfunc_t prnt);
static telnetshell_cmddef_t channelmod_cmdarray[] = { static telnetshell_cmddef_t channelmod_cmdarray[] = {
{"help","",channelmod_print_help,NULL,0,NULL}, {"help","",channelmod_print_help,{NULL},0,NULL},
{"show","<predef,current>",channelmod_show_cmd,NULL,0,NULL}, {"show","<predef,current>",channelmod_show_cmd,{NULL},0,NULL},
{"modify","<channelid> <param> <value>",channelmod_modify_cmd,NULL,0,NULL}, {"modify","<channelid> <param> <value>",channelmod_modify_cmd,{NULL},0,NULL},
{"","",NULL,NULL,0,NULL}, {"","",NULL,{NULL},0,NULL},
}; };
static telnetshell_vardef_t channelmod_vardef[] = { static telnetshell_vardef_t channelmod_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