X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=graph_def.c;h=36b6747a4d46a9e9b7d6754734ba2e691eb27952;hb=dfabd7793b9cb3fff1525c0e924729189d0d7867;hp=529b3b19d4a18d680a72dcf4a349ca915ff31e4f;hpb=0705bc1727eda83b75e5086867ddd2b88536efed;p=collection4.git diff --git a/graph_def.c b/graph_def.c index 529b3b1..36b6747 100644 --- a/graph_def.c +++ b/graph_def.c @@ -47,6 +47,79 @@ DEF_CONFIG_FIELD (type_instance); #undef DEF_CONFIG_FIELD +static int def_config_color (const oconfig_item_t *ci, uint32_t *ret_color) /* {{{ */ +{ + char *tmp; + char *endptr; + uint32_t color; + + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) + return (EINVAL); + + tmp = ci->values[0].value.string; + + endptr = NULL; + errno = 0; + color = (uint32_t) strtoul (tmp, &endptr, /* base = */ 16); + if ((errno != 0) || (endptr == tmp) || (color > 0x00ffffff)) + return (EINVAL); + + *ret_color = color; + + return (0); +} /* }}} int def_config_color */ + +static graph_def_t *def_config_get_obj (graph_config_t *cfg, /* {{{ */ + const oconfig_item_t *ci) +{ + graph_ident_t *ident; + char *ds_name = NULL; + graph_def_t *def; + int i; + + ident = gl_graph_get_selector (cfg); + if (ident == NULL) + { + fprintf (stderr, "def_config_get_obj: gl_graph_get_selector failed"); + return (NULL); + } + + for (i = 0; i < ci->children_num; i++) + { + oconfig_item_t *child; + +#define HANDLE_FIELD(name,field) \ + else if (strcasecmp (name, child->key) == 0) \ + def_config_##field (child, ident) + + child = ci->children + i; + if (strcasecmp ("DSName", child->key) == 0) + graph_config_get_string (child, &ds_name); + + HANDLE_FIELD ("Host", host); + HANDLE_FIELD ("Plugin", plugin); + HANDLE_FIELD ("PluginInstance", plugin_instance); + HANDLE_FIELD ("Type", type); + HANDLE_FIELD ("TypeInstance", type_instance); + +#undef HANDLE_FIELD + } + + def = def_create (cfg, ident, ds_name); + if (def == NULL) + { + fprintf (stderr, "def_config_get_obj: def_create failed\n"); + ident_destroy (ident); + free (ds_name); + return (NULL); + } + + ident_destroy (ident); + free (ds_name); + + return (def); +} /* }}} graph_def_t *def_config_get_obj */ + /* * Public functions */ @@ -117,52 +190,24 @@ void def_destroy (graph_def_t *def) /* {{{ */ int def_config (graph_config_t *cfg, const oconfig_item_t *ci) /* {{{ */ { - graph_ident_t *ident; - char *ds_name = NULL; - char *legend = NULL; graph_def_t *def; int i; - ident = gl_graph_get_selector (cfg); - if (ident == NULL) - return (ENOMEM); + def = def_config_get_obj (cfg, ci); + if (def == NULL) + return (EINVAL); for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child; -#define HANDLE_FIELD(name,field) \ - else if (strcasecmp (name, child->key) == 0) \ - def_config_##field (child, ident) - child = ci->children + i; - if (strcasecmp ("DSName", child->key) == 0) - graph_config_get_string (child, &ds_name); - else if (strcasecmp ("Legend", child->key) == 0) - graph_config_get_string (child, &legend); - HANDLE_FIELD ("Host", host); - HANDLE_FIELD ("Plugin", plugin); - HANDLE_FIELD ("PluginInstance", plugin_instance); - HANDLE_FIELD ("Type", type); - HANDLE_FIELD ("TypeInstance", type_instance); - -#undef HANDLE_FIELD + if (strcasecmp ("Legend", child->key) == 0) + graph_config_get_string (child, &def->legend); + else if (strcasecmp ("Color", child->key) == 0) + def_config_color (child, &def->color); } - def = def_create (cfg, ident, ds_name); - if (def == NULL) - { - fprintf (stderr, "def_config: def_create failed (ds_name = %s)\n", - (ds_name != NULL) ? ds_name : "(null)"); - ident_destroy (ident); - return (EINVAL); - } - - def->legend = legend; - - ident_destroy (ident); - free (ds_name); - return (gl_graph_add_def (cfg, def)); } /* }}} int def_config */