David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2014, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
| 15 | #include "test_config.h" |
| 16 | |
Ben Laurie | eba2384 | 2014-09-30 12:44:15 +0100 | [diff] [blame] | 17 | #include <stdio.h> |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 18 | #include <stdlib.h> |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 19 | #include <string.h> |
| 20 | |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 21 | #include <memory> |
| 22 | |
| 23 | #include <openssl/base64.h> |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 24 | |
| 25 | namespace { |
| 26 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 27 | template <typename T> |
| 28 | struct Flag { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 29 | const char *flag; |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 30 | T TestConfig::*member; |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 31 | }; |
| 32 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 33 | // FindField looks for the flag in |flags| that matches |flag|. If one is found, |
| 34 | // it returns a pointer to the corresponding field in |config|. Otherwise, it |
| 35 | // returns NULL. |
| 36 | template<typename T, size_t N> |
| 37 | T *FindField(TestConfig *config, const Flag<T> (&flags)[N], const char *flag) { |
| 38 | for (size_t i = 0; i < N; i++) { |
| 39 | if (strcmp(flag, flags[i].flag) == 0) { |
| 40 | return &(config->*(flags[i].member)); |
| 41 | } |
| 42 | } |
| 43 | return NULL; |
| 44 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 45 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 46 | const Flag<bool> kBoolFlags[] = { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 47 | { "-server", &TestConfig::is_server }, |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 48 | { "-dtls", &TestConfig::is_dtls }, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 49 | { "-fallback-scsv", &TestConfig::fallback_scsv }, |
| 50 | { "-require-any-client-certificate", |
| 51 | &TestConfig::require_any_client_certificate }, |
| 52 | { "-false-start", &TestConfig::false_start }, |
| 53 | { "-async", &TestConfig::async }, |
| 54 | { "-write-different-record-sizes", |
| 55 | &TestConfig::write_different_record_sizes }, |
| 56 | { "-cbc-record-splitting", &TestConfig::cbc_record_splitting }, |
| 57 | { "-partial-write", &TestConfig::partial_write }, |
Steven Valdez | 4f94b1c | 2016-05-24 12:31:07 -0400 | [diff] [blame] | 58 | { "-no-tls13", &TestConfig::no_tls13 }, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 59 | { "-no-tls12", &TestConfig::no_tls12 }, |
| 60 | { "-no-tls11", &TestConfig::no_tls11 }, |
| 61 | { "-no-tls1", &TestConfig::no_tls1 }, |
| 62 | { "-no-ssl3", &TestConfig::no_ssl3 }, |
Steven Valdez | 143e8b3 | 2016-07-11 13:19:03 -0400 | [diff] [blame] | 63 | { "-enable-channel-id", &TestConfig::enable_channel_id }, |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 64 | { "-shim-writes-first", &TestConfig::shim_writes_first }, |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 65 | { "-expect-session-miss", &TestConfig::expect_session_miss }, |
David Benjamin | 594e7d2 | 2016-03-17 17:49:56 -0400 | [diff] [blame] | 66 | { "-decline-alpn", &TestConfig::decline_alpn }, |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 67 | { "-expect-extended-master-secret", |
| 68 | &TestConfig::expect_extended_master_secret }, |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 69 | { "-enable-ocsp-stapling", &TestConfig::enable_ocsp_stapling }, |
| 70 | { "-enable-signed-cert-timestamps", |
| 71 | &TestConfig::enable_signed_cert_timestamps }, |
David Benjamin | e0e7d0d | 2015-02-08 19:33:25 -0500 | [diff] [blame] | 72 | { "-implicit-handshake", &TestConfig::implicit_handshake }, |
David Benjamin | 6f5c0f4 | 2015-02-24 01:23:21 -0500 | [diff] [blame] | 73 | { "-use-early-callback", &TestConfig::use_early_callback }, |
| 74 | { "-fail-early-callback", &TestConfig::fail_early_callback }, |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 75 | { "-install-ddos-callback", &TestConfig::install_ddos_callback }, |
| 76 | { "-fail-ddos-callback", &TestConfig::fail_ddos_callback }, |
| 77 | { "-fail-second-ddos-callback", &TestConfig::fail_second_ddos_callback }, |
David Benjamin | b8d74f5 | 2016-11-14 22:02:50 +0900 | [diff] [blame] | 78 | { "-fail-cert-callback", &TestConfig::fail_cert_callback }, |
David Benjamin | 87e4acd | 2015-04-02 19:57:35 -0400 | [diff] [blame] | 79 | { "-handshake-never-done", &TestConfig::handshake_never_done }, |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 80 | { "-use-export-context", &TestConfig::use_export_context }, |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 81 | { "-tls-unique", &TestConfig::tls_unique }, |
David Benjamin | ba4594a | 2015-06-18 18:36:15 -0400 | [diff] [blame] | 82 | { "-expect-ticket-renewal", &TestConfig::expect_ticket_renewal }, |
| 83 | { "-expect-no-session", &TestConfig::expect_no_session }, |
Steven Valdez | 08b65f4 | 2016-12-07 15:29:45 -0500 | [diff] [blame] | 84 | { "-expect-early-data-info", &TestConfig::expect_early_data_info }, |
David Benjamin | d98452d | 2015-06-16 14:16:23 -0400 | [diff] [blame] | 85 | { "-use-ticket-callback", &TestConfig::use_ticket_callback }, |
| 86 | { "-renew-ticket", &TestConfig::renew_ticket }, |
Steven Valdez | 08b65f4 | 2016-12-07 15:29:45 -0500 | [diff] [blame] | 87 | { "-enable-early-data", &TestConfig::enable_early_data }, |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 88 | { "-enable-client-custom-extension", |
| 89 | &TestConfig::enable_client_custom_extension }, |
| 90 | { "-enable-server-custom-extension", |
| 91 | &TestConfig::enable_server_custom_extension }, |
| 92 | { "-custom-extension-skip", &TestConfig::custom_extension_skip }, |
| 93 | { "-custom-extension-fail-add", &TestConfig::custom_extension_fail_add }, |
David Benjamin | 30789da | 2015-08-29 22:56:45 -0400 | [diff] [blame] | 94 | { "-check-close-notify", &TestConfig::check_close_notify }, |
| 95 | { "-shim-shuts-down", &TestConfig::shim_shuts_down }, |
Paul Lietar | 8f1c268 | 2015-08-18 12:21:54 +0100 | [diff] [blame] | 96 | { "-verify-fail", &TestConfig::verify_fail }, |
| 97 | { "-verify-peer", &TestConfig::verify_peer }, |
David Benjamin | 1d5ef3b | 2015-10-12 19:54:18 -0400 | [diff] [blame] | 98 | { "-expect-verify-result", &TestConfig::expect_verify_result }, |
| 99 | { "-renegotiate-once", &TestConfig::renegotiate_once }, |
| 100 | { "-renegotiate-freely", &TestConfig::renegotiate_freely }, |
Adam Langley | 27a0d08 | 2015-11-03 13:34:10 -0800 | [diff] [blame] | 101 | { "-renegotiate-ignore", &TestConfig::renegotiate_ignore }, |
David Benjamin | 99fdfb9 | 2015-11-02 12:11:35 -0500 | [diff] [blame] | 102 | { "-p384-only", &TestConfig::p384_only }, |
David Benjamin | 8c2b3bf | 2015-12-18 20:55:44 -0500 | [diff] [blame] | 103 | { "-enable-all-curves", &TestConfig::enable_all_curves }, |
David Benjamin | acb6dcc | 2016-03-10 09:15:01 -0500 | [diff] [blame] | 104 | { "-use-old-client-cert-callback", |
| 105 | &TestConfig::use_old_client_cert_callback }, |
David Benjamin | 1d4f4c0 | 2016-07-26 18:03:08 -0400 | [diff] [blame] | 106 | { "-send-alert", &TestConfig::send_alert }, |
David Benjamin | f3fbade | 2016-09-19 13:08:16 -0400 | [diff] [blame] | 107 | { "-peek-then-read", &TestConfig::peek_then_read }, |
David Benjamin | 65ac997 | 2016-09-02 21:35:25 -0400 | [diff] [blame] | 108 | { "-enable-grease", &TestConfig::enable_grease }, |
David Benjamin | 7bb1d29 | 2016-11-01 19:45:06 -0400 | [diff] [blame] | 109 | { "-use-exporter-between-reads", &TestConfig::use_exporter_between_reads }, |
David Benjamin | bbaf367 | 2016-11-17 10:53:09 +0900 | [diff] [blame] | 110 | { "-retain-only-sha256-client-cert-initial", |
| 111 | &TestConfig::retain_only_sha256_client_cert_initial }, |
| 112 | { "-retain-only-sha256-client-cert-resume", |
| 113 | &TestConfig::retain_only_sha256_client_cert_resume }, |
| 114 | { "-expect-sha256-client-cert-initial", |
| 115 | &TestConfig::expect_sha256_client_cert_initial }, |
| 116 | { "-expect-sha256-client-cert-resume", |
| 117 | &TestConfig::expect_sha256_client_cert_resume }, |
David Benjamin | a1eaba1 | 2017-01-01 23:19:22 -0500 | [diff] [blame] | 118 | { "-read-with-unfinished-write", &TestConfig::read_with_unfinished_write }, |
David Benjamin | d261004 | 2017-01-03 10:49:28 -0500 | [diff] [blame] | 119 | { "-expect-secure-renegotiation", |
| 120 | &TestConfig::expect_secure_renegotiation }, |
| 121 | { "-expect-no-secure-renegotiation", |
| 122 | &TestConfig::expect_no_secure_renegotiation }, |
David Benjamin | b5c58db | 2017-01-28 01:39:29 -0500 | [diff] [blame] | 123 | { "-expect-session-id", &TestConfig::expect_session_id }, |
| 124 | { "-expect-no-session-id", &TestConfig::expect_no_session_id }, |
Steven Valdez | 2d85062 | 2017-01-11 11:34:52 -0500 | [diff] [blame] | 125 | { "-expect-accept-early-data", &TestConfig::expect_accept_early_data }, |
| 126 | { "-expect-reject-early-data", &TestConfig::expect_reject_early_data }, |
David Benjamin | 8c26d75 | 2017-03-26 15:13:51 -0500 | [diff] [blame] | 127 | { "-no-op-extra-handshake", &TestConfig::no_op_extra_handshake }, |
| 128 | { "-handshake-twice", &TestConfig::handshake_twice }, |
David Benjamin | c8ff30c | 2017-04-04 13:52:36 -0400 | [diff] [blame] | 129 | { "-allow-unknown-alpn-protos", &TestConfig::allow_unknown_alpn_protos }, |
David Benjamin | 6952211 | 2017-03-28 15:38:29 -0500 | [diff] [blame] | 130 | { "-enable-ed25519", &TestConfig::enable_ed25519 }, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 131 | }; |
| 132 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 133 | const Flag<std::string> kStringFlags[] = { |
Steven Valdez | 0d62f26 | 2015-09-04 12:41:04 -0400 | [diff] [blame] | 134 | { "-digest-prefs", &TestConfig::digest_prefs }, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 135 | { "-key-file", &TestConfig::key_file }, |
| 136 | { "-cert-file", &TestConfig::cert_file }, |
| 137 | { "-expect-server-name", &TestConfig::expected_server_name }, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 138 | { "-advertise-npn", &TestConfig::advertise_npn }, |
| 139 | { "-expect-next-proto", &TestConfig::expected_next_proto }, |
| 140 | { "-select-next-proto", &TestConfig::select_next_proto }, |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 141 | { "-send-channel-id", &TestConfig::send_channel_id }, |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 142 | { "-host-name", &TestConfig::host_name }, |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 143 | { "-advertise-alpn", &TestConfig::advertise_alpn }, |
| 144 | { "-expect-alpn", &TestConfig::expected_alpn }, |
| 145 | { "-expect-advertised-alpn", &TestConfig::expected_advertised_alpn }, |
| 146 | { "-select-alpn", &TestConfig::select_alpn }, |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 147 | { "-psk", &TestConfig::psk }, |
| 148 | { "-psk-identity", &TestConfig::psk_identity }, |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 149 | { "-srtp-profiles", &TestConfig::srtp_profiles }, |
David Benjamin | 67d1fb5 | 2015-03-16 15:16:23 -0400 | [diff] [blame] | 150 | { "-cipher", &TestConfig::cipher }, |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 151 | { "-export-label", &TestConfig::export_label }, |
| 152 | { "-export-context", &TestConfig::export_context }, |
David Benjamin | 2c51645 | 2016-11-15 10:16:54 +0900 | [diff] [blame] | 153 | { "-expect-peer-cert-file", &TestConfig::expect_peer_cert_file }, |
Adam Langley | 2ff7933 | 2017-02-28 13:45:39 -0800 | [diff] [blame] | 154 | { "-use-client-ca-list", &TestConfig::use_client_ca_list }, |
| 155 | { "-expect-client-ca-list", &TestConfig::expected_client_ca_list }, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 156 | }; |
| 157 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 158 | const Flag<std::string> kBase64Flags[] = { |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 159 | { "-expect-certificate-types", &TestConfig::expected_certificate_types }, |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 160 | { "-expect-channel-id", &TestConfig::expected_channel_id }, |
David Benjamin | 61f9527 | 2014-11-25 01:55:35 -0500 | [diff] [blame] | 161 | { "-expect-ocsp-response", &TestConfig::expected_ocsp_response }, |
| 162 | { "-expect-signed-cert-timestamps", |
| 163 | &TestConfig::expected_signed_cert_timestamps }, |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 164 | { "-ocsp-response", &TestConfig::ocsp_response }, |
Paul Lietar | 4fac72e | 2015-09-09 13:44:55 +0100 | [diff] [blame] | 165 | { "-signed-cert-timestamps", &TestConfig::signed_cert_timestamps }, |
David Benjamin | 4199b0d | 2016-11-01 13:58:25 -0400 | [diff] [blame] | 166 | { "-ticket-key", &TestConfig::ticket_key }, |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 169 | const Flag<int> kIntFlags[] = { |
David Benjamin | 87c8a64 | 2015-02-21 01:54:29 -0500 | [diff] [blame] | 170 | { "-port", &TestConfig::port }, |
David Benjamin | 4666248 | 2016-08-17 00:51:00 -0400 | [diff] [blame] | 171 | { "-resume-count", &TestConfig::resume_count }, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 172 | { "-min-version", &TestConfig::min_version }, |
| 173 | { "-max-version", &TestConfig::max_version }, |
David Benjamin | 13be1de | 2015-01-11 16:29:36 -0500 | [diff] [blame] | 174 | { "-mtu", &TestConfig::mtu }, |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 175 | { "-export-keying-material", &TestConfig::export_keying_material }, |
David Benjamin | 324dce4 | 2015-10-12 19:49:00 -0400 | [diff] [blame] | 176 | { "-expect-total-renegotiations", &TestConfig::expect_total_renegotiations }, |
Nick Harper | 60edffd | 2016-06-21 15:19:24 -0700 | [diff] [blame] | 177 | { "-expect-peer-signature-algorithm", |
| 178 | &TestConfig::expect_peer_signature_algorithm }, |
David Benjamin | 9e68f19 | 2016-06-30 14:55:33 -0400 | [diff] [blame] | 179 | { "-expect-curve-id", &TestConfig::expect_curve_id }, |
Taylor Brandstetter | 376a0fe | 2016-05-10 19:30:28 -0700 | [diff] [blame] | 180 | { "-initial-timeout-duration-ms", &TestConfig::initial_timeout_duration_ms }, |
David Benjamin | a252b34 | 2016-09-26 19:57:53 -0400 | [diff] [blame] | 181 | { "-max-cert-list", &TestConfig::max_cert_list }, |
David Benjamin | abbbee1 | 2016-10-31 19:20:42 -0400 | [diff] [blame] | 182 | { "-expect-cipher-aes", &TestConfig::expect_cipher_aes }, |
| 183 | { "-expect-cipher-no-aes", &TestConfig::expect_cipher_no_aes }, |
Steven Valdez | a833c35 | 2016-11-01 13:39:36 -0400 | [diff] [blame] | 184 | { "-resumption-delay", &TestConfig::resumption_delay }, |
David Benjamin | e3fbb36 | 2017-01-06 16:19:28 -0500 | [diff] [blame] | 185 | { "-max-send-fragment", &TestConfig::max_send_fragment }, |
| 186 | { "-read-size", &TestConfig::read_size }, |
David Benjamin | 35ac5b7 | 2017-03-03 15:05:56 -0500 | [diff] [blame] | 187 | { "-expect-ticket-age-skew", &TestConfig::expect_ticket_age_skew }, |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 188 | }; |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 189 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 190 | const Flag<std::vector<int>> kIntVectorFlags[] = { |
| 191 | { "-signing-prefs", &TestConfig::signing_prefs }, |
David Benjamin | 71c21b4 | 2017-04-14 17:05:40 -0400 | [diff] [blame] | 192 | { "-verify-prefs", &TestConfig::verify_prefs }, |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 193 | }; |
| 194 | |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 195 | const char kInit[] = "-on-initial"; |
| 196 | const char kResume[] = "-on-resume"; |
| 197 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 198 | } // namespace |
| 199 | |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 200 | bool ParseConfig(int argc, char **argv, bool is_resume, |
| 201 | TestConfig *out_config) { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 202 | for (int i = 0; i < argc; i++) { |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 203 | bool skip = false; |
| 204 | char *flag = argv[i]; |
| 205 | const char *prefix = is_resume ? kResume : kInit; |
| 206 | const char *opposite = is_resume ? kInit : kResume; |
| 207 | if (strncmp(flag, prefix, strlen(prefix)) == 0) { |
| 208 | flag = flag + strlen(prefix); |
| 209 | for (int j = 0; j < argc; j++) { |
| 210 | if (strcmp(argv[j], flag) == 0) { |
| 211 | fprintf(stderr, "Can't use default and prefixed arguments: %s\n", |
| 212 | flag); |
| 213 | return false; |
| 214 | } |
| 215 | } |
| 216 | } else if (strncmp(flag, opposite, strlen(opposite)) == 0) { |
| 217 | flag = flag + strlen(opposite); |
| 218 | skip = true; |
| 219 | } |
| 220 | |
| 221 | bool *bool_field = FindField(out_config, kBoolFlags, flag); |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 222 | if (bool_field != NULL) { |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 223 | if (!skip) { |
| 224 | *bool_field = true; |
| 225 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 226 | continue; |
| 227 | } |
| 228 | |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 229 | std::string *string_field = FindField(out_config, kStringFlags, flag); |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 230 | if (string_field != NULL) { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 231 | i++; |
| 232 | if (i >= argc) { |
| 233 | fprintf(stderr, "Missing parameter\n"); |
| 234 | return false; |
| 235 | } |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 236 | if (!skip) { |
| 237 | string_field->assign(argv[i]); |
| 238 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 239 | continue; |
| 240 | } |
| 241 | |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 242 | std::string *base64_field = FindField(out_config, kBase64Flags, flag); |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 243 | if (base64_field != NULL) { |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 244 | i++; |
| 245 | if (i >= argc) { |
| 246 | fprintf(stderr, "Missing parameter\n"); |
| 247 | return false; |
| 248 | } |
| 249 | size_t len; |
| 250 | if (!EVP_DecodedLength(&len, strlen(argv[i]))) { |
| 251 | fprintf(stderr, "Invalid base64: %s\n", argv[i]); |
David Benjamin | 154c2f2 | 2016-03-05 11:57:44 -0500 | [diff] [blame] | 252 | return false; |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 253 | } |
| 254 | std::unique_ptr<uint8_t[]> decoded(new uint8_t[len]); |
| 255 | if (!EVP_DecodeBase64(decoded.get(), &len, len, |
| 256 | reinterpret_cast<const uint8_t *>(argv[i]), |
| 257 | strlen(argv[i]))) { |
| 258 | fprintf(stderr, "Invalid base64: %s\n", argv[i]); |
David Benjamin | 154c2f2 | 2016-03-05 11:57:44 -0500 | [diff] [blame] | 259 | return false; |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 260 | } |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 261 | if (!skip) { |
| 262 | base64_field->assign(reinterpret_cast<const char *>(decoded.get()), |
| 263 | len); |
| 264 | } |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 265 | continue; |
| 266 | } |
| 267 | |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 268 | int *int_field = FindField(out_config, kIntFlags, flag); |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 269 | if (int_field) { |
| 270 | i++; |
| 271 | if (i >= argc) { |
| 272 | fprintf(stderr, "Missing parameter\n"); |
| 273 | return false; |
| 274 | } |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 275 | if (!skip) { |
| 276 | *int_field = atoi(argv[i]); |
| 277 | } |
David Benjamin | 2561dc3 | 2014-08-24 01:25:27 -0400 | [diff] [blame] | 278 | continue; |
| 279 | } |
| 280 | |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 281 | std::vector<int> *int_vector_field = |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 282 | FindField(out_config, kIntVectorFlags, flag); |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 283 | if (int_vector_field) { |
| 284 | i++; |
| 285 | if (i >= argc) { |
| 286 | fprintf(stderr, "Missing parameter\n"); |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | // Each instance of the flag adds to the list. |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 291 | if (!skip) { |
| 292 | int_vector_field->push_back(atoi(argv[i])); |
| 293 | } |
David Benjamin | ca3d545 | 2016-07-14 12:51:01 -0400 | [diff] [blame] | 294 | continue; |
| 295 | } |
| 296 | |
Steven Valdez | 873ebc9 | 2017-05-09 12:12:58 -0400 | [diff] [blame] | 297 | fprintf(stderr, "Unknown argument: %s\n", flag); |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 298 | return false; |
| 299 | } |
| 300 | |
| 301 | return true; |
| 302 | } |