Craig Tiller | 1a61b17 | 2015-02-16 11:53:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 34 | #include "call.h" |
| 35 | #include "channel.h" |
| 36 | #include "server.h" |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 37 | #include "timeval.h" |
| 38 | #include "credentials.h" |
| 39 | #include "server_credentials.h" |
| 40 | |
| 41 | #ifdef HAVE_CONFIG_H |
| 42 | #include "config.h" |
| 43 | #endif |
| 44 | |
| 45 | #include "php.h" |
| 46 | #include "php_ini.h" |
| 47 | #include "ext/standard/info.h" |
| 48 | #include "php_grpc.h" |
| 49 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 50 | // ZEND_DECLARE_MODULE_GLOBALS(grpc) |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 51 | |
| 52 | /* {{{ grpc_functions[] |
| 53 | * |
| 54 | * Every user visible function must have an entry in grpc_functions[]. |
| 55 | */ |
| 56 | const zend_function_entry grpc_functions[] = { |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 57 | PHP_FE_END /* Must be the last line in grpc_functions[] */ |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 58 | }; |
| 59 | /* }}} */ |
| 60 | |
| 61 | /* {{{ grpc_module_entry |
| 62 | */ |
| 63 | zend_module_entry grpc_module_entry = { |
| 64 | #if ZEND_MODULE_API_NO >= 20010901 |
| 65 | STANDARD_MODULE_HEADER, |
| 66 | #endif |
murgatroid99 | 1d89452 | 2015-01-16 09:57:05 -0800 | [diff] [blame] | 67 | "grpc", grpc_functions, PHP_MINIT(grpc), |
| 68 | PHP_MSHUTDOWN(grpc), NULL, NULL, |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 69 | PHP_MINFO(grpc), |
| 70 | #if ZEND_MODULE_API_NO >= 20010901 |
| 71 | PHP_GRPC_VERSION, |
| 72 | #endif |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 73 | STANDARD_MODULE_PROPERTIES}; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 74 | /* }}} */ |
| 75 | |
| 76 | #ifdef COMPILE_DL_GRPC |
| 77 | ZEND_GET_MODULE(grpc) |
| 78 | #endif |
| 79 | |
| 80 | /* {{{ PHP_INI |
| 81 | */ |
| 82 | /* Remove comments and fill if you need to have entries in php.ini |
| 83 | PHP_INI_BEGIN() |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 84 | STD_PHP_INI_ENTRY("grpc.global_value", "42", PHP_INI_ALL, OnUpdateLong, |
| 85 | global_value, zend_grpc_globals, grpc_globals) |
| 86 | STD_PHP_INI_ENTRY("grpc.global_string", "foobar", PHP_INI_ALL, |
| 87 | OnUpdateString, global_string, zend_grpc_globals, grpc_globals) |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 88 | PHP_INI_END() |
| 89 | */ |
| 90 | /* }}} */ |
| 91 | |
| 92 | /* {{{ php_grpc_init_globals |
| 93 | */ |
| 94 | /* Uncomment this function if you have INI entries |
| 95 | static void php_grpc_init_globals(zend_grpc_globals *grpc_globals) |
| 96 | { |
| 97 | grpc_globals->global_value = 0; |
| 98 | grpc_globals->global_string = NULL; |
| 99 | } |
| 100 | */ |
| 101 | /* }}} */ |
| 102 | |
| 103 | /* {{{ PHP_MINIT_FUNCTION |
| 104 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 105 | PHP_MINIT_FUNCTION(grpc) { |
| 106 | /* If you have INI entries, uncomment these lines |
| 107 | REGISTER_INI_ENTRIES(); |
| 108 | */ |
| 109 | /* Register call error constants */ |
| 110 | grpc_init(); |
| 111 | REGISTER_LONG_CONSTANT("Grpc\\CALL_OK", GRPC_CALL_OK, CONST_CS); |
| 112 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR", GRPC_CALL_ERROR, CONST_CS); |
| 113 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_SERVER", |
| 114 | GRPC_CALL_ERROR_NOT_ON_SERVER, CONST_CS); |
| 115 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_CLIENT", |
| 116 | GRPC_CALL_ERROR_NOT_ON_CLIENT, CONST_CS); |
| 117 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_INVOKED", |
| 118 | GRPC_CALL_ERROR_ALREADY_INVOKED, CONST_CS); |
| 119 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_INVOKED", |
| 120 | GRPC_CALL_ERROR_NOT_INVOKED, CONST_CS); |
| 121 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_FINISHED", |
| 122 | GRPC_CALL_ERROR_ALREADY_FINISHED, CONST_CS); |
| 123 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_TOO_MANY_OPERATIONS", |
| 124 | GRPC_CALL_ERROR_TOO_MANY_OPERATIONS, CONST_CS); |
| 125 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_INVALID_FLAGS", |
| 126 | GRPC_CALL_ERROR_INVALID_FLAGS, CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 127 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 128 | /* Register flag constants */ |
| 129 | REGISTER_LONG_CONSTANT("Grpc\\WRITE_BUFFER_HINT", GRPC_WRITE_BUFFER_HINT, |
| 130 | CONST_CS); |
| 131 | REGISTER_LONG_CONSTANT("Grpc\\WRITE_NO_COMPRESS", GRPC_WRITE_NO_COMPRESS, |
| 132 | CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 133 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 134 | /* Register status constants */ |
| 135 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_OK", GRPC_STATUS_OK, CONST_CS); |
| 136 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_CANCELLED", GRPC_STATUS_CANCELLED, |
| 137 | CONST_CS); |
| 138 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNKNOWN", GRPC_STATUS_UNKNOWN, CONST_CS); |
| 139 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_INVALID_ARGUMENT", |
| 140 | GRPC_STATUS_INVALID_ARGUMENT, CONST_CS); |
| 141 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_DEADLINE_EXCEEDED", |
| 142 | GRPC_STATUS_DEADLINE_EXCEEDED, CONST_CS); |
| 143 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_NOT_FOUND", GRPC_STATUS_NOT_FOUND, |
| 144 | CONST_CS); |
| 145 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_ALREADY_EXISTS", |
| 146 | GRPC_STATUS_ALREADY_EXISTS, CONST_CS); |
| 147 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_PERMISSION_DENIED", |
| 148 | GRPC_STATUS_PERMISSION_DENIED, CONST_CS); |
| 149 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAUTHENTICATED", |
| 150 | GRPC_STATUS_UNAUTHENTICATED, CONST_CS); |
| 151 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_RESOURCE_EXHAUSTED", |
| 152 | GRPC_STATUS_RESOURCE_EXHAUSTED, CONST_CS); |
| 153 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_FAILED_PRECONDITION", |
| 154 | GRPC_STATUS_FAILED_PRECONDITION, CONST_CS); |
| 155 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_ABORTED", GRPC_STATUS_ABORTED, CONST_CS); |
| 156 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE, |
| 157 | CONST_CS); |
| 158 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNIMPLEMENTED", |
| 159 | GRPC_STATUS_UNIMPLEMENTED, CONST_CS); |
| 160 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_INTERNAL", GRPC_STATUS_INTERNAL, |
| 161 | CONST_CS); |
| 162 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAVAILABLE", GRPC_STATUS_UNAVAILABLE, |
| 163 | CONST_CS); |
| 164 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_DATA_LOSS", GRPC_STATUS_DATA_LOSS, |
| 165 | CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 166 | |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 167 | /* Register op type constants */ |
| 168 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_INITIAL_METADATA", |
| 169 | GRPC_OP_SEND_INITIAL_METADATA, CONST_CS); |
| 170 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_MESSAGE", |
| 171 | GRPC_OP_SEND_MESSAGE, CONST_CS); |
| 172 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_CLOSE_FROM_CLIENT", |
| 173 | GRPC_OP_SEND_CLOSE_FROM_CLIENT, CONST_CS); |
| 174 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_STATUS_FROM_SERVER", |
| 175 | GRPC_OP_SEND_STATUS_FROM_SERVER, CONST_CS); |
| 176 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_INITIAL_METADATA", |
| 177 | GRPC_OP_RECV_INITIAL_METADATA, CONST_CS); |
| 178 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_MESSAGE", |
| 179 | GRPC_OP_RECV_MESSAGE, CONST_CS); |
| 180 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_STATUS_ON_CLIENT", |
| 181 | GRPC_OP_RECV_STATUS_ON_CLIENT, CONST_CS); |
| 182 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_CLOSE_ON_SERVER", |
| 183 | GRPC_OP_RECV_CLOSE_ON_SERVER, CONST_CS); |
| 184 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 185 | grpc_init_call(TSRMLS_C); |
| 186 | grpc_init_channel(TSRMLS_C); |
| 187 | grpc_init_server(TSRMLS_C); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 188 | grpc_init_timeval(TSRMLS_C); |
| 189 | grpc_init_credentials(TSRMLS_C); |
| 190 | grpc_init_server_credentials(TSRMLS_C); |
| 191 | return SUCCESS; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 192 | } |
| 193 | /* }}} */ |
| 194 | |
| 195 | /* {{{ PHP_MSHUTDOWN_FUNCTION |
| 196 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 197 | PHP_MSHUTDOWN_FUNCTION(grpc) { |
| 198 | /* uncomment this line if you have INI entries |
| 199 | UNREGISTER_INI_ENTRIES(); |
| 200 | */ |
| 201 | grpc_shutdown_timeval(TSRMLS_C); |
| 202 | grpc_shutdown(); |
| 203 | return SUCCESS; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 204 | } |
| 205 | /* }}} */ |
| 206 | |
| 207 | /* {{{ PHP_MINFO_FUNCTION |
| 208 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 209 | PHP_MINFO_FUNCTION(grpc) { |
| 210 | php_info_print_table_start(); |
| 211 | php_info_print_table_header(2, "grpc support", "enabled"); |
| 212 | php_info_print_table_end(); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 213 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 214 | /* Remove comments if you have entries in php.ini |
| 215 | DISPLAY_INI_ENTRIES(); |
| 216 | */ |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 217 | } |
| 218 | /* }}} */ |
| 219 | /* The previous line is meant for vim and emacs, so it can correctly fold and |
| 220 | unfold functions in source code. See the corresponding marks just before |
| 221 | function definition, where the functions purpose is also documented. Please |
| 222 | follow this convention for the convenience of others editing your code. |
| 223 | */ |
| 224 | |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 225 | /* |
| 226 | * Local variables: |
| 227 | * tab-width: 4 |
| 228 | * c-basic-offset: 4 |
| 229 | * End: |
| 230 | * vim600: noet sw=4 ts=4 fdm=marker |
| 231 | * vim<600: noet sw=4 ts=4 |
| 232 | */ |