PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/release/src/router/php/ext/mysqli/php_mysqli_structs.h

https://gitlab.com/envieidoc/advancedtomato2
C Header | 362 lines | 263 code | 56 blank | 43 comment | 18 complexity | c649e20be6e525efc367acd6430a380d MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2014 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Georg Richter <georg@php.net> |
  16. | Andrey Hristov <andrey@php.net> |
  17. | Ulf Wendel <uw@php.net> |
  18. +----------------------------------------------------------------------+
  19. $Id$
  20. */
  21. #ifndef PHP_MYSQLI_STRUCTS_H
  22. #define PHP_MYSQLI_STRUCTS_H
  23. /* A little hack to prevent build break, when mysql is used together with
  24. * c-client, which also defines LIST.
  25. */
  26. #ifdef LIST
  27. #undef LIST
  28. #endif
  29. #ifndef TRUE
  30. #define TRUE 1
  31. #endif
  32. #ifndef FALSE
  33. #define FALSE 0
  34. #endif
  35. #ifdef MYSQLI_USE_MYSQLND
  36. #include "ext/mysqlnd/mysqlnd.h"
  37. #include "mysqli_mysqlnd.h"
  38. #else
  39. /*
  40. The libmysql headers (a PITA) also define it and there will be an warning.
  41. Undef it and later we might need to define it again.
  42. */
  43. #ifdef HAVE_MBRLEN
  44. #undef HAVE_MBRLEN
  45. #define WE_HAD_MBRLEN
  46. #endif
  47. #ifdef HAVE_MBSTATE_T
  48. #undef HAVE_MBSTATE_T
  49. #define WE_HAD_MBSTATE_T
  50. #endif
  51. #if defined(ulong) && !defined(HAVE_ULONG)
  52. #define HAVE_ULONG
  53. #endif
  54. #include <my_global.h>
  55. #if !defined(HAVE_MBRLEN) && defined(WE_HAD_MBRLEN)
  56. #define HAVE_MBRLEN 1
  57. #endif
  58. #if !defined(HAVE_MBSTATE_T) && defined(WE_HAD_MBSTATE_T)
  59. #define HAVE_MBSTATE_T 1
  60. #endif
  61. /*
  62. We need more than mysql.h because we need CHARSET_INFO in one place.
  63. This order has been borrowed from the ODBC driver. Nothing can be removed
  64. from the list of headers :(
  65. */
  66. #include <my_sys.h>
  67. #include <mysql.h>
  68. #include <errmsg.h>
  69. #include <my_list.h>
  70. #include <m_string.h>
  71. #include <mysqld_error.h>
  72. #include <my_list.h>
  73. #include <m_ctype.h>
  74. #include "mysqli_libmysql.h"
  75. #endif /* MYSQLI_USE_MYSQLND */
  76. #define MYSQLI_VERSION_ID 101009
  77. enum mysqli_status {
  78. MYSQLI_STATUS_UNKNOWN=0,
  79. MYSQLI_STATUS_CLEARED,
  80. MYSQLI_STATUS_INITIALIZED,
  81. MYSQLI_STATUS_VALID
  82. };
  83. typedef struct {
  84. char *val;
  85. ulong buflen;
  86. ulong output_len;
  87. ulong type;
  88. } VAR_BUFFER;
  89. typedef struct {
  90. unsigned int var_cnt;
  91. VAR_BUFFER *buf;
  92. zval **vars;
  93. char *is_null;
  94. } BIND_BUFFER;
  95. typedef struct {
  96. MYSQL_STMT *stmt;
  97. BIND_BUFFER param;
  98. BIND_BUFFER result;
  99. char *query;
  100. } MY_STMT;
  101. typedef struct {
  102. MYSQL *mysql;
  103. char *hash_key;
  104. zval *li_read;
  105. php_stream *li_stream;
  106. unsigned int multi_query;
  107. zend_bool persistent;
  108. #if defined(MYSQLI_USE_MYSQLND)
  109. int async_result_fetch_type;
  110. #endif
  111. } MY_MYSQL;
  112. typedef struct {
  113. void *ptr; /* resource: (mysql, result, stmt) */
  114. void *info; /* additional buffer */
  115. enum mysqli_status status; /* object status */
  116. } MYSQLI_RESOURCE;
  117. typedef struct _mysqli_object {
  118. zend_object zo;
  119. void *ptr;
  120. HashTable *prop_handler;
  121. } mysqli_object; /* extends zend_object */
  122. typedef struct st_mysqli_warning MYSQLI_WARNING;
  123. struct st_mysqli_warning {
  124. zval reason;
  125. zval sqlstate;
  126. int errorno;
  127. MYSQLI_WARNING *next;
  128. };
  129. typedef struct _mysqli_property_entry {
  130. const char *pname;
  131. size_t pname_length;
  132. int (*r_func)(mysqli_object *obj, zval **retval TSRMLS_DC);
  133. int (*w_func)(mysqli_object *obj, zval *value TSRMLS_DC);
  134. } mysqli_property_entry;
  135. typedef struct {
  136. zend_ptr_stack free_links;
  137. } mysqli_plist_entry;
  138. #ifdef PHP_WIN32
  139. #define PHP_MYSQLI_API __declspec(dllexport)
  140. #define MYSQLI_LLU_SPEC "%I64u"
  141. #define MYSQLI_LL_SPEC "%I64d"
  142. #ifndef L64
  143. #define L64(x) x##i64
  144. #endif
  145. typedef __int64 my_longlong;
  146. #else
  147. # if defined(__GNUC__) && __GNUC__ >= 4
  148. # define PHP_MYSQLI_API __attribute__ ((visibility("default")))
  149. # else
  150. # define PHP_MYSQLI_API
  151. # endif
  152. /* we need this for PRIu64 and PRId64 */
  153. #include <inttypes.h>
  154. #define MYSQLI_LLU_SPEC "%" PRIu64
  155. #define MYSQLI_LL_SPEC "%" PRId64
  156. #ifndef L64
  157. #define L64(x) x##LL
  158. #endif
  159. typedef int64_t my_longlong;
  160. #endif
  161. #ifdef ZTS
  162. #include "TSRM.h"
  163. #endif
  164. extern zend_class_entry *mysqli_link_class_entry;
  165. extern zend_class_entry *mysqli_stmt_class_entry;
  166. extern zend_class_entry *mysqli_result_class_entry;
  167. extern zend_class_entry *mysqli_driver_class_entry;
  168. extern zend_class_entry *mysqli_warning_class_entry;
  169. extern zend_class_entry *mysqli_exception_class_entry;
  170. extern int php_le_pmysqli(void);
  171. extern void php_mysqli_dtor_p_elements(void *data);
  172. extern void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status TSRMLS_DC);
  173. extern zend_object_iterator_funcs php_mysqli_result_iterator_funcs;
  174. extern zend_object_iterator *php_mysqli_result_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
  175. extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long fetchtype TSRMLS_DC);
  176. #ifdef HAVE_SPL
  177. extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
  178. #endif
  179. #define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \
  180. mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \
  181. mysql->multi_query = 0; \
  182. }
  183. #define MYSQLI_ENABLE_MQ if (!mysql->multi_query) { \
  184. mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \
  185. mysql->multi_query = 1; \
  186. }
  187. #define REGISTER_MYSQLI_CLASS_ENTRY(name, mysqli_entry, class_functions) { \
  188. zend_class_entry ce; \
  189. INIT_CLASS_ENTRY(ce, name,class_functions); \
  190. ce.create_object = mysqli_objects_new; \
  191. mysqli_entry = zend_register_internal_class(&ce TSRMLS_CC); \
  192. } \
  193. #define MYSQLI_REGISTER_RESOURCE_EX(__ptr, __zval) \
  194. ((mysqli_object *) zend_object_store_get_object(__zval TSRMLS_CC))->ptr = __ptr;
  195. #define MYSQLI_RETURN_RESOURCE(__ptr, __ce) \
  196. Z_TYPE_P(return_value) = IS_OBJECT; \
  197. (return_value)->value.obj = mysqli_objects_new(__ce TSRMLS_CC); \
  198. MYSQLI_REGISTER_RESOURCE_EX(__ptr, return_value)
  199. #define MYSQLI_REGISTER_RESOURCE(__ptr, __ce) \
  200. {\
  201. zval *object = getThis();\
  202. if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {\
  203. object = return_value;\
  204. Z_TYPE_P(object) = IS_OBJECT;\
  205. (object)->value.obj = mysqli_objects_new(__ce TSRMLS_CC);\
  206. }\
  207. MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\
  208. }
  209. #define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \
  210. { \
  211. MYSQLI_RESOURCE *my_res; \
  212. mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
  213. if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {\
  214. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
  215. RETURN_NULL();\
  216. }\
  217. __ptr = (__type)my_res->ptr; \
  218. if (__check && my_res->status < __check) { \
  219. php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
  220. RETURN_NULL();\
  221. }\
  222. }
  223. #define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \
  224. { \
  225. MYSQLI_RESOURCE *my_res; \
  226. if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\
  227. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
  228. return;\
  229. }\
  230. __ptr = (__type)my_res->ptr; \
  231. if (__check && my_res->status < __check) { \
  232. php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
  233. return;\
  234. }\
  235. }
  236. #define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \
  237. { \
  238. MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
  239. if (!(__ptr)->mysql) { \
  240. mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
  241. php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
  242. RETURN_NULL();\
  243. } \
  244. }
  245. #define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \
  246. { \
  247. MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
  248. if (!(__ptr)->stmt) { \
  249. mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
  250. php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
  251. RETURN_NULL();\
  252. } \
  253. }
  254. #define MYSQLI_SET_STATUS(__id, __value) \
  255. { \
  256. mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
  257. ((MYSQLI_RESOURCE *)intern->ptr)->status = __value; \
  258. } \
  259. #define MYSQLI_CLEAR_RESOURCE(__id) \
  260. { \
  261. mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
  262. efree(intern->ptr); \
  263. intern->ptr = NULL; \
  264. }
  265. ZEND_BEGIN_MODULE_GLOBALS(mysqli)
  266. long default_link;
  267. long num_links;
  268. long max_links;
  269. long num_active_persistent;
  270. long num_inactive_persistent;
  271. long max_persistent;
  272. long allow_persistent;
  273. unsigned long default_port;
  274. char *default_host;
  275. char *default_user;
  276. char *default_socket;
  277. char *default_pw;
  278. long reconnect;
  279. long allow_local_infile;
  280. long strict;
  281. long error_no;
  282. char *error_msg;
  283. long report_mode;
  284. HashTable *report_ht;
  285. unsigned long multi_query;
  286. unsigned long embedded;
  287. ZEND_END_MODULE_GLOBALS(mysqli)
  288. #ifdef ZTS
  289. #define MyG(v) TSRMG(mysqli_globals_id, zend_mysqli_globals *, v)
  290. #else
  291. #define MyG(v) (mysqli_globals.v)
  292. #endif
  293. #define my_estrdup(x) (x) ? estrdup(x) : NULL
  294. #define my_efree(x) if (x) efree(x)
  295. ZEND_EXTERN_MODULE_GLOBALS(mysqli)
  296. #endif /* PHP_MYSQLI_STRUCTS.H */
  297. /*
  298. * Local variables:
  299. * tab-width: 4
  300. * c-basic-offset: 4
  301. * indent-tabs-mode: t
  302. * End:
  303. * vim600: noet sw=4 ts=4 fdm=marker
  304. * vim<600: noet sw=4 ts=4
  305. */