mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-16 06:00:28 +00:00
Compare commits
2 Commits
develop
...
websrv_fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abd380f2a1 | ||
|
|
e3e1a38d35 |
@@ -47,6 +47,7 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/time.h>
|
||||
@@ -57,20 +58,20 @@
|
||||
#include "executables/softmodem-common.h"
|
||||
#include <readline/history.h>
|
||||
|
||||
|
||||
#include "telnetsrv_phycmd.h"
|
||||
#include "telnetsrv_proccmd.h"
|
||||
static char *telnet_defstatmod[] = {"softmodem","phy","loader","measur"};
|
||||
static char *telnet_defstatmod[] = {"softmodem", "phy", "loader", "measur"};
|
||||
static telnetsrv_params_t telnetparams;
|
||||
|
||||
#define TELNETSRV_OPTNAME_STATICMOD "staticmod"
|
||||
#define TELNETSRV_OPTNAME_SHRMOD "shrmod"
|
||||
#define TELNETSRV_OPTNAME_STATICMOD "staticmod"
|
||||
#define TELNETSRV_OPTNAME_SHRMOD "shrmod"
|
||||
|
||||
// clang-format off
|
||||
paramdef_t telnetoptions[] = {
|
||||
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
/* configuration parameters for telnet utility */
|
||||
/* optname helpstr paramflags XXXptr defXXXval type numelt */
|
||||
/* configuration parameters for telnet utility */
|
||||
/* optname helpstr paramflags XXXptr defXXXval type
|
||||
numelt */
|
||||
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
{"listenaddr", "<listen ip address>\n", 0, .uptr = &telnetparams.listenaddr, .defstrval = "0.0.0.0", TYPE_IPV4ADDR, 0},
|
||||
{"listenport", "<local port>\n", 0, .uptr = &telnetparams.listenport, .defuintval = 9090, TYPE_UINT, 0},
|
||||
@@ -88,10 +89,11 @@ paramdef_t telnetoptions[] = {
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
int get_phybsize(void) {
|
||||
int get_phybsize(void)
|
||||
{
|
||||
return telnetparams.phyprntbuff_size;
|
||||
};
|
||||
int add_telnetcmd(char *modulename,telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd );
|
||||
int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd);
|
||||
int setoutput(char *buff, int debug, telnet_printfunc_t prnt);
|
||||
int wsetoutput(char *buff, int debug, telnet_printfunc_t prnt, ...);
|
||||
int setparam(char *buff, int debug, telnet_printfunc_t prnt);
|
||||
@@ -117,22 +119,24 @@ telnetshell_cmddef_t telnet_cmdarray[] = {
|
||||
{"", "", NULL, {NULL}, 0, NULL},
|
||||
};
|
||||
|
||||
void client_printf(const char *message, ...) {
|
||||
void client_printf(const char *message, ...)
|
||||
{
|
||||
va_list va_args;
|
||||
va_start(va_args, message);
|
||||
|
||||
if (telnetparams.new_socket > 0) {
|
||||
vsnprintf(telnetparams.msgbuff,sizeof(telnetparams.msgbuff)-1,message, va_args);
|
||||
send(telnetparams.new_socket,telnetparams.msgbuff, strlen(telnetparams.msgbuff), MSG_NOSIGNAL);
|
||||
vsnprintf(telnetparams.msgbuff, sizeof(telnetparams.msgbuff) - 1, message, va_args);
|
||||
send(telnetparams.new_socket, telnetparams.msgbuff, strlen(telnetparams.msgbuff), MSG_NOSIGNAL);
|
||||
} else {
|
||||
vprintf(message, va_args);
|
||||
}
|
||||
|
||||
va_end(va_args);
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
void set_sched(pthread_t tid, int pid, int priority) {
|
||||
void set_sched(pthread_t tid, int pid, int priority)
|
||||
{
|
||||
int rt;
|
||||
struct sched_param schedp;
|
||||
int policy;
|
||||
@@ -144,44 +148,46 @@ void set_sched(pthread_t tid, int pid, int priority) {
|
||||
sprintf(strpolicy, "%s", "RR");
|
||||
schedp.sched_priority = -(priority + 100);
|
||||
} else if (priority < 0 && priority > -100) {
|
||||
policy=SCHED_FIFO;
|
||||
sprintf(strpolicy,"%s","fifo");
|
||||
policy = SCHED_FIFO;
|
||||
sprintf(strpolicy, "%s", "fifo");
|
||||
schedp.sched_priority = -priority; // fifo priority 1 to 99 (high) mapped to oai priority -1 to -99 (high)
|
||||
} else if (priority >= 0 && priority <= (NICE_MAX - NICE_MIN)) { // other (normal) nice value -20 to 19 mapped to oai priority 0 to 39
|
||||
} else if (priority >= 0
|
||||
&& priority <= (NICE_MAX - NICE_MIN)) { // other (normal) nice value -20 to 19 mapped to oai priority 0 to 39
|
||||
policy = SCHED_OTHER;
|
||||
sprintf(strpolicy, "%s", "other");
|
||||
schedp.sched_priority = 0;
|
||||
niceval = priority + NICE_MIN;
|
||||
} else if (priority > NICE_MAX - NICE_MIN && priority <= (2 * (NICE_MAX - NICE_MIN) + 1)) { // batch (normal) nice value -20 to 19 mapped to oai priority 40 to 79
|
||||
} else if (priority > NICE_MAX - NICE_MIN
|
||||
&& priority
|
||||
<= (2 * (NICE_MAX - NICE_MIN) + 1)) { // batch (normal) nice value -20 to 19 mapped to oai priority 40 to 79
|
||||
policy = SCHED_BATCH;
|
||||
sprintf(strpolicy, "%s", "batch");
|
||||
niceval = priority + NICE_MIN - (NICE_MAX - NICE_MIN + 1);
|
||||
schedp.sched_priority = 0;
|
||||
} else if (priority > (2 * (NICE_MAX - NICE_MIN) + 1)) { // idle mapped to oai priority >79
|
||||
policy=SCHED_IDLE;
|
||||
sprintf(strpolicy,"%s","idle");
|
||||
schedp.sched_priority=0;
|
||||
policy = SCHED_IDLE;
|
||||
sprintf(strpolicy, "%s", "idle");
|
||||
schedp.sched_priority = 0;
|
||||
} else {
|
||||
client_printf("Error: %i invalid priority \n", priority);
|
||||
return;
|
||||
}
|
||||
if( tid != 0) {
|
||||
if (tid != 0) {
|
||||
rt = pthread_setschedparam(tid, policy, &schedp);
|
||||
} else if(pid > 0) {
|
||||
rt = sched_setscheduler( pid, policy,&schedp);
|
||||
} else if (pid > 0) {
|
||||
rt = sched_setscheduler(pid, policy, &schedp);
|
||||
} else {
|
||||
rt= -1;
|
||||
rt = -1;
|
||||
client_printf("Error: no pid or tid specified\n");
|
||||
}
|
||||
|
||||
if (rt != 0) {
|
||||
client_printf("Error %i: %s modifying sched param to %s:%i, \n",
|
||||
errno,strerror(errno),strpolicy,schedp.sched_priority);
|
||||
} else {
|
||||
client_printf("policy set to %s, priority %i\n",strpolicy,schedp.sched_priority);
|
||||
client_printf("Error %i: %s modifying sched param to %s:%i, \n", errno, strerror(errno), strpolicy, schedp.sched_priority);
|
||||
} else {
|
||||
client_printf("policy set to %s, priority %i\n", strpolicy, schedp.sched_priority);
|
||||
|
||||
if (policy == SCHED_OTHER || policy == SCHED_BATCH) {
|
||||
rt = getpriority(PRIO_PROCESS,tid);
|
||||
rt = getpriority(PRIO_PROCESS, tid);
|
||||
|
||||
if (rt != -1) {
|
||||
rt = setpriority(PRIO_PROCESS, tid, niceval);
|
||||
@@ -190,21 +196,20 @@ void set_sched(pthread_t tid, int pid, int priority) {
|
||||
client_printf("Error %i: %s trying to set nice value of thread %u to %i\n", errno, strerror(errno), tid, niceval);
|
||||
}
|
||||
} else {
|
||||
client_printf("Error %i: %s trying to get nice value of thread %u \n",
|
||||
errno,strerror(errno),tid);
|
||||
client_printf("Error %i: %s trying to get nice value of thread %u \n", errno, strerror(errno), tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (policy == SCHED_OTHER || policy == SCHED_BATCH) {
|
||||
if ( tid > 0 && tid != pthread_self()) {
|
||||
if (tid > 0 && tid != pthread_self()) {
|
||||
client_printf("setting nice value using a thread id not implemented....\n");
|
||||
} else if (pid > 0) {
|
||||
errno=0;
|
||||
errno = 0;
|
||||
rt = setpriority(PRIO_PROCESS, pid, niceval);
|
||||
|
||||
if (rt != 0) {
|
||||
client_printf("Error %i: %s calling setpriority, \n",errno,strerror(errno));
|
||||
client_printf("Error %i: %s calling setpriority, \n", errno, strerror(errno));
|
||||
} else {
|
||||
client_printf("nice value set to %i\n", niceval);
|
||||
}
|
||||
@@ -212,7 +217,8 @@ void set_sched(pthread_t tid, int pid, int priority) {
|
||||
}
|
||||
}
|
||||
|
||||
void set_affinity(pthread_t tid, int pid, int coreid) {
|
||||
void set_affinity(pthread_t tid, int pid, int coreid)
|
||||
{
|
||||
cpu_set_t cpuset;
|
||||
int rt;
|
||||
CPU_ZERO(&cpuset);
|
||||
@@ -223,13 +229,13 @@ void set_affinity(pthread_t tid, int pid, int coreid) {
|
||||
} else if (pid > 0) {
|
||||
rt = sched_setaffinity((pid_t)pid, sizeof(cpu_set_t), &cpuset);
|
||||
} else {
|
||||
rt= -1;
|
||||
rt = -1;
|
||||
}
|
||||
|
||||
if (rt != 0) {
|
||||
client_printf("Error %i: %s calling , xxx_setaffinity...\n",errno,strerror(errno));
|
||||
client_printf("Error %i: %s calling , xxx_setaffinity...\n", errno, strerror(errno));
|
||||
} else {
|
||||
client_printf("thread %i affinity set to %i\n",(pid==0)?(int)tid:pid,coreid);
|
||||
client_printf("thread %i affinity set to %i\n", (pid == 0) ? (int)tid : pid, coreid);
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------------------*/
|
||||
@@ -238,9 +244,10 @@ function implementing telnet server specific commands, parameters of the
|
||||
telnet_cmdarray table
|
||||
*/
|
||||
|
||||
void redirstd(char *newfname,telnet_printfunc_t prnt ) {
|
||||
void redirstd(char *newfname, telnet_printfunc_t prnt)
|
||||
{
|
||||
FILE *fd;
|
||||
fd=freopen(newfname, "w", stdout);
|
||||
fd = freopen(newfname, "w", stdout);
|
||||
|
||||
if (fd == NULL) {
|
||||
prnt("ERROR: stdout redir to %s error %s\n", strerror(errno));
|
||||
@@ -248,7 +255,7 @@ void redirstd(char *newfname,telnet_printfunc_t prnt ) {
|
||||
prnt("stdout redirected to %s\n", newfname);
|
||||
}
|
||||
|
||||
fd=freopen(newfname, "w", stderr);
|
||||
fd = freopen(newfname, "w", stderr);
|
||||
|
||||
if (fd == NULL) {
|
||||
prnt("ERROR: stderr redir to %s error %s\n", strerror(errno));
|
||||
@@ -262,37 +269,38 @@ int wsetoutput(char *buffer, int debug, telnet_printfunc_t prnt, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setoutput(char *buff, int debug, telnet_printfunc_t prnt) {
|
||||
char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
|
||||
int setoutput(char *buff, int debug, telnet_printfunc_t prnt)
|
||||
{
|
||||
char cmds[TELNET_MAX_MSGLENGTH / TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
|
||||
char *logfname;
|
||||
char stdout_str[64];
|
||||
|
||||
memset(cmds,0,sizeof(cmds));
|
||||
sscanf(buff,"%9s %32s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4] );
|
||||
memset(cmds, 0, sizeof(cmds));
|
||||
sscanf(buff, "%9s %32s %9s %9s %9s", cmds[0], cmds[1], cmds[2], cmds[3], cmds[4]);
|
||||
|
||||
if (strncasecmp(cmds[0],"here",4) == 0) {
|
||||
if (strncasecmp(cmds[0], "here", 4) == 0) {
|
||||
fflush(stdout);
|
||||
sprintf(stdout_str,"/proc/%i/fd/%i",getpid(),telnetparams.new_socket);
|
||||
dup2(telnetparams.new_socket,fileno(stdout));
|
||||
sprintf(stdout_str, "/proc/%i/fd/%i", getpid(), telnetparams.new_socket);
|
||||
dup2(telnetparams.new_socket, fileno(stdout));
|
||||
// freopen(stdout_str, "w", stdout);
|
||||
// freopen(stdout_str, "w", stderr);
|
||||
dup2(telnetparams.new_socket,fileno(stderr));
|
||||
prnt("Log output redirected to this terminal (%s)\n",stdout_str);
|
||||
dup2(telnetparams.new_socket, fileno(stderr));
|
||||
prnt("Log output redirected to this terminal (%s)\n", stdout_str);
|
||||
}
|
||||
|
||||
if (strncasecmp(cmds[0],"file",4) == 0) {
|
||||
if (strncasecmp(cmds[0], "file", 4) == 0) {
|
||||
if (cmds[1][0] == 0)
|
||||
logfname = telnetparams.logfile;
|
||||
else
|
||||
logfname=cmds[1];
|
||||
logfname = cmds[1];
|
||||
prnt("Log output redirected to (%s)\n", logfname);
|
||||
fflush(stdout);
|
||||
redirstd(logfname,prnt);
|
||||
redirstd(logfname, prnt);
|
||||
}
|
||||
|
||||
if (strncasecmp(cmds[0],"off",3) == 0) {
|
||||
if (strncasecmp(cmds[0], "off", 3) == 0) {
|
||||
fflush(stdout);
|
||||
redirstd("/dev/tty",prnt);
|
||||
redirstd("/dev/tty", prnt);
|
||||
}
|
||||
|
||||
return CMDSTATUS_FOUND;
|
||||
@@ -303,55 +311,57 @@ int wsetparam(char *buff, int debug, telnet_printfunc_t prnt, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setparam(char *buff, int debug, telnet_printfunc_t prnt) {
|
||||
char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
|
||||
memset(cmds,0,sizeof(cmds));
|
||||
sscanf(buff,"%9s %9s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4] );
|
||||
int setparam(char *buff, int debug, telnet_printfunc_t prnt)
|
||||
{
|
||||
char cmds[TELNET_MAX_MSGLENGTH / TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
|
||||
memset(cmds, 0, sizeof(cmds));
|
||||
sscanf(buff, "%9s %9s %9s %9s %9s", cmds[0], cmds[1], cmds[2], cmds[3], cmds[4]);
|
||||
|
||||
if (strncasecmp(cmds[0],"prio",4) == 0) {
|
||||
if (strncasecmp(cmds[0], "prio", 4) == 0) {
|
||||
int prio;
|
||||
prio=(int)strtol(cmds[1],NULL,0);
|
||||
prio = (int)strtol(cmds[1], NULL, 0);
|
||||
|
||||
if (errno == ERANGE)
|
||||
return CMDSTATUS_VARNOTFOUND;
|
||||
|
||||
telnetparams.priority = prio;
|
||||
set_sched(pthread_self(),0,prio);
|
||||
set_sched(pthread_self(), 0, prio);
|
||||
return CMDSTATUS_FOUND;
|
||||
}
|
||||
|
||||
if (strncasecmp(cmds[0],"aff",3) == 0) {
|
||||
if (strncasecmp(cmds[0], "aff", 3) == 0) {
|
||||
int aff;
|
||||
aff=(int)strtol(cmds[1],NULL,0);
|
||||
aff = (int)strtol(cmds[1], NULL, 0);
|
||||
|
||||
if (errno == ERANGE)
|
||||
return CMDSTATUS_VARNOTFOUND;
|
||||
|
||||
set_affinity(pthread_self(),0,aff);
|
||||
set_affinity(pthread_self(), 0, aff);
|
||||
return CMDSTATUS_FOUND;
|
||||
}
|
||||
|
||||
return CMDSTATUS_NOTFOUND;
|
||||
} /* setparam */
|
||||
|
||||
int history_cmd(char *buff, int debug, telnet_printfunc_t prnt) {
|
||||
char cmds[TELNET_MAX_MSGLENGTH/TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
|
||||
memset(cmds,0,sizeof(cmds));
|
||||
sscanf(buff,"%9s %9s %9s %9s %9s", cmds[0],cmds[1],cmds[2],cmds[3],cmds[4] );
|
||||
int history_cmd(char *buff, int debug, telnet_printfunc_t prnt)
|
||||
{
|
||||
char cmds[TELNET_MAX_MSGLENGTH / TELNET_CMD_MAXSIZE][TELNET_CMD_MAXSIZE];
|
||||
memset(cmds, 0, sizeof(cmds));
|
||||
sscanf(buff, "%9s %9s %9s %9s %9s", cmds[0], cmds[1], cmds[2], cmds[3], cmds[4]);
|
||||
|
||||
if (strncasecmp(cmds[0],"list",4) == 0) {
|
||||
HIST_ENTRY **hist = history_list();
|
||||
|
||||
if (hist) {
|
||||
for (int i = 0; hist[i]; i++) {
|
||||
prnt ("%d: %s\n", i + history_base, hist[i]->line);
|
||||
prnt("%d: %s\n", i + history_base, hist[i]->line);
|
||||
}
|
||||
}
|
||||
|
||||
return CMDSTATUS_FOUND;
|
||||
}
|
||||
|
||||
if (strncasecmp(cmds[0],"reset",5) == 0) {
|
||||
if (strncasecmp(cmds[0], "reset", 5) == 0) {
|
||||
clear_history();
|
||||
write_history(telnetparams.histfile);
|
||||
return CMDSTATUS_FOUND;
|
||||
@@ -467,21 +477,28 @@ int setgetvar(int moduleindex, char getorset, char *params)
|
||||
n = sscanf(params, "%9s %ms", varname, &varval);
|
||||
|
||||
for (i = 0; telnetparams.CmdParsers[moduleindex].var[i].varvalptr != NULL; i++) {
|
||||
if (strncasecmp(telnetparams.CmdParsers[moduleindex].var[i].varname, varname, strlen(telnetparams.CmdParsers[moduleindex].var[i].varname)) == 0) {
|
||||
if (strncasecmp(telnetparams.CmdParsers[moduleindex].var[i].varname,
|
||||
varname,
|
||||
strlen(telnetparams.CmdParsers[moduleindex].var[i].varname))
|
||||
== 0) {
|
||||
if (n > 0 && (getorset == 'g' || getorset == 'G')) {
|
||||
client_printf("%s, %s = ", telnetparams.CmdParsers[moduleindex].module, telnetparams.CmdParsers[moduleindex].var[i].varname);
|
||||
client_printf("%s, %s = ",
|
||||
telnetparams.CmdParsers[moduleindex].module,
|
||||
telnetparams.CmdParsers[moduleindex].var[i].varname);
|
||||
char *strval = telnet_getvarvalue(telnetparams.CmdParsers[moduleindex].var, i);
|
||||
client_printf("%s\n", strval);
|
||||
free(strval);
|
||||
}
|
||||
if (n > 1 && (getorset == 's' || getorset == 'S')) {
|
||||
client_printf("%s, %s set to \n", telnetparams.CmdParsers[moduleindex].module, telnetparams.CmdParsers[moduleindex].var[i].varname);
|
||||
client_printf("%s, %s set to \n",
|
||||
telnetparams.CmdParsers[moduleindex].module,
|
||||
telnetparams.CmdParsers[moduleindex].var[i].varname);
|
||||
telnet_setvarvalue(&(telnetparams.CmdParsers[moduleindex].var[i]), varval, client_printf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n>1 && varval != NULL) {
|
||||
if (n > 1 && varval != NULL) {
|
||||
free(varval);
|
||||
}
|
||||
|
||||
@@ -496,10 +513,11 @@ void telnetsrv_freetbldata(webdatadef_t *wdata)
|
||||
free(wdata->lines[i].val[j]);
|
||||
}
|
||||
/*----------------------------------------------------------------------------------------------------*/
|
||||
char *get_time(char *buff,int bufflen) {
|
||||
struct tm tmstruct;
|
||||
time_t now = time (0);
|
||||
strftime (buff, bufflen, "%Y-%m-%d %H:%M:%S.000", localtime_r(&now,&tmstruct));
|
||||
char *get_time(char *buff, int bufflen)
|
||||
{
|
||||
struct tm tmstruct;
|
||||
time_t now = time(0);
|
||||
strftime(buff, bufflen, "%Y-%m-%d %H:%M:%S.000", localtime_r(&now, &tmstruct));
|
||||
return buff;
|
||||
}
|
||||
void telnet_pushcmd(telnetshell_cmddef_t *cmd, char *cmdbuff, telnet_printfunc_t prnt)
|
||||
@@ -516,32 +534,33 @@ void telnet_pushcmd(telnetshell_cmddef_t *cmd, char *cmdbuff, telnet_printfunc_t
|
||||
|
||||
int process_command(char *buf, int iteration)
|
||||
{
|
||||
int i,j,k;
|
||||
int i, j, k;
|
||||
char modulename[TELNET_CMD_MAXSIZE];
|
||||
char cmd[TELNET_CMD_MAXSIZE];
|
||||
char *cmdb=NULL;
|
||||
char *cmdb = NULL;
|
||||
int rt;
|
||||
memset(modulename,0,sizeof(modulename));
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
memset(modulename, 0, sizeof(modulename));
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
|
||||
|
||||
if (strncasecmp(buf,"ex",2) == 0)
|
||||
if (strncasecmp(buf, "ex", 2) == 0)
|
||||
return CMDSTATUS_EXIT;
|
||||
|
||||
if (strncasecmp(buf,"help",4) == 0) {
|
||||
for (i=0; telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++) {
|
||||
client_printf(" module %i = %s:\n",i,telnetparams.CmdParsers[i].module);
|
||||
if (strncasecmp(buf, "help", 4) == 0) {
|
||||
for (i = 0; telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++) {
|
||||
client_printf(" module %i = %s:\n", i, telnetparams.CmdParsers[i].module);
|
||||
|
||||
for(j=0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL ; j++) {
|
||||
for (j = 0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL; j++) {
|
||||
client_printf(" %s [get set] %s <value>\n",
|
||||
telnetparams.CmdParsers[i].module, telnetparams.CmdParsers[i].var[j].varname);
|
||||
telnetparams.CmdParsers[i].module,
|
||||
telnetparams.CmdParsers[i].var[j].varname);
|
||||
}
|
||||
|
||||
for(j=0; telnetparams.CmdParsers[i].cmd[j].cmdfunc != NULL ; j++) {
|
||||
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].module,
|
||||
telnetparams.CmdParsers[i].cmd[j].cmdname,
|
||||
telnetparams.CmdParsers[i].cmd[j].helpstr);
|
||||
}
|
||||
}
|
||||
@@ -549,25 +568,25 @@ int process_command(char *buf, int iteration)
|
||||
return CMDSTATUS_FOUND;
|
||||
}
|
||||
|
||||
rt=CMDSTATUS_NOTFOUND;
|
||||
j = sscanf(buf,"%19s %19s %m[^\t\n]",modulename,cmd,&cmdb);
|
||||
rt = CMDSTATUS_NOTFOUND;
|
||||
j = sscanf(buf, "%19s %19s %m[^\t\n]", modulename, cmd, &cmdb);
|
||||
|
||||
if (telnetparams.telnetdbg > 0)
|
||||
printf("process_command: %i words, module=%s cmd=%s, parameters= %s\n", j, modulename, cmd, (cmdb == NULL) ? "" : cmdb);
|
||||
|
||||
for (i=0; j>=2 && telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++) {
|
||||
if ( (strncasecmp(telnetparams.CmdParsers[i].module,modulename,strlen(telnetparams.CmdParsers[i].module)) == 0)) {
|
||||
if (strncasecmp(cmd,"getall",7) == 0 ) {
|
||||
for(j=0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL ; j++) {
|
||||
setgetvar(i,'g',telnetparams.CmdParsers[i].var[j].varname);
|
||||
for (i = 0; j >= 2 && telnetparams.CmdParsers[i].var != NULL && telnetparams.CmdParsers[i].cmd != NULL; i++) {
|
||||
if ((strncasecmp(telnetparams.CmdParsers[i].module, modulename, strlen(telnetparams.CmdParsers[i].module)) == 0)) {
|
||||
if (strncasecmp(cmd, "getall", 7) == 0) {
|
||||
for (j = 0; telnetparams.CmdParsers[i].var[j].varvalptr != NULL; j++) {
|
||||
setgetvar(i, 'g', telnetparams.CmdParsers[i].var[j].varname);
|
||||
}
|
||||
|
||||
rt= CMDSTATUS_FOUND;
|
||||
} else if (strcasecmp(cmd,"get") == 0 || strcasecmp(cmd,"set") == 0) {
|
||||
rt= setgetvar(i,cmd[0],cmdb);
|
||||
rt = CMDSTATUS_FOUND;
|
||||
} else if (strcasecmp(cmd, "get") == 0 || strcasecmp(cmd, "set") == 0) {
|
||||
rt = setgetvar(i, cmd[0], cmdb);
|
||||
} 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) {
|
||||
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) {
|
||||
@@ -575,49 +594,52 @@ int process_command(char *buf, int iteration)
|
||||
} else {
|
||||
telnetparams.CmdParsers[i].cmd[k].cmdfunc(cmdb, telnetparams.telnetdbg, client_printf);
|
||||
}
|
||||
rt= CMDSTATUS_FOUND;
|
||||
rt = CMDSTATUS_FOUND;
|
||||
}
|
||||
} /* for k */
|
||||
}/* else */
|
||||
}/* strncmp: module name test */
|
||||
else if (strncasecmp(modulename,"loop",4) == 0 ) {
|
||||
int f = fcntl(telnetparams.new_socket,F_GETFL);
|
||||
int f1=fcntl (telnetparams.new_socket, F_SETFL, O_NONBLOCK | f);
|
||||
} /* else */
|
||||
} /* strncmp: module name test */
|
||||
else if (strncasecmp(modulename, "loop", 4) == 0) {
|
||||
int f = fcntl(telnetparams.new_socket, F_GETFL);
|
||||
int f1 = fcntl(telnetparams.new_socket, F_SETFL, O_NONBLOCK | f);
|
||||
|
||||
if (f<0 || f1 <0) {
|
||||
client_printf( " Loop won't be cancelable: %s\n",strerror(errno) );
|
||||
if (f < 0 || f1 < 0) {
|
||||
client_printf(" Loop won't be cancelable: %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
for(int lc=0; lc<telnetparams.loopcount; lc++) {
|
||||
for (int lc = 0; lc < telnetparams.loopcount; lc++) {
|
||||
char dummybuff[20];
|
||||
char tbuff[64];
|
||||
client_printf(CSI "1J" CSI "1;10H " STDFMT "%s %i/%i\n",
|
||||
get_time(tbuff,sizeof(tbuff)),lc,telnetparams.loopcount );
|
||||
get_time(tbuff, sizeof(tbuff)),
|
||||
lc,
|
||||
telnetparams.loopcount);
|
||||
process_command(buf + strlen("loop") + 1, lc);
|
||||
errno=0;
|
||||
int rs = read(telnetparams.new_socket,dummybuff,sizeof(dummybuff));
|
||||
errno = 0;
|
||||
int rs = read(telnetparams.new_socket, dummybuff, sizeof(dummybuff));
|
||||
|
||||
if (telnetparams.telnetdbg > 0)
|
||||
client_printf("Received \"%s\" status %d, errno %s while running loop\n",dummybuff,rs,strerror(errno));
|
||||
client_printf("Received \"%s\" status %d, errno %s while running loop\n", dummybuff, rs, strerror(errno));
|
||||
|
||||
if ( errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
client_printf( STDFMT " Loop canceled, iteration %i/%i\n",lc,telnetparams.loopcount );
|
||||
lc=telnetparams.loopcount;
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
client_printf(STDFMT " Loop canceled, iteration %i/%i\n", lc, telnetparams.loopcount);
|
||||
lc = telnetparams.loopcount;
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(telnetparams.loopdelay * 1000);
|
||||
}
|
||||
|
||||
fcntl (telnetparams.new_socket, F_SETFL, f);
|
||||
rt= CMDSTATUS_FOUND;
|
||||
fcntl(telnetparams.new_socket, F_SETFL, f);
|
||||
rt = CMDSTATUS_FOUND;
|
||||
} /* loop */
|
||||
} /* for i */
|
||||
free(cmdb);
|
||||
return rt;
|
||||
}
|
||||
|
||||
void run_telnetsrv(void) {
|
||||
void run_telnetsrv(void)
|
||||
{
|
||||
int sock;
|
||||
struct sockaddr_in name;
|
||||
char buf[TELNET_MAX_MSGLENGTH];
|
||||
@@ -626,13 +648,13 @@ void run_telnetsrv(void) {
|
||||
int readc, filled;
|
||||
int status;
|
||||
int optval = 1;
|
||||
char prompt[sizeof(TELNET_PROMPT_PREFIX)+10];
|
||||
char prompt[sizeof(TELNET_PROMPT_PREFIX) + 10];
|
||||
pthread_setname_np(pthread_self(), "telnet");
|
||||
set_sched(pthread_self(),0,telnetparams.priority);
|
||||
set_sched(pthread_self(), 0, telnetparams.priority);
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (sock < 0)
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on socket call\n",strerror(errno));
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on socket call\n", strerror(errno));
|
||||
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
|
||||
name.sin_family = AF_INET;
|
||||
@@ -644,74 +666,71 @@ void run_telnetsrv(void) {
|
||||
|
||||
name.sin_port = htons((unsigned short)(telnetparams.listenport));
|
||||
|
||||
if(bind(sock, (void *) &name, sizeof(name)))
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on bind call\n",strerror(errno));
|
||||
if (bind(sock, (void *)&name, sizeof(name)))
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on bind call\n", strerror(errno));
|
||||
|
||||
if(listen(sock, 1) == -1)
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on listen call\n",strerror(errno));
|
||||
if (listen(sock, 1) == -1)
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on listen call\n", strerror(errno));
|
||||
|
||||
using_history();
|
||||
int plen=sprintf(prompt,"%s_%s> ",TELNET_PROMPT_PREFIX,get_softmodem_function(NULL));
|
||||
int plen = sprintf(prompt, "%s_%s> ", TELNET_PROMPT_PREFIX, get_softmodem_function(NULL));
|
||||
printf("\nInitializing telnet server...\n");
|
||||
|
||||
while( (telnetparams.new_socket = accept(sock, &cli_addr, &cli_len)) ) {
|
||||
while ((telnetparams.new_socket = accept(sock, &cli_addr, &cli_len))) {
|
||||
printf("[TELNETSRV] Telnet client connected....\n");
|
||||
read_history(telnetparams.histfile);
|
||||
stifle_history(telnetparams.histsize);
|
||||
|
||||
if(telnetparams.new_socket < 0)
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on accept call\n",strerror(errno));
|
||||
if (telnetparams.new_socket < 0)
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on accept call\n", strerror(errno));
|
||||
|
||||
while(telnetparams.new_socket>0) {
|
||||
while (telnetparams.new_socket > 0) {
|
||||
filled = 0;
|
||||
memset(buf,0,sizeof(buf));
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
while(filled < ( TELNET_MAX_MSGLENGTH-1)) {
|
||||
readc = recv(telnetparams.new_socket, buf+filled, TELNET_MAX_MSGLENGTH-filled-1, 0);
|
||||
|
||||
if(!readc)
|
||||
break;
|
||||
|
||||
filled += readc;
|
||||
|
||||
if(buf[filled-1] == '\n') {
|
||||
buf[filled-1] = 0;
|
||||
while (filled < (TELNET_MAX_MSGLENGTH - 1)) {
|
||||
readc = recv(telnetparams.new_socket, buf + filled, TELNET_MAX_MSGLENGTH - filled - 1, 0);
|
||||
if (!readc) {
|
||||
printf("[TELNETSRV] Telnet Client disconnected, %s\n", strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
filled += readc;
|
||||
|
||||
if(!readc) {
|
||||
printf ("[TELNETSRV] Telnet Client disconnected.\n");
|
||||
break;
|
||||
}
|
||||
if (buf[filled - 1] == '\n') {
|
||||
while (filled > 0 && isspace(buf[filled - 1]))
|
||||
filled--;
|
||||
buf[filled] = 0;
|
||||
break;
|
||||
}
|
||||
} /* while loop to fill buffer till return entered */
|
||||
|
||||
if (telnetparams.telnetdbg > 0)
|
||||
printf("[TELNETSRV] Command received: readc %i filled %i \"%s\"\n", readc, filled,buf);
|
||||
printf("[TELNETSRV] Command received: readc %i filled %i \"%s\"\n", readc, filled, buf);
|
||||
|
||||
if (buf[0] == '!') {
|
||||
if (buf[1] == '!') {
|
||||
sprintf(buf,"%s","telnet history list");
|
||||
sprintf(buf, "%s", "telnet history list");
|
||||
} else {
|
||||
HIST_ENTRY *hisentry = history_get(strtol(buf+1,NULL,0));
|
||||
HIST_ENTRY *hisentry = history_get(strtol(buf + 1, NULL, 0));
|
||||
|
||||
if (hisentry) {
|
||||
char msg[TELNET_MAX_MSGLENGTH + plen +10];
|
||||
sprintf(buf,"%s",hisentry->line);
|
||||
sprintf(msg,"%s %s\n",prompt, hisentry->line);
|
||||
char msg[TELNET_MAX_MSGLENGTH + plen + 10];
|
||||
sprintf(buf, "%s", hisentry->line);
|
||||
sprintf(msg, "%s %s\n", prompt, hisentry->line);
|
||||
send(telnetparams.new_socket, msg, strlen(msg), MSG_NOSIGNAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(buf) > 2 ) {
|
||||
if (strlen(buf) > 2) {
|
||||
status = process_command(buf, 0);
|
||||
} else
|
||||
status=CMDSTATUS_NOCMD;
|
||||
status = CMDSTATUS_NOCMD;
|
||||
|
||||
if (status != CMDSTATUS_EXIT) {
|
||||
if (status == CMDSTATUS_NOTFOUND) {
|
||||
char msg[TELNET_MAX_MSGLENGTH + 50];
|
||||
sprintf(msg,"Error: \n %s\n is not a softmodem command\n",buf);
|
||||
sprintf(msg, "Error: \n %s\n is not a softmodem command\n", buf);
|
||||
send(telnetparams.new_socket, msg, strlen(msg), MSG_NOSIGNAL);
|
||||
} else if (status == CMDSTATUS_FOUND) {
|
||||
add_history(buf);
|
||||
@@ -719,7 +738,7 @@ void run_telnetsrv(void) {
|
||||
|
||||
send(telnetparams.new_socket, prompt, strlen(prompt), MSG_NOSIGNAL);
|
||||
} else {
|
||||
printf ("[TELNETSRV] Closing telnet connection...\n");
|
||||
printf("[TELNETSRV] Closing telnet connection...\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -727,114 +746,111 @@ void run_telnetsrv(void) {
|
||||
write_history(telnetparams.histfile);
|
||||
clear_history();
|
||||
close(telnetparams.new_socket);
|
||||
printf ("[TELNETSRV] Telnet server waitting for connection...\n");
|
||||
printf("[TELNETSRV] Telnet server waitting for connection...\n");
|
||||
}
|
||||
|
||||
close(sock);
|
||||
return;
|
||||
}
|
||||
|
||||
void run_telnetclt(void) {
|
||||
void run_telnetclt(void)
|
||||
{
|
||||
int sock;
|
||||
struct sockaddr_in name;
|
||||
pthread_setname_np(pthread_self(), "telnetclt");
|
||||
set_sched(pthread_self(),0,telnetparams.priority);
|
||||
char prompt[sizeof(TELNET_PROMPT_PREFIX)+10];
|
||||
sprintf(prompt,"%s_%s> ",TELNET_PROMPT_PREFIX,get_softmodem_function(NULL));
|
||||
set_sched(pthread_self(), 0, telnetparams.priority);
|
||||
char prompt[sizeof(TELNET_PROMPT_PREFIX) + 10];
|
||||
sprintf(prompt, "%s_%s> ", TELNET_PROMPT_PREFIX, get_softmodem_function(NULL));
|
||||
name.sin_family = AF_INET;
|
||||
struct in_addr addr;
|
||||
inet_aton("127.0.0.1", &addr) ;
|
||||
name.sin_addr.s_addr = addr.s_addr;
|
||||
inet_aton("127.0.0.1", &addr);
|
||||
name.sin_addr.s_addr = addr.s_addr;
|
||||
name.sin_port = htons((unsigned short)(telnetparams.listenport));
|
||||
while (1) {
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0)
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on socket call\n",strerror(errno));
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on socket call\n", strerror(errno));
|
||||
|
||||
if (connect(sock, (void *)&name, sizeof(name)))
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on connect call\n", strerror(errno));
|
||||
|
||||
if(connect(sock, (void *) &name, sizeof(name)))
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on connect call\n",strerror(errno));
|
||||
|
||||
struct timeval ts;
|
||||
ts.tv_sec = 1; // 1 second
|
||||
ts.tv_usec = 0;
|
||||
while (1) {
|
||||
fd_set fds;
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(sock, &fds);
|
||||
FD_SET(STDIN_FILENO , &fds);
|
||||
FD_SET(STDIN_FILENO, &fds);
|
||||
// wait for data
|
||||
int nready = select(sock + 1, &fds, (fd_set *) 0, (fd_set *) 0, &ts);
|
||||
int nready = select(sock + 1, &fds, (fd_set *)0, (fd_set *)0, &ts);
|
||||
if (nready < 0) {
|
||||
perror("select. Error");
|
||||
break;
|
||||
}
|
||||
else if (nready == 0) {
|
||||
ts.tv_sec = 1; // 1 second
|
||||
ts.tv_usec = 0;
|
||||
}
|
||||
else if ( FD_ISSET(sock, &fds)) {
|
||||
int rv;
|
||||
char inbuf[TELNET_MAX_MSGLENGTH*2];
|
||||
memset(inbuf,0,sizeof(inbuf));
|
||||
rv = recv(sock , inbuf , sizeof(inbuf)-1 , 0);
|
||||
if (rv > 0) {
|
||||
printf("%s",inbuf);
|
||||
}
|
||||
else if (rv == 0) {
|
||||
printf("Connection closed by the remote end\n\r");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
perror("recv error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (FD_ISSET(STDIN_FILENO , &fds)) {
|
||||
char *inbuf=NULL;
|
||||
size_t inlen=0;
|
||||
inlen = getline( &inbuf,&inlen, stdin);
|
||||
if ( inlen > 0 ) {
|
||||
if ( send(sock, inbuf,inlen, 0) < 0)
|
||||
break;
|
||||
}
|
||||
free(inbuf);
|
||||
perror("select. Error");
|
||||
break;
|
||||
} else if (nready == 0) {
|
||||
ts.tv_sec = 1; // 1 second
|
||||
ts.tv_usec = 0;
|
||||
} else if (FD_ISSET(sock, &fds)) {
|
||||
int rv;
|
||||
char inbuf[TELNET_MAX_MSGLENGTH * 2];
|
||||
memset(inbuf, 0, sizeof(inbuf));
|
||||
rv = recv(sock, inbuf, sizeof(inbuf) - 1, 0);
|
||||
if (rv > 0) {
|
||||
printf("%s", inbuf);
|
||||
} else if (rv == 0) {
|
||||
printf("Connection closed by the remote end\n\r");
|
||||
break;
|
||||
} else {
|
||||
perror("recv error");
|
||||
break;
|
||||
}
|
||||
} else if (FD_ISSET(STDIN_FILENO, &fds)) {
|
||||
char *inbuf = NULL;
|
||||
size_t inlen = 0;
|
||||
inlen = getline(&inbuf, &inlen, stdin);
|
||||
if (inlen > 0) {
|
||||
if (send(sock, inbuf, inlen, 0) < 0)
|
||||
break;
|
||||
}
|
||||
free(inbuf);
|
||||
}
|
||||
}
|
||||
close(sock);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} /* run_telnetclt */
|
||||
|
||||
void poll_telnetcmdq(void *qid, void *arg) {
|
||||
notifiedFIFO_elt_t *msg = pollNotifiedFIFO((notifiedFIFO_t *)qid);
|
||||
|
||||
if (msg != NULL) {
|
||||
telnetsrv_qmsg_t *msgdata=NotifiedFifoData(msg);
|
||||
msgdata->cmdfunc(msgdata->cmdbuff,msgdata->debug,msgdata->prnt,arg);
|
||||
free(msgdata->cmdbuff);
|
||||
delNotifiedFIFO_elt(msg);
|
||||
}
|
||||
void poll_telnetcmdq(void *qid, void *arg)
|
||||
{
|
||||
notifiedFIFO_elt_t *msg = pollNotifiedFIFO((notifiedFIFO_t *)qid);
|
||||
|
||||
if (msg != NULL) {
|
||||
telnetsrv_qmsg_t *msgdata = NotifiedFifoData(msg);
|
||||
msgdata->cmdfunc(msgdata->cmdbuff, msgdata->debug, msgdata->prnt, arg);
|
||||
free(msgdata->cmdbuff);
|
||||
delNotifiedFIFO_elt(msg);
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------------------------------*/
|
||||
/* load the commands delivered with the telnet server
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
static bool exec_moduleinit(char *modname) {
|
||||
*/
|
||||
static bool exec_moduleinit(char *modname)
|
||||
{
|
||||
void (*fptr)(void);
|
||||
char initfunc[TELNET_CMD_MAXSIZE+10];
|
||||
char initfunc[TELNET_CMD_MAXSIZE + 10];
|
||||
|
||||
if (strlen(modname) > TELNET_CMD_MAXSIZE) {
|
||||
fprintf(stderr,"[TELNETSRV] module %s not loaded, name exceeds the %i size limit\n",
|
||||
modname, TELNET_CMD_MAXSIZE);
|
||||
fprintf(stderr, "[TELNETSRV] module %s not loaded, name exceeds the %i size limit\n", modname, TELNET_CMD_MAXSIZE);
|
||||
return false;
|
||||
}
|
||||
|
||||
sprintf(initfunc,"add_%s_cmds",modname);
|
||||
fptr = dlsym(RTLD_DEFAULT,initfunc);
|
||||
sprintf(initfunc, "add_%s_cmds", modname);
|
||||
fptr = dlsym(RTLD_DEFAULT, initfunc);
|
||||
|
||||
if ( fptr != NULL) {
|
||||
if (fptr != NULL) {
|
||||
fptr();
|
||||
return true;
|
||||
}
|
||||
@@ -842,10 +858,11 @@ static bool exec_moduleinit(char *modname) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int add_embeddedmodules(void) {
|
||||
int ret=0;
|
||||
int pindex = config_paramidx_fromname(telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t), TELNETSRV_OPTNAME_STATICMOD);
|
||||
for(int i=0; i<telnetoptions[pindex].numelt; i++) {
|
||||
int add_embeddedmodules(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int pindex = config_paramidx_fromname(telnetoptions, sizeof(telnetoptions) / sizeof(paramdef_t), TELNETSRV_OPTNAME_STATICMOD);
|
||||
for (int i = 0; i < telnetoptions[pindex].numelt; i++) {
|
||||
bool success = exec_moduleinit(telnetoptions[pindex].strlistptr[i]);
|
||||
if (success)
|
||||
ret++;
|
||||
@@ -854,10 +871,11 @@ int add_embeddedmodules(void) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int add_sharedmodules(void) {
|
||||
int ret=0;
|
||||
int pindex = config_paramidx_fromname(telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t), TELNETSRV_OPTNAME_SHRMOD);
|
||||
for(int i=0; i<telnetoptions[pindex].numelt; i++) {
|
||||
int add_sharedmodules(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int pindex = config_paramidx_fromname(telnetoptions, sizeof(telnetoptions) / sizeof(paramdef_t), TELNETSRV_OPTNAME_SHRMOD);
|
||||
for (int i = 0; i < telnetoptions[pindex].numelt; i++) {
|
||||
char *name = telnetoptions[pindex].strlistptr[i];
|
||||
char libname[256];
|
||||
snprintf(libname, sizeof(libname), "telnetsrv_%s", name);
|
||||
@@ -873,28 +891,29 @@ int add_sharedmodules(void) {
|
||||
/* autoinit functions is called by the loader when the telnet shared library is
|
||||
dynamically loaded
|
||||
*/
|
||||
int telnetsrv_autoinit(void) {
|
||||
memset(&telnetparams,0,sizeof(telnetparams));
|
||||
config_get( telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t),"telnetsrv");
|
||||
int telnetsrv_autoinit(void)
|
||||
{
|
||||
memset(&telnetparams, 0, sizeof(telnetparams));
|
||||
config_get(telnetoptions, sizeof(telnetoptions) / sizeof(paramdef_t), "telnetsrv");
|
||||
/* possibly load a exec specific shared lib */
|
||||
char *execfunc=get_softmodem_function(NULL);
|
||||
char *execfunc = get_softmodem_function(NULL);
|
||||
char libname[64];
|
||||
sprintf(libname,"telnetsrv_%s",execfunc);
|
||||
load_module_shlib(libname,NULL,0,NULL);
|
||||
if(pthread_create(&telnetparams.telnet_pthread,NULL, (void *(*)(void *))run_telnetsrv, NULL) != 0) {
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on pthread_create call\n",strerror(errno));
|
||||
sprintf(libname, "telnetsrv_%s", execfunc);
|
||||
load_module_shlib(libname, NULL, 0, NULL);
|
||||
if (pthread_create(&telnetparams.telnet_pthread, NULL, (void *(*)(void *))run_telnetsrv, NULL) != 0) {
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on pthread_create call\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
add_telnetcmd("telnet", telnet_vardef, telnet_cmdarray);
|
||||
add_embeddedmodules();
|
||||
add_sharedmodules();
|
||||
if ( telnetparams.listenstdin ) {
|
||||
if(pthread_create(&telnetparams.telnetclt_pthread,NULL, (void *(*)(void *))run_telnetclt, NULL) != 0) {
|
||||
fprintf(stderr,"[TELNETSRV] Error %s on pthread_create f() run_telnetclt \n",strerror(errno));
|
||||
return -1;
|
||||
if (telnetparams.listenstdin) {
|
||||
if (pthread_create(&telnetparams.telnetclt_pthread, NULL, (void *(*)(void *))run_telnetclt, NULL) != 0) {
|
||||
fprintf(stderr, "[TELNETSRV] Error %s on pthread_create f() run_telnetclt \n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -902,13 +921,13 @@ int telnetsrv_autoinit(void) {
|
||||
/* add_telnetcmd is used to add a set of commands to the telnet server. A module calls this
|
||||
* function at init time. the telnet server is delivered with a set of commands which
|
||||
* will be loaded or not depending on the telnet section of the config file
|
||||
*/
|
||||
*/
|
||||
int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd)
|
||||
{
|
||||
notifiedFIFO_t *afifo = NULL;
|
||||
|
||||
if( modulename == NULL || var == NULL || cmd == NULL) {
|
||||
fprintf(stderr,"[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n");
|
||||
if (modulename == NULL || var == NULL || cmd == NULL) {
|
||||
fprintf(stderr, "[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -937,26 +956,30 @@ int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmdde
|
||||
/* function which will be called by the shared lib loader, to check shared lib version
|
||||
against main exec version. version mismatch not considered as fatal (interfaces not supposed to change)
|
||||
*/
|
||||
int telnetsrv_checkbuildver(char *mainexec_buildversion, char **shlib_buildversion) {
|
||||
int telnetsrv_checkbuildver(char *mainexec_buildversion, char **shlib_buildversion)
|
||||
{
|
||||
#ifndef PACKAGE_VERSION
|
||||
#define PACKAGE_VERSION "standalone built: " __DATE__ __TIME__
|
||||
#endif
|
||||
*shlib_buildversion = PACKAGE_VERSION;
|
||||
|
||||
if (strcmp(mainexec_buildversion, *shlib_buildversion) != 0) {
|
||||
fprintf(stderr,"[TELNETSRV] shared lib version %s, doesn't match main version %s, compatibility should be checked\n",
|
||||
mainexec_buildversion,*shlib_buildversion);
|
||||
fprintf(stderr,
|
||||
"[TELNETSRV] shared lib version %s, doesn't match main version %s, compatibility should be checked\n",
|
||||
mainexec_buildversion,
|
||||
*shlib_buildversion);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int telnetsrv_getfarray(loader_shlibfunc_t **farray) {
|
||||
int const num_func_tln_srv = 3;
|
||||
int telnetsrv_getfarray(loader_shlibfunc_t **farray)
|
||||
{
|
||||
int const num_func_tln_srv = 3;
|
||||
*farray = malloc(sizeof(loader_shlibfunc_t) * num_func_tln_srv);
|
||||
(*farray)[0].fname=TELNET_ADDCMD_FNAME;
|
||||
(*farray)[0].fptr=(int (*)(void) )add_telnetcmd;
|
||||
(*farray)[1].fname=TELNET_POLLCMDQ_FNAME;
|
||||
(*farray)[0].fname = TELNET_ADDCMD_FNAME;
|
||||
(*farray)[0].fptr = (int (*)(void))add_telnetcmd;
|
||||
(*farray)[1].fname = TELNET_POLLCMDQ_FNAME;
|
||||
(*farray)[1].fptr = (int (*)(void))poll_telnetcmdq;
|
||||
(*farray)[2].fname = TELNET_PUSHCMD_FNAME;
|
||||
(*farray)[2].fptr = (int (*)(void))telnet_pushcmd;
|
||||
|
||||
@@ -29,17 +29,15 @@
|
||||
* \note
|
||||
* \warning
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
#define TELNETSERVERCODE
|
||||
#include "telnetsrv.h"
|
||||
#define TELNETSRV_LOADER_MAIN
|
||||
#include "telnetsrv_loader.h"
|
||||
|
||||
|
||||
int loader_show_cmd(char *buff, int debug, telnet_printfunc_t prnt);
|
||||
telnetshell_cmddef_t loader_cmdarray[] = {
|
||||
{"show", "[params,modules]", loader_show_cmd, {(webfunc_t)loader_show_cmd}, 0, NULL},
|
||||
@@ -50,36 +48,38 @@ telnetshell_cmddef_t loader_cmdarray[] = {
|
||||
int loader_show_cmd(char *buff, int debug, telnet_printfunc_t prnt)
|
||||
{
|
||||
if (buff == NULL) {
|
||||
prnt("ERROR wrong loader SHOW command...\n");
|
||||
return 0;
|
||||
buff = "modules";
|
||||
}
|
||||
if (debug > 0)
|
||||
prnt( "loader_show_cmd received %s\n",buff);
|
||||
if (debug > 0)
|
||||
prnt("loader_show_cmd received \"%s\"\n", buff);
|
||||
|
||||
if (strcasestr(buff,"params") != NULL) {
|
||||
prnt( "loader parameters:\n");
|
||||
prnt( " Main executable build version: \"%s\"\n", loader_data.mainexec_buildversion);
|
||||
prnt( " Default shared lib path: \"%s\"\n", loader_data.shlibpath);
|
||||
prnt( " Max number of shared lib : %i\n", loader_data.maxshlibs);
|
||||
} else if (strcasestr(buff, "modules") != NULL || buff[0] == 0 || strcasestr(buff, "show") != NULL) {
|
||||
prnt("%i shared lib have been dynamicaly loaded by the oai loader\n", loader_data.numshlibs);
|
||||
for (int i = 0; i < loader_data.numshlibs; i++) {
|
||||
prnt(" Module %i: %s\n", i, loader_data.shlibs[i].name);
|
||||
prnt(" Shared library build version: \"%s\"\n", ((loader_data.shlibs[i].shlib_buildversion == NULL) ? "" : loader_data.shlibs[i].shlib_buildversion));
|
||||
prnt(" Shared library path: \"%s\"\n", loader_data.shlibs[i].thisshlib_path);
|
||||
prnt(" %i function pointers registered:\n", loader_data.shlibs[i].numfunc);
|
||||
for (int j = 0; j < loader_data.shlibs[i].numfunc; j++) {
|
||||
prnt(" function %i %s at %p\n", j, loader_data.shlibs[i].funcarray[j].fname, loader_data.shlibs[i].funcarray[j].fptr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
prnt("%s: wrong loader command...\n", buff);
|
||||
if (strcasestr(buff, "params") != NULL) {
|
||||
prnt("loader parameters:\n");
|
||||
prnt(" Main executable build version: \"%s\"\n", loader_data.mainexec_buildversion);
|
||||
prnt(" Default shared lib path: \"%s\"\n", loader_data.shlibpath);
|
||||
prnt(" Max number of shared lib : %i\n", loader_data.maxshlibs);
|
||||
} else if (strcasestr(buff, "modules") != NULL || buff[0] == 0) {
|
||||
prnt("%i shared lib have been dynamicaly loaded by the oai loader\n", loader_data.numshlibs);
|
||||
for (int i = 0; i < loader_data.numshlibs; i++) {
|
||||
prnt(" Module %i: %s\n", i, loader_data.shlibs[i].name);
|
||||
prnt(" Shared library build version: \"%s\"\n",
|
||||
((loader_data.shlibs[i].shlib_buildversion == NULL) ? "" : loader_data.shlibs[i].shlib_buildversion));
|
||||
prnt(" Shared library path: \"%s\"\n", loader_data.shlibs[i].thisshlib_path);
|
||||
prnt(" %i function pointers registered:\n", loader_data.shlibs[i].numfunc);
|
||||
for (int j = 0; j < loader_data.shlibs[i].numfunc; j++) {
|
||||
prnt(" function %i %s at %p\n",
|
||||
j,
|
||||
loader_data.shlibs[i].funcarray[j].fname,
|
||||
loader_data.shlibs[i].funcarray[j].fptr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
prnt("%s: wrong loader command...\n", buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void add_loader_cmds(void)
|
||||
{
|
||||
|
||||
add_telnetcmd("loader", loader_globalvardef, loader_cmdarray);
|
||||
add_telnetcmd("loader", loader_globalvardef, loader_cmdarray);
|
||||
}
|
||||
|
||||
@@ -59,135 +59,133 @@
|
||||
|
||||
void decode_procstat(char *record, int debug, telnet_printfunc_t prnt, webdatadef_t *tdata)
|
||||
{
|
||||
char prntline[160];
|
||||
char *procfile_fields;
|
||||
char *strtokptr;
|
||||
char *lptr;
|
||||
int fieldcnt;
|
||||
char toksep[2];
|
||||
char prntline[160];
|
||||
char *procfile_fields;
|
||||
char *strtokptr;
|
||||
char *lptr;
|
||||
int fieldcnt;
|
||||
char toksep[2];
|
||||
|
||||
fieldcnt = 0;
|
||||
procfile_fields = strtok_r(record, " ", &strtokptr);
|
||||
lptr = prntline;
|
||||
/*http://man7.org/linux/man-pages/man5/proc.5.html gives the structure of the stat file */
|
||||
int priority = 0;
|
||||
int nice = 0;
|
||||
while (procfile_fields != NULL && fieldcnt < 42) {
|
||||
long int policy;
|
||||
if (strlen(procfile_fields) == 0)
|
||||
continue;
|
||||
fieldcnt++;
|
||||
sprintf(toksep, " ");
|
||||
switch (fieldcnt) {
|
||||
case 1: /* id */
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[0] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, "%9.9s ", procfile_fields);
|
||||
sprintf(toksep, ")");
|
||||
break;
|
||||
case 2: /* name */
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[1] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, "%20.20s ", procfile_fields + 1);
|
||||
break;
|
||||
case 3: // thread state
|
||||
lptr += sprintf(lptr, " %c ", procfile_fields[0]);
|
||||
break;
|
||||
case 14: // time in user mode
|
||||
case 15: // time in kernel mode
|
||||
lptr += sprintf(lptr, "%9.9s ", procfile_fields);
|
||||
break;
|
||||
case 18: // priority column index 2 in tdata, -2 to -100 (1, min to 99, highest prio)
|
||||
priority = strtol(procfile_fields, NULL, 0);
|
||||
case 19: // nice column index 3 in tdata 0 to 39 (-20, highest prio, to 19)
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[fieldcnt - 16] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, "%3.3s ", procfile_fields);
|
||||
nice = strtol(procfile_fields, NULL, 0);
|
||||
break;
|
||||
case 23: // vsize
|
||||
lptr += sprintf(lptr, "%9.9s ", procfile_fields);
|
||||
break;
|
||||
case 39: // processor
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[4] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, " %2.2s ", procfile_fields);
|
||||
break;
|
||||
case 41: // policy
|
||||
lptr += sprintf(lptr, "%3.3s ", procfile_fields);
|
||||
policy = strtol(procfile_fields, NULL, 0);
|
||||
char strschedp[64];
|
||||
switch (policy) {
|
||||
case SCHED_FIFO:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "rt:fifo");
|
||||
priority = priority + 1; // in /proc file system priority 1 to 99 mapped to -2 to -100
|
||||
break;
|
||||
case SCHED_OTHER:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "other");
|
||||
priority = nice - NICE_MIN; // linux nice is -20 to 19
|
||||
break;
|
||||
case SCHED_IDLE:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "idle");
|
||||
priority = 2 * (NICE_MAX - NICE_MIN + 1);
|
||||
break;
|
||||
case SCHED_BATCH:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "batch");
|
||||
priority = (NICE_MAX - NICE_MIN + 1) + nice - NICE_MIN;
|
||||
break;
|
||||
case SCHED_RR:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "rt:rr");
|
||||
priority = priority - 99;
|
||||
break;
|
||||
fieldcnt = 0;
|
||||
procfile_fields = strtok_r(record, " ", &strtokptr);
|
||||
lptr = prntline;
|
||||
/*http://man7.org/linux/man-pages/man5/proc.5.html gives the structure of the stat file */
|
||||
int priority = 0;
|
||||
int nice = 0;
|
||||
while (procfile_fields != NULL && fieldcnt < 42) {
|
||||
long int policy;
|
||||
if (strlen(procfile_fields) == 0)
|
||||
continue;
|
||||
fieldcnt++;
|
||||
sprintf(toksep, " ");
|
||||
switch (fieldcnt) {
|
||||
case 1: /* id */
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[0] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, "%9.9s ", procfile_fields);
|
||||
sprintf(toksep, ")");
|
||||
break;
|
||||
case 2: /* name */
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[1] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, "%20.20s ", procfile_fields + 1);
|
||||
break;
|
||||
case 3: // thread state
|
||||
lptr += sprintf(lptr, " %c ", procfile_fields[0]);
|
||||
break;
|
||||
case 14: // time in user mode
|
||||
case 15: // time in kernel mode
|
||||
lptr += sprintf(lptr, "%9.9s ", procfile_fields);
|
||||
break;
|
||||
case 18: // priority column index 2 in tdata, -2 to -100 (1, min to 99, highest prio)
|
||||
priority = strtol(procfile_fields, NULL, 0);
|
||||
case 19: // nice column index 3 in tdata 0 to 39 (-20, highest prio, to 19)
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[fieldcnt - 16] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, "%3.3s ", procfile_fields);
|
||||
nice = strtol(procfile_fields, NULL, 0);
|
||||
break;
|
||||
case 23: // vsize
|
||||
lptr += sprintf(lptr, "%9.9s ", procfile_fields);
|
||||
break;
|
||||
case 39: // processor
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[4] = strdup(procfile_fields);
|
||||
}
|
||||
lptr += sprintf(lptr, " %2.2s ", procfile_fields);
|
||||
break;
|
||||
case 41: // policy
|
||||
lptr += sprintf(lptr, "%3.3s ", procfile_fields);
|
||||
policy = strtol(procfile_fields, NULL, 0);
|
||||
char strschedp[64];
|
||||
switch (policy) {
|
||||
case SCHED_FIFO:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "rt:fifo");
|
||||
priority = priority + 1; // in /proc file system priority 1 to 99 mapped to -2 to -100
|
||||
break;
|
||||
case SCHED_OTHER:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "other");
|
||||
priority = nice - NICE_MIN; // linux nice is -20 to 19
|
||||
break;
|
||||
case SCHED_IDLE:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "idle");
|
||||
priority = 2 * (NICE_MAX - NICE_MIN + 1);
|
||||
break;
|
||||
case SCHED_BATCH:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "batch");
|
||||
priority = (NICE_MAX - NICE_MIN + 1) + nice - NICE_MIN;
|
||||
break;
|
||||
case SCHED_RR:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "rt:rr");
|
||||
priority = priority - 99;
|
||||
break;
|
||||
#ifdef SCHED_DEADLINE
|
||||
case SCHED_DEADLINE:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "rt:deadline");
|
||||
break;
|
||||
case SCHED_DEADLINE:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "rt:deadline");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "????");
|
||||
break;
|
||||
}
|
||||
lptr += sprintf(lptr, "%s ", strschedp);
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[5] = strdup(strschedp);
|
||||
tdata->lines[tdata->numlines].val[6] = malloc(10);
|
||||
snprintf(tdata->lines[tdata->numlines].val[6], 9, "%i", priority);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} /* switch on fieldcnr */
|
||||
procfile_fields = strtok_r(NULL, toksep, &strtokptr);
|
||||
} /* while on proc_fields != NULL */
|
||||
prnt("%s\n", prntline);
|
||||
if (tdata != NULL) {
|
||||
tdata->numlines++;
|
||||
}
|
||||
default:
|
||||
snprintf(strschedp, sizeof(strschedp), "%s ", "????");
|
||||
break;
|
||||
}
|
||||
lptr += sprintf(lptr, "%s ", strschedp);
|
||||
if (tdata != NULL) {
|
||||
tdata->lines[tdata->numlines].val[5] = strdup(strschedp);
|
||||
tdata->lines[tdata->numlines].val[6] = malloc(10);
|
||||
snprintf(tdata->lines[tdata->numlines].val[6], 9, "%i", priority);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} /* switch on fieldcnr */
|
||||
procfile_fields = strtok_r(NULL, toksep, &strtokptr);
|
||||
} /* while on proc_fields != NULL */
|
||||
prnt("%s\n", prntline);
|
||||
if (tdata != NULL) {
|
||||
tdata->numlines++;
|
||||
}
|
||||
} /*decode_procstat */
|
||||
|
||||
void read_statfile(char *fname, int debug, telnet_printfunc_t prnt, webdatadef_t *tdata)
|
||||
{
|
||||
FILE *procfile;
|
||||
char arecord[1024];
|
||||
FILE *procfile;
|
||||
char arecord[1024];
|
||||
|
||||
procfile=fopen(fname,"r");
|
||||
if (procfile == NULL)
|
||||
{
|
||||
prnt("Error: Couldn't open %s %i %s\n",fname,errno,strerror(errno));
|
||||
return;
|
||||
}
|
||||
if ( fgets(arecord,sizeof(arecord),procfile) == NULL)
|
||||
{
|
||||
prnt("Error: Nothing read from %s %i %s\n",fname,errno,strerror(errno));
|
||||
fclose(procfile);
|
||||
return;
|
||||
}
|
||||
procfile = fopen(fname, "r");
|
||||
if (procfile == NULL) {
|
||||
prnt("Error: Couldn't open %s %i %s\n", fname, errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
if (fgets(arecord, sizeof(arecord), procfile) == NULL) {
|
||||
prnt("Error: Nothing read from %s %i %s\n", fname, errno, strerror(errno));
|
||||
fclose(procfile);
|
||||
decode_procstat(arecord, debug, prnt, tdata);
|
||||
return;
|
||||
}
|
||||
fclose(procfile);
|
||||
decode_procstat(arecord, debug, prnt, tdata);
|
||||
}
|
||||
|
||||
int nullprnt(char *fmt, ...)
|
||||
@@ -197,7 +195,7 @@ int nullprnt(char *fmt, ...)
|
||||
|
||||
void proccmd_get_threaddata(char *buf, int debug, telnet_printfunc_t fprnt, webdatadef_t *tdata)
|
||||
{
|
||||
char aname[256];
|
||||
char aname[256];
|
||||
|
||||
DIR *proc_dir;
|
||||
struct dirent *entry;
|
||||
@@ -286,7 +284,9 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun
|
||||
} else {
|
||||
CLEAR_LOG_OPTION(optbit);
|
||||
}
|
||||
printfunc("%s log option %s\n", logsdata->lines[0].val[0], (strcmp(logsdata->lines[0].val[1], "true") == 0) ? "enabled" : "disabled");
|
||||
printfunc("%s log option %s\n",
|
||||
logsdata->lines[0].val[0],
|
||||
(strcmp(logsdata->lines[0].val[1], "true") == 0) ? "enabled" : "disabled");
|
||||
}
|
||||
}
|
||||
if (strcasestr(cmdbuff, "dbgopt") != NULL) {
|
||||
@@ -334,7 +334,9 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data, telnet_printfun
|
||||
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[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) ? "true" : "false";
|
||||
}
|
||||
@@ -388,124 +390,126 @@ int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt)
|
||||
prnt("ERROR wrong softmodem SHOW command...\n");
|
||||
return 0;
|
||||
}
|
||||
if (debug > 0)
|
||||
prnt(" proccmd_show received %s\n",buf);
|
||||
if (strcasestr(buf,"thread") != NULL) {
|
||||
print_threads(buf,debug,prnt);
|
||||
}
|
||||
if (strcasestr(buf,"loglvl") != NULL) {
|
||||
prnt("\n component level enabled output\n");
|
||||
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
|
||||
if (g_log->log_component[i].name != NULL) {
|
||||
prnt("%02i %17.17s:%10.10s %s %s\n",i ,g_log->log_component[i].name,
|
||||
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),
|
||||
((g_log->log_component[i].level>=0)?"Y":"N"),
|
||||
((g_log->log_component[i].filelog>0)?g_log->log_component[i].filelog_name:"stdout"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strcasestr(buf,"logopt") != NULL) {
|
||||
prnt("\n option enabled\n");
|
||||
for (int i=0; log_options[i].name != NULL; i++) {
|
||||
prnt("%02i %17.17s %10.10s \n",i ,log_options[i].name,
|
||||
((g_log->flag & log_options[i].value)?"Y":"N") );
|
||||
}
|
||||
}
|
||||
if (strcasestr(buf,"dbgopt") != NULL) {
|
||||
prnt("\n module debug dumpfile\n");
|
||||
for (int i=0; log_maskmap[i].name != NULL ; i++) {
|
||||
prnt("%02i %17.17s %5.5s %5.5s\n",i ,log_maskmap[i].name,
|
||||
((g_log->debug_mask & log_maskmap[i].value)?"Y":"N"),
|
||||
((g_log->dump_mask & log_maskmap[i].value)?"Y":"N") );
|
||||
}
|
||||
}
|
||||
if (strcasestr(buf,"config") != NULL) {
|
||||
prnt("Command line arguments:\n");
|
||||
for (int i=0; i < config_get_if()->argc; i++) {
|
||||
prnt(" %02i %s\n",i ,config_get_if()->argv[i]);
|
||||
}
|
||||
prnt("Config module flags ( -O <cfg source>:<xxx>:dbgl<flags>): 0x%08x\n", config_get_if()->rtflags);
|
||||
if (debug > 0)
|
||||
prnt(" proccmd_show received %s\n", buf);
|
||||
if (strcasestr(buf, "thread") != NULL) {
|
||||
print_threads(buf, debug, prnt);
|
||||
}
|
||||
if (strcasestr(buf, "loglvl") != NULL) {
|
||||
prnt("\n component level enabled output\n");
|
||||
for (int i = MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) {
|
||||
if (g_log->log_component[i].name != NULL) {
|
||||
prnt("%02i %17.17s:%10.10s %s %s\n",
|
||||
i,
|
||||
g_log->log_component[i].name,
|
||||
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),
|
||||
((g_log->log_component[i].level >= 0) ? "Y" : "N"),
|
||||
((g_log->log_component[i].filelog > 0) ? g_log->log_component[i].filelog_name : "stdout"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strcasestr(buf, "logopt") != NULL) {
|
||||
prnt("\n option enabled\n");
|
||||
for (int i = 0; log_options[i].name != NULL; i++) {
|
||||
prnt("%02i %17.17s %10.10s \n", i, log_options[i].name, ((g_log->flag & log_options[i].value) ? "Y" : "N"));
|
||||
}
|
||||
}
|
||||
if (strcasestr(buf, "dbgopt") != NULL) {
|
||||
prnt("\n module debug dumpfile\n");
|
||||
for (int i = 0; log_maskmap[i].name != NULL; i++) {
|
||||
prnt("%02i %17.17s %5.5s %5.5s\n",
|
||||
i,
|
||||
log_maskmap[i].name,
|
||||
((g_log->debug_mask & log_maskmap[i].value) ? "Y" : "N"),
|
||||
((g_log->dump_mask & log_maskmap[i].value) ? "Y" : "N"));
|
||||
}
|
||||
}
|
||||
if (strcasestr(buf, "config") != NULL) {
|
||||
prnt("Command line arguments:\n");
|
||||
for (int i = 0; i < config_get_if()->argc; i++) {
|
||||
prnt(" %02i %s\n", i, config_get_if()->argv[i]);
|
||||
}
|
||||
prnt("Config module flags ( -O <cfg source>:<xxx>:dbgl<flags>): 0x%08x\n", config_get_if()->rtflags);
|
||||
|
||||
prnt(" Print config debug msg, params values (flag %u): %s\n",CONFIG_PRINTPARAMS,
|
||||
((config_get_if()->rtflags & CONFIG_PRINTPARAMS) ? "Y" : "N") );
|
||||
prnt(" Print config debug msg, memory management(flag %u): %s\n",CONFIG_DEBUGPTR,
|
||||
((config_get_if()->rtflags & CONFIG_DEBUGPTR) ? "Y" : "N") );
|
||||
prnt(" Print config debug msg, command line processing (flag %u): %s\n",CONFIG_DEBUGCMDLINE,
|
||||
((config_get_if()->rtflags & CONFIG_DEBUGCMDLINE) ? "Y" : "N") );
|
||||
prnt(" Don't exit if param check fails (flag %u): %s\n",CONFIG_NOABORTONCHKF,
|
||||
((config_get_if()->rtflags & CONFIG_NOABORTONCHKF) ? "Y" : "N") );
|
||||
prnt("Config source: %s, parameters:\n",CONFIG_GETSOURCE );
|
||||
for (int i=0; i < config_get_if()->num_cfgP; i++) {
|
||||
prnt(" %02i %s\n",i ,config_get_if()->cfgP[i]);
|
||||
}
|
||||
prnt("Softmodem components:\n");
|
||||
prnt(" %02i Ru(s)\n", RC.nb_RU);
|
||||
prnt(" %02i lte RRc(s), %02i NbIoT RRC(s)\n", RC.nb_inst, RC.nb_nb_iot_rrc_inst);
|
||||
prnt(" %02i lte MACRLC(s), %02i NbIoT MACRLC(s)\n", RC.nb_macrlc_inst, RC.nb_nb_iot_macrlc_inst);
|
||||
prnt(" %02i lte L1, %02i NbIoT L1\n", RC.nb_L1_inst, RC.nb_nb_iot_L1_inst);
|
||||
prnt(" Print config debug msg, params values (flag %u): %s\n",
|
||||
CONFIG_PRINTPARAMS,
|
||||
((config_get_if()->rtflags & CONFIG_PRINTPARAMS) ? "Y" : "N"));
|
||||
prnt(" Print config debug msg, memory management(flag %u): %s\n",
|
||||
CONFIG_DEBUGPTR,
|
||||
((config_get_if()->rtflags & CONFIG_DEBUGPTR) ? "Y" : "N"));
|
||||
prnt(" Print config debug msg, command line processing (flag %u): %s\n",
|
||||
CONFIG_DEBUGCMDLINE,
|
||||
((config_get_if()->rtflags & CONFIG_DEBUGCMDLINE) ? "Y" : "N"));
|
||||
prnt(" Don't exit if param check fails (flag %u): %s\n",
|
||||
CONFIG_NOABORTONCHKF,
|
||||
((config_get_if()->rtflags & CONFIG_NOABORTONCHKF) ? "Y" : "N"));
|
||||
prnt("Config source: %s, parameters:\n", CONFIG_GETSOURCE);
|
||||
for (int i = 0; i < config_get_if()->num_cfgP; i++) {
|
||||
prnt(" %02i %s\n", i, config_get_if()->cfgP[i]);
|
||||
}
|
||||
prnt("Softmodem components:\n");
|
||||
prnt(" %02i Ru(s)\n", RC.nb_RU);
|
||||
prnt(" %02i lte RRc(s), %02i NbIoT RRC(s)\n", RC.nb_inst, RC.nb_nb_iot_rrc_inst);
|
||||
prnt(" %02i lte MACRLC(s), %02i NbIoT MACRLC(s)\n", RC.nb_macrlc_inst, RC.nb_nb_iot_macrlc_inst);
|
||||
prnt(" %02i lte L1, %02i NbIoT L1\n", RC.nb_L1_inst, RC.nb_nb_iot_L1_inst);
|
||||
|
||||
for(int i=0; i<RC.nb_inst; i++) {
|
||||
prnt(" lte RRC %i: %02i CC(s) \n",i,((RC.nb_CC == NULL)?0:RC.nb_CC[i]));
|
||||
}
|
||||
for(int i=0; i<RC.nb_L1_inst; i++) {
|
||||
prnt(" lte L1 %i: %02i CC(s)\n",i,((RC.nb_L1_CC == NULL)?0:RC.nb_L1_CC[i]));
|
||||
}
|
||||
for(int i=0; i<RC.nb_macrlc_inst; i++) {
|
||||
prnt(" lte macrlc %i: %02i CC(s)\n",i,((RC.nb_mac_CC == NULL)?0:RC.nb_mac_CC[i]));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < RC.nb_inst; i++) {
|
||||
prnt(" lte RRC %i: %02i CC(s) \n", i, ((RC.nb_CC == NULL) ? 0 : RC.nb_CC[i]));
|
||||
}
|
||||
for (int i = 0; i < RC.nb_L1_inst; i++) {
|
||||
prnt(" lte L1 %i: %02i CC(s)\n", i, ((RC.nb_L1_CC == NULL) ? 0 : RC.nb_L1_CC[i]));
|
||||
}
|
||||
for (int i = 0; i < RC.nb_macrlc_inst; i++) {
|
||||
prnt(" lte macrlc %i: %02i CC(s)\n", i, ((RC.nb_mac_CC == NULL) ? 0 : RC.nb_mac_CC[i]));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int proccmd_thread(char *buf, int debug, telnet_printfunc_t prnt)
|
||||
{
|
||||
int bv1,bv2;
|
||||
int res;
|
||||
char sv1[64];
|
||||
int bv1, bv2;
|
||||
int res;
|
||||
char sv1[64];
|
||||
|
||||
if (buf == NULL) {
|
||||
prnt("ERROR wrong thread command...\n");
|
||||
if (buf == NULL) {
|
||||
prnt("ERROR wrong thread command...\n");
|
||||
return 0;
|
||||
}
|
||||
bv1 = 0;
|
||||
bv2 = 0;
|
||||
sv1[0] = 0;
|
||||
if (debug > 0)
|
||||
prnt("proccmd_thread received %s\n", buf);
|
||||
if (strcasestr(buf, "help") != NULL) {
|
||||
prnt(PROCCMD_THREAD_HELP_STRING);
|
||||
return 0;
|
||||
}
|
||||
res = sscanf(buf, "%i %9s %i", &bv1, sv1, &bv2);
|
||||
if (debug > 0)
|
||||
prnt(" proccmd_thread: %i params = %i,%s,%i\n", res, bv1, sv1, bv2);
|
||||
if (res != 3) {
|
||||
print_threads(buf, debug, prnt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcasestr(sv1, "prio") != NULL) {
|
||||
set_sched(0, bv1, bv2);
|
||||
} else if (strcasestr(sv1, "aff") != NULL) {
|
||||
set_affinity(0, bv1, bv2);
|
||||
} else {
|
||||
prnt("%s is not a valid thread command\n", sv1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bv1=0;
|
||||
bv2=0;
|
||||
sv1[0]=0;
|
||||
if (debug > 0)
|
||||
prnt("proccmd_thread received %s\n",buf);
|
||||
if (strcasestr(buf,"help") != NULL) {
|
||||
prnt(PROCCMD_THREAD_HELP_STRING);
|
||||
return 0;
|
||||
}
|
||||
res=sscanf(buf,"%i %9s %i",&bv1,sv1,&bv2);
|
||||
if (debug > 0)
|
||||
prnt(" proccmd_thread: %i params = %i,%s,%i\n",res,bv1,sv1,bv2);
|
||||
if(res != 3)
|
||||
{
|
||||
print_threads(buf, debug, prnt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (strcasestr(sv1,"prio") != NULL)
|
||||
{
|
||||
set_sched(0,bv1, bv2);
|
||||
}
|
||||
else if (strcasestr(sv1,"aff") != NULL)
|
||||
{
|
||||
set_affinity(0,bv1, bv2);
|
||||
}
|
||||
else
|
||||
{
|
||||
prnt("%s is not a valid thread command\n",sv1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int proccmd_exit(char *buf, int debug, telnet_printfunc_t prnt)
|
||||
{
|
||||
if (debug > 0)
|
||||
prnt("process module received %s\n",buf);
|
||||
exit_fun("telnet server received exit command\n");
|
||||
return 0;
|
||||
if (debug > 0)
|
||||
prnt("process module received %s\n", buf);
|
||||
exit_fun("telnet server received exit command\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int proccmd_restart(char *buf, int debug, telnet_printfunc_t prnt)
|
||||
@@ -520,154 +524,157 @@ int proccmd_restart(char *buf, int debug, telnet_printfunc_t prnt)
|
||||
|
||||
int proccmd_log(char *buf, int debug, telnet_printfunc_t prnt)
|
||||
{
|
||||
int idx1=0;
|
||||
int idx2=NUM_LOG_LEVEL-1;
|
||||
char *logsubcmd=NULL;
|
||||
int idx1 = 0;
|
||||
int idx2 = NUM_LOG_LEVEL - 1;
|
||||
char *logsubcmd = NULL;
|
||||
|
||||
int s = sscanf(buf,"%ms %i-%i\n",&logsubcmd, &idx1,&idx2);
|
||||
|
||||
if (debug > 0)
|
||||
prnt( "proccmd_log received %s\n s=%i sub command %s\n",buf,s,((logsubcmd==NULL)?"":logsubcmd));
|
||||
if (buf == NULL) {
|
||||
prnt("ERROR wrong \"log\" command...\n");
|
||||
return 0;
|
||||
}
|
||||
int s = sscanf(buf, "%ms %i-%i\n", &logsubcmd, &idx1, &idx2);
|
||||
|
||||
if (s == 1 && logsubcmd != NULL) {
|
||||
if (strcasestr(logsubcmd,"online") != NULL) {
|
||||
if (strcasestr(buf,"noonline") != NULL) {
|
||||
set_glog_onlinelog(0);
|
||||
prnt("online logging disabled\n",buf);
|
||||
} else {
|
||||
set_glog_onlinelog(1);
|
||||
prnt("online logging enabled\n",buf);
|
||||
}
|
||||
}
|
||||
else if (strcasestr(logsubcmd,"show") != NULL) {
|
||||
prnt("Available log levels: \n ");
|
||||
for (int i=0; log_level_names[i].name != NULL; i++)
|
||||
prnt("%s ",log_level_names[i].name);
|
||||
prnt("\n\n");
|
||||
prnt("Available display options: \n ");
|
||||
for (int i=0; log_options[i].name != NULL; i++)
|
||||
prnt("%s ",log_options[i].name);
|
||||
prnt("\n\n");
|
||||
prnt("Available debug and dump options: \n ");
|
||||
for (int i=0; log_maskmap[i].name != NULL; i++)
|
||||
prnt("%s ",log_maskmap[i].name);
|
||||
prnt("\n\n");
|
||||
proccmd_show("loglvl",debug,prnt);
|
||||
proccmd_show("logopt",debug,prnt);
|
||||
proccmd_show("dbgopt",debug,prnt);
|
||||
}
|
||||
else if (strcasestr(logsubcmd,"help") != NULL) {
|
||||
prnt(PROCCMD_LOG_HELP_STRING);
|
||||
if (debug > 0)
|
||||
prnt("proccmd_log received %s\n s=%i sub command %s\n", buf, s, ((logsubcmd == NULL) ? "" : logsubcmd));
|
||||
|
||||
if (s == 1 && logsubcmd != NULL) {
|
||||
if (strcasestr(logsubcmd, "online") != NULL) {
|
||||
if (strcasestr(buf, "noonline") != NULL) {
|
||||
set_glog_onlinelog(0);
|
||||
prnt("online logging disabled\n", buf);
|
||||
} else {
|
||||
prnt("%s: wrong log command...\n",logsubcmd);
|
||||
set_glog_onlinelog(1);
|
||||
prnt("online logging enabled\n", buf);
|
||||
}
|
||||
} else if ( s == 2 && logsubcmd != NULL) {
|
||||
char *opt=NULL;
|
||||
char *logparam=NULL;
|
||||
int l;
|
||||
int optbit;
|
||||
} else if (strcasestr(logsubcmd, "show") != NULL) {
|
||||
prnt("Available log levels: \n ");
|
||||
for (int i = 0; log_level_names[i].name != NULL; i++)
|
||||
prnt("%s ", log_level_names[i].name);
|
||||
prnt("\n\n");
|
||||
prnt("Available display options: \n ");
|
||||
for (int i = 0; log_options[i].name != NULL; i++)
|
||||
prnt("%s ", log_options[i].name);
|
||||
prnt("\n\n");
|
||||
prnt("Available debug and dump options: \n ");
|
||||
for (int i = 0; log_maskmap[i].name != NULL; i++)
|
||||
prnt("%s ", log_maskmap[i].name);
|
||||
prnt("\n\n");
|
||||
proccmd_show("loglvl", debug, prnt);
|
||||
proccmd_show("logopt", debug, prnt);
|
||||
proccmd_show("dbgopt", debug, prnt);
|
||||
} else if (strcasestr(logsubcmd, "help") != NULL) {
|
||||
prnt(PROCCMD_LOG_HELP_STRING);
|
||||
} else {
|
||||
prnt("%s: wrong log command...\n", logsubcmd);
|
||||
}
|
||||
} else if (s == 2 && logsubcmd != NULL) {
|
||||
char *opt = NULL;
|
||||
char *logparam = NULL;
|
||||
int l;
|
||||
int optbit;
|
||||
|
||||
l=sscanf(logsubcmd,"%m[^'_']_%ms",&logparam,&opt);
|
||||
if (l == 2 && strcmp(logparam,"print") == 0){
|
||||
optbit=map_str_to_int(log_options,opt);
|
||||
if (optbit < 0) {
|
||||
prnt("option %s unknown\n",opt);
|
||||
} else {
|
||||
if (idx1 > 0)
|
||||
SET_LOG_OPTION(optbit);
|
||||
else
|
||||
CLEAR_LOG_OPTION(optbit);
|
||||
proccmd_show("logopt",debug,prnt);
|
||||
}
|
||||
}
|
||||
else if (l == 2 && strcmp(logparam,"debug") == 0){
|
||||
optbit=map_str_to_int(log_maskmap,opt);
|
||||
if (optbit < 0) {
|
||||
prnt("module %s unknown\n",opt);
|
||||
} else {
|
||||
if (idx1 > 0)
|
||||
SET_LOG_DEBUG(optbit);
|
||||
else
|
||||
CLEAR_LOG_DEBUG(optbit);
|
||||
proccmd_show("dbgopt",debug,prnt);
|
||||
}
|
||||
}
|
||||
else if (l == 2 && strcmp(logparam,"dump") == 0){
|
||||
optbit=map_str_to_int(log_maskmap,opt);
|
||||
if (optbit < 0) {
|
||||
prnt("module %s unknown\n",opt);
|
||||
} else {
|
||||
if (idx1 > 0)
|
||||
SET_LOG_DUMP(optbit);
|
||||
else
|
||||
CLEAR_LOG_DUMP(optbit);
|
||||
proccmd_show("dump", debug, prnt);
|
||||
}
|
||||
}
|
||||
if (logparam != NULL) free(logparam);
|
||||
if (opt != NULL) free(opt);
|
||||
} else if ( s == 3 && logsubcmd != NULL) {
|
||||
int level, enable,filelog;
|
||||
char *tmpstr=NULL;
|
||||
char *logparam=NULL;
|
||||
int l;
|
||||
|
||||
level = OAILOG_DISABLE - 1;
|
||||
filelog = -1;
|
||||
enable=-1;
|
||||
l=sscanf(logsubcmd,"%m[^'_']_%m[^'_']",&logparam,&tmpstr);
|
||||
if (debug > 0)
|
||||
prnt("l=%i, %s %s\n",l,((logparam==NULL)?"\"\"":logparam), ((tmpstr==NULL)?"\"\"":tmpstr));
|
||||
if (l ==2 ) {
|
||||
if (strcmp(logparam,"level") == 0) {
|
||||
level=map_str_to_int(log_level_names,tmpstr);
|
||||
if (level < 0) {
|
||||
prnt("level %s unknown\n",tmpstr);
|
||||
level=OAILOG_DISABLE - 1;
|
||||
}
|
||||
} else {
|
||||
prnt("%s%s unknown log sub command \n",logparam, tmpstr);
|
||||
}
|
||||
} else if (l ==1 ) {
|
||||
if (strcmp(logparam,"enable") == 0) {
|
||||
enable=1;
|
||||
} else if (strcmp(logparam,"disable") == 0) {
|
||||
level=OAILOG_DISABLE;
|
||||
} else if (strcmp(logparam,"file") == 0) {
|
||||
filelog = 1 ;
|
||||
} else if (strcmp(logparam,"nofile") == 0) {
|
||||
filelog = 0 ;
|
||||
} else {
|
||||
prnt("%s%s unknown log sub command \n",logparam, tmpstr);
|
||||
}
|
||||
l = sscanf(logsubcmd, "%m[^'_']_%ms", &logparam, &opt);
|
||||
if (l == 2 && strcmp(logparam, "print") == 0) {
|
||||
optbit = map_str_to_int(log_options, opt);
|
||||
if (optbit < 0) {
|
||||
prnt("option %s unknown\n", opt);
|
||||
} else {
|
||||
if (idx1 > 0)
|
||||
SET_LOG_OPTION(optbit);
|
||||
else
|
||||
CLEAR_LOG_OPTION(optbit);
|
||||
proccmd_show("logopt", debug, prnt);
|
||||
}
|
||||
} else if (l == 2 && strcmp(logparam, "debug") == 0) {
|
||||
optbit = map_str_to_int(log_maskmap, opt);
|
||||
if (optbit < 0) {
|
||||
prnt("module %s unknown\n", opt);
|
||||
} else {
|
||||
if (idx1 > 0)
|
||||
SET_LOG_DEBUG(optbit);
|
||||
else
|
||||
CLEAR_LOG_DEBUG(optbit);
|
||||
proccmd_show("dbgopt", debug, prnt);
|
||||
}
|
||||
} else if (l == 2 && strcmp(logparam, "dump") == 0) {
|
||||
optbit = map_str_to_int(log_maskmap, opt);
|
||||
if (optbit < 0) {
|
||||
prnt("module %s unknown\n", opt);
|
||||
} else {
|
||||
if (idx1 > 0)
|
||||
SET_LOG_DUMP(optbit);
|
||||
else
|
||||
CLEAR_LOG_DUMP(optbit);
|
||||
proccmd_show("dump", debug, prnt);
|
||||
}
|
||||
}
|
||||
if (logparam != NULL)
|
||||
free(logparam);
|
||||
if (opt != NULL)
|
||||
free(opt);
|
||||
} else if (s == 3 && logsubcmd != NULL) {
|
||||
int level, enable, filelog;
|
||||
char *tmpstr = NULL;
|
||||
char *logparam = NULL;
|
||||
int l;
|
||||
|
||||
level = OAILOG_DISABLE - 1;
|
||||
filelog = -1;
|
||||
enable = -1;
|
||||
l = sscanf(logsubcmd, "%m[^'_']_%m[^'_']", &logparam, &tmpstr);
|
||||
if (debug > 0)
|
||||
prnt("l=%i, %s %s\n", l, ((logparam == NULL) ? "\"\"" : logparam), ((tmpstr == NULL) ? "\"\"" : tmpstr));
|
||||
if (l == 2) {
|
||||
if (strcmp(logparam, "level") == 0) {
|
||||
level = map_str_to_int(log_level_names, tmpstr);
|
||||
prnt("%s unknown log sub command \n", logsubcmd);
|
||||
if (level < 0) {
|
||||
prnt("level %s unknown\n", tmpstr);
|
||||
level = OAILOG_DISABLE - 1;
|
||||
}
|
||||
} else {
|
||||
prnt("%s%s unknown log sub command \n", logparam, tmpstr);
|
||||
}
|
||||
if (logparam != NULL) free(logparam);
|
||||
if (tmpstr != NULL) free(tmpstr);
|
||||
for (int i=idx1; i<=idx2 ; i++) {
|
||||
if (level >= OAILOG_DISABLE)
|
||||
set_log(i, level);
|
||||
else if ( enable == 1)
|
||||
set_log(i,g_log->log_component[i].savedlevel);
|
||||
else if ( filelog == 1 ) {
|
||||
set_component_filelog(i);
|
||||
} else if ( filelog == 0 ) {
|
||||
close_component_filelog(i);
|
||||
}
|
||||
|
||||
} else if (l == 1) {
|
||||
if (strcmp(logparam, "enable") == 0) {
|
||||
enable = 1;
|
||||
} else if (strcmp(logparam, "disable") == 0) {
|
||||
level = OAILOG_DISABLE;
|
||||
} else if (strcmp(logparam, "file") == 0) {
|
||||
filelog = 1;
|
||||
} else if (strcmp(logparam, "nofile") == 0) {
|
||||
filelog = 0;
|
||||
} else {
|
||||
prnt("%s%s unknown log sub command \n", logparam, tmpstr);
|
||||
}
|
||||
proccmd_show("loglvl",debug,prnt);
|
||||
} else {
|
||||
prnt("%s: wrong log command...\n",buf);
|
||||
}
|
||||
} else {
|
||||
level = map_str_to_int(log_level_names, tmpstr);
|
||||
prnt("%s unknown log sub command \n", logsubcmd);
|
||||
}
|
||||
if (logparam != NULL)
|
||||
free(logparam);
|
||||
if (tmpstr != NULL)
|
||||
free(tmpstr);
|
||||
for (int i = idx1; i <= idx2; i++) {
|
||||
if (level >= OAILOG_DISABLE)
|
||||
set_log(i, level);
|
||||
else if (enable == 1)
|
||||
set_log(i, g_log->log_component[i].savedlevel);
|
||||
else if (filelog == 1) {
|
||||
set_component_filelog(i);
|
||||
} else if (filelog == 0) {
|
||||
close_component_filelog(i);
|
||||
}
|
||||
}
|
||||
proccmd_show("loglvl", debug, prnt);
|
||||
} else {
|
||||
prnt("%s: wrong log command...\n", buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
|
||||
void add_softmodem_cmds(void)
|
||||
{
|
||||
add_telnetcmd("softmodem",proc_vardef,proc_cmdarray);
|
||||
add_telnetcmd("softmodem", proc_vardef, proc_cmdarray);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <ulfius.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
#include <gnutls/x509.h>
|
||||
|
||||
#include "common/config/config_userapi.h"
|
||||
#include "common/utils/LOG/log.h"
|
||||
#include "common/utils/websrv/websrv.h"
|
||||
@@ -49,8 +50,9 @@ static websrv_params_t websrvparams;
|
||||
static telnetsrv_params_t *dummy_telnetsrv_params = NULL;
|
||||
paramdef_t websrvoptions[] = {
|
||||
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
/* configuration parameters for telnet utility */
|
||||
/* optname helpstr paramflags XXXptr defXXXval type numelt */
|
||||
/* configuration parameters for telnet utility */
|
||||
/* optname helpstr paramflags XXXptr defXXXval type
|
||||
numelt */
|
||||
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
{"listenaddr", "<listen ip address>\n", 0, uptr : &websrvparams.listenaddr, defstrval : "0.0.0.0", TYPE_IPV4ADDR, 0},
|
||||
{"listenport", "<local port>\n", 0, uptr : &(websrvparams.listenport), defuintval : 8090, TYPE_UINT, 0},
|
||||
@@ -137,7 +139,10 @@ int websrv_callback_auth(const struct _u_request *request, struct _u_response *r
|
||||
issuer_dn[libuf] = '\0';
|
||||
LOG_I(UTIL, "[websrv] dn of the client: %s, dn of the issuer: %s \n", dn, issuer_dn);
|
||||
} else {
|
||||
LOG_I(UTIL, "[websrv] dn of the client: %s, dn of the issuer: %s \n", (dn == NULL) ? "null" : dn, (issuer_dn == NULL) ? "null" : issuer_dn);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] dn of the client: %s, dn of the issuer: %s \n",
|
||||
(dn == NULL) ? "null" : dn,
|
||||
(issuer_dn == NULL) ? "null" : issuer_dn);
|
||||
ulfius_set_string_body_response(response, 400, "Couldn't authenticate client");
|
||||
}
|
||||
free(dn);
|
||||
@@ -210,7 +215,19 @@ int websrv_callback_set_moduleparams(const struct _u_request *request, struct _u
|
||||
char *cname;
|
||||
char *ctype;
|
||||
int cmod;
|
||||
ures = json_unpack_ex(jelem, &jerror, 0, "{s:s,s:{s:s,s:s,s:b}}", "value", &cvalue, "col", "name", &cname, "type", &ctype, "modifiable", &cmod);
|
||||
ures = json_unpack_ex(jelem,
|
||||
&jerror,
|
||||
0,
|
||||
"{s:s,s:{s:s,s:s,s:b}}",
|
||||
"value",
|
||||
&cvalue,
|
||||
"col",
|
||||
"name",
|
||||
&cname,
|
||||
"type",
|
||||
&ctype,
|
||||
"modifiable",
|
||||
&cmod);
|
||||
if (ures != 0) {
|
||||
websrv_printf("cannot unpack json element %i %s\n", i, jerror.text);
|
||||
} else {
|
||||
@@ -315,7 +332,11 @@ int websrv_callback_newmodule(const struct _u_request *request, struct _u_respon
|
||||
}
|
||||
telnetsrv_params_t *telnetparams = (telnetsrv_params_t *)user_data;
|
||||
for (int i = 0; i < u_map_count(request->map_url); i++) {
|
||||
LOG_I(UTIL, "[websrv] url element %i %s : %s\n", i, u_map_enum_keys(request->map_url)[i], u_map_enum_values(request->map_url)[i]);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] url element %i %s : %s\n",
|
||||
i,
|
||||
u_map_enum_keys(request->map_url)[i],
|
||||
u_map_enum_values(request->map_url)[i]);
|
||||
if (strcmp(u_map_enum_keys(request->map_url)[i], "module") == 0) {
|
||||
for (int j = 0; telnetparams->CmdParsers[j].cmd != NULL; j++) {
|
||||
/* found the module in the telnet server module array, it was likely not registered at init time */
|
||||
@@ -336,7 +357,11 @@ int websrv_callback_okset_softmodem_cmdvar(const struct _u_request *request, str
|
||||
{
|
||||
LOG_I(UTIL, "[websrv] : callback_okset_softmodem_cmdvar received %s %s\n", request->http_verb, request->http_url);
|
||||
for (int i = 0; i < u_map_count(request->map_header); i++)
|
||||
LOG_I(UTIL, "[websrv] header variable %i %s : %s\n", i, u_map_enum_keys(request->map_header)[i], u_map_enum_values(request->map_header)[i]);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] header variable %i %s : %s\n",
|
||||
i,
|
||||
u_map_enum_keys(request->map_header)[i],
|
||||
u_map_enum_values(request->map_header)[i]);
|
||||
int us = ulfius_add_header_to_response(response, "Access-Control-Request-Method", "POST");
|
||||
if (us != U_OK) {
|
||||
ulfius_set_string_body_response(response, 501, "Internal server error (ulfius_add_header_to_response)");
|
||||
@@ -433,45 +458,77 @@ int websrv_processwebfunc(struct _u_response *response, cmdparser_t *modulestruc
|
||||
{
|
||||
LOG_I(UTIL, "[websrv] : executing command %s %s\n", modulestruct->module, cmd->cmdname);
|
||||
if ((cmd->cmdflags & TELNETSRV_CMDFLAG_NEEDPARAM) && jparams == NULL) {
|
||||
LOG_W(UTIL, "No parameters sent by frontend for %s %s\n", modulestruct->module, cmd->cmdname);
|
||||
return 500;
|
||||
LOG_W(UTIL, "No parameters sent by frontend for %s %s\n", modulestruct->module, cmd->cmdname);
|
||||
return 500;
|
||||
}
|
||||
int http_status = 200;
|
||||
char *pname[2], *pvalue[2];
|
||||
size_t np =0;
|
||||
size_t np = 0;
|
||||
if (jparams != NULL) {
|
||||
int b[2];
|
||||
char *ptype[2];
|
||||
json_error_t jerror;
|
||||
np = json_array_size(jparams);
|
||||
int jrt;
|
||||
switch(np) {
|
||||
case 1:
|
||||
jrt=json_unpack_ex(jparams, &jerror, 0, "[{s:s,s:s,s:s,s,b}]", "name", &pname[0], "value", &pvalue[0], "type", &ptype[0], "modifiable", &b);
|
||||
break;
|
||||
case 2:
|
||||
jrt=json_unpack_ex(jparams, &jerror, 0, "[{s:s,s:s,s:s,s,b},{s:s,s:s,s:s,s,b}]",
|
||||
"name", &pname[0], "value", &pvalue[0], "type", &ptype[0], "modifiable", &b[0],
|
||||
"name", &pname[1], "value", &pvalue[1], "type", &ptype[1], "modifiable", &b[1]);
|
||||
break;
|
||||
default:
|
||||
http_status=500;
|
||||
break;
|
||||
// json_unpack_ex(jparams, &jerror, 0, "[{s:s,s:s,s:s,s,b}]", "name", &pname, "value", &pvalue, "type", &ptype, "modifiable", &b);
|
||||
|
||||
}
|
||||
if (jrt <0 || http_status != 200) {
|
||||
LOG_I(UTIL, "[websrv], couldn't unpack jparams, module %s, command %s: %s\n", modulestruct->module, cmd->cmdname, jerror.text);
|
||||
websrv_printjson((char *)__FUNCTION__, jparams, websrvparams.dbglvl);
|
||||
return 500;
|
||||
}
|
||||
int b[2];
|
||||
char *ptype[2];
|
||||
json_error_t jerror;
|
||||
np = json_array_size(jparams);
|
||||
int jrt;
|
||||
switch (np) {
|
||||
case 1:
|
||||
jrt = json_unpack_ex(jparams,
|
||||
&jerror,
|
||||
0,
|
||||
"[{s:s,s:s,s:s,s,b}]",
|
||||
"name",
|
||||
&pname[0],
|
||||
"value",
|
||||
&pvalue[0],
|
||||
"type",
|
||||
&ptype[0],
|
||||
"modifiable",
|
||||
&b);
|
||||
break;
|
||||
case 2:
|
||||
jrt = json_unpack_ex(jparams,
|
||||
&jerror,
|
||||
0,
|
||||
"[{s:s,s:s,s:s,s,b},{s:s,s:s,s:s,s,b}]",
|
||||
"name",
|
||||
&pname[0],
|
||||
"value",
|
||||
&pvalue[0],
|
||||
"type",
|
||||
&ptype[0],
|
||||
"modifiable",
|
||||
&b[0],
|
||||
"name",
|
||||
&pname[1],
|
||||
"value",
|
||||
&pvalue[1],
|
||||
"type",
|
||||
&ptype[1],
|
||||
"modifiable",
|
||||
&b[1]);
|
||||
break;
|
||||
default:
|
||||
http_status = 500;
|
||||
break;
|
||||
// json_unpack_ex(jparams, &jerror, 0, "[{s:s,s:s,s:s,s,b}]", "name", &pname, "value", &pvalue, "type", &ptype,
|
||||
// "modifiable", &b);
|
||||
}
|
||||
if (jrt < 0 || http_status != 200) {
|
||||
LOG_I(UTIL,
|
||||
"[websrv], couldn't unpack jparams, module %s, command %s: %s\n",
|
||||
modulestruct->module,
|
||||
cmd->cmdname,
|
||||
jerror.text);
|
||||
websrv_printjson((char *)__FUNCTION__, jparams, websrvparams.dbglvl);
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->cmdflags & TELNETSRV_CMDFLAG_GETWEBTBLDATA) {
|
||||
webdatadef_t wdata;
|
||||
memset(&wdata, 0, sizeof(wdata));
|
||||
wdata.numlines = 1;
|
||||
for (int i=0; i<np; i++) {
|
||||
for (int i = 0; i < np; i++) {
|
||||
snprintf(wdata.columns[i].coltitle, sizeof(wdata.columns[i].coltitle) - 1, "%s", pname[i]);
|
||||
wdata.numcols = np;
|
||||
wdata.lines[0].val[i] = pvalue[i];
|
||||
@@ -480,8 +537,15 @@ int websrv_processwebfunc(struct _u_response *response, cmdparser_t *modulestruc
|
||||
websrv_gettbldata_response(response, &wdata, modulestruct->module, cmd->cmdname);
|
||||
} else {
|
||||
char *sptr = index(cmd->cmdname, ' ');
|
||||
char cmdbuff[TELNET_CMD_MAXSIZE*3]; //cmd + 2 parameters
|
||||
snprintf(cmdbuff,sizeof(cmdbuff)-1, "%s%s%s %s",(sptr == NULL) ? "" : sptr,(sptr == NULL) ? "" : " ",(np>0) ? pvalue[0] : "",(np>1) ? pvalue[1] : "");
|
||||
char cmdbuff[TELNET_CMD_MAXSIZE * 3]; // cmd + 2 parameters
|
||||
snprintf(cmdbuff,
|
||||
sizeof(cmdbuff) - 1,
|
||||
"%s%s%s%s%s",
|
||||
(sptr == NULL) ? "" : sptr,
|
||||
(np > 0) ? " " : "",
|
||||
(np > 0) ? pvalue[0] : "",
|
||||
(np > 1) ? " " : "",
|
||||
(np > 1) ? pvalue[1] : "");
|
||||
if (cmd->qptr != NULL) {
|
||||
websrv_printf_start(response, 16384, true);
|
||||
telnet_pushcmd(cmd, cmdbuff, websrv_async_printf);
|
||||
@@ -536,7 +600,11 @@ int websrv_callback_exec_softmodemcmd(const struct _u_request *request, struct _
|
||||
/* callback processing module url (<address>/oaisoftmodem/module/variables), get method*/
|
||||
int websrv_callback_get_softmodemvar(const struct _u_request *request, struct _u_response *response, void *user_data)
|
||||
{
|
||||
LOG_I(UTIL, "[websrv] : callback_get_softmodemvar received %s %s module %s\n", request->http_verb, request->http_url, (user_data == NULL) ? "NULL" : ((cmdparser_t *)user_data)->module);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] : callback_get_softmodemvar received %s %s module %s\n",
|
||||
request->http_verb,
|
||||
request->http_url,
|
||||
(user_data == NULL) ? "NULL" : ((cmdparser_t *)user_data)->module);
|
||||
if (user_data == NULL) {
|
||||
ulfius_set_string_body_response(response, 500, "No variables defined for this module");
|
||||
return U_CALLBACK_COMPLETE;
|
||||
@@ -553,22 +621,61 @@ int websrv_callback_get_softmodemvar(const struct _u_request *request, struct _u
|
||||
json_t *oneaction;
|
||||
switch (modulestruct->var[j].vartype) {
|
||||
case TELNET_VARTYPE_DOUBLE:
|
||||
oneaction = json_pack("{s:s,s:s,s:g,s:b}", "type", "number", "name", modulestruct->var[j].varname, "value", *(double *)(modulestruct->var[j].varvalptr), "modifiable", modifiable);
|
||||
oneaction = json_pack("{s:s,s:s,s:g,s:b}",
|
||||
"type",
|
||||
"number",
|
||||
"name",
|
||||
modulestruct->var[j].varname,
|
||||
"value",
|
||||
*(double *)(modulestruct->var[j].varvalptr),
|
||||
"modifiable",
|
||||
modifiable);
|
||||
case TELNET_VARTYPE_INT32:
|
||||
case TELNET_VARTYPE_INT16:
|
||||
case TELNET_VARTYPE_INT8:
|
||||
case TELNET_VARTYPE_UINT:
|
||||
oneaction = json_pack("{s:s,s:s,s:i,s:b}", "type", "number", "name", modulestruct->var[j].varname, "value", (int)(*(int *)(modulestruct->var[j].varvalptr)), "modifiable", modifiable);
|
||||
oneaction = json_pack("{s:s,s:s,s:i,s:b}",
|
||||
"type",
|
||||
"number",
|
||||
"name",
|
||||
modulestruct->var[j].varname,
|
||||
"value",
|
||||
(int)(*(int *)(modulestruct->var[j].varvalptr)),
|
||||
"modifiable",
|
||||
modifiable);
|
||||
break;
|
||||
case TELNET_VARTYPE_INT64:
|
||||
oneaction =
|
||||
json_pack("{s:s,s:s,s:lli,s:b}", "type", "number", "name", modulestruct->var[j].varname, "value", (int64_t)(*(int64_t *)(modulestruct->var[j].varvalptr)), "modifiable", modifiable);
|
||||
oneaction = json_pack("{s:s,s:s,s:lli,s:b}",
|
||||
"type",
|
||||
"number",
|
||||
"name",
|
||||
modulestruct->var[j].varname,
|
||||
"value",
|
||||
(int64_t)(*(int64_t *)(modulestruct->var[j].varvalptr)),
|
||||
"modifiable",
|
||||
modifiable);
|
||||
break;
|
||||
case TELNET_VARTYPE_STRING:
|
||||
oneaction = json_pack("{s:s,s:s,s:s,s:b}", "type", "string", "name", modulestruct->var[j].varname, "value", strval, "modifiable", modifiable);
|
||||
oneaction = json_pack("{s:s,s:s,s:s,s:b}",
|
||||
"type",
|
||||
"string",
|
||||
"name",
|
||||
modulestruct->var[j].varname,
|
||||
"value",
|
||||
strval,
|
||||
"modifiable",
|
||||
modifiable);
|
||||
break;
|
||||
default:
|
||||
oneaction = json_pack("{s:s,s:s,s:s,s:b}", "type", "???", "name", modulestruct->var[j].varname, "value", "???", "modifiable", modifiable);
|
||||
oneaction = json_pack("{s:s,s:s,s:s,s:b}",
|
||||
"type",
|
||||
"???",
|
||||
"name",
|
||||
modulestruct->var[j].varname,
|
||||
"value",
|
||||
"???",
|
||||
"modifiable",
|
||||
modifiable);
|
||||
break;
|
||||
}
|
||||
if (oneaction == NULL) {
|
||||
@@ -601,7 +708,11 @@ int websrv_callback_get_softmodemvar(const struct _u_request *request, struct _u
|
||||
/* callback processing module url (<address>/oaisoftmodem/module/commands)*/
|
||||
int websrv_callback_get_softmodemcmd(const struct _u_request *request, struct _u_response *response, void *user_data)
|
||||
{
|
||||
LOG_I(UTIL, "[websrv] : callback_get_softmodemcmd received %s %s module %s\n", request->http_verb, request->http_url, (user_data == NULL) ? "NULL" : ((cmdparser_t *)user_data)->module);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] : callback_get_softmodemcmd received %s %s module %s\n",
|
||||
request->http_verb,
|
||||
request->http_url,
|
||||
(user_data == NULL) ? "NULL" : ((cmdparser_t *)user_data)->module);
|
||||
if (user_data == NULL) {
|
||||
ulfius_set_string_body_response(response, 500, "No commands defined for this module");
|
||||
return U_CALLBACK_COMPLETE;
|
||||
@@ -620,23 +731,23 @@ int websrv_callback_get_softmodemcmd(const struct _u_request *request, struct _u
|
||||
snprintf(confstr, sizeof(confstr), "Confirm %s ?", modulestruct->cmd[j].cmdname);
|
||||
acmd = json_pack("{s:s,s:s}", "name", modulestruct->cmd[j].cmdname, "confirm", confstr);
|
||||
} else if (modulestruct->cmd[j].cmdflags & TELNETSRV_CMDFLAG_NEEDPARAM) {
|
||||
char *question[] = {NULL,NULL};
|
||||
char *question[] = {NULL, NULL};
|
||||
char *helpcp = NULL;
|
||||
json_t *jQ1=NULL, *jQ2=NULL;
|
||||
json_t *jQ1 = NULL, *jQ2 = NULL;
|
||||
json_t *jQs = json_array();
|
||||
if (modulestruct->cmd[j].helpstr != NULL) {
|
||||
helpcp = strdup(modulestruct->cmd[j].helpstr);
|
||||
int ns=sscanf(helpcp,"<%m[^<>]> <%m[^<>]>",&question[0],&question[1]);
|
||||
int ns = sscanf(helpcp, "<%m[^<>]> <%m[^<>]>", &question[0], &question[1]);
|
||||
if (ns == 0) {
|
||||
LOG_W(UTIL, "[websrv] Cannot find parameters for command %s %s\n", modulestruct->module, modulestruct->cmd[j].cmdname);
|
||||
continue;
|
||||
}
|
||||
jQ1=json_pack("{s:s,s:s,s:s}", "display",question[0], "pname", "P0", "type", "string");
|
||||
LOG_W(UTIL, "[websrv] Cannot find parameters for command %s %s\n", modulestruct->module, modulestruct->cmd[j].cmdname);
|
||||
continue;
|
||||
}
|
||||
jQ1 = json_pack("{s:s,s:s,s:s}", "display", question[0], "pname", "P0", "type", "string");
|
||||
json_array_append_new(jQs, jQ1);
|
||||
if (ns >1) {
|
||||
jQ2=json_pack("{s:s,s:s,s:s}","display", (question[1] == NULL) ? "" : question[1], "pname", "P1" , "type", "string");
|
||||
json_array_append_new(jQs, jQ2);
|
||||
}
|
||||
if (ns > 1) {
|
||||
jQ2 = json_pack("{s:s,s:s,s:s}", "display", (question[1] == NULL) ? "" : question[1], "pname", "P1", "type", "string");
|
||||
json_array_append_new(jQs, jQ2);
|
||||
}
|
||||
}
|
||||
acmd = json_pack("{s:s,s:o}", "name", modulestruct->cmd[j].cmdname, "question", jQs);
|
||||
free(helpcp);
|
||||
@@ -645,10 +756,10 @@ int websrv_callback_get_softmodemcmd(const struct _u_request *request, struct _u
|
||||
} else {
|
||||
acmd = json_pack("{s:s}", "name", modulestruct->cmd[j].cmdname);
|
||||
}
|
||||
if ( acmd == NULL) {
|
||||
LOG_W(UTIL, "[websrv] interface for command %s %s cannot be built\n", modulestruct->module, modulestruct->cmd[j].cmdname);
|
||||
continue;
|
||||
}
|
||||
if (acmd == NULL) {
|
||||
LOG_W(UTIL, "[websrv] interface for command %s %s cannot be built\n", modulestruct->module, modulestruct->cmd[j].cmdname);
|
||||
continue;
|
||||
}
|
||||
json_t *jopts = json_array();
|
||||
if (modulestruct->cmd[j].cmdflags & TELNETSRV_CMDFLAG_AUTOUPDATE) {
|
||||
json_array_append_new(jopts, json_string("update"));
|
||||
@@ -784,7 +895,13 @@ int websrv_add_endpoint(char **http_method,
|
||||
int j = 0;
|
||||
int priority = (user_data == NULL) ? 10 : 1;
|
||||
for (int i = 0; i < num_method; i++) {
|
||||
status = ulfius_add_endpoint_by_val(&(websrvparams.instance), http_method[i], url_prefix, url_format, priority, callback_function[i], user_data);
|
||||
status = ulfius_add_endpoint_by_val(&(websrvparams.instance),
|
||||
http_method[i],
|
||||
url_prefix,
|
||||
url_format,
|
||||
priority,
|
||||
callback_function[i],
|
||||
user_data);
|
||||
if (status != U_OK) {
|
||||
LOG_E(UTIL, "[websrv] cannot add endpoint %s %s/%s\n", http_method[i], url_prefix, url_format);
|
||||
} else {
|
||||
@@ -798,11 +915,15 @@ int websrv_add_endpoint(char **http_method,
|
||||
void register_module_endpoints(cmdparser_t *module)
|
||||
{
|
||||
int (*callback_functions_var[3])(const struct _u_request *request, struct _u_response *response, void *user_data) = {
|
||||
websrv_callback_okset_softmodem_cmdvar, websrv_callback_set_softmodemvar, websrv_callback_get_softmodemvar};
|
||||
websrv_callback_okset_softmodem_cmdvar,
|
||||
websrv_callback_set_softmodemvar,
|
||||
websrv_callback_get_softmodemvar};
|
||||
char *http_methods[3] = {"OPTIONS", "POST", "GET"};
|
||||
|
||||
int (*callback_functions_cmd[3])(const struct _u_request *request, struct _u_response *response, void *user_data) = {
|
||||
websrv_callback_okset_softmodem_cmdvar, websrv_callback_exec_softmodemcmd, websrv_callback_get_softmodemcmd};
|
||||
websrv_callback_okset_softmodem_cmdvar,
|
||||
websrv_callback_exec_softmodemcmd,
|
||||
websrv_callback_get_softmodemcmd};
|
||||
char prefixurl[TELNET_CMD_MAXSIZE + 20];
|
||||
snprintf(prefixurl, TELNET_CMD_MAXSIZE + 19, "oaisoftmodem/%s", module->module);
|
||||
LOG_I(UTIL, "[websrv] add endpoints %s/[variables or commands] \n", prefixurl);
|
||||
@@ -842,14 +963,22 @@ void *websrv_autoinit()
|
||||
websrvparams.instance.max_post_body_size = 1024;
|
||||
|
||||
// 1: build the first page, when receiving the "oaisoftmodem" url
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance), "GET", "oaisoftmodem", "commands", 1, &websrv_callback_get_softmodemmodules, NULL);
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance),
|
||||
"GET",
|
||||
"oaisoftmodem",
|
||||
"commands",
|
||||
1,
|
||||
&websrv_callback_get_softmodemmodules,
|
||||
NULL);
|
||||
|
||||
// 2 default_endpoint declaration, it tries to open the file with the url name as specified in the request.It looks for the file
|
||||
ulfius_set_default_endpoint(&(websrvparams.instance), &websrv_callback_default, NULL);
|
||||
|
||||
// 3 endpoints corresponding to loaded telnet modules
|
||||
int (*callback_functions_var[3])(const struct _u_request *request, struct _u_response *response, void *user_data) = {
|
||||
websrv_callback_get_softmodemstatus, websrv_callback_okset_softmodem_cmdvar, websrv_callback_set_softmodemvar};
|
||||
websrv_callback_get_softmodemstatus,
|
||||
websrv_callback_okset_softmodem_cmdvar,
|
||||
websrv_callback_set_softmodemvar};
|
||||
char *http_methods[3] = {"GET", "OPTIONS", "POST"};
|
||||
|
||||
websrv_add_endpoint(http_methods, 3, "oaisoftmodem", "info", callback_functions_var, NULL);
|
||||
@@ -859,12 +988,30 @@ void *websrv_autoinit()
|
||||
}
|
||||
|
||||
/*4 callbacks to take care of modules not yet initialized, so not visible in telnet server data when this autoinit runs: */
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance), "GET", "oaisoftmodem", "@module/commands", 10, websrv_callback_newmodule, telnetparams);
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance), "GET", "oaisoftmodem", "@module/variables", 10, websrv_callback_newmodule, telnetparams);
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance),
|
||||
"GET",
|
||||
"oaisoftmodem",
|
||||
"@module/commands",
|
||||
10,
|
||||
websrv_callback_newmodule,
|
||||
telnetparams);
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance),
|
||||
"GET",
|
||||
"oaisoftmodem",
|
||||
"@module/variables",
|
||||
10,
|
||||
websrv_callback_newmodule,
|
||||
telnetparams);
|
||||
// 5 callback to handle file request
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance), "POST", "oaisoftmodem", "file", 1, &websrv_callback_get_softmodemfile, NULL);
|
||||
// 6 callback for help request
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance), "GET", "oaisoftmodem", "helpfiles/@hlpfile", 2, &websrv_callback_get_softmodemhelp, NULL);
|
||||
ulfius_add_endpoint_by_val(&(websrvparams.instance),
|
||||
"GET",
|
||||
"oaisoftmodem",
|
||||
"helpfiles/@hlpfile",
|
||||
2,
|
||||
&websrv_callback_get_softmodemhelp,
|
||||
NULL);
|
||||
// init softscope interface support */
|
||||
websrv_init_scope(&websrvparams);
|
||||
|
||||
|
||||
@@ -110,19 +110,41 @@ void websrv_printjson(char *label, json_t *jsonobj, int dbglvl)
|
||||
void websrv_dump_request(char *label, const struct _u_request *request, int dbglvl)
|
||||
{
|
||||
if (dbglvl > 0) {
|
||||
LOG_I(UTIL, "[websrv] %s, request %s, proto %s, verb %s, path %s\n", label, request->http_url, request->http_protocol, request->http_verb, request->http_verb);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] %s, request %s, proto %s, verb %s, path %s\n",
|
||||
label,
|
||||
request->http_url,
|
||||
request->http_protocol,
|
||||
request->http_verb,
|
||||
request->http_verb);
|
||||
if (request->map_post_body != NULL)
|
||||
for (int i = 0; i < u_map_count(request->map_post_body); i++)
|
||||
LOG_I(UTIL, "[websrv] POST parameter %i %s : %s\n", i, u_map_enum_keys(request->map_post_body)[i], u_map_enum_values(request->map_post_body)[i]);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] POST parameter %i %s : %s\n",
|
||||
i,
|
||||
u_map_enum_keys(request->map_post_body)[i],
|
||||
u_map_enum_values(request->map_post_body)[i]);
|
||||
if (request->map_cookie != NULL)
|
||||
for (int i = 0; i < u_map_count(request->map_cookie); i++)
|
||||
LOG_I(UTIL, "[websrv] cookie variable %i %s : %s\n", i, u_map_enum_keys(request->map_cookie)[i], u_map_enum_values(request->map_cookie)[i]);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] cookie variable %i %s : %s\n",
|
||||
i,
|
||||
u_map_enum_keys(request->map_cookie)[i],
|
||||
u_map_enum_values(request->map_cookie)[i]);
|
||||
if (request->map_header != NULL)
|
||||
for (int i = 0; i < u_map_count(request->map_header); i++)
|
||||
LOG_I(UTIL, "[websrv] header variable %i %s : %s\n", i, u_map_enum_keys(request->map_header)[i], u_map_enum_values(request->map_header)[i]);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] header variable %i %s : %s\n",
|
||||
i,
|
||||
u_map_enum_keys(request->map_header)[i],
|
||||
u_map_enum_values(request->map_header)[i]);
|
||||
if (request->map_url != NULL)
|
||||
for (int i = 0; i < u_map_count(request->map_url); i++)
|
||||
LOG_I(UTIL, "[websrv] url variable %i %s : %s\n", i, u_map_enum_keys(request->map_url)[i], u_map_enum_values(request->map_url)[i]);
|
||||
LOG_I(UTIL,
|
||||
"[websrv] url variable %i %s : %s\n",
|
||||
i,
|
||||
u_map_enum_keys(request->map_url)[i],
|
||||
u_map_enum_values(request->map_url)[i]);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------*/
|
||||
@@ -163,12 +185,27 @@ int websrv_string_response(char *astring, struct _u_response *response, int http
|
||||
/* set of calls to fill a buffer with a string and use this buffer in a response */
|
||||
void websrv_printf_start(struct _u_response *response, int buffsize, bool async)
|
||||
{
|
||||
pthread_mutex_lock(&(websrv_printf_buff.mutex));
|
||||
websrv_printf_buff.buff = malloc(buffsize);
|
||||
websrv_printf_buff.buffptr = websrv_printf_buff.buff;
|
||||
websrv_printf_buff.buffsize = buffsize;
|
||||
websrv_printf_buff.response = response;
|
||||
websrv_printf_buff.async = async;
|
||||
int st = -1;
|
||||
|
||||
for (int count = 0; count < 10; count++) {
|
||||
st = pthread_mutex_trylock(&(websrv_printf_buff.mutex));
|
||||
if (st == 0)
|
||||
break;
|
||||
usleep(100);
|
||||
count++;
|
||||
}
|
||||
if (st != 0) {
|
||||
char msg[255];
|
||||
snprintf(msg, sizeof(msg) - 1, "[websrv] cannot allocate print buffer, error %s", strerror(st));
|
||||
LOG_W(UTIL, "%s", msg);
|
||||
websrv_string_response(msg, websrv_printf_buff.response, 500, 0);
|
||||
} else {
|
||||
websrv_printf_buff.buff = malloc(buffsize);
|
||||
websrv_printf_buff.buffptr = websrv_printf_buff.buff;
|
||||
websrv_printf_buff.buffsize = buffsize;
|
||||
websrv_printf_buff.response = response;
|
||||
websrv_printf_buff.async = async;
|
||||
}
|
||||
}
|
||||
|
||||
void websrv_printf_atpos(int pos, const char *message, ...)
|
||||
@@ -176,7 +213,8 @@ void websrv_printf_atpos(int pos, const char *message, ...)
|
||||
va_list va_args;
|
||||
va_start(va_args, message);
|
||||
|
||||
websrv_printf_buff.buffptr = websrv_printf_buff.buff + pos + vsnprintf(websrv_printf_buff.buff + pos, websrv_printf_buff.buffsize - pos - 1, message, va_args);
|
||||
websrv_printf_buff.buffptr = websrv_printf_buff.buff + pos
|
||||
+ vsnprintf(websrv_printf_buff.buff + pos, websrv_printf_buff.buffsize - pos - 1, message, va_args);
|
||||
|
||||
va_end(va_args);
|
||||
return;
|
||||
@@ -186,8 +224,10 @@ void websrv_printf(const char *message, ...)
|
||||
{
|
||||
va_list va_args;
|
||||
va_start(va_args, message);
|
||||
websrv_printf_buff.buffptr += vsnprintf(websrv_printf_buff.buffptr, websrv_printf_buff.buffsize - (websrv_printf_buff.buffptr - websrv_printf_buff.buff) - 1, message, va_args);
|
||||
|
||||
websrv_printf_buff.buffptr += vsnprintf(websrv_printf_buff.buffptr,
|
||||
websrv_printf_buff.buffsize - (websrv_printf_buff.buffptr - websrv_printf_buff.buff) - 1,
|
||||
message,
|
||||
va_args);
|
||||
va_end(va_args);
|
||||
return;
|
||||
}
|
||||
@@ -207,7 +247,10 @@ void websrv_printf_end(int httpstatus, int dbglvl)
|
||||
websrv_string_response(websrv_printf_buff.buff, websrv_printf_buff.response, httpstatus, dbglvl);
|
||||
} else if (httpstatus < 1000) {
|
||||
LOG_W(UTIL, "[websrv] %s\n", websrv_printf_buff.buff);
|
||||
ulfius_set_binary_body_response(websrv_printf_buff.response, httpstatus, websrv_printf_buff.buff, websrv_printf_buff.buffptr - websrv_printf_buff.buff);
|
||||
ulfius_set_binary_body_response(websrv_printf_buff.response,
|
||||
httpstatus,
|
||||
websrv_printf_buff.buff,
|
||||
websrv_printf_buff.buffptr - websrv_printf_buff.buff);
|
||||
}
|
||||
|
||||
free(websrv_printf_buff.buff);
|
||||
|
||||
@@ -667,6 +667,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
|
||||
T_INT(frame_parms->symbols_per_slot),
|
||||
T_BUFFER(&rxdataF_comp[gNB_id][0], 2 * /* ulsch[UE_id]->harq_processes[harq_pid]->nb_rb */ frame_parms->N_RB_UL * 12 * 2));
|
||||
#endif
|
||||
|
||||
UEscopeCopy(ue, pdschRxdataF_comp, rxdataF_comp[0], sizeof(c16_t), nbRx, rx_size_symbol * NR_SYMBOLS_PER_SLOT, 0);
|
||||
|
||||
if (ue->phy_sim_pdsch_rxdataF_comp)
|
||||
|
||||
@@ -193,6 +193,7 @@ void websrv_setpoint(int x, int y, websrv_scopedata_msg_t *msg)
|
||||
msg->data_xy[msg->data_xy[0]] = (int16_t)y;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void commonGraph(OAIgraph_t *graph, int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, const char *label, FL_COLOR pointColor)
|
||||
{
|
||||
memset(graph, 0, sizeof(*graph));
|
||||
|
||||
Reference in New Issue
Block a user