diff options
author | Martin Nagy <mnagy@redhat.com> | 2009-01-14 09:50:41 +0100 |
---|---|---|
committer | Martin Nagy <mnagy@redhat.com> | 2009-01-14 09:50:41 +0100 |
commit | 14c6180ac9875059c38dce0240bb383d676164ca (patch) | |
tree | 02573526d1115593ab482dea3e80a68d6ba34049 | |
parent | 7d51b83f5953467924ab93ec33820cf015b96743 (diff) | |
download | ldap_driver_testing-14c6180ac9875059c38dce0240bb383d676164ca.tar.gz ldap_driver_testing-14c6180ac9875059c38dce0240bb383d676164ca.tar.xz ldap_driver_testing-14c6180ac9875059c38dce0240bb383d676164ca.zip |
Fix settings default value handling.
-rw-r--r-- | settings.c | 8 | ||||
-rw-r--r-- | settings.h | 21 |
2 files changed, 17 insertions, 12 deletions
@@ -45,13 +45,11 @@ set_settings(isc_mem_t *mctx, setting_t settings[], const char * const* argv) { isc_result_t result; int i, j; - const char *value_ptr; for (i = 0; argv[i] != NULL; i++) { for (j = 0; settings[j].name != NULL; j++) { if (args_are_equal(settings[j].name, argv[i])) { - value_ptr = get_value_str(argv[i]); - CHECK(set_value(mctx, &settings[j], value_ptr)); + CHECK(set_value(mctx, &settings[j], argv[i])); break; } } @@ -61,8 +59,8 @@ set_settings(isc_mem_t *mctx, setting_t settings[], const char * const* argv) for (j = 0; settings[j].name != NULL; j++) { if (settings[j].set != 0) continue; - if (settings[j].type == ST_NO_DEFAULT) { - log_error("argument %s must be set"); + if (!settings[j].has_a_default) { + log_error("argument %s must be set", settings[j].name); result = ISC_R_FAILURE; goto cleanup; } @@ -26,12 +26,12 @@ typedef enum { ST_LD_STRING, ST_SIGNED_INTEGER, ST_UNSIGNED_INTEGER, - ST_NO_DEFAULT, } setting_type_t; struct setting { const char *name; int set; + int has_a_default; setting_type_t type; union { const char *value_char; @@ -44,15 +44,22 @@ struct setting { /* * These defines are used as initializers for setting_t, for example: * - * const setting_t my_setting = { + * setting_t my_setting = { * "name", default_string("this is the default"), * &target_variable * } + * + * setting_t my_setting = { + * "name", no_default_string, &target_variable + * } */ -#define default_string(value) 0, ST_LD_STRING, { .value_char = (value) } -#define default_sint(value) 0, ST_SIGNED_INTEGER, { .value_sint = (value) } -#define default_uint(value) 0, ST_UNSIGNED_INTEGER, { .value_uint = (value) } -#define default_nothing() 0, ST_NO_DEFAULT, { .value_uint = 0 } +#define default_string(val) 0, 1, ST_LD_STRING, { .value_char = (val) } +#define default_sint(val) 0, 1, ST_SIGNED_INTEGER, { .value_sint = (val) } +#define default_uint(val) 0, 1, ST_UNSIGNED_INTEGER, { .value_uint = (val) } +/* No defaults. */ +#define no_default_string 0, 0, ST_LD_STRING, { .value_char = NULL } +#define no_default_sint 0, 0, ST_SIGNED_INTEGER, { .value_sint = 0 } +#define no_default_uint 0, 0, ST_UNSIGNED_INTEGER, { .value_uint = 0 } /* This is used in the end of setting_t arrays. */ #define end_of_settings { NULL, default_sint(0), NULL } @@ -61,6 +68,6 @@ struct setting { * Prototypes. */ isc_result_t -set_settings(isc_mem_t *mctx, setting_t settings[], const char * const* argv); +set_settings(isc_mem_t *mctx, setting_t *settings, const char * const* argv); #endif /* !_LD_SETTINGS_H_ */ |