summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ba7c803)
raw | patch | inline | side by side (parent: ba7c803)
author | Florian Forster <octo@huhu.verplant.org> | |
Wed, 1 Jul 2009 12:50:24 +0000 (14:50 +0200) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 1 Jul 2009 13:41:44 +0000 (15:41 +0200) |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history | |
src/powerdns.c | patch | blob | history | |
src/table.c | patch | blob | history | |
src/utils_db_query.c | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 8de871bd70a362b4066a2a865019eeb76900a0f1..d284fb879c028211f1a993b5b65f2238ee94ec5c 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (0);
} /* int parse_identifier */
-int parse_value (const char *value, value_t *ret_value, const data_source_t ds)
+int parse_value (const char *value, value_t *ret_value, int ds_type)
{
- char *endptr = NULL;
-
- if (DS_TYPE_COUNTER == ds.type)
- ret_value->counter = (counter_t)strtoll (value, &endptr, 0);
- else if (DS_TYPE_GAUGE == ds.type)
- ret_value->gauge = (gauge_t)strtod (value, &endptr);
- else if (DS_TYPE_DERIVE == ds.type)
- ret_value->counter = (derive_t)strtoll (value, &endptr, 0);
- else if (DS_TYPE_ABSOLUTE == ds.type)
- ret_value->counter = (absolute_t)strtoll (value, &endptr, 0);
- else {
- ERROR ("parse_value: Invalid data source \"%s\" "
- "(type = %i).", ds.name, ds.type);
- return -1;
- }
-
- if (value == endptr) {
- ERROR ("parse_value: Failed to parse string as number: %s.", value);
- return -1;
- }
- else if ((NULL != endptr) && ('\0' != *endptr))
- WARNING ("parse_value: Ignoring trailing garbage after number: %s.",
- endptr);
- return 0;
+ char *endptr = NULL;
+
+ switch (ds_type)
+ {
+ case DS_TYPE_COUNTER:
+ ret_value->counter = (counter_t) strtoull (value, &endptr, 0);
+ break;
+
+ case DS_TYPE_GAUGE:
+ ret_value->gauge = (gauge_t) strtod (value, &endptr);
+ break;
+
+ case DS_TYPE_DERIVE:
+ ret_value->counter = (derive_t) strtoll (value, &endptr, 0);
+ break;
+
+ case DS_TYPE_ABSOLUTE:
+ ret_value->counter = (absolute_t) strtoull (value, &endptr, 0);
+ break;
+
+ default:
+ ERROR ("parse_value: Invalid data source type: %i.", ds_type);
+ return -1;
+ }
+
+ if (value == endptr) {
+ ERROR ("parse_value: Failed to parse string as number: %s.", value);
+ return -1;
+ }
+ else if ((NULL != endptr) && ('\0' != *endptr))
+ WARNING ("parse_value: Ignoring trailing garbage after number: %s.",
+ endptr);
+ return 0;
} /* int parse_value */
int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
{
if ((strcmp ("U", ptr) == 0) && (ds->ds[i].type == DS_TYPE_GAUGE))
vl->values[i].gauge = NAN;
- else if (0 != parse_value (ptr, &vl->values[i], ds->ds[i]))
+ else if (0 != parse_value (ptr, &vl->values[i], ds->ds[i].type))
return -1;
}
diff --git a/src/common.h b/src/common.h
index d0cc4e829b59a2bf895248ac8bf7664b727e655e..e424f5dd88c652e81e4ac8a6628443c5c8d4e0f0 100644 (file)
--- a/src/common.h
+++ b/src/common.h
int parse_identifier (char *str, char **ret_host,
char **ret_plugin, char **ret_plugin_instance,
char **ret_type, char **ret_type_instance);
-int parse_value (const char *value, value_t *ret_value, const data_source_t ds);
+int parse_value (const char *value, value_t *ret_value, int ds_type);
int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds);
#if !HAVE_GETPWNAM_R
diff --git a/src/powerdns.c b/src/powerdns.c
index beb49fbb64a1dc7d3fb97d82f31ffe05fad98f7d..8799702792f27efa34cbed6e84aa354b0fe698f4 100644 (file)
--- a/src/powerdns.c
+++ b/src/powerdns.c
return;
}
- if (0 != parse_value (value, &values[0], ds->ds[0]))
+ if (0 != parse_value (value, &values[0], ds->ds[0].type))
{
ERROR ("powerdns plugin: Cannot convert `%s' "
"to a number.", value);
diff --git a/src/table.c b/src/table.c
index 2911bf026a6405371f89a7719864e8a3c711fee0..9641c759b2b059a010492b39d6e583196b8038fd 100644 (file)
--- a/src/table.c
+++ b/src/table.c
assert (res->values[i] < fields_num);
value = fields[res->values[i]];
- if (0 != parse_value (value, &values[i], res->ds->ds[i]))
+ if (0 != parse_value (value, &values[i], res->ds->ds[i].type))
return -1;
}
diff --git a/src/utils_db_query.c b/src/utils_db_query.c
index 5531b25fe7fd60eb5e34300b8f2cfb0ce3cbbf2f..9a211b4dbecf247077f00129c4a14ed86527c7bc 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
vl.values_len = 1;
value_str = column_values[r->legacy_position];
- if (0 != parse_value (value_str, &vl.values[0], r->ds->ds[0]))
+ if (0 != parse_value (value_str, &vl.values[0], r->ds->ds[0].type))
{
ERROR ("db query utils: udb_legacy_result_handle_result: "
"Parsing `%s' as %s failed.", value_str,
{
char *value_str = r->values_buffer[i];
- if (0 != parse_value (value_str, &vl.values[i], r->ds->ds[i]))
+ if (0 != parse_value (value_str, &vl.values[i], r->ds->ds[i].type))
{
ERROR ("db query utils: udb_result_submit: Parsing `%s' as %s failed.",
value_str,