This source file includes following definitions.
- mysqlnd_example_plugin_end
- mysqlnd_example_plugin_register
- mysqlnd_plugin_subsystem_init
- mysqlnd_plugin_end_apply_func
- mysqlnd_plugin_subsystem_end
- mysqlnd_plugin_register
- mysqlnd_plugin_register_ex
- mysqlnd_plugin_find
- mysqlnd_plugin_apply_with_argument
- mysqlnd_plugin_count
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include "php.h"
23 #include "mysqlnd.h"
24 #include "mysqlnd_priv.h"
25 #include "mysqlnd_statistics.h"
26 #include "mysqlnd_debug.h"
27
28
29 #if defined(MYSQLND_DBG_ENABLED) && MYSQLND_DBG_ENABLED == 1
30 static enum_func_status mysqlnd_example_plugin_end(void * p);
31
32 static MYSQLND_STATS * mysqlnd_plugin_example_stats = NULL;
33
34 enum mysqlnd_plugin_example_collected_stats
35 {
36 EXAMPLE_STAT1,
37 EXAMPLE_STAT2,
38 EXAMPLE_STAT_LAST
39 };
40
41 static const MYSQLND_STRING mysqlnd_plugin_example_stats_values_names[EXAMPLE_STAT_LAST] =
42 {
43 { MYSQLND_STR_W_LEN("stat1") },
44 { MYSQLND_STR_W_LEN("stat2") }
45 };
46
47 static struct st_mysqlnd_typeii_plugin_example mysqlnd_example_plugin =
48 {
49 {
50 MYSQLND_PLUGIN_API_VERSION,
51 "example",
52 10001L,
53 "1.00.01",
54 "PHP License",
55 "Andrey Hristov <andrey@php.net>",
56 {
57 NULL,
58 mysqlnd_plugin_example_stats_values_names,
59 },
60 {
61 mysqlnd_example_plugin_end
62 }
63 },
64 NULL,
65 };
66
67
68
69 static
70 enum_func_status mysqlnd_example_plugin_end(void * p)
71 {
72 struct st_mysqlnd_typeii_plugin_example * plugin = (struct st_mysqlnd_typeii_plugin_example *) p;
73 DBG_ENTER("mysqlnd_example_plugin_end");
74 mysqlnd_stats_end(plugin->plugin_header.plugin_stats.values, 1);
75 plugin->plugin_header.plugin_stats.values = NULL;
76 DBG_RETURN(PASS);
77 }
78
79
80
81
82 void
83 mysqlnd_example_plugin_register(void)
84 {
85 mysqlnd_stats_init(&mysqlnd_plugin_example_stats, EXAMPLE_STAT_LAST, 1);
86 mysqlnd_example_plugin.plugin_header.plugin_stats.values = mysqlnd_plugin_example_stats;
87 mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_example_plugin);
88 }
89
90 #endif
91
92
93 static HashTable mysqlnd_registered_plugins;
94
95 static unsigned int mysqlnd_plugins_counter = 0;
96
97
98
99 void
100 mysqlnd_plugin_subsystem_init(void)
101 {
102 zend_hash_init(&mysqlnd_registered_plugins, 4 , NULL , NULL , TRUE );
103 }
104
105
106
107
108 int
109 mysqlnd_plugin_end_apply_func(zval *el)
110 {
111 struct st_mysqlnd_plugin_header * plugin_header = (struct st_mysqlnd_plugin_header *)Z_PTR_P(el);
112 if (plugin_header->m.plugin_shutdown) {
113 plugin_header->m.plugin_shutdown(plugin_header);
114 }
115 return ZEND_HASH_APPLY_REMOVE;
116 }
117
118
119
120
121 void
122 mysqlnd_plugin_subsystem_end(void)
123 {
124 zend_hash_apply(&mysqlnd_registered_plugins, mysqlnd_plugin_end_apply_func);
125 zend_hash_destroy(&mysqlnd_registered_plugins);
126 }
127
128
129
130
131 PHPAPI unsigned int mysqlnd_plugin_register()
132 {
133 return mysqlnd_plugin_register_ex(NULL);
134 }
135
136
137
138
139 PHPAPI unsigned int mysqlnd_plugin_register_ex(struct st_mysqlnd_plugin_header * plugin)
140 {
141 if (plugin) {
142 if (plugin->plugin_api_version == MYSQLND_PLUGIN_API_VERSION) {
143 zend_hash_str_update_ptr(&mysqlnd_registered_plugins, plugin->plugin_name, strlen(plugin->plugin_name), plugin);
144 } else {
145 php_error_docref(NULL, E_WARNING, "Plugin API version mismatch while loading plugin %s. Expected %d, got %d",
146 plugin->plugin_name, MYSQLND_PLUGIN_API_VERSION, plugin->plugin_api_version);
147 return 0xCAFE;
148 }
149 }
150 return mysqlnd_plugins_counter++;
151 }
152
153
154
155
156 PHPAPI void * mysqlnd_plugin_find(const char * const name)
157 {
158 void * plugin;
159 if ((plugin = zend_hash_str_find_ptr(&mysqlnd_registered_plugins, name, strlen(name))) != NULL) {
160 return plugin;
161 }
162 return NULL;
163 }
164
165
166
167
168 PHPAPI void mysqlnd_plugin_apply_with_argument(apply_func_arg_t apply_func, void * argument)
169 {
170 zval *val;
171 int result;
172
173 ZEND_HASH_FOREACH_VAL(&mysqlnd_registered_plugins, val) {
174 result = apply_func(val, argument);
175 if (result & ZEND_HASH_APPLY_REMOVE) {
176 php_error_docref(NULL, E_WARNING, "mysqlnd_plugin_apply_with_argument must not remove table entries");
177 }
178 if (result & ZEND_HASH_APPLY_STOP) {
179 break;
180 }
181 } ZEND_HASH_FOREACH_END();
182 }
183
184
185
186
187 PHPAPI unsigned int mysqlnd_plugin_count()
188 {
189 return mysqlnd_plugins_counter;
190 }
191
192
193
194
195
196
197
198
199
200
201