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.
This commit is contained in:
@@ -845,33 +845,42 @@ 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;
|
||||||
if (afifo == NULL) {
|
|
||||||
afifo = malloc(sizeof(notifiedFIFO_t));
|
|
||||||
initNotifiedFIFO(afifo);
|
|
||||||
}
|
|
||||||
cmd->qptr = afifo;
|
|
||||||
}
|
|
||||||
printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
|
printf("[TELNETSRV] Telnet server: module %i = %s added to shell\n",
|
||||||
i,telnetparams.CmdParsers[i].module);
|
i, CmdParser->module);
|
||||||
break;
|
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) {
|
||||||
|
afifo = malloc(sizeof(notifiedFIFO_t));
|
||||||
|
initNotifiedFIFO(afifo);
|
||||||
|
}
|
||||||
|
cmd[k].qptr = afifo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user