From 6c71ce545666c98a876a60810fa7b5ce5b5dcbda Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Mon, 13 Apr 2015 13:32:43 -0700 Subject: [PATCH] Refactoring of server context creation (incremental improvement). --- src/core/security/factories.c | 16 ++++++++++++++++ src/core/security/security_context.h | 7 +++---- src/core/security/server_secure_chttp2.c | 11 +---------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/core/security/factories.c b/src/core/security/factories.c index 02267d55457..3d9216aac40 100644 --- a/src/core/security/factories.c +++ b/src/core/security/factories.c @@ -50,3 +50,19 @@ grpc_channel *grpc_secure_channel_create(grpc_credentials *creds, return grpc_secure_channel_create_with_factories( factories, GPR_ARRAY_SIZE(factories), creds, target, args); } + +grpc_security_status grpc_server_security_context_create( + grpc_server_credentials *creds, grpc_security_context **ctx) { + grpc_security_status status = GRPC_SECURITY_ERROR; + + *ctx = NULL; + if (strcmp(creds->type, GRPC_CREDENTIALS_TYPE_SSL) == 0) { + status = grpc_ssl_server_security_context_create( + grpc_ssl_server_credentials_get_config(creds), ctx); + } else if (strcmp(creds->type, + GRPC_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY) == 0) { + *ctx = grpc_fake_server_security_context_create(); + status = GRPC_SECURITY_OK; + } + return status; +} diff --git a/src/core/security/security_context.h b/src/core/security/security_context.h index 0b5821c3c08..2b4e38f3ea6 100644 --- a/src/core/security/security_context.h +++ b/src/core/security/security_context.h @@ -206,10 +206,9 @@ grpc_channel *grpc_secure_channel_create_with_factories( const grpc_secure_channel_factory *factories, size_t num_factories, grpc_credentials *creds, const char *target, const grpc_channel_args *args); -/* Secure server creation. */ +/* Secure server context creation. */ -grpc_server *grpc_secure_server_create_internal(grpc_completion_queue *cq, - const grpc_channel_args *args, - grpc_security_context *ctx); +grpc_security_status grpc_server_security_context_create( + grpc_server_credentials *creds, grpc_security_context **ctx); #endif /* GRPC_INTERNAL_CORE_SECURITY_SECURITY_CONTEXT_H */ diff --git a/src/core/security/server_secure_chttp2.c b/src/core/security/server_secure_chttp2.c index 081272724cf..165ed5474fe 100644 --- a/src/core/security/server_secure_chttp2.c +++ b/src/core/security/server_secure_chttp2.c @@ -141,16 +141,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr, /* create security context */ if (creds == NULL) goto error; - - if (strcmp(creds->type, GRPC_CREDENTIALS_TYPE_SSL) == 0) { - status = grpc_ssl_server_security_context_create( - grpc_ssl_server_credentials_get_config(creds), &ctx); - } else if (strcmp(creds->type, - GRPC_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY) == 0) { - ctx = grpc_fake_server_security_context_create(); - status = GRPC_SECURITY_OK; - } - + status = grpc_server_security_context_create(creds, &ctx); if (status != GRPC_SECURITY_OK) { gpr_log(GPR_ERROR, "Unable to create secure server with credentials of type %s.",