Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Black
OpenXG-RAN
Commits
291533dd
Commit
291533dd
authored
Apr 22, 2022
by
frtabu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more commands implementation in backend
parent
e18753db
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
12 deletions
+99
-12
common/utils/telnetsrv/telnetsrv.c
common/utils/telnetsrv/telnetsrv.c
+4
-0
common/utils/telnetsrv/telnetsrv.h
common/utils/telnetsrv/telnetsrv.h
+1
-0
common/utils/telnetsrv/telnetsrv_proccmd.c
common/utils/telnetsrv/telnetsrv_proccmd.c
+39
-5
common/utils/telnetsrv/telnetsrv_proccmd.h
common/utils/telnetsrv/telnetsrv_proccmd.h
+5
-2
common/utils/websrv/websrv.c
common/utils/websrv/websrv.c
+50
-5
No files found.
common/utils/telnetsrv/telnetsrv.c
View file @
291533dd
...
...
@@ -512,6 +512,8 @@ int process_command(char *buf) {
}
for
(
j
=
0
;
telnetparams
.
CmdParsers
[
i
].
cmd
[
j
].
cmdfunc
!=
NULL
;
j
++
)
{
if
(
telnetparams
.
CmdParsers
[
i
].
cmd
[
j
].
cmdflags
&
TELNETSRV_CMDFLAG_WEBSRVONLY
)
continue
;
client_printf
(
" %s %s %s
\n
"
,
telnetparams
.
CmdParsers
[
i
].
module
,
telnetparams
.
CmdParsers
[
i
].
cmd
[
j
].
cmdname
,
telnetparams
.
CmdParsers
[
i
].
cmd
[
j
].
helpstr
);
...
...
@@ -542,6 +544,8 @@ int process_command(char *buf) {
}
else
{
for
(
k
=
0
;
telnetparams
.
CmdParsers
[
i
].
cmd
[
k
].
cmdfunc
!=
NULL
;
k
++
)
{
if
(
strncasecmp
(
cmd
,
telnetparams
.
CmdParsers
[
i
].
cmd
[
k
].
cmdname
,
sizeof
(
telnetparams
.
CmdParsers
[
i
].
cmd
[
k
].
cmdname
))
==
0
)
{
if
(
telnetparams
.
CmdParsers
[
i
].
cmd
[
k
].
cmdflags
&
TELNETSRV_CMDFLAG_WEBSRVONLY
)
continue
;
if
(
telnetparams
.
CmdParsers
[
i
].
cmd
[
k
].
qptr
!=
NULL
)
{
notifiedFIFO_elt_t
*
msg
=
newNotifiedFIFO_elt
(
sizeof
(
telnetsrv_qmsg_t
),
0
,
NULL
,
NULL
);
telnetsrv_qmsg_t
*
cmddata
=
NotifiedFifoData
(
msg
);
...
...
common/utils/telnetsrv/telnetsrv.h
View file @
291533dd
...
...
@@ -83,6 +83,7 @@ typedef int(*qcmdfunc_t)(char*, int, telnet_printfunc_t prnt,void *arg);
#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
#define TELNETSRV_CMDFLAG_CONFEXEC (1<<4) // Ask for confirm before exec
typedef
struct
cmddef
{
char
cmdname
[
TELNET_CMD_MAXSIZE
];
char
helpstr
[
TELNET_HELPSTR_SIZE
];
...
...
common/utils/telnetsrv/telnetsrv_proccmd.c
View file @
291533dd
...
...
@@ -213,11 +213,45 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
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
)
?
0xFFFFFFFF
:
NULL
;
logsdata
->
lines
[
i
].
val
[
2
]
=
(
g_log
->
log_component
[
i
].
level
>=
0
)
?
(
char
*
)
0xFFFFFFFF
:
NULL
;
logsdata
->
lines
[
i
].
val
[
3
]
=
(
g_log
->
log_component
[
i
].
filelog
>
0
)
?
g_log
->
log_component
[
i
].
filelog_name
:
"stdout"
;
}
}
}
if
(
strcasestr
(
cmdbuff
,
"dbgopt"
)
!=
NULL
)
{
webdatadef_t
*
logsdata
=
(
webdatadef_t
*
)
data
;
logsdata
->
numcols
=
3
;
logsdata
->
numlines
=
0
;
snprintf
(
logsdata
->
columns
[
0
].
coltitle
,
TELNET_CMD_MAXSIZE
,
"module"
);
logsdata
->
columns
[
0
].
coltype
=
TELNET_VARTYPE_STRING
;
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"
);
logsdata
->
columns
[
2
].
coltype
=
TELNET_CHECKVAL_BOOL
;
for
(
int
i
=
0
;
log_maskmap
[
i
].
name
!=
NULL
;
i
++
)
{
logsdata
->
numlines
++
;
logsdata
->
lines
[
i
].
val
[
0
]
=
log_maskmap
[
i
].
name
;
logsdata
->
lines
[
i
].
val
[
1
]
=
(
g_log
->
debug_mask
&
log_maskmap
[
i
].
value
)
?
(
char
*
)
0xFFFFFFFF
:
NULL
;
logsdata
->
lines
[
i
].
val
[
2
]
=
(
g_log
->
dump_mask
&
log_maskmap
[
i
].
value
)
?
(
char
*
)
0xFFFFFFFF
:
NULL
;
}
}
if
(
strcasestr
(
cmdbuff
,
"logopt"
)
!=
NULL
)
{
webdatadef_t
*
logsdata
=
(
webdatadef_t
*
)
data
;
logsdata
->
numcols
=
2
;
logsdata
->
numlines
=
0
;
snprintf
(
logsdata
->
columns
[
0
].
coltitle
,
TELNET_CMD_MAXSIZE
,
"option"
);
logsdata
->
columns
[
0
].
coltype
=
TELNET_VARTYPE_STRING
;
snprintf
(
logsdata
->
columns
[
1
].
coltitle
,
TELNET_CMD_MAXSIZE
,
"enabled"
);
logsdata
->
columns
[
1
].
coltype
=
TELNET_CHECKVAL_BOOL
;
for
(
int
i
=
0
;
log_options
[
i
].
name
!=
NULL
;
i
++
)
{
logsdata
->
numlines
++
;
logsdata
->
lines
[
i
].
val
[
0
]
=
log_options
[
i
].
name
;
logsdata
->
lines
[
i
].
val
[
1
]
=
(
g_log
->
flag
&
log_options
[
i
].
value
)
?
(
char
*
)
0xFFFFFFFF
:
NULL
;
}
}
return
0
;
}
...
...
common/utils/telnetsrv/telnetsrv_proccmd.h
View file @
291533dd
...
...
@@ -74,10 +74,13 @@ telnetshell_vardef_t proc_vardef[] = {
telnetshell_cmddef_t
proc_cmdarray
[]
=
{
{
"show"
,
"loglvl|thread|config"
,
proccmd_show
,{(
webfunc_t
)
proccmd_websrv_getdata
},
TELNETSRV_CMDFLAG_
GETWEBDATA
,
NULL
},
{
"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
},
{
"thread"
,
"(enter help for details)"
,
proccmd_thread
,{(
webfunc_t
)
proccmd_websrv_getdata
},
0
,
NULL
},
{
"exit"
,
""
,
proccmd_exit
},
{
"exit"
,
""
,
proccmd_exit
,{
NULL
},
TELNETSRV_CMDFLAG_CONFEXEC
,
NULL
},
{
""
,
""
,
NULL
},
};
#else
...
...
common/utils/websrv/websrv.c
View file @
291533dd
...
...
@@ -160,7 +160,7 @@ void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata)
// 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
]));
jval
=
json_integer
((
long
)(
wdata
->
lines
[
i
].
val
[
j
]));
json_object_set_new
(
kv
,
wdata
->
columns
[
j
].
coltitle
,
jval
);
}
json_array_append_new
(
jdata
,
kv
);
...
...
@@ -168,6 +168,43 @@ void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata)
json_t
*
jbody
=
json_pack
(
"{s:o,s:o}"
,
"display"
,
json_string
(
""
),
"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 *jdata = json_array();
char *coltype;
for (int i=0; i<wdata->numcols; i++) {
json_t *jval;
if(wdata->columns[j].coltype & TELNET_CHECKVAL_BOOL)
coltype="boolean";
else if (wdata->columns[j].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_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;
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((long)(wdata->lines[i].val[j]));
json_object_set_new(kv, wdata->columns[j].coltitle, jval);
}
json_array_append_new(jdata,kv);
}
json_t *jbody=json_pack("{s:o,s:o}","columns",,"rows",);
websrv_jbody(response,jbody);*/
}
/*----------------------------------------------------------------------------------------------------------*/
/* callbacks and utility functions to stream a file */
char
*
websrv_read_file
(
const
char
*
filename
)
{
...
...
@@ -403,7 +440,7 @@ int websrv_processwebfunc(struct _u_response * response, cmdparser_t * modulestr
if
(
cmd
->
cmdflags
&
TELNETSRV_CMDFLAG_GETWEBDATA
)
{
webdatadef_t
wdata
;
memset
(
&
wdata
,
0
,
sizeof
(
wdata
));
cmd
->
webfunc_getdata
(
cmd
->
helpstr
,
websrvparams
.
dbglvl
,(
webdatadef_t
*
)
&
wdata
);
cmd
->
webfunc_getdata
(
cmd
->
cmdname
,
websrvparams
.
dbglvl
,(
webdatadef_t
*
)
&
wdata
);
websrv_getdata_response
(
response
,
&
wdata
);
}
else
{
websrv_printf_start
(
response
,
16384
);
...
...
@@ -528,10 +565,18 @@ int websrv_callback_get_softmodemcmd(const struct _u_request * request, struct _
LOG_I
(
UTIL
,
"[websrv] received %s commands request
\n
"
,
modulestruct
->
module
);
json_t
*
modulesubcom
=
json_array
();
for
(
int
j
=
0
;
modulestruct
->
cmd
[
j
].
cmdfunc
!=
NULL
;
j
++
)
{
if
(
strcasecmp
(
"help"
,
modulestruct
->
cmd
[
j
].
cmdname
)
!=
0
)
{
json_t
*
acmd
=
json_pack
(
"{s:s}"
,
"name"
,
modulestruct
->
cmd
[
j
].
cmdname
);
json_array_append
(
modulesubcom
,
acmd
);
if
(
strcasecmp
(
"help"
,
modulestruct
->
cmd
[
j
].
cmdname
)
==
0
||
(
modulestruct
->
cmd
[
j
].
cmdflags
&
TELNETSRV_CMDFLAG_TELNETONLY
)
)
{
continue
;
}
json_t
*
acmd
;
if
(
modulestruct
->
cmd
[
j
].
cmdflags
&
TELNETSRV_CMDFLAG_CONFEXEC
)
{
char
confstr
[
256
];
snprintf
(
confstr
,
sizeof
(
confstr
),
"Execute %s ?"
,
modulestruct
->
cmd
[
j
].
cmdname
);
acmd
=
json_pack
(
"{s:s,s:s}"
,
"name"
,
modulestruct
->
cmd
[
j
].
cmdname
,
"confirm"
,
confstr
);
}
else
{
acmd
=
json_pack
(
"{s:s}"
,
"name"
,
modulestruct
->
cmd
[
j
].
cmdname
);
}
json_array_append
(
modulesubcom
,
acmd
);
}
if
(
modulesubcom
==
NULL
)
{
LOG_E
(
UTIL
,
"[websrv] cannot encode modulesubcom response for %s
\n
"
,
modulestruct
->
module
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment