From 582ae3f47ec0459778c6d793ee2131e437b6131b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 17 Aug 2010 08:48:57 +0200 Subject: [PATCH] libcollectdclient: Add "lcc_identifier_compare". --- src/libcollectdclient/client.c | 29 +++++++++++++++++++++++++++++ src/libcollectdclient/collectd/client.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index 09975774..abe3ed83 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -1069,4 +1069,33 @@ int lcc_string_to_identifier (lcc_connection_t *c, /* {{{ */ return (0); } /* }}} int lcc_string_to_identifier */ +int lcc_identifier_compare (const lcc_identifier_t *i0, /* {{{ */ + const lcc_identifier_t *i1) +{ + int status; + + if ((i0 == NULL) && (i1 == NULL)) + return (0); + else if (i0 == NULL) + return (-1); + else if (i1 == NULL) + return (1); + +#define CMP_FIELD(f) do { \ + status = strcmp (i0->f, i1->f); \ + if (status != 0) \ + return (status); \ +} while (0); + + CMP_FIELD (host); + CMP_FIELD (plugin); + CMP_FIELD (plugin_instance); + CMP_FIELD (type); + CMP_FIELD (type_instance); + +#undef CMP_FIELD + + return (0); +} /* }}} int lcc_identifier_compare */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/libcollectdclient/collectd/client.h b/src/libcollectdclient/collectd/client.h index 99003538..1494c8d6 100644 --- a/src/libcollectdclient/collectd/client.h +++ b/src/libcollectdclient/collectd/client.h @@ -116,6 +116,12 @@ int lcc_identifier_to_string (lcc_connection_t *c, int lcc_string_to_identifier (lcc_connection_t *c, lcc_identifier_t *ident, const char *string); +/* Compares the identifiers "i0" and "i1" and returns less than zero or greater + * than zero if "i0" is smaller than or greater than "i1", respectively. If + * "i0" and "i1" are identical, zero is returned. */ +int lcc_identifier_compare (const lcc_identifier_t *i0, + const lcc_identifier_t *i1); + LCC_END_DECLS /* vim: set sw=2 sts=2 et : */ -- 2.11.0