PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - var/php_gcov/PHP_5_2/main - php_ini.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 276
Code covered: 60.1 % Executed lines: 166
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2009 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                 :    | Author: Zeev Suraski <zeev@zend.com>                                 |
      16                 :    +----------------------------------------------------------------------+
      17                 :  */
      18                 : 
      19                 : /* $Id: php_ini.c 272374 2008-12-31 11:17:49Z sebastian $ */
      20                 : 
      21                 : #include "php.h"
      22                 : #include "ext/standard/info.h"
      23                 : #include "zend_ini.h"
      24                 : #include "php_ini.h"
      25                 : #include "ext/standard/dl.h"
      26                 : #include "zend_extensions.h"
      27                 : #include "zend_highlight.h"
      28                 : #include "SAPI.h"
      29                 : #include "php_main.h"
      30                 : #include "php_scandir.h"
      31                 : #ifdef PHP_WIN32
      32                 : #include "win32/php_registry.h"
      33                 : #endif
      34                 : 
      35                 : #if HAVE_SCANDIR && HAVE_ALPHASORT && HAVE_DIRENT_H
      36                 : #include <dirent.h>
      37                 : #endif
      38                 : 
      39                 : #ifndef S_ISREG
      40                 : #define S_ISREG(mode)   (((mode) & S_IFMT) == S_IFREG)
      41                 : #endif
      42                 : 
      43                 : typedef struct _php_extension_lists {
      44                 :         zend_llist engine;
      45                 :         zend_llist functions;
      46                 : } php_extension_lists;
      47                 : 
      48                 : 
      49                 : /* True globals */
      50                 : static HashTable configuration_hash;
      51                 : PHPAPI char *php_ini_opened_path=NULL;
      52                 : static php_extension_lists extension_lists;
      53                 : PHPAPI char *php_ini_scanned_path=NULL;
      54                 : PHPAPI char *php_ini_scanned_files=NULL;
      55                 : 
      56                 : /* {{{ php_ini_displayer_cb
      57                 :  */
      58                 : static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
      59            1728 : {
      60            1728 :         if (ini_entry->displayer) {
      61             528 :                 ini_entry->displayer(ini_entry, type);
      62                 :         } else {
      63                 :                 char *display_string;
      64            1200 :                 uint display_string_length, esc_html=0;
      65                 :                 TSRMLS_FETCH();
      66                 : 
      67            1200 :                 if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
      68               0 :                         if (ini_entry->orig_value && ini_entry->orig_value[0]) {
      69               0 :                                 display_string = ini_entry->orig_value;
      70               0 :                                 display_string_length = ini_entry->orig_value_length;
      71               0 :                                 esc_html = !sapi_module.phpinfo_as_text;
      72                 :                         } else {
      73               0 :                                 if (!sapi_module.phpinfo_as_text) {
      74               0 :                                         display_string = "<i>no value</i>";
      75               0 :                                         display_string_length = sizeof("<i>no value</i>") - 1;
      76                 :                                 } else {
      77               0 :                                         display_string = "no value";
      78               0 :                                         display_string_length = sizeof("no value") - 1;
      79                 :                                 }
      80                 :                         }
      81            2004 :                 } else if (ini_entry->value && ini_entry->value[0]) {
      82             804 :                         display_string = ini_entry->value;
      83             804 :                         display_string_length = ini_entry->value_length;
      84             804 :                         esc_html = !sapi_module.phpinfo_as_text;
      85                 :                 } else {
      86             396 :                         if (!sapi_module.phpinfo_as_text) {
      87              86 :                                 display_string = "<i>no value</i>";
      88              86 :                                 display_string_length = sizeof("<i>no value</i>") - 1;
      89                 :                         } else {
      90             310 :                                 display_string = "no value";
      91             310 :                                 display_string_length = sizeof("no value") - 1;
      92                 :                         }
      93                 :                 }
      94                 : 
      95            1200 :                 if (esc_html) {
      96             164 :                         php_html_puts(display_string, display_string_length TSRMLS_CC);
      97                 :                 } else {
      98            1036 :                         PHPWRITE(display_string, display_string_length);
      99                 :                 }
     100                 :         }
     101            1728 : }
     102                 : /* }}} */
     103                 : 
     104                 : /* {{{ php_ini_displayer
     105                 :  */
     106                 : static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC)
     107           19767 : {
     108           19767 :         if (ini_entry->module_number != module_number) {
     109           18903 :                 return 0;
     110                 :         }
     111             864 :         if (!sapi_module.phpinfo_as_text) {
     112             189 :                 PUTS("<tr>");
     113             189 :                 PUTS("<td class=\"e\">");
     114             189 :                 PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
     115             189 :                 PUTS("</td><td class=\"v\">");
     116             189 :                 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
     117             189 :                 PUTS("</td><td class=\"v\">");
     118             189 :                 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
     119             189 :                 PUTS("</td></tr>\n");
     120                 :         } else {
     121             675 :                 PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
     122             675 :                 PUTS(" => ");
     123             675 :                 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
     124             675 :                 PUTS(" => ");
     125             675 :                 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
     126             675 :                 PUTS("\n");
     127                 :         }
     128             864 :         return 0;
     129                 : }
     130                 : /* }}} */
     131                 : 
     132                 : /* {{{ display_ini_entries
     133                 :  */
     134                 : PHPAPI void display_ini_entries(zend_module_entry *module)
     135             101 : {
     136                 :         int module_number;
     137                 :         TSRMLS_FETCH();
     138                 : 
     139             101 :         if (module) {
     140              98 :                 module_number = module->module_number;
     141                 :         } else {
     142               3 :                 module_number = 0;
     143                 :         }
     144             101 :         php_info_print_table_start();
     145             101 :         php_info_print_table_header(3, "Directive", "Local Value", "Master Value");
     146             101 :         zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (zend_intptr_t) module_number TSRMLS_CC);
     147             101 :         php_info_print_table_end();
     148             101 : }
     149                 : /* }}} */
     150                 : 
     151                 : /* php.ini support */
     152                 : 
     153                 : #ifdef ZTS
     154                 : # if (ZEND_DEBUG)
     155                 : # define ZEND_EXTENSION_TOKEN   "zend_extension_debug_ts"
     156                 : # else
     157                 : # define ZEND_EXTENSION_TOKEN   "zend_extension_ts"
     158                 : # endif
     159                 : #else
     160                 : # if (ZEND_DEBUG)
     161                 : # define ZEND_EXTENSION_TOKEN   "zend_extension_debug"
     162                 : # else
     163                 : # define ZEND_EXTENSION_TOKEN   "zend_extension"
     164                 : # endif
     165                 : #endif
     166                 : 
     167                 : /* {{{ php_config_ini_parser_cb
     168                 :  */
     169                 : static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg)
     170          513356 : {
     171          513356 :         switch (callback_type) {
     172                 :                 case ZEND_INI_PARSER_ENTRY: {
     173                 :                                 zval *entry;
     174                 : 
     175          513356 :                                 if (!arg2) {
     176               0 :                                         break;
     177                 :                                 }
     178          513356 :                                 if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */
     179                 :                                         zval copy;
     180                 : 
     181               0 :                                         copy = *arg2;
     182               0 :                                         zval_copy_ctor(&copy);
     183               0 :                                         copy.refcount = 0;
     184               0 :                                         zend_llist_add_element(&extension_lists.functions, &copy);
     185          513356 :                                 } else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
     186               0 :                                         char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
     187                 : 
     188               0 :                                         zend_llist_add_element(&extension_lists.engine, &extension_name);
     189                 :                                 } else {
     190          513356 :                                         zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry);
     191          513356 :                                         Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
     192                 :                                 }
     193                 :                         }
     194          513356 :                         break;
     195                 : 
     196                 :                 case ZEND_INI_PARSER_POP_ENTRY: {
     197                 :                                 zval *hash;
     198                 :                                 zval **find_hash;
     199                 :                                 zval *element;
     200                 : 
     201               0 :                                 if (!arg2) {
     202                 :                                         /* bare string - nothing to do */
     203               0 :                                         break;
     204                 :                                 }
     205                 : 
     206               0 :                                 if (zend_hash_find(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, (void **) &find_hash) == FAILURE) {
     207               0 :                                         ALLOC_ZVAL(hash);
     208               0 :                                         array_init(hash);
     209                 : 
     210               0 :                                         zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, &hash, sizeof(zval *), NULL);
     211                 :                                 } else {
     212               0 :                                         hash = *find_hash;
     213                 :                                 }
     214                 : 
     215               0 :                                 ALLOC_ZVAL(element);
     216               0 :                                 *element = *arg2;
     217               0 :                                 zval_copy_ctor(element);
     218               0 :                                 INIT_PZVAL(element);
     219               0 :                                 add_next_index_zval(hash, element);
     220                 :                         }
     221                 :                         break;
     222                 : 
     223                 :                 case ZEND_INI_PARSER_SECTION:
     224                 :                         break;
     225                 :         }
     226          513356 : }
     227                 : /* }}} */
     228                 : 
     229                 : /* {{{ php_load_function_extension_cb
     230                 :  */
     231                 : static void php_load_function_extension_cb(void *arg TSRMLS_DC)
     232               0 : {
     233               0 :         zval *extension = (zval *) arg;
     234                 :         zval zval;
     235                 : 
     236               0 :         php_dl(extension, MODULE_PERSISTENT, &zval, 0 TSRMLS_CC);
     237               0 : }
     238                 : /* }}} */
     239                 : 
     240                 : /* {{{ php_load_zend_extension_cb
     241                 :  */
     242                 : static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
     243               0 : {
     244               0 :         zend_load_extension(*((char **) arg));
     245               0 : }
     246                 : /* }}} */
     247                 : 
     248                 : /* {{{ pvalue_config_destructor
     249                 :  */
     250                 : static void pvalue_config_destructor(zval *pvalue)
     251          555052 : {
     252          555052 :         if (Z_TYPE_P(pvalue) == IS_STRING) {
     253          555052 :                 free(Z_STRVAL_P(pvalue));
     254                 :         }
     255          555052 : }
     256                 : /* }}} */
     257                 : 
     258                 : /* {{{ php_init_config
     259                 :  */
     260                 : int php_init_config(TSRMLS_D)
     261           13565 : {
     262           13565 :         char *php_ini_file_name = NULL;
     263           13565 :         char *php_ini_search_path = NULL;
     264                 :         int php_ini_scanned_path_len;
     265                 :         int safe_mode_state;
     266                 :         char *open_basedir;
     267           13565 :         int free_ini_search_path = 0;
     268                 :         zend_file_handle fh;
     269                 :         struct stat sb;
     270                 :         char ini_file[MAXPATHLEN];
     271                 :         char *p;
     272                 :         zend_llist scanned_ini_list;
     273           13565 :         int l, total_l=0;
     274                 :         zend_llist_element *element;
     275                 : 
     276           13565 :         if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1) == FAILURE) {
     277               0 :                 return FAILURE;
     278                 :         }
     279                 : 
     280           13565 :         if (sapi_module.ini_defaults) {
     281           13467 :                 sapi_module.ini_defaults(&configuration_hash);
     282                 :         }
     283                 : 
     284           13565 :         zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
     285           13565 :         zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1);
     286           13565 :         zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
     287                 : 
     288           13565 :         safe_mode_state = PG(safe_mode);
     289           13565 :         open_basedir = PG(open_basedir);
     290                 : 
     291           13565 :         if (sapi_module.php_ini_path_override) {
     292               0 :                 php_ini_file_name = sapi_module.php_ini_path_override;
     293               0 :                 php_ini_search_path = sapi_module.php_ini_path_override;
     294               0 :                 free_ini_search_path = 0;
     295           13565 :         } else if (!sapi_module.php_ini_ignore) {
     296                 :                 int search_path_size;
     297                 :                 char *default_location;
     298                 :                 char *env_location;
     299                 :                 char *binary_location;
     300                 :                 static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
     301                 : #ifdef PHP_WIN32
     302                 :                 char *reg_location;
     303                 : #endif
     304                 : 
     305           13467 :                 env_location = getenv("PHPRC");
     306           13467 :                 if (!env_location) {
     307           13467 :                         env_location = "";
     308                 :                 }
     309                 : 
     310                 :                 /*
     311                 :                  * Prepare search path
     312                 :                  */
     313                 : 
     314           13467 :                 search_path_size = MAXPATHLEN * 4 + strlen(env_location) + 3 + 1;
     315           13467 :                 php_ini_search_path = (char *) emalloc(search_path_size);
     316           13467 :                 free_ini_search_path = 1;
     317           13467 :                 php_ini_search_path[0] = 0;
     318                 : 
     319                 :                 /* Add environment location */
     320           13467 :                 if (env_location[0]) {
     321               0 :                         if (*php_ini_search_path) {
     322               0 :                                 strlcat(php_ini_search_path, paths_separator, search_path_size);
     323                 :                         }
     324               0 :                         strlcat(php_ini_search_path, env_location, search_path_size);
     325               0 :                         php_ini_file_name = env_location;
     326                 :                 }
     327                 : 
     328                 : #ifdef PHP_WIN32
     329                 :                 /* Add registry location */
     330                 :                 reg_location = GetIniPathFromRegistry();
     331                 :                 if (reg_location != NULL) {
     332                 :                         if (*php_ini_search_path) {
     333                 :                                 strlcat(php_ini_search_path, paths_separator, search_path_size);
     334                 :                         }
     335                 :                         strlcat(php_ini_search_path, reg_location, search_path_size);
     336                 :                         efree(reg_location);
     337                 :                 }
     338                 : #endif
     339                 : 
     340                 :                 /* Add cwd (not with CLI) */
     341           13467 :                 if (strcmp(sapi_module.name, "cli") != 0) {
     342              75 :                         if (*php_ini_search_path) {
     343               0 :                                 strlcat(php_ini_search_path, paths_separator, search_path_size);
     344                 :                         }
     345              75 :                         strlcat(php_ini_search_path, ".", search_path_size);
     346                 :                 }
     347                 : 
     348                 :                 /* Add binary directory */
     349                 : #ifdef PHP_WIN32
     350                 :                 binary_location = (char *) emalloc(MAXPATHLEN);
     351                 :                 if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
     352                 :                         efree(binary_location);
     353                 :                         binary_location = NULL;
     354                 :                 }
     355                 : #else
     356           13467 :                 if (sapi_module.executable_location) {
     357           13467 :                         binary_location = (char *)emalloc(MAXPATHLEN);
     358           13467 :                         if (!strchr(sapi_module.executable_location, '/')) {
     359                 :                                 char *envpath, *path;
     360               0 :                                 int found = 0;
     361                 : 
     362               0 :                                 if ((envpath = getenv("PATH")) != NULL) {
     363                 :                                         char *search_dir, search_path[MAXPATHLEN];
     364                 :                                         char *last;
     365                 : 
     366               0 :                                         path = estrdup(envpath);
     367               0 :                                         search_dir = php_strtok_r(path, ":", &last);
     368                 : 
     369               0 :                                         while (search_dir) {
     370               0 :                                                 snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
     371               0 :                                                 if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK)) {
     372               0 :                                                         found = 1;
     373               0 :                                                         break;
     374                 :                                                 }
     375               0 :                                                 search_dir = php_strtok_r(NULL, ":", &last);
     376                 :                                         }
     377               0 :                                         efree(path);
     378                 :                                 }
     379               0 :                                 if (!found) {
     380               0 :                                         efree(binary_location);
     381               0 :                                         binary_location = NULL;
     382                 :                                 }
     383           13467 :                         } else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
     384               0 :                                 efree(binary_location);
     385               0 :                                 binary_location = NULL;
     386                 :                         }
     387                 :                 } else {
     388               0 :                         binary_location = NULL;
     389                 :                 }
     390                 : #endif
     391           13467 :                 if (binary_location) {
     392           13467 :                         char *separator_location = strrchr(binary_location, DEFAULT_SLASH);
     393                 : 
     394           13467 :                         if (separator_location && separator_location != binary_location) {
     395           13467 :                                 *(separator_location) = 0;
     396                 :                         }
     397           13467 :                         if (*php_ini_search_path) {
     398              75 :                                 strlcat(php_ini_search_path, paths_separator, search_path_size);
     399                 :                         }
     400           13467 :                         strlcat(php_ini_search_path, binary_location, search_path_size);
     401           13467 :                         efree(binary_location);
     402                 :                 }
     403                 : 
     404                 :                 /* Add default location */
     405                 : #ifdef PHP_WIN32
     406                 :                 default_location = (char *) emalloc(MAXPATHLEN + 1);
     407                 : 
     408                 :                 if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
     409                 :                         if (*php_ini_search_path) {
     410                 :                                 strlcat(php_ini_search_path, paths_separator, search_path_size);
     411                 :                         }
     412                 :                         strlcat(php_ini_search_path, default_location, search_path_size);
     413                 :                 }
     414                 :                 efree(default_location);
     415                 : 
     416                 :                 {
     417                 :                         /* For people running under terminal services, GetWindowsDirectory will
     418                 :                          * return their personal Windows directory, so lets add the system
     419                 :                          * windows directory too */
     420                 :                         typedef UINT (WINAPI *get_system_windows_directory_func)(char *buffer, UINT size);
     421                 :                         static get_system_windows_directory_func get_system_windows_directory = NULL;
     422                 :                         HMODULE kern;
     423                 : 
     424                 :                         if (get_system_windows_directory == NULL) {
     425                 :                                 kern = LoadLibrary("kernel32.dll");
     426                 :                                 if (kern) {
     427                 :                                         get_system_windows_directory = (get_system_windows_directory_func)GetProcAddress(kern, "GetSystemWindowsDirectoryA");
     428                 :                                 }
     429                 :                         }
     430                 :                         if (get_system_windows_directory != NULL) {
     431                 :                                 default_location = (char *) emalloc(MAXPATHLEN + 1);
     432                 :                                 if (0 < get_system_windows_directory(default_location, MAXPATHLEN)) {
     433                 :                                         if (*php_ini_search_path) {
     434                 :                                                 strlcat(php_ini_search_path, paths_separator, search_path_size);
     435                 :                                         }
     436                 :                                         strlcat(php_ini_search_path, default_location, search_path_size);
     437                 :                                 }
     438                 :                                 efree(default_location);
     439                 :                         }
     440                 :                 }
     441                 : #else
     442           13467 :                 default_location = PHP_CONFIG_FILE_PATH;
     443           13467 :                 if (*php_ini_search_path) {
     444           13467 :                         strlcat(php_ini_search_path, paths_separator, search_path_size);
     445                 :                 }
     446           13467 :                 strlcat(php_ini_search_path, default_location, search_path_size);
     447                 : #endif
     448                 :         }
     449                 : 
     450           13565 :         PG(safe_mode) = 0;
     451           13565 :         PG(open_basedir) = NULL;
     452                 : 
     453                 :         /*
     454                 :          * Find and open actual ini file
     455                 :          */
     456                 : 
     457           13565 :         memset(&fh, 0, sizeof(fh));
     458                 : 
     459                 :         /* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
     460                 :          * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still
     461                 :          * load an optional ini file. */
     462           13565 :         if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {
     463                 : 
     464                 :                 /* Check if php_ini_file_name is a file and can be opened */
     465           13467 :                 if (php_ini_file_name && php_ini_file_name[0]) {
     466                 :                         struct stat statbuf;
     467                 : 
     468               0 :                         if (!VCWD_STAT(php_ini_file_name, &statbuf)) {
     469               0 :                                 if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
     470               0 :                                         fh.handle.fp = VCWD_FOPEN(php_ini_file_name, "r");
     471               0 :                                         if (fh.handle.fp) {
     472               0 :                                                 fh.filename = php_ini_opened_path = expand_filepath(php_ini_file_name, NULL TSRMLS_CC);
     473                 :                                         }
     474                 :                                 }
     475                 :                         }
     476                 :                 }
     477                 : 
     478                 :                 /* Otherwise search for php-%sapi-module-name%.ini file in search path */
     479           13467 :                 if (!fh.handle.fp) {
     480           13467 :                         const char *fmt = "php-%s.ini";
     481                 :                         char *ini_fname;
     482           13467 :                         spprintf(&ini_fname, 0, fmt, sapi_module.name);
     483           13467 :                         fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
     484           13467 :                         efree(ini_fname);
     485           13467 :                         if (fh.handle.fp) {
     486               0 :                                 fh.filename = php_ini_opened_path;
     487                 :                         }
     488                 :                 }
     489                 : 
     490                 :                 /* If still no ini file found, search for php.ini file in search path */
     491           13467 :                 if (!fh.handle.fp) {
     492           13467 :                         fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
     493           13467 :                         if (fh.handle.fp) {
     494           13467 :                                 fh.filename = php_ini_opened_path;
     495                 :                         }
     496                 :                 }
     497                 :         }
     498                 : 
     499           13565 :         if (free_ini_search_path) {
     500           13467 :                 efree(php_ini_search_path);
     501                 :         }
     502                 : 
     503           13565 :         PG(safe_mode) = safe_mode_state;
     504           13565 :         PG(open_basedir) = open_basedir;
     505                 : 
     506           13565 :         if (fh.handle.fp) {
     507           13467 :                 fh.type = ZEND_HANDLE_FP;
     508                 : 
     509           13467 :                 zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
     510                 : 
     511                 :                 {
     512                 :                         zval tmp;
     513                 : 
     514           13467 :                         Z_STRLEN(tmp) = strlen(fh.filename);
     515           13467 :                         Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
     516           13467 :                         Z_TYPE(tmp) = IS_STRING;
     517           13467 :                         zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
     518           13467 :                         if (php_ini_opened_path) {
     519           13467 :                                 efree(php_ini_opened_path);
     520                 :                         }
     521           13467 :                         php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
     522                 :                 }
     523                 :         }
     524                 : 
     525                 :         /* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
     526           13565 :         php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
     527           13565 :         if (!php_ini_scanned_path) {
     528                 :                 /* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
     529           13565 :                 php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
     530                 :         }
     531           13565 :         php_ini_scanned_path_len = strlen(php_ini_scanned_path);
     532                 : 
     533                 :         /* Scan and parse any .ini files found in scan path if path not empty. */
     534           13565 :         if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
     535                 :                 struct dirent **namelist;
     536                 :                 int ndir, i;
     537                 : 
     538               0 :                 if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
     539               0 :                         for (i = 0; i < ndir; i++) {
     540                 :                                 /* check for a .ini extension */
     541               0 :                                 if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
     542               0 :                                         free(namelist[i]);
     543               0 :                                         continue;
     544                 :                                 }
     545               0 :                                 if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
     546               0 :                                         snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
     547                 :                                 } else {
     548               0 :                                         snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
     549                 :                                 }
     550               0 :                                 if (VCWD_STAT(ini_file, &sb) == 0) {
     551               0 :                                         if (S_ISREG(sb.st_mode)) {
     552               0 :                                                 if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
     553               0 :                                                         fh.filename = ini_file;
     554               0 :                                                         fh.type = ZEND_HANDLE_FP;
     555               0 :                                                         zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
     556                 :                                                         /* Here, add it to the list of ini files read */
     557               0 :                                                         l = strlen(ini_file);
     558               0 :                                                         total_l += l + 2;
     559               0 :                                                         p = estrndup(ini_file, l);
     560               0 :                                                         zend_llist_add_element(&scanned_ini_list, &p);
     561                 :                                                 }
     562                 :                                         }
     563                 :                                 }
     564               0 :                                 free(namelist[i]);
     565                 :                         }
     566               0 :                         free(namelist);
     567                 : 
     568                 :                         /*
     569                 :                          * Don't need an extra byte for the \0 in this malloc as the last
     570                 :                          * element will not get a trailing , which gives us the byte for the \0
     571                 :                          */
     572               0 :                         if (total_l) {
     573               0 :                                 php_ini_scanned_files = (char *) malloc(total_l);
     574               0 :                                 *php_ini_scanned_files = '\0';
     575               0 :                                 for (element = scanned_ini_list.head; element; element = element->next) {
     576               0 :                                         strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
     577               0 :                                         strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
     578                 :                                 }
     579                 :                         }
     580               0 :                         zend_llist_destroy(&scanned_ini_list);
     581                 :                 }
     582                 :         } else {
     583                 :                 /* Make sure an empty php_ini_scanned_path ends up as NULL */
     584           13565 :                 php_ini_scanned_path = NULL;
     585                 :         }
     586                 : 
     587           13565 :         if (sapi_module.ini_entries) {
     588           13546 :                 zend_parse_ini_string(sapi_module.ini_entries, 1, php_config_ini_parser_cb, &extension_lists);
     589                 :         }
     590                 : 
     591           13565 :         return SUCCESS;
     592                 : }
     593                 : /* }}} */
     594                 : 
     595                 : /* {{{ php_shutdown_config
     596                 :  */
     597                 : int php_shutdown_config(void)
     598           13597 : {
     599           13597 :         zend_hash_destroy(&configuration_hash);
     600           13597 :         if (php_ini_opened_path) {
     601           13502 :                 free(php_ini_opened_path);
     602           13502 :                 php_ini_opened_path = NULL;
     603                 :         }
     604           13597 :         if (php_ini_scanned_files) {
     605               0 :                 free(php_ini_scanned_files);
     606               0 :                 php_ini_scanned_files = NULL;
     607                 :         }
     608           13597 :         return SUCCESS;
     609                 : }
     610                 : /* }}} */
     611                 : 
     612                 : /* {{{ php_ini_register_extensions
     613                 :  */
     614                 : void php_ini_register_extensions(TSRMLS_D)
     615           13565 : {
     616           13565 :         zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC);
     617           13565 :         zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC);
     618                 : 
     619           13565 :         zend_llist_destroy(&extension_lists.engine);
     620           13565 :         zend_llist_destroy(&extension_lists.functions);
     621           13565 : }
     622                 : /* }}} */
     623                 : 
     624                 : /* {{{ cfg_get_entry
     625                 :  */
     626                 : PHPAPI zval *cfg_get_entry(char *name, uint name_length)
     627         2645567 : {
     628                 :         zval *tmp;
     629                 : 
     630         2645567 :         if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) {
     631          432720 :                 return tmp;
     632                 :         } else {
     633         2212847 :                 return NULL;
     634                 :         }
     635                 : }
     636                 : /* }}} */
     637                 : 
     638                 : /* {{{ cfg_get_long
     639                 :  */
     640                 : PHPAPI int cfg_get_long(char *varname, long *result)
     641           13565 : {
     642                 :         zval *tmp, var;
     643                 : 
     644           13565 :         if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
     645           13565 :                 *result = 0;
     646           13565 :                 return FAILURE;
     647                 :         }
     648               0 :         var = *tmp;
     649               0 :         zval_copy_ctor(&var);
     650               0 :         convert_to_long(&var);
     651               0 :         *result = Z_LVAL(var);
     652               0 :         return SUCCESS;
     653                 : }
     654                 : /* }}} */
     655                 : 
     656                 : /* {{{ cfg_get_double
     657                 :  */
     658                 : PHPAPI int cfg_get_double(char *varname, double *result)
     659               0 : {
     660                 :         zval *tmp, var;
     661                 : 
     662               0 :         if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
     663               0 :                 *result = (double) 0;
     664               0 :                 return FAILURE;
     665                 :         }
     666               0 :         var = *tmp;
     667               0 :         zval_copy_ctor(&var);
     668               0 :         convert_to_double(&var);
     669               0 :         *result = Z_DVAL(var);
     670               0 :         return SUCCESS;
     671                 : }
     672                 : /* }}} */
     673                 : 
     674                 : /* {{{ cfg_get_string
     675                 :  */
     676                 : PHPAPI int cfg_get_string(char *varname, char **result)
     677              35 : {
     678                 :         zval *tmp;
     679                 : 
     680              35 :         if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) {
     681              27 :                 *result = NULL;
     682              27 :                 return FAILURE;
     683                 :         }
     684               8 :         *result = Z_STRVAL_P(tmp);
     685               8 :         return SUCCESS;
     686                 : }
     687                 : /* }}} */
     688                 : 
     689                 : /*
     690                 :  * Local variables:
     691                 :  * tab-width: 4
     692                 :  * c-basic-offset: 4
     693                 :  * indent-tabs-mode: t
     694                 :  * End:
     695                 :  * vim600: sw=4 ts=4 fdm=marker
     696                 :  * vim<600: sw=4 ts=4
     697                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:28 +0000 (5 days ago)

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