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: 47 85 55.3 %
Date: 2014-10-14 Functions: 10 12 83.3 %
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       20242 : 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       20242 :         handle = DL_LOAD(path);
      35       20242 :         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       20242 :         extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "extension_version_info");
      49       20242 :         if (!extension_version_info) {
      50           0 :                 extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "_extension_version_info");
      51             :         }
      52       20242 :         new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "zend_extension_entry");
      53       20242 :         if (!new_extension) {
      54           0 :                 new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "_zend_extension_entry");
      55             :         }
      56       20242 :         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       20242 :         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       20242 :         } 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       20242 :         } else if (zend_get_extension(new_extension->name)) {
     109           0 :                 fprintf(stderr, "Cannot load %s - it was already loaded\n", new_extension->name);
     110             : /* See http://support.microsoft.com/kb/190351 */
     111             : #ifdef PHP_WIN32
     112             :                 fflush(stderr);
     113             : #endif
     114           0 :                 DL_UNLOAD(handle);
     115           0 :                 return FAILURE;
     116             :         }
     117             : 
     118       20242 :         return zend_register_extension(new_extension, handle TSRMLS_CC);
     119             : #else
     120             :         fprintf(stderr, "Extensions are not supported on this platform.\n");
     121             : /* See http://support.microsoft.com/kb/190351 */
     122             : #ifdef PHP_WIN32
     123             :         fflush(stderr);
     124             : #endif
     125             :         return FAILURE;
     126             : #endif
     127             : }
     128             : 
     129             : 
     130       20242 : int zend_register_extension(zend_extension *new_extension, DL_HANDLE handle TSRMLS_DC)
     131             : {
     132             : #if ZEND_EXTENSIONS_SUPPORT
     133             :         zend_extension extension;
     134             : 
     135       20242 :         extension = *new_extension;
     136       20242 :         extension.handle = handle;
     137             : 
     138       20242 :         zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension TSRMLS_CC);
     139             : 
     140       20242 :         zend_llist_add_element(&zend_extensions, &extension);
     141             : 
     142             :         /*fprintf(stderr, "Loaded %s, version %s\n", extension.name, extension.version);*/
     143             : #endif
     144             : 
     145       20242 :         return SUCCESS;
     146             : }
     147             : 
     148             : 
     149       20279 : static void zend_extension_shutdown(zend_extension *extension TSRMLS_DC)
     150             : {
     151             : #if ZEND_EXTENSIONS_SUPPORT
     152       20279 :         if (extension->shutdown) {
     153           0 :                 extension->shutdown(extension);
     154             :         }
     155             : #endif
     156       20279 : }
     157             : 
     158       20242 : static int zend_extension_startup(zend_extension *extension)
     159             : {
     160             : #if ZEND_EXTENSIONS_SUPPORT
     161       20242 :         if (extension->startup) {
     162       20242 :                 if (extension->startup(extension)!=SUCCESS) {
     163           0 :                         return 1;
     164             :                 }
     165       20242 :                 zend_append_version_info(extension);
     166             :         }
     167             : #endif
     168       20242 :         return 0;
     169             : }
     170             : 
     171             : 
     172       20401 : int zend_startup_extensions_mechanism()
     173             : {
     174             :         /* Startup extensions mechanism */
     175       20401 :         zend_llist_init(&zend_extensions, sizeof(zend_extension), (void (*)(void *)) zend_extension_dtor, 1);
     176       20401 :         last_resource_number = 0;
     177       20401 :         return SUCCESS;
     178             : }
     179             : 
     180             : 
     181       20401 : int zend_startup_extensions()
     182             : {
     183       20401 :         zend_llist_apply_with_del(&zend_extensions, (int (*)(void *)) zend_extension_startup);
     184       20401 :         return SUCCESS;
     185             : }
     186             : 
     187             : 
     188       20435 : void zend_shutdown_extensions(TSRMLS_D)
     189             : {
     190       20435 :         zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_shutdown TSRMLS_CC);
     191       20435 :         zend_llist_destroy(&zend_extensions);
     192       20435 : }
     193             : 
     194             : 
     195       20279 : void zend_extension_dtor(zend_extension *extension)
     196             : {
     197             : #if ZEND_EXTENSIONS_SUPPORT && !ZEND_DEBUG
     198       20279 :         if (extension->handle && !getenv("ZEND_DONT_UNLOAD_MODULES")) {
     199           2 :                 DL_UNLOAD(extension->handle);
     200             :         }
     201             : #endif
     202       20279 : }
     203             : 
     204             : 
     205           0 : static void zend_extension_message_dispatcher(const zend_extension *extension, int num_args, va_list args TSRMLS_DC)
     206             : {
     207             :         int message;
     208             :         void *arg;
     209             : 
     210           0 :         if (!extension->message_handler || num_args!=2) {
     211           0 :                 return;
     212             :         }
     213           0 :         message = va_arg(args, int);
     214           0 :         arg = va_arg(args, void *);
     215           0 :         extension->message_handler(message, arg);
     216             : }
     217             : 
     218             : 
     219       20242 : ZEND_API void zend_extension_dispatch_message(int message, void *arg TSRMLS_DC)
     220             : {
     221       20242 :         zend_llist_apply_with_arguments(&zend_extensions, (llist_apply_with_args_func_t) zend_extension_message_dispatcher TSRMLS_CC, 2, message, arg);
     222       20242 : }
     223             : 
     224             : 
     225           0 : ZEND_API int zend_get_resource_handle(zend_extension *extension)
     226             : {
     227           0 :         if (last_resource_number<ZEND_MAX_RESERVED_RESOURCES) {
     228           0 :                 extension->resource_number = last_resource_number;
     229           0 :                 return last_resource_number++;
     230             :         } else {
     231           0 :                 return -1;
     232             :         }
     233             : }
     234             : 
     235             : 
     236       20242 : ZEND_API zend_extension *zend_get_extension(const char *extension_name)
     237             : {
     238             :         zend_llist_element *element;
     239             : 
     240       20242 :         for (element = zend_extensions.head; element; element = element->next) {
     241           0 :                 zend_extension *extension = (zend_extension *) element->data;
     242             : 
     243           0 :                 if (!strcmp(extension->name, extension_name)) {
     244           0 :                         return extension;
     245             :                 }
     246             :         }
     247       20242 :         return NULL;
     248             : }
     249             : 
     250             : /*
     251             :  * Local variables:
     252             :  * tab-width: 4
     253             :  * c-basic-offset: 4
     254             :  * indent-tabs-mode: t
     255             :  * End:
     256             :  */

Generated by: LCOV version 1.10

Generated at Tue, 14 Oct 2014 07:25:37 +0000 (6 days ago)

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