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 - Zend - zend_extensions.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 43 81 53.1 %
Date: 2014-04-16 Functions: 9 12 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "zend_extensions.h"
      23             : 
      24             : ZEND_API zend_llist zend_extensions;
      25             : static int last_resource_number;
      26             : 
      27       21004 : int zend_load_extension(const char *path TSRMLS_DC)
      28             : {
      29             : #if ZEND_EXTENSIONS_SUPPORT
      30             :         DL_HANDLE handle;
      31             :         zend_extension *new_extension;
      32             :         zend_extension_version_info *extension_version_info;
      33             : 
      34       21004 :         handle = DL_LOAD(path);
      35       21004 :         if (!handle) {
      36             : #ifndef ZEND_WIN32
      37           0 :                 fprintf(stderr, "Failed loading %s:  %s\n", path, DL_ERROR());
      38             : /* See http://support.microsoft.com/kb/190351 */
      39             : #ifdef PHP_WIN32
      40             :                 fflush(stderr);
      41             : #endif
      42             : #else
      43             :                 fprintf(stderr, "Failed loading %s\n", path);
      44             : #endif
      45           0 :                 return FAILURE;
      46             :         }
      47             : 
      48       21004 :         extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "extension_version_info");
      49       21004 :         if (!extension_version_info) {
      50           0 :                 extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "_extension_version_info");
      51             :         }
      52       21004 :         new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "zend_extension_entry");
      53       21004 :         if (!new_extension) {
      54           0 :                 new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "_zend_extension_entry");
      55             :         }
      56       21004 :         if (!extension_version_info || !new_extension) {
      57           0 :                 fprintf(stderr, "%s doesn't appear to be a valid Zend extension\n", path);
      58             : /* See http://support.microsoft.com/kb/190351 */
      59             : #ifdef PHP_WIN32
      60             :                 fflush(stderr);
      61             : #endif
      62           0 :                 DL_UNLOAD(handle);
      63           0 :                 return FAILURE;
      64             :         }
      65             : 
      66             : 
      67             :         /* allow extension to proclaim compatibility with any Zend version */
      68       21004 :         if (extension_version_info->zend_extension_api_no != ZEND_EXTENSION_API_NO &&(!new_extension->api_no_check || new_extension->api_no_check(ZEND_EXTENSION_API_NO) != SUCCESS)) {
      69           0 :                 if (extension_version_info->zend_extension_api_no > ZEND_EXTENSION_API_NO) {
      70           0 :                         fprintf(stderr, "%s requires Zend Engine API version %d.\n"
      71             :                                         "The Zend Engine API version %d which is installed, is outdated.\n\n",
      72             :                                         new_extension->name,
      73             :                                         extension_version_info->zend_extension_api_no,
      74             :                                         ZEND_EXTENSION_API_NO);
      75             : /* See http://support.microsoft.com/kb/190351 */
      76             : #ifdef PHP_WIN32
      77             :                         fflush(stderr);
      78             : #endif
      79           0 :                         DL_UNLOAD(handle);
      80           0 :                         return FAILURE;
      81           0 :                 } else if (extension_version_info->zend_extension_api_no < ZEND_EXTENSION_API_NO) {
      82           0 :                         fprintf(stderr, "%s requires Zend Engine API version %d.\n"
      83             :                                         "The Zend Engine API version %d which is installed, is newer.\n"
      84             :                                         "Contact %s at %s for a later version of %s.\n\n",
      85             :                                         new_extension->name,
      86             :                                         extension_version_info->zend_extension_api_no,
      87             :                                         ZEND_EXTENSION_API_NO,
      88             :                                         new_extension->author,
      89             :                                         new_extension->URL,
      90             :                                         new_extension->name);
      91             : /* See http://support.microsoft.com/kb/190351 */
      92             : #ifdef PHP_WIN32
      93             :                         fflush(stderr);
      94             : #endif
      95           0 :                         DL_UNLOAD(handle);
      96           0 :                         return FAILURE;
      97             :                 }
      98       21004 :         } else if (strcmp(ZEND_EXTENSION_BUILD_ID, extension_version_info->build_id) &&
      99           0 :                    (!new_extension->build_id_check || new_extension->build_id_check(ZEND_EXTENSION_BUILD_ID) != SUCCESS)) {
     100           0 :                 fprintf(stderr, "Cannot load %s - it was built with configuration %s, whereas running engine is %s\n",
     101             :                                         new_extension->name, extension_version_info->build_id, ZEND_EXTENSION_BUILD_ID);
     102             : /* See http://support.microsoft.com/kb/190351 */
     103             : #ifdef PHP_WIN32
     104             :                 fflush(stderr);
     105             : #endif
     106           0 :                 DL_UNLOAD(handle);
     107           0 :                 return FAILURE;
     108             :         }
     109             : 
     110       21004 :         return zend_register_extension(new_extension, handle TSRMLS_CC);
     111             : #else
     112             :         fprintf(stderr, "Extensions are not supported on this platform.\n");
     113             : /* See http://support.microsoft.com/kb/190351 */
     114             : #ifdef PHP_WIN32
     115             :         fflush(stderr);
     116             : #endif
     117             :         return FAILURE;
     118             : #endif
     119             : }
     120             : 
     121             : 
     122       21004 : int zend_register_extension(zend_extension *new_extension, DL_HANDLE handle TSRMLS_DC)
     123             : {
     124             : #if ZEND_EXTENSIONS_SUPPORT
     125             :         zend_extension extension;
     126             : 
     127       21004 :         extension = *new_extension;
     128       21004 :         extension.handle = handle;
     129             : 
     130       21004 :         zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension TSRMLS_CC);
     131             : 
     132       21004 :         zend_llist_add_element(&zend_extensions, &extension);
     133             : 
     134             :         /*fprintf(stderr, "Loaded %s, version %s\n", extension.name, extension.version);*/
     135             : #endif
     136             : 
     137       21004 :         return SUCCESS;
     138             : }
     139             : 
     140             : 
     141       21040 : static void zend_extension_shutdown(zend_extension *extension TSRMLS_DC)
     142             : {
     143             : #if ZEND_EXTENSIONS_SUPPORT
     144       21040 :         if (extension->shutdown) {
     145           0 :                 extension->shutdown(extension);
     146             :         }
     147             : #endif
     148       21040 : }
     149             : 
     150       21004 : static int zend_extension_startup(zend_extension *extension)
     151             : {
     152             : #if ZEND_EXTENSIONS_SUPPORT
     153       21004 :         if (extension->startup) {
     154       21004 :                 if (extension->startup(extension)!=SUCCESS) {
     155           0 :                         return 1;
     156             :                 }
     157       21004 :                 zend_append_version_info(extension);
     158             :         }
     159             : #endif
     160       21004 :         return 0;
     161             : }
     162             : 
     163             : 
     164       21159 : int zend_startup_extensions_mechanism()
     165             : {
     166             :         /* Startup extensions mechanism */
     167       21159 :         zend_llist_init(&zend_extensions, sizeof(zend_extension), (void (*)(void *)) zend_extension_dtor, 1);
     168       21159 :         last_resource_number = 0;
     169       21159 :         return SUCCESS;
     170             : }
     171             : 
     172             : 
     173       21159 : int zend_startup_extensions()
     174             : {
     175       21159 :         zend_llist_apply_with_del(&zend_extensions, (int (*)(void *)) zend_extension_startup);
     176       21159 :         return SUCCESS;
     177             : }
     178             : 
     179             : 
     180       21192 : void zend_shutdown_extensions(TSRMLS_D)
     181             : {
     182       21192 :         zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_shutdown TSRMLS_CC);
     183       21192 :         zend_llist_destroy(&zend_extensions);
     184       21192 : }
     185             : 
     186             : 
     187       21040 : void zend_extension_dtor(zend_extension *extension)
     188             : {
     189             : #if ZEND_EXTENSIONS_SUPPORT && !ZEND_DEBUG
     190       21040 :         if (extension->handle) {
     191       21040 :                 DL_UNLOAD(extension->handle);
     192             :         }
     193             : #endif
     194       21040 : }
     195             : 
     196             : 
     197           0 : static void zend_extension_message_dispatcher(const zend_extension *extension, int num_args, va_list args TSRMLS_DC)
     198             : {
     199             :         int message;
     200             :         void *arg;
     201             : 
     202           0 :         if (!extension->message_handler || num_args!=2) {
     203           0 :                 return;
     204             :         }
     205           0 :         message = va_arg(args, int);
     206           0 :         arg = va_arg(args, void *);
     207           0 :         extension->message_handler(message, arg);
     208             : }
     209             : 
     210             : 
     211       21004 : ZEND_API void zend_extension_dispatch_message(int message, void *arg TSRMLS_DC)
     212             : {
     213       21004 :         zend_llist_apply_with_arguments(&zend_extensions, (llist_apply_with_args_func_t) zend_extension_message_dispatcher TSRMLS_CC, 2, message, arg);
     214       21004 : }
     215             : 
     216             : 
     217           0 : ZEND_API int zend_get_resource_handle(zend_extension *extension)
     218             : {
     219           0 :         if (last_resource_number<ZEND_MAX_RESERVED_RESOURCES) {
     220           0 :                 extension->resource_number = last_resource_number;
     221           0 :                 return last_resource_number++;
     222             :         } else {
     223           0 :                 return -1;
     224             :         }
     225             : }
     226             : 
     227             : 
     228           0 : ZEND_API zend_extension *zend_get_extension(const char *extension_name)
     229             : {
     230             :         zend_llist_element *element;
     231             : 
     232           0 :         for (element = zend_extensions.head; element; element = element->next) {
     233           0 :                 zend_extension *extension = (zend_extension *) element->data;
     234             : 
     235           0 :                 if (!strcmp(extension->name, extension_name)) {
     236           0 :                         return extension;
     237             :                 }
     238             :         }
     239           0 :         return NULL;
     240             : }
     241             : 
     242             : /*
     243             :  * Local variables:
     244             :  * tab-width: 4
     245             :  * c-basic-offset: 4
     246             :  * indent-tabs-mode: t
     247             :  * End:
     248             :  */

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:44 +0000 (8 days ago)

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