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: 2015-09-02 Functions: 10 12 83.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Wed, 02 Sep 2015 17:19:06 +0000 (47 hours ago)

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