Commit 25bd5fb9 authored by Arash Sahbafard's avatar Arash Sahbafard Committed by laurent

Telnetsrv: TELNETSRV_CMDFLAG_PUSHINTPOOLQ cmds get fifo

Previously, only the first out of multiple telnet commands with
TELNETSRV_CMDFLAG_PUSHINTPOOLQ option would get a pointer to the fifo
queue, which is fixed in this commit.

Further, add_telnetcmd() now checks whether TELNET_MAXCMD is reached,
and prints and error.

Reformatted/simplified the function.
parent e28fccc7
...@@ -845,30 +845,39 @@ int telnetsrv_autoinit(void) { ...@@ -845,30 +845,39 @@ int telnetsrv_autoinit(void) {
* function at init time. the telnet server is delivered with a set of commands which * 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 * 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) { int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmddef_t *cmd)
int i; {
notifiedFIFO_t *afifo=NULL;
if( modulename == NULL || var == NULL || cmd == NULL) { if( modulename == NULL || var == NULL || cmd == NULL) {
fprintf(stderr,"[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n"); fprintf(stderr,"[TELNETSRV] Telnet server, add_telnetcmd: invalid parameters\n");
return -1; return -1;
} }
int i;
for (i=0; i<TELNET_MAXCMD ; i++) { for (i=0; i<TELNET_MAXCMD ; i++) {
if (telnetparams.CmdParsers[i].var == NULL) { cmdparser_t *CmdParser = &telnetparams.CmdParsers[i];
strncpy(telnetparams.CmdParsers[i].module,modulename,sizeof(telnetparams.CmdParsers[i].module)-1); if (CmdParser->var == NULL) {
telnetparams.CmdParsers[i].cmd = cmd; strncpy(CmdParser->module, modulename, sizeof(CmdParser->module) - 1);
telnetparams.CmdParsers[i].var = var; CmdParser->cmd = cmd;
if (cmd->cmdflags & TELNETSRV_CMDFLAG_PUSHINTPOOLQ) { CmdParser->var = var;
printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
i, CmdParser->module);
break;
}
}
if (i == TELNET_MAXCMD) {
fprintf(stderr, "[TELNETSRV] TELNET_MAXCMD reached, cannot add new module %s\n", modulename);
return -1;
}
notifiedFIFO_t *afifo = NULL;
for (int k = 0; cmd[k].cmdfunc != NULL ; k++) {
if (cmd[k].cmdflags & TELNETSRV_CMDFLAG_PUSHINTPOOLQ) {
if (afifo == NULL) { if (afifo == NULL) {
afifo = malloc(sizeof(notifiedFIFO_t)); afifo = malloc(sizeof(notifiedFIFO_t));
initNotifiedFIFO(afifo); initNotifiedFIFO(afifo);
} }
cmd->qptr = afifo; cmd[k].qptr = afifo;
}
printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
i,telnetparams.CmdParsers[i].module);
break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment