diff options
author | Mark D. Roth <roth@google.com> | 2017-06-12 08:29:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-12 08:29:17 -0700 |
commit | 696560cf35a49a0e92249ea92fda67fafcf144c5 (patch) | |
tree | d9c65fd67271328cf9ce7b61d61e8582dfd374d7 /src/core/lib/security | |
parent | c7d9c804966d12d852d08f4f132c716846a10ece (diff) | |
parent | 8d5e60b8787d1a6aefca037a08799f58a22aa78d (diff) |
Merge pull request #11391 from markdroth/channel_args_helpers
Add helpers for creating channel args.
Diffstat (limited to 'src/core/lib/security')
6 files changed, 17 insertions, 44 deletions
diff --git a/src/core/lib/security/context/security_context.c b/src/core/lib/security/context/security_context.c index e528428650..02b6d0164b 100644 --- a/src/core/lib/security/context/security_context.c +++ b/src/core/lib/security/context/security_context.c @@ -18,6 +18,7 @@ #include <string.h> +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/security/context/security_context.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/api_trace.h" @@ -304,13 +305,8 @@ static const grpc_arg_pointer_vtable auth_context_pointer_vtable = { auth_context_pointer_cmp}; grpc_arg grpc_auth_context_to_arg(grpc_auth_context *p) { - grpc_arg arg; - memset(&arg, 0, sizeof(grpc_arg)); - arg.type = GRPC_ARG_POINTER; - arg.key = GRPC_AUTH_CONTEXT_ARG; - arg.value.pointer.p = p; - arg.value.pointer.vtable = &auth_context_pointer_vtable; - return arg; + return grpc_channel_arg_pointer_create(GRPC_AUTH_CONTEXT_ARG, p, + &auth_context_pointer_vtable); } grpc_auth_context *grpc_auth_context_from_arg(const grpc_arg *arg) { diff --git a/src/core/lib/security/credentials/credentials.c b/src/core/lib/security/credentials/credentials.c index 64a7c3e728..b1f1e82076 100644 --- a/src/core/lib/security/credentials/credentials.c +++ b/src/core/lib/security/credentials/credentials.c @@ -159,12 +159,8 @@ static const grpc_arg_pointer_vtable credentials_pointer_vtable = { grpc_arg grpc_channel_credentials_to_arg( grpc_channel_credentials *credentials) { - grpc_arg result; - result.type = GRPC_ARG_POINTER; - result.key = GRPC_ARG_CHANNEL_CREDENTIALS; - result.value.pointer.vtable = &credentials_pointer_vtable; - result.value.pointer.p = credentials; - return result; + return grpc_channel_arg_pointer_create( + GRPC_ARG_CHANNEL_CREDENTIALS, credentials, &credentials_pointer_vtable); } grpc_channel_credentials *grpc_channel_credentials_from_arg( @@ -260,13 +256,8 @@ static const grpc_arg_pointer_vtable cred_ptr_vtable = { server_credentials_pointer_cmp}; grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials *p) { - grpc_arg arg; - memset(&arg, 0, sizeof(grpc_arg)); - arg.type = GRPC_ARG_POINTER; - arg.key = GRPC_SERVER_CREDENTIALS_ARG; - arg.value.pointer.p = p; - arg.value.pointer.vtable = &cred_ptr_vtable; - return arg; + return grpc_channel_arg_pointer_create(GRPC_SERVER_CREDENTIALS_ARG, p, + &cred_ptr_vtable); } grpc_server_credentials *grpc_server_credentials_from_arg(const grpc_arg *arg) { diff --git a/src/core/lib/security/credentials/fake/fake_credentials.c b/src/core/lib/security/credentials/fake/fake_credentials.c index 3cbb399429..67e74f7b92 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.c +++ b/src/core/lib/security/credentials/fake/fake_credentials.c @@ -78,11 +78,8 @@ grpc_server_credentials *grpc_fake_transport_security_server_credentials_create( } grpc_arg grpc_fake_transport_expected_targets_arg(char *expected_targets) { - grpc_arg arg; - arg.type = GRPC_ARG_STRING; - arg.key = GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS; - arg.value.string = expected_targets; - return arg; + return grpc_channel_arg_string_create(GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS, + expected_targets); } const char *grpc_fake_transport_get_expected_targets( diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.c b/src/core/lib/security/credentials/ssl/ssl_credentials.c index b94b457d35..006db1ec76 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.c +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.c @@ -52,11 +52,8 @@ static grpc_security_status ssl_create_security_connector( grpc_channel_args **new_args) { grpc_ssl_credentials *c = (grpc_ssl_credentials *)creds; grpc_security_status status = GRPC_SECURITY_OK; - size_t i = 0; const char *overridden_target_name = NULL; - grpc_arg new_arg; - - for (i = 0; args && i < args->num_args; i++) { + for (size_t i = 0; args && i < args->num_args; i++) { grpc_arg *arg = &args->args[i]; if (strcmp(arg->key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == 0 && arg->type == GRPC_ARG_STRING) { @@ -69,9 +66,8 @@ static grpc_security_status ssl_create_security_connector( if (status != GRPC_SECURITY_OK) { return status; } - new_arg.type = GRPC_ARG_STRING; - new_arg.key = GRPC_ARG_HTTP2_SCHEME; - new_arg.value.string = "https"; + grpc_arg new_arg = + grpc_channel_arg_string_create(GRPC_ARG_HTTP2_SCHEME, "https"); *new_args = grpc_channel_args_copy_and_add(args, &new_arg, 1); return status; } diff --git a/src/core/lib/security/transport/lb_targets_info.c b/src/core/lib/security/transport/lb_targets_info.c index 45bc91b30c..5583a4e0ff 100644 --- a/src/core/lib/security/transport/lb_targets_info.c +++ b/src/core/lib/security/transport/lb_targets_info.c @@ -37,12 +37,9 @@ static const grpc_arg_pointer_vtable server_to_balancer_names_vtable = { grpc_arg grpc_lb_targets_info_create_channel_arg( grpc_slice_hash_table *targets_info) { - grpc_arg arg; - arg.type = GRPC_ARG_POINTER; - arg.key = GRPC_ARG_LB_SECURE_NAMING_MAP; - arg.value.pointer.p = targets_info; - arg.value.pointer.vtable = &server_to_balancer_names_vtable; - return arg; + return grpc_channel_arg_pointer_create(GRPC_ARG_LB_SECURE_NAMING_MAP, + targets_info, + &server_to_balancer_names_vtable); } grpc_slice_hash_table *grpc_lb_targets_info_find_in_args( diff --git a/src/core/lib/security/transport/security_connector.c b/src/core/lib/security/transport/security_connector.c index 30a74302e1..9934d57ee6 100644 --- a/src/core/lib/security/transport/security_connector.c +++ b/src/core/lib/security/transport/security_connector.c @@ -191,12 +191,8 @@ static const grpc_arg_pointer_vtable connector_pointer_vtable = { connector_pointer_cmp}; grpc_arg grpc_security_connector_to_arg(grpc_security_connector *sc) { - grpc_arg result; - result.type = GRPC_ARG_POINTER; - result.key = GRPC_ARG_SECURITY_CONNECTOR; - result.value.pointer.vtable = &connector_pointer_vtable; - result.value.pointer.p = sc; - return result; + return grpc_channel_arg_pointer_create(GRPC_ARG_SECURITY_CONNECTOR, sc, + &connector_pointer_vtable); } grpc_security_connector *grpc_security_connector_from_arg(const grpc_arg *arg) { |