Annotation of embedaddon/php/ext/mysqli/php_mysqli_structs.h, revision 1.1.1.2

1.1       misho       1: /*
                      2:   +----------------------------------------------------------------------+
                      3:   | PHP Version 5                                                        |
                      4:   +----------------------------------------------------------------------+
                      5:   | Copyright (c) 1997-2012 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:   +----------------------------------------------------------------------+
1.1.1.2 ! misho      15:   | Authors: Georg Richter <georg@php.net>                               |
        !            16:   |          Andrey Hristov <andrey@php.net>                             |
        !            17:   |          Ulf Wendel <uw@php.net>                                     |
1.1       misho      18:   +----------------------------------------------------------------------+
                     19: 
1.1.1.2 ! misho      20:   $Id$
1.1       misho      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: } MY_STMT;
                    120: 
                    121: typedef struct {
                    122:        MYSQL                   *mysql;
                    123:        char                    *hash_key;
                    124:        zval                    *li_read;
                    125:        php_stream              *li_stream;
                    126:        unsigned int    multi_query;
                    127:        zend_bool               persistent;
                    128: #if defined(MYSQLI_USE_MYSQLND)
                    129:        int                             async_result_fetch_type;
                    130: #endif
                    131: } MY_MYSQL;
                    132: 
                    133: typedef struct {
                    134:        int                     mode;
                    135:        int                     socket;
                    136:        FILE            *fp;
                    137: } PROFILER;
                    138: 
                    139: typedef struct {
                    140:        void                            *ptr;           /* resource: (mysql, result, stmt)   */
                    141:        void                            *info;          /* additional buffer                             */
                    142:        enum mysqli_status      status;         /* object status */
                    143: } MYSQLI_RESOURCE;
                    144: 
                    145: typedef struct _mysqli_object {
                    146:        zend_object             zo;
                    147:        void                            *ptr;
                    148:        HashTable                       *prop_handler;
                    149: } mysqli_object; /* extends zend_object */
                    150: 
                    151: typedef struct st_mysqli_warning MYSQLI_WARNING;
                    152: 
                    153: struct st_mysqli_warning {
                    154:        zval    reason;
                    155:        zval    sqlstate;
                    156:        int             errorno;
                    157:        MYSQLI_WARNING  *next;
                    158: };
                    159: 
                    160: typedef struct _mysqli_property_entry {
                    161:        const char *pname;
                    162:        size_t pname_length;
                    163:        int (*r_func)(mysqli_object *obj, zval **retval TSRMLS_DC);
                    164:        int (*w_func)(mysqli_object *obj, zval *value TSRMLS_DC);
                    165: } mysqli_property_entry;
                    166: 
                    167: #if !defined(MYSQLI_USE_MYSQLND)
                    168: typedef struct {
                    169:        char    error_msg[LOCAL_INFILE_ERROR_LEN];
                    170:        void    *userdata;
                    171: } mysqli_local_infile;
                    172: #endif
                    173: 
                    174: typedef struct {
                    175:        zend_ptr_stack free_links;
                    176: } mysqli_plist_entry;
                    177: 
                    178: #ifdef PHP_WIN32
                    179: #define PHP_MYSQLI_API __declspec(dllexport)
                    180: #define MYSQLI_LLU_SPEC "%I64u"
                    181: #define MYSQLI_LL_SPEC "%I64d"
                    182: #ifndef L64
                    183: #define L64(x) x##i64
                    184: #endif
                    185: typedef __int64 my_longlong;
                    186: #else
                    187: # if defined(__GNUC__) && __GNUC__ >= 4
                    188: #  define PHP_MYSQLI_API __attribute__ ((visibility("default")))
                    189: # else
                    190: #  define PHP_MYSQLI_API
                    191: # endif
                    192: /* we need this for PRIu64 and PRId64 */
                    193: #include <inttypes.h>
                    194: #define MYSQLI_LLU_SPEC "%" PRIu64
                    195: #define MYSQLI_LL_SPEC "%" PRId64
                    196: #ifndef L64
                    197: #define L64(x) x##LL
                    198: #endif
                    199: typedef int64_t my_longlong;
                    200: #endif
                    201: 
                    202: #ifdef ZTS
                    203: #include "TSRM.h"
                    204: #endif
                    205: 
                    206: extern zend_class_entry *mysqli_link_class_entry;
                    207: extern zend_class_entry *mysqli_stmt_class_entry;
                    208: extern zend_class_entry *mysqli_result_class_entry;
                    209: extern zend_class_entry *mysqli_driver_class_entry;
                    210: extern zend_class_entry *mysqli_warning_class_entry;
                    211: extern zend_class_entry *mysqli_exception_class_entry;
1.1.1.2 ! misho     212: extern int php_le_pmysqli(void);
        !           213: extern void php_mysqli_dtor_p_elements(void *data);
        !           214: 
        !           215: extern void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status TSRMLS_DC);
        !           216: 
        !           217: extern zend_object_iterator_funcs php_mysqli_result_iterator_funcs;
        !           218: extern zend_object_iterator *php_mysqli_result_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
        !           219: 
        !           220: extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long fetchtype TSRMLS_DC);
        !           221: 
        !           222: #ifdef HAVE_SPL
        !           223: extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
        !           224: #endif
        !           225: 
        !           226: #define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \
        !           227:        mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \
        !           228:        mysql->multi_query = 0; \
        !           229: }
        !           230: 
        !           231: #define MYSQLI_ENABLE_MQ if (!mysql->multi_query) { \
        !           232:        mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \
        !           233:        mysql->multi_query = 1; \
        !           234: }
        !           235: 
        !           236: #define REGISTER_MYSQLI_CLASS_ENTRY(name, mysqli_entry, class_functions) { \
        !           237:        zend_class_entry ce; \
        !           238:        INIT_CLASS_ENTRY(ce, name,class_functions); \
        !           239:        ce.create_object = mysqli_objects_new; \
        !           240:        mysqli_entry = zend_register_internal_class(&ce TSRMLS_CC); \
        !           241: } \
1.1       misho     242: 
                    243: #define MYSQLI_REGISTER_RESOURCE_EX(__ptr, __zval)  \
                    244:        ((mysqli_object *) zend_object_store_get_object(__zval TSRMLS_CC))->ptr = __ptr;
                    245: 
                    246: #define MYSQLI_RETURN_RESOURCE(__ptr, __ce) \
                    247:        Z_TYPE_P(return_value) = IS_OBJECT; \
                    248:        (return_value)->value.obj = mysqli_objects_new(__ce TSRMLS_CC); \
                    249:        MYSQLI_REGISTER_RESOURCE_EX(__ptr, return_value)
                    250: 
                    251: #define MYSQLI_REGISTER_RESOURCE(__ptr, __ce) \
                    252: {\
                    253:        zval *object = getThis();\
                    254:        if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {\
                    255:                object = return_value;\
                    256:                Z_TYPE_P(object) = IS_OBJECT;\
                    257:                (object)->value.obj = mysqli_objects_new(__ce TSRMLS_CC);\
                    258:        }\
                    259:        MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\
                    260: }
                    261: 
                    262: #define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \
                    263: { \
                    264:        MYSQLI_RESOURCE *my_res; \
                    265:        mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
                    266:        if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {\
                    267:                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
                    268:                RETURN_NULL();\
                    269:        }\
                    270:        __ptr = (__type)my_res->ptr; \
                    271:        if (__check && my_res->status < __check) { \
                    272:                php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
                    273:                RETURN_NULL();\
                    274:        }\
                    275: }
                    276: 
1.1.1.2 ! misho     277: #define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \
        !           278: { \
        !           279:        MYSQLI_RESOURCE *my_res; \
        !           280:        if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\
        !           281:                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
        !           282:                return;\
        !           283:        }\
        !           284:        __ptr = (__type)my_res->ptr; \
        !           285:        if (__check && my_res->status < __check) { \
        !           286:                php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
        !           287:                return;\
        !           288:        }\
        !           289: }
        !           290: 
        !           291: 
1.1       misho     292: #define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \
                    293: { \
                    294:        MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
                    295:        if (!(__ptr)->mysql) { \
                    296:                mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
                    297:                php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
                    298:                RETURN_NULL();\
                    299:        } \
                    300: }
                    301: 
                    302: #define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \
                    303: { \
                    304:        MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
                    305:        if (!(__ptr)->stmt) { \
                    306:                mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
                    307:                php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
                    308:                RETURN_NULL();\
                    309:        } \
                    310: }
                    311: 
                    312: 
                    313: #define MYSQLI_SET_STATUS(__id, __value) \
                    314: { \
                    315:        mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
                    316:        ((MYSQLI_RESOURCE *)intern->ptr)->status = __value; \
                    317: } \
                    318: 
                    319: #define MYSQLI_CLEAR_RESOURCE(__id) \
                    320: { \
                    321:        mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
                    322:        efree(intern->ptr); \
                    323:        intern->ptr = NULL; \
                    324: }
                    325: 
                    326: 
                    327: ZEND_BEGIN_MODULE_GLOBALS(mysqli)
                    328:        long                    default_link;
                    329:        long                    num_links;
                    330:        long                    max_links;
                    331:        long                    num_active_persistent;
                    332:        long                    num_inactive_persistent;
                    333:        long                    max_persistent;
                    334:        long                    allow_persistent;
                    335:        unsigned long   default_port;
                    336:        char                    *default_host;
                    337:        char                    *default_user;
                    338:        char                    *default_socket;
                    339:        char                    *default_pw;
                    340:        long                    reconnect;
                    341:        long                    allow_local_infile;
                    342:        long                    strict;
                    343:        long                    error_no;
                    344:        char                    *error_msg;
                    345:        long                    report_mode;
                    346:        HashTable               *report_ht;
                    347:        unsigned long   multi_query;
                    348:        unsigned long   embedded;
                    349: ZEND_END_MODULE_GLOBALS(mysqli)
                    350: 
                    351: 
                    352: #ifdef ZTS
                    353: #define MyG(v) TSRMG(mysqli_globals_id, zend_mysqli_globals *, v)
                    354: #else
                    355: #define MyG(v) (mysqli_globals.v)
                    356: #endif
                    357: 
                    358: #define my_estrdup(x) (x) ? estrdup(x) : NULL
                    359: #define my_efree(x) if (x) efree(x)
                    360: 
                    361: ZEND_EXTERN_MODULE_GLOBALS(mysqli)
                    362: 
                    363: #endif /* PHP_MYSQLI_STRUCTS.H */
                    364: 
                    365: 
                    366: /*
                    367:  * Local variables:
                    368:  * tab-width: 4
                    369:  * c-basic-offset: 4
                    370:  * indent-tabs-mode: t
                    371:  * End:
                    372:  * vim600: noet sw=4 ts=4 fdm=marker
                    373:  * vim<600: noet sw=4 ts=4
                    374:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>