1 /*
2 *
3 * Copyright 2015 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 /**
20 * class Call
21 * @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/call.c
22 */
23
24 #include "call.h"
25
26 #include <ext/spl/spl_exceptions.h>
27 #include <zend_exceptions.h>
28
29 #include <grpc/support/alloc.h>
30
31 #include "call_credentials.h"
32 #include "completion_queue.h"
33 #include "timeval.h"
34 #include "channel.h"
35 #include "byte_buffer.h"
36
37 zend_class_entry *grpc_ce_call;
38 PHP_GRPC_DECLARE_OBJECT_HANDLER(call_ce_handlers)
39
40 /* Frees and destroys an instance of wrapped_grpc_call */
41 PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call)
42 if (p->owned && p->wrapped != NULL) {
43 grpc_call_unref(p->wrapped);
44 }
PHP_GRPC_FREE_WRAPPED_FUNC_END()45 PHP_GRPC_FREE_WRAPPED_FUNC_END()
46
47 /* Initializes an instance of wrapped_grpc_call to be associated with an
48 * object of a class specified by class_type */
49 php_grpc_zend_object create_wrapped_grpc_call(zend_class_entry *class_type
50 TSRMLS_DC) {
51 PHP_GRPC_ALLOC_CLASS_OBJECT(wrapped_grpc_call);
52 zend_object_std_init(&intern->std, class_type TSRMLS_CC);
53 object_properties_init(&intern->std, class_type);
54 PHP_GRPC_FREE_CLASS_OBJECT(wrapped_grpc_call, call_ce_handlers);
55 }
56
57 /* Creates and returns a PHP array object with the data in a
58 * grpc_metadata_array. Returns NULL on failure */
grpc_parse_metadata_array(grpc_metadata_array * metadata_array TSRMLS_DC)59 zval *grpc_parse_metadata_array(grpc_metadata_array
60 *metadata_array TSRMLS_DC) {
61 int count = metadata_array->count;
62 grpc_metadata *elements = metadata_array->metadata;
63 zval *array;
64 PHP_GRPC_MAKE_STD_ZVAL(array);
65 array_init(array);
66 int i;
67 HashTable *array_hash;
68 zval *inner_array;
69 char *str_key;
70 char *str_val;
71 size_t key_len;
72 zval *data = NULL;
73
74 array_hash = Z_ARRVAL_P(array);
75 grpc_metadata *elem;
76 for (i = 0; i < count; i++) {
77 elem = &elements[i];
78 key_len = GRPC_SLICE_LENGTH(elem->key);
79 str_key = ecalloc(key_len + 1, sizeof(char));
80 memcpy(str_key, GRPC_SLICE_START_PTR(elem->key), key_len);
81 str_val = ecalloc(GRPC_SLICE_LENGTH(elem->value) + 1, sizeof(char));
82 memcpy(str_val, GRPC_SLICE_START_PTR(elem->value),
83 GRPC_SLICE_LENGTH(elem->value));
84 if (php_grpc_zend_hash_find(array_hash, str_key, key_len, (void **)&data)
85 == SUCCESS) {
86 if (Z_TYPE_P(data) != IS_ARRAY) {
87 zend_throw_exception(zend_exception_get_default(TSRMLS_C),
88 "Metadata hash somehow contains wrong types.",
89 1 TSRMLS_CC);
90 efree(str_key);
91 efree(str_val);
92 PHP_GRPC_FREE_STD_ZVAL(array);
93 return NULL;
94 }
95 php_grpc_add_next_index_stringl(data, str_val,
96 GRPC_SLICE_LENGTH(elem->value),
97 false);
98 } else {
99 PHP_GRPC_MAKE_STD_ZVAL(inner_array);
100 array_init(inner_array);
101 php_grpc_add_next_index_stringl(inner_array, str_val,
102 GRPC_SLICE_LENGTH(elem->value), false);
103 add_assoc_zval(array, str_key, inner_array);
104 PHP_GRPC_FREE_STD_ZVAL(inner_array);
105 }
106 efree(str_key);
107 efree(str_val);
108 }
109 return array;
110 }
111
112 /* Populates a grpc_metadata_array with the data in a PHP array object.
113 Returns true on success and false on failure */
create_metadata_array(zval * array,grpc_metadata_array * metadata)114 bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
115 HashTable *array_hash;
116 HashTable *inner_array_hash;
117 zval *value;
118 zval *inner_array;
119 grpc_metadata_array_init(metadata);
120 metadata->count = 0;
121 metadata->metadata = NULL;
122 if (Z_TYPE_P(array) != IS_ARRAY) {
123 return false;
124 }
125 array_hash = Z_ARRVAL_P(array);
126
127 char *key;
128 int key_type;
129 PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(array_hash, key, key_type,
130 inner_array)
131 if (key_type != HASH_KEY_IS_STRING || key == NULL) {
132 return false;
133 }
134 if (Z_TYPE_P(inner_array) != IS_ARRAY) {
135 return false;
136 }
137 inner_array_hash = Z_ARRVAL_P(inner_array);
138 metadata->capacity += zend_hash_num_elements(inner_array_hash);
139 PHP_GRPC_HASH_FOREACH_END()
140
141 metadata->metadata = gpr_malloc(metadata->capacity * sizeof(grpc_metadata));
142
143 char *key1 = NULL;
144 int key_type1;
145 PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(array_hash, key1, key_type1,
146 inner_array)
147 if (key_type1 != HASH_KEY_IS_STRING) {
148 return false;
149 }
150 if (!grpc_header_key_is_legal(grpc_slice_from_static_string(key1))) {
151 return false;
152 }
153 inner_array_hash = Z_ARRVAL_P(inner_array);
154 PHP_GRPC_HASH_FOREACH_VAL_START(inner_array_hash, value)
155 if (Z_TYPE_P(value) != IS_STRING) {
156 return false;
157 }
158 metadata->metadata[metadata->count].key =
159 grpc_slice_from_copied_string(key1);
160 metadata->metadata[metadata->count].value =
161 grpc_slice_from_copied_buffer(Z_STRVAL_P(value), Z_STRLEN_P(value));
162 metadata->count += 1;
163 PHP_GRPC_HASH_FOREACH_END()
164 PHP_GRPC_HASH_FOREACH_END()
165 return true;
166 }
167
grpc_php_metadata_array_destroy_including_entries(grpc_metadata_array * array)168 void grpc_php_metadata_array_destroy_including_entries(
169 grpc_metadata_array* array) {
170 size_t i;
171 if (array->metadata) {
172 for (i = 0; i < array->count; i++) {
173 grpc_slice_unref(array->metadata[i].key);
174 grpc_slice_unref(array->metadata[i].value);
175 }
176 }
177 grpc_metadata_array_destroy(array);
178 }
179
180 /* Wraps a grpc_call struct in a PHP object. Owned indicates whether the
181 struct should be destroyed at the end of the object's lifecycle */
grpc_php_wrap_call(grpc_call * wrapped,bool owned TSRMLS_DC)182 zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) {
183 zval *call_object;
184 PHP_GRPC_MAKE_STD_ZVAL(call_object);
185 object_init_ex(call_object, grpc_ce_call);
186 wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call,
187 call_object);
188 call->wrapped = wrapped;
189 call->owned = owned;
190 return call_object;
191 }
192
193 /**
194 * Constructs a new instance of the Call class.
195 * @param Channel $channel_obj The channel to associate the call with.
196 * Must not be closed.
197 * @param string $method The method to call
198 * @param Timeval $deadline_obj The deadline for completing the call
199 * @param string $host_override = "" The host is set by user (optional)
200 */
PHP_METHOD(Call,__construct)201 PHP_METHOD(Call, __construct) {
202 zval *channel_obj;
203 char *method;
204 php_grpc_int method_len;
205 zval *deadline_obj;
206 char *host_override = NULL;
207 php_grpc_int host_override_len = 0;
208 wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call,
209 getThis());
210
211 /* "OsO|s" == 1 Object, 1 string, 1 Object, 1 optional string */
212 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OsO|s", &channel_obj,
213 grpc_ce_channel, &method, &method_len,
214 &deadline_obj, grpc_ce_timeval, &host_override,
215 &host_override_len) == FAILURE) {
216 zend_throw_exception(spl_ce_InvalidArgumentException,
217 "Call expects a Channel, a String, a Timeval and "
218 "an optional String", 1 TSRMLS_CC);
219 return;
220 }
221 wrapped_grpc_channel *channel =
222 PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_channel, channel_obj);
223 if (channel->wrapper == NULL) {
224 zend_throw_exception(spl_ce_InvalidArgumentException,
225 "Call cannot be constructed from a closed Channel",
226 1 TSRMLS_CC);
227 return;
228 }
229 gpr_mu_lock(&channel->wrapper->mu);
230 if (channel->wrapper == NULL || channel->wrapper->wrapped == NULL) {
231 zend_throw_exception(spl_ce_InvalidArgumentException,
232 "Call cannot be constructed from a closed Channel",
233 1 TSRMLS_CC);
234 gpr_mu_unlock(&channel->wrapper->mu);
235 return;
236 }
237 add_property_zval(getThis(), "channel", channel_obj);
238 wrapped_grpc_timeval *deadline =
239 PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_timeval, deadline_obj);
240 grpc_slice method_slice = grpc_slice_from_copied_string(method);
241 grpc_slice host_slice = host_override != NULL ?
242 grpc_slice_from_copied_string(host_override) : grpc_empty_slice();
243 call->wrapped =
244 grpc_channel_create_call(channel->wrapper->wrapped, NULL,
245 GRPC_PROPAGATE_DEFAULTS,
246 completion_queue, method_slice,
247 host_override != NULL ? &host_slice : NULL,
248 deadline->wrapped, NULL);
249 grpc_slice_unref(method_slice);
250 grpc_slice_unref(host_slice);
251 call->owned = true;
252 call->channel = channel;
253 gpr_mu_unlock(&channel->wrapper->mu);
254 }
255
256 /**
257 * Start a batch of RPC actions.
258 * @param array $array Array of actions to take
259 * @return object Object with results of all actions
260 */
PHP_METHOD(Call,startBatch)261 PHP_METHOD(Call, startBatch) {
262 zval *result;
263 PHP_GRPC_MAKE_STD_ZVAL(result);
264 object_init(result);
265 php_grpc_ulong index;
266 zval *recv_status;
267 zval *value;
268 zval *inner_value;
269 zval *message_value;
270 zval *message_flags;
271 wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call,
272 getThis());
273 if (call->channel) {
274 // startBatch in gRPC PHP server doesn't have channel in it.
275 if (call->channel->wrapper == NULL ||
276 call->channel->wrapper->wrapped == NULL) {
277 zend_throw_exception(spl_ce_RuntimeException,
278 "startBatch Error. Channel is closed",
279 1 TSRMLS_CC);
280 }
281 }
282
283 grpc_op ops[8];
284 size_t op_num = 0;
285 zval *array;
286 HashTable *array_hash;
287 HashTable *status_hash;
288 HashTable *message_hash;
289
290 grpc_metadata_array metadata;
291 grpc_metadata_array trailing_metadata;
292 grpc_metadata_array recv_metadata;
293 grpc_metadata_array recv_trailing_metadata;
294 grpc_status_code status;
295 grpc_slice recv_status_details = grpc_empty_slice();
296 grpc_slice send_status_details = grpc_empty_slice();
297 grpc_byte_buffer *message = NULL;
298 int cancelled;
299 grpc_call_error error;
300
301 zend_string* zmessage = NULL;
302
303 grpc_metadata_array_init(&metadata);
304 grpc_metadata_array_init(&trailing_metadata);
305 grpc_metadata_array_init(&recv_metadata);
306 grpc_metadata_array_init(&recv_trailing_metadata);
307 memset(ops, 0, sizeof(ops));
308
309 /* "a" == 1 array */
310 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) ==
311 FAILURE) {
312 zend_throw_exception(spl_ce_InvalidArgumentException,
313 "start_batch expects an array", 1 TSRMLS_CC);
314 goto cleanup;
315 }
316
317 array_hash = Z_ARRVAL_P(array);
318
319 char *key = NULL;
320 int key_type;
321 PHP_GRPC_HASH_FOREACH_LONG_KEY_VAL_START(array_hash, key, key_type, index,
322 value)
323 if (key_type != HASH_KEY_IS_LONG || key != NULL) {
324 zend_throw_exception(spl_ce_InvalidArgumentException,
325 "batch keys must be integers", 1 TSRMLS_CC);
326 goto cleanup;
327 }
328
329 ops[op_num].op = (grpc_op_type)index;
330 ops[op_num].flags = 0;
331 ops[op_num].reserved = NULL;
332
333 switch(index) {
334 case GRPC_OP_SEND_INITIAL_METADATA:
335 if (!create_metadata_array(value, &metadata)) {
336 zend_throw_exception(spl_ce_InvalidArgumentException,
337 "Bad metadata value given", 1 TSRMLS_CC);
338 goto cleanup;
339 }
340 ops[op_num].data.send_initial_metadata.count = metadata.count;
341 ops[op_num].data.send_initial_metadata.metadata = metadata.metadata;
342 break;
343 case GRPC_OP_SEND_MESSAGE:
344 if (Z_TYPE_P(value) != IS_ARRAY) {
345 zend_throw_exception(spl_ce_InvalidArgumentException,
346 "Expected an array for send message",
347 1 TSRMLS_CC);
348 goto cleanup;
349 }
350 message_hash = Z_ARRVAL_P(value);
351 if (php_grpc_zend_hash_find(message_hash, "flags", sizeof("flags"),
352 (void **)&message_flags) == SUCCESS) {
353 if (Z_TYPE_P(message_flags) != IS_LONG) {
354 zend_throw_exception(spl_ce_InvalidArgumentException,
355 "Expected an int for message flags",
356 1 TSRMLS_CC);
357 }
358 ops[op_num].flags = Z_LVAL_P(message_flags) & GRPC_WRITE_USED_MASK;
359 }
360 if (php_grpc_zend_hash_find(message_hash, "message", sizeof("message"),
361 (void **)&message_value) != SUCCESS ||
362 Z_TYPE_P(message_value) != IS_STRING) {
363 zend_throw_exception(spl_ce_InvalidArgumentException,
364 "Expected a string for send message",
365 1 TSRMLS_CC);
366 goto cleanup;
367 }
368 ops[op_num].data.send_message.send_message =
369 string_to_byte_buffer(Z_STRVAL_P(message_value),
370 Z_STRLEN_P(message_value));
371 break;
372 case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
373 break;
374 case GRPC_OP_SEND_STATUS_FROM_SERVER:
375 status_hash = Z_ARRVAL_P(value);
376 if (php_grpc_zend_hash_find(status_hash, "metadata", sizeof("metadata"),
377 (void **)&inner_value) == SUCCESS) {
378 if (!create_metadata_array(inner_value, &trailing_metadata)) {
379 zend_throw_exception(spl_ce_InvalidArgumentException,
380 "Bad trailing metadata value given",
381 1 TSRMLS_CC);
382 goto cleanup;
383 }
384 ops[op_num].data.send_status_from_server.trailing_metadata =
385 trailing_metadata.metadata;
386 ops[op_num].data.send_status_from_server.trailing_metadata_count =
387 trailing_metadata.count;
388 }
389 if (php_grpc_zend_hash_find(status_hash, "code", sizeof("code"),
390 (void**)&inner_value) == SUCCESS) {
391 if (Z_TYPE_P(inner_value) != IS_LONG) {
392 zend_throw_exception(spl_ce_InvalidArgumentException,
393 "Status code must be an integer",
394 1 TSRMLS_CC);
395 goto cleanup;
396 }
397 ops[op_num].data.send_status_from_server.status =
398 Z_LVAL_P(inner_value);
399 } else {
400 zend_throw_exception(spl_ce_InvalidArgumentException,
401 "Integer status code is required",
402 1 TSRMLS_CC);
403 goto cleanup;
404 }
405 if (php_grpc_zend_hash_find(status_hash, "details", sizeof("details"),
406 (void**)&inner_value) == SUCCESS) {
407 if (Z_TYPE_P(inner_value) != IS_STRING) {
408 zend_throw_exception(spl_ce_InvalidArgumentException,
409 "Status details must be a string",
410 1 TSRMLS_CC);
411 goto cleanup;
412 }
413 send_status_details = grpc_slice_from_copied_string(
414 Z_STRVAL_P(inner_value));
415 ops[op_num].data.send_status_from_server.status_details =
416 &send_status_details;
417 } else {
418 zend_throw_exception(spl_ce_InvalidArgumentException,
419 "String status details is required",
420 1 TSRMLS_CC);
421 goto cleanup;
422 }
423 break;
424 case GRPC_OP_RECV_INITIAL_METADATA:
425 ops[op_num].data.recv_initial_metadata.recv_initial_metadata =
426 &recv_metadata;
427 break;
428 case GRPC_OP_RECV_MESSAGE:
429 ops[op_num].data.recv_message.recv_message = &message;
430 break;
431 case GRPC_OP_RECV_STATUS_ON_CLIENT:
432 ops[op_num].data.recv_status_on_client.trailing_metadata =
433 &recv_trailing_metadata;
434 ops[op_num].data.recv_status_on_client.status = &status;
435 ops[op_num].data.recv_status_on_client.status_details =
436 &recv_status_details;
437 break;
438 case GRPC_OP_RECV_CLOSE_ON_SERVER:
439 ops[op_num].data.recv_close_on_server.cancelled = &cancelled;
440 break;
441 default:
442 zend_throw_exception(spl_ce_InvalidArgumentException,
443 "Unrecognized key in batch", 1 TSRMLS_CC);
444 goto cleanup;
445 }
446 op_num++;
447 PHP_GRPC_HASH_FOREACH_END()
448
449 error = grpc_call_start_batch(call->wrapped, ops, op_num, call->wrapped,
450 NULL);
451 if (error != GRPC_CALL_OK) {
452 zend_throw_exception(spl_ce_LogicException,
453 "start_batch was called incorrectly",
454 (long)error TSRMLS_CC);
455 goto cleanup;
456 }
457 grpc_completion_queue_pluck(completion_queue, call->wrapped,
458 gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
459 zval *recv_md;
460 for (int i = 0; i < op_num; i++) {
461 switch(ops[i].op) {
462 case GRPC_OP_SEND_INITIAL_METADATA:
463 add_property_bool(result, "send_metadata", true);
464 break;
465 case GRPC_OP_SEND_MESSAGE:
466 add_property_bool(result, "send_message", true);
467 break;
468 case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
469 add_property_bool(result, "send_close", true);
470 break;
471 case GRPC_OP_SEND_STATUS_FROM_SERVER:
472 add_property_bool(result, "send_status", true);
473 break;
474 case GRPC_OP_RECV_INITIAL_METADATA:
475 recv_md = grpc_parse_metadata_array(&recv_metadata);
476 add_property_zval(result, "metadata", recv_md);
477 zval_ptr_dtor(recv_md);
478 PHP_GRPC_FREE_STD_ZVAL(recv_md);
479 PHP_GRPC_DELREF(array);
480 break;
481 case GRPC_OP_RECV_MESSAGE:
482 zmessage = byte_buffer_to_zend_string(message);
483
484 if (zmessage == NULL) {
485 add_property_null(result, "message");
486 } else {
487 zval zmessage_val;
488 ZVAL_NEW_STR(&zmessage_val, zmessage);
489 add_property_zval(result, "message", &zmessage_val);
490 zval_ptr_dtor(&zmessage_val);
491 }
492 break;
493 case GRPC_OP_RECV_STATUS_ON_CLIENT:
494 PHP_GRPC_MAKE_STD_ZVAL(recv_status);
495 object_init(recv_status);
496 recv_md = grpc_parse_metadata_array(&recv_trailing_metadata);
497 add_property_zval(recv_status, "metadata", recv_md);
498 zval_ptr_dtor(recv_md);
499 PHP_GRPC_FREE_STD_ZVAL(recv_md);
500 PHP_GRPC_DELREF(array);
501 add_property_long(recv_status, "code", status);
502 char *status_details_text = grpc_slice_to_c_string(recv_status_details);
503 php_grpc_add_property_string(recv_status, "details", status_details_text,
504 true);
505 gpr_free(status_details_text);
506 add_property_zval(result, "status", recv_status);
507 zval_ptr_dtor(recv_status);
508 PHP_GRPC_DELREF(recv_status);
509 PHP_GRPC_FREE_STD_ZVAL(recv_status);
510 break;
511 case GRPC_OP_RECV_CLOSE_ON_SERVER:
512 add_property_bool(result, "cancelled", cancelled);
513 break;
514 default:
515 break;
516 }
517 }
518
519 cleanup:
520 grpc_php_metadata_array_destroy_including_entries(&metadata);
521 grpc_php_metadata_array_destroy_including_entries(&trailing_metadata);
522 grpc_metadata_array_destroy(&recv_metadata);
523 grpc_metadata_array_destroy(&recv_trailing_metadata);
524 grpc_slice_unref(recv_status_details);
525 grpc_slice_unref(send_status_details);
526 for (int i = 0; i < op_num; i++) {
527 if (ops[i].op == GRPC_OP_SEND_MESSAGE) {
528 grpc_byte_buffer_destroy(ops[i].data.send_message.send_message);
529 }
530 if (ops[i].op == GRPC_OP_RECV_MESSAGE) {
531 grpc_byte_buffer_destroy(message);
532 }
533 }
534 RETURN_DESTROY_ZVAL(result);
535 }
536
537 /**
538 * Get the endpoint this call/stream is connected to
539 * @return string The URI of the endpoint
540 */
PHP_METHOD(Call,getPeer)541 PHP_METHOD(Call, getPeer) {
542 wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call,
543 getThis());
544 char *peer = grpc_call_get_peer(call->wrapped);
545 PHP_GRPC_RETVAL_STRING(peer, 1);
546 gpr_free(peer);
547 }
548
549 /**
550 * Cancel the call. This will cause the call to end with STATUS_CANCELLED
551 * if it has not already ended with another status.
552 * @return void
553 */
PHP_METHOD(Call,cancel)554 PHP_METHOD(Call, cancel) {
555 wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call,
556 getThis());
557 grpc_call_cancel(call->wrapped, NULL);
558 }
559
560 /**
561 * Set the CallCredentials for this call.
562 * @param CallCredentials $creds_obj The CallCredentials object
563 * @return int The error code
564 */
PHP_METHOD(Call,setCredentials)565 PHP_METHOD(Call, setCredentials) {
566 zval *creds_obj;
567
568 /* "O" == 1 Object */
569 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &creds_obj,
570 grpc_ce_call_credentials) == FAILURE) {
571 zend_throw_exception(spl_ce_InvalidArgumentException,
572 "setCredentials expects 1 CallCredentials",
573 1 TSRMLS_CC);
574 return;
575 }
576
577 wrapped_grpc_call_credentials *creds =
578 PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call_credentials, creds_obj);
579 wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call,
580 getThis());
581
582 grpc_call_error error = GRPC_CALL_ERROR;
583 error = grpc_call_set_credentials(call->wrapped, creds->wrapped);
584 RETURN_LONG(error);
585 }
586
587 ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 3)
588 ZEND_ARG_INFO(0, channel)
589 ZEND_ARG_INFO(0, method)
590 ZEND_ARG_INFO(0, deadline)
591 ZEND_ARG_INFO(0, host_override)
592 ZEND_END_ARG_INFO()
593
594 ZEND_BEGIN_ARG_INFO_EX(arginfo_startBatch, 0, 0, 1)
595 ZEND_ARG_INFO(0, ops)
596 ZEND_END_ARG_INFO()
597
598 ZEND_BEGIN_ARG_INFO_EX(arginfo_getPeer, 0, 0, 0)
599 ZEND_END_ARG_INFO()
600
601 ZEND_BEGIN_ARG_INFO_EX(arginfo_cancel, 0, 0, 0)
602 ZEND_END_ARG_INFO()
603
604 ZEND_BEGIN_ARG_INFO_EX(arginfo_setCredentials, 0, 0, 1)
605 ZEND_ARG_INFO(0, credentials)
606 ZEND_END_ARG_INFO()
607
608 static zend_function_entry call_methods[] = {
609 PHP_ME(Call, __construct, arginfo_construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
610 PHP_ME(Call, startBatch, arginfo_startBatch, ZEND_ACC_PUBLIC)
611 PHP_ME(Call, getPeer, arginfo_getPeer, ZEND_ACC_PUBLIC)
612 PHP_ME(Call, cancel, arginfo_cancel, ZEND_ACC_PUBLIC)
613 PHP_ME(Call, setCredentials, arginfo_setCredentials, ZEND_ACC_PUBLIC)
614 PHP_FE_END
615 };
616
grpc_init_call(TSRMLS_D)617 void grpc_init_call(TSRMLS_D) {
618 zend_class_entry ce;
619 INIT_CLASS_ENTRY(ce, "Grpc\\Call", call_methods);
620 ce.create_object = create_wrapped_grpc_call;
621 grpc_ce_call = zend_register_internal_class(&ce TSRMLS_CC);
622 PHP_GRPC_INIT_HANDLER(wrapped_grpc_call, call_ce_handlers);
623 }
624