summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5997c21)
raw | patch | inline | side by side (parent: 5997c21)
author | Florian Forster <octo@collectd.org> | |
Tue, 8 Dec 2015 10:30:13 +0000 (11:30 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Tue, 8 Dec 2015 10:31:48 +0000 (11:31 +0100) |
CID: 38008
src/utils_format_json.c | patch | blob | history |
index 48aa4fc61c1eea967c15c3a51c934c374b48c23b..8d46edd03418832d20277a78d82a07bac81bd4df 100644 (file)
--- a/src/utils_format_json.c
+++ b/src/utils_format_json.c
return (0);
} /* }}} int dsnames_to_json */
-static int meta_data_to_json (char *buffer, size_t buffer_size, /* {{{ */
- meta_data_t *meta)
+static int meta_data_keys_to_json (char *buffer, size_t buffer_size, /* {{{ */
+ meta_data_t *meta, char **keys, size_t keys_num)
{
size_t offset = 0;
- char **keys = NULL;
- int keys_num;
int status;
- int i;
+ size_t i;
buffer[0] = 0;
- if (meta == NULL)
- return (EINVAL);
-
#define BUFFER_ADD(...) do { \
status = ssnprintf (buffer + offset, buffer_size - offset, \
__VA_ARGS__); \
offset += ((size_t) status); \
} while (0)
- keys_num = meta_data_toc (meta, &keys);
- if (keys_num == 0)
- {
- sfree (keys);
- return (0);
- }
-
for (i = 0; i < keys_num; ++i)
{
int type;
if (meta_data_get_boolean (meta, key, &value) == 0)
BUFFER_ADD (",\"%s\":%s", key, value ? "true" : "false");
}
-
- free (key);
} /* for (keys) */
- free (keys);
if (offset <= 0)
return (ENOENT);
#undef BUFFER_ADD
return (0);
+} /* }}} int meta_data_keys_to_json */
+
+static int meta_data_to_json (char *buffer, size_t buffer_size, /* {{{ */
+ meta_data_t *meta)
+{
+ char **keys = NULL;
+ size_t keys_num;
+ int status;
+ size_t i;
+
+ if ((buffer == NULL) || (buffer_size == 0) || (meta == NULL))
+ return (EINVAL);
+
+ status = meta_data_toc (meta, &keys);
+ if (status <= 0)
+ return (status);
+ keys_num = (size_t) status;
+
+ status = meta_data_keys_to_json (buffer, buffer_size, meta, keys, keys_num);
+
+ for (i = 0; i < keys_num; ++i)
+ sfree (keys[i]);
+ sfree (keys);
+
+ return status;
} /* }}} int meta_data_to_json */
static int value_list_to_json (char *buffer, size_t buffer_size, /* {{{ */