Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
mysqlnd_wireprotocol.h File Reference
#include "mysqlnd_net.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  st_mysqlnd_packet_methods
struct  st_mysqlnd_packet_header
struct  st_mysqlnd_packet_greet
struct  st_mysqlnd_packet_auth
struct  st_mysqlnd_packet_ok
struct  st_mysqlnd_packet_command
struct  st_mysqlnd_packet_eof
struct  st_mysqlnd_packet_rset_header
struct  st_mysqlnd_packet_res_field
struct  st_mysqlnd_packet_row
struct  st_mysqlnd_packet_stats
struct  st_mysqlnd_packet_prepare_response
struct  st_mysqlnd_packet_chg_user_resp

Defines

#define MYSQLND_HEADER_SIZE   4
#define COMPRESSED_HEADER_SIZE   3
#define MYSQLND_NULL_LENGTH   (unsigned long) ~0
#define PACKET_WRITE(packet, conn)   ((packet)->header.m->write_to_net((packet), (conn) TSRMLS_CC))
#define PACKET_READ(packet, conn)   ((packet)->header.m->read_from_net((packet), (conn) TSRMLS_CC))
#define PACKET_FREE(packet)

Typedefs

typedef struct
st_mysqlnd_packet_methods 
mysqlnd_packet_methods
typedef struct
st_mysqlnd_packet_header 
MYSQLND_PACKET_HEADER
typedef struct
st_mysqlnd_packet_greet 
MYSQLND_PACKET_GREET
typedef struct
st_mysqlnd_packet_auth 
MYSQLND_PACKET_AUTH
typedef struct st_mysqlnd_packet_ok MYSQLND_PACKET_OK
typedef struct
st_mysqlnd_packet_command 
MYSQLND_PACKET_COMMAND
typedef struct
st_mysqlnd_packet_eof 
MYSQLND_PACKET_EOF
typedef struct
st_mysqlnd_packet_rset_header 
MYSQLND_PACKET_RSET_HEADER
typedef struct
st_mysqlnd_packet_res_field 
MYSQLND_PACKET_RES_FIELD
typedef struct
st_mysqlnd_packet_row 
MYSQLND_PACKET_ROW
typedef struct
st_mysqlnd_packet_stats 
MYSQLND_PACKET_STATS
typedef struct
st_mysqlnd_packet_prepare_response 
MYSQLND_PACKET_PREPARE_RESPONSE
typedef struct
st_mysqlnd_packet_chg_user_resp 
MYSQLND_PACKET_CHG_USER_RESPONSE

Functions

PHPAPI void php_mysqlnd_scramble (zend_uchar *const buffer, const zend_uchar *const scramble, const zend_uchar *const pass)
unsigned long php_mysqlnd_net_field_length (zend_uchar **packet)
zend_ucharphp_mysqlnd_net_store_length (zend_uchar *packet, uint64_t length)
enum_func_status php_mysqlnd_rowp_read_binary_protocol (MYSQLND_MEMORY_POOL_CHUNK *row_buffer, zval **fields, unsigned int field_count, MYSQLND_FIELD *fields_metadata, zend_bool persistent, zend_bool as_unicode, zend_bool as_int_or_float, MYSQLND_STATS *stats TSRMLS_DC)
enum_func_status php_mysqlnd_rowp_read_text_protocol (MYSQLND_MEMORY_POOL_CHUNK *row_buffer, zval **fields, unsigned int field_count, MYSQLND_FIELD *fields_metadata, zend_bool persistent, zend_bool as_unicode, zend_bool as_int_or_float, MYSQLND_STATS *stats TSRMLS_DC)
PHPAPI MYSQLND_PROTOCOL * mysqlnd_protocol_init (zend_bool persistent TSRMLS_DC)
PHPAPI void mysqlnd_protocol_free (MYSQLND_PROTOCOL *const protocol TSRMLS_DC)
PHPAPI struct
st_mysqlnd_protocol_methods
mysqlnd_protocol_get_methods ()

Variables

PHPAPI const char mysqlnd_read_header_name []
PHPAPI const char mysqlnd_read_body_name []
PHPAPI const char *const mysqlnd_command_to_text [COM_END]
PHPAPI const char *const mysqlnd_empty_string

Class Documentation

struct st_mysqlnd_packet_header

Definition at line 60 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_header:
Class Members
mysqlnd_packet_methods * m
zend_uchar packet_no
zend_bool persistent
size_t size
struct st_mysqlnd_packet_greet

Definition at line 68 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_greet:
Class Members
uint8_t charset_no
char error
unsigned int error_no
MYSQLND_PACKET_HEADER header
zend_bool pre41
uint8_t protocol_version
zend_uchar scramble_buf
uint16_t server_capabilities
uint16_t server_status
char * server_version
char sqlstate
uint32_t thread_id
struct st_mysqlnd_packet_auth

Definition at line 88 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_auth:
Class Members
uint8_t charset_no
uint32_t client_flags
const char * db
size_t db_len
MYSQLND_PACKET_HEADER header
uint32_t max_packet_size
const char * password
zend_bool send_half_packet
unsigned char * server_scramble_buf
const char * user
struct st_mysqlnd_packet_ok

Definition at line 108 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_ok:
Class Members
uint64_t affected_rows
char error
unsigned int error_no
uint8_t field_count
MYSQLND_PACKET_HEADER header
uint64_t last_insert_id
char * message
size_t message_len
uint16_t server_status
char sqlstate
uint16_t warning_count
struct st_mysqlnd_packet_command

Definition at line 125 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_command:
Class Members
MYSQLND_PACKET_HEADER header
struct st_mysqlnd_packet_eof

Definition at line 134 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_eof:
Class Members
char error
unsigned int error_no
uint8_t field_count
MYSQLND_PACKET_HEADER header
uint16_t server_status
char sqlstate
uint16_t warning_count
struct st_mysqlnd_packet_rset_header

Definition at line 148 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_rset_header:
Class Members
uint64_t affected_rows
MYSQLND_ERROR_INFO error_info
unsigned long field_count
MYSQLND_PACKET_HEADER header
char * info_or_local_file
size_t info_or_local_file_len
uint64_t last_insert_id
uint16_t server_status
uint16_t warning_count
struct st_mysqlnd_packet_res_field

Definition at line 174 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_res_field:
Class Members
MYSQLND_ERROR_INFO error_info
MYSQLND_PACKET_HEADER header
MYSQLND_FIELD * metadata
zend_bool persistent_alloc
zend_bool skip_parsing
zend_bool stupid_list_fields_eof
struct st_mysqlnd_packet_row

Definition at line 187 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_row:
Class Members
zend_bool binary_protocol
unsigned int bit_fields_count
size_t bit_fields_total_len
zend_bool eof
MYSQLND_ERROR_INFO error_info
uint32_t field_count
zval ** fields
MYSQLND_FIELD * fields_metadata
MYSQLND_PACKET_HEADER header
zend_bool persistent_alloc
MYSQLND_MEMORY_POOL * result_set_memory_pool
struct
st_mysqlnd_memory_pool_chunk *
row_buffer
uint16_t server_status
zend_bool skip_extraction
uint16_t warning_count
struct st_mysqlnd_packet_stats

Definition at line 216 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_stats:
Class Members
MYSQLND_PACKET_HEADER header
char * message
size_t message_len
struct st_mysqlnd_packet_prepare_response

Definition at line 225 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_prepare_response:
Class Members
unsigned char error_code
MYSQLND_ERROR_INFO error_info
unsigned int field_count
MYSQLND_PACKET_HEADER header
unsigned int param_count
unsigned long stmt_id
unsigned int warning_count
struct st_mysqlnd_packet_chg_user_resp

Definition at line 240 of file mysqlnd_wireprotocol.h.

Collaboration diagram for st_mysqlnd_packet_chg_user_resp:
Class Members
MYSQLND_ERROR_INFO error_info
uint32_t field_count
MYSQLND_PACKET_HEADER header
zend_bool server_asked_323_auth
uint16_t server_capabilities

Define Documentation

#define COMPRESSED_HEADER_SIZE   3

Definition at line 29 of file mysqlnd_wireprotocol.h.

#define MYSQLND_HEADER_SIZE   4

Definition at line 28 of file mysqlnd_wireprotocol.h.

#define MYSQLND_NULL_LENGTH   (unsigned long) ~0

Definition at line 31 of file mysqlnd_wireprotocol.h.

#define PACKET_FREE (   packet)
Value:
do { \
              DBG_INF_FMT("PACKET_FREE(%p)", packet); \
              if ((packet)) { \
                     ((packet)->header.m->free_mem((packet), FALSE TSRMLS_CC)); \
              } \
       } while (0);

Definition at line 41 of file mysqlnd_wireprotocol.h.

#define PACKET_READ (   packet,
  conn 
)    ((packet)->header.m->read_from_net((packet), (conn) TSRMLS_CC))

Definition at line 40 of file mysqlnd_wireprotocol.h.

#define PACKET_WRITE (   packet,
  conn 
)    ((packet)->header.m->write_to_net((packet), (conn) TSRMLS_CC))

Definition at line 39 of file mysqlnd_wireprotocol.h.


Typedef Documentation


Function Documentation

PHPAPI void mysqlnd_protocol_free ( MYSQLND_PROTOCOL *const protocol  TSRMLS_DC)

Definition at line 2113 of file mysqlnd_wireprotocol.c.

{
       DBG_ENTER("mysqlnd_protocol_free");

       if (protocol) {
              zend_bool pers = protocol->persistent;
              mnd_pefree(protocol, pers);
       }
       DBG_VOID_RETURN;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2142 of file mysqlnd_wireprotocol.c.

{
       return &mysqlnd_mysqlnd_protocol_methods;
}
PHPAPI MYSQLND_PROTOCOL* mysqlnd_protocol_init ( zend_bool persistent  TSRMLS_DC)

Definition at line 2094 of file mysqlnd_wireprotocol.c.

{
       size_t alloc_size = sizeof(MYSQLND_PROTOCOL) + mysqlnd_plugin_count() * sizeof(void *);
       MYSQLND_PROTOCOL *ret = mnd_pecalloc(1, alloc_size, persistent);

       DBG_ENTER("mysqlnd_protocol_init");
       DBG_INF_FMT("persistent=%u", persistent);
       if (ret) {
              ret->persistent = persistent;
              ret->m = mysqlnd_mysqlnd_protocol_methods;
       }

       DBG_RETURN(ret);
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long php_mysqlnd_net_field_length ( zend_uchar **  packet)

Definition at line 130 of file mysqlnd_wireprotocol.c.

{
       register zend_uchar *p= (zend_uchar *)*packet;

       if (*p < 251) {
              (*packet)++;
              return (unsigned long) *p;
       }

       switch (*p) {
              case 251:
                     (*packet)++;
                     return MYSQLND_NULL_LENGTH;
              case 252:
                     (*packet) += 3;
                     return (unsigned long) uint2korr(p+1);
              case 253:
                     (*packet) += 4;
                     return (unsigned long) uint3korr(p+1);
              default:
                     (*packet) += 9;
                     return (unsigned long) uint4korr(p+1);
       }
}

Here is the caller graph for this function:

Definition at line 189 of file mysqlnd_wireprotocol.c.

{
       if (length < (uint64_t) L64(251)) {
              *packet = (zend_uchar) length;
              return packet + 1;
       }

       if (length < (uint64_t) L64(65536)) {
              *packet++ = 252;
              int2store(packet,(unsigned int) length);
              return packet + 2;
       }

       if (length < (uint64_t) L64(16777216)) {
              *packet++ = 253;
              int3store(packet,(ulong) length);
              return packet + 3;
       }
       *packet++ = 254;
       int8store(packet, length);
       return packet + 8;
}

Here is the caller graph for this function:

enum_func_status php_mysqlnd_rowp_read_binary_protocol ( MYSQLND_MEMORY_POOL_CHUNK *  row_buffer,
zval **  fields,
unsigned int  field_count,
MYSQLND_FIELD fields_metadata,
zend_bool  persistent,
zend_bool  as_unicode,
zend_bool  as_int_or_float,
MYSQLND_STATS *stats  TSRMLS_DC 
)

Definition at line 1190 of file mysqlnd_wireprotocol.c.

{
       unsigned int i;
       zend_uchar *p = row_buffer->ptr;
       zend_uchar *null_ptr, bit;
       zval **current_field, **end_field, **start_field;

       DBG_ENTER("php_mysqlnd_rowp_read_binary_protocol");

       if (!fields) {
              DBG_RETURN(FAIL);
       }

       end_field = (start_field = fields) + field_count;

       /* skip the first byte, not EODATA_MARKER -> 0x0, status */
       p++;
       null_ptr= p;
       p += (field_count + 9)/8;   /* skip null bits */
       bit    = 4;                               /* first 2 bits are reserved */

       for (i = 0, current_field = start_field; current_field < end_field; current_field++, i++) {
              DBG_INF("Directly creating zval");
              MAKE_STD_ZVAL(*current_field);
              if (!*current_field) {
                     DBG_RETURN(FAIL);
              }
       }

       for (i = 0, current_field = start_field; current_field < end_field; current_field++, i++) {
              enum_mysqlnd_collected_stats statistic;
              zend_uchar * orig_p = p;

              DBG_INF_FMT("Into zval=%p decoding column %u [%s.%s.%s] type=%u field->flags&unsigned=%u flags=%u is_bit=%u as_unicode=%u",
                     *current_field, i,
                     fields_metadata[i].db, fields_metadata[i].table, fields_metadata[i].name, fields_metadata[i].type,
                     fields_metadata[i].flags & UNSIGNED_FLAG, fields_metadata[i].flags, fields_metadata[i].type == MYSQL_TYPE_BIT, as_unicode);
              if (*null_ptr & bit) {
                     DBG_INF("It's null");
                     ZVAL_NULL(*current_field);
                     statistic = STAT_BINARY_TYPE_FETCHED_NULL;
              } else {
                     enum_mysqlnd_field_types type = fields_metadata[i].type;
                     mysqlnd_ps_fetch_functions[type].func(*current_field, &fields_metadata[i], 0, &p, as_unicode TSRMLS_CC);

                     if (MYSQLND_G(collect_statistics)) {
                            switch (fields_metadata[i].type) {
                                   case MYSQL_TYPE_DECIMAL:    statistic = STAT_BINARY_TYPE_FETCHED_DECIMAL; break;
                                   case MYSQL_TYPE_TINY:              statistic = STAT_BINARY_TYPE_FETCHED_INT8; break;
                                   case MYSQL_TYPE_SHORT:             statistic = STAT_BINARY_TYPE_FETCHED_INT16; break;
                                   case MYSQL_TYPE_LONG:              statistic = STAT_BINARY_TYPE_FETCHED_INT32; break;
                                   case MYSQL_TYPE_FLOAT:             statistic = STAT_BINARY_TYPE_FETCHED_FLOAT; break;
                                   case MYSQL_TYPE_DOUBLE:            statistic = STAT_BINARY_TYPE_FETCHED_DOUBLE; break;
                                   case MYSQL_TYPE_NULL:              statistic = STAT_BINARY_TYPE_FETCHED_NULL; break;
                                   case MYSQL_TYPE_TIMESTAMP:  statistic = STAT_BINARY_TYPE_FETCHED_TIMESTAMP; break;
                                   case MYSQL_TYPE_LONGLONG:   statistic = STAT_BINARY_TYPE_FETCHED_INT64; break;
                                   case MYSQL_TYPE_INT24:             statistic = STAT_BINARY_TYPE_FETCHED_INT24; break;
                                   case MYSQL_TYPE_DATE:              statistic = STAT_BINARY_TYPE_FETCHED_DATE; break;
                                   case MYSQL_TYPE_TIME:              statistic = STAT_BINARY_TYPE_FETCHED_TIME; break;
                                   case MYSQL_TYPE_DATETIME:   statistic = STAT_BINARY_TYPE_FETCHED_DATETIME; break;
                                   case MYSQL_TYPE_YEAR:              statistic = STAT_BINARY_TYPE_FETCHED_YEAR; break;
                                   case MYSQL_TYPE_NEWDATE:    statistic = STAT_BINARY_TYPE_FETCHED_DATE; break;
                                   case MYSQL_TYPE_VARCHAR:    statistic = STAT_BINARY_TYPE_FETCHED_STRING; break;
                                   case MYSQL_TYPE_BIT:        statistic = STAT_BINARY_TYPE_FETCHED_BIT; break;
                                   case MYSQL_TYPE_NEWDECIMAL: statistic = STAT_BINARY_TYPE_FETCHED_DECIMAL; break;
                                   case MYSQL_TYPE_ENUM:              statistic = STAT_BINARY_TYPE_FETCHED_ENUM; break;
                                   case MYSQL_TYPE_SET:        statistic = STAT_BINARY_TYPE_FETCHED_SET; break;
                                   case MYSQL_TYPE_TINY_BLOB:  statistic = STAT_BINARY_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_MEDIUM_BLOB:statistic = STAT_BINARY_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_LONG_BLOB:  statistic = STAT_BINARY_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_BLOB:              statistic = STAT_BINARY_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_VAR_STRING: statistic = STAT_BINARY_TYPE_FETCHED_STRING; break;
                                   case MYSQL_TYPE_STRING:            statistic = STAT_BINARY_TYPE_FETCHED_STRING; break;
                                   case MYSQL_TYPE_GEOMETRY:   statistic = STAT_BINARY_TYPE_FETCHED_GEOMETRY; break;
                                   default: statistic = STAT_BINARY_TYPE_FETCHED_OTHER; break;
                            }
                     }
              }
              MYSQLND_INC_CONN_STATISTIC_W_VALUE2(stats, statistic, 1,
                                                                      STAT_BYTES_RECEIVED_PURE_DATA_PS,
                                                                      (Z_TYPE_PP(current_field) == IS_STRING)?
                                                                             Z_STRLEN_PP(current_field) : (p - orig_p));

              if (!((bit<<=1) & 255)) {
                     bit = 1;      /* to the following byte */
                     null_ptr++;
              }
       }

       DBG_RETURN(PASS);
}

Here is the call graph for this function:

Here is the caller graph for this function:

enum_func_status php_mysqlnd_rowp_read_text_protocol ( MYSQLND_MEMORY_POOL_CHUNK *  row_buffer,
zval **  fields,
unsigned int  field_count,
MYSQLND_FIELD fields_metadata,
zend_bool  persistent,
zend_bool  as_unicode,
zend_bool  as_int_or_float,
MYSQLND_STATS *stats  TSRMLS_DC 
)

Definition at line 1290 of file mysqlnd_wireprotocol.c.

{
       unsigned int i;
       zend_bool last_field_was_string = FALSE;
       zval **current_field, **end_field, **start_field;
       zend_uchar *p = row_buffer->ptr;
       size_t data_size = row_buffer->app;
       zend_uchar *bit_area = (zend_uchar*) row_buffer->ptr + data_size + 1; /* we allocate from here */

       DBG_ENTER("php_mysqlnd_rowp_read_text_protocol");

       if (!fields) {
              DBG_RETURN(FAIL);
       }

       end_field = (start_field = fields) + field_count;

       for (i = 0, current_field = start_field; current_field < end_field; current_field++, i++) {
              DBG_INF("Directly creating zval");
              MAKE_STD_ZVAL(*current_field);
              if (!*current_field) {
                     DBG_RETURN(FAIL);
              }
       }

       for (i = 0, current_field = start_field; current_field < end_field; current_field++, i++) {
              /* Don't reverse the order. It is significant!*/
              zend_uchar *this_field_len_pos = p;
              /* php_mysqlnd_net_field_length() call should be after *this_field_len_pos = p; */
              unsigned long len = php_mysqlnd_net_field_length(&p);

              if (current_field > start_field && last_field_was_string) {
                     /*
                       Normal queries:
                       We have to put \0 now to the end of the previous field, if it was
                       a string. IS_NULL doesn't matter. Because we have already read our
                       length, then we can overwrite it in the row buffer.
                       This statement terminates the previous field, not the current one.

                       NULL_LENGTH is encoded in one byte, so we can stick a \0 there.
                       Any string's length is encoded in at least one byte, so we can stick
                       a \0 there.
                     */

                     *this_field_len_pos = '\0';
              }

              /* NULL or NOT NULL, this is the question! */
              if (len == MYSQLND_NULL_LENGTH) {
                     ZVAL_NULL(*current_field);
                     last_field_was_string = FALSE;
              } else {
#if MYSQLND_UNICODE || defined(MYSQLND_STRING_TO_INT_CONVERSION)
                     struct st_mysqlnd_perm_bind perm_bind =
                                   mysqlnd_ps_fetch_functions[fields_metadata[i].type];
#endif
                     if (MYSQLND_G(collect_statistics)) {
                            enum_mysqlnd_collected_stats statistic;
                            switch (fields_metadata[i].type) {
                                   case MYSQL_TYPE_DECIMAL:    statistic = STAT_TEXT_TYPE_FETCHED_DECIMAL; break;
                                   case MYSQL_TYPE_TINY:              statistic = STAT_TEXT_TYPE_FETCHED_INT8; break;
                                   case MYSQL_TYPE_SHORT:             statistic = STAT_TEXT_TYPE_FETCHED_INT16; break;
                                   case MYSQL_TYPE_LONG:              statistic = STAT_TEXT_TYPE_FETCHED_INT32; break;
                                   case MYSQL_TYPE_FLOAT:             statistic = STAT_TEXT_TYPE_FETCHED_FLOAT; break;
                                   case MYSQL_TYPE_DOUBLE:            statistic = STAT_TEXT_TYPE_FETCHED_DOUBLE; break;
                                   case MYSQL_TYPE_NULL:              statistic = STAT_TEXT_TYPE_FETCHED_NULL; break;
                                   case MYSQL_TYPE_TIMESTAMP:  statistic = STAT_TEXT_TYPE_FETCHED_TIMESTAMP; break;
                                   case MYSQL_TYPE_LONGLONG:   statistic = STAT_TEXT_TYPE_FETCHED_INT64; break;
                                   case MYSQL_TYPE_INT24:             statistic = STAT_TEXT_TYPE_FETCHED_INT24; break;
                                   case MYSQL_TYPE_DATE:              statistic = STAT_TEXT_TYPE_FETCHED_DATE; break;
                                   case MYSQL_TYPE_TIME:              statistic = STAT_TEXT_TYPE_FETCHED_TIME; break;
                                   case MYSQL_TYPE_DATETIME:   statistic = STAT_TEXT_TYPE_FETCHED_DATETIME; break;
                                   case MYSQL_TYPE_YEAR:              statistic = STAT_TEXT_TYPE_FETCHED_YEAR; break;
                                   case MYSQL_TYPE_NEWDATE:    statistic = STAT_TEXT_TYPE_FETCHED_DATE; break;
                                   case MYSQL_TYPE_VARCHAR:    statistic = STAT_TEXT_TYPE_FETCHED_STRING; break;
                                   case MYSQL_TYPE_BIT:        statistic = STAT_TEXT_TYPE_FETCHED_BIT; break;
                                   case MYSQL_TYPE_NEWDECIMAL: statistic = STAT_TEXT_TYPE_FETCHED_DECIMAL; break;
                                   case MYSQL_TYPE_ENUM:              statistic = STAT_TEXT_TYPE_FETCHED_ENUM; break;
                                   case MYSQL_TYPE_SET:        statistic = STAT_TEXT_TYPE_FETCHED_SET; break;
                                   case MYSQL_TYPE_TINY_BLOB:  statistic = STAT_TEXT_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_MEDIUM_BLOB:statistic = STAT_TEXT_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_LONG_BLOB:  statistic = STAT_TEXT_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_BLOB:              statistic = STAT_TEXT_TYPE_FETCHED_BLOB; break;
                                   case MYSQL_TYPE_VAR_STRING: statistic = STAT_TEXT_TYPE_FETCHED_STRING; break;
                                   case MYSQL_TYPE_STRING:            statistic = STAT_TEXT_TYPE_FETCHED_STRING; break;
                                   case MYSQL_TYPE_GEOMETRY:   statistic = STAT_TEXT_TYPE_FETCHED_GEOMETRY; break;
                                   default: statistic = STAT_TEXT_TYPE_FETCHED_OTHER; break;
                            }
                            MYSQLND_INC_CONN_STATISTIC_W_VALUE2(stats, statistic, 1, STAT_BYTES_RECEIVED_PURE_DATA_TEXT, len);
                     }
#ifdef MYSQLND_STRING_TO_INT_CONVERSION
                     if (as_int_or_float && perm_bind.php_type == IS_LONG) {
                            zend_uchar save = *(p + len);
                            /* We have to make it ASCIIZ temporarily */
                            *(p + len) = '\0';
                            if (perm_bind.pack_len < SIZEOF_LONG) {
                                   /* direct conversion */
                                   int64_t v =
#ifndef PHP_WIN32
                                          atoll((char *) p);
#else
                                          _atoi64((char *) p);
#endif
                                   ZVAL_LONG(*current_field, (long) v); /* the cast is safe */
                            } else {
                                   uint64_t v =
#ifndef PHP_WIN32
                                          (uint64_t) atoll((char *) p);
#else
                                          (uint64_t) _atoi64((char *) p);
#endif
                                   zend_bool uns = fields_metadata[i].flags & UNSIGNED_FLAG? TRUE:FALSE;
                                   /* We have to make it ASCIIZ temporarily */
#if SIZEOF_LONG==8
                                   if (uns == TRUE && v > 9223372036854775807L)
#elif SIZEOF_LONG==4
                                   if ((uns == TRUE && v > L64(2147483647)) ||
                                          (uns == FALSE && (( L64(2147483647) < (int64_t) v) ||
                                          (L64(-2147483648) > (int64_t) v))))
#else
#error Need fix for this architecture
#endif /* SIZEOF */
                                   {
                                          ZVAL_STRINGL(*current_field, (char *)p, len, 0);
                                   } else {
                                          ZVAL_LONG(*current_field, (long) v); /* the cast is safe */
                                   }
                            }
                            *(p + len) = save;
                     } else if (as_int_or_float && perm_bind.php_type == IS_DOUBLE) {
                            zend_uchar save = *(p + len);
                            /* We have to make it ASCIIZ temporarily */
                            *(p + len) = '\0';
                            ZVAL_DOUBLE(*current_field, atof((char *) p));
                            *(p + len) = save;
                     } else
#endif /* MYSQLND_STRING_TO_INT_CONVERSION */
                     if (fields_metadata[i].type == MYSQL_TYPE_BIT) {
                            /*
                              BIT fields are specially handled. As they come as bit mask, we have
                              to convert it to human-readable representation. As the bits take
                              less space in the protocol than the numbers they represent, we don't
                              have enough space in the packet buffer to overwrite inside.
                              Thus, a bit more space is pre-allocated at the end of the buffer,
                              see php_mysqlnd_rowp_read(). And we add the strings at the end.
                              Definitely not nice, _hackish_ :(, but works.
                            */
                            zend_uchar *start = bit_area;
                            ps_fetch_from_1_to_8_bytes(*current_field, &(fields_metadata[i]), 0, &p, as_unicode, len TSRMLS_CC);
                            /*
                              We have advanced in ps_fetch_from_1_to_8_bytes. We should go back because
                              later in this function there will be an advancement.
                            */
                            p -= len;
                            if (Z_TYPE_PP(current_field) == IS_LONG) {
                                   bit_area += 1 + sprintf((char *)start, "%ld", Z_LVAL_PP(current_field));
#if MYSQLND_UNICODE
                                   if (as_unicode) {
                                          ZVAL_UTF8_STRINGL(*current_field, start, bit_area - start - 1, 0);
                                   } else
#endif
                                   {
                                          ZVAL_STRINGL(*current_field, (char *) start, bit_area - start - 1, 0);
                                   }
                            } else if (Z_TYPE_PP(current_field) == IS_STRING){
                                   memcpy(bit_area, Z_STRVAL_PP(current_field), Z_STRLEN_PP(current_field));
                                   bit_area += Z_STRLEN_PP(current_field);
                                   *bit_area++ = '\0';
                                   zval_dtor(*current_field);
#if MYSQLND_UNICODE
                                   if (as_unicode) {
                                          ZVAL_UTF8_STRINGL(*current_field, start, bit_area - start - 1, 0);
                                   } else
#endif
                                   {
                                          ZVAL_STRINGL(*current_field, (char *) start, bit_area - start - 1, 0);
                                   }
                            }
                            /*
                              IS_UNICODE should not be specially handled. In unicode mode
                              the buffers are not referenced - everything is copied.
                            */
                     } else
#if MYSQLND_UNICODE == 0
                     {
                            ZVAL_STRINGL(*current_field, (char *)p, len, 0);
                     }
#else
                     /*
                       Here we have to convert to UTF16, which means not reusing the buffer.
                       Which in turn means that we can free the buffers once we have
                       stored the result set, if we use store_result().

                       Also the destruction of the zvals should not call zval_copy_ctor()
                       because then we will leak.

                       XXX: Keep in mind that up there there is an open `else` in
                       #ifdef MYSQLND_STRING_TO_INT_CONVERSION
                       which will make with this `if` an `else if`.
                     */
                     if ((perm_bind.is_possibly_blob == TRUE &&
                             fields_metadata[i].charsetnr == MYSQLND_BINARY_CHARSET_NR) ||
                            (!as_unicode && perm_bind.can_ret_as_str_in_uni == TRUE))
                     {
                            /* BLOB - no conversion please */
                            ZVAL_STRINGL(*current_field, (char *)p, len, 0);
                     } else {
                            ZVAL_UTF8_STRINGL(*current_field, (char *)p, len, 0);
                     }
#endif
                     p += len;
                     last_field_was_string = TRUE;
              }
       }
       if (last_field_was_string) {
              /* Normal queries: The buffer has one more byte at the end, because we need it */
              row_buffer->ptr[data_size] = '\0';
       }

       DBG_RETURN(PASS);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void php_mysqlnd_scramble ( zend_uchar *const  buffer,
const zend_uchar *const  scramble,
const zend_uchar *const  pass 
)

Definition at line 420 of file mysqlnd_wireprotocol.c.

{
       PHP_SHA1_CTX context;
       zend_uchar sha1[SHA1_MAX_LENGTH];
       zend_uchar sha2[SHA1_MAX_LENGTH];


       /* Phase 1: hash password */
       PHP_SHA1Init(&context);
       PHP_SHA1Update(&context, password, strlen((char *)password));
       PHP_SHA1Final(sha1, &context);

       /* Phase 2: hash sha1 */
       PHP_SHA1Init(&context);
       PHP_SHA1Update(&context, (zend_uchar*)sha1, SHA1_MAX_LENGTH);
       PHP_SHA1Final(sha2, &context);

       /* Phase 3: hash scramble + sha2 */
       PHP_SHA1Init(&context);
       PHP_SHA1Update(&context, scramble, SCRAMBLE_LENGTH);
       PHP_SHA1Update(&context, (zend_uchar*)sha2, SHA1_MAX_LENGTH);
       PHP_SHA1Final(buffer, &context);

       /* let's crypt buffer now */
       php_mysqlnd_crypt(buffer, (const zend_uchar *)buffer, (const zend_uchar *)sha1, SHA1_MAX_LENGTH);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 84 of file mysqlnd_wireprotocol.c.

PHPAPI const char* const mysqlnd_empty_string

Definition at line 72 of file mysqlnd_wireprotocol.c.

Definition at line 76 of file mysqlnd_wireprotocol.c.

Definition at line 75 of file mysqlnd_wireprotocol.c.