diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-04-27 13:11:18 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-04-27 13:19:06 +0300 |
commit | ef07786925303a1f8588a061b66034e066f533da (patch) | |
tree | 7318ebaddf37e5afa790ba13535a05b7b1075cfd /src | |
parent | b6173eeaf3311d9de26d530d5ff07fdf6ddddcad (diff) | |
download | mailfromd-ef07786925303a1f8588a061b66034e066f533da.tar.gz mailfromd-ef07786925303a1f8588a061b66034e066f533da.tar.bz2 |
Avoid casts between pointers and integers (optcache)
* lib/libmf.h (mf_option_value): Union.
(mf_option_cache): Rearrange members.
(handler,set): Change signature.
(isset): New member.
(mf_optcache_set_option): Change signature.
(mf_option_string,mf_option_boolean): Likewise.
(mf_option_time_t,mf_option_size_t): Remove.
(mf_option_timeout,mf_option_size): New prototypes.
* lib/optcache.c (optcache_dup): Clear isset member for each element.
(mf_optcache_set_option): Rewrite.
(mf_option_string, mf_option_boolean): Rewrite.
(mf_option_time_t,mf_option_size_t): Remove.
(mf_option_timeout,mf_option_size): New functions.
* lib/utils.c: Change the use of mf_optcache functions.
* src/main.c: Likewise.
* src/mfdbtool.c: Likewise.
* src/srvcfg.c: Likewise.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 32 | ||||
-rw-r--r-- | src/mfdbtool.c | 13 | ||||
-rw-r--r-- | src/srvcfg.c | 75 |
3 files changed, 62 insertions, 58 deletions
@@ -259,12 +259,11 @@ host_in_relayed_domain_p(char *client) static void -set_milter_timeout(void *value) +set_milter_timeout(union mf_option_value *val) { - time_t to = *(time_t*) value; - free(value); - if (smfi_settimeout(to) == MI_FAILURE) { - mu_error(_("invalid milter timeout: %lu"), (unsigned long) to); + if (smfi_settimeout(val->ov_time) == MI_FAILURE) { + mu_error(_("invalid milter timeout: %lu"), + (unsigned long)val->ov_time); exit(EX_USAGE); } } @@ -277,30 +276,31 @@ load_relay_file(void *item, void *data) } static void -set_relay(void *value) +set_relay(union mf_option_value *val) { - mu_list_foreach(value, load_relay_file, NULL); + mu_list_foreach(val->ov_list, load_relay_file, NULL); + mu_list_destroy(&val->ov_list); } void -set_stack_trace(void *value) +set_stack_trace(union mf_option_value *val) { - stack_trace_option = (int) value; + stack_trace_option = val->ov_bool; } static int -option_relay(char *opt, void **pval, char *newval) +option_relay(char const *opt, union mf_option_value *val, char const *newval) { - if (!*pval) - mu_list_create((mu_list_t*)pval); - mu_list_append(*pval, strdup(newval)); + if (!val->ov_list) + mu_list_create(&val->ov_list); + mu_list_append(val->ov_list, strdup(newval)); return 0; } struct mf_option_cache option_cache[] = { - { "stack-trace", NULL, mf_option_boolean, set_stack_trace }, - { "milter-timeout", NULL, mf_option_time, set_milter_timeout }, - { "relay", NULL, option_relay, set_relay }, + { "stack-trace", mf_option_boolean, set_stack_trace }, + { "milter-timeout", mf_option_timeout, set_milter_timeout }, + { "relay", option_relay, set_relay }, { NULL } }; diff --git a/src/mfdbtool.c b/src/mfdbtool.c index dd723c38..4af386ad 100644 --- a/src/mfdbtool.c +++ b/src/mfdbtool.c @@ -358,20 +358,21 @@ struct mu_cfg_param mfdbtool_cfg_param[] = { }; static void -set_state_directory(void *value) +set_state_directory(union mf_option_value *val) { - state_dir = value; + state_dir = val->ov_string; } static void -set_debug(void *value) +set_debug(union mf_option_value *val) { - mu_debug_parse_spec(value); + mu_debug_parse_spec(val->ov_string); + free(val->ov_string); } static struct mf_option_cache option_cache[] = { - { "state-directory", NULL, mf_option_string, set_state_directory }, - { "debug", NULL, mf_option_string, set_debug }, + { "state-directory", mf_option_string, set_state_directory }, + { "debug", mf_option_string, set_debug }, { NULL } }; diff --git a/src/srvcfg.c b/src/srvcfg.c index 40d56b89..4b338f82 100644 --- a/src/srvcfg.c +++ b/src/srvcfg.c @@ -137,21 +137,22 @@ parse_milter_url(const char *str) } static void -set_debug(void *value) +set_debug(union mf_option_value *val) { - mu_debug_parse_spec(value); + mu_debug_parse_spec(val->ov_string); + free(val->ov_string); } void -set_source_info(void *value) +set_source_info(union mf_option_value *val) { - mu_debug_line_info = (int) value; + mu_debug_line_info = val->ov_bool; } static void -set_user(void *value) +set_user(union mf_option_value *val) { - mf_server_user = value; + mf_server_user = val->ov_string; } static int @@ -185,38 +186,37 @@ mf_option_group(const char *arg) static int -option_group(char *opt, void **pval, char *newval) +option_group(char const *opt, union mf_option_value *val, char const *arg) { - return mf_option_group(newval); + return mf_option_group(arg); } static int -option_pidfile(char *opt, void **pval, char *newval) +option_pidfile(char const *opt, union mf_option_value *val, char const *arg) { - if (newval[0] != '/') { + if (arg[0] != '/') { mu_error(_("invalid pidfile name: must be absolute")); return 1; } - return mf_option_string(opt, pval, newval); + return mf_option_string(opt, val, arg); } static void -set_pidfile(void *value) +set_pidfile(union mf_option_value *val) { - pidfile = value; + pidfile = val->ov_string; } static void -set_io_timeout(void *value) +set_io_timeout(union mf_option_value *val) { - io_timeout = *(time_t*) value; - free(value); + io_timeout = val->ov_time; } static void -set_logger_option(void *value) +set_logger_option(union mf_option_value *val) { - log_stream = value; + log_stream = val->ov_string; } static int @@ -243,15 +243,16 @@ mf_option_state_directory(const char *arg) } void -set_state_directory(void *value) +set_state_directory(union mf_option_value *val) { /* nothing */ } int -option_state_directory(char *opt, void **pval, char *newval) +option_state_directory(char const *opt, union mf_option_value *val, + char const *arg) { - return mf_option_state_directory(newval); + return mf_option_state_directory(arg); } void @@ -282,13 +283,14 @@ mf_srvcfg_add(const char *type, const char *urlstr) } static void -set_port(void *value) +set_port(union mf_option_value *val) { - mf_srvcfg_add("default", value); + mf_srvcfg_add("default", val->ov_string); + free(val->ov_string); } static void -set_source_ip(void *value) +set_source_ip(union mf_option_value *val) { int rc; struct mu_sockaddr_hints hints; @@ -297,26 +299,27 @@ set_source_ip(void *value) hints.family = AF_INET; hints.socktype = SOCK_STREAM; hints.protocol = IPPROTO_TCP; - rc = mu_sockaddr_from_node(&source_address, (char*)value, NULL, + rc = mu_sockaddr_from_node(&source_address, val->ov_string, NULL, &hints); if (rc) { mu_error(_("cannot convert %s to sockaddr: %s"), - (char*)value, mu_strerror(rc)); + val->ov_string, mu_strerror(rc)); } + free(val->ov_string); } static struct mf_option_cache srv_option_cache[] = { - { "debug", NULL, mf_option_string, set_debug }, - { "source-info", NULL, mf_option_boolean, set_source_info }, - { "user", NULL, mf_option_string, set_user }, - { "group", NULL, option_group, NULL }, - { "pidfile", NULL, option_pidfile, set_pidfile }, - { "source-ip", NULL, mf_option_string, set_source_ip }, - { "io-timeout", NULL, mf_option_time, set_io_timeout }, - { "logger", NULL, mf_option_string, set_logger_option }, - { "state-directory", NULL, option_state_directory, + { "debug", mf_option_string, set_debug }, + { "source-info", mf_option_boolean, set_source_info }, + { "user", mf_option_string, set_user }, + { "group", option_group, NULL }, + { "pidfile", option_pidfile, set_pidfile }, + { "source-ip", mf_option_string, set_source_ip }, + { "io-timeout", mf_option_timeout, set_io_timeout }, + { "logger", mf_option_string, set_logger_option }, + { "state-directory", option_state_directory, set_state_directory }, - { "port", NULL, mf_option_string, set_port }, + { "port", mf_option_string, set_port }, { NULL } }; |