X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=src%2Fecoli_node_any.c;h=5bf498422a4f719f7718ceec2a7711395d9dff89;hb=331d87b8f34493ea7eb4db75fa9d90b2e3ed503b;hp=9166dbbd5fa0799794c25f31d74ea72799b2bfec;hpb=18d03456d96f7a086a2ccc82ce97fcf056848d90;p=protos%2Flibecoli.git diff --git a/src/ecoli_node_any.c b/src/ecoli_node_any.c index 9166dbb..5bf4984 100644 --- a/src/ecoli_node_any.c +++ b/src/ecoli_node_any.c @@ -14,42 +14,41 @@ #include #include #include -#include +#include #include #include EC_LOG_TYPE_REGISTER(node_any); struct ec_node_any { - struct ec_node gen; char *attr_name; }; -static int ec_node_any_parse(const struct ec_node *gen_node, - struct ec_parse *state, +static int ec_node_any_parse(const struct ec_node *node, + struct ec_pnode *pstate, const struct ec_strvec *strvec) { - struct ec_node_any *node = (struct ec_node_any *)gen_node; - const struct ec_keyval *attrs; + struct ec_node_any *priv = ec_node_priv(node); + const struct ec_dict *attrs; - (void)state; + (void)pstate; if (ec_strvec_len(strvec) == 0) return EC_PARSE_NOMATCH; - if (node->attr_name != NULL) { + if (priv->attr_name != NULL) { attrs = ec_strvec_get_attrs(strvec, 0); - if (attrs == NULL || !ec_keyval_has_key(attrs, node->attr_name)) + if (attrs == NULL || !ec_dict_has_key(attrs, priv->attr_name)) return EC_PARSE_NOMATCH; } return 1; } -static void ec_node_any_free_priv(struct ec_node *gen_node) +static void ec_node_any_free_priv(struct ec_node *node) { - struct ec_node_any *node = (struct ec_node_any *)gen_node; + struct ec_node_any *priv = ec_node_priv(node); - ec_free(node->attr_name); + ec_free(priv->attr_name); } static const struct ec_config_schema ec_node_any_schema[] = { @@ -63,10 +62,10 @@ static const struct ec_config_schema ec_node_any_schema[] = { }, }; -static int ec_node_any_set_config(struct ec_node *gen_node, +static int ec_node_any_set_config(struct ec_node *node, const struct ec_config *config) { - struct ec_node_any *node = (struct ec_node_any *)gen_node; + struct ec_node_any *priv = ec_node_priv(node); const struct ec_config *value = NULL; char *s = NULL; @@ -77,8 +76,8 @@ static int ec_node_any_set_config(struct ec_node *gen_node, goto fail; } - ec_free(node->attr_name); - node->attr_name = s; + ec_free(priv->attr_name); + priv->attr_name = s; return 0; @@ -92,13 +91,44 @@ static struct ec_node_type ec_node_any_type = { .schema = ec_node_any_schema, .set_config = ec_node_any_set_config, .parse = ec_node_any_parse, - .complete = ec_node_complete_unknown, .size = sizeof(struct ec_node_any), .free_priv = ec_node_any_free_priv, }; EC_NODE_TYPE_REGISTER(ec_node_any_type); +struct ec_node * +ec_node_any(const char *id, const char *attr) +{ + struct ec_config *config = NULL; + struct ec_node *node = NULL; + int ret; + + node = ec_node_from_type(&ec_node_any_type, id); + if (node == NULL) + return NULL; + + config = ec_config_dict(); + if (config == NULL) + goto fail; + + ret = ec_config_dict_set(config, "attr", ec_config_string(attr)); + if (ret < 0) + goto fail; + + ret = ec_node_set_config(node, config); + config = NULL; + if (ret < 0) + goto fail; + + return node; + +fail: + ec_config_free(config); + ec_node_free(node); + return NULL; +} + /* LCOV_EXCL_START */ static int ec_node_any_testcase(void) { @@ -122,11 +152,11 @@ static int ec_node_any_testcase(void) return -1; } testres |= EC_TEST_CHECK_COMPLETE(node, - "", EC_NODE_ENDLIST, - EC_NODE_ENDLIST); + "", EC_VA_END, + EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "foo", EC_NODE_ENDLIST, - EC_NODE_ENDLIST); + "foo", EC_VA_END, + EC_VA_END); ec_node_free(node); return testres;