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_plugin.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 27 35 77.1 %
Date: 2016-09-18 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@php.net>                             |
      16             :   |          Ulf Wendel <uw@php.net>                                     |
      17             :   +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : #include "php.h"
      21             : #include "mysqlnd.h"
      22             : #include "mysqlnd_priv.h"
      23             : #include "mysqlnd_statistics.h"
      24             : #include "mysqlnd_debug.h"
      25             : 
      26             : /*--------------------------------------------------------------------*/
      27             : #if defined(MYSQLND_DBG_ENABLED) && MYSQLND_DBG_ENABLED == 1
      28             : static enum_func_status mysqlnd_example_plugin_end(void * p);
      29             : 
      30             : static MYSQLND_STATS * mysqlnd_plugin_example_stats = NULL;
      31             : 
      32             : enum mysqlnd_plugin_example_collected_stats
      33             : {
      34             :         EXAMPLE_STAT1,
      35             :         EXAMPLE_STAT2,
      36             :         EXAMPLE_STAT_LAST
      37             : };
      38             : 
      39             : static const MYSQLND_STRING mysqlnd_plugin_example_stats_values_names[EXAMPLE_STAT_LAST] =
      40             : {
      41             :         { MYSQLND_STR_W_LEN("stat1") },
      42             :         { MYSQLND_STR_W_LEN("stat2") }
      43             : };
      44             : 
      45             : static struct st_mysqlnd_typeii_plugin_example mysqlnd_example_plugin =
      46             : {
      47             :         {
      48             :                 MYSQLND_PLUGIN_API_VERSION,
      49             :                 "example",
      50             :                 10001L,
      51             :                 "1.00.01",
      52             :                 "PHP License",
      53             :                 "Andrey Hristov <andrey@php.net>",
      54             :                 {
      55             :                         NULL, /* will be filled later */
      56             :                         mysqlnd_plugin_example_stats_values_names,
      57             :                 },
      58             :                 {
      59             :                         mysqlnd_example_plugin_end
      60             :                 }
      61             :         },
      62             :         NULL,   /* methods */
      63             :         0
      64             : };
      65             : 
      66             : 
      67             : /* {{{ mysqlnd_example_plugin_end */
      68             : static
      69             : enum_func_status mysqlnd_example_plugin_end(void * p)
      70             : {
      71             :         struct st_mysqlnd_typeii_plugin_example * plugin = (struct st_mysqlnd_typeii_plugin_example *) p;
      72             :         DBG_ENTER("mysqlnd_example_plugin_end");
      73             :         mysqlnd_stats_end(plugin->plugin_header.plugin_stats.values, 1);
      74             :         plugin->plugin_header.plugin_stats.values = NULL;
      75             :         DBG_RETURN(PASS);
      76             : }
      77             : /* }}} */
      78             : 
      79             : 
      80             : /* {{{ mysqlnd_example_plugin_register */
      81             : void
      82             : mysqlnd_example_plugin_register(void)
      83             : {
      84             :         mysqlnd_stats_init(&mysqlnd_plugin_example_stats, EXAMPLE_STAT_LAST, 1);
      85             :         mysqlnd_example_plugin.plugin_header.plugin_stats.values = mysqlnd_plugin_example_stats;
      86             :         mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_example_plugin);
      87             : }
      88             : /* }}} */
      89             : #endif /* defined(MYSQLND_DBG_ENABLED) && MYSQLND_DBG_ENABLED == 1 */
      90             : /*--------------------------------------------------------------------*/
      91             : 
      92             : static HashTable mysqlnd_registered_plugins;
      93             : 
      94             : static unsigned int mysqlnd_plugins_counter = 0;
      95             : 
      96             : 
      97             : /* {{{ mysqlnd_plugin_subsystem_init */
      98             : void
      99       23922 : mysqlnd_plugin_subsystem_init(void)
     100             : {
     101       23922 :         zend_hash_init(&mysqlnd_registered_plugins, 4 /* initial hash size */, NULL /* hash_func */, NULL /* dtor */, TRUE /* pers */);
     102       23922 : }
     103             : /* }}} */
     104             : 
     105             : 
     106             : /* {{{ mysqlnd_plugin_end_apply_func */
     107             : int
     108      119815 : mysqlnd_plugin_end_apply_func(zval *el)
     109             : {
     110      119815 :         struct st_mysqlnd_plugin_header * plugin_header = (struct st_mysqlnd_plugin_header *)Z_PTR_P(el);
     111      119815 :         if (plugin_header->m.plugin_shutdown) {
     112           0 :                 plugin_header->m.plugin_shutdown(plugin_header);
     113             :         }
     114      119815 :         return ZEND_HASH_APPLY_REMOVE;
     115             : }
     116             : /* }}} */
     117             : 
     118             : 
     119             : /* {{{ mysqlnd_plugin_subsystem_end */
     120             : void
     121       23963 : mysqlnd_plugin_subsystem_end(void)
     122             : {
     123       23963 :         zend_hash_apply(&mysqlnd_registered_plugins, mysqlnd_plugin_end_apply_func);
     124       23963 :         zend_hash_destroy(&mysqlnd_registered_plugins);
     125       23963 : }
     126             : /* }}} */
     127             : 
     128             : 
     129             : /* {{{ mysqlnd_plugin_register */
     130           0 : PHPAPI unsigned int mysqlnd_plugin_register()
     131             : {
     132           0 :         return mysqlnd_plugin_register_ex(NULL);
     133             : }
     134             : /* }}} */
     135             : 
     136             : 
     137             : /* {{{ mysqlnd_plugin_register_ex */
     138      119610 : PHPAPI unsigned int mysqlnd_plugin_register_ex(struct st_mysqlnd_plugin_header * plugin)
     139             : {
     140      119610 :         if (plugin) {
     141      119610 :                 if (plugin->plugin_api_version == MYSQLND_PLUGIN_API_VERSION) {
     142      119610 :                         zend_hash_str_update_ptr(&mysqlnd_registered_plugins, plugin->plugin_name, strlen(plugin->plugin_name), plugin);
     143             :                 } else {
     144           0 :                         php_error_docref(NULL, E_WARNING, "Plugin API version mismatch while loading plugin %s. Expected %d, got %d",
     145             :                                                         plugin->plugin_name, MYSQLND_PLUGIN_API_VERSION, plugin->plugin_api_version);
     146           0 :                         return 0xCAFE;
     147             :                 }
     148             :         }
     149      119610 :         return mysqlnd_plugins_counter++;
     150             : }
     151             : /* }}} */
     152             : 
     153             : 
     154             : /* {{{ mysqlnd_plugin_find */
     155        1776 : PHPAPI void * mysqlnd_plugin_find(const char * const name)
     156             : {
     157             :         void * plugin;
     158        3552 :         if ((plugin = zend_hash_str_find_ptr(&mysqlnd_registered_plugins, name, strlen(name))) != NULL) {
     159        1776 :                 return plugin;
     160             :         }
     161           0 :         return NULL;
     162             : }
     163             : /* }}} */
     164             : 
     165             : 
     166             : /* {{{ mysqlnd_plugin_apply_with_argument */
     167         300 : PHPAPI void mysqlnd_plugin_apply_with_argument(apply_func_arg_t apply_func, void * argument)
     168             : {
     169             :         zval *val;
     170             :         int result;
     171             : 
     172        3300 :         ZEND_HASH_FOREACH_VAL(&mysqlnd_registered_plugins, val) {
     173        1500 :                 result = apply_func(val, argument);
     174        1500 :                 if (result & ZEND_HASH_APPLY_REMOVE) {
     175           0 :                         php_error_docref(NULL, E_WARNING, "mysqlnd_plugin_apply_with_argument must not remove table entries");
     176             :                 }
     177        1500 :                 if (result & ZEND_HASH_APPLY_STOP) {
     178           0 :                         break;
     179             :                 }
     180             :         } ZEND_HASH_FOREACH_END();
     181         300 : }
     182             : /* }}} */
     183             : 
     184             : 
     185             : /* {{{ mysqlnd_plugin_count */
     186       36693 : PHPAPI unsigned int mysqlnd_plugin_count()
     187             : {
     188       36693 :         return mysqlnd_plugins_counter;
     189             : }
     190             : /* }}} */
     191             : 
     192             : 
     193             : /*
     194             :  * Local variables:
     195             :  * tab-width: 4
     196             :  * c-basic-offset: 4
     197             :  * End:
     198             :  * vim600: noet sw=4 ts=4 fdm=marker
     199             :  * vim<600: noet sw=4 ts=4
     200             :  */

Generated by: LCOV version 1.10

Generated at Sun, 18 Sep 2016 08:20:09 +0000 (6 days ago)

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