LTP GCOV extension - code coverage report
Current view: directory - main - php_ini.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 228
Code covered: 41.7 % Executed lines: 95
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5