summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aac35f0)
raw | patch | inline | side by side (parent: aac35f0)
author | Florian Forster <octo@noris.net> | |
Wed, 27 Aug 2008 15:41:46 +0000 (17:41 +0200) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 27 Aug 2008 15:41:46 +0000 (17:41 +0200) |
This completes all the commands, now quoted strings should be accepted
anywhere.
anywhere.
src/exec.c | patch | blob | history | |
src/unixsock.c | patch | blob | history | |
src/utils_cmd_putnotif.c | patch | blob | history | |
src/utils_cmd_putnotif.h | patch | blob | history |
diff --git a/src/exec.c b/src/exec.c
index 88026b662a0be208daa58b24c418357a1c63399a..711ec996861897bfa87ecb9e5adf1e6bb1078aca 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
{
if (strncasecmp ("PUTVAL", buffer, strlen ("PUTVAL")) == 0)
return (handle_putval (stdout, buffer));
-#if !COLLECT_DEBUG
-#error "TODO: PUTNOTIF"
- else if (strcasecmp (fields[1], "putnotif") == 0)
- return (handle_putnotif (stdout, fields + 1, fields_num));
-#endif
+ else if (strncasecmp ("PUTNOTIF", buffer, strlen ("PUTNOTIF")) == 0)
+ return (handle_putnotif (stdout, buffer));
else
{
/* For backwards compatibility */
diff --git a/src/unixsock.c b/src/unixsock.c
index 02f329f63955bc45bb4f9785d7cfe2efdf5de239..8f06046c5e3d586d8200d92d15eccf73965ec6f2 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
}
else if (strcasecmp (fields[0], "putnotif") == 0)
{
- handle_putnotif (fhout, fields, fields_num);
+ handle_putnotif (fhout, buffer);
}
else if (strcasecmp (fields[0], "flush") == 0)
{
index eb7d60bc88657dfb5df94fec66940482c3d7b5c3..5a9faff2321e315188e370c7b5508fb17a108576 100644 (file)
--- a/src/utils_cmd_putnotif.c
+++ b/src/utils_cmd_putnotif.c
#include "common.h"
#include "plugin.h"
+#include "utils_parse_option.h"
+
#define print_to_socket(fh, ...) \
if (fprintf (fh, __VA_ARGS__) < 0) { \
char errbuf[1024]; \
return -1; \
}
-static int parse_option_severity (notification_t *n, char *value)
+static int set_option_severity (notification_t *n, const char *value)
{
if (strcasecmp (value, "Failure") == 0)
n->severity = NOTIF_FAILURE;
return (-1);
return (0);
-} /* int parse_option_severity */
+} /* int set_option_severity */
-static int parse_option_time (notification_t *n, char *value)
+static int set_option_time (notification_t *n, const char *value)
{
time_t tmp;
n->time = tmp;
return (0);
-} /* int parse_option_time */
+} /* int set_option_time */
-static int parse_option (notification_t *n, char *buffer)
+static int set_option (notification_t *n, const char *option, const char *value)
{
- char *option = buffer;
- char *value;
-
- if ((n == NULL) || (option == NULL))
+ if ((n == NULL) || (option == NULL) || (value == NULL))
return (-1);
- value = strchr (option, '=');
- if (value == NULL)
- return (-1);
- *value = '\0'; value++;
+ DEBUG ("utils_cmd_putnotif: set_option (option = %s, value = %s);",
+ option, value);
if (strcasecmp ("severity", option) == 0)
- return (parse_option_severity (n, value));
+ return (set_option_severity (n, value));
else if (strcasecmp ("time", option) == 0)
- return (parse_option_time (n, value));
+ return (set_option_time (n, value));
+ else if (strcasecmp ("message", option) == 0)
+ sstrncpy (n->message, value, sizeof (n->message));
else if (strcasecmp ("host", option) == 0)
sstrncpy (n->host, value, sizeof (n->host));
else if (strcasecmp ("plugin", option) == 0)
return (1);
return (0);
-} /* int parse_option */
+} /* int set_option */
-static int parse_message (notification_t *n, char **fields, int fields_num)
+int handle_putnotif (FILE *fh, char *buffer)
{
+ char *command;
+ notification_t n;
int status;
- /* Strip off the leading `message=' */
- fields[0] += strlen ("message=");
-
- status = strjoin (n->message, sizeof (n->message), fields, fields_num, " ");
- if (status < 0)
+ if ((fh == NULL) || (buffer == NULL))
return (-1);
- return (0);
-} /* int parse_message */
+ DEBUG ("utils_cmd_putnotif: handle_putnotif (fh = %p, buffer = %s);",
+ (void *) fh, buffer);
-int handle_putnotif (FILE *fh, char **fields, int fields_num)
-{
- notification_t n;
- int status;
- int i;
+ command = NULL;
+ status = parse_string (&buffer, &command);
+ if (status != 0)
+ {
+ print_to_socket (fh, "-1 Cannot parse command.\n");
+ return (-1);
+ }
+ assert (command != NULL);
- /* Required fields: `PUTNOTIF', severity, time, message */
- if (fields_num < 4)
+ if (strcasecmp ("PUTNOTIF", command) != 0)
{
- DEBUG ("cmd putnotif: Wrong number of fields: %i", fields_num);
- print_to_socket (fh, "-1 Wrong number of fields: Got %i, "
- "expected at least 4.\n",
- fields_num);
+ print_to_socket (fh, "-1 Unexpected command: `%s'.\n", command);
return (-1);
}
memset (&n, '\0', sizeof (n));
status = 0;
- for (i = 1; i < fields_num; i++)
+ while (*buffer != 0)
{
- if (strncasecmp (fields[i], "message=", strlen ("message=")) == 0)
+ char *key;
+ char *value;
+
+ status = parse_option (&buffer, &key, &value);
+ if (status != 0)
{
- status = parse_message (&n, fields + i, fields_num - i);
- if (status != 0)
- {
- print_to_socket (fh, "-1 Error parsing the message. Have you hit the "
- "limit of %u bytes?\n", (unsigned int) sizeof (n.message));
- }
+ print_to_socket (fh, "-1 Malformed option.\n");
break;
}
- else
+
+ status = set_option (&n, key, value);
+ if (status != 0)
{
- status = parse_option (&n, fields[i]);
- if (status != 0)
- {
- print_to_socket (fh, "-1 Error parsing option `%s'\n", fields[i]);
- break;
- }
+ print_to_socket (fh, "-1 Error parsing option `%s'\n", key);
+ break;
}
} /* for (i) */
index 08b3bb37682f96c0862e7d69d29bc57af0c038f9..8d5475b92fc3b75ccd20c28e84b873ebb00fe79a 100644 (file)
--- a/src/utils_cmd_putnotif.h
+++ b/src/utils_cmd_putnotif.h
#ifndef UTILS_CMD_PUTNOTIF_H
#define UTILS_CMD_PUTNOTIF_H 1
-int handle_putnotif (FILE *fh, char **fields, int fields_num);
+int handle_putnotif (FILE *fh, char *buffer);
/* vim: set shiftwidth=2 softtabstop=2 tabstop=8 : */