mysqlnd_reverse_api.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "php.h"
  19. #include "mysqlnd.h"
  20. #include "mysqlnd_priv.h"
  21. #include "mysqlnd_debug.h"
  22. #include "mysqlnd_reverse_api.h"
  23. static HashTable mysqlnd_api_ext_ht;
  24. /* {{{ mysqlnd_reverse_api_init */
  25. PHPAPI void
  26. mysqlnd_reverse_api_init(void)
  27. {
  28. zend_hash_init(&mysqlnd_api_ext_ht, 3, NULL, NULL, 1);
  29. }
  30. /* }}} */
  31. /* {{{ mysqlnd_reverse_api_end */
  32. PHPAPI void
  33. mysqlnd_reverse_api_end(void)
  34. {
  35. zend_hash_destroy(&mysqlnd_api_ext_ht);
  36. }
  37. /* }}} */
  38. /* {{{ myslqnd_get_api_extensions */
  39. PHPAPI HashTable *
  40. mysqlnd_reverse_api_get_api_list(void)
  41. {
  42. return &mysqlnd_api_ext_ht;
  43. }
  44. /* }}} */
  45. /* {{{ mysqlnd_reverse_api_register_api */
  46. PHPAPI void
  47. mysqlnd_reverse_api_register_api(const MYSQLND_REVERSE_API * apiext)
  48. {
  49. zend_hash_str_add_ptr(&mysqlnd_api_ext_ht, apiext->module->name, strlen(apiext->module->name), (void*)apiext);
  50. }
  51. /* }}} */
  52. /* {{{ zval_to_mysqlnd */
  53. PHPAPI MYSQLND *
  54. zval_to_mysqlnd(zval * zv, const unsigned int client_api_capabilities, unsigned int * save_client_api_capabilities)
  55. {
  56. MYSQLND_REVERSE_API *api;
  57. ZEND_HASH_FOREACH_PTR(&mysqlnd_api_ext_ht, api) {
  58. if (api->conversion_cb) {
  59. MYSQLND *retval = api->conversion_cb(zv);
  60. if (retval) {
  61. if (retval->data) {
  62. *save_client_api_capabilities = retval->data->m->negotiate_client_api_capabilities(retval->data, client_api_capabilities);
  63. }
  64. return retval;
  65. }
  66. }
  67. } ZEND_HASH_FOREACH_END();
  68. return NULL;
  69. }
  70. /* }}} */