php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
mysqlnd_plugin.c
Go to the documentation of this file.
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 | Ulf Wendel <uw@php.net> |
15 +----------------------------------------------------------------------+
16*/
17
18#include "php.h"
19#include "mysqlnd.h"
20#include "mysqlnd_priv.h"
21#include "mysqlnd_statistics.h"
22#include "mysqlnd_debug.h"
23
24/*--------------------------------------------------------------------*/
25#if MYSQLND_DBG_ENABLED == 1
26static enum_func_status mysqlnd_example_plugin_end(void * p);
27
28static MYSQLND_STATS * mysqlnd_plugin_example_stats = NULL;
29
30enum mysqlnd_plugin_example_collected_stats
31{
32 EXAMPLE_STAT1,
33 EXAMPLE_STAT2,
34 EXAMPLE_STAT_LAST
35};
36
37static const MYSQLND_STRING mysqlnd_plugin_example_stats_values_names[EXAMPLE_STAT_LAST] =
38{
39 { MYSQLND_STR_W_LEN("stat1") },
40 { MYSQLND_STR_W_LEN("stat2") }
41};
42
43static struct st_mysqlnd_typeii_plugin_example mysqlnd_example_plugin =
44{
45 {
47 "example",
48 10001L,
49 "1.00.01",
50 "PHP License",
51 "Andrey Hristov <andrey@php.net>",
52 {
53 NULL, /* will be filled later */
54 mysqlnd_plugin_example_stats_values_names,
55 },
56 {
57 mysqlnd_example_plugin_end
58 }
59 },
60 NULL, /* methods */
61 0
62};
63
64
65/* {{{ mysqlnd_example_plugin_end */
66static
67enum_func_status mysqlnd_example_plugin_end(void * p)
68{
70 DBG_ENTER("mysqlnd_example_plugin_end");
74}
75/* }}} */
76
77
78/* {{{ mysqlnd_example_plugin_register */
79void
81{
82 mysqlnd_stats_init(&mysqlnd_plugin_example_stats, EXAMPLE_STAT_LAST, 1);
83 mysqlnd_example_plugin.plugin_header.plugin_stats.values = mysqlnd_plugin_example_stats;
84 mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_example_plugin);
85}
86/* }}} */
87#endif /* MYSQLND_DBG_ENABLED == 1 */
88/*--------------------------------------------------------------------*/
89
90static HashTable mysqlnd_registered_plugins;
91
92static unsigned int mysqlnd_plugins_counter = 0;
93
94
95/* {{{ mysqlnd_plugin_subsystem_init */
96void
98{
99 zend_hash_init(&mysqlnd_registered_plugins, 4 /* initial hash size */, NULL /* hash_func */, NULL /* dtor */, TRUE /* pers */);
100}
101/* }}} */
102
103
104/* {{{ mysqlnd_plugin_end_apply_func */
105int
107{
108 struct st_mysqlnd_plugin_header * plugin_header = (struct st_mysqlnd_plugin_header *)Z_PTR_P(el);
109 if (plugin_header->m.plugin_shutdown) {
110 plugin_header->m.plugin_shutdown(plugin_header);
111 }
113}
114/* }}} */
115
116
117/* {{{ mysqlnd_plugin_subsystem_end */
118void
120{
121 zend_hash_apply(&mysqlnd_registered_plugins, mysqlnd_plugin_end_apply_func);
122 zend_hash_destroy(&mysqlnd_registered_plugins);
123}
124/* }}} */
125
126
127/* {{{ mysqlnd_plugin_register */
129{
131}
132/* }}} */
133
134
135/* {{{ mysqlnd_plugin_register_ex */
137{
138 if (plugin) {
140 zend_hash_str_update_ptr(&mysqlnd_registered_plugins, plugin->plugin_name, strlen(plugin->plugin_name), plugin);
141 } else {
142 php_error_docref(NULL, E_WARNING, "Plugin API version mismatch while loading plugin %s. Expected %d, got %d",
144 return 0xCAFE;
145 }
146 }
147 return mysqlnd_plugins_counter++;
148}
149/* }}} */
150
151
152/* {{{ mysqlnd_plugin_find */
153PHPAPI void * mysqlnd_plugin_find(const char * const name)
154{
155 void * plugin;
156 if ((plugin = zend_hash_str_find_ptr(&mysqlnd_registered_plugins, name, strlen(name))) != NULL) {
157 return plugin;
158 }
159 return NULL;
160}
161/* }}} */
162
163
164/* {{{ mysqlnd_plugin_apply_with_argument */
166{
167 zval *val;
168 int result;
169
170 ZEND_HASH_MAP_FOREACH_VAL(&mysqlnd_registered_plugins, val) {
171 result = apply_func(val, argument);
173 php_error_docref(NULL, E_WARNING, "mysqlnd_plugin_apply_with_argument must not remove table entries");
174 }
176 break;
177 }
179}
180/* }}} */
181
182
183/* {{{ mysqlnd_plugin_count */
184PHPAPI unsigned int mysqlnd_plugin_count(void)
185{
186 return mysqlnd_plugins_counter;
187}
188/* }}} */
zval * val
Definition ffi.c:4262
#define TRUE
Definition gd_gd.c:7
#define NULL
Definition gdcache.h:45
#define PASS(tables)
Definition hash_gost.c:193
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
#define MYSQLND_PLUGIN_API_VERSION
Definition mysqlnd.h:25
#define MYSQLND_STR_W_LEN(str)
Definition mysqlnd.h:58
#define DBG_RETURN(value)
enum func_status enum_func_status
PHPAPI unsigned int mysqlnd_plugin_count(void)
PHPAPI unsigned int mysqlnd_plugin_register(void)
PHPAPI void mysqlnd_plugin_apply_with_argument(apply_func_arg_t apply_func, void *argument)
void mysqlnd_plugin_subsystem_init(void)
PHPAPI unsigned int mysqlnd_plugin_register_ex(struct st_mysqlnd_plugin_header *plugin)
PHPAPI void * mysqlnd_plugin_find(const char *const name)
void mysqlnd_plugin_subsystem_end(void)
int mysqlnd_plugin_end_apply_func(zval *el)
void mysqlnd_example_plugin_register(void)
PHPAPI void mysqlnd_stats_end(MYSQLND_STATS *stats, const bool persistent)
PHPAPI void mysqlnd_stats_init(MYSQLND_STATS **stats, const size_t statistic_count, const bool persistent)
struct st_mysqlnd_string MYSQLND_STRING
struct st_mysqlnd_stats MYSQLND_STATS
#define PHPAPI
Definition php.h:71
p
Definition session.c:1105
enum_func_status(* plugin_shutdown)(void *plugin)
struct st_mysqlnd_plugin_header::@230331340146370337307336142341316306046071113111 plugin_stats
struct st_mysqlnd_plugin_header::@062367037263132256212260151337323046270005127260 m
struct st_mysqlnd_plugin_header plugin_header
struct _zval_struct zval
strlen(string $string)
#define E_WARNING
Definition zend_errors.h:24
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
ZEND_API void ZEND_FASTCALL zend_hash_apply(HashTable *ht, apply_func_t apply_func)
Definition zend_hash.c:2059
int(* apply_func_arg_t)(zval *pDest, void *argument)
Definition zend_hash.h:151
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
Definition zend_hash.h:108
#define ZEND_HASH_MAP_FOREACH_VAL(ht, _val)
Definition zend_hash.h:1310
#define ZEND_HASH_APPLY_STOP
Definition zend_hash.h:148
#define ZEND_HASH_APPLY_REMOVE
Definition zend_hash.h:147
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
struct _zend_array HashTable
Definition zend_types.h:386
#define Z_PTR_P(zval_p)
zend_string * name
bool result