]> granicus.if.org Git - php/commitdiff
MDNR:
authorAndrey Hristov <andrey@php.net>
Mon, 12 Oct 2015 12:57:48 +0000 (14:57 +0200)
committerAndrey Hristov <andrey@php.net>
Thu, 12 Nov 2015 15:19:16 +0000 (16:19 +0100)
- removed init() method from mysqlnd_conn_data and moved the initialization
  to the object factory->get_connection(). Now it is unified as with the prepared
  statement which doesn't have any init() method
- the protocol decoder factory now takes connection as parameter at creation and
  thus there is no need to pass the connection as parameter when calling the read
  or the write method of a packet.
- saved the protocol payload decoder factory as pointer in every packet (read/write)
  so the connection doesn't need to be passed on every call of read/write (dependency
  has been already injected at creation). This will alow to move protocol specific
  code from MYSQLND_NET (send_ex()) to make MYSQLND_NET leaner and free from protocol
  stuff.

ext/mysqlnd/mysqlnd.c
ext/mysqlnd/mysqlnd_driver.c
ext/mysqlnd/mysqlnd_ext_plugin.c
ext/mysqlnd/mysqlnd_ext_plugin.h
ext/mysqlnd/mysqlnd_structs.h
ext/mysqlnd/mysqlnd_wireprotocol.c
ext/mysqlnd/mysqlnd_wireprotocol.h

index 3ca8b1114b437a6b80164ff0aa134ff0d902ed93..56f3396974965c5f7958e2a103a94283a9b48849 100644 (file)
@@ -2974,27 +2974,10 @@ MYSQLND_METHOD(mysqlnd_conn_data, local_tx_end)(MYSQLND_CONN_DATA * conn, size_t
 /* }}} */
 
 
-/* {{{ mysqlnd_conn_data::init */
-static enum_func_status
-MYSQLND_METHOD(mysqlnd_conn_data, init)(MYSQLND_CONN_DATA * conn)
-{
-       DBG_ENTER("mysqlnd_conn_data::init");
-       mysqlnd_stats_init(&conn->stats, STAT_LAST, conn->persistent);
-       SET_ERROR_AFF_ROWS(conn);
-
-       conn->net = mysqlnd_net_init(conn->persistent, conn->stats, conn->error_info);
-       conn->payload_decoder_factory = mysqlnd_protocol_payload_decoder_factory_init(conn->persistent);
-
-       DBG_RETURN(conn->stats && conn->net && conn->payload_decoder_factory? PASS:FAIL);
-}
-/* }}} */
-
-
 MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND_CONN_DATA * const conn);
 
 
 MYSQLND_CLASS_METHODS_START(mysqlnd_conn_data)
-       MYSQLND_METHOD(mysqlnd_conn_data, init),
        MYSQLND_METHOD(mysqlnd_conn_data, connect),
 
        MYSQLND_METHOD(mysqlnd_conn_data, escape_string),
index 11cbb70c5336c86de7cabc276e55af17b4fdac7a..859aba7f6e7069e42f434e613c2123b70f35d625 100644 (file)
@@ -142,17 +142,22 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(zend_bool persistent)
        CONN_SET_STATE(data, CONN_ALLOCED);
        data->m->get_reference(data);
 
-       if (PASS != data->m->init(data)) {
+       data->error_info->error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
+       if (!data->error_info->error_list) {
                new_object->m->dtor(new_object);
                DBG_RETURN(NULL);
        }
+       zend_llist_init(data->error_info->error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
 
-       data->error_info->error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
-       if (!data->error_info->error_list) {
+       mysqlnd_stats_init(&data->stats, STAT_LAST, persistent);
+       SET_ERROR_AFF_ROWS(data);
+
+       data->net = mysqlnd_net_init(persistent, data->stats, data->error_info);
+       data->payload_decoder_factory = mysqlnd_protocol_payload_decoder_factory_init(data, persistent);
+
+       if (!data->net || !data->payload_decoder_factory) {
                new_object->m->dtor(new_object);
                DBG_RETURN(NULL);
-       } else {
-               zend_llist_init(data->error_info->error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
        }
 
        DBG_RETURN(new_object);
@@ -284,7 +289,7 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_io_channel)(zend_bool persistent, MYS
 
 /* {{{ mysqlnd_object_factory::get_protocol_payload_decoder_factory */
 static MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY *
-MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_payload_decoder_factory)(zend_bool persistent)
+MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_payload_decoder_factory)(MYSQLND_CONN_DATA * conn, zend_bool persistent)
 {
        size_t alloc_size = sizeof(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY) + mysqlnd_plugin_count() * sizeof(void *);
        MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY *ret = mnd_pecalloc(1, alloc_size, persistent);
@@ -293,6 +298,7 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_payload_decoder_factory)(zen
        DBG_INF_FMT("persistent=%u", persistent);
        if (ret) {
                ret->persistent = persistent;
+               ret->conn = conn;
                ret->m = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory);
        }
 
index 44ded51cf718f2ea1b6753ee510e265fedbdef6d..1ba0b85f4831163bf7a6710dd645a314606d6cdc 100644 (file)
@@ -148,6 +148,21 @@ PHPAPI void ** _mysqlnd_plugin_get_plugin_net_data(const MYSQLND_NET * net, unsi
 /* }}} */
 
 
+/* {{{ mysqlnd_conn_get_methods */
+PHPAPI struct st_mysqlnd_object_factory_methods *
+mysqlnd_object_factory_get_methods()
+{
+       return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory);
+}
+/* }}} */
+
+/* {{{ mysqlnd_conn_set_methods */
+PHPAPI void mysqlnd_object_factory_set_methods(struct st_mysqlnd_object_factory_methods *methods)
+{
+       MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory) = *methods;
+}
+/* }}} */
+
 
 /* {{{ mysqlnd_conn_get_methods */
 PHPAPI struct st_mysqlnd_conn_methods *
index e802be64c8e40ae3e2709872b4fb702283f751ff..3a106f737cee7e87b3c13a839d72ee73002ef451 100644 (file)
@@ -50,6 +50,9 @@ PHPAPI void ** _mysqlnd_plugin_get_plugin_net_data(const MYSQLND_NET * net, unsi
 #define mysqlnd_plugin_get_plugin_net_data(n, p_id) _mysqlnd_plugin_get_plugin_net_data((n), (p_id))
 
 
+PHPAPI struct st_mysqlnd_object_factory_methods * mysqlnd_object_factory_get_methods();
+PHPAPI void mysqlnd_object_factory_set_methods(struct st_mysqlnd_object_factory_methods * methods);
+
 PHPAPI struct st_mysqlnd_conn_methods * mysqlnd_conn_get_methods();
 PHPAPI void mysqlnd_conn_set_methods(struct st_mysqlnd_conn_methods * methods);
 
index 03a341baba7a1598221f6b22f2c33a19967e7cba..cfd8c1e4f407796317c35b1b78adc656720adbba 100644 (file)
@@ -357,6 +357,7 @@ struct st_mysqlnd_packet_auth_pam;
 struct st_mysqlnd_packet_sha256_pk_request;
 struct st_mysqlnd_packet_sha256_pk_request_response;
 
+typedef MYSQLND_CONN_DATA *                                            (*func_mysqlnd_protocol_payload_decoder_factory__get_mysqlnd_conn_data)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory);
 typedef struct st_mysqlnd_packet_greet *               (*func_mysqlnd_protocol_payload_decoder_factory__get_greet_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, zend_bool persistent);
 typedef struct st_mysqlnd_packet_auth *                        (*func_mysqlnd_protocol_payload_decoder_factory__get_auth_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, zend_bool persistent);
 typedef struct st_mysqlnd_packet_auth_response *(*func_mysqlnd_protocol_payload_decoder_factory__get_auth_response_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, zend_bool persistent);
@@ -375,6 +376,7 @@ typedef struct st_mysqlnd_packet_sha256_pk_request_response *(*func_mysqlnd_prot
 
 struct st_mysqlnd_protocol_payload_decoder_factory_methods
 {
+       func_mysqlnd_protocol_payload_decoder_factory__get_mysqlnd_conn_data get_mysqlnd_conn_data;
        func_mysqlnd_protocol_payload_decoder_factory__get_greet_packet get_greet_packet;
        func_mysqlnd_protocol_payload_decoder_factory__get_auth_packet get_auth_packet;
        func_mysqlnd_protocol_payload_decoder_factory__get_auth_response_packet get_auth_response_packet;
@@ -401,7 +403,7 @@ typedef MYSQLND * (*func_mysqlnd_object_factory__get_connection)(zend_bool persi
 typedef MYSQLND * (*func_mysqlnd_object_factory__clone_connection_object)(MYSQLND * conn);
 typedef MYSQLND_STMT * (*func_mysqlnd_object_factory__get_prepared_statement)(MYSQLND_CONN_DATA * conn);
 typedef MYSQLND_NET * (*func_mysqlnd_object_factory__get_io_channel)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info);
-typedef MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * (*func_mysqlnd_object_factory__get_protocol_payload_decoder_factory)(zend_bool persistent);
+typedef MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * (*func_mysqlnd_object_factory__get_protocol_payload_decoder_factory)(MYSQLND_CONN_DATA * conn, zend_bool persistent);
 
 
 struct st_mysqlnd_object_factory_methods
@@ -414,7 +416,6 @@ struct st_mysqlnd_object_factory_methods
 };
 
 
-typedef enum_func_status       (*func_mysqlnd_conn_data__init)(MYSQLND_CONN_DATA * conn);
 typedef enum_func_status       (*func_mysqlnd_conn_data__connect)(MYSQLND_CONN_DATA * conn, const char * host, const char * user, const char * passwd, unsigned int passwd_len, const char * db, unsigned int db_len, unsigned int port, const char * socket_or_pipe, unsigned int mysql_flags);
 typedef zend_ulong                     (*func_mysqlnd_conn_data__escape_string)(MYSQLND_CONN_DATA * const conn, char *newstr, const char *escapestr, size_t escapestr_len);
 typedef enum_func_status       (*func_mysqlnd_conn_data__set_charset)(MYSQLND_CONN_DATA * const conn, const char * const charset);
@@ -510,7 +511,6 @@ typedef unsigned int                (*func_mysqlnd_conn_data__get_client_api_capabilities)(con
 
 struct st_mysqlnd_conn_data_methods
 {
-       func_mysqlnd_conn_data__init init;
        func_mysqlnd_conn_data__connect connect;
        func_mysqlnd_conn_data__escape_string escape_string;
        func_mysqlnd_conn_data__set_charset set_charset;
@@ -894,6 +894,7 @@ struct st_mysqlnd_net
 
 struct st_mysqlnd_protocol_payload_decoder_factory
 {
+       MYSQLND_CONN_DATA * conn;
        zend_bool persistent;
        struct st_mysqlnd_protocol_payload_decoder_factory_methods m;
 };
index 0d515e8fa4428486cf83db66644d48218df729b5..a67e583d058e0a92acb81d46c5529ab5b8c2f161 100644 (file)
@@ -324,13 +324,15 @@ mysqlnd_read_packet_header_and_body(MYSQLND_PACKET_HEADER * packet_header, MYSQL
 
 /* {{{ php_mysqlnd_greet_read */
 static enum_func_status
-php_mysqlnd_greet_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_greet_read(void * _packet)
 {
        zend_uchar buf[2048];
        zend_uchar *p = buf;
        zend_uchar *begin = buf;
        zend_uchar *pad_start = NULL;
        MYSQLND_PACKET_GREET *packet= (MYSQLND_PACKET_GREET *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
 
        DBG_ENTER("php_mysqlnd_greet_read");
 
@@ -488,12 +490,14 @@ void php_mysqlnd_greet_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_auth_write */
 static
-size_t php_mysqlnd_auth_write(void * _packet, MYSQLND_CONN_DATA * conn)
+size_t php_mysqlnd_auth_write(void * _packet)
 {
        zend_uchar buffer[AUTH_WRITE_BUFFER_LEN];
        zend_uchar *p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */
        int len;
        MYSQLND_PACKET_AUTH * packet= (MYSQLND_PACKET_AUTH *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
 
        DBG_ENTER("php_mysqlnd_auth_write");
 
@@ -684,15 +688,17 @@ void php_mysqlnd_auth_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_auth_response_read */
 static enum_func_status
-php_mysqlnd_auth_response_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_auth_response_read(void * _packet)
 {
+       register MYSQLND_PACKET_AUTH_RESPONSE * packet= (MYSQLND_PACKET_AUTH_RESPONSE *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        zend_uchar local_buf[AUTH_RESP_BUFFER_SIZE];
        size_t buf_len = conn->net->cmd_buffer.buffer? conn->net->cmd_buffer.length: AUTH_RESP_BUFFER_SIZE;
        zend_uchar *buf = conn->net->cmd_buffer.buffer? (zend_uchar *) conn->net->cmd_buffer.buffer : local_buf;
        zend_uchar *p = buf;
        zend_uchar *begin = buf;
        zend_ulong i;
-       register MYSQLND_PACKET_AUTH_RESPONSE * packet= (MYSQLND_PACKET_AUTH_RESPONSE *) _packet;
 
        DBG_ENTER("php_mysqlnd_auth_response_read");
 
@@ -806,9 +812,11 @@ php_mysqlnd_auth_response_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_change_auth_response_write */
 static size_t
-php_mysqlnd_change_auth_response_write(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_change_auth_response_write(void * _packet)
 {
        MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *packet= (MYSQLND_PACKET_CHANGE_AUTH_RESPONSE *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        zend_uchar * buffer = conn->net->cmd_buffer.length >= packet->auth_data_len? conn->net->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len);
        zend_uchar *p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */
 
@@ -849,15 +857,17 @@ php_mysqlnd_change_auth_response_free_mem(void * _packet, zend_bool stack_alloca
 
 /* {{{ php_mysqlnd_ok_read */
 static enum_func_status
-php_mysqlnd_ok_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_ok_read(void * _packet)
 {
+       register MYSQLND_PACKET_OK *packet= (MYSQLND_PACKET_OK *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        zend_uchar local_buf[OK_BUFFER_SIZE];
        size_t buf_len = conn->net->cmd_buffer.buffer? conn->net->cmd_buffer.length : OK_BUFFER_SIZE;
        zend_uchar *buf = conn->net->cmd_buffer.buffer? (zend_uchar *) conn->net->cmd_buffer.buffer : local_buf;
        zend_uchar *p = buf;
        zend_uchar *begin = buf;
        zend_ulong i;
-       register MYSQLND_PACKET_OK *packet= (MYSQLND_PACKET_OK *) _packet;
 
        DBG_ENTER("php_mysqlnd_ok_read");
 
@@ -937,7 +947,7 @@ php_mysqlnd_ok_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_eof_read */
 static enum_func_status
-php_mysqlnd_eof_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_eof_read(void * _packet)
 {
        /*
          EOF packet is since 4.1 five bytes long,
@@ -946,6 +956,8 @@ php_mysqlnd_eof_read(void * _packet, MYSQLND_CONN_DATA * conn)
          Error : error_code + '#' + sqlstate + MYSQLND_ERRMSG_SIZE
        */
        MYSQLND_PACKET_EOF *packet= (MYSQLND_PACKET_EOF *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        size_t buf_len = conn->net->cmd_buffer.length;
        zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
        zend_uchar *p = buf;
@@ -1016,10 +1028,12 @@ void php_mysqlnd_eof_free_mem(void * _packet, zend_bool stack_allocation)
 
 
 /* {{{ php_mysqlnd_cmd_write */
-size_t php_mysqlnd_cmd_write(void * _packet, MYSQLND_CONN_DATA * conn)
+size_t php_mysqlnd_cmd_write(void * _packet)
 {
        /* Let's have some space, which we can use, if not enough, we will allocate new buffer */
        MYSQLND_PACKET_COMMAND * packet= (MYSQLND_PACKET_COMMAND *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        MYSQLND_NET * net = conn->net;
        unsigned int error_reporting = EG(error_reporting);
        size_t sent = 0;
@@ -1094,15 +1108,17 @@ void php_mysqlnd_cmd_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_rset_header_read */
 static enum_func_status
-php_mysqlnd_rset_header_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_rset_header_read(void * _packet)
 {
+       MYSQLND_PACKET_RSET_HEADER * packet= (MYSQLND_PACKET_RSET_HEADER *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        enum_func_status ret = PASS;
        size_t buf_len = conn->net->cmd_buffer.length;
        zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
        zend_uchar *p = buf;
        zend_uchar *begin = buf;
        size_t len;
-       MYSQLND_PACKET_RSET_HEADER *packet= (MYSQLND_PACKET_RSET_HEADER *) _packet;
 
        DBG_ENTER("php_mysqlnd_rset_header_read");
 
@@ -1235,10 +1251,12 @@ static size_t rset_field_offsets[] =
 
 /* {{{ php_mysqlnd_rset_field_read */
 static enum_func_status
-php_mysqlnd_rset_field_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_rset_field_read(void * _packet)
 {
        /* Should be enough for the metadata of a single row */
        MYSQLND_PACKET_RES_FIELD *packet = (MYSQLND_PACKET_RES_FIELD *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        size_t buf_len = conn->net->cmd_buffer.length, total_len = 0;
        zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
        zend_uchar *p = buf;
@@ -1803,11 +1821,13 @@ php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zv
   if PS => packet->fields is passed from outside
 */
 static enum_func_status
-php_mysqlnd_rowp_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_rowp_read(void * _packet)
 {
+       MYSQLND_PACKET_ROW *packet= (MYSQLND_PACKET_ROW *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        zend_uchar *p;
        enum_func_status ret = PASS;
-       MYSQLND_PACKET_ROW *packet= (MYSQLND_PACKET_ROW *) _packet;
        size_t post_alloc_for_bit_fields = 0;
        size_t data_size = 0;
 
@@ -1923,9 +1943,11 @@ php_mysqlnd_rowp_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_stats_read */
 static enum_func_status
-php_mysqlnd_stats_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_stats_read(void * _packet)
 {
        MYSQLND_PACKET_STATS *packet= (MYSQLND_PACKET_STATS *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        size_t buf_len = conn->net->cmd_buffer.length;
        zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
 
@@ -1967,15 +1989,17 @@ void php_mysqlnd_stats_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_prepare_read */
 static enum_func_status
-php_mysqlnd_prepare_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_prepare_read(void * _packet)
 {
+       MYSQLND_PACKET_PREPARE_RESPONSE *packet= (MYSQLND_PACKET_PREPARE_RESPONSE *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        /* In case of an error, we should have place to put it */
        size_t buf_len = conn->net->cmd_buffer.length;
        zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
        zend_uchar *p = buf;
        zend_uchar *begin = buf;
        unsigned int data_size;
-       MYSQLND_PACKET_PREPARE_RESPONSE *packet= (MYSQLND_PACKET_PREPARE_RESPONSE *) _packet;
 
        DBG_ENTER("php_mysqlnd_prepare_read");
 
@@ -2057,14 +2081,16 @@ php_mysqlnd_prepare_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_chg_user_read */
 static enum_func_status
-php_mysqlnd_chg_user_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_chg_user_read(void * _packet)
 {
+       MYSQLND_PACKET_CHG_USER_RESPONSE *packet= (MYSQLND_PACKET_CHG_USER_RESPONSE *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        /* There could be an error message */
        size_t buf_len = conn->net->cmd_buffer.length;
        zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
        zend_uchar *p = buf;
        zend_uchar *begin = buf;
-       MYSQLND_PACKET_CHG_USER_RESPONSE *packet= (MYSQLND_PACKET_CHG_USER_RESPONSE *) _packet;
 
        DBG_ENTER("php_mysqlnd_chg_user_read");
 
@@ -2147,8 +2173,11 @@ php_mysqlnd_chg_user_free_mem(void * _packet, zend_bool stack_allocation)
 
 /* {{{ php_mysqlnd_sha256_pk_request_write */
 static
-size_t php_mysqlnd_sha256_pk_request_write(void * _packet, MYSQLND_CONN_DATA * conn)
+size_t php_mysqlnd_sha256_pk_request_write(void * _packet)
 {
+       MYSQLND_PACKET_HEADER *packet_header= (MYSQLND_PACKET_HEADER *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet_header->factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        zend_uchar buffer[MYSQLND_HEADER_SIZE + 1];
        size_t sent;
 
@@ -2178,12 +2207,14 @@ void php_mysqlnd_sha256_pk_request_free_mem(void * _packet, zend_bool stack_allo
 
 /* {{{ php_mysqlnd_sha256_pk_request_response_read */
 static enum_func_status
-php_mysqlnd_sha256_pk_request_response_read(void * _packet, MYSQLND_CONN_DATA * conn)
+php_mysqlnd_sha256_pk_request_response_read(void * _packet)
 {
+       MYSQLND_PACKET_SHA256_PK_REQUEST_RESPONSE * packet= (MYSQLND_PACKET_SHA256_PK_REQUEST_RESPONSE *) _packet;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory = packet->header.factory;
+       MYSQLND_CONN_DATA * conn = factory->m.get_mysqlnd_conn_data(factory);
        zend_uchar buf[SHA256_PK_REQUEST_RESP_BUFFER_SIZE];
        zend_uchar *p = buf;
        zend_uchar *begin = buf;
-       MYSQLND_PACKET_SHA256_PK_REQUEST_RESPONSE * packet= (MYSQLND_PACKET_SHA256_PK_REQUEST_RESPONSE *) _packet;
 
        DBG_ENTER("php_mysqlnd_sha256_pk_request_response_read");
 
@@ -2328,6 +2359,16 @@ mysqlnd_packet_methods packet_methods[PROT_LAST] =
 /* }}} */
 
 
+/* {{{ mysqlnd_protocol::get_mysqlnd_conn_data */
+MYSQLND_CONN_DATA *
+MYSQLND_METHOD(mysqlnd_protocol, get_mysqlnd_conn_data)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory)
+{
+       DBG_ENTER("mysqlnd_protocol::get_mysqlnd_conn_data");
+       DBG_RETURN(factory->conn);
+}
+/* }}} */
+
+
 /* {{{ mysqlnd_protocol::get_greet_packet */
 static struct st_mysqlnd_packet_greet *
 MYSQLND_METHOD(mysqlnd_protocol, get_greet_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, zend_bool persistent)
@@ -2336,6 +2377,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_greet_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECO
        DBG_ENTER("mysqlnd_protocol::get_greet_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_GREET_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2351,6 +2393,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_auth_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECOD
        DBG_ENTER("mysqlnd_protocol::get_auth_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_AUTH_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2366,6 +2409,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_auth_response_packet)(MYSQLND_PROTOCOL_PAYL
        DBG_ENTER("mysqlnd_protocol::get_auth_response_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_AUTH_RESP_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2381,6 +2425,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_change_auth_response_packet)(MYSQLND_PROTOC
        DBG_ENTER("mysqlnd_protocol::get_change_auth_response_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_CHANGE_AUTH_RESP_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2396,6 +2441,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_ok_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER
        DBG_ENTER("mysqlnd_protocol::get_ok_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_OK_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2411,6 +2457,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_eof_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODE
        DBG_ENTER("mysqlnd_protocol::get_eof_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_EOF_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2426,6 +2473,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_command_packet)(MYSQLND_PROTOCOL_PAYLOAD_DE
        DBG_ENTER("mysqlnd_protocol::get_command_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_CMD_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2441,6 +2489,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_rset_header_packet)(MYSQLND_PROTOCOL_PAYLOA
        DBG_ENTER("mysqlnd_protocol::get_rset_header_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_RSET_HEADER_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2456,6 +2505,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_result_field_packet)(MYSQLND_PROTOCOL_PAYLO
        DBG_ENTER("mysqlnd_protocol::get_result_field_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_RSET_FLD_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2471,6 +2521,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_row_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODE
        DBG_ENTER("mysqlnd_protocol::get_row_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_ROW_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2486,6 +2537,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_stats_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECO
        DBG_ENTER("mysqlnd_protocol::get_stats_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_STATS_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2501,6 +2553,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_prepare_response_packet)(MYSQLND_PROTOCOL_P
        DBG_ENTER("mysqlnd_protocol::get_prepare_response_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_PREPARE_RESP_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2516,6 +2569,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_change_user_response_packet)(MYSQLND_PROTOC
        DBG_ENTER("mysqlnd_protocol::get_change_user_response_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_CHG_USER_RESP_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2531,6 +2585,7 @@ MYSQLND_METHOD(mysqlnd_protocol, get_sha256_pk_request_packet)(MYSQLND_PROTOCOL_
        DBG_ENTER("mysqlnd_protocol::get_sha256_pk_request_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_SHA256_PK_REQUEST_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
@@ -2546,15 +2601,15 @@ MYSQLND_METHOD(mysqlnd_protocol, get_sha256_pk_request_response_packet)(MYSQLND_
        DBG_ENTER("mysqlnd_protocol::get_sha256_pk_request_response_packet");
        if (packet) {
                packet->header.m = &packet_methods[PROT_SHA256_PK_REQUEST_RESPONSE_PACKET];
+               packet->header.factory = factory;
                packet->header.persistent = persistent;
        }
        DBG_RETURN(packet);
 }
 /* }}} */
 
-
-
 MYSQLND_CLASS_METHODS_START(mysqlnd_protocol_payload_decoder_factory)
+       MYSQLND_METHOD(mysqlnd_protocol, get_mysqlnd_conn_data),
        MYSQLND_METHOD(mysqlnd_protocol, get_greet_packet),
        MYSQLND_METHOD(mysqlnd_protocol, get_auth_packet),
        MYSQLND_METHOD(mysqlnd_protocol, get_auth_response_packet),
@@ -2575,11 +2630,11 @@ MYSQLND_CLASS_METHODS_END;
 
 /* {{{ mysqlnd_protocol_payload_decoder_factory_init */
 PHPAPI MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY *
-mysqlnd_protocol_payload_decoder_factory_init(zend_bool persistent)
+mysqlnd_protocol_payload_decoder_factory_init(MYSQLND_CONN_DATA * conn, zend_bool persistent)
 {
        MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * ret;
        DBG_ENTER("mysqlnd_protocol_payload_decoder_factory_init");
-       ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_protocol_payload_decoder_factory(persistent);
+       ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_protocol_payload_decoder_factory(conn, persistent);
        DBG_RETURN(ret);
 }
 /* }}} */
index f3ed895faa2a1779d3c16634b72262659d53c939..e42a5e2e6cc94c4effeb14feb2e63f56b747fa6f 100644 (file)
@@ -36,8 +36,8 @@ PHPAPI extern const char mysqlnd_read_body_name[];
 
 
 /* Packet handling */
-#define PACKET_WRITE(packet, conn)     ((packet)->header.m->write_to_net((packet), (conn)))
-#define PACKET_READ(packet, conn)      ((packet)->header.m->read_from_net((packet), (conn)))
+#define PACKET_WRITE(packet, conn)     ((packet)->header.m->write_to_net((packet)))
+#define PACKET_READ(packet, conn)      ((packet)->header.m->read_from_net((packet)))
 #define PACKET_FREE(packet) \
        do { \
                DBG_INF_FMT("PACKET_FREE(%p)", packet); \
@@ -51,8 +51,8 @@ PHPAPI extern const char * const mysqlnd_command_to_text[COM_END];
 /* Low-level extraction functionality */
 typedef struct st_mysqlnd_packet_methods {
        size_t                          struct_size;
-       enum_func_status        (*read_from_net)(void * packet, MYSQLND_CONN_DATA * conn);
-       size_t                          (*write_to_net)(void * packet, MYSQLND_CONN_DATA * conn);
+       enum_func_status        (*read_from_net)(void * packet);
+       size_t                          (*write_to_net)(void * packet);
        void                            (*free_mem)(void *packet, zend_bool stack_allocation);
 } mysqlnd_packet_methods;
 
@@ -60,6 +60,7 @@ typedef struct st_mysqlnd_packet_methods {
 typedef struct st_mysqlnd_packet_header {
        size_t          size;
        mysqlnd_packet_methods *m;
+       MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory;
        zend_uchar      packet_no;
        zend_bool       persistent;
 } MYSQLND_PACKET_HEADER;
@@ -320,7 +321,7 @@ enum_func_status php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_MEMORY_POOL_CHUNK
                                                                                 zend_bool as_int_or_float, MYSQLND_STATS * stats);
 
 
-PHPAPI MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * mysqlnd_protocol_payload_decoder_factory_init(zend_bool persistent);
+PHPAPI MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * mysqlnd_protocol_payload_decoder_factory_init(MYSQLND_CONN_DATA * conn, zend_bool persistent);
 PHPAPI void mysqlnd_protocol_payload_decoder_factory_free(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const payload_decoder_factory);
 
 #endif /* MYSQLND_WIREPROTOCOL_H */