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
478fb00a
Commit
478fb00a
authored
9 years ago
by
Stanley Cheung
Browse files
Options
Downloads
Patches
Plain Diff
php: expose per-call host override option
parent
89bede02
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/php/ext/grpc/call.c
+19
-8
19 additions, 8 deletions
src/php/ext/grpc/call.c
src/php/ext/grpc/channel.c
+2
-20
2 additions, 20 deletions
src/php/ext/grpc/channel.c
src/php/tests/unit_tests/SecureEndToEndTest.php
+9
-5
9 additions, 5 deletions
src/php/tests/unit_tests/SecureEndToEndTest.php
with
30 additions
and
33 deletions
src/php/ext/grpc/call.c
+
19
−
8
View file @
478fb00a
...
@@ -216,13 +216,18 @@ PHP_METHOD(Call, __construct) {
...
@@ -216,13 +216,18 @@ PHP_METHOD(Call, __construct) {
char
*
method
;
char
*
method
;
int
method_len
;
int
method_len
;
zval
*
deadline_obj
;
zval
*
deadline_obj
;
/* "OsO" == 1 Object, 1 string, 1 Object */
char
*
host_override
=
NULL
;
if
(
zend_parse_parameters
(
ZEND_NUM_ARGS
()
TSRMLS_CC
,
"OsO"
,
&
channel_obj
,
int
host_override_len
=
0
;
grpc_ce_channel
,
&
method
,
&
method_len
,
/* "OsO|s" == 1 Object, 1 string, 1 Object, 1 optional string */
&
deadline_obj
,
grpc_ce_timeval
)
==
FAILURE
)
{
if
(
zend_parse_parameters
(
ZEND_NUM_ARGS
()
TSRMLS_CC
,
"OsO|s"
,
&
channel_obj
,
grpc_ce_channel
,
&
method
,
&
method_len
,
&
deadline_obj
,
grpc_ce_timeval
,
&
host_override
,
&
host_override_len
)
==
FAILURE
)
{
zend_throw_exception
(
zend_throw_exception
(
spl_ce_InvalidArgumentException
,
spl_ce_InvalidArgumentException
,
"Call expects a Channel, a String, a
nd a
Timeval"
,
"Call expects a Channel, a String, a Timeval
and an optional String
"
,
1
TSRMLS_CC
);
1
TSRMLS_CC
);
return
;
return
;
}
}
...
@@ -239,9 +244,15 @@ PHP_METHOD(Call, __construct) {
...
@@ -239,9 +244,15 @@ PHP_METHOD(Call, __construct) {
wrapped_grpc_timeval
*
deadline
=
wrapped_grpc_timeval
*
deadline
=
(
wrapped_grpc_timeval
*
)
zend_object_store_get_object
(
(
wrapped_grpc_timeval
*
)
zend_object_store_get_object
(
deadline_obj
TSRMLS_CC
);
deadline_obj
TSRMLS_CC
);
call
->
wrapped
=
grpc_channel_create_call
(
if
(
host_override
!=
NULL
)
{
channel
->
wrapped
,
NULL
,
GRPC_PROPAGATE_DEFAULTS
,
completion_queue
,
method
,
call
->
wrapped
=
grpc_channel_create_call
(
channel
->
target
,
deadline
->
wrapped
,
NULL
);
channel
->
wrapped
,
NULL
,
GRPC_PROPAGATE_DEFAULTS
,
completion_queue
,
method
,
host_override
,
deadline
->
wrapped
,
NULL
);
}
else
{
call
->
wrapped
=
grpc_channel_create_call
(
channel
->
wrapped
,
NULL
,
GRPC_PROPAGATE_DEFAULTS
,
completion_queue
,
method
,
NULL
,
deadline
->
wrapped
,
NULL
);
}
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/php/ext/grpc/channel.c
+
2
−
20
View file @
478fb00a
...
@@ -141,9 +141,6 @@ PHP_METHOD(Channel, __construct) {
...
@@ -141,9 +141,6 @@ PHP_METHOD(Channel, __construct) {
HashTable
*
array_hash
;
HashTable
*
array_hash
;
zval
**
creds_obj
=
NULL
;
zval
**
creds_obj
=
NULL
;
wrapped_grpc_credentials
*
creds
=
NULL
;
wrapped_grpc_credentials
*
creds
=
NULL
;
zval
**
override_obj
;
char
*
override
;
int
override_len
;
/* "s|a" == 1 string, 1 optional array */
/* "s|a" == 1 string, 1 optional array */
if
(
zend_parse_parameters
(
ZEND_NUM_ARGS
()
TSRMLS_CC
,
"s|a"
,
&
target
,
if
(
zend_parse_parameters
(
ZEND_NUM_ARGS
()
TSRMLS_CC
,
"s|a"
,
&
target
,
&
target_length
,
&
args_array
)
==
FAILURE
)
{
&
target_length
,
&
args_array
)
==
FAILURE
)
{
...
@@ -151,8 +148,6 @@ PHP_METHOD(Channel, __construct) {
...
@@ -151,8 +148,6 @@ PHP_METHOD(Channel, __construct) {
"Channel expects a string and an array"
,
1
TSRMLS_CC
);
"Channel expects a string and an array"
,
1
TSRMLS_CC
);
return
;
return
;
}
}
override
=
target
;
override_len
=
target_length
;
if
(
args_array
==
NULL
)
{
if
(
args_array
==
NULL
)
{
channel
->
wrapped
=
grpc_insecure_channel_create
(
target
,
NULL
,
NULL
);
channel
->
wrapped
=
grpc_insecure_channel_create
(
target
,
NULL
,
NULL
);
}
else
{
}
else
{
...
@@ -169,19 +164,6 @@ PHP_METHOD(Channel, __construct) {
...
@@ -169,19 +164,6 @@ PHP_METHOD(Channel, __construct) {
*
creds_obj
TSRMLS_CC
);
*
creds_obj
TSRMLS_CC
);
zend_hash_del
(
array_hash
,
"credentials"
,
12
);
zend_hash_del
(
array_hash
,
"credentials"
,
12
);
}
}
if
(
zend_hash_find
(
array_hash
,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG
,
sizeof
(
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG
),
(
void
**
)
&
override_obj
)
==
SUCCESS
)
{
if
(
Z_TYPE_PP
(
override_obj
)
!=
IS_STRING
)
{
zend_throw_exception
(
spl_ce_InvalidArgumentException
,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG
" must be a string"
,
1
TSRMLS_CC
);
return
;
}
override
=
Z_STRVAL_PP
(
override_obj
);
override_len
=
Z_STRLEN_PP
(
override_obj
);
}
php_grpc_read_args_array
(
args_array
,
&
args
);
php_grpc_read_args_array
(
args_array
,
&
args
);
if
(
creds
==
NULL
)
{
if
(
creds
==
NULL
)
{
channel
->
wrapped
=
grpc_insecure_channel_create
(
target
,
&
args
,
NULL
);
channel
->
wrapped
=
grpc_insecure_channel_create
(
target
,
&
args
,
NULL
);
...
@@ -192,8 +174,8 @@ PHP_METHOD(Channel, __construct) {
...
@@ -192,8 +174,8 @@ PHP_METHOD(Channel, __construct) {
}
}
efree
(
args
.
args
);
efree
(
args
.
args
);
}
}
channel
->
target
=
ecalloc
(
override
_len
+
1
,
sizeof
(
char
));
channel
->
target
=
ecalloc
(
target
_len
gth
+
1
,
sizeof
(
char
));
memcpy
(
channel
->
target
,
override
,
override
_len
);
memcpy
(
channel
->
target
,
target
,
target
_len
gth
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/php/tests/unit_tests/SecureEndToEndTest.php
+
9
−
5
View file @
478fb00a
...
@@ -40,13 +40,15 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
...
@@ -40,13 +40,15 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
file_get_contents
(
dirname
(
__FILE__
)
.
'/../data/server1.key'
),
file_get_contents
(
dirname
(
__FILE__
)
.
'/../data/server1.key'
),
file_get_contents
(
dirname
(
__FILE__
)
.
'/../data/server1.pem'
));
file_get_contents
(
dirname
(
__FILE__
)
.
'/../data/server1.pem'
));
$this
->
server
=
new
Grpc\Server
();
$this
->
server
=
new
Grpc\Server
();
$port
=
$this
->
server
->
addSecureHttp2Port
(
'0.0.0.0:0'
,
$
this
->
port
=
$this
->
server
->
addSecureHttp2Port
(
'0.0.0.0:0'
,
$server_credentials
);
$server_credentials
);
$this
->
server
->
start
();
$this
->
server
->
start
();
$this
->
host_override
=
'foo.test.google.fr'
;
$this
->
channel
=
new
Grpc\Channel
(
$this
->
channel
=
new
Grpc\Channel
(
'localhost:'
.
$port
,
'localhost:'
.
$
this
->
port
,
[
[
'grpc.ssl_target_name_override'
=>
'foo.test.google.fr'
,
'grpc.ssl_target_name_override'
=>
$this
->
host_override
,
'grpc.default_authority'
=>
$this
->
host_override
,
'credentials'
=>
$credentials
'credentials'
=>
$credentials
]);
]);
}
}
...
@@ -61,7 +63,8 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
...
@@ -61,7 +63,8 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
$status_text
=
'xyz'
;
$status_text
=
'xyz'
;
$call
=
new
Grpc\Call
(
$this
->
channel
,
$call
=
new
Grpc\Call
(
$this
->
channel
,
'dummy_method'
,
'dummy_method'
,
$deadline
);
$deadline
,
$this
->
host_override
);
$event
=
$call
->
startBatch
([
$event
=
$call
->
startBatch
([
Grpc\OP_SEND_INITIAL_METADATA
=>
[],
Grpc\OP_SEND_INITIAL_METADATA
=>
[],
...
@@ -112,7 +115,8 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
...
@@ -112,7 +115,8 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
$call
=
new
Grpc\Call
(
$this
->
channel
,
$call
=
new
Grpc\Call
(
$this
->
channel
,
'dummy_method'
,
'dummy_method'
,
$deadline
);
$deadline
,
$this
->
host_override
);
$event
=
$call
->
startBatch
([
$event
=
$call
->
startBatch
([
Grpc\OP_SEND_INITIAL_METADATA
=>
[],
Grpc\OP_SEND_INITIAL_METADATA
=>
[],
...
...
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