Skip to content

Commit

Permalink
Clean up syntax for list to list assignments
Browse files Browse the repository at this point in the history
list !* ANY	remove all attributes in the list
list := list2	delete list, copy list2, and assign the copy to list
list += list2	copy list2, and append the copy to list

list := `foo`   read attrs from program, and assign to list
list += `foo`	read attrs from program, and append to list
  • Loading branch information
alandekok committed Apr 14, 2014
1 parent a0ae300 commit ab81dc3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/main/map.c
Expand Up @@ -479,26 +479,34 @@ value_pair_map_t *radius_cp2map(TALLOC_CTX *ctx, CONF_PAIR *cp,
}
}

switch (map->src->type) {
if (map->dst->type == VPT_TYPE_LIST) {
/*
* Only += and -= operators are supported for list copy.
* Only += and :=, and !* operators are supported
* for lists.
*/
case VPT_TYPE_LIST:
switch (map->op) {
case T_OP_SUB:
case T_OP_ADD:
break;

default:
cf_log_err(ci, "Operator \"%s\" not allowed "
"for list copy",
fr_int2str(fr_tokens, map->op, "<INVALID>"));
switch (map->op) {
case T_OP_CMP_FALSE:
if ((map->src->type != VPT_TYPE_LITERAL) ||
(strcmp(map->src->name, "ANY") != 0)) {
cf_log_err(ci, "Must use 'ANY' for list '!*' operator");
goto error;
}
break;
break;

default:
case T_OP_ADD:
case T_OP_SET:
if ((map->src->type != VPT_TYPE_LIST) &&
(map->src->type != VPT_TYPE_EXEC)) {
cf_log_err(ci, "List assignment MUST be done from another list");
goto error;
}
break;

default:
cf_log_err(ci, "Operator \"%s\" not allowed for list copy",
fr_int2str(fr_tokens, map->op, "<INVALID>"));
goto error;
}
}

return map;
Expand Down
19 changes: 19 additions & 0 deletions src/tests/keywords/update-list-error
@@ -0,0 +1,19 @@
#
# PRE: update
#
# It's an error to update lists that don't exist.
#
update {
request := reply
config += request
reply !* ANY
}

update {
reply += `/path/to/foo bar baz`
}


update {
request := nope # ERROR
}

0 comments on commit ab81dc3

Please sign in to comment.