From: Ben Pfaff Date: Fri, 4 Apr 2008 00:02:07 +0000 (-0700) Subject: Factor out parsing vconn-ssl options. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f30d8168a7367af121bc7cc7b12f0dc2ab074afb;p=openvswitch Factor out parsing vconn-ssl options. --- diff --git a/controller/controller.c b/controller/controller.c index 770ee6a6..9ef72d0f 100644 --- a/controller/controller.c +++ b/controller/controller.c @@ -564,11 +564,7 @@ parse_options(int argc, char *argv[]) {"verbose", optional_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, -#ifdef HAVE_OPENSSL - {"private-key", required_argument, 0, 'p'}, - {"certificate", required_argument, 0, 'c'}, - {"ca-cert", required_argument, 0, 'C'}, -#endif + VCONN_SSL_LONG_OPTIONS {0, 0, 0, 0}, }; char *short_options = long_options_to_short_options(long_options); @@ -602,19 +598,7 @@ parse_options(int argc, char *argv[]) vlog_set_verbosity(optarg); break; -#ifdef HAVE_OPENSSL - case 'p': - vconn_ssl_set_private_key_file(optarg); - break; - - case 'c': - vconn_ssl_set_certificate_file(optarg); - break; - - case 'C': - vconn_ssl_set_ca_cert_file(optarg); - break; -#endif + VCONN_SSL_OPTION_HANDLERS case '?': exit(EXIT_FAILURE); diff --git a/include/vconn-ssl.h b/include/vconn-ssl.h index dbd30b4a..1d4a923d 100644 --- a/include/vconn-ssl.h +++ b/include/vconn-ssl.h @@ -37,6 +37,27 @@ void vconn_ssl_set_private_key_file(const char *file_name); void vconn_ssl_set_certificate_file(const char *file_name); void vconn_ssl_set_ca_cert_file(const char *file_name); -#endif + +#define VCONN_SSL_LONG_OPTIONS \ + {"private-key", required_argument, 0, 'p'}, \ + {"certificate", required_argument, 0, 'c'}, \ + {"ca-cert", required_argument, 0, 'C'}, + +#define VCONN_SSL_OPTION_HANDLERS \ + case 'p': \ + vconn_ssl_set_private_key_file(optarg); \ + break; \ + \ + case 'c': \ + vconn_ssl_set_certificate_file(optarg); \ + break; \ + \ + case 'C': \ + vconn_ssl_set_ca_cert_file(optarg); \ + break; +#else /* !HAVE_OPENSSL */ +#define VCONN_SSL_LONG_OPTIONS +#define VCONN_SSL_OPTION_HANDLERS +#endif /* !HAVE_OPENSSL */ #endif /* vconn-ssl.h */ diff --git a/secchan/secchan.c b/secchan/secchan.c index 155dfa9e..a0feea04 100644 --- a/secchan/secchan.c +++ b/secchan/secchan.c @@ -267,11 +267,7 @@ parse_options(int argc, char *argv[]) {"verbose", optional_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, -#ifdef HAVE_OPENSSL - {"private-key", required_argument, 0, 'p'}, - {"certificate", required_argument, 0, 'c'}, - {"ca-cert", required_argument, 0, 'C'}, -#endif + VCONN_SSL_LONG_OPTIONS {0, 0, 0, 0}, }; char *short_options = long_options_to_short_options(long_options); @@ -310,19 +306,7 @@ parse_options(int argc, char *argv[]) vlog_set_verbosity(optarg); break; -#ifdef HAVE_OPENSSL - case 'p': - vconn_ssl_set_private_key_file(optarg); - break; - - case 'c': - vconn_ssl_set_certificate_file(optarg); - break; - - case 'C': - vconn_ssl_set_ca_cert_file(optarg); - break; -#endif + VCONN_SSL_OPTION_HANDLERS case '?': exit(EXIT_FAILURE); diff --git a/switch/switch.c b/switch/switch.c index d8ccc80c..abd76b6e 100644 --- a/switch/switch.c +++ b/switch/switch.c @@ -124,11 +124,7 @@ parse_options(int argc, char *argv[]) {"verbose", optional_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, -#ifdef HAVE_OPENSSL - {"private-key", required_argument, 0, 'p'}, - {"certificate", required_argument, 0, 'c'}, - {"ca-cert", required_argument, 0, 'C'}, -#endif + VCONN_SSL_LONG_OPTIONS {0, 0, 0, 0}, }; char *short_options = long_options_to_short_options(long_options); @@ -174,19 +170,7 @@ parse_options(int argc, char *argv[]) } break; -#ifdef HAVE_OPENSSL - case 'p': - vconn_ssl_set_private_key_file(optarg); - break; - - case 'c': - vconn_ssl_set_certificate_file(optarg); - break; - - case 'C': - vconn_ssl_set_ca_cert_file(optarg); - break; -#endif + VCONN_SSL_OPTION_HANDLERS case '?': exit(EXIT_FAILURE); diff --git a/utilities/dpctl.c b/utilities/dpctl.c index 8f1e7723..c78c9b19 100644 --- a/utilities/dpctl.c +++ b/utilities/dpctl.c @@ -112,11 +112,7 @@ parse_options(int argc, char *argv[]) {"verbose", optional_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, -#ifdef HAVE_OPENSSL - {"private-key", required_argument, 0, 'p'}, - {"certificate", required_argument, 0, 'c'}, - {"ca-cert", required_argument, 0, 'C'}, -#endif + VCONN_SSL_LONG_OPTIONS {0, 0, 0, 0}, }; char *short_options = long_options_to_short_options(long_options); @@ -142,19 +138,7 @@ parse_options(int argc, char *argv[]) vlog_set_verbosity(optarg); break; -#ifdef HAVE_OPENSSL - case 'p': - vconn_ssl_set_private_key_file(optarg); - break; - - case 'c': - vconn_ssl_set_certificate_file(optarg); - break; - - case 'C': - vconn_ssl_set_ca_cert_file(optarg); - break; -#endif + VCONN_SSL_OPTION_HANDLERS case '?': exit(EXIT_FAILURE);