diff options
author | Michael Larson <slioch@slioch.vyatta.com> | 2010-04-15 13:39:40 -0700 |
---|---|---|
committer | Michael Larson <slioch@slioch.vyatta.com> | 2010-04-15 13:39:40 -0700 |
commit | 6e99cd44d88e70cce50f1e6fa105525809d8409e (patch) | |
tree | 9c10ca5af9f4e3e243321e36d0925b13dfef3538 | |
parent | 634c79ab395af94972fcf778ec80ae7d79dc5561 (diff) | |
download | vyatta-cfg-6e99cd44d88e70cce50f1e6fa105525809d8409e.tar.gz vyatta-cfg-6e99cd44d88e70cce50f1e6fa105525809d8409e.zip |
Multiple (i.e. one or two) datatypes can now be supported on a node.def type definition.
type: ipv4,ipv6
Will now allow for the value to validated against both data types (or the first success). In the case of both failing the following message format will be returned:
vyatta@vyatta# set load-balancing wan rule 1
"1" is not a valid value of type "bool"
"1" is not a valid value of type "ipv4"
Note, that any combination of types with text being one of the types is not supported. The reason being is that with text any value is allowed, therefore it doesn't really
make sense to validate a datatype on text + ipv4 when text will always be successful.
-rw-r--r-- | src/cli_new.c | 185 | ||||
-rw-r--r-- | src/cli_parse.y | 6 | ||||
-rw-r--r-- | src/cli_val.h | 1 | ||||
-rw-r--r-- | src/commit2.c | 7 |
4 files changed, 138 insertions, 61 deletions
diff --git a/src/cli_new.c b/src/cli_new.c index dc6b760..f6a22ea 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -697,6 +697,8 @@ valstruct str2val(char *cp) /**************************************************** STATIC FUNCTIONS ****************************************************/ +int char2val_notext(vtw_def *def, int my_type, char *value, valstruct **valp, char *buf); +int char2val_text(vtw_def *def, char *value, valstruct **valp); /************************************************** char2val: @@ -705,85 +707,147 @@ valstruct str2val(char *cp) ****************************************************/ int char2val(vtw_def *def, char *value, valstruct *valp) { - int token; - char *endp, *cp; - int linecnt, cnt; int my_type = def->def_type; - boolean first = TRUE; + int my_type2 = def->def_type2; memset(valp, 0, sizeof (*valp)); - if (my_type == ERROR_TYPE) { - my_type = TEXT_TYPE; - } - - if (my_type != TEXT_TYPE && my_type != ERROR_TYPE) { - cli_val_len = strlen(value); - cli_val_ptr = value; - while(1) { - token = yy_cli_val_lex(); - if (token != VALUE) { - if (first || token){ - if (def->def_type_help){ - set_at_string(value); - (void)expand_string(def->def_type_help); - fprintf(out_stream, "%s\n", exe_string); - } else { - print_msg("Wrong type of value in %s, " - "need %s\n", - m_path.path_buf + m_path.print_offset, - type_to_name(my_type)); - fprintf(out_stream, "\"%s\" is not a valid value of type \"%s\"\n", - value, type_to_name(my_type)); - } + /* + normal: + A) single text type + B) single non-text type + + new: + C) Text plus non-text (NOT SUPPORTED)! + D) 2 non-text (double up first loop) + //so perhaps split the below into two functions, text and non-text + */ + + if (my_type != TEXT_TYPE && + my_type != ERROR_TYPE) { + //since this is the restricted type + //we'll either do two calls to this + //or one call to this as text + + //currently fails to handle mixed text + non-text case... + char buf1[2048]; + if (char2val_notext(def,my_type,value,&valp,buf1) != 0) { + if (my_type2 != ERROR_TYPE) { + char buf2[2048]; + if (char2val_notext(def,my_type2,value,&valp,buf2) != 0) { + fprintf(out_stream,"%s%s",buf1,buf2); return -1; } - return 0; } - if (my_type != get_cli_value_ptr()->val_type) { + else { + fprintf(out_stream,"%s",buf1); + return -1; //only single definition + } + } + return 0; + } + else { + return char2val_text(def,value,&valp); + } +} + +//non-text type processing block + +int char2val_notext(vtw_def *def, int my_type, char *value, valstruct **valpp, char *err_buf) +{ + valstruct *valp = *valpp; + int token; + boolean first = TRUE; + cli_val_len = strlen(value); + cli_val_ptr = value; + while(1) { + token = yy_cli_val_lex(); + + if (token != VALUE) { + if (first || token){ + if (def->def_type_help){ set_at_string(value); (void)expand_string(def->def_type_help); - fprintf(out_stream, "%s\n", exe_string); + sprintf(err_buf, "%s\n", exe_string); } else { print_msg("Wrong type of value in %s, " - "need %s\n", - m_path.path_buf + m_path.print_offset, - type_to_name(my_type)); - fprintf(out_stream, "\"%s\" is not a valid value of type \"%s\"\n", - value, type_to_name(my_type)); + "need %s\n", + m_path.path_buf + m_path.print_offset, + type_to_name(my_type)); + + token = yy_cli_val_lex(); + + sprintf(err_buf, "\"%s\" is not a valid value of type \"%s\"\n", + value, type_to_name(my_type)); } - my_free(get_cli_value_ptr()->val); - if (first) - return -1; - return 0; + return -1; + } - if (first) { - *valp = *get_cli_value_ptr(); - get_cli_value_ptr()->free_me = FALSE; - first = FALSE; + return 0; + } + if (my_type != get_cli_value_ptr()->val_type) { + if (def->def_type_help){ + set_at_string(value); + (void)expand_string(def->def_type_help); + sprintf(err_buf, "%s\n", exe_string); } else { - if (def->multi) - add_val(valp, get_cli_value_ptr()); - else { - print_msg("Unexpected multivalue in %s\n", m_path.path); - free_val(get_cli_value_ptr()); - } + print_msg("Wrong type of value in %s, " + "need %s\n", + m_path.path_buf + m_path.print_offset, + type_to_name(my_type)); + + token = yy_cli_val_lex(); + + sprintf(err_buf, "\"%s\" is not a valid value of type \"%s\"\n", + value, type_to_name(my_type)); } - token = yy_cli_val_lex(); - if (!token) - return 0; - if (token != EOL) { - fprintf(out_stream, "\"%s\" is not a valid value\n", value); - print_msg("Badly formed value in %s\n", - m_path.path + m_path.print_offset); - if (token == VALUE) - my_free(get_cli_value_ptr()->val); + my_free(get_cli_value_ptr()->val); + if (first) { return -1; } + return 0; + } + if (first) { + *valp = *get_cli_value_ptr(); + get_cli_value_ptr()->free_me = FALSE; + first = FALSE; + } else { + if (def->multi) + add_val(valp, get_cli_value_ptr()); + else { + print_msg("Unexpected multivalue in %s\n", m_path.path); + free_val(get_cli_value_ptr()); + } + } + token = yy_cli_val_lex(); + if (!token) { + return 0; + } + if (token != EOL) { + + token = yy_cli_val_lex(); + + sprintf(err_buf, "\"%s\" is not a valid value\n", value); + print_msg("Badly formed value in %s\n", + m_path.path + m_path.print_offset); + if (token == VALUE) { + my_free(get_cli_value_ptr()->val); + } + return -1; } - return 0; } + return 0; +} + +int char2val_text(vtw_def *def, char *value, valstruct **valpp) +{ + valstruct *valp = *valpp; + char *endp, *cp; + int linecnt, cnt; + + //PROCESSING IF TYPE IS TEXT TYPE + valp->val_type = TEXT_TYPE; valp->free_me = TRUE; /* count lines */ @@ -1953,7 +2017,8 @@ boolean validate_value(vtw_def *def, char *cp) if (status != VTWERR_OK) return FALSE; if ((def->def_type!=ERROR_TYPE) && - (validate_value_val.val_type != def->def_type)) { + ((validate_value_val.val_type != def->def_type) && + (validate_value_val.val_type != def->def_type2))) { if (def->def_type_help){ (void)expand_string(def->def_type_help); fprintf(out_stream, "%s\n", exe_string); diff --git a/src/cli_parse.y b/src/cli_parse.y index 89c6638..db56d3e 100644 --- a/src/cli_parse.y +++ b/src/cli_parse.y @@ -129,6 +129,12 @@ tag: /* empty */ } } ; +type: TYPE TYPE_DEF COMMA TYPE_DEF + { + parse_defp->def_type = $2; + parse_defp->def_type2 = $4; + } + ; type: TYPE TYPE_DEF SEMI STRING { parse_defp->def_type = $2; diff --git a/src/cli_val.h b/src/cli_val.h index 9b3bcda..408cc50 100644 --- a/src/cli_val.h +++ b/src/cli_val.h @@ -102,6 +102,7 @@ typedef enum { typedef struct { vtw_type_e def_type; + vtw_type_e def_type2; char *def_type_help; char *def_node_help; char *def_default; diff --git a/src/commit2.c b/src/commit2.c index 1b22bf8..40d9cc8 100644 --- a/src/commit2.c +++ b/src/commit2.c @@ -811,7 +811,12 @@ dump_func(GNode *node, gpointer data) for (i = 0; i < depth; ++i) { fprintf(out," "); } - fprintf(out,"%s (t: %d, p: %d)", ((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_config._def.def_type,((struct VyattaNode*)gp)->_config._priority); + if (((struct VyattaNode*)gp)->_config._def.def_type2 != NULL) { + fprintf(out,"%s (t: %d-%d, p: %d)", ((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_config._def.def_type,((struct VyattaNode*)gp)->_config._def.def_type2,((struct VyattaNode*)gp)->_config._priority); + } + else { + fprintf(out,"%s (t: %d, p: %d)", ((struct VyattaNode*)gp)->_data._name,((struct VyattaNode*)gp)->_config._def.def_type,((struct VyattaNode*)gp)->_config._priority); + } if (((struct VyattaNode*)gp)->_data._value == TRUE) { fprintf(out," [VALUE]"); } |