utils_complain.c utils_complain.h \
utils_ignorelist.c utils_ignorelist.h \
utils_llist.c utils_llist.h \
+ utils_parse_option.c utils_parse_option.h \
utils_tail_match.c utils_tail_match.h \
utils_match.c utils_match.h \
utils_mount.c utils_mount.h \
if BUILD_PLUGIN_EXEC
pkglib_LTLIBRARIES += exec.la
exec_la_SOURCES = exec.c \
- utils_parse_option.h utils_parse_option.c \
utils_cmd_putnotif.c utils_cmd_putnotif.h \
utils_cmd_putval.c utils_cmd_putval.h
exec_la_LDFLAGS = -module -avoid-version
if BUILD_PLUGIN_UNIXSOCK
pkglib_LTLIBRARIES += unixsock.la
unixsock_la_SOURCES = unixsock.c \
- utils_parse_option.h utils_parse_option.c \
utils_cmd_flush.h utils_cmd_flush.c \
utils_cmd_getval.h utils_cmd_getval.c \
utils_cmd_listval.h utils_cmd_listval.c \
/**
* collectd - src/csv.c
- * Copyright (C) 2007 Florian octo Forster
+ * Copyright (C) 2007-2009 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
#include "plugin.h"
#include "common.h"
#include "utils_cache.h"
+#include "utils_parse_option.h"
/*
* Private variables
if (use_stdio)
{
+ size_t i;
+
+ escape_string (filename, sizeof (filename));
+
+ /* Replace commas by colons for PUTVAL compatible output. */
+ for (i = 0; i < sizeof (values); i++)
+ {
+ if (values[i] == 0)
+ break;
+ else if (values[i] == ',')
+ values[i] = ':';
+ }
+
fprintf (use_stdio == 1 ? stdout : stderr,
- "%s=%s\n", filename, values);
+ "PUTVAL %s interval=%i %s\n",
+ filename, interval_g, values);
return (0);
}
return (0);
} /* int parse_option */
+int escape_string (char *buffer, size_t buffer_size)
+{
+ char *temp;
+ size_t i;
+ size_t j;
+
+ /* Check if we need to escape at all first */
+ temp = strpbrk (buffer, " \t\"\\");
+ if (temp == NULL)
+ return (0);
+
+ temp = (char *) malloc (buffer_size);
+ if (temp == NULL)
+ return (-1);
+ memset (temp, 0, buffer_size);
+
+ temp[0] = '"';
+ j = 1;
+
+ for (i = 0; i < buffer_size; i++)
+ {
+ if (buffer[i] == 0)
+ {
+ break;
+ }
+ else if ((buffer[i] == '"') || (buffer[i] == '\\'))
+ {
+ if (j > (buffer_size - 4))
+ break;
+ temp[j] = '\\';
+ temp[j + 1] = buffer[i];
+ j += 2;
+ }
+ else
+ {
+ if (j > (buffer_size - 3))
+ break;
+ temp[j] = buffer[i];
+ j++;
+ }
+ }
+
+ assert ((j + 1) < buffer_size);
+ temp[j] = '"';
+ temp[j + 1] = 0;
+
+ sstrncpy (buffer, temp, buffer_size);
+ sfree (temp);
+ return (0);
+} /* int escape_string */
+
/* vim: set sw=2 ts=8 tw=78 et : */
int parse_string (char **ret_buffer, char **ret_string);
int parse_option (char **ret_buffer, char **ret_key, char **ret_value);
+int escape_string (char *buffer, size_t buffer_size);
+
#endif /* UTILS_PARSE_OPTION */
/* vim: set sw=2 ts=8 tw=78 et : */