diff options
author | ncteisen <ncteisen@gmail.com> | 2018-06-07 16:53:17 -0700 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2018-06-13 10:36:32 -0700 |
commit | 6dc54c496fb3d34af63ce6bdf8656496077689a9 (patch) | |
tree | 4d1a86cf396d433a12bc4f9985b9dac68861c479 /src/core/lib/security | |
parent | 9b52965ba4157d098bb951c892e18a1361917200 (diff) |
Remove all uses of raw GRPC_ARG_POINTER
Diffstat (limited to 'src/core/lib/security')
5 files changed, 21 insertions, 91 deletions
diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 14051a3f00..98e3cfde10 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -326,23 +326,9 @@ grpc_arg grpc_auth_context_to_arg(grpc_auth_context* p) { &auth_context_pointer_vtable); } -grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_AUTH_CONTEXT_ARG) != 0) return nullptr; - if (arg->type != GRPC_ARG_POINTER) { - gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, - GRPC_AUTH_CONTEXT_ARG); - return nullptr; - } - return static_cast<grpc_auth_context*>(arg->value.pointer.p); -} - grpc_auth_context* grpc_find_auth_context_in_args( - const grpc_channel_args* args) { - size_t i; - if (args == nullptr) return nullptr; - for (i = 0; i < args->num_args; i++) { - grpc_auth_context* p = grpc_auth_context_from_arg(&args->args[i]); - if (p != nullptr) return p; - } - return nullptr; + const grpc_channel_args* channel_args) { + const grpc_arg* arg = + grpc_channel_args_find(channel_args, GRPC_AUTH_CONTEXT_ARG); + return grpc_channel_arg_get_pointer<grpc_auth_context>(arg); } diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index c43cb440eb..1842862ce3 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -168,27 +168,11 @@ grpc_arg grpc_channel_credentials_to_arg( &credentials_pointer_vtable); } -grpc_channel_credentials* grpc_channel_credentials_from_arg( - const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_ARG_CHANNEL_CREDENTIALS)) return nullptr; - if (arg->type != GRPC_ARG_POINTER) { - gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, - GRPC_ARG_CHANNEL_CREDENTIALS); - return nullptr; - } - return static_cast<grpc_channel_credentials*>(arg->value.pointer.p); -} - grpc_channel_credentials* grpc_channel_credentials_find_in_args( - const grpc_channel_args* args) { - size_t i; - if (args == nullptr) return nullptr; - for (i = 0; i < args->num_args; i++) { - grpc_channel_credentials* credentials = - grpc_channel_credentials_from_arg(&args->args[i]); - if (credentials != nullptr) return credentials; - } - return nullptr; + const grpc_channel_args* channel_args) { + const grpc_arg* arg = + grpc_channel_args_find(channel_args, GRPC_ARG_CHANNEL_CREDENTIALS); + return grpc_channel_arg_get_pointer<grpc_channel_credentials>(arg); } grpc_server_credentials* grpc_server_credentials_ref( @@ -263,24 +247,9 @@ grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials* p) { &cred_ptr_vtable); } -grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_SERVER_CREDENTIALS_ARG) != 0) return nullptr; - if (arg->type != GRPC_ARG_POINTER) { - gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, - GRPC_SERVER_CREDENTIALS_ARG); - return nullptr; - } - return static_cast<grpc_server_credentials*>(arg->value.pointer.p); -} - grpc_server_credentials* grpc_find_server_credentials_in_args( - const grpc_channel_args* args) { - size_t i; - if (args == nullptr) return nullptr; - for (i = 0; i < args->num_args; i++) { - grpc_server_credentials* p = - grpc_server_credentials_from_arg(&args->args[i]); - if (p != nullptr) return p; - } - return nullptr; + const grpc_channel_args* channel_args) { + const grpc_arg* arg = + grpc_channel_args_find(channel_args, GRPC_SERVER_CREDENTIALS_ARG); + return grpc_channel_arg_get_pointer<grpc_server_credentials>(arg); } diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 2b6377d3ec..13dae19b4b 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -60,14 +60,12 @@ static grpc_security_status ssl_create_security_connector( tsi_ssl_session_cache* ssl_session_cache = nullptr; 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) { - overridden_target_name = arg->value.string; + if (strcmp(arg->key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == 0) { + overridden_target_name = grpc_channel_arg_get_string(arg); } - if (strcmp(arg->key, GRPC_SSL_SESSION_CACHE_ARG) == 0 && - arg->type == GRPC_ARG_POINTER) { + if (strcmp(arg->key, GRPC_SSL_SESSION_CACHE_ARG) == 0) { ssl_session_cache = - static_cast<tsi_ssl_session_cache*>(arg->value.pointer.p); + grpc_channel_arg_get_pointer<tsi_ssl_session_cache>(arg); } } status = grpc_ssl_channel_security_connector_create( diff --git a/src/core/lib/security/security_connector/security_connector.cc b/src/core/lib/security/security_connector/security_connector.cc index b54a7643e4..cb2763f72a 100644 --- a/src/core/lib/security/security_connector/security_connector.cc +++ b/src/core/lib/security/security_connector/security_connector.cc @@ -255,26 +255,11 @@ grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc) { &connector_arg_vtable); } -grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return nullptr; - if (arg->type != GRPC_ARG_POINTER) { - gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, - GRPC_ARG_SECURITY_CONNECTOR); - return nullptr; - } - return static_cast<grpc_security_connector*>(arg->value.pointer.p); -} - grpc_security_connector* grpc_security_connector_find_in_args( - const grpc_channel_args* args) { - size_t i; - if (args == nullptr) return nullptr; - for (i = 0; i < args->num_args; i++) { - grpc_security_connector* sc = - grpc_security_connector_from_arg(&args->args[i]); - if (sc != nullptr) return sc; - } - return nullptr; + const grpc_channel_args* channel_args) { + const grpc_arg* arg = + grpc_channel_args_find(channel_args, GRPC_ARG_SECURITY_CONNECTOR); + return grpc_channel_arg_get_pointer<grpc_security_connector>(arg); } static tsi_client_certificate_request_type diff --git a/src/core/lib/security/transport/target_authority_table.cc b/src/core/lib/security/transport/target_authority_table.cc index 1eeb557f6a..2f1034d207 100644 --- a/src/core/lib/security/transport/target_authority_table.cc +++ b/src/core/lib/security/transport/target_authority_table.cc @@ -61,15 +61,7 @@ TargetAuthorityTable* FindTargetAuthorityTableInArgs( const grpc_channel_args* args) { const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_TARGET_AUTHORITY_TABLE); - if (arg != nullptr) { - if (arg->type == GRPC_ARG_POINTER) { - return static_cast<TargetAuthorityTable*>(arg->value.pointer.p); - } else { - gpr_log(GPR_ERROR, "value of " GRPC_ARG_TARGET_AUTHORITY_TABLE - " channel arg was not pointer type; ignoring"); - } - } - return nullptr; + return grpc_channel_arg_get_pointer<TargetAuthorityTable>(arg); } } // namespace grpc_core |