grpc 1.30.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/etc/roots.pem +4644 -0
- data/grpc_c.32.ruby +0 -0
- data/grpc_c.64.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +34 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +107 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +64 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1050 -0
- data/src/ruby/ext/grpc/rb_call.h +53 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +297 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +835 -0
- data/src/ruby/ext/grpc/rb_channel.h +34 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +267 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +32 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +100 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +143 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
- data/src/ruby/ext/grpc/rb_grpc.c +328 -0
- data/src/ruby/ext/grpc/rb_grpc.h +76 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +573 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +865 -0
- data/src/ruby/ext/grpc/rb_loader.c +57 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +372 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +243 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +32 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.5/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +501 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +44 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +51 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +105 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +118 -0
- data/src/ruby/pb/test/client.rb +769 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +213 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +180 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +82 -0
- data/src/ruby/spec/channel_spec.rb +234 -0
- data/src/ruby/spec/client_auth_spec.rb +126 -0
- data/src/ruby/spec/client_server_spec.rb +664 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +672 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +82 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +79 -0
- data/src/ruby/spec/server_spec.rb +209 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +160 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- metadata +394 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_RB_CHANNEL_H_
|
20
|
+
#define GRPC_RB_CHANNEL_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
|
26
|
+
/* Initializes the Channel class. */
|
27
|
+
void Init_grpc_channel();
|
28
|
+
|
29
|
+
void grpc_rb_channel_polling_thread_start();
|
30
|
+
|
31
|
+
/* Gets the wrapped channel from the ruby wrapper */
|
32
|
+
grpc_channel* grpc_rb_get_wrapped_channel(VALUE v);
|
33
|
+
|
34
|
+
#endif /* GRPC_RB_CHANNEL_H_ */
|
@@ -0,0 +1,155 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include "rb_channel_args.h"
|
22
|
+
#include "rb_grpc_imports.generated.h"
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
|
26
|
+
#include "rb_grpc.h"
|
27
|
+
|
28
|
+
static rb_data_type_t grpc_rb_channel_args_data_type = {
|
29
|
+
"grpc_channel_args",
|
30
|
+
{GRPC_RB_GC_NOT_MARKED,
|
31
|
+
GRPC_RB_GC_DONT_FREE,
|
32
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE,
|
33
|
+
{NULL, NULL}},
|
34
|
+
NULL,
|
35
|
+
NULL,
|
36
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
37
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
38
|
+
#endif
|
39
|
+
};
|
40
|
+
|
41
|
+
/* A callback the processes the hash key values in channel_args hash */
|
42
|
+
static int grpc_rb_channel_create_in_process_add_args_hash_cb(VALUE key,
|
43
|
+
VALUE val,
|
44
|
+
VALUE args_obj) {
|
45
|
+
const char* the_key;
|
46
|
+
grpc_channel_args* args;
|
47
|
+
|
48
|
+
switch (TYPE(key)) {
|
49
|
+
case T_STRING:
|
50
|
+
the_key = StringValuePtr(key);
|
51
|
+
break;
|
52
|
+
|
53
|
+
case T_SYMBOL:
|
54
|
+
the_key = rb_id2name(SYM2ID(key));
|
55
|
+
break;
|
56
|
+
|
57
|
+
default:
|
58
|
+
rb_raise(rb_eTypeError, "bad chan arg: got <%s>, want <String|Symbol>",
|
59
|
+
rb_obj_classname(key));
|
60
|
+
return ST_STOP;
|
61
|
+
}
|
62
|
+
|
63
|
+
TypedData_Get_Struct(args_obj, grpc_channel_args,
|
64
|
+
&grpc_rb_channel_args_data_type, args);
|
65
|
+
if (args->num_args <= 0) {
|
66
|
+
rb_raise(rb_eRuntimeError, "hash_cb bug: num_args is %lu for key:%s",
|
67
|
+
args->num_args, StringValueCStr(key));
|
68
|
+
return ST_STOP;
|
69
|
+
}
|
70
|
+
|
71
|
+
args->args[args->num_args - 1].key = (char*)the_key;
|
72
|
+
switch (TYPE(val)) {
|
73
|
+
case T_SYMBOL:
|
74
|
+
args->args[args->num_args - 1].type = GRPC_ARG_STRING;
|
75
|
+
args->args[args->num_args - 1].value.string =
|
76
|
+
(char*)rb_id2name(SYM2ID(val));
|
77
|
+
--args->num_args;
|
78
|
+
return ST_CONTINUE;
|
79
|
+
|
80
|
+
case T_STRING:
|
81
|
+
args->args[args->num_args - 1].type = GRPC_ARG_STRING;
|
82
|
+
args->args[args->num_args - 1].value.string = StringValueCStr(val);
|
83
|
+
--args->num_args;
|
84
|
+
return ST_CONTINUE;
|
85
|
+
|
86
|
+
case T_FIXNUM:
|
87
|
+
args->args[args->num_args - 1].type = GRPC_ARG_INTEGER;
|
88
|
+
args->args[args->num_args - 1].value.integer = NUM2INT(val);
|
89
|
+
--args->num_args;
|
90
|
+
return ST_CONTINUE;
|
91
|
+
|
92
|
+
default:
|
93
|
+
rb_raise(rb_eTypeError, "%s: bad value: got <%s>, want <String|Fixnum>",
|
94
|
+
StringValueCStr(key), rb_obj_classname(val));
|
95
|
+
return ST_STOP;
|
96
|
+
}
|
97
|
+
rb_raise(rb_eRuntimeError, "impl bug: hash_cb reached to far while on key:%s",
|
98
|
+
StringValueCStr(key));
|
99
|
+
return ST_STOP;
|
100
|
+
}
|
101
|
+
|
102
|
+
/* channel_convert_params allows the call to
|
103
|
+
grpc_rb_hash_convert_to_channel_args to be made within an rb_protect
|
104
|
+
exception-handler. This allows any allocated memory to be freed before
|
105
|
+
propagating any exception that occurs */
|
106
|
+
typedef struct channel_convert_params {
|
107
|
+
VALUE src_hash;
|
108
|
+
grpc_channel_args* dst;
|
109
|
+
} channel_convert_params;
|
110
|
+
|
111
|
+
static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
|
112
|
+
ID id_size = rb_intern("size");
|
113
|
+
VALUE grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
|
114
|
+
channel_convert_params* params = (channel_convert_params*)as_value;
|
115
|
+
size_t num_args = 0;
|
116
|
+
|
117
|
+
if (!NIL_P(params->src_hash) && TYPE(params->src_hash) != T_HASH) {
|
118
|
+
rb_raise(rb_eTypeError, "bad channel args: got:<%s> want: a hash or nil",
|
119
|
+
rb_obj_classname(params->src_hash));
|
120
|
+
return Qnil;
|
121
|
+
}
|
122
|
+
|
123
|
+
if (TYPE(params->src_hash) == T_HASH) {
|
124
|
+
num_args = NUM2INT(rb_funcall(params->src_hash, id_size, 0));
|
125
|
+
params->dst->num_args = num_args;
|
126
|
+
params->dst->args = ALLOC_N(grpc_arg, num_args);
|
127
|
+
MEMZERO(params->dst->args, grpc_arg, num_args);
|
128
|
+
rb_hash_foreach(
|
129
|
+
params->src_hash, grpc_rb_channel_create_in_process_add_args_hash_cb,
|
130
|
+
TypedData_Wrap_Struct(grpc_rb_cChannelArgs,
|
131
|
+
&grpc_rb_channel_args_data_type, params->dst));
|
132
|
+
/* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb
|
133
|
+
* decrements it during has processing */
|
134
|
+
params->dst->num_args = num_args;
|
135
|
+
}
|
136
|
+
return Qnil;
|
137
|
+
}
|
138
|
+
|
139
|
+
void grpc_rb_hash_convert_to_channel_args(VALUE src_hash,
|
140
|
+
grpc_channel_args* dst) {
|
141
|
+
channel_convert_params params;
|
142
|
+
int status = 0;
|
143
|
+
|
144
|
+
/* Make a protected call to grpc_rb_hash_convert_channel_args */
|
145
|
+
params.src_hash = src_hash;
|
146
|
+
params.dst = dst;
|
147
|
+
rb_protect(grpc_rb_hash_convert_to_channel_args0, (VALUE)¶ms, &status);
|
148
|
+
if (status != 0) {
|
149
|
+
if (dst->args != NULL) {
|
150
|
+
/* Free any allocated memory before propagating the error */
|
151
|
+
xfree(dst->args);
|
152
|
+
}
|
153
|
+
rb_jump_tag(status);
|
154
|
+
}
|
155
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_RB_CHANNEL_ARGS_H_
|
20
|
+
#define GRPC_RB_CHANNEL_ARGS_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
|
26
|
+
/* Converts a hash object containing channel args to a channel args instance.
|
27
|
+
*
|
28
|
+
* This func ALLOCs args->args. The caller is responsible for freeing it. If
|
29
|
+
* a ruby error is raised during processing of the hash values, the func takes
|
30
|
+
* care to deallocate any memory allocated so far, and propagate the error.
|
31
|
+
*
|
32
|
+
* @param src_hash A ruby hash
|
33
|
+
* @param dst the grpc_channel_args that the hash entries will be added to.
|
34
|
+
*/
|
35
|
+
void grpc_rb_hash_convert_to_channel_args(VALUE src_hash,
|
36
|
+
grpc_channel_args* dst);
|
37
|
+
|
38
|
+
#endif /* GRPC_RB_CHANNEL_ARGS_H_ */
|
@@ -0,0 +1,267 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include <string.h>
|
22
|
+
|
23
|
+
#include "rb_channel_credentials.h"
|
24
|
+
#include "rb_grpc_imports.generated.h"
|
25
|
+
|
26
|
+
#include <grpc/grpc.h>
|
27
|
+
#include <grpc/grpc_security.h>
|
28
|
+
#include <grpc/support/alloc.h>
|
29
|
+
#include <grpc/support/log.h>
|
30
|
+
|
31
|
+
#include "rb_call_credentials.h"
|
32
|
+
#include "rb_grpc.h"
|
33
|
+
|
34
|
+
/* grpc_rb_cChannelCredentials is the ruby class that proxies
|
35
|
+
grpc_channel_credentials. */
|
36
|
+
static VALUE grpc_rb_cChannelCredentials = Qnil;
|
37
|
+
|
38
|
+
static char* pem_root_certs = NULL;
|
39
|
+
|
40
|
+
/* grpc_rb_channel_credentials wraps a grpc_channel_credentials. It provides a
|
41
|
+
* mark object that is used to hold references to any objects used to create
|
42
|
+
* the credentials. */
|
43
|
+
typedef struct grpc_rb_channel_credentials {
|
44
|
+
/* Holder of ruby objects involved in constructing the credentials */
|
45
|
+
VALUE mark;
|
46
|
+
|
47
|
+
/* The actual credentials */
|
48
|
+
grpc_channel_credentials* wrapped;
|
49
|
+
} grpc_rb_channel_credentials;
|
50
|
+
|
51
|
+
static void grpc_rb_channel_credentials_free_internal(void* p) {
|
52
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
53
|
+
if (p == NULL) {
|
54
|
+
return;
|
55
|
+
};
|
56
|
+
wrapper = (grpc_rb_channel_credentials*)p;
|
57
|
+
grpc_channel_credentials_release(wrapper->wrapped);
|
58
|
+
wrapper->wrapped = NULL;
|
59
|
+
|
60
|
+
xfree(p);
|
61
|
+
}
|
62
|
+
|
63
|
+
/* Destroys the credentials instances. */
|
64
|
+
static void grpc_rb_channel_credentials_free(void* p) {
|
65
|
+
grpc_rb_channel_credentials_free_internal(p);
|
66
|
+
grpc_ruby_shutdown();
|
67
|
+
}
|
68
|
+
|
69
|
+
/* Protects the mark object from GC */
|
70
|
+
static void grpc_rb_channel_credentials_mark(void* p) {
|
71
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
72
|
+
if (p == NULL) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
wrapper = (grpc_rb_channel_credentials*)p;
|
76
|
+
|
77
|
+
if (wrapper->mark != Qnil) {
|
78
|
+
rb_gc_mark(wrapper->mark);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
static rb_data_type_t grpc_rb_channel_credentials_data_type = {
|
83
|
+
"grpc_channel_credentials",
|
84
|
+
{grpc_rb_channel_credentials_mark,
|
85
|
+
grpc_rb_channel_credentials_free,
|
86
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE,
|
87
|
+
{NULL, NULL}},
|
88
|
+
NULL,
|
89
|
+
NULL,
|
90
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
91
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
92
|
+
#endif
|
93
|
+
};
|
94
|
+
|
95
|
+
/* Allocates ChannelCredential instances.
|
96
|
+
Provides safe initial defaults for the instance fields. */
|
97
|
+
static VALUE grpc_rb_channel_credentials_alloc(VALUE cls) {
|
98
|
+
grpc_ruby_init();
|
99
|
+
grpc_rb_channel_credentials* wrapper = ALLOC(grpc_rb_channel_credentials);
|
100
|
+
wrapper->wrapped = NULL;
|
101
|
+
wrapper->mark = Qnil;
|
102
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_channel_credentials_data_type,
|
103
|
+
wrapper);
|
104
|
+
}
|
105
|
+
|
106
|
+
/* Creates a wrapping object for a given channel credentials. This should only
|
107
|
+
* be called with grpc_channel_credentials objects that are not already
|
108
|
+
* associated with any Ruby object. */
|
109
|
+
VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials* c,
|
110
|
+
VALUE mark) {
|
111
|
+
VALUE rb_wrapper;
|
112
|
+
grpc_rb_channel_credentials* wrapper;
|
113
|
+
if (c == NULL) {
|
114
|
+
return Qnil;
|
115
|
+
}
|
116
|
+
rb_wrapper = grpc_rb_channel_credentials_alloc(grpc_rb_cChannelCredentials);
|
117
|
+
TypedData_Get_Struct(rb_wrapper, grpc_rb_channel_credentials,
|
118
|
+
&grpc_rb_channel_credentials_data_type, wrapper);
|
119
|
+
wrapper->wrapped = c;
|
120
|
+
wrapper->mark = mark;
|
121
|
+
return rb_wrapper;
|
122
|
+
}
|
123
|
+
|
124
|
+
/* The attribute used on the mark object to hold the pem_root_certs. */
|
125
|
+
static ID id_pem_root_certs;
|
126
|
+
|
127
|
+
/* The attribute used on the mark object to hold the pem_private_key. */
|
128
|
+
static ID id_pem_private_key;
|
129
|
+
|
130
|
+
/* The attribute used on the mark object to hold the pem_private_key. */
|
131
|
+
static ID id_pem_cert_chain;
|
132
|
+
|
133
|
+
/*
|
134
|
+
call-seq:
|
135
|
+
creds1 = Credentials.new()
|
136
|
+
...
|
137
|
+
creds2 = Credentials.new(pem_root_certs)
|
138
|
+
...
|
139
|
+
creds3 = Credentials.new(pem_root_certs, pem_private_key,
|
140
|
+
pem_cert_chain)
|
141
|
+
pem_root_certs: (optional) PEM encoding of the server root certificate
|
142
|
+
pem_private_key: (optional) PEM encoding of the client's private key
|
143
|
+
pem_cert_chain: (optional) PEM encoding of the client's cert chain
|
144
|
+
Initializes Credential instances. */
|
145
|
+
static VALUE grpc_rb_channel_credentials_init(int argc, VALUE* argv,
|
146
|
+
VALUE self) {
|
147
|
+
VALUE pem_root_certs = Qnil;
|
148
|
+
VALUE pem_private_key = Qnil;
|
149
|
+
VALUE pem_cert_chain = Qnil;
|
150
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
151
|
+
grpc_channel_credentials* creds = NULL;
|
152
|
+
grpc_ssl_pem_key_cert_pair key_cert_pair;
|
153
|
+
const char* pem_root_certs_cstr = NULL;
|
154
|
+
MEMZERO(&key_cert_pair, grpc_ssl_pem_key_cert_pair, 1);
|
155
|
+
|
156
|
+
/* "03" == no mandatory arg, 3 optional */
|
157
|
+
rb_scan_args(argc, argv, "03", &pem_root_certs, &pem_private_key,
|
158
|
+
&pem_cert_chain);
|
159
|
+
|
160
|
+
TypedData_Get_Struct(self, grpc_rb_channel_credentials,
|
161
|
+
&grpc_rb_channel_credentials_data_type, wrapper);
|
162
|
+
if (pem_root_certs != Qnil) {
|
163
|
+
pem_root_certs_cstr = RSTRING_PTR(pem_root_certs);
|
164
|
+
}
|
165
|
+
if (pem_private_key == Qnil && pem_cert_chain == Qnil) {
|
166
|
+
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, NULL, NULL, NULL);
|
167
|
+
} else {
|
168
|
+
key_cert_pair.private_key = RSTRING_PTR(pem_private_key);
|
169
|
+
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain);
|
170
|
+
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, &key_cert_pair,
|
171
|
+
NULL, NULL);
|
172
|
+
}
|
173
|
+
if (creds == NULL) {
|
174
|
+
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");
|
175
|
+
return Qnil;
|
176
|
+
}
|
177
|
+
wrapper->wrapped = creds;
|
178
|
+
|
179
|
+
/* Add the input objects as hidden fields to preserve them. */
|
180
|
+
rb_ivar_set(self, id_pem_cert_chain, pem_cert_chain);
|
181
|
+
rb_ivar_set(self, id_pem_private_key, pem_private_key);
|
182
|
+
rb_ivar_set(self, id_pem_root_certs, pem_root_certs);
|
183
|
+
|
184
|
+
return self;
|
185
|
+
}
|
186
|
+
|
187
|
+
static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE* argv,
|
188
|
+
VALUE self) {
|
189
|
+
grpc_channel_credentials* creds;
|
190
|
+
grpc_call_credentials* other;
|
191
|
+
grpc_channel_credentials* prev = NULL;
|
192
|
+
VALUE mark;
|
193
|
+
if (argc == 0) {
|
194
|
+
return self;
|
195
|
+
}
|
196
|
+
mark = rb_ary_new();
|
197
|
+
rb_ary_push(mark, self);
|
198
|
+
creds = grpc_rb_get_wrapped_channel_credentials(self);
|
199
|
+
for (int i = 0; i < argc; i++) {
|
200
|
+
rb_ary_push(mark, argv[i]);
|
201
|
+
other = grpc_rb_get_wrapped_call_credentials(argv[i]);
|
202
|
+
creds = grpc_composite_channel_credentials_create(creds, other, NULL);
|
203
|
+
if (prev != NULL) {
|
204
|
+
grpc_channel_credentials_release(prev);
|
205
|
+
}
|
206
|
+
prev = creds;
|
207
|
+
|
208
|
+
if (creds == NULL) {
|
209
|
+
rb_raise(rb_eRuntimeError,
|
210
|
+
"Failed to compose channel and call credentials");
|
211
|
+
}
|
212
|
+
}
|
213
|
+
return grpc_rb_wrap_channel_credentials(creds, mark);
|
214
|
+
}
|
215
|
+
|
216
|
+
static grpc_ssl_roots_override_result get_ssl_roots_override(
|
217
|
+
char** pem_root_certs_ptr) {
|
218
|
+
*pem_root_certs_ptr = pem_root_certs;
|
219
|
+
if (pem_root_certs == NULL) {
|
220
|
+
return GRPC_SSL_ROOTS_OVERRIDE_FAIL;
|
221
|
+
} else {
|
222
|
+
return GRPC_SSL_ROOTS_OVERRIDE_OK;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
static VALUE grpc_rb_set_default_roots_pem(VALUE self, VALUE roots) {
|
227
|
+
char* roots_ptr = StringValueCStr(roots);
|
228
|
+
size_t length = strlen(roots_ptr);
|
229
|
+
(void)self;
|
230
|
+
pem_root_certs = gpr_malloc((length + 1) * sizeof(char));
|
231
|
+
memcpy(pem_root_certs, roots_ptr, length + 1);
|
232
|
+
return Qnil;
|
233
|
+
}
|
234
|
+
|
235
|
+
void Init_grpc_channel_credentials() {
|
236
|
+
grpc_rb_cChannelCredentials = rb_define_class_under(
|
237
|
+
grpc_rb_mGrpcCore, "ChannelCredentials", rb_cObject);
|
238
|
+
|
239
|
+
/* Allocates an object managed by the ruby runtime */
|
240
|
+
rb_define_alloc_func(grpc_rb_cChannelCredentials,
|
241
|
+
grpc_rb_channel_credentials_alloc);
|
242
|
+
|
243
|
+
/* Provides a ruby constructor and support for dup/clone. */
|
244
|
+
rb_define_method(grpc_rb_cChannelCredentials, "initialize",
|
245
|
+
grpc_rb_channel_credentials_init, -1);
|
246
|
+
rb_define_method(grpc_rb_cChannelCredentials, "initialize_copy",
|
247
|
+
grpc_rb_cannot_init_copy, 1);
|
248
|
+
rb_define_method(grpc_rb_cChannelCredentials, "compose",
|
249
|
+
grpc_rb_channel_credentials_compose, -1);
|
250
|
+
rb_define_module_function(grpc_rb_cChannelCredentials,
|
251
|
+
"set_default_roots_pem",
|
252
|
+
grpc_rb_set_default_roots_pem, 1);
|
253
|
+
|
254
|
+
grpc_set_ssl_roots_override_callback(get_ssl_roots_override);
|
255
|
+
|
256
|
+
id_pem_cert_chain = rb_intern("__pem_cert_chain");
|
257
|
+
id_pem_private_key = rb_intern("__pem_private_key");
|
258
|
+
id_pem_root_certs = rb_intern("__pem_root_certs");
|
259
|
+
}
|
260
|
+
|
261
|
+
/* Gets the wrapped grpc_channel_credentials from the ruby wrapper */
|
262
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_channel_credentials(VALUE v) {
|
263
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
264
|
+
TypedData_Get_Struct(v, grpc_rb_channel_credentials,
|
265
|
+
&grpc_rb_channel_credentials_data_type, wrapper);
|
266
|
+
return wrapper->wrapped;
|
267
|
+
}
|