Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
a87924e6
Commit
a87924e6
authored
10 years ago
by
Yuki Yugui Sonoda
Browse files
Options
Downloads
Patches
Plain Diff
Use TypedData for GRPC::Core::Credentials
parent
bf256ae0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ruby/ext/grpc/rb_credentials.c
+29
-18
29 additions, 18 deletions
src/ruby/ext/grpc/rb_credentials.c
with
29 additions
and
18 deletions
src/ruby/ext/grpc/rb_credentials.c
+
29
−
18
View file @
a87924e6
...
...
@@ -83,14 +83,21 @@ static void grpc_rb_credentials_mark(void *p) {
}
}
static
rb_data_type_t
grpc_rb_credentials_data_type
=
{
"grpc_credentials"
,
{
grpc_rb_credentials_mark
,
grpc_rb_credentials_free
,
GRPC_RB_MEMSIZE_UNAVAILABLE
},
NULL
,
NULL
,
RUBY_TYPED_FREE_IMMEDIATELY
};
/* Allocates Credential instances.
Provides safe initial defaults for the instance fields. */
static
VALUE
grpc_rb_credentials_alloc
(
VALUE
cls
)
{
grpc_rb_credentials
*
wrapper
=
ALLOC
(
grpc_rb_credentials
);
wrapper
->
wrapped
=
NULL
;
wrapper
->
mark
=
Qnil
;
return
Data_Wrap_Struct
(
cls
,
grpc_rb_credentials_mark
,
grpc_rb_credentials_free
,
wrapper
);
return
TypedData_Wrap_Struct
(
cls
,
&
grpc_rb_credentials_data_type
,
wrapper
);
}
/* Clones Credentials instances.
...
...
@@ -110,8 +117,10 @@ static VALUE grpc_rb_credentials_init_copy(VALUE copy, VALUE orig) {
rb_raise
(
rb_eTypeError
,
"not a %s"
,
rb_obj_classname
(
grpc_rb_cCredentials
));
}
Data_Get_Struct
(
orig
,
grpc_rb_credentials
,
orig_cred
);
Data_Get_Struct
(
copy
,
grpc_rb_credentials
,
copy_cred
);
TypedData_Get_Struct
(
orig
,
grpc_rb_credentials
,
&
grpc_rb_credentials_data_type
,
orig_cred
);
TypedData_Get_Struct
(
copy
,
grpc_rb_credentials
,
&
grpc_rb_credentials_data_type
,
copy_cred
);
/* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
* wrapper object. */
...
...
@@ -133,8 +142,7 @@ static VALUE grpc_rb_default_credentials_create(VALUE cls) {
}
wrapper
->
mark
=
Qnil
;
return
Data_Wrap_Struct
(
cls
,
grpc_rb_credentials_mark
,
grpc_rb_credentials_free
,
wrapper
);
return
TypedData_Wrap_Struct
(
cls
,
&
grpc_rb_credentials_data_type
,
wrapper
);
}
/*
...
...
@@ -151,8 +159,7 @@ static VALUE grpc_rb_compute_engine_credentials_create(VALUE cls) {
}
wrapper
->
mark
=
Qnil
;
return
Data_Wrap_Struct
(
cls
,
grpc_rb_credentials_mark
,
grpc_rb_credentials_free
,
wrapper
);
return
TypedData_Wrap_Struct
(
cls
,
&
grpc_rb_credentials_data_type
,
wrapper
);
}
/*
...
...
@@ -166,8 +173,10 @@ static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) {
grpc_rb_credentials
*
other_wrapper
=
NULL
;
grpc_rb_credentials
*
wrapper
=
NULL
;
Data_Get_Struct
(
self
,
grpc_rb_credentials
,
self_wrapper
);
Data_Get_Struct
(
other
,
grpc_rb_credentials
,
other_wrapper
);
TypedData_Get_Struct
(
self
,
grpc_rb_credentials
,
&
grpc_rb_credentials_data_type
,
self_wrapper
);
TypedData_Get_Struct
(
other
,
grpc_rb_credentials
,
&
grpc_rb_credentials_data_type
,
other_wrapper
);
wrapper
=
ALLOC
(
grpc_rb_credentials
);
wrapper
->
wrapped
=
grpc_composite_credentials_create
(
self_wrapper
->
wrapped
,
other_wrapper
->
wrapped
);
...
...
@@ -178,8 +187,8 @@ static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) {
}
wrapper
->
mark
=
Qnil
;
return
Data_Wrap_Struct
(
grpc_rb_cCredentials
,
grpc_rb_credentials_mark
,
grpc_rb_credentials_
fre
e
,
wrapper
);
return
Typed
Data_Wrap_Struct
(
grpc_rb_cCredentials
,
&
grpc_rb_credentials_
data_typ
e
,
wrapper
);
}
/* The attribute used on the mark object to hold the pem_root_certs. */
...
...
@@ -214,7 +223,8 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
rb_scan_args
(
argc
,
argv
,
"12"
,
&
pem_root_certs
,
&
pem_private_key
,
&
pem_cert_chain
);
Data_Get_Struct
(
self
,
grpc_rb_credentials
,
wrapper
);
TypedData_Get_Struct
(
self
,
grpc_rb_credentials
,
&
grpc_rb_credentials_data_type
,
wrapper
);
if
(
pem_root_certs
==
Qnil
)
{
rb_raise
(
rb_eRuntimeError
,
"could not create a credential: nil pem_root_certs"
);
...
...
@@ -225,8 +235,8 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
}
else
{
key_cert_pair
.
private_key
=
RSTRING_PTR
(
pem_private_key
);
key_cert_pair
.
cert_chain
=
RSTRING_PTR
(
pem_cert_chain
);
creds
=
grpc_ssl_credentials_create
(
RSTRING_PTR
(
pem_root_certs
),
&
key_cert_pair
);
creds
=
grpc_ssl_credentials_create
(
RSTRING_PTR
(
pem_root_certs
),
&
key_cert_pair
);
}
if
(
creds
==
NULL
)
{
rb_raise
(
rb_eRuntimeError
,
"could not create a credentials, not sure why"
);
...
...
@@ -253,8 +263,8 @@ void Init_grpc_credentials() {
rb_define_alloc_func
(
grpc_rb_cCredentials
,
grpc_rb_credentials_alloc
);
/* Provides a ruby constructor and support for dup/clone. */
rb_define_method
(
grpc_rb_cCredentials
,
"initialize"
,
grpc_rb_credentials_init
,
-
1
);
rb_define_method
(
grpc_rb_cCredentials
,
"initialize"
,
grpc_rb_credentials_init
,
-
1
);
rb_define_method
(
grpc_rb_cCredentials
,
"initialize_copy"
,
grpc_rb_credentials_init_copy
,
1
);
...
...
@@ -277,6 +287,7 @@ void Init_grpc_credentials() {
/* Gets the wrapped grpc_credentials from the ruby wrapper */
grpc_credentials
*
grpc_rb_get_wrapped_credentials
(
VALUE
v
)
{
grpc_rb_credentials
*
wrapper
=
NULL
;
Data_Get_Struct
(
v
,
grpc_rb_credentials
,
wrapper
);
TypedData_Get_Struct
(
v
,
grpc_rb_credentials
,
&
grpc_rb_credentials_data_type
,
wrapper
);
return
wrapper
->
wrapped
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment