src/configfile.[ch]: Implement "cf_util_get_string".
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 24 Sep 2009 15:32:29 +0000 (17:32 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 24 Sep 2009 15:32:29 +0000 (17:32 +0200)
src/configfile.c
src/configfile.h

index d401a2e..df04289 100644 (file)
@@ -917,3 +917,28 @@ int cf_read (char *filename)
 
        return (0);
 } /* int cf_read */
 
        return (0);
 } /* int cf_read */
+
+/* Assures the config option is a string, duplicates it and returns the copy in
+ * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
+ * success. */
+int cf_util_get_string (const oconfig_item_t *ci, char **ret_string) /* {{{ */
+{
+       char *string;
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+       {
+               ERROR ("cf_util_get_string: The %s plugin requires "
+                               "exactly one string argument.", ci->key);
+               return (-1);
+       }
+
+       string = strdup (ci->values[0].value.string);
+       if (string == NULL)
+               return (-1);
+
+       if (*ret_string != NULL)
+               sfree (*ret_string);
+       *ret_string = string;
+
+       return (0);
+} /* }}} int cf_util_get_string */
index 3952c18..aca5877 100644 (file)
@@ -86,4 +86,9 @@ int cf_read (char *filename);
 int global_option_set (const char *option, const char *value);
 const char *global_option_get (const char *option);
 
 int global_option_set (const char *option, const char *value);
 const char *global_option_get (const char *option);
 
+/* Assures the config option is a string, duplicates it and returns the copy in
+ * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
+ * success. */
+int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
+
 #endif /* defined(CONFIGFILE_H) */
 #endif /* defined(CONFIGFILE_H) */