rb_xds_server_credentials.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2021 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 
22 
23 #include "rb_grpc.h"
25 #include "rb_server_credentials.h"
26 
27 #include <grpc/grpc.h>
28 #include <grpc/grpc_security.h>
29 #include <grpc/support/log.h>
30 
31 /* grpc_rb_cXdsServerCredentials is the ruby class that proxies
32  grpc_server_credentials. */
33 static VALUE grpc_rb_cXdsServerCredentials = Qnil;
34 
35 /* grpc_rb_xds_server_credentials wraps a grpc_server_credentials. It provides
36  a peer ruby object, 'mark' to hold references to objects involved in
37  constructing the server credentials. */
39  /* Holder of ruby objects involved in constructing the server credentials */
40  VALUE mark;
41  /* The actual server credentials */
44 
45 /* Destroys the server credentials instances. */
48  if (p == NULL) {
49  return;
50  };
52 
53  /* Delete the wrapped object if the mark object is Qnil, which indicates that
54  no other object is the actual owner. */
55  if (wrapper->wrapped != NULL && wrapper->mark == Qnil) {
57  wrapper->wrapped = NULL;
58  }
59 
60  xfree(p);
61 }
62 
63 /* Destroys the server credentials instances. */
67 }
68 
69 /* Protects the mark object from GC */
71  if (p == NULL) {
72  return;
73  }
75 
76  /* If it's not already cleaned up, mark the mark object */
77  if (wrapper->mark != Qnil) {
78  rb_gc_mark(wrapper->mark);
79  }
80 }
81 
82 static const rb_data_type_t grpc_rb_xds_server_credentials_data_type = {
83  "grpc_xds_server_credentials",
86  NULL,
87  NULL,
88 #ifdef RUBY_TYPED_FREE_IMMEDIATELY
89  RUBY_TYPED_FREE_IMMEDIATELY
90 #endif
91 };
92 
93 /* Allocates ServerCredential instances.
94  Provides safe initial defaults for the instance fields. */
95 static VALUE grpc_rb_xds_server_credentials_alloc(VALUE cls) {
99  wrapper->wrapped = NULL;
100  wrapper->mark = Qnil;
101  return TypedData_Wrap_Struct(cls, &grpc_rb_xds_server_credentials_data_type,
102  wrapper);
103 }
104 
105 /* The attribute used on the mark object to preserve the fallback_creds. */
107 
108 /*
109  call-seq:
110  creds = ServerCredentials.new(fallback_creds)
111  fallback_creds: (ServerCredentials) fallback credentials to create
112  XDS credentials.
113  Initializes ServerCredential instances. */
114 static VALUE grpc_rb_xds_server_credentials_init(VALUE self,
115  VALUE fallback_creds) {
117  grpc_server_credentials* creds = NULL;
118 
119  grpc_server_credentials* grpc_fallback_creds =
121  creds = grpc_xds_server_credentials_create(grpc_fallback_creds);
122 
123  if (creds == NULL) {
124  rb_raise(rb_eRuntimeError,
125  "the call to grpc_xds_server_credentials_create() failed, could "
126  "not create a credentials, see "
127  "https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
128  "debugging tips");
129  return Qnil;
130  }
131  TypedData_Get_Struct(self, grpc_rb_xds_server_credentials,
133  wrapper->wrapped = creds;
134 
135  /* Add the input objects as hidden fields to preserve them. */
136  rb_ivar_set(self, id_fallback_creds, fallback_creds);
137 
138  return self;
139 }
140 
142  grpc_rb_cXdsServerCredentials = rb_define_class_under(
143  grpc_rb_mGrpcCore, "XdsServerCredentials", rb_cObject);
144 
145  /* Allocates an object managed by the ruby runtime */
146  rb_define_alloc_func(grpc_rb_cXdsServerCredentials,
148 
149  /* Provides a ruby constructor and support for dup/clone. */
150  rb_define_method(grpc_rb_cXdsServerCredentials, "initialize",
152  rb_define_method(grpc_rb_cXdsServerCredentials, "initialize_copy",
154 
155  id_fallback_creds = rb_intern("__fallback_creds");
156 }
157 
158 /* Gets the wrapped grpc_server_credentials from the ruby wrapper */
161  Check_TypedStruct(v, &grpc_rb_xds_server_credentials_data_type);
162  TypedData_Get_Struct(v, grpc_rb_xds_server_credentials,
164  return wrapper->wrapped;
165 }
166 
167 /* Check if v is kind of ServerCredentials */
169  return rb_typeddata_is_kind_of(v, &grpc_rb_xds_server_credentials_data_type);
170 }
rb_xds_server_credentials.h
log.h
rb_grpc_imports.generated.h
GRPC_RB_MEMSIZE_UNAVAILABLE
#define GRPC_RB_MEMSIZE_UNAVAILABLE
Definition: rb_grpc.h:57
grpc_ruby_shutdown
void grpc_ruby_shutdown()
Definition: rb_grpc.c:296
grpc_rb_cXdsServerCredentials
static VALUE grpc_rb_cXdsServerCredentials
Definition: rb_xds_server_credentials.c:33
grpc_rb_xds_server_credentials_free
static void grpc_rb_xds_server_credentials_free(void *p)
Definition: rb_xds_server_credentials.c:64
grpc_rb_xds_server_credentials_alloc
static VALUE grpc_rb_xds_server_credentials_alloc(VALUE cls)
Definition: rb_xds_server_credentials.c:95
xds_manager.p
p
Definition: xds_manager.py:60
grpc_security.h
_grpc_channel_wrapper::wrapped
grpc_channel * wrapped
Definition: src/php/ext/grpc/channel.h:35
grpc_server_credentials_release
GRPCAPI void grpc_server_credentials_release(grpc_server_credentials *creds)
Definition: credentials.cc:95
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
grpc.h
grpc_rb_xds_server_credentials_data_type
static const rb_data_type_t grpc_rb_xds_server_credentials_data_type
Definition: rb_xds_server_credentials.c:82
grpc_rb_get_wrapped_xds_server_credentials
grpc_server_credentials * grpc_rb_get_wrapped_xds_server_credentials(VALUE v)
Definition: rb_xds_server_credentials.c:159
wrapper
grpc_channel_wrapper * wrapper
Definition: src/php/ext/grpc/channel.h:48
grpc_rb_xds_server_credentials_mark
static void grpc_rb_xds_server_credentials_mark(void *p)
Definition: rb_xds_server_credentials.c:70
rb_server_credentials.h
id_fallback_creds
static ID id_fallback_creds
Definition: rb_xds_server_credentials.c:106
grpc_server_credentials
Definition: src/core/lib/security/credentials/credentials.h:259
rb_grpc.h
grpc_rb_mGrpcCore
VALUE grpc_rb_mGrpcCore
Definition: rb_grpc.c:252
grpc_rb_xds_server_credentials
struct grpc_rb_xds_server_credentials grpc_rb_xds_server_credentials
grpc_rb_xds_server_credentials::mark
VALUE mark
Definition: rb_xds_server_credentials.c:40
ALLOC
#define ALLOC(class_name)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1486
grpc_rb_xds_server_credentials
Definition: rb_xds_server_credentials.c:38
grpc_rb_cannot_init_copy
VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self)
Definition: rb_grpc.c:80
grpc_rb_xds_server_credentials_init
static VALUE grpc_rb_xds_server_credentials_init(VALUE self, VALUE fallback_creds)
Definition: rb_xds_server_credentials.c:114
Init_grpc_xds_server_credentials
void Init_grpc_xds_server_credentials()
Definition: rb_xds_server_credentials.c:141
grpc_rb_xds_server_credentials_free_internal
static void grpc_rb_xds_server_credentials_free_internal(void *p)
Definition: rb_xds_server_credentials.c:46
grpc_rb_get_wrapped_server_credentials
grpc_server_credentials * grpc_rb_get_wrapped_server_credentials(VALUE v)
Definition: rb_server_credentials.c:248
grpc_xds_server_credentials_create
GRPCAPI grpc_server_credentials * grpc_xds_server_credentials_create(grpc_server_credentials *fallback_credentials)
Definition: core/lib/security/credentials/xds/xds_credentials.cc:249
grpc_rb_is_xds_server_credentials
bool grpc_rb_is_xds_server_credentials(VALUE v)
Definition: rb_xds_server_credentials.c:168
grpc_rb_xds_server_credentials::wrapped
grpc_server_credentials * wrapped
Definition: rb_xds_server_credentials.c:42
grpc_ruby_init
void grpc_ruby_init()
Definition: rb_grpc.c:286


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:59