summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 08d2e13)
raw | patch | inline | side by side (parent: 08d2e13)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 18 Feb 2009 13:20:51 +0000 (14:20 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Feb 2009 08:50:11 +0000 (09:50 +0100) |
This function might be useful for other plugins as well. Also, it has been
renamed to replace_special() which is slightly more appropriate imho.
renamed to replace_special() which is slightly more appropriate imho.
src/bind.c | patch | blob | history | |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/bind.c b/src/bind.c
index 8e785d98004f4be270a12b5a4979076468eb83a0..13967bb1a624fdda73bb5a19fc36d318fd5d91a4 100644 (file)
--- a/src/bind.c
+++ b/src/bind.c
STATIC_ARRAY_SIZE (memsummary_translation_table);
/* }}} */
-static void remove_special (char *buffer, size_t buffer_size) /* {{{ */
-{
- size_t i;
-
- for (i = 0; i < buffer_size; i++)
- {
- if (buffer[i] == 0)
- return;
- if ((!isalnum ((int) buffer[i])) && (buffer[i] != '-'))
- buffer[i] = '_';
- }
-} /* }}} void remove_special */
-
static void submit_counter(time_t ts, const char *plugin_instance, /* {{{ */
const char *type, const char *type_instance, counter_t value)
{
if (plugin_instance) {
sstrncpy(vl.plugin_instance, plugin_instance,
sizeof(vl.plugin_instance));
- remove_special (vl.plugin_instance, sizeof (vl.plugin_instance));
+ replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
}
sstrncpy(vl.type, type, sizeof(vl.type));
if (type_instance) {
sstrncpy(vl.type_instance, type_instance,
sizeof(vl.type_instance));
- remove_special (vl.plugin_instance, sizeof (vl.plugin_instance));
+ replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
}
plugin_dispatch_values(&vl);
} /* }}} void submit_counter */
diff --git a/src/common.c b/src/common.c
index 28f16da0190ada6346806335f8f0ba484afc7f72..3ec4c6e1442947422eff75e5a3ed3f6d24dc7224 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (0);
} /* int escape_slashes */
+void replace_special (char *buffer, size_t buffer_size)
+{
+ size_t i;
+
+ for (i = 0; i < buffer_size; i++)
+ {
+ if (buffer[i] == 0)
+ return;
+ if ((!isalnum ((int) buffer[i])) && (buffer[i] != '-'))
+ buffer[i] = '_';
+ }
+} /* void replace_special */
+
int timeval_cmp (struct timeval tv0, struct timeval tv1, struct timeval *delta)
{
struct timeval *larger;
diff --git a/src/common.h b/src/common.h
index 85db3adb35faf5981477b1dd90179f6aaffa9c6b..8b401d68be1329446632a7b7069497717514a61b 100644 (file)
--- a/src/common.h
+++ b/src/common.h
@@ -158,6 +158,23 @@ int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const
*/
int escape_slashes (char *buf, int buf_len);
+/*
+ * NAME
+ * replace_special
+ *
+ * DESCRIPTION
+ * Replaces any special characters (anything that's not alpha-numeric or a
+ * dash) with an underscore.
+ *
+ * E.g. "foo$bar&" would become "foo_bar_".
+ *
+ * PARAMETERS
+ * `buffer' String to be handled.
+ * `buffer_size' Length of the string. The function returns after
+ * encountering a null-byte or reading this many bytes.
+ */
+void replace_special (char *buffer, size_t buffer_size);
+
int strsubstitute (char *str, char c_from, char c_to);
/*