Commit 8d74ea38 authored by frtabu's avatar frtabu

backend implementation of variable modifications

parent a3ac83a1
...@@ -389,61 +389,75 @@ char *telnet_getvarvalue(telnetshell_vardef_t *var, int varindex) { ...@@ -389,61 +389,75 @@ char *telnet_getvarvalue(telnetshell_vardef_t *var, int varindex) {
return val; return val;
} }
int setgetvar(int moduleindex,char getorset,char *params) { int telnet_setvarvalue(telnetshell_vardef_t *var,char *strval, telnet_printfunc_t prnt ) {
int n,i; int st=0;
char varname[TELNET_CMD_MAXSIZE]; switch(var->vartype) {
char *varval=NULL;
memset(varname,0,sizeof(varname));
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 (n > 0 && (getorset == 'g' || getorset == 'G')) {
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);
switch(telnetparams.CmdParsers[moduleindex].var[i].vartype) {
case TELNET_VARTYPE_INT32: case TELNET_VARTYPE_INT32:
*(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (int)strtol(varval,NULL,0); *(int *)(var->varvalptr) = (int)strtol(strval,NULL,0);
client_printf("%i\n",*(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)); if (prnt != NULL)
prnt("%i\n",*(int *)(var->varvalptr));
break; break;
case TELNET_VARTYPE_INT16: case TELNET_VARTYPE_INT16:
*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (short)strtol(varval,NULL,0); *(short *)(var->varvalptr) = (short)strtol(strval,NULL,0);
client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)); if (prnt != NULL)
prnt("%hi\n",*(short *)(var->varvalptr));
break; break;
case TELNET_VARTYPE_INT8: case TELNET_VARTYPE_INT8:
*(char *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (char)strtol(varval,NULL,0); *(char *)(var->varvalptr) = (char)strtol(strval,NULL,0);
client_printf("%i\n",*(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)); if (prnt != NULL)
prnt("%i\n",*(int *)(var->varvalptr));
break; break;
case TELNET_VARTYPE_UINT: case TELNET_VARTYPE_UINT:
*(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (unsigned int)strtol(varval,NULL,0); *(unsigned int *)(var->varvalptr) = (unsigned int)strtol(strval,NULL,0);
client_printf("%u\n",*(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)); if (prnt != NULL)
prnt("%u\n",*(unsigned int *)(var->varvalptr));
break; break;
case TELNET_VARTYPE_DOUBLE: case TELNET_VARTYPE_DOUBLE:
*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = strtod(varval,NULL); *(double *)(var->varvalptr) = strtod(strval,NULL);
client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)); if (prnt != NULL)
prnt("%g\n",*(double *)(var->varvalptr));
break; break;
case TELNET_VARTYPE_STRING: case TELNET_VARTYPE_STRING:
sprintf(*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr),"%s", varval); sprintf(*(char **)(var->varvalptr),"%s", strval);
client_printf("\"%s\"\n",*(char **)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)); if (prnt != NULL)
prnt("\"%s\"\n",*(char **)(var->varvalptr));
break; break;
default: default:
client_printf("unknown type\n"); if (prnt != NULL)
prnt("unknown type\n");
st=-1;
break; break;
} }
return st;
}
int setgetvar(int moduleindex,char getorset,char *params) {
int n,i;
char varname[TELNET_CMD_MAXSIZE];
char *varval=NULL;
memset(varname,0,sizeof(varname));
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 (n > 0 && (getorset == 'g' || getorset == 'G')) {
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);
telnet_setvarvalue(&(telnetparams.CmdParsers[moduleindex].var[i]),varval, client_printf);
} }
} }
} }
......
...@@ -163,5 +163,6 @@ extern int get_phybsize(void); ...@@ -163,5 +163,6 @@ extern int get_phybsize(void);
#ifdef WEBSERVERCODE #ifdef WEBSERVERCODE
extern telnetsrv_params_t *get_telnetsrv_params(void); extern telnetsrv_params_t *get_telnetsrv_params(void);
extern char *telnet_getvarvalue(telnetshell_vardef_t *var, int varindex); extern char *telnet_getvarvalue(telnetshell_vardef_t *var, int varindex);
extern int telnet_setvarvalue(telnetshell_vardef_t *var,char *strval, telnet_printfunc_t prnt ) ;
#endif #endif
#endif #endif
This diff is collapsed.
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