src/configfile.c: Removed `cf_callback_socket'
[collectd.git] / src / configfile.c
index 91bef48..5472de4 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/configfile.c
- * Copyright (C) 2005  Florian octo Forster
+ * Copyright (C) 2005,2006  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
 #define ERR_NEEDS_ARG "Section `%s' needs an argument.\n"
 #define ERR_NEEDS_SECTION "`%s' can only be used within a section.\n"
 
+#define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str))
+
+#define DEBUG_CALLBACK(shortvar, var, arguments, value) \
+       DBG("shortvar = %s, var = %s, arguments = %s, value = %s, ...", \
+                       ESCAPE_NULL(shortvar), \
+                       ESCAPE_NULL(var), \
+                       ESCAPE_NULL(arguments), \
+                       ESCAPE_NULL(value))
+
 extern int operating_mode;
 
 typedef struct cf_callback
 {
-       char  *type;
-       int  (*callback) (char *, char *);
-       char **keys;
+       const char  *type;
+       int  (*callback) (const char *, const char *);
+       const char **keys;
        int    keys_num;
        struct cf_callback *next;
 } cf_callback_t;
@@ -102,7 +111,10 @@ static int cf_dispatch (char *type, const char *orig_key, const char *orig_value
        int ret;
        int i;
 
-       DBG ("type = %s, key = %s, value = %s", type, orig_key, orig_value);
+       DBG ("type = %s, key = %s, value = %s",
+                       ESCAPE_NULL(type),
+                       ESCAPE_NULL(orig_key),
+                       ESCAPE_NULL(orig_value));
 
        if ((cf_cb = cf_search (type)) == NULL)
        {
@@ -140,7 +152,7 @@ static int cf_dispatch (char *type, const char *orig_key, const char *orig_value
        return (ret);
 }
 
-void cf_unregister (char *type)
+void cf_unregister (const char *type)
 {
        cf_callback_t *this, *prev;
 
@@ -159,9 +171,9 @@ void cf_unregister (char *type)
                }
 }
 
-void cf_register (char *type,
-               int (*callback) (char *, char *),
-               char **keys, int keys_num)
+void cf_register (const char *type,
+               int (*callback) (const char *, const char *),
+               const char **keys, int keys_num)
 {
        cf_callback_t *cf_cb;
        char buf[64];
@@ -195,7 +207,7 @@ void cf_register (char *type,
                }
                else
                {
-                       DBG ("Key was truncated: `%s'", keys[i]);
+                       DBG ("Key was truncated: `%s'", ESCAPE_NULL(keys[i]));
                }
        }
 }
@@ -237,8 +249,7 @@ static int cf_callback_mode (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
-       DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
-                       shortvar, var, arguments, value);
+       DEBUG_CALLBACK (shortvar, var, arguments, value);
 
        if (strcasecmp (value, "Client") == 0)
                operating_mode = MODE_CLIENT;
@@ -247,6 +258,27 @@ static int cf_callback_mode (const char *shortvar, const char *var,
                operating_mode = MODE_SERVER;
        else if (strcasecmp (value, "Local") == 0)
                operating_mode = MODE_LOCAL;
+#else /* !HAVE_LIBRRD */
+       else if (strcasecmp (value, "Server") == 0)
+       {
+               fprintf (stderr, "Invalid mode `Server': "
+                               "You need to link against librrd for this "
+                               "mode to be available.\n");
+               syslog (LOG_ERR, "Invalid mode `Server': "
+                               "You need to link against librrd for this "
+                               "mode to be available.");
+               return (LC_CBRET_ERROR);
+       }
+       else if (strcasecmp (value, "Local") == 0)
+       {
+               fprintf (stderr, "Invalid mode `Local': "
+                               "You need to link against librrd for this "
+                               "mode to be available.\n");
+               syslog (LOG_ERR, "Invalid mode `Local': "
+                               "You need to link against librrd for this "
+                               "mode to be available.");
+               return (LC_CBRET_ERROR);
+       }
 #endif
        else if (strcasecmp (value, "Log") == 0)
                operating_mode = MODE_LOG;
@@ -271,8 +303,7 @@ static int cf_callback_mode_plugindir (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
-       DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
-                       shortvar, var, arguments, value);
+       DEBUG_CALLBACK (shortvar, var, arguments, value);
 
        plugin_set_dir (value);
 
@@ -285,8 +316,7 @@ static int cf_callback_mode_option (const char *shortvar, const char *var,
 {
        cf_mode_item_t *item;
 
-       DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
-                       shortvar, var, arguments, value);
+       DEBUG_CALLBACK (shortvar, var, arguments, value);
 
        if (extra == NULL)
        {
@@ -335,8 +365,7 @@ static int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
-       DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
-                       shortvar, var, arguments, value);
+       DEBUG_CALLBACK (shortvar, var, arguments, value);
 
        if (plugin_load (value))
                syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", value);
@@ -346,49 +375,6 @@ static int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
        return (LC_CBRET_OKAY);
 }
 
-static int cf_callback_socket (const char *shortvar, const char *var,
-               const char *arguments, const char *value, lc_flags_t flags,
-               void *extra)
-{
-       char *buffer;
-
-       char *fields[3];
-       int   numfields;
-
-       char *node;
-       char *service = NET_DEFAULT_PORT;
-
-       DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
-                       shortvar, var, arguments, value);
-
-       buffer = strdup (value);
-       if (buffer == NULL)
-               return (LC_CBRET_ERROR);
-
-       numfields = strsplit (buffer, fields, 3);
-
-       if ((numfields != 1) && (numfields != 2))
-       {
-               syslog (LOG_ERR, "Invalid number of arguments to `%s'",
-                               shortvar);
-               free (buffer);
-               return (LC_CBRET_ERROR);
-       }
-
-       node = fields[0];
-       if (numfields == 2)
-               service = fields[1];
-
-       /* Still return `LC_CBRET_OKAY' because this is not an syntax error */
-       if (network_create_socket (node, service) < 1)
-               syslog (LOG_ERR, "network_create_socket (%s, %s) failed",
-                               node, service);
-
-       free (buffer);
-
-       return (LC_CBRET_OKAY);
-}
-
 /*
  * `cf_callback_plugin'
  *   Start/end section `plugin'
@@ -401,8 +387,7 @@ static int cf_callback_plugin (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
-       DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
-                       shortvar, var, arguments, value);
+       DEBUG_CALLBACK (shortvar, var, arguments, value);
 
        if (flags == LC_FLAGS_SECTIONSTART)
        {
@@ -462,8 +447,7 @@ static int cf_callback_plugin_dispatch (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
-       DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
-                       shortvar, var, arguments, value);
+       DEBUG_CALLBACK (shortvar, var, arguments, value);
 
        if ((nesting_depth == 0) || (current_module == NULL))
        {
@@ -497,11 +481,6 @@ static void cf_init (void)
        lc_register_callback ("LoadPlugin", SHORTOPT_NONE,
                        LC_VAR_STRING, cf_callback_mode_loadmodule, NULL);
 
-       lc_register_callback ("Listen", SHORTOPT_NONE,
-                       LC_VAR_STRING, cf_callback_socket, NULL);
-       lc_register_callback ("Server", SHORTOPT_NONE,
-                       LC_VAR_STRING, cf_callback_socket, NULL);
-
        for (i = 0; i < cf_mode_num; i++)
        {
                cf_mode_item_t *item;