Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 16 | * |
| 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 */ |
| 35 | extern zend_class_entry *grpc_ce_call_credentials; |
| 36 | |
| 37 | /* Wrapper struct for grpc_call_credentials that can be associated |
| 38 | * with a PHP object */ |
thinkerou | 6f9d30b | 2016-07-27 03:19:03 +0800 | [diff] [blame] | 39 | PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_call_credentials) |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 40 | grpc_call_credentials *wrapped; |
thinkerou | 6f9d30b | 2016-07-27 03:19:03 +0800 | [diff] [blame] | 41 | PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call_credentials) |
| 42 | |
| 43 | #if PHP_MAJOR_VERSION < 7 |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 44 | |
thinkerou | 1930468 | 2016-07-22 02:43:19 +0800 | [diff] [blame] | 45 | #define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \ |
| 46 | (wrapped_grpc_call_credentials *)zend_object_store_get_object(zv TSRMLS_CC) |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 47 | |
thinkerou | 6f9d30b | 2016-07-27 03:19:03 +0800 | [diff] [blame] | 48 | #else |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 49 | |
| 50 | static inline wrapped_grpc_call_credentials |
thinkerou | 011d1ef | 2016-07-27 09:44:49 +0800 | [diff] [blame] | 51 | *wrapped_grpc_call_credentials_from_obj(zend_object *obj) { |
thinkerou | 5dafd82 | 2016-07-28 22:43:38 +0800 | [diff] [blame] | 52 | return (wrapped_grpc_call_credentials*)( |
| 53 | (char*)(obj) - XtOffsetOf(wrapped_grpc_call_credentials, std)); |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 54 | } |
| 55 | |
thinkerou | 6f9d30b | 2016-07-27 03:19:03 +0800 | [diff] [blame] | 56 | #define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \ |
thinkerou | 011d1ef | 2016-07-27 09:44:49 +0800 | [diff] [blame] | 57 | wrapped_grpc_call_credentials_from_obj(Z_OBJ_P((zv))) |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 58 | |
| 59 | #endif /* PHP_MAJOR_VERSION */ |
| 60 | |
Stanley Cheung | 3580580 | 2015-12-10 11:42:55 -0800 | [diff] [blame] | 61 | /* Struct to hold callback function for plugin creds API */ |
| 62 | typedef 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 Cheung | 6d8cc7c | 2017-09-04 22:22:18 -0700 | [diff] [blame] | 68 | int 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 Cheung | 3580580 | 2015-12-10 11:42:55 -0800 | [diff] [blame] | 74 | |
| 75 | /* Cleanup function for plugin creds API */ |
| 76 | void plugin_destroy_state(void *ptr); |
| 77 | |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 78 | /* Initializes the CallCredentials PHP class */ |
| 79 | void grpc_init_call_credentials(TSRMLS_D); |
| 80 | |
| 81 | #endif /* NET_GRPC_PHP_GRPC_CALL_CREDENTIALS_H_ */ |