Skip to content

Commit

Permalink
iserver CHANGE support leafref nodes for setting data to the sysrepo
Browse files Browse the repository at this point in the history
Since sysrepo does not supposrt to set leafref directly, we have to Resolve
leafref node to its target and set the leafref node with its target type.

Fixes CESNET#16
  • Loading branch information
rkrejci committed Aug 22, 2016
1 parent 4dceb4d commit a574dc8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ op_set_srval(struct lyd_node *node, char *path, int dup, sr_val_t *val, char **v
uint32_t i;
struct lyd_node_leaf_list *leaf;
const char *str;
LY_DATA_TYPE type;

if (!dup) {
assert(val_buf);
Expand All @@ -143,8 +144,9 @@ op_set_srval(struct lyd_node *node, char *path, int dup, sr_val_t *val, char **v
case LYS_LEAF:
case LYS_LEAFLIST:
leaf = (struct lyd_node_leaf_list *)node;

switch (((struct lys_node_leaf *)node->schema)->type.base) {
settype:
type = leaf->value_type;
switch (type & LY_DATA_TYPE_MASK) {
case LY_TYPE_BINARY:
val->type = SR_BINARY_T;
str = leaf->value.binary;
Expand All @@ -168,7 +170,7 @@ op_set_srval(struct lyd_node *node, char *path, int dup, sr_val_t *val, char **v
case LY_TYPE_DEC64:
val->type = SR_DECIMAL64_T;
val->data.decimal64_val = (double)leaf->value.dec64;
for (i = 0; i < ((struct lys_node_leaf *)node->schema)->type.info.dec64.dig; i++) {
for (i = 0; i < ((struct lys_node_leaf *)leaf->schema)->type.info.dec64.dig; i++) {
/* shift decimal point */
val->data.decimal64_val *= 0.1;
}
Expand Down Expand Up @@ -209,6 +211,7 @@ op_set_srval(struct lyd_node *node, char *path, int dup, sr_val_t *val, char **v
break;
case LY_TYPE_INST:
val->type = SR_INSTANCEID_T;
val->data.instanceid_val = dup ? strdup(leaf->value_str) : (char*)leaf->value_str;
break;
case LY_TYPE_STRING:
val->type = SR_STRING_T;
Expand Down Expand Up @@ -251,8 +254,11 @@ op_set_srval(struct lyd_node *node, char *path, int dup, sr_val_t *val, char **v
val->type = SR_UINT64_T;
val->data.uint64_val = leaf->value.uint64;
break;
case LY_TYPE_LEAFREF:
leaf = (struct lyd_node_leaf_list *)leaf->value.leafref;
goto settype;
default:
//LY_LEAFREF, LY_DERIVED, LY_UNION
//LY_DERIVED, LY_UNION
val->type = SR_UNKNOWN_T;
break;
}
Expand Down

0 comments on commit a574dc8

Please sign in to comment.