Skip to content

Commit

Permalink
MNDR:
Browse files Browse the repository at this point in the history
- better name for MYSQLND_PPEC - MYSQLND_PFC (protocol frame codec)
  • Loading branch information
faizshukri committed Nov 12, 2015
1 parent 654d1a7 commit a530ecf
Show file tree
Hide file tree
Showing 18 changed files with 725 additions and 693 deletions.
3 changes: 2 additions & 1 deletion ext/mysqlnd/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ if (PHP_MYSQLND != "no") {
"mysqlnd_ext_plugin.c " +
"mysqlnd_loaddata.c " +
"mysqlnd_reverse_api.c " +
"mysqlnd_vio.c " +
"mysqlnd_plugin.c " +
"mysqlnd_protocol_frame_codec.c " +
"mysqlnd_ps.c " +
"mysqlnd_ps_codec.c " +
"mysqlnd_result.c " +
"mysqlnd_result_meta.c " +
"mysqlnd_statistics.c " +
"mysqlnd_vio.c " +
"mysqlnd_wireprotocol.c " +
"php_mysqlnd.c ";
EXTENSION("mysqlnd", mysqlnd_source, false, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqlnd/config9.m4
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dnl If some extension uses mysqlnd it will get compiled in PHP core
if test "$PHP_MYSQLND" != "no" || test "$PHP_MYSQLND_ENABLED" = "yes"; then
mysqlnd_ps_sources="mysqlnd_ps.c mysqlnd_ps_codec.c"
mysqlnd_base_sources="mysqlnd.c mysqlnd_alloc.c mysqlnd_charset.c mysqlnd_wireprotocol.c \
mysqlnd_loaddata.c mysqlnd_reverse_api.c mysqlnd_vio.c \
mysqlnd_loaddata.c mysqlnd_reverse_api.c mysqlnd_vio.c mysqlnd_protocol_frame_codec.c \
mysqlnd_statistics.c mysqlnd_driver.c mysqlnd_ext_plugin.c mysqlnd_auth.c \
mysqlnd_result.c mysqlnd_result_meta.c mysqlnd_debug.c\
mysqlnd_block_alloc.c mysqlnd_plugin.c php_mysqlnd.c"
Expand Down
62 changes: 30 additions & 32 deletions ext/mysqlnd/mysqlnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
+----------------------------------------------------------------------+
*/

/* $Id$ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_vio.h"
#include "mysqlnd_protocol_frame_codec.h"
#include "mysqlnd_wireprotocol.h"
#include "mysqlnd_priv.h"
#include "mysqlnd_result.h"
Expand Down Expand Up @@ -267,8 +267,8 @@ MYSQLND_METHOD(mysqlnd_conn_data, free_contents)(MYSQLND_CONN_DATA * conn)
conn->current_result = NULL;
}

if (conn->net) {
conn->net->data->m.free_contents(conn->net);
if (conn->protocol_frame_codec) {
conn->protocol_frame_codec->data->m.free_contents(conn->protocol_frame_codec);
}

if (conn->vio) {
Expand Down Expand Up @@ -341,9 +341,9 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, dtor)(MYSQLND_CONN_DATA * conn)
conn->m->free_contents(conn);
conn->m->free_options(conn);

if (conn->net) {
mysqlnd_ppec_free(conn->net, conn->stats, conn->error_info);
conn->net = NULL;
if (conn->protocol_frame_codec) {
mysqlnd_pfc_free(conn->protocol_frame_codec, conn->stats, conn->error_info);
conn->protocol_frame_codec = NULL;
}

if (conn->vio) {
Expand Down Expand Up @@ -540,7 +540,7 @@ mysqlnd_run_authentication(
scrambled_data =
auth_plugin->methods.get_auth_data(NULL, &scrambled_data_len, conn, user, passwd, passwd_len,
plugin_data, plugin_data_len, session_options,
&conn->net->data->options, mysql_flags);
&conn->protocol_frame_codec->data->options, mysql_flags);
if (conn->error_info->error_no) {
goto end;
}
Expand Down Expand Up @@ -664,7 +664,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, execute_init_commands)(MYSQLND_CONN_DATA * con
static unsigned int
MYSQLND_METHOD(mysqlnd_conn_data, get_updated_connect_flags)(MYSQLND_CONN_DATA * conn, unsigned int mysql_flags)
{
MYSQLND_PPEC * net = conn->net;
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
MYSQLND_VIO * vio = conn->vio;

DBG_ENTER("mysqlnd_conn_data::get_updated_connect_flags");
Expand All @@ -682,7 +682,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, get_updated_connect_flags)(MYSQLND_CONN_DATA *
mysql_flags &= ~CLIENT_COMPRESS;
}
#else
if (net && net->data->options.flags & MYSQLND_NET_FLAG_USE_COMPRESSION) {
if (pfc && pfc->data->options.flags & MYSQLND_NET_FLAG_USE_COMPRESSION) {
mysql_flags |= CLIENT_COMPRESS;
}
#endif
Expand Down Expand Up @@ -713,12 +713,12 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect_handshake)(MYSQLND_CONN_DATA * conn,
const unsigned int mysql_flags)
{
enum_func_status ret = FAIL;
size_t client_flags = mysql_flags;
DBG_ENTER("mysqlnd_conn_data::connect_handshake");

if (FAIL == conn->vio->data->m.connect(conn->vio, *scheme, conn->persistent, conn->stats, conn->error_info)) {
DBG_RETURN(FAIL);
} else if (PASS == conn->net->data->m.connect(conn->net, *scheme, conn->persistent, conn->stats, conn->error_info)) {
if (PASS == conn->vio->data->m.connect(conn->vio, *scheme, conn->persistent, conn->stats, conn->error_info) &&
PASS == conn->protocol_frame_codec->data->m.reset(conn->protocol_frame_codec, conn->stats, conn->error_info))
{
size_t client_flags = mysql_flags;
struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_HANDSHAKE, conn, username, password, database, client_flags);
if (command) {
ret = command->run(command);
Expand Down Expand Up @@ -784,7 +784,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
zend_bool reconnect = FALSE;
zend_bool saved_compression = FALSE;
zend_bool local_tx_started = FALSE;
MYSQLND_PPEC * net = conn->net;
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
MYSQLND_STRING transport = { NULL, 0 };

DBG_ENTER("mysqlnd_conn_data::connect");
Expand Down Expand Up @@ -813,17 +813,17 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,

conn->m->free_contents(conn);
/* Now reconnect using the same handle */
if (net->data->compressed) {
if (pfc->data->compressed) {
/*
we need to save the state. As we will re-connect, net->compressed should be off, or
we need to save the state. As we will re-connect, pfc->compressed should be off, or
we will look for a compression header as part of the greet message, but there will
be none.
*/
saved_compression = TRUE;
net->data->compressed = FALSE;
pfc->data->compressed = FALSE;
}
if (net->data->ssl) {
net->data->ssl = FALSE;
if (pfc->data->ssl) {
pfc->data->ssl = FALSE;
}
} else {
unsigned int max_allowed_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE;
Expand Down Expand Up @@ -867,14 +867,14 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
SET_CONNECTION_STATE(&conn->state, CONN_READY);

if (saved_compression) {
net->data->compressed = TRUE;
pfc->data->compressed = TRUE;
}
/*
If a connect on a existing handle is performed and mysql_flags is
passed which doesn't CLIENT_COMPRESS, then we need to overwrite the value
which we set based on saved_compression.
*/
net->data->compressed = mysql_flags & CLIENT_COMPRESS? TRUE:FALSE;
pfc->data->compressed = mysql_flags & CLIENT_COMPRESS? TRUE:FALSE;


conn->scheme.s = mnd_pestrndup(transport.s, transport.l, conn->persistent);
Expand Down Expand Up @@ -1435,15 +1435,15 @@ MYSQLND_METHOD(mysqlnd_conn_data, ssl_set)(MYSQLND_CONN_DATA * const conn, const
{
const size_t this_func = STRUCT_OFFSET(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data), ssl_set);
enum_func_status ret = FAIL;
MYSQLND_VIO * net = conn->vio;
MYSQLND_VIO * vio = conn->vio;
DBG_ENTER("mysqlnd_conn_data::ssl_set");

if (PASS == conn->m->local_tx_start(conn, this_func)) {
ret = (PASS == net->data->m.set_client_option(net, MYSQLND_OPT_SSL_KEY, key) &&
PASS == net->data->m.set_client_option(net, MYSQLND_OPT_SSL_CERT, cert) &&
PASS == net->data->m.set_client_option(net, MYSQLND_OPT_SSL_CA, ca) &&
PASS == net->data->m.set_client_option(net, MYSQLND_OPT_SSL_CAPATH, capath) &&
PASS == net->data->m.set_client_option(net, MYSQLND_OPT_SSL_CIPHER, cipher)) ? PASS : FAIL;
ret = (PASS == vio->data->m.set_client_option(vio, MYSQLND_OPT_SSL_KEY, key) &&
PASS == vio->data->m.set_client_option(vio, MYSQLND_OPT_SSL_CERT, cert) &&
PASS == vio->data->m.set_client_option(vio, MYSQLND_OPT_SSL_CA, ca) &&
PASS == vio->data->m.set_client_option(vio, MYSQLND_OPT_SSL_CAPATH, capath) &&
PASS == vio->data->m.set_client_option(vio, MYSQLND_OPT_SSL_CIPHER, cipher)) ? PASS : FAIL;

conn->m->local_tx_end(conn, this_func, ret);
}
Expand Down Expand Up @@ -1688,12 +1688,10 @@ MYSQLND_METHOD(mysqlnd_conn_data, send_close)(MYSQLND_CONN_DATA * const conn)
enum_func_status ret = PASS;
MYSQLND_VIO * vio = conn->vio;
php_stream * net_stream = vio->data->m.get_stream(vio);
enum mysqlnd_connection_state state;
enum mysqlnd_connection_state state = GET_CONNECTION_STATE(&conn->state);

DBG_ENTER("mysqlnd_send_close");
DBG_INF_FMT("conn=%llu net->data->stream->abstract=%p", conn->thread_id, net_stream? net_stream->abstract:NULL);

state = GET_CONNECTION_STATE(&conn->state);
DBG_INF_FMT("conn=%llu vio->data->stream->abstract=%p", conn->thread_id, net_stream? net_stream->abstract:NULL);
DBG_INF_FMT("state=%u", state);

if (state >= CONN_READY) {
Expand Down Expand Up @@ -2116,7 +2114,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const c
ret = conn->vio->data->m.set_client_option(conn->vio, option, value);
break;
case MYSQL_SERVER_PUBLIC_KEY:
ret = conn->net->data->m.set_client_option(conn->net, option, value);
ret = conn->protocol_frame_codec->data->m.set_client_option(conn->protocol_frame_codec, option, value);
break;
#ifdef MYSQLND_STRING_TO_INT_CONVERSION
case MYSQLND_OPT_INT_AND_FLOAT_NATIVE:
Expand Down
11 changes: 5 additions & 6 deletions ext/mysqlnd/mysqlnd_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
+----------------------------------------------------------------------+
*/

/* $Id: mysqlnd.c 307377 2011-01-11 13:02:57Z andrey $ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_structs.h"
Expand Down Expand Up @@ -360,7 +359,7 @@ mysqlnd_native_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd,
const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len,
const MYSQLND_SESSION_OPTIONS * const session_options,
const MYSQLND_PPEC_OPTIONS * const ppec_options,
const MYSQLND_PFC_OPTIONS * const ppec_options,
zend_ulong mysql_flags
)
{
Expand Down Expand Up @@ -420,7 +419,7 @@ mysqlnd_pam_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self,
MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd,
const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len,
const MYSQLND_SESSION_OPTIONS * const session_options,
const MYSQLND_PPEC_OPTIONS * const ppec_options,
const MYSQLND_PFC_OPTIONS * const ppec_options,
zend_ulong mysql_flags
)
{
Expand Down Expand Up @@ -481,7 +480,7 @@ mysqlnd_xor_string(char * dst, const size_t dst_len, const char * xor_str, const
static RSA *
mysqlnd_sha256_get_rsa_key(MYSQLND_CONN_DATA * conn,
const MYSQLND_SESSION_OPTIONS * const session_options,
const MYSQLND_PPEC_OPTIONS * const io_options
const MYSQLND_PFC_OPTIONS * const io_options
)
{
RSA * ret = NULL;
Expand Down Expand Up @@ -570,7 +569,7 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd,
const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len,
const MYSQLND_SESSION_OPTIONS * const session_options,
const MYSQLND_PPEC_OPTIONS * const ppec_options,
const MYSQLND_PFC_OPTIONS * const ppec_options,
zend_ulong mysql_flags
)
{
Expand All @@ -580,7 +579,7 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
DBG_INF_FMT("salt(%d)=[%.*s]", auth_plugin_data_len, auth_plugin_data_len, auth_plugin_data);


if (conn->net->data->ssl) {
if (conn->protocol_frame_codec->data->ssl) {
DBG_INF("simple clear text under SSL");
/* clear text under SSL */
*auth_data_len = passwd_len;
Expand Down
18 changes: 9 additions & 9 deletions ext/mysqlnd/mysqlnd_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
+----------------------------------------------------------------------+
*/

/* $Id: mysqlnd.c 317989 2011-10-10 20:49:28Z andrey $ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_vio.h"
#include "mysqlnd_protocol_frame_codec.h"
#include "mysqlnd_wireprotocol.h"
#include "mysqlnd_priv.h"
#include "mysqlnd_result.h"
Expand Down Expand Up @@ -140,12 +140,12 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(struct st_mysqlnd_object_

mysqlnd_stats_init(&data->stats, STAT_LAST, persistent);

data->net = mysqlnd_ppec_init(persistent, data->stats, data->error_info);
data->protocol_frame_codec = mysqlnd_pfc_init(persistent, data->stats, data->error_info);
data->vio = mysqlnd_vio_init(persistent, data->stats, data->error_info);
data->payload_decoder_factory = mysqlnd_protocol_payload_decoder_factory_init(data, persistent);
data->command_factory = mysqlnd_command_factory_get();

if (!data->net || !data->payload_decoder_factory) {
if (!data->protocol_frame_codec || !data->vio || !data->payload_decoder_factory || !data->command_factory) {
new_object->m->dtor(new_object);
DBG_RETURN(NULL);
}
Expand Down Expand Up @@ -244,20 +244,20 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA


/* {{{ mysqlnd_object_factory::get_ppec */
static MYSQLND_PPEC *
static MYSQLND_PFC *
MYSQLND_METHOD(mysqlnd_object_factory, get_ppec)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info)
{
size_t ppec_alloc_size = sizeof(MYSQLND_PPEC) + mysqlnd_plugin_count() * sizeof(void *);
size_t ppec_data_alloc_size = sizeof(MYSQLND_PPEC_DATA) + mysqlnd_plugin_count() * sizeof(void *);
MYSQLND_PPEC * ppec = mnd_pecalloc(1, ppec_alloc_size, persistent);
MYSQLND_PPEC_DATA * ppec_data = mnd_pecalloc(1, ppec_data_alloc_size, persistent);
size_t ppec_alloc_size = sizeof(MYSQLND_PFC) + mysqlnd_plugin_count() * sizeof(void *);
size_t ppec_data_alloc_size = sizeof(MYSQLND_PFC_DATA) + mysqlnd_plugin_count() * sizeof(void *);
MYSQLND_PFC * ppec = mnd_pecalloc(1, ppec_alloc_size, persistent);
MYSQLND_PFC_DATA * ppec_data = mnd_pecalloc(1, ppec_data_alloc_size, persistent);

DBG_ENTER("mysqlnd_object_factory::get_ppec");
DBG_INF_FMT("persistent=%u", persistent);
if (ppec && ppec_data) {
ppec->data = ppec_data;
ppec->persistent = ppec->data->persistent = persistent;
ppec->data->m = *mysqlnd_ppec_get_methods();
ppec->data->m = *mysqlnd_pfc_get_methods();

if (PASS != ppec->data->m.init(ppec, stats, error_info)) {
ppec->data->m.dtor(ppec, stats, error_info);
Expand Down
1 change: 0 additions & 1 deletion ext/mysqlnd/mysqlnd_enum_n_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
+----------------------------------------------------------------------+
*/

/* $Id$ */
#ifndef MYSQLND_ENUM_N_DEF_H
#define MYSQLND_ENUM_N_DEF_H

Expand Down
18 changes: 8 additions & 10 deletions ext/mysqlnd/mysqlnd_ext_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
| Ulf Wendel <[email protected]> |
+----------------------------------------------------------------------+
*/

/* $Id: mysqlnd.c 318221 2011-10-19 15:04:12Z andrey $ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_priv.h"
Expand Down Expand Up @@ -142,14 +140,14 @@ mysqlnd_plugin__get_plugin_stmt_data(const MYSQLND_STMT * stmt, unsigned int plu

/* {{{ mysqlnd_plugin__get_plugin_ppec_data */
static void **
mysqlnd_plugin__get_plugin_ppec_data(const MYSQLND_PPEC * ppec, unsigned int plugin_id)
mysqlnd_plugin__get_plugin_ppec_data(const MYSQLND_PFC * ppec, unsigned int plugin_id)
{
DBG_ENTER("mysqlnd_plugin__get_plugin_ppec_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!ppec || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)ppec + sizeof(MYSQLND_PPEC) + plugin_id * sizeof(void *)));
DBG_RETURN((void *)((char *)ppec + sizeof(MYSQLND_PFC) + plugin_id * sizeof(void *)));
}
/* }}} */

Expand Down Expand Up @@ -324,18 +322,18 @@ _mysqlnd_protocol_payload_decoder_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE
/* }}} */


/* {{{ _mysqlnd_ppec_get_methods */
/* {{{ _mysqlnd_pfc_get_methods */
static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_envelope_codec) *
_mysqlnd_ppec_get_methods()
_mysqlnd_pfc_get_methods()
{
return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_packet_envelope_codec);
}
/* }}} */


/* {{{ _mysqlnd_ppec_set_methods */
/* {{{ _mysqlnd_pfc_set_methods */
static void
_mysqlnd_ppec_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_envelope_codec) * methods)
_mysqlnd_pfc_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_envelope_codec) * methods)
{
MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_packet_envelope_codec) = *methods;
}
Expand Down Expand Up @@ -431,8 +429,8 @@ struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xetters =
_mysqlnd_protocol_payload_decoder_factory_set_methods,
},
{
_mysqlnd_ppec_get_methods,
_mysqlnd_ppec_set_methods,
_mysqlnd_pfc_get_methods,
_mysqlnd_pfc_set_methods,
},
{
_mysqlnd_vio_get_methods,
Expand Down
Loading

0 comments on commit a530ecf

Please sign in to comment.