xref: /php-src/ext/mysqlnd/mysqlnd_reverse_api.c (revision 90b7bde6)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Authors: Andrey Hristov <andrey@php.net>                             |
14   |          Johannes Schlüter <johannes@php.net>                        |
15   |          Ulf Wendel <uw@php.net>                                     |
16   +----------------------------------------------------------------------+
17 */
18 
19 #include "php.h"
20 #include "mysqlnd.h"
21 #include "mysqlnd_priv.h"
22 #include "mysqlnd_debug.h"
23 #include "mysqlnd_reverse_api.h"
24 
25 
26 static HashTable mysqlnd_api_ext_ht;
27 
28 
29 /* {{{ mysqlnd_reverse_api_init */
30 PHPAPI void
mysqlnd_reverse_api_init(void)31 mysqlnd_reverse_api_init(void)
32 {
33 	zend_hash_init(&mysqlnd_api_ext_ht, 3, NULL, NULL, 1);
34 }
35 /* }}} */
36 
37 
38 /* {{{ mysqlnd_reverse_api_end */
39 PHPAPI void
mysqlnd_reverse_api_end(void)40 mysqlnd_reverse_api_end(void)
41 {
42 	zend_hash_destroy(&mysqlnd_api_ext_ht);
43 }
44 /* }}} */
45 
46 
47 /* {{{ myslqnd_get_api_extensions */
48 PHPAPI HashTable *
mysqlnd_reverse_api_get_api_list(void)49 mysqlnd_reverse_api_get_api_list(void)
50 {
51 	return &mysqlnd_api_ext_ht;
52 }
53 /* }}} */
54 
55 
56 /* {{{ mysqlnd_reverse_api_register_api */
57 PHPAPI void
mysqlnd_reverse_api_register_api(const MYSQLND_REVERSE_API * apiext)58 mysqlnd_reverse_api_register_api(const MYSQLND_REVERSE_API * apiext)
59 {
60 	zend_hash_str_add_ptr(&mysqlnd_api_ext_ht, apiext->module->name, strlen(apiext->module->name), (void*)apiext);
61 }
62 /* }}} */
63 
64 
65 /* {{{ zval_to_mysqlnd */
66 PHPAPI MYSQLND *
zval_to_mysqlnd(zval * zv,const unsigned int client_api_capabilities,unsigned int * save_client_api_capabilities)67 zval_to_mysqlnd(zval * zv, const unsigned int client_api_capabilities, unsigned int * save_client_api_capabilities)
68 {
69 	MYSQLND_REVERSE_API *api;
70 	ZEND_HASH_MAP_FOREACH_PTR(&mysqlnd_api_ext_ht, api) {
71 		if (api->conversion_cb) {
72 			MYSQLND *retval = api->conversion_cb(zv);
73 			if (retval) {
74 				if (retval->data) {
75 					*save_client_api_capabilities = retval->data->m->negotiate_client_api_capabilities(retval->data, client_api_capabilities);
76 				}
77 				return retval;
78 			}
79 		}
80 	} ZEND_HASH_FOREACH_END();
81 	return NULL;
82 }
83 /* }}} */
84