X-Git-Url: https://git.octo.it/?p=collection4.git;a=blobdiff_plain;f=graph_ident.c;h=b008a56dac3ae6da05fc3e5d0b2b44b141f826fa;hp=9a52003c5a7dfd0816b1967cc1f5cf316e078c62;hb=af2ed61b280e1ec169aba2bcb9df30ac76b006d2;hpb=477b8a38dc1b3d0ae5e726f765722c962b2fcb46 diff --git a/graph_ident.c b/graph_ident.c index 9a52003..b008a56 100644 --- a/graph_ident.c +++ b/graph_ident.c @@ -1,16 +1,12 @@ #include #include #include +#include #include /* PATH_MAX */ #include "graph_ident.h" #include "common.h" - -#define ANY_TOKEN "/any/" -#define ALL_TOKEN "/all/" - -#define IS_ANY(str) (((str) != NULL) && (strcasecmp (ANY_TOKEN, (str)) == 0)) -#define IS_ALL(str) (((str) != NULL) && (strcasecmp (ALL_TOKEN, (str)) == 0)) +#include "filesystem.h" /* * Data types @@ -28,32 +24,39 @@ struct graph_ident_s /* {{{ */ * Private functions */ static char *part_copy_with_selector (const char *selector, /* {{{ */ - const char *part, _Bool keep_all_selector) + const char *part, unsigned int flags) { if ((selector == NULL) || (part == NULL)) return (NULL); - if (IS_ANY (part)) + if ((flags & IDENT_FLAG_REPLACE_ANY) && IS_ANY (part)) return (NULL); - if (!keep_all_selector && IS_ALL (part)) + if ((flags & IDENT_FLAG_REPLACE_ALL) && IS_ALL (part)) return (NULL); - /* ANY in the graph selection => concrete value in the instance. */ + /* Replace the ANY and ALL flags if requested and if the selecter actually + * *is* that flag. */ if (IS_ANY (selector)) - return (strdup (part)); + { + if (flags & IDENT_FLAG_REPLACE_ANY) + return (strdup (part)); + else + return (strdup (selector)); + } if (IS_ALL (selector)) { - if (keep_all_selector) - return (strdup (ALL_TOKEN)); - else + if (flags & IDENT_FLAG_REPLACE_ALL) return (strdup (part)); + else + return (strdup (selector)); } if (strcmp (selector, part) != 0) return (NULL); + /* Otherwise (no replacement), return a copy of the selector. */ return (strdup (selector)); } /* }}} char *part_copy_with_selector */ @@ -129,7 +132,7 @@ graph_ident_t *ident_create (const char *host, /* {{{ */ return (ret); } /* }}} graph_ident_t *ident_create */ -graph_ident_t *ident_clone (const graph_ident_t *ident) +graph_ident_t *ident_clone (const graph_ident_t *ident) /* {{{ */ { return (ident_create (ident->host, ident->plugin, ident->plugin_instance, @@ -137,7 +140,7 @@ graph_ident_t *ident_clone (const graph_ident_t *ident) } /* }}} graph_ident_t *ident_clone */ graph_ident_t *ident_copy_with_selector (const graph_ident_t *selector, /* {{{ */ - const graph_ident_t *ident, _Bool keep_all_selector) + const graph_ident_t *ident, unsigned int flags) { graph_ident_t *ret; @@ -155,8 +158,7 @@ graph_ident_t *ident_copy_with_selector (const graph_ident_t *selector, /* {{{ * ret->type_instance = NULL; #define COPY_PART(p) do { \ - ret->p = part_copy_with_selector (selector->p, ident->p, \ - keep_all_selector); \ + ret->p = part_copy_with_selector (selector->p, ident->p, flags); \ if (ret->p == NULL) \ { \ free (ret->host); \ @@ -193,6 +195,7 @@ void ident_destroy (graph_ident_t *ident) /* {{{ */ free (ident); } /* }}} void ident_destroy */ +/* ident_get_* methods {{{ */ const char *ident_get_host (graph_ident_t *ident) /* {{{ */ { if (ident == NULL) @@ -232,6 +235,95 @@ const char *ident_get_type_instance (graph_ident_t *ident) /* {{{ */ return (ident->type_instance); } /* }}} char *ident_get_type_instance */ +/* }}} ident_get_* methods */ + +/* ident_set_* methods {{{ */ +int ident_set_host (graph_ident_t *ident, const char *host) /* {{{ */ +{ + char *tmp; + + if ((ident == NULL) || (host == NULL)) + return (EINVAL); + + tmp = strdup (host); + if (tmp == NULL) + return (ENOMEM); + + free (ident->host); + ident->host = tmp; + + return (0); +} /* }}} int ident_set_host */ + +int ident_set_plugin (graph_ident_t *ident, const char *plugin) /* {{{ */ +{ + char *tmp; + + if ((ident == NULL) || (plugin == NULL)) + return (EINVAL); + + tmp = strdup (plugin); + if (tmp == NULL) + return (ENOMEM); + + free (ident->plugin); + ident->plugin = tmp; + + return (0); +} /* }}} int ident_set_plugin */ + +int ident_set_plugin_instance (graph_ident_t *ident, const char *plugin_instance) /* {{{ */ +{ + char *tmp; + + if ((ident == NULL) || (plugin_instance == NULL)) + return (EINVAL); + + tmp = strdup (plugin_instance); + if (tmp == NULL) + return (ENOMEM); + + free (ident->plugin_instance); + ident->plugin_instance = tmp; + + return (0); +} /* }}} int ident_set_plugin_instance */ + +int ident_set_type (graph_ident_t *ident, const char *type) /* {{{ */ +{ + char *tmp; + + if ((ident == NULL) || (type == NULL)) + return (EINVAL); + + tmp = strdup (type); + if (tmp == NULL) + return (ENOMEM); + + free (ident->type); + ident->type = tmp; + + return (0); +} /* }}} int ident_set_type */ + +int ident_set_type_instance (graph_ident_t *ident, const char *type_instance) /* {{{ */ +{ + char *tmp; + + if ((ident == NULL) || (type_instance == NULL)) + return (EINVAL); + + tmp = strdup (type_instance); + if (tmp == NULL) + return (ENOMEM); + + free (ident->type_instance); + ident->type_instance = tmp; + + return (0); +} /* }}} int ident_set_type_instance */ + +/* }}} ident_set_* methods */ int ident_compare (const graph_ident_t *i0, /* {{{ */ const graph_ident_t *i1)