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: 29 38 76.3 %
Date: 2014-07-21 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 5                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2014 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             : 
      21             : /* $Id: mysqlnd.c 306407 2010-12-16 12:56:19Z andrey $ */
      22             : #include "php.h"
      23             : #include "mysqlnd.h"
      24             : #include "mysqlnd_priv.h"
      25             : #include "mysqlnd_statistics.h"
      26             : #include "mysqlnd_debug.h"
      27             : 
      28             : /*--------------------------------------------------------------------*/
      29             : #if defined(MYSQLND_DBG_ENABLED) && MYSQLND_DBG_ENABLED == 1
      30             : static enum_func_status mysqlnd_example_plugin_end(void * p TSRMLS_DC);
      31             : 
      32             : static MYSQLND_STATS * mysqlnd_plugin_example_stats = NULL;
      33             : 
      34             : enum mysqlnd_plugin_example_collected_stats
      35             : {
      36             :         EXAMPLE_STAT1,
      37             :         EXAMPLE_STAT2,
      38             :         EXAMPLE_STAT_LAST
      39             : };
      40             : 
      41             : static const MYSQLND_STRING mysqlnd_plugin_example_stats_values_names[EXAMPLE_STAT_LAST] =
      42             : {
      43             :         { MYSQLND_STR_W_LEN("stat1") },
      44             :         { MYSQLND_STR_W_LEN("stat2") }
      45             : };
      46             : 
      47             : static struct st_mysqlnd_typeii_plugin_example mysqlnd_example_plugin =
      48             : {
      49             :         {
      50             :                 MYSQLND_PLUGIN_API_VERSION,
      51             :                 "example",
      52             :                 10001L,
      53             :                 "1.00.01",
      54             :                 "PHP License",
      55             :                 "Andrey Hristov <andrey@php.net>",
      56             :                 {
      57             :                         NULL, /* will be filled later */
      58             :                         mysqlnd_plugin_example_stats_values_names,
      59             :                 },
      60             :                 {
      61             :                         mysqlnd_example_plugin_end
      62             :                 }
      63             :         },
      64             :         NULL,   /* methods */
      65             : };
      66             : 
      67             : 
      68             : /* {{{ mysqlnd_example_plugin_end */
      69             : static 
      70             : enum_func_status mysqlnd_example_plugin_end(void * p TSRMLS_DC)
      71             : {
      72             :         struct st_mysqlnd_typeii_plugin_example * plugin = (struct st_mysqlnd_typeii_plugin_example *) p;
      73             :         DBG_ENTER("mysqlnd_example_plugin_end");
      74             :         mysqlnd_stats_end(plugin->plugin_header.plugin_stats.values);
      75             :         plugin->plugin_header.plugin_stats.values = NULL;
      76             :         DBG_RETURN(PASS);
      77             : }
      78             : /* }}} */
      79             : 
      80             : 
      81             : /* {{{ mysqlnd_example_plugin_register */
      82             : void
      83             : mysqlnd_example_plugin_register(TSRMLS_D)
      84             : {
      85             :         mysqlnd_stats_init(&mysqlnd_plugin_example_stats, EXAMPLE_STAT_LAST);
      86             :         mysqlnd_example_plugin.plugin_header.plugin_stats.values = mysqlnd_plugin_example_stats;
      87             :         mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_example_plugin TSRMLS_CC);
      88             : }
      89             : /* }}} */
      90             : #endif /* defined(MYSQLND_DBG_ENABLED) && MYSQLND_DBG_ENABLED == 1 */
      91             : /*--------------------------------------------------------------------*/
      92             : 
      93             : static HashTable mysqlnd_registered_plugins;
      94             :                 
      95             : static unsigned int mysqlnd_plugins_counter = 0;
      96             : 
      97             : 
      98             : /* {{{ mysqlnd_plugin_subsystem_init */
      99             : void
     100       21257 : mysqlnd_plugin_subsystem_init(TSRMLS_D)
     101             : {
     102       21257 :         zend_hash_init(&mysqlnd_registered_plugins, 4 /* initial hash size */, NULL /* hash_func */, NULL /* dtor */, TRUE /* pers */);
     103       21257 : }
     104             : /* }}} */
     105             : 
     106             : 
     107             : /* {{{ mysqlnd_plugin_end_apply_func */
     108             : int
     109      106450 : mysqlnd_plugin_end_apply_func(void *pDest TSRMLS_DC)
     110             : {
     111      106450 :         struct st_mysqlnd_plugin_header * plugin_header = *(struct st_mysqlnd_plugin_header **) pDest;
     112      106450 :         if (plugin_header->m.plugin_shutdown) {
     113           0 :                 plugin_header->m.plugin_shutdown(plugin_header TSRMLS_CC);
     114             :         }
     115      106450 :         return ZEND_HASH_APPLY_REMOVE;
     116             : }
     117             : /* }}} */
     118             : 
     119             : 
     120             : /* {{{ mysqlnd_plugin_subsystem_end */
     121             : void
     122       21290 : mysqlnd_plugin_subsystem_end(TSRMLS_D)
     123             : {
     124       21290 :         zend_hash_apply(&mysqlnd_registered_plugins, mysqlnd_plugin_end_apply_func TSRMLS_CC);
     125       21290 :         zend_hash_destroy(&mysqlnd_registered_plugins);
     126       21290 : }
     127             : /* }}} */
     128             : 
     129             : 
     130             : /* {{{ mysqlnd_plugin_register */
     131           0 : PHPAPI unsigned int mysqlnd_plugin_register()
     132             : {
     133             :         TSRMLS_FETCH();
     134           0 :         return mysqlnd_plugin_register_ex(NULL TSRMLS_CC);
     135             : }
     136             : /* }}} */
     137             : 
     138             : 
     139             : /* {{{ mysqlnd_plugin_register_ex */
     140      106285 : PHPAPI unsigned int mysqlnd_plugin_register_ex(struct st_mysqlnd_plugin_header * plugin TSRMLS_DC)
     141             : {
     142      106285 :         if (plugin) {
     143      106285 :                 if (plugin->plugin_api_version == MYSQLND_PLUGIN_API_VERSION) {
     144      106285 :                         zend_hash_update(&mysqlnd_registered_plugins, plugin->plugin_name, strlen(plugin->plugin_name) + 1, &plugin, sizeof(void *), NULL);
     145             :                 } else {
     146           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Plugin API version mismatch while loading plugin %s. Expected %d, got %d",
     147           0 :                                                         plugin->plugin_name, MYSQLND_PLUGIN_API_VERSION, plugin->plugin_api_version);
     148           0 :                         return 0xCAFE;
     149             :                 }
     150             :         }
     151      106285 :         return mysqlnd_plugins_counter++;
     152             : }
     153             : /* }}} */
     154             : 
     155             : 
     156             : /* {{{ mysqlnd_plugin_find */
     157        1926 : PHPAPI void * _mysqlnd_plugin_find(const char * const name TSRMLS_DC)
     158             : {
     159             :         void * plugin;
     160        1926 :         if (SUCCESS == zend_hash_find(&mysqlnd_registered_plugins, name, strlen(name) + 1, (void **) &plugin)) {
     161        1926 :                 return (void *)*(char **) plugin;
     162             :         }
     163           0 :         return NULL;
     164             : 
     165             : }
     166             : /* }}} */
     167             : 
     168             : 
     169             : /* {{{ _mysqlnd_plugin_apply_with_argument */
     170         300 : PHPAPI void _mysqlnd_plugin_apply_with_argument(apply_func_arg_t apply_func, void * argument TSRMLS_DC)
     171             : {
     172             :         /* Note: We want to be thread-safe (read-only), so we can use neither
     173             :          * zend_hash_apply_with_argument nor zend_hash_internal_pointer_reset and
     174             :          * friends
     175             :          */
     176             :         Bucket *p;
     177             : 
     178         300 :         p = mysqlnd_registered_plugins.pListHead;
     179        2100 :         while (p != NULL) {
     180        1500 :                 int result = apply_func(p->pData, argument TSRMLS_CC);
     181             : 
     182        1500 :                 if (result & ZEND_HASH_APPLY_REMOVE) {
     183           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "mysqlnd_plugin_apply_with_argument must not remove table entries");
     184             :                 }
     185        1500 :                 p = p->pListNext;
     186        1500 :                 if (result & ZEND_HASH_APPLY_STOP) {
     187           0 :                         break;
     188             :                 }
     189             :         }
     190         300 : }
     191             : /* }}} */
     192             : 
     193             : 
     194             : /* {{{ mysqlnd_plugin_count */
     195       34664 : PHPAPI unsigned int mysqlnd_plugin_count()
     196             : {
     197       34664 :         return mysqlnd_plugins_counter;
     198             : }
     199             : /* }}} */
     200             : 
     201             : 
     202             : /*
     203             :  * Local variables:
     204             :  * tab-width: 4
     205             :  * c-basic-offset: 4
     206             :  * End:
     207             :  * vim600: noet sw=4 ts=4 fdm=marker
     208             :  * vim<600: noet sw=4 ts=4
     209             :  */

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:13 +0000 (8 days ago)

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