2000-12-19 03:23:50 +08:00
/*
1999-04-17 08:37:12 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2001-12-11 23:32:16 +08:00
| PHP Version 4 |
1999-04-17 08:37:12 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2001-12-11 23:32:16 +08:00
| Copyright ( c ) 1997 - 2002 The PHP Group |
1999-04-17 08:37:12 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2000-05-18 23:34:45 +08:00
| This source file is subject to version 2.02 of the PHP license , |
1999-07-16 21:13:16 +08:00
| that is bundled with this package in the file LICENSE , and is |
| available at through the world - wide - web at |
2000-05-18 23:34:45 +08:00
| http : //www.php.net/license/2_02.txt. |
1999-07-16 21:13:16 +08:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
1999-04-17 08:37:12 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Andi Gutmans < andi @ zend . com > |
| Zeev Suraski < zeev @ zend . com > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
2000-07-24 09:40:02 +08:00
/* $Id$ */
1999-04-17 08:37:12 +08:00
# include "php.h"
2002-03-16 05:03:08 +08:00
# include "php_streams.h"
2000-06-06 07:24:42 +08:00
# include "php_main.h"
2000-10-13 17:13:01 +08:00
# include "php_globals.h"
1999-04-17 08:37:12 +08:00
# include "php_ini.h"
# include "internal_functions_registry.h"
1999-12-05 03:19:57 +08:00
# include "php_standard.h"
2001-09-06 03:47:55 +08:00
# include "php_math.h"
2001-08-06 21:36:08 +08:00
# include "php_incomplete_class.h"
2000-04-06 05:43:03 +08:00
# include "ext/standard/info.h"
2001-08-25 23:57:42 +08:00
# include "ext/session/php_session.h"
1999-04-17 08:37:12 +08:00
# include "zend_operators.h"
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
# include <stdarg.h>
# include <stdlib.h>
# include <math.h>
# include <time.h>
# include <stdio.h>
1999-11-01 09:07:51 +08:00
# include <netdb.h>
2001-08-30 00:00:30 +08:00
2001-01-22 01:29:15 +08:00
# if HAVE_ARPA_INET_H
2001-08-30 00:00:30 +08:00
# include <arpa / inet.h>
2001-01-22 01:29:15 +08:00
# endif
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
# if HAVE_UNISTD_H
2001-08-30 00:00:30 +08:00
# include <unistd.h>
1999-04-17 08:37:12 +08:00
# endif
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
# if HAVE_STRING_H
2001-08-30 00:00:30 +08:00
# include <string.h>
1999-04-17 08:37:12 +08:00
# else
2001-08-30 00:00:30 +08:00
# include <strings.h>
1999-04-17 08:37:12 +08:00
# endif
2001-08-30 00:00:30 +08:00
1999-10-08 10:10:57 +08:00
# if HAVE_LOCALE_H
2001-08-30 00:00:30 +08:00
# include <locale.h>
1999-10-08 10:10:57 +08:00
# endif
2001-08-30 00:00:30 +08:00
2001-05-19 07:38:46 +08:00
# if HAVE_SYS_MMAN_H
2001-08-30 00:00:30 +08:00
# include <sys / mman.h>
2001-05-19 07:38:46 +08:00
# endif
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
# include "safe_mode.h"
2001-08-30 00:00:30 +08:00
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
2001-08-30 00:00:30 +08:00
# include "win32 / unistd.h"
1999-04-17 08:37:12 +08:00
# endif
2001-08-30 00:00:30 +08:00
# include "zend_globals.h"
1999-04-17 08:37:12 +08:00
# include "php_globals.h"
1999-04-27 01:26:37 +08:00
# include "SAPI.h"
2000-09-02 00:10:17 +08:00
# include "php_ticks.h"
2001-08-30 00:00:30 +08:00
1999-11-28 08:31:02 +08:00
# ifdef ZTS
int basic_globals_id ;
# else
php_basic_globals basic_globals ;
1999-08-06 16:56:15 +08:00
# endif
2001-08-30 00:00:30 +08:00
2000-10-13 08:09:31 +08:00
# include "php_fopen_wrappers.h"
1999-04-17 08:37:12 +08:00
static unsigned char second_and_third_args_force_ref [ ] = { 3 , BYREF_NONE , BYREF_FORCE , BYREF_FORCE } ;
2000-07-24 00:49:42 +08:00
static unsigned char second_args_force_ref [ ] = { 2 , BYREF_NONE , BYREF_FORCE } ;
1999-04-17 08:37:12 +08:00
static unsigned char third_and_fourth_args_force_ref [ ] = { 4 , BYREF_NONE , BYREF_NONE , BYREF_FORCE , BYREF_FORCE } ;
2000-08-21 00:09:06 +08:00
static unsigned char third_and_rest_force_ref [ ] = { 3 , BYREF_NONE , BYREF_NONE , BYREF_FORCE_REST } ;
1999-04-17 08:37:12 +08:00
1999-08-06 23:25:11 +08:00
typedef struct _php_shutdown_function_entry {
zval * * arguments ;
int arg_count ;
} php_shutdown_function_entry ;
2000-09-02 00:10:17 +08:00
typedef struct _user_tick_function_entry {
zval * * arguments ;
int arg_count ;
2002-07-16 22:14:22 +08:00
int calling ;
2000-09-02 00:10:17 +08:00
} user_tick_function_entry ;
1999-04-17 08:37:12 +08:00
/* some prototypes for local functions */
2000-01-18 01:33:37 +08:00
static void user_shutdown_function_dtor ( php_shutdown_function_entry * shutdown_function_entry ) ;
2000-09-02 00:10:17 +08:00
static void user_tick_function_dtor ( user_tick_function_entry * tick_function_entry ) ;
2001-08-30 00:00:30 +08:00
2001-08-30 07:53:22 +08:00
/* Demo code. Enable only if you need this. */
# define ENABLE_TEST_CLASS 0
# if ENABLE_TEST_CLASS
2001-08-30 00:00:30 +08:00
void test_class_startup ( void ) ;
1999-12-05 22:16:37 +08:00
pval test_class_get_property ( zend_property_reference * property_reference ) ;
int test_class_set_property ( zend_property_reference * property_reference , pval * value ) ;
void test_class_call_function ( INTERNAL_FUNCTION_PARAMETERS , zend_property_reference * property_reference ) ;
1999-04-17 08:37:12 +08:00
2001-08-30 07:53:22 +08:00
pval test_class_get_property ( zend_property_reference * property_reference )
{
pval result ;
zend_overloaded_element * overloaded_property ;
zend_llist_element * element ;
printf ( " Reading a property from a OverloadedTestClass object: \n " ) ;
for ( element = property_reference - > elements_list - > head ; element ; element = element - > next ) {
overloaded_property = ( zend_overloaded_element * ) element - > data ;
switch ( Z_TYPE_P ( overloaded_property ) ) {
case OE_IS_ARRAY :
printf ( " Array offset: " ) ;
break ;
case OE_IS_OBJECT :
printf ( " Object property: " ) ;
break ;
}
switch ( Z_TYPE ( overloaded_property - > element ) ) {
case IS_LONG :
printf ( " %ld (numeric) \n " , Z_LVAL ( overloaded_property - > element ) ) ;
break ;
case IS_STRING :
printf ( " '%s' \n " , Z_STRVAL ( overloaded_property - > element ) ) ;
break ;
}
pval_destructor ( & overloaded_property - > element ) ;
}
Z_STRVAL ( result ) = estrndup ( " testing " , 7 ) ;
Z_STRLEN ( result ) = 7 ;
Z_TYPE ( result ) = IS_STRING ;
return result ;
}
int test_class_set_property ( zend_property_reference * property_reference , pval * value )
{
zend_overloaded_element * overloaded_property ;
zend_llist_element * element ;
printf ( " Writing to a property from a OverloadedTestClass object: \n " ) ;
printf ( " Writing ' " ) ;
zend_print_variable ( value ) ;
printf ( " ' \n " ) ;
for ( element = property_reference - > elements_list - > head ; element ; element = element - > next ) {
overloaded_property = ( zend_overloaded_element * ) element - > data ;
switch ( Z_TYPE_P ( overloaded_property ) ) {
case OE_IS_ARRAY :
printf ( " Array offset: " ) ;
break ;
case OE_IS_OBJECT :
printf ( " Object property: " ) ;
break ;
}
switch ( Z_TYPE ( overloaded_property - > element ) ) {
case IS_LONG :
printf ( " %ld (numeric) \n " , Z_LVAL ( overloaded_property - > element ) ) ;
break ;
case IS_STRING :
printf ( " '%s' \n " , Z_STRVAL ( overloaded_property - > element ) ) ;
break ;
}
pval_destructor ( & overloaded_property - > element ) ;
}
return 0 ;
}
void test_class_call_function ( INTERNAL_FUNCTION_PARAMETERS , zend_property_reference * property_reference )
{
zend_overloaded_element * overloaded_property ;
zend_llist_element * element ;
printf ( " Invoking a method on OverloadedTestClass object: \n " ) ;
for ( element = property_reference - > elements_list - > head ; element ; element = element - > next ) {
overloaded_property = ( zend_overloaded_element * ) element - > data ;
switch ( Z_TYPE_P ( overloaded_property ) ) {
case OE_IS_ARRAY :
printf ( " Array offset: " ) ;
break ;
case OE_IS_OBJECT :
printf ( " Object property: " ) ;
break ;
case OE_IS_METHOD :
printf ( " Overloaded method: " ) ;
}
switch ( Z_TYPE ( overloaded_property - > element ) ) {
case IS_LONG :
printf ( " %ld (numeric) \n " , Z_LVAL ( overloaded_property - > element ) ) ;
break ;
case IS_STRING :
printf ( " '%s' \n " , Z_STRVAL ( overloaded_property - > element ) ) ;
break ;
}
pval_destructor ( & overloaded_property - > element ) ;
}
printf ( " %d arguments \n " , ZEND_NUM_ARGS ( ) ) ;
RETVAL_STRING ( " testing " , 1 ) ;
}
void test_class_startup ( void )
{
zend_class_entry test_class_entry ;
TSRMLS_FETCH ( ) ;
INIT_OVERLOADED_CLASS_ENTRY ( test_class_entry ,
" OverloadedTestClass " ,
NULL , test_class_call_function ,
test_class_get_property ,
test_class_set_property ) ;
zend_register_internal_class ( & test_class_entry TSRMLS_CC ) ;
}
# endif
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
function_entry basic_functions [ ] = {
2001-08-30 00:00:30 +08:00
PHP_FE ( constant , NULL )
PHP_FE ( bin2hex , NULL )
PHP_FE ( sleep , NULL )
PHP_FE ( usleep , NULL )
PHP_FE ( time , NULL )
PHP_FE ( mktime , NULL )
PHP_FE ( gmmktime , NULL )
2000-05-28 03:27:20 +08:00
# if HAVE_STRFTIME
2001-08-30 00:00:30 +08:00
PHP_FE ( strftime , NULL )
PHP_FE ( gmstrftime , NULL )
2000-05-28 03:27:20 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( strtotime , NULL )
PHP_FE ( date , NULL )
PHP_FE ( gmdate , NULL )
PHP_FE ( getdate , NULL )
PHP_FE ( localtime , NULL )
PHP_FE ( checkdate , NULL )
PHP_FE ( flush , NULL )
PHP_FE ( wordwrap , NULL )
PHP_FE ( htmlspecialchars , NULL )
PHP_FE ( htmlentities , NULL )
2002-03-16 05:03:08 +08:00
PHP_FE ( html_entity_decode , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( get_html_translation_table , NULL )
2002-07-29 03:18:08 +08:00
PHP_FE ( sha1 , NULL )
PHP_FE ( sha1_file , NULL )
2001-08-30 00:00:30 +08:00
PHP_NAMED_FE ( md5 , php_if_md5 , NULL )
2001-11-19 02:48:17 +08:00
PHP_NAMED_FE ( md5_file , php_if_md5_file , NULL )
2001-08-30 00:00:30 +08:00
PHP_NAMED_FE ( crc32 , php_if_crc32 , NULL )
PHP_FE ( iptcparse , NULL )
PHP_FE ( iptcembed , NULL )
PHP_FE ( getimagesize , second_args_force_ref )
2002-06-23 08:43:11 +08:00
PHP_FE ( image_type_to_mime_type , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( phpinfo , NULL )
PHP_FE ( phpversion , NULL )
PHP_FE ( phpcredits , NULL )
PHP_FE ( php_logo_guid , NULL )
PHP_FE ( zend_logo_guid , NULL )
PHP_FE ( php_sapi_name , NULL )
PHP_FE ( php_uname , NULL )
PHP_FE ( strnatcmp , NULL )
PHP_FE ( strnatcasecmp , NULL )
PHP_FE ( substr_count , NULL )
PHP_FE ( strspn , NULL )
PHP_FE ( strcspn , NULL )
PHP_FE ( strtok , NULL )
PHP_FE ( strtoupper , NULL )
PHP_FE ( strtolower , NULL )
PHP_FE ( strpos , NULL )
PHP_FE ( strrpos , NULL )
PHP_FE ( strrev , NULL )
PHP_FE ( hebrev , NULL )
PHP_FE ( hebrevc , NULL )
PHP_FE ( nl2br , NULL )
PHP_FE ( basename , NULL )
PHP_FE ( dirname , NULL )
PHP_FE ( pathinfo , NULL )
PHP_FE ( stripslashes , NULL )
PHP_FE ( stripcslashes , NULL )
PHP_FE ( strstr , NULL )
PHP_FE ( stristr , NULL )
PHP_FE ( strrchr , NULL )
2001-01-17 09:10:50 +08:00
# ifdef HAVE_STRCOLL
2001-08-30 00:00:30 +08:00
PHP_FE ( strcoll , NULL )
2001-01-17 09:10:50 +08:00
# endif
2001-08-30 00:00:30 +08:00
2002-08-02 18:08:53 +08:00
# ifdef HAVE_STRFMON
PHP_FE ( money_format , NULL )
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( substr , NULL )
PHP_FE ( substr_replace , NULL )
PHP_FE ( quotemeta , NULL )
PHP_FE ( ucfirst , NULL )
PHP_FE ( ucwords , NULL )
PHP_FE ( strtr , NULL )
PHP_FE ( addslashes , NULL )
PHP_FE ( addcslashes , NULL )
2001-09-24 02:32:46 +08:00
PHP_FE ( rtrim , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( str_replace , NULL )
PHP_FE ( str_repeat , NULL )
PHP_FE ( count_chars , NULL )
PHP_FE ( chunk_split , NULL )
PHP_FE ( trim , NULL )
PHP_FE ( ltrim , NULL )
PHP_FE ( strip_tags , NULL )
PHP_FE ( similar_text , third_arg_force_ref )
PHP_FE ( explode , NULL )
PHP_FE ( implode , NULL )
PHP_FE ( setlocale , NULL )
PHP_FE ( localeconv , NULL )
2001-07-04 18:10:30 +08:00
# if HAVE_NL_LANGINFO
2001-08-30 00:00:30 +08:00
PHP_FE ( nl_langinfo , NULL )
2001-07-04 18:10:30 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( soundex , NULL )
PHP_FE ( levenshtein , NULL )
PHP_FE ( chr , NULL )
PHP_FE ( ord , NULL )
PHP_FE ( parse_str , second_arg_force_ref )
PHP_FE ( str_pad , NULL )
2001-09-24 02:32:46 +08:00
PHP_FALIAS ( chop , rtrim , NULL )
2001-08-30 00:00:30 +08:00
PHP_FALIAS ( strchr , strstr , NULL )
PHP_NAMED_FE ( sprintf , PHP_FN ( user_sprintf ) , NULL )
PHP_NAMED_FE ( printf , PHP_FN ( user_printf ) , NULL )
PHP_FE ( vprintf , NULL )
PHP_FE ( vsprintf , NULL )
PHP_FE ( sscanf , third_and_rest_force_ref )
PHP_FE ( fscanf , third_and_rest_force_ref )
PHP_FE ( parse_url , NULL )
PHP_FE ( urlencode , NULL )
PHP_FE ( urldecode , NULL )
PHP_FE ( rawurlencode , NULL )
PHP_FE ( rawurldecode , NULL )
1999-07-28 21:59:35 +08:00
2000-06-14 02:07:19 +08:00
# ifdef HAVE_SYMLINK
2001-08-30 00:00:30 +08:00
PHP_FE ( readlink , NULL )
PHP_FE ( linkinfo , NULL )
PHP_FE ( symlink , NULL )
PHP_FE ( link , NULL )
2000-06-14 02:07:19 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( unlink , NULL )
PHP_FE ( exec , second_and_third_args_force_ref )
PHP_FE ( system , second_arg_force_ref )
PHP_FE ( escapeshellcmd , NULL )
PHP_FE ( escapeshellarg , NULL )
PHP_FE ( passthru , second_arg_force_ref )
PHP_FE ( shell_exec , NULL )
2002-04-03 00:46:33 +08:00
PHP_FE ( proc_open , third_arg_force_ref )
2002-04-03 21:39:35 +08:00
PHP_FE ( proc_close , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( rand , NULL )
PHP_FE ( srand , NULL )
PHP_FE ( getrandmax , NULL )
PHP_FE ( mt_rand , NULL )
PHP_FE ( mt_srand , NULL )
PHP_FE ( mt_getrandmax , NULL )
2001-05-20 06:21:40 +08:00
# if HAVE_GETSERVBYNAME
2001-08-30 00:00:30 +08:00
PHP_FE ( getservbyname , NULL )
2001-05-20 06:21:40 +08:00
# endif
2001-08-30 00:00:30 +08:00
2001-01-22 01:29:15 +08:00
# if HAVE_GETSERVBYPORT
2001-08-30 00:00:30 +08:00
PHP_FE ( getservbyport , NULL )
2001-01-22 01:29:15 +08:00
# endif
2001-08-30 00:00:30 +08:00
2001-01-22 01:29:15 +08:00
# if HAVE_GETPROTOBYNAME
2001-08-30 00:00:30 +08:00
PHP_FE ( getprotobyname , NULL )
2001-01-22 01:29:15 +08:00
# endif
2001-08-30 00:00:30 +08:00
2001-01-22 01:29:15 +08:00
# if HAVE_GETPROTOBYNUMBER
2001-08-30 00:00:30 +08:00
PHP_FE ( getprotobynumber , NULL )
2001-01-22 01:29:15 +08:00
# endif
2001-05-20 06:21:40 +08:00
2001-08-30 00:00:30 +08:00
PHP_FE ( gethostbyaddr , NULL )
PHP_FE ( gethostbyname , NULL )
PHP_FE ( gethostbynamel , NULL )
# if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32))
PHP_FE ( checkdnsrr , NULL )
PHP_FE ( getmxrr , second_and_third_args_force_ref )
2000-05-28 03:27:20 +08:00
# endif
1999-04-17 08:37:12 +08:00
2001-08-30 00:00:30 +08:00
PHP_FE ( getmyuid , NULL )
PHP_FE ( getmygid , NULL )
PHP_FE ( getmypid , NULL )
PHP_FE ( getmyinode , NULL )
PHP_FE ( getlastmod , NULL )
PHP_FE ( base64_decode , NULL )
PHP_FE ( base64_encode , NULL )
PHP_FE ( abs , NULL )
PHP_FE ( ceil , NULL )
PHP_FE ( floor , NULL )
PHP_FE ( round , NULL )
PHP_FE ( sin , NULL )
PHP_FE ( cos , NULL )
PHP_FE ( tan , NULL )
PHP_FE ( asin , NULL )
PHP_FE ( acos , NULL )
PHP_FE ( atan , NULL )
PHP_FE ( atan2 , NULL )
PHP_FE ( sinh , NULL )
PHP_FE ( cosh , NULL )
PHP_FE ( tanh , NULL )
2001-08-02 00:55:24 +08:00
# ifndef PHP_WIN32
2001-08-30 00:00:30 +08:00
PHP_FE ( asinh , NULL )
PHP_FE ( acosh , NULL )
PHP_FE ( atanh , NULL )
PHP_FE ( expm1 , NULL )
PHP_FE ( log1p , NULL )
2001-08-02 00:55:24 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( pi , NULL )
2002-01-10 07:59:05 +08:00
PHP_FE ( is_finite , NULL )
PHP_FE ( is_nan , NULL )
PHP_FE ( is_infinite , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( pow , NULL )
PHP_FE ( exp , NULL )
PHP_FE ( log , NULL )
PHP_FE ( log10 , NULL )
PHP_FE ( sqrt , NULL )
PHP_FE ( hypot , NULL )
PHP_FE ( deg2rad , NULL )
PHP_FE ( rad2deg , NULL )
PHP_FE ( bindec , NULL )
PHP_FE ( hexdec , NULL )
PHP_FE ( octdec , NULL )
PHP_FE ( decbin , NULL )
PHP_FE ( decoct , NULL )
PHP_FE ( dechex , NULL )
PHP_FE ( base_convert , NULL )
PHP_FE ( number_format , NULL )
2002-02-21 19:44:41 +08:00
PHP_FE ( fmod , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( ip2long , NULL )
PHP_FE ( long2ip , NULL )
PHP_FE ( getenv , NULL )
2000-05-28 03:27:20 +08:00
# ifdef HAVE_PUTENV
2001-08-30 00:00:30 +08:00
PHP_FE ( putenv , NULL )
2000-05-28 03:27:20 +08:00
# endif
1999-07-25 06:16:54 +08:00
2001-08-30 00:00:30 +08:00
PHP_FE ( microtime , NULL )
PHP_FE ( gettimeofday , NULL )
2000-05-28 03:27:20 +08:00
# ifdef HAVE_GETRUSAGE
2001-08-30 00:00:30 +08:00
PHP_FE ( getrusage , NULL )
2000-05-28 03:27:20 +08:00
# endif
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
PHP_FE ( uniqid , NULL )
PHP_FE ( quoted_printable_decode , NULL )
PHP_FE ( convert_cyr_string , NULL )
PHP_FE ( get_current_user , NULL )
PHP_FE ( set_time_limit , NULL )
PHP_FE ( get_cfg_var , NULL )
PHP_FALIAS ( magic_quotes_runtime , set_magic_quotes_runtime , NULL )
PHP_FE ( set_magic_quotes_runtime , NULL )
PHP_FE ( get_magic_quotes_gpc , NULL )
PHP_FE ( get_magic_quotes_runtime , NULL )
PHP_FE ( import_request_variables , NULL )
PHP_FE ( error_log , NULL )
PHP_FE ( call_user_func , NULL )
PHP_FE ( call_user_func_array , NULL )
PHP_FE ( call_user_method , second_arg_force_ref )
PHP_FE ( call_user_method_array , second_arg_force_ref )
PHP_FE ( serialize , NULL )
PHP_FE ( unserialize , NULL )
PHP_FE ( var_dump , NULL )
2001-12-09 07:44:34 +08:00
PHP_FE ( var_export , NULL )
2002-02-11 01:38:15 +08:00
PHP_FE ( debug_zval_dump , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( print_r , NULL )
PHP_FE ( register_shutdown_function , NULL )
PHP_FE ( register_tick_function , NULL )
PHP_FE ( unregister_tick_function , NULL )
PHP_FE ( highlight_file , NULL )
PHP_FALIAS ( show_source , highlight_file , NULL )
PHP_FE ( highlight_string , NULL )
PHP_FE ( ini_get , NULL )
2001-08-31 01:47:04 +08:00
PHP_FE ( ini_get_all , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( ini_set , NULL )
PHP_FALIAS ( ini_alter , ini_set , NULL )
PHP_FE ( ini_restore , NULL )
PHP_FE ( setcookie , NULL )
PHP_FE ( header , NULL )
PHP_FE ( headers_sent , NULL )
PHP_FE ( connection_aborted , NULL )
PHP_FE ( connection_status , NULL )
PHP_FE ( ignore_user_abort , NULL )
PHP_FE ( parse_ini_file , NULL )
PHP_FE ( is_uploaded_file , NULL )
PHP_FE ( move_uploaded_file , NULL )
2000-09-09 05:56:47 +08:00
2002-01-10 07:47:46 +08:00
/* functions from type.c */
PHP_FE ( intval , NULL )
PHP_FE ( floatval , NULL )
PHP_FALIAS ( doubleval , floatval , NULL )
PHP_FE ( strval , NULL )
PHP_FE ( gettype , NULL )
PHP_FE ( settype , first_arg_force_ref )
PHP_FE ( is_null , NULL )
PHP_FE ( is_resource , NULL )
PHP_FE ( is_bool , NULL )
PHP_FE ( is_long , NULL )
PHP_FE ( is_float , NULL )
PHP_FALIAS ( is_int , is_long , NULL )
PHP_FALIAS ( is_integer , is_long , NULL )
PHP_FALIAS ( is_double , is_float , NULL )
PHP_FALIAS ( is_real , is_float , NULL )
PHP_FE ( is_numeric , NULL )
PHP_FE ( is_string , NULL )
PHP_FE ( is_array , NULL )
PHP_FE ( is_object , NULL )
PHP_FE ( is_scalar , NULL )
PHP_FE ( is_callable , third_arg_force_ref )
2000-03-07 04:37:11 +08:00
/* functions from reg.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( ereg , third_arg_force_ref )
PHP_FE ( ereg_replace , NULL )
PHP_FE ( eregi , third_arg_force_ref )
PHP_FE ( eregi_replace , NULL )
PHP_FE ( split , NULL )
PHP_FE ( spliti , NULL )
PHP_FALIAS ( join , implode , NULL )
PHP_FE ( sql_regcase , NULL )
2000-03-07 04:37:11 +08:00
/* functions from dl.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( dl , NULL )
2000-05-28 03:27:20 +08:00
2000-03-07 04:37:11 +08:00
/* functions from file.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( pclose , NULL )
PHP_FE ( popen , NULL )
PHP_FE ( readfile , NULL )
PHP_FE ( rewind , NULL )
PHP_FE ( rmdir , NULL )
PHP_FE ( umask , NULL )
PHP_FE ( fclose , NULL )
PHP_FE ( feof , NULL )
PHP_FE ( fgetc , NULL )
PHP_FE ( fgets , NULL )
PHP_FE ( fgetss , NULL )
PHP_FE ( fread , NULL )
PHP_STATIC_FE ( " fopen " , php_if_fopen , NULL )
PHP_FE ( fpassthru , NULL )
PHP_STATIC_FE ( " ftruncate " , php_if_ftruncate , NULL )
PHP_STATIC_FE ( " fstat " , php_if_fstat , NULL )
PHP_FE ( fseek , NULL )
PHP_FE ( ftell , NULL )
PHP_FE ( fflush , NULL )
PHP_FE ( fwrite , NULL )
PHP_FALIAS ( fputs , fwrite , NULL )
PHP_FE ( mkdir , NULL )
PHP_FE ( rename , NULL )
PHP_FE ( copy , NULL )
PHP_FE ( tempnam , NULL )
PHP_STATIC_FE ( " tmpfile " , php_if_tmpfile , NULL )
PHP_FE ( file , NULL )
2002-03-17 00:52:24 +08:00
PHP_FE ( file_get_contents , NULL )
2002-04-30 08:28:24 +08:00
PHP_FE ( stream_context_create , NULL )
PHP_FE ( stream_context_set_params , NULL )
PHP_FE ( stream_context_set_option , NULL )
PHP_FE ( stream_context_get_options , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( fgetcsv , NULL )
PHP_FE ( flock , NULL )
PHP_FE ( get_meta_tags , NULL )
PHP_FE ( set_file_buffer , NULL )
2000-03-07 04:37:11 +08:00
/* set_socket_blocking() is deprecated,
2001-08-30 00:00:30 +08:00
use socket_set_blocking ( ) instead
*/
PHP_FE ( set_socket_blocking , NULL )
PHP_FE ( socket_set_blocking , NULL )
2002-03-19 21:33:07 +08:00
PHP_FE ( file_get_wrapper_data , NULL )
2002-03-19 11:51:01 +08:00
PHP_FE ( file_register_wrapper , NULL )
2001-08-30 00:00:30 +08:00
2002-07-10 23:23:47 +08:00
# if HAVE_SYS_TIME_H || defined(PHP_WIN32)
2001-08-30 00:00:30 +08:00
PHP_FE ( socket_set_timeout , NULL )
2000-05-28 03:27:20 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( socket_get_status , NULL )
2001-10-23 19:14:51 +08:00
# if (!defined(PHP_WIN32) && !defined(__BEOS__) && HAVE_REALPATH) || defined(ZTS)
2001-08-30 00:00:30 +08:00
PHP_FE ( realpath , NULL )
2000-08-20 02:01:04 +08:00
# endif
2000-03-07 04:37:11 +08:00
2002-03-22 03:18:13 +08:00
# ifdef HAVE_FNMATCH
PHP_FE ( fnmatch , NULL )
# endif
2000-03-07 04:37:11 +08:00
/* functions from fsock.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( fsockopen , third_and_fourth_args_force_ref )
PHP_FE ( pfsockopen , third_and_fourth_args_force_ref )
2000-03-07 04:37:11 +08:00
/* functions from pack.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( pack , NULL )
PHP_FE ( unpack , NULL )
2000-03-07 04:37:11 +08:00
/* functions from browscap.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( get_browser , NULL )
2000-03-07 04:37:11 +08:00
2000-05-28 03:27:20 +08:00
# if HAVE_CRYPT
2000-03-07 04:37:11 +08:00
/* functions from crypt.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( crypt , NULL )
2000-05-28 03:27:20 +08:00
# endif
2000-03-07 04:37:11 +08:00
/* functions from dir.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( opendir , NULL )
PHP_FE ( closedir , NULL )
PHP_FE ( chdir , NULL )
2001-09-12 10:07:46 +08:00
# if defined(HAVE_CHROOT) && !defined(ZTS) && ENABLE_CHROOT_FUNC
2001-08-30 00:00:30 +08:00
PHP_FE ( chroot , NULL )
2001-02-15 08:43:44 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( getcwd , NULL )
PHP_FE ( rewinddir , NULL )
PHP_STATIC_FE ( " readdir " , php_if_readdir , NULL )
PHP_FALIAS ( dir , getdir , NULL )
2002-03-22 03:18:13 +08:00
# ifdef HAVE_GLOB
PHP_FE ( glob , NULL )
# endif
2000-03-07 04:37:11 +08:00
/* functions from filestat.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( fileatime , NULL )
PHP_FE ( filectime , NULL )
PHP_FE ( filegroup , NULL )
PHP_FE ( fileinode , NULL )
PHP_FE ( filemtime , NULL )
PHP_FE ( fileowner , NULL )
PHP_FE ( fileperms , NULL )
PHP_FE ( filesize , NULL )
PHP_FE ( filetype , NULL )
PHP_FE ( file_exists , NULL )
PHP_FE ( is_writable , NULL )
PHP_FALIAS ( is_writeable , is_writable , NULL )
PHP_FE ( is_readable , NULL )
2002-07-03 14:45:01 +08:00
# ifndef PHP_WIN32
2001-08-30 00:00:30 +08:00
PHP_FE ( is_executable , NULL )
2002-07-03 14:45:01 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( is_file , NULL )
PHP_FE ( is_dir , NULL )
PHP_FE ( is_link , NULL )
PHP_STATIC_FE ( " stat " , php_if_stat , NULL )
PHP_STATIC_FE ( " lstat " , php_if_lstat , NULL )
PHP_FE ( chown , NULL )
PHP_FE ( chgrp , NULL )
PHP_FE ( chmod , NULL )
2002-04-27 07:46:51 +08:00
# if HAVE_UTIME
2001-08-30 00:00:30 +08:00
PHP_FE ( touch , NULL )
2002-04-27 07:46:51 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_FE ( clearstatcache , NULL )
PHP_FE ( disk_total_space , NULL )
PHP_FE ( disk_free_space , NULL )
PHP_FALIAS ( diskfreespace , disk_free_space , NULL )
2000-03-07 04:37:11 +08:00
/* functions from mail.c */
2001-02-27 04:26:07 +08:00
# ifdef HAVE_SENDMAIL
2001-08-30 00:00:30 +08:00
PHP_FE ( mail , NULL )
PHP_FE ( ezmlm_hash , NULL )
2001-02-27 04:26:07 +08:00
# endif
2000-03-07 04:37:11 +08:00
/* functions from syslog.c */
2001-02-25 05:08:15 +08:00
# ifdef HAVE_SYSLOG_H
2001-08-30 00:00:30 +08:00
PHP_FE ( openlog , NULL )
PHP_FE ( syslog , NULL )
PHP_FE ( closelog , NULL )
PHP_FE ( define_syslog_variables , NULL )
2001-02-25 05:08:15 +08:00
# endif
2000-03-07 04:37:11 +08:00
/* functions from lcg.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( lcg_value , NULL )
2000-03-07 04:37:11 +08:00
/* functions from metaphone.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( metaphone , NULL )
2000-03-07 04:37:11 +08:00
/* functions from output.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( ob_start , NULL )
2001-11-30 18:48:38 +08:00
PHP_FE ( ob_flush , NULL )
PHP_FE ( ob_clean , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( ob_end_flush , NULL )
PHP_FE ( ob_end_clean , NULL )
PHP_FE ( ob_get_length , NULL )
2001-12-03 15:43:53 +08:00
PHP_FE ( ob_get_level , NULL )
2002-03-01 11:05:50 +08:00
PHP_FE ( ob_get_status , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( ob_get_contents , NULL )
PHP_FE ( ob_implicit_flush , NULL )
2002-08-05 11:09:42 +08:00
PHP_FE ( ob_list_handlers , NULL )
2000-03-07 04:37:11 +08:00
/* functions from array.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( ksort , first_arg_force_ref )
PHP_FE ( krsort , first_arg_force_ref )
PHP_FE ( natsort , first_arg_force_ref )
PHP_FE ( natcasesort , first_arg_force_ref )
PHP_FE ( asort , first_arg_force_ref )
PHP_FE ( arsort , first_arg_force_ref )
PHP_FE ( sort , first_arg_force_ref )
PHP_FE ( rsort , first_arg_force_ref )
PHP_FE ( usort , first_arg_force_ref )
PHP_FE ( uasort , first_arg_force_ref )
PHP_FE ( uksort , first_arg_force_ref )
PHP_FE ( shuffle , first_arg_force_ref )
PHP_FE ( array_walk , first_arg_force_ref )
PHP_FE ( count , NULL )
PHP_FE ( end , first_arg_force_ref )
PHP_FE ( prev , first_arg_force_ref )
PHP_FE ( next , first_arg_force_ref )
PHP_FE ( reset , first_arg_force_ref )
PHP_FE ( current , first_arg_force_ref )
PHP_FE ( key , first_arg_force_ref )
PHP_FE ( min , NULL )
PHP_FE ( max , NULL )
PHP_FE ( in_array , NULL )
PHP_FE ( array_search , NULL )
PHP_FE ( extract , NULL )
PHP_FE ( compact , NULL )
2001-10-24 02:46:35 +08:00
PHP_FE ( array_fill , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( range , NULL )
PHP_FE ( array_multisort , NULL )
PHP_FE ( array_push , first_arg_force_ref )
PHP_FE ( array_pop , first_arg_force_ref )
PHP_FE ( array_shift , first_arg_force_ref )
PHP_FE ( array_unshift , first_arg_force_ref )
PHP_FE ( array_splice , first_arg_force_ref )
PHP_FE ( array_slice , NULL )
PHP_FE ( array_merge , NULL )
PHP_FE ( array_merge_recursive , NULL )
PHP_FE ( array_keys , NULL )
PHP_FE ( array_values , NULL )
PHP_FE ( array_count_values , NULL )
PHP_FE ( array_reverse , NULL )
PHP_FE ( array_reduce , NULL )
PHP_FE ( array_pad , NULL )
PHP_FE ( array_flip , NULL )
2001-10-06 02:38:53 +08:00
PHP_FE ( array_change_key_case , NULL )
2001-08-30 00:00:30 +08:00
PHP_FE ( array_rand , NULL )
PHP_FE ( array_unique , NULL )
PHP_FE ( array_intersect , NULL )
PHP_FE ( array_diff , NULL )
PHP_FE ( array_sum , NULL )
PHP_FE ( array_filter , NULL )
PHP_FE ( array_map , NULL )
2001-10-27 13:11:15 +08:00
PHP_FE ( array_chunk , NULL )
2001-11-12 02:28:43 +08:00
PHP_FE ( array_key_exists , NULL )
2000-06-11 02:58:45 +08:00
2000-03-07 04:37:11 +08:00
/* aliases from array.c */
2001-08-30 00:00:30 +08:00
PHP_FALIAS ( pos , current , first_arg_force_ref )
PHP_FALIAS ( sizeof , count , NULL )
2002-01-03 05:21:48 +08:00
PHP_FALIAS ( key_exists , array_key_exists , NULL )
2000-12-19 03:23:50 +08:00
2000-03-07 04:37:11 +08:00
/* functions from assert.c */
2001-08-30 00:00:30 +08:00
PHP_FE ( assert , NULL )
PHP_FE ( assert_options , NULL )
2000-03-07 04:37:11 +08:00
2001-10-06 07:56:19 +08:00
/* functions from versioning.c */
PHP_FE ( version_compare , NULL )
2001-11-15 17:53:40 +08:00
/* functions from ftok.c*/
# if HAVE_SYSVSEM || HAVE_SYSVSHM || HAVE_SHMOP
PHP_FE ( ftok , NULL )
# endif
2001-12-07 05:39:01 +08:00
PHP_FE ( str_rot13 , NULL )
2002-02-21 11:32:42 +08:00
/* functions from aggregate.c */
PHP_FE ( aggregate , first_arg_force_ref )
PHP_FE ( aggregate_methods , first_arg_force_ref )
PHP_FE ( aggregate_methods_by_list , first_arg_force_ref )
PHP_FE ( aggregate_properties , first_arg_force_ref )
PHP_FE ( aggregate_properties_by_list , first_arg_force_ref )
2002-03-21 23:28:46 +08:00
# if HAVE_PCRE || HAVE_BUNDLED_PCRE
PHP_FE ( aggregate_methods_by_regexp , first_arg_force_ref )
2002-02-21 11:32:42 +08:00
PHP_FE ( aggregate_properties_by_regexp , first_arg_force_ref )
2002-03-21 23:28:46 +08:00
# endif
2002-02-21 11:32:42 +08:00
PHP_FE ( deaggregate , first_arg_force_ref )
PHP_FE ( aggregation_info , first_arg_force_ref )
2002-05-03 16:00:41 +08:00
PHP_FE ( output_add_rewrite_var , NULL )
2002-05-05 02:33:13 +08:00
PHP_FE ( output_reset_rewrite_vars , NULL )
2002-05-03 16:00:41 +08:00
1999-04-17 08:37:12 +08:00
{ NULL , NULL , NULL }
} ;
2000-01-31 04:31:41 +08:00
static PHP_INI_MH ( OnUpdateSafeModeProtectedEnvVars )
{
2000-01-31 04:49:16 +08:00
char * protected_vars , * protected_var ;
2001-05-27 09:18:12 +08:00
char * token_buf ;
2001-08-30 00:00:30 +08:00
int dummy = 1 ;
2000-01-31 04:49:16 +08:00
protected_vars = estrndup ( new_value , new_value_length ) ;
2000-02-01 06:31:00 +08:00
zend_hash_clean ( & BG ( sm_protected_env_vars ) ) ;
2000-01-31 04:49:16 +08:00
2001-08-30 00:00:30 +08:00
protected_var = php_strtok_r ( protected_vars , " , " , & token_buf ) ;
2000-01-31 06:10:30 +08:00
while ( protected_var ) {
2000-02-01 06:31:00 +08:00
zend_hash_update ( & BG ( sm_protected_env_vars ) , protected_var , strlen ( protected_var ) , & dummy , sizeof ( int ) , NULL ) ;
2001-08-30 00:00:30 +08:00
protected_var = php_strtok_r ( NULL , " , " , & token_buf ) ;
2000-01-31 04:49:16 +08:00
}
efree ( protected_vars ) ;
2000-01-31 04:31:41 +08:00
return SUCCESS ;
}
2000-02-01 06:31:00 +08:00
static PHP_INI_MH ( OnUpdateSafeModeAllowedEnvVars )
{
if ( BG ( sm_allowed_env_vars ) ) {
free ( BG ( sm_allowed_env_vars ) ) ;
}
BG ( sm_allowed_env_vars ) = zend_strndup ( new_value , new_value_length ) ;
return SUCCESS ;
}
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
PHP_INI_BEGIN ( )
2001-08-30 00:00:30 +08:00
PHP_INI_ENTRY_EX ( " safe_mode_protected_env_vars " , SAFE_MODE_PROTECTED_ENV_VARS , PHP_INI_SYSTEM , OnUpdateSafeModeProtectedEnvVars , NULL )
PHP_INI_ENTRY_EX ( " safe_mode_allowed_env_vars " , SAFE_MODE_ALLOWED_ENV_VARS , PHP_INI_SYSTEM , OnUpdateSafeModeAllowedEnvVars , NULL )
1999-04-17 08:37:12 +08:00
PHP_INI_END ( )
1999-12-18 04:55:31 +08:00
zend_module_entry basic_functions_module = {
2001-10-12 07:33:59 +08:00
STANDARD_MODULE_HEADER ,
2000-03-07 02:44:01 +08:00
" standard " , /* extension name */
1999-04-17 08:37:12 +08:00
basic_functions , /* function list */
1999-07-27 04:09:08 +08:00
PHP_MINIT ( basic ) , /* process startup */
PHP_MSHUTDOWN ( basic ) , /* process shutdown */
PHP_RINIT ( basic ) , /* request startup */
PHP_RSHUTDOWN ( basic ) , /* request shutdown */
2000-03-07 04:37:11 +08:00
PHP_MINFO ( basic ) , /* extension info */
2001-10-12 07:33:59 +08:00
PHP_VERSION , /* extension version */
2001-05-23 03:19:04 +08:00
STANDARD_MODULE_PROPERTIES
1999-04-17 08:37:12 +08:00
} ;
2001-08-30 00:00:30 +08:00
# if defined(HAVE_PUTENV)
2000-01-18 01:33:37 +08:00
static void php_putenv_destructor ( putenv_entry * pe )
1999-04-17 08:37:12 +08:00
{
if ( pe - > previous_value ) {
putenv ( pe - > previous_value ) ;
} else {
# if HAVE_UNSETENV
unsetenv ( pe - > key ) ;
# else
char * * env ;
2000-12-19 03:23:50 +08:00
1999-04-17 08:37:12 +08:00
for ( env = environ ; env ! = NULL & & * env ! = NULL ; env + + ) {
2001-08-30 00:00:30 +08:00
if ( ! strncmp ( * env , pe - > key , pe - > key_len ) & & ( * env ) [ pe - > key_len ] = = ' = ' ) { /* found it */
1999-04-17 08:37:12 +08:00
* env = " " ;
break ;
}
}
# endif
}
efree ( pe - > putenv_string ) ;
efree ( pe - > key ) ;
}
# endif
2001-07-28 19:36:37 +08:00
static void basic_globals_ctor ( php_basic_globals * basic_globals_p TSRMLS_DC )
1999-12-14 02:31:29 +08:00
{
BG ( next ) = NULL ;
BG ( left ) = - 1 ;
2000-09-02 23:54:18 +08:00
BG ( user_tick_functions ) = NULL ;
2002-02-21 11:32:42 +08:00
BG ( aggregation_table ) = NULL ;
2000-02-01 06:31:00 +08:00
zend_hash_init ( & BG ( sm_protected_env_vars ) , 5 , NULL , NULL , 1 ) ;
BG ( sm_allowed_env_vars ) = NULL ;
2000-09-20 01:37:34 +08:00
2001-08-26 09:09:20 +08:00
memset ( & BG ( url_adapt_state ) , 0 , sizeof ( BG ( url_adapt_state ) ) ) ;
memset ( & BG ( url_adapt_state_ex ) , 0 , sizeof ( BG ( url_adapt_state_ex ) ) ) ;
2000-08-11 21:30:37 +08:00
# ifdef PHP_WIN32
CoInitialize ( NULL ) ;
# endif
2001-08-06 21:36:08 +08:00
BG ( incomplete_class ) = php_create_incomplete_class ( TSRMLS_C ) ;
1999-12-14 02:31:29 +08:00
}
2001-08-30 00:00:30 +08:00
2001-07-28 19:36:37 +08:00
static void basic_globals_dtor ( php_basic_globals * basic_globals_p TSRMLS_DC )
2000-01-31 04:49:16 +08:00
{
2000-02-01 06:31:00 +08:00
zend_hash_destroy ( & BG ( sm_protected_env_vars ) ) ;
if ( BG ( sm_allowed_env_vars ) ) {
free ( BG ( sm_allowed_env_vars ) ) ;
}
2000-08-11 21:30:37 +08:00
# ifdef PHP_WIN32
CoUninitialize ( ) ;
# endif
2000-01-31 04:49:16 +08:00
}
1999-07-27 04:09:08 +08:00
PHP_MINIT_FUNCTION ( basic )
1999-04-17 08:37:12 +08:00
{
1999-11-28 08:31:02 +08:00
# ifdef ZTS
2001-07-27 18:16:41 +08:00
ts_allocate_id ( & basic_globals_id , sizeof ( php_basic_globals ) , ( ts_allocate_ctor ) basic_globals_ctor , ( ts_allocate_dtor ) basic_globals_dtor ) ;
1999-12-14 02:31:29 +08:00
# else
2001-07-28 19:36:37 +08:00
basic_globals_ctor ( & basic_globals TSRMLS_CC ) ;
1999-11-28 08:31:02 +08:00
# endif
2000-12-19 03:23:50 +08:00
2001-05-23 11:37:53 +08:00
REGISTER_LONG_CONSTANT ( " CONNECTION_ABORTED " , PHP_CONNECTION_ABORTED , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " CONNECTION_NORMAL " , PHP_CONNECTION_NORMAL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " CONNECTION_TIMEOUT " , PHP_CONNECTION_TIMEOUT , CONST_CS | CONST_PERSISTENT ) ;
2001-08-30 00:00:30 +08:00
2001-08-31 01:47:04 +08:00
REGISTER_LONG_CONSTANT ( " INI_USER " , ZEND_INI_USER , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " INI_PERDIR " , ZEND_INI_PERDIR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " INI_SYSTEM " , ZEND_INI_SYSTEM , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " INI_ALL " , ZEND_INI_ALL , CONST_CS | CONST_PERSISTENT ) ;
2000-04-09 07:53:19 +08:00
# define REGISTER_MATH_CONSTANT(x) REGISTER_DOUBLE_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT)
REGISTER_MATH_CONSTANT ( M_E ) ;
REGISTER_MATH_CONSTANT ( M_LOG2E ) ;
REGISTER_MATH_CONSTANT ( M_LOG10E ) ;
REGISTER_MATH_CONSTANT ( M_LN2 ) ;
REGISTER_MATH_CONSTANT ( M_LN10 ) ;
REGISTER_MATH_CONSTANT ( M_PI ) ;
REGISTER_MATH_CONSTANT ( M_PI_2 ) ;
REGISTER_MATH_CONSTANT ( M_PI_4 ) ;
REGISTER_MATH_CONSTANT ( M_1_PI ) ;
REGISTER_MATH_CONSTANT ( M_2_PI ) ;
REGISTER_MATH_CONSTANT ( M_2_SQRTPI ) ;
REGISTER_MATH_CONSTANT ( M_SQRT2 ) ;
REGISTER_MATH_CONSTANT ( M_SQRT1_2 ) ;
2001-08-30 07:53:22 +08:00
# if ENABLE_TEST_CLASS
1999-04-17 08:37:12 +08:00
test_class_startup ( ) ;
2001-08-30 07:53:22 +08:00
# endif
1999-04-17 08:37:12 +08:00
REGISTER_INI_ENTRIES ( ) ;
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
1999-07-15 00:02:10 +08:00
register_phpinfo_constants ( INIT_FUNC_ARGS_PASSTHRU ) ;
1999-11-21 21:25:04 +08:00
register_html_constants ( INIT_FUNC_ARGS_PASSTHRU ) ;
2000-07-09 04:38:23 +08:00
register_string_constants ( INIT_FUNC_ARGS_PASSTHRU ) ;
2000-03-07 04:37:11 +08:00
2001-08-30 00:00:30 +08:00
PHP_MINIT ( regex ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( file ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( pack ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( browscap ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2001-01-18 04:37:49 +08:00
# if defined(HAVE_LOCALECONV) && defined(ZTS)
2001-08-30 00:00:30 +08:00
PHP_MINIT ( localeconv ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2001-01-15 00:36:30 +08:00
# endif
2001-08-30 00:00:30 +08:00
2001-07-04 18:10:30 +08:00
# if defined(HAVE_NL_LANGINFO)
2001-08-30 00:00:30 +08:00
PHP_MINIT ( nl_langinfo ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2001-07-04 18:10:30 +08:00
# endif
2001-08-30 00:00:30 +08:00
2000-03-07 20:28:06 +08:00
# if HAVE_CRYPT
2001-08-30 00:00:30 +08:00
PHP_MINIT ( crypt ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2000-03-07 20:28:06 +08:00
# endif
2001-08-30 00:00:30 +08:00
PHP_MINIT ( lcg ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2001-05-07 01:55:10 +08:00
2001-08-30 00:00:30 +08:00
PHP_MINIT ( dir ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( syslog ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( array ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( assert ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( url_scanner_ex ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2002-04-03 00:46:33 +08:00
PHP_MINIT ( proc_open ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2000-03-07 04:37:11 +08:00
2002-04-17 06:14:27 +08:00
PHP_MINIT ( user_streams ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2002-06-25 03:36:26 +08:00
PHP_MINIT ( imagetypes ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2001-08-06 21:36:08 +08:00
2002-04-17 06:14:27 +08:00
php_register_url_stream_wrapper ( " php " , & php_stream_php_wrapper TSRMLS_CC ) ;
2002-08-12 23:56:13 +08:00
# ifndef PHP_CURL_URL_WRAPPERS
php_register_url_stream_wrapper ( " http " , & php_stream_http_wrapper TSRMLS_CC ) ;
2002-04-17 06:14:27 +08:00
php_register_url_stream_wrapper ( " ftp " , & php_stream_ftp_wrapper TSRMLS_CC ) ;
2002-03-16 05:03:08 +08:00
# if HAVE_OPENSSL_EXT
2002-04-17 06:14:27 +08:00
php_register_url_stream_wrapper ( " https " , & php_stream_http_wrapper TSRMLS_CC ) ;
2002-03-16 05:03:08 +08:00
# endif
2002-08-12 23:56:13 +08:00
# endif
2000-12-19 03:23:50 +08:00
1999-04-17 08:37:12 +08:00
return SUCCESS ;
}
1999-07-27 04:09:08 +08:00
PHP_MSHUTDOWN_FUNCTION ( basic )
1999-04-17 08:37:12 +08:00
{
1999-11-28 08:31:02 +08:00
# ifdef ZTS
ts_free_id ( basic_globals_id ) ;
2001-07-28 19:36:37 +08:00
# else
basic_globals_dtor ( & basic_globals TSRMLS_CC ) ;
1999-11-28 08:31:02 +08:00
# endif
2000-01-31 04:49:16 +08:00
2002-08-12 23:56:13 +08:00
php_unregister_url_stream_wrapper ( " php " TSRMLS_CC ) ;
# ifndef PHP_CURL_URL_WRAPPERS
2002-04-17 06:14:27 +08:00
php_unregister_url_stream_wrapper ( " http " TSRMLS_CC ) ;
php_unregister_url_stream_wrapper ( " ftp " TSRMLS_CC ) ;
2002-03-16 05:03:08 +08:00
# if HAVE_OPENSSL_EXT
2002-04-17 06:14:27 +08:00
php_unregister_url_stream_wrapper ( " https " TSRMLS_CC ) ;
2002-03-16 05:03:08 +08:00
# endif
2002-08-12 23:56:13 +08:00
# endif
2002-03-16 05:03:08 +08:00
1999-04-17 08:37:12 +08:00
UNREGISTER_INI_ENTRIES ( ) ;
2000-03-07 04:37:11 +08:00
2001-08-30 00:00:30 +08:00
PHP_MSHUTDOWN ( regex ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_MSHUTDOWN ( browscap ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_MSHUTDOWN ( array ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_MSHUTDOWN ( assert ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_MSHUTDOWN ( url_scanner_ex ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_MSHUTDOWN ( file ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
2001-01-18 04:37:49 +08:00
# if defined(HAVE_LOCALECONV) && defined(ZTS)
2001-08-30 00:00:30 +08:00
PHP_MSHUTDOWN ( localeconv ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
2001-01-15 00:36:30 +08:00
# endif
2000-10-13 08:09:31 +08:00
2000-12-19 03:23:50 +08:00
return SUCCESS ;
1999-04-17 08:37:12 +08:00
}
1999-07-27 04:09:08 +08:00
PHP_RINIT_FUNCTION ( basic )
1999-04-17 08:37:12 +08:00
{
2001-08-03 16:49:19 +08:00
memset ( BG ( strtok_table ) , 0 , 256 ) ;
1999-11-28 08:31:02 +08:00
BG ( strtok_string ) = NULL ;
2001-08-03 17:50:38 +08:00
BG ( strtok_zval ) = NULL ;
1999-11-28 08:31:02 +08:00
BG ( locale_string ) = NULL ;
1999-12-02 01:21:52 +08:00
BG ( user_compare_func_name ) = NULL ;
BG ( array_walk_func_name ) = NULL ;
2001-05-19 07:38:46 +08:00
# ifdef HAVE_MMAP
BG ( mmap_file ) = NULL ;
# endif
1999-12-13 00:14:40 +08:00
BG ( page_uid ) = - 1 ;
2001-07-10 01:36:04 +08:00
BG ( page_gid ) = - 1 ;
1999-12-13 00:14:40 +08:00
BG ( page_inode ) = - 1 ;
BG ( page_mtime ) = - 1 ;
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
# ifdef HAVE_PUTENV
2000-01-18 01:33:37 +08:00
if ( zend_hash_init ( & BG ( putenv_ht ) , 1 , NULL , ( void ( * ) ( void * ) ) php_putenv_destructor , 0 ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
return FAILURE ;
}
# endif
2001-08-30 00:00:30 +08:00
BG ( user_shutdown_function_names ) = NULL ;
2000-03-07 04:37:11 +08:00
2001-09-06 03:47:55 +08:00
# if HAVE_CRYPT
PHP_RINIT ( crypt ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
# endif
2001-08-30 00:00:30 +08:00
PHP_RINIT ( lcg ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2001-05-07 01:55:10 +08:00
2001-08-30 00:00:30 +08:00
PHP_RINIT ( filestat ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_RINIT ( syslog ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_RINIT ( dir ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2002-05-03 16:00:41 +08:00
PHP_RINIT ( url_scanner_ex ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
2001-08-30 00:00:30 +08:00
2002-06-13 01:25:48 +08:00
/* Reset magic_quotes_runtime */
PG ( magic_quotes_runtime ) = INI_BOOL ( " magic_quotes_runtime " ) ;
1999-04-17 08:37:12 +08:00
return SUCCESS ;
}
1999-07-27 04:09:08 +08:00
PHP_RSHUTDOWN_FUNCTION ( basic )
1999-04-17 08:37:12 +08:00
{
2001-08-30 00:00:30 +08:00
if ( BG ( strtok_zval ) ) {
2001-08-05 00:53:57 +08:00
zval_ptr_dtor ( & BG ( strtok_zval ) ) ;
2001-08-30 00:00:30 +08:00
}
2001-07-09 07:28:48 +08:00
BG ( strtok_string ) = NULL ;
2001-08-03 17:50:38 +08:00
BG ( strtok_zval ) = NULL ;
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
# ifdef HAVE_PUTENV
1999-11-28 08:31:02 +08:00
zend_hash_destroy ( & BG ( putenv_ht ) ) ;
1999-04-17 08:37:12 +08:00
# endif
2001-08-30 00:00:30 +08:00
1999-10-08 10:10:57 +08:00
/* Check if locale was changed and change it back
to the value in startup environment */
1999-11-28 08:31:02 +08:00
if ( BG ( locale_string ) ! = NULL ) {
2000-06-06 02:47:34 +08:00
setlocale ( LC_ALL , " C " ) ;
setlocale ( LC_CTYPE , " " ) ;
1999-10-08 10:10:57 +08:00
}
1999-11-28 08:31:02 +08:00
STR_FREE ( BG ( locale_string ) ) ;
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
2001-08-30 00:00:30 +08:00
PHP_RSHUTDOWN ( fsock ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_RSHUTDOWN ( filestat ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_RSHUTDOWN ( syslog ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
PHP_RSHUTDOWN ( assert ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
2002-05-03 16:00:41 +08:00
PHP_RSHUTDOWN ( url_scanner_ex ) ( SHUTDOWN_FUNC_ARGS_PASSTHRU ) ;
2000-03-07 04:37:11 +08:00
2000-09-02 00:10:17 +08:00
if ( BG ( user_tick_functions ) ) {
zend_llist_destroy ( BG ( user_tick_functions ) ) ;
efree ( BG ( user_tick_functions ) ) ;
BG ( user_tick_functions ) = NULL ;
}
2002-02-21 11:32:42 +08:00
if ( BG ( aggregation_table ) ) {
zend_hash_destroy ( BG ( aggregation_table ) ) ;
efree ( BG ( aggregation_table ) ) ;
BG ( aggregation_table ) = NULL ;
}
2001-05-19 07:38:46 +08:00
# ifdef HAVE_MMAP
if ( BG ( mmap_file ) ) {
munmap ( BG ( mmap_file ) , BG ( mmap_len ) ) ;
}
# endif
1999-04-17 08:37:12 +08:00
return SUCCESS ;
}
2000-03-05 01:28:16 +08:00
2000-03-07 04:37:11 +08:00
PHP_MINFO_FUNCTION ( basic )
{
2000-06-07 17:55:37 +08:00
php_info_print_table_start ( ) ;
2001-08-30 00:00:30 +08:00
PHP_MINFO ( regex ) ( ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU ) ;
PHP_MINFO ( dl ) ( ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU ) ;
PHP_MINFO ( mail ) ( ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU ) ;
2000-06-07 17:55:37 +08:00
php_info_print_table_end ( ) ;
2001-08-30 00:00:30 +08:00
PHP_MINFO ( assert ) ( ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU ) ;
2000-03-07 04:37:11 +08:00
}
2001-08-30 00:00:30 +08:00
2000-11-25 05:05:25 +08:00
/* {{{ proto mixed constant(string const_name)
Given the name of a constant this function will return the constants associated value */
PHP_FUNCTION ( constant )
{
2001-08-30 00:00:30 +08:00
zval * * const_name ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | |
zend_get_parameters_ex ( 1 , & const_name ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
convert_to_string_ex ( const_name ) ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( ! zend_get_constant ( Z_STRVAL_PP ( const_name ) , Z_STRLEN_PP ( const_name ) , return_value TSRMLS_CC ) ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Couldn't find constant %s " , get_active_function_name ( TSRMLS_C ) , Z_STRVAL_PP ( const_name ) ) ;
2001-08-30 00:00:30 +08:00
RETURN_NULL ( ) ;
}
2000-11-25 05:05:25 +08:00
}
/* }}} */
2001-07-02 19:11:58 +08:00
/* {{{ proto int ip2long(string ip_address)
2000-07-26 19:43:01 +08:00
Converts a string containing an ( IPv4 ) Internet Protocol dotted address into a proper address */
2000-03-05 01:28:16 +08:00
PHP_FUNCTION ( ip2long )
{
zval * * str ;
2000-06-06 03:47:54 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & str ) = = FAILURE ) {
2000-03-05 01:28:16 +08:00
WRONG_PARAM_COUNT ;
}
convert_to_string_ex ( str ) ;
2001-05-20 08:23:49 +08:00
RETURN_LONG ( ntohl ( inet_addr ( Z_STRVAL_PP ( str ) ) ) ) ;
2000-03-05 01:28:16 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
2000-03-05 01:28:16 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto string long2ip(int proper_address)
2000-07-26 19:43:01 +08:00
Converts an ( IPv4 ) Internet network address into a string in Internet standard dotted format */
2000-03-05 01:28:16 +08:00
PHP_FUNCTION ( long2ip )
{
zval * * num ;
2001-12-07 21:20:18 +08:00
unsigned long n ;
2000-03-05 01:28:16 +08:00
struct in_addr myaddr ;
2000-12-19 03:23:50 +08:00
2000-06-06 03:47:54 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & num ) = = FAILURE ) {
2000-03-05 01:28:16 +08:00
WRONG_PARAM_COUNT ;
}
2001-12-07 21:20:18 +08:00
convert_to_string_ex ( num ) ;
n = strtoul ( Z_STRVAL_PP ( num ) , NULL , 0 ) ;
2000-12-19 03:23:50 +08:00
2001-12-07 21:20:18 +08:00
myaddr . s_addr = htonl ( n ) ;
2001-08-30 00:00:30 +08:00
RETURN_STRING ( inet_ntoa ( myaddr ) , 1 ) ;
2000-03-05 01:28:16 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
2000-03-05 01:28:16 +08:00
1999-04-17 08:37:12 +08:00
/********************
* System Functions *
* * * * * * * * * * * * * * * * * * * */
2000-03-29 09:39:04 +08:00
/* {{{ proto string getenv(string varname)
Get the value of an environment variable */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( getenv )
1999-04-17 08:37:12 +08:00
{
2001-12-30 17:36:24 +08:00
char * ptr , * str ;
int str_len ;
2000-02-11 01:55:01 +08:00
2001-12-30 17:36:24 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & str , & str_len ) = = FAILURE ) {
2000-02-11 01:55:01 +08:00
RETURN_FALSE ;
1999-04-17 08:37:12 +08:00
}
2001-12-30 17:36:24 +08:00
ptr = sapi_getenv ( str , str_len TSRMLS_CC ) ;
if ( ! ptr ) {
ptr = getenv ( str ) ;
2000-02-11 01:55:01 +08:00
}
if ( ptr ) {
RETURN_STRING ( ptr , 1 ) ;
1999-04-17 08:37:12 +08:00
}
RETURN_FALSE ;
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-05-28 03:27:20 +08:00
# ifdef HAVE_PUTENV
2001-07-02 19:11:58 +08:00
/* {{{ proto bool putenv(string setting)
2000-03-29 09:39:04 +08:00
Set the value of an environment variable */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( putenv )
1999-04-17 08:37:12 +08:00
{
1999-10-06 20:54:45 +08:00
pval * * str ;
1999-04-17 08:37:12 +08:00
2000-06-06 03:47:54 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & str ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( str ) ;
1999-04-17 08:37:12 +08:00
2000-11-27 21:31:21 +08:00
if ( Z_STRVAL_PP ( str ) & & * ( Z_STRVAL_PP ( str ) ) ) {
2001-08-12 01:03:37 +08:00
char * p , * * env ;
1999-04-17 08:37:12 +08:00
putenv_entry pe ;
2000-12-19 03:23:50 +08:00
2001-08-12 01:03:37 +08:00
pe . putenv_string = estrndup ( Z_STRVAL_PP ( str ) , Z_STRLEN_PP ( str ) ) ;
2000-11-27 21:31:21 +08:00
pe . key = estrndup ( Z_STRVAL_PP ( str ) , Z_STRLEN_PP ( str ) ) ;
2001-08-30 00:00:30 +08:00
if ( ( p = strchr ( pe . key , ' = ' ) ) ) { /* nullify the '=' if there is one */
* p = ' \0 ' ;
1999-04-17 08:37:12 +08:00
}
pe . key_len = strlen ( pe . key ) ;
2000-12-19 03:23:50 +08:00
2000-02-01 06:31:00 +08:00
if ( PG ( safe_mode ) ) {
/* Check the protected list */
if ( zend_hash_exists ( & BG ( sm_protected_env_vars ) , pe . key , pe . key_len ) ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Safe Mode warning: Cannot override protected environment variable '%s' " , get_active_function_name ( TSRMLS_C ) , pe . key ) ;
2000-02-01 06:31:00 +08:00
efree ( pe . putenv_string ) ;
efree ( pe . key ) ;
RETURN_FALSE ;
}
/* Check the allowed list */
if ( BG ( sm_allowed_env_vars ) & & * BG ( sm_allowed_env_vars ) ) {
char * allowed_env_vars = estrdup ( BG ( sm_allowed_env_vars ) ) ;
char * allowed_prefix = strtok ( allowed_env_vars , " , " ) ;
2001-08-30 00:00:30 +08:00
zend_bool allowed = 0 ;
2000-02-01 06:31:00 +08:00
while ( allowed_prefix ) {
if ( ! strncmp ( allowed_prefix , pe . key , strlen ( allowed_prefix ) ) ) {
2001-08-30 00:00:30 +08:00
allowed = 1 ;
2000-02-01 06:31:00 +08:00
break ;
}
allowed_prefix = strtok ( NULL , " , " ) ;
}
efree ( allowed_env_vars ) ;
if ( ! allowed ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Safe Mode warning: Cannot set environment variable '%s' - it's not in the allowed list " , get_active_function_name ( TSRMLS_C ) , pe . key ) ;
2000-02-01 06:31:00 +08:00
efree ( pe . putenv_string ) ;
efree ( pe . key ) ;
RETURN_FALSE ;
}
}
2000-01-31 06:10:30 +08:00
}
2001-10-29 06:51:58 +08:00
zend_hash_del ( & BG ( putenv_ht ) , pe . key , pe . key_len + 1 ) ;
2000-12-19 03:23:50 +08:00
1999-04-17 08:37:12 +08:00
/* find previous value */
pe . previous_value = NULL ;
for ( env = environ ; env ! = NULL & & * env ! = NULL ; env + + ) {
2001-08-30 00:00:30 +08:00
if ( ! strncmp ( * env , pe . key , pe . key_len ) & & ( * env ) [ pe . key_len ] = = ' = ' ) { /* found it */
1999-04-17 08:37:12 +08:00
pe . previous_value = * env ;
break ;
}
}
2002-05-05 02:11:36 +08:00
if ( putenv ( pe . putenv_string ) = = 0 ) { /* success */
2001-10-29 06:51:58 +08:00
zend_hash_add ( & BG ( putenv_ht ) , pe . key , pe . key_len + 1 , ( void * * ) & pe , sizeof ( putenv_entry ) , NULL ) ;
2001-01-09 17:02:21 +08:00
# ifdef HAVE_TZSET
2001-08-30 00:00:30 +08:00
if ( ! strncmp ( pe . key , " TZ " , 2 ) ) {
tzset ( ) ;
}
2001-01-09 17:02:21 +08:00
# endif
1999-04-17 08:37:12 +08:00
RETURN_TRUE ;
} else {
efree ( pe . putenv_string ) ;
efree ( pe . key ) ;
RETURN_FALSE ;
}
}
}
2000-03-29 09:39:04 +08:00
/* }}} */
2000-05-28 03:27:20 +08:00
# endif
1999-04-17 08:37:12 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto void flush(void)
Flush the output buffer */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( flush )
1999-04-17 08:37:12 +08:00
{
2001-07-31 14:28:05 +08:00
sapi_flush ( TSRMLS_C ) ;
1999-04-17 08:37:12 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto void sleep(int seconds)
Delay for a given number of seconds */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( sleep )
1999-04-17 08:37:12 +08:00
{
1999-10-06 20:54:45 +08:00
pval * * num ;
1999-04-17 08:37:12 +08:00
2000-06-06 03:47:54 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & num ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
2001-08-30 00:00:30 +08:00
1999-10-06 20:54:45 +08:00
convert_to_long_ex ( num ) ;
2000-11-27 21:31:21 +08:00
php_sleep ( Z_LVAL_PP ( num ) ) ;
1999-04-17 08:37:12 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto void usleep(int micro_seconds)
Delay for a given number of micro seconds */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( usleep )
1999-04-17 08:37:12 +08:00
{
# if HAVE_USLEEP
1999-10-06 20:54:45 +08:00
pval * * num ;
1999-04-17 08:37:12 +08:00
2000-06-06 03:47:54 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & num ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
1999-10-06 20:54:45 +08:00
convert_to_long_ex ( num ) ;
2000-11-27 21:31:21 +08:00
usleep ( Z_LVAL_PP ( num ) ) ;
1999-04-17 08:37:12 +08:00
# endif
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto string get_current_user(void)
Get the name of the owner of the current PHP script */
1999-11-14 04:31:54 +08:00
PHP_FUNCTION ( get_current_user )
1999-04-17 08:37:12 +08:00
{
2001-08-13 15:55:39 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 0 ) {
WRONG_PARAM_COUNT ;
}
2001-08-13 14:43:47 +08:00
2001-08-12 01:03:37 +08:00
RETURN_STRING ( php_get_current_user ( ) , 1 ) ;
1999-11-14 04:31:54 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto string get_cfg_var(string option_name)
Get the value of a PHP configuration option */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( get_cfg_var )
1999-04-17 08:37:12 +08:00
{
1999-10-06 20:54:45 +08:00
pval * * varname ;
1999-04-17 08:37:12 +08:00
char * value ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & varname ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
2000-12-19 03:23:50 +08:00
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( varname ) ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( cfg_get_string ( Z_STRVAL_PP ( varname ) , & value ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
RETURN_FALSE ;
}
2001-08-12 01:03:37 +08:00
RETURN_STRING ( value , 1 ) ;
1999-04-17 08:37:12 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
2001-07-02 19:11:58 +08:00
/* {{{ proto bool set_magic_quotes_runtime(int new_setting)
2000-03-29 09:39:04 +08:00
Set the current active configuration setting of magic_quotes_runtime and return previous */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( set_magic_quotes_runtime )
1999-04-17 08:37:12 +08:00
{
1999-10-06 20:54:45 +08:00
pval * * new_setting ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & new_setting ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
RETURN_FALSE ;
}
1999-10-06 20:54:45 +08:00
convert_to_boolean_ex ( new_setting ) ;
2000-12-19 03:23:50 +08:00
2000-11-27 21:31:21 +08:00
PG ( magic_quotes_runtime ) = ( zend_bool ) Z_LVAL_PP ( new_setting ) ;
1999-04-17 08:37:12 +08:00
RETURN_TRUE ;
}
2000-03-29 09:39:04 +08:00
/* }}} */
/* {{{ proto int get_magic_quotes_runtime(void)
2000-12-19 03:23:50 +08:00
Get the current active configuration setting of magic_quotes_runtime */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( get_magic_quotes_runtime )
1999-04-17 08:37:12 +08:00
{
RETURN_LONG ( PG ( magic_quotes_runtime ) ) ;
}
2001-08-30 00:00:30 +08:00
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto int get_magic_quotes_gpc(void)
Get the current active configuration setting of magic_quotes_gpc */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( get_magic_quotes_gpc )
1999-04-17 08:37:12 +08:00
{
RETURN_LONG ( PG ( magic_quotes_gpc ) ) ;
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-12-19 03:23:50 +08:00
/*
1999-04-17 08:37:12 +08:00
1 st arg = error message
2 nd arg = error option
3 rd arg = optional parameters ( email address or tcp address )
4 th arg = used for additional headers if email
2001-08-30 00:00:30 +08:00
error options :
1999-08-03 03:17:14 +08:00
0 = send to php_error_log ( uses syslog or file depending on ini setting )
1999-04-17 08:37:12 +08:00
1 = send via email to 3 rd parameter 4 th option = additional headers
2 = send via tcp / ip to 3 rd parameter ( name or ip : port )
3 = save to file in 3 rd parameter
*/
2001-07-02 19:11:58 +08:00
/* {{{ proto bool error_log(string message, int message_type [, string destination] [, string extra_headers])
2000-03-29 09:39:04 +08:00
Send an error message somewhere */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( error_log )
1999-04-17 08:37:12 +08:00
{
1999-10-06 20:54:45 +08:00
pval * * string , * * erropt = NULL , * * option = NULL , * * emailhead = NULL ;
1999-04-17 08:37:12 +08:00
int opt_err = 0 ;
2001-08-30 00:00:30 +08:00
char * message , * opt = NULL , * headers = NULL ;
1999-04-17 08:37:12 +08:00
2001-08-30 00:00:30 +08:00
switch ( ZEND_NUM_ARGS ( ) ) {
case 1 :
if ( zend_get_parameters_ex ( 1 , & string ) = = FAILURE ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Argument 1 invalid " , get_active_function_name ( TSRMLS_C ) ) ;
2001-08-30 00:00:30 +08:00
RETURN_FALSE ;
}
break ;
case 2 :
if ( zend_get_parameters_ex ( 2 , & string , & erropt ) = = FAILURE ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Invalid arguments " , get_active_function_name ( TSRMLS_C ) ) ;
2001-08-30 00:00:30 +08:00
RETURN_FALSE ;
}
convert_to_long_ex ( erropt ) ;
opt_err = Z_LVAL_PP ( erropt ) ;
break ;
case 3 :
2002-07-08 20:52:22 +08:00
if ( zend_get_parameters_ex ( 3 , & string , & erropt , & option ) = = FAILURE ) {
php_error ( E_WARNING , " %s(): Invalid arguments " , get_active_function_name ( TSRMLS_C ) ) ;
2001-08-30 00:00:30 +08:00
RETURN_FALSE ;
}
convert_to_long_ex ( erropt ) ;
opt_err = Z_LVAL_PP ( erropt ) ;
convert_to_string_ex ( option ) ;
opt = Z_STRVAL_PP ( option ) ;
break ;
case 4 :
2002-07-08 20:52:22 +08:00
if ( zend_get_parameters_ex ( 4 , & string , & erropt , & option , & emailhead ) = = FAILURE ) {
php_error ( E_WARNING , " %s(): Invalid arguments in " , get_active_function_name ( TSRMLS_C ) ) ;
2001-08-30 00:00:30 +08:00
RETURN_FALSE ;
}
break ;
default :
WRONG_PARAM_COUNT ;
1999-04-17 08:37:12 +08:00
}
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( string ) ;
2001-08-30 00:00:30 +08:00
message = Z_STRVAL_PP ( string ) ;
1999-04-17 08:37:12 +08:00
if ( erropt ! = NULL ) {
1999-10-06 20:54:45 +08:00
convert_to_long_ex ( erropt ) ;
2001-08-30 00:00:30 +08:00
opt_err = Z_LVAL_PP ( erropt ) ;
1999-04-17 08:37:12 +08:00
}
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
if ( option ! = NULL ) {
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( option ) ;
2001-08-30 00:00:30 +08:00
opt = Z_STRVAL_PP ( option ) ;
1999-04-17 08:37:12 +08:00
}
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
if ( emailhead ! = NULL ) {
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( emailhead ) ;
2001-08-30 00:00:30 +08:00
headers = Z_STRVAL_PP ( emailhead ) ;
1999-04-17 08:37:12 +08:00
}
2001-08-30 00:00:30 +08:00
if ( _php_error_log ( opt_err , message , opt , headers TSRMLS_CC ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
RETURN_FALSE ;
}
2001-08-30 00:00:30 +08:00
1999-04-17 08:37:12 +08:00
RETURN_TRUE ;
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2001-08-30 00:00:30 +08:00
2001-07-31 15:09:49 +08:00
PHPAPI int _php_error_log ( int opt_err , char * message , char * opt , char * headers TSRMLS_DC )
2001-02-06 05:59:17 +08:00
{
2002-03-16 09:28:57 +08:00
php_stream * stream = NULL ;
1999-04-17 08:37:12 +08:00
2001-08-30 00:00:30 +08:00
switch ( opt_err ) {
case 1 : /*send an email */
{
1999-04-17 08:37:12 +08:00
# if HAVE_SENDMAIL
2002-03-16 20:45:43 +08:00
if ( ! php_mail ( opt , " PHP error_log message " , message , headers , NULL TSRMLS_CC ) ) {
2001-02-06 05:59:17 +08:00
return FAILURE ;
}
1999-04-17 08:37:12 +08:00
# else
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Mail option not available! " , get_active_function_name ( TSRMLS_C ) ) ;
2001-02-06 05:59:17 +08:00
return FAILURE ;
1999-04-17 08:37:12 +08:00
# endif
2001-02-06 05:59:17 +08:00
}
break ;
2001-08-30 00:00:30 +08:00
case 2 : /*send to an address */
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): TCP/IP option not available! " , get_active_function_name ( TSRMLS_C ) ) ;
1999-04-17 08:37:12 +08:00
return FAILURE ;
2001-02-06 05:59:17 +08:00
break ;
2001-08-30 00:00:30 +08:00
case 3 : /*save to a file */
2002-03-18 06:50:59 +08:00
stream = php_stream_open_wrapper ( opt , " a " , IGNORE_URL | ENFORCE_SAFE_MODE | REPORT_ERRORS , NULL ) ;
2002-03-16 05:03:08 +08:00
if ( ! stream )
2001-02-06 05:59:17 +08:00
return FAILURE ;
2002-03-16 05:03:08 +08:00
php_stream_write ( stream , message , strlen ( message ) ) ;
php_stream_close ( stream ) ;
2001-02-06 05:59:17 +08:00
break ;
2001-08-30 00:00:30 +08:00
2001-02-06 05:59:17 +08:00
default :
2001-08-06 00:21:33 +08:00
php_log_err ( message TSRMLS_CC ) ;
2001-02-06 05:59:17 +08:00
break ;
1999-04-17 08:37:12 +08:00
}
return SUCCESS ;
}
2000-06-25 02:46:17 +08:00
/* {{{ proto mixed call_user_func(string function_name [, mixed parmeter] [, mixed ...])
Call a user function which is the first parameter */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( call_user_func )
1999-04-17 08:37:12 +08:00
{
2001-08-30 00:00:30 +08:00
zval * * * params ;
zval * retval_ptr ;
char * name ;
int argc = ZEND_NUM_ARGS ( ) ;
2000-12-19 03:23:50 +08:00
2001-05-15 04:06:06 +08:00
if ( argc < 1 ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
2001-05-15 04:56:05 +08:00
2001-05-15 04:06:06 +08:00
params = emalloc ( sizeof ( zval * * ) * argc ) ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( zend_get_parameters_array_ex ( argc , params ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
efree ( params ) ;
RETURN_FALSE ;
}
2001-03-10 05:42:26 +08:00
if ( Z_TYPE_PP ( params [ 0 ] ) ! = IS_STRING & & Z_TYPE_PP ( params [ 0 ] ) ! = IS_ARRAY ) {
SEPARATE_ZVAL ( params [ 0 ] ) ;
convert_to_string_ex ( params [ 0 ] ) ;
}
2001-05-15 04:56:05 +08:00
if ( ! zend_is_callable ( * params [ 0 ] , 0 , & name ) ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): First argumented is expected to be a valid callback, '%s' was given " , get_active_function_name ( TSRMLS_C ) , name ) ;
2001-05-15 04:56:05 +08:00
efree ( name ) ;
2001-05-15 04:06:06 +08:00
efree ( params ) ;
RETURN_NULL ( ) ;
}
2001-10-29 17:45:47 +08:00
if ( call_user_function_ex ( EG ( function_table ) , NULL , * params [ 0 ] , & retval_ptr , argc - 1 , params + 1 , 0 , NULL TSRMLS_CC ) = = SUCCESS & & retval_ptr ) {
1999-12-20 02:58:27 +08:00
COPY_PZVAL_TO_ZVAL ( * return_value , retval_ptr ) ;
1999-04-17 08:37:12 +08:00
} else {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Unable to call %s() " , get_active_function_name ( TSRMLS_C ) , name ) ;
1999-04-17 08:37:12 +08:00
}
2001-05-15 03:02:23 +08:00
2001-05-15 04:06:06 +08:00
efree ( name ) ;
1999-04-17 08:37:12 +08:00
efree ( params ) ;
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-11-25 05:05:25 +08:00
/* {{{ proto mixed call_user_func_array(string function_name, array parameters)
Call a user function which is the first parameter with the arguments contained in array */
PHP_FUNCTION ( call_user_func_array )
{
2001-08-30 00:00:30 +08:00
zval * * * func_params , * * func , * * params ;
zval * retval_ptr ;
HashTable * func_params_ht ;
char * name ;
int count ;
int current = 0 ;
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & func , & params ) = = FAILURE ) {
2001-05-15 03:02:23 +08:00
WRONG_PARAM_COUNT ;
}
2001-08-30 00:00:30 +08:00
2001-03-10 05:42:26 +08:00
SEPARATE_ZVAL ( params ) ;
2000-12-07 22:54:52 +08:00
convert_to_array_ex ( params ) ;
2000-12-19 03:23:50 +08:00
2001-05-15 04:06:06 +08:00
if ( Z_TYPE_PP ( func ) ! = IS_STRING & & Z_TYPE_PP ( func ) ! = IS_ARRAY ) {
SEPARATE_ZVAL ( func ) ;
convert_to_string_ex ( func ) ;
2001-03-10 05:42:26 +08:00
}
2001-05-15 04:56:05 +08:00
if ( ! zend_is_callable ( * func , 0 , & name ) ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): First argumented is expected to be a valid callback, '%s' was given " , get_active_function_name ( TSRMLS_C ) , name ) ;
2001-05-15 04:56:05 +08:00
efree ( name ) ;
2001-05-15 04:06:06 +08:00
RETURN_NULL ( ) ;
}
2000-12-07 22:54:52 +08:00
2001-05-15 04:06:06 +08:00
func_params_ht = Z_ARRVAL_PP ( params ) ;
2000-12-19 03:23:50 +08:00
2001-05-15 04:06:06 +08:00
count = zend_hash_num_elements ( func_params_ht ) ;
func_params = emalloc ( sizeof ( zval * * ) * count ) ;
2000-12-19 03:23:50 +08:00
2001-05-15 04:06:06 +08:00
for ( zend_hash_internal_pointer_reset ( func_params_ht ) ;
2001-08-30 00:00:30 +08:00
zend_hash_get_current_data ( func_params_ht , ( void * * ) & func_params [ current ] ) = = SUCCESS ;
zend_hash_move_forward ( func_params_ht )
) {
2001-05-15 04:06:06 +08:00
current + + ;
}
2000-12-19 03:23:50 +08:00
2001-07-30 16:24:42 +08:00
if ( call_user_function_ex ( EG ( function_table ) , NULL , * func , & retval_ptr , count , func_params , 0 , NULL TSRMLS_CC ) = = SUCCESS & & retval_ptr ) {
2001-05-15 03:02:23 +08:00
COPY_PZVAL_TO_ZVAL ( * return_value , retval_ptr ) ;
} else {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Unable to call %s() " , get_active_function_name ( TSRMLS_C ) , name ) ;
2001-05-15 03:02:23 +08:00
}
2000-12-19 03:23:50 +08:00
2001-05-15 04:06:06 +08:00
efree ( name ) ;
efree ( func_params ) ;
2000-11-25 05:05:25 +08:00
}
/* }}} */
2002-07-08 20:52:22 +08:00
# define _CUM_DEPREC "%s(): This function is deprecated, use the call_user_func variety with the array(&$obj, \"method\") syntax instead"
2001-05-15 03:02:23 +08:00
2001-03-03 04:22:14 +08:00
/* {{{ proto mixed call_user_method(string method_name, mixed object [, mixed parameter] [, mixed ...])
Call a user method on a specific object or class */
1999-05-16 19:19:26 +08:00
PHP_FUNCTION ( call_user_method )
1999-04-17 08:37:12 +08:00
{
2001-05-15 03:02:23 +08:00
zval * * * params ;
zval * retval_ptr ;
2001-08-30 00:00:30 +08:00
int arg_count = ZEND_NUM_ARGS ( ) ;
2000-12-19 03:23:50 +08:00
2002-07-08 20:52:22 +08:00
php_error ( E_NOTICE , _CUM_DEPREC , get_active_function_name ( TSRMLS_C ) ) ;
2001-07-02 19:11:58 +08:00
2001-08-30 00:00:30 +08:00
if ( arg_count < 2 ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
2001-05-15 03:02:23 +08:00
params = ( zval * * * ) emalloc ( sizeof ( zval * * ) * arg_count ) ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( zend_get_parameters_array_ex ( arg_count , params ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
efree ( params ) ;
RETURN_FALSE ;
}
2001-02-06 01:37:47 +08:00
if ( Z_TYPE_PP ( params [ 1 ] ) ! = IS_OBJECT & & Z_TYPE_PP ( params [ 1 ] ) ! = IS_STRING ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Second argument is not an object or class name " , get_active_function_name ( TSRMLS_C ) ) ;
1999-04-17 08:37:12 +08:00
efree ( params ) ;
RETURN_FALSE ;
}
2001-08-30 00:00:30 +08:00
1999-08-06 23:25:11 +08:00
SEPARATE_ZVAL ( params [ 0 ] ) ;
convert_to_string ( * params [ 0 ] ) ;
2001-08-30 00:00:30 +08:00
2001-10-29 17:45:47 +08:00
if ( call_user_function_ex ( EG ( function_table ) , params [ 1 ] , * params [ 0 ] , & retval_ptr , arg_count - 2 , params + 2 , 0 , NULL TSRMLS_CC ) = = SUCCESS & & retval_ptr ) {
1999-12-20 02:58:27 +08:00
COPY_PZVAL_TO_ZVAL ( * return_value , retval_ptr ) ;
1999-04-17 08:37:12 +08:00
} else {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Unable to call %s() " , get_active_function_name ( TSRMLS_C ) , Z_STRVAL_PP ( params [ 0 ] ) ) ;
1999-04-17 08:37:12 +08:00
}
efree ( params ) ;
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2001-03-03 04:22:14 +08:00
/* {{{ proto mixed call_user_method_array(string method_name, mixed object, array params)
Call a user method on a specific object or class using a parameter array */
2000-12-08 22:37:49 +08:00
PHP_FUNCTION ( call_user_method_array )
{
2001-08-30 00:00:30 +08:00
zval * * method_name , * * obj , * * params , * * * method_args = NULL , * retval_ptr ;
2000-12-08 22:37:49 +08:00
HashTable * params_ar ;
2001-08-30 00:00:30 +08:00
int num_elems , element = 0 ;
2000-12-19 03:23:50 +08:00
2002-07-08 20:52:22 +08:00
php_error ( E_NOTICE , _CUM_DEPREC , get_active_function_name ( TSRMLS_C ) ) ;
2001-05-15 03:02:23 +08:00
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 3 | | zend_get_parameters_ex ( 3 , & method_name , & obj , & params ) = = FAILURE ) {
2001-05-15 03:02:23 +08:00
WRONG_PARAM_COUNT ;
}
2001-03-03 04:22:14 +08:00
if ( Z_TYPE_PP ( obj ) ! = IS_OBJECT & & Z_TYPE_PP ( obj ) ! = IS_STRING ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Second argument is not an object or class name " , get_active_function_name ( TSRMLS_C ) ) ;
2001-03-03 04:22:14 +08:00
RETURN_FALSE ;
}
SEPARATE_ZVAL ( method_name ) ;
SEPARATE_ZVAL ( params ) ;
2000-12-08 22:37:49 +08:00
convert_to_string_ex ( method_name ) ;
convert_to_array_ex ( params ) ;
2000-12-19 03:23:50 +08:00
2001-05-15 03:02:23 +08:00
params_ar = HASH_OF ( * params ) ;
num_elems = zend_hash_num_elements ( params_ar ) ;
2001-08-30 00:00:30 +08:00
method_args = ( zval * * * ) emalloc ( sizeof ( zval * * ) * num_elems ) ;
2000-12-08 22:37:49 +08:00
for ( zend_hash_internal_pointer_reset ( params_ar ) ;
2001-08-30 00:00:30 +08:00
zend_hash_get_current_data ( params_ar , ( void * * ) & ( method_args [ element ] ) ) = = SUCCESS ;
zend_hash_move_forward ( params_ar )
) {
2000-12-08 22:37:49 +08:00
element + + ;
2001-08-30 00:00:30 +08:00
}
2001-07-30 16:24:42 +08:00
if ( call_user_function_ex ( EG ( function_table ) , obj , * method_name , & retval_ptr , num_elems , method_args , 0 , NULL TSRMLS_CC ) = = SUCCESS & & retval_ptr ) {
2001-05-15 03:02:23 +08:00
COPY_PZVAL_TO_ZVAL ( * return_value , retval_ptr ) ;
} else {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Unable to call %s() " , get_active_function_name ( TSRMLS_C ) , Z_STRVAL_PP ( method_name ) ) ;
2001-05-15 03:02:23 +08:00
}
2000-12-19 03:23:50 +08:00
2000-12-08 22:37:49 +08:00
efree ( method_args ) ;
}
/* }}} */
2001-08-30 00:00:30 +08:00
2000-01-18 01:33:37 +08:00
void user_shutdown_function_dtor ( php_shutdown_function_entry * shutdown_function_entry )
1999-04-17 08:37:12 +08:00
{
1999-08-06 23:25:11 +08:00
int i ;
1999-04-17 08:37:12 +08:00
2001-08-30 00:00:30 +08:00
for ( i = 0 ; i < shutdown_function_entry - > arg_count ; i + + ) {
1999-08-06 23:25:11 +08:00
zval_ptr_dtor ( & shutdown_function_entry - > arguments [ i ] ) ;
}
efree ( shutdown_function_entry - > arguments ) ;
1999-04-17 08:37:12 +08:00
}
2000-09-02 00:10:17 +08:00
void user_tick_function_dtor ( user_tick_function_entry * tick_function_entry )
{
int i ;
for ( i = 0 ; i < tick_function_entry - > arg_count ; i + + ) {
zval_ptr_dtor ( & tick_function_entry - > arguments [ i ] ) ;
}
efree ( tick_function_entry - > arguments ) ;
}
2000-02-13 08:26:54 +08:00
2001-07-31 12:53:54 +08:00
static int user_shutdown_function_call ( php_shutdown_function_entry * shutdown_function_entry TSRMLS_DC )
2000-02-12 05:14:42 +08:00
{
zval retval ;
2001-08-30 00:00:30 +08:00
if ( call_user_function ( EG ( function_table ) , NULL ,
shutdown_function_entry - > arguments [ 0 ] ,
& retval ,
shutdown_function_entry - > arg_count - 1 ,
2001-10-29 17:45:47 +08:00
shutdown_function_entry - > arguments + 1
2001-08-30 00:00:30 +08:00
TSRMLS_CC ) = = SUCCESS ) {
2000-02-12 05:14:42 +08:00
zval_dtor ( & retval ) ;
2001-08-30 00:00:30 +08:00
2000-02-13 08:26:54 +08:00
} else {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Unable to call %s() - function does not exist " , get_active_function_name ( TSRMLS_C ) , Z_STRVAL_P ( shutdown_function_entry - > arguments [ 0 ] ) ) ;
2000-02-13 08:26:54 +08:00
}
2000-02-12 05:14:42 +08:00
return 0 ;
}
1999-04-17 08:37:12 +08:00
2001-07-31 12:53:54 +08:00
static void user_tick_function_call ( user_tick_function_entry * tick_fe TSRMLS_DC )
2000-09-02 00:10:17 +08:00
{
zval retval ;
zval * function = tick_fe - > arguments [ 0 ] ;
2002-07-16 22:14:22 +08:00
/* Prevent reentrant calls to the same user ticks function */
if ( ! tick_fe - > calling ) {
tick_fe - > calling = 1 ;
if ( call_user_function ( EG ( function_table ) , NULL ,
function ,
& retval ,
tick_fe - > arg_count - 1 ,
tick_fe - > arguments + 1
TSRMLS_CC ) = = SUCCESS ) {
zval_dtor ( & retval ) ;
2000-09-02 00:10:17 +08:00
2001-08-30 00:00:30 +08:00
} else {
2002-07-16 22:14:22 +08:00
zval * * obj , * * method ;
if ( Z_TYPE_P ( function ) = = IS_STRING ) {
php_error ( E_WARNING , " %s(): Unable to call %s() - function does not exist " , get_active_function_name ( TSRMLS_C ) , Z_STRVAL_P ( function ) ) ;
} else if ( Z_TYPE_P ( function ) = = IS_ARRAY
& & zend_hash_index_find ( Z_ARRVAL_P ( function ) , 0 , ( void * * ) & obj ) = = SUCCESS
& & zend_hash_index_find ( Z_ARRVAL_P ( function ) , 1 , ( void * * ) & method ) = = SUCCESS
& & Z_TYPE_PP ( obj ) = = IS_OBJECT
& & Z_TYPE_PP ( method ) = = IS_STRING ) {
php_error ( E_WARNING , " %s(): Unable to call %s::%s() - function does not exist " , get_active_function_name ( TSRMLS_C ) , Z_OBJCE_PP ( obj ) - > name , Z_STRVAL_PP ( method ) ) ;
} else {
php_error ( E_WARNING , " %s(): Unable to call tick function " , get_active_function_name ( TSRMLS_C ) ) ;
}
2001-08-30 00:00:30 +08:00
}
2002-07-16 22:14:22 +08:00
tick_fe - > calling = 0 ;
2000-09-02 00:10:17 +08:00
}
}
static void run_user_tick_functions ( int tick_count )
{
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-09-02 00:10:17 +08:00
2001-07-31 12:53:54 +08:00
zend_llist_apply ( BG ( user_tick_functions ) , ( llist_apply_func_t ) user_tick_function_call TSRMLS_CC ) ;
2000-09-02 00:10:17 +08:00
}
2001-08-30 00:00:30 +08:00
static int user_tick_function_compare ( user_tick_function_entry * tick_fe1 , user_tick_function_entry * tick_fe2 )
2000-09-02 00:10:17 +08:00
{
zval * func1 = tick_fe1 - > arguments [ 0 ] ;
zval * func2 = tick_fe2 - > arguments [ 0 ] ;
2001-07-30 12:58:07 +08:00
TSRMLS_FETCH ( ) ;
2000-12-19 03:23:50 +08:00
2000-09-02 00:10:17 +08:00
if ( Z_TYPE_P ( func1 ) = = IS_STRING & & Z_TYPE_P ( func2 ) = = IS_STRING ) {
return ( zend_binary_zval_strcmp ( func1 , func2 ) = = 0 ) ;
} else if ( Z_TYPE_P ( func1 ) = = IS_ARRAY & & Z_TYPE_P ( func2 ) = = IS_ARRAY ) {
zval result ;
2001-07-30 12:58:07 +08:00
zend_compare_arrays ( & result , func1 , func2 TSRMLS_CC ) ;
2000-09-02 00:10:17 +08:00
return ( Z_LVAL ( result ) = = 0 ) ;
2001-08-30 00:00:30 +08:00
} else {
2000-09-02 00:10:17 +08:00
return 0 ;
2001-08-30 00:00:30 +08:00
}
2000-09-02 00:10:17 +08:00
}
2000-02-13 08:26:54 +08:00
1999-12-05 22:16:37 +08:00
void php_call_shutdown_functions ( void )
1999-04-17 08:37:12 +08:00
{
2001-07-27 18:16:41 +08:00
TSRMLS_FETCH ( ) ;
2000-02-13 08:26:54 +08:00
2001-08-30 00:00:30 +08:00
if ( BG ( user_shutdown_function_names ) )
zend_try {
zend_hash_apply ( BG ( user_shutdown_function_names ) , ( apply_func_t ) user_shutdown_function_call TSRMLS_CC ) ;
memcpy ( & EG ( bailout ) , & orig_bailout , sizeof ( jmp_buf ) ) ;
zend_hash_destroy ( BG ( user_shutdown_function_names ) ) ;
efree ( BG ( user_shutdown_function_names ) ) ;
}
zend_end_try ( ) ;
1999-04-17 08:37:12 +08:00
}
/* {{{ proto void register_shutdown_function(string function_name)
Register a user - level function to be called on request termination */
PHP_FUNCTION ( register_shutdown_function )
{
1999-08-06 23:25:11 +08:00
php_shutdown_function_entry shutdown_function_entry ;
int i ;
2000-06-06 03:47:54 +08:00
shutdown_function_entry . arg_count = ZEND_NUM_ARGS ( ) ;
1999-08-06 23:25:11 +08:00
2001-08-30 00:00:30 +08:00
if ( shutdown_function_entry . arg_count < 1 ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
1999-08-06 23:25:11 +08:00
2001-08-30 00:00:30 +08:00
shutdown_function_entry . arguments = ( pval * * ) emalloc ( sizeof ( pval * ) * shutdown_function_entry . arg_count ) ;
if ( zend_get_parameters_array ( ht , shutdown_function_entry . arg_count , shutdown_function_entry . arguments ) = = FAILURE ) {
1999-08-06 23:25:11 +08:00
RETURN_FALSE ;
2000-06-03 12:16:46 +08:00
}
1999-11-28 08:31:02 +08:00
if ( ! BG ( user_shutdown_function_names ) ) {
2001-06-20 00:03:35 +08:00
ALLOC_HASHTABLE ( BG ( user_shutdown_function_names ) ) ;
2001-08-30 00:00:30 +08:00
zend_hash_init ( BG ( user_shutdown_function_names ) , 0 , NULL , ( void ( * ) ( void * ) ) user_shutdown_function_dtor , 0 ) ;
1999-04-17 08:37:12 +08:00
}
1999-08-06 23:25:11 +08:00
2001-08-30 00:00:30 +08:00
for ( i = 0 ; i < shutdown_function_entry . arg_count ; i + + ) {
1999-08-06 23:25:11 +08:00
shutdown_function_entry . arguments [ i ] - > refcount + + ;
}
1999-11-28 08:31:02 +08:00
zend_hash_next_index_insert ( BG ( user_shutdown_function_names ) , & shutdown_function_entry , sizeof ( php_shutdown_function_entry ) , NULL ) ;
1999-04-17 08:37:12 +08:00
}
/* }}} */
1999-04-26 22:00:49 +08:00
ZEND_API void php_get_highlight_struct ( zend_syntax_highlighter_ini * syntax_highlighter_ini )
1999-04-17 08:37:12 +08:00
{
1999-05-10 02:40:59 +08:00
syntax_highlighter_ini - > highlight_comment = INI_STR ( " highlight.comment " ) ;
syntax_highlighter_ini - > highlight_default = INI_STR ( " highlight.default " ) ;
2001-08-30 00:00:30 +08:00
syntax_highlighter_ini - > highlight_html = INI_STR ( " highlight.html " ) ;
1999-05-10 02:40:59 +08:00
syntax_highlighter_ini - > highlight_keyword = INI_STR ( " highlight.keyword " ) ;
2001-08-30 00:00:30 +08:00
syntax_highlighter_ini - > highlight_string = INI_STR ( " highlight.string " ) ;
1999-04-17 08:37:12 +08:00
}
2002-03-01 00:00:26 +08:00
/* {{{ proto bool highlight_file(string file_name [, bool return] )
1999-04-17 08:37:12 +08:00
Syntax highlight a source file */
PHP_FUNCTION ( highlight_file )
{
2002-01-25 19:27:47 +08:00
zval * filename ;
1999-04-17 08:37:12 +08:00
zend_syntax_highlighter_ini syntax_highlighter_ini ;
2002-03-01 00:00:26 +08:00
zend_bool i = 0 ;
1999-04-17 08:37:12 +08:00
2002-03-01 00:00:26 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z|b " , & filename , & i ) = = FAILURE ) {
2002-01-25 19:27:47 +08:00
return ;
}
2002-01-25 23:43:58 +08:00
convert_to_string ( filename ) ;
2002-01-25 19:27:47 +08:00
2002-05-12 02:35:59 +08:00
if ( PG ( safe_mode ) & & ( ! php_checkuid ( Z_STRVAL_P ( filename ) , NULL , CHECKUID_ALLOW_ONLY_FILE ) ) ) {
RETURN_FALSE ;
}
if ( php_check_open_basedir ( Z_STRVAL_P ( filename ) TSRMLS_CC ) ) {
RETURN_FALSE ;
}
2002-01-25 19:27:47 +08:00
if ( i ) {
2002-03-01 11:05:50 +08:00
php_start_ob_buffer ( NULL , 0 , 1 TSRMLS_CC ) ;
1999-04-17 08:37:12 +08:00
}
php_get_highlight_struct ( & syntax_highlighter_ini ) ;
2002-01-25 19:27:47 +08:00
if ( highlight_file ( Z_STRVAL_P ( filename ) , & syntax_highlighter_ini TSRMLS_CC ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
RETURN_FALSE ;
}
2002-01-25 19:27:47 +08:00
if ( i ) {
php_ob_get_buffer ( return_value TSRMLS_CC ) ;
php_end_ob_buffer ( 0 , 0 TSRMLS_CC ) ;
} else {
RETURN_TRUE ;
}
1999-04-17 08:37:12 +08:00
}
/* }}} */
2002-03-01 00:00:26 +08:00
/* {{{ proto bool highlight_string(string string [, bool return] )
2002-01-25 19:27:47 +08:00
Syntax highlight a string or optionally return it */
1999-04-17 08:37:12 +08:00
PHP_FUNCTION ( highlight_string )
{
2002-01-25 19:27:47 +08:00
zval * expr ;
1999-04-17 08:37:12 +08:00
zend_syntax_highlighter_ini syntax_highlighter_ini ;
2000-09-13 04:48:33 +08:00
char * hicompiled_string_description ;
2002-03-01 00:00:26 +08:00
zend_bool i = 0 ;
2000-12-19 03:23:50 +08:00
2002-03-01 00:00:26 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z|b " , & expr , & i ) = = FAILURE ) {
2002-01-25 19:27:47 +08:00
return ;
1999-04-17 08:37:12 +08:00
}
2002-01-25 23:43:58 +08:00
convert_to_string ( expr ) ;
2000-12-19 03:23:50 +08:00
2002-01-25 19:27:47 +08:00
if ( i ) {
2002-03-01 11:05:50 +08:00
php_start_ob_buffer ( NULL , 0 , 1 TSRMLS_CC ) ;
2002-01-25 19:27:47 +08:00
}
1999-04-17 08:37:12 +08:00
php_get_highlight_struct ( & syntax_highlighter_ini ) ;
2000-12-19 03:23:50 +08:00
2001-07-30 09:56:43 +08:00
hicompiled_string_description = zend_make_compiled_string_description ( " highlighted code " TSRMLS_CC ) ;
1999-04-17 08:37:12 +08:00
2002-01-25 19:27:47 +08:00
if ( highlight_string ( expr , & syntax_highlighter_ini , hicompiled_string_description TSRMLS_CC ) = = FAILURE ) {
2000-09-13 04:48:33 +08:00
efree ( hicompiled_string_description ) ;
1999-04-17 08:37:12 +08:00
RETURN_FALSE ;
}
2000-09-13 04:48:33 +08:00
efree ( hicompiled_string_description ) ;
2002-01-25 19:27:47 +08:00
if ( i ) {
php_ob_get_buffer ( return_value TSRMLS_CC ) ;
php_end_ob_buffer ( 0 , 0 TSRMLS_CC ) ;
} else {
RETURN_TRUE ;
}
1999-04-17 08:37:12 +08:00
}
/* }}} */
2000-03-29 09:39:04 +08:00
/* {{{ proto string ini_get(string varname)
Get a configuration option */
1999-04-17 08:37:12 +08:00
PHP_FUNCTION ( ini_get )
{
1999-10-06 20:54:45 +08:00
pval * * varname ;
2000-09-06 02:33:02 +08:00
char * str ;
1999-04-17 08:37:12 +08:00
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & varname ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( varname ) ;
2001-10-29 06:51:58 +08:00
str = php_ini_string ( Z_STRVAL_PP ( varname ) , Z_STRLEN_PP ( varname ) + 1 , 0 ) ;
1999-04-17 08:37:12 +08:00
2000-09-06 02:33:02 +08:00
if ( ! str ) {
1999-04-17 08:37:12 +08:00
RETURN_FALSE ;
}
2001-08-12 01:03:37 +08:00
RETURN_STRING ( str , 1 ) ;
1999-04-17 08:37:12 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2001-08-31 01:47:04 +08:00
static int php_ini_get_option ( zend_ini_entry * ini_entry , int num_args , va_list args , zend_hash_key * hash_key )
{
zval * ini_array = va_arg ( args , zval * ) ;
int module_number = va_arg ( args , int ) ;
zval * option ;
if ( module_number ! = 0 & & ini_entry - > module_number ! = module_number ) {
return 0 ;
}
if ( hash_key - > nKeyLength = = 0 | | hash_key - > arKey [ 0 ] ! = 0 ) {
MAKE_STD_ZVAL ( option ) ;
array_init ( option ) ;
2001-11-13 08:37:49 +08:00
if ( ini_entry - > orig_value ) {
add_assoc_stringl ( option , " global_value " , ini_entry - > orig_value , ini_entry - > orig_value_length , 1 ) ;
} else if ( ini_entry - > value ) {
2001-08-31 01:47:04 +08:00
add_assoc_stringl ( option , " global_value " , ini_entry - > value , ini_entry - > value_length , 1 ) ;
} else {
add_assoc_null ( option , " global_value " ) ;
}
2001-11-13 08:37:49 +08:00
if ( ini_entry - > value ) {
add_assoc_stringl ( option , " local_value " , ini_entry - > value , ini_entry - > value_length , 1 ) ;
2001-08-31 01:47:04 +08:00
} else {
add_assoc_null ( option , " local_value " ) ;
}
add_assoc_long ( option , " access " , ini_entry - > modifyable ) ;
add_assoc_zval_ex ( ini_array , ini_entry - > name , ini_entry - > name_length , option ) ;
}
return 0 ;
}
/* {{{ proto array ini_get_all([string extension])
Get all configuration options */
PHP_FUNCTION ( ini_get_all )
{
char * extname = NULL ;
int extname_len = 0 , extnumber = 0 ;
zend_module_entry * module ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s " , & extname , & extname_len ) = = FAILURE ) {
return ;
}
zend_ini_sort_entries ( TSRMLS_C ) ;
if ( extname ) {
2001-10-29 06:51:58 +08:00
if ( zend_hash_find ( & module_registry , extname , extname_len + 1 , ( void * * ) & module ) = = FAILURE ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Unable to find extension '%s' " , get_active_function_name ( TSRMLS_C ) , extname ) ;
2001-08-31 01:47:04 +08:00
RETURN_FALSE ;
}
extnumber = module - > module_number ;
}
array_init ( return_value ) ;
zend_hash_apply_with_arguments ( & EG ( ini_directives ) , ( apply_func_args_t ) php_ini_get_option , 2 , return_value , extnumber TSRMLS_CC ) ;
}
/* }}} */
2002-08-16 09:39:10 +08:00
static int php_ini_check_path ( char * option_name , int option_len , char * new_option_name , int new_option_len )
{
if ( option_len ! = ( new_option_len - 1 ) ) {
return 0 ;
}
return strncmp ( option_name , new_option_name , option_len ) ;
}
2000-03-29 09:39:04 +08:00
/* {{{ proto string ini_set(string varname, string newvalue)
2000-08-14 16:37:28 +08:00
Set a configuration option , returns false on error and the old value of the configuration option on success */
2000-02-26 22:53:18 +08:00
PHP_FUNCTION ( ini_set )
1999-04-17 08:37:12 +08:00
{
1999-10-06 20:54:45 +08:00
pval * * varname , * * new_value ;
1999-04-17 08:37:12 +08:00
char * old_value ;
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & varname , & new_value ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( varname ) ;
convert_to_string_ex ( new_value ) ;
1999-04-17 08:37:12 +08:00
2001-10-29 06:51:58 +08:00
old_value = php_ini_string ( Z_STRVAL_PP ( varname ) , Z_STRLEN_PP ( varname ) + 1 , 0 ) ;
2001-08-30 00:00:30 +08:00
2000-09-06 02:33:02 +08:00
/* copy to return here, because alter might free it! */
1999-04-17 08:37:12 +08:00
if ( old_value ) {
2000-09-06 02:33:02 +08:00
RETVAL_STRING ( old_value , 1 ) ;
1999-04-17 08:37:12 +08:00
} else {
2000-09-06 02:33:02 +08:00
RETVAL_FALSE ;
}
2002-08-16 18:08:32 +08:00
# define _CHECK_PATH(var, ini) php_ini_check_path(Z_STRVAL_PP(var), Z_STRLEN_PP(var), ini, sizeof(ini))
2002-08-16 09:39:10 +08:00
/* safe_mode & basedir check */
2002-08-16 18:08:32 +08:00
if ( PG ( safe_mode ) | | PG ( open_basedir ) ) {
if ( _CHECK_PATH ( varname , " error_log " ) | |
_CHECK_PATH ( varname , " java.class.path " ) | |
_CHECK_PATH ( varname , " java.home " ) | |
_CHECK_PATH ( varname , " java.library.path " ) | |
_CHECK_PATH ( varname , " session.save_path " ) | |
_CHECK_PATH ( varname , " vpopmail.directory " ) ) {
if ( PG ( safe_mode ) & & ( ! php_checkuid ( Z_STRVAL_PP ( new_value ) , NULL , CHECKUID_CHECK_FILE_AND_DIR ) ) ) {
zval_dtor ( return_value ) ;
RETURN_FALSE ;
}
2002-08-16 09:39:10 +08:00
2002-08-16 18:08:32 +08:00
if ( php_check_open_basedir ( Z_STRVAL_PP ( new_value ) TSRMLS_CC ) ) {
zval_dtor ( return_value ) ;
RETURN_FALSE ;
}
2002-08-16 09:39:10 +08:00
}
}
2001-10-29 06:51:58 +08:00
if ( zend_alter_ini_entry ( Z_STRVAL_PP ( varname ) , Z_STRLEN_PP ( varname ) + 1 , Z_STRVAL_PP ( new_value ) , Z_STRLEN_PP ( new_value ) ,
2001-08-30 00:00:30 +08:00
PHP_INI_USER , PHP_INI_STAGE_RUNTIME ) = = FAILURE ) {
2000-10-29 19:38:26 +08:00
zval_dtor ( return_value ) ;
1999-04-17 08:37:12 +08:00
RETURN_FALSE ;
}
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2000-03-29 09:39:04 +08:00
/* {{{ proto string ini_restore(string varname)
Restore the value of a configuration option specified by varname */
1999-04-17 08:37:12 +08:00
PHP_FUNCTION ( ini_restore )
{
1999-10-06 20:54:45 +08:00
pval * * varname ;
1999-04-17 08:37:12 +08:00
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & varname ) = = FAILURE ) {
1999-04-17 08:37:12 +08:00
WRONG_PARAM_COUNT ;
}
1999-10-06 20:54:45 +08:00
convert_to_string_ex ( varname ) ;
1999-04-17 08:37:12 +08:00
2001-10-29 06:51:58 +08:00
zend_restore_ini_entry ( Z_STRVAL_PP ( varname ) , Z_STRLEN_PP ( varname ) + 1 , PHP_INI_STAGE_RUNTIME ) ;
1999-04-17 08:37:12 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
2002-07-25 19:22:20 +08:00
/* {{{ proto bool print_r(mixed var [, bool return])
Prints out or returns information about the specified variable */
1999-04-17 08:37:12 +08:00
PHP_FUNCTION ( print_r )
{
2002-07-25 19:22:20 +08:00
zval * var ;
zend_bool i = 0 ;
1999-04-17 08:37:12 +08:00
2002-07-25 19:22:20 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z|b " , & var , & i ) = = FAILURE ) {
return ;
}
if ( i ) {
php_start_ob_buffer ( NULL , 0 , 1 TSRMLS_CC ) ;
1999-04-17 08:37:12 +08:00
}
2002-07-25 19:22:20 +08:00
zend_print_pval_r ( var , 0 ) ;
1999-10-06 20:54:45 +08:00
2002-07-25 19:22:20 +08:00
if ( i ) {
php_ob_get_buffer ( return_value TSRMLS_CC ) ;
php_end_ob_buffer ( 0 , 0 TSRMLS_CC ) ;
} else {
RETURN_TRUE ;
}
1999-04-17 08:37:12 +08:00
}
2000-03-29 09:39:04 +08:00
/* }}} */
1999-04-17 08:37:12 +08:00
/* This should go back to PHP */
1999-09-05 05:10:39 +08:00
/* {{{ proto int connection_aborted(void)
Returns true if client disconnected */
PHP_FUNCTION ( connection_aborted )
{
2001-08-30 00:00:30 +08:00
RETURN_LONG ( PG ( connection_status ) & PHP_CONNECTION_ABORTED ) ;
1999-09-05 05:10:39 +08:00
}
/* }}} */
/* {{{ proto int connection_status(void)
Returns the connection status bitfield */
PHP_FUNCTION ( connection_status )
{
2001-08-30 00:00:30 +08:00
RETURN_LONG ( PG ( connection_status ) ) ;
1999-09-05 05:10:39 +08:00
}
/* }}} */
2002-08-13 12:44:45 +08:00
/* {{{ proto int ignore_user_abort(bool value)
1999-09-05 05:10:39 +08:00
Set whether we want to ignore a user abort event or not */
PHP_FUNCTION ( ignore_user_abort )
{
2001-08-30 00:00:30 +08:00
pval * * arg ;
int old_setting ;
old_setting = PG ( ignore_user_abort ) ;
switch ( ZEND_NUM_ARGS ( ) ) {
case 0 :
break ;
case 1 :
if ( zend_get_parameters_ex ( 1 , & arg ) = = FAILURE ) {
RETURN_FALSE ;
}
convert_to_boolean_ex ( arg ) ;
PG ( ignore_user_abort ) = ( zend_bool ) Z_LVAL_PP ( arg ) ;
break ;
default :
WRONG_PARAM_COUNT ;
break ;
}
RETURN_LONG ( old_setting ) ;
1999-09-05 05:10:39 +08:00
}
/* }}} */
2001-08-30 00:00:30 +08:00
# if HAVE_GETSERVBYNAME
1999-11-01 09:07:51 +08:00
/* {{{ proto int getservbyname(string service, string protocol)
2002-01-05 15:54:49 +08:00
Returns port associated with service . Protocol must be " tcp " or " udp " */
1999-11-01 09:07:51 +08:00
PHP_FUNCTION ( getservbyname )
{
2001-08-12 01:03:37 +08:00
pval * * name , * * proto ;
1999-11-01 09:07:51 +08:00
struct servent * serv ;
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & name , & proto ) = = FAILURE ) {
1999-11-01 09:07:51 +08:00
WRONG_PARAM_COUNT ;
}
convert_to_string_ex ( name ) ;
convert_to_string_ex ( proto ) ;
2001-08-12 01:03:37 +08:00
serv = getservbyname ( Z_STRVAL_PP ( name ) , Z_STRVAL_PP ( proto ) ) ;
1999-11-01 09:07:51 +08:00
2001-08-30 00:00:30 +08:00
if ( serv = = NULL ) {
1999-11-01 09:07:51 +08:00
RETURN_FALSE ;
2001-08-30 00:00:30 +08:00
}
1999-11-01 09:07:51 +08:00
RETURN_LONG ( ntohs ( serv - > s_port ) ) ;
}
/* }}} */
2001-08-30 00:00:30 +08:00
# endif
1999-11-01 09:07:51 +08:00
2001-08-30 00:00:30 +08:00
# if HAVE_GETSERVBYPORT
1999-11-01 09:07:51 +08:00
/* {{{ proto string getservbyport(int port, string protocol)
2002-01-05 15:54:49 +08:00
Returns service name associated with port . Protocol must be " tcp " or " udp " */
1999-11-01 09:07:51 +08:00
PHP_FUNCTION ( getservbyport )
{
2001-08-12 01:03:37 +08:00
pval * * port , * * proto ;
1999-11-01 09:07:51 +08:00
struct servent * serv ;
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & port , & proto ) = = FAILURE ) {
1999-11-01 09:07:51 +08:00
WRONG_PARAM_COUNT ;
}
convert_to_long_ex ( port ) ;
convert_to_string_ex ( proto ) ;
2001-08-12 01:03:37 +08:00
serv = getservbyport ( htons ( ( unsigned short ) Z_LVAL_PP ( port ) ) , Z_STRVAL_PP ( proto ) ) ;
1999-11-01 09:07:51 +08:00
2001-08-30 00:00:30 +08:00
if ( serv = = NULL ) {
1999-11-01 09:07:51 +08:00
RETURN_FALSE ;
2001-08-30 00:00:30 +08:00
}
2001-08-12 01:03:37 +08:00
RETURN_STRING ( serv - > s_name , 1 ) ;
1999-11-01 09:07:51 +08:00
}
/* }}} */
2001-08-30 00:00:30 +08:00
# endif
1999-11-01 09:07:51 +08:00
2001-08-30 00:00:30 +08:00
# if HAVE_GETPROTOBYNAME
1999-11-02 11:47:09 +08:00
/* {{{ proto int getprotobyname(string name)
2000-02-24 15:46:56 +08:00
Returns protocol number associated with name as per / etc / protocols */
1999-11-02 11:47:09 +08:00
PHP_FUNCTION ( getprotobyname )
{
pval * * name ;
struct protoent * ent ;
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1
| | zend_get_parameters_ex ( 1 , & name ) = = FAILURE ) {
1999-11-02 11:47:09 +08:00
WRONG_PARAM_COUNT ;
}
convert_to_string_ex ( name ) ;
2000-12-19 03:23:50 +08:00
2000-11-27 21:31:21 +08:00
ent = getprotobyname ( Z_STRVAL_PP ( name ) ) ;
1999-11-02 11:47:09 +08:00
2001-08-30 00:00:30 +08:00
if ( ent = = NULL ) {
2000-11-27 21:31:21 +08:00
Z_LVAL_P ( return_value ) = - 1 ;
Z_TYPE_P ( return_value ) = IS_LONG ;
1999-11-02 11:47:09 +08:00
return ;
}
RETURN_LONG ( ent - > p_proto ) ;
}
/* }}} */
2001-08-30 00:00:30 +08:00
# endif
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
# if HAVE_GETPROTOBYNUMBER
1999-11-02 11:47:09 +08:00
/* {{{ proto string getprotobynumber(int proto)
2000-02-24 15:46:56 +08:00
Returns protocol name associated with protocol number proto */
1999-11-02 11:47:09 +08:00
PHP_FUNCTION ( getprotobynumber )
{
pval * * proto ;
struct protoent * ent ;
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & proto ) = = FAILURE ) {
1999-11-02 11:47:09 +08:00
WRONG_PARAM_COUNT ;
}
convert_to_long_ex ( proto ) ;
2000-11-27 21:31:21 +08:00
ent = getprotobynumber ( Z_LVAL_PP ( proto ) ) ;
2000-12-19 03:23:50 +08:00
2001-08-30 00:00:30 +08:00
if ( ent = = NULL ) {
1999-11-02 11:47:09 +08:00
RETURN_FALSE ;
2001-08-30 00:00:30 +08:00
}
1999-11-02 11:47:09 +08:00
2001-08-12 01:03:37 +08:00
RETURN_STRING ( ent - > p_name , 1 ) ;
1999-11-02 11:47:09 +08:00
}
/* }}} */
2001-08-30 00:00:30 +08:00
# endif
1999-11-02 11:47:09 +08:00
2001-12-07 17:34:50 +08:00
/* {{{ proto bool register_tick_function(string function_name [, mixed arg [, mixed ... ]])
2000-09-02 00:10:17 +08:00
Registers a tick callback function */
PHP_FUNCTION ( register_tick_function )
{
user_tick_function_entry tick_fe ;
int i ;
2002-07-16 22:14:22 +08:00
tick_fe . calling = 0 ;
2000-09-02 00:10:17 +08:00
tick_fe . arg_count = ZEND_NUM_ARGS ( ) ;
if ( tick_fe . arg_count < 1 ) {
WRONG_PARAM_COUNT ;
}
2001-08-30 00:00:30 +08:00
tick_fe . arguments = ( zval * * ) emalloc ( sizeof ( zval * ) * tick_fe . arg_count ) ;
2000-09-02 00:10:17 +08:00
if ( zend_get_parameters_array ( ht , tick_fe . arg_count , tick_fe . arguments ) = = FAILURE ) {
RETURN_FALSE ;
}
2000-12-19 03:23:50 +08:00
2000-09-02 00:10:17 +08:00
if ( Z_TYPE_P ( tick_fe . arguments [ 0 ] ) ! = IS_ARRAY )
convert_to_string_ex ( & tick_fe . arguments [ 0 ] ) ;
2000-12-19 03:23:50 +08:00
2000-09-02 00:10:17 +08:00
if ( ! BG ( user_tick_functions ) ) {
2001-08-30 00:00:30 +08:00
BG ( user_tick_functions ) = ( zend_llist * ) emalloc ( sizeof ( zend_llist ) ) ;
zend_llist_init ( BG ( user_tick_functions ) ,
sizeof ( user_tick_function_entry ) ,
2002-02-21 11:32:42 +08:00
( llist_dtor_func_t ) user_tick_function_dtor , 0 ) ;
2000-09-02 00:10:17 +08:00
php_add_tick_function ( run_user_tick_functions ) ;
}
for ( i = 0 ; i < tick_fe . arg_count ; i + + ) {
tick_fe . arguments [ i ] - > refcount + + ;
}
zend_llist_add_element ( BG ( user_tick_functions ) , & tick_fe ) ;
RETURN_TRUE ;
}
/* }}} */
/* {{{ proto void unregister_tick_function(string function_name)
Unregisters a tick callback function */
PHP_FUNCTION ( unregister_tick_function )
{
zval * * function ;
user_tick_function_entry tick_fe ;
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( ZEND_NUM_ARGS ( ) , & function ) ) {
WRONG_PARAM_COUNT ;
}
2001-08-30 00:00:30 +08:00
if ( Z_TYPE_PP ( function ) ! = IS_ARRAY ) {
2000-09-02 00:10:17 +08:00
convert_to_string_ex ( function ) ;
2001-08-30 00:00:30 +08:00
}
tick_fe . arguments = ( zval * * ) emalloc ( sizeof ( zval * ) ) ;
2000-09-02 00:10:17 +08:00
tick_fe . arguments [ 0 ] = * function ;
tick_fe . arg_count = 1 ;
2001-08-30 00:00:30 +08:00
zend_llist_del_element ( BG ( user_tick_functions ) , & tick_fe , ( int ( * ) ( void * , void * ) ) user_tick_function_compare ) ;
2000-09-02 00:10:17 +08:00
efree ( tick_fe . arguments ) ;
}
/* }}} */
1999-12-17 07:47:10 +08:00
2001-07-02 19:11:58 +08:00
/* {{{ proto bool is_uploaded_file(string path)
2001-12-07 17:34:50 +08:00
Check if file was created by rfc1867 upload */
2000-09-09 05:58:28 +08:00
PHP_FUNCTION ( is_uploaded_file )
2000-09-09 05:56:47 +08:00
{
zval * * path ;
if ( ! SG ( rfc1867_uploaded_files ) ) {
RETURN_FALSE ;
}
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 1 | | zend_get_parameters_ex ( 1 , & path ) ! = SUCCESS ) {
2000-09-09 05:56:47 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2001-08-30 00:00:30 +08:00
2000-09-09 05:56:47 +08:00
convert_to_string_ex ( path ) ;
2001-10-29 06:51:58 +08:00
if ( zend_hash_exists ( SG ( rfc1867_uploaded_files ) , Z_STRVAL_PP ( path ) , Z_STRLEN_PP ( path ) + 1 ) ) {
2000-09-09 05:56:47 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
2000-10-11 19:25:13 +08:00
/* }}} */
2000-09-09 05:56:47 +08:00
2001-07-02 19:11:58 +08:00
/* {{{ proto bool move_uploaded_file(string path, string new_path)
2001-12-07 17:34:50 +08:00
Move a file if and only if it was created by an upload */
2000-09-09 06:31:21 +08:00
PHP_FUNCTION ( move_uploaded_file )
{
zval * * path , * * new_path ;
2001-08-30 00:00:30 +08:00
zend_bool successful = 0 ;
2000-09-09 06:31:21 +08:00
if ( ! SG ( rfc1867_uploaded_files ) ) {
RETURN_FALSE ;
}
2001-08-30 00:00:30 +08:00
if ( ZEND_NUM_ARGS ( ) ! = 2 | | zend_get_parameters_ex ( 2 , & path , & new_path ) ! = SUCCESS ) {
2000-09-09 06:31:21 +08:00
ZEND_WRONG_PARAM_COUNT ( ) ;
}
convert_to_string_ex ( path ) ;
convert_to_string_ex ( new_path ) ;
2001-10-29 06:51:58 +08:00
if ( ! zend_hash_exists ( SG ( rfc1867_uploaded_files ) , Z_STRVAL_PP ( path ) , Z_STRLEN_PP ( path ) + 1 ) ) {
2000-09-09 06:31:21 +08:00
RETURN_FALSE ;
}
2001-04-18 01:06:06 +08:00
2001-08-30 00:00:30 +08:00
if ( PG ( safe_mode ) & & ( ! php_checkuid ( Z_STRVAL_PP ( new_path ) , NULL , CHECKUID_CHECK_FILE_AND_DIR ) ) ) {
RETURN_FALSE ;
}
2001-04-18 01:06:06 +08:00
2002-03-18 04:56:20 +08:00
if ( php_check_open_basedir ( Z_STRVAL_PP ( new_path ) TSRMLS_CC ) ) {
RETURN_FALSE ;
}
2001-04-30 20:45:02 +08:00
VCWD_UNLINK ( Z_STRVAL_PP ( new_path ) ) ;
2001-08-30 00:00:30 +08:00
if ( rename ( Z_STRVAL_PP ( path ) , Z_STRVAL_PP ( new_path ) ) = = 0 ) {
successful = 1 ;
} else
if ( php_copy_file ( Z_STRVAL_PP ( path ) , Z_STRVAL_PP ( new_path ) TSRMLS_CC ) = = SUCCESS ) {
2001-04-30 20:45:02 +08:00
VCWD_UNLINK ( Z_STRVAL_PP ( path ) ) ;
2001-08-30 00:00:30 +08:00
successful = 1 ;
2000-09-09 06:31:21 +08:00
}
2000-09-09 19:41:14 +08:00
if ( successful ) {
2001-10-29 06:51:58 +08:00
zend_hash_del ( SG ( rfc1867_uploaded_files ) , Z_STRVAL_PP ( path ) , Z_STRLEN_PP ( path ) + 1 ) ;
2000-09-09 19:41:14 +08:00
} else {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Unable to move '%s' to '%s' " , get_active_function_name ( TSRMLS_C ) , Z_STRVAL_PP ( path ) , Z_STRVAL_PP ( new_path ) ) ;
2000-09-09 06:31:21 +08:00
}
2000-09-09 19:41:14 +08:00
RETURN_BOOL ( successful ) ;
2000-09-09 06:31:21 +08:00
}
2000-10-11 19:25:13 +08:00
/* }}} */
2000-09-09 06:31:21 +08:00
2000-10-30 06:42:01 +08:00
static void php_simple_ini_parser_cb ( zval * arg1 , zval * arg2 , int callback_type , zval * arr )
{
zval * element ;
switch ( callback_type ) {
2001-08-30 00:00:30 +08:00
2000-10-30 06:42:01 +08:00
case ZEND_INI_PARSER_ENTRY :
2001-11-11 20:41:14 +08:00
if ( ! arg2 ) {
/* bare string - nothing to do */
break ;
}
2000-10-30 06:42:01 +08:00
ALLOC_ZVAL ( element ) ;
* element = * arg2 ;
zval_copy_ctor ( element ) ;
INIT_PZVAL ( element ) ;
2001-10-29 06:51:58 +08:00
zend_hash_update ( Z_ARRVAL_P ( arr ) , Z_STRVAL_P ( arg1 ) , Z_STRLEN_P ( arg1 ) + 1 , & element , sizeof ( zval * ) , NULL ) ;
2000-10-30 06:42:01 +08:00
break ;
2001-08-30 00:00:30 +08:00
2000-10-30 06:42:01 +08:00
case ZEND_INI_PARSER_SECTION :
break ;
}
}
2000-10-30 07:34:33 +08:00
static void php_ini_parser_cb_with_sections ( zval * arg1 , zval * arg2 , int callback_type , zval * arr )
{
zval * element ;
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-10-30 07:34:33 +08:00
switch ( callback_type ) {
2001-08-30 00:00:30 +08:00
case ZEND_INI_PARSER_ENTRY :
{
zval * active_arr ;
2001-11-11 20:41:14 +08:00
if ( ! arg2 ) {
/* bare string - nothing to do */
break ;
}
2001-08-30 00:00:30 +08:00
if ( BG ( active_ini_file_section ) ) {
active_arr = BG ( active_ini_file_section ) ;
} else {
active_arr = arr ;
2000-10-30 07:34:33 +08:00
}
2001-08-30 00:00:30 +08:00
ALLOC_ZVAL ( element ) ;
* element = * arg2 ;
zval_copy_ctor ( element ) ;
INIT_PZVAL ( element ) ;
zend_hash_update ( Z_ARRVAL_P ( active_arr ) , Z_STRVAL_P ( arg1 ) ,
2001-10-29 06:51:58 +08:00
Z_STRLEN_P ( arg1 ) + 1 , & element ,
2001-08-30 00:00:30 +08:00
sizeof ( zval * ) , NULL ) ;
}
break ;
2000-10-30 07:34:33 +08:00
case ZEND_INI_PARSER_SECTION :
MAKE_STD_ZVAL ( BG ( active_ini_file_section ) ) ;
array_init ( BG ( active_ini_file_section ) ) ;
2001-08-30 00:00:30 +08:00
zend_hash_update ( Z_ARRVAL_P ( arr ) ,
Z_STRVAL_P ( arg1 ) ,
2001-10-29 06:51:58 +08:00
Z_STRLEN_P ( arg1 ) + 1 ,
2001-08-30 00:00:30 +08:00
& BG ( active_ini_file_section ) ,
sizeof ( zval * ) , NULL ) ;
2000-10-30 07:34:33 +08:00
break ;
}
}
2002-08-13 12:44:45 +08:00
/* {{{ proto array parse_ini_file(string filename [, bool process_sections])
2000-10-30 06:42:01 +08:00
Parse configuration file */
PHP_FUNCTION ( parse_ini_file )
{
2000-10-30 07:34:33 +08:00
zval * * filename , * * process_sections ;
2000-10-30 06:42:01 +08:00
zend_file_handle fh ;
2000-10-30 07:34:33 +08:00
zend_ini_parser_cb_t ini_parser_cb ;
2000-10-30 06:42:01 +08:00
2000-10-30 07:34:33 +08:00
switch ( ARG_COUNT ( ht ) ) {
2001-08-30 00:00:30 +08:00
2000-10-30 07:34:33 +08:00
case 1 :
2001-08-30 00:00:30 +08:00
if ( zend_get_parameters_ex ( 1 , & filename ) = = FAILURE ) {
2000-10-30 07:34:33 +08:00
RETURN_FALSE ;
}
ini_parser_cb = ( zend_ini_parser_cb_t ) php_simple_ini_parser_cb ;
break ;
2001-08-30 00:00:30 +08:00
2000-10-30 07:34:33 +08:00
case 2 :
2001-08-30 00:00:30 +08:00
if ( zend_get_parameters_ex ( 2 , & filename , & process_sections ) = = FAILURE ) {
2000-10-30 07:34:33 +08:00
RETURN_FALSE ;
}
2001-08-30 00:00:30 +08:00
2000-10-30 07:34:33 +08:00
convert_to_boolean_ex ( process_sections ) ;
2001-08-30 00:00:30 +08:00
2000-10-30 07:34:33 +08:00
if ( Z_BVAL_PP ( process_sections ) ) {
2001-07-28 19:36:37 +08:00
TSRMLS_FETCH ( ) ;
2000-10-30 07:34:33 +08:00
BG ( active_ini_file_section ) = NULL ;
ini_parser_cb = ( zend_ini_parser_cb_t ) php_ini_parser_cb_with_sections ;
} else {
ini_parser_cb = ( zend_ini_parser_cb_t ) php_simple_ini_parser_cb ;
}
break ;
2001-08-30 00:00:30 +08:00
2000-10-30 07:34:33 +08:00
default :
ZEND_WRONG_PARAM_COUNT ( ) ;
break ;
2000-10-30 06:42:01 +08:00
}
2000-10-30 07:34:33 +08:00
2000-10-30 06:42:01 +08:00
convert_to_string_ex ( filename ) ;
2002-05-12 03:19:49 +08:00
if ( PG ( safe_mode ) & & ( ! php_checkuid ( Z_STRVAL_PP ( filename ) , NULL , CHECKUID_ALLOW_ONLY_FILE ) ) ) {
RETURN_FALSE ;
}
if ( php_check_open_basedir ( Z_STRVAL_PP ( filename ) TSRMLS_CC ) ) {
RETURN_FALSE ;
}
2001-04-30 20:45:02 +08:00
fh . handle . fp = VCWD_FOPEN ( Z_STRVAL_PP ( filename ) , " r " ) ;
2000-10-30 06:42:01 +08:00
if ( ! fh . handle . fp ) {
2002-07-08 20:52:22 +08:00
php_error ( E_WARNING , " %s(): Cannot open '%s' for reading " , get_active_function_name ( TSRMLS_C ) , Z_STRVAL_PP ( filename ) ) ;
2000-10-30 06:42:01 +08:00
return ;
}
2000-11-27 21:31:21 +08:00
Z_TYPE ( fh ) = ZEND_HANDLE_FP ;
2000-10-31 07:39:14 +08:00
fh . filename = Z_STRVAL_PP ( filename ) ;
2000-10-30 06:42:01 +08:00
array_init ( return_value ) ;
2000-10-31 07:39:14 +08:00
zend_parse_ini_file ( & fh , 0 , ini_parser_cb , return_value ) ;
2000-10-30 06:42:01 +08:00
}
/* }}} */
2001-08-09 04:05:37 +08:00
static int copy_request_variable ( void * pDest , int num_args , va_list args , zend_hash_key * hash_key )
{
char * prefix , * new_key ;
uint prefix_len , new_key_len ;
zval * * var = ( zval * * ) pDest ;
TSRMLS_FETCH ( ) ;
2001-08-30 00:00:30 +08:00
if ( num_args ! = 2 ) {
2001-08-09 04:05:37 +08:00
return 0 ;
}
prefix = va_arg ( args , char * ) ;
prefix_len = va_arg ( args , uint ) ;
new_key_len = prefix_len + hash_key - > nKeyLength ;
new_key = ( char * ) emalloc ( new_key_len ) ;
memcpy ( new_key , prefix , prefix_len ) ;
2001-10-29 06:51:58 +08:00
memcpy ( new_key + prefix_len , hash_key - > arKey , hash_key - > nKeyLength ) ;
2001-08-09 04:05:37 +08:00
ZEND_SET_SYMBOL_WITH_LENGTH ( & EG ( symbol_table ) , new_key , new_key_len , * var , 0 , 1 ) ;
efree ( new_key ) ;
return 0 ;
}
2001-10-17 01:08:11 +08:00
/* {{{ proto bool import_request_variables(string types [, string prefix])
2001-08-09 04:05:37 +08:00
Import GET / POST / Cookie variables into the global scope */
PHP_FUNCTION ( import_request_variables )
{
zval * * z_types , * * z_prefix ;
char * types , * prefix ;
uint prefix_len ;
char * p ;
switch ( ZEND_NUM_ARGS ( ) ) {
2001-08-30 00:00:30 +08:00
2001-08-09 04:05:37 +08:00
case 1 :
2001-08-30 00:00:30 +08:00
if ( zend_get_parameters_ex ( 1 , & z_types ) = = FAILURE ) {
2001-08-09 04:05:37 +08:00
RETURN_FALSE ;
}
prefix = " " ;
prefix_len = 0 ;
break ;
2001-08-30 00:00:30 +08:00
2001-08-09 04:05:37 +08:00
case 2 :
2001-08-30 00:00:30 +08:00
if ( zend_get_parameters_ex ( 2 , & z_types , & z_prefix ) = = FAILURE ) {
2001-08-09 04:05:37 +08:00
RETURN_FALSE ;
}
convert_to_string_ex ( z_prefix ) ;
prefix = Z_STRVAL_PP ( z_prefix ) ;
prefix_len = Z_STRLEN_PP ( z_prefix ) ;
break ;
2001-08-30 00:00:30 +08:00
2001-08-09 04:05:37 +08:00
default :
ZEND_WRONG_PARAM_COUNT ( ) ;
}
2001-08-30 00:00:30 +08:00
if ( prefix_len = = 0 ) {
2001-08-09 04:05:37 +08:00
zend_error ( E_NOTICE , " No prefix specified in %s() - possible security hazard " , get_active_function_name ( TSRMLS_C ) ) ;
}
convert_to_string_ex ( z_types ) ;
types = Z_STRVAL_PP ( z_types ) ;
2001-08-30 00:00:30 +08:00
for ( p = types ; p & & * p ; p + + ) {
2001-08-09 04:05:37 +08:00
switch ( * p ) {
2001-08-30 00:00:30 +08:00
2001-08-09 04:05:37 +08:00
case ' g ' :
case ' G ' :
zend_hash_apply_with_arguments ( Z_ARRVAL_P ( PG ( http_globals ) [ TRACK_VARS_GET ] ) , ( apply_func_args_t ) copy_request_variable , 2 , prefix , prefix_len ) ;
break ;
2001-08-30 00:00:30 +08:00
2001-08-09 04:05:37 +08:00
case ' p ' :
case ' P ' :
zend_hash_apply_with_arguments ( Z_ARRVAL_P ( PG ( http_globals ) [ TRACK_VARS_POST ] ) , ( apply_func_args_t ) copy_request_variable , 2 , prefix , prefix_len ) ;
zend_hash_apply_with_arguments ( Z_ARRVAL_P ( PG ( http_globals ) [ TRACK_VARS_FILES ] ) , ( apply_func_args_t ) copy_request_variable , 2 , prefix , prefix_len ) ;
break ;
2001-08-30 00:00:30 +08:00
2001-08-09 04:05:37 +08:00
case ' c ' :
case ' C ' :
zend_hash_apply_with_arguments ( Z_ARRVAL_P ( PG ( http_globals ) [ TRACK_VARS_COOKIE ] ) , ( apply_func_args_t ) copy_request_variable , 2 , prefix , prefix_len ) ;
break ;
}
}
}
2001-08-30 00:00:30 +08:00
/* }}} */
2001-08-09 04:05:37 +08:00
1999-04-17 08:37:12 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-12-07 21:20:18 +08:00
* vim600 : fdm = marker
* vim : noet sw = 4 ts = 4
2000-12-19 03:23:50 +08:00
*/
2001-08-30 00:00:30 +08:00