diff options
author | murgatroid99 <mlumish@google.com> | 2015-12-04 14:36:27 -0800 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2015-12-04 14:36:27 -0800 |
commit | 9946f2b80a9dcc01fece8b9ddae4c80a77647b9d (patch) | |
tree | 559ffa1181daf6e89885a42dc083f3a5f3b4d88a /src/ruby/ext/grpc/rb_channel_credentials.c | |
parent | 873d04bc3dfcfc8c5719210e05e5284436002d9c (diff) |
Add CallCredentials class to Ruby wrapping code
Diffstat (limited to 'src/ruby/ext/grpc/rb_channel_credentials.c')
-rw-r--r-- | src/ruby/ext/grpc/rb_channel_credentials.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ruby/ext/grpc/rb_channel_credentials.c b/src/ruby/ext/grpc/rb_channel_credentials.c index 072a6f54ab..c8837942a7 100644 --- a/src/ruby/ext/grpc/rb_channel_credentials.c +++ b/src/ruby/ext/grpc/rb_channel_credentials.c @@ -38,6 +38,7 @@ #include <grpc/grpc.h> #include <grpc/grpc_security.h> +#include "rb_call_credentials.h" #include "rb_grpc.h" /* grpc_rb_cChannelCredentials is the ruby class that proxies @@ -98,6 +99,17 @@ static rb_data_type_t grpc_rb_channel_credentials_data_type = { #endif }; +/* Creates a wrapping object for a given channel credentials. This should only + * be called with grpc_channel_credentials objects that are not already + * associated with any Ruby object. */ +VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c) { + if (c == NULL) { + return Qnil; + } + return TypedData_Wrap_Struct(grpc_rb_cChannelCredentials, + &grpc_rb_channel_credentials_data_type, c); +} + /* Allocates ChannelCredential instances. Provides safe initial defaults for the instance fields. */ static VALUE grpc_rb_channel_credentials_alloc(VALUE cls) { @@ -199,6 +211,21 @@ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE *argv, VALUE self) return self; } +static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE *argv, + VALUE self) { + grpc_channel_credentials *creds; + grpc_call_credentials *other; + if (argc == 0) { + return self; + } + creds = grpc_rb_get_wrapped_channel_credentials(self); + for (int i = 0; i < argc; i++) { + other = grpc_rb_get_wrapped_call_credentials(argv[i]); + creds = grpc_composite_channel_credentials_create(creds, other, NULL); + } + return grpc_rb_wrap_channel_credentials(creds); +} + void Init_grpc_channel_credentials() { grpc_rb_cChannelCredentials = rb_define_class_under(grpc_rb_mGrpcCore, "ChannelCredentials", rb_cObject); @@ -212,6 +239,8 @@ void Init_grpc_channel_credentials() { grpc_rb_channel_credentials_init, -1); rb_define_method(grpc_rb_cChannelCredentials, "initialize_copy", grpc_rb_channel_credentials_init_copy, 1); + rb_define_method(grpc_rb_cChannelCredentials, "compose", + grpc_rb_channel_credentials_compose, -1); id_pem_cert_chain = rb_intern("__pem_cert_chain"); id_pem_private_key = rb_intern("__pem_private_key"); |