summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 14e67b8)
raw | patch | inline | side by side (parent: 14e67b8)
author | Florian Forster <octo@noris.net> | |
Wed, 27 Aug 2008 09:59:53 +0000 (11:59 +0200) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 27 Aug 2008 09:59:53 +0000 (11:59 +0200) |
The getval handler now uses the `parse_string' function in
`utils_parse_option' to handle quoted strings correctly.
`utils_parse_option' to handle quoted strings correctly.
bindings/perl/Collectd/Unixsock.pm | patch | blob | history | |
src/unixsock.c | patch | blob | history | |
src/utils_cmd_getval.c | patch | blob | history | |
src/utils_cmd_getval.h | patch | blob | history |
index cd910ed080e73d1779b2787f3d1230825c5b797c..d4499246cdf2497a5c6b01f39387a38c9e95adcd 100644 (file)
my %args = @_;
my $status;
- my $fh = $obj->{'sock'} or confess;
+ my $fh = $obj->{'sock'} or confess ('object has no filehandle');
my $msg;
my $identifier;
my $ret = {};
$identifier = _create_identifier (\%args) or return;
+ if ($identifier =~ m/[\s"]/)
+ {
+ $identifier =~ s#\\#\\\\#g;
+ $identifier =~ s#"#\\"#g;
+ $identifier = "\"$identifier\"";
+ }
$msg = "GETVAL $identifier\n";
#print "-> $msg";
{
return;
}
- if ($ident_str =~ m/ /)
+ if ($ident_str =~ m/[\s"]/)
{
$ident_str =~ s#\\#\\\\#g;
$ident_str =~ s#"#\\"#g;
diff --git a/src/unixsock.c b/src/unixsock.c
index c2e1f302d67fc2f59aca6e5155f963f5d8f05ad5..db75809432dc3542161a00d392a2af398d183ca2 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
if (strcasecmp (fields[0], "getval") == 0)
{
- handle_getval (fhout, fields, fields_num);
+ handle_getval (fhout, buffer);
}
else if (strcasecmp (fields[0], "putval") == 0)
{
diff --git a/src/utils_cmd_getval.c b/src/utils_cmd_getval.c
index 470d3022e4881dfa8b8f32b282ff260ce511aac2..33b40e09af7532a951d2611f83fe9fe2493360ee 100644 (file)
--- a/src/utils_cmd_getval.c
+++ b/src/utils_cmd_getval.c
#include "plugin.h"
#include "utils_cache.h"
+#include "utils_parse_option.h"
#define print_to_socket(fh, ...) \
if (fprintf (fh, __VA_ARGS__) < 0) { \
return -1; \
}
-int handle_getval (FILE *fh, char **fields, int fields_num)
+int handle_getval (FILE *fh, char *buffer)
{
+ char *command;
+ char *identifier;
+ char *identifier_copy;
+
char *hostname;
char *plugin;
char *plugin_instance;
gauge_t *values;
size_t values_num;
- char *identifier_copy;
-
const data_set_t *ds;
int status;
int i;
- if (fields_num != 2)
+ if ((fh == NULL) || (buffer == NULL))
+ return (-1);
+
+ DEBUG ("utils_cmd_getval: handle_getval (fh = %p, buffer = %s);",
+ (void *) fh, buffer);
+
+ command = NULL;
+ status = parse_string (&buffer, &command);
+ if (status != 0)
{
- DEBUG ("unixsock plugin: Wrong number of fields: %i", fields_num);
- print_to_socket (fh, "-1 Wrong number of fields: Got %i, expected 2.\n",
- fields_num);
+ print_to_socket (fh, "-1 Cannot parse command.\n");
return (-1);
}
- DEBUG ("unixsock plugin: Got query for `%s'", fields[1]);
+ assert (command != NULL);
- if (strlen (fields[1]) < strlen ("h/p/t"))
+ if (strcasecmp ("GETVAL", command) != 0)
{
- print_to_socket (fh, "-1 Invalied identifier, %s\n", fields[1]);
+ print_to_socket (fh, "-1 Unexpected command: `%s'.\n", command);
return (-1);
}
+ identifier = NULL;
+ status = parse_string (&buffer, &identifier);
+ if (status != 0)
+ {
+ print_to_socket (fh, "-1 Cannot parse identifier.\n");
+ return (-1);
+ }
+ assert (identifier != NULL);
+
/* parse_identifier() modifies its first argument,
* returning pointers into it */
- identifier_copy = sstrdup (fields[1]);
+ identifier_copy = sstrdup (identifier);
status = parse_identifier (identifier_copy, &hostname,
&plugin, &plugin_instance,
&type, &type_instance);
if (status != 0)
{
- DEBUG ("unixsock plugin: Cannot parse `%s'", fields[1]);
- print_to_socket (fh, "-1 Cannot parse identifier.\n");
+ DEBUG ("unixsock plugin: Cannot parse identifier `%s'.", identifier);
+ print_to_socket (fh, "-1 Cannot parse identifier `%s'.\n", identifier);
sfree (identifier_copy);
return (-1);
}
values = NULL;
values_num = 0;
- status = uc_get_rate_by_name (fields[1], &values, &values_num);
+ status = uc_get_rate_by_name (identifier, &values, &values_num);
if (status != 0)
{
print_to_socket (fh, "-1 No such value\n");
diff --git a/src/utils_cmd_getval.h b/src/utils_cmd_getval.h
index d7bd1151c2c52b515852f0100e82b68f6fe59b5a..86134cdf9a19b1e542662352161a8e51c35bad9f 100644 (file)
--- a/src/utils_cmd_getval.h
+++ b/src/utils_cmd_getval.h
#ifndef UTILS_CMD_GETVAL_H
#define UTILS_CMD_GETVAL_H 1
-int handle_getval (FILE *fh, char **fields, int fields_num);
+int handle_getval (FILE *fh, char *buffer);
#endif /* UTILS_CMD_GETVAL_H */