{GPL, other}: Relicense to MIT license.
[collectd.git] / src / target_set.c
index 3a4220e..41133e3 100644 (file)
@@ -1,62 +1,29 @@
 /**
  * collectd - src/target_set.c
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
-/*
- * First tell the compiler to stick to the C99 and POSIX standards as close as
- * possible.
- */
-#ifndef __STRICT_ANSI__ /* {{{ */
-# define __STRICT_ANSI__
-#endif
-
-#ifndef _ISOC99_SOURCE
-# define _ISOC99_SOURCE
-#endif
-
-#ifdef _POSIX_C_SOURCE
-# undef _POSIX_C_SOURCE
-#endif
-#define _POSIX_C_SOURCE 200112L
-
-#if 0
-/* Single UNIX needed for strdup. */
-#ifdef _XOPEN_SOURCE
-# undef _XOPEN_SOURCE
-#endif
-#define _XOPEN_SOURCE 500
-#endif
-
-#ifndef _REENTRANT
-# define _REENTRANT
-#endif
-
-#ifndef _THREAD_SAFE
-# define _THREAD_SAFE
-#endif
-
-#ifdef _GNU_SOURCE
-# undef _GNU_SOURCE
-#endif
-/* }}} */
-
 #include "collectd.h"
 #include "common.h"
 #include "filter_chain.h"
@@ -66,7 +33,7 @@ struct ts_data_s
   char *host;
   char *plugin;
   char *plugin_instance;
-  char *type;
+  /* char *type; */
   char *type_instance;
 };
 typedef struct ts_data_s ts_data_t;
@@ -90,7 +57,7 @@ static char *ts_strdup (const char *orig) /* {{{ */
 } /* }}} char *ts_strdup */
 
 static int ts_config_add_string (char **dest, /* {{{ */
-    const oconfig_item_t *ci)
+    const oconfig_item_t *ci, int may_be_empty)
 {
   char *temp;
 
@@ -105,6 +72,13 @@ static int ts_config_add_string (char **dest, /* {{{ */
     return (-1);
   }
 
+  if ((!may_be_empty) && (ci->values[0].value.string[0] == 0))
+  {
+    ERROR ("Target `set': The `%s' option does not accept empty strings.",
+        ci->key);
+    return (-1);
+  }
+
   temp = ts_strdup (ci->values[0].value.string);
   if (temp == NULL)
   {
@@ -132,7 +106,7 @@ static int ts_destroy (void **user_data) /* {{{ */
   free (data->host);
   free (data->plugin);
   free (data->plugin_instance);
-  free (data->type);
+  /* free (data->type); */
   free (data->type_instance);
   free (data);
 
@@ -156,7 +130,7 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
   data->host = NULL;
   data->plugin = NULL;
   data->plugin_instance = NULL;
-  data->type = NULL;
+  /* data->type = NULL; */
   data->type_instance = NULL;
 
   status = 0;
@@ -166,15 +140,22 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
 
     if ((strcasecmp ("Host", child->key) == 0)
         || (strcasecmp ("Hostname", child->key) == 0))
-      status = ts_config_add_string (&data->host, child);
+      status = ts_config_add_string (&data->host, child,
+          /* may be empty = */ 0);
     else if (strcasecmp ("Plugin", child->key) == 0)
-      status = ts_config_add_string (&data->plugin, child);
+      status = ts_config_add_string (&data->plugin, child,
+          /* may be empty = */ 0);
     else if (strcasecmp ("PluginInstance", child->key) == 0)
-      status = ts_config_add_string (&data->plugin_instance, child);
+      status = ts_config_add_string (&data->plugin_instance, child,
+          /* may be empty = */ 1);
+#if 0
     else if (strcasecmp ("Type", child->key) == 0)
-      status = ts_config_add_string (&data->type, child);
+      status = ts_config_add_string (&data->type, child,
+          /* may be empty = */ 0);
+#endif
     else if (strcasecmp ("TypeInstance", child->key) == 0)
-      status = ts_config_add_string (&data->type_instance, child);
+      status = ts_config_add_string (&data->type_instance, child,
+          /* may be empty = */ 1);
     else
     {
       ERROR ("Target `set': The `%s' configuration option is not understood "
@@ -192,11 +173,11 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
     if ((data->host == NULL)
         && (data->plugin == NULL)
         && (data->plugin_instance == NULL)
-        && (data->type == NULL)
+        /* && (data->type == NULL) */
         && (data->type_instance == NULL))
     {
-      ERROR ("Target `set': You need to set at lease one of `Host', "
-          "`Plugin', `PluginInstance', `Type', or `TypeInstance'.");
+      ERROR ("Target `set': You need to set at least one of `Host', "
+          "`Plugin', `PluginInstance' or `TypeInstance'.");
       status = -1;
     }
 
@@ -214,7 +195,7 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
 } /* }}} int ts_create */
 
 static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */
-    notification_meta_t **meta, void **user_data)
+    notification_meta_t __attribute__((unused)) **meta, void **user_data)
 {
   ts_data_t *data;
 
@@ -232,10 +213,10 @@ static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */
   SET_FIELD (host);
   SET_FIELD (plugin);
   SET_FIELD (plugin_instance);
-  SET_FIELD (type);
+  /* SET_FIELD (type); */
   SET_FIELD (type_instance);
 
-  return (0);
+  return (FC_TARGET_CONTINUE);
 } /* }}} int ts_invoke */
 
 void module_register (void)