summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli_def.l4
-rw-r--r--src/cli_new.c88
-rw-r--r--src/cli_val.h4
-rw-r--r--src/common/unionfs.c4
-rw-r--r--src/delete.c4
-rw-r--r--src/set.c33
6 files changed, 87 insertions, 50 deletions
diff --git a/src/cli_def.l b/src/cli_def.l
index 804d142..a7de87d 100644
--- a/src/cli_def.l
+++ b/src/cli_def.l
@@ -257,7 +257,7 @@ RE_TYPE_NAME (txt|u32|ipv4|ipv4net|ipv6|ipv6net|bool|macaddr)
/* values */
RE_VAL_U32 [0-9]+
RE_VAL_BOOL (true|false)
-RE_VAL_TEXT [a-zA-Z]+
+RE_VAL_PRIORITY (PARENT)
/* operators */
RE_OP_COND (==|!=|<|>|<=|>=|in)
@@ -445,7 +445,7 @@ RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_he
return VAR;
}
-<INITIAL,expression>{RE_VAL_TEXT} { return return_value(TEXT_TYPE); }
+<INITIAL,expression>{RE_VAL_PRIORITY} { return return_value(PRIORITY_TYPE); }
<INITIAL,expression>{RE_VAL_U32} { return return_value(INT_TYPE); }
<INITIAL,expression>{RE_IPV4} { return return_value(IPV4_TYPE); }
<INITIAL,expression>{RE_IPV4NET} { return return_value(IPV4NET_TYPE); }
diff --git a/src/cli_new.c b/src/cli_new.c
index f6a22ea..c4d1b86 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -206,23 +206,23 @@ void add_val(valstruct *first, valstruct *second)
{
assert (first->free_me && second->free_me);
assert(second->cnt == 0);
- if (first->val_type != second->val_type) {
- printf("Different types\n\n");
- } else {
- if (first->cnt%MULTI_ALLOC == 0) {
- /* convert into multivalue */
- first->vals = my_realloc(first->vals, (first->cnt + MULTI_ALLOC) *
- sizeof(char *), "add_value");
- if (first->cnt == 0) { /* single value - convert */
- first->vals[0] = first->val;
- first->cnt = 1;
- first->val = NULL;
- }
+ if (first->cnt%MULTI_ALLOC == 0) {
+ /* convert into multivalue */
+ first->vals = my_realloc(first->vals, (first->cnt + MULTI_ALLOC) *
+ sizeof(char *), "add_value 1");
+ first->val_types = my_realloc(first->val_types,(first->cnt + MULTI_ALLOC) *
+ sizeof(vtw_type_e), "add_value 2");
+ if (first->cnt == 0) { /* single value - convert */
+ first->vals[0] = first->val;
+ first->val_types[0] = first->val_type;
+ first->cnt = 1;
+ first->val = NULL;
}
- second->free_me = FALSE; /* we took its string */
- first->vals[first->cnt] = second->val;
- ++first->cnt;
}
+ second->free_me = FALSE; /* we took its string */
+ first->vals[first->cnt] = second->val;
+ first->val_types[first->cnt] = second->val_type;
+ ++first->cnt;
}
/*****************************************************
append - append node to the tail of list
@@ -697,7 +697,7 @@ valstruct str2val(char *cp)
/****************************************************
STATIC FUNCTIONS
****************************************************/
-int char2val_notext(vtw_def *def, int my_type, char *value, valstruct **valp, char *buf);
+int char2val_notext(vtw_def *def, int my_type, int my_type2, char *value, valstruct **valp, char *buf);
int char2val_text(vtw_def *def, char *value, valstruct **valp);
/**************************************************
@@ -731,18 +731,9 @@ int char2val(vtw_def *def, char *value, valstruct *valp)
//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;
- }
- }
- else {
- fprintf(out_stream,"%s",buf1);
- return -1; //only single definition
- }
+ if (char2val_notext(def,my_type,my_type2,value,&valp,buf1) != 0) {
+ fprintf(out_stream,"%s",buf1);
+ return -1; //only single definition
}
return 0;
}
@@ -753,13 +744,22 @@ int char2val(vtw_def *def, char *value, valstruct *valp)
//non-text type processing block
-int char2val_notext(vtw_def *def, int my_type, char *value, valstruct **valpp, char *err_buf)
+int char2val_notext(vtw_def *def, int my_type, int my_type2, char *value, valstruct **valpp, char *err_buf)
{
valstruct *valp = *valpp;
int token;
boolean first = TRUE;
cli_val_len = strlen(value);
cli_val_ptr = value;
+
+ char type_buf[256];
+ if (my_type2 != ERROR_TYPE) {
+ sprintf(type_buf,"%s or %s",type_to_name(my_type),type_to_name(my_type2));
+ }
+ else {
+ sprintf(type_buf,"%s",type_to_name(my_type));
+ }
+
while(1) {
token = yy_cli_val_lex();
@@ -774,19 +774,20 @@ int char2val_notext(vtw_def *def, int my_type, char *value, valstruct **valpp, c
print_msg("Wrong type of value in %s, "
"need %s\n",
m_path.path_buf + m_path.print_offset,
- type_to_name(my_type));
+ type_buf);
token = yy_cli_val_lex();
sprintf(err_buf, "\"%s\" is not a valid value of type \"%s\"\n",
- value, type_to_name(my_type));
+ value, type_buf);
}
return -1;
}
return 0;
}
- if (my_type != get_cli_value_ptr()->val_type) {
+ if (my_type != get_cli_value_ptr()->val_type &&
+ (my_type2 != ERROR_TYPE && my_type2 != get_cli_value_ptr()->val_type)) {
if (def->def_type_help){
set_at_string(value);
(void)expand_string(def->def_type_help);
@@ -795,12 +796,12 @@ int char2val_notext(vtw_def *def, int my_type, char *value, valstruct **valpp, c
print_msg("Wrong type of value in %s, "
"need %s\n",
m_path.path_buf + m_path.print_offset,
- type_to_name(my_type));
+ type_buf);
token = yy_cli_val_lex();
sprintf(err_buf, "\"%s\" is not a valid value of type \"%s\"\n",
- value, type_to_name(my_type));
+ value, type_buf);
}
my_free(get_cli_value_ptr()->val);
if (first) {
@@ -870,6 +871,7 @@ int char2val_text(vtw_def *def, char *value, valstruct **valpp)
cnt = (linecnt + MULTI_ALLOC - 1) / MULTI_ALLOC;
cnt *= MULTI_ALLOC;
valp->vals = my_malloc(cnt * sizeof(char *), "char2val 2");
+ valp->val_types = my_malloc(cnt * sizeof(vtw_type_e), "char2val 3");
for(cp = value, cnt = 0; cnt < linecnt; ++cnt) {
endp = strchr(cp, '\n');
if (endp)
@@ -914,8 +916,6 @@ boolean val_cmp(const valstruct *left, const valstruct *right, vtw_cond_e cond)
else
rstop = 1;
- DPRINT("val_cmp: type=%d count=(%d,%d) val=(%s,%s)\n",
- val_type, lstop, rstop, left->val, right->val);
for(lcur = 0; lcur < lstop; ++lcur) {
if (!lcur && !left->cnt)
lval = left->val;
@@ -947,6 +947,11 @@ boolean val_cmp(const valstruct *left, const valstruct *right, vtw_cond_e cond)
(void) sscanf(lval, format, left_parts, left_parts+1,
left_parts+2, left_parts+3, left_parts+4,
left_parts+5);
+
+ if ((rcur || right->cnt)
+ && right->val_types[rcur] != NULL) {
+ format = cond_formats[right->val_types[rcur]];
+ }
(void) sscanf(rval, format, right_parts, right_parts+1,
right_parts+2, right_parts+3, right_parts+4,
right_parts+5);
@@ -971,16 +976,21 @@ boolean val_cmp(const valstruct *left, const valstruct *right, vtw_cond_e cond)
res = 0;
}
done_comp:
- if(res > 0) res = 1;
- else if(res < 0) res = -1;
+ if (res > 0)
+ res = 1;
+ else if (res < 0)
+ res = -1;
+
ret = ((res == cond1[cond]) ||
(res == cond2[cond]));
+
if (ret && cond == IN_COND) {
set_in_cond_tik(rcur); /* for delete */
/* one success is enough for right cycle
in case of IN_COND, continue left cycle */
break;
}
+
if (!ret && cond != IN_COND)
/* one failure is enough in cases
other than IN_COND - go out */
@@ -1675,6 +1685,8 @@ void free_val(valstruct *val)
my_free(val->vals[cnt]);
if(val->vals)
my_free(val->vals);
+ if(val->val_types)
+ my_free(val->val_types);
}
/*****************************************************
free_string - dealloc string
diff --git a/src/cli_val.h b/src/cli_val.h
index e6182e7..00ed103 100644
--- a/src/cli_val.h
+++ b/src/cli_val.h
@@ -30,7 +30,8 @@ typedef enum {
MACADDR_TYPE,
DOMAIN_TYPE, /*end of addr types */
TEXT_TYPE,
- BOOL_TYPE
+ BOOL_TYPE,
+ PRIORITY_TYPE
}vtw_type_e;
typedef enum {
@@ -65,6 +66,7 @@ typedef struct {
char *val;
int cnt; /* >0 means multivalue */
char **vals; /* We might union with val */
+ vtw_type_e *val_types; /* used with vals and multitypes */
boolean free_me;
}valstruct;
diff --git a/src/common/unionfs.c b/src/common/unionfs.c
index 151c6ce..2f7cd70 100644
--- a/src/common/unionfs.c
+++ b/src/common/unionfs.c
@@ -227,10 +227,10 @@ retrieve_data(char* rel_data_path, GNode *node, char* root, NODE_OPERATION op)
//either multi or tag--shouldn't have made a difference, but arkady was confused.
vn->_config._multi = (def.tag | def.multi);
- if (def.def_tag > 0) {
+ if (def.def_tag != 0) {
vn->_config._limit = def.def_tag;
}
- else if (def.def_multi > 0) {
+ else if (def.def_multi != 0) {
vn->_config._limit = def.def_multi;
}
else {
diff --git a/src/delete.c b/src/delete.c
index f432934..4f38f54 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -322,8 +322,8 @@ int main(int argc, char **argv)
bye("Corrupted old value ---- \n%s\n-----\n", cp);
res = val_cmp(&new_value, &old_value, IN_COND);
if (!res) {
- fprintf(out_stream, "%s is not a configured value\n", new_value.val);
- bye("Not in multivalue");
+ fprintf(out_stream, "%s is not a configured value, %s\n", new_value.val,old_value.val);
+ bye("Not in multivalue");
}
touch();
if (old_value.cnt) {
diff --git a/src/set.c b/src/set.c
index 47db90c..08db114 100644
--- a/src/set.c
+++ b/src/set.c
@@ -93,7 +93,10 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val)
}
//apply limit count here, needs to be defined as a tag,multi and have a value set
- if ((defp->tag || defp->multi) && (defp->def_tag > 0 || defp->def_multi > 0)) {
+
+ //NOTE: changed behavior for def_tag==1. Needs signed 32 support in parser where -1
+ //represents embedded tag node... TODO
+ if ((defp->tag || defp->multi) && (defp->def_tag != 0 || defp->def_multi != 0)) {
//get count of siblings
char path[2048];
@@ -124,7 +127,7 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val)
}
closedir(dirp);
- if (defp->tag && file_count == 1 && defp->def_tag == 1) {
+ if (defp->tag && file_count == 1 && defp->def_tag < 0) {
//this is the special case, where the previous value should be deleted here...
char command[8192];
//let unionfs handle the diff
@@ -133,14 +136,34 @@ boolean set_validate(vtw_def *defp, char *valp, boolean empty_val)
}
if (defp->tag) {
- if (defp->def_tag > 1 && file_count >= defp->def_tag) {
- fprintf(out_stream,"Number of values exceeded for %s, allowed: %d, actual: %d\n",val,defp->def_tag,file_count);
+ if (defp->def_tag > 0 && file_count >= defp->def_tag) {
+ char *p = rindex(path,'/');
+ char tmp[2048];
+ if (p != NULL) {
+ int off = p - path;
+ strncpy(tmp,path + off + 1, strlen(path) - off - 1);
+ tmp[strlen(path) - off - 1] = '\0';
+ fprintf(out_stream,"Number of values exceeded for '%s', allowed: %d, actual: %d\n",tmp,defp->def_tag,file_count);
+ }
+ else {
+ fprintf(out_stream,"Number of values exceeded, allowed: %d, actual: %d\n",defp->def_tag,file_count);
+ }
return FALSE;
}
}
else {
if (defp->def_multi > 1 && file_count >= defp->def_multi) {
- fprintf(out_stream,"Number of values exceeded for %s, allowed: %d, actual: %d\n",val,defp->def_multi,file_count);
+ char *p = rindex(path,'/');
+ char tmp[2048];
+ if (p != NULL) {
+ int off = p - path;
+ strncpy(tmp,path + off + 1, strlen(path) - off - 1);
+ tmp[strlen(path) - off - 1] = '\0';
+ fprintf(out_stream,"Number of values exceeded for '%s', allowed: %d, actual: %d\n",tmp,defp->def_tag,file_count);
+ }
+ else {
+ fprintf(out_stream,"Number of values exceeded, allowed: %d, actual: %d\n",defp->def_tag,file_count);
+ }
return FALSE;
}
}