octo@crystal:~/Projects/collectd $ svn merge -r646:651 trunk tags/collectd-3.9.1
[collectd.git] / src / configfile.c
index 2569b4a..477d881 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
@@ -20,9 +20,6 @@
  *   Florian octo Forster <octo at verplant.org>
  **/
 
-/* TODO
- * make internal-only functions `static' */
-
 #include "collectd.h"
 
 #include "libconfig/libconfig.h"
 #define ERR_NEEDS_ARG "Section `%s' needs an argument.\n"
 #define ERR_NEEDS_SECTION "`%s' can only be used within a section.\n"
 
-#ifdef HAVE_LIBRRD
 extern int operating_mode;
-#else
-static int operating_mode = MODE_CLIENT;
-#endif
 
 typedef struct cf_callback
 {
@@ -69,26 +62,25 @@ typedef struct cf_mode_item
  */
 static cf_mode_item_t cf_mode_list[] =
 {
-       {"Server",      NULL, MODE_CLIENT                           },
-       {"Port",        NULL, MODE_CLIENT | MODE_SERVER             },
-       {"PIDFile",     NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL},
-       {"DataDir",     NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL},
-       {"LogFile",     NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}
+       {"TimeToLive",  NULL, MODE_CLIENT                           },
+       {"PIDFile",     NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL | MODE_LOG },
+       {"DataDir",     NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL | MODE_LOG },
+       {"LogFile",     NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL | MODE_LOG }
 };
-static int cf_mode_num = 5;
+static int cf_mode_num = 4;
 
 static int nesting_depth = 0;
 static char *current_module = NULL;
 
 /* `cf_register' needs this prototype */
-int cf_callback_plugin_dispatch (const char *, const char *, const char *,
-               const char *, lc_flags_t, void *);
+static int cf_callback_plugin_dispatch (const char *, const char *,
+               const char *, const char *, lc_flags_t, void *);
 
 /*
  * Functions to handle register/unregister, search, and other plugin related
  * stuff
  */
-cf_callback_t *cf_search (char *type)
+static cf_callback_t *cf_search (char *type)
 {
        cf_callback_t *cf_cb;
 
@@ -102,7 +94,7 @@ cf_callback_t *cf_search (char *type)
        return (cf_cb);
 }
 
-int cf_dispatch (char *type, const char *orig_key, const char *orig_value)
+static int cf_dispatch (char *type, const char *orig_key, const char *orig_value)
 {
        cf_callback_t *cf_cb;
        char *key;
@@ -114,7 +106,7 @@ int cf_dispatch (char *type, const char *orig_key, const char *orig_value)
 
        if ((cf_cb = cf_search (type)) == NULL)
        {
-               syslog (LOG_WARNING, "Plugin `%s' did not register a callback.\n", type);
+               syslog (LOG_WARNING, "Plugin `%s' did not register a callback.", type);
                return (-1);
        }
 
@@ -138,11 +130,13 @@ int cf_dispatch (char *type, const char *orig_key, const char *orig_value)
        }
 
        if (i >= cf_cb->keys_num)
-               syslog (LOG_WARNING, "Plugin `%s' did not register for value `%s'.\n", type, key);
+               syslog (LOG_WARNING, "Plugin `%s' did not register for value `%s'.", type, key);
 
        free (key);
        free (value);
 
+       DBG ("return (%i)", ret);
+
        return (ret);
 }
 
@@ -239,7 +233,7 @@ char *cf_get_option (const char *key, char *def)
  *
  * Mode `value'
  */
-int cf_callback_mode (const char *shortvar, const char *var,
+static int cf_callback_mode (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
@@ -248,10 +242,14 @@ int cf_callback_mode (const char *shortvar, const char *var,
 
        if (strcasecmp (value, "Client") == 0)
                operating_mode = MODE_CLIENT;
+#if HAVE_LIBRRD
        else if (strcasecmp (value, "Server") == 0)
                operating_mode = MODE_SERVER;
        else if (strcasecmp (value, "Local") == 0)
                operating_mode = MODE_LOCAL;
+#endif
+       else if (strcasecmp (value, "Log") == 0)
+               operating_mode = MODE_LOG;
        else
        {
                syslog (LOG_ERR, "Invalid value for config option `Mode': `%s'", value);
@@ -269,7 +267,7 @@ int cf_callback_mode (const char *shortvar, const char *var,
  *   PluginDir `value'
  * </Mode>
  */
-int cf_callback_mode_plugindir (const char *shortvar, const char *var,
+static int cf_callback_mode_plugindir (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
@@ -281,7 +279,7 @@ int cf_callback_mode_plugindir (const char *shortvar, const char *var,
        return (LC_CBRET_OKAY);
 }
 
-int cf_callback_mode_option (const char *shortvar, const char *var,
+static int cf_callback_mode_option (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
@@ -333,7 +331,7 @@ int cf_callback_mode_option (const char *shortvar, const char *var,
  *   LoadPlugin `value'
  * </Mode>
  */
-int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
+static int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
@@ -348,37 +346,7 @@ int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
        return (LC_CBRET_OKAY);
 }
 
-/*
- * `cf_callback_mode_switch'
- *   Change the contents of the global variable `operating_mode'
- *
- *   This should be command line options. One *can* do this in the config
- *   files, but I will not document this. Don't whine abount it not working as
- *   you expect if you do it anyways.
- */
-int cf_callback_mode_switch (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);
-
-       if (strcasecmp (shortvar, "Client") == 0)
-               operating_mode = MODE_CLIENT;
-       else if (strcasecmp (shortvar, "Local") == 0)
-               operating_mode = MODE_LOCAL;
-       else if (strcasecmp (shortvar, "Server") == 0)
-               operating_mode = MODE_SERVER;
-       else
-       {
-               fprintf (stderr, "cf_callback_mode_switch: Wrong mode!\n");
-               return (LC_CBRET_ERROR);
-       }
-
-       return (LC_CBRET_OKAY);
-}
-
-int cf_callback_socket (const char *shortvar, const char *var,
+static int cf_callback_socket (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
@@ -429,7 +397,7 @@ int cf_callback_socket (const char *shortvar, const char *var,
  *   ...
  * </Plugin>
  */
-int cf_callback_plugin (const char *shortvar, const char *var,
+static int cf_callback_plugin (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
@@ -490,7 +458,7 @@ int cf_callback_plugin (const char *shortvar, const char *var,
  *   `var' `value'
  * </Plugin>
  */
-int cf_callback_plugin_dispatch (const char *shortvar, const char *var,
+static int cf_callback_plugin_dispatch (const char *shortvar, const char *var,
                const char *arguments, const char *value, lc_flags_t flags,
                void *extra)
 {
@@ -510,7 +478,7 @@ int cf_callback_plugin_dispatch (const char *shortvar, const char *var,
        return (LC_CBRET_OKAY);
 }
 
-void cf_init (void)
+static void cf_init (void)
 {
        static int run_once = 0;
        int i;