Back to index

php5  5.3.10
mysqlnd_wireprotocol.h
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 2006-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Authors: Georg Richter <georg@mysql.com>                             |
00016   |          Andrey Hristov <andrey@mysql.com>                           |
00017   |          Ulf Wendel <uwendel@mysql.com>                              |
00018   +----------------------------------------------------------------------+
00019 */
00020 
00021 /* $Id: mysqlnd_wireprotocol.h 321634 2012-01-01 13:15:04Z felipe $ */
00022 
00023 #ifndef MYSQLND_WIREPROTOCOL_H
00024 #define MYSQLND_WIREPROTOCOL_H
00025 
00026 #include "mysqlnd_net.h"
00027 
00028 #define MYSQLND_HEADER_SIZE 4
00029 #define COMPRESSED_HEADER_SIZE 3
00030 
00031 #define MYSQLND_NULL_LENGTH (unsigned long) ~0
00032 
00033 /* Used in mysqlnd_debug.c */
00034 PHPAPI extern const char mysqlnd_read_header_name[];
00035 PHPAPI extern const char mysqlnd_read_body_name[];
00036 
00037 
00038 /* Packet handling */
00039 #define PACKET_WRITE(packet, conn) ((packet)->header.m->write_to_net((packet), (conn) TSRMLS_CC))
00040 #define PACKET_READ(packet, conn)  ((packet)->header.m->read_from_net((packet), (conn) TSRMLS_CC))
00041 #define PACKET_FREE(packet) \
00042        do { \
00043               DBG_INF_FMT("PACKET_FREE(%p)", packet); \
00044               if ((packet)) { \
00045                      ((packet)->header.m->free_mem((packet), FALSE TSRMLS_CC)); \
00046               } \
00047        } while (0);
00048 
00049 PHPAPI extern const char * const mysqlnd_command_to_text[COM_END];
00050 
00051 /* Low-level extraction functionality */
00052 typedef struct st_mysqlnd_packet_methods {
00053        size_t                      struct_size;
00054        enum_func_status     (*read_from_net)(void *packet, MYSQLND *conn TSRMLS_DC);
00055        size_t                      (*write_to_net)(void *packet, MYSQLND *conn TSRMLS_DC);
00056        void                        (*free_mem)(void *packet, zend_bool stack_allocation TSRMLS_DC);
00057 } mysqlnd_packet_methods;
00058 
00059 
00060 typedef struct st_mysqlnd_packet_header {
00061        size_t        size;
00062        mysqlnd_packet_methods *m;
00063        zend_uchar    packet_no;
00064        zend_bool     persistent;
00065 } MYSQLND_PACKET_HEADER;
00066 
00067 /* Server greets the client */
00068 typedef struct st_mysqlnd_packet_greet {
00069        MYSQLND_PACKET_HEADER              header;
00070        uint8_t              protocol_version;
00071        char          *server_version;
00072        uint32_t      thread_id;
00073        zend_uchar    scramble_buf[SCRAMBLE_LENGTH];
00074        /* 1 byte pad */
00075        uint16_t      server_capabilities;
00076        uint8_t              charset_no;
00077        uint16_t      server_status;
00078        /* 13 byte pad*/
00079        zend_bool     pre41;
00080        /* If error packet, we use these */
00081        char          error[MYSQLND_ERRMSG_SIZE+1];
00082        char          sqlstate[MYSQLND_SQLSTATE_LENGTH + 1];
00083        unsigned int  error_no;
00084 } MYSQLND_PACKET_GREET;
00085 
00086 
00087 /* Client authenticates */
00088 typedef struct st_mysqlnd_packet_auth {
00089        MYSQLND_PACKET_HEADER              header;
00090        uint32_t      client_flags;
00091        uint32_t      max_packet_size;
00092        uint8_t       charset_no;
00093        /* 23 byte pad */
00094        const char    *user;
00095        /* 8 byte scramble */
00096        const char    *db;
00097        /* 12 byte scramble */
00098 
00099        /* Here the packet ends. This is user supplied data */
00100        const char    *password;
00101        /* +1 for \0 because of scramble() */
00102        unsigned char *server_scramble_buf;
00103        size_t               db_len;
00104        zend_bool            send_half_packet;
00105 } MYSQLND_PACKET_AUTH;
00106 
00107 /* OK packet */
00108 typedef struct st_mysqlnd_packet_ok {
00109        MYSQLND_PACKET_HEADER              header;
00110        uint8_t              field_count; /* always 0x0 */
00111        uint64_t      affected_rows;
00112        uint64_t      last_insert_id;
00113        uint16_t      server_status;
00114        uint16_t      warning_count;
00115        char          *message;
00116        size_t        message_len;
00117        /* If error packet, we use these */
00118        char          error[MYSQLND_ERRMSG_SIZE+1];
00119        char          sqlstate[MYSQLND_SQLSTATE_LENGTH + 1];
00120        unsigned int  error_no;
00121 } MYSQLND_PACKET_OK;
00122 
00123 
00124 /* Command packet */
00125 typedef struct st_mysqlnd_packet_command {
00126        MYSQLND_PACKET_HEADER                     header;
00127        enum php_mysqlnd_server_command    command;
00128        const char                                       *argument;
00129        size_t                                           arg_len;
00130 } MYSQLND_PACKET_COMMAND;
00131 
00132 
00133 /* EOF packet */
00134 typedef struct st_mysqlnd_packet_eof {
00135        MYSQLND_PACKET_HEADER              header;
00136        uint8_t              field_count; /* 0xFE */
00137        uint16_t      warning_count;
00138        uint16_t      server_status;
00139        /* If error packet, we use these */
00140        char          error[MYSQLND_ERRMSG_SIZE+1];
00141        char          sqlstate[MYSQLND_SQLSTATE_LENGTH + 1];
00142        unsigned int  error_no;
00143 } MYSQLND_PACKET_EOF;
00144 /* EOF packet */
00145 
00146 
00147 /* Result Set header*/
00148 typedef struct st_mysqlnd_packet_rset_header {
00149        MYSQLND_PACKET_HEADER              header;
00150        /*
00151          0x00 => ok
00152          ~0   => LOAD DATA LOCAL
00153          error_no != 0 => error
00154          others => result set -> Read res_field packets up to field_count
00155        */
00156        unsigned long        field_count;
00157        /*
00158          These are filled if no SELECT query. For SELECT warning_count
00159          and server status are in the last row packet, the EOF packet.
00160        */
00161        uint16_t      warning_count;
00162        uint16_t      server_status;
00163        uint64_t      affected_rows;
00164        uint64_t      last_insert_id;
00165        /* This is for both LOAD DATA or info, when no result set */
00166        char          *info_or_local_file;
00167        size_t        info_or_local_file_len;
00168        /* If error packet, we use these */
00169        MYSQLND_ERROR_INFO   error_info;
00170 } MYSQLND_PACKET_RSET_HEADER;
00171 
00172 
00173 /* Result set field packet */
00174 typedef struct st_mysqlnd_packet_res_field {
00175        MYSQLND_PACKET_HEADER       header;
00176        MYSQLND_FIELD               *metadata;
00177        /* For table definitions, empty for result sets */
00178        zend_bool                          skip_parsing;
00179        zend_bool                          stupid_list_fields_eof;
00180        zend_bool                          persistent_alloc;
00181 
00182        MYSQLND_ERROR_INFO          error_info;
00183 } MYSQLND_PACKET_RES_FIELD;
00184 
00185 
00186 /* Row packet */
00187 typedef struct st_mysqlnd_packet_row {
00188        MYSQLND_PACKET_HEADER       header;
00189        zval          **fields;
00190        uint32_t      field_count;
00191        zend_bool     eof;
00192        /*
00193          These are, of course, only for SELECT in the EOF packet,
00194          which is detected by this packet
00195        */
00196        uint16_t      warning_count;
00197        uint16_t      server_status;
00198 
00199        struct st_mysqlnd_memory_pool_chunk       *row_buffer;
00200        MYSQLND_MEMORY_POOL * result_set_memory_pool;
00201 
00202        zend_bool            skip_extraction;
00203        zend_bool            binary_protocol;
00204        zend_bool            persistent_alloc;
00205        MYSQLND_FIELD *fields_metadata;
00206        /* We need this to alloc bigger bufs in non-PS mode */
00207        unsigned int  bit_fields_count;
00208        size_t               bit_fields_total_len; /* trailing \0 not counted */
00209 
00210        /* If error packet, we use these */
00211        MYSQLND_ERROR_INFO   error_info;
00212 } MYSQLND_PACKET_ROW;
00213 
00214 
00215 /* Statistics packet */
00216 typedef struct st_mysqlnd_packet_stats {
00217        MYSQLND_PACKET_HEADER       header;
00218        char *message;
00219        /* message_len is not part of the packet*/
00220        size_t message_len;
00221 } MYSQLND_PACKET_STATS;
00222 
00223 
00224 /* COM_PREPARE response packet */
00225 typedef struct st_mysqlnd_packet_prepare_response {
00226        MYSQLND_PACKET_HEADER       header;
00227        /* also known as field_count 0x00=OK , 0xFF=error */
00228        unsigned char error_code;
00229        unsigned long stmt_id;
00230        unsigned int  field_count;
00231        unsigned int  param_count;
00232        unsigned int  warning_count;
00233 
00234        /* present in case of error */
00235        MYSQLND_ERROR_INFO   error_info;
00236 } MYSQLND_PACKET_PREPARE_RESPONSE;
00237 
00238 
00239 /* Statistics packet */
00240 typedef struct st_mysqlnd_packet_chg_user_resp {
00241        MYSQLND_PACKET_HEADER       header;
00242        uint32_t                    field_count;
00243 
00244        /* message_len is not part of the packet*/
00245        uint16_t                    server_capabilities;
00246        /* If error packet, we use these */
00247        MYSQLND_ERROR_INFO   error_info;
00248        zend_bool                   server_asked_323_auth;
00249 } MYSQLND_PACKET_CHG_USER_RESPONSE;
00250 
00251 
00252 PHPAPI void php_mysqlnd_scramble(zend_uchar * const buffer, const zend_uchar * const scramble, const zend_uchar * const pass);
00253 
00254 unsigned long php_mysqlnd_net_field_length(zend_uchar **packet);
00255 zend_uchar *  php_mysqlnd_net_store_length(zend_uchar *packet, uint64_t length);
00256 
00257 PHPAPI const extern char * const mysqlnd_empty_string;
00258 
00259 
00260 enum_func_status php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval ** fields,
00261                                                                        unsigned int field_count, MYSQLND_FIELD *fields_metadata,
00262                                                                        zend_bool persistent,
00263                                                                        zend_bool as_unicode, zend_bool as_int_or_float,
00264                                                                        MYSQLND_STATS * stats TSRMLS_DC);
00265 
00266 
00267 enum_func_status php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval ** fields,
00268                                                                        unsigned int field_count, MYSQLND_FIELD *fields_metadata,
00269                                                                        zend_bool persistent,
00270                                                                        zend_bool as_unicode, zend_bool as_int_or_float,
00271                                                                        MYSQLND_STATS * stats TSRMLS_DC);
00272 
00273 
00274 PHPAPI MYSQLND_PROTOCOL * mysqlnd_protocol_init(zend_bool persistent TSRMLS_DC);
00275 PHPAPI void mysqlnd_protocol_free(MYSQLND_PROTOCOL * const protocol TSRMLS_DC);
00276 PHPAPI struct st_mysqlnd_protocol_methods * mysqlnd_protocol_get_methods();
00277 
00278 #endif /* MYSQLND_WIREPROTOCOL_H */
00279 
00280 /*
00281  * Local variables:
00282  * tab-width: 4
00283  * c-basic-offset: 4
00284  * End:
00285  * vim600: noet sw=4 ts=4 fdm=marker
00286  * vim<600: noet sw=4 ts=4
00287  */