summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2f6cab9)
raw | patch | inline | side by side (parent: 2f6cab9)
author | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Fri, 3 Feb 2012 08:30:44 +0000 (09:30 +0100) | ||
committer | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Fri, 3 Feb 2012 08:30:44 +0000 (09:30 +0100) |
src/write_graphite.c | patch | blob | history |
diff --git a/src/write_graphite.c b/src/write_graphite.c
index 827ec3881263a749eeb68d89c50d7a357a185ac4..9e96198d6951c4eb64f469b4a28e083fe3950a07 100644 (file)
--- a/src/write_graphite.c
+++ b/src/write_graphite.c
const char *ds_name, const char dotchar)
{
int status;
- char *n_hostname = 0;
- char *n_type_instance = 0;
+ char *n_hostname = NULL;
+ char *n_plugin = NULL;
+ char *n_plugin_instance = NULL;
+ char *n_type = NULL;
+ char *n_type_instance = NULL;
assert (plugin != NULL);
assert (type != NULL);
- if (prefix == NULL)
- prefix = "";
-
- if (postfix == NULL)
- postfix = "";
-
if ((n_hostname = malloc(strlen(hostname)+1)) == NULL)
{
ERROR ("Unable to allocate memory for normalized hostname buffer");
return (-1);
}
+ if ((n_plugin = malloc(strlen(plugin)+1)) == NULL)
+ {
+ ERROR ("Unable to allocate memory for normalized plugin buffer");
+ return (-1);
+ }
+
+ if ((n_type = malloc(strlen(type)+1)) == NULL)
+ {
+ ERROR ("Unable to allocate memory for normalized type buffer");
+ return (-1);
+ }
+
if (swap_chars(n_hostname, hostname, '.', dotchar) == -1)
{
ERROR ("Unable to normalize hostname");
return (-1);
}
- if (type_instance && type_instance[0] != '\0') {
+ if (swap_chars(n_plugin, plugin, ' ', '_') == -1)
+ {
+ ERROR ("Unable to normalize plugin");
+ return (-1);
+ }
+
+ if (swap_chars(n_type, type, ' ', '_') == -1)
+ {
+ ERROR ("Unable to normalize type");
+ return (-1);
+ }
+
+ if (type_instance != NULL && type_instance[0] != '\0')
+ {
if ((n_type_instance = malloc(strlen(type_instance)+1)) == NULL)
{
ERROR ("Unable to allocate memory for normalized datasource name buffer");
ERROR ("Unable to normalize datasource name");
return (-1);
}
+ if (swap_chars(n_type_instance, type_instance, ' ', '_') == -1)
+ {
+ ERROR ("Unable to normalize datasource name");
+ return (-1);
+ }
+ }
+
+ if (plugin_instance != NULL && plugin_instance[0] != '\0')
+ {
+ if ((n_plugin_instance = malloc(strlen(plugin_instance)+1)) == NULL)
+ {
+ ERROR ("Unable to allocate memory for normalized plugin instance buffer");
+ return (-1);
+ }
+ if (swap_chars(n_plugin_instance, plugin_instance, ' ', '_') == -1)
+ {
+ ERROR ("Unable to normalize datasource name");
+ return (-1);
+ }
}
- if ((plugin_instance == NULL) || (plugin_instance[0] == '\0'))
+ if ((n_plugin_instance == NULL) || (n_plugin_instance[0] == '\0'))
{
if ((n_type_instance == NULL) || (n_type_instance[0] == '\0'))
{
if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s",
- prefix, n_hostname, postfix, plugin, type);
+ prefix, n_hostname, postfix, n_plugin, n_type);
else
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
- prefix, n_hostname, postfix, plugin, type, ds_name);
+ prefix, n_hostname, postfix, n_plugin, n_type, ds_name);
}
else
{
if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s",
- prefix, n_hostname, postfix, plugin, type,
+ prefix, n_hostname, postfix, n_plugin, n_type,
n_type_instance);
else
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s.%s",
- prefix, n_hostname, postfix, plugin, type,
+ prefix, n_hostname, postfix, n_plugin, n_type,
n_type_instance, ds_name);
}
}
{
if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
- prefix, n_hostname, postfix, plugin,
- plugin_instance, type);
+ prefix, n_hostname, postfix, n_plugin,
+ n_plugin_instance, n_type);
else
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s.%s",
- prefix, n_hostname, postfix, plugin,
- plugin_instance, type, ds_name);
+ prefix, n_hostname, postfix, n_plugin,
+ n_plugin_instance, n_type, ds_name);
}
else
{
if ((ds_name == NULL) || (ds_name[0] == '\0'))
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s",
- prefix, n_hostname, postfix, plugin,
- plugin_instance, type, n_type_instance);
+ prefix, n_hostname, postfix, n_plugin,
+ n_plugin_instance, n_type, n_type_instance);
else
status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s.%s",
- prefix, n_hostname, postfix, plugin,
- plugin_instance, type, n_type_instance, ds_name);
+ prefix, n_hostname, postfix, n_plugin,
+ n_plugin_instance, n_type, n_type_instance, ds_name);
}
}
sfree(n_hostname);
sfree(n_type_instance);
+ sfree(n_type);
+ sfree(n_plugin);
+ sfree(n_plugin_instance);
if ((status < 1) || (status >= ret_len))
return (-1);