#include "config-process.h" #include "device.h" #include "util.h" #include #include #include #include typedef struct _process_ctx { struct avl_tree *ret; } process_ctx_t; typedef struct _config_subtype { struct avl_node node; } config_subtype_t; static device_t * config_process_device(const char *name, struct json_object *obj) { const char *typename = NULL; struct json_object *device = neco_json_get_value(obj, "device", json_type_object); if (device) typename = neco_json_get_string(device, "type"); const device_type_t *type = get_device_type(typename ?: "interface"); if (!type) return NULL; return type->process_config(name, obj); } struct avl_tree * config_process(struct json_object *config) { if (!json_object_is_type(config, json_type_object)) return NULL; struct json_object *devices = neco_json_get_value(config, "devices", json_type_object); if (!devices) return NULL; process_ctx_t ctx; ctx.ret = calloc(1, sizeof(*ctx.ret)); if (!ctx.ret) return NULL; avl_init(ctx.ret, avl_strcmp, false, NULL); json_object_object_foreach(devices, name, obj) { device_t *device = config_process_device(name, obj); if (!device) continue; avl_insert(ctx.ret, &device->node); } return ctx.ret; }