PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/mysqlnd - mysqlnd_driver.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 111 159 69.8 %
Date: 2016-05-26 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2016 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Authors: Andrey Hristov <andrey@mysql.com>                           |
      16             :   |          Ulf Wendel <uwendel@mysql.com>                              |
      17             :   |          Georg Richter <georg@mysql.com>                             |
      18             :   +----------------------------------------------------------------------+
      19             : */
      20             : #include "php.h"
      21             : #include "mysqlnd.h"
      22             : #include "mysqlnd_vio.h"
      23             : #include "mysqlnd_protocol_frame_codec.h"
      24             : #include "mysqlnd_wireprotocol.h"
      25             : #include "mysqlnd_connection.h"
      26             : #include "mysqlnd_ps.h"
      27             : #include "mysqlnd_plugin.h"
      28             : #include "mysqlnd_priv.h"
      29             : #include "mysqlnd_statistics.h"
      30             : #include "mysqlnd_debug.h"
      31             : #include "mysqlnd_reverse_api.h"
      32             : #include "mysqlnd_ext_plugin.h"
      33             : 
      34             : static zend_bool mysqlnd_library_initted = FALSE;
      35             : 
      36             : static struct st_mysqlnd_plugin_core mysqlnd_plugin_core =
      37             : {
      38             :         {
      39             :                 MYSQLND_PLUGIN_API_VERSION,
      40             :                 "mysqlnd",
      41             :                 MYSQLND_VERSION_ID,
      42             :                 PHP_MYSQLND_VERSION,
      43             :                 "PHP License 3.01",
      44             :                 "Andrey Hristov <andrey@mysql.com>,  Ulf Wendel <uwendel@mysql.com>, Georg Richter <georg@mysql.com>",
      45             :                 {
      46             :                         NULL, /* will be filled later */
      47             :                         mysqlnd_stats_values_names,
      48             :                 },
      49             :                 {
      50             :                         NULL /* plugin shutdown */
      51             :                 }
      52             :         }
      53             : };
      54             : 
      55             : 
      56             : /* {{{ mysqlnd_library_end */
      57       22623 : PHPAPI void mysqlnd_library_end(void)
      58             : {
      59       22623 :         if (mysqlnd_library_initted == TRUE) {
      60       22623 :                 mysqlnd_plugin_subsystem_end();
      61       22623 :                 mysqlnd_stats_end(mysqlnd_global_stats, 1);
      62       22623 :                 mysqlnd_global_stats = NULL;
      63       22623 :                 mysqlnd_library_initted = FALSE;
      64       22623 :                 mysqlnd_reverse_api_end();
      65             :         }
      66       22623 : }
      67             : /* }}} */
      68             : 
      69             : 
      70             : /* {{{ mysqlnd_library_init */
      71       22587 : PHPAPI void mysqlnd_library_init(void)
      72             : {
      73       22587 :         if (mysqlnd_library_initted == FALSE) {
      74       22587 :                 mysqlnd_library_initted = TRUE;
      75       22587 :                 mysqlnd_conn_set_methods(&MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_conn));
      76       22587 :                 mysqlnd_conn_data_set_methods(&MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_conn_data));
      77       22587 :                 _mysqlnd_init_ps_subsystem();
      78             :                 /* Should be calloc, as mnd_calloc will reference LOCK_access*/
      79       22587 :                 mysqlnd_stats_init(&mysqlnd_global_stats, STAT_LAST, 1);
      80       22587 :                 mysqlnd_plugin_subsystem_init();
      81             :                 {
      82       22587 :                         mysqlnd_plugin_core.plugin_header.plugin_stats.values = mysqlnd_global_stats;
      83       22587 :                         mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_plugin_core);
      84             :                 }
      85             : #if defined(MYSQLND_DBG_ENABLED) && MYSQLND_DBG_ENABLED == 1
      86             :                 mysqlnd_example_plugin_register();
      87             : #endif
      88       22587 :                 mysqlnd_debug_trace_plugin_register();
      89       22587 :                 mysqlnd_register_builtin_authentication_plugins();
      90             : 
      91       22587 :                 mysqlnd_reverse_api_init();
      92             :         }
      93       22587 : }
      94             : /* }}} */
      95             : 
      96             : 
      97             : /* {{{ mysqlnd_object_factory::get_connection */
      98             : static MYSQLND *
      99        1732 : MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) *factory, const zend_bool persistent)
     100             : {
     101        1732 :         size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
     102        1732 :         size_t alloc_size_ret_data = sizeof(MYSQLND_CONN_DATA) + mysqlnd_plugin_count() * sizeof(void *);
     103             :         MYSQLND * new_object;
     104             :         MYSQLND_CONN_DATA * data;
     105             : 
     106        1732 :         DBG_ENTER("mysqlnd_driver::get_connection");
     107        1732 :         DBG_INF_FMT("persistent=%u", persistent);
     108        1732 :         new_object = mnd_pecalloc(1, alloc_size_ret, persistent);
     109        1732 :         if (!new_object) {
     110           0 :                 DBG_RETURN(NULL);
     111             :         }
     112        1732 :         new_object->data = mnd_pecalloc(1, alloc_size_ret_data, persistent);
     113        1732 :         if (!new_object->data) {
     114           0 :                 mnd_pefree(new_object, persistent);
     115           0 :                 DBG_RETURN(NULL);
     116             :         }
     117        1732 :         new_object->persistent = persistent;
     118        1732 :         new_object->m = mysqlnd_conn_get_methods();
     119        1732 :         data = new_object->data;
     120             : 
     121        1732 :         if (FAIL == mysqlnd_error_info_init(&data->error_info_impl, persistent)) {
     122           0 :                 new_object->m->dtor(new_object);
     123           0 :                 DBG_RETURN(NULL);
     124             :         }
     125        1732 :         data->error_info = &data->error_info_impl;
     126             : 
     127        1732 :         data->options = &(data->options_impl);
     128             : 
     129        1732 :         mysqlnd_upsert_status_init(&data->upsert_status_impl);
     130        1732 :         data->upsert_status = &(data->upsert_status_impl);
     131        1732 :         UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(data->upsert_status);
     132             : 
     133        1732 :         data->persistent = persistent;
     134        1732 :         data->m = mysqlnd_conn_data_get_methods();
     135        1732 :         data->object_factory = *factory;
     136             : 
     137        1732 :         mysqlnd_connection_state_init(&data->state);
     138             : 
     139        1732 :         data->m->get_reference(data);
     140             : 
     141        1732 :         mysqlnd_stats_init(&data->stats, STAT_LAST, persistent);
     142             : 
     143        1732 :         data->protocol_frame_codec = mysqlnd_pfc_init(persistent, factory, data->stats, data->error_info);
     144        1732 :         data->vio = mysqlnd_vio_init(persistent, factory, data->stats, data->error_info);
     145        1732 :         data->payload_decoder_factory = mysqlnd_protocol_payload_decoder_factory_init(data, persistent);
     146        1732 :         data->command_factory = mysqlnd_command_factory_get();
     147             : 
     148        1732 :         if (!data->protocol_frame_codec || !data->vio || !data->payload_decoder_factory || !data->command_factory) {
     149           0 :                 new_object->m->dtor(new_object);
     150           0 :                 DBG_RETURN(NULL);
     151             :         }
     152             : 
     153        1732 :         DBG_RETURN(new_object);
     154             : }
     155             : /* }}} */
     156             : 
     157             : 
     158             : /* {{{ mysqlnd_object_factory::clone_connection_object */
     159             : static MYSQLND *
     160           0 : MYSQLND_METHOD(mysqlnd_object_factory, clone_connection_object)(MYSQLND * to_be_cloned)
     161             : {
     162           0 :         size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
     163             :         MYSQLND * new_object;
     164             : 
     165           0 :         DBG_ENTER("mysqlnd_driver::clone_connection_object");
     166           0 :         DBG_INF_FMT("persistent=%u", to_be_cloned->persistent);
     167           0 :         if (!to_be_cloned || !to_be_cloned->data) {
     168           0 :                 DBG_RETURN(NULL);
     169             :         }
     170           0 :         new_object = mnd_pecalloc(1, alloc_size_ret, to_be_cloned->persistent);
     171           0 :         if (!new_object) {
     172           0 :                 DBG_RETURN(NULL);
     173             :         }
     174           0 :         new_object->persistent = to_be_cloned->persistent;
     175           0 :         new_object->m = to_be_cloned->m;
     176             : 
     177           0 :         new_object->data = to_be_cloned->data->m->get_reference(to_be_cloned->data);
     178           0 :         if (!new_object->data) {
     179           0 :                 new_object->m->dtor(new_object);
     180           0 :                 new_object = NULL;
     181             :         }
     182           0 :         DBG_RETURN(new_object);
     183             : }
     184             : /* }}} */
     185             : 
     186             : 
     187             : /* {{{ mysqlnd_object_factory::get_prepared_statement */
     188             : static MYSQLND_STMT *
     189        4253 : MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA * const conn, const zend_bool persistent)
     190             : {
     191        4253 :         size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
     192        4253 :         MYSQLND_STMT * ret = mnd_pecalloc(1, alloc_size, conn->persistent);
     193        4253 :         MYSQLND_STMT_DATA * stmt = NULL;
     194             : 
     195        4253 :         DBG_ENTER("mysqlnd_object_factory::get_prepared_statement");
     196             :         do {
     197        4253 :                 if (!ret) {
     198           0 :                         break;
     199             :                 }
     200        4253 :                 ret->m = mysqlnd_stmt_get_methods();
     201        4253 :                 ret->persistent = conn->persistent;
     202             : 
     203        4253 :                 stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), persistent);
     204        4253 :                 DBG_INF_FMT("stmt=%p", stmt);
     205        4253 :                 if (!stmt) {
     206           0 :                         break;
     207             :                 }
     208        4253 :                 stmt->persistent = persistent;
     209             : 
     210        4253 :                 if (FAIL == mysqlnd_error_info_init(&stmt->error_info_impl, persistent)) {
     211           0 :                         break;          
     212             :                 }
     213        4253 :                 stmt->error_info = &stmt->error_info_impl;
     214             : 
     215        4253 :                 mysqlnd_upsert_status_init(&stmt->upsert_status_impl);
     216        4253 :                 stmt->upsert_status = &(stmt->upsert_status_impl);
     217        4253 :                 stmt->state = MYSQLND_STMT_INITTED;
     218        4253 :                 stmt->execute_cmd_buffer.length = 4096;
     219        4253 :                 stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
     220        4253 :                 if (!stmt->execute_cmd_buffer.buffer) {
     221           0 :                         break;
     222             :                 }
     223             : 
     224        4253 :                 stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
     225             : 
     226             :                 /*
     227             :                   Mark that we reference the connection, thus it won't be
     228             :                   be destructed till there is open statements. The last statement
     229             :                   or normal query result will close it then.
     230             :                 */
     231        4253 :                 stmt->conn = conn->m->get_reference(conn);
     232             : 
     233        4253 :                 DBG_RETURN(ret);
     234             :         } while (0);
     235             : 
     236           0 :         SET_OOM_ERROR(conn->error_info);
     237           0 :         if (ret) {
     238           0 :                 ret->m->dtor(ret, TRUE);
     239           0 :                 ret = NULL;
     240             :         }
     241           0 :         DBG_RETURN(NULL);
     242             : }
     243             : /* }}} */
     244             : 
     245             : 
     246             : /* {{{ mysqlnd_object_factory::get_pfc */
     247             : static MYSQLND_PFC *
     248        1732 : MYSQLND_METHOD(mysqlnd_object_factory, get_pfc)(const zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info)
     249             : {
     250        1732 :         size_t pfc_alloc_size = sizeof(MYSQLND_PFC) + mysqlnd_plugin_count() * sizeof(void *);
     251        1732 :         size_t pfc_data_alloc_size = sizeof(MYSQLND_PFC_DATA) + mysqlnd_plugin_count() * sizeof(void *);
     252        1732 :         MYSQLND_PFC * pfc = mnd_pecalloc(1, pfc_alloc_size, persistent);
     253        1732 :         MYSQLND_PFC_DATA * pfc_data = mnd_pecalloc(1, pfc_data_alloc_size, persistent);
     254             : 
     255        1732 :         DBG_ENTER("mysqlnd_object_factory::get_pfc");
     256        1732 :         DBG_INF_FMT("persistent=%u", persistent);
     257        3464 :         if (pfc && pfc_data) {
     258        1732 :                 pfc->data = pfc_data;
     259        1732 :                 pfc->persistent = pfc->data->persistent = persistent;
     260        1732 :                 pfc->data->m = *mysqlnd_pfc_get_methods();
     261             : 
     262        1732 :                 if (PASS != pfc->data->m.init(pfc, stats, error_info)) {
     263           0 :                         pfc->data->m.dtor(pfc, stats, error_info);
     264           0 :                         pfc = NULL;
     265             :                 }
     266             :         } else {
     267           0 :                 if (pfc_data) {
     268           0 :                         mnd_pefree(pfc_data, persistent);
     269           0 :                         pfc_data = NULL;
     270             :                 }
     271           0 :                 if (pfc) {
     272           0 :                         mnd_pefree(pfc, persistent);
     273           0 :                         pfc = NULL;
     274             :                 }
     275             :         }
     276        1732 :         DBG_RETURN(pfc);
     277             : }
     278             : /* }}} */
     279             : 
     280             : 
     281             : /* {{{ mysqlnd_object_factory::get_vio */
     282             : static MYSQLND_VIO *
     283        1732 : MYSQLND_METHOD(mysqlnd_object_factory, get_vio)(const zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info)
     284             : {
     285        1732 :         size_t vio_alloc_size = sizeof(MYSQLND_VIO) + mysqlnd_plugin_count() * sizeof(void *);
     286        1732 :         size_t vio_data_alloc_size = sizeof(MYSQLND_VIO_DATA) + mysqlnd_plugin_count() * sizeof(void *);
     287        1732 :         MYSQLND_VIO * vio = mnd_pecalloc(1, vio_alloc_size, persistent);
     288        1732 :         MYSQLND_VIO_DATA * vio_data = mnd_pecalloc(1, vio_data_alloc_size, persistent);
     289             : 
     290        1732 :         DBG_ENTER("mysqlnd_object_factory::get_vio");
     291        1732 :         DBG_INF_FMT("persistent=%u", persistent);
     292        3464 :         if (vio && vio_data) {
     293        1732 :                 vio->data = vio_data;
     294        1732 :                 vio->persistent = vio->data->persistent = persistent;
     295        1732 :                 vio->data->m = *mysqlnd_vio_get_methods();
     296             : 
     297        1732 :                 if (PASS != vio->data->m.init(vio, stats, error_info)) {
     298           0 :                         vio->data->m.dtor(vio, stats, error_info);
     299           0 :                         vio = NULL;
     300             :                 }
     301             :         } else {
     302           0 :                 if (vio_data) {
     303           0 :                         mnd_pefree(vio_data, persistent);
     304           0 :                         vio_data = NULL;
     305             :                 }
     306           0 :                 if (vio) {
     307           0 :                         mnd_pefree(vio, persistent);
     308           0 :                         vio = NULL;
     309             :                 }
     310             :         }
     311        1732 :         DBG_RETURN(vio);
     312             : }
     313             : /* }}} */
     314             : 
     315             : 
     316             : /* {{{ mysqlnd_object_factory::get_protocol_payload_decoder_factory */
     317             : static MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY *
     318        1732 : MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_payload_decoder_factory)(MYSQLND_CONN_DATA * conn, const zend_bool persistent)
     319             : {
     320        1732 :         size_t alloc_size = sizeof(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY) + mysqlnd_plugin_count() * sizeof(void *);
     321        1732 :         MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY *ret = mnd_pecalloc(1, alloc_size, persistent);
     322             : 
     323        1732 :         DBG_ENTER("mysqlnd_object_factory::get_protocol_payload_decoder_factory");
     324        1732 :         DBG_INF_FMT("persistent=%u", persistent);
     325        1732 :         if (ret) {
     326        1732 :                 ret->persistent = persistent;
     327        1732 :                 ret->conn = conn;
     328        1732 :                 ret->m = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory);
     329             :         }
     330             : 
     331        1732 :         DBG_RETURN(ret);
     332             : }
     333             : /* }}} */
     334             : 
     335             : 
     336             : PHPAPI MYSQLND_CLASS_METHODS_START(mysqlnd_object_factory)
     337             :         MYSQLND_METHOD(mysqlnd_object_factory, get_connection),
     338             :         MYSQLND_METHOD(mysqlnd_object_factory, clone_connection_object),
     339             :         MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement),
     340             :         MYSQLND_METHOD(mysqlnd_object_factory, get_pfc),
     341             :         MYSQLND_METHOD(mysqlnd_object_factory, get_vio),
     342             :         MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_payload_decoder_factory)
     343             : MYSQLND_CLASS_METHODS_END;
     344             : 
     345             : /*
     346             :  * Local variables:
     347             :  * tab-width: 4
     348             :  * c-basic-offset: 4
     349             :  * End:
     350             :  * vim600: noet sw=4 ts=4 fdm=marker
     351             :  * vim<600: noet sw=4 ts=4
     352             :  */

Generated by: LCOV version 1.10

Generated at Thu, 26 May 2016 12:48:00 +0000 (21 hours ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.