blob: 663cc6858de7d819a1e959cf560fde4f72825a66 [file] [log] [blame]
Stanley Cheungaeea1022015-10-21 17:00:49 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Stanley Cheungaeea1022015-10-21 17:00:49 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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
Stanley Cheungaeea1022015-10-21 17:00:49 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Stanley Cheungaeea1022015-10-21 17:00:49 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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.
Stanley Cheungaeea1022015-10-21 17:00:49 -070016 *
17 */
18
19#ifndef NET_GRPC_PHP_GRPC_CALL_CREDENTIALS_H_
20#define NET_GRPC_PHP_GRPC_CALL_CREDENTIALS_H_
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include "php.h"
27#include "php_ini.h"
28#include "ext/standard/info.h"
29#include "php_grpc.h"
30
31#include "grpc/grpc.h"
32#include "grpc/grpc_security.h"
33
34/* Class entry for the CallCredentials PHP class */
35extern zend_class_entry *grpc_ce_call_credentials;
36
37/* Wrapper struct for grpc_call_credentials that can be associated
38 * with a PHP object */
thinkerou6f9d30b2016-07-27 03:19:03 +080039PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_call_credentials)
Stanley Cheungaeea1022015-10-21 17:00:49 -070040 grpc_call_credentials *wrapped;
thinkerou6f9d30b2016-07-27 03:19:03 +080041PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call_credentials)
42
43#if PHP_MAJOR_VERSION < 7
Stanley Cheungaeea1022015-10-21 17:00:49 -070044
thinkerou19304682016-07-22 02:43:19 +080045#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
46 (wrapped_grpc_call_credentials *)zend_object_store_get_object(zv TSRMLS_CC)
thinkeroua3730b72016-07-20 16:59:54 +080047
thinkerou6f9d30b2016-07-27 03:19:03 +080048#else
thinkeroua3730b72016-07-20 16:59:54 +080049
50static inline wrapped_grpc_call_credentials
thinkerou011d1ef2016-07-27 09:44:49 +080051*wrapped_grpc_call_credentials_from_obj(zend_object *obj) {
thinkerou5dafd822016-07-28 22:43:38 +080052 return (wrapped_grpc_call_credentials*)(
53 (char*)(obj) - XtOffsetOf(wrapped_grpc_call_credentials, std));
thinkeroua3730b72016-07-20 16:59:54 +080054}
55
thinkerou6f9d30b2016-07-27 03:19:03 +080056#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
thinkerou011d1ef2016-07-27 09:44:49 +080057 wrapped_grpc_call_credentials_from_obj(Z_OBJ_P((zv)))
thinkeroua3730b72016-07-20 16:59:54 +080058
59#endif /* PHP_MAJOR_VERSION */
60
Stanley Cheung35805802015-12-10 11:42:55 -080061/* Struct to hold callback function for plugin creds API */
62typedef struct plugin_state {
63 zend_fcall_info *fci;
64 zend_fcall_info_cache *fci_cache;
65} plugin_state;
66
67/* Callback function for plugin creds API */
Stanley Cheung6d8cc7c2017-09-04 22:22:18 -070068int plugin_get_metadata(
69 void *ptr, grpc_auth_metadata_context context,
70 grpc_credentials_plugin_metadata_cb cb, void *user_data,
71 grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
72 size_t *num_creds_md, grpc_status_code *status,
73 const char **error_details);
Stanley Cheung35805802015-12-10 11:42:55 -080074
75/* Cleanup function for plugin creds API */
76void plugin_destroy_state(void *ptr);
77
Stanley Cheungaeea1022015-10-21 17:00:49 -070078/* Initializes the CallCredentials PHP class */
79void grpc_init_call_credentials(TSRMLS_D);
80
81#endif /* NET_GRPC_PHP_GRPC_CALL_CREDENTIALS_H_ */