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