From d16f2e55481e2ba667d2b74d387b3a1b6787bde9 Mon Sep 17 00:00:00 2001 From: jsing Date: Sun, 28 Dec 2014 14:21:42 +0000 Subject: [PATCH] Provide two different function pointers for option function callbacks. This allows for simpler code in the common cases and will allow for further extension to support the complex cases. --- usr.bin/openssl/apps.c | 6 +++--- usr.bin/openssl/apps.h | 5 +++-- usr.bin/openssl/ecparam.c | 10 +++++----- usr.bin/openssl/version.c | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c index 009f48652ae..47c418f424d 100644 --- a/usr.bin/openssl/apps.c +++ b/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.14 2014/12/14 14:42:06 jsing Exp $ */ +/* $OpenBSD: apps.c,v 1.15 2014/12/28 14:21:42 jsing Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -2298,7 +2298,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) break; case OPTION_ARG_FUNC: - if (opt->func(opt, argv[i]) != 0) + if (opt->opt.argfunc(argv[i]) != 0) return (1); break; @@ -2314,7 +2314,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) break; case OPTION_FUNC: - if (opt->func(opt, NULL) != 0) + if (opt->opt.func() != 0) return (1); break; diff --git a/usr.bin/openssl/apps.h b/usr.bin/openssl/apps.h index b2b7e851076..b069d2d29bf 100644 --- a/usr.bin/openssl/apps.h +++ b/usr.bin/openssl/apps.h @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.h,v 1.9 2014/12/14 14:42:06 jsing Exp $ */ +/* $OpenBSD: apps.h,v 1.10 2014/12/28 14:21:42 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -296,10 +296,11 @@ struct option { } type; union { char **arg; + int (*argfunc)(char *arg); int *flag; + int (*func)(void); int *value; } opt; - int (*func)(struct option *opt, char *arg); const int value; }; diff --git a/usr.bin/openssl/ecparam.c b/usr.bin/openssl/ecparam.c index 1441fa7d2ab..57797a8e4e6 100644 --- a/usr.bin/openssl/ecparam.c +++ b/usr.bin/openssl/ecparam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecparam.c,v 1.6 2014/12/14 14:45:33 jsing Exp $ */ +/* $OpenBSD: ecparam.c,v 1.7 2014/12/28 14:21:42 jsing Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -111,7 +111,7 @@ static struct { } ecparam_config; static int -ecparam_opt_form(struct option *opt, char *arg) +ecparam_opt_form(char *arg) { if (strcmp(arg, "compressed") == 0) ecparam_config.form = POINT_CONVERSION_COMPRESSED; @@ -127,7 +127,7 @@ ecparam_opt_form(struct option *opt, char *arg) } static int -ecparam_opt_enctype(struct option *opt, char *arg) +ecparam_opt_enctype(char *arg) { if (strcmp(arg, "explicit") == 0) ecparam_config.asn1_flag = 0; @@ -159,7 +159,7 @@ struct option ecparam_options[] = { .desc = "Specify point conversion form:\n" " compressed, uncompressed (default), hybrid", .type = OPTION_ARG_FUNC, - .func = ecparam_opt_form, + .opt.argfunc = ecparam_opt_form, }, #ifndef OPENSSL_NO_ENGINE { @@ -237,7 +237,7 @@ struct option ecparam_options[] = { .desc = "Specify EC parameter ASN.1 encoding type:\n" " explicit, named_curve (default)", .type = OPTION_ARG_FUNC, - .func = ecparam_opt_enctype, + .opt.argfunc = ecparam_opt_enctype, }, { .name = "text", diff --git a/usr.bin/openssl/version.c b/usr.bin/openssl/version.c index db9c98e977a..953d0c3afea 100644 --- a/usr.bin/openssl/version.c +++ b/usr.bin/openssl/version.c @@ -1,4 +1,4 @@ -/* $OpenBSD: version.c,v 1.3 2014/10/13 02:46:14 bcook Exp $ */ +/* $OpenBSD: version.c,v 1.4 2014/12/28 14:21:42 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -145,7 +145,7 @@ static struct { } version_config; static int -version_all_opts(struct option *opt, char *arg) +version_all_opts(void) { version_config.cflags = 1; version_config.date = 1; @@ -162,7 +162,7 @@ static struct option version_options[] = { .name = "a", .desc = "All information (same as setting all other flags)", .type = OPTION_FUNC, - .func = version_all_opts, + .opt.func = version_all_opts, }, { .name = "b", -- 2.20.1