diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/channel/context.h | 2 | ||||
-rw-r--r-- | src/core/security/client_auth_filter.c | 2 | ||||
-rw-r--r-- | src/core/security/security_context.c | 40 | ||||
-rw-r--r-- | src/core/security/security_context.h | 6 | ||||
-rw-r--r-- | src/core/security/server_auth_filter.c | 8 | ||||
-rw-r--r-- | src/core/surface/call.c | 20 | ||||
-rw-r--r-- | src/core/transport/transport.h | 2 |
7 files changed, 37 insertions, 43 deletions
diff --git a/src/core/channel/context.h b/src/core/channel/context.h index 85de60d81a..ac5796b9ef 100644 --- a/src/core/channel/context.h +++ b/src/core/channel/context.h @@ -44,6 +44,6 @@ typedef enum { typedef struct { void *value; void (*destroy)(void *); -} grpc_call_context; +} grpc_call_context_element; #endif /* GRPC_INTERNAL_CORE_CHANNEL_CONTEXT_H */ diff --git a/src/core/security/client_auth_filter.c b/src/core/security/client_auth_filter.c index 9e1198919b..72002ee5c2 100644 --- a/src/core/security/client_auth_filter.c +++ b/src/core/security/client_auth_filter.c @@ -125,7 +125,7 @@ static void send_security_metadata(grpc_call_element *elem, call_data *calld = elem->call_data; channel_data *chand = elem->channel_data; grpc_client_security_context *ctx = - (grpc_client_security_context *)op->contexts[GRPC_CONTEXT_SECURITY].value; + (grpc_client_security_context *)op->context[GRPC_CONTEXT_SECURITY].value; char *service_url = NULL; grpc_credentials *channel_creds = chand->security_connector->request_metadata_creds; diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c index c9fcff661f..14c194c8f6 100644 --- a/src/core/security/security_context.c +++ b/src/core/security/security_context.c @@ -109,6 +109,8 @@ void grpc_server_security_context_destroy(void *ctx) { /* --- grpc_auth_context --- */ +static grpc_auth_property_iterator empty_iterator = {NULL, 0, NULL}; + grpc_auth_context *grpc_auth_context_create(grpc_auth_context *chained, size_t property_count) { grpc_auth_context *ctx = gpr_malloc(sizeof(grpc_auth_context)); @@ -138,6 +140,7 @@ void grpc_auth_context_unref(grpc_auth_context *ctx) { } gpr_free(ctx->properties); } + gpr_free(ctx); } } @@ -146,19 +149,22 @@ const char *grpc_auth_context_peer_identity_property_name( return ctx->peer_identity_property_name; } -grpc_auth_property_iterator *grpc_auth_context_property_iterator( +int grpc_auth_context_peer_is_authenticated( const grpc_auth_context *ctx) { - grpc_auth_property_iterator *it; - if (ctx == NULL) return NULL; - it = gpr_malloc(sizeof(grpc_auth_property_iterator)); - memset(it, 0, sizeof(grpc_auth_property_iterator)); - it->ctx = ctx; + return ctx->peer_identity_property_name == NULL ? 0 : 1; +} + +grpc_auth_property_iterator grpc_auth_context_property_iterator( + const grpc_auth_context *ctx) { + grpc_auth_property_iterator it = empty_iterator; + if (ctx == NULL) return it; + it.ctx = ctx; return it; } const grpc_auth_property *grpc_auth_property_iterator_next( grpc_auth_property_iterator *it) { - if (it == NULL) return NULL; + if (it == NULL || it->ctx == NULL) return NULL; while (it->index == it->ctx->property_count) { if (it->ctx->chained == NULL) return NULL; it->ctx = it->ctx->chained; @@ -179,28 +185,22 @@ const grpc_auth_property *grpc_auth_property_iterator_next( } } -grpc_auth_property_iterator *grpc_auth_context_find_properties_by_name( +grpc_auth_property_iterator grpc_auth_context_find_properties_by_name( const grpc_auth_context *ctx, const char *name) { - grpc_auth_property_iterator *it; - if (ctx == NULL || name == NULL) return NULL; - it = grpc_auth_context_property_iterator(ctx); - it->name = gpr_strdup(name); + grpc_auth_property_iterator it = empty_iterator; + if (ctx == NULL || name == NULL) return empty_iterator; + it.ctx = ctx; + it.name = name; return it; } -grpc_auth_property_iterator *grpc_auth_context_peer_identity( +grpc_auth_property_iterator grpc_auth_context_peer_identity( const grpc_auth_context *ctx) { - if (ctx == NULL || ctx->peer_identity_property_name == NULL) return NULL; + if (ctx == NULL) return empty_iterator; return grpc_auth_context_find_properties_by_name( ctx, ctx->peer_identity_property_name); } -void grpc_auth_property_iterator_destroy(grpc_auth_property_iterator *it) { - if (it == NULL) return; - if (it->name != NULL) gpr_free(it->name); - gpr_free(it); -} - grpc_auth_property grpc_auth_property_init_from_cstring(const char *name, const char *value) { grpc_auth_property prop; diff --git a/src/core/security/security_context.h b/src/core/security/security_context.h index 60a3177773..d8909cd6f1 100644 --- a/src/core/security/security_context.h +++ b/src/core/security/security_context.h @@ -42,12 +42,6 @@ /* Property names are always NULL terminated. */ -struct grpc_auth_property_iterator { - const grpc_auth_context *ctx; - size_t index; - char *name; -}; - struct grpc_auth_context { struct grpc_auth_context *chained; grpc_auth_property *properties; diff --git a/src/core/security/server_auth_filter.c b/src/core/security/server_auth_filter.c index 03372328ed..1823f75808 100644 --- a/src/core/security/server_auth_filter.c +++ b/src/core/security/server_auth_filter.c @@ -77,17 +77,17 @@ static void init_call_elem(grpc_call_element *elem, /* initialize members */ calld->unused = 0; - GPR_ASSERT(initial_op && initial_op->contexts != NULL && + GPR_ASSERT(initial_op && initial_op->context != NULL && chand->security_connector->auth_context != NULL && - initial_op->contexts[GRPC_CONTEXT_SECURITY].value == NULL); + initial_op->context[GRPC_CONTEXT_SECURITY].value == NULL); /* Create a security context for the call and reference the auth context from the channel. */ server_ctx = grpc_server_security_context_create(); server_ctx->auth_context = grpc_auth_context_ref(chand->security_connector->auth_context); - initial_op->contexts[GRPC_CONTEXT_SECURITY].value = server_ctx; - initial_op->contexts[GRPC_CONTEXT_SECURITY].destroy = + initial_op->context[GRPC_CONTEXT_SECURITY].value = server_ctx; + initial_op->context[GRPC_CONTEXT_SECURITY].destroy = grpc_server_security_context_destroy; } diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 0169ce3158..db76c3a3b3 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -206,7 +206,7 @@ struct grpc_call { received_status status[STATUS_SOURCE_COUNT]; /* Contexts for various subsystems (security, tracing, ...). */ - grpc_call_context contexts[GRPC_CONTEXT_COUNT]; + grpc_call_context_element context[GRPC_CONTEXT_COUNT]; /* Deadline alarm - if have_alarm is non-zero */ grpc_alarm alarm; @@ -290,7 +290,7 @@ grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq, initial_op.recv_state = &call->recv_state; initial_op.on_done_recv = call_on_done_recv; initial_op.recv_user_data = call; - initial_op.contexts = call->contexts; + initial_op.context = call->context; call->receiving = 1; GRPC_CALL_INTERNAL_REF(call, "receiving"); initial_op_ptr = &initial_op; @@ -344,8 +344,8 @@ static void destroy_call(void *call, int ignored_success) { grpc_mdelem_unref(c->send_initial_metadata[i].md); } for (i = 0; i < GRPC_CONTEXT_COUNT; i++) { - if (c->contexts[i].destroy) { - c->contexts[i].destroy(c->contexts[i].value); + if (c->context[i].destroy) { + c->context[i].destroy(c->context[i].value); } } grpc_sopb_destroy(&c->send_ops); @@ -1048,7 +1048,7 @@ static grpc_call_error cancel_with_status( static void execute_op(grpc_call *call, grpc_transport_op *op) { grpc_call_element *elem; elem = CALL_ELEM_FROM_CALL(call, 0); - op->contexts = call->contexts; + op->context = call->context; elem->filter->start_transport_op(elem, op); } @@ -1289,15 +1289,15 @@ grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, void grpc_call_context_set(grpc_call *call, grpc_context_index elem, void *value, void (*destroy)(void *value)) { - if (call->contexts[elem].destroy) { - call->contexts[elem].destroy(call->contexts[elem].value); + if (call->context[elem].destroy) { + call->context[elem].destroy(call->context[elem].value); } - call->contexts[elem].value = value; - call->contexts[elem].destroy = destroy; + call->context[elem].value = value; + call->context[elem].destroy = destroy; } void *grpc_call_context_get(grpc_call *call, grpc_context_index elem) { - return call->contexts[elem].value; + return call->context[elem].value; } gpr_uint8 grpc_call_is_client(grpc_call *call) { return call->is_client; } diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h index dd6bee8ce9..6f8d39e352 100644 --- a/src/core/transport/transport.h +++ b/src/core/transport/transport.h @@ -79,7 +79,7 @@ typedef struct grpc_transport_op { grpc_mdstr *cancel_message; /* Indexes correspond to grpc_context_index enum values */ - grpc_call_context *contexts; + grpc_call_context_element *context; } grpc_transport_op; /* Callbacks made from the transport to the upper layers of grpc. */ |