root/ext/mysqli/php_mysqli_structs.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */