Skip to content
Snippets Groups Projects
Commit 8b87e84b authored by murgatroid99's avatar murgatroid99
Browse files

Switched to new secure server API

parent e7460e87
No related branches found
No related tags found
No related merge requests found
...@@ -96,9 +96,6 @@ PHP_METHOD(Server, __construct) { ...@@ -96,9 +96,6 @@ PHP_METHOD(Server, __construct) {
zval *queue_obj; zval *queue_obj;
zval *args_array = NULL; zval *args_array = NULL;
grpc_channel_args args; grpc_channel_args args;
HashTable *array_hash;
zval **creds_obj = NULL;
wrapped_grpc_server_credentials *creds = NULL;
/* "O|a" == 1 Object, 1 optional array */ /* "O|a" == 1 Object, 1 optional array */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|a", &queue_obj, if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|a", &queue_obj,
grpc_ce_completion_queue, &args_array) == FAILURE) { grpc_ce_completion_queue, &args_array) == FAILURE) {
...@@ -114,28 +111,8 @@ PHP_METHOD(Server, __construct) { ...@@ -114,28 +111,8 @@ PHP_METHOD(Server, __construct) {
if (args_array == NULL) { if (args_array == NULL) {
server->wrapped = grpc_server_create(queue->wrapped, NULL); server->wrapped = grpc_server_create(queue->wrapped, NULL);
} else { } else {
array_hash = Z_ARRVAL_P(args_array);
if (zend_hash_find(array_hash, "credentials", sizeof("credentials"),
(void **)&creds_obj) == SUCCESS) {
if (zend_get_class_entry(*creds_obj TSRMLS_CC) !=
grpc_ce_server_credentials) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"credentials must be a ServerCredentials object",
1 TSRMLS_CC);
return;
}
creds = (wrapped_grpc_server_credentials *)zend_object_store_get_object(
*creds_obj TSRMLS_CC);
zend_hash_del(array_hash, "credentials", sizeof("credentials"));
}
php_grpc_read_args_array(args_array, &args); php_grpc_read_args_array(args_array, &args);
if (creds == NULL) { server->wrapped = grpc_server_create(queue->wrapped, &args);
server->wrapped = grpc_server_create(queue->wrapped, &args);
} else {
gpr_log(GPR_DEBUG, "Initialized secure server");
server->wrapped =
grpc_secure_server_create(creds->wrapped, queue->wrapped, &args);
}
efree(args.args); efree(args.args);
} }
} }
...@@ -187,14 +164,21 @@ PHP_METHOD(Server, add_secure_http2_port) { ...@@ -187,14 +164,21 @@ PHP_METHOD(Server, add_secure_http2_port) {
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC); (wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
const char *addr; const char *addr;
int addr_len; int addr_len;
/* "s" == 1 string */ zval *creds_obj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) == /* "sO" == 1 string, 1 object */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len,
&creds_obj, grpc_ce_server_credentials) ==
FAILURE) { FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException, zend_throw_exception(
"add_http2_port expects a string", 1 TSRMLS_CC); spl_ce_InvalidArgumentException,
"add_http2_port expects a string and a ServerCredentials", 1 TSRMLS_CC);
return; return;
} }
RETURN_LONG(grpc_server_add_secure_http2_port(server->wrapped, addr)); wrapped_grpc_server_credentials *creds =
(wrapped_grpc_server_credentials *)zend_object_store_get_object(
creds_obj TSRMLS_CC);
RETURN_LONG(grpc_server_add_secure_http2_port(server->wrapped, addr,
creds->wrapped));
} }
/** /**
......
...@@ -41,9 +41,9 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{ ...@@ -41,9 +41,9 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
null, null,
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_queue, $this->server = new Grpc\Server($this->server_queue);
['credentials' => $server_credentials]); $port = $this->server->add_secure_http2_port('0.0.0.0:0',
$port = $this->server->add_secure_http2_port('0.0.0.0:0'); $server_credentials);
$this->channel = new Grpc\Channel( $this->channel = new Grpc\Channel(
'localhost:' . $port, 'localhost:' . $port,
[ [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment