Factor out parsing vconn-ssl options.
authorBen Pfaff <blp@nicira.com>
Fri, 4 Apr 2008 00:02:07 +0000 (17:02 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 4 Apr 2008 23:22:23 +0000 (16:22 -0700)
controller/controller.c
include/vconn-ssl.h
secchan/secchan.c
switch/switch.c
utilities/dpctl.c

index 770ee6a65d7da52a2e9e7b594744d75540038aa8..9ef72d0f0d92879334889686d8928c41919e0712 100644 (file)
@@ -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);
index dbd30b4a2853edc02711053b6cc13cacac41ad61..1d4a923d46bbe4416da05b12cc999dbf0b9812c1 100644 (file)
 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 */
index 155dfa9eef98b33399733ce47b43bd971aefbf8a..a0feea04f6a982ea2fcf1d0a5a4b14de19358613 100644 (file)
@@ -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);
index d8ccc80c3de7f3558b5bbc9b3dbd4d30fb77c8d8..abd76b6e1a3c113d12b6b4f44c1b31d8c94096f7 100644 (file)
@@ -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);
index 8f1e77238d5e37879b23ea2e94d054a555b3da27..c78c9b19f7173308128b9a55b994df8d44f688ba 100644 (file)
@@ -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);