summaryrefslogtreecommitdiffstats
path: root/libnetdata/dictionary
diff options
context:
space:
mode:
authorSimon Nagl <simonnagl@aim.com>2019-02-04 15:33:07 +0100
committerVladimir Kobal <vlad@prokk.net>2019-02-04 16:33:07 +0200
commitb6aeb7e3d98268c16d923c08a06795390c75a191 (patch)
treebc89703eeea62e513a7b0e84d2f6de91f8eaf922 /libnetdata/dictionary
parentadaaae7cc77c628cc4bf78dbe84c93ef44c21ef0 (diff)
CUPS plugin (#5188)
* Implement a CUPS collector plugin * Compile cups.plugin only if enabled * Fix build with CFLAGS -O1 -ggdb -Wall -Wextra -Wformat-signedness -fstack-protector-all -DNETDATA_INTERNAL_CHECKS=1 -D_FORTIFY_SOURCE=2 -DNETDATA_VERIFY_LOCKS=1 * cups.plugin check for all used functions * Use cups-config to configure cups compiler flags * Do not quit if cups-config is not installed * Fix compiler warning collectors/cups.plugin/cups_plugin.c:359:27: warning: format '%d' expects argument of type 'int', but argument 6 has type 'unsigned int' [-Wformat=] * Add cups.plugin to toc and overview documentation * cups.plugin fix plugin doc layout * cups.plugin: Add prerequisites doc * cups.plugin: Fix error if cups is not installed
Diffstat (limited to 'libnetdata/dictionary')
-rw-r--r--libnetdata/dictionary/dictionary.c35
-rw-r--r--libnetdata/dictionary/dictionary.h1
2 files changed, 36 insertions, 0 deletions
diff --git a/libnetdata/dictionary/dictionary.c b/libnetdata/dictionary/dictionary.c
index dd94a801dc..cfcf1fbab1 100644
--- a/libnetdata/dictionary/dictionary.c
+++ b/libnetdata/dictionary/dictionary.c
@@ -292,3 +292,38 @@ int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *data
return ret;
}
+
+static int dictionary_walker_name_value(avl *a, int (*callback)(char *name, void *entry, void *data), void *data) {
+ int total = 0, ret = 0;
+
+ if(a->avl_link[0]) {
+ ret = dictionary_walker_name_value(a->avl_link[0], callback, data);
+ if(ret < 0) return ret;
+ total += ret;
+ }
+
+ ret = callback(((NAME_VALUE *)a)->name, ((NAME_VALUE *)a)->value, data);
+ if(ret < 0) return ret;
+ total += ret;
+
+ if(a->avl_link[1]) {
+ ret = dictionary_walker_name_value(a->avl_link[1], callback, data);
+ if (ret < 0) return ret;
+ total += ret;
+ }
+
+ return total;
+}
+
+int dictionary_get_all_name_value(DICTIONARY *dict, int (*callback)(char *name, void *entry, void *data), void *data) {
+ int ret = 0;
+
+ dictionary_read_lock(dict);
+
+ if(likely(dict->values_index.root))
+ ret = dictionary_walker_name_value(dict->values_index.root, callback, data);
+
+ dictionary_unlock(dict);
+
+ return ret;
+}
diff --git a/libnetdata/dictionary/dictionary.h b/libnetdata/dictionary/dictionary.h
index 61b9bfc615..9be261eb22 100644
--- a/libnetdata/dictionary/dictionary.h
+++ b/libnetdata/dictionary/dictionary.h
@@ -44,5 +44,6 @@ extern void *dictionary_get(DICTIONARY *dict, const char *name);
extern int dictionary_del(DICTIONARY *dict, const char *name);
extern int dictionary_get_all(DICTIONARY *dict, int (*callback)(void *entry, void *d), void *data);
+extern int dictionary_get_all_name_value(DICTIONARY *dict, int (*callback)(char *name, void *entry, void *d), void *data);
#endif /* NETDATA_DICTIONARY_H */