21
21
#include "php_ini.h"
22
22
#include "ext/standard/dl.h"
23
23
#include "zend_extensions.h"
24
- #include "zend_highlight.h"
25
24
#include "SAPI.h"
26
25
#include "php_main.h"
27
26
#include "php_scandir.h"
49
48
#endif
50
49
51
50
52
- typedef struct _php_extension_lists {
51
+ typedef struct php_extension_lists {
53
52
zend_llist engine ;
54
53
zend_llist functions ;
55
54
} php_extension_lists ;
56
55
57
56
/* True globals */
58
- static int is_special_section = 0 ;
57
+ static bool is_special_section = false ;
59
58
static HashTable * active_ini_hash ;
60
59
static HashTable configuration_hash ;
61
- static int has_per_dir_config = 0 ;
62
- static int has_per_host_config = 0 ;
60
+ static bool has_per_dir_config = false ;
61
+ static bool has_per_host_config = false ;
63
62
PHPAPI char * php_ini_opened_path = NULL ;
64
63
static php_extension_lists extension_lists ;
65
64
PHPAPI char * php_ini_scanned_path = NULL ;
@@ -175,7 +174,7 @@ PHPAPI void config_zval_dtor(zval *zvalue)
175
174
/* Reset / free active_ini_section global */
176
175
#define RESET_ACTIVE_INI_HASH () do { \
177
176
active_ini_hash = NULL; \
178
- is_special_section = 0; \
177
+ is_special_section = false; \
179
178
} while (0)
180
179
/* }}} */
181
180
@@ -211,7 +210,7 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
211
210
} else {
212
211
/* Store in active hash */
213
212
entry = zend_hash_update (active_hash , Z_STR_P (arg1 ), arg2 );
214
- Z_STR_P (entry ) = zend_string_dup (Z_STR_P (entry ), 1 );
213
+ Z_STR_P (entry ) = zend_string_dup (Z_STR_P (entry ), true );
215
214
}
216
215
}
217
216
break ;
@@ -230,7 +229,7 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
230
229
/* If option not found in hash or is not an array -> create array, otherwise add to existing array */
231
230
if ((find_arr = zend_hash_find (active_hash , Z_STR_P (arg1 ))) == NULL || Z_TYPE_P (find_arr ) != IS_ARRAY ) {
232
231
ZVAL_NEW_PERSISTENT_ARR (& option_arr );
233
- zend_hash_init (Z_ARRVAL (option_arr ), 8 , NULL , config_zval_dtor , 1 );
232
+ zend_hash_init (Z_ARRVAL (option_arr ), 8 , NULL , config_zval_dtor , true );
234
233
find_arr = zend_hash_update (active_hash , Z_STR_P (arg1 ), & option_arr );
235
234
}
236
235
@@ -240,7 +239,7 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
240
239
} else {
241
240
entry = zend_hash_next_index_insert (Z_ARRVAL_P (find_arr ), arg2 );
242
241
}
243
- Z_STR_P (entry ) = zend_string_dup (Z_STR_P (entry ), 1 );
242
+ Z_STR_P (entry ) = zend_string_dup (Z_STR_P (entry ), true );
244
243
}
245
244
break ;
246
245
@@ -252,27 +251,27 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
252
251
size_t key_len ;
253
252
254
253
/* PATH sections */
255
- if (! zend_binary_strncasecmp ( Z_STRVAL_P (arg1 ), Z_STRLEN_P ( arg1 ), "PATH" , sizeof ( "PATH" ) - 1 , sizeof ( "PATH" ) - 1 )) {
254
+ if (zend_string_starts_with_literal_ci ( Z_STR_P (arg1 ), "PATH" )) {
256
255
key = Z_STRVAL_P (arg1 );
257
256
key = key + sizeof ("PATH" ) - 1 ;
258
257
key_len = Z_STRLEN_P (arg1 ) - sizeof ("PATH" ) + 1 ;
259
- is_special_section = 1 ;
260
- has_per_dir_config = 1 ;
258
+ is_special_section = true ;
259
+ has_per_dir_config = true ;
261
260
262
261
/* make the path lowercase on Windows, for case insensitivity. Does nothing for other platforms */
263
262
TRANSLATE_SLASHES_LOWER (key );
264
263
265
264
/* HOST sections */
266
- } else if (! zend_binary_strncasecmp ( Z_STRVAL_P (arg1 ), Z_STRLEN_P ( arg1 ), "HOST" , sizeof ( "HOST" ) - 1 , sizeof ( "HOST" ) - 1 )) {
265
+ } else if (zend_string_starts_with_literal_ci ( Z_STR_P (arg1 ), "HOST" )) {
267
266
key = Z_STRVAL_P (arg1 );
268
267
key = key + sizeof ("HOST" ) - 1 ;
269
268
key_len = Z_STRLEN_P (arg1 ) - sizeof ("HOST" ) + 1 ;
270
- is_special_section = 1 ;
271
- has_per_host_config = 1 ;
269
+ is_special_section = true ;
270
+ has_per_host_config = true ;
272
271
zend_str_tolower (key , key_len ); /* host names are case-insensitive. */
273
272
274
273
} else {
275
- is_special_section = 0 ;
274
+ is_special_section = false ;
276
275
}
277
276
278
277
if (key && key_len > 0 ) {
@@ -297,7 +296,7 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
297
296
zval section_arr ;
298
297
299
298
ZVAL_NEW_PERSISTENT_ARR (& section_arr );
300
- zend_hash_init (Z_ARRVAL (section_arr ), 8 , NULL , (dtor_func_t ) config_zval_dtor , 1 );
299
+ zend_hash_init (Z_ARRVAL (section_arr ), 8 , NULL , (dtor_func_t ) config_zval_dtor , true );
301
300
entry = zend_hash_str_update (target_hash , key , key_len , & section_arr );
302
301
}
303
302
if (Z_TYPE_P (entry ) == IS_ARRAY ) {
@@ -407,30 +406,30 @@ static void append_ini_path(char *php_ini_search_path, size_t search_path_size,
407
406
}
408
407
409
408
/* {{{ php_init_config */
410
- int php_init_config (void )
409
+ void php_init_config (void )
411
410
{
412
411
char * php_ini_file_name = NULL ;
413
412
char * php_ini_search_path = NULL ;
414
- int php_ini_scanned_path_len ;
413
+ size_t php_ini_scanned_path_len ;
415
414
char * open_basedir ;
416
- int free_ini_search_path = 0 ;
415
+ bool free_ini_search_path = false ;
417
416
zend_string * opened_path = NULL ;
418
417
419
- zend_hash_init (& configuration_hash , 8 , NULL , config_zval_dtor , 1 );
418
+ zend_hash_init (& configuration_hash , 8 , NULL , config_zval_dtor , true );
420
419
421
420
if (sapi_module .ini_defaults ) {
422
421
sapi_module .ini_defaults (& configuration_hash );
423
422
}
424
423
425
- zend_llist_init (& extension_lists .engine , sizeof (char * ), (llist_dtor_func_t ) free_estring , 1 );
426
- zend_llist_init (& extension_lists .functions , sizeof (char * ), (llist_dtor_func_t ) free_estring , 1 );
424
+ zend_llist_init (& extension_lists .engine , sizeof (char * ), (llist_dtor_func_t ) free_estring , true );
425
+ zend_llist_init (& extension_lists .functions , sizeof (char * ), (llist_dtor_func_t ) free_estring , true );
427
426
428
427
open_basedir = PG (open_basedir );
429
428
430
429
if (sapi_module .php_ini_path_override ) {
431
430
php_ini_file_name = sapi_module .php_ini_path_override ;
432
431
php_ini_search_path = sapi_module .php_ini_path_override ;
433
- free_ini_search_path = 0 ;
432
+ free_ini_search_path = false ;
434
433
} else if (!sapi_module .php_ini_ignore ) {
435
434
size_t search_path_size ;
436
435
char * default_location ;
@@ -480,7 +479,7 @@ int php_init_config(void)
480
479
481
480
search_path_size = MAXPATHLEN * 4 + strlen (env_location ) + 3 + 1 ;
482
481
php_ini_search_path = (char * ) emalloc (search_path_size );
483
- free_ini_search_path = 1 ;
482
+ free_ini_search_path = true ;
484
483
php_ini_search_path [0 ] = 0 ;
485
484
486
485
/* Add environment ___location */
@@ -601,15 +600,15 @@ int php_init_config(void)
601
600
zend_stream_init_fp (& fh , fp , filename );
602
601
RESET_ACTIVE_INI_HASH ();
603
602
604
- zend_parse_ini_file (& fh , 1 , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , & configuration_hash );
603
+ zend_parse_ini_file (& fh , true , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , & configuration_hash );
605
604
606
605
{
607
606
zval tmp ;
608
607
609
- ZVAL_NEW_STR (& tmp , zend_string_init (filename , strlen (filename ), 1 ));
608
+ ZVAL_NEW_STR (& tmp , zend_string_init (filename , strlen (filename ), true ));
610
609
zend_hash_str_update (& configuration_hash , "cfg_file_path" , sizeof ("cfg_file_path" )- 1 , & tmp );
611
610
if (opened_path ) {
612
- zend_string_release_ex (opened_path , 0 );
611
+ zend_string_release_ex (opened_path , false );
613
612
}
614
613
php_ini_opened_path = zend_strndup (Z_STRVAL (tmp ), Z_STRLEN (tmp ));
615
614
}
@@ -626,22 +625,20 @@ int php_init_config(void)
626
625
/* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
627
626
php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR ;
628
627
}
629
- php_ini_scanned_path_len = ( int ) strlen (php_ini_scanned_path );
628
+ php_ini_scanned_path_len = strlen (php_ini_scanned_path );
630
629
631
630
/* Scan and parse any .ini files found in scan path if path not empty. */
632
631
if (!sapi_module .php_ini_ignore && php_ini_scanned_path_len ) {
633
632
struct dirent * * namelist ;
634
- int ndir , i ;
635
633
zend_stat_t sb = {0 };
636
634
char ini_file [MAXPATHLEN ];
637
635
char * p ;
638
636
zend_llist scanned_ini_list ;
639
- zend_llist_element * element ;
640
- int l , total_l = 0 ;
637
+ size_t total_l = 0 ;
641
638
char * bufpath , * debpath , * endpath ;
642
- int lenpath ;
639
+ size_t lenpath ;
643
640
644
- zend_llist_init (& scanned_ini_list , sizeof (char * ), (llist_dtor_func_t ) free_estring , 1 );
641
+ zend_llist_init (& scanned_ini_list , sizeof (char * ), (llist_dtor_func_t ) free_estring , true );
645
642
646
643
bufpath = estrdup (php_ini_scanned_path );
647
644
for (debpath = bufpath ; debpath ; debpath = endpath ) {
@@ -654,11 +651,11 @@ int php_init_config(void)
654
651
to allow "/foo/php.d:" or ":/foo/php.d" */
655
652
debpath = PHP_CONFIG_FILE_SCAN_DIR ;
656
653
}
657
- lenpath = ( int ) strlen (debpath );
654
+ lenpath = strlen (debpath );
658
655
659
- if ( lenpath > 0 && ( ndir = php_scandir ( debpath , & namelist , 0 , php_alphasort )) > 0 ) {
660
-
661
- for (i = 0 ; i < ndir ; i ++ ) {
656
+ int ndir ;
657
+ if ( lenpath > 0 && ( ndir = php_scandir ( debpath , & namelist , NULL , php_alphasort )) > 0 ) {
658
+ for (int i = 0 ; i < ndir ; i ++ ) {
662
659
663
660
/* check for any file with .ini extension */
664
661
if (!(p = strrchr (namelist [i ]-> d_name , '.' )) || (p && strcmp (p , ".ini" ))) {
@@ -679,9 +676,9 @@ int php_init_config(void)
679
676
FILE * file = VCWD_FOPEN (ini_file , "r" );
680
677
if (file ) {
681
678
zend_stream_init_fp (& fh , file , ini_file );
682
- if (zend_parse_ini_file (& fh , 1 , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , & configuration_hash ) == SUCCESS ) {
679
+ if (zend_parse_ini_file (& fh , true , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , & configuration_hash ) == SUCCESS ) {
683
680
/* Here, add it to the list of ini files read */
684
- l = ( int ) strlen (ini_file );
681
+ size_t l = strlen (ini_file );
685
682
total_l += l + 2 ;
686
683
p = estrndup (ini_file , l );
687
684
zend_llist_add_element (& scanned_ini_list , & p );
@@ -698,13 +695,13 @@ int php_init_config(void)
698
695
efree (bufpath );
699
696
700
697
if (total_l ) {
701
- int php_ini_scanned_files_len = (php_ini_scanned_files ) ? ( int ) strlen (php_ini_scanned_files ) + 1 : 0 ;
698
+ size_t php_ini_scanned_files_len = (php_ini_scanned_files ) ? strlen (php_ini_scanned_files ) + 1 : 0 ;
702
699
php_ini_scanned_files = (char * ) realloc (php_ini_scanned_files , php_ini_scanned_files_len + total_l + 1 );
703
700
if (!php_ini_scanned_files_len ) {
704
701
* php_ini_scanned_files = '\0' ;
705
702
}
706
703
total_l += php_ini_scanned_files_len ;
707
- for (element = scanned_ini_list .head ; element ; element = element -> next ) {
704
+ for (zend_llist_element * element = scanned_ini_list .head ; element ; element = element -> next ) {
708
705
if (php_ini_scanned_files_len ) {
709
706
strlcat (php_ini_scanned_files , ",\n" , total_l );
710
707
}
@@ -721,15 +718,13 @@ int php_init_config(void)
721
718
if (sapi_module .ini_entries ) {
722
719
/* Reset active ini section */
723
720
RESET_ACTIVE_INI_HASH ();
724
- zend_parse_ini_string (sapi_module .ini_entries , 1 , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , & configuration_hash );
721
+ zend_parse_ini_string (sapi_module .ini_entries , true , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , & configuration_hash );
725
722
}
726
-
727
- return SUCCESS ;
728
723
}
729
724
/* }}} */
730
725
731
726
/* {{{ php_shutdown_config */
732
- int php_shutdown_config (void )
727
+ void php_shutdown_config (void )
733
728
{
734
729
zend_hash_destroy (& configuration_hash );
735
730
if (php_ini_opened_path ) {
@@ -740,7 +735,6 @@ int php_shutdown_config(void)
740
735
free (php_ini_scanned_files );
741
736
php_ini_scanned_files = NULL ;
742
737
}
743
- return SUCCESS ;
744
738
}
745
739
/* }}} */
746
740
@@ -756,7 +750,7 @@ void php_ini_register_extensions(void)
756
750
/* }}} */
757
751
758
752
/* {{{ php_parse_user_ini_file */
759
- PHPAPI int php_parse_user_ini_file (const char * dirname , const char * ini_filename , HashTable * target_hash )
753
+ PHPAPI zend_result php_parse_user_ini_file (const char * dirname , const char * ini_filename , HashTable * target_hash )
760
754
{
761
755
zend_stat_t sb = {0 };
762
756
char ini_file [MAXPATHLEN ];
@@ -766,7 +760,7 @@ PHPAPI int php_parse_user_ini_file(const char *dirname, const char *ini_filename
766
760
if (VCWD_STAT (ini_file , & sb ) == 0 ) {
767
761
if (S_ISREG (sb .st_mode )) {
768
762
zend_file_handle fh ;
769
- int ret = FAILURE ;
763
+ zend_result ret = FAILURE ;
770
764
771
765
zend_stream_init_fp (& fh , VCWD_FOPEN (ini_file , "r" ), ini_file );
772
766
if (fh .handle .fp ) {
@@ -780,7 +774,7 @@ PHPAPI int php_parse_user_ini_file(const char *dirname, const char *ini_filename
780
774
bool orig_rc_debug = zend_rc_debug ;
781
775
zend_rc_debug = false;
782
776
#endif
783
- ret = zend_parse_ini_file (& fh , 1 , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , target_hash );
777
+ ret = zend_parse_ini_file (& fh , true , ZEND_INI_SCANNER_NORMAL , (zend_ini_parser_cb_t ) php_ini_parser_cb , target_hash );
784
778
#if ZEND_RC_DEBUG
785
779
zend_rc_debug = orig_rc_debug ;
786
780
#endif
@@ -797,22 +791,22 @@ PHPAPI int php_parse_user_ini_file(const char *dirname, const char *ini_filename
797
791
/* }}} */
798
792
799
793
/* {{{ php_ini_activate_config */
800
- PHPAPI void php_ini_activate_config (HashTable * source_hash , int modify_type , int stage )
794
+ PHPAPI void php_ini_activate_config (const HashTable * source_hash , int modify_type , int stage )
801
795
{
802
796
zend_string * str ;
803
797
zval * data ;
804
798
805
799
/* Walk through config hash and alter matching ini entries using the values found in the hash */
806
800
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL (source_hash , str , data ) {
807
- zend_string * data_str = zend_string_dup (Z_STR_P (data ), 0 );
808
- zend_alter_ini_entry_ex (str , data_str , modify_type , stage , 0 );
801
+ zend_string * data_str = zend_string_dup (Z_STR_P (data ), false );
802
+ zend_alter_ini_entry_ex (str , data_str , modify_type , stage , false );
809
803
zend_string_release (data_str );
810
804
} ZEND_HASH_FOREACH_END ();
811
805
}
812
806
/* }}} */
813
807
814
808
/* {{{ php_ini_has_per_dir_config */
815
- PHPAPI int php_ini_has_per_dir_config (void )
809
+ PHPAPI bool php_ini_has_per_dir_config (void )
816
810
{
817
811
return has_per_dir_config ;
818
812
}
@@ -861,7 +855,7 @@ PHPAPI void php_ini_activate_per_dir_config(char *path, size_t path_len)
861
855
/* }}} */
862
856
863
857
/* {{{ php_ini_has_per_host_config */
864
- PHPAPI int php_ini_has_per_host_config (void )
858
+ PHPAPI bool php_ini_has_per_host_config (void )
865
859
{
866
860
return has_per_host_config ;
867
861
}
@@ -896,7 +890,7 @@ PHPAPI zval *cfg_get_entry(const char *name, size_t name_length)
896
890
/* }}} */
897
891
898
892
/* {{{ cfg_get_long */
899
- PHPAPI int cfg_get_long (const char * varname , zend_long * result )
893
+ PHPAPI zend_result cfg_get_long (const char * varname , zend_long * result )
900
894
{
901
895
zval * tmp ;
902
896
@@ -910,7 +904,7 @@ PHPAPI int cfg_get_long(const char *varname, zend_long *result)
910
904
/* }}} */
911
905
912
906
/* {{{ cfg_get_double */
913
- PHPAPI int cfg_get_double (const char * varname , double * result )
907
+ PHPAPI zend_result cfg_get_double (const char * varname , double * result )
914
908
{
915
909
zval * tmp ;
916
910
@@ -924,7 +918,7 @@ PHPAPI int cfg_get_double(const char *varname, double *result)
924
918
/* }}} */
925
919
926
920
/* {{{ cfg_get_string */
927
- PHPAPI int cfg_get_string (const char * varname , char * * result )
921
+ PHPAPI zend_result cfg_get_string (const char * varname , char * * result )
928
922
{
929
923
zval * tmp ;
930
924
0 commit comments