diff options
author | Yang Gao <yangg@google.com> | 2015-04-13 16:22:35 -0700 |
---|---|---|
committer | Yang Gao <yangg@google.com> | 2015-04-13 16:22:35 -0700 |
commit | 7b3b058b577171406fab81c93703c752286e8f5b (patch) | |
tree | 191fe13d493b507c181a5c7a5eb7e9e6e22752e4 | |
parent | dcfe504a99a621c9f9c32c12dd8ae3f22fdb0e95 (diff) | |
parent | 6c71ce545666c98a876a60810fa7b5ce5b5dcbda (diff) |
Merge pull request #1270 from jboeuf/server_security_context_factory
Refactoring of server context creation (incremental improvement).
-rw-r--r-- | src/core/security/factories.c | 16 | ||||
-rw-r--r-- | src/core/security/security_context.h | 7 | ||||
-rw-r--r-- | 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 02267d5545..3d9216aac4 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 0b5821c3c0..2b4e38f3ea 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 081272724c..165ed5474f 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.", |