Merge pull request #2 from murgatroid99/php_new_secure_server_api

Switched to new secure server API
pull/835/head
Craig Tiller 10 years ago
commit 08d91dee6c
  1. 42
      src/php/ext/grpc/server.c
  2. 6
      src/php/tests/unit_tests/SecureEndToEndTest.php

@ -96,9 +96,6 @@ PHP_METHOD(Server, __construct) {
zval *queue_obj;
zval *args_array = NULL;
grpc_channel_args args;
HashTable *array_hash;
zval **creds_obj = NULL;
wrapped_grpc_server_credentials *creds = NULL;
/* "O|a" == 1 Object, 1 optional array */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|a", &queue_obj,
grpc_ce_completion_queue, &args_array) == FAILURE) {
@ -114,28 +111,8 @@ PHP_METHOD(Server, __construct) {
if (args_array == NULL) {
server->wrapped = grpc_server_create(queue->wrapped, NULL);
} 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);
if (creds == NULL) {
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);
}
server->wrapped = grpc_server_create(queue->wrapped, &args);
efree(args.args);
}
}
@ -187,14 +164,21 @@ PHP_METHOD(Server, add_secure_http2_port) {
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
const char *addr;
int addr_len;
/* "s" == 1 string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) ==
zval *creds_obj;
/* "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) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"add_http2_port expects a string", 1 TSRMLS_CC);
zend_throw_exception(
spl_ce_InvalidArgumentException,
"add_http2_port expects a string and a ServerCredentials", 1 TSRMLS_CC);
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{
null,
file_get_contents(dirname(__FILE__) . '/../data/server1.key'),
file_get_contents(dirname(__FILE__) . '/../data/server1.pem'));
$this->server = new Grpc\Server($this->server_queue,
['credentials' => $server_credentials]);
$port = $this->server->add_secure_http2_port('0.0.0.0:0');
$this->server = new Grpc\Server($this->server_queue);
$port = $this->server->add_secure_http2_port('0.0.0.0:0',
$server_credentials);
$this->channel = new Grpc\Channel(
'localhost:' . $port,
[

Loading…
Cancel
Save