#include <ecoli_strvec.h>
#include <ecoli_keyval.h>
#include <ecoli_log.h>
+#include <ecoli_config.h>
#include <ecoli_test.h>
#include <ecoli_node.h>
return type;
}
+ errno = ENOENT;
return NULL;
}
int ec_node_type_register(struct ec_node_type *type)
{
- if (ec_node_type_lookup(type->name) != NULL)
- return -EEXIST;
- if (type->size < sizeof(struct ec_node))
- return -EINVAL;
+ EC_CHECK_ARG(type->size >= sizeof(struct ec_node), -1, EINVAL);
+
+ if (ec_node_type_lookup(type->name) != NULL) {
+ errno = EEXIST;
+ return -1;
+ }
TAILQ_INSERT_TAIL(&node_type_list, type, next);
ec_free(node->id);
ec_free(node->desc);
ec_keyval_free(node->attrs);
+ ec_config_free(node->config);
ec_free(node);
}
fail:
ec_free(children);
+ assert(errno != 0);
return -1;
}
+int
+ec_node_set_config(struct ec_node *node, struct ec_config *config)
+{
+ if (node->type->schema == NULL) {
+ errno = EINVAL;
+ goto fail;
+ }
+ if (ec_config_validate(config, node->type->schema,
+ node->type->schema_len) < 0)
+ goto fail;
+ if (node->type->set_config != NULL) {
+ if (node->type->set_config(node, config) < 0)
+ goto fail;
+ }
+
+ ec_config_free(node->config);
+ node->config = config;
+
+ return 0;
+
+fail:
+ return -1;
+}
+
+const struct ec_config *ec_node_get_config(struct ec_node *node)
+{
+ return node->config;
+}
+
#if 0 /* later */
int ec_node_del_child(struct ec_node *node, struct ec_node *child)
{
const char *ec_node_id(const struct ec_node *node)
{
- if (node->id == NULL)
- return "None";
return node->id;
}
errno = EINVAL;
return -1;
}
+
return 0;
}
int testres = 0;
int ret;
- f = open_memstream(&buf, &buflen);
- if (f == NULL)
- goto fail;
-
node = EC_NODE_SEQ(EC_NO_ID,
ec_node_str("id_x", "x"),
ec_node_str("id_y", "y"));
if (node == NULL)
goto fail;
+ ec_node_clone(node);
+ ec_node_free(node);
+
+ f = open_memstream(&buf, &buflen);
+ if (f == NULL)
+ goto fail;
ec_node_dump(f, node);
ec_node_type_dump(f);
ec_node_dump(f, NULL);
"type=str id=id_y"),
"bad dump\n");
free(buf);
+ buf = NULL;
+
+ testres |= EC_TEST_CHECK(
+ !strcmp(ec_node_type(node)->name, "seq") &&
+ !strcmp(ec_node_id(node), EC_NO_ID) &&
+ !strcmp(ec_node_desc(node), "<seq>"),
+ "bad child 0");
testres |= EC_TEST_CHECK(
ec_node_get_children_count(node) == 2,
child = ec_node_find(node, "id_x");
testres |= EC_TEST_CHECK(child != NULL &&
!strcmp(ec_node_type(child)->name, "str") &&
- !strcmp(ec_node_id(child), "id_x"),
+ !strcmp(ec_node_id(child), "id_x") &&
+ !strcmp(ec_node_desc(child), "x"),
"bad child id_x");
child = ec_node_find(node, "id_dezdex");
testres |= EC_TEST_CHECK(child == NULL,
ec_node_free(node);
if (f != NULL)
fclose(f);
+ free(buf);
+ assert(errno != 0);
return -1;
}
/* LCOV_EXCL_STOP */