php-src/ext/mysqlnd/mysqlnd_ext_plugin.c
Andrey Hristov cfd868651a MDNR:
- 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.
2015-11-12 16:19:16 +01:00

314 lines
9.2 KiB
C

/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2015 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
| Georg Richter <georg@mysql.com> |
+----------------------------------------------------------------------+
*/
/* $Id: mysqlnd.c 318221 2011-10-19 15:04:12Z andrey $ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_priv.h"
#include "mysqlnd_result.h"
#include "mysqlnd_debug.h"
static struct st_mysqlnd_conn_methods * mysqlnd_conn_methods;
static struct st_mysqlnd_conn_data_methods * mysqlnd_conn_data_methods;
static struct st_mysqlnd_stmt_methods * mysqlnd_stmt_methods;
/* {{{ _mysqlnd_plugin_get_plugin_connection_data */
PHPAPI void **
_mysqlnd_plugin_get_plugin_connection_data(const MYSQLND * conn, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_connection_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!conn || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)conn + sizeof(MYSQLND) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_connection_data_data */
PHPAPI void **
_mysqlnd_plugin_get_plugin_connection_data_data(const MYSQLND_CONN_DATA * conn, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_connection_data_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!conn || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)conn + sizeof(MYSQLND_CONN_DATA) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_result_data */
PHPAPI void ** _mysqlnd_plugin_get_plugin_result_data(const MYSQLND_RES * result, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_result_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!result || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_result_unbuffered_data */
PHPAPI void ** _mysqlnd_plugin_get_plugin_result_unbuffered_data(const MYSQLND_RES_UNBUFFERED * result, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_result_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!result || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES_UNBUFFERED) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_result_buffered_data */
PHPAPI void ** _mysqlnd_plugin_get_plugin_result_buffered_data_zval(const MYSQLND_RES_BUFFERED_ZVAL * result, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_result_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!result || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES_BUFFERED_ZVAL) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_result_buffered_data */
PHPAPI void ** _mysqlnd_plugin_get_plugin_result_buffered_data_c(const MYSQLND_RES_BUFFERED_C * result, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_result_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!result || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES_BUFFERED_C) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_protocol_data */
PHPAPI void **
_mysqlnd_plugin_get_plugin_protocol_data(const MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_protocol_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!factory || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)factory + sizeof(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_stmt_data */
PHPAPI void ** _mysqlnd_plugin_get_plugin_stmt_data(const MYSQLND_STMT * stmt, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_stmt_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!stmt || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)stmt + sizeof(MYSQLND_STMT) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_net_data */
PHPAPI void ** _mysqlnd_plugin_get_plugin_net_data(const MYSQLND_NET * net, unsigned int plugin_id)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_net_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!net || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)net + sizeof(MYSQLND_NET) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ 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 *
mysqlnd_conn_get_methods()
{
return mysqlnd_conn_methods;
}
/* }}} */
/* {{{ mysqlnd_conn_set_methods */
PHPAPI void mysqlnd_conn_set_methods(struct st_mysqlnd_conn_methods *methods)
{
mysqlnd_conn_methods = methods;
}
/* }}} */
/* {{{ mysqlnd_conn_get_methods */
PHPAPI struct st_mysqlnd_conn_data_methods *
mysqlnd_conn_data_get_methods()
{
return mysqlnd_conn_data_methods;
}
/* }}} */
/* {{{ mysqlnd_conn_set_methods */
PHPAPI void mysqlnd_conn_data_set_methods(struct st_mysqlnd_conn_data_methods * methods)
{
mysqlnd_conn_data_methods = methods;
}
/* }}} */
/* {{{ mysqlnd_result_get_methods */
PHPAPI struct st_mysqlnd_res_methods *
mysqlnd_result_get_methods()
{
return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_res);
}
/* }}} */
/* {{{ mysqlnd_result_set_methods */
PHPAPI void
mysqlnd_result_set_methods(struct st_mysqlnd_res_methods * methods)
{
MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_res) = *methods;
}
/* }}} */
/* {{{ mysqlnd_result_unbuffered_get_methods */
PHPAPI struct st_mysqlnd_result_unbuffered_methods *
mysqlnd_result_unbuffered_get_methods()
{
return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_unbuffered);
}
/* }}} */
/* {{{ mysqlnd_result_unbuffered_set_methods */
PHPAPI void
mysqlnd_result_unbuffered_set_methods(struct st_mysqlnd_result_unbuffered_methods * methods)
{
MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_unbuffered) = *methods;
}
/* }}} */
/* {{{ mysqlnd_result_buffered_get_methods */
PHPAPI struct st_mysqlnd_result_buffered_methods *
mysqlnd_result_buffered_get_methods()
{
return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_buffered);
}
/* }}} */
/* {{{ mysqlnd_result_buffered_set_methods */
PHPAPI void
mysqlnd_result_buffered_set_methods(struct st_mysqlnd_result_buffered_methods * methods)
{
MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_buffered) = *methods;
}
/* }}} */
/* {{{ mysqlnd_stmt_get_methods */
PHPAPI struct st_mysqlnd_stmt_methods *
mysqlnd_stmt_get_methods()
{
return mysqlnd_stmt_methods;
}
/* }}} */
/* {{{ mysqlnd_stmt_set_methods */
PHPAPI void
mysqlnd_stmt_set_methods(struct st_mysqlnd_stmt_methods *methods)
{
mysqlnd_stmt_methods = methods;
}
/* }}} */
/* {{{ mysqlnd_protocol_payload_decoder_factory_get_methods */
PHPAPI struct st_mysqlnd_protocol_payload_decoder_factory_methods *
mysqlnd_protocol_payload_decoder_factory_get_methods()
{
return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory);
}
/* }}} */
/* {{{ mysqlnd_protocol_payload_decoder_factory_set_methods */
PHPAPI void
mysqlnd_protocol_payload_decoder_factory_set_methods(struct st_mysqlnd_protocol_payload_decoder_factory_methods * methods)
{
MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory) = *methods;
}
/* }}} */
/* {{{ mysqlnd_net_get_methods */
PHPAPI struct st_mysqlnd_net_methods *
mysqlnd_net_get_methods()
{
return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_net);
}
/* }}} */
/* {{{ mysqlnd_net_set_methods */
PHPAPI void
mysqlnd_net_set_methods(struct st_mysqlnd_net_methods * methods)
{
MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_net) = *methods;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/