mysqlnd_priv.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2006-2016 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: Andrey Hristov <andrey@mysql.com> |
  16. | Ulf Wendel <uwendel@mysql.com> |
  17. | Georg Richter <georg@mysql.com> |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* $Id$ */
  21. #ifndef MYSQLND_PRIV_H
  22. #define MYSQLND_PRIV_H
  23. #ifndef Z_ADDREF_P
  24. /* PHP 5.2, old GC */
  25. #define Z_ADDREF_P(pz) (++(pz)->refcount)
  26. #define Z_DELREF_P(pz) (--(pz)->refcount)
  27. #define Z_REFCOUNT_P(pz) ((pz)->refcount)
  28. #define Z_SET_REFCOUNT_P(pz, rc) ((pz)->refcount = rc)
  29. #define Z_REFCOUNT_PP(ppz) Z_REFCOUNT_P(*(ppz))
  30. #define Z_DELREF_PP(ppz) Z_DELREF_P(*(ppz))
  31. #endif
  32. #ifdef ZTS
  33. #include "TSRM.h"
  34. #endif
  35. #ifndef pestrndup
  36. #define pestrndup(s, length, persistent) ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))
  37. #endif
  38. #define mysqlnd_array_init(arg, field_count) \
  39. { \
  40. ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));\
  41. zend_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0); \
  42. Z_TYPE_P(arg) = IS_ARRAY;\
  43. }
  44. #define MYSQLND_STR_W_LEN(str) str, (sizeof(str) - 1)
  45. #define MYSQLND_DEBUG_DUMP_TIME 1
  46. #define MYSQLND_DEBUG_DUMP_TRACE 2
  47. #define MYSQLND_DEBUG_DUMP_PID 4
  48. #define MYSQLND_DEBUG_DUMP_LINE 8
  49. #define MYSQLND_DEBUG_DUMP_FILE 16
  50. #define MYSQLND_DEBUG_DUMP_LEVEL 32
  51. #define MYSQLND_DEBUG_APPEND 64
  52. #define MYSQLND_DEBUG_FLUSH 128
  53. #define MYSQLND_DEBUG_TRACE_MEMORY_CALLS 256
  54. #define MYSQLND_DEBUG_PROFILE_CALLS 512
  55. /* Client Error codes */
  56. #define CR_UNKNOWN_ERROR 2000
  57. #define CR_CONNECTION_ERROR 2002
  58. #define CR_SERVER_GONE_ERROR 2006
  59. #define CR_OUT_OF_MEMORY 2008
  60. #define CR_SERVER_LOST 2013
  61. #define CR_COMMANDS_OUT_OF_SYNC 2014
  62. #define CR_CANT_FIND_CHARSET 2019
  63. #define CR_MALFORMED_PACKET 2027
  64. #define CR_NOT_IMPLEMENTED 2054
  65. #define CR_NO_PREPARE_STMT 2030
  66. #define CR_PARAMS_NOT_BOUND 2031
  67. #define CR_INVALID_PARAMETER_NO 2034
  68. #define CR_INVALID_BUFFER_USE 2035
  69. #define MYSQLND_EE_FILENOTFOUND 7890
  70. #define UNKNOWN_SQLSTATE "HY000"
  71. #define MAX_CHARSET_LEN 32
  72. #define SET_ERROR_AFF_ROWS(s) (s)->upsert_status->affected_rows = (uint64_t) ~0
  73. /* Error handling */
  74. #define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
  75. {\
  76. if ((buf)) { \
  77. mnd_pefree((buf), (persistent)); \
  78. } \
  79. if ((message)) { \
  80. (buf) = mnd_pestrndup((message), (len), (persistent)); \
  81. } else { \
  82. (buf) = NULL; \
  83. } \
  84. (buf_len) = (len); \
  85. }
  86. #define SET_EMPTY_MESSAGE(buf, buf_len, persistent) \
  87. {\
  88. if ((buf)) { \
  89. mnd_pefree((buf), (persistent)); \
  90. (buf) = NULL; \
  91. } \
  92. (buf_len) = 0; \
  93. }
  94. #define SET_EMPTY_ERROR(error_info) \
  95. { \
  96. (error_info).error_no = 0; \
  97. (error_info).error[0] = '\0'; \
  98. strlcpy((error_info).sqlstate, "00000", sizeof((error_info).sqlstate)); \
  99. if ((error_info).error_list) { \
  100. zend_llist_clean((error_info).error_list); \
  101. } \
  102. }
  103. #define SET_CLIENT_ERROR(error_info, a, b, c) \
  104. { \
  105. if (0 == (a)) { \
  106. SET_EMPTY_ERROR((error_info)); \
  107. } else { \
  108. (error_info).error_no = (a); \
  109. strlcpy((error_info).sqlstate, (b), sizeof((error_info).sqlstate)); \
  110. strlcpy((error_info).error, (c), sizeof((error_info).error)); \
  111. if ((error_info).error_list) {\
  112. MYSQLND_ERROR_LIST_ELEMENT error_for_the_list = {0}; \
  113. \
  114. error_for_the_list.error_no = (a); \
  115. strlcpy(error_for_the_list.sqlstate, (b), sizeof(error_for_the_list.sqlstate)); \
  116. error_for_the_list.error = mnd_pestrdup((c), TRUE); \
  117. if (error_for_the_list.error) { \
  118. DBG_INF_FMT("adding error [%s] to the list", error_for_the_list.error); \
  119. zend_llist_add_element((error_info).error_list, &error_for_the_list); \
  120. } \
  121. } \
  122. } \
  123. }
  124. #define COPY_CLIENT_ERROR(error_info_to, error_info_from) \
  125. { \
  126. SET_CLIENT_ERROR((error_info_to), (error_info_from).error_no, (error_info_from).sqlstate, (error_info_from).error); \
  127. }
  128. #define SET_OOM_ERROR(error_info) SET_CLIENT_ERROR((error_info), CR_OUT_OF_MEMORY, UNKNOWN_SQLSTATE, mysqlnd_out_of_memory)
  129. #define SET_STMT_ERROR(stmt, a, b, c) SET_CLIENT_ERROR(*(stmt)->error_info, a, b, c)
  130. #define CONN_GET_STATE(c) (c)->m->get_state((c) TSRMLS_CC)
  131. #define CONN_SET_STATE(c, s) (c)->m->set_state((c), (s) TSRMLS_CC)
  132. /* PS stuff */
  133. typedef void (*ps_field_fetch_func)(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_len, zend_uchar ** row TSRMLS_DC);
  134. struct st_mysqlnd_perm_bind {
  135. ps_field_fetch_func func;
  136. /* should be signed int */
  137. int pack_len;
  138. unsigned int php_type;
  139. zend_bool is_possibly_blob;
  140. zend_bool can_ret_as_str_in_uni;
  141. };
  142. extern struct st_mysqlnd_perm_bind mysqlnd_ps_fetch_functions[MYSQL_TYPE_LAST + 1];
  143. enum_func_status mysqlnd_stmt_fetch_row_buffered(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * fetched_anything TSRMLS_DC);
  144. enum_func_status mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * fetched_anything TSRMLS_DC);
  145. PHPAPI extern const char * const mysqlnd_old_passwd;
  146. PHPAPI extern const char * const mysqlnd_out_of_sync;
  147. PHPAPI extern const char * const mysqlnd_server_gone;
  148. PHPAPI extern const char * const mysqlnd_out_of_memory;
  149. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_object_factory);
  150. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_conn);
  151. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_conn_data);
  152. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_res);
  153. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_result_unbuffered);
  154. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_result_buffered);
  155. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_protocol);
  156. PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_net);
  157. enum_func_status mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * filename, zend_bool * is_warning TSRMLS_DC);
  158. void _mysqlnd_init_ps_subsystem();/* This one is private, mysqlnd_library_init() will call it */
  159. void _mysqlnd_init_ps_fetch_subsystem();
  160. void ps_fetch_from_1_to_8_bytes(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_len, zend_uchar ** row, unsigned int byte_count TSRMLS_DC);
  161. void mysqlnd_plugin_subsystem_init(TSRMLS_D);
  162. void mysqlnd_plugin_subsystem_end(TSRMLS_D);
  163. void mysqlnd_register_builtin_authentication_plugins(TSRMLS_D);
  164. void mysqlnd_example_plugin_register(TSRMLS_D);
  165. struct st_mysqlnd_packet_greet;
  166. struct st_mysqlnd_authentication_plugin;
  167. enum_func_status
  168. mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
  169. const char * const user,
  170. const char * const passwd,
  171. const size_t passwd_len,
  172. const char * const db,
  173. const size_t db_len,
  174. const MYSQLND_OPTIONS * const options,
  175. unsigned long mysql_flags,
  176. unsigned int server_charset_no,
  177. zend_bool use_full_blown_auth_packet,
  178. const char * const auth_protocol,
  179. const zend_uchar * const auth_plugin_data,
  180. const size_t auth_plugin_data_len,
  181. char ** switch_to_auth_protocol,
  182. size_t * switch_to_auth_protocol_len,
  183. zend_uchar ** switch_to_auth_protocol_data,
  184. size_t * switch_to_auth_protocol_data_len
  185. TSRMLS_DC);
  186. enum_func_status
  187. mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
  188. const char * const user,
  189. const size_t user_len,
  190. const char * const passwd,
  191. const size_t passwd_len,
  192. const char * const db,
  193. const size_t db_len,
  194. const zend_bool silent,
  195. zend_bool use_full_blown_auth_packet,
  196. const char * const auth_protocol,
  197. zend_uchar * auth_plugin_data,
  198. size_t auth_plugin_data_len,
  199. char ** switch_to_auth_protocol,
  200. size_t * switch_to_auth_protocol_len,
  201. zend_uchar ** switch_to_auth_protocol_data,
  202. size_t * switch_to_auth_protocol_data_len
  203. TSRMLS_DC);
  204. #endif /* MYSQLND_PRIV_H */
  205. /*
  206. * Local variables:
  207. * tab-width: 4
  208. * c-basic-offset: 4
  209. * End:
  210. * vim600: noet sw=4 ts=4 fdm=marker
  211. * vim<600: noet sw=4 ts=4
  212. */