From c3c0f531a2c1436a8061f393ab0f328f63bbb203 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sat, 13 Dec 2014 03:35:51 +0000 Subject: [PATCH 01/29] Scalar type hints with ZPP casting rules --- Zend/tests/is_a.phpt | 8 +- Zend/tests/typehints/scalar_aliases.phpt | 20 ++ Zend/tests/typehints/scalar_basic.phpt | 241 ++++++++++++++++++ Zend/tests/typehints/scalar_none.phpt | 55 ++++ Zend/tests/typehints/scalar_null.phpt | 51 ++++ Zend/zend_API.c | 1 + Zend/zend_execute.c | 71 +++++- Zend/zend_language_parser.y | 44 +++- Zend/zend_language_scanner.l | 28 +- .../tests/ReflectionMethod_basic1.phpt | 6 +- .../tests/ReflectionMethod_basic2.phpt | 10 +- .../tests/ReflectionMethod_basic3.phpt | 8 +- .../tests/ReflectionMethod_basic4.phpt | 6 +- .../ReflectionMethod_getModifiers_basic.phpt | 4 +- ext/standard/tests/array/krsort_object.phpt | 74 +++--- ext/standard/tests/array/ksort_object.phpt | 74 +++--- ext/standard/tests/strings/lcfirst.phpt | Bin 6878 -> 6906 bytes ext/standard/tests/strings/strlen.phpt | Bin 7091 -> 7099 bytes ext/standard/tests/strings/strpos.phpt | Bin 9991 -> 9999 bytes ext/standard/tests/strings/strstr.phpt | Bin 10531 -> 10539 bytes ext/standard/tests/strings/ucfirst.phpt | Bin 6106 -> 6130 bytes 21 files changed, 578 insertions(+), 123 deletions(-) create mode 100644 Zend/tests/typehints/scalar_aliases.phpt create mode 100644 Zend/tests/typehints/scalar_basic.phpt create mode 100644 Zend/tests/typehints/scalar_none.phpt create mode 100644 Zend/tests/typehints/scalar_null.phpt diff --git a/Zend/tests/is_a.phpt b/Zend/tests/is_a.phpt index 0a01eb756e119..f4161f2390996 100644 --- a/Zend/tests/is_a.phpt +++ b/Zend/tests/is_a.phpt @@ -12,21 +12,21 @@ function __autoload($name) { class BASE { } -interface INT { +interface I { } -class A extends BASE implements INT { +class A extends BASE implements I { } $a = new A; var_dump(is_a($a, "B1")); var_dump(is_a($a, "A")); var_dump(is_a($a, "BASE")); -var_dump(is_a($a, "INT")); +var_dump(is_a($a, "I")); var_dump(is_subclass_of($a, "B2")); var_dump(is_subclass_of($a, "A")); var_dump(is_subclass_of($a, "BASE")); -var_dump(is_subclass_of($a, "INT")); +var_dump(is_subclass_of($a, "I")); var_dump(is_subclass_of("X1", "X2")); ?> diff --git a/Zend/tests/typehints/scalar_aliases.phpt b/Zend/tests/typehints/scalar_aliases.phpt new file mode 100644 index 0000000000000..500e5da399bf4 --- /dev/null +++ b/Zend/tests/typehints/scalar_aliases.phpt @@ -0,0 +1,20 @@ +--TEST-- +Scalar type hint aliases +--FILE-- + 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + var_dump($function($value)); + } +} +--EXPECTF-- + +Testing 'int' typehint: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d +string(1) "a" +*** Trying string(0) "" +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d +string(0) "" +*** Trying int(%d) +int(%d) +*** Trying float(NAN) +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined on line %d +float(NAN) +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d and defined on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined on line %d +object(Stringable)#%s (0) { +} +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d and defined on line %d +resource(%d) of type (stream) + +Testing 'float' typehint: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d +string(1) "a" +*** Trying string(0) "" +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d +string(0) "" +*** Trying int(%d) +float(%s) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d and defined on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined on line %d +object(Stringable)#%s (0) { +} +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d and defined on line %d +resource(%d) of type (stream) + +Testing 'string' typehint: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(%d) +string(%d) "%d" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d and defined on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +string(6) "foobar" +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d and defined on line %d +resource(%d) of type (stream) + +Testing 'bool' typehint: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(%d) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d and defined on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined on line %d +object(Stringable)#%s (0) { +} +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d and defined on line %d +resource(%d) of type (stream) diff --git a/Zend/tests/typehints/scalar_none.phpt b/Zend/tests/typehints/scalar_none.phpt new file mode 100644 index 0000000000000..0b7f7ec9a202f --- /dev/null +++ b/Zend/tests/typehints/scalar_none.phpt @@ -0,0 +1,55 @@ +--TEST-- +Scalar type hint missing parameters +--FILE-- + 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; }, + 'int nullable' => function (int $i = NULL) { return $i; }, + 'float nullable' => function (float $f = NULL) { return $f; }, + 'string nullable' => function (string $s = NULL) { return $s; }, + 'bool nullable' => function (bool $b = NULL) { return $b; } +]; + +foreach ($functions as $type => $function) { + echo "Testing $type:", PHP_EOL; + var_dump($function()); +} +--EXPECTF-- +Testing int: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d and defined on line %d +E_NOTICE: Undefined variable: i on line %d +NULL +Testing float: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d and defined on line %d +E_NOTICE: Undefined variable: f on line %d +NULL +Testing string: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d and defined on line %d +E_NOTICE: Undefined variable: s on line %d +NULL +Testing bool: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d and defined on line %d +E_NOTICE: Undefined variable: b on line %d +NULL +Testing int nullable: +NULL +Testing float nullable: +NULL +Testing string nullable: +NULL +Testing bool nullable: +NULL diff --git a/Zend/tests/typehints/scalar_null.phpt b/Zend/tests/typehints/scalar_null.phpt new file mode 100644 index 0000000000000..c5aa1ce986c36 --- /dev/null +++ b/Zend/tests/typehints/scalar_null.phpt @@ -0,0 +1,51 @@ +--TEST-- +Scalar type hint nullability +--FILE-- + 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; }, + 'int nullable' => function (int $i = NULL) { return $i; }, + 'float nullable' => function (float $f = NULL) { return $f; }, + 'string nullable' => function (string $s = NULL) { return $s; }, + 'bool nullable' => function (bool $b = NULL) { return $b; } +]; + +foreach ($functions as $type => $function) { + echo "Testing $type:", PHP_EOL; + var_dump($function(NULL)); +} +--EXPECTF-- +Testing int: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined on line %d +NULL +Testing float: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined on line %d +NULL +Testing string: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined on line %d +NULL +Testing bool: +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined on line %d +NULL +Testing int nullable: +NULL +Testing float nullable: +NULL +Testing string nullable: +NULL +Testing bool nullable: +NULL diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 69327778e3dc6..9fcd9cb434806 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -164,6 +164,7 @@ ZEND_API char *zend_get_type_by_const(int type) /* {{{ */ switch(type) { case IS_FALSE: case IS_TRUE: + case _IS_BOOL: return "boolean"; case IS_LONG: return "integer"; diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 62064dcd5f587..c10506db33303 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -692,10 +692,72 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, if (!zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(arg) != IS_NULL || !(cur_arg_info->allow_null || (default_value && is_null_constant(default_value))))) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "", arg); } -#if ZEND_DEBUG } else { - zend_error(E_ERROR, "Unknown typehint"); + ZVAL_DEREF(arg); + + if (Z_TYPE_P(arg) == IS_NULL) { + if (!(cur_arg_info->allow_null || (default_value && is_null_constant(default_value)))) { +failure: + zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), zend_zval_type_name(arg), "", arg); + } + return; + } + + switch (cur_arg_info->type_hint) { + case IS_LONG: { + zend_long dest; + if (_z_param_long(arg, &dest, NULL, 0, 0)) { + if (Z_TYPE_P(arg) != IS_LONG) { + zval_dtor(arg); + } + ZVAL_LONG(arg, dest); + } else { + goto failure; + } + } + break; + case IS_DOUBLE: { + double dest; + if (_z_param_double(arg, &dest, NULL, 0)) { + if (Z_TYPE_P(arg) != IS_DOUBLE) { + zval_dtor(arg); + } + ZVAL_DOUBLE(arg, dest); + } else { + goto failure; + } + } + break; + case IS_STRING: { + zend_string *dest; + if (_z_param_str(arg, &dest, 0)) { + if (Z_TYPE_P(arg) != IS_STRING) { + zval_dtor(arg); + } + ZVAL_STR(arg, dest); + } else { + goto failure; + } + } + break; + case _IS_BOOL: { + zend_bool dest; + if (_z_param_bool(arg, &dest, NULL, 0)) { + if (Z_TYPE_P(arg) != IS_TRUE && Z_TYPE_P(arg) != IS_FALSE) { + zval_dtor(arg); + } + ZVAL_BOOL(arg, dest); + } else { + goto failure; + } + } + break; + default: +#if ZEND_DEBUG + zend_error(E_ERROR, "Unknown typehint"); #endif + break; + } } } } @@ -725,6 +787,11 @@ static inline int zend_verify_missing_arg_type(zend_function *zf, uint32_t arg_n zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", "none", "", NULL); } else if (cur_arg_info->type_hint == IS_CALLABLE) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", "none", "", NULL); + } else if (cur_arg_info->type_hint == IS_LONG + || cur_arg_info->type_hint == IS_DOUBLE + || cur_arg_info->type_hint == IS_STRING + || cur_arg_info->type_hint == _IS_BOOL) { + zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), "none", "", NULL); #if ZEND_DEBUG } else { zend_error(E_ERROR, "Unknown typehint"); diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 009d7bae0b33f..bfb7787677848 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -82,7 +82,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %left '*' '/' '%' %right '!' %nonassoc T_INSTANCEOF -%right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@' +%right '~' T_INC T_DEC T_DOUBLE_CAST T_STRING_CAST T_OBJECT_CAST cast_operator '@' %right T_POW %right '[' %nonassoc T_NEW T_CLONE @@ -136,13 +136,13 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %token T_INSTANCEOF "instanceof (T_INSTANCEOF)" %token T_INC "++ (T_INC)" %token T_DEC "-- (T_DEC)" -%token T_INT_CAST "(int) (T_INT_CAST)" +%token T_INT_TYPE "int (T_INT_TYPE)" +%token T_FLOAT_TYPE "float (T_FLOAT_TYPE)" +%token T_STRING_TYPE "string (T_STRING_TYPE)" +%token T_BOOL_TYPE "bool (T_BOOL_TYPE)" %token T_DOUBLE_CAST "(double) (T_DOUBLE_CAST)" %token T_STRING_CAST "(string) (T_STRING_CAST)" -%token T_ARRAY_CAST "(array) (T_ARRAY_CAST)" %token T_OBJECT_CAST "(object) (T_OBJECT_CAST)" -%token T_BOOL_CAST "(bool) (T_BOOL_CAST)" -%token T_UNSET_CAST "(unset) (T_UNSET_CAST)" %token T_NEW "new (T_NEW)" %token T_CLONE "clone (T_CLONE)" %token T_EXIT "exit (T_EXIT)" @@ -573,9 +573,15 @@ optional_type: ; type: - T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } - | T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); } - | name { $$ = $1; } + T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } + | T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); } + | T_INT_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_LONG); } + | T_FLOAT_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_DOUBLE); } + | T_STRING_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_STRING); } + | T_BOOL_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, _IS_BOOL); } + | T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } + | T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); } + | name { $$ = $1; } ; return_type: @@ -857,13 +863,27 @@ expr_without_variable: | expr T_COALESCE expr { $$ = zend_ast_create(ZEND_AST_COALESCE, $1, $3); } | internal_functions_in_yacc { $$ = $1; } - | T_INT_CAST expr { $$ = zend_ast_create_cast(IS_LONG, $2); } + | '(' T_INT_TYPE ')' expr + %prec cast_operator + { $$ = zend_ast_create_cast(IS_LONG, $4); } + | '(' T_FLOAT_TYPE ')' expr + %prec cast_operator + { $$ = zend_ast_create_cast(IS_DOUBLE, $4); } + | '(' T_STRING_TYPE ')' expr + %prec cast_operator + { $$ = zend_ast_create_cast(IS_STRING, $4); } + | '(' T_BOOL_TYPE ')' expr + %prec cast_operator + { $$ = zend_ast_create_cast(_IS_BOOL, $4); } + | '(' T_ARRAY ')' expr + %prec cast_operator + { $$ = zend_ast_create_cast(IS_ARRAY, $4); } + | '(' T_UNSET ')' expr + %prec cast_operator + { $$ = zend_ast_create_cast(IS_NULL, $4); } | T_DOUBLE_CAST expr { $$ = zend_ast_create_cast(IS_DOUBLE, $2); } | T_STRING_CAST expr { $$ = zend_ast_create_cast(IS_STRING, $2); } - | T_ARRAY_CAST expr { $$ = zend_ast_create_cast(IS_ARRAY, $2); } | T_OBJECT_CAST expr { $$ = zend_ast_create_cast(IS_OBJECT, $2); } - | T_BOOL_CAST expr { $$ = zend_ast_create_cast(_IS_BOOL, $2); } - | T_UNSET_CAST expr { $$ = zend_ast_create_cast(IS_NULL, $2); } | T_EXIT exit_expr { $$ = zend_ast_create(ZEND_AST_EXIT, $2); } | '@' expr { $$ = zend_ast_create(ZEND_AST_SILENCE, $2); } | scalar { $$ = $1; } diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 0081192d40f61..9c87c188331ad 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -1309,32 +1309,32 @@ NEWLINE ("\r"|"\n"|"\r\n") return T_VAR; } -"("{TABS_AND_SPACES}("int"|"integer"){TABS_AND_SPACES}")" { - return T_INT_CAST; +("int"|"integer") { + return T_INT_TYPE; } -"("{TABS_AND_SPACES}("real"|"double"|"float"){TABS_AND_SPACES}")" { - return T_DOUBLE_CAST; +"float" { + return T_FLOAT_TYPE; } -"("{TABS_AND_SPACES}("string"|"binary"){TABS_AND_SPACES}")" { - return T_STRING_CAST; +"string" { + return T_STRING_TYPE; } -"("{TABS_AND_SPACES}"array"{TABS_AND_SPACES}")" { - return T_ARRAY_CAST; +("bool"|"boolean") { + return T_BOOL_TYPE; } -"("{TABS_AND_SPACES}"object"{TABS_AND_SPACES}")" { - return T_OBJECT_CAST; +"("{TABS_AND_SPACES}("real"|"double"){TABS_AND_SPACES}")" { + return T_DOUBLE_CAST; } -"("{TABS_AND_SPACES}("bool"|"boolean"){TABS_AND_SPACES}")" { - return T_BOOL_CAST; +"("{TABS_AND_SPACES}("binary"){TABS_AND_SPACES}")" { + return T_STRING_CAST; } -"("{TABS_AND_SPACES}("unset"){TABS_AND_SPACES}")" { - return T_UNSET_CAST; +"("{TABS_AND_SPACES}"object"{TABS_AND_SPACES}")" { + return T_OBJECT_CAST; } "eval" { diff --git a/ext/reflection/tests/ReflectionMethod_basic1.phpt b/ext/reflection/tests/ReflectionMethod_basic1.phpt index 75ab957690c1f..aeabcc6a0199a 100644 --- a/ext/reflection/tests/ReflectionMethod_basic1.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic1.phpt @@ -48,7 +48,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function int(); + public function inter(); } reflectMethod("DerivedClass", "foo"); @@ -56,7 +56,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "int"); +reflectMethod("TestInterface", "inter"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -208,7 +208,7 @@ bool(false) ********************************** ********************************** -Reflecting on method TestInterface::int() +Reflecting on method TestInterface::inter() isFinal(): diff --git a/ext/reflection/tests/ReflectionMethod_basic2.phpt b/ext/reflection/tests/ReflectionMethod_basic2.phpt index c91af677016c2..8bc7705eb65d7 100644 --- a/ext/reflection/tests/ReflectionMethod_basic2.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic2.phpt @@ -36,7 +36,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function int(); + public function inter(); } reflectMethod("DerivedClass", "foo"); @@ -44,7 +44,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "int"); +reflectMethod("TestInterface", "inter"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -131,16 +131,16 @@ string(%d) "Method [ protected method prot ] { ********************************** ********************************** -Reflecting on method TestInterface::int() +Reflecting on method TestInterface::inter() __toString(): -string(%d) "Method [ abstract public method int ] { +string(%d) "Method [ abstract public method inter ] { @@ %s 36 - 36 } " export(): -string(%d) "Method [ abstract public method int ] { +string(%d) "Method [ abstract public method inter ] { @@ %s 36 - 36 } " diff --git a/ext/reflection/tests/ReflectionMethod_basic3.phpt b/ext/reflection/tests/ReflectionMethod_basic3.phpt index 7b65927667df8..ad6c663818d31 100644 --- a/ext/reflection/tests/ReflectionMethod_basic3.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic3.phpt @@ -38,7 +38,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function int(); + public function inter(); } reflectMethod("DerivedClass", "foo"); @@ -46,7 +46,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "int"); +reflectMethod("TestInterface", "inter"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -124,11 +124,11 @@ bool(true) ********************************** ********************************** -Reflecting on method TestInterface::int() +Reflecting on method TestInterface::inter() getName(): -string(3) "int" +string(5) "inter" isInternal(): bool(false) diff --git a/ext/reflection/tests/ReflectionMethod_basic4.phpt b/ext/reflection/tests/ReflectionMethod_basic4.phpt index 82672e44f582b..a0c2ddcf17953 100644 --- a/ext/reflection/tests/ReflectionMethod_basic4.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic4.phpt @@ -42,7 +42,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function int(); + public function inter(); } reflectMethod("DerivedClass", "foo"); @@ -50,7 +50,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "int"); +reflectMethod("TestInterface", "inter"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -127,7 +127,7 @@ int(34) ********************************** ********************************** -Reflecting on method TestInterface::int() +Reflecting on method TestInterface::inter() getFileName(): diff --git a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt index 72baa53fda004..bb43be078d4e0 100644 --- a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt @@ -60,7 +60,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function int(); + public function inter(); public function __clone(); } @@ -222,7 +222,7 @@ Modifiers for method TestClass::__autoload(): 0x08010100 -Modifiers for method TestInterface::int(): +Modifiers for method TestInterface::inter(): 0x08000102 diff --git a/ext/standard/tests/array/krsort_object.phpt b/ext/standard/tests/array/krsort_object.phpt index 36d8589a82bd2..6236595796cb0 100644 --- a/ext/standard/tests/array/krsort_object.phpt +++ b/ext/standard/tests/array/krsort_object.phpt @@ -15,7 +15,7 @@ Test krsort() function : object functionality - sort objects echo "*** Testing krsort() : object functionality ***\n"; // class declaration for integer objects -class Integer +class IntegerObject { public $class_value; // initializing object member value @@ -25,7 +25,7 @@ class Integer } // class declaration for string objects -class String +class StringObject { public $class_value; // initializing object member value @@ -42,17 +42,17 @@ class String // array of integer objects with different key values $unsorted_int_obj = array ( - 10 => new Integer(11), 20 => new Integer(66), - 3 => new Integer(23), 4 => new Integer(-5), - 50 => new Integer(0.001), 6 => new Integer(0) + 10 => new IntegerObject(11), 20 => new IntegerObject(66), + 3 => new IntegerObject(23), 4 => new IntegerObject(-5), + 50 => new IntegerObject(0.001), 6 => new IntegerObject(0) ); // array of string objects with different key values $unsorted_str_obj = array ( - "axx" => new String("axx"), "t" => new String("t"), - "w" => new String("w"), "py" => new String("py"), - "apple" => new String("apple"), "Orange" => new String("Orange"), - "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle") + "axx" => new StringObject("axx"), "t" => new StringObject("t"), + "w" => new StringObject("w"), "py" => new StringObject("py"), + "apple" => new StringObject("apple"), "Orange" => new StringObject("Orange"), + "Lemon" => new StringObject("Lemon"), "aPPle" => new StringObject("aPPle") ); @@ -88,32 +88,32 @@ echo "Done\n"; bool(true) array(6) { [50]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> float(0.001) } [20]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(66) } [10]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(11) } [6]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(0) } [4]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(-5) } [3]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(23) } @@ -121,42 +121,42 @@ array(6) { bool(true) array(8) { ["w"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "w" } ["t"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "t" } ["py"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(2) "py" } ["axx"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(3) "axx" } ["apple"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "apple" } ["aPPle"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "aPPle" } ["Orange"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(6) "Orange" } ["Lemon"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "Lemon" } @@ -166,32 +166,32 @@ array(8) { bool(true) array(6) { [50]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> float(0.001) } [20]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(66) } [10]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(11) } [6]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(0) } [4]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(-5) } [3]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(23) } @@ -199,42 +199,42 @@ array(6) { bool(true) array(8) { ["w"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "w" } ["t"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "t" } ["py"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(2) "py" } ["axx"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(3) "axx" } ["apple"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "apple" } ["aPPle"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "aPPle" } ["Orange"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(6) "Orange" } ["Lemon"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "Lemon" } diff --git a/ext/standard/tests/array/ksort_object.phpt b/ext/standard/tests/array/ksort_object.phpt index 20e8ba26eb3c9..2d76026aa49b6 100644 --- a/ext/standard/tests/array/ksort_object.phpt +++ b/ext/standard/tests/array/ksort_object.phpt @@ -15,7 +15,7 @@ Test ksort() function : object functionality - sort objects echo "*** Testing ksort() : object functionality ***\n"; // class declaration for integer objects -class Integer +class IntegerObject { public $class_value; // initializing object member value @@ -26,7 +26,7 @@ class Integer } // class declaration for string objects -class String +class StringObject { public $class_value; // initializing object member value @@ -43,17 +43,17 @@ class String // array of integer objects $unsorted_int_obj = array ( - 11 => new Integer(11), 66 => new Integer(66), - 23 => new Integer(23), -5 => new Integer(-5), - 1 => new Integer(0.001), 0 => new Integer(0) + 11 => new IntegerObject(11), 66 => new IntegerObject(66), + 23 => new IntegerObject(23), -5 => new IntegerObject(-5), + 1 => new IntegerObject(0.001), 0 => new IntegerObject(0) ); // array of string objects $unsorted_str_obj = array ( - "axx" => new String("axx"), "t" => new String("t"), - "w" => new String("w"), "py" => new String("py"), - "apple" => new String("apple"), "Orange" => new String("Orange"), - "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle") + "axx" => new StringObject("axx"), "t" => new StringObject("t"), + "w" => new StringObject("w"), "py" => new StringObject("py"), + "apple" => new StringObject("apple"), "Orange" => new StringObject("Orange"), + "Lemon" => new StringObject("Lemon"), "aPPle" => new StringObject("aPPle") ); echo "\n-- Testing ksort() by supplying various object arrays, 'flag' value is defualt --\n"; @@ -87,32 +87,32 @@ echo "Done\n"; bool(true) array(6) { [-5]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(-5) } [0]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(0) } [1]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> float(0.001) } [11]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(11) } [23]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(23) } [66]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(66) } @@ -120,42 +120,42 @@ array(6) { bool(true) array(8) { ["Lemon"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "Lemon" } ["Orange"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(6) "Orange" } ["aPPle"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "aPPle" } ["apple"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "apple" } ["axx"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(3) "axx" } ["py"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(2) "py" } ["t"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "t" } ["w"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "w" } @@ -165,32 +165,32 @@ array(8) { bool(true) array(6) { [-5]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(-5) } [0]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(0) } [1]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> float(0.001) } [11]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(11) } [23]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(23) } [66]=> - object(Integer)#%d (1) { + object(IntegerObject)#%d (1) { ["class_value"]=> int(66) } @@ -198,42 +198,42 @@ array(6) { bool(true) array(8) { ["Lemon"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "Lemon" } ["Orange"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(6) "Orange" } ["aPPle"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "aPPle" } ["apple"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(5) "apple" } ["axx"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(3) "axx" } ["py"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(2) "py" } ["t"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "t" } ["w"]=> - object(String)#%d (1) { + object(StringObject)#%d (1) { ["class_value"]=> string(1) "w" } diff --git a/ext/standard/tests/strings/lcfirst.phpt b/ext/standard/tests/strings/lcfirst.phpt index e603f4bbf8d425626d903fe40e94e344055db422..6cbd213fbeb6ea78249ea0b675d4f8332dfeb9d8 100644 GIT binary patch delta 107 zcmca-`pa|y6IXt2YH>+XW?s6^W_G57>}>u?S*gh-lTUDlazL2YT$2w9h-^0I(&JEo rD^}1|NGvWc%}q^FP%nmys!z_Bl$<O5Bp>R_OQ)a?13TxGHL}W diff --git a/ext/standard/tests/strings/strpos.phpt b/ext/standard/tests/strings/strpos.phpt index b2bfedeb871e432abd948b1b3c25339d42a60392..36854d1b372d6f6cc50d5575ccffc66b09e66567 100644 GIT binary patch delta 28 kcmZqo>-XDmhLb5VX|e&A&g5^Lx-5xFIjNhKxt_=X0GW9TEdT%j delta 16 XcmeD8Yxmo5hI8@-&hX9JTu)>GK4}Ky diff --git a/ext/standard/tests/strings/strstr.phpt b/ext/standard/tests/strings/strstr.phpt index bdedb7e9f6719f8eb55e8fed9a16daa8872335fc..fd7f58ef1a51a4d6fcb7f585af339874148bf5e7 100644 GIT binary patch delta 28 kcmZ1+v^r>m7&}v9(&Q?3oyiXDx-5xFIjNg-*|#YI0E^cNVgLXD delta 16 XcmZ1-v^Z#k82e-?_VCT6?AsIpHAMx{ diff --git a/ext/standard/tests/strings/ucfirst.phpt b/ext/standard/tests/strings/ucfirst.phpt index 468f7f034e6d10142893677f957b78d983df1cb1..8fb1a156b46a78c5fde89267972c0bfd5d4d5bb5 100644 GIT binary patch delta 93 zcmcbm|4DxV6IXt2YH>+XW?s6^W_BhHR+hx1oYcwu>|tymhBepZ1-v4gtJ(E9B;g7b lbQKbdi%WA;Qxw#TfufUl@!#e$G|*H~3I?g!JWIfV9RRdL9^3!` delta 61 zcmeyQe@lM>6MIQfW?s4u=VmS@4%W$H>|vV=*j+dT!J-Pf3W>$VrMamo3hI;3^514P O(^OCj-n>b`fgJ#2$`elj From 75a225d0d5eb38d8aba789cbe50ec9ae812592f2 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sat, 27 Dec 2014 17:47:33 +0000 Subject: [PATCH 02/29] Do not make scalar type hints reserved words, merely reserve class name --- Zend/tests/typehints/scalar_reserved1.phpt | 8 ++++ Zend/tests/typehints/scalar_reserved2.phpt | 8 ++++ Zend/tests/typehints/scalar_reserved3.phpt | 8 ++++ Zend/tests/typehints/scalar_reserved4.phpt | 8 ++++ Zend/tests/typehints/scalar_reserved5.phpt | 8 ++++ Zend/tests/typehints/scalar_reserved6.phpt | 8 ++++ Zend/zend_compile.c | 41 +++++++++++++++++ Zend/zend_language_parser.y | 44 +++++-------------- Zend/zend_language_scanner.l | 28 ++++++------ .../tests/ReflectionMethod_basic1.phpt | 6 +-- .../tests/ReflectionMethod_basic2.phpt | 10 ++--- .../tests/ReflectionMethod_basic3.phpt | 8 ++-- .../tests/ReflectionMethod_basic4.phpt | 6 +-- .../ReflectionMethod_getModifiers_basic.phpt | 4 +- 14 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 Zend/tests/typehints/scalar_reserved1.phpt create mode 100644 Zend/tests/typehints/scalar_reserved2.phpt create mode 100644 Zend/tests/typehints/scalar_reserved3.phpt create mode 100644 Zend/tests/typehints/scalar_reserved4.phpt create mode 100644 Zend/tests/typehints/scalar_reserved5.phpt create mode 100644 Zend/tests/typehints/scalar_reserved6.phpt diff --git a/Zend/tests/typehints/scalar_reserved1.phpt b/Zend/tests/typehints/scalar_reserved1.phpt new file mode 100644 index 0000000000000..8a940308cad2d --- /dev/null +++ b/Zend/tests/typehints/scalar_reserved1.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type hint names cannot be used as class, trait or interface names (1) +--FILE-- +op_type; \ if ((src)->op_type == IS_CONST) { \ @@ -3949,7 +3965,17 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, zend_bool is_ } } else { zend_string *class_name = zend_ast_get_str(type_ast); + const struct _scalar_typehint_info *info = &scalar_typehints[0]; + while (info->name) { + if (class_name->len == info->name_len + && zend_binary_strcasecmp(class_name->val, info->name_len, info->name, info->name_len) == 0) { + arg_info->type_hint = info->type; + goto done; + } + info++; + } + if (zend_is_const_default_class_ref(type_ast)) { class_name = zend_resolve_class_name_ast(type_ast); } else { @@ -3959,9 +3985,15 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, zend_bool is_ arg_info->type_hint = IS_OBJECT; arg_info->class_name = class_name; +done: if (default_ast && !has_null_default && !Z_CONSTANT(default_node.u.constant)) { + if (arg_info->class_name) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " "with a class type hint can only be NULL"); + } else if (Z_TYPE(default_node.u.constant) != arg_info->type_hint) { + zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " + "with a %s type hint can only be %s or NULL", class_name->val, class_name->val); + } } } } @@ -4558,6 +4590,7 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ zend_class_entry *ce = zend_arena_alloc(&CG(arena), sizeof(zend_class_entry)); zend_op *opline; znode declare_node, extends_node; + const struct _scalar_typehint_info *info = &scalar_typehints[0]; if (CG(active_class_entry)) { zend_error_noreturn(E_COMPILE_ERROR, "Class declarations may not be nested"); @@ -4589,6 +4622,14 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ "because the name is already in use", name->val); } + while (info->name) { + if (lcname->len == info->name_len && strcmp(lcname->val, info->name) == 0) { + zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s " + "because %s is a type name", name->val, info->name); + } + info++; + } + name = zend_new_interned_string(name); lcname = zend_new_interned_string(lcname); diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index bfb7787677848..3671eadd6b721 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -82,7 +82,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %left '*' '/' '%' %right '!' %nonassoc T_INSTANCEOF -%right '~' T_INC T_DEC T_DOUBLE_CAST T_STRING_CAST T_OBJECT_CAST cast_operator '@' +%right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@' %right T_POW %right '[' %nonassoc T_NEW T_CLONE @@ -136,13 +136,13 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %token T_INSTANCEOF "instanceof (T_INSTANCEOF)" %token T_INC "++ (T_INC)" %token T_DEC "-- (T_DEC)" -%token T_INT_TYPE "int (T_INT_TYPE)" -%token T_FLOAT_TYPE "float (T_FLOAT_TYPE)" -%token T_STRING_TYPE "string (T_STRING_TYPE)" -%token T_BOOL_TYPE "bool (T_BOOL_TYPE)" +%token T_INT_CAST "(int) (T_INT_CAST)" %token T_DOUBLE_CAST "(double) (T_DOUBLE_CAST)" %token T_STRING_CAST "(string) (T_STRING_CAST)" +%token T_ARRAY_CAST "(array) (T_ARRAY_CAST)" %token T_OBJECT_CAST "(object) (T_OBJECT_CAST)" +%token T_BOOL_CAST "(bool) (T_BOOL_CAST)" +%token T_UNSET_CAST "(unset) (T_UNSET_CAST)" %token T_NEW "new (T_NEW)" %token T_CLONE "clone (T_CLONE)" %token T_EXIT "exit (T_EXIT)" @@ -573,15 +573,9 @@ optional_type: ; type: - T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } - | T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); } - | T_INT_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_LONG); } - | T_FLOAT_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_DOUBLE); } - | T_STRING_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_STRING); } - | T_BOOL_TYPE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, _IS_BOOL); } - | T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } - | T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); } - | name { $$ = $1; } + | T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } + | T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); } + | name { $$ = $1; } ; return_type: @@ -863,27 +857,13 @@ expr_without_variable: | expr T_COALESCE expr { $$ = zend_ast_create(ZEND_AST_COALESCE, $1, $3); } | internal_functions_in_yacc { $$ = $1; } - | '(' T_INT_TYPE ')' expr - %prec cast_operator - { $$ = zend_ast_create_cast(IS_LONG, $4); } - | '(' T_FLOAT_TYPE ')' expr - %prec cast_operator - { $$ = zend_ast_create_cast(IS_DOUBLE, $4); } - | '(' T_STRING_TYPE ')' expr - %prec cast_operator - { $$ = zend_ast_create_cast(IS_STRING, $4); } - | '(' T_BOOL_TYPE ')' expr - %prec cast_operator - { $$ = zend_ast_create_cast(_IS_BOOL, $4); } - | '(' T_ARRAY ')' expr - %prec cast_operator - { $$ = zend_ast_create_cast(IS_ARRAY, $4); } - | '(' T_UNSET ')' expr - %prec cast_operator - { $$ = zend_ast_create_cast(IS_NULL, $4); } + | T_INT_CAST expr { $$ = zend_ast_create_cast(IS_LONG, $2); } | T_DOUBLE_CAST expr { $$ = zend_ast_create_cast(IS_DOUBLE, $2); } | T_STRING_CAST expr { $$ = zend_ast_create_cast(IS_STRING, $2); } + | T_ARRAY_CAST expr { $$ = zend_ast_create_cast(IS_ARRAY, $2); } | T_OBJECT_CAST expr { $$ = zend_ast_create_cast(IS_OBJECT, $2); } + | T_BOOL_CAST expr { $$ = zend_ast_create_cast(_IS_BOOL, $2); } + | T_UNSET_CAST expr { $$ = zend_ast_create_cast(IS_NULL, $2); } | T_EXIT exit_expr { $$ = zend_ast_create(ZEND_AST_EXIT, $2); } | '@' expr { $$ = zend_ast_create(ZEND_AST_SILENCE, $2); } | scalar { $$ = $1; } diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 9c87c188331ad..0081192d40f61 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -1309,32 +1309,32 @@ NEWLINE ("\r"|"\n"|"\r\n") return T_VAR; } -("int"|"integer") { - return T_INT_TYPE; +"("{TABS_AND_SPACES}("int"|"integer"){TABS_AND_SPACES}")" { + return T_INT_CAST; } -"float" { - return T_FLOAT_TYPE; +"("{TABS_AND_SPACES}("real"|"double"|"float"){TABS_AND_SPACES}")" { + return T_DOUBLE_CAST; } -"string" { - return T_STRING_TYPE; +"("{TABS_AND_SPACES}("string"|"binary"){TABS_AND_SPACES}")" { + return T_STRING_CAST; } -("bool"|"boolean") { - return T_BOOL_TYPE; +"("{TABS_AND_SPACES}"array"{TABS_AND_SPACES}")" { + return T_ARRAY_CAST; } -"("{TABS_AND_SPACES}("real"|"double"){TABS_AND_SPACES}")" { - return T_DOUBLE_CAST; +"("{TABS_AND_SPACES}"object"{TABS_AND_SPACES}")" { + return T_OBJECT_CAST; } -"("{TABS_AND_SPACES}("binary"){TABS_AND_SPACES}")" { - return T_STRING_CAST; +"("{TABS_AND_SPACES}("bool"|"boolean"){TABS_AND_SPACES}")" { + return T_BOOL_CAST; } -"("{TABS_AND_SPACES}"object"{TABS_AND_SPACES}")" { - return T_OBJECT_CAST; +"("{TABS_AND_SPACES}("unset"){TABS_AND_SPACES}")" { + return T_UNSET_CAST; } "eval" { diff --git a/ext/reflection/tests/ReflectionMethod_basic1.phpt b/ext/reflection/tests/ReflectionMethod_basic1.phpt index aeabcc6a0199a..75ab957690c1f 100644 --- a/ext/reflection/tests/ReflectionMethod_basic1.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic1.phpt @@ -48,7 +48,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function inter(); + public function int(); } reflectMethod("DerivedClass", "foo"); @@ -56,7 +56,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "inter"); +reflectMethod("TestInterface", "int"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -208,7 +208,7 @@ bool(false) ********************************** ********************************** -Reflecting on method TestInterface::inter() +Reflecting on method TestInterface::int() isFinal(): diff --git a/ext/reflection/tests/ReflectionMethod_basic2.phpt b/ext/reflection/tests/ReflectionMethod_basic2.phpt index 8bc7705eb65d7..c91af677016c2 100644 --- a/ext/reflection/tests/ReflectionMethod_basic2.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic2.phpt @@ -36,7 +36,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function inter(); + public function int(); } reflectMethod("DerivedClass", "foo"); @@ -44,7 +44,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "inter"); +reflectMethod("TestInterface", "int"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -131,16 +131,16 @@ string(%d) "Method [ protected method prot ] { ********************************** ********************************** -Reflecting on method TestInterface::inter() +Reflecting on method TestInterface::int() __toString(): -string(%d) "Method [ abstract public method inter ] { +string(%d) "Method [ abstract public method int ] { @@ %s 36 - 36 } " export(): -string(%d) "Method [ abstract public method inter ] { +string(%d) "Method [ abstract public method int ] { @@ %s 36 - 36 } " diff --git a/ext/reflection/tests/ReflectionMethod_basic3.phpt b/ext/reflection/tests/ReflectionMethod_basic3.phpt index ad6c663818d31..7b65927667df8 100644 --- a/ext/reflection/tests/ReflectionMethod_basic3.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic3.phpt @@ -38,7 +38,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function inter(); + public function int(); } reflectMethod("DerivedClass", "foo"); @@ -46,7 +46,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "inter"); +reflectMethod("TestInterface", "int"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -124,11 +124,11 @@ bool(true) ********************************** ********************************** -Reflecting on method TestInterface::inter() +Reflecting on method TestInterface::int() getName(): -string(5) "inter" +string(3) "int" isInternal(): bool(false) diff --git a/ext/reflection/tests/ReflectionMethod_basic4.phpt b/ext/reflection/tests/ReflectionMethod_basic4.phpt index a0c2ddcf17953..82672e44f582b 100644 --- a/ext/reflection/tests/ReflectionMethod_basic4.phpt +++ b/ext/reflection/tests/ReflectionMethod_basic4.phpt @@ -42,7 +42,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function inter(); + public function int(); } reflectMethod("DerivedClass", "foo"); @@ -50,7 +50,7 @@ reflectMethod("TestClass", "stat"); reflectMethod("TestClass", "priv"); reflectMethod("TestClass", "prot"); reflectMethod("DerivedClass", "prot"); -reflectMethod("TestInterface", "inter"); +reflectMethod("TestInterface", "int"); reflectMethod("ReflectionProperty", "__construct"); reflectMethod("TestClass", "__destruct"); @@ -127,7 +127,7 @@ int(34) ********************************** ********************************** -Reflecting on method TestInterface::inter() +Reflecting on method TestInterface::int() getFileName(): diff --git a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt index bb43be078d4e0..72baa53fda004 100644 --- a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt @@ -60,7 +60,7 @@ class TestClass class DerivedClass extends TestClass {} interface TestInterface { - public function inter(); + public function int(); public function __clone(); } @@ -222,7 +222,7 @@ Modifiers for method TestClass::__autoload(): 0x08010100 -Modifiers for method TestInterface::inter(): +Modifiers for method TestInterface::int(): 0x08000102 From d4dd2a9bafdb588acd54c9062cd75a7f95de887a Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Mon, 29 Dec 2014 13:29:03 +0000 Subject: [PATCH 03/29] Use new names of arg parsing functions --- Zend/zend_execute.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index c10506db33303..5cf4f74055ff2 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -706,7 +706,7 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, switch (cur_arg_info->type_hint) { case IS_LONG: { zend_long dest; - if (_z_param_long(arg, &dest, NULL, 0, 0)) { + if (zend_parse_arg_long(arg, &dest, NULL, 0, 0)) { if (Z_TYPE_P(arg) != IS_LONG) { zval_dtor(arg); } @@ -718,7 +718,7 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, break; case IS_DOUBLE: { double dest; - if (_z_param_double(arg, &dest, NULL, 0)) { + if (zend_parse_arg_double(arg, &dest, NULL, 0)) { if (Z_TYPE_P(arg) != IS_DOUBLE) { zval_dtor(arg); } @@ -730,7 +730,7 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, break; case IS_STRING: { zend_string *dest; - if (_z_param_str(arg, &dest, 0)) { + if (zend_parse_arg_str(arg, &dest, 0)) { if (Z_TYPE_P(arg) != IS_STRING) { zval_dtor(arg); } @@ -742,7 +742,7 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, break; case _IS_BOOL: { zend_bool dest; - if (_z_param_bool(arg, &dest, NULL, 0)) { + if (zend_parse_arg_bool(arg, &dest, NULL, 0)) { if (Z_TYPE_P(arg) != IS_TRUE && Z_TYPE_P(arg) != IS_FALSE) { zval_dtor(arg); } From a13d13429ade7a4eb8890c2f19c98abdaf1addbf Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Mon, 29 Dec 2014 13:49:12 +0000 Subject: [PATCH 04/29] Refactor scalar type hints implementation per Dmitry's patch --- Zend/zend_execute.c | 139 +++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 73 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 5cf4f74055ff2..26b6a3526a2fc 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -610,6 +610,54 @@ static int is_null_constant(zval *default_value) return 0; } +static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg) +{ + switch (type_hint) { + case _IS_BOOL: { + zend_bool dest; + + if (!zend_parse_arg_bool(arg, &dest, NULL, 0)) { + return 0; + } + zval_ptr_dtor(arg); + ZVAL_BOOL(arg, dest); + return 1; + } + case IS_LONG: { + zend_long dest; + + if (!zend_parse_arg_long(arg, &dest, NULL, 0, 0)) { + return 0; + } + zval_ptr_dtor(arg); + ZVAL_LONG(arg, dest); + return 1; + } + case IS_DOUBLE: { + double dest; + + if (!zend_parse_arg_double(arg, &dest, NULL, 0)) { + return 0; + } + zval_ptr_dtor(arg); + ZVAL_DOUBLE(arg, dest); + return 1; + } + case IS_STRING: { + zend_string *dest; + + if (!zend_parse_arg_str(arg, &dest, 0)) { + return 0; + } + zval_ptr_dtor(arg); + ZVAL_STR(arg, dest); + return 1; + } + default: + return 0; + } +} + static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, zval *arg) { zend_internal_arg_info *cur_arg_info; @@ -638,8 +686,8 @@ static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, z zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, zend_zval_type_name(arg), "", arg); } } else if (cur_arg_info->type_hint) { + ZVAL_DEREF(arg); if (cur_arg_info->type_hint == IS_ARRAY) { - ZVAL_DEREF(arg); if (Z_TYPE_P(arg) != IS_ARRAY && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", zend_zval_type_name(arg), "", arg); } @@ -647,10 +695,17 @@ static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, z if (!zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "", arg); } -#if ZEND_DEBUG - } else { - zend_error(E_ERROR, "Unknown typehint"); -#endif + } else if (UNEXPECTED(cur_arg_info->type_hint != Z_TYPE_P(arg))) { + if (Z_TYPE_P(arg) == IS_NULL) { + if (!cur_arg_info->allow_null) { +failure: + zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), zend_zval_type_name(arg), "", arg); + } + return; + } + if (!zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { + goto failure; + } } } } @@ -683,8 +738,8 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, zend_zval_type_name(arg), "", arg); } } else if (cur_arg_info->type_hint) { + ZVAL_DEREF(arg); if (cur_arg_info->type_hint == IS_ARRAY) { - ZVAL_DEREF(arg); if (Z_TYPE_P(arg) != IS_ARRAY && (Z_TYPE_P(arg) != IS_NULL || !(cur_arg_info->allow_null || (default_value && is_null_constant(default_value))))) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", zend_zval_type_name(arg), "", arg); } @@ -692,71 +747,16 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, if (!zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(arg) != IS_NULL || !(cur_arg_info->allow_null || (default_value && is_null_constant(default_value))))) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "", arg); } - } else { - ZVAL_DEREF(arg); - + } else if (UNEXPECTED(cur_arg_info->type_hint != Z_TYPE_P(arg))) { if (Z_TYPE_P(arg) == IS_NULL) { - if (!(cur_arg_info->allow_null || (default_value && is_null_constant(default_value)))) { + if (!cur_arg_info->allow_null) { failure: zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), zend_zval_type_name(arg), "", arg); } return; } - - switch (cur_arg_info->type_hint) { - case IS_LONG: { - zend_long dest; - if (zend_parse_arg_long(arg, &dest, NULL, 0, 0)) { - if (Z_TYPE_P(arg) != IS_LONG) { - zval_dtor(arg); - } - ZVAL_LONG(arg, dest); - } else { - goto failure; - } - } - break; - case IS_DOUBLE: { - double dest; - if (zend_parse_arg_double(arg, &dest, NULL, 0)) { - if (Z_TYPE_P(arg) != IS_DOUBLE) { - zval_dtor(arg); - } - ZVAL_DOUBLE(arg, dest); - } else { - goto failure; - } - } - break; - case IS_STRING: { - zend_string *dest; - if (zend_parse_arg_str(arg, &dest, 0)) { - if (Z_TYPE_P(arg) != IS_STRING) { - zval_dtor(arg); - } - ZVAL_STR(arg, dest); - } else { - goto failure; - } - } - break; - case _IS_BOOL: { - zend_bool dest; - if (zend_parse_arg_bool(arg, &dest, NULL, 0)) { - if (Z_TYPE_P(arg) != IS_TRUE && Z_TYPE_P(arg) != IS_FALSE) { - zval_dtor(arg); - } - ZVAL_BOOL(arg, dest); - } else { - goto failure; - } - } - break; - default: -#if ZEND_DEBUG - zend_error(E_ERROR, "Unknown typehint"); -#endif - break; + if (!zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { + goto failure; } } } @@ -787,15 +787,8 @@ static inline int zend_verify_missing_arg_type(zend_function *zf, uint32_t arg_n zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", "none", "", NULL); } else if (cur_arg_info->type_hint == IS_CALLABLE) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", "none", "", NULL); - } else if (cur_arg_info->type_hint == IS_LONG - || cur_arg_info->type_hint == IS_DOUBLE - || cur_arg_info->type_hint == IS_STRING - || cur_arg_info->type_hint == _IS_BOOL) { - zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), "none", "", NULL); -#if ZEND_DEBUG } else { - zend_error(E_ERROR, "Unknown typehint"); -#endif + zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), "none", "", NULL); } return 0; } From a03af7ff92f472bd157bbd7b16333c43b61dc418 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 4 Jan 2015 02:42:54 +0000 Subject: [PATCH 05/29] Fix class name prohibition to work for namespaced classes, too --- Zend/zend_compile.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 6d792d2ec6a3f..e617af9bfe21f 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4608,6 +4608,15 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ import_name = zend_hash_find_ptr(CG(current_import), lcname); } + while (info->name) { + if (lcname->len == info->name_len && strcmp(lcname->val, info->name) == 0) { + zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s " + "because %s is a type name", name->val, info->name); + } + info++; + } + + if (CG(current_namespace)) { name = zend_prefix_with_ns(name); @@ -4622,14 +4631,6 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ "because the name is already in use", name->val); } - while (info->name) { - if (lcname->len == info->name_len && strcmp(lcname->val, info->name) == 0) { - zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s " - "because %s is a type name", name->val, info->name); - } - info++; - } - name = zend_new_interned_string(name); lcname = zend_new_interned_string(lcname); From 1a28ad036e6db141a73582cb1fabb3a6fd3abd62 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Tue, 6 Jan 2015 03:03:05 +0000 Subject: [PATCH 06/29] Forbid scalar type hint names for use, class_alias --- Zend/tests/typehints/scalar_reserved1.phpt | 2 +- .../scalar_reserved1_class_alias.phpt | 9 + .../tests/typehints/scalar_reserved1_use.phpt | 8 + Zend/tests/typehints/scalar_reserved2.phpt | 2 +- .../scalar_reserved2_class_alias.phpt | 9 + .../tests/typehints/scalar_reserved2_use.phpt | 8 + Zend/tests/typehints/scalar_reserved3.phpt | 2 +- .../scalar_reserved3_class_alias.phpt | 9 + .../tests/typehints/scalar_reserved3_use.phpt | 8 + Zend/tests/typehints/scalar_reserved4.phpt | 2 +- .../scalar_reserved4_class_alias.phpt | 9 + .../tests/typehints/scalar_reserved4_use.phpt | 8 + Zend/tests/typehints/scalar_reserved5.phpt | 2 +- .../scalar_reserved5_class_alias.phpt | 9 + .../tests/typehints/scalar_reserved5_use.phpt | 8 + Zend/tests/typehints/scalar_reserved6.phpt | 2 +- .../scalar_reserved6_class_alias.phpt | 9 + .../tests/typehints/scalar_reserved6_use.phpt | 8 + Zend/zend_API.c | 3 + Zend/zend_compile.c | 30 +- Zend/zend_compile.h | 39 + Zend/zend_language_scanner.c | 5044 +++++++++-------- Zend/zend_language_scanner_defs.h | 2 +- 23 files changed, 2680 insertions(+), 2552 deletions(-) create mode 100644 Zend/tests/typehints/scalar_reserved1_class_alias.phpt create mode 100644 Zend/tests/typehints/scalar_reserved1_use.phpt create mode 100644 Zend/tests/typehints/scalar_reserved2_class_alias.phpt create mode 100644 Zend/tests/typehints/scalar_reserved2_use.phpt create mode 100644 Zend/tests/typehints/scalar_reserved3_class_alias.phpt create mode 100644 Zend/tests/typehints/scalar_reserved3_use.phpt create mode 100644 Zend/tests/typehints/scalar_reserved4_class_alias.phpt create mode 100644 Zend/tests/typehints/scalar_reserved4_use.phpt create mode 100644 Zend/tests/typehints/scalar_reserved5_class_alias.phpt create mode 100644 Zend/tests/typehints/scalar_reserved5_use.phpt create mode 100644 Zend/tests/typehints/scalar_reserved6_class_alias.phpt create mode 100644 Zend/tests/typehints/scalar_reserved6_use.phpt diff --git a/Zend/tests/typehints/scalar_reserved1.phpt b/Zend/tests/typehints/scalar_reserved1.phpt index 8a940308cad2d..00a7482e216c3 100644 --- a/Zend/tests/typehints/scalar_reserved1.phpt +++ b/Zend/tests/typehints/scalar_reserved1.phpt @@ -5,4 +5,4 @@ Scalar type hint names cannot be used as class, trait or interface names (1) class integer {} --EXPECTF-- -Fatal error: Cannot declare class integer because integer is a type name in %s on line %d +Fatal error: "integer" cannot be used as a class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved1_class_alias.phpt b/Zend/tests/typehints/scalar_reserved1_class_alias.phpt new file mode 100644 index 0000000000000..59b15734fa932 --- /dev/null +++ b/Zend/tests/typehints/scalar_reserved1_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type hint names cannot be used as class, trait or interface names (1) - class_alias +--FILE-- +val, name, name_len); } + + zend_assert_valid_class_name(lcname); + ce = zend_hash_add_ptr(CG(class_table), lcname, ce); zend_string_release(lcname); if (ce) { diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index e617af9bfe21f..0f391f527a3cc 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -32,22 +32,6 @@ #include "zend_language_scanner.h" #include "zend_inheritance.h" -struct _scalar_typehint_info { - const char* name; - const size_t name_len; - const zend_uchar type; -}; - -static const struct _scalar_typehint_info scalar_typehints[] = { - {"int", sizeof("int") - 1, IS_LONG}, - {"integer", sizeof("integer") - 1, IS_LONG}, - {"float", sizeof("float") - 1, IS_DOUBLE}, - {"string", sizeof("string") - 1, IS_STRING}, - {"bool", sizeof("bool") - 1, _IS_BOOL}, - {"boolean", sizeof("boolean") - 1, _IS_BOOL}, - {NULL, 0, IS_UNDEF} -}; - #define SET_NODE(target, src) do { \ target ## _type = (src)->op_type; \ if ((src)->op_type == IS_CONST) { \ @@ -4590,7 +4574,6 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ zend_class_entry *ce = zend_arena_alloc(&CG(arena), sizeof(zend_class_entry)); zend_op *opline; znode declare_node, extends_node; - const struct _scalar_typehint_info *info = &scalar_typehints[0]; if (CG(active_class_entry)) { zend_error_noreturn(E_COMPILE_ERROR, "Class declarations may not be nested"); @@ -4608,14 +4591,7 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ import_name = zend_hash_find_ptr(CG(current_import), lcname); } - while (info->name) { - if (lcname->len == info->name_len && strcmp(lcname->val, info->name) == 0) { - zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s " - "because %s is a type name", name->val, info->name); - } - info++; - } - + zend_assert_valid_class_name(name); if (CG(current_namespace)) { name = zend_prefix_with_ns(name); @@ -4852,6 +4828,10 @@ void zend_compile_use(zend_ast *ast) /* {{{ */ } } + if (type == T_CLASS) { + zend_assert_valid_class_name(new_name); + } + if (case_sensitive) { lookup_name = zend_string_copy(new_name); } else { diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 8a9b37cc6c6f8..bf1b20bab8213 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -31,6 +31,45 @@ #include "zend_llist.h" +struct _scalar_typehint_info { + const char* name; + const size_t name_len; + const zend_uchar type; +}; + +static const struct _scalar_typehint_info scalar_typehints[] = { + {"int", sizeof("int") - 1, IS_LONG}, + {"integer", sizeof("integer") - 1, IS_LONG}, + {"float", sizeof("float") - 1, IS_DOUBLE}, + {"string", sizeof("string") - 1, IS_STRING}, + {"bool", sizeof("bool") - 1, _IS_BOOL}, + {"boolean", sizeof("boolean") - 1, _IS_BOOL}, + {NULL, 0, IS_UNDEF} +}; + +static void zend_assert_valid_class_name(const zend_string *const_name) +{ + const struct _scalar_typehint_info *info = &scalar_typehints[0]; + const char *end_slash = strrchr(const_name->val, '\\'); + zend_string *name = (zend_string*)const_name; + + if (end_slash) { + end_slash++; + name = zend_string_init(end_slash, strlen(end_slash), 0); + } + + while (info->name) { + if (name->len == info->name_len && zend_binary_strcasecmp(name->val, name->len, info->name, info->name_len) == 0) { + zend_error_noreturn(E_COMPILE_ERROR, "\"%s\" cannot be used as a class name", name->val); + } + info++; + } + + if (end_slash) { + zend_string_release(name); + } +} + #define DEBUG_ZEND 0 #define SET_UNUSED(op) op ## _type = IS_UNUSED diff --git a/Zend/zend_language_scanner.c b/Zend/zend_language_scanner.c index 99c25554874c8..8a869152b8c3d 100644 --- a/Zend/zend_language_scanner.c +++ b/Zend/zend_language_scanner.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 */ +/* Generated by re2c 0.13.7.5 */ #line 1 "Zend/zend_language_scanner.l" /* +----------------------------------------------------------------------+ @@ -1128,16 +1128,15 @@ int lex_scan(zval *zendlval) } /* *********************************** */ yyc_INITIAL: - - YYDEBUG(0, *YYCURSOR); + YYDEBUG(1, *YYCURSOR); YYFILL(7); yych = *YYCURSOR; - if (yych != '<') goto yy4; - YYDEBUG(2, *YYCURSOR); - ++YYCURSOR; - if ((yych = *YYCURSOR) == '?') goto yy5; -yy3: + if (yych != '<') goto yy5; YYDEBUG(3, *YYCURSOR); + ++YYCURSOR; + if ((yych = *YYCURSOR) == '?') goto yy6; +yy4: + YYDEBUG(4, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1766 "Zend/zend_language_scanner.l" { @@ -1184,23 +1183,23 @@ int lex_scan(zval *zendlval) HANDLE_NEWLINES(yytext, yyleng); return T_INLINE_HTML; } -#line 1188 "Zend/zend_language_scanner.c" -yy4: - YYDEBUG(4, *YYCURSOR); - yych = *++YYCURSOR; - goto yy3; +#line 1187 "Zend/zend_language_scanner.c" yy5: YYDEBUG(5, *YYCURSOR); + yych = *++YYCURSOR; + goto yy4; +yy6: + YYDEBUG(6, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= 'O') { - if (yych == '=') goto yy7; + if (yych == '=') goto yy8; } else { - if (yych <= 'P') goto yy9; - if (yych == 'p') goto yy9; + if (yych <= 'P') goto yy10; + if (yych == 'p') goto yy10; } -yy6: - YYDEBUG(6, *YYCURSOR); +yy7: + YYDEBUG(7, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1757 "Zend/zend_language_scanner.l" { @@ -1211,47 +1210,47 @@ int lex_scan(zval *zendlval) goto inline_char_handler; } } -#line 1215 "Zend/zend_language_scanner.c" -yy7: - YYDEBUG(7, *YYCURSOR); - ++YYCURSOR; +#line 1214 "Zend/zend_language_scanner.c" +yy8: YYDEBUG(8, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(9, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1744 "Zend/zend_language_scanner.l" { BEGIN(ST_IN_SCRIPTING); return T_OPEN_TAG_WITH_ECHO; } -#line 1226 "Zend/zend_language_scanner.c" -yy9: - YYDEBUG(9, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'H') goto yy11; - if (yych == 'h') goto yy11; +#line 1225 "Zend/zend_language_scanner.c" yy10: YYDEBUG(10, *YYCURSOR); - YYCURSOR = YYMARKER; - goto yy6; + yych = *++YYCURSOR; + if (yych == 'H') goto yy12; + if (yych == 'h') goto yy12; yy11: YYDEBUG(11, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'P') goto yy12; - if (yych != 'p') goto yy10; + YYCURSOR = YYMARKER; + goto yy7; yy12: YYDEBUG(12, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'P') goto yy13; + if (yych != 'p') goto yy11; +yy13: + YYDEBUG(13, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= '\f') { - if (yych <= 0x08) goto yy10; - if (yych >= '\v') goto yy10; + if (yych <= 0x08) goto yy11; + if (yych >= '\v') goto yy11; } else { - if (yych <= '\r') goto yy15; - if (yych != ' ') goto yy10; + if (yych <= '\r') goto yy16; + if (yych != ' ') goto yy11; } -yy13: - YYDEBUG(13, *YYCURSOR); - ++YYCURSOR; yy14: YYDEBUG(14, *YYCURSOR); + ++YYCURSOR; +yy15: + YYDEBUG(15, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1750 "Zend/zend_language_scanner.l" { @@ -1259,12 +1258,12 @@ int lex_scan(zval *zendlval) BEGIN(ST_IN_SCRIPTING); return T_OPEN_TAG; } -#line 1263 "Zend/zend_language_scanner.c" -yy15: - YYDEBUG(15, *YYCURSOR); +#line 1262 "Zend/zend_language_scanner.c" +yy16: + YYDEBUG(16, *YYCURSOR); ++YYCURSOR; - if ((yych = *YYCURSOR) == '\n') goto yy13; - goto yy14; + if ((yych = *YYCURSOR) == '\n') goto yy14; + goto yy15; /* *********************************** */ yyc_ST_BACKQUOTE: { @@ -1302,32 +1301,32 @@ int lex_scan(zval *zendlval) 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, }; - YYDEBUG(16, *YYCURSOR); + YYDEBUG(17, *YYCURSOR); YYFILL(2); yych = *YYCURSOR; if (yych <= '_') { - if (yych != '$') goto yy23; + if (yych != '$') goto yy24; } else { - if (yych <= '`') goto yy21; - if (yych == '{') goto yy20; - goto yy23; + if (yych <= '`') goto yy22; + if (yych == '{') goto yy21; + goto yy24; } - YYDEBUG(18, *YYCURSOR); + YYDEBUG(19, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '_') { - if (yych <= '@') goto yy19; - if (yych <= 'Z') goto yy26; - if (yych >= '_') goto yy26; + if (yych <= '@') goto yy20; + if (yych <= 'Z') goto yy27; + if (yych >= '_') goto yy27; } else { if (yych <= 'z') { - if (yych >= 'a') goto yy26; + if (yych >= 'a') goto yy27; } else { - if (yych <= '{') goto yy29; - if (yych >= 0x7F) goto yy26; + if (yych <= '{') goto yy30; + if (yych >= 0x7F) goto yy27; } } -yy19: - YYDEBUG(19, *YYCURSOR); +yy20: + YYDEBUG(20, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2176 "Zend/zend_language_scanner.l" { @@ -1370,31 +1369,31 @@ int lex_scan(zval *zendlval) zend_scan_escape_string(zendlval, yytext, yyleng, '`'); return T_ENCAPSED_AND_WHITESPACE; } -#line 1374 "Zend/zend_language_scanner.c" -yy20: - YYDEBUG(20, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '$') goto yy24; - goto yy19; +#line 1373 "Zend/zend_language_scanner.c" yy21: YYDEBUG(21, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych == '$') goto yy25; + goto yy20; +yy22: YYDEBUG(22, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(23, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2120 "Zend/zend_language_scanner.l" { BEGIN(ST_IN_SCRIPTING); return '`'; } -#line 1390 "Zend/zend_language_scanner.c" -yy23: - YYDEBUG(23, *YYCURSOR); - yych = *++YYCURSOR; - goto yy19; +#line 1389 "Zend/zend_language_scanner.c" yy24: YYDEBUG(24, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + goto yy20; +yy25: YYDEBUG(25, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(26, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2107 "Zend/zend_language_scanner.l" { @@ -1403,21 +1402,22 @@ int lex_scan(zval *zendlval) yyless(1); return T_CURLY_OPEN; } -#line 1407 "Zend/zend_language_scanner.c" -yy26: - YYDEBUG(26, *YYCURSOR); +#line 1406 "Zend/zend_language_scanner.c" +yy27: + YYDEBUG(27, *YYCURSOR); yyaccept = 0; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(27, *YYCURSOR); + YYDEBUG(28, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy26; + goto yy27; } - if (yych == '-') goto yy31; - if (yych == '[') goto yy33; -yy28: - YYDEBUG(28, *YYCURSOR); + if (yych == '-') goto yy32; + if (yych <= '@') goto yy29; + if (yych <= '[') goto yy34; +yy29: + YYDEBUG(29, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1831 "Zend/zend_language_scanner.l" { @@ -1425,10 +1425,10 @@ int lex_scan(zval *zendlval) return T_VARIABLE; } #line 1428 "Zend/zend_language_scanner.c" -yy29: - YYDEBUG(29, *YYCURSOR); - ++YYCURSOR; +yy30: YYDEBUG(30, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(31, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1555 "Zend/zend_language_scanner.l" { @@ -1436,18 +1436,18 @@ int lex_scan(zval *zendlval) return T_DOLLAR_OPEN_CURLY_BRACES; } #line 1439 "Zend/zend_language_scanner.c" -yy31: - YYDEBUG(31, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '>') goto yy35; yy32: YYDEBUG(32, *YYCURSOR); - YYCURSOR = YYMARKER; - goto yy28; + yych = *++YYCURSOR; + if (yych == '>') goto yy36; yy33: YYDEBUG(33, *YYCURSOR); - ++YYCURSOR; + YYCURSOR = YYMARKER; + goto yy29; +yy34: YYDEBUG(34, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(35, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1824 "Zend/zend_language_scanner.l" { @@ -1457,22 +1457,22 @@ int lex_scan(zval *zendlval) return T_VARIABLE; } #line 1460 "Zend/zend_language_scanner.c" -yy35: - YYDEBUG(35, *YYCURSOR); +yy36: + YYDEBUG(36, *YYCURSOR); yych = *++YYCURSOR; if (yych <= '_') { - if (yych <= '@') goto yy32; - if (yych <= 'Z') goto yy36; - if (yych <= '^') goto yy32; + if (yych <= '@') goto yy33; + if (yych <= 'Z') goto yy37; + if (yych <= '^') goto yy33; } else { - if (yych <= '`') goto yy32; - if (yych <= 'z') goto yy36; - if (yych <= '~') goto yy32; + if (yych <= '`') goto yy33; + if (yych <= 'z') goto yy37; + if (yych <= '~') goto yy33; } -yy36: - YYDEBUG(36, *YYCURSOR); - ++YYCURSOR; +yy37: YYDEBUG(37, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(38, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1815 "Zend/zend_language_scanner.l" { @@ -1520,34 +1520,34 @@ int lex_scan(zval *zendlval) 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, }; - YYDEBUG(38, *YYCURSOR); + YYDEBUG(39, *YYCURSOR); YYFILL(2); yych = *YYCURSOR; if (yych <= '#') { - if (yych == '"') goto yy43; - goto yy45; + if (yych == '"') goto yy44; + goto yy46; } else { - if (yych <= '$') goto yy40; - if (yych == '{') goto yy42; - goto yy45; + if (yych <= '$') goto yy41; + if (yych == '{') goto yy43; + goto yy46; } -yy40: - YYDEBUG(40, *YYCURSOR); +yy41: + YYDEBUG(41, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '_') { - if (yych <= '@') goto yy41; - if (yych <= 'Z') goto yy48; - if (yych >= '_') goto yy48; + if (yych <= '@') goto yy42; + if (yych <= 'Z') goto yy49; + if (yych >= '_') goto yy49; } else { if (yych <= 'z') { - if (yych >= 'a') goto yy48; + if (yych >= 'a') goto yy49; } else { - if (yych <= '{') goto yy51; - if (yych >= 0x7F) goto yy48; + if (yych <= '{') goto yy52; + if (yych >= 0x7F) goto yy49; } } -yy41: - YYDEBUG(41, *YYCURSOR); +yy42: + YYDEBUG(42, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2126 "Zend/zend_language_scanner.l" { @@ -1599,15 +1599,15 @@ int lex_scan(zval *zendlval) return T_ENCAPSED_AND_WHITESPACE; } #line 1602 "Zend/zend_language_scanner.c" -yy42: - YYDEBUG(42, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '$') goto yy46; - goto yy41; yy43: YYDEBUG(43, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych == '$') goto yy47; + goto yy42; +yy44: YYDEBUG(44, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(45, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2115 "Zend/zend_language_scanner.l" { @@ -1615,14 +1615,14 @@ int lex_scan(zval *zendlval) return '"'; } #line 1618 "Zend/zend_language_scanner.c" -yy45: - YYDEBUG(45, *YYCURSOR); - yych = *++YYCURSOR; - goto yy41; yy46: YYDEBUG(46, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + goto yy42; +yy47: YYDEBUG(47, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(48, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2107 "Zend/zend_language_scanner.l" { @@ -1632,50 +1632,51 @@ int lex_scan(zval *zendlval) return T_CURLY_OPEN; } #line 1635 "Zend/zend_language_scanner.c" -yy48: - YYDEBUG(48, *YYCURSOR); +yy49: + YYDEBUG(49, *YYCURSOR); yyaccept = 0; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(49, *YYCURSOR); + YYDEBUG(50, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy48; + goto yy49; } - if (yych == '-') goto yy53; - if (yych == '[') goto yy55; -yy50: - YYDEBUG(50, *YYCURSOR); + if (yych == '-') goto yy54; + if (yych <= '@') goto yy51; + if (yych <= '[') goto yy56; +yy51: + YYDEBUG(51, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1831 "Zend/zend_language_scanner.l" { zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 1656 "Zend/zend_language_scanner.c" -yy51: - YYDEBUG(51, *YYCURSOR); - ++YYCURSOR; +#line 1657 "Zend/zend_language_scanner.c" +yy52: YYDEBUG(52, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(53, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1555 "Zend/zend_language_scanner.l" { yy_push_state(ST_LOOKING_FOR_VARNAME); return T_DOLLAR_OPEN_CURLY_BRACES; } -#line 1667 "Zend/zend_language_scanner.c" -yy53: - YYDEBUG(53, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '>') goto yy57; +#line 1668 "Zend/zend_language_scanner.c" yy54: YYDEBUG(54, *YYCURSOR); - YYCURSOR = YYMARKER; - goto yy50; + yych = *++YYCURSOR; + if (yych == '>') goto yy58; yy55: YYDEBUG(55, *YYCURSOR); - ++YYCURSOR; + YYCURSOR = YYMARKER; + goto yy51; +yy56: YYDEBUG(56, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(57, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1824 "Zend/zend_language_scanner.l" { @@ -1684,23 +1685,23 @@ int lex_scan(zval *zendlval) zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 1688 "Zend/zend_language_scanner.c" -yy57: - YYDEBUG(57, *YYCURSOR); +#line 1689 "Zend/zend_language_scanner.c" +yy58: + YYDEBUG(58, *YYCURSOR); yych = *++YYCURSOR; if (yych <= '_') { - if (yych <= '@') goto yy54; - if (yych <= 'Z') goto yy58; - if (yych <= '^') goto yy54; + if (yych <= '@') goto yy55; + if (yych <= 'Z') goto yy59; + if (yych <= '^') goto yy55; } else { - if (yych <= '`') goto yy54; - if (yych <= 'z') goto yy58; - if (yych <= '~') goto yy54; + if (yych <= '`') goto yy55; + if (yych <= 'z') goto yy59; + if (yych <= '~') goto yy55; } -yy58: - YYDEBUG(58, *YYCURSOR); - ++YYCURSOR; +yy59: YYDEBUG(59, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(60, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1815 "Zend/zend_language_scanner.l" { @@ -1709,16 +1710,16 @@ int lex_scan(zval *zendlval) zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 1713 "Zend/zend_language_scanner.c" +#line 1714 "Zend/zend_language_scanner.c" } /* *********************************** */ yyc_ST_END_HEREDOC: - YYDEBUG(60, *YYCURSOR); + YYDEBUG(61, *YYCURSOR); YYFILL(1); yych = *YYCURSOR; - YYDEBUG(62, *YYCURSOR); - ++YYCURSOR; YYDEBUG(63, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(64, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2093 "Zend/zend_language_scanner.l" { @@ -1733,7 +1734,7 @@ int lex_scan(zval *zendlval) BEGIN(ST_IN_SCRIPTING); return T_END_HEREDOC; } -#line 1737 "Zend/zend_language_scanner.c" +#line 1738 "Zend/zend_language_scanner.c" /* *********************************** */ yyc_ST_HEREDOC: { @@ -1771,29 +1772,29 @@ int lex_scan(zval *zendlval) 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, }; - YYDEBUG(64, *YYCURSOR); + YYDEBUG(65, *YYCURSOR); YYFILL(2); yych = *YYCURSOR; - if (yych == '$') goto yy66; - if (yych == '{') goto yy68; - goto yy69; -yy66: - YYDEBUG(66, *YYCURSOR); + if (yych == '$') goto yy67; + if (yych == '{') goto yy69; + goto yy70; +yy67: + YYDEBUG(67, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '_') { - if (yych <= '@') goto yy67; - if (yych <= 'Z') goto yy72; - if (yych >= '_') goto yy72; + if (yych <= '@') goto yy68; + if (yych <= 'Z') goto yy73; + if (yych >= '_') goto yy73; } else { if (yych <= 'z') { - if (yych >= 'a') goto yy72; + if (yych >= 'a') goto yy73; } else { - if (yych <= '{') goto yy75; - if (yych >= 0x7F) goto yy72; + if (yych <= '{') goto yy76; + if (yych >= 0x7F) goto yy73; } } -yy67: - YYDEBUG(67, *YYCURSOR); +yy68: + YYDEBUG(68, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2218 "Zend/zend_language_scanner.l" { @@ -1868,20 +1869,20 @@ int lex_scan(zval *zendlval) zend_scan_escape_string(zendlval, yytext, yyleng - newline, 0); return T_ENCAPSED_AND_WHITESPACE; } -#line 1872 "Zend/zend_language_scanner.c" -yy68: - YYDEBUG(68, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '$') goto yy70; - goto yy67; +#line 1873 "Zend/zend_language_scanner.c" yy69: YYDEBUG(69, *YYCURSOR); yych = *++YYCURSOR; - goto yy67; + if (yych == '$') goto yy71; + goto yy68; yy70: YYDEBUG(70, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + goto yy68; +yy71: YYDEBUG(71, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(72, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2107 "Zend/zend_language_scanner.l" { @@ -1890,51 +1891,52 @@ int lex_scan(zval *zendlval) yyless(1); return T_CURLY_OPEN; } -#line 1894 "Zend/zend_language_scanner.c" -yy72: - YYDEBUG(72, *YYCURSOR); +#line 1895 "Zend/zend_language_scanner.c" +yy73: + YYDEBUG(73, *YYCURSOR); yyaccept = 0; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(73, *YYCURSOR); + YYDEBUG(74, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy72; + goto yy73; } - if (yych == '-') goto yy77; - if (yych == '[') goto yy79; -yy74: - YYDEBUG(74, *YYCURSOR); + if (yych == '-') goto yy78; + if (yych <= '@') goto yy75; + if (yych <= '[') goto yy80; +yy75: + YYDEBUG(75, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1831 "Zend/zend_language_scanner.l" { zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 1915 "Zend/zend_language_scanner.c" -yy75: - YYDEBUG(75, *YYCURSOR); - ++YYCURSOR; +#line 1917 "Zend/zend_language_scanner.c" +yy76: YYDEBUG(76, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(77, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1555 "Zend/zend_language_scanner.l" { yy_push_state(ST_LOOKING_FOR_VARNAME); return T_DOLLAR_OPEN_CURLY_BRACES; } -#line 1926 "Zend/zend_language_scanner.c" -yy77: - YYDEBUG(77, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '>') goto yy81; +#line 1928 "Zend/zend_language_scanner.c" yy78: YYDEBUG(78, *YYCURSOR); - YYCURSOR = YYMARKER; - goto yy74; + yych = *++YYCURSOR; + if (yych == '>') goto yy82; yy79: YYDEBUG(79, *YYCURSOR); - ++YYCURSOR; + YYCURSOR = YYMARKER; + goto yy75; +yy80: YYDEBUG(80, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(81, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1824 "Zend/zend_language_scanner.l" { @@ -1943,23 +1945,23 @@ int lex_scan(zval *zendlval) zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 1947 "Zend/zend_language_scanner.c" -yy81: - YYDEBUG(81, *YYCURSOR); +#line 1949 "Zend/zend_language_scanner.c" +yy82: + YYDEBUG(82, *YYCURSOR); yych = *++YYCURSOR; if (yych <= '_') { - if (yych <= '@') goto yy78; - if (yych <= 'Z') goto yy82; - if (yych <= '^') goto yy78; + if (yych <= '@') goto yy79; + if (yych <= 'Z') goto yy83; + if (yych <= '^') goto yy79; } else { - if (yych <= '`') goto yy78; - if (yych <= 'z') goto yy82; - if (yych <= '~') goto yy78; + if (yych <= '`') goto yy79; + if (yych <= 'z') goto yy83; + if (yych <= '~') goto yy79; } -yy82: - YYDEBUG(82, *YYCURSOR); - ++YYCURSOR; +yy83: YYDEBUG(83, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(84, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1815 "Zend/zend_language_scanner.l" { @@ -1968,7 +1970,7 @@ int lex_scan(zval *zendlval) zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 1972 "Zend/zend_language_scanner.c" +#line 1974 "Zend/zend_language_scanner.c" } /* *********************************** */ yyc_ST_IN_SCRIPTING: @@ -2007,7 +2009,7 @@ int lex_scan(zval *zendlval) 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, }; - YYDEBUG(84, *YYCURSOR); + YYDEBUG(85, *YYCURSOR); YYFILL(16); yych = *YYCURSOR; YYDEBUG(-1, yych); @@ -2040,32 +2042,32 @@ int lex_scan(zval *zendlval) case 0x1C: case 0x1D: case 0x1E: - case 0x1F: goto yy147; + case 0x1F: goto yy148; case '\t': case '\n': case '\r': - case ' ': goto yy103; - case '!': goto yy118; - case '"': goto yy143; - case '#': goto yy139; - case '$': goto yy129; - case '%': goto yy123; - case '&': goto yy124; - case '\'': goto yy141; - case '(': goto yy112; + case ' ': goto yy104; + case '!': goto yy119; + case '"': goto yy144; + case '#': goto yy140; + case '$': goto yy130; + case '%': goto yy124; + case '&': goto yy125; + case '\'': goto yy142; + case '(': goto yy113; case ')': case ',': case ';': case '@': case '[': case ']': - case '~': goto yy130; - case '*': goto yy121; - case '+': goto yy117; - case '-': goto yy101; - case '.': goto yy108; - case '/': goto yy122; - case '0': goto yy135; + case '~': goto yy131; + case '*': goto yy122; + case '+': goto yy118; + case '-': goto yy102; + case '.': goto yy109; + case '/': goto yy123; + case '0': goto yy136; case '1': case '2': case '3': @@ -2074,592 +2076,592 @@ int lex_scan(zval *zendlval) case '6': case '7': case '8': - case '9': goto yy137; - case ':': goto yy105; - case '<': goto yy119; - case '=': goto yy115; - case '>': goto yy120; - case '?': goto yy109; + case '9': goto yy138; + case ':': goto yy106; + case '<': goto yy120; + case '=': goto yy116; + case '>': goto yy121; + case '?': goto yy110; case 'A': - case 'a': goto yy96; + case 'a': goto yy97; case 'B': - case 'b': goto yy98; + case 'b': goto yy99; case 'C': - case 'c': goto yy90; + case 'c': goto yy91; case 'D': - case 'd': goto yy88; + case 'd': goto yy89; case 'E': - case 'e': goto yy86; + case 'e': goto yy87; case 'F': - case 'f': goto yy89; + case 'f': goto yy90; case 'G': - case 'g': goto yy99; + case 'g': goto yy100; case 'I': - case 'i': goto yy94; + case 'i': goto yy95; case 'L': - case 'l': goto yy116; + case 'l': goto yy117; case 'N': - case 'n': goto yy110; + case 'n': goto yy111; case 'O': - case 'o': goto yy127; + case 'o': goto yy128; case 'P': - case 'p': goto yy100; + case 'p': goto yy101; case 'R': - case 'r': goto yy91; + case 'r': goto yy92; case 'S': - case 's': goto yy97; + case 's': goto yy98; case 'T': - case 't': goto yy93; + case 't': goto yy94; case 'U': - case 'u': goto yy113; + case 'u': goto yy114; case 'V': - case 'v': goto yy111; + case 'v': goto yy112; case 'W': - case 'w': goto yy95; + case 'w': goto yy96; case 'X': - case 'x': goto yy128; + case 'x': goto yy129; case 'Y': - case 'y': goto yy92; - case '\\': goto yy106; - case '^': goto yy126; - case '_': goto yy114; - case '`': goto yy145; - case '{': goto yy131; - case '|': goto yy125; - case '}': goto yy133; - default: goto yy138; - } -yy86: - YYDEBUG(86, *YYCURSOR); + case 'y': goto yy93; + case '\\': goto yy107; + case '^': goto yy127; + case '_': goto yy115; + case '`': goto yy146; + case '{': goto yy132; + case '|': goto yy126; + case '}': goto yy134; + default: goto yy139; + } +yy87: + YYDEBUG(87, *YYCURSOR); ++YYCURSOR; YYDEBUG(-1, yych); switch ((yych = *YYCURSOR)) { case 'C': - case 'c': goto yy695; + case 'c': goto yy696; case 'L': - case 'l': goto yy696; + case 'l': goto yy697; case 'M': - case 'm': goto yy697; + case 'm': goto yy698; case 'N': - case 'n': goto yy698; + case 'n': goto yy699; case 'V': - case 'v': goto yy699; + case 'v': goto yy700; case 'X': - case 'x': goto yy700; - default: goto yy150; + case 'x': goto yy701; + default: goto yy151; } -yy87: - YYDEBUG(87, *YYCURSOR); +yy88: + YYDEBUG(88, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1854 "Zend/zend_language_scanner.l" { zend_copy_value(zendlval, yytext, yyleng); return T_STRING; } -#line 2160 "Zend/zend_language_scanner.c" -yy88: - YYDEBUG(88, *YYCURSOR); +#line 2162 "Zend/zend_language_scanner.c" +yy89: + YYDEBUG(89, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'O') { if (yych <= 'H') { - if (yych == 'E') goto yy677; - goto yy150; + if (yych == 'E') goto yy678; + goto yy151; } else { - if (yych <= 'I') goto yy678; - if (yych <= 'N') goto yy150; - goto yy679; + if (yych <= 'I') goto yy679; + if (yych <= 'N') goto yy151; + goto yy680; } } else { if (yych <= 'h') { - if (yych == 'e') goto yy677; - goto yy150; + if (yych == 'e') goto yy678; + goto yy151; } else { - if (yych <= 'i') goto yy678; - if (yych == 'o') goto yy679; - goto yy150; + if (yych <= 'i') goto yy679; + if (yych == 'o') goto yy680; + goto yy151; } } -yy89: - YYDEBUG(89, *YYCURSOR); +yy90: + YYDEBUG(90, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'U') { if (yych <= 'N') { - if (yych == 'I') goto yy653; - goto yy150; + if (yych == 'I') goto yy654; + goto yy151; } else { - if (yych <= 'O') goto yy654; - if (yych <= 'T') goto yy150; - goto yy655; + if (yych <= 'O') goto yy655; + if (yych <= 'T') goto yy151; + goto yy656; } } else { if (yych <= 'n') { - if (yych == 'i') goto yy653; - goto yy150; + if (yych == 'i') goto yy654; + goto yy151; } else { - if (yych <= 'o') goto yy654; - if (yych == 'u') goto yy655; - goto yy150; + if (yych <= 'o') goto yy655; + if (yych == 'u') goto yy656; + goto yy151; } } -yy90: - YYDEBUG(90, *YYCURSOR); +yy91: + YYDEBUG(91, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'O') { if (yych <= 'K') { - if (yych == 'A') goto yy618; - goto yy150; + if (yych == 'A') goto yy619; + goto yy151; } else { - if (yych <= 'L') goto yy619; - if (yych <= 'N') goto yy150; - goto yy620; + if (yych <= 'L') goto yy620; + if (yych <= 'N') goto yy151; + goto yy621; } } else { if (yych <= 'k') { - if (yych == 'a') goto yy618; - goto yy150; + if (yych == 'a') goto yy619; + goto yy151; } else { - if (yych <= 'l') goto yy619; - if (yych == 'o') goto yy620; - goto yy150; + if (yych <= 'l') goto yy620; + if (yych == 'o') goto yy621; + goto yy151; } } -yy91: - YYDEBUG(91, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy600; - if (yych == 'e') goto yy600; - goto yy150; yy92: YYDEBUG(92, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy595; - if (yych == 'i') goto yy595; - goto yy150; + if (yych == 'E') goto yy601; + if (yych == 'e') goto yy601; + goto yy151; yy93: YYDEBUG(93, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'I') goto yy596; + if (yych == 'i') goto yy596; + goto yy151; +yy94: + YYDEBUG(94, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'R') { - if (yych == 'H') goto yy583; - if (yych <= 'Q') goto yy150; - goto yy584; + if (yych == 'H') goto yy584; + if (yych <= 'Q') goto yy151; + goto yy585; } else { if (yych <= 'h') { - if (yych <= 'g') goto yy150; - goto yy583; + if (yych <= 'g') goto yy151; + goto yy584; } else { - if (yych == 'r') goto yy584; - goto yy150; + if (yych == 'r') goto yy585; + goto yy151; } } -yy94: - YYDEBUG(94, *YYCURSOR); +yy95: + YYDEBUG(95, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'S') { if (yych <= 'L') { - if (yych == 'F') goto yy530; - goto yy150; + if (yych == 'F') goto yy531; + goto yy151; } else { - if (yych <= 'M') goto yy532; - if (yych <= 'N') goto yy533; - if (yych <= 'R') goto yy150; - goto yy534; + if (yych <= 'M') goto yy533; + if (yych <= 'N') goto yy534; + if (yych <= 'R') goto yy151; + goto yy535; } } else { if (yych <= 'm') { - if (yych == 'f') goto yy530; - if (yych <= 'l') goto yy150; - goto yy532; + if (yych == 'f') goto yy531; + if (yych <= 'l') goto yy151; + goto yy533; } else { - if (yych <= 'n') goto yy533; - if (yych == 's') goto yy534; - goto yy150; + if (yych <= 'n') goto yy534; + if (yych == 's') goto yy535; + goto yy151; } } -yy95: - YYDEBUG(95, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'H') goto yy525; - if (yych == 'h') goto yy525; - goto yy150; yy96: YYDEBUG(96, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'H') goto yy526; + if (yych == 'h') goto yy526; + goto yy151; +yy97: + YYDEBUG(97, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'S') { if (yych <= 'M') { - if (yych == 'B') goto yy507; - goto yy150; + if (yych == 'B') goto yy508; + goto yy151; } else { - if (yych <= 'N') goto yy508; - if (yych <= 'Q') goto yy150; - if (yych <= 'R') goto yy509; - goto yy510; + if (yych <= 'N') goto yy509; + if (yych <= 'Q') goto yy151; + if (yych <= 'R') goto yy510; + goto yy511; } } else { if (yych <= 'n') { - if (yych == 'b') goto yy507; - if (yych <= 'm') goto yy150; - goto yy508; + if (yych == 'b') goto yy508; + if (yych <= 'm') goto yy151; + goto yy509; } else { - if (yych <= 'q') goto yy150; - if (yych <= 'r') goto yy509; - if (yych <= 's') goto yy510; - goto yy150; + if (yych <= 'q') goto yy151; + if (yych <= 'r') goto yy510; + if (yych <= 's') goto yy511; + goto yy151; } } -yy97: - YYDEBUG(97, *YYCURSOR); +yy98: + YYDEBUG(98, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'W') { - if (yych == 'T') goto yy495; - if (yych <= 'V') goto yy150; - goto yy496; + if (yych == 'T') goto yy496; + if (yych <= 'V') goto yy151; + goto yy497; } else { if (yych <= 't') { - if (yych <= 's') goto yy150; - goto yy495; + if (yych <= 's') goto yy151; + goto yy496; } else { - if (yych == 'w') goto yy496; - goto yy150; + if (yych == 'w') goto yy497; + goto yy151; } } -yy98: - YYDEBUG(98, *YYCURSOR); +yy99: + YYDEBUG(99, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= ';') { if (yych <= '"') { - if (yych <= '!') goto yy150; - goto yy487; + if (yych <= '!') goto yy151; + goto yy488; } else { - if (yych == '\'') goto yy488; - goto yy150; + if (yych == '\'') goto yy489; + goto yy151; } } else { if (yych <= 'R') { - if (yych <= '<') goto yy486; - if (yych <= 'Q') goto yy150; - goto yy489; + if (yych <= '<') goto yy487; + if (yych <= 'Q') goto yy151; + goto yy490; } else { - if (yych == 'r') goto yy489; - goto yy150; + if (yych == 'r') goto yy490; + goto yy151; } } -yy99: - YYDEBUG(99, *YYCURSOR); +yy100: + YYDEBUG(100, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'O') { - if (yych == 'L') goto yy476; - if (yych <= 'N') goto yy150; - goto yy477; + if (yych == 'L') goto yy477; + if (yych <= 'N') goto yy151; + goto yy478; } else { if (yych <= 'l') { - if (yych <= 'k') goto yy150; - goto yy476; + if (yych <= 'k') goto yy151; + goto yy477; } else { - if (yych == 'o') goto yy477; - goto yy150; + if (yych == 'o') goto yy478; + goto yy151; } } -yy100: - YYDEBUG(100, *YYCURSOR); +yy101: + YYDEBUG(101, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'U') { - if (yych == 'R') goto yy452; - if (yych <= 'T') goto yy150; - goto yy453; + if (yych == 'R') goto yy453; + if (yych <= 'T') goto yy151; + goto yy454; } else { if (yych <= 'r') { - if (yych <= 'q') goto yy150; - goto yy452; + if (yych <= 'q') goto yy151; + goto yy453; } else { - if (yych == 'u') goto yy453; - goto yy150; + if (yych == 'u') goto yy454; + goto yy151; } } -yy101: - YYDEBUG(101, *YYCURSOR); +yy102: + YYDEBUG(102, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '<') { - if (yych == '-') goto yy448; + if (yych == '-') goto yy449; } else { - if (yych <= '=') goto yy446; - if (yych <= '>') goto yy450; + if (yych <= '=') goto yy447; + if (yych <= '>') goto yy451; } -yy102: - YYDEBUG(102, *YYCURSOR); +yy103: + YYDEBUG(103, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1544 "Zend/zend_language_scanner.l" { return yytext[0]; } -#line 2396 "Zend/zend_language_scanner.c" -yy103: - YYDEBUG(103, *YYCURSOR); - ++YYCURSOR; - yych = *YYCURSOR; - goto yy445; +#line 2398 "Zend/zend_language_scanner.c" yy104: YYDEBUG(104, *YYCURSOR); + ++YYCURSOR; + yych = *YYCURSOR; + goto yy446; +yy105: + YYDEBUG(105, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1263 "Zend/zend_language_scanner.l" { HANDLE_NEWLINES(yytext, yyleng); return T_WHITESPACE; } -#line 2410 "Zend/zend_language_scanner.c" -yy105: - YYDEBUG(105, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == ':') goto yy442; - goto yy102; +#line 2412 "Zend/zend_language_scanner.c" yy106: YYDEBUG(106, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych == ':') goto yy443; + goto yy103; +yy107: YYDEBUG(107, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(108, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1288 "Zend/zend_language_scanner.l" { return T_NS_SEPARATOR; } -#line 2425 "Zend/zend_language_scanner.c" -yy108: - YYDEBUG(108, *YYCURSOR); +#line 2427 "Zend/zend_language_scanner.c" +yy109: + YYDEBUG(109, *YYCURSOR); yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); if (yych <= '/') { - if (yych == '.') goto yy439; - goto yy102; + if (yych == '.') goto yy440; + goto yy103; } else { - if (yych <= '9') goto yy435; - if (yych == '=') goto yy437; - goto yy102; + if (yych <= '9') goto yy436; + if (yych == '=') goto yy438; + goto yy103; } -yy109: - YYDEBUG(109, *YYCURSOR); - yych = *++YYCURSOR; - if (yych <= '=') goto yy102; - if (yych <= '>') goto yy429; - if (yych <= '?') goto yy431; - goto yy102; yy110: YYDEBUG(110, *YYCURSOR); yych = *++YYCURSOR; + if (yych <= '=') goto yy103; + if (yych <= '>') goto yy430; + if (yych <= '?') goto yy432; + goto yy103; +yy111: + YYDEBUG(111, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'E') { - if (yych == 'A') goto yy417; - if (yych <= 'D') goto yy150; - goto yy418; + if (yych == 'A') goto yy418; + if (yych <= 'D') goto yy151; + goto yy419; } else { if (yych <= 'a') { - if (yych <= '`') goto yy150; - goto yy417; + if (yych <= '`') goto yy151; + goto yy418; } else { - if (yych == 'e') goto yy418; - goto yy150; + if (yych == 'e') goto yy419; + goto yy151; } } -yy111: - YYDEBUG(111, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy414; - if (yych == 'a') goto yy414; - goto yy150; yy112: YYDEBUG(112, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'A') goto yy415; + if (yych == 'a') goto yy415; + goto yy151; +yy113: + YYDEBUG(113, *YYCURSOR); yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); if (yych <= 'S') { if (yych <= 'D') { if (yych <= ' ') { - if (yych == '\t') goto yy339; - if (yych <= 0x1F) goto yy102; - goto yy339; + if (yych == '\t') goto yy340; + if (yych <= 0x1F) goto yy103; + goto yy340; } else { - if (yych <= '@') goto yy102; - if (yych == 'C') goto yy102; - goto yy339; + if (yych <= '@') goto yy103; + if (yych == 'C') goto yy103; + goto yy340; } } else { if (yych <= 'I') { - if (yych == 'F') goto yy339; - if (yych <= 'H') goto yy102; - goto yy339; + if (yych == 'F') goto yy340; + if (yych <= 'H') goto yy103; + goto yy340; } else { - if (yych == 'O') goto yy339; - if (yych <= 'Q') goto yy102; - goto yy339; + if (yych == 'O') goto yy340; + if (yych <= 'Q') goto yy103; + goto yy340; } } } else { if (yych <= 'f') { if (yych <= 'b') { - if (yych == 'U') goto yy339; - if (yych <= '`') goto yy102; - goto yy339; + if (yych == 'U') goto yy340; + if (yych <= '`') goto yy103; + goto yy340; } else { - if (yych == 'd') goto yy339; - if (yych <= 'e') goto yy102; - goto yy339; + if (yych == 'd') goto yy340; + if (yych <= 'e') goto yy103; + goto yy340; } } else { if (yych <= 'o') { - if (yych == 'i') goto yy339; - if (yych <= 'n') goto yy102; - goto yy339; + if (yych == 'i') goto yy340; + if (yych <= 'n') goto yy103; + goto yy340; } else { if (yych <= 's') { - if (yych <= 'q') goto yy102; - goto yy339; + if (yych <= 'q') goto yy103; + goto yy340; } else { - if (yych == 'u') goto yy339; - goto yy102; + if (yych == 'u') goto yy340; + goto yy103; } } } } -yy113: - YYDEBUG(113, *YYCURSOR); +yy114: + YYDEBUG(114, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'S') { - if (yych == 'N') goto yy330; - if (yych <= 'R') goto yy150; - goto yy331; + if (yych == 'N') goto yy331; + if (yych <= 'R') goto yy151; + goto yy332; } else { if (yych <= 'n') { - if (yych <= 'm') goto yy150; - goto yy330; + if (yych <= 'm') goto yy151; + goto yy331; } else { - if (yych == 's') goto yy331; - goto yy150; + if (yych == 's') goto yy332; + goto yy151; } } -yy114: - YYDEBUG(114, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '_') goto yy248; - goto yy150; yy115: YYDEBUG(115, *YYCURSOR); yych = *++YYCURSOR; - if (yych <= '<') goto yy102; - if (yych <= '=') goto yy242; - if (yych <= '>') goto yy244; - goto yy102; + if (yych == '_') goto yy249; + goto yy151; yy116: YYDEBUG(116, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy238; - if (yych == 'i') goto yy238; - goto yy150; + if (yych <= '<') goto yy103; + if (yych <= '=') goto yy243; + if (yych <= '>') goto yy245; + goto yy103; yy117: YYDEBUG(117, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '+') goto yy236; - if (yych == '=') goto yy234; - goto yy102; + if (yych == 'I') goto yy239; + if (yych == 'i') goto yy239; + goto yy151; yy118: YYDEBUG(118, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '=') goto yy231; - goto yy102; + if (yych == '+') goto yy237; + if (yych == '=') goto yy235; + goto yy103; yy119: YYDEBUG(119, *YYCURSOR); yych = *++YYCURSOR; - if (yych <= ';') goto yy102; - if (yych <= '<') goto yy209; - if (yych <= '=') goto yy211; - if (yych <= '>') goto yy213; - goto yy102; + if (yych == '=') goto yy232; + goto yy103; yy120: YYDEBUG(120, *YYCURSOR); yych = *++YYCURSOR; - if (yych <= '<') goto yy102; - if (yych <= '=') goto yy205; - if (yych <= '>') goto yy203; - goto yy102; + if (yych <= ';') goto yy103; + if (yych <= '<') goto yy210; + if (yych <= '=') goto yy212; + if (yych <= '>') goto yy214; + goto yy103; yy121: YYDEBUG(121, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '*') goto yy197; - if (yych == '=') goto yy199; - goto yy102; + if (yych <= '<') goto yy103; + if (yych <= '=') goto yy206; + if (yych <= '>') goto yy204; + goto yy103; yy122: YYDEBUG(122, *YYCURSOR); yych = *++YYCURSOR; - if (yych <= '.') { - if (yych == '*') goto yy189; - goto yy102; - } else { - if (yych <= '/') goto yy191; - if (yych == '=') goto yy192; - goto yy102; - } + if (yych == '*') goto yy198; + if (yych == '=') goto yy200; + goto yy103; yy123: YYDEBUG(123, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '=') goto yy187; - goto yy102; + if (yych <= '.') { + if (yych == '*') goto yy190; + goto yy103; + } else { + if (yych <= '/') goto yy192; + if (yych == '=') goto yy193; + goto yy103; + } yy124: YYDEBUG(124, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '&') goto yy183; - if (yych == '=') goto yy185; - goto yy102; + if (yych == '=') goto yy188; + goto yy103; yy125: YYDEBUG(125, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '=') goto yy181; - if (yych == '|') goto yy179; - goto yy102; + if (yych == '&') goto yy184; + if (yych == '=') goto yy186; + goto yy103; yy126: YYDEBUG(126, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '=') goto yy177; - goto yy102; + if (yych == '=') goto yy182; + if (yych == '|') goto yy180; + goto yy103; yy127: YYDEBUG(127, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy175; - if (yych == 'r') goto yy175; - goto yy150; + if (yych == '=') goto yy178; + goto yy103; yy128: YYDEBUG(128, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy172; - if (yych == 'o') goto yy172; - goto yy150; + if (yych == 'R') goto yy176; + if (yych == 'r') goto yy176; + goto yy151; yy129: YYDEBUG(129, *YYCURSOR); yych = *++YYCURSOR; - if (yych <= '_') { - if (yych <= '@') goto yy102; - if (yych <= 'Z') goto yy169; - if (yych <= '^') goto yy102; - goto yy169; - } else { - if (yych <= '`') goto yy102; - if (yych <= 'z') goto yy169; - if (yych <= '~') goto yy102; - goto yy169; - } + if (yych == 'O') goto yy173; + if (yych == 'o') goto yy173; + goto yy151; yy130: YYDEBUG(130, *YYCURSOR); yych = *++YYCURSOR; - goto yy102; + if (yych <= '_') { + if (yych <= '@') goto yy103; + if (yych <= 'Z') goto yy170; + if (yych <= '^') goto yy103; + goto yy170; + } else { + if (yych <= '`') goto yy103; + if (yych <= 'z') goto yy170; + if (yych <= '~') goto yy103; + goto yy170; + } yy131: YYDEBUG(131, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + goto yy103; +yy132: YYDEBUG(132, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(133, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1549 "Zend/zend_language_scanner.l" { yy_push_state(ST_IN_SCRIPTING); return '{'; } -#line 2659 "Zend/zend_language_scanner.c" -yy133: - YYDEBUG(133, *YYCURSOR); - ++YYCURSOR; +#line 2661 "Zend/zend_language_scanner.c" +yy134: YYDEBUG(134, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(135, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1561 "Zend/zend_language_scanner.l" { @@ -2669,33 +2671,33 @@ int lex_scan(zval *zendlval) } return '}'; } -#line 2673 "Zend/zend_language_scanner.c" -yy135: - YYDEBUG(135, *YYCURSOR); +#line 2675 "Zend/zend_language_scanner.c" +yy136: + YYDEBUG(136, *YYCURSOR); yyaccept = 2; yych = *(YYMARKER = ++YYCURSOR); if (yych <= 'E') { if (yych <= '9') { - if (yych == '.') goto yy151; - if (yych >= '0') goto yy154; + if (yych == '.') goto yy152; + if (yych >= '0') goto yy155; } else { - if (yych == 'B') goto yy162; - if (yych >= 'E') goto yy156; + if (yych == 'B') goto yy163; + if (yych >= 'E') goto yy157; } } else { if (yych <= 'b') { - if (yych == 'X') goto yy161; - if (yych >= 'b') goto yy162; + if (yych == 'X') goto yy162; + if (yych >= 'b') goto yy163; } else { if (yych <= 'e') { - if (yych >= 'e') goto yy156; + if (yych >= 'e') goto yy157; } else { - if (yych == 'x') goto yy161; + if (yych == 'x') goto yy162; } } } -yy136: - YYDEBUG(136, *YYCURSOR); +yy137: + YYDEBUG(137, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1614 "Zend/zend_language_scanner.l" { @@ -2736,33 +2738,33 @@ int lex_scan(zval *zendlval) } return T_LNUMBER; } -#line 2740 "Zend/zend_language_scanner.c" -yy137: - YYDEBUG(137, *YYCURSOR); +#line 2742 "Zend/zend_language_scanner.c" +yy138: + YYDEBUG(138, *YYCURSOR); yyaccept = 2; yych = *(YYMARKER = ++YYCURSOR); if (yych <= '9') { - if (yych == '.') goto yy151; - if (yych <= '/') goto yy136; - goto yy154; + if (yych == '.') goto yy152; + if (yych <= '/') goto yy137; + goto yy155; } else { if (yych <= 'E') { - if (yych <= 'D') goto yy136; - goto yy156; + if (yych <= 'D') goto yy137; + goto yy157; } else { - if (yych == 'e') goto yy156; - goto yy136; + if (yych == 'e') goto yy157; + goto yy137; } } -yy138: - YYDEBUG(138, *YYCURSOR); - yych = *++YYCURSOR; - goto yy150; yy139: YYDEBUG(139, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + goto yy151; yy140: YYDEBUG(140, *YYCURSOR); + ++YYCURSOR; +yy141: + YYDEBUG(141, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1860 "Zend/zend_language_scanner.l" { @@ -2793,12 +2795,12 @@ int lex_scan(zval *zendlval) return T_COMMENT; } -#line 2797 "Zend/zend_language_scanner.c" -yy141: - YYDEBUG(141, *YYCURSOR); - ++YYCURSOR; +#line 2799 "Zend/zend_language_scanner.c" yy142: YYDEBUG(142, *YYCURSOR); + ++YYCURSOR; +yy143: + YYDEBUG(143, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1928 "Zend/zend_language_scanner.l" { @@ -2868,12 +2870,12 @@ int lex_scan(zval *zendlval) } return T_CONSTANT_ENCAPSED_STRING; } -#line 2872 "Zend/zend_language_scanner.c" -yy143: - YYDEBUG(143, *YYCURSOR); - ++YYCURSOR; +#line 2874 "Zend/zend_language_scanner.c" yy144: YYDEBUG(144, *YYCURSOR); + ++YYCURSOR; +yy145: + YYDEBUG(145, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1997 "Zend/zend_language_scanner.l" { @@ -2916,22 +2918,22 @@ int lex_scan(zval *zendlval) BEGIN(ST_DOUBLE_QUOTES); return '"'; } -#line 2920 "Zend/zend_language_scanner.c" -yy145: - YYDEBUG(145, *YYCURSOR); - ++YYCURSOR; +#line 2922 "Zend/zend_language_scanner.c" +yy146: YYDEBUG(146, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(147, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2087 "Zend/zend_language_scanner.l" { BEGIN(ST_BACKQUOTE); return '`'; } -#line 2931 "Zend/zend_language_scanner.c" -yy147: - YYDEBUG(147, *YYCURSOR); - ++YYCURSOR; +#line 2933 "Zend/zend_language_scanner.c" +yy148: YYDEBUG(148, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(149, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2349 "Zend/zend_language_scanner.l" { @@ -2942,32 +2944,32 @@ int lex_scan(zval *zendlval) zend_error(E_COMPILE_WARNING,"Unexpected character in input: '%c' (ASCII=%d) state=%d", yytext[0], yytext[0], YYSTATE); goto restart; } -#line 2946 "Zend/zend_language_scanner.c" -yy149: - YYDEBUG(149, *YYCURSOR); +#line 2948 "Zend/zend_language_scanner.c" +yy150: + YYDEBUG(150, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy150: - YYDEBUG(150, *YYCURSOR); - if (yybm[0+yych] & 4) { - goto yy149; - } - goto yy87; yy151: YYDEBUG(151, *YYCURSOR); + if (yybm[0+yych] & 4) { + goto yy150; + } + goto yy88; +yy152: + YYDEBUG(152, *YYCURSOR); yyaccept = 3; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(152, *YYCURSOR); + YYDEBUG(153, *YYCURSOR); if (yybm[0+yych] & 8) { - goto yy151; + goto yy152; } - if (yych == 'E') goto yy156; - if (yych == 'e') goto yy156; -yy153: - YYDEBUG(153, *YYCURSOR); + if (yych == 'E') goto yy157; + if (yych == 'e') goto yy157; +yy154: + YYDEBUG(154, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1702 "Zend/zend_language_scanner.l" { @@ -2978,97 +2980,97 @@ int lex_scan(zval *zendlval) ZEND_ASSERT(end == yytext + yyleng); return T_DNUMBER; } -#line 2982 "Zend/zend_language_scanner.c" -yy154: - YYDEBUG(154, *YYCURSOR); +#line 2984 "Zend/zend_language_scanner.c" +yy155: + YYDEBUG(155, *YYCURSOR); yyaccept = 2; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(155, *YYCURSOR); + YYDEBUG(156, *YYCURSOR); if (yych <= '9') { - if (yych == '.') goto yy151; - if (yych <= '/') goto yy136; - goto yy154; + if (yych == '.') goto yy152; + if (yych <= '/') goto yy137; + goto yy155; } else { if (yych <= 'E') { - if (yych <= 'D') goto yy136; + if (yych <= 'D') goto yy137; } else { - if (yych != 'e') goto yy136; + if (yych != 'e') goto yy137; } } -yy156: - YYDEBUG(156, *YYCURSOR); +yy157: + YYDEBUG(157, *YYCURSOR); yych = *++YYCURSOR; if (yych <= ',') { - if (yych == '+') goto yy158; + if (yych == '+') goto yy159; } else { - if (yych <= '-') goto yy158; - if (yych <= '/') goto yy157; - if (yych <= '9') goto yy159; + if (yych <= '-') goto yy159; + if (yych <= '/') goto yy158; + if (yych <= '9') goto yy160; } -yy157: - YYDEBUG(157, *YYCURSOR); +yy158: + YYDEBUG(158, *YYCURSOR); YYCURSOR = YYMARKER; if (yyaccept <= 2) { if (yyaccept <= 1) { - if (yyaccept <= 0) { - goto yy87; + if (yyaccept == 0) { + goto yy88; } else { - goto yy102; + goto yy103; } } else { - goto yy136; + goto yy137; } } else { if (yyaccept <= 4) { - if (yyaccept <= 3) { - goto yy153; + if (yyaccept == 3) { + goto yy154; } else { - goto yy190; + goto yy191; } } else { - goto yy210; + goto yy211; } } -yy158: - YYDEBUG(158, *YYCURSOR); - yych = *++YYCURSOR; - if (yych <= '/') goto yy157; - if (yych >= ':') goto yy157; yy159: YYDEBUG(159, *YYCURSOR); + yych = *++YYCURSOR; + if (yych <= '/') goto yy158; + if (yych >= ':') goto yy158; +yy160: + YYDEBUG(160, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(160, *YYCURSOR); - if (yych <= '/') goto yy153; - if (yych <= '9') goto yy159; - goto yy153; -yy161: YYDEBUG(161, *YYCURSOR); - yych = *++YYCURSOR; - if (yybm[0+yych] & 32) { - goto yy166; - } - goto yy157; + if (yych <= '/') goto yy154; + if (yych <= '9') goto yy160; + goto yy154; yy162: YYDEBUG(162, *YYCURSOR); yych = *++YYCURSOR; - if (yybm[0+yych] & 16) { - goto yy163; + if (yybm[0+yych] & 32) { + goto yy167; } - goto yy157; + goto yy158; yy163: YYDEBUG(163, *YYCURSOR); + yych = *++YYCURSOR; + if (yybm[0+yych] & 16) { + goto yy164; + } + goto yy158; +yy164: + YYDEBUG(164, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(164, *YYCURSOR); + YYDEBUG(165, *YYCURSOR); if (yybm[0+yych] & 16) { - goto yy163; + goto yy164; } - YYDEBUG(165, *YYCURSOR); + YYDEBUG(166, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1586 "Zend/zend_language_scanner.l" { @@ -3098,17 +3100,17 @@ int lex_scan(zval *zendlval) return T_DNUMBER; } } -#line 3102 "Zend/zend_language_scanner.c" -yy166: - YYDEBUG(166, *YYCURSOR); +#line 3104 "Zend/zend_language_scanner.c" +yy167: + YYDEBUG(167, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(167, *YYCURSOR); + YYDEBUG(168, *YYCURSOR); if (yybm[0+yych] & 32) { - goto yy166; + goto yy167; } - YYDEBUG(168, *YYCURSOR); + YYDEBUG(169, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1653 "Zend/zend_language_scanner.l" { @@ -3138,135 +3140,135 @@ int lex_scan(zval *zendlval) return T_DNUMBER; } } -#line 3142 "Zend/zend_language_scanner.c" -yy169: - YYDEBUG(169, *YYCURSOR); +#line 3144 "Zend/zend_language_scanner.c" +yy170: + YYDEBUG(170, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(170, *YYCURSOR); + YYDEBUG(171, *YYCURSOR); if (yych <= '^') { if (yych <= '9') { - if (yych >= '0') goto yy169; + if (yych >= '0') goto yy170; } else { - if (yych <= '@') goto yy171; - if (yych <= 'Z') goto yy169; + if (yych <= '@') goto yy172; + if (yych <= 'Z') goto yy170; } } else { if (yych <= '`') { - if (yych <= '_') goto yy169; + if (yych <= '_') goto yy170; } else { - if (yych <= 'z') goto yy169; - if (yych >= 0x7F) goto yy169; + if (yych <= 'z') goto yy170; + if (yych >= 0x7F) goto yy170; } } -yy171: - YYDEBUG(171, *YYCURSOR); +yy172: + YYDEBUG(172, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1831 "Zend/zend_language_scanner.l" { zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 3172 "Zend/zend_language_scanner.c" -yy172: - YYDEBUG(172, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy173; - if (yych != 'r') goto yy150; +#line 3174 "Zend/zend_language_scanner.c" yy173: YYDEBUG(173, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'R') goto yy174; + if (yych != 'r') goto yy151; +yy174: + YYDEBUG(174, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(174, *YYCURSOR); + YYDEBUG(175, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1532 "Zend/zend_language_scanner.l" { return T_LOGICAL_XOR; } -#line 3190 "Zend/zend_language_scanner.c" -yy175: - YYDEBUG(175, *YYCURSOR); +#line 3192 "Zend/zend_language_scanner.c" +yy176: + YYDEBUG(176, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(176, *YYCURSOR); + YYDEBUG(177, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1524 "Zend/zend_language_scanner.l" { return T_LOGICAL_OR; } -#line 3203 "Zend/zend_language_scanner.c" -yy177: - YYDEBUG(177, *YYCURSOR); - ++YYCURSOR; +#line 3205 "Zend/zend_language_scanner.c" +yy178: YYDEBUG(178, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(179, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1512 "Zend/zend_language_scanner.l" { return T_XOR_EQUAL; } -#line 3213 "Zend/zend_language_scanner.c" -yy179: - YYDEBUG(179, *YYCURSOR); - ++YYCURSOR; +#line 3215 "Zend/zend_language_scanner.c" +yy180: YYDEBUG(180, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(181, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1516 "Zend/zend_language_scanner.l" { return T_BOOLEAN_OR; } -#line 3223 "Zend/zend_language_scanner.c" -yy181: - YYDEBUG(181, *YYCURSOR); - ++YYCURSOR; +#line 3225 "Zend/zend_language_scanner.c" +yy182: YYDEBUG(182, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(183, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1508 "Zend/zend_language_scanner.l" { return T_OR_EQUAL; } -#line 3233 "Zend/zend_language_scanner.c" -yy183: - YYDEBUG(183, *YYCURSOR); - ++YYCURSOR; +#line 3235 "Zend/zend_language_scanner.c" +yy184: YYDEBUG(184, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(185, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1520 "Zend/zend_language_scanner.l" { return T_BOOLEAN_AND; } -#line 3243 "Zend/zend_language_scanner.c" -yy185: - YYDEBUG(185, *YYCURSOR); - ++YYCURSOR; +#line 3245 "Zend/zend_language_scanner.c" +yy186: YYDEBUG(186, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(187, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1504 "Zend/zend_language_scanner.l" { return T_AND_EQUAL; } -#line 3253 "Zend/zend_language_scanner.c" -yy187: - YYDEBUG(187, *YYCURSOR); - ++YYCURSOR; +#line 3255 "Zend/zend_language_scanner.c" +yy188: YYDEBUG(188, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(189, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1492 "Zend/zend_language_scanner.l" { return T_MOD_EQUAL; } -#line 3263 "Zend/zend_language_scanner.c" -yy189: - YYDEBUG(189, *YYCURSOR); - yyaccept = 4; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == '*') goto yy194; +#line 3265 "Zend/zend_language_scanner.c" yy190: YYDEBUG(190, *YYCURSOR); + yyaccept = 4; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == '*') goto yy195; +yy191: + YYDEBUG(191, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1889 "Zend/zend_language_scanner.l" { @@ -3301,249 +3303,249 @@ int lex_scan(zval *zendlval) return T_COMMENT; } -#line 3305 "Zend/zend_language_scanner.c" -yy191: - YYDEBUG(191, *YYCURSOR); - yych = *++YYCURSOR; - goto yy140; +#line 3307 "Zend/zend_language_scanner.c" yy192: YYDEBUG(192, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + goto yy141; +yy193: YYDEBUG(193, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(194, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1484 "Zend/zend_language_scanner.l" { return T_DIV_EQUAL; } -#line 3319 "Zend/zend_language_scanner.c" -yy194: - YYDEBUG(194, *YYCURSOR); +#line 3321 "Zend/zend_language_scanner.c" +yy195: + YYDEBUG(195, *YYCURSOR); yych = *++YYCURSOR; if (yybm[0+yych] & 64) { - goto yy195; + goto yy196; } - goto yy157; -yy195: - YYDEBUG(195, *YYCURSOR); + goto yy158; +yy196: + YYDEBUG(196, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(196, *YYCURSOR); + YYDEBUG(197, *YYCURSOR); if (yybm[0+yych] & 64) { - goto yy195; + goto yy196; } - goto yy190; -yy197: - YYDEBUG(197, *YYCURSOR); - ++YYCURSOR; - if ((yych = *YYCURSOR) == '=') goto yy201; + goto yy191; +yy198: YYDEBUG(198, *YYCURSOR); + ++YYCURSOR; + if ((yych = *YYCURSOR) == '=') goto yy202; + YYDEBUG(199, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1476 "Zend/zend_language_scanner.l" { return T_POW; } -#line 3347 "Zend/zend_language_scanner.c" -yy199: - YYDEBUG(199, *YYCURSOR); - ++YYCURSOR; +#line 3349 "Zend/zend_language_scanner.c" +yy200: YYDEBUG(200, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(201, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1472 "Zend/zend_language_scanner.l" { return T_MUL_EQUAL; } -#line 3357 "Zend/zend_language_scanner.c" -yy201: - YYDEBUG(201, *YYCURSOR); - ++YYCURSOR; +#line 3359 "Zend/zend_language_scanner.c" +yy202: YYDEBUG(202, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(203, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1480 "Zend/zend_language_scanner.l" { return T_POW_EQUAL; } -#line 3367 "Zend/zend_language_scanner.c" -yy203: - YYDEBUG(203, *YYCURSOR); - ++YYCURSOR; - if ((yych = *YYCURSOR) == '=') goto yy207; +#line 3369 "Zend/zend_language_scanner.c" +yy204: YYDEBUG(204, *YYCURSOR); + ++YYCURSOR; + if ((yych = *YYCURSOR) == '=') goto yy208; + YYDEBUG(205, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1540 "Zend/zend_language_scanner.l" { return T_SR; } -#line 3378 "Zend/zend_language_scanner.c" -yy205: - YYDEBUG(205, *YYCURSOR); - ++YYCURSOR; +#line 3380 "Zend/zend_language_scanner.c" +yy206: YYDEBUG(206, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(207, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1460 "Zend/zend_language_scanner.l" { return T_IS_GREATER_OR_EQUAL; } -#line 3388 "Zend/zend_language_scanner.c" -yy207: - YYDEBUG(207, *YYCURSOR); - ++YYCURSOR; +#line 3390 "Zend/zend_language_scanner.c" +yy208: YYDEBUG(208, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(209, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1500 "Zend/zend_language_scanner.l" { return T_SR_EQUAL; } -#line 3398 "Zend/zend_language_scanner.c" -yy209: - YYDEBUG(209, *YYCURSOR); - yyaccept = 5; - yych = *(YYMARKER = ++YYCURSOR); - if (yych <= ';') goto yy210; - if (yych <= '<') goto yy217; - if (yych <= '=') goto yy215; +#line 3400 "Zend/zend_language_scanner.c" yy210: YYDEBUG(210, *YYCURSOR); + yyaccept = 5; + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= ';') goto yy211; + if (yych <= '<') goto yy218; + if (yych <= '=') goto yy216; +yy211: + YYDEBUG(211, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1536 "Zend/zend_language_scanner.l" { return T_SL; } -#line 3413 "Zend/zend_language_scanner.c" -yy211: - YYDEBUG(211, *YYCURSOR); - ++YYCURSOR; +#line 3415 "Zend/zend_language_scanner.c" +yy212: YYDEBUG(212, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(213, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1456 "Zend/zend_language_scanner.l" { return T_IS_SMALLER_OR_EQUAL; } -#line 3423 "Zend/zend_language_scanner.c" -yy213: - YYDEBUG(213, *YYCURSOR); - ++YYCURSOR; +#line 3425 "Zend/zend_language_scanner.c" yy214: YYDEBUG(214, *YYCURSOR); + ++YYCURSOR; +yy215: + YYDEBUG(215, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1452 "Zend/zend_language_scanner.l" { return T_IS_NOT_EQUAL; } -#line 3434 "Zend/zend_language_scanner.c" -yy215: - YYDEBUG(215, *YYCURSOR); - ++YYCURSOR; +#line 3436 "Zend/zend_language_scanner.c" +yy216: YYDEBUG(216, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(217, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1496 "Zend/zend_language_scanner.l" { return T_SL_EQUAL; } -#line 3444 "Zend/zend_language_scanner.c" -yy217: - YYDEBUG(217, *YYCURSOR); +#line 3446 "Zend/zend_language_scanner.c" +yy218: + YYDEBUG(218, *YYCURSOR); ++YYCURSOR; YYFILL(2); yych = *YYCURSOR; - YYDEBUG(218, *YYCURSOR); + YYDEBUG(219, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy217; + goto yy218; } if (yych <= 'Z') { if (yych <= '&') { - if (yych == '"') goto yy222; - goto yy157; + if (yych == '"') goto yy223; + goto yy158; } else { - if (yych <= '\'') goto yy221; - if (yych <= '@') goto yy157; + if (yych <= '\'') goto yy222; + if (yych <= '@') goto yy158; } } else { if (yych <= '`') { - if (yych != '_') goto yy157; + if (yych != '_') goto yy158; } else { - if (yych <= 'z') goto yy219; - if (yych <= '~') goto yy157; + if (yych <= 'z') goto yy220; + if (yych <= '~') goto yy158; } } -yy219: - YYDEBUG(219, *YYCURSOR); +yy220: + YYDEBUG(220, *YYCURSOR); ++YYCURSOR; YYFILL(2); yych = *YYCURSOR; - YYDEBUG(220, *YYCURSOR); + YYDEBUG(221, *YYCURSOR); if (yych <= '@') { if (yych <= '\f') { - if (yych == '\n') goto yy226; - goto yy157; + if (yych == '\n') goto yy227; + goto yy158; } else { - if (yych <= '\r') goto yy228; - if (yych <= '/') goto yy157; - if (yych <= '9') goto yy219; - goto yy157; + if (yych <= '\r') goto yy229; + if (yych <= '/') goto yy158; + if (yych <= '9') goto yy220; + goto yy158; } } else { if (yych <= '_') { - if (yych <= 'Z') goto yy219; - if (yych <= '^') goto yy157; - goto yy219; + if (yych <= 'Z') goto yy220; + if (yych <= '^') goto yy158; + goto yy220; } else { - if (yych <= '`') goto yy157; - if (yych <= 'z') goto yy219; - if (yych <= '~') goto yy157; - goto yy219; + if (yych <= '`') goto yy158; + if (yych <= 'z') goto yy220; + if (yych <= '~') goto yy158; + goto yy220; } } -yy221: - YYDEBUG(221, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '\'') goto yy157; - if (yych <= '/') goto yy230; - if (yych <= '9') goto yy157; - goto yy230; yy222: YYDEBUG(222, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '"') goto yy157; - if (yych <= '/') goto yy224; - if (yych <= '9') goto yy157; - goto yy224; + if (yych == '\'') goto yy158; + if (yych <= '/') goto yy231; + if (yych <= '9') goto yy158; + goto yy231; yy223: YYDEBUG(223, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == '"') goto yy158; + if (yych <= '/') goto yy225; + if (yych <= '9') goto yy158; + goto yy225; +yy224: + YYDEBUG(224, *YYCURSOR); ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; -yy224: - YYDEBUG(224, *YYCURSOR); +yy225: + YYDEBUG(225, *YYCURSOR); if (yych <= 'Z') { if (yych <= '/') { - if (yych != '"') goto yy157; + if (yych != '"') goto yy158; } else { - if (yych <= '9') goto yy223; - if (yych <= '@') goto yy157; - goto yy223; + if (yych <= '9') goto yy224; + if (yych <= '@') goto yy158; + goto yy224; } } else { if (yych <= '`') { - if (yych == '_') goto yy223; - goto yy157; + if (yych == '_') goto yy224; + goto yy158; } else { - if (yych <= 'z') goto yy223; - if (yych <= '~') goto yy157; - goto yy223; + if (yych <= 'z') goto yy224; + if (yych <= '~') goto yy158; + goto yy224; } } -yy225: - YYDEBUG(225, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '\n') goto yy226; - if (yych == '\r') goto yy228; - goto yy157; yy226: YYDEBUG(226, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych == '\n') goto yy227; + if (yych == '\r') goto yy229; + goto yy158; yy227: YYDEBUG(227, *YYCURSOR); + ++YYCURSOR; +yy228: + YYDEBUG(228, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2039 "Zend/zend_language_scanner.l" { @@ -3592,3272 +3594,3272 @@ int lex_scan(zval *zendlval) return T_START_HEREDOC; } -#line 3596 "Zend/zend_language_scanner.c" -yy228: - YYDEBUG(228, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '\n') goto yy226; - goto yy227; +#line 3598 "Zend/zend_language_scanner.c" yy229: YYDEBUG(229, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == '\n') goto yy227; + goto yy228; +yy230: + YYDEBUG(230, *YYCURSOR); ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; -yy230: - YYDEBUG(230, *YYCURSOR); +yy231: + YYDEBUG(231, *YYCURSOR); if (yych <= 'Z') { if (yych <= '/') { - if (yych == '\'') goto yy225; - goto yy157; + if (yych == '\'') goto yy226; + goto yy158; } else { - if (yych <= '9') goto yy229; - if (yych <= '@') goto yy157; - goto yy229; + if (yych <= '9') goto yy230; + if (yych <= '@') goto yy158; + goto yy230; } } else { if (yych <= '`') { - if (yych == '_') goto yy229; - goto yy157; + if (yych == '_') goto yy230; + goto yy158; } else { - if (yych <= 'z') goto yy229; - if (yych <= '~') goto yy157; - goto yy229; + if (yych <= 'z') goto yy230; + if (yych <= '~') goto yy158; + goto yy230; } } -yy231: - YYDEBUG(231, *YYCURSOR); - yych = *++YYCURSOR; - if (yych != '=') goto yy214; +yy232: YYDEBUG(232, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych != '=') goto yy215; YYDEBUG(233, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(234, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1444 "Zend/zend_language_scanner.l" { return T_IS_NOT_IDENTICAL; } -#line 3640 "Zend/zend_language_scanner.c" -yy234: - YYDEBUG(234, *YYCURSOR); - ++YYCURSOR; +#line 3642 "Zend/zend_language_scanner.c" +yy235: YYDEBUG(235, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(236, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1464 "Zend/zend_language_scanner.l" { return T_PLUS_EQUAL; } -#line 3650 "Zend/zend_language_scanner.c" -yy236: - YYDEBUG(236, *YYCURSOR); - ++YYCURSOR; +#line 3652 "Zend/zend_language_scanner.c" +yy237: YYDEBUG(237, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(238, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1432 "Zend/zend_language_scanner.l" { return T_INC; } -#line 3660 "Zend/zend_language_scanner.c" -yy238: - YYDEBUG(238, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'S') goto yy239; - if (yych != 's') goto yy150; +#line 3662 "Zend/zend_language_scanner.c" yy239: YYDEBUG(239, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy240; - if (yych != 't') goto yy150; + if (yych == 'S') goto yy240; + if (yych != 's') goto yy151; yy240: YYDEBUG(240, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy241; + if (yych != 't') goto yy151; +yy241: + YYDEBUG(241, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(241, *YYCURSOR); + YYDEBUG(242, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1420 "Zend/zend_language_scanner.l" { return T_LIST; } -#line 3683 "Zend/zend_language_scanner.c" -yy242: - YYDEBUG(242, *YYCURSOR); - ++YYCURSOR; - if ((yych = *YYCURSOR) == '=') goto yy246; +#line 3685 "Zend/zend_language_scanner.c" +yy243: YYDEBUG(243, *YYCURSOR); + ++YYCURSOR; + if ((yych = *YYCURSOR) == '=') goto yy247; + YYDEBUG(244, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1448 "Zend/zend_language_scanner.l" { return T_IS_EQUAL; } -#line 3694 "Zend/zend_language_scanner.c" -yy244: - YYDEBUG(244, *YYCURSOR); - ++YYCURSOR; +#line 3696 "Zend/zend_language_scanner.c" +yy245: YYDEBUG(245, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(246, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1416 "Zend/zend_language_scanner.l" { return T_DOUBLE_ARROW; } -#line 3704 "Zend/zend_language_scanner.c" -yy246: - YYDEBUG(246, *YYCURSOR); - ++YYCURSOR; +#line 3706 "Zend/zend_language_scanner.c" +yy247: YYDEBUG(247, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(248, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1440 "Zend/zend_language_scanner.l" { return T_IS_IDENTICAL; } -#line 3714 "Zend/zend_language_scanner.c" -yy248: - YYDEBUG(248, *YYCURSOR); +#line 3716 "Zend/zend_language_scanner.c" +yy249: + YYDEBUG(249, *YYCURSOR); yych = *++YYCURSOR; YYDEBUG(-1, yych); switch (yych) { case 'C': - case 'c': goto yy250; + case 'c': goto yy251; case 'D': - case 'd': goto yy255; + case 'd': goto yy256; case 'F': - case 'f': goto yy252; + case 'f': goto yy253; case 'H': - case 'h': goto yy249; + case 'h': goto yy250; case 'L': - case 'l': goto yy254; + case 'l': goto yy255; case 'M': - case 'm': goto yy253; + case 'm': goto yy254; case 'N': - case 'n': goto yy256; + case 'n': goto yy257; case 'T': - case 't': goto yy251; - default: goto yy150; + case 't': goto yy252; + default: goto yy151; } -yy249: - YYDEBUG(249, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy317; - if (yych == 'a') goto yy317; - goto yy150; yy250: YYDEBUG(250, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy310; - if (yych == 'l') goto yy310; - goto yy150; + if (yych == 'A') goto yy318; + if (yych == 'a') goto yy318; + goto yy151; yy251: YYDEBUG(251, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy303; - if (yych == 'r') goto yy303; - goto yy150; + if (yych == 'L') goto yy311; + if (yych == 'l') goto yy311; + goto yy151; yy252: YYDEBUG(252, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'R') goto yy304; + if (yych == 'r') goto yy304; + goto yy151; +yy253: + YYDEBUG(253, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'U') { - if (yych == 'I') goto yy287; - if (yych <= 'T') goto yy150; - goto yy288; + if (yych == 'I') goto yy288; + if (yych <= 'T') goto yy151; + goto yy289; } else { if (yych <= 'i') { - if (yych <= 'h') goto yy150; - goto yy287; + if (yych <= 'h') goto yy151; + goto yy288; } else { - if (yych == 'u') goto yy288; - goto yy150; + if (yych == 'u') goto yy289; + goto yy151; } } -yy253: - YYDEBUG(253, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy279; - if (yych == 'e') goto yy279; - goto yy150; yy254: YYDEBUG(254, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy273; - if (yych == 'i') goto yy273; - goto yy150; + if (yych == 'E') goto yy280; + if (yych == 'e') goto yy280; + goto yy151; yy255: YYDEBUG(255, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy268; - if (yych == 'i') goto yy268; - goto yy150; + if (yych == 'I') goto yy274; + if (yych == 'i') goto yy274; + goto yy151; yy256: YYDEBUG(256, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy257; - if (yych != 'a') goto yy150; + if (yych == 'I') goto yy269; + if (yych == 'i') goto yy269; + goto yy151; yy257: YYDEBUG(257, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'M') goto yy258; - if (yych != 'm') goto yy150; + if (yych == 'A') goto yy258; + if (yych != 'a') goto yy151; yy258: YYDEBUG(258, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy259; - if (yych != 'e') goto yy150; + if (yych == 'M') goto yy259; + if (yych != 'm') goto yy151; yy259: YYDEBUG(259, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'S') goto yy260; - if (yych != 's') goto yy150; + if (yych == 'E') goto yy260; + if (yych != 'e') goto yy151; yy260: YYDEBUG(260, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'P') goto yy261; - if (yych != 'p') goto yy150; + if (yych == 'S') goto yy261; + if (yych != 's') goto yy151; yy261: YYDEBUG(261, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy262; - if (yych != 'a') goto yy150; + if (yych == 'P') goto yy262; + if (yych != 'p') goto yy151; yy262: YYDEBUG(262, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy263; - if (yych != 'c') goto yy150; + if (yych == 'A') goto yy263; + if (yych != 'a') goto yy151; yy263: YYDEBUG(263, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy264; - if (yych != 'e') goto yy150; + if (yych == 'C') goto yy264; + if (yych != 'c') goto yy151; yy264: YYDEBUG(264, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'E') goto yy265; + if (yych != 'e') goto yy151; +yy265: YYDEBUG(265, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(266, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(267, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(267, *YYCURSOR); + YYDEBUG(268, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1739 "Zend/zend_language_scanner.l" { return T_NS_C; } -#line 3848 "Zend/zend_language_scanner.c" -yy268: - YYDEBUG(268, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy269; - if (yych != 'r') goto yy150; +#line 3850 "Zend/zend_language_scanner.c" yy269: YYDEBUG(269, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'R') goto yy270; + if (yych != 'r') goto yy151; +yy270: YYDEBUG(270, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(271, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(272, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(272, *YYCURSOR); + YYDEBUG(273, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1735 "Zend/zend_language_scanner.l" { return T_DIR; } -#line 3872 "Zend/zend_language_scanner.c" -yy273: - YYDEBUG(273, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'N') goto yy274; - if (yych != 'n') goto yy150; +#line 3874 "Zend/zend_language_scanner.c" yy274: YYDEBUG(274, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy275; - if (yych != 'e') goto yy150; + if (yych == 'N') goto yy275; + if (yych != 'n') goto yy151; yy275: YYDEBUG(275, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'E') goto yy276; + if (yych != 'e') goto yy151; +yy276: YYDEBUG(276, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(277, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(278, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(278, *YYCURSOR); + YYDEBUG(279, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1727 "Zend/zend_language_scanner.l" { return T_LINE; } -#line 3901 "Zend/zend_language_scanner.c" -yy279: - YYDEBUG(279, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy280; - if (yych != 't') goto yy150; +#line 3903 "Zend/zend_language_scanner.c" yy280: YYDEBUG(280, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'H') goto yy281; - if (yych != 'h') goto yy150; + if (yych == 'T') goto yy281; + if (yych != 't') goto yy151; yy281: YYDEBUG(281, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy282; - if (yych != 'o') goto yy150; + if (yych == 'H') goto yy282; + if (yych != 'h') goto yy151; yy282: YYDEBUG(282, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy283; - if (yych != 'd') goto yy150; + if (yych == 'O') goto yy283; + if (yych != 'o') goto yy151; yy283: YYDEBUG(283, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'D') goto yy284; + if (yych != 'd') goto yy151; +yy284: YYDEBUG(284, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(285, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(286, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(286, *YYCURSOR); + YYDEBUG(287, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1723 "Zend/zend_language_scanner.l" { return T_METHOD_C; } -#line 3940 "Zend/zend_language_scanner.c" -yy287: - YYDEBUG(287, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'L') goto yy298; - if (yych == 'l') goto yy298; - goto yy150; +#line 3942 "Zend/zend_language_scanner.c" yy288: YYDEBUG(288, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy289; - if (yych != 'n') goto yy150; + if (yych == 'L') goto yy299; + if (yych == 'l') goto yy299; + goto yy151; yy289: YYDEBUG(289, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy290; - if (yych != 'c') goto yy150; + if (yych == 'N') goto yy290; + if (yych != 'n') goto yy151; yy290: YYDEBUG(290, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy291; - if (yych != 't') goto yy150; + if (yych == 'C') goto yy291; + if (yych != 'c') goto yy151; yy291: YYDEBUG(291, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy292; - if (yych != 'i') goto yy150; + if (yych == 'T') goto yy292; + if (yych != 't') goto yy151; yy292: YYDEBUG(292, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy293; - if (yych != 'o') goto yy150; + if (yych == 'I') goto yy293; + if (yych != 'i') goto yy151; yy293: YYDEBUG(293, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy294; - if (yych != 'n') goto yy150; + if (yych == 'O') goto yy294; + if (yych != 'o') goto yy151; yy294: YYDEBUG(294, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'N') goto yy295; + if (yych != 'n') goto yy151; +yy295: YYDEBUG(295, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(296, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(297, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(297, *YYCURSOR); + YYDEBUG(298, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1719 "Zend/zend_language_scanner.l" { return T_FUNC_C; } -#line 3995 "Zend/zend_language_scanner.c" -yy298: - YYDEBUG(298, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy299; - if (yych != 'e') goto yy150; +#line 3997 "Zend/zend_language_scanner.c" yy299: YYDEBUG(299, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'E') goto yy300; + if (yych != 'e') goto yy151; +yy300: YYDEBUG(300, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(301, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(302, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(302, *YYCURSOR); + YYDEBUG(303, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1731 "Zend/zend_language_scanner.l" { return T_FILE; } -#line 4019 "Zend/zend_language_scanner.c" -yy303: - YYDEBUG(303, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy304; - if (yych != 'a') goto yy150; +#line 4021 "Zend/zend_language_scanner.c" yy304: YYDEBUG(304, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy305; - if (yych != 'i') goto yy150; + if (yych == 'A') goto yy305; + if (yych != 'a') goto yy151; yy305: YYDEBUG(305, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy306; - if (yych != 't') goto yy150; + if (yych == 'I') goto yy306; + if (yych != 'i') goto yy151; yy306: YYDEBUG(306, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'T') goto yy307; + if (yych != 't') goto yy151; +yy307: YYDEBUG(307, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(308, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(309, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(309, *YYCURSOR); + YYDEBUG(310, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1715 "Zend/zend_language_scanner.l" { return T_TRAIT_C; } -#line 4053 "Zend/zend_language_scanner.c" -yy310: - YYDEBUG(310, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy311; - if (yych != 'a') goto yy150; +#line 4055 "Zend/zend_language_scanner.c" yy311: YYDEBUG(311, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'S') goto yy312; - if (yych != 's') goto yy150; + if (yych == 'A') goto yy312; + if (yych != 'a') goto yy151; yy312: YYDEBUG(312, *YYCURSOR); yych = *++YYCURSOR; if (yych == 'S') goto yy313; - if (yych != 's') goto yy150; + if (yych != 's') goto yy151; yy313: YYDEBUG(313, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'S') goto yy314; + if (yych != 's') goto yy151; +yy314: YYDEBUG(314, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych != '_') goto yy151; YYDEBUG(315, *YYCURSOR); + yych = *++YYCURSOR; + if (yych != '_') goto yy151; + YYDEBUG(316, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(316, *YYCURSOR); + YYDEBUG(317, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1711 "Zend/zend_language_scanner.l" { return T_CLASS_C; } -#line 4087 "Zend/zend_language_scanner.c" -yy317: - YYDEBUG(317, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'L') goto yy318; - if (yych != 'l') goto yy150; +#line 4089 "Zend/zend_language_scanner.c" yy318: YYDEBUG(318, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy319; - if (yych != 't') goto yy150; + if (yych == 'L') goto yy319; + if (yych != 'l') goto yy151; yy319: YYDEBUG(319, *YYCURSOR); yych = *++YYCURSOR; - if (yych != '_') goto yy150; + if (yych == 'T') goto yy320; + if (yych != 't') goto yy151; +yy320: YYDEBUG(320, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy321; - if (yych != 'c') goto yy150; -yy321: + if (yych != '_') goto yy151; YYDEBUG(321, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy322; - if (yych != 'o') goto yy150; + if (yych == 'C') goto yy322; + if (yych != 'c') goto yy151; yy322: YYDEBUG(322, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'M') goto yy323; - if (yych != 'm') goto yy150; + if (yych == 'O') goto yy323; + if (yych != 'o') goto yy151; yy323: YYDEBUG(323, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'P') goto yy324; - if (yych != 'p') goto yy150; + if (yych == 'M') goto yy324; + if (yych != 'm') goto yy151; yy324: YYDEBUG(324, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy325; - if (yych != 'i') goto yy150; + if (yych == 'P') goto yy325; + if (yych != 'p') goto yy151; yy325: YYDEBUG(325, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy326; - if (yych != 'l') goto yy150; + if (yych == 'I') goto yy326; + if (yych != 'i') goto yy151; yy326: YYDEBUG(326, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy327; - if (yych != 'e') goto yy150; + if (yych == 'L') goto yy327; + if (yych != 'l') goto yy151; yy327: YYDEBUG(327, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy328; - if (yych != 'r') goto yy150; + if (yych == 'E') goto yy328; + if (yych != 'e') goto yy151; yy328: YYDEBUG(328, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'R') goto yy329; + if (yych != 'r') goto yy151; +yy329: + YYDEBUG(329, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(329, *YYCURSOR); + YYDEBUG(330, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1384 "Zend/zend_language_scanner.l" { return T_HALT_COMPILER; } -#line 4153 "Zend/zend_language_scanner.c" -yy330: - YYDEBUG(330, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'S') goto yy334; - if (yych == 's') goto yy334; - goto yy150; +#line 4155 "Zend/zend_language_scanner.c" yy331: YYDEBUG(331, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy332; - if (yych != 'e') goto yy150; + if (yych == 'S') goto yy335; + if (yych == 's') goto yy335; + goto yy151; yy332: YYDEBUG(332, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy333; + if (yych != 'e') goto yy151; +yy333: + YYDEBUG(333, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(333, *YYCURSOR); + YYDEBUG(334, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1364 "Zend/zend_language_scanner.l" { return T_USE; } -#line 4177 "Zend/zend_language_scanner.c" -yy334: - YYDEBUG(334, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy335; - if (yych != 'e') goto yy150; +#line 4179 "Zend/zend_language_scanner.c" yy335: YYDEBUG(335, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy336; - if (yych != 't') goto yy150; + if (yych == 'E') goto yy336; + if (yych != 'e') goto yy151; yy336: YYDEBUG(336, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy337; + if (yych != 't') goto yy151; +yy337: + YYDEBUG(337, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(337, *YYCURSOR); + YYDEBUG(338, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1412 "Zend/zend_language_scanner.l" { return T_UNSET; } -#line 4200 "Zend/zend_language_scanner.c" -yy338: - YYDEBUG(338, *YYCURSOR); +#line 4202 "Zend/zend_language_scanner.c" +yy339: + YYDEBUG(339, *YYCURSOR); ++YYCURSOR; YYFILL(7); yych = *YYCURSOR; -yy339: - YYDEBUG(339, *YYCURSOR); +yy340: + YYDEBUG(340, *YYCURSOR); if (yych <= 'S') { if (yych <= 'D') { if (yych <= ' ') { - if (yych == '\t') goto yy338; - if (yych <= 0x1F) goto yy157; - goto yy338; + if (yych == '\t') goto yy339; + if (yych <= 0x1F) goto yy158; + goto yy339; } else { if (yych <= 'A') { - if (yych <= '@') goto yy157; - goto yy343; + if (yych <= '@') goto yy158; + goto yy344; } else { - if (yych <= 'B') goto yy341; - if (yych <= 'C') goto yy157; - goto yy346; + if (yych <= 'B') goto yy342; + if (yych <= 'C') goto yy158; + goto yy347; } } } else { if (yych <= 'I') { - if (yych == 'F') goto yy347; - if (yych <= 'H') goto yy157; - goto yy348; + if (yych == 'F') goto yy348; + if (yych <= 'H') goto yy158; + goto yy349; } else { if (yych <= 'O') { - if (yych <= 'N') goto yy157; - goto yy342; + if (yych <= 'N') goto yy158; + goto yy343; } else { - if (yych <= 'Q') goto yy157; - if (yych <= 'R') goto yy345; - goto yy344; + if (yych <= 'Q') goto yy158; + if (yych <= 'R') goto yy346; + goto yy345; } } } } else { if (yych <= 'f') { if (yych <= 'a') { - if (yych == 'U') goto yy340; - if (yych <= '`') goto yy157; - goto yy343; + if (yych == 'U') goto yy341; + if (yych <= '`') goto yy158; + goto yy344; } else { if (yych <= 'c') { - if (yych <= 'b') goto yy341; - goto yy157; + if (yych <= 'b') goto yy342; + goto yy158; } else { - if (yych <= 'd') goto yy346; - if (yych <= 'e') goto yy157; - goto yy347; + if (yych <= 'd') goto yy347; + if (yych <= 'e') goto yy158; + goto yy348; } } } else { if (yych <= 'q') { if (yych <= 'i') { - if (yych <= 'h') goto yy157; - goto yy348; + if (yych <= 'h') goto yy158; + goto yy349; } else { - if (yych == 'o') goto yy342; - goto yy157; + if (yych == 'o') goto yy343; + goto yy158; } } else { if (yych <= 's') { - if (yych <= 'r') goto yy345; - goto yy344; + if (yych <= 'r') goto yy346; + goto yy345; } else { - if (yych != 'u') goto yy157; + if (yych != 'u') goto yy158; } } } } -yy340: - YYDEBUG(340, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'N') goto yy407; - if (yych == 'n') goto yy407; - goto yy157; yy341: YYDEBUG(341, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'N') goto yy408; + if (yych == 'n') goto yy408; + goto yy158; +yy342: + YYDEBUG(342, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'O') { - if (yych == 'I') goto yy394; - if (yych <= 'N') goto yy157; - goto yy395; + if (yych == 'I') goto yy395; + if (yych <= 'N') goto yy158; + goto yy396; } else { if (yych <= 'i') { - if (yych <= 'h') goto yy157; - goto yy394; + if (yych <= 'h') goto yy158; + goto yy395; } else { - if (yych == 'o') goto yy395; - goto yy157; + if (yych == 'o') goto yy396; + goto yy158; } } -yy342: - YYDEBUG(342, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'B') goto yy386; - if (yych == 'b') goto yy386; - goto yy157; yy343: YYDEBUG(343, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy379; - if (yych == 'r') goto yy379; - goto yy157; + if (yych == 'B') goto yy387; + if (yych == 'b') goto yy387; + goto yy158; yy344: YYDEBUG(344, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy371; - if (yych == 't') goto yy371; - goto yy157; + if (yych == 'R') goto yy380; + if (yych == 'r') goto yy380; + goto yy158; yy345: YYDEBUG(345, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy369; - if (yych == 'e') goto yy369; - goto yy157; + if (yych == 'T') goto yy372; + if (yych == 't') goto yy372; + goto yy158; yy346: YYDEBUG(346, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy365; - if (yych == 'o') goto yy365; - goto yy157; + if (yych == 'E') goto yy370; + if (yych == 'e') goto yy370; + goto yy158; yy347: YYDEBUG(347, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy358; - if (yych == 'l') goto yy358; - goto yy157; + if (yych == 'O') goto yy366; + if (yych == 'o') goto yy366; + goto yy158; yy348: YYDEBUG(348, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy349; - if (yych != 'n') goto yy157; + if (yych == 'L') goto yy359; + if (yych == 'l') goto yy359; + goto yy158; yy349: YYDEBUG(349, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy350; - if (yych != 't') goto yy157; + if (yych == 'N') goto yy350; + if (yych != 'n') goto yy158; yy350: YYDEBUG(350, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy351; - if (yych != 'e') goto yy353; + if (yych == 'T') goto yy351; + if (yych != 't') goto yy158; yy351: YYDEBUG(351, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'G') goto yy356; - if (yych == 'g') goto yy356; - goto yy157; + if (yych == 'E') goto yy352; + if (yych != 'e') goto yy354; yy352: YYDEBUG(352, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'G') goto yy357; + if (yych == 'g') goto yy357; + goto yy158; +yy353: + YYDEBUG(353, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy353: - YYDEBUG(353, *YYCURSOR); +yy354: + YYDEBUG(354, *YYCURSOR); if (yych <= 0x1F) { - if (yych == '\t') goto yy352; - goto yy157; + if (yych == '\t') goto yy353; + goto yy158; } else { - if (yych <= ' ') goto yy352; - if (yych != ')') goto yy157; + if (yych <= ' ') goto yy353; + if (yych != ')') goto yy158; } - YYDEBUG(354, *YYCURSOR); - ++YYCURSOR; YYDEBUG(355, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(356, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1312 "Zend/zend_language_scanner.l" { return T_INT_CAST; } -#line 4376 "Zend/zend_language_scanner.c" -yy356: - YYDEBUG(356, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy357; - if (yych != 'e') goto yy157; +#line 4378 "Zend/zend_language_scanner.c" yy357: YYDEBUG(357, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy352; - if (yych == 'r') goto yy352; - goto yy157; + if (yych == 'E') goto yy358; + if (yych != 'e') goto yy158; yy358: YYDEBUG(358, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy359; - if (yych != 'o') goto yy157; + if (yych == 'R') goto yy353; + if (yych == 'r') goto yy353; + goto yy158; yy359: YYDEBUG(359, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy360; - if (yych != 'a') goto yy157; + if (yych == 'O') goto yy360; + if (yych != 'o') goto yy158; yy360: YYDEBUG(360, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy361; - if (yych != 't') goto yy157; + if (yych == 'A') goto yy361; + if (yych != 'a') goto yy158; yy361: YYDEBUG(361, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy362; + if (yych != 't') goto yy158; +yy362: + YYDEBUG(362, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(362, *YYCURSOR); + YYDEBUG(363, *YYCURSOR); if (yych <= 0x1F) { - if (yych == '\t') goto yy361; - goto yy157; + if (yych == '\t') goto yy362; + goto yy158; } else { - if (yych <= ' ') goto yy361; - if (yych != ')') goto yy157; + if (yych <= ' ') goto yy362; + if (yych != ')') goto yy158; } - YYDEBUG(363, *YYCURSOR); - ++YYCURSOR; YYDEBUG(364, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(365, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1316 "Zend/zend_language_scanner.l" { return T_DOUBLE_CAST; } -#line 4424 "Zend/zend_language_scanner.c" -yy365: - YYDEBUG(365, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'U') goto yy366; - if (yych != 'u') goto yy157; +#line 4426 "Zend/zend_language_scanner.c" yy366: YYDEBUG(366, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'B') goto yy367; - if (yych != 'b') goto yy157; + if (yych == 'U') goto yy367; + if (yych != 'u') goto yy158; yy367: YYDEBUG(367, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy368; - if (yych != 'l') goto yy157; + if (yych == 'B') goto yy368; + if (yych != 'b') goto yy158; yy368: YYDEBUG(368, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy361; - if (yych == 'e') goto yy361; - goto yy157; + if (yych == 'L') goto yy369; + if (yych != 'l') goto yy158; yy369: YYDEBUG(369, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy370; - if (yych != 'a') goto yy157; + if (yych == 'E') goto yy362; + if (yych == 'e') goto yy362; + goto yy158; yy370: YYDEBUG(370, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy361; - if (yych == 'l') goto yy361; - goto yy157; + if (yych == 'A') goto yy371; + if (yych != 'a') goto yy158; yy371: YYDEBUG(371, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy372; - if (yych != 'r') goto yy157; + if (yych == 'L') goto yy362; + if (yych == 'l') goto yy362; + goto yy158; yy372: YYDEBUG(372, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy373; - if (yych != 'i') goto yy157; + if (yych == 'R') goto yy373; + if (yych != 'r') goto yy158; yy373: YYDEBUG(373, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy374; - if (yych != 'n') goto yy157; + if (yych == 'I') goto yy374; + if (yych != 'i') goto yy158; yy374: YYDEBUG(374, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'G') goto yy375; - if (yych != 'g') goto yy157; + if (yych == 'N') goto yy375; + if (yych != 'n') goto yy158; yy375: YYDEBUG(375, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'G') goto yy376; + if (yych != 'g') goto yy158; +yy376: + YYDEBUG(376, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(376, *YYCURSOR); + YYDEBUG(377, *YYCURSOR); if (yych <= 0x1F) { - if (yych == '\t') goto yy375; - goto yy157; + if (yych == '\t') goto yy376; + goto yy158; } else { - if (yych <= ' ') goto yy375; - if (yych != ')') goto yy157; + if (yych <= ' ') goto yy376; + if (yych != ')') goto yy158; } - YYDEBUG(377, *YYCURSOR); - ++YYCURSOR; YYDEBUG(378, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(379, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1320 "Zend/zend_language_scanner.l" { return T_STRING_CAST; } -#line 4498 "Zend/zend_language_scanner.c" -yy379: - YYDEBUG(379, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy380; - if (yych != 'r') goto yy157; +#line 4500 "Zend/zend_language_scanner.c" yy380: YYDEBUG(380, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy381; - if (yych != 'a') goto yy157; + if (yych == 'R') goto yy381; + if (yych != 'r') goto yy158; yy381: YYDEBUG(381, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'Y') goto yy382; - if (yych != 'y') goto yy157; + if (yych == 'A') goto yy382; + if (yych != 'a') goto yy158; yy382: YYDEBUG(382, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'Y') goto yy383; + if (yych != 'y') goto yy158; +yy383: + YYDEBUG(383, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(383, *YYCURSOR); + YYDEBUG(384, *YYCURSOR); if (yych <= 0x1F) { - if (yych == '\t') goto yy382; - goto yy157; + if (yych == '\t') goto yy383; + goto yy158; } else { - if (yych <= ' ') goto yy382; - if (yych != ')') goto yy157; + if (yych <= ' ') goto yy383; + if (yych != ')') goto yy158; } - YYDEBUG(384, *YYCURSOR); - ++YYCURSOR; YYDEBUG(385, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(386, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1324 "Zend/zend_language_scanner.l" { return T_ARRAY_CAST; } -#line 4535 "Zend/zend_language_scanner.c" -yy386: - YYDEBUG(386, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'J') goto yy387; - if (yych != 'j') goto yy157; +#line 4537 "Zend/zend_language_scanner.c" yy387: YYDEBUG(387, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy388; - if (yych != 'e') goto yy157; + if (yych == 'J') goto yy388; + if (yych != 'j') goto yy158; yy388: YYDEBUG(388, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy389; - if (yych != 'c') goto yy157; + if (yych == 'E') goto yy389; + if (yych != 'e') goto yy158; yy389: YYDEBUG(389, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy390; - if (yych != 't') goto yy157; + if (yych == 'C') goto yy390; + if (yych != 'c') goto yy158; yy390: YYDEBUG(390, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy391; + if (yych != 't') goto yy158; +yy391: + YYDEBUG(391, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(391, *YYCURSOR); + YYDEBUG(392, *YYCURSOR); if (yych <= 0x1F) { - if (yych == '\t') goto yy390; - goto yy157; + if (yych == '\t') goto yy391; + goto yy158; } else { - if (yych <= ' ') goto yy390; - if (yych != ')') goto yy157; + if (yych <= ' ') goto yy391; + if (yych != ')') goto yy158; } - YYDEBUG(392, *YYCURSOR); - ++YYCURSOR; YYDEBUG(393, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(394, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1328 "Zend/zend_language_scanner.l" { return T_OBJECT_CAST; } -#line 4577 "Zend/zend_language_scanner.c" -yy394: - YYDEBUG(394, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'N') goto yy404; - if (yych == 'n') goto yy404; - goto yy157; +#line 4579 "Zend/zend_language_scanner.c" yy395: YYDEBUG(395, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy396; - if (yych != 'o') goto yy157; + if (yych == 'N') goto yy405; + if (yych == 'n') goto yy405; + goto yy158; yy396: YYDEBUG(396, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy397; - if (yych != 'l') goto yy157; + if (yych == 'O') goto yy397; + if (yych != 'o') goto yy158; yy397: YYDEBUG(397, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy402; - if (yych == 'e') goto yy402; - goto yy399; + if (yych == 'L') goto yy398; + if (yych != 'l') goto yy158; yy398: YYDEBUG(398, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy403; + if (yych == 'e') goto yy403; + goto yy400; +yy399: + YYDEBUG(399, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy399: - YYDEBUG(399, *YYCURSOR); +yy400: + YYDEBUG(400, *YYCURSOR); if (yych <= 0x1F) { - if (yych == '\t') goto yy398; - goto yy157; + if (yych == '\t') goto yy399; + goto yy158; } else { - if (yych <= ' ') goto yy398; - if (yych != ')') goto yy157; + if (yych <= ' ') goto yy399; + if (yych != ')') goto yy158; } - YYDEBUG(400, *YYCURSOR); - ++YYCURSOR; YYDEBUG(401, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(402, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1332 "Zend/zend_language_scanner.l" { return T_BOOL_CAST; } -#line 4622 "Zend/zend_language_scanner.c" -yy402: - YYDEBUG(402, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy403; - if (yych != 'a') goto yy157; +#line 4624 "Zend/zend_language_scanner.c" yy403: YYDEBUG(403, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy398; - if (yych == 'n') goto yy398; - goto yy157; + if (yych == 'A') goto yy404; + if (yych != 'a') goto yy158; yy404: YYDEBUG(404, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy405; - if (yych != 'a') goto yy157; + if (yych == 'N') goto yy399; + if (yych == 'n') goto yy399; + goto yy158; yy405: YYDEBUG(405, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy406; - if (yych != 'r') goto yy157; + if (yych == 'A') goto yy406; + if (yych != 'a') goto yy158; yy406: YYDEBUG(406, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'Y') goto yy375; - if (yych == 'y') goto yy375; - goto yy157; + if (yych == 'R') goto yy407; + if (yych != 'r') goto yy158; yy407: YYDEBUG(407, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'S') goto yy408; - if (yych != 's') goto yy157; + if (yych == 'Y') goto yy376; + if (yych == 'y') goto yy376; + goto yy158; yy408: YYDEBUG(408, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy409; - if (yych != 'e') goto yy157; + if (yych == 'S') goto yy409; + if (yych != 's') goto yy158; yy409: YYDEBUG(409, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy410; - if (yych != 't') goto yy157; + if (yych == 'E') goto yy410; + if (yych != 'e') goto yy158; yy410: YYDEBUG(410, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy411; + if (yych != 't') goto yy158; +yy411: + YYDEBUG(411, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(411, *YYCURSOR); + YYDEBUG(412, *YYCURSOR); if (yych <= 0x1F) { - if (yych == '\t') goto yy410; - goto yy157; + if (yych == '\t') goto yy411; + goto yy158; } else { - if (yych <= ' ') goto yy410; - if (yych != ')') goto yy157; + if (yych <= ' ') goto yy411; + if (yych != ')') goto yy158; } - YYDEBUG(412, *YYCURSOR); - ++YYCURSOR; YYDEBUG(413, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(414, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1336 "Zend/zend_language_scanner.l" { return T_UNSET_CAST; } -#line 4686 "Zend/zend_language_scanner.c" -yy414: - YYDEBUG(414, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy415; - if (yych != 'r') goto yy150; +#line 4688 "Zend/zend_language_scanner.c" yy415: YYDEBUG(415, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'R') goto yy416; + if (yych != 'r') goto yy151; +yy416: + YYDEBUG(416, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(416, *YYCURSOR); + YYDEBUG(417, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1308 "Zend/zend_language_scanner.l" { return T_VAR; } -#line 4704 "Zend/zend_language_scanner.c" -yy417: - YYDEBUG(417, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'M') goto yy421; - if (yych == 'm') goto yy421; - goto yy150; +#line 4706 "Zend/zend_language_scanner.c" yy418: YYDEBUG(418, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'W') goto yy419; - if (yych != 'w') goto yy150; + if (yych == 'M') goto yy422; + if (yych == 'm') goto yy422; + goto yy151; yy419: YYDEBUG(419, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'W') goto yy420; + if (yych != 'w') goto yy151; +yy420: + YYDEBUG(420, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(420, *YYCURSOR); + YYDEBUG(421, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1300 "Zend/zend_language_scanner.l" { return T_NEW; } -#line 4728 "Zend/zend_language_scanner.c" -yy421: - YYDEBUG(421, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy422; - if (yych != 'e') goto yy150; +#line 4730 "Zend/zend_language_scanner.c" yy422: YYDEBUG(422, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'S') goto yy423; - if (yych != 's') goto yy150; + if (yych == 'E') goto yy423; + if (yych != 'e') goto yy151; yy423: YYDEBUG(423, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'P') goto yy424; - if (yych != 'p') goto yy150; + if (yych == 'S') goto yy424; + if (yych != 's') goto yy151; yy424: YYDEBUG(424, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy425; - if (yych != 'a') goto yy150; + if (yych == 'P') goto yy425; + if (yych != 'p') goto yy151; yy425: YYDEBUG(425, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy426; - if (yych != 'c') goto yy150; + if (yych == 'A') goto yy426; + if (yych != 'a') goto yy151; yy426: YYDEBUG(426, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy427; - if (yych != 'e') goto yy150; + if (yych == 'C') goto yy427; + if (yych != 'c') goto yy151; yy427: YYDEBUG(427, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy428; + if (yych != 'e') goto yy151; +yy428: + YYDEBUG(428, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(428, *YYCURSOR); + YYDEBUG(429, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1360 "Zend/zend_language_scanner.l" { return T_NAMESPACE; } -#line 4771 "Zend/zend_language_scanner.c" -yy429: - YYDEBUG(429, *YYCURSOR); - ++YYCURSOR; - if ((yych = *YYCURSOR) == '\n') goto yy433; - if (yych == '\r') goto yy434; +#line 4773 "Zend/zend_language_scanner.c" yy430: YYDEBUG(430, *YYCURSOR); + ++YYCURSOR; + if ((yych = *YYCURSOR) == '\n') goto yy434; + if (yych == '\r') goto yy435; +yy431: + YYDEBUG(431, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1922 "Zend/zend_language_scanner.l" { BEGIN(INITIAL); return T_CLOSE_TAG; /* implicit ';' at php-end tag */ } -#line 4785 "Zend/zend_language_scanner.c" -yy431: - YYDEBUG(431, *YYCURSOR); - ++YYCURSOR; +#line 4787 "Zend/zend_language_scanner.c" +yy432: YYDEBUG(432, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(433, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1296 "Zend/zend_language_scanner.l" { return T_COALESCE; } -#line 4795 "Zend/zend_language_scanner.c" -yy433: - YYDEBUG(433, *YYCURSOR); - yych = *++YYCURSOR; - goto yy430; +#line 4797 "Zend/zend_language_scanner.c" yy434: YYDEBUG(434, *YYCURSOR); yych = *++YYCURSOR; - if (yych == '\n') goto yy433; - goto yy430; + goto yy431; yy435: YYDEBUG(435, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == '\n') goto yy434; + goto yy431; +yy436: + YYDEBUG(436, *YYCURSOR); yyaccept = 3; YYMARKER = ++YYCURSOR; YYFILL(3); yych = *YYCURSOR; - YYDEBUG(436, *YYCURSOR); + YYDEBUG(437, *YYCURSOR); if (yych <= 'D') { - if (yych <= '/') goto yy153; - if (yych <= '9') goto yy435; - goto yy153; + if (yych <= '/') goto yy154; + if (yych <= '9') goto yy436; + goto yy154; } else { - if (yych <= 'E') goto yy156; - if (yych == 'e') goto yy156; - goto yy153; + if (yych <= 'E') goto yy157; + if (yych == 'e') goto yy157; + goto yy154; } -yy437: - YYDEBUG(437, *YYCURSOR); - ++YYCURSOR; +yy438: YYDEBUG(438, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(439, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1488 "Zend/zend_language_scanner.l" { return T_CONCAT_EQUAL; } -#line 4830 "Zend/zend_language_scanner.c" -yy439: - YYDEBUG(439, *YYCURSOR); - yych = *++YYCURSOR; - if (yych != '.') goto yy157; +#line 4832 "Zend/zend_language_scanner.c" +yy440: YYDEBUG(440, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych != '.') goto yy158; YYDEBUG(441, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(442, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1292 "Zend/zend_language_scanner.l" { return T_ELLIPSIS; } -#line 4843 "Zend/zend_language_scanner.c" -yy442: - YYDEBUG(442, *YYCURSOR); - ++YYCURSOR; +#line 4845 "Zend/zend_language_scanner.c" +yy443: YYDEBUG(443, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(444, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1284 "Zend/zend_language_scanner.l" { return T_PAAMAYIM_NEKUDOTAYIM; } -#line 4853 "Zend/zend_language_scanner.c" -yy444: - YYDEBUG(444, *YYCURSOR); +#line 4855 "Zend/zend_language_scanner.c" +yy445: + YYDEBUG(445, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy445: - YYDEBUG(445, *YYCURSOR); +yy446: + YYDEBUG(446, *YYCURSOR); if (yych <= '\f') { - if (yych <= 0x08) goto yy104; - if (yych <= '\n') goto yy444; - goto yy104; + if (yych <= 0x08) goto yy105; + if (yych <= '\n') goto yy445; + goto yy105; } else { - if (yych <= '\r') goto yy444; - if (yych == ' ') goto yy444; - goto yy104; + if (yych <= '\r') goto yy445; + if (yych == ' ') goto yy445; + goto yy105; } -yy446: - YYDEBUG(446, *YYCURSOR); - ++YYCURSOR; +yy447: YYDEBUG(447, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(448, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1468 "Zend/zend_language_scanner.l" { return T_MINUS_EQUAL; } -#line 4879 "Zend/zend_language_scanner.c" -yy448: - YYDEBUG(448, *YYCURSOR); - ++YYCURSOR; +#line 4881 "Zend/zend_language_scanner.c" +yy449: YYDEBUG(449, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(450, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1436 "Zend/zend_language_scanner.l" { return T_DEC; } -#line 4889 "Zend/zend_language_scanner.c" -yy450: - YYDEBUG(450, *YYCURSOR); - ++YYCURSOR; +#line 4891 "Zend/zend_language_scanner.c" +yy451: YYDEBUG(451, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(452, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1258 "Zend/zend_language_scanner.l" { yy_push_state(ST_LOOKING_FOR_PROPERTY); return T_OBJECT_OPERATOR; } -#line 4900 "Zend/zend_language_scanner.c" -yy452: - YYDEBUG(452, *YYCURSOR); +#line 4902 "Zend/zend_language_scanner.c" +yy453: + YYDEBUG(453, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'O') { - if (yych == 'I') goto yy459; - if (yych <= 'N') goto yy150; - goto yy460; + if (yych == 'I') goto yy460; + if (yych <= 'N') goto yy151; + goto yy461; } else { if (yych <= 'i') { - if (yych <= 'h') goto yy150; - goto yy459; + if (yych <= 'h') goto yy151; + goto yy460; } else { - if (yych == 'o') goto yy460; - goto yy150; + if (yych == 'o') goto yy461; + goto yy151; } } -yy453: - YYDEBUG(453, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'B') goto yy454; - if (yych != 'b') goto yy150; yy454: YYDEBUG(454, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy455; - if (yych != 'l') goto yy150; + if (yych == 'B') goto yy455; + if (yych != 'b') goto yy151; yy455: YYDEBUG(455, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy456; - if (yych != 'i') goto yy150; + if (yych == 'L') goto yy456; + if (yych != 'l') goto yy151; yy456: YYDEBUG(456, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy457; - if (yych != 'c') goto yy150; + if (yych == 'I') goto yy457; + if (yych != 'i') goto yy151; yy457: YYDEBUG(457, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'C') goto yy458; + if (yych != 'c') goto yy151; +yy458: + YYDEBUG(458, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(458, *YYCURSOR); + YYDEBUG(459, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1408 "Zend/zend_language_scanner.l" { return T_PUBLIC; } -#line 4949 "Zend/zend_language_scanner.c" -yy459: - YYDEBUG(459, *YYCURSOR); +#line 4951 "Zend/zend_language_scanner.c" +yy460: + YYDEBUG(460, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'V') { - if (yych == 'N') goto yy468; - if (yych <= 'U') goto yy150; - goto yy469; + if (yych == 'N') goto yy469; + if (yych <= 'U') goto yy151; + goto yy470; } else { if (yych <= 'n') { - if (yych <= 'm') goto yy150; - goto yy468; + if (yych <= 'm') goto yy151; + goto yy469; } else { - if (yych == 'v') goto yy469; - goto yy150; + if (yych == 'v') goto yy470; + goto yy151; } } -yy460: - YYDEBUG(460, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy461; - if (yych != 't') goto yy150; yy461: YYDEBUG(461, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy462; - if (yych != 'e') goto yy150; + if (yych == 'T') goto yy462; + if (yych != 't') goto yy151; yy462: YYDEBUG(462, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy463; - if (yych != 'c') goto yy150; + if (yych == 'E') goto yy463; + if (yych != 'e') goto yy151; yy463: YYDEBUG(463, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy464; - if (yych != 't') goto yy150; + if (yych == 'C') goto yy464; + if (yych != 'c') goto yy151; yy464: YYDEBUG(464, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy465; - if (yych != 'e') goto yy150; + if (yych == 'T') goto yy465; + if (yych != 't') goto yy151; yy465: YYDEBUG(465, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy466; - if (yych != 'd') goto yy150; + if (yych == 'E') goto yy466; + if (yych != 'e') goto yy151; yy466: YYDEBUG(466, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'D') goto yy467; + if (yych != 'd') goto yy151; +yy467: + YYDEBUG(467, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(467, *YYCURSOR); + YYDEBUG(468, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1404 "Zend/zend_language_scanner.l" { return T_PROTECTED; } -#line 5008 "Zend/zend_language_scanner.c" -yy468: - YYDEBUG(468, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy474; - if (yych == 't') goto yy474; - goto yy150; +#line 5010 "Zend/zend_language_scanner.c" yy469: YYDEBUG(469, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy470; - if (yych != 'a') goto yy150; + if (yych == 'T') goto yy475; + if (yych == 't') goto yy475; + goto yy151; yy470: YYDEBUG(470, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy471; - if (yych != 't') goto yy150; + if (yych == 'A') goto yy471; + if (yych != 'a') goto yy151; yy471: YYDEBUG(471, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy472; - if (yych != 'e') goto yy150; + if (yych == 'T') goto yy472; + if (yych != 't') goto yy151; yy472: YYDEBUG(472, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy473; + if (yych != 'e') goto yy151; +yy473: + YYDEBUG(473, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(473, *YYCURSOR); + YYDEBUG(474, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1400 "Zend/zend_language_scanner.l" { return T_PRIVATE; } -#line 5042 "Zend/zend_language_scanner.c" -yy474: - YYDEBUG(474, *YYCURSOR); +#line 5044 "Zend/zend_language_scanner.c" +yy475: + YYDEBUG(475, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(475, *YYCURSOR); + YYDEBUG(476, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1234 "Zend/zend_language_scanner.l" { return T_PRINT; } -#line 5055 "Zend/zend_language_scanner.c" -yy476: - YYDEBUG(476, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'O') goto yy481; - if (yych == 'o') goto yy481; - goto yy150; +#line 5057 "Zend/zend_language_scanner.c" yy477: YYDEBUG(477, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy478; - if (yych != 't') goto yy150; + if (yych == 'O') goto yy482; + if (yych == 'o') goto yy482; + goto yy151; yy478: YYDEBUG(478, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy479; - if (yych != 'o') goto yy150; + if (yych == 'T') goto yy479; + if (yych != 't') goto yy151; yy479: YYDEBUG(479, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'O') goto yy480; + if (yych != 'o') goto yy151; +yy480: + YYDEBUG(480, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(480, *YYCURSOR); + YYDEBUG(481, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1226 "Zend/zend_language_scanner.l" { return T_GOTO; } -#line 5084 "Zend/zend_language_scanner.c" -yy481: - YYDEBUG(481, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'B') goto yy482; - if (yych != 'b') goto yy150; +#line 5086 "Zend/zend_language_scanner.c" yy482: YYDEBUG(482, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy483; - if (yych != 'a') goto yy150; + if (yych == 'B') goto yy483; + if (yych != 'b') goto yy151; yy483: YYDEBUG(483, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy484; - if (yych != 'l') goto yy150; + if (yych == 'A') goto yy484; + if (yych != 'a') goto yy151; yy484: YYDEBUG(484, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'L') goto yy485; + if (yych != 'l') goto yy151; +yy485: + YYDEBUG(485, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(485, *YYCURSOR); + YYDEBUG(486, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1372 "Zend/zend_language_scanner.l" { return T_GLOBAL; } -#line 5112 "Zend/zend_language_scanner.c" -yy486: - YYDEBUG(486, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '<') goto yy494; - goto yy157; +#line 5114 "Zend/zend_language_scanner.c" yy487: YYDEBUG(487, *YYCURSOR); yych = *++YYCURSOR; - goto yy144; + if (yych == '<') goto yy495; + goto yy158; yy488: YYDEBUG(488, *YYCURSOR); yych = *++YYCURSOR; - goto yy142; + goto yy145; yy489: YYDEBUG(489, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy490; - if (yych != 'e') goto yy150; + goto yy143; yy490: YYDEBUG(490, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy491; - if (yych != 'a') goto yy150; + if (yych == 'E') goto yy491; + if (yych != 'e') goto yy151; yy491: YYDEBUG(491, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'K') goto yy492; - if (yych != 'k') goto yy150; + if (yych == 'A') goto yy492; + if (yych != 'a') goto yy151; yy492: YYDEBUG(492, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'K') goto yy493; + if (yych != 'k') goto yy151; +yy493: + YYDEBUG(493, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(493, *YYCURSOR); + YYDEBUG(494, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1218 "Zend/zend_language_scanner.l" { return T_BREAK; } -#line 5153 "Zend/zend_language_scanner.c" -yy494: - YYDEBUG(494, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == '<') goto yy217; - goto yy157; +#line 5155 "Zend/zend_language_scanner.c" yy495: YYDEBUG(495, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy502; - if (yych == 'a') goto yy502; - goto yy150; + if (yych == '<') goto yy218; + goto yy158; yy496: YYDEBUG(496, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy497; - if (yych != 'i') goto yy150; + if (yych == 'A') goto yy503; + if (yych == 'a') goto yy503; + goto yy151; yy497: YYDEBUG(497, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy498; - if (yych != 't') goto yy150; + if (yych == 'I') goto yy498; + if (yych != 'i') goto yy151; yy498: YYDEBUG(498, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy499; - if (yych != 'c') goto yy150; + if (yych == 'T') goto yy499; + if (yych != 't') goto yy151; yy499: YYDEBUG(499, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'H') goto yy500; - if (yych != 'h') goto yy150; + if (yych == 'C') goto yy500; + if (yych != 'c') goto yy151; yy500: YYDEBUG(500, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'H') goto yy501; + if (yych != 'h') goto yy151; +yy501: + YYDEBUG(501, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(501, *YYCURSOR); + YYDEBUG(502, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1202 "Zend/zend_language_scanner.l" { return T_SWITCH; } -#line 5197 "Zend/zend_language_scanner.c" -yy502: - YYDEBUG(502, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy503; - if (yych != 't') goto yy150; +#line 5199 "Zend/zend_language_scanner.c" yy503: YYDEBUG(503, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy504; - if (yych != 'i') goto yy150; + if (yych == 'T') goto yy504; + if (yych != 't') goto yy151; yy504: YYDEBUG(504, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy505; - if (yych != 'c') goto yy150; + if (yych == 'I') goto yy505; + if (yych != 'i') goto yy151; yy505: YYDEBUG(505, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'C') goto yy506; + if (yych != 'c') goto yy151; +yy506: + YYDEBUG(506, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(506, *YYCURSOR); + YYDEBUG(507, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1388 "Zend/zend_language_scanner.l" { return T_STATIC; } -#line 5225 "Zend/zend_language_scanner.c" -yy507: - YYDEBUG(507, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'S') goto yy518; - if (yych == 's') goto yy518; - goto yy150; +#line 5227 "Zend/zend_language_scanner.c" yy508: YYDEBUG(508, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy516; - if (yych == 'd') goto yy516; - goto yy150; + if (yych == 'S') goto yy519; + if (yych == 's') goto yy519; + goto yy151; yy509: YYDEBUG(509, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy512; - if (yych == 'r') goto yy512; - goto yy150; + if (yych == 'D') goto yy517; + if (yych == 'd') goto yy517; + goto yy151; yy510: YYDEBUG(510, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'R') goto yy513; + if (yych == 'r') goto yy513; + goto yy151; +yy511: + YYDEBUG(511, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(511, *YYCURSOR); + YYDEBUG(512, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1198 "Zend/zend_language_scanner.l" { return T_AS; } -#line 5256 "Zend/zend_language_scanner.c" -yy512: - YYDEBUG(512, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy513; - if (yych != 'a') goto yy150; +#line 5258 "Zend/zend_language_scanner.c" yy513: YYDEBUG(513, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'Y') goto yy514; - if (yych != 'y') goto yy150; + if (yych == 'A') goto yy514; + if (yych != 'a') goto yy151; yy514: YYDEBUG(514, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'Y') goto yy515; + if (yych != 'y') goto yy151; +yy515: + YYDEBUG(515, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(515, *YYCURSOR); + YYDEBUG(516, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1424 "Zend/zend_language_scanner.l" { return T_ARRAY; } -#line 5279 "Zend/zend_language_scanner.c" -yy516: - YYDEBUG(516, *YYCURSOR); +#line 5281 "Zend/zend_language_scanner.c" +yy517: + YYDEBUG(517, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(517, *YYCURSOR); + YYDEBUG(518, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1528 "Zend/zend_language_scanner.l" { return T_LOGICAL_AND; } -#line 5292 "Zend/zend_language_scanner.c" -yy518: - YYDEBUG(518, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy519; - if (yych != 't') goto yy150; +#line 5294 "Zend/zend_language_scanner.c" yy519: YYDEBUG(519, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy520; - if (yych != 'r') goto yy150; + if (yych == 'T') goto yy520; + if (yych != 't') goto yy151; yy520: YYDEBUG(520, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy521; - if (yych != 'a') goto yy150; + if (yych == 'R') goto yy521; + if (yych != 'r') goto yy151; yy521: YYDEBUG(521, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy522; - if (yych != 'c') goto yy150; + if (yych == 'A') goto yy522; + if (yych != 'a') goto yy151; yy522: YYDEBUG(522, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy523; - if (yych != 't') goto yy150; + if (yych == 'C') goto yy523; + if (yych != 'c') goto yy151; yy523: YYDEBUG(523, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy524; + if (yych != 't') goto yy151; +yy524: + YYDEBUG(524, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(524, *YYCURSOR); + YYDEBUG(525, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1392 "Zend/zend_language_scanner.l" { return T_ABSTRACT; } -#line 5330 "Zend/zend_language_scanner.c" -yy525: - YYDEBUG(525, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'I') goto yy526; - if (yych != 'i') goto yy150; +#line 5332 "Zend/zend_language_scanner.c" yy526: YYDEBUG(526, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy527; - if (yych != 'l') goto yy150; + if (yych == 'I') goto yy527; + if (yych != 'i') goto yy151; yy527: YYDEBUG(527, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy528; - if (yych != 'e') goto yy150; + if (yych == 'L') goto yy528; + if (yych != 'l') goto yy151; yy528: YYDEBUG(528, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy529; + if (yych != 'e') goto yy151; +yy529: + YYDEBUG(529, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(529, *YYCURSOR); + YYDEBUG(530, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1158 "Zend/zend_language_scanner.l" { return T_WHILE; } -#line 5358 "Zend/zend_language_scanner.c" -yy530: - YYDEBUG(530, *YYCURSOR); +#line 5360 "Zend/zend_language_scanner.c" +yy531: + YYDEBUG(531, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(531, *YYCURSOR); + YYDEBUG(532, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1142 "Zend/zend_language_scanner.l" { return T_IF; } -#line 5371 "Zend/zend_language_scanner.c" -yy532: - YYDEBUG(532, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'P') goto yy574; - if (yych == 'p') goto yy574; - goto yy150; +#line 5373 "Zend/zend_language_scanner.c" yy533: YYDEBUG(533, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'P') goto yy575; + if (yych == 'p') goto yy575; + goto yy151; +yy534: + YYDEBUG(534, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'T') { if (yych <= 'C') { - if (yych <= 'B') goto yy150; - goto yy541; + if (yych <= 'B') goto yy151; + goto yy542; } else { - if (yych <= 'R') goto yy150; - if (yych <= 'S') goto yy539; - goto yy540; + if (yych <= 'R') goto yy151; + if (yych <= 'S') goto yy540; + goto yy541; } } else { if (yych <= 'r') { - if (yych == 'c') goto yy541; - goto yy150; + if (yych == 'c') goto yy542; + goto yy151; } else { - if (yych <= 's') goto yy539; - if (yych <= 't') goto yy540; - goto yy150; + if (yych <= 's') goto yy540; + if (yych <= 't') goto yy541; + goto yy151; } } -yy534: - YYDEBUG(534, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'S') goto yy535; - if (yych != 's') goto yy150; yy535: YYDEBUG(535, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy536; - if (yych != 'e') goto yy150; + if (yych == 'S') goto yy536; + if (yych != 's') goto yy151; yy536: YYDEBUG(536, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy537; - if (yych != 't') goto yy150; + if (yych == 'E') goto yy537; + if (yych != 'e') goto yy151; yy537: YYDEBUG(537, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy538; + if (yych != 't') goto yy151; +yy538: + YYDEBUG(538, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(538, *YYCURSOR); + YYDEBUG(539, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1376 "Zend/zend_language_scanner.l" { return T_ISSET; } -#line 5427 "Zend/zend_language_scanner.c" -yy539: - YYDEBUG(539, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy560; - if (yych == 't') goto yy560; - goto yy150; +#line 5429 "Zend/zend_language_scanner.c" yy540: YYDEBUG(540, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy553; - if (yych == 'e') goto yy553; - goto yy150; + if (yych == 'T') goto yy561; + if (yych == 't') goto yy561; + goto yy151; yy541: YYDEBUG(541, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy542; - if (yych != 'l') goto yy150; + if (yych == 'E') goto yy554; + if (yych == 'e') goto yy554; + goto yy151; yy542: YYDEBUG(542, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'U') goto yy543; - if (yych != 'u') goto yy150; + if (yych == 'L') goto yy543; + if (yych != 'l') goto yy151; yy543: YYDEBUG(543, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy544; - if (yych != 'd') goto yy150; + if (yych == 'U') goto yy544; + if (yych != 'u') goto yy151; yy544: YYDEBUG(544, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy545; - if (yych != 'e') goto yy150; + if (yych == 'D') goto yy545; + if (yych != 'd') goto yy151; yy545: YYDEBUG(545, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy546; + if (yych != 'e') goto yy151; +yy546: + YYDEBUG(546, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '^') { if (yych <= '9') { - if (yych >= '0') goto yy149; + if (yych >= '0') goto yy150; } else { - if (yych <= '@') goto yy546; - if (yych <= 'Z') goto yy149; + if (yych <= '@') goto yy547; + if (yych <= 'Z') goto yy150; } } else { if (yych <= '`') { - if (yych <= '_') goto yy547; + if (yych <= '_') goto yy548; } else { - if (yych <= 'z') goto yy149; - if (yych >= 0x7F) goto yy149; + if (yych <= 'z') goto yy150; + if (yych >= 0x7F) goto yy150; } } -yy546: - YYDEBUG(546, *YYCURSOR); +yy547: + YYDEBUG(547, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1344 "Zend/zend_language_scanner.l" { return T_INCLUDE; } -#line 5485 "Zend/zend_language_scanner.c" -yy547: - YYDEBUG(547, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'O') goto yy548; - if (yych != 'o') goto yy150; +#line 5487 "Zend/zend_language_scanner.c" yy548: YYDEBUG(548, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy549; - if (yych != 'n') goto yy150; + if (yych == 'O') goto yy549; + if (yych != 'o') goto yy151; yy549: YYDEBUG(549, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy550; - if (yych != 'c') goto yy150; + if (yych == 'N') goto yy550; + if (yych != 'n') goto yy151; yy550: YYDEBUG(550, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy551; - if (yych != 'e') goto yy150; + if (yych == 'C') goto yy551; + if (yych != 'c') goto yy151; yy551: YYDEBUG(551, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy552; + if (yych != 'e') goto yy151; +yy552: + YYDEBUG(552, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(552, *YYCURSOR); + YYDEBUG(553, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1348 "Zend/zend_language_scanner.l" { return T_INCLUDE_ONCE; } -#line 5518 "Zend/zend_language_scanner.c" -yy553: - YYDEBUG(553, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy554; - if (yych != 'r') goto yy150; +#line 5520 "Zend/zend_language_scanner.c" yy554: YYDEBUG(554, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'F') goto yy555; - if (yych != 'f') goto yy150; + if (yych == 'R') goto yy555; + if (yych != 'r') goto yy151; yy555: YYDEBUG(555, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy556; - if (yych != 'a') goto yy150; + if (yych == 'F') goto yy556; + if (yych != 'f') goto yy151; yy556: YYDEBUG(556, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy557; - if (yych != 'c') goto yy150; + if (yych == 'A') goto yy557; + if (yych != 'a') goto yy151; yy557: YYDEBUG(557, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy558; - if (yych != 'e') goto yy150; + if (yych == 'C') goto yy558; + if (yych != 'c') goto yy151; yy558: YYDEBUG(558, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy559; + if (yych != 'e') goto yy151; +yy559: + YYDEBUG(559, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(559, *YYCURSOR); + YYDEBUG(560, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1242 "Zend/zend_language_scanner.l" { return T_INTERFACE; } -#line 5556 "Zend/zend_language_scanner.c" -yy560: - YYDEBUG(560, *YYCURSOR); +#line 5558 "Zend/zend_language_scanner.c" +yy561: + YYDEBUG(561, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'E') { - if (yych == 'A') goto yy561; - if (yych <= 'D') goto yy150; - goto yy562; + if (yych == 'A') goto yy562; + if (yych <= 'D') goto yy151; + goto yy563; } else { if (yych <= 'a') { - if (yych <= '`') goto yy150; + if (yych <= '`') goto yy151; } else { - if (yych == 'e') goto yy562; - goto yy150; + if (yych == 'e') goto yy563; + goto yy151; } } -yy561: - YYDEBUG(561, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'N') goto yy568; - if (yych == 'n') goto yy568; - goto yy150; yy562: YYDEBUG(562, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy563; - if (yych != 'a') goto yy150; + if (yych == 'N') goto yy569; + if (yych == 'n') goto yy569; + goto yy151; yy563: YYDEBUG(563, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy564; - if (yych != 'd') goto yy150; + if (yych == 'A') goto yy564; + if (yych != 'a') goto yy151; yy564: YYDEBUG(564, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy565; - if (yych != 'o') goto yy150; + if (yych == 'D') goto yy565; + if (yych != 'd') goto yy151; yy565: YYDEBUG(565, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'F') goto yy566; - if (yych != 'f') goto yy150; + if (yych == 'O') goto yy566; + if (yych != 'o') goto yy151; yy566: YYDEBUG(566, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'F') goto yy567; + if (yych != 'f') goto yy151; +yy567: + YYDEBUG(567, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(567, *YYCURSOR); + YYDEBUG(568, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1368 "Zend/zend_language_scanner.l" { return T_INSTEADOF; } -#line 5610 "Zend/zend_language_scanner.c" -yy568: - YYDEBUG(568, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'C') goto yy569; - if (yych != 'c') goto yy150; +#line 5612 "Zend/zend_language_scanner.c" yy569: YYDEBUG(569, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy570; - if (yych != 'e') goto yy150; + if (yych == 'C') goto yy570; + if (yych != 'c') goto yy151; yy570: YYDEBUG(570, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy571; - if (yych != 'o') goto yy150; + if (yych == 'E') goto yy571; + if (yych != 'e') goto yy151; yy571: YYDEBUG(571, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'F') goto yy572; - if (yych != 'f') goto yy150; + if (yych == 'O') goto yy572; + if (yych != 'o') goto yy151; yy572: YYDEBUG(572, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'F') goto yy573; + if (yych != 'f') goto yy151; +yy573: + YYDEBUG(573, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(573, *YYCURSOR); + YYDEBUG(574, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1194 "Zend/zend_language_scanner.l" { return T_INSTANCEOF; } -#line 5643 "Zend/zend_language_scanner.c" -yy574: - YYDEBUG(574, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'L') goto yy575; - if (yych != 'l') goto yy150; +#line 5645 "Zend/zend_language_scanner.c" yy575: YYDEBUG(575, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy576; - if (yych != 'e') goto yy150; + if (yych == 'L') goto yy576; + if (yych != 'l') goto yy151; yy576: YYDEBUG(576, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'M') goto yy577; - if (yych != 'm') goto yy150; + if (yych == 'E') goto yy577; + if (yych != 'e') goto yy151; yy577: YYDEBUG(577, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy578; - if (yych != 'e') goto yy150; + if (yych == 'M') goto yy578; + if (yych != 'm') goto yy151; yy578: YYDEBUG(578, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy579; - if (yych != 'n') goto yy150; + if (yych == 'E') goto yy579; + if (yych != 'e') goto yy151; yy579: YYDEBUG(579, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy580; - if (yych != 't') goto yy150; + if (yych == 'N') goto yy580; + if (yych != 'n') goto yy151; yy580: YYDEBUG(580, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'S') goto yy581; - if (yych != 's') goto yy150; + if (yych == 'T') goto yy581; + if (yych != 't') goto yy151; yy581: YYDEBUG(581, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'S') goto yy582; + if (yych != 's') goto yy151; +yy582: + YYDEBUG(582, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(582, *YYCURSOR); + YYDEBUG(583, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1254 "Zend/zend_language_scanner.l" { return T_IMPLEMENTS; } -#line 5691 "Zend/zend_language_scanner.c" -yy583: - YYDEBUG(583, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy591; - if (yych == 'r') goto yy591; - goto yy150; +#line 5693 "Zend/zend_language_scanner.c" yy584: YYDEBUG(584, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'R') goto yy592; + if (yych == 'r') goto yy592; + goto yy151; +yy585: + YYDEBUG(585, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'Y') { - if (yych == 'A') goto yy587; - if (yych <= 'X') goto yy150; + if (yych == 'A') goto yy588; + if (yych <= 'X') goto yy151; } else { if (yych <= 'a') { - if (yych <= '`') goto yy150; - goto yy587; + if (yych <= '`') goto yy151; + goto yy588; } else { - if (yych != 'y') goto yy150; + if (yych != 'y') goto yy151; } } - YYDEBUG(585, *YYCURSOR); + YYDEBUG(586, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(586, *YYCURSOR); + YYDEBUG(587, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1126 "Zend/zend_language_scanner.l" { return T_TRY; } -#line 5723 "Zend/zend_language_scanner.c" -yy587: - YYDEBUG(587, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'I') goto yy588; - if (yych != 'i') goto yy150; +#line 5725 "Zend/zend_language_scanner.c" yy588: YYDEBUG(588, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy589; - if (yych != 't') goto yy150; + if (yych == 'I') goto yy589; + if (yych != 'i') goto yy151; yy589: YYDEBUG(589, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy590; + if (yych != 't') goto yy151; +yy590: + YYDEBUG(590, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(590, *YYCURSOR); + YYDEBUG(591, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1246 "Zend/zend_language_scanner.l" { return T_TRAIT; } -#line 5746 "Zend/zend_language_scanner.c" -yy591: - YYDEBUG(591, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'O') goto yy592; - if (yych != 'o') goto yy150; +#line 5748 "Zend/zend_language_scanner.c" yy592: YYDEBUG(592, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'W') goto yy593; - if (yych != 'w') goto yy150; + if (yych == 'O') goto yy593; + if (yych != 'o') goto yy151; yy593: YYDEBUG(593, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'W') goto yy594; + if (yych != 'w') goto yy151; +yy594: + YYDEBUG(594, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(594, *YYCURSOR); + YYDEBUG(595, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1138 "Zend/zend_language_scanner.l" { return T_THROW; } -#line 5769 "Zend/zend_language_scanner.c" -yy595: - YYDEBUG(595, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy596; - if (yych != 'e') goto yy150; +#line 5771 "Zend/zend_language_scanner.c" yy596: YYDEBUG(596, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy597; - if (yych != 'l') goto yy150; + if (yych == 'E') goto yy597; + if (yych != 'e') goto yy151; yy597: YYDEBUG(597, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy598; - if (yych != 'd') goto yy150; + if (yych == 'L') goto yy598; + if (yych != 'l') goto yy151; yy598: YYDEBUG(598, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'D') goto yy599; + if (yych != 'd') goto yy151; +yy599: + YYDEBUG(599, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(599, *YYCURSOR); + YYDEBUG(600, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1122 "Zend/zend_language_scanner.l" { return T_YIELD; } -#line 5797 "Zend/zend_language_scanner.c" -yy600: - YYDEBUG(600, *YYCURSOR); +#line 5799 "Zend/zend_language_scanner.c" +yy601: + YYDEBUG(601, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'T') { - if (yych == 'Q') goto yy602; - if (yych <= 'S') goto yy150; + if (yych == 'Q') goto yy603; + if (yych <= 'S') goto yy151; } else { if (yych <= 'q') { - if (yych <= 'p') goto yy150; - goto yy602; + if (yych <= 'p') goto yy151; + goto yy603; } else { - if (yych != 't') goto yy150; + if (yych != 't') goto yy151; } } - YYDEBUG(601, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'U') goto yy614; - if (yych == 'u') goto yy614; - goto yy150; -yy602: YYDEBUG(602, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'U') goto yy603; - if (yych != 'u') goto yy150; + if (yych == 'U') goto yy615; + if (yych == 'u') goto yy615; + goto yy151; yy603: YYDEBUG(603, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy604; - if (yych != 'i') goto yy150; + if (yych == 'U') goto yy604; + if (yych != 'u') goto yy151; yy604: YYDEBUG(604, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy605; - if (yych != 'r') goto yy150; + if (yych == 'I') goto yy605; + if (yych != 'i') goto yy151; yy605: YYDEBUG(605, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy606; - if (yych != 'e') goto yy150; + if (yych == 'R') goto yy606; + if (yych != 'r') goto yy151; yy606: YYDEBUG(606, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy607; + if (yych != 'e') goto yy151; +yy607: + YYDEBUG(607, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '^') { if (yych <= '9') { - if (yych >= '0') goto yy149; + if (yych >= '0') goto yy150; } else { - if (yych <= '@') goto yy607; - if (yych <= 'Z') goto yy149; + if (yych <= '@') goto yy608; + if (yych <= 'Z') goto yy150; } } else { if (yych <= '`') { - if (yych <= '_') goto yy608; + if (yych <= '_') goto yy609; } else { - if (yych <= 'z') goto yy149; - if (yych >= 0x7F) goto yy149; + if (yych <= 'z') goto yy150; + if (yych >= 0x7F) goto yy150; } } -yy607: - YYDEBUG(607, *YYCURSOR); +yy608: + YYDEBUG(608, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1352 "Zend/zend_language_scanner.l" { return T_REQUIRE; } -#line 5862 "Zend/zend_language_scanner.c" -yy608: - YYDEBUG(608, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'O') goto yy609; - if (yych != 'o') goto yy150; +#line 5864 "Zend/zend_language_scanner.c" yy609: YYDEBUG(609, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy610; - if (yych != 'n') goto yy150; + if (yych == 'O') goto yy610; + if (yych != 'o') goto yy151; yy610: YYDEBUG(610, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy611; - if (yych != 'c') goto yy150; + if (yych == 'N') goto yy611; + if (yych != 'n') goto yy151; yy611: YYDEBUG(611, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy612; - if (yych != 'e') goto yy150; + if (yych == 'C') goto yy612; + if (yych != 'c') goto yy151; yy612: YYDEBUG(612, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy613; + if (yych != 'e') goto yy151; +yy613: + YYDEBUG(613, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(613, *YYCURSOR); + YYDEBUG(614, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1356 "Zend/zend_language_scanner.l" { return T_REQUIRE_ONCE; } -#line 5895 "Zend/zend_language_scanner.c" -yy614: - YYDEBUG(614, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy615; - if (yych != 'r') goto yy150; +#line 5897 "Zend/zend_language_scanner.c" yy615: YYDEBUG(615, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy616; - if (yych != 'n') goto yy150; + if (yych == 'R') goto yy616; + if (yych != 'r') goto yy151; yy616: YYDEBUG(616, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'N') goto yy617; + if (yych != 'n') goto yy151; +yy617: + YYDEBUG(617, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(617, *YYCURSOR); + YYDEBUG(618, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1118 "Zend/zend_language_scanner.l" { return T_RETURN; } -#line 5918 "Zend/zend_language_scanner.c" -yy618: - YYDEBUG(618, *YYCURSOR); +#line 5920 "Zend/zend_language_scanner.c" +yy619: + YYDEBUG(619, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'T') { if (yych <= 'L') { - if (yych <= 'K') goto yy150; - goto yy641; + if (yych <= 'K') goto yy151; + goto yy642; } else { - if (yych <= 'R') goto yy150; - if (yych <= 'S') goto yy640; - goto yy639; + if (yych <= 'R') goto yy151; + if (yych <= 'S') goto yy641; + goto yy640; } } else { if (yych <= 'r') { - if (yych == 'l') goto yy641; - goto yy150; + if (yych == 'l') goto yy642; + goto yy151; } else { - if (yych <= 's') goto yy640; - if (yych <= 't') goto yy639; - goto yy150; + if (yych <= 's') goto yy641; + if (yych <= 't') goto yy640; + goto yy151; } } -yy619: - YYDEBUG(619, *YYCURSOR); +yy620: + YYDEBUG(620, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'O') { - if (yych == 'A') goto yy631; - if (yych <= 'N') goto yy150; - goto yy632; + if (yych == 'A') goto yy632; + if (yych <= 'N') goto yy151; + goto yy633; } else { if (yych <= 'a') { - if (yych <= '`') goto yy150; - goto yy631; + if (yych <= '`') goto yy151; + goto yy632; } else { - if (yych == 'o') goto yy632; - goto yy150; + if (yych == 'o') goto yy633; + goto yy151; } } -yy620: - YYDEBUG(620, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'N') goto yy621; - if (yych != 'n') goto yy150; yy621: YYDEBUG(621, *YYCURSOR); yych = *++YYCURSOR; - if (yych <= 'T') { - if (yych <= 'R') goto yy150; - if (yych >= 'T') goto yy623; - } else { - if (yych <= 'r') goto yy150; - if (yych <= 's') goto yy622; - if (yych <= 't') goto yy623; - goto yy150; - } + if (yych == 'N') goto yy622; + if (yych != 'n') goto yy151; yy622: YYDEBUG(622, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy629; - if (yych == 't') goto yy629; - goto yy150; + if (yych <= 'T') { + if (yych <= 'R') goto yy151; + if (yych >= 'T') goto yy624; + } else { + if (yych <= 'r') goto yy151; + if (yych <= 's') goto yy623; + if (yych <= 't') goto yy624; + goto yy151; + } yy623: YYDEBUG(623, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy624; - if (yych != 'i') goto yy150; + if (yych == 'T') goto yy630; + if (yych == 't') goto yy630; + goto yy151; yy624: YYDEBUG(624, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy625; - if (yych != 'n') goto yy150; + if (yych == 'I') goto yy625; + if (yych != 'i') goto yy151; yy625: YYDEBUG(625, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'U') goto yy626; - if (yych != 'u') goto yy150; + if (yych == 'N') goto yy626; + if (yych != 'n') goto yy151; yy626: YYDEBUG(626, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy627; - if (yych != 'e') goto yy150; + if (yych == 'U') goto yy627; + if (yych != 'u') goto yy151; yy627: YYDEBUG(627, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy628; + if (yych != 'e') goto yy151; +yy628: + YYDEBUG(628, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(628, *YYCURSOR); + YYDEBUG(629, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1222 "Zend/zend_language_scanner.l" { return T_CONTINUE; } -#line 6012 "Zend/zend_language_scanner.c" -yy629: - YYDEBUG(629, *YYCURSOR); +#line 6014 "Zend/zend_language_scanner.c" +yy630: + YYDEBUG(630, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(630, *YYCURSOR); + YYDEBUG(631, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1114 "Zend/zend_language_scanner.l" { return T_CONST; } -#line 6025 "Zend/zend_language_scanner.c" -yy631: - YYDEBUG(631, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'S') goto yy636; - if (yych == 's') goto yy636; - goto yy150; +#line 6027 "Zend/zend_language_scanner.c" yy632: YYDEBUG(632, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy633; - if (yych != 'n') goto yy150; + if (yych == 'S') goto yy637; + if (yych == 's') goto yy637; + goto yy151; yy633: YYDEBUG(633, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy634; - if (yych != 'e') goto yy150; + if (yych == 'N') goto yy634; + if (yych != 'n') goto yy151; yy634: YYDEBUG(634, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy635; + if (yych != 'e') goto yy151; +yy635: + YYDEBUG(635, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(635, *YYCURSOR); + YYDEBUG(636, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1304 "Zend/zend_language_scanner.l" { return T_CLONE; } -#line 6054 "Zend/zend_language_scanner.c" -yy636: - YYDEBUG(636, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'S') goto yy637; - if (yych != 's') goto yy150; +#line 6056 "Zend/zend_language_scanner.c" yy637: YYDEBUG(637, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'S') goto yy638; + if (yych != 's') goto yy151; +yy638: + YYDEBUG(638, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(638, *YYCURSOR); + YYDEBUG(639, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1238 "Zend/zend_language_scanner.l" { return T_CLASS; } -#line 6072 "Zend/zend_language_scanner.c" -yy639: - YYDEBUG(639, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'C') goto yy650; - if (yych == 'c') goto yy650; - goto yy150; +#line 6074 "Zend/zend_language_scanner.c" yy640: YYDEBUG(640, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy648; - if (yych == 'e') goto yy648; - goto yy150; + if (yych == 'C') goto yy651; + if (yych == 'c') goto yy651; + goto yy151; yy641: YYDEBUG(641, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy642; - if (yych != 'l') goto yy150; + if (yych == 'E') goto yy649; + if (yych == 'e') goto yy649; + goto yy151; yy642: YYDEBUG(642, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy643; - if (yych != 'a') goto yy150; + if (yych == 'L') goto yy643; + if (yych != 'l') goto yy151; yy643: YYDEBUG(643, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'B') goto yy644; - if (yych != 'b') goto yy150; + if (yych == 'A') goto yy644; + if (yych != 'a') goto yy151; yy644: YYDEBUG(644, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy645; - if (yych != 'l') goto yy150; + if (yych == 'B') goto yy645; + if (yych != 'b') goto yy151; yy645: YYDEBUG(645, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy646; - if (yych != 'e') goto yy150; + if (yych == 'L') goto yy646; + if (yych != 'l') goto yy151; yy646: YYDEBUG(646, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy647; + if (yych != 'e') goto yy151; +yy647: + YYDEBUG(647, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(647, *YYCURSOR); + YYDEBUG(648, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1428 "Zend/zend_language_scanner.l" { return T_CALLABLE; } -#line 6122 "Zend/zend_language_scanner.c" -yy648: - YYDEBUG(648, *YYCURSOR); +#line 6124 "Zend/zend_language_scanner.c" +yy649: + YYDEBUG(649, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(649, *YYCURSOR); + YYDEBUG(650, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1210 "Zend/zend_language_scanner.l" { return T_CASE; } -#line 6135 "Zend/zend_language_scanner.c" -yy650: - YYDEBUG(650, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'H') goto yy651; - if (yych != 'h') goto yy150; +#line 6137 "Zend/zend_language_scanner.c" yy651: YYDEBUG(651, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'H') goto yy652; + if (yych != 'h') goto yy151; +yy652: + YYDEBUG(652, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(652, *YYCURSOR); + YYDEBUG(653, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1130 "Zend/zend_language_scanner.l" { return T_CATCH; } -#line 6153 "Zend/zend_language_scanner.c" -yy653: - YYDEBUG(653, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'N') goto yy670; - if (yych == 'n') goto yy670; - goto yy150; +#line 6155 "Zend/zend_language_scanner.c" yy654: YYDEBUG(654, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy663; - if (yych == 'r') goto yy663; - goto yy150; + if (yych == 'N') goto yy671; + if (yych == 'n') goto yy671; + goto yy151; yy655: YYDEBUG(655, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy656; - if (yych != 'n') goto yy150; + if (yych == 'R') goto yy664; + if (yych == 'r') goto yy664; + goto yy151; yy656: YYDEBUG(656, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy657; - if (yych != 'c') goto yy150; + if (yych == 'N') goto yy657; + if (yych != 'n') goto yy151; yy657: YYDEBUG(657, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy658; - if (yych != 't') goto yy150; + if (yych == 'C') goto yy658; + if (yych != 'c') goto yy151; yy658: YYDEBUG(658, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy659; - if (yych != 'i') goto yy150; + if (yych == 'T') goto yy659; + if (yych != 't') goto yy151; yy659: YYDEBUG(659, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy660; - if (yych != 'o') goto yy150; + if (yych == 'I') goto yy660; + if (yych != 'i') goto yy151; yy660: YYDEBUG(660, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy661; - if (yych != 'n') goto yy150; + if (yych == 'O') goto yy661; + if (yych != 'o') goto yy151; yy661: YYDEBUG(661, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'N') goto yy662; + if (yych != 'n') goto yy151; +yy662: + YYDEBUG(662, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(662, *YYCURSOR); + YYDEBUG(663, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1110 "Zend/zend_language_scanner.l" { return T_FUNCTION; } -#line 6208 "Zend/zend_language_scanner.c" -yy663: - YYDEBUG(663, *YYCURSOR); +#line 6210 "Zend/zend_language_scanner.c" +yy664: + YYDEBUG(664, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '^') { if (yych <= '@') { - if (yych <= '/') goto yy664; - if (yych <= '9') goto yy149; + if (yych <= '/') goto yy665; + if (yych <= '9') goto yy150; } else { - if (yych == 'E') goto yy665; - if (yych <= 'Z') goto yy149; + if (yych == 'E') goto yy666; + if (yych <= 'Z') goto yy150; } } else { if (yych <= 'd') { - if (yych != '`') goto yy149; + if (yych != '`') goto yy150; } else { - if (yych <= 'e') goto yy665; - if (yych <= 'z') goto yy149; - if (yych >= 0x7F) goto yy149; + if (yych <= 'e') goto yy666; + if (yych <= 'z') goto yy150; + if (yych >= 0x7F) goto yy150; } } -yy664: - YYDEBUG(664, *YYCURSOR); +yy665: + YYDEBUG(665, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1170 "Zend/zend_language_scanner.l" { return T_FOR; } -#line 6236 "Zend/zend_language_scanner.c" -yy665: - YYDEBUG(665, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy666; - if (yych != 'a') goto yy150; +#line 6238 "Zend/zend_language_scanner.c" yy666: YYDEBUG(666, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy667; - if (yych != 'c') goto yy150; + if (yych == 'A') goto yy667; + if (yych != 'a') goto yy151; yy667: YYDEBUG(667, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'H') goto yy668; - if (yych != 'h') goto yy150; + if (yych == 'C') goto yy668; + if (yych != 'c') goto yy151; yy668: YYDEBUG(668, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'H') goto yy669; + if (yych != 'h') goto yy151; +yy669: + YYDEBUG(669, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(669, *YYCURSOR); + YYDEBUG(670, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1178 "Zend/zend_language_scanner.l" { return T_FOREACH; } -#line 6264 "Zend/zend_language_scanner.c" -yy670: - YYDEBUG(670, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy671; - if (yych != 'a') goto yy150; +#line 6266 "Zend/zend_language_scanner.c" yy671: YYDEBUG(671, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy672; - if (yych != 'l') goto yy150; + if (yych == 'A') goto yy672; + if (yych != 'a') goto yy151; yy672: YYDEBUG(672, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'L') goto yy673; + if (yych != 'l') goto yy151; +yy673: + YYDEBUG(673, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '^') { if (yych <= '@') { - if (yych <= '/') goto yy673; - if (yych <= '9') goto yy149; + if (yych <= '/') goto yy674; + if (yych <= '9') goto yy150; } else { - if (yych == 'L') goto yy674; - if (yych <= 'Z') goto yy149; + if (yych == 'L') goto yy675; + if (yych <= 'Z') goto yy150; } } else { if (yych <= 'k') { - if (yych != '`') goto yy149; + if (yych != '`') goto yy150; } else { - if (yych <= 'l') goto yy674; - if (yych <= 'z') goto yy149; - if (yych >= 0x7F) goto yy149; + if (yych <= 'l') goto yy675; + if (yych <= 'z') goto yy150; + if (yych >= 0x7F) goto yy150; } } -yy673: - YYDEBUG(673, *YYCURSOR); +yy674: + YYDEBUG(674, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1396 "Zend/zend_language_scanner.l" { return T_FINAL; } -#line 6302 "Zend/zend_language_scanner.c" -yy674: - YYDEBUG(674, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'Y') goto yy675; - if (yych != 'y') goto yy150; +#line 6304 "Zend/zend_language_scanner.c" yy675: YYDEBUG(675, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'Y') goto yy676; + if (yych != 'y') goto yy151; +yy676: + YYDEBUG(676, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(676, *YYCURSOR); + YYDEBUG(677, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1134 "Zend/zend_language_scanner.l" { return T_FINALLY; } -#line 6320 "Zend/zend_language_scanner.c" -yy677: - YYDEBUG(677, *YYCURSOR); +#line 6322 "Zend/zend_language_scanner.c" +yy678: + YYDEBUG(678, *YYCURSOR); yych = *++YYCURSOR; if (yych <= 'F') { - if (yych == 'C') goto yy683; - if (yych <= 'E') goto yy150; - goto yy684; + if (yych == 'C') goto yy684; + if (yych <= 'E') goto yy151; + goto yy685; } else { if (yych <= 'c') { - if (yych <= 'b') goto yy150; - goto yy683; + if (yych <= 'b') goto yy151; + goto yy684; } else { - if (yych == 'f') goto yy684; - goto yy150; + if (yych == 'f') goto yy685; + goto yy151; } } -yy678: - YYDEBUG(678, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy681; - if (yych == 'e') goto yy681; - goto yy150; yy679: YYDEBUG(679, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy682; + if (yych == 'e') goto yy682; + goto yy151; +yy680: + YYDEBUG(680, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(680, *YYCURSOR); + YYDEBUG(681, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1166 "Zend/zend_language_scanner.l" { return T_DO; } -#line 6355 "Zend/zend_language_scanner.c" -yy681: - YYDEBUG(681, *YYCURSOR); +#line 6357 "Zend/zend_language_scanner.c" +yy682: + YYDEBUG(682, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(682, *YYCURSOR); + YYDEBUG(683, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1106 "Zend/zend_language_scanner.l" { return T_EXIT; } -#line 6368 "Zend/zend_language_scanner.c" -yy683: - YYDEBUG(683, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'L') goto yy690; - if (yych == 'l') goto yy690; - goto yy150; +#line 6370 "Zend/zend_language_scanner.c" yy684: YYDEBUG(684, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy685; - if (yych != 'a') goto yy150; + if (yych == 'L') goto yy691; + if (yych == 'l') goto yy691; + goto yy151; yy685: YYDEBUG(685, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'U') goto yy686; - if (yych != 'u') goto yy150; + if (yych == 'A') goto yy686; + if (yych != 'a') goto yy151; yy686: YYDEBUG(686, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy687; - if (yych != 'l') goto yy150; + if (yych == 'U') goto yy687; + if (yych != 'u') goto yy151; yy687: YYDEBUG(687, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy688; - if (yych != 't') goto yy150; + if (yych == 'L') goto yy688; + if (yych != 'l') goto yy151; yy688: YYDEBUG(688, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'T') goto yy689; + if (yych != 't') goto yy151; +yy689: + YYDEBUG(689, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(689, *YYCURSOR); + YYDEBUG(690, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1214 "Zend/zend_language_scanner.l" { return T_DEFAULT; } -#line 6407 "Zend/zend_language_scanner.c" -yy690: - YYDEBUG(690, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy691; - if (yych != 'a') goto yy150; +#line 6409 "Zend/zend_language_scanner.c" yy691: YYDEBUG(691, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy692; - if (yych != 'r') goto yy150; + if (yych == 'A') goto yy692; + if (yych != 'a') goto yy151; yy692: YYDEBUG(692, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy693; - if (yych != 'e') goto yy150; + if (yych == 'R') goto yy693; + if (yych != 'r') goto yy151; yy693: YYDEBUG(693, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy694; + if (yych != 'e') goto yy151; +yy694: + YYDEBUG(694, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(694, *YYCURSOR); + YYDEBUG(695, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1186 "Zend/zend_language_scanner.l" { return T_DECLARE; } -#line 6435 "Zend/zend_language_scanner.c" -yy695: - YYDEBUG(695, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'H') goto yy757; - if (yych == 'h') goto yy757; - goto yy150; +#line 6437 "Zend/zend_language_scanner.c" yy696: YYDEBUG(696, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'S') goto yy751; - if (yych == 's') goto yy751; - goto yy150; + if (yych == 'H') goto yy758; + if (yych == 'h') goto yy758; + goto yy151; yy697: YYDEBUG(697, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'P') goto yy747; - if (yych == 'p') goto yy747; - goto yy150; + if (yych == 'S') goto yy752; + if (yych == 's') goto yy752; + goto yy151; yy698: YYDEBUG(698, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy713; - if (yych == 'd') goto yy713; - goto yy150; + if (yych == 'P') goto yy748; + if (yych == 'p') goto yy748; + goto yy151; yy699: YYDEBUG(699, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy710; - if (yych == 'a') goto yy710; - goto yy150; + if (yych == 'D') goto yy714; + if (yych == 'd') goto yy714; + goto yy151; yy700: YYDEBUG(700, *YYCURSOR); yych = *++YYCURSOR; + if (yych == 'A') goto yy711; + if (yych == 'a') goto yy711; + goto yy151; +yy701: + YYDEBUG(701, *YYCURSOR); + yych = *++YYCURSOR; if (yych <= 'T') { - if (yych == 'I') goto yy701; - if (yych <= 'S') goto yy150; - goto yy702; + if (yych == 'I') goto yy702; + if (yych <= 'S') goto yy151; + goto yy703; } else { if (yych <= 'i') { - if (yych <= 'h') goto yy150; + if (yych <= 'h') goto yy151; } else { - if (yych == 't') goto yy702; - goto yy150; + if (yych == 't') goto yy703; + goto yy151; } } -yy701: - YYDEBUG(701, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy708; - if (yych == 't') goto yy708; - goto yy150; yy702: YYDEBUG(702, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy703; - if (yych != 'e') goto yy150; + if (yych == 'T') goto yy709; + if (yych == 't') goto yy709; + goto yy151; yy703: YYDEBUG(703, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'N') goto yy704; - if (yych != 'n') goto yy150; + if (yych == 'E') goto yy704; + if (yych != 'e') goto yy151; yy704: YYDEBUG(704, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'D') goto yy705; - if (yych != 'd') goto yy150; + if (yych == 'N') goto yy705; + if (yych != 'n') goto yy151; yy705: YYDEBUG(705, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'S') goto yy706; - if (yych != 's') goto yy150; + if (yych == 'D') goto yy706; + if (yych != 'd') goto yy151; yy706: YYDEBUG(706, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'S') goto yy707; + if (yych != 's') goto yy151; +yy707: + YYDEBUG(707, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(707, *YYCURSOR); + YYDEBUG(708, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1250 "Zend/zend_language_scanner.l" { return T_EXTENDS; } -#line 6519 "Zend/zend_language_scanner.c" -yy708: - YYDEBUG(708, *YYCURSOR); +#line 6521 "Zend/zend_language_scanner.c" +yy709: + YYDEBUG(709, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(709, *YYCURSOR); + YYDEBUG(710, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1102 "Zend/zend_language_scanner.l" { return T_EXIT; } -#line 6532 "Zend/zend_language_scanner.c" -yy710: - YYDEBUG(710, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'L') goto yy711; - if (yych != 'l') goto yy150; +#line 6534 "Zend/zend_language_scanner.c" yy711: YYDEBUG(711, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'L') goto yy712; + if (yych != 'l') goto yy151; +yy712: + YYDEBUG(712, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(712, *YYCURSOR); + YYDEBUG(713, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1340 "Zend/zend_language_scanner.l" { return T_EVAL; } -#line 6550 "Zend/zend_language_scanner.c" -yy713: - YYDEBUG(713, *YYCURSOR); +#line 6552 "Zend/zend_language_scanner.c" +yy714: + YYDEBUG(714, *YYCURSOR); yych = *++YYCURSOR; YYDEBUG(-1, yych); switch (yych) { case 'D': - case 'd': goto yy714; + case 'd': goto yy715; case 'F': - case 'f': goto yy715; + case 'f': goto yy716; case 'I': - case 'i': goto yy716; + case 'i': goto yy717; case 'S': - case 's': goto yy717; + case 's': goto yy718; case 'W': - case 'w': goto yy718; - default: goto yy150; + case 'w': goto yy719; + default: goto yy151; } -yy714: - YYDEBUG(714, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy740; - if (yych == 'e') goto yy740; - goto yy150; yy715: YYDEBUG(715, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'O') goto yy732; - if (yych == 'o') goto yy732; - goto yy150; + if (yych == 'E') goto yy741; + if (yych == 'e') goto yy741; + goto yy151; yy716: YYDEBUG(716, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'F') goto yy730; - if (yych == 'f') goto yy730; - goto yy150; + if (yych == 'O') goto yy733; + if (yych == 'o') goto yy733; + goto yy151; yy717: YYDEBUG(717, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'W') goto yy724; - if (yych == 'w') goto yy724; - goto yy150; + if (yych == 'F') goto yy731; + if (yych == 'f') goto yy731; + goto yy151; yy718: YYDEBUG(718, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'H') goto yy719; - if (yych != 'h') goto yy150; + if (yych == 'W') goto yy725; + if (yych == 'w') goto yy725; + goto yy151; yy719: YYDEBUG(719, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'I') goto yy720; - if (yych != 'i') goto yy150; + if (yych == 'H') goto yy720; + if (yych != 'h') goto yy151; yy720: YYDEBUG(720, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy721; - if (yych != 'l') goto yy150; + if (yych == 'I') goto yy721; + if (yych != 'i') goto yy151; yy721: YYDEBUG(721, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy722; - if (yych != 'e') goto yy150; + if (yych == 'L') goto yy722; + if (yych != 'l') goto yy151; yy722: YYDEBUG(722, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy723; + if (yych != 'e') goto yy151; +yy723: + YYDEBUG(723, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(723, *YYCURSOR); + YYDEBUG(724, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1162 "Zend/zend_language_scanner.l" { return T_ENDWHILE; } -#line 6624 "Zend/zend_language_scanner.c" -yy724: - YYDEBUG(724, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'I') goto yy725; - if (yych != 'i') goto yy150; +#line 6626 "Zend/zend_language_scanner.c" yy725: YYDEBUG(725, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'T') goto yy726; - if (yych != 't') goto yy150; + if (yych == 'I') goto yy726; + if (yych != 'i') goto yy151; yy726: YYDEBUG(726, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy727; - if (yych != 'c') goto yy150; + if (yych == 'T') goto yy727; + if (yych != 't') goto yy151; yy727: YYDEBUG(727, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'H') goto yy728; - if (yych != 'h') goto yy150; + if (yych == 'C') goto yy728; + if (yych != 'c') goto yy151; yy728: YYDEBUG(728, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'H') goto yy729; + if (yych != 'h') goto yy151; +yy729: + YYDEBUG(729, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(729, *YYCURSOR); + YYDEBUG(730, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1206 "Zend/zend_language_scanner.l" { return T_ENDSWITCH; } -#line 6657 "Zend/zend_language_scanner.c" -yy730: - YYDEBUG(730, *YYCURSOR); +#line 6659 "Zend/zend_language_scanner.c" +yy731: + YYDEBUG(731, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(731, *YYCURSOR); + YYDEBUG(732, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1150 "Zend/zend_language_scanner.l" { return T_ENDIF; } -#line 6670 "Zend/zend_language_scanner.c" -yy732: - YYDEBUG(732, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'R') goto yy733; - if (yych != 'r') goto yy150; +#line 6672 "Zend/zend_language_scanner.c" yy733: YYDEBUG(733, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'R') goto yy734; + if (yych != 'r') goto yy151; +yy734: + YYDEBUG(734, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '^') { if (yych <= '@') { - if (yych <= '/') goto yy734; - if (yych <= '9') goto yy149; + if (yych <= '/') goto yy735; + if (yych <= '9') goto yy150; } else { - if (yych == 'E') goto yy735; - if (yych <= 'Z') goto yy149; + if (yych == 'E') goto yy736; + if (yych <= 'Z') goto yy150; } } else { if (yych <= 'd') { - if (yych != '`') goto yy149; + if (yych != '`') goto yy150; } else { - if (yych <= 'e') goto yy735; - if (yych <= 'z') goto yy149; - if (yych >= 0x7F) goto yy149; + if (yych <= 'e') goto yy736; + if (yych <= 'z') goto yy150; + if (yych >= 0x7F) goto yy150; } } -yy734: - YYDEBUG(734, *YYCURSOR); +yy735: + YYDEBUG(735, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1174 "Zend/zend_language_scanner.l" { return T_ENDFOR; } -#line 6703 "Zend/zend_language_scanner.c" -yy735: - YYDEBUG(735, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'A') goto yy736; - if (yych != 'a') goto yy150; +#line 6705 "Zend/zend_language_scanner.c" yy736: YYDEBUG(736, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'C') goto yy737; - if (yych != 'c') goto yy150; + if (yych == 'A') goto yy737; + if (yych != 'a') goto yy151; yy737: YYDEBUG(737, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'H') goto yy738; - if (yych != 'h') goto yy150; + if (yych == 'C') goto yy738; + if (yych != 'c') goto yy151; yy738: YYDEBUG(738, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'H') goto yy739; + if (yych != 'h') goto yy151; +yy739: + YYDEBUG(739, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(739, *YYCURSOR); + YYDEBUG(740, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1182 "Zend/zend_language_scanner.l" { return T_ENDFOREACH; } -#line 6731 "Zend/zend_language_scanner.c" -yy740: - YYDEBUG(740, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'C') goto yy741; - if (yych != 'c') goto yy150; +#line 6733 "Zend/zend_language_scanner.c" yy741: YYDEBUG(741, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'L') goto yy742; - if (yych != 'l') goto yy150; + if (yych == 'C') goto yy742; + if (yych != 'c') goto yy151; yy742: YYDEBUG(742, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'A') goto yy743; - if (yych != 'a') goto yy150; + if (yych == 'L') goto yy743; + if (yych != 'l') goto yy151; yy743: YYDEBUG(743, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'R') goto yy744; - if (yych != 'r') goto yy150; + if (yych == 'A') goto yy744; + if (yych != 'a') goto yy151; yy744: YYDEBUG(744, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'E') goto yy745; - if (yych != 'e') goto yy150; + if (yych == 'R') goto yy745; + if (yych != 'r') goto yy151; yy745: YYDEBUG(745, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy746; + if (yych != 'e') goto yy151; +yy746: + YYDEBUG(746, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(746, *YYCURSOR); + YYDEBUG(747, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1190 "Zend/zend_language_scanner.l" { return T_ENDDECLARE; } -#line 6769 "Zend/zend_language_scanner.c" -yy747: - YYDEBUG(747, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'T') goto yy748; - if (yych != 't') goto yy150; +#line 6771 "Zend/zend_language_scanner.c" yy748: YYDEBUG(748, *YYCURSOR); yych = *++YYCURSOR; - if (yych == 'Y') goto yy749; - if (yych != 'y') goto yy150; + if (yych == 'T') goto yy749; + if (yych != 't') goto yy151; yy749: YYDEBUG(749, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'Y') goto yy750; + if (yych != 'y') goto yy151; +yy750: + YYDEBUG(750, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(750, *YYCURSOR); + YYDEBUG(751, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1380 "Zend/zend_language_scanner.l" { return T_EMPTY; } -#line 6792 "Zend/zend_language_scanner.c" -yy751: - YYDEBUG(751, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'E') goto yy752; - if (yych != 'e') goto yy150; +#line 6794 "Zend/zend_language_scanner.c" yy752: YYDEBUG(752, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'E') goto yy753; + if (yych != 'e') goto yy151; +yy753: + YYDEBUG(753, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '^') { if (yych <= '@') { - if (yych <= '/') goto yy753; - if (yych <= '9') goto yy149; + if (yych <= '/') goto yy754; + if (yych <= '9') goto yy150; } else { - if (yych == 'I') goto yy754; - if (yych <= 'Z') goto yy149; + if (yych == 'I') goto yy755; + if (yych <= 'Z') goto yy150; } } else { if (yych <= 'h') { - if (yych != '`') goto yy149; + if (yych != '`') goto yy150; } else { - if (yych <= 'i') goto yy754; - if (yych <= 'z') goto yy149; - if (yych >= 0x7F) goto yy149; + if (yych <= 'i') goto yy755; + if (yych <= 'z') goto yy150; + if (yych >= 0x7F) goto yy150; } } -yy753: - YYDEBUG(753, *YYCURSOR); +yy754: + YYDEBUG(754, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1154 "Zend/zend_language_scanner.l" { return T_ELSE; } -#line 6825 "Zend/zend_language_scanner.c" -yy754: - YYDEBUG(754, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'F') goto yy755; - if (yych != 'f') goto yy150; +#line 6827 "Zend/zend_language_scanner.c" yy755: YYDEBUG(755, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'F') goto yy756; + if (yych != 'f') goto yy151; +yy756: + YYDEBUG(756, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(756, *YYCURSOR); + YYDEBUG(757, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1146 "Zend/zend_language_scanner.l" { return T_ELSEIF; } -#line 6843 "Zend/zend_language_scanner.c" -yy757: - YYDEBUG(757, *YYCURSOR); - yych = *++YYCURSOR; - if (yych == 'O') goto yy758; - if (yych != 'o') goto yy150; +#line 6845 "Zend/zend_language_scanner.c" yy758: YYDEBUG(758, *YYCURSOR); + yych = *++YYCURSOR; + if (yych == 'O') goto yy759; + if (yych != 'o') goto yy151; +yy759: + YYDEBUG(759, *YYCURSOR); ++YYCURSOR; if (yybm[0+(yych = *YYCURSOR)] & 4) { - goto yy149; + goto yy150; } - YYDEBUG(759, *YYCURSOR); + YYDEBUG(760, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1230 "Zend/zend_language_scanner.l" { return T_ECHO; } -#line 6861 "Zend/zend_language_scanner.c" +#line 6863 "Zend/zend_language_scanner.c" } /* *********************************** */ yyc_ST_LOOKING_FOR_PROPERTY: @@ -6896,52 +6898,52 @@ int lex_scan(zval *zendlval) 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, }; - YYDEBUG(760, *YYCURSOR); + YYDEBUG(761, *YYCURSOR); YYFILL(2); yych = *YYCURSOR; if (yych <= '-') { if (yych <= '\r') { - if (yych <= 0x08) goto yy768; - if (yych <= '\n') goto yy762; - if (yych <= '\f') goto yy768; + if (yych <= 0x08) goto yy769; + if (yych <= '\n') goto yy763; + if (yych <= '\f') goto yy769; } else { - if (yych == ' ') goto yy762; - if (yych <= ',') goto yy768; - goto yy764; + if (yych == ' ') goto yy763; + if (yych <= ',') goto yy769; + goto yy765; } } else { if (yych <= '_') { - if (yych <= '@') goto yy768; - if (yych <= 'Z') goto yy766; - if (yych <= '^') goto yy768; - goto yy766; + if (yych <= '@') goto yy769; + if (yych <= 'Z') goto yy767; + if (yych <= '^') goto yy769; + goto yy767; } else { - if (yych <= '`') goto yy768; - if (yych <= 'z') goto yy766; - if (yych <= '~') goto yy768; - goto yy766; + if (yych <= '`') goto yy769; + if (yych <= 'z') goto yy767; + if (yych <= '~') goto yy769; + goto yy767; } } -yy762: - YYDEBUG(762, *YYCURSOR); - ++YYCURSOR; - yych = *YYCURSOR; - goto yy774; yy763: YYDEBUG(763, *YYCURSOR); + ++YYCURSOR; + yych = *YYCURSOR; + goto yy775; +yy764: + YYDEBUG(764, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1263 "Zend/zend_language_scanner.l" { HANDLE_NEWLINES(yytext, yyleng); return T_WHITESPACE; } -#line 6939 "Zend/zend_language_scanner.c" -yy764: - YYDEBUG(764, *YYCURSOR); - ++YYCURSOR; - if ((yych = *YYCURSOR) == '>') goto yy771; +#line 6941 "Zend/zend_language_scanner.c" yy765: YYDEBUG(765, *YYCURSOR); + ++YYCURSOR; + if ((yych = *YYCURSOR) == '>') goto yy772; +yy766: + YYDEBUG(766, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1278 "Zend/zend_language_scanner.l" { @@ -6949,14 +6951,14 @@ int lex_scan(zval *zendlval) yy_pop_state(); goto restart; } -#line 6953 "Zend/zend_language_scanner.c" -yy766: - YYDEBUG(766, *YYCURSOR); - ++YYCURSOR; - yych = *YYCURSOR; - goto yy770; +#line 6955 "Zend/zend_language_scanner.c" yy767: YYDEBUG(767, *YYCURSOR); + ++YYCURSOR; + yych = *YYCURSOR; + goto yy771; +yy768: + YYDEBUG(768, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1272 "Zend/zend_language_scanner.l" { @@ -6964,43 +6966,43 @@ int lex_scan(zval *zendlval) zend_copy_value(zendlval, yytext, yyleng); return T_STRING; } -#line 6968 "Zend/zend_language_scanner.c" -yy768: - YYDEBUG(768, *YYCURSOR); - yych = *++YYCURSOR; - goto yy765; +#line 6970 "Zend/zend_language_scanner.c" yy769: YYDEBUG(769, *YYCURSOR); + yych = *++YYCURSOR; + goto yy766; +yy770: + YYDEBUG(770, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy770: - YYDEBUG(770, *YYCURSOR); - if (yybm[0+yych] & 64) { - goto yy769; - } - goto yy767; yy771: YYDEBUG(771, *YYCURSOR); - ++YYCURSOR; + if (yybm[0+yych] & 64) { + goto yy770; + } + goto yy768; +yy772: YYDEBUG(772, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(773, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1268 "Zend/zend_language_scanner.l" { return T_OBJECT_OPERATOR; } -#line 6993 "Zend/zend_language_scanner.c" -yy773: - YYDEBUG(773, *YYCURSOR); +#line 6995 "Zend/zend_language_scanner.c" +yy774: + YYDEBUG(774, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy774: - YYDEBUG(774, *YYCURSOR); +yy775: + YYDEBUG(775, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy773; + goto yy774; } - goto yy763; + goto yy764; } /* *********************************** */ yyc_ST_LOOKING_FOR_VARNAME: @@ -7039,40 +7041,40 @@ int lex_scan(zval *zendlval) 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, }; - YYDEBUG(775, *YYCURSOR); + YYDEBUG(776, *YYCURSOR); YYFILL(2); yych = *YYCURSOR; if (yych <= '_') { - if (yych <= '@') goto yy779; - if (yych <= 'Z') goto yy777; - if (yych <= '^') goto yy779; + if (yych <= '@') goto yy780; + if (yych <= 'Z') goto yy778; + if (yych <= '^') goto yy780; } else { - if (yych <= '`') goto yy779; - if (yych <= 'z') goto yy777; - if (yych <= '~') goto yy779; + if (yych <= '`') goto yy780; + if (yych <= 'z') goto yy778; + if (yych <= '~') goto yy780; } -yy777: - YYDEBUG(777, *YYCURSOR); +yy778: + YYDEBUG(778, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= '_') { if (yych <= '@') { - if (yych <= '/') goto yy778; - if (yych <= '9') goto yy781; + if (yych <= '/') goto yy779; + if (yych <= '9') goto yy782; } else { - if (yych <= '[') goto yy781; - if (yych >= '_') goto yy781; + if (yych <= '[') goto yy782; + if (yych >= '_') goto yy782; } } else { if (yych <= '|') { - if (yych <= '`') goto yy778; - if (yych <= 'z') goto yy781; + if (yych <= '`') goto yy779; + if (yych <= 'z') goto yy782; } else { - if (yych != '~') goto yy781; + if (yych != '~') goto yy782; } } -yy778: - YYDEBUG(778, *YYCURSOR); +yy779: + YYDEBUG(779, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1579 "Zend/zend_language_scanner.l" { @@ -7081,30 +7083,32 @@ int lex_scan(zval *zendlval) yy_push_state(ST_IN_SCRIPTING); goto restart; } -#line 7085 "Zend/zend_language_scanner.c" -yy779: - YYDEBUG(779, *YYCURSOR); - yych = *++YYCURSOR; - goto yy778; +#line 7087 "Zend/zend_language_scanner.c" yy780: YYDEBUG(780, *YYCURSOR); + yych = *++YYCURSOR; + goto yy779; +yy781: + YYDEBUG(781, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy781: - YYDEBUG(781, *YYCURSOR); +yy782: + YYDEBUG(782, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy780; + goto yy781; } - if (yych == '[') goto yy783; - if (yych == '}') goto yy783; - YYDEBUG(782, *YYCURSOR); - YYCURSOR = YYMARKER; - goto yy778; + if (yych <= '@') goto yy783; + if (yych <= '[') goto yy784; + if (yych == '}') goto yy784; yy783: YYDEBUG(783, *YYCURSOR); - ++YYCURSOR; + YYCURSOR = YYMARKER; + goto yy779; +yy784: YYDEBUG(784, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(785, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1570 "Zend/zend_language_scanner.l" { @@ -7114,16 +7118,16 @@ int lex_scan(zval *zendlval) yy_push_state(ST_IN_SCRIPTING); return T_STRING_VARNAME; } -#line 7118 "Zend/zend_language_scanner.c" +#line 7122 "Zend/zend_language_scanner.c" } /* *********************************** */ yyc_ST_NOWDOC: - YYDEBUG(785, *YYCURSOR); + YYDEBUG(786, *YYCURSOR); YYFILL(1); yych = *YYCURSOR; - YYDEBUG(787, *YYCURSOR); - ++YYCURSOR; YYDEBUG(788, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(789, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2292 "Zend/zend_language_scanner.l" { @@ -7181,7 +7185,7 @@ int lex_scan(zval *zendlval) HANDLE_NEWLINES(yytext, yyleng - newline); return T_ENCAPSED_AND_WHITESPACE; } -#line 7185 "Zend/zend_language_scanner.c" +#line 7189 "Zend/zend_language_scanner.c" /* *********************************** */ yyc_ST_VAR_OFFSET: { @@ -7219,74 +7223,74 @@ int lex_scan(zval *zendlval) 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, }; - YYDEBUG(789, *YYCURSOR); + YYDEBUG(790, *YYCURSOR); YYFILL(3); yych = *YYCURSOR; if (yych <= '/') { if (yych <= ' ') { if (yych <= '\f') { - if (yych <= 0x08) goto yy803; - if (yych <= '\n') goto yy799; - goto yy803; + if (yych <= 0x08) goto yy804; + if (yych <= '\n') goto yy800; + goto yy804; } else { - if (yych <= '\r') goto yy799; - if (yych <= 0x1F) goto yy803; - goto yy799; + if (yych <= '\r') goto yy800; + if (yych <= 0x1F) goto yy804; + goto yy800; } } else { if (yych <= '$') { - if (yych <= '"') goto yy798; - if (yych <= '#') goto yy799; - goto yy794; + if (yych <= '"') goto yy799; + if (yych <= '#') goto yy800; + goto yy795; } else { - if (yych == '\'') goto yy799; - goto yy798; + if (yych == '\'') goto yy800; + goto yy799; } } } else { if (yych <= '\\') { if (yych <= '@') { - if (yych <= '0') goto yy791; - if (yych <= '9') goto yy793; - goto yy798; - } else { - if (yych <= 'Z') goto yy801; - if (yych <= '[') goto yy798; + if (yych <= '0') goto yy792; + if (yych <= '9') goto yy794; goto yy799; + } else { + if (yych <= 'Z') goto yy802; + if (yych <= '[') goto yy799; + goto yy800; } } else { if (yych <= '_') { - if (yych <= ']') goto yy796; - if (yych <= '^') goto yy798; - goto yy801; + if (yych <= ']') goto yy797; + if (yych <= '^') goto yy799; + goto yy802; } else { - if (yych <= '`') goto yy798; - if (yych <= 'z') goto yy801; - if (yych <= '~') goto yy798; - goto yy801; + if (yych <= '`') goto yy799; + if (yych <= 'z') goto yy802; + if (yych <= '~') goto yy799; + goto yy802; } } } -yy791: - YYDEBUG(791, *YYCURSOR); +yy792: + YYDEBUG(792, *YYCURSOR); yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= 'W') { if (yych <= '9') { - if (yych >= '0') goto yy815; + if (yych >= '0') goto yy816; } else { - if (yych == 'B') goto yy812; + if (yych == 'B') goto yy813; } } else { if (yych <= 'b') { - if (yych <= 'X') goto yy814; - if (yych >= 'b') goto yy812; + if (yych <= 'X') goto yy815; + if (yych >= 'b') goto yy813; } else { - if (yych == 'x') goto yy814; + if (yych == 'x') goto yy815; } } -yy792: - YYDEBUG(792, *YYCURSOR); +yy793: + YYDEBUG(793, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1681 "Zend/zend_language_scanner.l" { /* Offset could be treated as a long */ @@ -7304,51 +7308,51 @@ int lex_scan(zval *zendlval) } return T_NUM_STRING; } -#line 7308 "Zend/zend_language_scanner.c" -yy793: - YYDEBUG(793, *YYCURSOR); - yych = *++YYCURSOR; - goto yy811; +#line 7312 "Zend/zend_language_scanner.c" yy794: YYDEBUG(794, *YYCURSOR); + yych = *++YYCURSOR; + goto yy812; +yy795: + YYDEBUG(795, *YYCURSOR); ++YYCURSOR; if ((yych = *YYCURSOR) <= '_') { - if (yych <= '@') goto yy795; - if (yych <= 'Z') goto yy807; - if (yych >= '_') goto yy807; + if (yych <= '@') goto yy796; + if (yych <= 'Z') goto yy808; + if (yych >= '_') goto yy808; } else { - if (yych <= '`') goto yy795; - if (yych <= 'z') goto yy807; - if (yych >= 0x7F) goto yy807; + if (yych <= '`') goto yy796; + if (yych <= 'z') goto yy808; + if (yych >= 0x7F) goto yy808; } -yy795: - YYDEBUG(795, *YYCURSOR); +yy796: + YYDEBUG(796, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1841 "Zend/zend_language_scanner.l" { /* Only '[' can be valid, but returning other tokens will allow a more explicit parse error */ return yytext[0]; } -#line 7333 "Zend/zend_language_scanner.c" -yy796: - YYDEBUG(796, *YYCURSOR); - ++YYCURSOR; +#line 7337 "Zend/zend_language_scanner.c" +yy797: YYDEBUG(797, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(798, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1836 "Zend/zend_language_scanner.l" { yy_pop_state(); return ']'; } -#line 7344 "Zend/zend_language_scanner.c" -yy798: - YYDEBUG(798, *YYCURSOR); - yych = *++YYCURSOR; - goto yy795; +#line 7348 "Zend/zend_language_scanner.c" yy799: YYDEBUG(799, *YYCURSOR); - ++YYCURSOR; + yych = *++YYCURSOR; + goto yy796; +yy800: YYDEBUG(800, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(801, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1846 "Zend/zend_language_scanner.l" { @@ -7358,25 +7362,25 @@ int lex_scan(zval *zendlval) ZVAL_NULL(zendlval); return T_ENCAPSED_AND_WHITESPACE; } -#line 7362 "Zend/zend_language_scanner.c" -yy801: - YYDEBUG(801, *YYCURSOR); - ++YYCURSOR; - yych = *YYCURSOR; - goto yy806; +#line 7366 "Zend/zend_language_scanner.c" yy802: YYDEBUG(802, *YYCURSOR); + ++YYCURSOR; + yych = *YYCURSOR; + goto yy807; +yy803: + YYDEBUG(803, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1854 "Zend/zend_language_scanner.l" { zend_copy_value(zendlval, yytext, yyleng); return T_STRING; } -#line 7376 "Zend/zend_language_scanner.c" -yy803: - YYDEBUG(803, *YYCURSOR); - ++YYCURSOR; +#line 7380 "Zend/zend_language_scanner.c" +yy804: YYDEBUG(804, *YYCURSOR); + ++YYCURSOR; + YYDEBUG(805, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 2349 "Zend/zend_language_scanner.l" { @@ -7387,113 +7391,113 @@ int lex_scan(zval *zendlval) zend_error(E_COMPILE_WARNING,"Unexpected character in input: '%c' (ASCII=%d) state=%d", yytext[0], yytext[0], YYSTATE); goto restart; } -#line 7391 "Zend/zend_language_scanner.c" -yy805: - YYDEBUG(805, *YYCURSOR); +#line 7395 "Zend/zend_language_scanner.c" +yy806: + YYDEBUG(806, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy806: - YYDEBUG(806, *YYCURSOR); - if (yybm[0+yych] & 16) { - goto yy805; - } - goto yy802; yy807: YYDEBUG(807, *YYCURSOR); + if (yybm[0+yych] & 16) { + goto yy806; + } + goto yy803; +yy808: + YYDEBUG(808, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(808, *YYCURSOR); + YYDEBUG(809, *YYCURSOR); if (yych <= '^') { if (yych <= '9') { - if (yych >= '0') goto yy807; + if (yych >= '0') goto yy808; } else { - if (yych <= '@') goto yy809; - if (yych <= 'Z') goto yy807; + if (yych <= '@') goto yy810; + if (yych <= 'Z') goto yy808; } } else { if (yych <= '`') { - if (yych <= '_') goto yy807; + if (yych <= '_') goto yy808; } else { - if (yych <= 'z') goto yy807; - if (yych >= 0x7F) goto yy807; + if (yych <= 'z') goto yy808; + if (yych >= 0x7F) goto yy808; } } -yy809: - YYDEBUG(809, *YYCURSOR); +yy810: + YYDEBUG(810, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1831 "Zend/zend_language_scanner.l" { zend_copy_value(zendlval, (yytext+1), (yyleng-1)); return T_VARIABLE; } -#line 7432 "Zend/zend_language_scanner.c" -yy810: - YYDEBUG(810, *YYCURSOR); +#line 7436 "Zend/zend_language_scanner.c" +yy811: + YYDEBUG(811, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; -yy811: - YYDEBUG(811, *YYCURSOR); - if (yybm[0+yych] & 32) { - goto yy810; - } - goto yy792; yy812: YYDEBUG(812, *YYCURSOR); - yych = *++YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy820; + if (yybm[0+yych] & 32) { + goto yy811; } + goto yy793; yy813: YYDEBUG(813, *YYCURSOR); - YYCURSOR = YYMARKER; - goto yy792; + yych = *++YYCURSOR; + if (yybm[0+yych] & 128) { + goto yy821; + } yy814: YYDEBUG(814, *YYCURSOR); + YYCURSOR = YYMARKER; + goto yy793; +yy815: + YYDEBUG(815, *YYCURSOR); yych = *++YYCURSOR; if (yybm[0+yych] & 64) { - goto yy818; + goto yy819; } - goto yy813; -yy815: - YYDEBUG(815, *YYCURSOR); + goto yy814; +yy816: + YYDEBUG(816, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(816, *YYCURSOR); - if (yych <= '/') goto yy817; - if (yych <= '9') goto yy815; -yy817: YYDEBUG(817, *YYCURSOR); + if (yych <= '/') goto yy818; + if (yych <= '9') goto yy816; +yy818: + YYDEBUG(818, *YYCURSOR); yyleng = YYCURSOR - SCNG(yy_text); #line 1697 "Zend/zend_language_scanner.l" { /* Offset must be treated as a string */ ZVAL_STRINGL(zendlval, yytext, yyleng); return T_NUM_STRING; } -#line 7477 "Zend/zend_language_scanner.c" -yy818: - YYDEBUG(818, *YYCURSOR); +#line 7481 "Zend/zend_language_scanner.c" +yy819: + YYDEBUG(819, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(819, *YYCURSOR); + YYDEBUG(820, *YYCURSOR); if (yybm[0+yych] & 64) { - goto yy818; + goto yy819; } - goto yy817; -yy820: - YYDEBUG(820, *YYCURSOR); + goto yy818; +yy821: + YYDEBUG(821, *YYCURSOR); ++YYCURSOR; YYFILL(1); yych = *YYCURSOR; - YYDEBUG(821, *YYCURSOR); + YYDEBUG(822, *YYCURSOR); if (yybm[0+yych] & 128) { - goto yy820; + goto yy821; } - goto yy817; + goto yy818; } } #line 2358 "Zend/zend_language_scanner.l" diff --git a/Zend/zend_language_scanner_defs.h b/Zend/zend_language_scanner_defs.h index 5926e3c61d971..baf859bcd461a 100644 --- a/Zend/zend_language_scanner_defs.h +++ b/Zend/zend_language_scanner_defs.h @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 */ +/* Generated by re2c 0.13.7.5 */ #line 3 "Zend/zend_language_scanner_defs.h" enum YYCONDTYPE { From 5544e37231fe754fa35d5f8a301647d3df35f942 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Tue, 6 Jan 2015 03:06:39 +0000 Subject: [PATCH 07/29] Inline --- Zend/zend_compile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index bf1b20bab8213..09966ed32796a 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -47,7 +47,7 @@ static const struct _scalar_typehint_info scalar_typehints[] = { {NULL, 0, IS_UNDEF} }; -static void zend_assert_valid_class_name(const zend_string *const_name) +static zend_always_inline void zend_assert_valid_class_name(const zend_string *const_name) { const struct _scalar_typehint_info *info = &scalar_typehints[0]; const char *end_slash = strrchr(const_name->val, '\\'); From cc01e37e54874541aad343dd6c5902e9a111b9fc Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sat, 10 Jan 2015 03:29:41 +0000 Subject: [PATCH 08/29] It Begins --- Zend/zend_compile.c | 13 ++++++++++++- Zend/zend_compile.h | 1 + Zend/zend_execute.c | 12 ++++++------ Zend/zend_globals.h | 1 + Zend/zend_types.h | 5 +++++ Zend/zend_vm_def.h | 12 +++++++----- Zend/zend_vm_execute.h | 10 ++++++---- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 0f391f527a3cc..81eb1d44343b9 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -142,6 +142,7 @@ static zend_bool zend_get_unqualified_name(const zend_string *name, const char * static void init_compiler_declarables(void) /* {{{ */ { ZVAL_LONG(&CG(declarables).ticks, 0); + CG(declarables).strict_typehints = 0; } /* }}} */ @@ -2548,7 +2549,8 @@ void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function * opline->op1.num = zend_vm_calc_used_stack(arg_count, fbc); } - call_flags = (opline->opcode == ZEND_NEW ? ZEND_CALL_CTOR : 0); + call_flags = ((opline->opcode == ZEND_NEW) ? ZEND_CALL_CTOR : 0) + | (CG(declarables).strict_typehints ? ZEND_CALL_STRICT_TYPEHINTS : 0); opline = zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL); opline->op1.num = call_flags; @@ -3787,6 +3789,15 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */ zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be " "the very first statement in the script"); } + } else if (zend_string_equals_literal_ci(name, "strict_typehints")) { + zval value_zv; + zend_const_expr_to_zval(&value_zv, value_ast); + + if (Z_TYPE(value_zv) != IS_FALSE && Z_TYPE(value_zv) != IS_TRUE) { + zend_error_noreturn(E_COMPILE_ERROR, "strict_typehints declaration must have a boolean value"); + } + + CG(declarables).strict_typehints = (Z_TYPE(value_zv) == IS_TRUE) ? 1 : 0; } else { zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", name->val); } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 09966ed32796a..3d44a08df7840 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -469,6 +469,7 @@ struct _zend_execute_data { #define ZEND_CALL_FREE_EXTRA_ARGS (1 << 2) /* equal to IS_TYPE_REFCOUNTED */ #define ZEND_CALL_CTOR (1 << 3) #define ZEND_CALL_CTOR_RESULT_UNUSED (1 << 4) +#define ZEND_CALL_STRICT_TYPEHINTS (1 << 5) #define ZEND_CALL_INFO(call) \ (Z_TYPE_INFO((call)->This) >> 24) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 26b6a3526a2fc..604303ae10deb 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -658,7 +658,7 @@ static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg) } } -static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, zval *arg) +static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zend_bool strict) { zend_internal_arg_info *cur_arg_info; char *need_msg; @@ -695,7 +695,7 @@ static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, z if (!zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "", arg); } - } else if (UNEXPECTED(cur_arg_info->type_hint != Z_TYPE_P(arg))) { + } else if (UNEXPECTED(!ZEND_SAME_FAKE_TYPE(cur_arg_info->type_hint, Z_TYPE_P(arg)))) { if (Z_TYPE_P(arg) == IS_NULL) { if (!cur_arg_info->allow_null) { failure: @@ -703,14 +703,14 @@ static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, z } return; } - if (!zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { + if (strict || !zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { goto failure; } } } } -static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zval *default_value) +static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zval *default_value, zend_bool strict) { zend_arg_info *cur_arg_info; char *need_msg; @@ -747,7 +747,7 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, if (!zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(arg) != IS_NULL || !(cur_arg_info->allow_null || (default_value && is_null_constant(default_value))))) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "", arg); } - } else if (UNEXPECTED(cur_arg_info->type_hint != Z_TYPE_P(arg))) { + } else if (UNEXPECTED(!ZEND_SAME_FAKE_TYPE(cur_arg_info->type_hint, Z_TYPE_P(arg)))) { if (Z_TYPE_P(arg) == IS_NULL) { if (!cur_arg_info->allow_null) { failure: @@ -755,7 +755,7 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, } return; } - if (!zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { + if (strict || !zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { goto failure; } } diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index beca5ad631b33..7295eaefd3a6c 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -64,6 +64,7 @@ END_EXTERN_C() typedef struct _zend_declarables { zval ticks; + zend_bool strict_typehints; } zend_declarables; typedef struct _zend_vm_stack *zend_vm_stack; diff --git a/Zend/zend_types.h b/Zend/zend_types.h index 80e17003739f2..f3bc9774ecb91 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -238,6 +238,11 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) { return pz->u1.v.type; } +#define ZEND_SAME_FAKE_TYPE(faketype, realtype) ( \ + (faketype) == (realtype) \ + || ((faketype) == _IS_BOOL && ((realtype) == IS_TRUE || (realtype) == IS_FALSE)) \ +) + /* we should never set just Z_TYPE, we should set Z_TYPE_INFO */ #define Z_TYPE(zval) zval_get_type(&(zval)) #define Z_TYPE_P(zval_p) Z_TYPE(*(zval_p)) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 8a1bda8cd76fa..0557ddd16c6f5 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2768,6 +2768,8 @@ ZEND_VM_HANDLER(60, ZEND_DO_FCALL, ANY, ANY) zend_object *object = Z_OBJ(call->This); zval *ret; + ZEND_ADD_CALL_FLAG(call, opline->op1.num & ZEND_CALL_STRICT_TYPEHINTS); + SAVE_OPLINE(); EX(call) = call->prev_execute_data; if (UNEXPECTED((fbc->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) != 0)) { @@ -2843,7 +2845,7 @@ ZEND_VM_HANDLER(60, ZEND_DO_FCALL, ANY, ANY) zval *p = ZEND_CALL_ARG(call, 1); for (i = 0; i < num_args; ++i) { - zend_verify_internal_arg_type(fbc, i + 1, p); + zend_verify_internal_arg_type(fbc, i + 1, p, (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); p++; } if (UNEXPECTED(EG(exception) != NULL)) { @@ -3692,7 +3694,7 @@ ZEND_VM_HANDLER(63, ZEND_RECV, ANY, ANY) } else if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) { zval *param = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->result.var); - zend_verify_arg_type(EX(func), arg_num, param, NULL); + zend_verify_arg_type(EX(func), arg_num, param, NULL, (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); CHECK_EXCEPTION(); } @@ -3720,7 +3722,7 @@ ZEND_VM_HANDLER(64, ZEND_RECV_INIT, ANY, CONST) } if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) { - zend_verify_arg_type(EX(func), arg_num, param, EX_CONSTANT(opline->op2)); + zend_verify_arg_type(EX(func), arg_num, param, EX_CONSTANT(opline->op2), (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); } CHECK_EXCEPTION(); @@ -3746,8 +3748,8 @@ ZEND_VM_HANDLER(164, ZEND_RECV_VARIADIC, ANY, ANY) ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(params)) { param = EX_VAR_NUM(EX(func)->op_array.last_var + EX(func)->op_array.T); if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) { - do { - zend_verify_arg_type(EX(func), arg_num, param, NULL); + do { + zend_verify_arg_type(EX(func), arg_num, param, NULL, (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); if (Z_OPT_REFCOUNTED_P(param)) Z_ADDREF_P(param); ZEND_HASH_FILL_ADD(param); param++; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 19e1a741b5df6..ab736264ade5b 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -494,6 +494,8 @@ static int ZEND_FASTCALL ZEND_DO_FCALL_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) zend_object *object = Z_OBJ(call->This); zval *ret; + ZEND_ADD_CALL_FLAG(call, opline->op1.num & ZEND_CALL_STRICT_TYPEHINTS); + SAVE_OPLINE(); EX(call) = call->prev_execute_data; if (UNEXPECTED((fbc->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) != 0)) { @@ -569,7 +571,7 @@ static int ZEND_FASTCALL ZEND_DO_FCALL_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) zval *p = ZEND_CALL_ARG(call, 1); for (i = 0; i < num_args; ++i) { - zend_verify_internal_arg_type(fbc, i + 1, p); + zend_verify_internal_arg_type(fbc, i + 1, p, (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); p++; } if (UNEXPECTED(EG(exception) != NULL)) { @@ -987,7 +989,7 @@ static int ZEND_FASTCALL ZEND_RECV_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) } else if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) { zval *param = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->result.var); - zend_verify_arg_type(EX(func), arg_num, param, NULL); + zend_verify_arg_type(EX(func), arg_num, param, NULL, (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); CHECK_EXCEPTION(); } @@ -1014,7 +1016,7 @@ static int ZEND_FASTCALL ZEND_RECV_VARIADIC_SPEC_HANDLER(ZEND_OPCODE_HANDLER_AR param = EX_VAR_NUM(EX(func)->op_array.last_var + EX(func)->op_array.T); if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) { do { - zend_verify_arg_type(EX(func), arg_num, param, NULL); + zend_verify_arg_type(EX(func), arg_num, param, NULL, (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); if (Z_OPT_REFCOUNTED_P(param)) Z_ADDREF_P(param); ZEND_HASH_FILL_ADD(param); param++; @@ -1764,7 +1766,7 @@ static int ZEND_FASTCALL ZEND_RECV_INIT_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ } if (UNEXPECTED((EX(func)->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0)) { - zend_verify_arg_type(EX(func), arg_num, param, EX_CONSTANT(opline->op2)); + zend_verify_arg_type(EX(func), arg_num, param, EX_CONSTANT(opline->op2), (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0); } CHECK_EXCEPTION(); From 02ec3572d91b35032dfe57e93f385dcbe2e12751 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Mon, 12 Jan 2015 23:27:32 +0000 Subject: [PATCH 09/29] Per-file --- Zend/zend_compile.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 81eb1d44343b9..1b7503605c70a 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1531,6 +1531,8 @@ void zend_do_end_compilation(void) /* {{{ */ { CG(has_bracketed_namespaces) = 0; zend_end_namespace(); + /* strict typehinting is per-file */ + CG(declarables).strict_typehints = 0; } /* }}} */ From fe663cc4043cb3f0ea2a528d1c65ef6e21f758c3 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Tue, 13 Jan 2015 00:57:56 +0000 Subject: [PATCH 10/29] Partial ZPP strictness implementation --- Zend/zend_API.c | 105 ++++++++++++++++++++++++++------------------ Zend/zend_API.h | 95 +++++++++++++++++++++++---------------- Zend/zend_execute.c | 16 +++---- 3 files changed, 128 insertions(+), 88 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 72b3ec5c60152..e055a63b8dcac 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -149,12 +149,12 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array) / } /* }}} */ -ZEND_API void zend_wrong_param_count(void) /* {{{ */ +ZEND_API void zend_wrong_param_count(zend_bool strict) /* {{{ */ { const char *space; const char *class_name = get_active_class_name(&space); - zend_error(E_WARNING, "Wrong parameter count for %s%s%s()", class_name, space, get_active_function_name()); + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "Wrong parameter count for %s%s%s()", class_name, space, get_active_function_name()); } /* }}} */ @@ -234,12 +234,12 @@ ZEND_API int parse_arg_object_to_str(zval *arg, zend_string **str, int type) /* /* }}} */ #ifdef FAST_ZPP -ZEND_API void zend_wrong_paramers_count_error(int num_args, int min_num_args, int max_num_args) /* {{{ */ +ZEND_API void zend_wrong_paramers_count_error(int num_args, int min_num_args, int max_num_args, zend_bool strict) /* {{{ */ { zend_function *active_function = EG(current_execute_data)->func; const char *class_name = active_function->common.scope ? active_function->common.scope->name->val : ""; - zend_error(E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given", class_name, \ class_name[0] ? "::" : "", \ active_function->common.function_name->val, @@ -250,7 +250,7 @@ ZEND_API void zend_wrong_paramers_count_error(int num_args, int min_num_args, in } /* }}} */ -ZEND_API void zend_wrong_paramer_type_error(int num, zend_expected_type expected_type, zval *arg) /* {{{ */ +ZEND_API void zend_wrong_paramer_type_error(int num, zend_expected_type expected_type, zval *arg, zend_bool strict) /* {{{ */ { const char *space; const char *class_name = get_active_class_name(&space); @@ -259,17 +259,17 @@ ZEND_API void zend_wrong_paramer_type_error(int num, zend_expected_type expected NULL }; - zend_error(E_WARNING, "%s%s%s() expects parameter %d to be %s, %s given", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s() expects parameter %d to be %s, %s given", class_name, space, get_active_function_name(), num, expected_error[expected_type], zend_zval_type_name(arg)); } /* }}} */ -ZEND_API void zend_wrong_paramer_class_error(int num, char *name, zval *arg) /* {{{ */ +ZEND_API void zend_wrong_paramer_class_error(int num, char *name, zval *arg, zend_bool strict) /* {{{ */ { const char *space; const char *class_name = get_active_class_name(&space); - zend_error(E_WARNING, "%s%s%s() expects parameter %d to be %s, %s given", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s() expects parameter %d to be %s, %s given", class_name, space, get_active_function_name(), num, name, zend_zval_type_name(arg)); } /* }}} */ @@ -285,7 +285,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error) /* { } /* }}} */ -ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null) /* {{{ */ +ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null, zend_bool strict) /* {{{ */ { zend_class_entry *ce_base = *pce; @@ -300,7 +300,7 @@ ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, in const char *space; const char *class_name = get_active_class_name(&space); - zend_error(E_WARNING, "%s%s%s() expects parameter %d to be a class name derived from %s, '%s' given", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s() expects parameter %d to be a class name derived from %s, '%s' given", class_name, space, get_active_function_name(), num, ce_base->name->val, Z_STRVAL_P(arg)); *pce = NULL; @@ -311,7 +311,7 @@ ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, in const char *space; const char *class_name = get_active_class_name(&space); - zend_error(E_WARNING, "%s%s%s() expects parameter %d to be a valid class name, '%s' given", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s() expects parameter %d to be a valid class name, '%s' given", class_name, space, get_active_function_name(), num, Z_STRVAL_P(arg)); return 0; @@ -321,7 +321,7 @@ ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, in /* }}} */ #endif -static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, const char **spec, char **error, int *severity) /* {{{ */ +static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, const char **spec, char **error, int *severity, zend_bool strict) /* {{{ */ { const char *spec_walk = *spec; char c = *spec_walk++; @@ -353,7 +353,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons is_null = va_arg(*va, zend_bool *); } - if (!zend_parse_arg_long(arg, p, is_null, check_null, c == 'L')) { + if (!zend_parse_arg_long(arg, p, is_null, check_null, c == 'L', strict)) { return "integer"; } } @@ -368,7 +368,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons is_null = va_arg(*va, zend_bool *); } - if (!zend_parse_arg_double(arg, p, is_null, check_null)) { + if (!zend_parse_arg_double(arg, p, is_null, check_null, strict)) { return "float"; } } @@ -378,7 +378,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons { char **p = va_arg(*va, char **); size_t *pl = va_arg(*va, size_t *); - if (!zend_parse_arg_string(arg, p, pl, check_null)) { + if (!zend_parse_arg_string(arg, p, pl, check_null, strict)) { return "string"; } } @@ -388,7 +388,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons { char **p = va_arg(*va, char **); size_t *pl = va_arg(*va, size_t *); - if (!zend_parse_arg_path(arg, p, pl, check_null)) { + if (!zend_parse_arg_path(arg, p, pl, check_null, strict)) { return "a valid path"; } } @@ -397,7 +397,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons case 'P': { zend_string **str = va_arg(*va, zend_string **); - if (!zend_parse_arg_path_str(arg, str, check_null)) { + if (!zend_parse_arg_path_str(arg, str, check_null, strict)) { return "a valid path"; } } @@ -406,7 +406,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons case 'S': { zend_string **str = va_arg(*va, zend_string **); - if (!zend_parse_arg_str(arg, str, check_null)) { + if (!zend_parse_arg_str(arg, str, check_null, strict)) { return "string"; } } @@ -421,7 +421,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons is_null = va_arg(*va, zend_bool *); } - if (!zend_parse_arg_bool(arg, p, is_null, check_null)) { + if (!zend_parse_arg_bool(arg, p, is_null, check_null, strict)) { return "boolean"; } } @@ -540,7 +540,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons break; } else { if (is_callable_error) { - *severity = E_WARNING; + *severity = strict ? E_RECOVERABLE_ERROR : E_WARNING; zend_spprintf(error, 0, "to be a valid callback, %s", is_callable_error); efree(is_callable_error); return ""; @@ -571,13 +571,13 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons } /* }}} */ -static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec, int quiet) /* {{{ */ +static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec, int quiet, zend_bool strict) /* {{{ */ { const char *expected_type = NULL; char *error = NULL; - int severity = E_WARNING; + int severity = strict ? E_RECOVERABLE_ERROR : E_WARNING; - expected_type = zend_parse_arg_impl(arg_num, arg, va, spec, &error, &severity); + expected_type = zend_parse_arg_impl(arg_num, arg, va, spec, &error, &severity, strict); if (expected_type) { if (!quiet && (*expected_type || error)) { const char *space; @@ -607,9 +607,10 @@ ZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char va_list va; int ret; int quiet = flags & ZEND_PARSE_PARAMS_QUIET; + zend_bool strict = (flags & ZEND_PARSE_PARAMS_STRICT) ? 1 : 0; va_start(va, spec); - ret = zend_parse_arg(arg_num, arg, &va, &spec, quiet); + ret = zend_parse_arg(arg_num, arg, &va, &spec, quiet, strict); va_end(va); return ret; @@ -625,6 +626,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, zval *arg; int arg_count; int quiet = flags & ZEND_PARSE_PARAMS_QUIET; + zend_bool strict = (flags & ZEND_PARSE_PARAMS_STRICT) ? 1 : 0; zend_bool have_varargs = 0; zval **varargs = NULL; int *n_varargs = NULL; @@ -660,7 +662,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, if (!quiet) { zend_function *active_function = EG(current_execute_data)->func; const char *class_name = active_function->common.scope ? active_function->common.scope->name->val : ""; - zend_error(E_WARNING, "%s%s%s(): only one varargs specifier (* or +) is permitted", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s(): only one varargs specifier (* or +) is permitted", class_name, class_name[0] ? "::" : "", active_function->common.function_name->val); @@ -680,7 +682,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, if (!quiet) { zend_function *active_function = EG(current_execute_data)->func; const char *class_name = active_function->common.scope ? active_function->common.scope->name->val : ""; - zend_error(E_WARNING, "%s%s%s(): bad type specifier while parsing parameters", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s(): bad type specifier while parsing parameters", class_name, class_name[0] ? "::" : "", active_function->common.function_name->val); @@ -703,7 +705,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, if (!quiet) { zend_function *active_function = EG(current_execute_data)->func; const char *class_name = active_function->common.scope ? active_function->common.scope->name->val : ""; - zend_error(E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given", class_name, class_name[0] ? "::" : "", active_function->common.function_name->val, @@ -718,7 +720,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data)); if (num_args > arg_count) { - zend_error(E_WARNING, "%s(): could not obtain parameters for parsing", + zend_error(strict ? E_RECOVERABLE_ERROR : E_WARNING, "%s(): could not obtain parameters for parsing", get_active_function_name()); return FAILURE; } @@ -752,7 +754,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, arg = ZEND_CALL_ARG(EG(current_execute_data), i + 1); - if (zend_parse_arg(i+1, arg, va, &type_spec, quiet) == FAILURE) { + if (zend_parse_arg(i+1, arg, va, &type_spec, quiet, strict) == FAILURE) { /* clean up varargs array if it was used */ if (varargs && *varargs) { *varargs = NULL; @@ -766,13 +768,13 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, } /* }}} */ -#define RETURN_IF_ZERO_ARGS(num_args, type_spec, quiet) { \ +#define RETURN_IF_ZERO_ARGS(num_args, type_spec, flags) { \ int __num_args = (num_args); \ \ - if (0 == (type_spec)[0] && 0 != __num_args && !(quiet)) { \ + if (0 == (type_spec)[0] && 0 != __num_args && !(flags & ZEND_PARSE_PARAMS_QUIET)) { \ const char *__space; \ const char * __class_name = get_active_class_name(&__space); \ - zend_error(E_WARNING, "%s%s%s() expects exactly 0 parameters, %d given", \ + zend_error((flags & ZEND_PARSE_PARAMS_STRICT) ? E_RECOVERABLE_ERROR : E_WARNING, "%s%s%s() expects exactly 0 parameters, %d given", \ __class_name, __space, \ get_active_function_name(), __num_args); \ return FAILURE; \ @@ -784,7 +786,11 @@ ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_ va_list va; int retval; - RETURN_IF_ZERO_ARGS(num_args, type_spec, flags & ZEND_PARSE_PARAMS_QUIET); + if (ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) { + flags |= ZEND_PARSE_PARAMS_STRICT; + } + + RETURN_IF_ZERO_ARGS(num_args, type_spec, flags); va_start(va, type_spec); retval = zend_parse_va_args(num_args, type_spec, &va, flags); @@ -798,11 +804,16 @@ ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...) /* { va_list va; int retval; + int flags = 0; + + if (ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) { + flags |= ZEND_PARSE_PARAMS_STRICT; + } - RETURN_IF_ZERO_ARGS(num_args, type_spec, 0); + RETURN_IF_ZERO_ARGS(num_args, type_spec, flags); va_start(va, type_spec); - retval = zend_parse_va_args(num_args, type_spec, &va, 0); + retval = zend_parse_va_args(num_args, type_spec, &va, flags); va_end(va); return retval; @@ -813,24 +824,29 @@ ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const ch { va_list va; int retval; + int flags = 0; const char *p = type_spec; zval **object; zend_class_entry *ce; + if (ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) { + flags |= ZEND_PARSE_PARAMS_STRICT; + } + /* Just checking this_ptr is not enough, because fcall_common_helper does not set * Z_OBJ(EG(This)) to NULL when calling an internal function with common.scope == NULL. * In that case EG(This) would still be the $this from the calling code and we'd take the * wrong branch here. */ zend_bool is_method = EG(current_execute_data)->func->common.scope != NULL; if (!is_method || !this_ptr || Z_TYPE_P(this_ptr) != IS_OBJECT) { - RETURN_IF_ZERO_ARGS(num_args, p, 0); + RETURN_IF_ZERO_ARGS(num_args, p, flags); va_start(va, type_spec); - retval = zend_parse_va_args(num_args, type_spec, &va, 0); + retval = zend_parse_va_args(num_args, type_spec, &va, flags); va_end(va); } else { p++; - RETURN_IF_ZERO_ARGS(num_args, p, 0); + RETURN_IF_ZERO_ARGS(num_args, p, flags); va_start(va, type_spec); @@ -843,7 +859,7 @@ ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const ch Z_OBJCE_P(this_ptr)->name->val, get_active_function_name(), ce->name->val, get_active_function_name()); } - retval = zend_parse_va_args(num_args, p, &va, 0); + retval = zend_parse_va_args(num_args, p, &va, flags); va_end(va); } return retval; @@ -857,17 +873,20 @@ ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this const char *p = type_spec; zval **object; zend_class_entry *ce; - int quiet = flags & ZEND_PARSE_PARAMS_QUIET; + + if (ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) { + flags |= ZEND_PARSE_PARAMS_STRICT; + } if (!this_ptr) { - RETURN_IF_ZERO_ARGS(num_args, p, quiet); + RETURN_IF_ZERO_ARGS(num_args, p, flags); va_start(va, type_spec); retval = zend_parse_va_args(num_args, type_spec, &va, flags); va_end(va); } else { p++; - RETURN_IF_ZERO_ARGS(num_args, p, quiet); + RETURN_IF_ZERO_ARGS(num_args, p, flags); va_start(va, type_spec); @@ -876,7 +895,7 @@ ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this *object = this_ptr; if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce)) { - if (!quiet) { + if (!(flags & ZEND_PARSE_PARAMS_QUIET)) { zend_error(E_CORE_ERROR, "%s::%s() must be derived from %s::%s", ce->name->val, get_active_function_name(), Z_OBJCE_P(this_ptr)->name->val, get_active_function_name()); } diff --git a/Zend/zend_API.h b/Zend/zend_API.h index d84fbcb2bfef5..f0270d0847c0a 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -255,7 +255,9 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array); /* Parameter parsing API -- andrei */ -#define ZEND_PARSE_PARAMS_QUIET (1<<1) +#define ZEND_PARSE_PARAMS_QUIET (1<<1) +#define ZEND_PARSE_PARAMS_STRICT (1<<2) + ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...); ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...); ZEND_API char *zend_zval_type_name(const zval *arg); @@ -293,7 +295,7 @@ ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zen ZEND_API int zend_disable_function(char *function_name, size_t function_name_length); ZEND_API int zend_disable_class(char *class_name, size_t class_name_length); -ZEND_API void zend_wrong_param_count(void); +ZEND_API void zend_wrong_param_count(zend_bool strict); #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0) #define IS_CALLABLE_CHECK_NO_ACCESS (1<<1) @@ -351,12 +353,12 @@ ZEND_API char *zend_get_type_by_const(int type); #define getThis() (Z_OBJ(EX(This)) ? &EX(This) : NULL) #define ZEND_IS_METHOD_CALL() (EX(func)->common.scope != NULL) -#define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT() -#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret) +#define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT((ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0) +#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL((ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0, ret) #define ARG_COUNT(dummy) EX_NUM_ARGS() #define ZEND_NUM_ARGS() EX_NUM_ARGS() -#define ZEND_WRONG_PARAM_COUNT() { zend_wrong_param_count(); return; } -#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret) { zend_wrong_param_count(); return ret; } +#define ZEND_WRONG_PARAM_COUNT(strict) { zend_wrong_param_count(strict); return; } +#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(strict, ret) { zend_wrong_param_count(strict); return ret; } #ifndef ZEND_WIN32 #define DLEXPORT @@ -701,9 +703,9 @@ typedef enum _zend_expected_type { Z_EXPECTED_LAST } zend_expected_type; -ZEND_API void zend_wrong_paramers_count_error(int num_args, int min_num_args, int max_num_args); -ZEND_API void zend_wrong_paramer_type_error(int num, zend_expected_type expected_type, zval *arg); -ZEND_API void zend_wrong_paramer_class_error(int num, char *name, zval *arg); +ZEND_API void zend_wrong_paramers_count_error(int num_args, int min_num_args, int max_num_args, zend_bool strict); +ZEND_API void zend_wrong_paramer_type_error(int num, zend_expected_type expected_type, zval *arg, zend_bool strict); +ZEND_API void zend_wrong_paramer_class_error(int num, char *name, zval *arg, zend_bool strict); ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); #define ZPP_ERROR_OK 0 @@ -714,7 +716,8 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); #define ZPP_ERROR_WRONG_COUNT 5 #define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \ - const int _flags = (flags); \ + zend_bool _strict = (EX_CALL_INFO() & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0; \ + const int _flags = (flags) | (_strict ? ZEND_PARSE_PARAMS_STRICT : 0); \ int _min_num_args = (min_num_args); \ int _max_num_args = (max_num_args); \ int _num_args = EX_NUM_ARGS(); \ @@ -738,7 +741,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); (UNEXPECTED(_num_args > _max_num_args) && \ EXPECTED(_max_num_args >= 0))) { \ if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \ - zend_wrong_paramers_count_error(_num_args, _min_num_args, _max_num_args); \ + zend_wrong_paramers_count_error(_num_args, _min_num_args, _max_num_args, _strict); \ } \ error_code = ZPP_ERROR_FAILURE; \ break; \ @@ -754,11 +757,11 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); if (UNEXPECTED(error_code != ZPP_ERROR_OK)) { \ if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \ if (error_code == ZPP_ERROR_WRONG_CALLBACK) { \ - zend_wrong_callback_error(E_WARNING, _i, _error); \ + zend_wrong_callback_error(_strict ? E_RECOVERABLE_ERROR : E_WARNING, _i, _error); \ } else if (error_code == ZPP_ERROR_WRONG_CLASS) { \ - zend_wrong_paramer_class_error(_i, _error, _arg); \ + zend_wrong_paramer_class_error(_i, _error, _arg, _strict); \ } else if (error_code == ZPP_ERROR_WRONG_ARG) { \ - zend_wrong_paramer_type_error(_i, _expected_type, _arg); \ + zend_wrong_paramer_type_error(_i, _expected_type, _arg, _strict); \ } \ } \ failure; \ @@ -811,7 +814,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "b" */ #define Z_PARAM_BOOL_EX(dest, is_null, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null))) { \ + if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null, _strict))) { \ _expected_type = Z_EXPECTED_BOOL; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -823,7 +826,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "C" */ #define Z_PARAM_CLASS_EX(dest, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \ + if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null, _strict))) { \ error_code = ZPP_ERROR_FAILURE; \ break; \ } @@ -834,7 +837,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "d" */ #define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null))) { \ + if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null, _strict))) { \ _expected_type = Z_EXPECTED_DOUBLE; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -889,7 +892,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "l" */ #define Z_PARAM_LONG_EX(dest, is_null, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 0))) { \ + if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 0, _strict))) { \ _expected_type = Z_EXPECTED_LONG; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -901,7 +904,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "L" */ #define Z_PARAM_STRICT_LONG_EX(dest, is_null, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 1))) { \ + if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 1, _strict))) { \ _expected_type = Z_EXPECTED_LONG; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -943,7 +946,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "p" */ #define Z_PARAM_PATH_EX(dest, dest_len, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null))) { \ + if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null, _strict))) { \ _expected_type = Z_EXPECTED_PATH; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -955,7 +958,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "P" */ #define Z_PARAM_PATH_STR_EX(dest, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null))) { \ + if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null, _strict))) { \ _expected_type = Z_EXPECTED_PATH; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -979,7 +982,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "s" */ #define Z_PARAM_STRING_EX(dest, dest_len, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null))) { \ + if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null, _strict))) { \ _expected_type = Z_EXPECTED_STRING; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -991,7 +994,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* old "S" */ #define Z_PARAM_STR_EX(dest, check_null, separate) \ Z_PARAM_PROLOGUE(separate); \ - if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null))) { \ + if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null, _strict))) { \ _expected_type = Z_EXPECTED_STRING; \ error_code = ZPP_ERROR_WRONG_ARG; \ break; \ @@ -1046,13 +1049,18 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error); /* Inlined implementations shared by new and old parameter parsing APIs */ ZEND_API int parse_arg_object_to_str(zval *arg, zend_string **str, int type); -ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null); +ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null, zend_bool strict); -static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null) +static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null, zend_bool strict) { if (check_null) { *is_null = 0; } + + if (UNEXPECTED(strict && Z_TYPE_P(arg) != IS_TRUE && Z_TYPE_P(arg) != IS_FALSE && !(check_null && Z_TYPE_P(arg) == IS_NULL))) { + return 0; + } + if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) { *dest = 1; } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) { @@ -1068,11 +1076,16 @@ static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, ze return 1; } -static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, zend_bool *is_null, int check_null, int strict) +static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, zend_bool *is_null, int check_null, int cap, zend_bool strict) { if (check_null) { *is_null = 0; } + + if (UNEXPECTED(strict && Z_TYPE_P(arg) != IS_LONG && !(check_null && Z_TYPE_P(arg) == IS_NULL))) { + return 0; + } + if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) { *dest = Z_LVAL_P(arg); } else if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) { @@ -1080,8 +1093,7 @@ static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, ze return 0; } if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(Z_DVAL_P(arg)))) { - /* Ironically, the strict parameter makes zpp *non*-strict here */ - if (strict) { + if (cap) { *dest = (Z_DVAL_P(arg) > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN; } else { return 0; @@ -1099,7 +1111,7 @@ static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, ze return 0; } if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(d))) { - if (strict) { + if (cap) { *dest = (d > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN; } else { return 0; @@ -1124,11 +1136,16 @@ static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, ze return 1; } -static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zend_bool *is_null, int check_null) +static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zend_bool *is_null, int check_null, zend_bool strict) { if (check_null) { *is_null = 0; } + + if (UNEXPECTED(strict && Z_TYPE_P(arg) != IS_DOUBLE && !(check_null && Z_TYPE_P(arg) == IS_NULL))) { + return 0; + } + if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) { *dest = Z_DVAL_P(arg); } else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) { @@ -1157,8 +1174,12 @@ static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zen return 1; } -static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, int check_null) +static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, int check_null, zend_bool strict) { + if (UNEXPECTED(strict && Z_TYPE_P(arg) != IS_STRING && !(check_null && Z_TYPE_P(arg) == IS_NULL))) { + return 0; + } + if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) { *dest = Z_STR_P(arg); } else if (EXPECTED(Z_TYPE_P(arg) < IS_STRING)) { @@ -1179,11 +1200,11 @@ static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, return 1; } -static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, int check_null) +static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, int check_null, zend_bool strict) { zend_string *str; - if (!zend_parse_arg_str(arg, &str, check_null)) { + if (!zend_parse_arg_str(arg, &str, check_null, strict)) { return 0; } if (check_null && UNEXPECTED(!str)) { @@ -1196,20 +1217,20 @@ static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size return 1; } -static zend_always_inline int zend_parse_arg_path_str(zval *arg, zend_string **dest, int check_null) +static zend_always_inline int zend_parse_arg_path_str(zval *arg, zend_string **dest, int check_null, zend_bool strict) { - if (!zend_parse_arg_str(arg, dest, check_null) || + if (!zend_parse_arg_str(arg, dest, check_null, strict) || (*dest && UNEXPECTED(CHECK_NULL_PATH((*dest)->val, (*dest)->len)))) { return 0; } return 1; } -static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, int check_null) +static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, int check_null, zend_bool strict) { zend_string *str; - if (!zend_parse_arg_path_str(arg, &str, check_null)) { + if (!zend_parse_arg_path_str(arg, &str, check_null, strict)) { return 0; } if (check_null && UNEXPECTED(!str)) { diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 604303ae10deb..823412c7bb6fa 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -610,13 +610,13 @@ static int is_null_constant(zval *default_value) return 0; } -static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg) +static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg, zend_bool strict) { switch (type_hint) { case _IS_BOOL: { zend_bool dest; - if (!zend_parse_arg_bool(arg, &dest, NULL, 0)) { + if (!zend_parse_arg_bool(arg, &dest, NULL, 0, strict)) { return 0; } zval_ptr_dtor(arg); @@ -626,7 +626,7 @@ static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg) case IS_LONG: { zend_long dest; - if (!zend_parse_arg_long(arg, &dest, NULL, 0, 0)) { + if (!zend_parse_arg_long(arg, &dest, NULL, 0, 0, strict)) { return 0; } zval_ptr_dtor(arg); @@ -636,7 +636,7 @@ static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg) case IS_DOUBLE: { double dest; - if (!zend_parse_arg_double(arg, &dest, NULL, 0)) { + if (!zend_parse_arg_double(arg, &dest, NULL, 0, strict)) { return 0; } zval_ptr_dtor(arg); @@ -646,7 +646,7 @@ static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg) case IS_STRING: { zend_string *dest; - if (!zend_parse_arg_str(arg, &dest, 0)) { + if (!zend_parse_arg_str(arg, &dest, 0, strict)) { return 0; } zval_ptr_dtor(arg); @@ -695,7 +695,7 @@ static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, z if (!zend_is_callable(arg, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) { zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "", arg); } - } else if (UNEXPECTED(!ZEND_SAME_FAKE_TYPE(cur_arg_info->type_hint, Z_TYPE_P(arg)))) { + } else if (UNEXPECTED(!ZEND_SAME_FAKE_TYPE(cur_arg_info->type_hint, Z_TYPE_P(arg)))) { if (Z_TYPE_P(arg) == IS_NULL) { if (!cur_arg_info->allow_null) { failure: @@ -703,7 +703,7 @@ static void zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num, z } return; } - if (strict || !zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { + if (!zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg, strict)) { goto failure; } } @@ -755,7 +755,7 @@ static void zend_verify_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, } return; } - if (strict || !zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg)) { + if (!zend_verify_scalar_type_hint(cur_arg_info->type_hint, arg, strict)) { goto failure; } } From ca4901254b4428bb1715a740951f5df73d43b9f8 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Tue, 13 Jan 2015 02:44:03 +0000 Subject: [PATCH 11/29] Add strict scalar types test --- Zend/tests/typehints/scalar_strict_basic.phpt | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Zend/tests/typehints/scalar_strict_basic.phpt diff --git a/Zend/tests/typehints/scalar_strict_basic.phpt b/Zend/tests/typehints/scalar_strict_basic.phpt new file mode 100644 index 0000000000000..ab7a54a770886 --- /dev/null +++ b/Zend/tests/typehints/scalar_strict_basic.phpt @@ -0,0 +1,142 @@ +--TEST-- +Strict scalar type hint basics +--FILE-- + 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +$errored = true; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames, &$errored) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + $errored = true; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +$values = [ + 1, + 1.0, + "1", + TRUE, + FALSE, + NULL, + [], + new StdClass, + fopen("data:text/plain,foobar", "r") +]; + +function type($value) { + if (is_float($value)) { + return "float"; + } else if (is_bool($value)) { + return $value ? "true" : "false"; + } else if (is_null($value)) { + return "null"; + } else { + return gettype($value); + } +} + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; + foreach ($values as $value) { + $errored = false; + echo "*** Trying ", type($value), " value", PHP_EOL; + $result = $function($value); + if (!$errored) { + var_dump($result); + } + } +} +--EXPECTF-- + +Testing 'int' typehint: +*** Trying integer value +int(1) +*** Trying float value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line 53 and defined on line 18 +*** Trying string value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line 53 and defined on line 18 +*** Trying true value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line 53 and defined on line 18 +*** Trying false value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line 53 and defined on line 18 +*** Trying null value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line 53 and defined on line 18 +*** Trying array value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line 53 and defined on line 18 +*** Trying object value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line 53 and defined on line 18 +*** Trying resource value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line 53 and defined on line 18 + +Testing 'float' typehint: +*** Trying integer value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, integer given, called in %s on line 53 and defined on line 19 +*** Trying float value +float(1) +*** Trying string value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line 53 and defined on line 19 +*** Trying true value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line 53 and defined on line 19 +*** Trying false value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line 53 and defined on line 19 +*** Trying null value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line 53 and defined on line 19 +*** Trying array value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line 53 and defined on line 19 +*** Trying object value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line 53 and defined on line 19 +*** Trying resource value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line 53 and defined on line 19 + +Testing 'string' typehint: +*** Trying integer value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line 53 and defined on line 20 +*** Trying float value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line 53 and defined on line 20 +*** Trying string value +string(1) "1" +*** Trying true value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line 53 and defined on line 20 +*** Trying false value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line 53 and defined on line 20 +*** Trying null value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line 53 and defined on line 20 +*** Trying array value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line 53 and defined on line 20 +*** Trying object value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line 53 and defined on line 20 +*** Trying resource value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line 53 and defined on line 20 + +Testing 'bool' typehint: +*** Trying integer value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line 53 and defined on line 21 +*** Trying float value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line 53 and defined on line 21 +*** Trying string value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line 53 and defined on line 21 +*** Trying true value +bool(true) +*** Trying false value +bool(false) +*** Trying null value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line 53 and defined on line 21 +*** Trying array value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line 53 and defined on line 21 +*** Trying object value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line 53 and defined on line 21 +*** Trying resource value +E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line 53 and defined on line 21 From e1a238670c940ea6c017de0cada52e76528db64b Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 25 Jan 2015 01:40:54 +0000 Subject: [PATCH 12/29] Shorten syntax to strict_types=1 --- Zend/tests/typehints/scalar_strict_basic.phpt | 2 +- Zend/zend_compile.c | 14 +++++++------- Zend/zend_globals.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Zend/tests/typehints/scalar_strict_basic.phpt b/Zend/tests/typehints/scalar_strict_basic.phpt index ab7a54a770886..b52fa7015c432 100644 --- a/Zend/tests/typehints/scalar_strict_basic.phpt +++ b/Zend/tests/typehints/scalar_strict_basic.phpt @@ -3,7 +3,7 @@ Strict scalar type hint basics --FILE-- 'E_NOTICE', diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 1b7503605c70a..1d5466bacd5c1 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -142,7 +142,7 @@ static zend_bool zend_get_unqualified_name(const zend_string *name, const char * static void init_compiler_declarables(void) /* {{{ */ { ZVAL_LONG(&CG(declarables).ticks, 0); - CG(declarables).strict_typehints = 0; + CG(declarables).strict_types = 0; } /* }}} */ @@ -1532,7 +1532,7 @@ void zend_do_end_compilation(void) /* {{{ */ CG(has_bracketed_namespaces) = 0; zend_end_namespace(); /* strict typehinting is per-file */ - CG(declarables).strict_typehints = 0; + CG(declarables).strict_types = 0; } /* }}} */ @@ -2552,7 +2552,7 @@ void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function * } call_flags = ((opline->opcode == ZEND_NEW) ? ZEND_CALL_CTOR : 0) - | (CG(declarables).strict_typehints ? ZEND_CALL_STRICT_TYPEHINTS : 0); + | (CG(declarables).strict_types ? ZEND_CALL_STRICT_TYPEHINTS : 0); opline = zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL); opline->op1.num = call_flags; @@ -3791,15 +3791,15 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */ zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be " "the very first statement in the script"); } - } else if (zend_string_equals_literal_ci(name, "strict_typehints")) { + } else if (zend_string_equals_literal_ci(name, "strict_types")) { zval value_zv; zend_const_expr_to_zval(&value_zv, value_ast); - if (Z_TYPE(value_zv) != IS_FALSE && Z_TYPE(value_zv) != IS_TRUE) { - zend_error_noreturn(E_COMPILE_ERROR, "strict_typehints declaration must have a boolean value"); + if (Z_TYPE(value_zv) != IS_LONG || (Z_LVAL(value_zv) != 0 && Z_LVAL(value_zv) != 1)) { + zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must have 0 or 1 as its value"); } - CG(declarables).strict_typehints = (Z_TYPE(value_zv) == IS_TRUE) ? 1 : 0; + CG(declarables).strict_types = Z_LVAL(value_zv); } else { zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", name->val); } diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index 7295eaefd3a6c..630d0f4c063d4 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -64,7 +64,7 @@ END_EXTERN_C() typedef struct _zend_declarables { zval ticks; - zend_bool strict_typehints; + zend_bool strict_types; } zend_declarables; typedef struct _zend_vm_stack *zend_vm_stack; From b112c13a41674e9c307f42c6054e3036ca3e6960 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 25 Jan 2015 02:18:58 +0000 Subject: [PATCH 13/29] Test strict code calling weak code and vice-versa --- Zend/tests/typehints/strict_call_weak.phpt | 17 +++++++++++++++++ Zend/tests/typehints/strict_call_weak_2.inc | 7 +++++++ .../typehints/strict_call_weak_explicit.phpt | 17 +++++++++++++++++ .../typehints/strict_call_weak_explicit_2.inc | 7 +++++++ Zend/tests/typehints/weak_call_strict.phpt | 16 ++++++++++++++++ Zend/tests/typehints/weak_call_strict_2.inc | 7 +++++++ .../typehints/weak_explicit_call_strict.phpt | 16 ++++++++++++++++ 7 files changed, 87 insertions(+) create mode 100644 Zend/tests/typehints/strict_call_weak.phpt create mode 100644 Zend/tests/typehints/strict_call_weak_2.inc create mode 100644 Zend/tests/typehints/strict_call_weak_explicit.phpt create mode 100644 Zend/tests/typehints/strict_call_weak_explicit_2.inc create mode 100644 Zend/tests/typehints/weak_call_strict.phpt create mode 100644 Zend/tests/typehints/weak_call_strict_2.inc create mode 100644 Zend/tests/typehints/weak_explicit_call_strict.phpt diff --git a/Zend/tests/typehints/strict_call_weak.phpt b/Zend/tests/typehints/strict_call_weak.phpt new file mode 100644 index 0000000000000..45b87b042ab3a --- /dev/null +++ b/Zend/tests/typehints/strict_call_weak.phpt @@ -0,0 +1,17 @@ +--TEST-- +strict_types=1 code calling strict_types=0 code +--FILE-- + +--EXPECTF-- +Catchable fatal error: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak.php on line 10 and defined in %sstrict_call_weak_2.inc on line 5 + diff --git a/Zend/tests/typehints/strict_call_weak_2.inc b/Zend/tests/typehints/strict_call_weak_2.inc new file mode 100644 index 0000000000000..cba5512897735 --- /dev/null +++ b/Zend/tests/typehints/strict_call_weak_2.inc @@ -0,0 +1,7 @@ + +--EXPECTF-- +Catchable fatal error: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak_explicit.php on line 10 and defined in %sstrict_call_weak_explicit_2.inc on line 5 + diff --git a/Zend/tests/typehints/strict_call_weak_explicit_2.inc b/Zend/tests/typehints/strict_call_weak_explicit_2.inc new file mode 100644 index 0000000000000..d26c84761c06f --- /dev/null +++ b/Zend/tests/typehints/strict_call_weak_explicit_2.inc @@ -0,0 +1,7 @@ + +--EXPECT-- +Success! diff --git a/Zend/tests/typehints/weak_call_strict_2.inc b/Zend/tests/typehints/weak_call_strict_2.inc new file mode 100644 index 0000000000000..fe2a17f682071 --- /dev/null +++ b/Zend/tests/typehints/weak_call_strict_2.inc @@ -0,0 +1,7 @@ + +--EXPECT-- +Success! From 2985944a8af96ec5b81c7d7b9288d06a829e6435 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 25 Jan 2015 02:21:34 +0000 Subject: [PATCH 14/29] Fix usage of zend_wrong_param_count in ext/mysqli --- ext/mysqli/mysqli_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 9f6d8220ce64c..27d3560db328b 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -368,7 +368,7 @@ PHP_FUNCTION(mysqli_stmt_bind_param) args = safe_emalloc(argc, sizeof(zval), 0); if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - zend_wrong_param_count(); + ZEND_WRONG_PARAM_COUNT(); rc = 1; } else { rc = mysqli_stmt_bind_param_do_bind(stmt, argc, num_vars, args, start, types); From 86b0685f55fe72590296acae056f996bc951a461 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 25 Jan 2015 02:22:28 +0000 Subject: [PATCH 15/29] Prefix zend_wrong_param_count with _ to discourage use --- Zend/zend_API.c | 2 +- Zend/zend_API.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index e055a63b8dcac..22fb42d09984e 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -149,7 +149,7 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array) / } /* }}} */ -ZEND_API void zend_wrong_param_count(zend_bool strict) /* {{{ */ +ZEND_API void _zend_wrong_param_count(zend_bool strict) /* {{{ */ { const char *space; const char *class_name = get_active_class_name(&space); diff --git a/Zend/zend_API.h b/Zend/zend_API.h index f0270d0847c0a..0855f811dc313 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -295,7 +295,7 @@ ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zen ZEND_API int zend_disable_function(char *function_name, size_t function_name_length); ZEND_API int zend_disable_class(char *class_name, size_t class_name_length); -ZEND_API void zend_wrong_param_count(zend_bool strict); +ZEND_API void _zend_wrong_param_count(zend_bool strict); #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0) #define IS_CALLABLE_CHECK_NO_ACCESS (1<<1) @@ -357,8 +357,8 @@ ZEND_API char *zend_get_type_by_const(int type); #define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL((ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0, ret) #define ARG_COUNT(dummy) EX_NUM_ARGS() #define ZEND_NUM_ARGS() EX_NUM_ARGS() -#define ZEND_WRONG_PARAM_COUNT(strict) { zend_wrong_param_count(strict); return; } -#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(strict, ret) { zend_wrong_param_count(strict); return ret; } +#define ZEND_WRONG_PARAM_COUNT(strict) { _zend_wrong_param_count(strict); return; } +#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(strict, ret) { _zend_wrong_param_count(strict); return ret; } #ifndef ZEND_WIN32 #define DLEXPORT From 17b3707bad9b896a79c2b56ece433faab348b587 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 25 Jan 2015 02:41:53 +0000 Subject: [PATCH 16/29] Test strict code including weak code and vice-versa --- .../typehints/explicit_weak_include_strict.phpt | 14 ++++++++++++++ .../typehints/strict_include_explicit_weak.phpt | 14 ++++++++++++++ .../typehints/strict_include_explicit_weak_2.inc | 9 +++++++++ Zend/tests/typehints/strict_include_weak.phpt | 14 ++++++++++++++ Zend/tests/typehints/strict_include_weak_2.inc | 9 +++++++++ Zend/tests/typehints/weak_include_strict.phpt | 14 ++++++++++++++ Zend/tests/typehints/weak_include_strict_2.inc | 9 +++++++++ 7 files changed, 83 insertions(+) create mode 100644 Zend/tests/typehints/explicit_weak_include_strict.phpt create mode 100644 Zend/tests/typehints/strict_include_explicit_weak.phpt create mode 100644 Zend/tests/typehints/strict_include_explicit_weak_2.inc create mode 100644 Zend/tests/typehints/strict_include_weak.phpt create mode 100644 Zend/tests/typehints/strict_include_weak_2.inc create mode 100644 Zend/tests/typehints/weak_include_strict.phpt create mode 100644 Zend/tests/typehints/weak_include_strict_2.inc diff --git a/Zend/tests/typehints/explicit_weak_include_strict.phpt b/Zend/tests/typehints/explicit_weak_include_strict.phpt new file mode 100644 index 0000000000000..b7bcc5d02d2d4 --- /dev/null +++ b/Zend/tests/typehints/explicit_weak_include_strict.phpt @@ -0,0 +1,14 @@ +--TEST-- +explicitly strict_types=0 code including strict_types=1 code +--FILE-- + +--EXPECTF-- +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/typehints/strict_include_explicit_weak.phpt b/Zend/tests/typehints/strict_include_explicit_weak.phpt new file mode 100644 index 0000000000000..a42d633f47e51 --- /dev/null +++ b/Zend/tests/typehints/strict_include_explicit_weak.phpt @@ -0,0 +1,14 @@ +--TEST-- +strict_types=1 code including explicitly strict_types=0 code +--FILE-- + +--EXPECTF-- +Success! diff --git a/Zend/tests/typehints/strict_include_explicit_weak_2.inc b/Zend/tests/typehints/strict_include_explicit_weak_2.inc new file mode 100644 index 0000000000000..3da32e1738209 --- /dev/null +++ b/Zend/tests/typehints/strict_include_explicit_weak_2.inc @@ -0,0 +1,9 @@ + +--EXPECTF-- +Success! diff --git a/Zend/tests/typehints/strict_include_weak_2.inc b/Zend/tests/typehints/strict_include_weak_2.inc new file mode 100644 index 0000000000000..d4ee8a836b241 --- /dev/null +++ b/Zend/tests/typehints/strict_include_weak_2.inc @@ -0,0 +1,9 @@ + +--EXPECTF-- +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/typehints/weak_include_strict_2.inc b/Zend/tests/typehints/weak_include_strict_2.inc new file mode 100644 index 0000000000000..8acfc039e8410 --- /dev/null +++ b/Zend/tests/typehints/weak_include_strict_2.inc @@ -0,0 +1,9 @@ + Date: Sun, 25 Jan 2015 02:44:21 +0000 Subject: [PATCH 17/29] Fix fix --- ext/mysqli/mysqli_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 27d3560db328b..3516ab489471e 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -368,7 +368,7 @@ PHP_FUNCTION(mysqli_stmt_bind_param) args = safe_emalloc(argc, sizeof(zval), 0); if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); + WRONG_PARAM_COUNT; rc = 1; } else { rc = mysqli_stmt_bind_param_do_bind(stmt, argc, num_vars, args, start, types); From 187a95f8d3a9f482b30c3b382d6ee4de356e6c5c Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 25 Jan 2015 03:06:45 +0000 Subject: [PATCH 18/29] Test nested strict/weak function calls --- Zend/tests/typehints/strict_nested.phpt | 115 ++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Zend/tests/typehints/strict_nested.phpt diff --git a/Zend/tests/typehints/strict_nested.phpt b/Zend/tests/typehints/strict_nested.phpt new file mode 100644 index 0000000000000..44e5214aeefbe --- /dev/null +++ b/Zend/tests/typehints/strict_nested.phpt @@ -0,0 +1,115 @@ +--TEST-- +Test nested function calls in strict_types=0 and strict_types=1 modes +--FILE-- +call(); // should cause an error +(new WeakTakesIntCaller)->call(); // should succeed +(new ExplicitWeakTakesIntCaller)->call(); // should succeed + +declare(strict_types=0) { + strict_calls_takes_int(); // should cause an error: our call to func is weak, but it was declared in strict mode so calls it makes are strict + weak_calls_takes_int(); // should succeed + explicit_weak_calls_takes_int(); // should succeed + (new StrictTakesIntCaller)->call(); // should cause an error + (new WeakTakesIntCaller)->call(); // should succeed + (new ExplicitWeakTakesIntCaller)->call(); // should succeed +} + +declare(strict_types=1) { + strict_calls_takes_int(); // should cause an error + weak_calls_takes_int(); // should succeed: our call to func is strict, but it was declared in weak mode so calls it makes are weak + explicit_weak_calls_takes_int(); // should succeed + (new StrictTakesIntCaller)->call(); // should cause an error + (new WeakTakesIntCaller)->call(); // should succeed + (new ExplicitWeakTakesIntCaller)->call(); // should succeed +} + +?> +--EXPECTF-- +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 26 and defined in %sstrict_nested.php on line 14 +Failure! +Success! +Success! +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 31 and defined in %sstrict_nested.php on line 14 +Failure! +Success! +Success! +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 26 and defined in %sstrict_nested.php on line 14 +Failure! +Success! +Success! +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 31 and defined in %sstrict_nested.php on line 14 +Failure! +Success! +Success! +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 26 and defined in %sstrict_nested.php on line 14 +Failure! +Success! +Success! +Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 31 and defined in %sstrict_nested.php on line 14 +Failure! +Success! +Success! From 0af3b7c017264d6f5264dc7e284478a3c70f6bd7 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 25 Jan 2015 03:28:17 +0000 Subject: [PATCH 19/29] Test behaviour of weak type hints with references --- .../typehints/scalar_weak_reference.phpt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Zend/tests/typehints/scalar_weak_reference.phpt diff --git a/Zend/tests/typehints/scalar_weak_reference.phpt b/Zend/tests/typehints/scalar_weak_reference.phpt new file mode 100644 index 0000000000000..f397ceaa8d97b --- /dev/null +++ b/Zend/tests/typehints/scalar_weak_reference.phpt @@ -0,0 +1,29 @@ +--TEST-- +Weak scalar type hints, with references +--FILE-- + +--EXPECT-- +float(1) +int(1) +float(1) +string(1) "1" +bool(true) From cbbaea08da8363358fa2257f7b441ab9d148aae4 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Thu, 29 Jan 2015 18:07:25 +0000 Subject: [PATCH 20/29] Fix merge error --- Zend/zend_language_parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 3671eadd6b721..009d7bae0b33f 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -573,7 +573,7 @@ optional_type: ; type: - | T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } + T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); } | T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); } | name { $$ = $1; } ; From c7719ab4e5e49cdcef350a873ce4067bab3b7c02 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 1 Feb 2015 14:22:48 +0000 Subject: [PATCH 21/29] Refactor typehint lookup --- Zend/zend_compile.c | 78 ++++++++++++++++++++++++++++++++++++++++----- Zend/zend_compile.h | 41 ++---------------------- 2 files changed, 72 insertions(+), 47 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 1d5466bacd5c1..0f5fb03c45a3a 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -139,6 +139,71 @@ static zend_bool zend_get_unqualified_name(const zend_string *name, const char * } /* }}} */ +struct _scalar_typehint_info { + const char* name; + const size_t name_len; + const zend_uchar type; +}; + +static const struct _scalar_typehint_info scalar_typehints[] = { + {"int", sizeof("int") - 1, IS_LONG}, + {"integer", sizeof("integer") - 1, IS_LONG}, + {"float", sizeof("float") - 1, IS_DOUBLE}, + {"string", sizeof("string") - 1, IS_STRING}, + {"bool", sizeof("bool") - 1, _IS_BOOL}, + {"boolean", sizeof("boolean") - 1, _IS_BOOL}, + {NULL, 0, IS_UNDEF} +}; + +static zend_always_inline const struct _scalar_typehint_info* zend_find_scalar_typehint(const zend_string *const_name) /* {{{ */ +{ + const struct _scalar_typehint_info *info = &scalar_typehints[0]; + const char *uqname; + size_t uqname_len; + + if (!zend_get_unqualified_name(const_name, &uqname, &uqname_len)) { + uqname = const_name->val; + uqname_len = const_name->len; + } + + while (info->name) { + if (uqname_len == info->name_len && zend_binary_strcasecmp(uqname, uqname_len, info->name, info->name_len) == 0) { + break; + } + info++; + } + + if (info->name) { + return info; + } else { + return NULL; + } +} +/* }}} */ + +ZEND_API void zend_assert_valid_class_name(const zend_string *const_name) /* {{{ */ +{ + const struct _scalar_typehint_info *info = zend_find_scalar_typehint(const_name); + + if (info) { + zend_error_noreturn(E_COMPILE_ERROR, "\"%s\" cannot be used as a class name", info->name); + } +} +/* }}} */ + +static zend_always_inline zend_uchar zend_lookup_scalar_typehint_by_name(const zend_string *const_name) /* {{{ */ +{ + const struct _scalar_typehint_info *info = zend_find_scalar_typehint(const_name); + + if (info) { + return info->type; + } else { + return 0; + } +} +/* }}} */ + + static void init_compiler_declarables(void) /* {{{ */ { ZVAL_LONG(&CG(declarables).ticks, 0); @@ -3962,15 +4027,12 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, zend_bool is_ } } else { zend_string *class_name = zend_ast_get_str(type_ast); - const struct _scalar_typehint_info *info = &scalar_typehints[0]; + zend_uchar type; - while (info->name) { - if (class_name->len == info->name_len - && zend_binary_strcasecmp(class_name->val, info->name_len, info->name, info->name_len) == 0) { - arg_info->type_hint = info->type; - goto done; - } - info++; + type = zend_lookup_scalar_typehint_by_name(class_name); + if (type != 0) { + arg_info->type_hint = type; + goto done; } if (zend_is_const_default_class_ref(type_ast)) { diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 3d44a08df7840..ae5a042fd42e2 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -31,45 +31,6 @@ #include "zend_llist.h" -struct _scalar_typehint_info { - const char* name; - const size_t name_len; - const zend_uchar type; -}; - -static const struct _scalar_typehint_info scalar_typehints[] = { - {"int", sizeof("int") - 1, IS_LONG}, - {"integer", sizeof("integer") - 1, IS_LONG}, - {"float", sizeof("float") - 1, IS_DOUBLE}, - {"string", sizeof("string") - 1, IS_STRING}, - {"bool", sizeof("bool") - 1, _IS_BOOL}, - {"boolean", sizeof("boolean") - 1, _IS_BOOL}, - {NULL, 0, IS_UNDEF} -}; - -static zend_always_inline void zend_assert_valid_class_name(const zend_string *const_name) -{ - const struct _scalar_typehint_info *info = &scalar_typehints[0]; - const char *end_slash = strrchr(const_name->val, '\\'); - zend_string *name = (zend_string*)const_name; - - if (end_slash) { - end_slash++; - name = zend_string_init(end_slash, strlen(end_slash), 0); - } - - while (info->name) { - if (name->len == info->name_len && zend_binary_strcasecmp(name->val, name->len, info->name, info->name_len) == 0) { - zend_error_noreturn(E_COMPILE_ERROR, "\"%s\" cannot be used as a class name", name->val); - } - info++; - } - - if (end_slash) { - zend_string_release(name); - } -} - #define DEBUG_ZEND 0 #define SET_UNUSED(op) op ## _type = IS_UNUSED @@ -777,6 +738,8 @@ int zendlex(zend_parser_stack_elem *elem); int zend_add_literal(zend_op_array *op_array, zval *zv); +ZEND_API void zend_assert_valid_class_name(const zend_string *const_name); + /* BEGIN: OPCODES */ #include "zend_vm_opcodes.h" From 6b6b2b4b7cc2f463c7add85fd1ccd1ba89b004cf Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 1 Feb 2015 16:33:52 +0000 Subject: [PATCH 22/29] Implement scalar return types (strict only for now) --- Zend/zend_compile.c | 23 ++++++++++++++--------- Zend/zend_execute.c | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 0f5fb03c45a3a..b2d4a91763d45 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3909,19 +3909,24 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, zend_bool is_ arg_infos->type_hint = return_type_ast->attr; } else { zend_string *class_name = zend_ast_get_str(return_type_ast); + zend_uchar type = zend_lookup_scalar_typehint_by_name(class_name); - if (zend_is_const_default_class_ref(return_type_ast)) { - class_name = zend_resolve_class_name_ast(return_type_ast); + if (type != 0) { + arg_infos->type_hint = type; } else { - zend_string_addref(class_name); - if (!is_method) { - zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare a return type of %s outside of a class scope", class_name->val); - return; + if (zend_is_const_default_class_ref(return_type_ast)) { + class_name = zend_resolve_class_name_ast(return_type_ast); + } else { + zend_string_addref(class_name); + if (!is_method) { + zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare a return type of %s outside of a class scope", class_name->val); + return; + } } - } - arg_infos->type_hint = IS_OBJECT; - arg_infos->class_name = class_name; + arg_infos->type_hint = IS_OBJECT; + arg_infos->class_name = class_name; + } } arg_infos++; diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 823412c7bb6fa..1928e9c018ab6 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -901,10 +901,17 @@ static void zend_verify_return_type(zend_function *zf, zval *ret) if (!zend_is_callable(ret, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(ret) != IS_NULL || !ret_info->allow_null)) { zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be callable", "", zend_zval_type_name(ret), ""); } -#if ZEND_DEBUG - } else { - zend_error(E_ERROR, "Unknown typehint"); -#endif + } else if (UNEXPECTED(!ZEND_SAME_FAKE_TYPE(ret_info->type_hint, Z_TYPE_P(ret)))) { + if (Z_TYPE_P(ret) == IS_NULL) { + if (!ret_info->allow_null) { +failure: + zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type ", zend_get_type_by_const(ret_info->type_hint), zend_zval_type_name(ret), ""); + } + return; + } + if (!zend_verify_scalar_type_hint(ret_info->type_hint, ret, 1)) { + goto failure; + } } } } @@ -926,10 +933,8 @@ static inline int zend_verify_missing_return_type(zend_function *zf) zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type array", "", "none", ""); } else if (ret_info->type_hint == IS_CALLABLE) { zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be callable", "", "none", ""); -#if ZEND_DEBUG } else { - zend_error(E_ERROR, "Unknown typehint"); -#endif + zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type ", zend_get_type_by_const(ret_info->type_hint), "none", ""); } return 0; } From 44ed070a9afed6f45165769f959c1122e765ad35 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 1 Feb 2015 16:40:57 +0000 Subject: [PATCH 23/29] Fix Gd usages of ZEND_WRONG_PARAM_COUNT, add usage note --- Zend/zend_API.h | 11 +++++++---- ext/gd/gd.c | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 0855f811dc313..4f12834bcfaa9 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -353,12 +353,15 @@ ZEND_API char *zend_get_type_by_const(int type); #define getThis() (Z_OBJ(EX(This)) ? &EX(This) : NULL) #define ZEND_IS_METHOD_CALL() (EX(func)->common.scope != NULL) -#define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT((ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0) -#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL((ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0, ret) +#define WRONG_PARAM_COUNT _ZEND_WRONG_PARAM_COUNT((ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0) +#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) _ZEND_WRONG_PARAM_COUNT_WITH_RETVAL((ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_STRICT_TYPEHINTS) ? 1 : 0, ret) #define ARG_COUNT(dummy) EX_NUM_ARGS() #define ZEND_NUM_ARGS() EX_NUM_ARGS() -#define ZEND_WRONG_PARAM_COUNT(strict) { _zend_wrong_param_count(strict); return; } -#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(strict, ret) { _zend_wrong_param_count(strict); return ret; } +/* These are prefixed with underscores for a reason: don't use them directly + * Use WRONG_PARAM_COUNT; + */ +#define _ZEND_WRONG_PARAM_COUNT(strict) { _zend_wrong_param_count(strict); return; } +#define _ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(strict, ret) { _zend_wrong_param_count(strict); return ret; } #ifndef ZEND_WIN32 #define DLEXPORT diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 61050ba2881d3..ebd4500495bb6 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3940,13 +3940,13 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int if (mode == TTFTEXT_BBOX) { if (argc < 4 || argc > ((extended) ? 5 : 4)) { - ZEND_WRONG_PARAM_COUNT(); + WRONG_PARAM_COUNT; } else if (zend_parse_parameters(argc, "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) { RETURN_FALSE; } } else { if (argc < 8 || argc > ((extended) ? 9 : 8)) { - ZEND_WRONG_PARAM_COUNT(); + WRONG_PARAM_COUNT; } else if (zend_parse_parameters(argc, "rddlllss|a", &IM, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) { RETURN_FALSE; } @@ -4395,7 +4395,7 @@ PHP_FUNCTION(imagepsbbox) BBox char_bbox, str_bbox = {0, 0, 0, 0}; if (argc != 3 && argc != 6) { - ZEND_WRONG_PARAM_COUNT(); + WRONG_PARAM_COUNT; } if (zend_parse_parameters(ZEND_NUM_ARGS(), "Srl|lld", &str, &fnt, &sz, &sp, &wd, &angle) == FAILURE) { From 5a7ac0fadec3e5fcc22c96b0e7c9a73a9de20a32 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 1 Feb 2015 23:20:39 +0000 Subject: [PATCH 24/29] Implement per-file strictness for scalar return types --- Zend/zend_compile.c | 16 ++++++++++++++-- Zend/zend_execute.c | 4 ++-- Zend/zend_vm_def.h | 3 ++- Zend/zend_vm_execute.h | 15 ++++++++++----- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index b2d4a91763d45..ec41f64900847 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1902,7 +1902,8 @@ static zend_op *zend_delayed_compile_end(uint32_t offset) /* {{{ */ static void zend_emit_return_type_check(znode *expr, zend_arg_info *return_info) /* {{{ */ { if (return_info->type_hint != IS_UNDEF) { - zend_emit_op(NULL, ZEND_VERIFY_RETURN_TYPE, expr, NULL); + zend_op *opline = zend_emit_op(NULL, ZEND_VERIFY_RETURN_TYPE, expr, NULL); + opline->extended_value = (CG(declarables).strict_types ? 1 : 0); } } /* }}} */ @@ -3238,7 +3239,18 @@ void zend_compile_return(zend_ast *ast) /* {{{ */ } if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { - zend_emit_return_type_check(&expr_node, CG(active_op_array)->arg_info - 1); + zend_arg_info *arg_info = CG(active_op_array)->arg_info - 1; + + /* for scalar, weak return types, the value may be casted + * thus, for constants, we need to store them in a tmp var + */ + if (expr_node.op_type == IS_CONST && !CG(declarables).strict_types) { + znode expr_node_copy = expr_node; + + zend_emit_op_tmp(&expr_node, ZEND_QM_ASSIGN, &expr_node_copy, NULL); + } + + zend_emit_return_type_check(&expr_node, arg_info); if (expr_node.op_type == IS_CONST) { zval_copy_ctor(&expr_node.u.constant); } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 1928e9c018ab6..0d4634f51ca00 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -874,7 +874,7 @@ static int zend_verify_internal_return_type(zend_function *zf, zval *ret) } #endif -static void zend_verify_return_type(zend_function *zf, zval *ret) +static void zend_verify_return_type(zend_function *zf, zval *ret, zend_bool strict) { zend_arg_info *ret_info = zf->common.arg_info - 1; char *need_msg; @@ -909,7 +909,7 @@ static void zend_verify_return_type(zend_function *zf, zval *ret) } return; } - if (!zend_verify_scalar_type_hint(ret_info->type_hint, ret, 1)) { + if (!zend_verify_scalar_type_hint(ret_info->type_hint, ret, strict)) { goto failure; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 0557ddd16c6f5..c1cee3635357e 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2962,7 +2962,8 @@ ZEND_VM_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV, UNUSED) zend_free_op free_op1; retval_ptr = GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R); - zend_verify_return_type(EX(func), retval_ptr); + /* extended_value stores strictness flag */ + zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index ab736264ade5b..48b21506ead36 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -6113,7 +6113,8 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_CONST_UNUSED_HANDLER(ZEND retval_ptr = EX_CONSTANT(opline->op1); - zend_verify_return_type(EX(func), retval_ptr); + /* extended_value stores strictness flag */ + zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -10131,7 +10132,8 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_TMP_UNUSED_HANDLER(ZEND_O zend_free_op free_op1; retval_ptr = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); - zend_verify_return_type(EX(func), retval_ptr); + /* extended_value stores strictness flag */ + zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -14972,7 +14974,8 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_VAR_UNUSED_HANDLER(ZEND_O zend_free_op free_op1; retval_ptr = _get_zval_ptr_var_deref(opline->op1.var, execute_data, &free_op1); - zend_verify_return_type(EX(func), retval_ptr); + /* extended_value stores strictness flag */ + zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -20235,7 +20238,8 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_UNUSED_UNUSED_HANDLER(ZEN retval_ptr = NULL; - zend_verify_return_type(EX(func), retval_ptr); + /* extended_value stores strictness flag */ + zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -28419,7 +28423,8 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_CV_UNUSED_HANDLER(ZEND_OP retval_ptr = _get_zval_ptr_cv_deref_BP_VAR_R(execute_data, opline->op1.var); - zend_verify_return_type(EX(func), retval_ptr); + /* extended_value stores strictness flag */ + zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); From 0294485164199ee043d8871a22e0a7a9f3d82fc8 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Mon, 2 Feb 2015 20:07:46 +0000 Subject: [PATCH 25/29] Prevent "undefined variable opline" errors --- Zend/zend_vm_def.h | 3 +++ Zend/zend_vm_execute.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index c1cee3635357e..9b4a7b0ca29f7 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2958,12 +2958,15 @@ ZEND_VM_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV, UNUSED) if (OP1_TYPE == IS_UNUSED) { zend_verify_missing_return_type(EX(func)); } else { +/* prevents "undefined variable opline" errors */ +#if OP1_TYPE != IS_UNUSED zval *retval_ptr; zend_free_op free_op1; retval_ptr = GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R); /* extended_value stores strictness flag */ zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); +#endif } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 48b21506ead36..83943a9c66b6a 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -6109,12 +6109,15 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_CONST_UNUSED_HANDLER(ZEND if (IS_CONST == IS_UNUSED) { zend_verify_missing_return_type(EX(func)); } else { +/* prevents "undefined variable opline" errors */ +#if IS_CONST != IS_UNUSED zval *retval_ptr; retval_ptr = EX_CONSTANT(opline->op1); /* extended_value stores strictness flag */ zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); +#endif } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -10128,12 +10131,15 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_TMP_UNUSED_HANDLER(ZEND_O if (IS_TMP_VAR == IS_UNUSED) { zend_verify_missing_return_type(EX(func)); } else { +/* prevents "undefined variable opline" errors */ +#if IS_TMP_VAR != IS_UNUSED zval *retval_ptr; zend_free_op free_op1; retval_ptr = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); /* extended_value stores strictness flag */ zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); +#endif } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -14970,12 +14976,15 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_VAR_UNUSED_HANDLER(ZEND_O if (IS_VAR == IS_UNUSED) { zend_verify_missing_return_type(EX(func)); } else { +/* prevents "undefined variable opline" errors */ +#if IS_VAR != IS_UNUSED zval *retval_ptr; zend_free_op free_op1; retval_ptr = _get_zval_ptr_var_deref(opline->op1.var, execute_data, &free_op1); /* extended_value stores strictness flag */ zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); +#endif } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -20234,12 +20243,15 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_UNUSED_UNUSED_HANDLER(ZEN if (IS_UNUSED == IS_UNUSED) { zend_verify_missing_return_type(EX(func)); } else { +/* prevents "undefined variable opline" errors */ +#if IS_UNUSED != IS_UNUSED zval *retval_ptr; retval_ptr = NULL; /* extended_value stores strictness flag */ zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); +#endif } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -28419,12 +28431,15 @@ static int ZEND_FASTCALL ZEND_VERIFY_RETURN_TYPE_SPEC_CV_UNUSED_HANDLER(ZEND_OP if (IS_CV == IS_UNUSED) { zend_verify_missing_return_type(EX(func)); } else { +/* prevents "undefined variable opline" errors */ +#if IS_CV != IS_UNUSED zval *retval_ptr; retval_ptr = _get_zval_ptr_cv_deref_BP_VAR_R(execute_data, opline->op1.var); /* extended_value stores strictness flag */ zend_verify_return_type(EX(func), retval_ptr, opline->extended_value); +#endif } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); From b5513cdb698bab1abbde3900c95f703f39b07228 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Thu, 5 Feb 2015 19:36:27 +0000 Subject: [PATCH 26/29] Add scalar return types test --- Zend/tests/typehints/scalar_return_basic.phpt | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 Zend/tests/typehints/scalar_return_basic.phpt diff --git a/Zend/tests/typehints/scalar_return_basic.phpt b/Zend/tests/typehints/scalar_return_basic.phpt new file mode 100644 index 0000000000000..f31055ee56e1c --- /dev/null +++ b/Zend/tests/typehints/scalar_return_basic.phpt @@ -0,0 +1,241 @@ +--TEST-- +Return scalar type hint basics +--FILE-- + 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function ($i): int { return $i; }, + 'float' => function ($f): float { return $f; }, + 'string' => function ($s): string { return $s; }, + 'bool' => function ($b): bool { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + var_dump($function($value)); + } +} +--EXPECTF-- + +Testing 'int' typehint: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d +string(1) "a" +*** Trying string(0) "" +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d +string(0) "" +*** Trying int(%d) +int(%d) +*** Trying float(NAN) +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, float returned on line %d +float(NAN) +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, null returned on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, array returned on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, object returned on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, object returned on line %d +object(Stringable)#%s (0) { +} +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, resource returned on line %d +resource(%d) of type (stream) + +Testing 'float' typehint: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d +string(1) "a" +*** Trying string(0) "" +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d +string(0) "" +*** Trying int(%d) +float(%s) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, null returned on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, array returned on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, object returned on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, object returned on line %d +object(Stringable)#%s (0) { +} +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, resource returned on line %d +resource(%d) of type (stream) + +Testing 'string' typehint: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(%d) +string(%d) "%d" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, null returned on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, array returned on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, object returned on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +string(6) "foobar" +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, resource returned on line %d +resource(%d) of type (stream) + +Testing 'bool' typehint: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(%d) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, null returned on line %d +NULL +*** Trying array(0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, array returned on line %d +array(0) { +} +*** Trying object(stdClass)#%s (0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, object returned on line %d +object(stdClass)#%s (0) { +} +*** Trying object(Stringable)#%s (0) { +} +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, object returned on line %d +object(Stringable)#%s (0) { +} +*** Trying resource(%d) of type (stream) +E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, resource returned on line %d +resource(%d) of type (stream) From d6bea5bb1e5f4811e45162343cb7e513d9fcbec5 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 10 Feb 2015 15:51:16 +0000 Subject: [PATCH 27/29] Fixed use after free on the following code sapi/cli/php -r 'function hello(string $world) : string { var_dump(bin2hex($world)); return $world; } echo "foo" . hello(6) . "\n";' --- Zend/zend_execute.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 0d4634f51ca00..584f2be5a6544 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -646,11 +646,10 @@ static zend_bool zend_verify_scalar_type_hint(zend_uchar type_hint, zval *arg, z case IS_STRING: { zend_string *dest; + /* on success "arg" is converted to IS_STRING */ if (!zend_parse_arg_str(arg, &dest, 0, strict)) { return 0; } - zval_ptr_dtor(arg); - ZVAL_STR(arg, dest); return 1; } default: From 10f03cd4146bdbe9f3f8e4ca2c07bcd3d0cc7e12 Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sat, 14 Feb 2015 02:32:50 +0000 Subject: [PATCH 28/29] Merge return_types_none_null_distinction Conflicts: Zend/zend_compile.c Zend/zend_execute.c --- NEWS | 13 +- UPGRADING | 21 +- Zend/tests/bug40509.phpt | 2 +- Zend/tests/bug40705.phpt | 2 +- Zend/tests/bug69017.phpt | 42 + Zend/tests/bug69025.phpt | 15 + Zend/tests/foreach_003.phpt | 71 + Zend/tests/foreach_004.phpt | 65 + Zend/tests/foreach_005.phpt | 22 + Zend/tests/foreach_006.phpt | 20 + Zend/tests/foreach_007.phpt | 13 + Zend/tests/foreach_008.phpt | 21 + Zend/tests/foreach_009.phpt | 40 + Zend/tests/foreach_010.phpt | 40 + Zend/tests/foreach_011.phpt | 19 + Zend/tests/foreach_012.phpt | 18 + Zend/tests/foreach_013.phpt | 17 + Zend/tests/foreach_014.phpt | 15 + Zend/tests/foreach_015.phpt | 18 + Zend/tests/foreach_016.phpt | 18 + Zend/tests/foreach_017.phpt | 111 + Zend/tests/return_types/001.phpt | 2 +- Zend/tests/return_types/null_and_none1.phpt | 12 + Zend/tests/return_types/null_and_none2.phpt | 12 + Zend/tests/return_types/null_and_none3.phpt | 12 + .../varSyntax/constClassMemberAccess.phpt | 27 + Zend/zend_API.c | 2 +- Zend/zend_API.h | 2 +- Zend/zend_compile.c | 156 +- Zend/zend_compile.h | 9 +- Zend/zend_execute.c | 16 +- Zend/zend_execute_API.c | 10 + Zend/zend_generators.c | 6 + Zend/zend_globals.h | 5 + Zend/zend_hash.c | 202 +- Zend/zend_hash.h | 24 +- Zend/zend_object_handlers.c | 2 + Zend/zend_opcode.c | 6 +- Zend/zend_string.h | 4 + Zend/zend_types.h | 20 +- Zend/zend_vm_def.h | 767 ++++-- Zend/zend_vm_execute.h | 1964 ++++++++------ Zend/zend_vm_opcodes.c | 10 +- Zend/zend_vm_opcodes.h | 7 +- ext/curl/interface.c | 89 +- ext/dom/php_dom.c | 17 +- ext/dom/xpath.c | 6 +- ext/fileinfo/libmagic.patch | 2 +- ext/fileinfo/libmagic/funcs.c | 2 +- ext/json/json_scanner.c | 921 ++++--- ext/json/json_scanner.re | 4 +- ext/json/php_json_scanner.h | 6 +- ext/json/php_json_scanner_defs.h | 2 +- ext/mssql/CREDITS | 2 - ext/mssql/config.m4 | 56 - ext/mssql/config.w32 | 28 - ext/mssql/mssql_win32_howto.txt | 35 - ext/mssql/php_mssql.c | 2283 ---------------- ext/mssql/php_mssql.h | 214 -- ext/mysqlnd/mysqlnd_plugin.c | 4 - ext/opcache/Optimizer/block_pass.c | 20 +- ext/opcache/Optimizer/nop_removal.c | 6 +- ext/opcache/Optimizer/optimize_temp_vars_5.c | 34 +- ext/opcache/Optimizer/pass1_5.c | 6 +- ext/opcache/Optimizer/pass2.c | 4 +- ext/opcache/Optimizer/pass3.c | 6 +- ext/opcache/Optimizer/zend_optimizer.c | 12 +- ext/opcache/zend_persist.c | 6 +- ext/pcre/php_pcre.c | 39 +- ext/pcre/php_pcre.h | 4 +- ext/pdo/pdo_sql_parser.c | 32 +- ext/pdo/pdo_sql_parser.re | 7 +- ext/reflection/php_reflection.c | 99 +- ...Parameter_DefaultValueConstant_basic1.phpt | 3 +- ext/session/mod_user_class.c | 6 +- ext/session/php_session.h | 6 +- ext/session/session.c | 8 +- .../session_set_save_handler_variation5.phpt | 2 +- ext/soap/php_schema.c | 2 +- ext/sockets/conversions.c | 13 +- ext/spl/spl_iterators.c | 54 +- ext/standard/array.c | 203 +- ext/standard/file.c | 7 +- ext/standard/info.c | 29 +- ext/standard/string.c | 95 +- ext/standard/tests/network/bug68925.phpt | 4 +- ext/sybase_ct/CREDITS | 2 - ext/sybase_ct/config.m4 | 120 - ext/sybase_ct/config.w32 | 21 - ext/sybase_ct/php_sybase_ct.c | 2242 ---------------- ext/sybase_ct/php_sybase_ct.h | 131 - ext/sybase_ct/tests/bug22403.phpt | 88 - ext/sybase_ct/tests/bug26407.phpt | 91 - ext/sybase_ct/tests/bug27843.phpt | 54 - ext/sybase_ct/tests/bug28354.phpt | 46 - ext/sybase_ct/tests/bug29064.phpt | 143 - ext/sybase_ct/tests/bug30312-withfree.phpt | 34 - ext/sybase_ct/tests/bug30312.phpt | 27 - ext/sybase_ct/tests/bug43578.phpt | 65 - ext/sybase_ct/tests/bug6339.phpt | 24 - ext/sybase_ct/tests/skipif.inc | 13 - ext/sybase_ct/tests/test.inc | 86 - ext/sybase_ct/tests/test_appname.phpt | 55 - ext/sybase_ct/tests/test_close.phpt | 25 - ext/sybase_ct/tests/test_close_default.phpt | 21 - ext/sybase_ct/tests/test_close_notopen.phpt | 18 - ext/sybase_ct/tests/test_connect.phpt | 19 - .../tests/test_connection_caching.phpt | 26 - .../test_connectionbased_msghandler.phpt | 27 - ext/sybase_ct/tests/test_fetch_object.phpt | 74 - ext/sybase_ct/tests/test_fields.phpt | 76 - ext/sybase_ct/tests/test_long.phpt | 80 - ext/sybase_ct/tests/test_msghandler.phpt | 43 - .../tests/test_msghandler_handled.phpt | 69 - ext/sybase_ct/tests/test_query_nostore.phpt | 98 - ext/sybase_ct/tests/test_types.phpt | 87 - .../tests/test_unbuffered_no_full_fetch.phpt | 44 - .../tests/test_unbuffered_query.phpt | 57 - ext/tidy/tidy.c | 2 +- main/output.c | 8 +- main/php_ini.c | 9 +- main/streams/streams.c | 25 +- pear/install-pear-nozlib.phar | 705 +++-- php.ini-development | 92 - php.ini-production | 92 - sapi/aolserver/CREDITS | 2 - sapi/aolserver/README | 69 - sapi/aolserver/aolserver.c | 624 ----- sapi/aolserver/config.m4 | 31 - sapi/aolserver/config.w32 | 16 - sapi/aolserver/php.sym | 2 - sapi/apache/CREDITS | 3 - sapi/apache/apMakefile.libdir | 4 - sapi/apache/apMakefile.tmpl | 77 - sapi/apache/config.m4 | 273 -- sapi/apache/config.w32 | 24 - sapi/apache/libphp7.module.in | 11 - sapi/apache/libpre.c | 55 - sapi/apache/mod_php7.c | 1045 -------- sapi/apache/mod_php7.exp | 1 - sapi/apache/mod_php7.h | 60 - sapi/apache/php.sym | 1 - sapi/apache/php_apache.c | 607 ----- sapi/apache/php_apache_http.h | 70 - sapi/apache/sapi_apache.c | 73 - sapi/apache2filter/CREDITS | 2 - sapi/apache2filter/EXPERIMENTAL | 5 - sapi/apache2filter/README | 71 - sapi/apache2filter/apache_config.c | 217 -- sapi/apache2filter/config.m4 | 139 - sapi/apache2filter/config.w32 | 39 - sapi/apache2filter/php.sym | 1 - sapi/apache2filter/php_apache.h | 77 - sapi/apache2filter/php_functions.c | 425 --- sapi/apache2filter/sapi_apache2.c | 756 ------ sapi/apache2handler/apache_config.c | 21 - sapi/apache2handler/sapi_apache2.c | 7 +- sapi/apache_hooks/CREDITS | 2 - sapi/apache_hooks/README | 206 -- sapi/apache_hooks/apMakefile.libdir | 4 - sapi/apache_hooks/apMakefile.tmpl | 77 - sapi/apache_hooks/config.m4 | 275 -- sapi/apache_hooks/config.w32 | 21 - sapi/apache_hooks/libphp7.module.in | 11 - sapi/apache_hooks/mod_php7.c | 1478 ---------- sapi/apache_hooks/mod_php7.exp | 1 - sapi/apache_hooks/mod_php7.h | 88 - sapi/apache_hooks/php.sym | 1 - sapi/apache_hooks/php_apache.c | 1970 -------------- sapi/apache_hooks/php_apache_http.h | 44 - sapi/apache_hooks/sapi_apache.c | 131 - sapi/caudium/CREDITS | 2 - sapi/caudium/README | 16 - sapi/caudium/TODO | 30 - sapi/caudium/caudium.c | 782 ------ sapi/caudium/config.m4 | 98 - sapi/cgi/cgi_main.c | 3 - sapi/continuity/CREDITS | 2 - sapi/continuity/capi.c | 507 ---- sapi/continuity/config.m4 | 28 - sapi/isapi/CREDITS | 2 - sapi/isapi/config.m4 | 24 - sapi/isapi/config.w32 | 13 - sapi/isapi/php.sym | 5 - sapi/isapi/php7isapi.c | 971 ------- sapi/isapi/php7isapi.def | 5 - sapi/isapi/stresstest/getopt.c | 175 -- sapi/isapi/stresstest/getopt.h | 12 - sapi/isapi/stresstest/notes.txt | 56 - sapi/isapi/stresstest/stresstest.cpp | 936 ------- sapi/milter/CREDITS | 2 - sapi/milter/EXPERIMENTAL | 5 - sapi/milter/Makefile.frag | 8 - sapi/milter/TODO | 5 - sapi/milter/config.m4 | 31 - sapi/milter/getopt.c | 173 -- sapi/milter/milter.php | 132 - sapi/milter/php_getopt.h | 7 - sapi/milter/php_milter.c | 1196 --------- sapi/milter/php_milter.h | 31 - sapi/phpdbg/phpdbg.c | 3 + sapi/phttpd/CREDITS | 2 - sapi/phttpd/README | 5 - sapi/phttpd/config.m4 | 21 - sapi/phttpd/php.sym | 4 - sapi/phttpd/php_phttpd.h | 24 - sapi/phttpd/phttpd.c | 300 --- sapi/pi3web/CREDITS | 2 - sapi/pi3web/README | 50 - sapi/pi3web/config.m4 | 27 - sapi/pi3web/config.w32 | 16 - sapi/pi3web/php.sym | 0 sapi/pi3web/pi3web_sapi.c | 438 --- sapi/pi3web/pi3web_sapi.h | 102 - sapi/roxen/README | 18 - sapi/roxen/TODO | 33 - sapi/roxen/config.m4 | 55 - sapi/roxen/roxen.c | 725 ----- sapi/thttpd/CREDITS | 2 - sapi/thttpd/README | 85 - sapi/thttpd/config.m4 | 39 - sapi/thttpd/php.sym | 3 - sapi/thttpd/php_thttpd.h | 35 - sapi/thttpd/stub.c | 0 sapi/thttpd/thttpd.c | 766 ------ sapi/thttpd/thttpd_patch | 2377 ----------------- sapi/tux/CREDITS | 2 - sapi/tux/README | 86 - sapi/tux/config.m4 | 16 - sapi/tux/php.sym | 2 - sapi/tux/php_tux.c | 449 ---- sapi/webjames/CREDITS | 2 - sapi/webjames/README | 28 - sapi/webjames/config.m4 | 21 - sapi/webjames/php_webjames.h | 28 - sapi/webjames/webjames.c | 327 --- tests/lang/bug23624.phpt | 2 +- tests/lang/foreachLoop.001.phpt | 4 +- tests/lang/foreachLoop.009.phpt | 6 +- tests/lang/foreachLoop.011.phpt | 7 +- tests/lang/foreachLoop.013.phpt | 118 +- tests/lang/foreachLoop.014.phpt | 139 +- tests/lang/foreachLoop.015.phpt | 118 +- tests/lang/foreachLoopObjects.006.phpt | 32 +- travis/compile.sh | 3 +- win32/registry.c | 12 +- win32/sendmail.c | 15 +- 247 files changed, 4142 insertions(+), 29978 deletions(-) create mode 100644 Zend/tests/bug69017.phpt create mode 100644 Zend/tests/bug69025.phpt create mode 100644 Zend/tests/foreach_003.phpt create mode 100644 Zend/tests/foreach_004.phpt create mode 100644 Zend/tests/foreach_005.phpt create mode 100644 Zend/tests/foreach_006.phpt create mode 100644 Zend/tests/foreach_007.phpt create mode 100644 Zend/tests/foreach_008.phpt create mode 100644 Zend/tests/foreach_009.phpt create mode 100644 Zend/tests/foreach_010.phpt create mode 100644 Zend/tests/foreach_011.phpt create mode 100644 Zend/tests/foreach_012.phpt create mode 100644 Zend/tests/foreach_013.phpt create mode 100644 Zend/tests/foreach_014.phpt create mode 100644 Zend/tests/foreach_015.phpt create mode 100644 Zend/tests/foreach_016.phpt create mode 100644 Zend/tests/foreach_017.phpt create mode 100644 Zend/tests/return_types/null_and_none1.phpt create mode 100644 Zend/tests/return_types/null_and_none2.phpt create mode 100644 Zend/tests/return_types/null_and_none3.phpt create mode 100644 Zend/tests/varSyntax/constClassMemberAccess.phpt delete mode 100644 ext/mssql/CREDITS delete mode 100644 ext/mssql/config.m4 delete mode 100644 ext/mssql/config.w32 delete mode 100644 ext/mssql/mssql_win32_howto.txt delete mode 100644 ext/mssql/php_mssql.c delete mode 100644 ext/mssql/php_mssql.h delete mode 100644 ext/sybase_ct/CREDITS delete mode 100644 ext/sybase_ct/config.m4 delete mode 100644 ext/sybase_ct/config.w32 delete mode 100644 ext/sybase_ct/php_sybase_ct.c delete mode 100644 ext/sybase_ct/php_sybase_ct.h delete mode 100644 ext/sybase_ct/tests/bug22403.phpt delete mode 100644 ext/sybase_ct/tests/bug26407.phpt delete mode 100644 ext/sybase_ct/tests/bug27843.phpt delete mode 100644 ext/sybase_ct/tests/bug28354.phpt delete mode 100644 ext/sybase_ct/tests/bug29064.phpt delete mode 100644 ext/sybase_ct/tests/bug30312-withfree.phpt delete mode 100644 ext/sybase_ct/tests/bug30312.phpt delete mode 100644 ext/sybase_ct/tests/bug43578.phpt delete mode 100644 ext/sybase_ct/tests/bug6339.phpt delete mode 100644 ext/sybase_ct/tests/skipif.inc delete mode 100644 ext/sybase_ct/tests/test.inc delete mode 100644 ext/sybase_ct/tests/test_appname.phpt delete mode 100644 ext/sybase_ct/tests/test_close.phpt delete mode 100644 ext/sybase_ct/tests/test_close_default.phpt delete mode 100644 ext/sybase_ct/tests/test_close_notopen.phpt delete mode 100644 ext/sybase_ct/tests/test_connect.phpt delete mode 100644 ext/sybase_ct/tests/test_connection_caching.phpt delete mode 100644 ext/sybase_ct/tests/test_connectionbased_msghandler.phpt delete mode 100644 ext/sybase_ct/tests/test_fetch_object.phpt delete mode 100644 ext/sybase_ct/tests/test_fields.phpt delete mode 100644 ext/sybase_ct/tests/test_long.phpt delete mode 100644 ext/sybase_ct/tests/test_msghandler.phpt delete mode 100644 ext/sybase_ct/tests/test_msghandler_handled.phpt delete mode 100644 ext/sybase_ct/tests/test_query_nostore.phpt delete mode 100644 ext/sybase_ct/tests/test_types.phpt delete mode 100644 ext/sybase_ct/tests/test_unbuffered_no_full_fetch.phpt delete mode 100644 ext/sybase_ct/tests/test_unbuffered_query.phpt delete mode 100644 sapi/aolserver/CREDITS delete mode 100644 sapi/aolserver/README delete mode 100644 sapi/aolserver/aolserver.c delete mode 100644 sapi/aolserver/config.m4 delete mode 100644 sapi/aolserver/config.w32 delete mode 100644 sapi/aolserver/php.sym delete mode 100644 sapi/apache/CREDITS delete mode 100644 sapi/apache/apMakefile.libdir delete mode 100644 sapi/apache/apMakefile.tmpl delete mode 100644 sapi/apache/config.m4 delete mode 100644 sapi/apache/config.w32 delete mode 100644 sapi/apache/libphp7.module.in delete mode 100644 sapi/apache/libpre.c delete mode 100644 sapi/apache/mod_php7.c delete mode 100644 sapi/apache/mod_php7.exp delete mode 100644 sapi/apache/mod_php7.h delete mode 100644 sapi/apache/php.sym delete mode 100644 sapi/apache/php_apache.c delete mode 100644 sapi/apache/php_apache_http.h delete mode 100644 sapi/apache/sapi_apache.c delete mode 100644 sapi/apache2filter/CREDITS delete mode 100644 sapi/apache2filter/EXPERIMENTAL delete mode 100644 sapi/apache2filter/README delete mode 100644 sapi/apache2filter/apache_config.c delete mode 100644 sapi/apache2filter/config.m4 delete mode 100755 sapi/apache2filter/config.w32 delete mode 100644 sapi/apache2filter/php.sym delete mode 100644 sapi/apache2filter/php_apache.h delete mode 100644 sapi/apache2filter/php_functions.c delete mode 100644 sapi/apache2filter/sapi_apache2.c delete mode 100644 sapi/apache_hooks/CREDITS delete mode 100644 sapi/apache_hooks/README delete mode 100644 sapi/apache_hooks/apMakefile.libdir delete mode 100644 sapi/apache_hooks/apMakefile.tmpl delete mode 100644 sapi/apache_hooks/config.m4 delete mode 100644 sapi/apache_hooks/config.w32 delete mode 100644 sapi/apache_hooks/libphp7.module.in delete mode 100644 sapi/apache_hooks/mod_php7.c delete mode 100644 sapi/apache_hooks/mod_php7.exp delete mode 100644 sapi/apache_hooks/mod_php7.h delete mode 100644 sapi/apache_hooks/php.sym delete mode 100644 sapi/apache_hooks/php_apache.c delete mode 100644 sapi/apache_hooks/php_apache_http.h delete mode 100644 sapi/apache_hooks/sapi_apache.c delete mode 100644 sapi/caudium/CREDITS delete mode 100644 sapi/caudium/README delete mode 100644 sapi/caudium/TODO delete mode 100644 sapi/caudium/caudium.c delete mode 100644 sapi/caudium/config.m4 delete mode 100644 sapi/continuity/CREDITS delete mode 100644 sapi/continuity/capi.c delete mode 100644 sapi/continuity/config.m4 delete mode 100644 sapi/isapi/CREDITS delete mode 100644 sapi/isapi/config.m4 delete mode 100644 sapi/isapi/config.w32 delete mode 100644 sapi/isapi/php.sym delete mode 100644 sapi/isapi/php7isapi.c delete mode 100644 sapi/isapi/php7isapi.def delete mode 100644 sapi/isapi/stresstest/getopt.c delete mode 100644 sapi/isapi/stresstest/getopt.h delete mode 100644 sapi/isapi/stresstest/notes.txt delete mode 100644 sapi/isapi/stresstest/stresstest.cpp delete mode 100644 sapi/milter/CREDITS delete mode 100644 sapi/milter/EXPERIMENTAL delete mode 100644 sapi/milter/Makefile.frag delete mode 100644 sapi/milter/TODO delete mode 100644 sapi/milter/config.m4 delete mode 100644 sapi/milter/getopt.c delete mode 100644 sapi/milter/milter.php delete mode 100644 sapi/milter/php_getopt.h delete mode 100644 sapi/milter/php_milter.c delete mode 100644 sapi/milter/php_milter.h delete mode 100644 sapi/phttpd/CREDITS delete mode 100644 sapi/phttpd/README delete mode 100644 sapi/phttpd/config.m4 delete mode 100644 sapi/phttpd/php.sym delete mode 100644 sapi/phttpd/php_phttpd.h delete mode 100644 sapi/phttpd/phttpd.c delete mode 100644 sapi/pi3web/CREDITS delete mode 100644 sapi/pi3web/README delete mode 100644 sapi/pi3web/config.m4 delete mode 100644 sapi/pi3web/config.w32 delete mode 100644 sapi/pi3web/php.sym delete mode 100644 sapi/pi3web/pi3web_sapi.c delete mode 100644 sapi/pi3web/pi3web_sapi.h delete mode 100644 sapi/roxen/README delete mode 100644 sapi/roxen/TODO delete mode 100644 sapi/roxen/config.m4 delete mode 100644 sapi/roxen/roxen.c delete mode 100644 sapi/thttpd/CREDITS delete mode 100644 sapi/thttpd/README delete mode 100644 sapi/thttpd/config.m4 delete mode 100644 sapi/thttpd/php.sym delete mode 100644 sapi/thttpd/php_thttpd.h delete mode 100644 sapi/thttpd/stub.c delete mode 100644 sapi/thttpd/thttpd.c delete mode 100644 sapi/thttpd/thttpd_patch delete mode 100644 sapi/tux/CREDITS delete mode 100644 sapi/tux/README delete mode 100644 sapi/tux/config.m4 delete mode 100644 sapi/tux/php.sym delete mode 100644 sapi/tux/php_tux.c delete mode 100644 sapi/webjames/CREDITS delete mode 100644 sapi/webjames/README delete mode 100644 sapi/webjames/config.m4 delete mode 100644 sapi/webjames/php_webjames.h delete mode 100644 sapi/webjames/webjames.c diff --git a/NEWS b/NEWS index dcfe1a5ff7cc2..ec5979199475f 100644 --- a/NEWS +++ b/NEWS @@ -8,9 +8,9 @@ . Update the MIME type list from the one shipped by Apache HTTPD. (Adam) - Core: - . Fixed #68933 (Invalid read of size 8 in zend_std_read_property). + . Fixed bug #68933 (Invalid read of size 8 in zend_std_read_property). (Laruence, arjen at react dot com) - . Fixed #68868 (Segfault in clean_non_persistent_constants() in SugarCRM + . Fixed bug #68868 (Segfault in clean_non_persistent_constants() in SugarCRM 6.5.20). (Laruence) . Fixed bug #68104 (Segfault while pre-evaluating a disabled function). (Laruence) @@ -19,7 +19,7 @@ . Added PHP_INT_MIN constant. (Andrea) . Added Closure::call() method. (Andrea) . Implemented FR #38409 (parse_ini_file() looses the type of booleans). (Tjerk) - . Fixed #67959 (Segfault when calling phpversion('spl')). (Florian) + . Fixed bug #67959 (Segfault when calling phpversion('spl')). (Florian) . Implemented the RFC `Catchable "Call to a member function bar() on a non-object"`. (Timm) . Added options parameter for unserialize allowing to specify acceptable @@ -45,6 +45,7 @@ . Invalid octal literals in source code now produce compile errors, fixes PHPSadness #31. (Andrea) . Removed dl() function on fpm-fcgi. (Nikita) . Removed support for hexadecimal numeric strings. (Nikita) + . Removed obsolete extensions and SAPIs. See the full list in UPGRADING. (Anatol) - Curl: . Fixed bug #68937 (Segfault in curl_multi_exec). (Laruence) @@ -94,7 +95,7 @@ + Opcache). (Laruence) - OpenSSL: - . Fix bug #61285, #68329, #68046, #41631: encrypted streams don't observe + . Fixed bug #61285, #68329, #68046, #41631: encrypted streams don't observe socket timeouts (Brad Broerman) - pcntl: @@ -131,12 +132,12 @@ . Fixed bug #68479 (Added escape parameter to SplFileObject::fputcsv). (Salathe) - Sqlite3: - . Fix bug #68260 (SQLite3Result::fetchArray declares wrong + . Fixed bug #68260 (SQLite3Result::fetchArray declares wrong required_num_args). (Julien) - Standard: . Removed call_user_method() and call_user_method_array() functions. (Kalle) - . Fix user session handlers (See rfc:session.user.return-value). (Sara) + . Fixed user session handlers (See rfc:session.user.return-value). (Sara) . Added intdiv() function. (Andrea) . Improved precision of log() function for base 2 and 10. (Marc Bennewitz) . Remove string category support in setlocale(). (Nikita) diff --git a/UPGRADING b/UPGRADING index 0ea6a090002f6..f992e1bfa478b 100644 --- a/UPGRADING +++ b/UPGRADING @@ -9,7 +9,7 @@ PHP X.Y UPGRADE NOTES 5. Changed Functions 6. New Functions 7. New Classes and Interfaces -8. Removed Extensions +8. Removed Extensions and SAPIs 9. Other Changes to Extensions 10. New Global Constants 11. Changes to INI File Handling @@ -170,9 +170,26 @@ PHP X.Y UPGRADE NOTES ======================================== -8. Removed Extensions +8. Removed Extensions and SAPIs ======================================== +- sapi/aolserver +- sapi/apache +- sapi/apache_hooks +- sapi/apache2filter +- sapi/caudium +- sapi/continuity +- sapi/isapi +- sapi/milter +- sapi/phttpd +- sapi/pi3web +- sapi/roxen +- sapi/thttpd +- sapi/tux +- sapi/webjames +- ext/mssql +- ext/sybase_ct +For more details see https://wiki.php.net/rfc/removal_of_dead_sapis_and_exts ======================================== 9. Other Changes to Extensions diff --git a/Zend/tests/bug40509.phpt b/Zend/tests/bug40509.phpt index 21eaae94448c8..65e32533ef111 100644 --- a/Zend/tests/bug40509.phpt +++ b/Zend/tests/bug40509.phpt @@ -23,4 +23,4 @@ var_dump(key($arr["v"])); int(0) int(0) int(0) -NULL +int(0) diff --git a/Zend/tests/bug40705.phpt b/Zend/tests/bug40705.phpt index 374f73b75eb63..8a679654d5413 100644 --- a/Zend/tests/bug40705.phpt +++ b/Zend/tests/bug40705.phpt @@ -23,4 +23,4 @@ int(0) int(0) int(1) int(2) -NULL +int(0) diff --git a/Zend/tests/bug69017.phpt b/Zend/tests/bug69017.phpt new file mode 100644 index 0000000000000..762fcbc9a0714 --- /dev/null +++ b/Zend/tests/bug69017.phpt @@ -0,0 +1,42 @@ +--TEST-- +#69017 (Fail to push to the empty array with the constant value defined in class scope) +--FILE-- + 'one'); + public static $a2 = array(self::ZERO => 'zero'); + public static $a3 = array(self::MAX => 'zero'); +} + + +c1::$a1[] = 1; +c1::$a2[] = 1; +c1::$a3[] = 1; + +var_dump(c1::$a1); +var_dump(c1::$a2); +var_dump(c1::$a3); +?> +--EXPECTF-- +Warning: Cannot add element to the array as the next element is already occupied in %sbug69017.php on line %d +array(2) { + [1]=> + string(3) "one" + [2]=> + int(1) +} +array(2) { + [0]=> + string(4) "zero" + [1]=> + int(1) +} +array(1) { + [%d]=> + string(4) "zero" +} diff --git a/Zend/tests/bug69025.phpt b/Zend/tests/bug69025.phpt new file mode 100644 index 0000000000000..389c09f75fb90 --- /dev/null +++ b/Zend/tests/bug69025.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #69025 (Invalid read of size 4 when calling __callStatic) +--FILE-- + +OK +--EXPECT-- +OK diff --git a/Zend/tests/foreach_003.phpt b/Zend/tests/foreach_003.phpt new file mode 100644 index 0000000000000..71b0f2a5a3ab4 --- /dev/null +++ b/Zend/tests/foreach_003.phpt @@ -0,0 +1,71 @@ +--TEST-- +Iterator exceptions in foreach by value +--FILE-- +count = $count; + $this->trap = $trap; + } + + function trap($trap) { + if ($trap === $this->trap) { + throw new Exception($trap); + } + } + + function rewind() {$this->trap(__FUNCTION__); $this->n = 0;} + function valid() {$this->trap(__FUNCTION__); return $this->n < $this->count;} + function key() {$this->trap(__FUNCTION__); return $this->n;} + function current() {$this->trap(__FUNCTION__); return $this->n;} + function next() {$this->trap(__FUNCTION__); $this->n++;} +} + +foreach(['rewind', 'valid', 'key', 'current', 'next'] as $trap) { + $obj = new IT(3, $trap); + try { + // IS_CV + foreach ($obj as $key => $val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + unset($obj); + + try { + // IS_VAR + foreach (new IT(3, $trap) as $key => $val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + + try { + // IS_TMP_VAR + foreach ((object)new IT(2, $trap) as $key => $val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +rewind +rewind +rewind +valid +valid +valid +key +key +key +current +current +current +0 +next +0 +next +0 +next diff --git a/Zend/tests/foreach_004.phpt b/Zend/tests/foreach_004.phpt new file mode 100644 index 0000000000000..1f754a77edd38 --- /dev/null +++ b/Zend/tests/foreach_004.phpt @@ -0,0 +1,65 @@ +--TEST-- +Iterator exceptions in foreach by reference +--FILE-- +trap = $trap; + } + + function trap($trap) { + if ($trap === $this->trap) { + throw new Exception($trap); + } + } + + function rewind() {$this->trap(__FUNCTION__); return parent::rewind();} + function valid() {$this->trap(__FUNCTION__); return parent::valid();} + function key() {$this->trap(__FUNCTION__); return parent::key();} + function next() {$this->trap(__FUNCTION__); return parent::next();} +} + +foreach(['rewind', 'valid', 'key', 'next'] as $trap) { + $obj = new IT($trap); + try { + // IS_CV + foreach ($obj as $key => &$val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + unset($obj); + + try { + // IS_VAR + foreach (new IT($trap) as $key => &$val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + + try { + // IS_TMP_VAR + foreach ((object)new IT($trap) as $key => &$val) echo "$val\n"; + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECT-- +rewind +rewind +rewind +valid +valid +valid +key +key +key +0 +next +0 +next +0 +next diff --git a/Zend/tests/foreach_005.phpt b/Zend/tests/foreach_005.phpt new file mode 100644 index 0000000000000..6ed9fe940bf2f --- /dev/null +++ b/Zend/tests/foreach_005.phpt @@ -0,0 +1,22 @@ +--TEST-- +Nested foreach by reference on the same array +--FILE-- + +--EXPECT-- +1-1 +2-2 +2-3 +3-2 +3-3 +4-4 +5-3 +5-4 +5-5 diff --git a/Zend/tests/foreach_006.phpt b/Zend/tests/foreach_006.phpt new file mode 100644 index 0000000000000..65d6fdc52cc8b --- /dev/null +++ b/Zend/tests/foreach_006.phpt @@ -0,0 +1,20 @@ +--TEST-- +Foreach by reference on constant +--FILE-- + +--EXPECT-- +1 +2 +3 +1 +2 +3 +1 +2 +3 diff --git a/Zend/tests/foreach_007.phpt b/Zend/tests/foreach_007.phpt new file mode 100644 index 0000000000000..b99bc73ebe448 --- /dev/null +++ b/Zend/tests/foreach_007.phpt @@ -0,0 +1,13 @@ +--TEST-- +Foreach by reference and inserting new element when we are already at the end +--FILE-- + +--EXPECT-- +1 +2 diff --git a/Zend/tests/foreach_008.phpt b/Zend/tests/foreach_008.phpt new file mode 100644 index 0000000000000..c68bcd89da76f --- /dev/null +++ b/Zend/tests/foreach_008.phpt @@ -0,0 +1,21 @@ +--TEST-- +Nested foreach by reference and array modification +--FILE-- + +--EXPECT-- +0 - 0 +0 - 1 +0 - 3 +3 - 0 +3 - 3 diff --git a/Zend/tests/foreach_009.phpt b/Zend/tests/foreach_009.phpt new file mode 100644 index 0000000000000..6ce8384642501 --- /dev/null +++ b/Zend/tests/foreach_009.phpt @@ -0,0 +1,40 @@ +--TEST-- +Nested foreach by reference and array modification with resize +--FILE-- + +--EXPECT-- +4-4 +4-5 +4-6 +4-7 +5-4 +5-5 +5-6 +5-7 +5-8 +6-4 +6-5 +6-6 +6-7 +6-8 +7-4 +7-5 +7-6 +7-7 +7-8 +8-4 +8-5 +8-6 +8-7 +8-8 diff --git a/Zend/tests/foreach_010.phpt b/Zend/tests/foreach_010.phpt new file mode 100644 index 0000000000000..6ba7e7e9fd761 --- /dev/null +++ b/Zend/tests/foreach_010.phpt @@ -0,0 +1,40 @@ +--TEST-- +Nested foreach by value over object and object modification with resize +--FILE-- +0, 'b'=>1, 'c'=>2, 'd'=>3, 'e'=>4, 'f'=>5, 'g'=>6, 'h'=>7]; +unset($o->a, $o->b, $o->c, $o->d); +foreach ($o as $v1) { + foreach ($o as $v2) { + echo "$v1-$v2\n"; + if ($v1 == 5 && $v2 == 6) { + $o->i = 8; + } + } +} +?> +--EXPECT-- +4-4 +4-5 +4-6 +4-7 +5-4 +5-5 +5-6 +5-7 +5-8 +6-4 +6-5 +6-6 +6-7 +6-8 +7-4 +7-5 +7-6 +7-7 +7-8 +8-4 +8-5 +8-6 +8-7 +8-8 diff --git a/Zend/tests/foreach_011.phpt b/Zend/tests/foreach_011.phpt new file mode 100644 index 0000000000000..e91426fb27df1 --- /dev/null +++ b/Zend/tests/foreach_011.phpt @@ -0,0 +1,19 @@ +--TEST-- +sort() functions precerve foreach by reference iterator pointer +--FILE-- + +--EXPECT-- +1 +2 +3 +2 +1 +0 diff --git a/Zend/tests/foreach_012.phpt b/Zend/tests/foreach_012.phpt new file mode 100644 index 0000000000000..5e5538cd4d307 --- /dev/null +++ b/Zend/tests/foreach_012.phpt @@ -0,0 +1,18 @@ +--TEST-- +array_walk() function precerve foreach by reference iterator pointer +--FILE-- + +--EXPECT-- +1 +2 +3 +14 +15 \ No newline at end of file diff --git a/Zend/tests/foreach_013.phpt b/Zend/tests/foreach_013.phpt new file mode 100644 index 0000000000000..cfbb3d7f7915f --- /dev/null +++ b/Zend/tests/foreach_013.phpt @@ -0,0 +1,17 @@ +--TEST-- +array_push() function precerve foreach by reference iterator pointer +--FILE-- + +--EXPECT-- +1 +2 +3 +4 diff --git a/Zend/tests/foreach_014.phpt b/Zend/tests/foreach_014.phpt new file mode 100644 index 0000000000000..8d0ac582a9ec5 --- /dev/null +++ b/Zend/tests/foreach_014.phpt @@ -0,0 +1,15 @@ +--TEST-- +array_pop() function precerve foreach by reference iterator pointer +--FILE-- + +--EXPECT-- +1 +2 diff --git a/Zend/tests/foreach_015.phpt b/Zend/tests/foreach_015.phpt new file mode 100644 index 0000000000000..adc8085f3482d --- /dev/null +++ b/Zend/tests/foreach_015.phpt @@ -0,0 +1,18 @@ +--TEST-- +array_shift() function precerve foreach by reference iterator pointer +--FILE-- + +--EXPECT-- +1 +2 +3 +4 +array(0) { +} \ No newline at end of file diff --git a/Zend/tests/foreach_016.phpt b/Zend/tests/foreach_016.phpt new file mode 100644 index 0000000000000..423c8dd0a6247 --- /dev/null +++ b/Zend/tests/foreach_016.phpt @@ -0,0 +1,18 @@ +--TEST-- +array_unshift() function precerve foreach by reference iterator pointer +--FILE-- + +--EXPECT-- +1 +2 +3 +int(11) diff --git a/Zend/tests/foreach_017.phpt b/Zend/tests/foreach_017.phpt new file mode 100644 index 0000000000000..55eeeb0891b64 --- /dev/null +++ b/Zend/tests/foreach_017.phpt @@ -0,0 +1,111 @@ +--TEST-- +array_splice() function precerve foreach by reference iterator pointer +--FILE-- + +--EXPECT-- +0 +1 +2 +3 +4 + +0 +1 +4 + +0 +1 +2 +4 + +0 +1 +2 +3 +4 + +0 +1 +x +y +z +4 + +0 +1 +2 +4 diff --git a/Zend/tests/return_types/001.phpt b/Zend/tests/return_types/001.phpt index a751bd3f2feed..5204863b02f17 100644 --- a/Zend/tests/return_types/001.phpt +++ b/Zend/tests/return_types/001.phpt @@ -9,4 +9,4 @@ function test1() : array { test1(); --EXPECTF-- -Catchable fatal error: Return value of test1() must be of the type array, none returned in %s on line %d +Catchable fatal error: Return value of test1() must be of the type array, no value returned in %s on line %d diff --git a/Zend/tests/return_types/null_and_none1.phpt b/Zend/tests/return_types/null_and_none1.phpt new file mode 100644 index 0000000000000..60f434c5610be --- /dev/null +++ b/Zend/tests/return_types/null_and_none1.phpt @@ -0,0 +1,12 @@ +--TEST-- +Return types none/null distinction: Empty function +--FILE-- + ['b' => 'c']]; +} + +var_dump(A::A); +var_dump(A::A['a']); +var_dump(A::A['a']['b']); + +?> +--EXPECT-- +array(1) { + ["a"]=> + array(1) { + ["b"]=> + string(1) "c" + } +} +array(1) { + ["b"]=> + string(1) "c" +} +string(1) "c" \ No newline at end of file diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 22fb42d09984e..758e8808ad741 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -911,7 +911,7 @@ ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this /* }}} */ /* Argument parsing API -- andrei */ -ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC) /* {{{ */ +ZEND_API int _array_init(zval *arg, uint32_t size ZEND_FILE_LINE_DC) /* {{{ */ { ZVAL_NEW_ARR(arg); _zend_hash_init(Z_ARRVAL_P(arg), size, ZVAL_PTR_DTOR, 0 ZEND_FILE_LINE_RELAY_CC); diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 4f12834bcfaa9..caeb96df0dffa 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -372,7 +372,7 @@ ZEND_API char *zend_get_type_by_const(int type); #define object_init(arg) _object_init((arg) ZEND_FILE_LINE_CC) #define object_init_ex(arg, ce) _object_init_ex((arg), (ce) ZEND_FILE_LINE_CC) #define object_and_properties_init(arg, ce, properties) _object_and_properties_init((arg), (ce), (properties) ZEND_FILE_LINE_CC) -ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC); +ZEND_API int _array_init(zval *arg, uint32_t size ZEND_FILE_LINE_DC); ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC); ZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC); ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties ZEND_FILE_LINE_DC); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ec41f64900847..832b7f4796535 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -895,7 +895,7 @@ static int generate_free_loop_var(znode *var) /* {{{ */ { zend_op *opline = get_next_op(CG(active_op_array)); - opline->opcode = ZEND_FREE; + opline->opcode = var->flag ? ZEND_FE_FREE : ZEND_FREE; SET_NODE(opline->op1, var); SET_UNUSED(opline->op2); } @@ -1235,13 +1235,14 @@ static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool i { zend_constant *c; - if (!(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) { - /* Substitute case-sensitive (or lowercase) persistent constants */ - c = zend_hash_find_ptr(EG(zend_constants), name); - if (c && (c->flags & CONST_PERSISTENT)) { - ZVAL_DUP(zv, &c->value); - return 1; - } + /* Substitute case-sensitive (or lowercase) constants */ + c = zend_hash_find_ptr(EG(zend_constants), name); + if (c && ( + ((c->flags & CONST_PERSISTENT) && !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION)) + || (Z_TYPE(c->value) < IS_OBJECT && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) + )) { + ZVAL_DUP(zv, &c->value); + return 1; } { @@ -1264,6 +1265,37 @@ static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool i } /* }}} */ +static zend_bool zend_try_ct_eval_class_const(zval *zv, zend_string *class_name, zend_string *name) /* {{{ */ +{ + uint32_t fetch_type = zend_get_class_fetch_type(class_name); + zval *c; + + if (CG(active_class_entry) && (fetch_type == ZEND_FETCH_CLASS_SELF || (fetch_type == ZEND_FETCH_CLASS_DEFAULT && zend_string_equals_ci(class_name, CG(active_class_entry)->name)))) { + c = zend_hash_find(&CG(active_class_entry)->constants_table, name); + } else if (fetch_type == ZEND_FETCH_CLASS_DEFAULT && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) { + zend_class_entry *ce = zend_hash_find_ptr_lc(CG(class_table), class_name->val, class_name->len); + if (ce) { + c = zend_hash_find(&ce->constants_table, name); + } else { + return 0; + } + } else { + return 0; + } + + if (CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION) { + return 0; + } + + /* Substitute case-sensitive (or lowercase) persistent class constants */ + if (c && Z_TYPE_P(c) < IS_OBJECT) { + ZVAL_DUP(zv, c); + return 1; + } + + return 0; +} + void zend_init_list(void *result, void *item) /* {{{ */ { void** list = emalloc(sizeof(void*) * 2); @@ -1695,13 +1727,6 @@ ZEND_API size_t zend_dirname(char *path, size_t len) } /* }}} */ -static inline zend_bool zend_string_equals_str_ci(zend_string *str1, zend_string *str2) /* {{{ */ -{ - return str1->len == str2->len - && !zend_binary_strcasecmp(str1->val, str1->len, str2->val, str2->len); -} -/* }}} */ - static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */ { switch (type & BP_VAR_MASK) { @@ -3250,7 +3275,12 @@ void zend_compile_return(zend_ast *ast) /* {{{ */ zend_emit_op_tmp(&expr_node, ZEND_QM_ASSIGN, &expr_node_copy, NULL); } - zend_emit_return_type_check(&expr_node, arg_info); + /* maintains empty return/NULL return distinction */ + if (!expr_ast) { + zend_emit_return_type_check(NULL, arg_info); + } else { + zend_emit_return_type_check(&expr_node, arg_info); + } if (expr_node.op_type == IS_CONST) { zval_copy_ctor(&expr_node.u.constant); } @@ -3494,32 +3524,19 @@ void zend_compile_foreach(zend_ast *ast) /* {{{ */ } opnum_reset = get_next_op_number(CG(active_op_array)); - opline = zend_emit_op(&reset_node, ZEND_FE_RESET, &expr_node, NULL); - if (by_ref && is_variable) { - opline->extended_value = ZEND_FE_FETCH_BYREF; - } + opline = zend_emit_op(&reset_node, by_ref ? ZEND_FE_RESET_RW : ZEND_FE_RESET_R, &expr_node, NULL); + reset_node.flag = 1; /* generate FE_FREE */ zend_stack_push(&CG(loop_var_stack), &reset_node); opnum_fetch = get_next_op_number(CG(active_op_array)); - opline = zend_emit_op(&value_node, ZEND_FE_FETCH, &reset_node, NULL); - if (by_ref) { - opline->extended_value |= ZEND_FE_FETCH_BYREF; - } + opline = zend_emit_op(&value_node, by_ref ? ZEND_FE_FETCH_RW : ZEND_FE_FETCH_R, &reset_node, NULL); if (key_ast) { - opline->extended_value |= ZEND_FE_FETCH_WITH_KEY; + opline->extended_value = 1; } opline = zend_emit_op(NULL, ZEND_OP_DATA, NULL, NULL); - /* Allocate enough space to keep HashPointer on VM stack */ - opline->op1_type = IS_TMP_VAR; - opline->op1.var = get_temporary_variable(CG(active_op_array)); - if (sizeof(HashPointer) > sizeof(zval)) { - /* Make sure 1 zval is enough for HashPointer (2 must be enough) */ - get_temporary_variable(CG(active_op_array)); - } - if (key_ast) { zend_make_tmp_result(&key_node, opline); } @@ -3610,6 +3627,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */ zend_compile_expr(&expr_node, expr_ast); + expr_node.flag = 0; zend_stack_push(&CG(loop_var_stack), &expr_node); zend_begin_loop(); @@ -3996,9 +4014,13 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, zend_bool is_ "Variadic parameter cannot have a default value"); } } else if (default_ast) { + /* we cannot substitute constants here or it will break ReflectionParameter::getDefaultValueConstantName() and ReflectionParameter::isDefaultValueConstant() */ + uint32_t cops = CG(compiler_options); + CG(compiler_options) |= ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION | ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION; opcode = ZEND_RECV_INIT; default_node.op_type = IS_CONST; zend_const_expr_to_zval(&default_node.u.constant, default_ast); + CG(compiler_options) = cops; } else { opcode = ZEND_RECV; default_node.op_type = IS_UNUSED; @@ -4206,7 +4228,7 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo } } } else { - if (!in_trait && zend_string_equals_str_ci(lcname, ce->name)) { + if (!in_trait && zend_string_equals_ci(lcname, ce->name)) { if (!ce->constructor) { ce->constructor = (zend_function *) op_array; } @@ -4298,7 +4320,7 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as if (CG(current_import_function)) { zend_string *import_name = zend_hash_find_ptr(CG(current_import_function), lcname); - if (import_name && !zend_string_equals_str_ci(lcname, import_name)) { + if (import_name && !zend_string_equals_ci(lcname, import_name)) { zend_error(E_COMPILE_ERROR, "Cannot declare function %s " "because the name is already in use", name->val); } @@ -4694,7 +4716,7 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ zend_string_addref(name); } - if (import_name && !zend_string_equals_str_ci(lcname, import_name)) { + if (import_name && !zend_string_equals_ci(lcname, import_name)) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s " "because the name is already in use", name->val); } @@ -4872,7 +4894,7 @@ static char *zend_get_use_type_str(uint32_t type) /* {{{ */ static void zend_check_already_in_use(uint32_t type, zend_string *old_name, zend_string *new_name, zend_string *check_name) /* {{{ */ { - if (zend_string_equals_str_ci(old_name, check_name)) { + if (zend_string_equals_ci(old_name, check_name)) { return; } @@ -5928,30 +5950,32 @@ void zend_compile_class_const(znode *result, zend_ast *ast) /* {{{ */ znode class_node, const_node; zend_op *opline, *class_op = NULL; + zend_string *resolved_name; + + zend_eval_const_expr(&class_ast); + zend_eval_const_expr(&const_ast); + + if (class_ast->kind == ZEND_AST_ZVAL) { + resolved_name = zend_resolve_class_name_ast(class_ast); + if (const_ast->kind == ZEND_AST_ZVAL && zend_try_ct_eval_class_const(&result->u.constant, resolved_name, zend_ast_get_str(const_ast))) { + result->op_type = IS_CONST; + zend_string_release(resolved_name); + return; + } + } if (zend_is_const_default_class_ref(class_ast)) { class_node.op_type = IS_CONST; - ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast)); + ZVAL_STR(&class_node.u.constant, resolved_name); } else { + if (class_ast->kind == ZEND_AST_ZVAL) { + zend_string_release(resolved_name); + } class_op = zend_compile_class_ref(&class_node, class_ast); } zend_compile_expr(&const_node, const_ast); - if (class_op && const_node.op_type == IS_CONST && class_op->extended_value == ZEND_FETCH_CLASS_SELF && Z_TYPE(const_node.u.constant) == IS_STRING && CG(active_class_entry)) { - zval *const_zv = zend_hash_find(&CG(active_class_entry)->constants_table, Z_STR(const_node.u.constant)); - if (const_zv && Z_TYPE_P(const_zv) < IS_CONSTANT) { - CG(active_op_array)->last--; - CG(active_op_array)->T--; - - result->op_type = IS_CONST; - ZVAL_COPY(&result->u.constant, const_zv); - - zend_string_release(Z_STR(const_node.u.constant)); - return; - } - } - opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, &const_node); zend_set_class_name_op1(opline, &class_node); @@ -5991,8 +6015,8 @@ void zend_compile_resolve_class_name(znode *result, zend_ast *ast) /* {{{ */ ZVAL_STR_COPY(&result->u.constant, CG(active_class_entry)->name); } break; - case ZEND_FETCH_CLASS_STATIC: - case ZEND_FETCH_CLASS_PARENT: + case ZEND_FETCH_CLASS_STATIC: + case ZEND_FETCH_CLASS_PARENT: if (!CG(active_class_entry)) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot access %s::class when no class scope is active", @@ -6669,6 +6693,30 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */ zend_string_release(resolved_name); break; } + case ZEND_AST_CLASS_CONST: + { + zend_ast *class_ast = ast->child[0]; + zend_ast *name_ast = ast->child[1]; + zend_string *resolved_name; + + zend_eval_const_expr(&class_ast); + zend_eval_const_expr(&name_ast); + + if (class_ast->kind != ZEND_AST_ZVAL || name_ast->kind != ZEND_AST_ZVAL) { + return; + } + + resolved_name = zend_resolve_class_name_ast(class_ast); + + if (!zend_try_ct_eval_class_const(&result, resolved_name, zend_ast_get_str(name_ast))) { + zend_string_release(resolved_name); + return; + } + + zend_string_release(resolved_name); + break; + } + default: return; } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index ae5a042fd42e2..c28701a7f6cfb 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -95,7 +95,8 @@ typedef union _znode_op { } znode_op; typedef struct _znode { /* used only during compilation */ - int op_type; + zend_uchar op_type; + zend_uchar flag; union { znode_op op; zval constant; /* replaced by literal/zv */ @@ -834,9 +835,6 @@ ZEND_API void zend_assert_valid_class_name(const zend_string *const_name); #define ZEND_FETCH_ARG_MASK 0x000fffff -#define ZEND_FE_FETCH_BYREF 1 -#define ZEND_FE_FETCH_WITH_KEY 2 - #define EXT_TYPE_FREE_ON_RETURN (1<<2) #define ZEND_MEMBER_FUNC_CALL 1<<0 @@ -930,6 +928,9 @@ END_EXTERN_C() /* disable usage of builtin instruction for strlen() */ #define ZEND_COMPILE_NO_BUILTIN_STRLEN (1<<6) +/* disable substitution of persistent constants at compile-time */ +#define ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION (1<<7) + /* The default value for CG(compiler_options) */ #define ZEND_COMPILE_DEFAULT ZEND_COMPILE_HANDLE_OP_ARRAY diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 584f2be5a6544..c37eeb357365f 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -925,15 +925,15 @@ static inline int zend_verify_missing_return_type(zend_function *zf) char *class_name; need_msg = zend_verify_arg_class_kind(ret_info, &class_name, &ce); - zend_verify_return_error(E_RECOVERABLE_ERROR, zf, need_msg, class_name, "none", ""); + zend_verify_return_error(E_RECOVERABLE_ERROR, zf, need_msg, class_name, "no value", ""); return 0; } else if (ret_info->type_hint) { if (ret_info->type_hint == IS_ARRAY) { - zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type array", "", "none", ""); + zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type array", "", "no value", ""); } else if (ret_info->type_hint == IS_CALLABLE) { - zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be callable", "", "none", ""); + zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be callable", "", "no value", ""); } else { - zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type ", zend_get_type_by_const(ret_info->type_hint), "none", ""); + zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type ", zend_get_type_by_const(ret_info->type_hint), "no value", ""); } return 0; } @@ -1692,6 +1692,14 @@ static inline zend_brk_cont_element* zend_brk_cont(int nest_levels, int array_of if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { zval_ptr_dtor_nogc(EX_VAR(brk_opline->op1.var)); } + } else if (brk_opline->opcode == ZEND_FE_FREE) { + if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { + zval *var = EX_VAR(brk_opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); + } } } array_offset = jmp_to->parent; diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index c9da46d819382..c6a0d8f0c9aba 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -183,6 +183,11 @@ void init_executor(void) /* {{{ */ EG(scope) = NULL; + EG(ht_iterators_count) = sizeof(EG(ht_iterators_slots)) / sizeof(HashTableIterator); + EG(ht_iterators_used) = 0; + EG(ht_iterators) = EG(ht_iterators_slots); + memset(EG(ht_iterators), 0, sizeof(EG(ht_iterators_slots))); + EG(active) = 1; } /* }}} */ @@ -373,6 +378,11 @@ void shutdown_executor(void) /* {{{ */ zend_shutdown_fpu(); + EG(ht_iterators_used) = 0; + if (EG(ht_iterators) != EG(ht_iterators_slots)) { + efree(EG(ht_iterators)); + } + EG(active) = 0; } /* }}} */ diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index f19bb850138b5..971d4e7bc8c6c 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -60,6 +60,12 @@ static void zend_generator_cleanup_unfinished_execution(zend_generator *generato if (brk_opline->opcode == ZEND_FREE) { zval *var = EX_VAR(brk_opline->op1.var); zval_ptr_dtor_nogc(var); + } else if (brk_opline->opcode == ZEND_FE_FREE) { + zval *var = EX_VAR(brk_opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); } } } diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index 630d0f4c063d4..1d805a63c3c44 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -226,6 +226,11 @@ struct _zend_executor_globals { zend_bool active; zend_bool valid_symbol_table; + uint32_t ht_iterators_count; /* number of allocatd slots */ + uint32_t ht_iterators_used; /* number of used slots */ + HashTableIterator *ht_iterators; + HashTableIterator ht_iterators_slots[16]; + void *saved_fpu_cw_ptr; #if XPFPA_HAVE_CW XPFPA_CW_DATATYPE saved_fpu_cw; diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 480ac64dd16d1..195b5e48f0e1a 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -193,6 +193,140 @@ ZEND_API void zend_hash_set_apply_protection(HashTable *ht, zend_bool bApplyProt } } +ZEND_API uint32_t zend_hash_iterator_add(HashTable *ht, HashPosition pos) +{ + HashTableIterator *iter = EG(ht_iterators); + HashTableIterator *end = iter + EG(ht_iterators_count); + uint32_t idx; + + if (EXPECTED(ht->u.v.nIteratorsCount != 255)) { + ht->u.v.nIteratorsCount++; + } + while (iter != end) { + if (iter->ht == NULL) { + iter->ht = ht; + iter->pos = pos; + idx = iter - EG(ht_iterators); + if (idx + 1 > EG(ht_iterators_used)) { + EG(ht_iterators_used) = idx + 1; + } + return idx; + } + iter++; + } + if (EG(ht_iterators) == EG(ht_iterators_slots)) { + EG(ht_iterators) = emalloc(sizeof(HashTableIterator) * (EG(ht_iterators_count) + 8)); + memcpy(EG(ht_iterators), EG(ht_iterators_slots), sizeof(HashTableIterator) * EG(ht_iterators_count)); + } else { + EG(ht_iterators) = erealloc(EG(ht_iterators), sizeof(HashTableIterator) * (EG(ht_iterators_count) + 8)); + } + iter = EG(ht_iterators) + EG(ht_iterators_count); + EG(ht_iterators_count) += 8; + iter->ht = ht; + iter->pos = pos; + memset(iter + 1, 0, sizeof(HashTableIterator) * 7); + idx = iter - EG(ht_iterators); + EG(ht_iterators_used) = idx + 1; + return idx; +} + +ZEND_API HashPosition zend_hash_iterator_pos(uint32_t idx, HashTable *ht) +{ + HashTableIterator *iter = EG(ht_iterators) + idx; + + ZEND_ASSERT(idx != (uint32_t)-1); + if (iter->pos == INVALID_IDX) { + return INVALID_IDX; + } else if (UNEXPECTED(iter->ht != ht)) { + if (EXPECTED(iter->ht) && EXPECTED(iter->ht->u.v.nIteratorsCount != 255)) { + iter->ht->u.v.nIteratorsCount--; + } + if (EXPECTED(ht->u.v.nIteratorsCount != 255)) { + ht->u.v.nIteratorsCount++; + } + iter->ht = ht; + iter->pos = ht->nInternalPointer; + } + return iter->pos; +} + +ZEND_API void zend_hash_iterator_del(uint32_t idx) +{ + HashTableIterator *iter = EG(ht_iterators) + idx; + + ZEND_ASSERT(idx != (uint32_t)-1); + + if (EXPECTED(iter->ht) && EXPECTED(iter->ht->u.v.nIteratorsCount != 255)) { + iter->ht->u.v.nIteratorsCount--; + } + iter->ht = NULL; + + if (idx == EG(ht_iterators_used) - 1) { + while (idx > 0 && EG(ht_iterators)[idx - 1].ht == NULL) { + idx--; + } + EG(ht_iterators_used) = idx; + } +} + +static zend_never_inline void _zend_hash_iterators_remove(HashTable *ht) +{ + HashTableIterator *iter = EG(ht_iterators); + HashTableIterator *end = iter + EG(ht_iterators_used); + uint32_t idx; + + while (iter != end) { + if (iter->ht == ht) { + iter->ht = NULL; + } + iter++; + } + + idx = EG(ht_iterators_used); + while (idx > 0 && EG(ht_iterators)[idx - 1].ht == NULL) { + idx--; + } + EG(ht_iterators_used) = idx; +} + +static zend_always_inline void zend_hash_iterators_remove(HashTable *ht) +{ + if (UNEXPECTED(ht->u.v.nIteratorsCount)) { + _zend_hash_iterators_remove(ht); + } +} + +ZEND_API HashPosition zend_hash_iterators_lower_pos(HashTable *ht, HashPosition start) +{ + HashTableIterator *iter = EG(ht_iterators); + HashTableIterator *end = iter + EG(ht_iterators_used); + HashPosition res = INVALID_IDX; + uint32_t idx; + + while (iter != end) { + if (iter->ht == ht) { + if (iter->pos >= start && iter->pos < res) { + res = iter->pos; + } + } + iter++; + } + return res; +} + +ZEND_API void _zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to) +{ + HashTableIterator *iter = EG(ht_iterators); + HashTableIterator *end = iter + EG(ht_iterators_used); + + while (iter != end) { + if (iter->ht == ht && iter->pos == from) { + iter->pos = to; + } + iter++; + } +} + static zend_always_inline Bucket *zend_hash_find_bucket(const HashTable *ht, zend_string *key) { zend_ulong h; @@ -305,6 +439,7 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s if (ht->nInternalPointer == INVALID_IDX) { ht->nInternalPointer = idx; } + zend_hash_iterators_update(ht, INVALID_IDX, idx); p = ht->arData + idx; p->h = h = zend_string_hash_val(key); p->key = key; @@ -472,6 +607,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht, if (ht->nInternalPointer == INVALID_IDX) { ht->nInternalPointer = h; } + zend_hash_iterators_update(ht, INVALID_IDX, h); if ((zend_long)h >= (zend_long)ht->nNextFreeElement) { ht->nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX; } @@ -514,6 +650,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht, if (ht->nInternalPointer == INVALID_IDX) { ht->nInternalPointer = idx; } + zend_hash_iterators_update(ht, INVALID_IDX, idx); if ((zend_long)h >= (zend_long)ht->nNextFreeElement) { ht->nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX; } @@ -594,19 +731,42 @@ ZEND_API int zend_hash_rehash(HashTable *ht) } memset(ht->arHash, INVALID_IDX, ht->nTableSize * sizeof(uint32_t)); - for (i = 0, j = 0; i < ht->nNumUsed; i++) { - p = ht->arData + i; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - if (i != j) { - ht->arData[j] = ht->arData[i]; - if (ht->nInternalPointer == i) { - ht->nInternalPointer = j; + if (EXPECTED(ht->u.v.nIteratorsCount == 0)) { + for (i = 0, j = 0; i < ht->nNumUsed; i++) { + p = ht->arData + i; + if (Z_TYPE(p->val) == IS_UNDEF) continue; + if (i != j) { + ht->arData[j] = ht->arData[i]; + if (ht->nInternalPointer == i) { + ht->nInternalPointer = j; + } + } + nIndex = ht->arData[j].h & ht->nTableMask; + Z_NEXT(ht->arData[j].val) = ht->arHash[nIndex]; + ht->arHash[nIndex] = j; + j++; + } + } else { + uint32_t iter_pos = zend_hash_iterators_lower_pos(ht, 0); + + for (i = 0, j = 0; i < ht->nNumUsed; i++) { + p = ht->arData + i; + if (Z_TYPE(p->val) == IS_UNDEF) continue; + if (i != j) { + ht->arData[j] = ht->arData[i]; + if (ht->nInternalPointer == i) { + ht->nInternalPointer = j; + } + if (i == iter_pos) { + zend_hash_iterators_update(ht, i, j); + iter_pos = zend_hash_iterators_lower_pos(ht, iter_pos + 1); + } } + nIndex = ht->arData[j].h & ht->nTableMask; + Z_NEXT(ht->arData[j].val) = ht->arHash[nIndex]; + ht->arHash[nIndex] = j; + j++; } - nIndex = ht->arData[j].h & ht->nTableMask; - Z_NEXT(ht->arData[j].val) = ht->arHash[nIndex]; - ht->arHash[nIndex] = j; - j++; } ht->nNumUsed = j; return SUCCESS; @@ -628,17 +788,22 @@ static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, } while (ht->nNumUsed > 0 && (Z_TYPE(ht->arData[ht->nNumUsed-1].val) == IS_UNDEF)); } ht->nNumOfElements--; - if (ht->nInternalPointer == idx) { + if (ht->nInternalPointer == idx || UNEXPECTED(ht->u.v.nIteratorsCount)) { + uint32_t new_idx = idx; + while (1) { - idx++; - if (idx >= ht->nNumUsed) { - ht->nInternalPointer = INVALID_IDX; + new_idx++; + if (new_idx >= ht->nNumUsed) { + new_idx = INVALID_IDX; break; - } else if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) { - ht->nInternalPointer = idx; + } else if (Z_TYPE(ht->arData[new_idx].val) != IS_UNDEF) { break; } } + if (ht->nInternalPointer == idx) { + ht->nInternalPointer = new_idx; + } + zend_hash_iterators_update(ht, idx, new_idx); } if (p->key) { zend_string_release(p->key); @@ -893,6 +1058,7 @@ ZEND_API void zend_hash_destroy(HashTable *ht) } while (++p != end); } } + zend_hash_iterators_remove(ht); } else if (EXPECTED(!(ht->u.flags & HASH_FLAG_INITIALIZED))) { return; } @@ -933,7 +1099,7 @@ ZEND_API void zend_array_destroy(HashTable *ht) } } while (++p != end); } - + zend_hash_iterators_remove(ht); SET_INCONSISTENT(HT_DESTROYED); } else if (EXPECTED(!(ht->u.flags & HASH_FLAG_INITIALIZED))) { return; diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 377f508658ad5..602cd7a2e4575 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -50,8 +50,6 @@ typedef struct _zend_hash_key { typedef zend_bool (*merge_checker_func_t)(HashTable *target_ht, zval *source_data, zend_hash_key *hash_key, void *pParam); -typedef uint32_t HashPosition; - BEGIN_EXTERN_C() /* startup/shutdown */ @@ -171,13 +169,6 @@ ZEND_API zval *zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos); ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos); ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos); -typedef struct _HashPointer { - HashPosition pos; - HashTable *ht; - zend_ulong h; - zend_string *key; -} HashPointer; - #define zend_hash_has_more_elements(ht) \ zend_hash_has_more_elements_ex(ht, &(ht)->nInternalPointer) #define zend_hash_move_forward(ht) \ @@ -234,6 +225,21 @@ void zend_hash_display(const HashTable *ht); ZEND_API int _zend_handle_numeric_str_ex(const char *key, size_t length, zend_ulong *idx); + +ZEND_API uint32_t zend_hash_iterator_add(HashTable *ht, HashPosition pos); +ZEND_API HashPosition zend_hash_iterator_pos(uint32_t idx, HashTable *ht); +ZEND_API void zend_hash_iterator_del(uint32_t idx); +ZEND_API HashPosition zend_hash_iterators_lower_pos(HashTable *ht, HashPosition start); +ZEND_API void _zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to); + +static zend_always_inline void zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to) +{ + if (UNEXPECTED(ht->u.v.nIteratorsCount)) { + _zend_hash_iterators_update(ht, from, to); + } +} + + END_EXTERN_C() #define ZEND_INIT_SYMTABLE(ht) \ diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 7a94a3dcd30de..9a376aa1a00bd 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -936,6 +936,7 @@ ZEND_API void zend_std_call_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ /* destruct the function also, then - we have allocated it in get_method */ efree_size(func, sizeof(zend_internal_function)); + execute_data->func = NULL; } /* }}} */ @@ -1156,6 +1157,7 @@ ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ /* destruct the function also, then - we have allocated it in get_method */ efree_size(func, sizeof(zend_internal_function)); + execute_data->func = NULL; } /* }}} */ diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index a6d041f131209..c1e3adb3ec06f 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -766,8 +766,10 @@ ZEND_API int pass_two(zend_op_array *op_array) case ZEND_JMP_SET: case ZEND_COALESCE: case ZEND_NEW: - case ZEND_FE_RESET: - case ZEND_FE_FETCH: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op2); break; case ZEND_VERIFY_RETURN_TYPE: diff --git a/Zend/zend_string.h b/Zend/zend_string.h index 21bb24755e164..746f4b3bcf4e7 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -209,11 +209,15 @@ static zend_always_inline void zend_string_release(zend_string *s) } } + static zend_always_inline zend_bool zend_string_equals(zend_string *s1, zend_string *s2) { return s1 == s2 || (s1->len == s2->len && !memcmp(s1->val, s2->val, s1->len)); } +#define zend_string_equals_ci(s1, s2) \ + ((s1)->len == (s2)->len && !zend_binary_strcasecmp((s1)->val, (s1)->len, (s2)->val, (s2)->len)) + #define zend_string_equals_literal_ci(str, c) \ ((str)->len == sizeof(c) - 1 && !zend_binary_strcasecmp((str)->val, (str)->len, (c), sizeof(c) - 1)) diff --git a/Zend/zend_types.h b/Zend/zend_types.h index f3bc9774ecb91..f4668b3d37e9a 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -128,6 +128,8 @@ struct _zval_struct { uint32_t cache_slot; /* literal cache slot */ uint32_t lineno; /* line number (for ast nodes) */ uint32_t num_args; /* arguments number for EX(This) */ + uint32_t fe_pos; /* foreach position */ + uint32_t fe_iter_idx; /* foreach iterator index */ } u2; }; @@ -160,10 +162,11 @@ typedef struct _Bucket { typedef struct _HashTable { union { struct { - ZEND_ENDIAN_LOHI_3( + ZEND_ENDIAN_LOHI_4( zend_uchar flags, zend_uchar nApplyCount, - uint16_t reserve) + zend_uchar nIteratorsCount, + zend_uchar reserve) } v; uint32_t flags; } u; @@ -178,6 +181,13 @@ typedef struct _HashTable { dtor_func_t pDestructor; } HashTable; +typedef uint32_t HashPosition; + +typedef struct _HashTableIterator { + HashTable *ht; + HashPosition pos; +} HashTableIterator; + struct _zend_array { zend_refcounted gc; HashTable ht; @@ -265,6 +275,12 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) { #define Z_CACHE_SLOT(zval) (zval).u2.cache_slot #define Z_CACHE_SLOT_P(zval_p) Z_CACHE_SLOT(*(zval_p)) +#define Z_FE_POS(zval) (zval).u2.fe_pos +#define Z_FE_POS_P(zval_p) Z_FE_POS(*(zval_p)) + +#define Z_FE_ITER(zval) (zval).u2.fe_iter_idx +#define Z_FE_ITER_P(zval_p) Z_FE_ITER(*(zval_p)) + #define Z_COUNTED(zval) (zval).value.counted #define Z_COUNTED_P(zval_p) Z_COUNTED(*(zval_p)) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 9b4a7b0ca29f7..9d0ce9f3deea2 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2138,6 +2138,21 @@ ZEND_VM_HANDLER(70, ZEND_FREE, TMPVAR, ANY) ZEND_VM_NEXT_OPCODE(); } +ZEND_VM_HANDLER(127, ZEND_FE_FREE, TMPVAR, ANY) +{ + zval *var; + USE_OPLINE + + SAVE_OPLINE(); + var = EX_VAR(opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); +} + ZEND_VM_HANDLER(54, ZEND_ADD_CHAR, TMP|UNUSED, CONST) { USE_OPLINE @@ -2873,14 +2888,16 @@ ZEND_VM_HANDLER(60, ZEND_DO_FCALL, ANY, ANY) } else { zend_execute_internal(call, ret); } + + ZEND_ASSERT( + !call->func || + !(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || + zend_verify_internal_return_type(call->func, EX_VAR(opline->result.var))); + EG(current_execute_data) = call->prev_execute_data; zend_vm_stack_free_args(call); zend_vm_stack_free_call_frame(call); - ZEND_ASSERT( - !(fbc->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || - zend_verify_internal_return_type(fbc, EX_VAR(opline->result.var))); - if (!RETURN_VALUE_USED(opline)) { zval_ptr_dtor(EX_VAR(opline->result.var)); } @@ -3832,6 +3849,14 @@ ZEND_VM_HANDLER(100, ZEND_GOTO, ANY, CONST) if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { zval_ptr_dtor_nogc(EX_VAR(brk_opline->op1.var)); } + } else if (brk_opline->opcode == ZEND_FE_FREE) { + if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { + zval *var = EX_VAR(brk_opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); + } } ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op1)); } @@ -4631,245 +4656,456 @@ ZEND_VM_HANDLER(76, ZEND_UNSET_OBJ, VAR|UNUSED|CV, CONST|TMPVAR|CV) ZEND_VM_NEXT_OPCODE(); } -ZEND_VM_HANDLER(77, ZEND_FE_RESET, CONST|TMP|VAR|CV, ANY) +ZEND_VM_HANDLER(77, ZEND_FE_RESET_R, CONST|TMP|VAR|CV, ANY) { USE_OPLINE zend_free_op free_op1; - zval *array_ptr, *array_ref, iterator, tmp; + zval *array_ptr, *result; HashTable *fe_ht; - zend_object_iterator *iter = NULL; - zend_class_entry *ce = NULL; - zend_bool is_empty = 0; SAVE_OPLINE(); - if ((OP1_TYPE == IS_CV || OP1_TYPE == IS_VAR) && - (opline->extended_value & ZEND_FE_FETCH_BYREF)) { - array_ptr = array_ref = GET_OP1_ZVAL_PTR_PTR(BP_VAR_R); - ZVAL_DEREF(array_ptr); - if (Z_TYPE_P(array_ptr) == IS_ARRAY) { - SEPARATE_ARRAY(array_ptr); - if (!Z_ISREF_P(array_ref)) { - ZVAL_NEW_REF(array_ref, array_ref); - array_ptr = Z_REFVAL_P(array_ref); - } - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce->get_iterator == NULL) { + array_ptr = GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R); + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (OP1_TYPE != IS_TMP_VAR && Z_OPT_REFCOUNTED_P(result)) { + Z_ADDREF_P(array_ptr); + } + Z_FE_POS_P(result) = 0; + + FREE_OP1_IF_VAR(); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (OP1_TYPE != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + HashPosition pos = 0; + Bucket *p; + + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (OP1_TYPE != IS_TMP_VAR) { Z_ADDREF_P(array_ptr); } - array_ref = array_ptr; + fe_ht = Z_OBJPROP_P(array_ptr); + pos = 0; + while (1) { + if (pos >= fe_ht->nNumUsed) { + FREE_OP1_IF_VAR(); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; + } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + FREE_OP1_IF_VAR(); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } else { - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } - } else { - array_ptr = array_ref = GET_OP1_ZVAL_PTR(BP_VAR_R); - if (OP1_TYPE & (IS_VAR|IS_CV)) { - ZVAL_DEREF(array_ptr); - } - if (OP1_TYPE == IS_TMP_VAR) { - ZVAL_COPY_VALUE(&tmp, array_ptr); - if (Z_OPT_IMMUTABLE_P(&tmp)) { - zval_copy_ctor_func(&tmp); - } - array_ref = array_ptr = &tmp; - if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce && ce->get_iterator) { - Z_DELREF_P(array_ref); + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 0); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + FREE_OP1(); + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); } + zend_throw_exception_internal(NULL); + HANDLE_EXCEPTION(); } - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (!ce->get_iterator) { - if (OP1_TYPE == IS_CV) { - Z_ADDREF_P(array_ref); + + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + FREE_OP1(); + HANDLE_EXCEPTION(); } } - } else if (Z_IMMUTABLE_P(array_ref)) { - if (OP1_TYPE == IS_CV) { - zval_copy_ctor_func(array_ref); - Z_ADDREF_P(array_ref); + + is_empty = iter->funcs->valid(iter) != SUCCESS; + + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + FREE_OP1(); + HANDLE_EXCEPTION(); + } + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + FREE_OP1(); + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } else { - ZVAL_COPY_VALUE(&tmp, array_ref); - zval_copy_ctor_func(&tmp); - array_ptr = array_ref = &tmp; - } - } else if (Z_REFCOUNTED_P(array_ref)) { - if (OP1_TYPE == IS_CONST || - (OP1_TYPE == IS_CV && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 1) || - (OP1_TYPE == IS_VAR && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 2)) { - if (OP1_TYPE == IS_VAR) { - Z_DELREF_P(array_ref); - } - ZVAL_DUP(&tmp, array_ref); - array_ptr = array_ref = &tmp; - } else if (OP1_TYPE == IS_CV || OP1_TYPE == IS_VAR) { - if (Z_ISREF_P(array_ref) && Z_REFCOUNT_P(array_ref) == 1) { - ZVAL_UNREF(array_ref); - array_ptr = array_ref; - } - if (Z_IMMUTABLE_P(array_ptr)) { - zval_copy_ctor_func(array_ptr); - } else if (Z_ISREF_P(array_ref) && - Z_COPYABLE_P(array_ptr) && - Z_REFCOUNT_P(array_ptr) > 1) { - Z_DELREF_P(array_ptr); - zval_copy_ctor_func(array_ptr); - } - if (OP1_TYPE == IS_CV) { - Z_ADDREF_P(array_ref); - } + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } } + } else { + zend_error(E_WARNING, "Invalid argument supplied for foreach()"); + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + FREE_OP1(); + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } +} - if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_FETCH_BYREF); +ZEND_VM_HANDLER(125, ZEND_FE_RESET_RW, CONST|TMP|VAR|CV, ANY) +{ + USE_OPLINE + zend_free_op free_op1; + zval *array_ptr, *array_ref; + HashTable *fe_ht; + HashPosition pos = 0; + Bucket *p; - if (OP1_TYPE == IS_VAR && !(opline->extended_value & ZEND_FE_FETCH_BYREF)) { - FREE_OP1_IF_VAR(); + SAVE_OPLINE(); + + if (OP1_TYPE == IS_VAR || OP1_TYPE == IS_CV) { + array_ref = array_ptr = GET_OP1_ZVAL_PTR_PTR(BP_VAR_R); + if (Z_ISREF_P(array_ref)) { + array_ptr = Z_REFVAL_P(array_ref); } - if (iter && EXPECTED(EG(exception) == NULL)) { - ZVAL_OBJ(&iterator, &iter->std); - array_ptr = array_ref = &iterator; + } else { + array_ref = array_ptr = GET_OP1_ZVAL_PTR(BP_VAR_R); + } + + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + if (OP1_TYPE == IS_VAR || OP1_TYPE == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + if (OP1_TYPE == IS_CONST) { + zval_copy_ctor_func(array_ptr); } else { - if (OP1_TYPE == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + SEPARATE_ARRAY(array_ptr); + } + fe_ht = Z_ARRVAL_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { FREE_OP1_VAR_PTR(); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } - if (!EG(exception)) { - zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + p = fe_ht->arData + pos; + if (Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) { + break; } - zend_throw_exception_internal(NULL); - HANDLE_EXCEPTION(); + pos++; } - } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + FREE_OP1_VAR_PTR(); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (OP1_TYPE != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + if (OP1_TYPE == IS_VAR || OP1_TYPE == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + fe_ht = Z_OBJPROP_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { + FREE_OP1_VAR_PTR(); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; + } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + FREE_OP1_VAR_PTR(); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 1); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + if (OP1_TYPE == IS_VAR) { + FREE_OP1_VAR_PTR(); + } else { + FREE_OP1(); + } + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + } + zend_throw_exception_internal(NULL); + HANDLE_EXCEPTION(); + } - ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (OP1_TYPE == IS_VAR) { + FREE_OP1_VAR_PTR(); + } else { + FREE_OP1(); + } + HANDLE_EXCEPTION(); + } + } + + is_empty = iter->funcs->valid(iter) != SUCCESS; - if (iter) { - iter->index = 0; - if (iter->funcs->rewind) { - iter->funcs->rewind(iter); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (OP1_TYPE == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + OBJ_RELEASE(&iter->std); + if (OP1_TYPE == IS_VAR) { FREE_OP1_VAR_PTR(); + } else { + FREE_OP1(); } HANDLE_EXCEPTION(); } - } - is_empty = iter->funcs->valid(iter) != SUCCESS; - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (OP1_TYPE == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + if (OP1_TYPE == IS_VAR) { FREE_OP1_VAR_PTR(); + } else { + FREE_OP1(); } - HANDLE_EXCEPTION(); + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } else { + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } + } + } else { + zend_error(E_WARNING, "Invalid argument supplied for foreach()"); + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + if (OP1_TYPE == IS_VAR) { + FREE_OP1_VAR_PTR(); + } else { + FREE_OP1(); } - iter->index = -1; /* will be set to 0 before using next handler */ - } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { - HashPointer *ptr = (HashPointer*)EX_VAR((opline+2)->op1.var); - HashPosition pos = 0; - Bucket *p; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } +} + +ZEND_VM_HANDLER(78, ZEND_FE_FETCH_R, VAR, ANY) +{ + USE_OPLINE + zend_free_op free_op1; + zval *array; + zval *value; + HashTable *fe_ht; + HashPosition pos; + Bucket *p; + array = EX_VAR(opline->op1.var); + SAVE_OPLINE(); + if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) { + fe_ht = Z_ARRVAL_P(array); + pos = Z_FE_POS_P(EX_VAR(opline->op1.var)); while (1) { - if (pos >= fe_ht->nNumUsed) { - is_empty = 1; - if (OP1_TYPE == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { - FREE_OP1_VAR_PTR(); - } + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } p = fe_ht->arData + pos; - if (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF)) { + value = &p->val; + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; + } else if (Z_TYPE_P(value) == IS_INDIRECT) { + value = Z_INDIRECT_P(value); + if (Z_TYPE_P(value) == IS_UNDEF) { + pos++; + continue; + } } - if (!ce || - !p->key || - zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS) { - break; + break; + } + if (opline->extended_value) { + if (!p->key) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); } - pos++; } - fe_ht->nInternalPointer = pos; - ptr->pos = pos; - ptr->ht = fe_ht; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; - is_empty = 0; + ZVAL_COPY(EX_VAR(opline->result.var), value); + Z_FE_POS_P(EX_VAR(opline->op1.var)) = pos + 1; + ZEND_VM_INC_OPCODE(); + ZEND_VM_NEXT_OPCODE(); + } else if (EXPECTED(Z_TYPE_P(array) == IS_OBJECT)) { + zend_object_iterator *iter; + + if ((iter = zend_iterator_unwrap(array)) == NULL) { + /* plain object */ + zend_object *zobj = Z_OBJ_P(array); + + fe_ht = Z_OBJPROP_P(array); + pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht); + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + + p = fe_ht->arData + pos; + value = &p->val; + if (Z_TYPE_P(value) == IS_UNDEF) { + pos++; + continue; + } else if (Z_TYPE_P(value) == IS_INDIRECT) { + value = Z_INDIRECT_P(value); + if (Z_TYPE_P(value) == IS_UNDEF) { + pos++; + continue; + } + } + if (!p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS) { + break; + } + pos++; + } + if (opline->extended_value) { + if (UNEXPECTED(!p->key)) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); + } else if (p->key->val[0]) { + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); + } else { + const char *class_name, *prop_name; + size_t prop_name_len; + zend_unmangle_property_name_ex( + p->key, &class_name, &prop_name, &prop_name_len); + ZVAL_STRINGL(EX_VAR((opline+1)->result.var), prop_name, prop_name_len); + } + } + ZVAL_COPY(EX_VAR(opline->result.var), value); + while (1) { + pos++; + if (pos >= fe_ht->nNumUsed) { + pos = INVALID_IDX; + break; + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (Z_TYPE_P(array) != IS_OBJECT || + !p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS)) { + break; + } + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; + ZEND_VM_INC_OPCODE(); + ZEND_VM_NEXT_OPCODE(); + } else { + /* !iter happens from exception */ + if (iter && ++iter->index > 0) { + /* This could cause an endless loop if index becomes zero again. + * In case that ever happens we need an additional flag. */ + iter->funcs->move_forward(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + } + /* If index is zero we come from FE_RESET and checked valid() already. */ + if (!iter || (iter->index > 0 && iter->funcs->valid(iter) == FAILURE)) { + /* reached end of iteration */ + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + value = iter->funcs->get_current_data(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + if (!value) { + /* failure in get_current_data */ + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + ZVAL_COPY(EX_VAR(opline->result.var), value); + if (opline->extended_value) { + if (iter->funcs->get_current_key) { + iter->funcs->get_current_key(iter, EX_VAR((opline+1)->result.var)); + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + } else { + ZVAL_LONG(EX_VAR((opline+1)->result.var), iter->index); + } + } + ZEND_VM_INC_OPCODE(); + ZEND_VM_NEXT_OPCODE(); + } } else { zend_error(E_WARNING, "Invalid argument supplied for foreach()"); - is_empty = 1; - } - - if (OP1_TYPE == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { - FREE_OP1_VAR_PTR(); - } - if (is_empty) { ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else { - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } } -ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY) +ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY) { USE_OPLINE zend_free_op free_op1; - zval *array, *array_ref; + zval *array; zval *value; HashTable *fe_ht; - HashPointer *ptr; HashPosition pos; Bucket *p; - array = array_ref = EX_VAR(opline->op1.var); - if (Z_ISREF_P(array)) { - array = Z_REFVAL_P(array); - // TODO: referenced value might be changed to different array ??? - if (Z_IMMUTABLE_P(array)) { - zval_copy_ctor_func(array); - } - } - + array = EX_VAR(opline->op1.var); SAVE_OPLINE(); + ZVAL_DEREF(array); if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) { fe_ht = Z_ARRVAL_P(array); - ptr = (HashPointer*)EX_VAR((opline+1)->op1.var); - pos = ptr->pos; - if (UNEXPECTED(pos == INVALID_IDX)) { - /* reached end of iteration */ - ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else if (UNEXPECTED(ptr->ht != fe_ht)) { - ptr->ht = fe_ht; - pos = 0; - } else if (UNEXPECTED(fe_ht->nInternalPointer != ptr->pos)) { - if (fe_ht->u.flags & HASH_FLAG_PACKED) { - pos = ptr->h; - } else { - pos = fe_ht->arHash[ptr->h & fe_ht->nTableMask]; - while (1) { - if (pos == INVALID_IDX) { - pos = fe_ht->nInternalPointer; - break; - } else if (fe_ht->arData[pos].h == ptr->h && fe_ht->arData[pos].key == ptr->key) { - break; - } - pos = Z_NEXT(fe_ht->arData[pos].val); - } - } - } + pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht); while (1) { if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { /* reached end of iteration */ @@ -4877,46 +5113,42 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY) } p = fe_ht->arData + pos; value = &p->val; - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; - } else if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + } else if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value); - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; } } - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - ZVAL_MAKE_REF(value); - Z_ADDREF_P(value); - ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); + break; + } + if (opline->extended_value) { + if (!p->key) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); } else { - ZVAL_COPY(EX_VAR(opline->result.var), value); - } - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { - if (!p->key) { - ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); - } + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); } - break; } - do { + ZVAL_MAKE_REF(value); + Z_ADDREF_P(value); + ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); + while (1) { pos++; if (pos >= fe_ht->nNumUsed) { - fe_ht->nInternalPointer = ptr->pos = INVALID_IDX; - ZEND_VM_INC_OPCODE(); - ZEND_VM_NEXT_OPCODE(); + pos = INVALID_IDX; + break; } p = fe_ht->arData + pos; - } while (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF)); - fe_ht->nInternalPointer = ptr->pos = pos; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; + if (Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) { + break; + } + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } else if (EXPECTED(Z_TYPE_P(array) == IS_OBJECT)) { @@ -4927,30 +5159,7 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY) zend_object *zobj = Z_OBJ_P(array); fe_ht = Z_OBJPROP_P(array); - ptr = (HashPointer*)EX_VAR((opline+1)->op1.var); - pos = ptr->pos; - if (pos == INVALID_IDX) { - /* reached end of iteration */ - ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else if (UNEXPECTED(ptr->ht != fe_ht)) { - ptr->ht = fe_ht; - pos = 0; - } else if (UNEXPECTED(fe_ht->nInternalPointer != ptr->pos)) { - if (fe_ht->u.flags & HASH_FLAG_PACKED) { - pos = ptr->h; - } else { - pos = fe_ht->arHash[ptr->h & fe_ht->nTableMask]; - while (1) { - if (pos == INVALID_IDX) { - pos = fe_ht->nInternalPointer; - break; - } else if (fe_ht->arData[pos].h == ptr->h && fe_ht->arData[pos].key == ptr->key) { - break; - } - pos = Z_NEXT(fe_ht->arData[pos].val); - } - } - } + pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht); while (1) { if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { /* reached end of iteration */ @@ -4959,61 +5168,55 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY) p = fe_ht->arData + pos; value = &p->val; - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; - } else if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + } else if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value); - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; } } - - if (UNEXPECTED(!p->key)) { - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { - ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); - } - break; - } else if (zend_check_property_access(zobj, p->key) == SUCCESS) { - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { - if (p->key->val[0]) { - ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); - } else { - const char *class_name, *prop_name; - size_t prop_name_len; - zend_unmangle_property_name_ex( - p->key, &class_name, &prop_name, &prop_name_len); - ZVAL_STRINGL(EX_VAR((opline+1)->result.var), prop_name, prop_name_len); - } - } + if (!p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS) { break; } pos++; } - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - ZVAL_MAKE_REF(value); - Z_ADDREF_P(value); - ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); - } else { - ZVAL_COPY(EX_VAR(opline->result.var), value); + if (opline->extended_value) { + if (UNEXPECTED(!p->key)) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); + } else if (p->key->val[0]) { + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); + } else { + const char *class_name, *prop_name; + size_t prop_name_len; + zend_unmangle_property_name_ex( + p->key, &class_name, &prop_name, &prop_name_len); + ZVAL_STRINGL(EX_VAR((opline+1)->result.var), prop_name, prop_name_len); + } } - do { + ZVAL_MAKE_REF(value); + Z_ADDREF_P(value); + ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); + while (1) { pos++; if (pos >= fe_ht->nNumUsed) { - fe_ht->nInternalPointer = ptr->pos = INVALID_IDX; - ZEND_VM_INC_OPCODE(); - ZEND_VM_NEXT_OPCODE(); + pos = INVALID_IDX; + break; } p = fe_ht->arData + pos; - } while (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF) || - (EXPECTED(p->key != NULL) && - zend_check_property_access(zobj, p->key) == FAILURE)); - fe_ht->nInternalPointer = ptr->pos = pos; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (Z_TYPE_P(array) != IS_OBJECT || + !p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS)) { + break; + } + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } else { @@ -5023,7 +5226,7 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY) * In case that ever happens we need an additional flag. */ iter->funcs->move_forward(iter); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } } @@ -5031,38 +5234,34 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY) if (!iter || (iter->index > 0 && iter->funcs->valid(iter) == FAILURE)) { /* reached end of iteration */ if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } value = iter->funcs->get_current_data(iter); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } if (!value) { /* failure in get_current_data */ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - ZVAL_MAKE_REF(value); - Z_ADDREF_P(value); - ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); - } else { - ZVAL_COPY(EX_VAR(opline->result.var), value); - } - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { + if (opline->extended_value) { if (iter->funcs->get_current_key) { iter->funcs->get_current_key(iter, EX_VAR((opline+1)->result.var)); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } } else { ZVAL_LONG(EX_VAR((opline+1)->result.var), iter->index); } } + ZVAL_MAKE_REF(value); + Z_ADDREF_P(value); + ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } @@ -5851,6 +6050,14 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY) if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { zval_ptr_dtor_nogc(EX_VAR(brk_opline->op1.var)); } + } else if (brk_opline->opcode == ZEND_FE_FREE) { + if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { + zval *var = EX_VAR(brk_opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); + } } else if (brk_opline->opcode == ZEND_END_SILENCE) { /* restore previous error_reporting value */ if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(brk_opline->op1.var)) != 0) { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 83943a9c66b6a..0bbd5131d4d0d 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -599,14 +599,16 @@ static int ZEND_FASTCALL ZEND_DO_FCALL_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS) } else { zend_execute_internal(call, ret); } + + ZEND_ASSERT( + !call->func || + !(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || + zend_verify_internal_return_type(call->func, EX_VAR(opline->result.var))); + EG(current_execute_data) = call->prev_execute_data; zend_vm_stack_free_args(call); zend_vm_stack_free_call_frame(call); - ZEND_ASSERT( - !(fbc->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) || - zend_verify_internal_return_type(fbc, EX_VAR(opline->result.var))); - if (!RETURN_VALUE_USED(opline)) { zval_ptr_dtor(EX_VAR(opline->result.var)); } @@ -1353,6 +1355,14 @@ static int ZEND_FASTCALL ZEND_HANDLE_EXCEPTION_SPEC_HANDLER(ZEND_OPCODE_HANDLER if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { zval_ptr_dtor_nogc(EX_VAR(brk_opline->op1.var)); } + } else if (brk_opline->opcode == ZEND_FE_FREE) { + if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { + zval *var = EX_VAR(brk_opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); + } } else if (brk_opline->opcode == ZEND_END_SILENCE) { /* restore previous error_reporting value */ if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(brk_opline->op1.var)) != 0) { @@ -1811,6 +1821,14 @@ static int ZEND_FASTCALL ZEND_GOTO_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { zval_ptr_dtor_nogc(EX_VAR(brk_opline->op1.var)); } + } else if (brk_opline->opcode == ZEND_FE_FREE) { + if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN)) { + zval *var = EX_VAR(brk_opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); + } } ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op1)); } @@ -3045,194 +3063,270 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HA ZEND_VM_NEXT_OPCODE(); } -static int ZEND_FASTCALL ZEND_FE_RESET_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +static int ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE - zval *array_ptr, *array_ref, iterator, tmp; + zval *array_ptr, *result; HashTable *fe_ht; - zend_object_iterator *iter = NULL; - zend_class_entry *ce = NULL; - zend_bool is_empty = 0; SAVE_OPLINE(); - if ((IS_CONST == IS_CV || IS_CONST == IS_VAR) && - (opline->extended_value & ZEND_FE_FETCH_BYREF)) { - array_ptr = array_ref = NULL; - ZVAL_DEREF(array_ptr); - if (Z_TYPE_P(array_ptr) == IS_ARRAY) { - SEPARATE_ARRAY(array_ptr); - if (!Z_ISREF_P(array_ref)) { - ZVAL_NEW_REF(array_ref, array_ref); - array_ptr = Z_REFVAL_P(array_ref); - } - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce->get_iterator == NULL) { + array_ptr = EX_CONSTANT(opline->op1); + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_CONST != IS_TMP_VAR && Z_OPT_REFCOUNTED_P(result)) { + Z_ADDREF_P(array_ptr); + } + Z_FE_POS_P(result) = 0; + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_CONST != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + HashPosition pos = 0; + Bucket *p; + + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_CONST != IS_TMP_VAR) { Z_ADDREF_P(array_ptr); } - array_ref = array_ptr; - } else { - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } - } else { - array_ptr = array_ref = EX_CONSTANT(opline->op1); - if (IS_CONST & (IS_VAR|IS_CV)) { - ZVAL_DEREF(array_ptr); - } - if (IS_CONST == IS_TMP_VAR) { - ZVAL_COPY_VALUE(&tmp, array_ptr); - if (Z_OPT_IMMUTABLE_P(&tmp)) { - zval_copy_ctor_func(&tmp); + fe_ht = Z_OBJPROP_P(array_ptr); + pos = 0; + while (1) { + if (pos >= fe_ht->nNumUsed) { + + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; } - array_ref = array_ptr = &tmp; - if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce && ce->get_iterator) { - Z_DELREF_P(array_ref); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 0); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); } + zend_throw_exception_internal(NULL); + HANDLE_EXCEPTION(); } - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (!ce->get_iterator) { - if (IS_CONST == IS_CV) { - Z_ADDREF_P(array_ref); + + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + + HANDLE_EXCEPTION(); } } - } else if (Z_IMMUTABLE_P(array_ref)) { - if (IS_CONST == IS_CV) { - zval_copy_ctor_func(array_ref); - Z_ADDREF_P(array_ref); + + is_empty = iter->funcs->valid(iter) != SUCCESS; + + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + + HANDLE_EXCEPTION(); + } + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } else { - ZVAL_COPY_VALUE(&tmp, array_ref); - zval_copy_ctor_func(&tmp); - array_ptr = array_ref = &tmp; - } - } else if (Z_REFCOUNTED_P(array_ref)) { - if (IS_CONST == IS_CONST || - (IS_CONST == IS_CV && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 1) || - (IS_CONST == IS_VAR && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 2)) { - if (IS_CONST == IS_VAR) { - Z_DELREF_P(array_ref); - } - ZVAL_DUP(&tmp, array_ref); - array_ptr = array_ref = &tmp; - } else if (IS_CONST == IS_CV || IS_CONST == IS_VAR) { - if (Z_ISREF_P(array_ref) && Z_REFCOUNT_P(array_ref) == 1) { - ZVAL_UNREF(array_ref); - array_ptr = array_ref; - } - if (Z_IMMUTABLE_P(array_ptr)) { - zval_copy_ctor_func(array_ptr); - } else if (Z_ISREF_P(array_ref) && - Z_COPYABLE_P(array_ptr) && - Z_REFCOUNT_P(array_ptr) > 1) { - Z_DELREF_P(array_ptr); - zval_copy_ctor_func(array_ptr); - } - if (IS_CONST == IS_CV) { - Z_ADDREF_P(array_ref); - } + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } } + } else { + zend_error(E_WARNING, "Invalid argument supplied for foreach()"); + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } +} + +static int ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE + + zval *array_ptr, *array_ref; + HashTable *fe_ht; + HashPosition pos = 0; + Bucket *p; - if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_FETCH_BYREF); + SAVE_OPLINE(); - if (IS_CONST == IS_VAR && !(opline->extended_value & ZEND_FE_FETCH_BYREF)) { + if (IS_CONST == IS_VAR || IS_CONST == IS_CV) { + array_ref = array_ptr = NULL; + if (Z_ISREF_P(array_ref)) { + array_ptr = Z_REFVAL_P(array_ref); + } + } else { + array_ref = array_ptr = EX_CONSTANT(opline->op1); + } + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + if (IS_CONST == IS_VAR || IS_CONST == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); } - if (iter && EXPECTED(EG(exception) == NULL)) { - ZVAL_OBJ(&iterator, &iter->std); - array_ptr = array_ref = &iterator; + if (IS_CONST == IS_CONST) { + zval_copy_ctor_func(array_ptr); } else { - if (IS_CONST == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + SEPARATE_ARRAY(array_ptr); + } + fe_ht = Z_ARRVAL_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } - if (!EG(exception)) { - zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + p = fe_ht->arData + pos; + if (Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) { + break; } - zend_throw_exception_internal(NULL); - HANDLE_EXCEPTION(); + pos++; } - } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_CONST != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + if (IS_CONST == IS_VAR || IS_CONST == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + fe_ht = Z_OBJPROP_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { - ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; + } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); - if (iter) { - iter->index = 0; - if (iter->funcs->rewind) { - iter->funcs->rewind(iter); - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_CONST == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 1); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + if (IS_CONST == IS_VAR) { + + } else { } + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + } + zend_throw_exception_internal(NULL); HANDLE_EXCEPTION(); } - } - is_empty = iter->funcs->valid(iter) != SUCCESS; - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_CONST == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (IS_CONST == IS_VAR) { + + } else { + + } + HANDLE_EXCEPTION(); + } } - HANDLE_EXCEPTION(); - } - iter->index = -1; /* will be set to 0 before using next handler */ - } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { - HashPointer *ptr = (HashPointer*)EX_VAR((opline+2)->op1.var); - HashPosition pos = 0; - Bucket *p; - while (1) { - if (pos >= fe_ht->nNumUsed) { - is_empty = 1; - if (IS_CONST == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + is_empty = iter->funcs->valid(iter) != SUCCESS; + + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (IS_CONST == IS_VAR) { + + } else { } - ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + HANDLE_EXCEPTION(); } - p = fe_ht->arData + pos; - if (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF)) { - pos++; - continue; + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + if (IS_CONST == IS_VAR) { + + } else { + } - if (!ce || - !p->key || - zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS) { - break; + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } else { + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } - pos++; } - fe_ht->nInternalPointer = pos; - ptr->pos = pos; - ptr->ht = fe_ht; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; - is_empty = 0; } else { zend_error(E_WARNING, "Invalid argument supplied for foreach()"); - is_empty = 1; - } + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + if (IS_CONST == IS_VAR) { - if (IS_CONST == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + } else { - } - if (is_empty) { + } ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else { - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } } @@ -8968,194 +9062,271 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) ZEND_VM_NEXT_OPCODE(); } -static int ZEND_FASTCALL ZEND_FE_RESET_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +static int ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE zend_free_op free_op1; - zval *array_ptr, *array_ref, iterator, tmp; + zval *array_ptr, *result; HashTable *fe_ht; - zend_object_iterator *iter = NULL; - zend_class_entry *ce = NULL; - zend_bool is_empty = 0; SAVE_OPLINE(); - if ((IS_TMP_VAR == IS_CV || IS_TMP_VAR == IS_VAR) && - (opline->extended_value & ZEND_FE_FETCH_BYREF)) { - array_ptr = array_ref = NULL; - ZVAL_DEREF(array_ptr); - if (Z_TYPE_P(array_ptr) == IS_ARRAY) { - SEPARATE_ARRAY(array_ptr); - if (!Z_ISREF_P(array_ref)) { - ZVAL_NEW_REF(array_ref, array_ref); - array_ptr = Z_REFVAL_P(array_ref); - } - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce->get_iterator == NULL) { + array_ptr = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_TMP_VAR != IS_TMP_VAR && Z_OPT_REFCOUNTED_P(result)) { + Z_ADDREF_P(array_ptr); + } + Z_FE_POS_P(result) = 0; + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_TMP_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + HashPosition pos = 0; + Bucket *p; + + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_TMP_VAR != IS_TMP_VAR) { Z_ADDREF_P(array_ptr); } - array_ref = array_ptr; - } else { - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } - } else { - array_ptr = array_ref = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); - if (IS_TMP_VAR & (IS_VAR|IS_CV)) { - ZVAL_DEREF(array_ptr); - } - if (IS_TMP_VAR == IS_TMP_VAR) { - ZVAL_COPY_VALUE(&tmp, array_ptr); - if (Z_OPT_IMMUTABLE_P(&tmp)) { - zval_copy_ctor_func(&tmp); + fe_ht = Z_OBJPROP_P(array_ptr); + pos = 0; + while (1) { + if (pos >= fe_ht->nNumUsed) { + + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; } - array_ref = array_ptr = &tmp; - if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce && ce->get_iterator) { - Z_DELREF_P(array_ref); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 0); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + zval_ptr_dtor_nogc(free_op1); + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); } + zend_throw_exception_internal(NULL); + HANDLE_EXCEPTION(); } - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (!ce->get_iterator) { - if (IS_TMP_VAR == IS_CV) { - Z_ADDREF_P(array_ref); + + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + zval_ptr_dtor_nogc(free_op1); + HANDLE_EXCEPTION(); } } - } else if (Z_IMMUTABLE_P(array_ref)) { - if (IS_TMP_VAR == IS_CV) { - zval_copy_ctor_func(array_ref); - Z_ADDREF_P(array_ref); + + is_empty = iter->funcs->valid(iter) != SUCCESS; + + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + zval_ptr_dtor_nogc(free_op1); + HANDLE_EXCEPTION(); + } + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + zval_ptr_dtor_nogc(free_op1); + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } else { - ZVAL_COPY_VALUE(&tmp, array_ref); - zval_copy_ctor_func(&tmp); - array_ptr = array_ref = &tmp; - } - } else if (Z_REFCOUNTED_P(array_ref)) { - if (IS_TMP_VAR == IS_CONST || - (IS_TMP_VAR == IS_CV && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 1) || - (IS_TMP_VAR == IS_VAR && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 2)) { - if (IS_TMP_VAR == IS_VAR) { - Z_DELREF_P(array_ref); - } - ZVAL_DUP(&tmp, array_ref); - array_ptr = array_ref = &tmp; - } else if (IS_TMP_VAR == IS_CV || IS_TMP_VAR == IS_VAR) { - if (Z_ISREF_P(array_ref) && Z_REFCOUNT_P(array_ref) == 1) { - ZVAL_UNREF(array_ref); - array_ptr = array_ref; - } - if (Z_IMMUTABLE_P(array_ptr)) { - zval_copy_ctor_func(array_ptr); - } else if (Z_ISREF_P(array_ref) && - Z_COPYABLE_P(array_ptr) && - Z_REFCOUNT_P(array_ptr) > 1) { - Z_DELREF_P(array_ptr); - zval_copy_ctor_func(array_ptr); - } - if (IS_TMP_VAR == IS_CV) { - Z_ADDREF_P(array_ref); - } + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } } + } else { + zend_error(E_WARNING, "Invalid argument supplied for foreach()"); + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + zval_ptr_dtor_nogc(free_op1); + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } +} + +static int ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE + zend_free_op free_op1; + zval *array_ptr, *array_ref; + HashTable *fe_ht; + HashPosition pos = 0; + Bucket *p; - if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_FETCH_BYREF); + SAVE_OPLINE(); - if (IS_TMP_VAR == IS_VAR && !(opline->extended_value & ZEND_FE_FETCH_BYREF)) { + if (IS_TMP_VAR == IS_VAR || IS_TMP_VAR == IS_CV) { + array_ref = array_ptr = NULL; + if (Z_ISREF_P(array_ref)) { + array_ptr = Z_REFVAL_P(array_ref); + } + } else { + array_ref = array_ptr = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1); + } + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + if (IS_TMP_VAR == IS_VAR || IS_TMP_VAR == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); } - if (iter && EXPECTED(EG(exception) == NULL)) { - ZVAL_OBJ(&iterator, &iter->std); - array_ptr = array_ref = &iterator; + if (IS_TMP_VAR == IS_CONST) { + zval_copy_ctor_func(array_ptr); } else { - if (IS_TMP_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + SEPARATE_ARRAY(array_ptr); + } + fe_ht = Z_ARRVAL_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } - if (!EG(exception)) { - zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + p = fe_ht->arData + pos; + if (Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) { + break; } - zend_throw_exception_internal(NULL); - HANDLE_EXCEPTION(); + pos++; } - } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); - ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_TMP_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + if (IS_TMP_VAR == IS_VAR || IS_TMP_VAR == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + fe_ht = Z_OBJPROP_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { - if (iter) { - iter->index = 0; - if (iter->funcs->rewind) { - iter->funcs->rewind(iter); - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_TMP_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; + } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 1); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + if (IS_TMP_VAR == IS_VAR) { + } else { + zval_ptr_dtor_nogc(free_op1); + } + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); } + zend_throw_exception_internal(NULL); HANDLE_EXCEPTION(); } - } - is_empty = iter->funcs->valid(iter) != SUCCESS; - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_TMP_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (IS_TMP_VAR == IS_VAR) { + + } else { + zval_ptr_dtor_nogc(free_op1); + } + HANDLE_EXCEPTION(); + } } - HANDLE_EXCEPTION(); - } - iter->index = -1; /* will be set to 0 before using next handler */ - } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { - HashPointer *ptr = (HashPointer*)EX_VAR((opline+2)->op1.var); - HashPosition pos = 0; - Bucket *p; - while (1) { - if (pos >= fe_ht->nNumUsed) { - is_empty = 1; - if (IS_TMP_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + is_empty = iter->funcs->valid(iter) != SUCCESS; + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (IS_TMP_VAR == IS_VAR) { + + } else { + zval_ptr_dtor_nogc(free_op1); } - ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + HANDLE_EXCEPTION(); } - p = fe_ht->arData + pos; - if (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF)) { - pos++; - continue; + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + if (IS_TMP_VAR == IS_VAR) { + + } else { + zval_ptr_dtor_nogc(free_op1); } - if (!ce || - !p->key || - zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS) { - break; + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } else { + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } - pos++; } - fe_ht->nInternalPointer = pos; - ptr->pos = pos; - ptr->ht = fe_ht; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; - is_empty = 0; } else { zend_error(E_WARNING, "Invalid argument supplied for foreach()"); - is_empty = 1; - } - - if (IS_TMP_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + if (IS_TMP_VAR == IS_VAR) { - } - if (is_empty) { + } else { + zval_ptr_dtor_nogc(free_op1); + } ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else { - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } } @@ -11792,245 +11963,456 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) ZEND_VM_NEXT_OPCODE(); } -static int ZEND_FASTCALL ZEND_FE_RESET_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +static int ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE zend_free_op free_op1; - zval *array_ptr, *array_ref, iterator, tmp; + zval *array_ptr, *result; HashTable *fe_ht; - zend_object_iterator *iter = NULL; - zend_class_entry *ce = NULL; - zend_bool is_empty = 0; SAVE_OPLINE(); - if ((IS_VAR == IS_CV || IS_VAR == IS_VAR) && - (opline->extended_value & ZEND_FE_FETCH_BYREF)) { - array_ptr = array_ref = _get_zval_ptr_ptr_var(opline->op1.var, execute_data, &free_op1); - ZVAL_DEREF(array_ptr); - if (Z_TYPE_P(array_ptr) == IS_ARRAY) { - SEPARATE_ARRAY(array_ptr); - if (!Z_ISREF_P(array_ref)) { - ZVAL_NEW_REF(array_ref, array_ref); - array_ptr = Z_REFVAL_P(array_ref); - } - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce->get_iterator == NULL) { + array_ptr = _get_zval_ptr_var_deref(opline->op1.var, execute_data, &free_op1); + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_VAR != IS_TMP_VAR && Z_OPT_REFCOUNTED_P(result)) { + Z_ADDREF_P(array_ptr); + } + Z_FE_POS_P(result) = 0; + + zval_ptr_dtor_nogc(free_op1); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + HashPosition pos = 0; + Bucket *p; + + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_VAR != IS_TMP_VAR) { Z_ADDREF_P(array_ptr); } - array_ref = array_ptr; - } else { - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } - } else { - array_ptr = array_ref = _get_zval_ptr_var(opline->op1.var, execute_data, &free_op1); - if (IS_VAR & (IS_VAR|IS_CV)) { - ZVAL_DEREF(array_ptr); - } - if (IS_VAR == IS_TMP_VAR) { - ZVAL_COPY_VALUE(&tmp, array_ptr); - if (Z_OPT_IMMUTABLE_P(&tmp)) { - zval_copy_ctor_func(&tmp); + fe_ht = Z_OBJPROP_P(array_ptr); + pos = 0; + while (1) { + if (pos >= fe_ht->nNumUsed) { + zval_ptr_dtor_nogc(free_op1); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; } - array_ref = array_ptr = &tmp; - if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce && ce->get_iterator) { - Z_DELREF_P(array_ref); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + zval_ptr_dtor_nogc(free_op1); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 0); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + zval_ptr_dtor_nogc(free_op1); + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); } + zend_throw_exception_internal(NULL); + HANDLE_EXCEPTION(); } - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (!ce->get_iterator) { - if (IS_VAR == IS_CV) { - Z_ADDREF_P(array_ref); + + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + zval_ptr_dtor_nogc(free_op1); + HANDLE_EXCEPTION(); } } - } else if (Z_IMMUTABLE_P(array_ref)) { - if (IS_VAR == IS_CV) { - zval_copy_ctor_func(array_ref); - Z_ADDREF_P(array_ref); + + is_empty = iter->funcs->valid(iter) != SUCCESS; + + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + zval_ptr_dtor_nogc(free_op1); + HANDLE_EXCEPTION(); + } + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + zval_ptr_dtor_nogc(free_op1); + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } else { - ZVAL_COPY_VALUE(&tmp, array_ref); - zval_copy_ctor_func(&tmp); - array_ptr = array_ref = &tmp; - } - } else if (Z_REFCOUNTED_P(array_ref)) { - if (IS_VAR == IS_CONST || - (IS_VAR == IS_CV && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 1) || - (IS_VAR == IS_VAR && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 2)) { - if (IS_VAR == IS_VAR) { - Z_DELREF_P(array_ref); - } - ZVAL_DUP(&tmp, array_ref); - array_ptr = array_ref = &tmp; - } else if (IS_VAR == IS_CV || IS_VAR == IS_VAR) { - if (Z_ISREF_P(array_ref) && Z_REFCOUNT_P(array_ref) == 1) { - ZVAL_UNREF(array_ref); - array_ptr = array_ref; - } - if (Z_IMMUTABLE_P(array_ptr)) { - zval_copy_ctor_func(array_ptr); - } else if (Z_ISREF_P(array_ref) && - Z_COPYABLE_P(array_ptr) && - Z_REFCOUNT_P(array_ptr) > 1) { - Z_DELREF_P(array_ptr); - zval_copy_ctor_func(array_ptr); - } - if (IS_VAR == IS_CV) { - Z_ADDREF_P(array_ref); - } + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } } + } else { + zend_error(E_WARNING, "Invalid argument supplied for foreach()"); + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + zval_ptr_dtor_nogc(free_op1); + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } +} - if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_FETCH_BYREF); +static int ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE + zend_free_op free_op1; + zval *array_ptr, *array_ref; + HashTable *fe_ht; + HashPosition pos = 0; + Bucket *p; - if (IS_VAR == IS_VAR && !(opline->extended_value & ZEND_FE_FETCH_BYREF)) { - zval_ptr_dtor_nogc(free_op1); + SAVE_OPLINE(); + + if (IS_VAR == IS_VAR || IS_VAR == IS_CV) { + array_ref = array_ptr = _get_zval_ptr_ptr_var(opline->op1.var, execute_data, &free_op1); + if (Z_ISREF_P(array_ref)) { + array_ptr = Z_REFVAL_P(array_ref); } - if (iter && EXPECTED(EG(exception) == NULL)) { - ZVAL_OBJ(&iterator, &iter->std); - array_ptr = array_ref = &iterator; + } else { + array_ref = array_ptr = _get_zval_ptr_var(opline->op1.var, execute_data, &free_op1); + } + + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + if (IS_VAR == IS_VAR || IS_VAR == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); } else { - if (IS_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + if (IS_VAR == IS_CONST) { + zval_copy_ctor_func(array_ptr); + } else { + SEPARATE_ARRAY(array_ptr); + } + fe_ht = Z_ARRVAL_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } - if (!EG(exception)) { - zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + p = fe_ht->arData + pos; + if (Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) { + break; } - zend_throw_exception_internal(NULL); - HANDLE_EXCEPTION(); + pos++; } - } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + if (IS_VAR == IS_VAR || IS_VAR == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + fe_ht = Z_OBJPROP_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { + if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; + } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 1); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + if (IS_VAR == IS_VAR) { + if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + } else { + zval_ptr_dtor_nogc(free_op1); + } + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + } + zend_throw_exception_internal(NULL); + HANDLE_EXCEPTION(); + } - ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (IS_VAR == IS_VAR) { + if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + } else { + zval_ptr_dtor_nogc(free_op1); + } + HANDLE_EXCEPTION(); + } + } + + is_empty = iter->funcs->valid(iter) != SUCCESS; - if (iter) { - iter->index = 0; - if (iter->funcs->rewind) { - iter->funcs->rewind(iter); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + OBJ_RELEASE(&iter->std); + if (IS_VAR == IS_VAR) { if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + } else { + zval_ptr_dtor_nogc(free_op1); } HANDLE_EXCEPTION(); } - } - is_empty = iter->funcs->valid(iter) != SUCCESS; - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + if (IS_VAR == IS_VAR) { if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + } else { + zval_ptr_dtor_nogc(free_op1); + } + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } else { + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } - HANDLE_EXCEPTION(); } - iter->index = -1; /* will be set to 0 before using next handler */ - } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { - HashPointer *ptr = (HashPointer*)EX_VAR((opline+2)->op1.var); - HashPosition pos = 0; - Bucket *p; + } else { + zend_error(E_WARNING, "Invalid argument supplied for foreach()"); + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + if (IS_VAR == IS_VAR) { + if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; + } else { + zval_ptr_dtor_nogc(free_op1); + } + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } +} +static int ZEND_FASTCALL ZEND_FE_FETCH_R_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE + + zval *array; + zval *value; + HashTable *fe_ht; + HashPosition pos; + Bucket *p; + + array = EX_VAR(opline->op1.var); + SAVE_OPLINE(); + if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) { + fe_ht = Z_ARRVAL_P(array); + pos = Z_FE_POS_P(EX_VAR(opline->op1.var)); while (1) { - if (pos >= fe_ht->nNumUsed) { - is_empty = 1; - if (IS_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { - if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; - } + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } p = fe_ht->arData + pos; - if (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF)) { + value = &p->val; + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; + } else if (Z_TYPE_P(value) == IS_INDIRECT) { + value = Z_INDIRECT_P(value); + if (Z_TYPE_P(value) == IS_UNDEF) { + pos++; + continue; + } } - if (!ce || - !p->key || - zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS) { - break; + break; + } + if (opline->extended_value) { + if (!p->key) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); } - pos++; } - fe_ht->nInternalPointer = pos; - ptr->pos = pos; - ptr->ht = fe_ht; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; - is_empty = 0; + ZVAL_COPY(EX_VAR(opline->result.var), value); + Z_FE_POS_P(EX_VAR(opline->op1.var)) = pos + 1; + ZEND_VM_INC_OPCODE(); + ZEND_VM_NEXT_OPCODE(); + } else if (EXPECTED(Z_TYPE_P(array) == IS_OBJECT)) { + zend_object_iterator *iter; + + if ((iter = zend_iterator_unwrap(array)) == NULL) { + /* plain object */ + zend_object *zobj = Z_OBJ_P(array); + + fe_ht = Z_OBJPROP_P(array); + pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht); + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + + p = fe_ht->arData + pos; + value = &p->val; + if (Z_TYPE_P(value) == IS_UNDEF) { + pos++; + continue; + } else if (Z_TYPE_P(value) == IS_INDIRECT) { + value = Z_INDIRECT_P(value); + if (Z_TYPE_P(value) == IS_UNDEF) { + pos++; + continue; + } + } + if (!p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS) { + break; + } + pos++; + } + if (opline->extended_value) { + if (UNEXPECTED(!p->key)) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); + } else if (p->key->val[0]) { + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); + } else { + const char *class_name, *prop_name; + size_t prop_name_len; + zend_unmangle_property_name_ex( + p->key, &class_name, &prop_name, &prop_name_len); + ZVAL_STRINGL(EX_VAR((opline+1)->result.var), prop_name, prop_name_len); + } + } + ZVAL_COPY(EX_VAR(opline->result.var), value); + while (1) { + pos++; + if (pos >= fe_ht->nNumUsed) { + pos = INVALID_IDX; + break; + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (Z_TYPE_P(array) != IS_OBJECT || + !p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS)) { + break; + } + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; + ZEND_VM_INC_OPCODE(); + ZEND_VM_NEXT_OPCODE(); + } else { + /* !iter happens from exception */ + if (iter && ++iter->index > 0) { + /* This could cause an endless loop if index becomes zero again. + * In case that ever happens we need an additional flag. */ + iter->funcs->move_forward(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + } + /* If index is zero we come from FE_RESET and checked valid() already. */ + if (!iter || (iter->index > 0 && iter->funcs->valid(iter) == FAILURE)) { + /* reached end of iteration */ + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + value = iter->funcs->get_current_data(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + if (!value) { + /* failure in get_current_data */ + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + ZVAL_COPY(EX_VAR(opline->result.var), value); + if (opline->extended_value) { + if (iter->funcs->get_current_key) { + iter->funcs->get_current_key(iter, EX_VAR((opline+1)->result.var)); + if (UNEXPECTED(EG(exception) != NULL)) { + zval_ptr_dtor(array); + HANDLE_EXCEPTION(); + } + } else { + ZVAL_LONG(EX_VAR((opline+1)->result.var), iter->index); + } + } + ZEND_VM_INC_OPCODE(); + ZEND_VM_NEXT_OPCODE(); + } } else { zend_error(E_WARNING, "Invalid argument supplied for foreach()"); - is_empty = 1; - } - - if (IS_VAR == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { - if (free_op1) {zval_ptr_dtor_nogc(free_op1);}; - } - if (is_empty) { ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else { - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } } -static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +static int ZEND_FASTCALL ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE - zval *array, *array_ref; + zval *array; zval *value; HashTable *fe_ht; - HashPointer *ptr; HashPosition pos; Bucket *p; - array = array_ref = EX_VAR(opline->op1.var); - if (Z_ISREF_P(array)) { - array = Z_REFVAL_P(array); - // TODO: referenced value might be changed to different array ??? - if (Z_IMMUTABLE_P(array)) { - zval_copy_ctor_func(array); - } - } - + array = EX_VAR(opline->op1.var); SAVE_OPLINE(); + ZVAL_DEREF(array); if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) { fe_ht = Z_ARRVAL_P(array); - ptr = (HashPointer*)EX_VAR((opline+1)->op1.var); - pos = ptr->pos; - if (UNEXPECTED(pos == INVALID_IDX)) { - /* reached end of iteration */ - ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else if (UNEXPECTED(ptr->ht != fe_ht)) { - ptr->ht = fe_ht; - pos = 0; - } else if (UNEXPECTED(fe_ht->nInternalPointer != ptr->pos)) { - if (fe_ht->u.flags & HASH_FLAG_PACKED) { - pos = ptr->h; - } else { - pos = fe_ht->arHash[ptr->h & fe_ht->nTableMask]; - while (1) { - if (pos == INVALID_IDX) { - pos = fe_ht->nInternalPointer; - break; - } else if (fe_ht->arData[pos].h == ptr->h && fe_ht->arData[pos].key == ptr->key) { - break; - } - pos = Z_NEXT(fe_ht->arData[pos].val); - } - } - } + pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht); while (1) { if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { /* reached end of iteration */ @@ -12038,46 +12420,42 @@ static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG } p = fe_ht->arData + pos; value = &p->val; - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; - } else if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + } else if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value); - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; } } - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - ZVAL_MAKE_REF(value); - Z_ADDREF_P(value); - ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); + break; + } + if (opline->extended_value) { + if (!p->key) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); } else { - ZVAL_COPY(EX_VAR(opline->result.var), value); + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); } - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { - if (!p->key) { - ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); - } - } - break; } - do { + ZVAL_MAKE_REF(value); + Z_ADDREF_P(value); + ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); + while (1) { pos++; if (pos >= fe_ht->nNumUsed) { - fe_ht->nInternalPointer = ptr->pos = INVALID_IDX; - ZEND_VM_INC_OPCODE(); - ZEND_VM_NEXT_OPCODE(); + pos = INVALID_IDX; + break; } p = fe_ht->arData + pos; - } while (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF)); - fe_ht->nInternalPointer = ptr->pos = pos; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; + if (Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) { + break; + } + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } else if (EXPECTED(Z_TYPE_P(array) == IS_OBJECT)) { @@ -12088,30 +12466,7 @@ static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG zend_object *zobj = Z_OBJ_P(array); fe_ht = Z_OBJPROP_P(array); - ptr = (HashPointer*)EX_VAR((opline+1)->op1.var); - pos = ptr->pos; - if (pos == INVALID_IDX) { - /* reached end of iteration */ - ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else if (UNEXPECTED(ptr->ht != fe_ht)) { - ptr->ht = fe_ht; - pos = 0; - } else if (UNEXPECTED(fe_ht->nInternalPointer != ptr->pos)) { - if (fe_ht->u.flags & HASH_FLAG_PACKED) { - pos = ptr->h; - } else { - pos = fe_ht->arHash[ptr->h & fe_ht->nTableMask]; - while (1) { - if (pos == INVALID_IDX) { - pos = fe_ht->nInternalPointer; - break; - } else if (fe_ht->arData[pos].h == ptr->h && fe_ht->arData[pos].key == ptr->key) { - break; - } - pos = Z_NEXT(fe_ht->arData[pos].val); - } - } - } + pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht); while (1) { if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { /* reached end of iteration */ @@ -12120,61 +12475,55 @@ static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG p = fe_ht->arData + pos; value = &p->val; - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; - } else if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + } else if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value); - if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + if (Z_TYPE_P(value) == IS_UNDEF) { pos++; continue; } } - - if (UNEXPECTED(!p->key)) { - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { - ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); - } - break; - } else if (zend_check_property_access(zobj, p->key) == SUCCESS) { - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { - if (p->key->val[0]) { - ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); - } else { - const char *class_name, *prop_name; - size_t prop_name_len; - zend_unmangle_property_name_ex( - p->key, &class_name, &prop_name, &prop_name_len); - ZVAL_STRINGL(EX_VAR((opline+1)->result.var), prop_name, prop_name_len); - } - } + if (!p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS) { break; } pos++; } - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - ZVAL_MAKE_REF(value); - Z_ADDREF_P(value); - ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); - } else { - ZVAL_COPY(EX_VAR(opline->result.var), value); + if (opline->extended_value) { + if (UNEXPECTED(!p->key)) { + ZVAL_LONG(EX_VAR((opline+1)->result.var), p->h); + } else if (p->key->val[0]) { + ZVAL_STR_COPY(EX_VAR((opline+1)->result.var), p->key); + } else { + const char *class_name, *prop_name; + size_t prop_name_len; + zend_unmangle_property_name_ex( + p->key, &class_name, &prop_name, &prop_name_len); + ZVAL_STRINGL(EX_VAR((opline+1)->result.var), prop_name, prop_name_len); + } } - do { + ZVAL_MAKE_REF(value); + Z_ADDREF_P(value); + ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); + while (1) { pos++; if (pos >= fe_ht->nNumUsed) { - fe_ht->nInternalPointer = ptr->pos = INVALID_IDX; - ZEND_VM_INC_OPCODE(); - ZEND_VM_NEXT_OPCODE(); + pos = INVALID_IDX; + break; } p = fe_ht->arData + pos; - } while (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF) || - (EXPECTED(p->key != NULL) && - zend_check_property_access(zobj, p->key) == FAILURE)); - fe_ht->nInternalPointer = ptr->pos = pos; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (Z_TYPE_P(array) != IS_OBJECT || + !p->key || + zend_check_property_access(Z_OBJ_P(array), p->key) == SUCCESS)) { + break; + } + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } else { @@ -12184,7 +12533,7 @@ static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG * In case that ever happens we need an additional flag. */ iter->funcs->move_forward(iter); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } } @@ -12192,38 +12541,34 @@ static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG if (!iter || (iter->index > 0 && iter->funcs->valid(iter) == FAILURE)) { /* reached end of iteration */ if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } value = iter->funcs->get_current_data(iter); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } if (!value) { /* failure in get_current_data */ ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } - if (opline->extended_value & ZEND_FE_FETCH_BYREF) { - ZVAL_MAKE_REF(value); - Z_ADDREF_P(value); - ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); - } else { - ZVAL_COPY(EX_VAR(opline->result.var), value); - } - if (opline->extended_value & ZEND_FE_FETCH_WITH_KEY) { + if (opline->extended_value) { if (iter->funcs->get_current_key) { iter->funcs->get_current_key(iter, EX_VAR((opline+1)->result.var)); if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); + zval_ptr_dtor(array); HANDLE_EXCEPTION(); } } else { ZVAL_LONG(EX_VAR((opline+1)->result.var), iter->index); } } + ZVAL_MAKE_REF(value); + Z_ADDREF_P(value); + ZVAL_REF(EX_VAR(opline->result.var), Z_REF_P(value)); ZEND_VM_INC_OPCODE(); ZEND_VM_NEXT_OPCODE(); } @@ -24090,194 +24435,270 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDL ZEND_VM_NEXT_OPCODE(); } -static int ZEND_FASTCALL ZEND_FE_RESET_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +static int ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE - zval *array_ptr, *array_ref, iterator, tmp; + zval *array_ptr, *result; HashTable *fe_ht; - zend_object_iterator *iter = NULL; - zend_class_entry *ce = NULL; - zend_bool is_empty = 0; SAVE_OPLINE(); - if ((IS_CV == IS_CV || IS_CV == IS_VAR) && - (opline->extended_value & ZEND_FE_FETCH_BYREF)) { - array_ptr = array_ref = _get_zval_ptr_cv_BP_VAR_R(execute_data, opline->op1.var); - ZVAL_DEREF(array_ptr); - if (Z_TYPE_P(array_ptr) == IS_ARRAY) { - SEPARATE_ARRAY(array_ptr); - if (!Z_ISREF_P(array_ref)) { - ZVAL_NEW_REF(array_ref, array_ref); - array_ptr = Z_REFVAL_P(array_ref); - } - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce->get_iterator == NULL) { + array_ptr = _get_zval_ptr_cv_deref_BP_VAR_R(execute_data, opline->op1.var); + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_CV != IS_TMP_VAR && Z_OPT_REFCOUNTED_P(result)) { + Z_ADDREF_P(array_ptr); + } + Z_FE_POS_P(result) = 0; + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_CV != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + HashPosition pos = 0; + Bucket *p; + + result = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(result, array_ptr); + if (IS_CV != IS_TMP_VAR) { Z_ADDREF_P(array_ptr); } - array_ref = array_ptr; - } else { - if (Z_REFCOUNTED_P(array_ref)) Z_ADDREF_P(array_ref); - } - } else { - array_ptr = array_ref = _get_zval_ptr_cv_BP_VAR_R(execute_data, opline->op1.var); - if (IS_CV & (IS_VAR|IS_CV)) { - ZVAL_DEREF(array_ptr); - } - if (IS_CV == IS_TMP_VAR) { - ZVAL_COPY_VALUE(&tmp, array_ptr); - if (Z_OPT_IMMUTABLE_P(&tmp)) { - zval_copy_ctor_func(&tmp); + fe_ht = Z_OBJPROP_P(array_ptr); + pos = 0; + while (1) { + if (pos >= fe_ht->nNumUsed) { + + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; } - array_ref = array_ptr = &tmp; - if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (ce && ce->get_iterator) { - Z_DELREF_P(array_ref); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 0); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); } + zend_throw_exception_internal(NULL); + HANDLE_EXCEPTION(); } - } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { - ce = Z_OBJCE_P(array_ptr); - if (!ce->get_iterator) { - if (IS_CV == IS_CV) { - Z_ADDREF_P(array_ref); + + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + + HANDLE_EXCEPTION(); } } - } else if (Z_IMMUTABLE_P(array_ref)) { - if (IS_CV == IS_CV) { - zval_copy_ctor_func(array_ref); - Z_ADDREF_P(array_ref); + + is_empty = iter->funcs->valid(iter) != SUCCESS; + + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + + HANDLE_EXCEPTION(); + } + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } else { - ZVAL_COPY_VALUE(&tmp, array_ref); - zval_copy_ctor_func(&tmp); - array_ptr = array_ref = &tmp; - } - } else if (Z_REFCOUNTED_P(array_ref)) { - if (IS_CV == IS_CONST || - (IS_CV == IS_CV && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 1) || - (IS_CV == IS_VAR && - !Z_ISREF_P(array_ref) && - Z_REFCOUNT_P(array_ref) > 2)) { - if (IS_CV == IS_VAR) { - Z_DELREF_P(array_ref); - } - ZVAL_DUP(&tmp, array_ref); - array_ptr = array_ref = &tmp; - } else if (IS_CV == IS_CV || IS_CV == IS_VAR) { - if (Z_ISREF_P(array_ref) && Z_REFCOUNT_P(array_ref) == 1) { - ZVAL_UNREF(array_ref); - array_ptr = array_ref; - } - if (Z_IMMUTABLE_P(array_ptr)) { - zval_copy_ctor_func(array_ptr); - } else if (Z_ISREF_P(array_ref) && - Z_COPYABLE_P(array_ptr) && - Z_REFCOUNT_P(array_ptr) > 1) { - Z_DELREF_P(array_ptr); - zval_copy_ctor_func(array_ptr); - } - if (IS_CV == IS_CV) { - Z_ADDREF_P(array_ref); - } + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } } + } else { + zend_error(E_WARNING, "Invalid argument supplied for foreach()"); + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } +} + +static int ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + USE_OPLINE - if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_FETCH_BYREF); + zval *array_ptr, *array_ref; + HashTable *fe_ht; + HashPosition pos = 0; + Bucket *p; - if (IS_CV == IS_VAR && !(opline->extended_value & ZEND_FE_FETCH_BYREF)) { + SAVE_OPLINE(); + if (IS_CV == IS_VAR || IS_CV == IS_CV) { + array_ref = array_ptr = _get_zval_ptr_cv_BP_VAR_R(execute_data, opline->op1.var); + if (Z_ISREF_P(array_ref)) { + array_ptr = Z_REFVAL_P(array_ref); } - if (iter && EXPECTED(EG(exception) == NULL)) { - ZVAL_OBJ(&iterator, &iter->std); - array_ptr = array_ref = &iterator; + } else { + array_ref = array_ptr = _get_zval_ptr_cv_BP_VAR_R(execute_data, opline->op1.var); + } + + if (EXPECTED(Z_TYPE_P(array_ptr) == IS_ARRAY)) { + if (IS_CV == IS_VAR || IS_CV == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); } else { - if (IS_CV == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + if (IS_CV == IS_CONST) { + zval_copy_ctor_func(array_ptr); + } else { + SEPARATE_ARRAY(array_ptr); + } + fe_ht = Z_ARRVAL_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); } - if (!EG(exception)) { - zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); + p = fe_ht->arData + pos; + if (Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) { + break; } - zend_throw_exception_internal(NULL); - HANDLE_EXCEPTION(); + pos++; } - } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); - ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else if (IS_CV != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { + if (!Z_OBJCE_P(array_ptr)->get_iterator) { + if (IS_CV == IS_VAR || IS_CV == IS_CV) { + if (array_ptr == array_ref) { + ZVAL_NEW_REF(array_ref, array_ref); + array_ptr = Z_REFVAL_P(array_ref); + } + Z_ADDREF_P(array_ref); + ZVAL_COPY_VALUE(EX_VAR(opline->result.var), array_ref); + } else { + array_ptr = EX_VAR(opline->result.var); + ZVAL_COPY_VALUE(array_ptr, array_ref); + } + fe_ht = Z_OBJPROP_P(array_ptr); + while (1) { + if (pos >= fe_ht->nNumUsed) { - if (iter) { - iter->index = 0; - if (iter->funcs->rewind) { - iter->funcs->rewind(iter); - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_CV == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } + p = fe_ht->arData + pos; + if ((Z_TYPE(p->val) != IS_UNDEF && + (Z_TYPE(p->val) != IS_INDIRECT || + Z_TYPE_P(Z_INDIRECT(p->val)) != IS_UNDEF)) && + (!p->key || + zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS)) { + break; + } + pos++; + } + Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(fe_ht, pos); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); + } else { + zend_class_entry *ce = Z_OBJCE_P(array_ptr); + zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, 1); + zend_bool is_empty; + + if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + if (IS_CV == IS_VAR) { + + } else { + + } + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ce->name->val); } + zend_throw_exception_internal(NULL); HANDLE_EXCEPTION(); } - } - is_empty = iter->funcs->valid(iter) != SUCCESS; - if (UNEXPECTED(EG(exception) != NULL)) { - zval_ptr_dtor(array_ref); - if (IS_CV == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + iter->index = 0; + if (iter->funcs->rewind) { + iter->funcs->rewind(iter); + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (IS_CV == IS_VAR) { + + } else { + + } + HANDLE_EXCEPTION(); + } } - HANDLE_EXCEPTION(); - } - iter->index = -1; /* will be set to 0 before using next handler */ - } else if ((fe_ht = HASH_OF(array_ptr)) != NULL) { - HashPointer *ptr = (HashPointer*)EX_VAR((opline+2)->op1.var); - HashPosition pos = 0; - Bucket *p; - while (1) { - if (pos >= fe_ht->nNumUsed) { - is_empty = 1; - if (IS_CV == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + is_empty = iter->funcs->valid(iter) != SUCCESS; + + if (UNEXPECTED(EG(exception) != NULL)) { + OBJ_RELEASE(&iter->std); + if (IS_CV == IS_VAR) { + + } else { } - ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + HANDLE_EXCEPTION(); } - p = fe_ht->arData + pos; - if (Z_TYPE(p->val) == IS_UNDEF || - (Z_TYPE(p->val) == IS_INDIRECT && - Z_TYPE_P(Z_INDIRECT(p->val)) == IS_UNDEF)) { - pos++; - continue; + iter->index = -1; /* will be set to 0 before using next handler */ + + ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + + if (IS_CV == IS_VAR) { + + } else { + } - if (!ce || - !p->key || - zend_check_property_access(Z_OBJ_P(array_ptr), p->key) == SUCCESS) { - break; + if (is_empty) { + ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); + } else { + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); } - pos++; } - fe_ht->nInternalPointer = pos; - ptr->pos = pos; - ptr->ht = fe_ht; - ptr->h = fe_ht->arData[pos].h; - ptr->key = fe_ht->arData[pos].key; - is_empty = 0; } else { zend_error(E_WARNING, "Invalid argument supplied for foreach()"); - is_empty = 1; - } + ZVAL_UNDEF(EX_VAR(opline->result.var)); + Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; + if (IS_CV == IS_VAR) { - if (IS_CV == IS_VAR && opline->extended_value & ZEND_FE_FETCH_BYREF) { + } else { - } - if (is_empty) { + } ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2)); - } else { - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } } @@ -33006,6 +33427,21 @@ static int ZEND_FASTCALL ZEND_FREE_SPEC_TMPVAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS ZEND_VM_NEXT_OPCODE(); } +static int ZEND_FASTCALL ZEND_FE_FREE_SPEC_TMPVAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) +{ + zval *var; + USE_OPLINE + + SAVE_OPLINE(); + var = EX_VAR(opline->op1.var); + if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { + zend_hash_iterator_del(Z_FE_ITER_P(var)); + } + zval_ptr_dtor_nogc(var); + CHECK_EXCEPTION(); + ZEND_VM_NEXT_OPCODE(); +} + static int ZEND_FASTCALL ZEND_BOOL_SPEC_TMPVAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { USE_OPLINE @@ -38326,31 +38762,31 @@ void zend_init_opcodes_handlers(void) ZEND_UNSET_OBJ_SPEC_CV_TMPVAR_HANDLER, ZEND_NULL_HANDLER, ZEND_UNSET_OBJ_SPEC_CV_CV_HANDLER, - ZEND_FE_RESET_SPEC_CONST_HANDLER, - ZEND_FE_RESET_SPEC_CONST_HANDLER, - ZEND_FE_RESET_SPEC_CONST_HANDLER, - ZEND_FE_RESET_SPEC_CONST_HANDLER, - ZEND_FE_RESET_SPEC_CONST_HANDLER, - ZEND_FE_RESET_SPEC_TMP_HANDLER, - ZEND_FE_RESET_SPEC_TMP_HANDLER, - ZEND_FE_RESET_SPEC_TMP_HANDLER, - ZEND_FE_RESET_SPEC_TMP_HANDLER, - ZEND_FE_RESET_SPEC_TMP_HANDLER, - ZEND_FE_RESET_SPEC_VAR_HANDLER, - ZEND_FE_RESET_SPEC_VAR_HANDLER, - ZEND_FE_RESET_SPEC_VAR_HANDLER, - ZEND_FE_RESET_SPEC_VAR_HANDLER, - ZEND_FE_RESET_SPEC_VAR_HANDLER, + ZEND_FE_RESET_R_SPEC_CONST_HANDLER, + ZEND_FE_RESET_R_SPEC_CONST_HANDLER, + ZEND_FE_RESET_R_SPEC_CONST_HANDLER, + ZEND_FE_RESET_R_SPEC_CONST_HANDLER, + ZEND_FE_RESET_R_SPEC_CONST_HANDLER, + ZEND_FE_RESET_R_SPEC_TMP_HANDLER, + ZEND_FE_RESET_R_SPEC_TMP_HANDLER, + ZEND_FE_RESET_R_SPEC_TMP_HANDLER, + ZEND_FE_RESET_R_SPEC_TMP_HANDLER, + ZEND_FE_RESET_R_SPEC_TMP_HANDLER, + ZEND_FE_RESET_R_SPEC_VAR_HANDLER, + ZEND_FE_RESET_R_SPEC_VAR_HANDLER, + ZEND_FE_RESET_R_SPEC_VAR_HANDLER, + ZEND_FE_RESET_R_SPEC_VAR_HANDLER, + ZEND_FE_RESET_R_SPEC_VAR_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, - ZEND_FE_RESET_SPEC_CV_HANDLER, - ZEND_FE_RESET_SPEC_CV_HANDLER, - ZEND_FE_RESET_SPEC_CV_HANDLER, - ZEND_FE_RESET_SPEC_CV_HANDLER, - ZEND_FE_RESET_SPEC_CV_HANDLER, + ZEND_FE_RESET_R_SPEC_CV_HANDLER, + ZEND_FE_RESET_R_SPEC_CV_HANDLER, + ZEND_FE_RESET_R_SPEC_CV_HANDLER, + ZEND_FE_RESET_R_SPEC_CV_HANDLER, + ZEND_FE_RESET_R_SPEC_CV_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, @@ -38361,11 +38797,11 @@ void zend_init_opcodes_handlers(void) ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, - ZEND_FE_FETCH_SPEC_VAR_HANDLER, - ZEND_FE_FETCH_SPEC_VAR_HANDLER, - ZEND_FE_FETCH_SPEC_VAR_HANDLER, - ZEND_FE_FETCH_SPEC_VAR_HANDLER, - ZEND_FE_FETCH_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_R_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_R_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_R_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_R_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_R_SPEC_VAR_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, @@ -39526,11 +39962,31 @@ void zend_init_opcodes_handlers(void) ZEND_NULL_HANDLER, ZEND_VERIFY_RETURN_TYPE_SPEC_CV_UNUSED_HANDLER, ZEND_NULL_HANDLER, + ZEND_FE_RESET_RW_SPEC_CONST_HANDLER, + ZEND_FE_RESET_RW_SPEC_CONST_HANDLER, + ZEND_FE_RESET_RW_SPEC_CONST_HANDLER, + ZEND_FE_RESET_RW_SPEC_CONST_HANDLER, + ZEND_FE_RESET_RW_SPEC_CONST_HANDLER, + ZEND_FE_RESET_RW_SPEC_TMP_HANDLER, + ZEND_FE_RESET_RW_SPEC_TMP_HANDLER, + ZEND_FE_RESET_RW_SPEC_TMP_HANDLER, + ZEND_FE_RESET_RW_SPEC_TMP_HANDLER, + ZEND_FE_RESET_RW_SPEC_TMP_HANDLER, + ZEND_FE_RESET_RW_SPEC_VAR_HANDLER, + ZEND_FE_RESET_RW_SPEC_VAR_HANDLER, + ZEND_FE_RESET_RW_SPEC_VAR_HANDLER, + ZEND_FE_RESET_RW_SPEC_VAR_HANDLER, + ZEND_FE_RESET_RW_SPEC_VAR_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, + ZEND_FE_RESET_RW_SPEC_CV_HANDLER, + ZEND_FE_RESET_RW_SPEC_CV_HANDLER, + ZEND_FE_RESET_RW_SPEC_CV_HANDLER, + ZEND_FE_RESET_RW_SPEC_CV_HANDLER, + ZEND_FE_RESET_RW_SPEC_CV_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, @@ -39541,6 +39997,11 @@ void zend_init_opcodes_handlers(void) ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, + ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER, + ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, @@ -39556,41 +40017,16 @@ void zend_init_opcodes_handlers(void) ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, - ZEND_NULL_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, + ZEND_FE_FREE_SPEC_TMPVAR_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, ZEND_NULL_HANDLER, diff --git a/Zend/zend_vm_opcodes.c b/Zend/zend_vm_opcodes.c index c3006e6036938..d7c5db696685a 100644 --- a/Zend/zend_vm_opcodes.c +++ b/Zend/zend_vm_opcodes.c @@ -99,8 +99,8 @@ const char *zend_vm_opcodes_map[170] = { "ZEND_UNSET_VAR", "ZEND_UNSET_DIM", "ZEND_UNSET_OBJ", - "ZEND_FE_RESET", - "ZEND_FE_FETCH", + "ZEND_FE_RESET_R", + "ZEND_FE_FETCH_R", "ZEND_EXIT", "ZEND_FETCH_R", "ZEND_FETCH_DIM_R", @@ -147,9 +147,9 @@ const char *zend_vm_opcodes_map[170] = { "ZEND_DEFINED", "ZEND_TYPE_CHECK", "ZEND_VERIFY_RETURN_TYPE", - NULL, - NULL, - NULL, + "ZEND_FE_RESET_RW", + "ZEND_FE_FETCH_RW", + "ZEND_FE_FREE", NULL, NULL, NULL, diff --git a/Zend/zend_vm_opcodes.h b/Zend/zend_vm_opcodes.h index f0fc7c7182ee8..aa4afbd984bba 100644 --- a/Zend/zend_vm_opcodes.h +++ b/Zend/zend_vm_opcodes.h @@ -101,8 +101,8 @@ END_EXTERN_C() #define ZEND_UNSET_VAR 74 #define ZEND_UNSET_DIM 75 #define ZEND_UNSET_OBJ 76 -#define ZEND_FE_RESET 77 -#define ZEND_FE_FETCH 78 +#define ZEND_FE_RESET_R 77 +#define ZEND_FE_FETCH_R 78 #define ZEND_EXIT 79 #define ZEND_FETCH_R 80 #define ZEND_FETCH_DIM_R 81 @@ -149,6 +149,9 @@ END_EXTERN_C() #define ZEND_DEFINED 122 #define ZEND_TYPE_CHECK 123 #define ZEND_VERIFY_RETURN_TYPE 124 +#define ZEND_FE_RESET_RW 125 +#define ZEND_FE_FETCH_RW 126 +#define ZEND_FE_FREE 127 #define ZEND_PRE_INC_OBJ 132 #define ZEND_PRE_DEC_OBJ 133 #define ZEND_POST_INC_OBJ 134 diff --git a/ext/curl/interface.c b/ext/curl/interface.c index cb9e168a177c8..f7f6a5ed5f78f 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2004,12 +2004,13 @@ PHP_FUNCTION(curl_copy_handle) static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ */ { CURLcode error = CURLE_OK; + zend_long lval; switch (option) { /* Long options */ case CURLOPT_SSL_VERIFYHOST: - convert_to_long(zvalue); - if (Z_LVAL_P(zvalue) == 1) { + lval = zval_get_long(zvalue); + if (lval == 1) { #if LIBCURL_VERSION_NUM <= 0x071c00 /* 7.28.0 */ php_error_docref(NULL, E_NOTICE, "CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead"); #else @@ -2163,19 +2164,19 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ #if CURLOPT_MUTE != 0 case CURLOPT_MUTE: #endif - convert_to_long_ex(zvalue); + lval = zval_get_long(zvalue); #if LIBCURL_VERSION_NUM >= 0x71304 if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) && - (PG(open_basedir) && *PG(open_basedir)) && (Z_LVAL_P(zvalue) & CURLPROTO_FILE)) { + (PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) { php_error_docref(NULL, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set"); return 1; } #endif - error = curl_easy_setopt(ch->cp, option, Z_LVAL_P(zvalue)); + error = curl_easy_setopt(ch->cp, option, lval); break; case CURLOPT_SAFE_UPLOAD: - convert_to_long_ex(zvalue); - ch->safe_upload = (Z_LVAL_P(zvalue) != 0); + lval = zval_get_long(zvalue); + ch->safe_upload = (lval != 0); break; /* String options */ @@ -2236,8 +2237,10 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ case CURLOPT_MAIL_AUTH: #endif { - convert_to_string_ex(zvalue); - return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 0); + zend_string *str = zval_get_string(zvalue); + int ret = php_curl_option_str(ch, option, str->val, str->len, 0); + zend_string_release(str); + return ret; } /* Curl nullable string options */ @@ -2259,21 +2262,31 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ if (Z_ISNULL_P(zvalue)) { error = curl_easy_setopt(ch->cp, option, NULL); } else { - convert_to_string_ex(zvalue); - return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 0); + zend_string *str = zval_get_string(zvalue); + int ret = php_curl_option_str(ch, option, str->val, str->len, 0); + zend_string_release(str); + return ret; } break; } /* Curl private option */ case CURLOPT_PRIVATE: - convert_to_string_ex(zvalue); - return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 1); + { + zend_string *str = zval_get_string(zvalue); + int ret = php_curl_option_str(ch, option, str->val, str->len, 1); + zend_string_release(str); + return ret; + } /* Curl url option */ case CURLOPT_URL: - convert_to_string_ex(zvalue); - return php_curl_option_url(ch, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue)); + { + zend_string *str = zval_get_string(zvalue); + int ret = php_curl_option_url(ch, str->val, str->len); + zend_string_release(str); + return ret; + } /* Curl file handle options */ case CURLOPT_FILE: @@ -2450,16 +2463,16 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ break; case CURLOPT_FOLLOWLOCATION: - convert_to_long_ex(zvalue); + lval = zval_get_long(zvalue); #if LIBCURL_VERSION_NUM < 0x071304 if (PG(open_basedir) && *PG(open_basedir)) { - if (Z_LVAL_P(zvalue) != 0) { + if (lval != 0) { php_error_docref(NULL, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set"); return FAILURE; } } #endif - error = curl_easy_setopt(ch->cp, option, Z_LVAL_P(zvalue)); + error = curl_easy_setopt(ch->cp, option, lval); break; case CURLOPT_HEADERFUNCTION: @@ -2593,19 +2606,21 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first); } else { #if LIBCURL_VERSION_NUM >= 0x071101 - convert_to_string_ex(zvalue); + zend_string *str = zval_get_string(zvalue); /* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */ - error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_P(zvalue)); - error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, Z_STRVAL_P(zvalue)); + error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, str->len); + error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, str->val); + zend_string_release(str); #else char *post = NULL; + zend_string *str = zval_get_string(zvalue); - convert_to_string_ex(zvalue); - post = estrndup(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue)); + post = estrndup(str->val, str->len); zend_llist_add_element(&ch->to_free->str, &post); curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post); - error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, Z_STRLEN_P(zvalue)); + error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, str->len); + zend_string_release(str); #endif } break; @@ -2633,8 +2648,8 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ break; case CURLOPT_RETURNTRANSFER: - convert_to_long_ex(zvalue); - if (Z_LVAL_P(zvalue)) { + lval = zval_get_long(zvalue); + if (lval) { ch->handlers->write->method = PHP_CURL_RETURN; } else { ch->handlers->write->method = PHP_CURL_STDOUT; @@ -2653,15 +2668,15 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ #if LIBCURL_VERSION_NUM >= 0x070f05 /* Available since 7.15.5 */ case CURLOPT_MAX_RECV_SPEED_LARGE: case CURLOPT_MAX_SEND_SPEED_LARGE: - convert_to_long_ex(zvalue); - error = curl_easy_setopt(ch->cp, option, (curl_off_t)Z_LVAL_P(zvalue)); + lval = zval_get_long(zvalue); + error = curl_easy_setopt(ch->cp, option, (curl_off_t)lval); break; #endif #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */ case CURLOPT_POSTREDIR: - convert_to_long_ex(zvalue); - error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_P(zvalue) & CURL_REDIR_POST_ALL); + lval = zval_get_long(zvalue); + error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, lval & CURL_REDIR_POST_ALL); break; #endif @@ -2696,18 +2711,22 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ case CURLOPT_SSH_KNOWNHOSTS: #endif { - convert_to_string_ex(zvalue); + zend_string *str = zval_get_string(zvalue); + int ret; - if (Z_STRLEN_P(zvalue) && php_check_open_basedir(Z_STRVAL_P(zvalue))) { + if (str->len && php_check_open_basedir(str->val)) { + zend_string_release(str); return FAILURE; } - return php_curl_option_str(ch, option, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), 0); + ret = php_curl_option_str(ch, option, str->val, str->len, 0); + zend_string_release(str); + return ret; } case CURLINFO_HEADER_OUT: - convert_to_long_ex(zvalue); - if (Z_LVAL_P(zvalue) == 1) { + lval = zval_get_long(zvalue); + if (lval == 1) { curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug); curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch); curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1); diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index b6b66fc507451..04c7e3a40eeda 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -418,7 +418,7 @@ static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp) /* {{{ * HashTable *debug_info, *prop_handlers = obj->prop_handler, *std_props; - HashPosition pos; + zend_string *string_key; dom_prop_handler *entry; zval object_value; @@ -435,19 +435,10 @@ static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp) /* {{{ * ZVAL_STRING(&object_value, "(object value omitted)"); - for (zend_hash_internal_pointer_reset_ex(prop_handlers, &pos); - (entry = zend_hash_get_current_data_ptr_ex(prop_handlers, &pos)) != NULL; - zend_hash_move_forward_ex(prop_handlers, &pos)) { + ZEND_HASH_FOREACH_STR_KEY_PTR(prop_handlers, string_key, entry) { zval value; - zend_string *string_key; - zend_ulong num_key; - if (entry->read_func(obj, &value) == FAILURE) { - continue; - } - - if (zend_hash_get_current_key_ex(prop_handlers, &string_key, - &num_key, &pos) != HASH_KEY_IS_STRING) { + if (entry->read_func(obj, &value) == FAILURE || !string_key) { continue; } @@ -457,7 +448,7 @@ static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp) /* {{{ * } zend_hash_add(debug_info, string_key, &value); - } + } ZEND_HASH_FOREACH_END(); zval_dtor(&object_value); diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index e7a3ed7648e8c..1fb6574695a46 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -520,14 +520,12 @@ PHP_FUNCTION(dom_xpath_register_php_functions) if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a", &array_value) == SUCCESS) { intern = Z_XPATHOBJ_P(id); - zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value)); - while ((entry = zend_hash_get_current_data(Z_ARRVAL_P(array_value)))) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array_value), entry) { zend_string *str = zval_get_string(entry); ZVAL_LONG(&new_string,1); zend_hash_update(intern->registered_phpfunctions, str, &new_string); - zend_hash_move_forward(Z_ARRVAL_P(array_value)); zend_string_release(str); - } + } ZEND_HASH_FOREACH_END(); intern->registerPhpFunctions = 2; RETURN_TRUE; diff --git a/ext/fileinfo/libmagic.patch b/ext/fileinfo/libmagic.patch index e1f2aa52fba97..ac407e5dcea9a 100644 --- a/ext/fileinfo/libmagic.patch +++ b/ext/fileinfo/libmagic.patch @@ -2192,7 +2192,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c + zval_ptr_dtor(&patt); + + ZVAL_STRING(&repl, rep); -+ res = php_pcre_replace_impl(pce, ms->o.buf, strlen(ms->o.buf), &repl, 0, -1, &rep_cnt); ++ res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), &repl, 0, -1, &rep_cnt); + + zval_ptr_dtor(&repl); + if (NULL == res) { diff --git a/ext/fileinfo/libmagic/funcs.c b/ext/fileinfo/libmagic/funcs.c index 4df0a2a496b33..82f4cd38cd69b 100644 --- a/ext/fileinfo/libmagic/funcs.c +++ b/ext/fileinfo/libmagic/funcs.c @@ -457,7 +457,7 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep) zval_ptr_dtor(&patt); ZVAL_STRING(&repl, rep); - res = php_pcre_replace_impl(pce, ms->o.buf, strlen(ms->o.buf), &repl, 0, -1, &rep_cnt); + res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), &repl, 0, -1, &rep_cnt); zval_ptr_dtor(&repl); if (NULL == res) { diff --git a/ext/json/json_scanner.c b/ext/json/json_scanner.c index 2cfd8b84bea0b..c75a1e02e8a89 100644 --- a/ext/json/json_scanner.c +++ b/ext/json/json_scanner.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 */ +/* Generated by re2c 0.13.6 */ /* +----------------------------------------------------------------------+ | PHP Version 5 | @@ -82,7 +82,7 @@ static int php_json_ucs2_to_int(php_json_scanner *s, int size) return php_json_ucs2_to_int_ex(s, size, 1); } -void php_json_scanner_init(php_json_scanner *s, char *str, int str_len, long options) +void php_json_scanner_init(php_json_scanner *s, char *str, size_t str_len, int options) { s->cursor = (php_json_ctype *) str; s->limit = (php_json_ctype *) str + str_len; @@ -147,56 +147,55 @@ int php_json_scan(php_json_scanner *s) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - yych = *YYCURSOR; if (yych <= '9') { if (yych <= ' ') { if (yych <= '\n') { - if (yych <= 0x00) goto yy2; - if (yych <= 0x08) goto yy4; - if (yych <= '\t') goto yy6; - goto yy8; + if (yych <= 0x00) goto yy3; + if (yych <= 0x08) goto yy5; + if (yych <= '\t') goto yy7; + goto yy9; } else { - if (yych == '\r') goto yy9; - if (yych <= 0x1F) goto yy4; - goto yy6; + if (yych == '\r') goto yy10; + if (yych <= 0x1F) goto yy5; + goto yy7; } } else { if (yych <= ',') { - if (yych == '"') goto yy10; - if (yych <= '+') goto yy4; - goto yy12; + if (yych == '"') goto yy11; + if (yych <= '+') goto yy5; + goto yy13; } else { - if (yych <= '-') goto yy14; - if (yych <= '/') goto yy4; - if (yych <= '0') goto yy15; - goto yy17; + if (yych <= '-') goto yy15; + if (yych <= '/') goto yy5; + if (yych <= '0') goto yy16; + goto yy18; } } } else { if (yych <= 'm') { if (yych <= '\\') { - if (yych <= ':') goto yy18; - if (yych == '[') goto yy20; - goto yy4; + if (yych <= ':') goto yy19; + if (yych == '[') goto yy21; + goto yy5; } else { - if (yych <= ']') goto yy22; - if (yych == 'f') goto yy24; - goto yy4; + if (yych <= ']') goto yy23; + if (yych == 'f') goto yy25; + goto yy5; } } else { if (yych <= 'z') { - if (yych <= 'n') goto yy25; - if (yych == 't') goto yy26; - goto yy4; + if (yych <= 'n') goto yy26; + if (yych == 't') goto yy27; + goto yy5; } else { - if (yych <= '{') goto yy27; - if (yych == '}') goto yy29; - goto yy4; + if (yych <= '{') goto yy28; + if (yych == '}') goto yy30; + goto yy5; } } } -yy2: +yy3: ++YYCURSOR; { if (s->limit < s->cursor) { @@ -206,27 +205,27 @@ int php_json_scan(php_json_scanner *s) return PHP_JSON_T_ERROR; } } -yy4: - ++YYCURSOR; yy5: + ++YYCURSOR; +yy6: { s->errcode = PHP_JSON_ERROR_SYNTAX; return PHP_JSON_T_ERROR; } -yy6: +yy7: ++YYCURSOR; yych = *YYCURSOR; - goto yy57; -yy7: - { goto std; } + goto yy58; yy8: - yych = *++YYCURSOR; - goto yy7; + { goto std; } yy9: yych = *++YYCURSOR; - if (yych == '\n') goto yy58; - goto yy57; + goto yy8; yy10: + yych = *++YYCURSOR; + if (yych == '\n') goto yy59; + goto yy58; +yy11: ++YYCURSOR; { s->str_start = s->cursor; @@ -234,25 +233,25 @@ int php_json_scan(php_json_scanner *s) PHP_JSON_CONDITION_SET(STR_P1); PHP_JSON_CONDITION_GOTO(STR_P1); } -yy12: +yy13: ++YYCURSOR; { return ','; } -yy14: - yych = *++YYCURSOR; - if (yych <= '/') goto yy5; - if (yych <= '0') goto yy55; - if (yych <= '9') goto yy45; - goto yy5; yy15: + yych = *++YYCURSOR; + if (yych <= '/') goto yy6; + if (yych <= '0') goto yy56; + if (yych <= '9') goto yy46; + goto yy6; +yy16: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= 'D') { - if (yych == '.') goto yy47; + if (yych == '.') goto yy48; } else { - if (yych <= 'E') goto yy48; - if (yych == 'e') goto yy48; + if (yych <= 'E') goto yy49; + if (yych == 'e') goto yy49; } -yy16: +yy17: { zend_bool bigint = 0, negative = s->token[0] == '-'; size_t digits = (size_t) (s->cursor - s->token - negative); @@ -267,7 +266,7 @@ int php_json_scan(php_json_scanner *s) } } if (!bigint) { - ZVAL_LONG(&s->value, strtol((char *) s->token, NULL, 10)); + ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10)); return PHP_JSON_T_INT; } else if (s->options & PHP_JSON_BIGINT_AS_STRING) { ZVAL_STRINGL(&s->value, (char *) s->token, s->cursor - s->token); @@ -277,203 +276,203 @@ int php_json_scan(php_json_scanner *s) return PHP_JSON_T_DOUBLE; } } -yy17: +yy18: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - goto yy46; -yy18: + goto yy47; +yy19: ++YYCURSOR; { return ':'; } -yy20: +yy21: ++YYCURSOR; { return '['; } -yy22: +yy23: ++YYCURSOR; { return ']'; } -yy24: - yyaccept = 1; - yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'a') goto yy40; - goto yy5; yy25: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'u') goto yy36; - goto yy5; + if (yych == 'a') goto yy41; + goto yy6; yy26: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'r') goto yy31; - goto yy5; + if (yych == 'u') goto yy37; + goto yy6; yy27: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'r') goto yy32; + goto yy6; +yy28: ++YYCURSOR; { return '{'; } -yy29: +yy30: ++YYCURSOR; { return '}'; } -yy31: - yych = *++YYCURSOR; - if (yych == 'u') goto yy33; yy32: + yych = *++YYCURSOR; + if (yych == 'u') goto yy34; +yy33: YYCURSOR = YYMARKER; if (yyaccept <= 1) { - if (yyaccept <= 0) { - goto yy16; + if (yyaccept == 0) { + goto yy17; } else { - goto yy5; + goto yy6; } } else { - goto yy52; + goto yy53; } -yy33: +yy34: yych = *++YYCURSOR; - if (yych != 'e') goto yy32; + if (yych != 'e') goto yy33; ++YYCURSOR; { ZVAL_TRUE(&s->value); return PHP_JSON_T_TRUE; } -yy36: +yy37: yych = *++YYCURSOR; - if (yych != 'l') goto yy32; + if (yych != 'l') goto yy33; yych = *++YYCURSOR; - if (yych != 'l') goto yy32; + if (yych != 'l') goto yy33; ++YYCURSOR; { ZVAL_NULL(&s->value); return PHP_JSON_T_NUL; } -yy40: +yy41: yych = *++YYCURSOR; - if (yych != 'l') goto yy32; + if (yych != 'l') goto yy33; yych = *++YYCURSOR; - if (yych != 's') goto yy32; + if (yych != 's') goto yy33; yych = *++YYCURSOR; - if (yych != 'e') goto yy32; + if (yych != 'e') goto yy33; ++YYCURSOR; { ZVAL_FALSE(&s->value); return PHP_JSON_T_FALSE; } -yy45: +yy46: yyaccept = 0; YYMARKER = ++YYCURSOR; yych = *YYCURSOR; -yy46: +yy47: if (yybm[0+yych] & 64) { - goto yy45; + goto yy46; } if (yych <= 'D') { - if (yych != '.') goto yy16; + if (yych != '.') goto yy17; } else { - if (yych <= 'E') goto yy48; - if (yych == 'e') goto yy48; - goto yy16; + if (yych <= 'E') goto yy49; + if (yych == 'e') goto yy49; + goto yy17; } -yy47: - yych = *++YYCURSOR; - if (yych <= '/') goto yy32; - if (yych <= '9') goto yy53; - goto yy32; yy48: + yych = *++YYCURSOR; + if (yych <= '/') goto yy33; + if (yych <= '9') goto yy54; + goto yy33; +yy49: yych = *++YYCURSOR; if (yych <= ',') { - if (yych != '+') goto yy32; + if (yych != '+') goto yy33; } else { - if (yych <= '-') goto yy49; - if (yych <= '/') goto yy32; - if (yych <= '9') goto yy50; - goto yy32; + if (yych <= '-') goto yy50; + if (yych <= '/') goto yy33; + if (yych <= '9') goto yy51; + goto yy33; } -yy49: - yych = *++YYCURSOR; - if (yych <= '/') goto yy32; - if (yych >= ':') goto yy32; yy50: + yych = *++YYCURSOR; + if (yych <= '/') goto yy33; + if (yych >= ':') goto yy33; +yy51: ++YYCURSOR; yych = *YYCURSOR; - if (yych <= '/') goto yy52; - if (yych <= '9') goto yy50; -yy52: + if (yych <= '/') goto yy53; + if (yych <= '9') goto yy51; +yy53: { ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL)); return PHP_JSON_T_DOUBLE; } -yy53: +yy54: yyaccept = 2; YYMARKER = ++YYCURSOR; yych = *YYCURSOR; if (yych <= 'D') { - if (yych <= '/') goto yy52; - if (yych <= '9') goto yy53; - goto yy52; + if (yych <= '/') goto yy53; + if (yych <= '9') goto yy54; + goto yy53; } else { - if (yych <= 'E') goto yy48; - if (yych == 'e') goto yy48; - goto yy52; + if (yych <= 'E') goto yy49; + if (yych == 'e') goto yy49; + goto yy53; } -yy55: +yy56: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= 'D') { - if (yych == '.') goto yy47; - goto yy16; + if (yych == '.') goto yy48; + goto yy17; } else { - if (yych <= 'E') goto yy48; - if (yych == 'e') goto yy48; - goto yy16; + if (yych <= 'E') goto yy49; + if (yych == 'e') goto yy49; + goto yy17; } -yy56: +yy57: ++YYCURSOR; yych = *YYCURSOR; -yy57: +yy58: if (yybm[0+yych] & 128) { - goto yy56; + goto yy57; } - goto yy7; -yy58: + goto yy8; +yy59: ++YYCURSOR; yych = *YYCURSOR; - goto yy7; + goto yy8; } /* *********************************** */ yyc_STR_P1: yych = *YYCURSOR; if (yych <= 0xDF) { if (yych <= '[') { - if (yych <= 0x1F) goto yy61; - if (yych == '"') goto yy65; - goto yy63; + if (yych <= 0x1F) goto yy62; + if (yych == '"') goto yy66; + goto yy64; } else { - if (yych <= '\\') goto yy67; - if (yych <= 0x7F) goto yy63; - if (yych <= 0xC1) goto yy69; - goto yy71; + if (yych <= '\\') goto yy68; + if (yych <= 0x7F) goto yy64; + if (yych <= 0xC1) goto yy70; + goto yy72; } } else { if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy72; - if (yych <= 0xEC) goto yy73; - if (yych <= 0xED) goto yy74; - goto yy75; + if (yych <= 0xE0) goto yy73; + if (yych <= 0xEC) goto yy74; + if (yych <= 0xED) goto yy75; + goto yy76; } else { - if (yych <= 0xF0) goto yy76; - if (yych <= 0xF3) goto yy77; - if (yych <= 0xF4) goto yy78; - goto yy69; + if (yych <= 0xF0) goto yy77; + if (yych <= 0xF3) goto yy78; + if (yych <= 0xF4) goto yy79; + goto yy70; } } -yy61: +yy62: ++YYCURSOR; { s->errcode = PHP_JSON_ERROR_CTRL_CHAR; return PHP_JSON_T_ERROR; } -yy63: - ++YYCURSOR; yy64: - { PHP_JSON_CONDITION_GOTO(STR_P1); } + ++YYCURSOR; yy65: + { PHP_JSON_CONDITION_GOTO(STR_P1); } +yy66: ++YYCURSOR; { zend_string *str; @@ -497,361 +496,361 @@ int php_json_scan(php_json_scanner *s) return PHP_JSON_T_STRING; } } -yy67: +yy68: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= 'e') { if (yych <= '/') { - if (yych == '"') goto yy91; - if (yych >= '/') goto yy91; + if (yych == '"') goto yy92; + if (yych >= '/') goto yy92; } else { if (yych <= '\\') { - if (yych >= '\\') goto yy91; + if (yych >= '\\') goto yy92; } else { - if (yych == 'b') goto yy91; + if (yych == 'b') goto yy92; } } } else { if (yych <= 'q') { - if (yych <= 'f') goto yy91; - if (yych == 'n') goto yy91; + if (yych <= 'f') goto yy92; + if (yych == 'n') goto yy92; } else { if (yych <= 's') { - if (yych <= 'r') goto yy91; + if (yych <= 'r') goto yy92; } else { - if (yych <= 't') goto yy91; - if (yych <= 'u') goto yy93; + if (yych <= 't') goto yy92; + if (yych <= 'u') goto yy94; } } } -yy68: +yy69: { s->errcode = PHP_JSON_ERROR_SYNTAX; return PHP_JSON_T_ERROR; } -yy69: - ++YYCURSOR; yy70: + ++YYCURSOR; +yy71: { s->errcode = PHP_JSON_ERROR_UTF8; return PHP_JSON_T_ERROR; } -yy71: - yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy70; - if (yych <= 0xBF) goto yy82; - goto yy70; yy72: - yyaccept = 1; - yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x9F) goto yy70; - if (yych <= 0xBF) goto yy90; - goto yy70; + yych = *++YYCURSOR; + if (yych <= 0x7F) goto yy71; + if (yych <= 0xBF) goto yy83; + goto yy71; yy73: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x7F) goto yy70; - if (yych <= 0xBF) goto yy89; - goto yy70; + if (yych <= 0x9F) goto yy71; + if (yych <= 0xBF) goto yy91; + goto yy71; yy74: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x7F) goto yy70; - if (yych <= 0x9F) goto yy88; - goto yy70; + if (yych <= 0x7F) goto yy71; + if (yych <= 0xBF) goto yy90; + goto yy71; yy75: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x7F) goto yy70; - if (yych <= 0xBF) goto yy87; - goto yy70; + if (yych <= 0x7F) goto yy71; + if (yych <= 0x9F) goto yy89; + goto yy71; yy76: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x8F) goto yy70; - if (yych <= 0xBF) goto yy85; - goto yy70; + if (yych <= 0x7F) goto yy71; + if (yych <= 0xBF) goto yy88; + goto yy71; yy77: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x7F) goto yy70; - if (yych <= 0xBF) goto yy83; - goto yy70; + if (yych <= 0x8F) goto yy71; + if (yych <= 0xBF) goto yy86; + goto yy71; yy78: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x7F) goto yy70; - if (yych >= 0x90) goto yy70; + if (yych <= 0x7F) goto yy71; + if (yych <= 0xBF) goto yy84; + goto yy71; +yy79: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= 0x7F) goto yy71; + if (yych >= 0x90) goto yy71; yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych <= 0xBF) goto yy81; -yy80: + if (yych <= 0x7F) goto yy81; + if (yych <= 0xBF) goto yy82; +yy81: YYCURSOR = YYMARKER; if (yyaccept <= 1) { - if (yyaccept <= 0) { - goto yy68; + if (yyaccept == 0) { + goto yy69; } else { - goto yy70; + goto yy71; } } else { - goto yy100; + goto yy101; } -yy81: - yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych >= 0xC0) goto yy80; yy82: yych = *++YYCURSOR; - goto yy64; + if (yych <= 0x7F) goto yy81; + if (yych >= 0xC0) goto yy81; yy83: yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych >= 0xC0) goto yy80; + goto yy65; +yy84: yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych <= 0xBF) goto yy82; - goto yy80; -yy85: + if (yych <= 0x7F) goto yy81; + if (yych >= 0xC0) goto yy81; yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych >= 0xC0) goto yy80; + if (yych <= 0x7F) goto yy81; + if (yych <= 0xBF) goto yy83; + goto yy81; +yy86: yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych <= 0xBF) goto yy82; - goto yy80; -yy87: + if (yych <= 0x7F) goto yy81; + if (yych >= 0xC0) goto yy81; yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych <= 0xBF) goto yy82; - goto yy80; + if (yych <= 0x7F) goto yy81; + if (yych <= 0xBF) goto yy83; + goto yy81; yy88: yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych <= 0xBF) goto yy82; - goto yy80; + if (yych <= 0x7F) goto yy81; + if (yych <= 0xBF) goto yy83; + goto yy81; yy89: yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych <= 0xBF) goto yy82; - goto yy80; + if (yych <= 0x7F) goto yy81; + if (yych <= 0xBF) goto yy83; + goto yy81; yy90: yych = *++YYCURSOR; - if (yych <= 0x7F) goto yy80; - if (yych <= 0xBF) goto yy82; - goto yy80; + if (yych <= 0x7F) goto yy81; + if (yych <= 0xBF) goto yy83; + goto yy81; yy91: + yych = *++YYCURSOR; + if (yych <= 0x7F) goto yy81; + if (yych <= 0xBF) goto yy83; + goto yy81; +yy92: ++YYCURSOR; { s->str_esc++; PHP_JSON_CONDITION_GOTO(STR_P1); } -yy93: +yy94: yych = *++YYCURSOR; if (yych <= 'D') { if (yych <= '9') { - if (yych <= '/') goto yy80; - if (yych >= '1') goto yy96; + if (yych <= '/') goto yy81; + if (yych >= '1') goto yy97; } else { - if (yych <= '@') goto yy80; - if (yych <= 'C') goto yy96; - goto yy95; + if (yych <= '@') goto yy81; + if (yych <= 'C') goto yy97; + goto yy96; } } else { if (yych <= 'c') { - if (yych <= 'F') goto yy96; - if (yych <= '`') goto yy80; - goto yy96; + if (yych <= 'F') goto yy97; + if (yych <= '`') goto yy81; + goto yy97; } else { - if (yych <= 'd') goto yy95; - if (yych <= 'f') goto yy96; - goto yy80; + if (yych <= 'd') goto yy96; + if (yych <= 'f') goto yy97; + goto yy81; } } yych = *++YYCURSOR; if (yych <= '9') { - if (yych <= '/') goto yy80; - if (yych <= '0') goto yy111; - if (yych <= '7') goto yy112; - goto yy97; + if (yych <= '/') goto yy81; + if (yych <= '0') goto yy112; + if (yych <= '7') goto yy113; + goto yy98; } else { if (yych <= 'F') { - if (yych <= '@') goto yy80; - goto yy97; + if (yych <= '@') goto yy81; + goto yy98; } else { - if (yych <= '`') goto yy80; - if (yych <= 'f') goto yy97; - goto yy80; + if (yych <= '`') goto yy81; + if (yych <= 'f') goto yy98; + goto yy81; } } -yy95: +yy96: yych = *++YYCURSOR; if (yych <= 'B') { if (yych <= '7') { - if (yych <= '/') goto yy80; - goto yy97; + if (yych <= '/') goto yy81; + goto yy98; } else { - if (yych <= '9') goto yy101; - if (yych <= '@') goto yy80; - goto yy101; + if (yych <= '9') goto yy102; + if (yych <= '@') goto yy81; + goto yy102; } } else { if (yych <= '`') { - if (yych <= 'F') goto yy97; - goto yy80; + if (yych <= 'F') goto yy98; + goto yy81; } else { - if (yych <= 'b') goto yy101; - if (yych <= 'f') goto yy97; - goto yy80; + if (yych <= 'b') goto yy102; + if (yych <= 'f') goto yy98; + goto yy81; } } -yy96: - yych = *++YYCURSOR; - if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; - } else { - if (yych <= 'F') goto yy97; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; - } yy97: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; } else { if (yych <= 'F') goto yy98; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; } yy98: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; } else { if (yych <= 'F') goto yy99; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; } yy99: - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych <= '@') { + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; + } else { + if (yych <= 'F') goto yy100; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; + } yy100: + ++YYCURSOR; +yy101: { s->str_esc += 3; PHP_JSON_CONDITION_GOTO(STR_P1); } -yy101: +yy102: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; } else { - if (yych <= 'F') goto yy102; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= 'F') goto yy103; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; } -yy102: +yy103: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; } else { - if (yych <= 'F') goto yy103; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= 'F') goto yy104; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; } -yy103: +yy104: yyaccept = 2; yych = *(YYMARKER = ++YYCURSOR); - if (yych != '\\') goto yy100; - yych = *++YYCURSOR; - if (yych != 'u') goto yy80; + if (yych != '\\') goto yy101; yych = *++YYCURSOR; - if (yych == 'D') goto yy106; - if (yych != 'd') goto yy80; -yy106: + if (yych != 'u') goto yy81; yych = *++YYCURSOR; - if (yych <= 'B') goto yy80; - if (yych <= 'F') goto yy107; - if (yych <= 'b') goto yy80; - if (yych >= 'g') goto yy80; + if (yych == 'D') goto yy107; + if (yych != 'd') goto yy81; yy107: yych = *++YYCURSOR; - if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; - } else { - if (yych <= 'F') goto yy108; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; - } + if (yych <= 'B') goto yy81; + if (yych <= 'F') goto yy108; + if (yych <= 'b') goto yy81; + if (yych >= 'g') goto yy81; yy108: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; } else { if (yych <= 'F') goto yy109; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; } yy109: + yych = *++YYCURSOR; + if (yych <= '@') { + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; + } else { + if (yych <= 'F') goto yy110; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; + } +yy110: ++YYCURSOR; { s->str_esc += 8; PHP_JSON_CONDITION_GOTO(STR_P1); } -yy111: - yych = *++YYCURSOR; - if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych <= '7') goto yy116; - if (yych <= '9') goto yy113; - goto yy80; - } else { - if (yych <= 'F') goto yy113; - if (yych <= '`') goto yy80; - if (yych <= 'f') goto yy113; - goto yy80; - } yy112: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych <= '7') goto yy117; + if (yych <= '9') goto yy114; + goto yy81; } else { - if (yych <= 'F') goto yy113; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= 'F') goto yy114; + if (yych <= '`') goto yy81; + if (yych <= 'f') goto yy114; + goto yy81; } yy113: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; } else { if (yych <= 'F') goto yy114; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; } yy114: + yych = *++YYCURSOR; + if (yych <= '@') { + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; + } else { + if (yych <= 'F') goto yy115; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; + } +yy115: ++YYCURSOR; { s->str_esc += 4; PHP_JSON_CONDITION_GOTO(STR_P1); } -yy116: +yy117: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy80; - if (yych >= ':') goto yy80; + if (yych <= '/') goto yy81; + if (yych >= ':') goto yy81; } else { - if (yych <= 'F') goto yy117; - if (yych <= '`') goto yy80; - if (yych >= 'g') goto yy80; + if (yych <= 'F') goto yy118; + if (yych <= '`') goto yy81; + if (yych >= 'g') goto yy81; } -yy117: +yy118: ++YYCURSOR; { s->str_esc += 5; @@ -860,22 +859,22 @@ int php_json_scan(php_json_scanner *s) /* *********************************** */ yyc_STR_P2: yych = *YYCURSOR; - if (yych == '"') goto yy123; - if (yych == '\\') goto yy125; + if (yych == '"') goto yy124; + if (yych == '\\') goto yy126; ++YYCURSOR; { PHP_JSON_CONDITION_GOTO(STR_P2); } -yy123: +yy124: ++YYCURSOR; YYSETCONDITION(yycJS); { PHP_JSON_SCANNER_COPY_ESC(); return PHP_JSON_T_STRING; } -yy125: +yy126: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if (yych == 'u') goto yy127; -yy126: + if (yych == 'u') goto yy128; +yy127: { char esc; PHP_JSON_SCANNER_COPY_ESC(); @@ -909,105 +908,105 @@ int php_json_scan(php_json_scanner *s) s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO(STR_P2); } -yy127: +yy128: yych = *++YYCURSOR; if (yych <= 'D') { if (yych <= '9') { - if (yych <= '/') goto yy128; - if (yych <= '0') goto yy129; - goto yy131; + if (yych <= '/') goto yy129; + if (yych <= '0') goto yy130; + goto yy132; } else { - if (yych <= '@') goto yy128; - if (yych <= 'C') goto yy131; - goto yy130; + if (yych <= '@') goto yy129; + if (yych <= 'C') goto yy132; + goto yy131; } } else { if (yych <= 'c') { - if (yych <= 'F') goto yy131; - if (yych >= 'a') goto yy131; + if (yych <= 'F') goto yy132; + if (yych >= 'a') goto yy132; } else { - if (yych <= 'd') goto yy130; - if (yych <= 'f') goto yy131; + if (yych <= 'd') goto yy131; + if (yych <= 'f') goto yy132; } } -yy128: +yy129: YYCURSOR = YYMARKER; - if (yyaccept <= 0) { - goto yy126; + if (yyaccept == 0) { + goto yy127; } else { - goto yy135; + goto yy136; } -yy129: +yy130: yych = *++YYCURSOR; if (yych <= '9') { - if (yych <= '/') goto yy128; - if (yych <= '0') goto yy146; - if (yych <= '7') goto yy147; - goto yy132; + if (yych <= '/') goto yy129; + if (yych <= '0') goto yy147; + if (yych <= '7') goto yy148; + goto yy133; } else { if (yych <= 'F') { - if (yych <= '@') goto yy128; - goto yy132; + if (yych <= '@') goto yy129; + goto yy133; } else { - if (yych <= '`') goto yy128; - if (yych <= 'f') goto yy132; - goto yy128; + if (yych <= '`') goto yy129; + if (yych <= 'f') goto yy133; + goto yy129; } } -yy130: +yy131: yych = *++YYCURSOR; if (yych <= 'B') { if (yych <= '7') { - if (yych <= '/') goto yy128; - goto yy132; + if (yych <= '/') goto yy129; + goto yy133; } else { - if (yych <= '9') goto yy136; - if (yych <= '@') goto yy128; - goto yy136; + if (yych <= '9') goto yy137; + if (yych <= '@') goto yy129; + goto yy137; } } else { if (yych <= '`') { - if (yych <= 'F') goto yy132; - goto yy128; + if (yych <= 'F') goto yy133; + goto yy129; } else { - if (yych <= 'b') goto yy136; - if (yych <= 'f') goto yy132; - goto yy128; + if (yych <= 'b') goto yy137; + if (yych <= 'f') goto yy133; + goto yy129; } } -yy131: - yych = *++YYCURSOR; - if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; - } else { - if (yych <= 'F') goto yy132; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; - } yy132: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; } else { if (yych <= 'F') goto yy133; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; } yy133: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; } else { if (yych <= 'F') goto yy134; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; } yy134: - ++YYCURSOR; + yych = *++YYCURSOR; + if (yych <= '@') { + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; + } else { + if (yych <= 'F') goto yy135; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; + } yy135: + ++YYCURSOR; +yy136: { int utf16 = php_json_ucs2_to_int(s, 4); PHP_JSON_SCANNER_COPY_UTF(); @@ -1017,62 +1016,62 @@ int php_json_scan(php_json_scanner *s) s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO(STR_P2); } -yy136: +yy137: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; } else { - if (yych <= 'F') goto yy137; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= 'F') goto yy138; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; } -yy137: +yy138: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; } else { - if (yych <= 'F') goto yy138; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= 'F') goto yy139; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; } -yy138: +yy139: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if (yych != '\\') goto yy135; - yych = *++YYCURSOR; - if (yych != 'u') goto yy128; + if (yych != '\\') goto yy136; yych = *++YYCURSOR; - if (yych == 'D') goto yy141; - if (yych != 'd') goto yy128; -yy141: + if (yych != 'u') goto yy129; yych = *++YYCURSOR; - if (yych <= 'B') goto yy128; - if (yych <= 'F') goto yy142; - if (yych <= 'b') goto yy128; - if (yych >= 'g') goto yy128; + if (yych == 'D') goto yy142; + if (yych != 'd') goto yy129; yy142: yych = *++YYCURSOR; - if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; - } else { - if (yych <= 'F') goto yy143; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; - } + if (yych <= 'B') goto yy129; + if (yych <= 'F') goto yy143; + if (yych <= 'b') goto yy129; + if (yych >= 'g') goto yy129; yy143: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; } else { if (yych <= 'F') goto yy144; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; } yy144: + yych = *++YYCURSOR; + if (yych <= '@') { + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; + } else { + if (yych <= 'F') goto yy145; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; + } +yy145: ++YYCURSOR; { int utf32, utf16_hi, utf16_lo; @@ -1087,40 +1086,40 @@ int php_json_scan(php_json_scanner *s) s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO(STR_P2); } -yy146: - yych = *++YYCURSOR; - if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych <= '7') goto yy151; - if (yych <= '9') goto yy148; - goto yy128; - } else { - if (yych <= 'F') goto yy148; - if (yych <= '`') goto yy128; - if (yych <= 'f') goto yy148; - goto yy128; - } yy147: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych <= '7') goto yy152; + if (yych <= '9') goto yy149; + goto yy129; } else { - if (yych <= 'F') goto yy148; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= 'F') goto yy149; + if (yych <= '`') goto yy129; + if (yych <= 'f') goto yy149; + goto yy129; } yy148: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; } else { if (yych <= 'F') goto yy149; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; } yy149: + yych = *++YYCURSOR; + if (yych <= '@') { + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; + } else { + if (yych <= 'F') goto yy150; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; + } +yy150: ++YYCURSOR; { int utf16 = php_json_ucs2_to_int(s, 3); @@ -1130,17 +1129,17 @@ int php_json_scan(php_json_scanner *s) s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO(STR_P2); } -yy151: +yy152: yych = *++YYCURSOR; if (yych <= '@') { - if (yych <= '/') goto yy128; - if (yych >= ':') goto yy128; + if (yych <= '/') goto yy129; + if (yych >= ':') goto yy129; } else { - if (yych <= 'F') goto yy152; - if (yych <= '`') goto yy128; - if (yych >= 'g') goto yy128; + if (yych <= 'F') goto yy153; + if (yych <= '`') goto yy129; + if (yych >= 'g') goto yy129; } -yy152: +yy153: ++YYCURSOR; { int utf16 = php_json_ucs2_to_int(s, 2); diff --git a/ext/json/json_scanner.re b/ext/json/json_scanner.re index 28743e5453cc0..c18d8779b6802 100644 --- a/ext/json/json_scanner.re +++ b/ext/json/json_scanner.re @@ -81,7 +81,7 @@ static int php_json_ucs2_to_int(php_json_scanner *s, int size) return php_json_ucs2_to_int_ex(s, size, 1); } -void php_json_scanner_init(php_json_scanner *s, char *str, int str_len, long options) +void php_json_scanner_init(php_json_scanner *s, char *str, size_t str_len, int options) { s->cursor = (php_json_ctype *) str; s->limit = (php_json_ctype *) str + str_len; @@ -171,7 +171,7 @@ std: } } if (!bigint) { - ZVAL_LONG(&s->value, strtol((char *) s->token, NULL, 10)); + ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10)); return PHP_JSON_T_INT; } else if (s->options & PHP_JSON_BIGINT_AS_STRING) { ZVAL_STRINGL(&s->value, (char *) s->token, s->cursor - s->token); diff --git a/ext/json/php_json_scanner.h b/ext/json/php_json_scanner.h index 4b031a4f12dba..f515ff55cdac4 100644 --- a/ext/json/php_json_scanner.h +++ b/ext/json/php_json_scanner.h @@ -32,15 +32,15 @@ typedef struct _php_json_scanner { php_json_ctype *ctxmarker; /* marker position for context backtracking */ php_json_ctype *str_start; /* start position of the string */ php_json_ctype *pstr; /* string pointer for escapes conversion */ + zval value; /* value */ int str_esc; /* number of extra characters for escaping */ int state; /* condition state */ - zval value; /* value */ - long options; /* options */ + int options; /* options */ php_json_error_code errcode; /* error type if there is an error */ } php_json_scanner; -void php_json_scanner_init(php_json_scanner *scanner, char *str, int str_len, long options); +void php_json_scanner_init(php_json_scanner *scanner, char *str, size_t str_len, int options); int php_json_scan(php_json_scanner *s); #endif /* PHP_JSON_SCANNER_H */ diff --git a/ext/json/php_json_scanner_defs.h b/ext/json/php_json_scanner_defs.h index b3867433a7c90..e1a5824dd3c6c 100644 --- a/ext/json/php_json_scanner_defs.h +++ b/ext/json/php_json_scanner_defs.h @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 */ +/* Generated by re2c 0.13.6 */ enum YYCONDTYPE { yycJS, diff --git a/ext/mssql/CREDITS b/ext/mssql/CREDITS deleted file mode 100644 index 548684afcaa70..0000000000000 --- a/ext/mssql/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -MS SQL -Frank M. Kromann diff --git a/ext/mssql/config.m4 b/ext/mssql/config.m4 deleted file mode 100644 index 2a298af734078..0000000000000 --- a/ext/mssql/config.m4 +++ /dev/null @@ -1,56 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(mssql,for MSSQL support via FreeTDS, -[ --with-mssql[=DIR] Include MSSQL-DB support. DIR is the FreeTDS home - directory [/usr/local/freetds]]) - -if test "$PHP_MSSQL" != "no"; then - - if test "$PHP_MSSQL" = "yes"; then - for i in /usr/local /usr; do - if test -f $i/include/sybdb.h; then - FREETDS_INSTALLATION_DIR=$i - FREETDS_INCLUDE_DIR=$i/include - break - elif test -f $i/include/freetds/sybdb.h; then - FREETDS_INSTALLATION_DIR=$i - FREETDS_INCLUDE_DIR=$i/include/freetds - break - fi - done - - if test -z "$FREETDS_INSTALLATION_DIR"; then - AC_MSG_ERROR(Cannot find FreeTDS in known installation directories) - fi - - elif test "$PHP_MSSQL" != "no"; then - - if test -f $PHP_MSSQL/include/sybdb.h; then - FREETDS_INSTALLATION_DIR=$PHP_MSSQL - FREETDS_INCLUDE_DIR=$PHP_MSSQL/include - elif test -f $PHP_MSSQL/include/freetds/sybdb.h; then - FREETDS_INSTALLATION_DIR=$PHP_MSSQL - FREETDS_INCLUDE_DIR=$PHP_MSSQL/include/freetds - else - AC_MSG_ERROR(Directory $PHP_MSSQL is not a FreeTDS installation directory) - fi - fi - - if test ! -r "$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libsybdb.a" && test ! -r "$FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libsybdb.so"; then - AC_MSG_ERROR(Could not find $FREETDS_INSTALLATION_DIR/$PHP_LIBDIR/libsybdb.[a|so]) - fi - - PHP_ADD_INCLUDE($FREETDS_INCLUDE_DIR) - PHP_ADD_LIBRARY_WITH_PATH(sybdb, $FREETDS_INSTALLATION_DIR/$PHP_LIBDIR, MSSQL_SHARED_LIBADD) - - PHP_NEW_EXTENSION(mssql, php_mssql.c, $ext_shared) - AC_CHECK_LIB(dnet_stub, dnet_addr, - [ PHP_ADD_LIBRARY_WITH_PATH(dnet_stub,,MSSQL_SHARED_LIBADD) - AC_DEFINE(HAVE_LIBDNET_STUB,1,[ ]) - ]) - AC_DEFINE(HAVE_MSSQL,1,[ ]) - AC_DEFINE(HAVE_FREETDS,1,[ ]) - PHP_SUBST(MSSQL_SHARED_LIBADD) -fi diff --git a/ext/mssql/config.w32 b/ext/mssql/config.w32 deleted file mode 100644 index bd1f68669b89d..0000000000000 --- a/ext/mssql/config.w32 +++ /dev/null @@ -1,28 +0,0 @@ -// $Id$ -// vim:ft=javascript - -ARG_WITH("mssql", "mssql support", "no"); - -if (PHP_MSSQL != "no") { - if (CHECK_LIB("ntwdblib.lib", "mssql", "\\MSSQL7\\DevTools\\Lib;\\MSSQL7\\DevTools\\Lib;" + PHP_MSSQL) && - CHECK_HEADER_ADD_INCLUDE("sqlfront.h", "CFLAGS_MSSQL", "\\MSSQL7\\DevTools\\Include;\\MSSQL7\\DevTools\\Include" + PHP_MSSQL)) { - EXTENSION("mssql", "php_mssql.c"); - AC_DEFINE('HAVE_MSSQL', 1, 'Have MSSQL support'); - ADD_FLAG("CFLAGS_MSSQL", "/D DBNTWIN32=1 /D MSSQL70=1"); - } else { - WARNING("mssql not enabled; libraries and headers not found"); - } -} - -ARG_WITH("dblib", "mssql support with freetds", "no"); - -if (PHP_DBLIB != "no") { - if (CHECK_LIB("dblib.lib", "dblib", PHP_PHP_BUILD + "\\freetds") && - CHECK_HEADER_ADD_INCLUDE("sybfront.h", "CFLAGS_DBLIB", PHP_PHP_BUILD + "\\freetds;" + PHP_DBLIB)) { - EXTENSION("dblib", "php_mssql.c", null, null, null, "ext\\dblib"); - AC_DEFINE('HAVE_MSSQL', 1, 'Have MSSQL support'); - ADD_FLAG("CFLAGS_DBLIB", "/D HAVE_FREETDS=1 /D DBNTWIN32=1 /D MSSQL70=1 /D MSSQL_EXPORTS /D COMPILE_DL_MSSQL"); - } else { - WARNING("dblib not enabled; libraries and headers not found"); - } -} diff --git a/ext/mssql/mssql_win32_howto.txt b/ext/mssql/mssql_win32_howto.txt deleted file mode 100644 index 735226f88a2b1..0000000000000 --- a/ext/mssql/mssql_win32_howto.txt +++ /dev/null @@ -1,35 +0,0 @@ -Rules for building MSSQL ------------------------- - -The MSSQL project contains 2 configurations. - -The files needed for each configurations are: - -Win32 Release_TS -Win32 Debug_TS - - php_build\mssql-70\include\sqldb.h - php_build\mssql-70\include\sqlfront.h - php_build\mssql-70\lib\ntwdblib.lib - -php_build is a directory at the same level as php7. - -Start Visual Studio, load php_modules.dsw, select the MSSQL projects, -configuration and build it. - -This module requires ntwdblib.dll and one or more of the following dll's - -dbmsadsn.dll -dbmsrpcn.dll -dbmsshrn.dll -dbmssocn.dll for tcp/ip connections -dbmsspxn.dll for ipx/spx connections -dbmsvinn.dll -dbnmpntw.dll for netbios connections - -All these files are installed while installing MS SQL Server. If the SQL Server -is installed on another maschine you need to install the client tools on -the web server as well. - - - \ No newline at end of file diff --git a/ext/mssql/php_mssql.c b/ext/mssql/php_mssql.c deleted file mode 100644 index 08e118d281c9a..0000000000000 --- a/ext/mssql/php_mssql.c +++ /dev/null @@ -1,2283 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Frank M. Kromann | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef COMPILE_DL_MSSQL -#define HAVE_MSSQL 1 -#endif - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_globals.h" -#include "ext/standard/php_standard.h" -#include "ext/standard/info.h" -#include "php_mssql.h" -#include "php_ini.h" - -#if HAVE_MSSQL -#define SAFE_STRING(s) ((s)?(s):"") - -#define MSSQL_ASSOC 1<<0 -#define MSSQL_NUM 1<<1 -#define MSSQL_BOTH (MSSQL_ASSOC|MSSQL_NUM) - -static int le_result, le_link, le_plink, le_statement; - -static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type); -static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type); - -static void _mssql_bind_hash_dtor(void *data); - -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_connect, 0, 0, 0) - ZEND_ARG_INFO(0, servername) - ZEND_ARG_INFO(0, username) - ZEND_ARG_INFO(0, password) - ZEND_ARG_INFO(0, newlink) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_close, 0, 0, 0) - ZEND_ARG_INFO(0, link_identifier) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_select_db, 0, 0, 1) - ZEND_ARG_INFO(0, database_name) - ZEND_ARG_INFO(0, link_identifier) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_query, 0, 0, 1) - ZEND_ARG_INFO(0, query) - ZEND_ARG_INFO(0, link_identifier) - ZEND_ARG_INFO(0, batch_size) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_fetch_batch, 0, 0, 1) - ZEND_ARG_INFO(0, result) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_rows_affected, 0, 0, 1) - ZEND_ARG_INFO(0, link_identifier) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_mssql_get_last_message, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_fetch_field, 0, 0, 1) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, field_offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_fetch_array, 0, 0, 1) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, result_type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_fetch_assoc, 0, 0, 1) - ZEND_ARG_INFO(0, result_id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_field_length, 0, 0, 1) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_data_seek, 0, 0, 2) - ZEND_ARG_INFO(0, result_identifier) - ZEND_ARG_INFO(0, row_number) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_result, 0, 0, 3) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, row) - ZEND_ARG_INFO(0, field) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_min_error_severity, 0, 0, 1) - ZEND_ARG_INFO(0, severity) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_init, 0, 0, 1) - ZEND_ARG_INFO(0, sp_name) - ZEND_ARG_INFO(0, link_identifier) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_bind, 0, 0, 4) - ZEND_ARG_INFO(0, stmt) - ZEND_ARG_INFO(0, param_name) - ZEND_ARG_INFO(1, var) - ZEND_ARG_INFO(0, type) - ZEND_ARG_INFO(0, is_output) - ZEND_ARG_INFO(0, is_null) - ZEND_ARG_INFO(0, maxlen) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_execute, 0, 0, 1) - ZEND_ARG_INFO(0, stmt) - ZEND_ARG_INFO(0, skip_results) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_free_statement, 0, 0, 1) - ZEND_ARG_INFO(0, stmt) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mssql_guid_string, 0, 0, 1) - ZEND_ARG_INFO(0, binary) - ZEND_ARG_INFO(0, short_format) -ZEND_END_ARG_INFO() -/* }}} */ - -/* {{{ mssql_functions -*/ -const zend_function_entry mssql_functions[] = { - PHP_FE(mssql_connect, arginfo_mssql_connect) - PHP_FE(mssql_pconnect, arginfo_mssql_connect) - PHP_FE(mssql_close, arginfo_mssql_close) - PHP_FE(mssql_select_db, arginfo_mssql_select_db) - PHP_FE(mssql_query, arginfo_mssql_query) - PHP_FE(mssql_fetch_batch, arginfo_mssql_fetch_batch) - PHP_FE(mssql_rows_affected, arginfo_mssql_rows_affected) - PHP_FE(mssql_free_result, arginfo_mssql_fetch_batch) - PHP_FE(mssql_get_last_message, arginfo_mssql_get_last_message) - PHP_FE(mssql_num_rows, arginfo_mssql_fetch_batch) - PHP_FE(mssql_num_fields, arginfo_mssql_fetch_batch) - PHP_FE(mssql_fetch_field, arginfo_mssql_fetch_field) - PHP_FE(mssql_fetch_row, arginfo_mssql_fetch_batch) - PHP_FE(mssql_fetch_array, arginfo_mssql_fetch_array) - PHP_FE(mssql_fetch_assoc, arginfo_mssql_fetch_assoc) - PHP_FE(mssql_fetch_object, arginfo_mssql_fetch_batch) - PHP_FE(mssql_field_length, arginfo_mssql_field_length) - PHP_FE(mssql_field_name, arginfo_mssql_field_length) - PHP_FE(mssql_field_type, arginfo_mssql_field_length) - PHP_FE(mssql_data_seek, arginfo_mssql_data_seek) - PHP_FE(mssql_field_seek, arginfo_mssql_fetch_field) - PHP_FE(mssql_result, arginfo_mssql_result) - PHP_FE(mssql_next_result, arginfo_mssql_fetch_assoc) - PHP_FE(mssql_min_error_severity, arginfo_mssql_min_error_severity) - PHP_FE(mssql_min_message_severity, arginfo_mssql_min_error_severity) - PHP_FE(mssql_init, arginfo_mssql_init) - PHP_FE(mssql_bind, arginfo_mssql_bind) - PHP_FE(mssql_execute, arginfo_mssql_execute) - PHP_FE(mssql_free_statement, arginfo_mssql_free_statement) - PHP_FE(mssql_guid_string, arginfo_mssql_guid_string) - PHP_FE_END -}; -/* }}} */ - -ZEND_DECLARE_MODULE_GLOBALS(mssql) -static PHP_GINIT_FUNCTION(mssql); - -/* {{{ mssql_module_entry -*/ -zend_module_entry mssql_module_entry = -{ - STANDARD_MODULE_HEADER, - "mssql", - mssql_functions, - PHP_MINIT(mssql), - PHP_MSHUTDOWN(mssql), - PHP_RINIT(mssql), - PHP_RSHUTDOWN(mssql), - PHP_MINFO(mssql), - NO_VERSION_YET, - PHP_MODULE_GLOBALS(mssql), - PHP_GINIT(mssql), - NULL, - NULL, - STANDARD_MODULE_PROPERTIES_EX -}; -/* }}} */ - -#ifdef COMPILE_DL_MSSQL -ZEND_GET_MODULE(mssql) -#endif - -#define CHECK_LINK(link) { if (link==-1) { php_error_docref(NULL, E_WARNING, "A link to the server could not be established"); RETURN_FALSE; } } - -/* {{{ PHP_INI_DISP -*/ -static PHP_INI_DISP(display_text_size) -{ - char *value; - - if (type == PHP_INI_DISPLAY_ORIG && ini_entry->modified) { - value = ini_entry->orig_value; - } else if (ini_entry->value) { - value = ini_entry->value; - } else { - value = NULL; - } - - if (atoi(value) == -1) { - PUTS("Server default"); - } else { - php_printf("%s", value); - } -} -/* }}} */ - -/* {{{ PHP_INI -*/ -PHP_INI_BEGIN() - STD_PHP_INI_BOOLEAN("mssql.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_persistent, zend_mssql_globals, mssql_globals) - STD_PHP_INI_ENTRY_EX("mssql.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_persistent, zend_mssql_globals, mssql_globals, display_link_numbers) - STD_PHP_INI_ENTRY_EX("mssql.max_links", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_links, zend_mssql_globals, mssql_globals, display_link_numbers) - STD_PHP_INI_ENTRY_EX("mssql.min_error_severity", "10", PHP_INI_ALL, OnUpdateLong, cfg_min_error_severity, zend_mssql_globals, mssql_globals, display_link_numbers) - STD_PHP_INI_ENTRY_EX("mssql.min_message_severity", "10", PHP_INI_ALL, OnUpdateLong, cfg_min_message_severity, zend_mssql_globals, mssql_globals, display_link_numbers) - /* - mssql.compatAbility_mode (with typo) was used for relatively long time. - Unless it is fixed the old version is also kept for compatibility reasons. - */ - STD_PHP_INI_BOOLEAN("mssql.compatability_mode", "0", PHP_INI_ALL, OnUpdateBool, compatibility_mode, zend_mssql_globals, mssql_globals) - STD_PHP_INI_BOOLEAN("mssql.compatibility_mode", "0", PHP_INI_ALL, OnUpdateBool, compatibility_mode, zend_mssql_globals, mssql_globals) - STD_PHP_INI_ENTRY_EX("mssql.connect_timeout", "5", PHP_INI_ALL, OnUpdateLong, connect_timeout, zend_mssql_globals, mssql_globals, display_link_numbers) - STD_PHP_INI_ENTRY_EX("mssql.timeout", "60", PHP_INI_ALL, OnUpdateLong, timeout, zend_mssql_globals, mssql_globals, display_link_numbers) - STD_PHP_INI_ENTRY_EX("mssql.textsize", "-1", PHP_INI_ALL, OnUpdateLong, textsize, zend_mssql_globals, mssql_globals, display_text_size) - STD_PHP_INI_ENTRY_EX("mssql.textlimit", "-1", PHP_INI_ALL, OnUpdateLong, textlimit, zend_mssql_globals, mssql_globals, display_text_size) - STD_PHP_INI_ENTRY_EX("mssql.batchsize", "0", PHP_INI_ALL, OnUpdateLong, batchsize, zend_mssql_globals, mssql_globals, display_link_numbers) - STD_PHP_INI_BOOLEAN("mssql.datetimeconvert", "1", PHP_INI_ALL, OnUpdateBool, datetimeconvert, zend_mssql_globals, mssql_globals) - STD_PHP_INI_BOOLEAN("mssql.secure_connection", "0", PHP_INI_SYSTEM, OnUpdateBool, secure_connection, zend_mssql_globals, mssql_globals) - STD_PHP_INI_ENTRY_EX("mssql.max_procs", "-1", PHP_INI_ALL, OnUpdateLong, max_procs, zend_mssql_globals, mssql_globals, display_link_numbers) -#ifdef HAVE_FREETDS - STD_PHP_INI_ENTRY("mssql.charset", "", PHP_INI_ALL, OnUpdateString, charset, zend_mssql_globals, mssql_globals) -#endif -PHP_INI_END() -/* }}} */ - -/* error handler */ -static int php_mssql_error_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) -{ - - if (severity >= MS_SQL_G(min_error_severity)) { - php_error_docref(NULL, E_WARNING, "%s (severity %d)", dberrstr, severity); - } - return INT_CANCEL; -} - -/* {{{ php_mssql_message_handler -*/ -/* message handler */ -static int php_mssql_message_handler(DBPROCESS *dbproc, DBINT msgno,int msgstate, int severity,char *msgtext,char *srvname, char *procname,DBUSMALLINT line) -{ - - if (severity >= MS_SQL_G(min_message_severity)) { - php_error_docref(NULL, E_WARNING, "message: %s (severity %d)", msgtext, severity); - } - if (MS_SQL_G(server_message)) { - zend_string_free(MS_SQL_G(server_message)); - MS_SQL_G(server_message) = NULL; - } - MS_SQL_G(server_message) = estrdup(msgtext); - return 0; -} -/* }}} */ - -/* {{{ _clean_invalid_results -*/ -static int _clean_invalid_results(zend_rsrc_list_entry *le) -{ - if (Z_TYPE_P(le) == le_result) { - mssql_link *mssql_ptr = ((mssql_result *) le->ptr)->mssql_ptr; - - if (!mssql_ptr->valid) { - return 1; - } - } - return 0; -} -/* }}} */ - -/* {{{ _free_result -*/ -static void _free_result(mssql_result *result, int free_fields) -{ - int i,j; - - if (result->data) { - for (i=0; inum_rows; i++) { - if (result->data[i]) { - for (j=0; jnum_fields; j++) { - zval_dtor(&result->data[i][j]); - } - efree(result->data[i]); - } - } - efree(result->data); - result->data = NULL; - result->blocks_initialized = 0; - } - - if (free_fields && result->fields) { - for (i=0; inum_fields; i++) { - zend_string_free(result->fields[i].name); - zend_string_free(result->fields[i].column_source); - } - efree(result->fields); - } -} -/* }}} */ - -/* {{{ _free_mssql_statement -*/ -static void _free_mssql_statement(zend_rsrc_list_entry *rsrc) -{ - mssql_statement *statement = (mssql_statement *)rsrc->ptr; - - if (statement->binds) { - zend_hash_destroy(statement->binds); - efree(statement->binds); - } - - efree(statement); -} -/* }}} */ - -/* {{{ _free_mssql_result -*/ -static void _free_mssql_result(zend_rsrc_list_entry *rsrc) -{ - mssql_result *result = (mssql_result *)rsrc->ptr; - - _free_result(result, 1); - dbcancel(result->mssql_ptr->link); - efree(result); -} -/* }}} */ - -/* {{{ php_mssql_set_defaullt_link -*/ -static void php_mssql_set_default_link(int id) -{ - if (MS_SQL_G(default_link)!=-1) { - zend_list_delete(MS_SQL_G(default_link)); - } - MS_SQL_G(default_link) = id; - zend_list_addref(id); -} -/* }}} */ - -/* {{{ _close_mssql_link -*/ -static void _close_mssql_link(zend_rsrc_list_entry *rsrc) -{ - mssql_link *mssql_ptr = (mssql_link *)rsrc->ptr; - - mssql_ptr->valid = 0; - zend_hash_apply(&EG(regular_list),(apply_func_t) _clean_invalid_results); - dbclose(mssql_ptr->link); - dbfreelogin(mssql_ptr->login); - efree(mssql_ptr); - MS_SQL_G(num_links)--; -} -/* }}} */ - -/* {{{ _close_mssql_plink -*/ -static void _close_mssql_plink(zend_rsrc_list_entry *rsrc) -{ - mssql_link *mssql_ptr = (mssql_link *)rsrc->ptr; - - dbclose(mssql_ptr->link); - dbfreelogin(mssql_ptr->login); - free(mssql_ptr); - MS_SQL_G(num_persistent)--; - MS_SQL_G(num_links)--; -} -/* }}} */ - -/* {{{ _mssql_bind_hash_dtor -*/ -static void _mssql_bind_hash_dtor(void *data) -{ - mssql_bind *bind= (mssql_bind *) data; - - zval_ptr_dtor(&(bind->zval)); -} -/* }}} */ - -/* {{{ PHP_GINIT_FUNCTION -*/ -static PHP_GINIT_FUNCTION(mssql) -{ - long compatibility_mode; - - mssql_globals->num_persistent = 0; - mssql_globals->get_column_content = php_mssql_get_column_content_with_type; - if (cfg_get_long("mssql.compatibility_mode", &compatibility_mode) == SUCCESS) { - if (compatibility_mode) { - mssql_globals->get_column_content = php_mssql_get_column_content_without_type; - } - } -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION -*/ -PHP_MINIT_FUNCTION(mssql) -{ - REGISTER_INI_ENTRIES(); - - le_statement = zend_register_list_destructors_ex(_free_mssql_statement, NULL, "mssql statement", module_number); - le_result = zend_register_list_destructors_ex(_free_mssql_result, NULL, "mssql result", module_number); - le_link = zend_register_list_destructors_ex(_close_mssql_link, NULL, "mssql link", module_number); - le_plink = zend_register_list_destructors_ex(NULL, _close_mssql_plink, "mssql link persistent", module_number); - Z_TYPE(mssql_module_entry) = type; - - if (dbinit()==FAIL) { - return FAILURE; - } - - /* BEGIN MSSQL data types for mssql_bind */ - REGISTER_LONG_CONSTANT("MSSQL_ASSOC", MSSQL_ASSOC, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MSSQL_NUM", MSSQL_NUM, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MSSQL_BOTH", MSSQL_BOTH, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("SQLTEXT",SQLTEXT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLVARCHAR",SQLVARCHAR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLCHAR",SQLCHAR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLINT1",SQLINT1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLINT2",SQLINT2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLINT4",SQLINT4, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLBIT",SQLBIT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLFLT4",SQLFLT4, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLFLT8",SQLFLT8, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SQLFLTN",SQLFLTN, CONST_CS | CONST_PERSISTENT); - /* END MSSQL data types for mssql_bind */ - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION -*/ -PHP_MSHUTDOWN_FUNCTION(mssql) -{ - UNREGISTER_INI_ENTRIES(); -#ifndef HAVE_FREETDS - dbwinexit(); -#else - dbexit(); -#endif - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RINIT_FUNCTION -*/ -PHP_RINIT_FUNCTION(mssql) -{ - MS_SQL_G(default_link) = -1; - MS_SQL_G(num_links) = MS_SQL_G(num_persistent); - MS_SQL_G(appname) = estrndup("PHP 7", 5); - MS_SQL_G(server_message) = NULL; - MS_SQL_G(min_error_severity) = MS_SQL_G(cfg_min_error_severity); - MS_SQL_G(min_message_severity) = MS_SQL_G(cfg_min_message_severity); - if (MS_SQL_G(connect_timeout) < 1) MS_SQL_G(connect_timeout) = 1; - if (MS_SQL_G(timeout) < 0) MS_SQL_G(timeout) = 60; - if (MS_SQL_G(max_procs) != -1) { - dbsetmaxprocs((TDS_SHORT)MS_SQL_G(max_procs)); - } - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RSHUTDOWN_FUNCTION -*/ -PHP_RSHUTDOWN_FUNCTION(mssql) -{ - zend_string_free(MS_SQL_G(appname)); - MS_SQL_G(appname) = NULL; - if (MS_SQL_G(server_message)) { - zend_string_free(MS_SQL_G(server_message)); - MS_SQL_G(server_message) = NULL; - } - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION -*/ -PHP_MINFO_FUNCTION(mssql) -{ - char buf[32]; - - php_info_print_table_start(); - php_info_print_table_header(2, "MSSQL Support", "enabled"); - - snprintf(buf, sizeof(buf), "%ld", MS_SQL_G(num_persistent)); - php_info_print_table_row(2, "Active Persistent Links", buf); - snprintf(buf, sizeof(buf), "%ld", MS_SQL_G(num_links)); - php_info_print_table_row(2, "Active Links", buf); - - php_info_print_table_row(2, "Library version", MSSQL_VERSION); - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); - -} -/* }}} */ - -/* {{{ php_mssql_do_connect -*/ -static void php_mssql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) -{ - char *host = NULL, *user = NULL, *passwd = NULL; - size_t host_len = 0, user_len = 0, passwd_len = 0; - zend_bool new_link = 0; - char *hashed_details; - int hashed_details_length; - mssql_link mssql, *mssql_ptr; - char buffer[40]; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sssb", &host, &host_len, &user, &user_len, &passwd, &passwd_len, &new_link) == FAILURE) { - return; - } - - /* Limit strings to 255 chars to prevent overflow issues in underlying libraries */ - if(host_len>255) { - host[255] = '\0'; - } - if(user_len>255) { - user[255] = '\0'; - } - if(passwd_len>255) { - passwd[255] = '\0'; - } - - switch(ZEND_NUM_ARGS()) - { - case 0: - /* defaults */ - hashed_details_length=5+3; - hashed_details = (char *) emalloc(hashed_details_length+1); - strcpy(hashed_details, "mssql___"); - break; - case 1: - hashed_details_length = spprintf(&hashed_details, 0, "mssql_%s__", host); - break; - case 2: - hashed_details_length = spprintf(&hashed_details, 0, "mssql_%s_%s_", host, user); - break; - case 3: - case 4: - hashed_details_length = spprintf(&hashed_details, 0, "mssql_%s_%s_%s", host, user, passwd); - break; - } - - if (hashed_details == NULL) { - php_error_docref(NULL, E_WARNING, "Out of memory"); - RETURN_FALSE; - } - - dbsetlogintime(MS_SQL_G(connect_timeout)); - dbsettime(MS_SQL_G(timeout)); - - /* set a DBLOGIN record */ - if ((mssql.login = dblogin()) == NULL) { - php_error_docref(NULL, E_WARNING, "Unable to allocate login record"); - RETURN_FALSE; - } - - DBERRHANDLE(mssql.login, (EHANDLEFUNC) php_mssql_error_handler); - DBMSGHANDLE(mssql.login, (MHANDLEFUNC) php_mssql_message_handler); - -#ifndef HAVE_FREETDS - if (MS_SQL_G(secure_connection)){ - DBSETLSECURE(mssql.login); - } - else { -#endif - if (user) { - DBSETLUSER(mssql.login,user); - } - if (passwd) { - DBSETLPWD(mssql.login,passwd); - } -#ifndef HAVE_FREETDS - } -#endif - -#ifdef HAVE_FREETDS - if (MS_SQL_G(charset) && strlen(MS_SQL_G(charset))) { - DBSETLCHARSET(mssql.login, MS_SQL_G(charset)); - } -#endif - - DBSETLAPP(mssql.login,MS_SQL_G(appname)); - mssql.valid = 1; - -#ifndef HAVE_FREETDS - DBSETLVERSION(mssql.login, DBVER60); -#endif -/* DBSETLTIME(mssql.login, TIMEOUT_INFINITE); */ - - if (!MS_SQL_G(allow_persistent)) { - persistent=0; - } - if (persistent) { - zend_rsrc_list_entry *le; - - /* try to find if we already have this link in our persistent list */ - if (new_link || zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_length + 1, (void **) &le)==FAILURE) { /* we don't */ - zend_rsrc_list_entry new_le; - - if (MS_SQL_G(max_links) != -1 && MS_SQL_G(num_links) >= MS_SQL_G(max_links)) { - php_error_docref(NULL, E_WARNING, "Too many open links (%ld)", MS_SQL_G(num_links)); - efree(hashed_details); - dbfreelogin(mssql.login); - RETURN_FALSE; - } - if (MS_SQL_G(max_persistent) != -1 && MS_SQL_G(num_persistent) >= MS_SQL_G(max_persistent)) { - php_error_docref(NULL, E_WARNING, "Too many open persistent links (%ld)", MS_SQL_G(num_persistent)); - efree(hashed_details); - dbfreelogin(mssql.login); - RETURN_FALSE; - } - /* create the link */ - if ((mssql.link = dbopen(mssql.login, host)) == FAIL) { - php_error_docref(NULL, E_WARNING, "Unable to connect to server: %s", (host == NULL ? "" : host)); - efree(hashed_details); - dbfreelogin(mssql.login); - RETURN_FALSE; - } - - if (DBSETOPT(mssql.link, DBBUFFER, "2")==FAIL) { - efree(hashed_details); - dbfreelogin(mssql.login); - dbclose(mssql.link); - RETURN_FALSE; - } - -#ifndef HAVE_FREETDS - if (MS_SQL_G(textlimit) != -1) { - snprintf(buffer, sizeof(buffer), "%li", MS_SQL_G(textlimit)); - if (DBSETOPT(mssql.link, DBTEXTLIMIT, buffer)==FAIL) { - efree(hashed_details); - dbfreelogin(mssql.login); - dbclose(mssql.link); - RETURN_FALSE; - } - } -#endif - if (MS_SQL_G(textsize) != -1) { - snprintf(buffer, sizeof(buffer), "SET TEXTSIZE %li", MS_SQL_G(textsize)); - dbcmd(mssql.link, buffer); - dbsqlexec(mssql.link); - dbresults(mssql.link); - } - - /* hash it up */ - mssql_ptr = (mssql_link *) malloc(sizeof(mssql_link)); - if (!mssql_ptr) { - efree(hashed_details); - dbfreelogin(mssql.login); - dbclose(mssql.link); - RETURN_FALSE; - } - - memcpy(mssql_ptr, &mssql, sizeof(mssql_link)); - Z_TYPE(new_le) = le_plink; - new_le.ptr = mssql_ptr; - if (zend_hash_update(&EG(persistent_list), hashed_details, hashed_details_length + 1, &new_le, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) { - free(mssql_ptr); - efree(hashed_details); - dbfreelogin(mssql.login); - dbclose(mssql.link); - RETURN_FALSE; - } - MS_SQL_G(num_persistent)++; - MS_SQL_G(num_links)++; - } else { /* we do */ - if (Z_TYPE_P(le) != le_plink) { -#if BROKEN_MSSQL_PCONNECTS - log_error("PHP/MS SQL: Hashed persistent link is not a MS SQL link!",php_rqst->server); -#endif - php_error_docref(NULL, E_WARNING, "Hashed persistent link is not a MS SQL link!"); - efree(hashed_details); - RETURN_FALSE; - } - - mssql_ptr = (mssql_link *) le->ptr; - /* test that the link hasn't died */ - if (DBDEAD(mssql_ptr->link) == TRUE) { - dbclose(mssql_ptr->link); -#if BROKEN_MSSQL_PCONNECTS - log_error("PHP/MS SQL: Persistent link died, trying to reconnect...",php_rqst->server); -#endif - if ((mssql_ptr->link=dbopen(mssql_ptr->login,host))==NULL) { -#if BROKEN_MSSQL_PCONNECTS - log_error("PHP/MS SQL: Unable to reconnect!",php_rqst->server); -#endif - php_error_docref(NULL, E_WARNING, "Link to server lost, unable to reconnect"); - zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_length+1); - efree(hashed_details); - dbfreelogin(mssql_ptr->login); - RETURN_FALSE; - } -#if BROKEN_MSSQL_PCONNECTS - log_error("PHP/MS SQL: Reconnect successful!",php_rqst->server); -#endif - if (DBSETOPT(mssql_ptr->link, DBBUFFER, "2")==FAIL) { -#if BROKEN_MSSQL_PCONNECTS - log_error("PHP/MS SQL: Unable to set required options",php_rqst->server); -#endif - zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_length + 1); - efree(hashed_details); - dbfreelogin(mssql_ptr->login); - dbclose(mssql_ptr->link); - RETURN_FALSE; - } - } - } - ZEND_REGISTER_RESOURCE(return_value, mssql_ptr, le_plink); - } else { /* non persistent */ - zend_rsrc_list_entry *index_ptr, new_index_ptr; - - /* first we check the hash for the hashed_details key. if it exists, - * it should point us to the right offset where the actual mssql link sits. - * if it doesn't, open a new mssql link, add it to the resource list, - * and add a pointer to it with hashed_details as the key. - */ - if (!new_link && zend_hash_find(&EG(regular_list), hashed_details, hashed_details_length + 1,(void **) &index_ptr)==SUCCESS) { - int type,link; - void *ptr; - - if (Z_TYPE_P(index_ptr) != le_index_ptr) { - efree(hashed_details); - dbfreelogin(mssql.login); - RETURN_FALSE; - } - link = (int) index_ptr->ptr; - ptr = zend_list_find(link,&type); /* check if the link is still there */ - if (ptr && (type==le_link || type==le_plink)) { - zend_list_addref(link); - Z_LVAL_P(return_value) = link; - php_mssql_set_default_link(link); - Z_TYPE_P(return_value) = IS_RESOURCE; - dbfreelogin(mssql.login); - efree(hashed_details); - return; - } else { - zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length + 1); - } - } - if (MS_SQL_G(max_links) != -1 && MS_SQL_G(num_links) >= MS_SQL_G(max_links)) { - php_error_docref(NULL, E_WARNING, "Too many open links (%ld)", MS_SQL_G(num_links)); - efree(hashed_details); - dbfreelogin(mssql.login); - RETURN_FALSE; - } - - if ((mssql.link=dbopen(mssql.login, host))==NULL) { - php_error_docref(NULL, E_WARNING, "Unable to connect to server: %s", (host == NULL ? "" : host)); - efree(hashed_details); - dbfreelogin(mssql.login); - RETURN_FALSE; - } - - if (DBSETOPT(mssql.link, DBBUFFER,"2")==FAIL) { - efree(hashed_details); - dbfreelogin(mssql.login); - dbclose(mssql.link); - RETURN_FALSE; - } - -#ifndef HAVE_FREETDS - if (MS_SQL_G(textlimit) != -1) { - snprintf(buffer, sizeof(buffer), "%li", MS_SQL_G(textlimit)); - if (DBSETOPT(mssql.link, DBTEXTLIMIT, buffer)==FAIL) { - efree(hashed_details); - dbfreelogin(mssql.login); - dbclose(mssql.link); - RETURN_FALSE; - } - } -#endif - if (MS_SQL_G(textsize) != -1) { - snprintf(buffer, sizeof(buffer), "SET TEXTSIZE %li", MS_SQL_G(textsize)); - dbcmd(mssql.link, buffer); - dbsqlexec(mssql.link); - dbresults(mssql.link); - } - - /* add it to the list */ - mssql_ptr = (mssql_link *) emalloc(sizeof(mssql_link)); - memcpy(mssql_ptr, &mssql, sizeof(mssql_link)); - ZEND_REGISTER_RESOURCE(return_value, mssql_ptr, le_link); - - /* add it to the hash */ - new_index_ptr.ptr = (void *) Z_LVAL_P(return_value); - Z_TYPE(new_index_ptr) = le_index_ptr; - if (zend_hash_update(&EG(regular_list), hashed_details, hashed_details_length + 1,(void *) &new_index_ptr, sizeof(zend_rsrc_list_entry),NULL)==FAILURE) { - efree(hashed_details); - RETURN_FALSE; - } - MS_SQL_G(num_links)++; - } - efree(hashed_details); - php_mssql_set_default_link(Z_LVAL_P(return_value)); -} -/* }}} */ - -/* {{{ php_mssql_get_default_link -*/ -static int php_mssql_get_default_link(INTERNAL_FUNCTION_PARAMETERS) -{ - if (MS_SQL_G(default_link)==-1) { /* no link opened yet, implicitly open one */ - ht = 0; - php_mssql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); - } - return MS_SQL_G(default_link); -} -/* }}} */ - -/* {{{ proto int mssql_connect([string servername [, string username [, string password [, bool new_link]]]]) - Establishes a connection to a MS-SQL server */ -PHP_FUNCTION(mssql_connect) -{ - php_mssql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); -} -/* }}} */ - -/* {{{ proto int mssql_pconnect([string servername [, string username [, string password [, bool new_link]]]]) - Establishes a persistent connection to a MS-SQL server */ -PHP_FUNCTION(mssql_pconnect) -{ - php_mssql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,1); -} -/* }}} */ - -/* {{{ proto bool mssql_close([resource conn_id]) - Closes a connection to a MS-SQL server */ -PHP_FUNCTION(mssql_close) -{ - zval *mssql_link_index = NULL; - int id = -1; - mssql_link *mssql_ptr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &mssql_link_index) == FAILURE) { - return; - } - - if (mssql_link_index == NULL) { - id = php_mssql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); - CHECK_LINK(id); - } - - ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, id, "MS SQL-Link", le_link, le_plink); - - if (mssql_link_index) { - zend_list_delete(Z_RESVAL_P(mssql_link_index)); - } else { - zend_list_delete(id); - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool mssql_select_db(string database_name [, resource conn_id]) - Select a MS-SQL database */ -PHP_FUNCTION(mssql_select_db) -{ - char *db; - zval *mssql_link_index = NULL; - size_t db_len; - int id = -1; - mssql_link *mssql_ptr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|r", &db, &db_len, &mssql_link_index) == FAILURE) { - return; - } - - if (mssql_link_index == NULL) { - id = php_mssql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); - CHECK_LINK(id); - } - - ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, id, "MS SQL-Link", le_link, le_plink); - - if (dbuse(mssql_ptr->link, db)==FAIL) { - php_error_docref(NULL, E_WARNING, "Unable to select database: %s", db); - RETURN_FALSE; - } else { - RETURN_TRUE; - } -} -/* }}} */ - -/* {{{ php_mssql_get_column_content_with_type -*/ -static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type ) -{ - if (dbdata(mssql_ptr->link,offset) == NULL && dbdatlen(mssql_ptr->link,offset) == 0) { - ZVAL_NULL(result); - return; - } - - switch (column_type) - { - case SQLBIT: - case SQLINT1: - case SQLINT2: - case SQLINT4: - case SQLINTN: { - ZVAL_LONG(result, (long) anyintcol(offset)); - break; - } - case SQLCHAR: - case SQLVARCHAR: - case SQLTEXT: { - int length; - char *data = charcol(offset); - - length=dbdatlen(mssql_ptr->link,offset); -#if ilia_0 - while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace */ - length--; - } -#endif - ZVAL_STRINGL(result, data, length, 1); - break; - } - case SQLFLT4: - ZVAL_DOUBLE(result, (double) floatcol4(offset)); - break; - case SQLMONEY: - case SQLMONEY4: - case SQLMONEYN: { - DBFLT8 res_buf; - dbconvert(NULL, column_type, dbdata(mssql_ptr->link,offset), 8, SQLFLT8, (LPBYTE)&res_buf, -1); - ZVAL_DOUBLE(result, res_buf); - } - break; - case SQLFLT8: - ZVAL_DOUBLE(result, (double) floatcol8(offset)); - break; -#ifdef SQLUNIQUE - case SQLUNIQUE: { -#else - case 36: { /* FreeTDS hack */ -#endif - char *data = charcol(offset); - - /* uniqueidentifier is a 16-byte binary number */ - ZVAL_STRINGL(result, data, 16, 1); - } - break; - case SQLVARBINARY: - case SQLBINARY: - case SQLIMAGE: { - int res_length = dbdatlen(mssql_ptr->link, offset); - - if (!res_length) { - ZVAL_NULL(result); - } else { - ZVAL_STRINGL(result, (char *)dbdata(mssql_ptr->link, offset), res_length, 1); - } - } - break; - case SQLNUMERIC: - default: { - if (dbwillconvert(column_type,SQLCHAR)) { - char *res_buf; - DBDATEREC dateinfo; - int res_length = dbdatlen(mssql_ptr->link,offset); - - if (res_length == -1) { - res_length = 255; - } - - if ((column_type != SQLDATETIME && column_type != SQLDATETIM4) || MS_SQL_G(datetimeconvert)) { - - switch (column_type) { - case SQLDATETIME : - case SQLDATETIM4 : - res_length += 20; - break; - case SQLMONEY : - case SQLMONEY4 : - case SQLMONEYN : - case SQLDECIMAL : - case SQLNUMERIC : - res_length += 5; - case 127 : - res_length += 20; - break; - } - - res_buf = (unsigned char *) emalloc(res_length+1); - res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR,res_buf,-1); - res_buf[res_length] = '\0'; - } else { - if (column_type == SQLDATETIM4) { - DBDATETIME temp; - - dbconvert(NULL, SQLDATETIM4, dbdata(mssql_ptr->link,offset), -1, SQLDATETIME, (LPBYTE) &temp, -1); - dbdatecrack(mssql_ptr->link, &dateinfo, &temp); - } else { - dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset)); - } - - res_length = 19; - spprintf(&res_buf, 0, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second); - } - - ZVAL_STRINGL(result, res_buf, res_length, 0); - } else { - php_error_docref(NULL, E_WARNING, "column %d has unknown data type (%d)", offset, coltype(offset)); - ZVAL_FALSE(result); - } - } - } -} -/* }}} */ - -/* {{{ php_mssql_get_column_content_without_type -*/ -static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type) -{ - if (dbdatlen(mssql_ptr->link,offset) == 0) { - ZVAL_NULL(result); - return; - } - - if (column_type == SQLVARBINARY || - column_type == SQLBINARY || - column_type == SQLIMAGE) { - DBBINARY *bin; - unsigned char *res_buf; - int res_length = dbdatlen(mssql_ptr->link, offset); - - if (res_length == 0) { - ZVAL_NULL(result); - return; - } else if (res_length < 0) { - ZVAL_FALSE(result); - return; - } - - res_buf = (unsigned char *) emalloc(res_length+1); - bin = ((DBBINARY *)dbdata(mssql_ptr->link, offset)); - res_buf[res_length] = '\0'; - memcpy(res_buf, bin, res_length); - ZVAL_STRINGL(result, res_buf, res_length, 0); - } - else if (dbwillconvert(coltype(offset),SQLCHAR)) { - unsigned char *res_buf; - DBDATEREC dateinfo; - int res_length = dbdatlen(mssql_ptr->link,offset); - - if ((column_type != SQLDATETIME && column_type != SQLDATETIM4) || MS_SQL_G(datetimeconvert)) { - - switch (column_type) { - case SQLDATETIME : - case SQLDATETIM4 : - res_length += 20; - break; - case SQLMONEY : - case SQLMONEY4 : - case SQLMONEYN : - case SQLDECIMAL : - case SQLNUMERIC : - res_length += 5; - case 127 : - res_length += 20; - break; - } - - res_buf = (unsigned char *) emalloc(res_length+1); - res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR, res_buf, -1); - res_buf[res_length] = '\0'; - } else { - if (column_type == SQLDATETIM4) { - DBDATETIME temp; - - dbconvert(NULL, SQLDATETIM4, dbdata(mssql_ptr->link,offset), -1, SQLDATETIME, (LPBYTE) &temp, -1); - dbdatecrack(mssql_ptr->link, &dateinfo, &temp); - } else { - dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset)); - } - - res_length = 19; - spprintf(&res_buf, 0, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second); - } - - ZVAL_STRINGL(result, res_buf, res_length, 0); - } else { - php_error_docref(NULL, E_WARNING, "column %d has unknown data type (%d)", offset, coltype(offset)); - ZVAL_FALSE(result); - } -} -/* }}} */ - -/* {{{ _mssql_get_sp_result -*/ -static void _mssql_get_sp_result(mssql_link *mssql_ptr, mssql_statement *statement) -{ - int i, num_rets, type; - char *parameter; - mssql_bind *bind; - - /* Now to fetch RETVAL and OUTPUT values*/ - num_rets = dbnumrets(mssql_ptr->link); - - if (num_rets!=0) { - for (i = 1; i <= num_rets; i++) { - parameter = (char*)dbretname(mssql_ptr->link, i); - type = dbrettype(mssql_ptr->link, i); - - if (statement->binds != NULL) { /* Maybe a non-parameter sp */ - if (zend_hash_find(statement->binds, parameter, strlen(parameter), (void**)&bind)==SUCCESS) { - if (!dbretlen(mssql_ptr->link,i)) { - ZVAL_NULL(bind->zval); - } - else { - switch (type) { - case SQLBIT: - case SQLINT1: - case SQLINT2: - case SQLINT4: - convert_to_long_ex(&bind->zval); - /* FIXME this works only on little endian machine !!! */ - Z_LVAL_P(bind->zval) = *((int *)(dbretdata(mssql_ptr->link,i))); - break; - - case SQLFLT4: - case SQLFLT8: - case SQLFLTN: - case SQLMONEY4: - case SQLMONEY: - case SQLMONEYN: - convert_to_double_ex(&bind->zval); - Z_DVAL_P(bind->zval) = *((double *)(dbretdata(mssql_ptr->link,i))); - break; - - case SQLCHAR: - case SQLVARCHAR: - case SQLTEXT: - convert_to_string_ex(&bind->zval); - Z_STRLEN_P(bind->zval) = dbretlen(mssql_ptr->link,i); - Z_STRVAL_P(bind->zval) = estrndup(dbretdata(mssql_ptr->link,i),Z_STRLEN_P(bind->zval)); - break; - /* TODO binary */ - } - } - } - else { - php_error_docref(NULL, E_WARNING, "An output parameter variable was not provided"); - } - } - } - } - if (statement->binds != NULL) { /* Maybe a non-parameter sp */ - if (zend_hash_find(statement->binds, "RETVAL", 6, (void**)&bind)==SUCCESS) { - if (dbhasretstat(mssql_ptr->link)) { - convert_to_long_ex(&bind->zval); - Z_LVAL_P(bind->zval)=dbretstatus(mssql_ptr->link); - } - else { - php_error_docref(NULL, E_WARNING, "stored procedure has no return value. Nothing was returned into RETVAL"); - } - } - } -} -/* }}} */ - -/* {{{ _mssql_fetch_batch -*/ -static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int retvalue) -{ - int i, j = 0; - char computed_buf[16]; - - if (!result->have_fields) { - for (i=0; inum_fields; i++) { - char *source = NULL; - char *fname = (char *)dbcolname(mssql_ptr->link,i+1); - - if (*fname) { - result->fields[i].name = estrdup(fname); - } else { - if (j>0) { - snprintf(computed_buf,16,"computed%d",j); - } else { - strcpy(computed_buf,"computed"); - } - result->fields[i].name = estrdup(computed_buf); - j++; - } - result->fields[i].max_length = dbcollen(mssql_ptr->link,i+1); - source = (char *)dbcolsource(mssql_ptr->link,i+1); - if (source) { - result->fields[i].column_source = estrdup(source); - } - else { - result->fields[i].column_source = STR_EMPTY_ALLOC(); - } - - result->fields[i].type = coltype(i+1); - /* set numeric flag */ - switch (result->fields[i].type) { - case SQLINT1: - case SQLINT2: - case SQLINT4: - case SQLINTN: - case SQLFLT4: - case SQLFLT8: - case SQLNUMERIC: - case SQLDECIMAL: - result->fields[i].numeric = 1; - break; - case SQLCHAR: - case SQLVARCHAR: - case SQLTEXT: - default: - result->fields[i].numeric = 0; - break; - } - } - result->have_fields = 1; - } - - i=0; - if (!result->data) { - result->data = (zval **) safe_emalloc(sizeof(zval *), MSSQL_ROWS_BLOCK*(++result->blocks_initialized), 0); - } - while (retvalue!=FAIL && retvalue!=NO_MORE_ROWS) { - result->num_rows++; - if (result->num_rows > result->blocks_initialized*MSSQL_ROWS_BLOCK) { - result->data = (zval **) erealloc(result->data,sizeof(zval *)*MSSQL_ROWS_BLOCK*(++result->blocks_initialized)); - } - result->data[i] = (zval *) safe_emalloc(sizeof(zval), result->num_fields, 0); - for (j=0; jnum_fields; j++) { - INIT_ZVAL(result->data[i][j]); - MS_SQL_G(get_column_content(mssql_ptr, j+1, &result->data[i][j], result->fields[j].type)); - } - if (ibatchsize || result->batchsize==0) { - i++; - dbclrbuf(mssql_ptr->link,DBLASTROW(mssql_ptr->link)); - retvalue=dbnextrow(mssql_ptr->link); - } - else - break; - result->lastresult = retvalue; - } - if (result->statement && (retvalue == NO_MORE_RESULTS || retvalue == NO_MORE_RPC_RESULTS)) { - _mssql_get_sp_result(mssql_ptr, result->statement); - } - return i; -} -/* }}} */ - -/* {{{ proto int mssql_fetch_batch(resource result_index) - Returns the next batch of records */ -PHP_FUNCTION(mssql_fetch_batch) -{ - zval *mssql_result_index; - mssql_result *result; - mssql_link *mssql_ptr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_result_index) == FAILURE) { - return; - } - - if (Z_RESVAL_P(mssql_result_index) == 0) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - mssql_ptr = result->mssql_ptr; - _free_result(result, 0); - result->cur_row=result->num_rows=0; - result->num_rows = _mssql_fetch_batch(mssql_ptr, result, result->lastresult); - - RETURN_LONG(result->num_rows); -} -/* }}} */ - -/* {{{ proto resource mssql_query(string query [, resource conn_id [, int batch_size]]) - Perform an SQL query on a MS-SQL server database */ -PHP_FUNCTION(mssql_query) -{ - char *query; - zval *mssql_link_index = NULL; - size_t query_len; - int retvalue, batchsize, num_fields; - zend_long zbatchsize = 0; - mssql_link *mssql_ptr; - mssql_result *result; - int id = -1; - - dbsettime(MS_SQL_G(timeout)); - batchsize = MS_SQL_G(batchsize); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|rl", &query, &query_len, &mssql_link_index, &zbatchsize) == FAILURE) { - return; - } - - switch(ZEND_NUM_ARGS()) { - case 1: - id = php_mssql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); - CHECK_LINK(id); - break; - case 3: - batchsize = (int) zbatchsize; - break; - } - - ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, id, "MS SQL-Link", le_link, le_plink); - - if (dbcmd(mssql_ptr->link, query)==FAIL) { - php_error_docref(NULL, E_WARNING, "Unable to set query"); - RETURN_FALSE; - } - if (dbsqlexec(mssql_ptr->link)==FAIL || (retvalue = dbresults(mssql_ptr->link))==FAIL) { - php_error_docref(NULL, E_WARNING, "Query failed"); - dbcancel(mssql_ptr->link); - RETURN_FALSE; - } - - /* Skip results not returning any columns */ - while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retvalue == SUCCEED) { - retvalue = dbresults(mssql_ptr->link); - } - - if (num_fields <= 0) { - RETURN_TRUE; - } - - retvalue=dbnextrow(mssql_ptr->link); - if (retvalue==FAIL) { - dbcancel(mssql_ptr->link); - RETURN_FALSE; - } - - result = (mssql_result *) emalloc(sizeof(mssql_result)); - result->statement = NULL; - result->num_fields = num_fields; - result->blocks_initialized = 1; - - result->batchsize = batchsize; - result->data = NULL; - result->blocks_initialized = 0; - result->mssql_ptr = mssql_ptr; - result->cur_field=result->cur_row=result->num_rows=0; - result->have_fields = 0; - - result->fields = (mssql_field *) safe_emalloc(sizeof(mssql_field), result->num_fields, 0); - result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue); - - ZEND_REGISTER_RESOURCE(return_value, result, le_result); -} -/* }}} */ - -/* {{{ proto int mssql_rows_affected(resource conn_id) - Returns the number of records affected by the query */ -PHP_FUNCTION(mssql_rows_affected) -{ - zval *mssql_link_index; - mssql_link *mssql_ptr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_link_index) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, -1, "MS SQL-Link", le_link, le_plink); - - RETURN_LONG(DBCOUNT(mssql_ptr->link)); -} -/* }}} */ - -/* {{{ proto bool mssql_free_result(resource result_index) - Free a MS-SQL result index */ -PHP_FUNCTION(mssql_free_result) -{ - zval *mssql_result_index; - mssql_result *result; - int retvalue; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_result_index) == FAILURE) { - return; - } - - if (Z_RESVAL_P(mssql_result_index) == 0) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - /* Release remaining results */ - do { - dbcanquery(result->mssql_ptr->link); - retvalue = dbresults(result->mssql_ptr->link); - } while (retvalue == SUCCEED); - - zend_list_delete(Z_RESVAL_P(mssql_result_index)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string mssql_get_last_message(void) - Gets the last message from the MS-SQL server */ -PHP_FUNCTION(mssql_get_last_message) -{ - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - if (MS_SQL_G(server_message)) { - RETURN_STRING(MS_SQL_G(server_message),1); - } else { - RETURN_STRING("",1); - } -} -/* }}} */ - -/* {{{ proto int mssql_num_rows(resource mssql_result_index) - Returns the number of rows fetched in from the result id specified */ -PHP_FUNCTION(mssql_num_rows) -{ - zval *mssql_result_index; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_result_index) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - RETURN_LONG(result->num_rows); -} -/* }}} */ - -/* {{{ proto int mssql_num_fields(resource mssql_result_index) - Returns the number of fields fetched in from the result id specified */ -PHP_FUNCTION(mssql_num_fields) -{ - zval *mssql_result_index; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_result_index) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - RETURN_LONG(result->num_fields); -} -/* }}} */ - -/* {{{ php_mssql_fetch_hash -*/ -static void php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) -{ - zval *mssql_result_index; - mssql_result *result; - int i; - zend_long resulttype = 0; - - switch (result_type) { - case MSSQL_NUM: - case MSSQL_ASSOC: - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_result_index) == FAILURE) { - return; - } - break; - case MSSQL_BOTH: - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &mssql_result_index, &resulttype) == FAILURE) { - return; - } - result_type = (resulttype > 0 && (resulttype & MSSQL_BOTH)) ? resulttype : result_type; - break; - default: - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (MS_SQL_G(server_message)) { - zend_string_free(MS_SQL_G(server_message)); - MS_SQL_G(server_message) = NULL; - } - - if (result->cur_row >= result->num_rows) { - RETURN_FALSE; - } - - array_init(return_value); - - for (i=0; inum_fields; i++) { - if (Z_TYPE(result->data[result->cur_row][i]) != IS_NULL) { - char *data; - int data_len; - - if (Z_TYPE(result->data[result->cur_row][i]) == IS_STRING) { - data = Z_STRVAL(result->data[result->cur_row][i]); - data_len = Z_STRLEN(result->data[result->cur_row][i]); - - if (result_type & MSSQL_NUM) { - add_index_stringl(return_value, i, data, data_len); - } - - if (result_type & MSSQL_ASSOC) { - add_assoc_stringl(return_value, result->fields[i].name, data, data_len); - } - } - else if (Z_TYPE(result->data[result->cur_row][i]) == IS_LONG) { - if (result_type & MSSQL_NUM) - add_index_long(return_value, i, Z_LVAL(result->data[result->cur_row][i])); - - if (result_type & MSSQL_ASSOC) - add_assoc_long(return_value, result->fields[i].name, Z_LVAL(result->data[result->cur_row][i])); - } - else if (Z_TYPE(result->data[result->cur_row][i]) == IS_DOUBLE) { - if (result_type & MSSQL_NUM) - add_index_double(return_value, i, Z_DVAL(result->data[result->cur_row][i])); - - if (result_type & MSSQL_ASSOC) - add_assoc_double(return_value, result->fields[i].name, Z_DVAL(result->data[result->cur_row][i])); - } - } - else - { - if (result_type & MSSQL_NUM) - add_index_null(return_value, i); - if (result_type & MSSQL_ASSOC) - add_assoc_null(return_value, result->fields[i].name); - } - } - result->cur_row++; -} -/* }}} */ - -/* {{{ proto array mssql_fetch_row(resource result_id) - Returns an array of the current row in the result set specified by result_id */ -PHP_FUNCTION(mssql_fetch_row) -{ - php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MSSQL_NUM); -} -/* }}} */ - -/* {{{ proto object mssql_fetch_object(resource result_id) - Returns a pseudo-object of the current row in the result set specified by result_id */ -PHP_FUNCTION(mssql_fetch_object) -{ - php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MSSQL_ASSOC); - if (Z_TYPE_P(return_value)==IS_ARRAY) { - object_and_properties_init(return_value, ZEND_STANDARD_CLASS_DEF_PTR, Z_ARRVAL_P(return_value)); - } -} -/* }}} */ - -/* {{{ proto array mssql_fetch_array(resource result_id [, int result_type]) - Returns an associative array of the current row in the result set specified by result_id */ -PHP_FUNCTION(mssql_fetch_array) -{ - php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MSSQL_BOTH); -} -/* }}} */ - -/* {{{ proto array mssql_fetch_assoc(resource result_id) - Returns an associative array of the current row in the result set specified by result_id */ -PHP_FUNCTION(mssql_fetch_assoc) -{ - php_mssql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MSSQL_ASSOC); -} -/* }}} */ - -/* {{{ proto bool mssql_data_seek(resource result_id, int offset) - Moves the internal row pointer of the MS-SQL result associated with the specified result identifier to pointer to the specified row number */ -PHP_FUNCTION(mssql_data_seek) -{ - zval *mssql_result_index; - zend_long offset; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &mssql_result_index, &offset) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (offset < 0 || offset >= result->num_rows) { - php_error_docref(NULL, E_WARNING, "Bad row offset"); - RETURN_FALSE; - } - - result->cur_row = offset; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ php_mssql_get_field_name -*/ -static char *php_mssql_get_field_name(int type) -{ - switch (type) { - case SQLBINARY: - case SQLVARBINARY: - return "blob"; - break; - case SQLCHAR: - case SQLVARCHAR: - return "char"; - break; - case SQLTEXT: - return "text"; - break; - case SQLDATETIME: - case SQLDATETIM4: - case SQLDATETIMN: - return "datetime"; - break; - case SQLDECIMAL: - case SQLFLT4: - case SQLFLT8: - case SQLFLTN: - return "real"; - break; - case SQLINT1: - case SQLINT2: - case SQLINT4: - case SQLINTN: - return "int"; - break; - case SQLNUMERIC: - return "numeric"; - break; - case SQLMONEY: - case SQLMONEY4: - case SQLMONEYN: - return "money"; - break; - case SQLBIT: - return "bit"; - break; - case SQLIMAGE: - return "image"; - break; -#ifdef SQLUNIQUE - case SQLUNIQUE: - return "uniqueidentifier"; - break; -#endif - default: - return "unknown"; - break; - } -} -/* }}} */ - -/* {{{ proto object mssql_fetch_field(resource result_id [, int offset]) - Gets information about certain fields in a query result */ -PHP_FUNCTION(mssql_fetch_field) -{ - zval *mssql_result_index; - zend_long field_offset = -1; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &mssql_result_index, &field_offset) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (field_offset==-1) { - field_offset = result->cur_field; - result->cur_field++; - } - - if (field_offset<0 || field_offset >= result->num_fields) { - if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ - php_error_docref(NULL, E_WARNING, "Bad column offset"); - } - RETURN_FALSE; - } - - object_init(return_value); - - add_property_string(return_value, "name",result->fields[field_offset].name); - add_property_long(return_value, "max_length",result->fields[field_offset].max_length); - add_property_string(return_value, "column_source",result->fields[field_offset].column_source); - add_property_long(return_value, "numeric", result->fields[field_offset].numeric); - add_property_string(return_value, "type", php_mssql_get_field_name(Z_TYPE(result->fields[field_offset]))); -} -/* }}} */ - -/* {{{ proto int mssql_field_length(resource result_id [, int offset]) - Get the length of a MS-SQL field */ -PHP_FUNCTION(mssql_field_length) -{ - zval *mssql_result_index; - zend_long field_offset = -1; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &mssql_result_index, &field_offset) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (field_offset==-1) { - field_offset = result->cur_field; - result->cur_field++; - } - - if (field_offset<0 || field_offset >= result->num_fields) { - if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ - php_error_docref(NULL, E_WARNING, "Bad column offset"); - } - RETURN_FALSE; - } - - RETURN_LONG(result->fields[field_offset].max_length); -} -/* }}} */ - -/* {{{ proto string mssql_field_name(resource result_id [, int offset]) - Returns the name of the field given by offset in the result set given by result_id */ -PHP_FUNCTION(mssql_field_name) -{ - zval *mssql_result_index; - zend_long field_offset = -1; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &mssql_result_index, &field_offset) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (field_offset==-1) { - field_offset = result->cur_field; - result->cur_field++; - } - - if (field_offset<0 || field_offset >= result->num_fields) { - if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ - php_error_docref(NULL, E_WARNING, "Bad column offset"); - } - RETURN_FALSE; - } - - RETURN_STRINGL(result->fields[field_offset].name, strlen(result->fields[field_offset].name), 1); -} -/* }}} */ - -/* {{{ proto string mssql_field_type(resource result_id [, int offset]) - Returns the type of a field */ -PHP_FUNCTION(mssql_field_type) -{ - zval *mssql_result_index; - zend_long field_offset = -1; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &mssql_result_index, &field_offset) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (field_offset==-1) { - field_offset = result->cur_field; - result->cur_field++; - } - - if (field_offset<0 || field_offset >= result->num_fields) { - if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ - php_error_docref(NULL, E_WARNING, "Bad column offset"); - } - RETURN_FALSE; - } - - RETURN_STRINGL(php_mssql_get_field_name(Z_TYPE(result->fields[field_offset])), strlen(php_mssql_get_field_name(Z_TYPE(result->fields[field_offset]))), 1); -} -/* }}} */ - -/* {{{ proto bool mssql_field_seek(resource result_id, int offset) - Seeks to the specified field offset */ -PHP_FUNCTION(mssql_field_seek) -{ - zval *mssql_result_index; - zend_long field_offset; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &mssql_result_index, &field_offset) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (field_offset<0 || field_offset >= result->num_fields) { - php_error_docref(NULL, E_WARNING, "Bad column offset"); - RETURN_FALSE; - } - - result->cur_field = field_offset; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string mssql_result(resource result_id, int row, mixed field) - Returns the contents of one cell from a MS-SQL result set */ -PHP_FUNCTION(mssql_result) -{ - zval **field, *mssql_result_index; - zend_long row; - int field_offset=0; - mssql_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlZ", &mssql_result_index, &row, &field) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - if (row < 0 || row >= result->num_rows) { - php_error_docref(NULL, E_WARNING, "Bad row offset (%ld)", row); - RETURN_FALSE; - } - - switch(Z_TYPE_PP(field)) { - case IS_STRING: { - int i; - - for (i=0; inum_fields; i++) { - if (!strcasecmp(result->fields[i].name, Z_STRVAL_PP(field))) { - field_offset = i; - break; - } - } - if (i>=result->num_fields) { /* no match found */ - php_error_docref(NULL, E_WARNING, "%s field not found in result", Z_STRVAL_PP(field)); - RETURN_FALSE; - } - break; - } - default: - convert_to_long_ex(field); - field_offset = Z_LVAL_PP(field); - if (field_offset<0 || field_offset>=result->num_fields) { - php_error_docref(NULL, E_WARNING, "Bad column offset specified"); - RETURN_FALSE; - } - break; - } - - *return_value = result->data[row][field_offset]; - zval_copy_ctor(return_value); -} -/* }}} */ - -/* {{{ proto bool mssql_next_result(resource result_id) - Move the internal result pointer to the next result */ -PHP_FUNCTION(mssql_next_result) -{ - zval *mssql_result_index; - int retvalue; - mssql_result *result; - mssql_link *mssql_ptr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_result_index) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(result, mssql_result *, &mssql_result_index, -1, "MS SQL-result", le_result); - - mssql_ptr = result->mssql_ptr; - retvalue = dbresults(mssql_ptr->link); - - while (dbnumcols(mssql_ptr->link) <= 0 && retvalue == SUCCEED) { - retvalue = dbresults(mssql_ptr->link); - } - - if (retvalue == FAIL) { - RETURN_FALSE; - } - else if (retvalue == NO_MORE_RESULTS || retvalue == NO_MORE_RPC_RESULTS) { - if (result->statement) { - _mssql_get_sp_result(mssql_ptr, result->statement); - } - RETURN_FALSE; - } - else { - _free_result(result, 1); - result->cur_row=result->num_fields=result->num_rows=0; - dbclrbuf(mssql_ptr->link,DBLASTROW(mssql_ptr->link)); - retvalue = dbnextrow(mssql_ptr->link); - - result->num_fields = dbnumcols(mssql_ptr->link); - result->fields = (mssql_field *) safe_emalloc(sizeof(mssql_field), result->num_fields, 0); - result->have_fields = 0; - result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue); - RETURN_TRUE; - } - -} -/* }}} */ - - -/* {{{ proto void mssql_min_error_severity(int severity) - Sets the lower error severity */ -PHP_FUNCTION(mssql_min_error_severity) -{ - zend_long severity; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &severity) == FAILURE) { - return; - } - - MS_SQL_G(min_error_severity) = severity; -} - -/* }}} */ - -/* {{{ proto void mssql_min_message_severity(int severity) - Sets the lower message severity */ -PHP_FUNCTION(mssql_min_message_severity) -{ - zend_long severity; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &severity) == FAILURE) { - return; - } - - MS_SQL_G(min_message_severity) = severity; -} -/* }}} */ - -/* {{{ proto int mssql_init(string sp_name [, resource conn_id]) - Initializes a stored procedure or a remote stored procedure */ -PHP_FUNCTION(mssql_init) -{ - char *sp_name; - size_t sp_name_len; - zval *mssql_link_index = NULL; - mssql_link *mssql_ptr; - mssql_statement *statement; - int id = -1; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|r", &sp_name, &sp_name_len, &mssql_link_index) == FAILURE) { - return; - } - - if (mssql_link_index == NULL) { - id = php_mssql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); - CHECK_LINK(id); - } - - ZEND_FETCH_RESOURCE2(mssql_ptr, mssql_link *, &mssql_link_index, id, "MS SQL-Link", le_link, le_plink); - - if (dbrpcinit(mssql_ptr->link, sp_name,0)==FAIL) { - php_error_docref(NULL, E_WARNING, "unable to init stored procedure"); - RETURN_FALSE; - } - - statement=NULL; - statement = ecalloc(1,sizeof(mssql_statement)); - statement->link = mssql_ptr; - statement->executed=FALSE; - - statement->id = zend_list_insert(statement,le_statement); - - RETURN_RESOURCE(statement->id); -} -/* }}} */ - -/* {{{ proto bool mssql_bind(resource stmt, string param_name, mixed var, int type [, bool is_output [, bool is_null [, int maxlen]]]) - Adds a parameter to a stored procedure or a remote stored procedure */ -PHP_FUNCTION(mssql_bind) -{ - char *param_name; - size_t param_name_len; - int datalen; - int status = 0; - zend_long type = 0, maxlen = -1; - zval *stmt, **var; - zend_bool is_output = 0, is_null = 0; - mssql_link *mssql_ptr; - mssql_statement *statement; - mssql_bind bind,*bindp; - LPBYTE value = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsZl|bbl", &stmt, ¶m_name, ¶m_name_len, &var, &type, &is_output, &is_null, &maxlen) == FAILURE) { - return; - } - - if (ZEND_NUM_ARGS() == 7 && !is_output) { - maxlen = -1; - } - - ZEND_FETCH_RESOURCE(statement, mssql_statement *, &stmt, -1, "MS SQL-Statement", le_statement); - - if (statement==NULL) { - RETURN_FALSE; - } - mssql_ptr=statement->link; - - /* modify datalen and maxlen according to dbrpcparam documentation */ - if ( (type==SQLVARCHAR) || (type==SQLCHAR) || (type==SQLTEXT) ) { /* variable-length type */ - if (is_null) { - maxlen=0; - datalen=0; - } else { - convert_to_string_ex(var); - datalen=Z_STRLEN_PP(var); - value=(LPBYTE)Z_STRVAL_PP(var); - } - } else { - /* fixed-length type */ - if (is_null) { - datalen=0; - } else { - datalen=-1; - } - maxlen=-1; - - switch (type) { - case SQLFLT4: - case SQLFLT8: - case SQLFLTN: - convert_to_double_ex(var); - value=(LPBYTE)(&Z_DVAL_PP(var)); - break; - - case SQLBIT: - case SQLINT1: - case SQLINT2: - case SQLINT4: - convert_to_long_ex(var); - value=(LPBYTE)(&Z_LVAL_PP(var)); - break; - - default: - php_error_docref(NULL, E_WARNING, "unsupported type"); - RETURN_FALSE; - break; - } - } - - if (is_output) { - status=DBRPCRETURN; - } - - /* hashtable of binds */ - if (! statement->binds) { - ALLOC_HASHTABLE(statement->binds); - zend_hash_init(statement->binds, 13, NULL, _mssql_bind_hash_dtor, 0); - } - - if (zend_hash_exists(statement->binds, param_name, param_name_len)) { - RETURN_FALSE; - } - else { - memset((void*)&bind,0,sizeof(mssql_bind)); - zend_hash_add(statement->binds, param_name, param_name_len, &bind, sizeof(mssql_bind), (void **)&bindp); - if( NULL == bindp ) RETURN_FALSE; - bindp->zval=*var; - zval_add_ref(var); - - /* no call to dbrpcparam if RETVAL */ - if ( strcmp("RETVAL", param_name)!=0 ) { - if (dbrpcparam(mssql_ptr->link, param_name, (BYTE)status, type, maxlen, datalen, (LPBYTE)value)==FAIL) { - php_error_docref(NULL, E_WARNING, "Unable to set parameter"); - RETURN_FALSE; - } - } - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto mixed mssql_execute(resource stmt [, bool skip_results = false]) - Executes a stored procedure on a MS-SQL server database */ -PHP_FUNCTION(mssql_execute) -{ - zval *stmt; - zend_bool skip_results = 0; - int retvalue, retval_results; - mssql_link *mssql_ptr; - mssql_statement *statement; - mssql_result *result; - int num_fields; - int batchsize; - int exec_retval; - - batchsize = MS_SQL_G(batchsize); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|b", &stmt, &skip_results) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(statement, mssql_statement *, &stmt, -1, "MS SQL-Statement", le_statement); - - mssql_ptr=statement->link; - exec_retval = dbrpcexec(mssql_ptr->link); - - if (exec_retval == FAIL || dbsqlok(mssql_ptr->link) == FAIL) { - php_error_docref(NULL, E_WARNING, "stored procedure execution failed"); - - if (exec_retval == FAIL) { - dbcancel(mssql_ptr->link); - } - - RETURN_FALSE; - } - - retval_results=dbresults(mssql_ptr->link); - - if (retval_results==FAIL) { - php_error_docref(NULL, E_WARNING, "could not retrieve results"); - dbcancel(mssql_ptr->link); - RETURN_FALSE; - } - - /* The following is just like mssql_query, fetch all rows from the first result - * set into the row buffer. - */ - result=NULL; - if (retval_results == SUCCEED) { - if (skip_results) { - do { - dbcanquery(mssql_ptr->link); - retval_results = dbresults(mssql_ptr->link); - } while (retval_results == SUCCEED); - } - else { - /* Skip results not returning any columns */ - while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retval_results == SUCCEED) { - retval_results = dbresults(mssql_ptr->link); - } - if ((num_fields = dbnumcols(mssql_ptr->link)) > 0) { - retvalue = dbnextrow(mssql_ptr->link); - result = (mssql_result *) emalloc(sizeof(mssql_result)); - result->batchsize = batchsize; - result->blocks_initialized = 1; - result->data = (zval **) safe_emalloc(sizeof(zval *), MSSQL_ROWS_BLOCK, 0); - result->mssql_ptr = mssql_ptr; - result->cur_field=result->cur_row=result->num_rows=0; - result->num_fields = num_fields; - result->have_fields = 0; - - result->fields = (mssql_field *) safe_emalloc(sizeof(mssql_field), num_fields, 0); - result->statement = statement; - result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue); - } - } - } - if (retval_results == NO_MORE_RESULTS || retval_results == NO_MORE_RPC_RESULTS) { - _mssql_get_sp_result(mssql_ptr, statement); - } - - if (result==NULL) { - RETURN_TRUE; /* no recordset returned ...*/ - } - else { - ZEND_REGISTER_RESOURCE(return_value, result, le_result); - } -} -/* }}} */ - -/* {{{ proto bool mssql_free_statement(resource result_index) - Free a MS-SQL statement index */ -PHP_FUNCTION(mssql_free_statement) -{ - zval *mssql_statement_index; - mssql_statement *statement; - int retvalue; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mssql_statement_index) == FAILURE) { - return; - } - - if (Z_RESVAL_P(mssql_statement_index) == 0) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(statement, mssql_statement *, &mssql_statement_index, -1, "MS SQL-statement", le_statement); - /* Release remaining results */ - do { - dbcanquery(statement->link->link); - retvalue = dbresults(statement->link->link); - } while (retvalue == SUCCEED); - - zend_list_delete(Z_RESVAL_P(mssql_statement_index)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string mssql_guid_string(string binary [,bool short_format]) - Converts a 16 byte binary GUID to a string */ -PHP_FUNCTION(mssql_guid_string) -{ - char *binary; - size_t binary_len; - zend_bool sf = 0; - char buffer[32+1]; - char buffer2[36+1]; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &binary, &binary_len, &sf) == FAILURE) { - return; - } - - dbconvert(NULL, SQLBINARY, (BYTE*) binary, MIN(16, binary_len), SQLCHAR, buffer, -1); - - if (sf) { - php_strtoupper(buffer, 32); - RETURN_STRING(buffer, 1); - } - else { - int i; - /* FIXME this works only on little endian machine */ - for (i=0; i<4; i++) { - buffer2[2*i] = buffer[6-2*i]; - buffer2[2*i+1] = buffer[7-2*i]; - } - buffer2[8] = '-'; - for (i=0; i<2; i++) { - buffer2[9+2*i] = buffer[10-2*i]; - buffer2[10+2*i] = buffer[11-2*i]; - } - buffer2[13] = '-'; - for (i=0; i<2; i++) { - buffer2[14+2*i] = buffer[14-2*i]; - buffer2[15+2*i] = buffer[15-2*i]; - } - buffer2[18] = '-'; - for (i=0; i<4; i++) { - buffer2[19+i] = buffer[16+i]; - } - buffer2[23] = '-'; - for (i=0; i<12; i++) { - buffer2[24+i] = buffer[20+i]; - } - buffer2[36] = 0; - - php_strtoupper(buffer2, 36); - RETURN_STRING(buffer2, 1); - } -} -/* }}} */ - -#endif diff --git a/ext/mssql/php_mssql.h b/ext/mssql/php_mssql.h deleted file mode 100644 index 18a82ef652e83..0000000000000 --- a/ext/mssql/php_mssql.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Frank M. Kromann | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef PHP_MSSQL_H -#define PHP_MSSQL_H - - -#if HAVE_MSSQL -#define MSDBLIB - -/* FreeTDS checks for PHP_MSSQL_API for avoid type redefinition */ -#ifdef HAVE_FREETDS -#define PHP_MSSQL_API -#endif - -#include -#include - -typedef short TDS_SHORT; -#ifdef HAVE_FREETDS -#define MSSQL_VERSION "FreeTDS" -#define SQLTEXT SYBTEXT -#define SQLCHAR SYBCHAR -#define SQLVARCHAR SYBVARCHAR -#define SQLINT1 SYBINT1 -#define SQLINT2 SYBINT2 -#define SQLINT4 SYBINT4 -#define SQLINTN SYBINTN -#define SQLBIT SYBBIT -#define SQLFLT4 SYBREAL -#define SQLFLT8 SYBFLT8 -#define SQLFLTN SYBFLTN -#define SQLDECIMAL SYBDECIMAL -#define SQLNUMERIC SYBNUMERIC -#define SQLDATETIME SYBDATETIME -#define SQLDATETIM4 SYBDATETIME4 -#define SQLDATETIMN SYBDATETIMN -#define SQLMONEY SYBMONEY -#define SQLMONEY4 SYBMONEY4 -#define SQLMONEYN SYBMONEYN -#define SQLIMAGE SYBIMAGE -#define SQLBINARY SYBBINARY -#define SQLVARBINARY SYBVARBINARY -#ifdef SQLUNIQUE /* FreeTSD 0.61+ */ -#define SQLUNIQUE SYBUNIQUE -#endif -#define DBERRHANDLE(a, b) dberrhandle(b) -#define DBMSGHANDLE(a, b) dbmsghandle(b) -#define DBSETOPT(a, b, c) dbsetopt(a, b, c, -1) -#define NO_MORE_RPC_RESULTS 3 -#ifndef dbfreelogin -#define dbfreelogin dbloginfree -#endif -#define dbrpcexec dbrpcsend -typedef unsigned char *LPBYTE; -typedef float DBFLT4; -#else -#define MSSQL_VERSION "7.0" -#define DBERRHANDLE(a, b) dbprocerrhandle(a, b) -#define DBMSGHANDLE(a, b) dbprocmsghandle(a, b) -#define EHANDLEFUNC DBERRHANDLE_PROC -#define MHANDLEFUNC DBMSGHANDLE_PROC -#define DBSETOPT(a, b, c) dbsetopt(a, b, c) -#endif - -#define coltype(j) dbcoltype(mssql_ptr->link,j) -#define intcol(i) ((int) *(DBINT *) dbdata(mssql_ptr->link,i)) -#define smallintcol(i) ((int) *(DBSMALLINT *) dbdata(mssql_ptr->link,i)) -#define tinyintcol(i) ((int) *(DBTINYINT *) dbdata(mssql_ptr->link,i)) -#define anyintcol(j) (coltype(j)==SQLINT4?intcol(j):(coltype(j)==SQLINT2?smallintcol(j):tinyintcol(j))) -#define charcol(i) ((DBCHAR *) dbdata(mssql_ptr->link,i)) -#define floatcol4(i) (*(DBFLT4 *) dbdata(mssql_ptr->link,i)) -#define floatcol8(i) (*(DBFLT8 *) dbdata(mssql_ptr->link,i)) - -#ifdef ZTS -#include "TSRM.h" -#endif - -extern zend_module_entry mssql_module_entry; -#define mssql_module_ptr &mssql_module_entry - -PHP_MINIT_FUNCTION(mssql); -PHP_MSHUTDOWN_FUNCTION(mssql); -PHP_RINIT_FUNCTION(mssql); -PHP_RSHUTDOWN_FUNCTION(mssql); -PHP_MINFO_FUNCTION(mssql); - -PHP_FUNCTION(mssql_connect); -PHP_FUNCTION(mssql_pconnect); -PHP_FUNCTION(mssql_close); -PHP_FUNCTION(mssql_select_db); -PHP_FUNCTION(mssql_query); -PHP_FUNCTION(mssql_fetch_batch); -PHP_FUNCTION(mssql_rows_affected); -PHP_FUNCTION(mssql_free_result); -PHP_FUNCTION(mssql_get_last_message); -PHP_FUNCTION(mssql_num_rows); -PHP_FUNCTION(mssql_num_fields); -PHP_FUNCTION(mssql_fetch_field); -PHP_FUNCTION(mssql_fetch_row); -PHP_FUNCTION(mssql_fetch_array); -PHP_FUNCTION(mssql_fetch_assoc); -PHP_FUNCTION(mssql_fetch_object); -PHP_FUNCTION(mssql_field_length); -PHP_FUNCTION(mssql_field_name); -PHP_FUNCTION(mssql_field_type); -PHP_FUNCTION(mssql_data_seek); -PHP_FUNCTION(mssql_field_seek); -PHP_FUNCTION(mssql_result); -PHP_FUNCTION(mssql_next_result); -PHP_FUNCTION(mssql_min_error_severity); -PHP_FUNCTION(mssql_min_message_severity); -PHP_FUNCTION(mssql_init); -PHP_FUNCTION(mssql_bind); -PHP_FUNCTION(mssql_execute); -PHP_FUNCTION(mssql_free_statement); -PHP_FUNCTION(mssql_guid_string); - -typedef struct mssql_link { - LOGINREC *login; - DBPROCESS *link; - int valid; -} mssql_link; - -typedef struct mssql_statement { - int id; - mssql_link *link; - HashTable *binds; - int executed; -} mssql_statement; - -typedef struct { - - zval *zval; - /* TODO: more data for special types (BLOBS, NUMERIC...) */ -} mssql_bind; - -ZEND_BEGIN_MODULE_GLOBALS(mssql) - long default_link; - long num_links,num_persistent; - long max_links,max_persistent; - zend_bool allow_persistent; - char *appname; - char *server_message; -#ifdef HAVE_FREETDS - char *charset; -#endif - long min_error_severity, min_message_severity; - long cfg_min_error_severity, cfg_min_message_severity; - long connect_timeout, timeout; - zend_bool compatibility_mode; - void (*get_column_content)(mssql_link *mssql_ptr,int offset,zval *result,int column_type ); - long textsize, textlimit, batchsize; - zend_bool datetimeconvert; - HashTable *resource_list, *resource_plist; - zend_bool secure_connection; - long max_procs; -ZEND_END_MODULE_GLOBALS(mssql) - -#define MSSQL_ROWS_BLOCK 128 - -typedef struct mssql_field { - char *name,*column_source; - long max_length; - int numeric; - int type; -} mssql_field; - -typedef struct mssql_result { - zval **data; - mssql_field *fields; - mssql_link *mssql_ptr; - mssql_statement * statement; - int batchsize; - int lastresult; - int blocks_initialized; - int cur_row,cur_field; - int num_rows,num_fields,have_fields; -} mssql_result; - - -#ifdef ZTS -# define MS_SQL_G(v) TSRMG(mssql_globals_id, zend_mssql_globals *, v) -#else -# define MS_SQL_G(v) (mssql_globals.v) -#endif - -#else - -#define mssql_module_ptr NULL - -#endif /* HAVE_MSSQL */ - -#define phpext_mssql_ptr mssql_module_ptr - -#endif /* PHP_MSSQL_H */ diff --git a/ext/mysqlnd/mysqlnd_plugin.c b/ext/mysqlnd/mysqlnd_plugin.c index 243dae41d7120..d0709282f190d 100644 --- a/ext/mysqlnd/mysqlnd_plugin.c +++ b/ext/mysqlnd/mysqlnd_plugin.c @@ -168,10 +168,6 @@ PHPAPI void * _mysqlnd_plugin_find(const char * const name) /* {{{ _mysqlnd_plugin_apply_with_argument */ PHPAPI void _mysqlnd_plugin_apply_with_argument(apply_func_arg_t apply_func, void * argument) { - /* Note: We want to be thread-safe (read-only), so we can use neither - * zend_hash_apply_with_argument nor zend_hash_internal_pointer_reset and - * friends - */ zval *val; int result; diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c index 7948990f81302..4db48944e170f 100644 --- a/ext/opcache/Optimizer/block_pass.c +++ b/ext/opcache/Optimizer/block_pass.c @@ -166,14 +166,16 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: - case ZEND_FE_RESET: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: case ZEND_NEW: case ZEND_JMP_SET: case ZEND_COALESCE: START_BLOCK_OP(ZEND_OP2(opline).opline_num); START_BLOCK_OP(opno + 1); break; - case ZEND_FE_FETCH: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: START_BLOCK_OP(ZEND_OP2(opline).opline_num); START_BLOCK_OP(opno + 2); break; @@ -205,12 +207,15 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz for (i = 0; i< op_array->last_brk_cont; i++) { if (op_array->brk_cont_array[i].start >= 0 && (op_array->opcodes[op_array->brk_cont_array[i].brk].opcode == ZEND_FREE || + op_array->opcodes[op_array->brk_cont_array[i].brk].opcode == ZEND_FE_FREE || op_array->opcodes[op_array->brk_cont_array[i].brk].opcode == ZEND_END_SILENCE)) { int parent = op_array->brk_cont_array[i].parent; while (parent >= 0 && op_array->brk_cont_array[parent].start < 0 && - op_array->opcodes[op_array->brk_cont_array[parent].brk].opcode != ZEND_FREE) { + (op_array->opcodes[op_array->brk_cont_array[parent].brk].opcode != ZEND_FREE || + op_array->opcodes[op_array->brk_cont_array[parent].brk].opcode != ZEND_FE_FREE || + op_array->opcodes[op_array->brk_cont_array[parent].brk].opcode != ZEND_END_SILENCE)) { parent = op_array->brk_cont_array[parent].parent; } op_array->brk_cont_array[i].parent = parent; @@ -225,6 +230,7 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz for (i = 0; i< op_array->last_brk_cont; i++) { if (op_array->brk_cont_array[i].start >= 0 && (op_array->opcodes[op_array->brk_cont_array[i].brk].opcode == ZEND_FREE || + op_array->opcodes[op_array->brk_cont_array[i].brk].opcode == ZEND_FE_FREE || op_array->opcodes[op_array->brk_cont_array[i].brk].opcode == ZEND_END_SILENCE)) { if (i != j) { op_array->brk_cont_array[j] = op_array->brk_cont_array[i]; @@ -293,11 +299,13 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: - case ZEND_FE_RESET: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: case ZEND_NEW: case ZEND_JMP_SET: case ZEND_COALESCE: - case ZEND_FE_FETCH: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: cur_block->op2_to = &blocks[ZEND_OP2(opline).opline_num]; /* break missing intentionally */ default: @@ -619,7 +627,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array, ZEND_OP1_TYPE(VAR_SOURCE(opline->op1)) == IS_CONST && opline->opcode != ZEND_CASE && /* CASE _always_ expects variable */ opline->opcode != ZEND_FETCH_LIST && - opline->opcode != ZEND_FE_RESET && + (opline->opcode != ZEND_FE_RESET_R || opline->opcode != ZEND_FE_RESET_RW) && opline->opcode != ZEND_FREE ) { zend_op *src = VAR_SOURCE(opline->op1); diff --git a/ext/opcache/Optimizer/nop_removal.c b/ext/opcache/Optimizer/nop_removal.c index 0bb8cce17fbc9..dccd010ae4421 100644 --- a/ext/opcache/Optimizer/nop_removal.c +++ b/ext/opcache/Optimizer/nop_removal.c @@ -93,8 +93,10 @@ void zend_optimizer_nop_removal(zend_op_array *op_array) case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: - case ZEND_FE_FETCH: - case ZEND_FE_RESET: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: case ZEND_NEW: case ZEND_JMP_SET: case ZEND_COALESCE: diff --git a/ext/opcache/Optimizer/optimize_temp_vars_5.c b/ext/opcache/Optimizer/optimize_temp_vars_5.c index 27ba6bad8e542..dc93ce2f4c807 100644 --- a/ext/opcache/Optimizer/optimize_temp_vars_5.c +++ b/ext/opcache/Optimizer/optimize_temp_vars_5.c @@ -66,16 +66,6 @@ void optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *c if (ZEND_RESULT_TYPE(opline) & (IS_VAR | IS_TMP_VAR)) { start_of_T[VAR_NUM(ZEND_RESULT(opline).var) - offset] = opline; } - /* special puprose variable to keep HashPointer on VM stack */ - if (opline->opcode == ZEND_OP_DATA && - (opline-1)->opcode == ZEND_FE_FETCH && - opline->op1_type == IS_TMP_VAR) { - start_of_T[VAR_NUM(ZEND_OP1(opline).var) - offset] = opline; - if (sizeof(HashPointer) > sizeof(zval)) { - /* Make shure 1 zval is enough for HashPointer (2 must be enough) */ - start_of_T[VAR_NUM(ZEND_OP1(opline).var) + 1 - offset] = opline; - } - } opline--; } @@ -88,25 +78,13 @@ void optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *c while (opline >= end) { if ((ZEND_OP1_TYPE(opline) & (IS_VAR | IS_TMP_VAR))) { - /* special puprose variable to keep HashPointer on VM stack */ - if (opline->opcode == ZEND_OP_DATA && - (opline-1)->opcode == ZEND_FE_FETCH && - opline->op1_type == IS_TMP_VAR) { - max++; - ZEND_OP1(opline).var = NUM_VAR(max + offset); - if (sizeof(HashPointer) > sizeof(zval)) { - /* Make shure 1 zval is enough for HashPointer (2 must be enough) */ - max++; - } - } else { - currT = VAR_NUM(ZEND_OP1(opline).var) - offset; - if (!valid_T[currT]) { - GET_AVAILABLE_T(); - map_T[currT] = i; - valid_T[currT] = 1; - } - ZEND_OP1(opline).var = NUM_VAR(map_T[currT] + offset); + currT = VAR_NUM(ZEND_OP1(opline).var) - offset; + if (!valid_T[currT]) { + GET_AVAILABLE_T(); + map_T[currT] = i; + valid_T[currT] = 1; } + ZEND_OP1(opline).var = NUM_VAR(map_T[currT] + offset); } /* Skip OP_DATA */ diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c index 348fcb8efbe01..341e80501b44f 100644 --- a/ext/opcache/Optimizer/pass1_5.c +++ b/ext/opcache/Optimizer/pass1_5.c @@ -602,8 +602,10 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx) case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: - case ZEND_FE_RESET: - case ZEND_FE_FETCH: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: case ZEND_NEW: case ZEND_JMP_SET: case ZEND_COALESCE: diff --git a/ext/opcache/Optimizer/pass2.c b/ext/opcache/Optimizer/pass2.c index 5be1e30c9fc06..b5785924932f5 100644 --- a/ext/opcache/Optimizer/pass2.c +++ b/ext/opcache/Optimizer/pass2.c @@ -203,7 +203,9 @@ void zend_optimizer_pass2(zend_op_array *op_array) jmp_to = &op_array->brk_cont_array[array_offset]; array_offset = jmp_to->parent; if (--nest_levels > 0) { - if (op_array->opcodes[jmp_to->brk].opcode == ZEND_FREE) { + if (op_array->opcodes[jmp_to->brk].opcode == ZEND_FREE || + op_array->opcodes[jmp_to->brk].opcode == ZEND_FE_FREE || + op_array->opcodes[jmp_to->brk].opcode == ZEND_END_SILENCE) { dont_optimize = 1; break; } diff --git a/ext/opcache/Optimizer/pass3.c b/ext/opcache/Optimizer/pass3.c index c3a55b319f194..3019b274e953a 100644 --- a/ext/opcache/Optimizer/pass3.c +++ b/ext/opcache/Optimizer/pass3.c @@ -328,7 +328,8 @@ void zend_optimizer_pass3(zend_op_array *op_array) op->opcode == ZEND_RETURN || op->opcode == ZEND_RETURN_BY_REF || op->opcode == ZEND_FAST_RET || - op->opcode == ZEND_FE_FETCH || + op->opcode == ZEND_FE_FETCH_R || + op->opcode == ZEND_FE_FETCH_RW || op->opcode == ZEND_EXIT) { break; } @@ -363,7 +364,8 @@ void zend_optimizer_pass3(zend_op_array *op_array) op->opcode == ZEND_RETURN || op->opcode == ZEND_RETURN_BY_REF || op->opcode == ZEND_FAST_RET || - op->opcode == ZEND_FE_FETCH || + op->opcode == ZEND_FE_FETCH_R || + op->opcode == ZEND_FE_FETCH_RW || op->opcode == ZEND_EXIT) { break; } diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 54063d0ed3292..a8506fb0789a8 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -450,8 +450,10 @@ static void zend_accel_optimize(zend_op_array *op_array, case ZEND_JMP_SET: case ZEND_COALESCE: case ZEND_NEW: - case ZEND_FE_RESET: - case ZEND_FE_FETCH: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, ZEND_OP2(opline)); break; } @@ -488,8 +490,10 @@ static void zend_accel_optimize(zend_op_array *op_array, case ZEND_JMP_SET: case ZEND_COALESCE: case ZEND_NEW: - case ZEND_FE_RESET: - case ZEND_FE_FETCH: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, ZEND_OP2(opline)); break; } diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 3d63f96e346d9..5b32baa64b5e4 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -378,8 +378,10 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc case ZEND_JMP_SET: case ZEND_COALESCE: case ZEND_NEW: - case ZEND_FE_RESET: - case ZEND_FE_FETCH: + case ZEND_FE_RESET_R: + case ZEND_FE_RESET_RW: + case ZEND_FE_FETCH_R: + case ZEND_FE_FETCH_RW: ZEND_OP2(opline).jmp_addr = &new_opcodes[ZEND_OP2(opline).jmp_addr - op_array->opcodes]; break; } diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index c255fd91740e0..8a6ecb5817c7b 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -998,6 +998,7 @@ static zend_string *preg_do_repl_func(zval *function, char *subject, int *offset /* {{{ php_pcre_replace */ PHPAPI zend_string *php_pcre_replace(zend_string *regex, + zend_string *subject_str, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int limit, int *replace_count) @@ -1009,13 +1010,13 @@ PHPAPI zend_string *php_pcre_replace(zend_string *regex, return NULL; } - return php_pcre_replace_impl(pce, subject, subject_len, replace_val, + return php_pcre_replace_impl(pce, subject_str, subject, subject_len, replace_val, is_callable_replace, limit, replace_count); } /* }}} */ /* {{{ php_pcre_replace_impl() */ -PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, +PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *subject_str, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int limit, int *replace_count) { pcre_extra *extra = pce->extra;/* Holds results of studying */ @@ -1084,8 +1085,8 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, } } - alloc_len = 2 * subject_len; - result = zend_string_alloc(alloc_len * sizeof(char), 0); + alloc_len = 0; + result = NULL; /* Initialize */ match = NULL; @@ -1148,9 +1149,17 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, } } - if (new_len > alloc_len) { - alloc_len = alloc_len + 2 * new_len; - result = zend_string_realloc(result, alloc_len, 0); + if (new_len >= alloc_len) { + if (alloc_len == 0) { + alloc_len = 2 * subject_len; + if (new_len >= alloc_len) { + alloc_len = alloc_len + 2 * new_len; + } + result = zend_string_alloc(alloc_len, 0); + } else { + alloc_len = alloc_len + 2 * new_len; + result = zend_string_realloc(result, alloc_len, 0); + } } /* copy the part of the string before the match */ memcpy(&result->val[result_len], piece, match-piece); @@ -1205,6 +1214,10 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, memcpy(&result->val[result_len], piece, 1); result_len++; } else { + if (!result && subject_str) { + result = zend_string_copy(subject_str); + break; + } new_len = result_len + subject_len - start_offset; if (new_len > alloc_len) { alloc_len = new_len; /* now we know exactly how long it is */ @@ -1214,12 +1227,15 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, memcpy(&result->val[result_len], piece, subject_len - start_offset); result_len += subject_len - start_offset; result->val[result_len] = '\0'; + result->len = result_len; break; } } else { pcre_handle_exec_error(count); - zend_string_free(result); - result = NULL; + if (result) { + zend_string_free(result); + result = NULL; + } break; } @@ -1233,9 +1249,6 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, start_offset = offsets[1]; } - if (result) { - result->len = result_len; - } if (size_offsets <= 32) { free_alloca(offsets, use_heap); } else { @@ -1300,6 +1313,7 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub /* Do the actual replacement and put the result back into subject_str for further replacements. */ if ((result = php_pcre_replace(regex_str, + subject_str, subject_str->val, (int)subject_str->len, replace_value, @@ -1320,6 +1334,7 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub return subject_str; } else { result = php_pcre_replace(Z_STR_P(regex), + subject_str, subject_str->val, (int)subject_str->len, replace, diff --git a/ext/pcre/php_pcre.h b/ext/pcre/php_pcre.h index dc923fe62f625..88f810493ff00 100644 --- a/ext/pcre/php_pcre.h +++ b/ext/pcre/php_pcre.h @@ -33,7 +33,7 @@ #include #endif -PHPAPI zend_string *php_pcre_replace(zend_string *regex, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int limit, int *replace_count); +PHPAPI zend_string *php_pcre_replace(zend_string *regex, zend_string *subject_str, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int limit, int *replace_count); PHPAPI pcre* pcre_get_compiled_regex(zend_string *regex, pcre_extra **extra, int *options); PHPAPI pcre* pcre_get_compiled_regex_ex(zend_string *regex, pcre_extra **extra, int *preg_options, int *coptions); @@ -59,7 +59,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex); PHPAPI void php_pcre_match_impl( pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, zval *subpats, int global, int use_flags, zend_long flags, zend_long start_offset); -PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, +PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *subject_str, char *subject, int subject_len, zval *return_value, int is_callable_replace, int limit, int *replace_count); PHPAPI void php_pcre_split_impl( pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c index d29e3b13b7231..11e245d7d1792 100644 --- a/ext/pdo/pdo_sql_parser.c +++ b/ext/pdo/pdo_sql_parser.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.7.5 */ +/* Generated by re2c 0.13.5 */ #line 1 "ext/pdo/pdo_sql_parser.re" /* +----------------------------------------------------------------------+ @@ -70,10 +70,9 @@ static int scan(Scanner *s) } yy2: YYCURSOR = YYMARKER; - if (yyaccept == 0) { - goto yy4; - } else { - goto yy10; + switch (yyaccept) { + case 0: goto yy4; + case 1: goto yy10; } yy3: yyaccept = 0; @@ -82,7 +81,7 @@ static int scan(Scanner *s) yy4: #line 63 "ext/pdo/pdo_sql_parser.re" { SKIP_ONE(PDO_PARSER_TEXT); } -#line 86 "ext/pdo/pdo_sql_parser.c" +#line 85 "ext/pdo/pdo_sql_parser.c" yy5: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); @@ -166,7 +165,7 @@ static int scan(Scanner *s) yy8: #line 62 "ext/pdo/pdo_sql_parser.re" { RET(PDO_PARSER_BIND_POS); } -#line 170 "ext/pdo/pdo_sql_parser.c" +#line 169 "ext/pdo/pdo_sql_parser.c" yy9: ++YYCURSOR; switch ((yych = *YYCURSOR)) { @@ -176,7 +175,7 @@ static int scan(Scanner *s) yy10: #line 65 "ext/pdo/pdo_sql_parser.re" { RET(PDO_PARSER_TEXT); } -#line 180 "ext/pdo/pdo_sql_parser.c" +#line 179 "ext/pdo/pdo_sql_parser.c" yy11: yych = *++YYCURSOR; switch (yych) { @@ -213,7 +212,7 @@ static int scan(Scanner *s) yy16: #line 64 "ext/pdo/pdo_sql_parser.re" { RET(PDO_PARSER_TEXT); } -#line 217 "ext/pdo/pdo_sql_parser.c" +#line 216 "ext/pdo/pdo_sql_parser.c" yy17: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -293,7 +292,7 @@ static int scan(Scanner *s) yy31: #line 60 "ext/pdo/pdo_sql_parser.re" { RET(PDO_PARSER_TEXT); } -#line 297 "ext/pdo/pdo_sql_parser.c" +#line 296 "ext/pdo/pdo_sql_parser.c" yy32: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -367,7 +366,7 @@ static int scan(Scanner *s) yy34: #line 61 "ext/pdo/pdo_sql_parser.re" { RET(PDO_PARSER_BIND); } -#line 371 "ext/pdo/pdo_sql_parser.c" +#line 370 "ext/pdo/pdo_sql_parser.c" yy35: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -397,7 +396,7 @@ static int scan(Scanner *s) ++YYCURSOR; #line 59 "ext/pdo/pdo_sql_parser.re" { RET(PDO_PARSER_TEXT); } -#line 401 "ext/pdo/pdo_sql_parser.c" +#line 400 "ext/pdo/pdo_sql_parser.c" yy42: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -419,7 +418,7 @@ static int scan(Scanner *s) ++YYCURSOR; #line 58 "ext/pdo/pdo_sql_parser.re" { RET(PDO_PARSER_TEXT); } -#line 423 "ext/pdo/pdo_sql_parser.c" +#line 422 "ext/pdo/pdo_sql_parser.c" } #line 66 "ext/pdo/pdo_sql_parser.re" @@ -781,9 +780,7 @@ int old_pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char padding = 3; } if(params) { - HashPosition *param_pos; - zend_hash_internal_pointer_reset(params); - while ((param == zend_hash_get_current_data_ptr_ex(params, ¶m_pos)) != NULL) { + ZEND_HASH_FOREACH_PTR(params, param) { if(param->parameter) { convert_to_string(param->parameter); /* accommodate a string that needs to be fully quoted @@ -792,8 +789,7 @@ int old_pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char */ newbuffer_len += padding * Z_STRLEN_P(param->parameter); } - zend_hash_move_forward(params); - } + } ZEND_HASH_FOREACH_END(); } *outquery = (char *) emalloc(newbuffer_len + 1); *outquery_len = 0; diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index ef989d35c4dd6..1297e45db7996 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -422,9 +422,7 @@ int old_pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char padding = 3; } if(params) { - HashPosition *param_pos; - zend_hash_internal_pointer_reset(params); - while ((param == zend_hash_get_current_data_ptr_ex(params, ¶m_pos)) != NULL) { + ZEND_HASH_FOREACH_PTR(params, param) { if(param->parameter) { convert_to_string(param->parameter); /* accommodate a string that needs to be fully quoted @@ -433,8 +431,7 @@ int old_pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char */ newbuffer_len += padding * Z_STRLEN_P(param->parameter); } - zend_hash_move_forward(params); - } + } ZEND_HASH_FOREACH_END(); } *outquery = (char *) emalloc(newbuffer_len + 1); *outquery_len = 0; diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 194c7ee99b999..92b5d9da5fc0f 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -447,36 +447,27 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in /* counting static properties */ count = zend_hash_num_elements(&ce->properties_info); if (count > 0) { - HashPosition pos; zend_property_info *prop; - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - - while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { + ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { if(prop->flags & ZEND_ACC_SHADOW) { count_shadow_props++; } else if (prop->flags & ZEND_ACC_STATIC) { count_static_props++; } - zend_hash_move_forward_ex(&ce->properties_info, &pos); - } + } ZEND_HASH_FOREACH_END(); } /* static properties */ string_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props); if (count_static_props > 0) { - HashPosition pos; zend_property_info *prop; - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - - while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { + ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { _property_string(str, prop, NULL, sub_indent.buf->val); } - - zend_hash_move_forward_ex(&ce->properties_info, &pos); - } + } ZEND_HASH_FOREACH_END(); } string_printf(str, "%s }\n", indent); } @@ -486,38 +477,30 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in /* counting static methods */ count = zend_hash_num_elements(&ce->function_table); if (count > 0) { - HashPosition pos; zend_function *mptr; - zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - - while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) { + ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { if (mptr->common.fn_flags & ZEND_ACC_STATIC && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { count_static_funcs++; } - zend_hash_move_forward_ex(&ce->function_table, &pos); - } + } ZEND_HASH_FOREACH_END(); } /* static methods */ string_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs); if (count_static_funcs > 0) { - HashPosition pos; zend_function *mptr; - zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - - while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) { + ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { if (mptr->common.fn_flags & ZEND_ACC_STATIC && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { string_printf(str, "\n"); _function_string(str, mptr, ce, sub_indent.buf->val); } - zend_hash_move_forward_ex(&ce->function_table, &pos); - } + } ZEND_HASH_FOREACH_END(); } else { string_printf(str, "\n"); } @@ -529,17 +512,13 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props; string_printf(str, "\n%s - Properties [%d] {\n", indent, count); if (count > 0) { - HashPosition pos; zend_property_info *prop; - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - - while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { + ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { _property_string(str, prop, NULL, sub_indent.buf->val); } - zend_hash_move_forward_ex(&ce->properties_info, &pos); - } + } ZEND_HASH_FOREACH_END(); } string_printf(str, "%s }\n", indent); } @@ -547,29 +526,20 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) { string dyn; HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj); - HashPosition pos; - zval **prop; + zend_string *prop_name; string_init(&dyn); count = 0; if (properties && zend_hash_num_elements(properties)) { - zend_hash_internal_pointer_reset_ex(properties, &pos); - - while ((prop = zend_hash_get_current_data_ptr_ex(properties, &pos)) != NULL) { - zend_string *prop_name; - zend_ulong index; - - if (zend_hash_get_current_key_ex(properties, &prop_name, &index, &pos) == HASH_KEY_IS_STRING) { - if (prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */ - if (!zend_hash_exists(&ce->properties_info, prop_name)) { - count++; - _property_string(&dyn, NULL, prop_name->val, sub_indent.buf->val); - } + ZEND_HASH_FOREACH_STR_KEY(properties, prop_name) { + if (prop_name && prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */ + if (!zend_hash_exists(&ce->properties_info, prop_name)) { + count++; + _property_string(&dyn, NULL, prop_name->val, sub_indent.buf->val); } } - zend_hash_move_forward_ex(properties, &pos); - } + } ZEND_HASH_FOREACH_END(); } string_printf(str, "\n%s - Dynamic properties [%d] {\n", indent, count); @@ -582,26 +552,23 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in if (&ce->function_table) { count = zend_hash_num_elements(&ce->function_table) - count_static_funcs; if (count > 0) { - HashPosition pos; zend_function *mptr; + zend_string *key; string dyn; count = 0; string_init(&dyn); - zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) { + ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { - zend_string *key; - zend_ulong num_index; size_t len = mptr->common.function_name->len; /* Do not display old-style inherited constructors */ if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 || mptr->common.scope == ce - || zend_hash_get_current_key_ex(&ce->function_table, &key, &num_index, &pos) != HASH_KEY_IS_STRING + || !key || zend_binary_strcasecmp(key->val, key->len, mptr->common.function_name->val, len) == 0) { zend_function *closure; @@ -620,8 +587,7 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in _free_function(closure); } } - zend_hash_move_forward_ex(&ce->function_table, &pos); - } + } ZEND_HASH_FOREACH_END(); string_printf(str, "\n%s - Methods [%d] {", indent, count); if (!count) { string_printf(str, "\n"); @@ -777,10 +743,8 @@ static void _function_parameter_string(string *str, zend_function *fptr, char* i static void _function_closure_string(string *str, zend_function *fptr, char* indent) { uint32_t i, count; - zend_ulong num_index; zend_string *key; HashTable *static_variables; - HashPosition pos; if (fptr->type != ZEND_USER_FUNCTION || !fptr->op_array.static_variables) { return; @@ -795,13 +759,10 @@ static void _function_closure_string(string *str, zend_function *fptr, char* ind string_printf(str, "\n"); string_printf(str, "%s- Bound Variables [%d] {\n", indent, zend_hash_num_elements(static_variables)); - zend_hash_internal_pointer_reset_ex(static_variables, &pos); i = 0; - while (i < count) { - zend_hash_get_current_key_ex(static_variables, &key, &num_index, &pos); + ZEND_HASH_FOREACH_STR_KEY(static_variables, key) { string_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, key->val); - zend_hash_move_forward_ex(static_variables, &pos); - } + } ZEND_HASH_FOREACH_END(); string_printf(str, "%s}\n", indent); } /* }}} */ @@ -1118,12 +1079,10 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde } { - HashPosition iterator; zend_function *fptr; int first = 1; - zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); - while ((fptr = zend_hash_get_current_data_ptr_ex(CG(function_table), &iterator)) != NULL) { + ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { if (first) { @@ -1132,8 +1091,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde } _function_string(str, fptr, NULL, " "); } - zend_hash_move_forward_ex(CG(function_table), &iterator); - } + } ZEND_HASH_FOREACH_END(); if (!first) { string_printf(str, "%s }\n", indent); } @@ -5300,7 +5258,6 @@ ZEND_METHOD(reflection_extension, getFunctions) { reflection_object *intern; zend_module_entry *module; - HashPosition iterator; zval function; zend_function *fptr; @@ -5310,15 +5267,13 @@ ZEND_METHOD(reflection_extension, getFunctions) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); - while ((fptr = zend_hash_get_current_data_ptr_ex(CG(function_table), &iterator)) != NULL) { + ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { reflection_function_factory(fptr, NULL, &function); zend_hash_update(Z_ARRVAL_P(return_value), fptr->common.function_name, &function); } - zend_hash_move_forward_ex(CG(function_table), &iterator); - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt index cdd00d26248f0..20f4c95dc7a7d 100644 --- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt +++ b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt @@ -5,7 +5,7 @@ ReflectionParameter::isDefaultValueConstant() && getDefaultValueConstantName() define("CONST_TEST_1", "const1"); -function ReflectionParameterTest($test1=array(), $test2 = CONST_TEST_1) { +function ReflectionParameterTest($test1=array(), $test2 = CONST_TEST_1, $test3 = CASE_LOWER) { echo $test; } $reflect = new ReflectionFunction('ReflectionParameterTest'); @@ -46,6 +46,7 @@ foreach ($params as $param) { bool(false) bool(true) string(12) "CONST_TEST_1" +string(10) "CASE_LOWER" string(9) "self::bar" string(9) "Foo2::bar" string(12) "CONST_TEST_1" diff --git a/ext/session/mod_user_class.c b/ext/session/mod_user_class.c index 328416c02e161..82aea1485423a 100644 --- a/ext/session/mod_user_class.c +++ b/ext/session/mod_user_class.c @@ -80,7 +80,7 @@ PHP_METHOD(SessionHandler, read) return; } - if (PS(default_mod)->s_read(&PS(mod_data), key, &val) == FAILURE) { + if (PS(default_mod)->s_read(&PS(mod_data), key, &val, PS(gc_maxlifetime)) == FAILURE) { RETVAL_FALSE; return; } @@ -101,7 +101,7 @@ PHP_METHOD(SessionHandler, write) return; } - RETURN_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val)); + RETURN_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, PS(gc_maxlifetime))); } /* }}} */ @@ -186,6 +186,6 @@ PHP_METHOD(SessionHandler, updateTimestamp) } /* Legacy save handler may not support update_timestamp API. Just write. */ - RETVAL_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val)); + RETVAL_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, PS(gc_maxlifetime))); } /* }}} */ diff --git a/ext/session/php_session.h b/ext/session/php_session.h index 2c3e0cf79868b..972a39cefc825 100644 --- a/ext/session/php_session.h +++ b/ext/session/php_session.h @@ -33,13 +33,13 @@ #define PS_NUM_APIS 9 #define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name #define PS_CLOSE_ARGS void **mod_data -#define PS_READ_ARGS void **mod_data, zend_string *key, zend_string **val -#define PS_WRITE_ARGS void **mod_data, zend_string *key, zend_string *val +#define PS_READ_ARGS void **mod_data, zend_string *key, zend_string **val, int maxlifetime +#define PS_WRITE_ARGS void **mod_data, zend_string *key, zend_string *val, int maxlifetime #define PS_DESTROY_ARGS void **mod_data, zend_string *key #define PS_GC_ARGS void **mod_data, int maxlifetime, int *nrdels #define PS_CREATE_SID_ARGS void **mod_data #define PS_VALIDATE_SID_ARGS void **mod_data, zend_string *key -#define PS_UPDATE_TIMESTAMP_ARGS void **mod_data, zend_string *key, zend_string *val +#define PS_UPDATE_TIMESTAMP_ARGS void **mod_data, zend_string *key, zend_string *val, int maxlifetime typedef struct ps_module_struct { const char *s_name; diff --git a/ext/session/session.c b/ext/session/session.c index c6f5f5230f3f9..4d0354717295e 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -519,7 +519,7 @@ static void php_session_initialize(void) /* {{{ */ /* Read data */ php_session_track_init(); - if (PS(mod)->s_read(&PS(mod_data), PS(id), &val) == FAILURE) { + if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, PS(gc_maxlifetime)) == FAILURE) { /* Some broken save handler implementation returns FAILURE for non-existent session ID */ /* It's better to raise error for this, but disabled error for better compatibility */ /* @@ -557,13 +557,13 @@ static void php_session_save_current_state(int write) /* {{{ */ && val->len == PS(session_vars)->len && !memcmp(val->val, PS(session_vars)->val, val->len) ) { - ret = PS(mod)->s_update_timestamp(&PS(mod_data), PS(id), val); + ret = PS(mod)->s_update_timestamp(&PS(mod_data), PS(id), val, PS(gc_maxlifetime)); } else { - ret = PS(mod)->s_write(&PS(mod_data), PS(id), val); + ret = PS(mod)->s_write(&PS(mod_data), PS(id), val, PS(gc_maxlifetime)); } zend_string_release(val); } else { - ret = PS(mod)->s_write(&PS(mod_data), PS(id), STR_EMPTY_ALLOC()); + ret = PS(mod)->s_write(&PS(mod_data), PS(id), STR_EMPTY_ALLOC(), PS(gc_maxlifetime)); } } diff --git a/ext/session/tests/session_set_save_handler_variation5.phpt b/ext/session/tests/session_set_save_handler_variation5.phpt index c721e2a46d40d..4e67365b45ca0 100644 --- a/ext/session/tests/session_set_save_handler_variation5.phpt +++ b/ext/session/tests/session_set_save_handler_variation5.phpt @@ -94,6 +94,6 @@ GC [0] bool(true) Destroy [%s,PHPT-%d] -Warning: unlink(%s/session_test_PHPT-%s): No such file or directory in %s/save_handler.inc on line %d +Warning: unlink(%ssession_test_PHPT-%s): No such file or directory in %ssave_handler.inc on line %d Close [%s,PHPSESSID] bool(true) diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index 9b1d379b7bfd0..a0918038039af 100644 --- a/ext/soap/php_schema.c +++ b/ext/soap/php_schema.c @@ -1062,7 +1062,7 @@ static int schema_group(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr groupType, sdlTyp { xmlNodePtr trav; xmlAttrPtr ns, name, ref = NULL; - sdlContentModelPtr newModel; + sdlContentModelPtr newModel = NULL; ns = get_attribute(groupType->properties, "targetNamespace"); if (ns == NULL) { diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c index 963db66818d89..f6a86315b100d 100644 --- a/ext/sockets/conversions.c +++ b/ext/sockets/conversions.c @@ -217,17 +217,14 @@ static unsigned from_array_iterate(const zval *arr, void **args, ser_context *ctx) { - HashPosition pos; unsigned i; zval *elem; char buf[sizeof("element #4294967295")]; char *bufp = buf; /* Note i starts at 1, not 0! */ - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos), i = 1; - !ctx->err.has_error - && (elem = zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), &pos)) != NULL; - zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos), i++) { + i = 1; + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { if (snprintf(buf, sizeof(buf), "element #%u", i) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } @@ -236,7 +233,11 @@ static unsigned from_array_iterate(const zval *arr, func(elem, i, args, ctx); zend_llist_remove_tail(&ctx->keys); - } + if (ctx->err.has_error) { + break; + } + i++; + } ZEND_HASH_FOREACH_END(); return i -1; } diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index bb7424a395fb4..21b3c8c905cf6 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -2028,10 +2028,9 @@ SPL_METHOD(CallbackFilterIterator, accept) SPL_METHOD(RegexIterator, accept) { spl_dual_it_object *intern; - char *subject; - zend_string *result; - int subject_len, use_copy, count = 0; - zval *subject_ptr, subject_copy, zcount, *replacement, tmp_replacement, rv; + zend_string *result, *subject; + int count = 0; + zval zcount, *replacement, tmp_replacement, rv; if (zend_parse_parameters_none() == FAILURE) { return; @@ -2046,51 +2045,40 @@ SPL_METHOD(RegexIterator, accept) } if (intern->u.regex.flags & REGIT_USE_KEY) { - subject_ptr = &intern->current.key; + subject = zval_get_string(&intern->current.key); } else { - subject_ptr = &intern->current.data; + subject = zval_get_string(&intern->current.data); } - ZVAL_UNDEF(&subject_copy); - use_copy = zend_make_printable_zval(subject_ptr, &subject_copy); - if (use_copy) { - subject = Z_STRVAL(subject_copy); - subject_len = (int)Z_STRLEN(subject_copy); - } else { - subject = Z_STRVAL_P(subject_ptr); - subject_len = (int)Z_STRLEN_P(subject_ptr); - } - - use_copy = 0; switch (intern->u.regex.mode) { case REGIT_MODE_MAX: /* won't happen but makes compiler happy */ case REGIT_MODE_MATCH: - count = pcre_exec(intern->u.regex.pce->re, intern->u.regex.pce->extra, subject, subject_len, 0, 0, NULL, 0); + count = pcre_exec(intern->u.regex.pce->re, intern->u.regex.pce->extra, subject->val, subject->len, 0, 0, NULL, 0); RETVAL_BOOL(count >= 0); break; case REGIT_MODE_ALL_MATCHES: case REGIT_MODE_GET_MATCH: - if (!use_copy) { - subject = estrndup(subject, subject_len); - use_copy = 1; - } +//??? if (!use_copy) { +//??? subject = estrndup(subject, subject_len); +//??? use_copy = 1; +//??? } zval_ptr_dtor(&intern->current.data); ZVAL_UNDEF(&intern->current.data); - php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount, + php_pcre_match_impl(intern->u.regex.pce, subject->val, subject->len, &zcount, &intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0); RETVAL_BOOL(Z_LVAL(zcount) > 0); break; case REGIT_MODE_SPLIT: - if (!use_copy) { - subject = estrndup(subject, subject_len); - use_copy = 1; - } +//??? if (!use_copy) { +//??? subject = estrndup(subject, subject_len); +//??? use_copy = 1; +//??? } zval_ptr_dtor(&intern->current.data); ZVAL_UNDEF(&intern->current.data); - php_pcre_split_impl(intern->u.regex.pce, subject, subject_len, &intern->current.data, -1, intern->u.regex.preg_flags); + php_pcre_split_impl(intern->u.regex.pce, subject->val, subject->len, &intern->current.data, -1, intern->u.regex.preg_flags); count = zend_hash_num_elements(Z_ARRVAL(intern->current.data)); RETVAL_BOOL(count > 1); break; @@ -2103,7 +2091,7 @@ SPL_METHOD(RegexIterator, accept) convert_to_string(&tmp_replacement); replacement = &tmp_replacement; } - result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0, -1, &count); + result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject->val, subject->len, replacement, 0, -1, &count); if (intern->u.regex.flags & REGIT_USE_KEY) { zval_ptr_dtor(&intern->current.key); @@ -2122,13 +2110,7 @@ SPL_METHOD(RegexIterator, accept) if (intern->u.regex.flags & REGIT_INVERTED) { RETVAL_BOOL(Z_TYPE_P(return_value) != IS_TRUE); } - - if (use_copy) { - efree(subject); - } - if (!Z_ISUNDEF(subject_copy)) { - zval_ptr_dtor(&subject_copy); - } + zend_string_release(subject); } /* }}} */ /* {{{ proto string RegexIterator::getRegex() diff --git a/ext/standard/array.c b/ext/standard/array.c index 966ea0f1f69de..f0f7d7848ba88 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1726,7 +1726,7 @@ PHP_FUNCTION(range) goto err; } /* Initialize the return_value as an array. */ - array_init_size(return_value, ((low - high) / lstep) + 1); + array_init_size(return_value, (uint32_t)(((low - high) / lstep) + 1)); zend_hash_real_init(Z_ARRVAL_P(return_value), 1); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { for (; low >= high; low -= (unsigned int)lstep) { @@ -1746,7 +1746,7 @@ PHP_FUNCTION(range) err = 1; goto err; } - array_init_size(return_value, ((high - low) / lstep) + 1); + array_init_size(return_value, (uint32_t)(((high - low) / lstep) + 1)); zend_hash_real_init(Z_ARRVAL_P(return_value), 1); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { for (; low <= high; low += (unsigned int)lstep) { @@ -1785,7 +1785,7 @@ PHP_FUNCTION(range) goto err; } - array_init_size(return_value, ((low - high) / step) + 1); + array_init_size(return_value, (uint32_t)(((low - high) / step) + 1)); zend_hash_real_init(Z_ARRVAL_P(return_value), 1); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { for (value = low; value >= (high - DOUBLE_DRIFT_FIX); value = low - (++i * step)) { @@ -1799,7 +1799,7 @@ PHP_FUNCTION(range) goto err; } - array_init_size(return_value, ((high - low) / step) + 1); + array_init_size(return_value, (uint32_t)(((high - low) / step) + 1)); zend_hash_real_init(Z_ARRVAL_P(return_value), 1); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { for (value = low; value <= (high + DOUBLE_DRIFT_FIX); value = low + (++i * step)) { @@ -1826,7 +1826,7 @@ PHP_FUNCTION(range) err = 1; goto err; } - array_init_size(return_value, ((low - high) / lstep) + 1); + array_init_size(return_value, (uint32_t)(((low - high) / lstep) + 1)); zend_hash_real_init(Z_ARRVAL_P(return_value), 1); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { for (; low >= high; low -= lstep) { @@ -1839,7 +1839,7 @@ PHP_FUNCTION(range) err = 1; goto err; } - array_init_size(return_value, ((high - low) / lstep) + 1); + array_init_size(return_value, (uint32_t)(((high - low) / lstep) + 1)); zend_hash_real_init(Z_ARRVAL_P(return_value), 1); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { for (; low <= high; low += lstep) { @@ -1877,26 +1877,54 @@ static void php_array_data_shuffle(zval *array) /* {{{ */ hash = Z_ARRVAL_P(array); n_left = n_elems; - if (hash->nNumUsed != hash->nNumOfElements) { - for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) { - p = hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - if (j != idx) { - hash->arData[j] = *p; + if (EXPECTED(hash->u.v.nIteratorsCount == 0)) { + if (hash->nNumUsed != hash->nNumOfElements) { + for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) { + p = hash->arData + idx; + if (Z_TYPE(p->val) == IS_UNDEF) continue; + if (j != idx) { + hash->arData[j] = *p; + } + j++; } - j++; } - } - while (--n_left) { - rnd_idx = php_rand(); - RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX); - if (rnd_idx != n_left) { - temp = hash->arData[n_left]; - hash->arData[n_left] = hash->arData[rnd_idx]; - hash->arData[rnd_idx] = temp; + while (--n_left) { + rnd_idx = php_rand(); + RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX); + if (rnd_idx != n_left) { + temp = hash->arData[n_left]; + hash->arData[n_left] = hash->arData[rnd_idx]; + hash->arData[rnd_idx] = temp; + } + } + } else { + uint32_t iter_pos = zend_hash_iterators_lower_pos(hash, 0); + + if (hash->nNumUsed != hash->nNumOfElements) { + for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) { + p = hash->arData + idx; + if (Z_TYPE(p->val) == IS_UNDEF) continue; + if (j != idx) { + hash->arData[j] = *p; + if (idx == iter_pos) { + zend_hash_iterators_update(hash, idx, j); + iter_pos = zend_hash_iterators_lower_pos(hash, iter_pos + 1); + } + } + j++; + } + } + while (--n_left) { + rnd_idx = php_rand(); + RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX); + if (rnd_idx != n_left) { + temp = hash->arData[n_left]; + hash->arData[n_left] = hash->arData[rnd_idx]; + hash->arData[rnd_idx] = temp; + zend_hash_iterators_update(hash, rnd_idx, n_left); + } } } - HANDLE_BLOCK_INTERRUPTIONS(); hash->nNumUsed = n_elems; hash->nInternalPointer = 0; @@ -1941,6 +1969,7 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re uint idx; Bucket *p; /* Pointer to hash bucket */ zval *entry; /* Hash entry */ + uint32_t iter_pos = zend_hash_iterators_lower_pos(in_hash, 0); /* Get number of entries in the input hash */ num_in = zend_hash_num_elements(in_hash); @@ -1966,7 +1995,6 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re for (pos = 0, idx = 0; pos < offset && idx < in_hash->nNumUsed; idx++) { p = in_hash->arData + idx; if (Z_TYPE(p->val) == IS_UNDEF) continue; - pos++; /* Get entry and increase reference count */ entry = &p->val; @@ -1976,6 +2004,13 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re } else { zend_hash_add_new(&out_hash, p->key, entry); } + if (idx == iter_pos) { + if (idx != pos) { + zend_hash_iterators_update(in_hash, idx, pos); + } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); + } + pos++; } /* If hash for removed entries exists, go until offset+length and copy the entries to it */ @@ -2001,10 +2036,12 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re } } } else { /* otherwise just skip those entries */ - for ( ; pos < offset + length && idx < in_hash->nNumUsed; idx++) { + int pos2 = pos; + + for ( ; pos2 < offset + length && idx < in_hash->nNumUsed; idx++) { p = in_hash->arData + idx; if (Z_TYPE(p->val) == IS_UNDEF) continue; - pos++; + pos2++; if (p->key == NULL) { zend_hash_index_del(in_hash, p->h); } else { @@ -2016,12 +2053,14 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re } } } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos); /* If there are entries to insert.. */ if (replace) { ZEND_HASH_FOREACH_VAL_IND(replace, entry) { if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry); zend_hash_next_index_insert_new(&out_hash, entry); + pos++; } ZEND_HASH_FOREACH_END(); } @@ -2035,13 +2074,31 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re } else { zend_hash_add_new(&out_hash, p->key, entry); } + if (idx == iter_pos) { + if (idx != pos) { + zend_hash_iterators_update(in_hash, idx, pos); + } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); + } + pos++; } - zend_hash_internal_pointer_reset(&out_hash); - + /* replace HashTable data */ + in_hash->u.v.nIteratorsCount = 0; in_hash->pDestructor = NULL; zend_hash_destroy(in_hash); - *in_hash = out_hash; + + in_hash->u.v.flags = out_hash.u.v.flags; + in_hash->nTableSize = out_hash.nTableSize; + in_hash->nTableMask = out_hash.nTableMask; + in_hash->nNumUsed = out_hash.nNumUsed; + in_hash->nNumOfElements = out_hash.nNumOfElements; + in_hash->nNextFreeElement = out_hash.nNextFreeElement; + in_hash->arData = out_hash.arData; + in_hash->arHash = out_hash.arHash; + in_hash->pDestructor = out_hash.pDestructor; + + zend_hash_internal_pointer_reset(in_hash); } /* }}} */ @@ -2194,17 +2251,38 @@ PHP_FUNCTION(array_shift) if (Z_ARRVAL_P(stack)->u.flags & HASH_FLAG_PACKED) { uint32_t k = 0; - for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) { - p = Z_ARRVAL_P(stack)->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - if (idx != k) { - Bucket *q = Z_ARRVAL_P(stack)->arData + k; - q->h = k; - q->key = NULL; - ZVAL_COPY_VALUE(&q->val, &p->val); - ZVAL_UNDEF(&p->val); + if (EXPECTED(Z_ARRVAL_P(stack)->u.v.nIteratorsCount == 0)) { + for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) { + p = Z_ARRVAL_P(stack)->arData + idx; + if (Z_TYPE(p->val) == IS_UNDEF) continue; + if (idx != k) { + Bucket *q = Z_ARRVAL_P(stack)->arData + k; + q->h = k; + q->key = NULL; + ZVAL_COPY_VALUE(&q->val, &p->val); + ZVAL_UNDEF(&p->val); + } + k++; + } + } else { + uint32_t iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), 0); + + for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) { + p = Z_ARRVAL_P(stack)->arData + idx; + if (Z_TYPE(p->val) == IS_UNDEF) continue; + if (idx != k) { + Bucket *q = Z_ARRVAL_P(stack)->arData + k; + q->h = k; + q->key = NULL; + ZVAL_COPY_VALUE(&q->val, &p->val); + ZVAL_UNDEF(&p->val); + if (idx == iter_pos) { + zend_hash_iterators_update(Z_ARRVAL_P(stack), idx, k); + iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), iter_pos + 1); + } + } + k++; } - k++; } Z_ARRVAL_P(stack)->nNumUsed = k; Z_ARRVAL_P(stack)->nNextFreeElement = k; @@ -2257,17 +2335,50 @@ PHP_FUNCTION(array_unshift) } zend_hash_next_index_insert_new(&new_hash, &args[i]); } - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) { - if (key) { - zend_hash_add_new(&new_hash, key, value); - } else { - zend_hash_next_index_insert_new(&new_hash, value); - } - } ZEND_HASH_FOREACH_END(); + if (EXPECTED(Z_ARRVAL_P(stack)->u.v.nIteratorsCount == 0)) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) { + if (key) { + zend_hash_add_new(&new_hash, key, value); + } else { + zend_hash_next_index_insert_new(&new_hash, value); + } + } ZEND_HASH_FOREACH_END(); + } else { + uint32_t old_idx; + uint32_t new_idx = i; + uint32_t iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), 0); + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) { + if (key) { + zend_hash_add_new(&new_hash, key, value); + } else { + zend_hash_next_index_insert_new(&new_hash, value); + } + old_idx = (Bucket*)value - Z_ARRVAL_P(stack)->arData; + if (old_idx == iter_pos) { + zend_hash_iterators_update(Z_ARRVAL_P(stack), old_idx, new_idx); + iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), iter_pos + 1); + } + new_idx++; + } ZEND_HASH_FOREACH_END(); + } + + /* replace HashTable data */ + Z_ARRVAL_P(stack)->u.v.nIteratorsCount = 0; Z_ARRVAL_P(stack)->pDestructor = NULL; zend_hash_destroy(Z_ARRVAL_P(stack)); - *Z_ARRVAL_P(stack) = new_hash; + + Z_ARRVAL_P(stack)->u.v.flags = new_hash.u.v.flags; + Z_ARRVAL_P(stack)->nTableSize = new_hash.nTableSize; + Z_ARRVAL_P(stack)->nTableMask = new_hash.nTableMask; + Z_ARRVAL_P(stack)->nNumUsed = new_hash.nNumUsed; + Z_ARRVAL_P(stack)->nNumOfElements = new_hash.nNumOfElements; + Z_ARRVAL_P(stack)->nNextFreeElement = new_hash.nNextFreeElement; + Z_ARRVAL_P(stack)->arData = new_hash.arData; + Z_ARRVAL_P(stack)->arHash = new_hash.arHash; + Z_ARRVAL_P(stack)->pDestructor = new_hash.pDestructor; + + zend_hash_internal_pointer_reset(Z_ARRVAL_P(stack)); /* Clean up and return the number of elements in the stack */ RETVAL_LONG(zend_hash_num_elements(Z_ARRVAL_P(stack))); diff --git a/ext/standard/file.c b/ext/standard/file.c index 2540c3113efd5..2d2bb2780842f 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -156,11 +156,8 @@ static ZEND_RSRC_DTOR_FUNC(file_context_dtor) static void file_globals_ctor(php_file_globals *file_globals_p) { - FG(pclose_ret) = 0; - FG(pclose_wait) = 0; - FG(user_stream_current_filename) = NULL; - FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; - FG(wrapper_errors) = NULL; + memset(file_globals_p, 0, sizeof(php_file_globals)); + file_globals_p->def_chunk_size = PHP_SOCK_CHUNK_SIZE; } static void file_globals_dtor(php_file_globals *file_globals_p) diff --git a/ext/standard/info.c b/ext/standard/info.c index e188a1287fbe7..eb0a7ca131882 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -102,7 +102,7 @@ static void php_info_print_stream_hash(const char *name, HashTable *ht) /* {{{ * if (ht) { if (zend_hash_num_elements(ht)) { - HashPosition pos; + int first = 1; if (!sapi_module.phpinfo_as_text) { php_info_printf("Registered %s", name); @@ -110,21 +110,20 @@ static void php_info_print_stream_hash(const char *name, HashTable *ht) /* {{{ * php_info_printf("\nRegistered %s => ", name); } - zend_hash_internal_pointer_reset_ex(ht, &pos); - while (zend_hash_get_current_key_ex(ht, &key, NULL, &pos) == HASH_KEY_IS_STRING) - { - if (!sapi_module.phpinfo_as_text) { - php_info_print_html_esc(key->val, key->len); - } else { - php_info_print(key->val); - } - zend_hash_move_forward_ex(ht, &pos); - if (zend_hash_get_current_key_ex(ht, &key, NULL, &pos) == HASH_KEY_IS_STRING) { - php_info_print(", "); - } else { - break; + ZEND_HASH_FOREACH_STR_KEY(ht, key) { + if (key) { + if (first) { + first = 0; + } else { + php_info_print(", "); + } + if (!sapi_module.phpinfo_as_text) { + php_info_print_html_esc(key->val, key->len); + } else { + php_info_print(key->val); + } } - } + } ZEND_HASH_FOREACH_END(); if (!sapi_module.phpinfo_as_text) { php_info_print("\n"); diff --git a/ext/standard/string.c b/ext/standard/string.c index 65f80fd38ca8e..b7e71283b9d2c 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2409,8 +2409,7 @@ PHP_FUNCTION(substr_replace) zend_long f; int argc = ZEND_NUM_ARGS(); zend_string *result; - - HashPosition pos_from, pos_repl, pos_len; + HashPosition from_idx, repl_idx, len_idx; zval *tmp_str = NULL, *tmp_from = NULL, *tmp_repl = NULL, *tmp_len= NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzz|z/", &str, &repl, &from, &len) == FAILURE) { @@ -2490,8 +2489,15 @@ PHP_FUNCTION(substr_replace) l = Z_STRLEN_P(str) - f; } if (Z_TYPE_P(repl) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(repl), &pos_repl); - if (NULL != (tmp_repl = zend_hash_get_current_data_ex(Z_ARRVAL_P(repl), &pos_repl))) { + repl_idx = 0; + while (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { + tmp_repl = &Z_ARRVAL_P(repl)->arData[repl_idx].val; + if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { + break; + } + repl_idx++; + } + if (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { convert_to_string_ex(tmp_repl); repl_len = Z_STRLEN_P(tmp_repl); } @@ -2519,17 +2525,7 @@ PHP_FUNCTION(substr_replace) array_init(return_value); - if (Z_TYPE_P(from) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(from), &pos_from); - } - - if (argc > 3 && Z_TYPE_P(len) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(len), &pos_len); - } - - if (Z_TYPE_P(repl) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(repl), &pos_repl); - } + from_idx = len_idx = repl_idx = 0; ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(str), num_index, str_index, tmp_str) { zval *orig_str; @@ -2553,7 +2549,14 @@ PHP_FUNCTION(substr_replace) */ if (Z_TYPE_P(from) == IS_ARRAY) { - if (NULL != (tmp_from = zend_hash_get_current_data_ex(Z_ARRVAL_P(from), &pos_from))) { + while (from_idx < Z_ARRVAL_P(from)->nNumUsed) { + tmp_from = &Z_ARRVAL_P(from)->arData[from_idx].val; + if (Z_TYPE_P(tmp_from) != IS_UNDEF) { + break; + } + from_idx++; + } + if (from_idx < Z_ARRVAL_P(from)->nNumUsed) { f = zval_get_long(tmp_from); if (f < 0) { @@ -2564,7 +2567,7 @@ PHP_FUNCTION(substr_replace) } else if (f > Z_STRLEN_P(orig_str)) { f = Z_STRLEN_P(orig_str); } - zend_hash_move_forward_ex(Z_ARRVAL_P(from), &pos_from); + from_idx++; } else { f = 0; } @@ -2581,9 +2584,16 @@ PHP_FUNCTION(substr_replace) } if (argc > 3 && Z_TYPE_P(len) == IS_ARRAY) { - if (NULL != (tmp_len = zend_hash_get_current_data_ex(Z_ARRVAL_P(len), &pos_len))) { + while (len_idx < Z_ARRVAL_P(len)->nNumUsed) { + tmp_len = &Z_ARRVAL_P(len)->arData[len_idx].val; + if (Z_TYPE_P(tmp_len) != IS_UNDEF) { + break; + } + len_idx++; + } + if (len_idx < Z_ARRVAL_P(len)->nNumUsed) { l = zval_get_long(tmp_len); - zend_hash_move_forward_ex(Z_ARRVAL_P(len), &pos_len); + len_idx++; } else { l = Z_STRLEN_P(orig_str); } @@ -2607,7 +2617,14 @@ PHP_FUNCTION(substr_replace) result_len = Z_STRLEN_P(orig_str) - l; if (Z_TYPE_P(repl) == IS_ARRAY) { - if (NULL != (tmp_repl = zend_hash_get_current_data_ex(Z_ARRVAL_P(repl), &pos_repl))) { + while (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { + tmp_repl = &Z_ARRVAL_P(repl)->arData[repl_idx].val; + if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { + break; + } + repl_idx++; + } + if (repl_idx < Z_ARRVAL_P(repl)->nNumUsed) { zval *repl_str; zval zrepl; @@ -2630,7 +2647,7 @@ PHP_FUNCTION(substr_replace) */ result_len += Z_STRLEN_P(repl_str); - zend_hash_move_forward_ex(Z_ARRVAL_P(repl), &pos_repl); + repl_idx++; result = zend_string_alloc(result_len, 0); memcpy(result->val, Z_STRVAL_P(orig_str), f); @@ -3965,7 +3982,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s zend_long replace_count = 0; zend_string *subject_str; zend_string *lc_subject_str = NULL; - HashPosition pos; + uint32_t replace_idx; /* Make sure we're dealing with strings. */ subject_str = zval_get_string(subject); @@ -3981,7 +3998,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s ZVAL_STR_COPY(result, subject_str); if (Z_TYPE_P(replace) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(replace), &pos); + replace_idx = 0; } else { /* Set replacement value to the passed one */ replace_value = Z_STRVAL_P(replace); @@ -3996,7 +4013,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s convert_to_string(search_entry); if (Z_STRLEN_P(search_entry) == 0) { if (Z_TYPE_P(replace) == IS_ARRAY) { - zend_hash_move_forward_ex(Z_ARRVAL_P(replace), &pos); + replace_idx++; } continue; } @@ -4004,7 +4021,14 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s /* If replace is an array. */ if (Z_TYPE_P(replace) == IS_ARRAY) { /* Get current entry */ - if ((replace_entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(replace), &pos)) != NULL) { + while (replace_idx < Z_ARRVAL_P(replace)->nNumUsed) { + replace_entry = &Z_ARRVAL_P(replace)->arData[replace_idx].val; + if (Z_TYPE_P(replace_entry) != IS_UNDEF) { + break; + } + replace_idx++; + } + if (replace_idx < Z_ARRVAL_P(replace)->nNumUsed) { /* Make sure we're dealing with strings. */ replace_entry_str = zval_get_string(replace_entry); @@ -4012,7 +4036,7 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zval *s replace_value = replace_entry_str->val; replace_len = replace_entry_str->len; - zend_hash_move_forward_ex(Z_ARRVAL_P(replace), &pos); + replace_idx++; } else { /* We've run out of replacement strings, so use an empty one. */ replace_value = ""; @@ -4506,23 +4530,24 @@ PHP_FUNCTION(setlocale) char *retval; zend_long cat; int num_args, i = 0; - HashPosition pos; + uint32_t idx; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l+", &cat, &args, &num_args) == FAILURE) { return; } #ifdef HAVE_SETLOCALE - if (Z_TYPE(args[0]) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL(args[0]), &pos); - } - + idx = 0; while (1) { if (Z_TYPE(args[0]) == IS_ARRAY) { - if (!zend_hash_num_elements(Z_ARRVAL(args[0]))) { - break; + while (idx < Z_ARRVAL(args[0])->nNumUsed) { + plocale = &Z_ARRVAL(args[0])->arData[idx].val; + if (Z_TYPE_P(plocale) != IS_UNDEF) { + break; + } + idx++; } - if ((plocale = zend_hash_get_current_data_ex(Z_ARRVAL(args[0]), &pos)) == NULL) { + if (idx >= Z_ARRVAL(args[0])->nNumUsed) { break; } } else { @@ -4574,7 +4599,7 @@ PHP_FUNCTION(setlocale) } if (Z_TYPE(args[0]) == IS_ARRAY) { - if (zend_hash_move_forward_ex(Z_ARRVAL(args[0]), &pos) == FAILURE) break; + idx++; } else { if (++i >= num_args) break; } diff --git a/ext/standard/tests/network/bug68925.phpt b/ext/standard/tests/network/bug68925.phpt index 2638dd331d2db..764e13e0eda38 100644 --- a/ext/standard/tests/network/bug68925.phpt +++ b/ext/standard/tests/network/bug68925.phpt @@ -6,8 +6,8 @@ var_dump(gethostbyname(str_repeat("0", 2501))); var_dump(gethostbynamel(str_repeat("0", 2501))); ?> --EXPECTF-- -Warning: gethostbyname(): Host name is too long, the limit is %d characters in %s/bug68925.php on line %d +Warning: gethostbyname(): Host name is too long, the limit is %d characters in %s%ebug68925.php on line %d string(2501) "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" -Warning: gethostbynamel(): Host name is too long, the limit is %d characters in %s/bug68925.php on line %d +Warning: gethostbynamel(): Host name is too long, the limit is %d characters in %s%ebug68925.php on line %d bool(false) diff --git a/ext/sybase_ct/CREDITS b/ext/sybase_ct/CREDITS deleted file mode 100644 index f739a533c41f0..0000000000000 --- a/ext/sybase_ct/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Sybase-CT -Zeev Suraski, Tom May, Timm Friebe diff --git a/ext/sybase_ct/config.m4 b/ext/sybase_ct/config.m4 deleted file mode 100644 index 276fe12675509..0000000000000 --- a/ext/sybase_ct/config.m4 +++ /dev/null @@ -1,120 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(sybase-ct, for Sybase-CT support, -[ --with-sybase-ct[=DIR] Include Sybase-CT support. DIR is the Sybase home - directory [/home/sybase]]) - -if test "$PHP_SYBASE_CT" != "no"; then - - if test "$PHP_SYBASE" && test "$PHP_SYBASE" != "no" && test "$ext_shared" = "no"; then - AC_MSG_ERROR([You can not use both --with-sybase and --with-sybase-ct in same build!]) - fi - - AC_DEFINE(HAVE_SYBASE_CT,1,[ ]) - PHP_NEW_EXTENSION(sybase_ct, php_sybase_ct.c, $ext_shared) - PHP_SUBST(SYBASE_CT_SHARED_LIBADD) - - if test "$PHP_SYBASE_CT" = "yes"; then - SYBASE_CT_INCDIR=/home/sybase/include - SYBASE_CT_LIBDIR=/home/sybase/lib - else - SYBASE_CT_INCDIR=$PHP_SYBASE_CT/include - SYBASE_CT_LIBDIR=$PHP_SYBASE_CT/lib - fi - - dnl Determine whether we're building 64 or 32 bit... - AC_CHECK_SIZEOF(long int, 4) - AC_MSG_CHECKING([checking if we're on a 64-bit platform]) - if test "$ac_cv_sizeof_long_int" = "4"; then - AC_MSG_RESULT([no]) - PHP_SYBASE_64=no - else - AC_MSG_RESULT([yes]) - PHP_SYBASE_64=yes - fi - - - AC_MSG_CHECKING([Checking for ctpublic.h]) - if test -f $SYBASE_CT_INCDIR/ctpublic.h; then - AC_MSG_RESULT([found in $SYBASE_CT_INCDIR]) - PHP_ADD_INCLUDE($SYBASE_CT_INCDIR) - else - AC_MSG_ERROR([ctpublic.h missing!]) - fi - - AC_MSG_CHECKING([Checking Sybase libdir]) - AC_MSG_RESULT([Have $SYBASE_CT_LIBDIR]) - - AC_MSG_CHECKING([Checking for Sybase platform libraries]) - - PHP_ADD_LIBPATH($SYBASE_CT_LIBDIR, SYBASE_CT_SHARED_LIBADD) - if test -f $SYBASE_CT_INCDIR/tds.h || test -f $SYBASE_CT_INCDIR/tds_sysdep_public.h; then - PHP_ADD_LIBRARY(ct,, SYBASE_CT_SHARED_LIBADD) - SYBASE_CT_LIBS="-L$SYBASE_CT_LIBDIR -lct" - AC_MSG_RESULT([FreeTDS: $SYBASE_CT_LIBS]) - elif test -f $SYBASE_CT_LIBDIR/libsybct64.so && test $PHP_SYBASE_64 = "yes"; then - PHP_ADD_LIBRARY(sybcs64,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(sybct64,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(sybcomn64,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(sybintl64,, SYBASE_CT_SHARED_LIBADD) - - ac_solid_uname_s=`uname -s 2>/dev/null` - case $ac_solid_uname_s in - *OSF*) ;; # Tru64/DEC OSF does NOT use the SYB_LP64 define - *) CFLAGS="${CFLAGS} -DSYB_LP64" ;; # - esac - SYBASE_CT_LIBS="-L$SYBASE_CT_LIBDIR -lsybcs64 -lsybct64 -lsybcomn64 -lsybintl64" - AC_MSG_RESULT([Sybase64: $SYBASE_CT_LIBS]) - - PHP_CHECK_LIBRARY(sybtcl64, netg_errstr, [ - PHP_ADD_LIBRARY(sybtcl64,,SYBASE_CT_SHARED_LIBADD) - ],[ - PHP_ADD_LIBRARY(sybtcl64,,SYBASE_CT_SHARED_LIBADD) - ],[ - $SYBASE_CT_LIBS - ]) - - PHP_CHECK_LIBRARY(insck64, insck__getVdate, [PHP_ADD_LIBRARY(insck64,, SYBASE_CT_SHARED_LIBADD)],[],[-L$SYBASE_CT_LIBDIR]) - PHP_CHECK_LIBRARY(insck64, bsd_tcp, [PHP_ADD_LIBRARY(insck64,, SYBASE_CT_SHARED_LIBADD)],[],[-L$SYBASE_CT_LIBDIR]) - elif test -f $SYBASE_CT_LIBDIR/libsybct.so; then - PHP_ADD_LIBRARY(sybcs,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(sybct,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(sybcomn,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(sybintl,, SYBASE_CT_SHARED_LIBADD) - - SYBASE_CT_LIBS="-L$SYBASE_CT_LIBDIR -lsybcs -lsybct -lsybcomn -lsybintl" - AC_MSG_RESULT([Sybase32 syb-prefix: $SYBASE_CT_LIBS]) - - PHP_CHECK_LIBRARY(sybtcl, netg_errstr, [ - PHP_ADD_LIBRARY(sybtcl,,SYBASE_CT_SHARED_LIBADD) - ],[ - PHP_ADD_LIBRARY(sybtcl,,SYBASE_CT_SHARED_LIBADD) - ],[ - $SYBASE_CT_LIBS - ]) - - PHP_CHECK_LIBRARY(insck, insck__getVdate, [PHP_ADD_LIBRARY(insck,, SYBASE_CT_SHARED_LIBADD)],[],[-L$SYBASE_CT_LIBDIR]) - PHP_CHECK_LIBRARY(insck, bsd_tcp, [PHP_ADD_LIBRARY(insck,, SYBASE_CT_SHARED_LIBADD)],[],[-L$SYBASE_CT_LIBDIR]) - else - PHP_ADD_LIBRARY(cs,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(ct,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(comn,, SYBASE_CT_SHARED_LIBADD) - PHP_ADD_LIBRARY(intl,, SYBASE_CT_SHARED_LIBADD) - - SYBASE_CT_LIBS="-L$SYBASE_CT_LIBDIR -lcs -lct -lcomn -lintl" - AC_MSG_RESULT([Sybase32 default: $SYBASE_CT_LIBS]) - - PHP_CHECK_LIBRARY(tcl, netg_errstr, [ - PHP_ADD_LIBRARY(tcl,,SYBASE_CT_SHARED_LIBADD) - ],[ - PHP_ADD_LIBRARY(sybtcl,,SYBASE_CT_SHARED_LIBADD) - ],[ - $SYBASE_CT_LIBS - ]) - - PHP_CHECK_LIBRARY(insck, insck__getVdate, [PHP_ADD_LIBRARY(insck,, SYBASE_CT_SHARED_LIBADD)],[],[-L$SYBASE_CT_LIBDIR]) - PHP_CHECK_LIBRARY(insck, bsd_tcp, [PHP_ADD_LIBRARY(insck,, SYBASE_CT_SHARED_LIBADD)],[],[-L$SYBASE_CT_LIBDIR]) - fi -fi diff --git a/ext/sybase_ct/config.w32 b/ext/sybase_ct/config.w32 deleted file mode 100644 index c773b623af284..0000000000000 --- a/ext/sybase_ct/config.w32 +++ /dev/null @@ -1,21 +0,0 @@ - -// $Id$ -// vim:ft=javascript - -ARG_WITH("sybase-ct", "SYBASE_CT support", "no"); - -if (PHP_SYBASE_CT != "no") { - - if (CHECK_HEADER_ADD_INCLUDE("ctpublic.h", "CFLAGS_SYBASE_CT", PHP_PHP_BUILD + "\\sybase\\include;" + PHP_SYBASE_CT) && - (!X64 && CHECK_LIB("libsybcs.lib", "sybase_ct", PHP_PHP_BUILD + "\\sybase\\lib;" + PHP_SYBASE_CT) && - CHECK_LIB("libsybct.lib", "sybase_ct", PHP_PHP_BUILD + "\\sybase\\lib;" + PHP_SYBASE_CT) || - X64 && CHECK_LIB("libsybcs64.lib", "sybase_ct", PHP_PHP_BUILD + "\\sybase\\lib;" + PHP_SYBASE_CT) && - CHECK_LIB("libsybct64.lib", "sybase_ct", PHP_PHP_BUILD + "\\sybase\\lib;" + PHP_SYBASE_CT)) - ) { - EXTENSION('sybase_ct', 'php_sybase_ct.c'); - AC_DEFINE('HAVE_SYBASE_CT', 1); - } else { - WARNING("sybase_ct not enabled; libraries and headers not found"); - } -} - diff --git a/ext/sybase_ct/php_sybase_ct.c b/ext/sybase_ct/php_sybase_ct.c deleted file mode 100644 index 5ed1fb4dd7d0a..0000000000000 --- a/ext/sybase_ct/php_sybase_ct.c +++ /dev/null @@ -1,2242 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Zeev Suraski | - | Tom May | - | Timm Friebe | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_sybase_ct.h" -#include "ext/standard/php_standard.h" -#include "ext/standard/info.h" -#include "php_globals.h" -#include "php_ini.h" - -/* True globals, no need for thread safety */ -static int le_link, le_plink, le_result; - -#if HAVE_SYBASE_CT - -ZEND_DECLARE_MODULE_GLOBALS(sybase) -static PHP_GINIT_FUNCTION(sybase); -static PHP_GSHUTDOWN_FUNCTION(sybase); - -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_connect, 0, 0, 0) - ZEND_ARG_INFO(0, host) - ZEND_ARG_INFO(0, user) - ZEND_ARG_INFO(0, password) - ZEND_ARG_INFO(0, charset) - ZEND_ARG_INFO(0, appname) - ZEND_ARG_INFO(0, new) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_pconnect, 0, 0, 0) - ZEND_ARG_INFO(0, host) - ZEND_ARG_INFO(0, user) - ZEND_ARG_INFO(0, password) - ZEND_ARG_INFO(0, charset) - ZEND_ARG_INFO(0, appname) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_close, 0, 0, 0) - ZEND_ARG_INFO(0, link_id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_select_db, 0, 0, 1) - ZEND_ARG_INFO(0, database) - ZEND_ARG_INFO(0, link_id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_query, 0, 0, 1) - ZEND_ARG_INFO(0, query) - ZEND_ARG_INFO(0, link_id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_unbuffered_query, 0, 0, 1) - ZEND_ARG_INFO(0, query) - ZEND_ARG_INFO(0, link_id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_free_result, 0, 0, 1) - ZEND_ARG_INFO(0, result) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_get_last_message, 0, 0, 1) - ZEND_ARG_INFO(0, d) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_num_rows, 0, 0, 1) - ZEND_ARG_INFO(0, result) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_num_fields, 0, 0, 1) - ZEND_ARG_INFO(0, result) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_fetch_row, 0, 0, 1) - ZEND_ARG_INFO(0, result) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_fetch_object, 0, 0, 1) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_fetch_array, 0, 0, 1) - ZEND_ARG_INFO(0, result) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_fetch_assoc, 0, 0, 1) - ZEND_ARG_INFO(0, result) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_data_seek, 0, 0, 2) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_fetch_field, 0, 0, 1) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_field_seek, 0, 0, 2) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_result, 0, 0, 3) - ZEND_ARG_INFO(0, result) - ZEND_ARG_INFO(0, row) - ZEND_ARG_INFO(0, field) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_affected_rows, 0, 0, 0) - ZEND_ARG_INFO(0, link_id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_min_client_severity, 0, 0, 1) - ZEND_ARG_INFO(0, severity) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_min_server_severity, 0, 0, 1) - ZEND_ARG_INFO(0, severity) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_deadlock_retry_count, 0, 0, 1) - ZEND_ARG_INFO(0, retry_count) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_sybase_set_message_handler, 0, 0, 1) - ZEND_ARG_INFO(0, error_func) - ZEND_ARG_INFO(0, connection) -ZEND_END_ARG_INFO() -/* }}} */ - -const zend_function_entry sybase_functions[] = { - PHP_FE(sybase_connect, arginfo_sybase_connect) - PHP_FE(sybase_pconnect, arginfo_sybase_pconnect) - PHP_FE(sybase_close, arginfo_sybase_close) - PHP_FE(sybase_select_db, arginfo_sybase_select_db) - PHP_FE(sybase_query, arginfo_sybase_query) - PHP_FE(sybase_unbuffered_query, arginfo_sybase_unbuffered_query) - PHP_FE(sybase_free_result, arginfo_sybase_free_result) - PHP_FE(sybase_get_last_message, arginfo_sybase_get_last_message) - PHP_FE(sybase_num_rows, arginfo_sybase_num_rows) - PHP_FE(sybase_num_fields, arginfo_sybase_num_fields) - PHP_FE(sybase_fetch_row, arginfo_sybase_fetch_row) - PHP_FE(sybase_fetch_array, arginfo_sybase_fetch_array) - PHP_FE(sybase_fetch_assoc, arginfo_sybase_fetch_assoc) - PHP_FE(sybase_fetch_object, arginfo_sybase_fetch_object) - PHP_FE(sybase_data_seek, arginfo_sybase_data_seek) - PHP_FE(sybase_fetch_field, arginfo_sybase_fetch_field) - PHP_FE(sybase_field_seek, arginfo_sybase_field_seek) - PHP_FE(sybase_result, arginfo_sybase_result) - PHP_FE(sybase_affected_rows, arginfo_sybase_affected_rows) - PHP_FE(sybase_min_client_severity, arginfo_sybase_min_client_severity) - PHP_FE(sybase_min_server_severity, arginfo_sybase_min_server_severity) - PHP_FE(sybase_set_message_handler, arginfo_sybase_set_message_handler) - PHP_FE(sybase_deadlock_retry_count, arginfo_sybase_deadlock_retry_count) - -#if !defined(PHP_WIN32) && !defined(HAVE_MSSQL) - PHP_FALIAS(mssql_connect, sybase_connect, arginfo_sybase_connect) - PHP_FALIAS(mssql_pconnect, sybase_pconnect, arginfo_sybase_pconnect) - PHP_FALIAS(mssql_close, sybase_close, arginfo_sybase_close) - PHP_FALIAS(mssql_select_db, sybase_select_db, arginfo_sybase_select_db) - PHP_FALIAS(mssql_query, sybase_query, arginfo_sybase_query) - PHP_FALIAS(mssql_unbuffered_query, sybase_unbuffered_query, arginfo_sybase_unbuffered_query) - PHP_FALIAS(mssql_free_result, sybase_free_result, arginfo_sybase_free_result) - PHP_FALIAS(mssql_get_last_message, sybase_get_last_message, arginfo_sybase_get_last_message) - PHP_FALIAS(mssql_num_rows, sybase_num_rows, arginfo_sybase_num_rows) - PHP_FALIAS(mssql_num_fields, sybase_num_fields, arginfo_sybase_num_fields) - PHP_FALIAS(mssql_fetch_row, sybase_fetch_row, arginfo_sybase_fetch_row) - PHP_FALIAS(mssql_fetch_array, sybase_fetch_array, arginfo_sybase_fetch_array) - PHP_FALIAS(mssql_fetch_assoc, sybase_fetch_assoc, arginfo_sybase_fetch_assoc) - PHP_FALIAS(mssql_fetch_object, sybase_fetch_object, arginfo_sybase_fetch_object) - PHP_FALIAS(mssql_data_seek, sybase_data_seek, arginfo_sybase_data_seek) - PHP_FALIAS(mssql_fetch_field, sybase_fetch_field, arginfo_sybase_fetch_field) - PHP_FALIAS(mssql_field_seek, sybase_field_seek, arginfo_sybase_field_seek) - PHP_FALIAS(mssql_result, sybase_result, arginfo_sybase_result) - PHP_FALIAS(mssql_affected_rows, sybase_affected_rows, arginfo_sybase_affected_rows) - PHP_FALIAS(mssql_min_client_severity, sybase_min_client_severity, arginfo_sybase_min_client_severity) - PHP_FALIAS(mssql_min_server_severity, sybase_min_server_severity, arginfo_sybase_min_server_severity) - PHP_FALIAS(mssql_set_message_handler, sybase_set_message_handler, arginfo_sybase_set_message_handler) - PHP_FALIAS(mssql_deadlock_retry_count, sybase_deadlock_retry_count, arginfo_sybase_deadlock_retry_count) -#endif - PHP_FE_END -}; - -zend_module_entry sybase_module_entry = { - STANDARD_MODULE_HEADER, - "sybase_ct", - sybase_functions, - PHP_MINIT(sybase), - PHP_MSHUTDOWN(sybase), - PHP_RINIT(sybase), - PHP_RSHUTDOWN(sybase), - PHP_MINFO(sybase), - NO_VERSION_YET, - PHP_MODULE_GLOBALS(sybase), - PHP_GINIT(sybase), - PHP_GSHUTDOWN(sybase), - NULL, - STANDARD_MODULE_PROPERTIES_EX -}; - -/* static CS_CONTEXT *context; */ - -#ifdef COMPILE_DL_SYBASE_CT -ZEND_GET_MODULE(sybase) -#endif - -ZEND_DECLARE_MODULE_GLOBALS(sybase) - -#define CHECK_LINK(link) { if (link==-1) { php_error_docref(NULL, E_WARNING, "Sybase: A link to the server could not be established"); RETURN_FALSE; } } - - -static int _clean_invalid_results(zend_rsrc_list_entry *le) -{ - if (Z_TYPE_P(le) == le_result) { - sybase_link *sybase_ptr = ((sybase_result *) le->ptr)->sybase_ptr; - - if (!sybase_ptr->valid) { - return 1; - } - } - return 0; -} - -#define efree_n(x) { efree(x); x = NULL; } -#define efree_if(x) if (x) efree_n(x) - -#ifdef PHP_SYBASE_DEBUG -#define FREE_SYBASE_RESULT(result) \ - if (result) { \ - fprintf(stderr, "_free_sybase_result(%p) called from line #%d\n", result, __LINE__); \ - fflush(stderr); \ - _free_sybase_result(result); \ - result = NULL; \ - } -#else -#define FREE_SYBASE_RESULT(result) \ - if (result) { \ - _free_sybase_result(result); \ - result = NULL; \ - } -#endif -static void _free_sybase_result(sybase_result *result) -{ - int i, j; - - if (result->data) { - for (i = 0; i < (result->store ? result->num_rows : MIN(1, result->num_rows)); i++) { - for (j=0; jnum_fields; j++) { - zval_dtor(&result->data[i][j]); - } - efree(result->data[i]); - } - efree(result->data); - } - - if (result->fields) { - for (i=0; inum_fields; i++) { - zend_string_free(result->fields[i].name); - zend_string_free(result->fields[i].column_source); - } - efree(result->fields); - } - - if (result->tmp_buffer) { - for (i=0; inum_fields; i++) { - efree(result->tmp_buffer[i]); - } - efree(result->tmp_buffer); - } - - efree_if(result->lengths); - efree_if(result->indicators); - efree_if(result->datafmt); - efree_if(result->numerics); - efree_if(result->types); - - efree(result); -} - -/* Forward declaration */ -static int php_sybase_finish_results (sybase_result *result); - -static void php_free_sybase_result(zend_rsrc_list_entry *rsrc) -{ - sybase_result *result = (sybase_result *)rsrc->ptr; - - /* Check to see if we've read all rows */ - if (result->sybase_ptr && result->sybase_ptr->active_result_index) { - if (result->sybase_ptr->cmd) { - ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL); - } - php_sybase_finish_results(result); - } - - FREE_SYBASE_RESULT(result); -} - -static void _close_sybase_link(zend_rsrc_list_entry *rsrc) -{ - sybase_link *sybase_ptr = (sybase_link *)rsrc->ptr; - CS_INT con_status; - - sybase_ptr->valid = 0; - if (sybase_ptr->callback_name != NULL) { - zval_ptr_dtor(&sybase_ptr->callback_name); - sybase_ptr->callback_name= NULL; - } - zend_hash_apply(&EG(regular_list), (apply_func_t) _clean_invalid_results); - - /* Non-persistent connections will always be connected or we wouldn't - * get here, but since we want to check the death status anyway - * we might as well double-check the connect status. - */ - if (ct_con_props(sybase_ptr->connection, CS_GET, CS_CON_STATUS, - &con_status, CS_UNUSED, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to get connection status on close"); - /* Assume the worst. */ - con_status = CS_CONSTAT_CONNECTED | CS_CONSTAT_DEAD; - } - if (con_status & CS_CONSTAT_CONNECTED) { - if ((con_status & CS_CONSTAT_DEAD) || ct_close(sybase_ptr->connection, CS_UNUSED)!=CS_SUCCEED) { - ct_close(sybase_ptr->connection, CS_FORCE_CLOSE); - } - } - - ct_cmd_drop(sybase_ptr->cmd); - ct_con_drop(sybase_ptr->connection); - efree(sybase_ptr); - SybCtG(num_links)--; -} - - -static void _close_sybase_plink(zend_rsrc_list_entry *rsrc) -{ - sybase_link *sybase_ptr = (sybase_link *)rsrc->ptr; - CS_INT con_status; - - /* Persistent connections may have been closed before a failed - * reopen attempt. - */ - if (ct_con_props(sybase_ptr->connection, CS_GET, CS_CON_STATUS, - &con_status, CS_UNUSED, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to get connection status on close"); - /* Assume the worst. */ - con_status = CS_CONSTAT_CONNECTED | CS_CONSTAT_DEAD; - } - if (con_status & CS_CONSTAT_CONNECTED) { - if ((con_status & CS_CONSTAT_DEAD) || ct_close(sybase_ptr->connection, CS_UNUSED)!=CS_SUCCEED) { - ct_close(sybase_ptr->connection, CS_FORCE_CLOSE); - } - } - - ct_con_drop(sybase_ptr->connection); - free(sybase_ptr); - SybCtG(num_persistent)--; - SybCtG(num_links)--; -} - - -static CS_RETCODE CS_PUBLIC _client_message_handler(CS_CONTEXT *context, CS_CONNECTION *connection, CS_CLIENTMSG *errmsg) -{ - - if (CS_SEVERITY(errmsg->msgnumber) >= SybCtG(min_client_severity)) { - php_error_docref(NULL, E_WARNING, "Sybase: Client message: %s (severity %ld)", errmsg->msgstring, (long)CS_SEVERITY(errmsg->msgnumber)); - } - zend_string_free(SybCtG(server_message)); - SybCtG(server_message) = estrdup(errmsg->msgstring); - - - /* If this is a timeout message, return CS_FAIL to cancel the - * operation and mark the connection as dead. - */ - if (CS_SEVERITY(errmsg->msgnumber) == CS_SV_RETRY_FAIL && - CS_NUMBER(errmsg->msgnumber) == 63 && - CS_ORIGIN(errmsg->msgnumber) == 2 && - CS_LAYER(errmsg->msgnumber) == 1) - { - return CS_FAIL; - } - - return CS_SUCCEED; -} - -static int _call_message_handler(zval *callback_name, CS_SERVERMSG *srvmsg) -{ - int handled = 0; - zval *msgnumber, *severity, *state, *line, *text, *retval = NULL; - zval **args[5]; - - /* Border case - empty fcall */ - if (NULL == callback_name) return 0; - - /* Build arguments */ - MAKE_STD_ZVAL(msgnumber); - ZVAL_LONG(msgnumber, srvmsg->msgnumber); - args[0] = &msgnumber; - - MAKE_STD_ZVAL(severity); - ZVAL_LONG(severity, srvmsg->severity); - args[1] = &severity; - - MAKE_STD_ZVAL(state); - ZVAL_LONG(state, srvmsg->state); - args[2] = &state; - - MAKE_STD_ZVAL(line); - ZVAL_LONG(line, srvmsg->line); - args[3] = &line; - - MAKE_STD_ZVAL(text); - ZVAL_STRING(text, srvmsg->text, 1); - args[4] = &text; - - if (call_user_function_ex(EG(function_table), NULL, callback_name, &retval, 5, args, 0, NULL) == FAILURE) { - zval expr_copy; - int use_copy; - - use_copy = zend_make_printable_zval(callback_name, &expr_copy); - php_error_docref(NULL, E_WARNING, "Sybase: Cannot call the messagehandler %s", Z_STRVAL(expr_copy)); - zval_dtor(&expr_copy); - } - - if (retval) { - handled = ((Z_TYPE_P(retval) != IS_BOOL) || (Z_BVAL_P(retval) != 0)); - zval_ptr_dtor(&retval); - } else { - handled = 0; - } - - zval_ptr_dtor(&msgnumber); - zval_ptr_dtor(&severity); - zval_ptr_dtor(&state); - zval_ptr_dtor(&line); - zval_ptr_dtor(&text); - - return handled; -} - -static CS_RETCODE CS_PUBLIC _server_message_handler(CS_CONTEXT *context, CS_CONNECTION *connection, CS_SERVERMSG *srvmsg) -{ - sybase_link *sybase; - int handled = 0; - - /* Remember the last server message in any case */ - zend_string_free(SybCtG(server_message)); - SybCtG(server_message) = estrdup(srvmsg->text); - - /* Retrieve sybase link */ - if (ct_con_props(connection, CS_GET, CS_USERDATA, &sybase, CS_SIZEOF(sybase), NULL) != CS_SUCCEED) { - sybase = NULL; - } - - /* If this is a deadlock message, set the connection's deadlock flag - * so we will retry the request. Sorry about the bare constant here, - * but it's not defined anywhere and it's a "well-known" number. - */ - if (sybase && (srvmsg->msgnumber == 1205)) { - sybase->deadlock = 1; - } - - /* Check mininum server severity level */ - if (srvmsg->severity < SybCtG(min_server_severity)) { - return CS_SUCCEED; - } - - /* Call global message handler */ - handled = handled | _call_message_handler(SybCtG(callback_name), srvmsg); - - /* Call link specific message handler */ - if (sybase) { - handled = handled | _call_message_handler(sybase->callback_name, srvmsg); - } - - /* Spit out a warning if neither of them has handled this message */ - if (!handled) { - php_error_docref(NULL, E_WARNING, "Sybase: Server message: %s (severity %ld, procedure %s)", - srvmsg->text, (long)srvmsg->severity, ((srvmsg->proclen>0) ? srvmsg->proc : "N/A")); - } - - return CS_SUCCEED; -} - - -PHP_INI_BEGIN() - STD_PHP_INI_BOOLEAN("sybct.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateLong, allow_persistent, zend_sybase_globals, sybase_globals) - STD_PHP_INI_ENTRY_EX("sybct.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_persistent, zend_sybase_globals, sybase_globals, display_link_numbers) - STD_PHP_INI_ENTRY_EX("sybct.max_links", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_links, zend_sybase_globals, sybase_globals, display_link_numbers) - STD_PHP_INI_ENTRY("sybct.min_server_severity", "10", PHP_INI_ALL, OnUpdateLong, min_server_severity, zend_sybase_globals, sybase_globals) - STD_PHP_INI_ENTRY("sybct.min_client_severity", "10", PHP_INI_ALL, OnUpdateLong, min_client_severity, zend_sybase_globals, sybase_globals) - STD_PHP_INI_ENTRY("sybct.login_timeout", "-1", PHP_INI_ALL, OnUpdateLong, login_timeout, zend_sybase_globals, sybase_globals) - STD_PHP_INI_ENTRY("sybct.hostname", NULL, PHP_INI_ALL, OnUpdateString, hostname, zend_sybase_globals, sybase_globals) - STD_PHP_INI_ENTRY_EX("sybct.deadlock_retry_count", "0", PHP_INI_ALL, OnUpdateLong, deadlock_retry_count, zend_sybase_globals, sybase_globals, display_link_numbers) -PHP_INI_END() - - -static PHP_GINIT_FUNCTION(sybase) -{ - long opt; - - if (cs_ctx_alloc(CTLIB_VERSION, &sybase_globals->context)!=CS_SUCCEED || ct_init(sybase_globals->context, CTLIB_VERSION)!=CS_SUCCEED) { - return; - } - - /* Initialize message handlers */ - if (ct_callback(sybase_globals->context, NULL, CS_SET, CS_SERVERMSG_CB, (CS_VOID *)_server_message_handler)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to set server message handler"); - } - - if (ct_callback(sybase_globals->context, NULL, CS_SET, CS_CLIENTMSG_CB, (CS_VOID *)_client_message_handler)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to set client message handler"); - } - - /* Set datetime conversion format to "Nov 3 1998 8:06PM". - * This is the default format for the ct-lib that comes with - * Sybase ASE 11.5.1 for Solaris, but the Linux libraries that - * come with 11.0.3.3 default to "03/11/98" which is singularly - * useless. This levels the playing field for all platforms. - */ - { - CS_INT dt_convfmt = CS_DATES_SHORT; - if (cs_dt_info(sybase_globals->context, CS_SET, NULL, CS_DT_CONVFMT, CS_UNUSED, &dt_convfmt, sizeof(dt_convfmt), NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to set datetime conversion format"); - } - } - - /* Set the timeout, which is per context and can't be set with - * ct_con_props(), so set it globally from the config value if - * requested. The default is CS_NO_LIMIT. - * - * Note that despite some noise in the documentation about using - * signals to implement timeouts, they are actually implemented - * by using poll() or select() on Solaris and Linux. - */ - if (cfg_get_long("sybct.timeout", &opt)==SUCCESS) { - CS_INT cs_timeout = opt; - if (ct_config(sybase_globals->context, CS_SET, CS_TIMEOUT, &cs_timeout, CS_UNUSED, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to update the timeout"); - } - } - - sybase_globals->num_persistent=0; - sybase_globals->callback_name = NULL; -} - - -static PHP_GSHUTDOWN_FUNCTION(sybase) -{ - ct_exit(sybase_globals->context, CS_UNUSED); - cs_ctx_drop(sybase_globals->context); -} - -PHP_MINIT_FUNCTION(sybase) -{ - REGISTER_INI_ENTRIES(); - - le_link = zend_register_list_destructors_ex(_close_sybase_link, NULL, "sybase-ct link", module_number); - le_plink = zend_register_list_destructors_ex(NULL, _close_sybase_plink, "sybase-ct link persistent", module_number); - le_result = zend_register_list_destructors_ex(php_free_sybase_result, NULL, "sybase-ct result", module_number); - - return SUCCESS; -} - - - -PHP_RINIT_FUNCTION(sybase) -{ - SybCtG(default_link)=-1; - SybCtG(num_links) = SybCtG(num_persistent); - SybCtG(appname) = estrndup("PHP " PHP_VERSION, sizeof("PHP " PHP_VERSION)); - SybCtG(server_message) = STR_EMPTY_ALLOC(); - return SUCCESS; -} - - - -PHP_MSHUTDOWN_FUNCTION(sybase) -{ - UNREGISTER_INI_ENTRIES(); -#if 0 - ct_exit(context, CS_UNUSED); - cs_ctx_drop(context); -#endif - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(sybase) -{ - efree(SybCtG(appname)); - SybCtG(appname) = NULL; - if (SybCtG(callback_name)) { - zval_ptr_dtor(&SybCtG(callback_name)); - SybCtG(callback_name)= NULL; - } - zend_string_free(SybCtG(server_message)); - SybCtG(server_message) = NULL; - return SUCCESS; -} - - -static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char *user, char *passwd, char *charset, char *appname) -{ - CS_LOCALE *tmp_locale; - long packetsize; - - /* set a CS_CONNECTION record */ - if (ct_con_alloc(SybCtG(context), &sybase->connection)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to allocate connection record"); - return 0; - } - - /* Note - this saves a copy of sybase, not a pointer to it. */ - if (ct_con_props(sybase->connection, CS_SET, CS_USERDATA, &sybase, CS_SIZEOF(sybase), NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to set userdata"); - ct_con_drop(sybase->connection); - return 0; - } - - if (user) { - ct_con_props(sybase->connection, CS_SET, CS_USERNAME, user, CS_NULLTERM, NULL); - } - if (passwd) { - ct_con_props(sybase->connection, CS_SET, CS_PASSWORD, passwd, CS_NULLTERM, NULL); - } - if (appname) { - ct_con_props(sybase->connection, CS_SET, CS_APPNAME, appname, CS_NULLTERM, NULL); - } else { - ct_con_props(sybase->connection, CS_SET, CS_APPNAME, SybCtG(appname), CS_NULLTERM, NULL); - } - - if (SybCtG(hostname)) { - ct_con_props(sybase->connection, CS_SET, CS_HOSTNAME, SybCtG(hostname), CS_NULLTERM, NULL); - } - - if (charset) { - if (cs_loc_alloc(SybCtG(context), &tmp_locale)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to allocate locale information"); - } else { - if (cs_locale(SybCtG(context), CS_SET, tmp_locale, CS_LC_ALL, NULL, CS_NULLTERM, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to load default locale data"); - } else { - if (cs_locale(SybCtG(context), CS_SET, tmp_locale, CS_SYB_CHARSET, charset, CS_NULLTERM, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to update character set"); - } else { - if (ct_con_props(sybase->connection, CS_SET, CS_LOC_PROP, tmp_locale, CS_UNUSED, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to update connection properties"); - } - } - } - } - } - - if (cfg_get_long("sybct.packet_size", &packetsize) == SUCCESS) { - if (ct_con_props(sybase->connection, CS_SET, CS_PACKETSIZE, (CS_VOID *)&packetsize, CS_UNUSED, NULL) != CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to update connection packetsize"); - } - } - - /* Set the login timeout. Actually, the login timeout is per context - * and not per connection, but we will update the context here to - * allow for code such as the following: - * - * ini_set('sybct.login_timeout', $timeout); - * sybase_connect(...) - * - * Note that preceding calls to sybase_connect() will now use the - * updated value and not the default one! - * - * The default value for CS_LOGIN_TIMEOUT is 60 (1 minute). - */ - if (SybCtG(login_timeout) != -1) { - CS_INT cs_login_timeout = SybCtG(login_timeout); - if (ct_config(SybCtG(context), CS_SET, CS_LOGIN_TIMEOUT, &cs_login_timeout, CS_UNUSED, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to update the login timeout"); - } - } - - sybase->valid = 1; - sybase->dead = 0; - sybase->active_result_index = 0; - sybase->callback_name = NULL; - - /* create the link */ - if (ct_connect(sybase->connection, host, CS_NULLTERM)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to connect"); - ct_con_drop(sybase->connection); - return 0; - } - - if (ct_cmd_alloc(sybase->connection, &sybase->cmd)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to allocate command record"); - ct_close(sybase->connection, CS_UNUSED); - ct_con_drop(sybase->connection); - return 0; - } - - return 1; -} - - -static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) -{ - char *user = NULL, *passwd = NULL, *host = NULL, *charset = NULL, *appname = NULL; - char *hashed_details; - int hashed_details_length, len; - zend_bool new = 0; - sybase_link *sybase_ptr; - - host= user= passwd= charset= appname= NULL; - if (persistent) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!s!s!", &host, &len, &user, &len, &passwd, &len, &charset, &len, &appname, &len) == FAILURE) { - return; - } - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!s!s!b", &host, &len, &user, &len, &passwd, &len, &charset, &len, &appname, &len, &new) == FAILURE) { - return; - } - } - hashed_details_length = spprintf( - &hashed_details, - 0, - "sybase_%s_%s_%s_%s_%s", - host ? host : "", - user ? user : "", - passwd ? passwd : "", - charset ? charset : "", - appname ? appname : "" - ); - - if (!SybCtG(allow_persistent)) { - persistent=0; - } - if (persistent) { - zend_rsrc_list_entry *le; - - /* try to find if we already have this link in our persistent list */ - if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_length+1, (void **) &le)==FAILURE) { /* we don't */ - zend_rsrc_list_entry new_le; - - if (SybCtG(max_links)!=-1 && SybCtG(num_links)>=SybCtG(max_links)) { - php_error_docref(NULL, E_WARNING, "Sybase: Too many open links (%ld)", SybCtG(num_links)); - efree(hashed_details); - RETURN_FALSE; - } - if (SybCtG(max_persistent)!=-1 && SybCtG(num_persistent)>=SybCtG(max_persistent)) { - php_error_docref(NULL, E_WARNING, "Sybase: Too many open persistent links (%ld)", SybCtG(num_persistent)); - efree(hashed_details); - RETURN_FALSE; - } - - sybase_ptr = (sybase_link *) malloc(sizeof(sybase_link)); - if (!sybase_ptr) { - efree(hashed_details); - RETURN_FALSE; - } - if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset, appname)) { - free(sybase_ptr); - efree(hashed_details); - RETURN_FALSE; - } - - /* hash it up */ - Z_TYPE(new_le) = le_plink; - new_le.ptr = sybase_ptr; - if (zend_hash_update(&EG(persistent_list), hashed_details, hashed_details_length+1, (void *) &new_le, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) { - ct_close(sybase_ptr->connection, CS_UNUSED); - ct_con_drop(sybase_ptr->connection); - free(sybase_ptr); - efree(hashed_details); - RETURN_FALSE; - } - SybCtG(num_persistent)++; - SybCtG(num_links)++; - } else { /* we do */ - CS_INT con_status; - - if (Z_TYPE_P(le) != le_plink) { - efree(hashed_details); - RETURN_FALSE; - } - - sybase_ptr = (sybase_link *) le->ptr; - - /* If the link has died, close it and overwrite it with a new one. */ - - if (ct_con_props(sybase_ptr->connection, CS_GET, CS_CON_STATUS, - &con_status, CS_UNUSED, NULL)!=CS_SUCCEED) { - php_error_docref(NULL, E_WARNING, "Sybase: Unable to get connection status"); - efree(hashed_details); - RETURN_FALSE; - } - if (!(con_status & CS_CONSTAT_CONNECTED) || (con_status & CS_CONSTAT_DEAD) || sybase_ptr->dead) { - sybase_link sybase; - - if (con_status & CS_CONSTAT_CONNECTED) { - ct_close(sybase_ptr->connection, CS_FORCE_CLOSE); - } - /* Create a new connection, then replace the old - * connection. If we fail to create a new connection, - * put the old one back so there will be a connection, - * even if it is a non-functional one. This is because - * code may still be holding an id for this connection - * so we can't free the CS_CONNECTION. - * (This is actually totally hokey, it would be better - * to just ct_con_drop() the connection and set - * sybase_ptr->connection to NULL, then test it for - * NULL before trying to use it elsewhere . . .) - */ - memcpy(&sybase, sybase_ptr, sizeof(sybase_link)); - if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset, appname)) { - memcpy(sybase_ptr, &sybase, sizeof(sybase_link)); - efree(hashed_details); - RETURN_FALSE; - } - ct_con_drop(sybase.connection); /* drop old connection */ - } - } - ZEND_REGISTER_RESOURCE(return_value, sybase_ptr, le_plink); - } else { /* non persistent */ - zend_rsrc_list_entry *index_ptr, new_index_ptr; - - /* first we check the hash for the hashed_details key. if it exists, - * it should point us to the right offset where the actual sybase link sits. - * if it doesn't, open a new sybase link, add it to the resource list, - * and add a pointer to it with hashed_details as the key. - */ - if (!new && zend_hash_find(&EG(regular_list), hashed_details, hashed_details_length+1, (void **) &index_ptr)==SUCCESS) { - int type, link; - void *ptr; - - if (Z_TYPE_P(index_ptr) != le_index_ptr) { - efree(hashed_details); - RETURN_FALSE; - } - link = (int) index_ptr->ptr; - ptr = zend_list_find(link, &type); /* check if the link is still there */ - if (ptr && (type==le_link || type==le_plink)) { - zend_list_addref(link); - Z_LVAL_P(return_value) = SybCtG(default_link) = link; - Z_TYPE_P(return_value) = IS_RESOURCE; - efree(hashed_details); - return; - } else { - zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length+1); - } - } - if (SybCtG(max_links)!=-1 && SybCtG(num_links)>=SybCtG(max_links)) { - php_error_docref(NULL, E_WARNING, "Sybase: Too many open links (%ld)", SybCtG(num_links)); - efree(hashed_details); - RETURN_FALSE; - } - - sybase_ptr = (sybase_link *) emalloc(sizeof(sybase_link)); - if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset, appname)) { - efree(sybase_ptr); - efree(hashed_details); - RETURN_FALSE; - } - - /* add it to the list */ - ZEND_REGISTER_RESOURCE(return_value, sybase_ptr, le_link); - - /* add it to the hash */ - new_index_ptr.ptr = (void *) Z_LVAL_P(return_value); - Z_TYPE(new_index_ptr) = le_index_ptr; - if (zend_hash_update(&EG(regular_list), hashed_details, hashed_details_length+1, (void *) &new_index_ptr, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) { - ct_close(sybase_ptr->connection, CS_UNUSED); - ct_con_drop(sybase_ptr->connection); - efree(sybase_ptr); - efree(hashed_details); - RETURN_FALSE; - } - SybCtG(num_links)++; - } - efree(hashed_details); - SybCtG(default_link)=Z_LVAL_P(return_value); - zend_list_addref(SybCtG(default_link)); -} - - -static int php_sybase_get_default_link(INTERNAL_FUNCTION_PARAMETERS) -{ - if (SybCtG(default_link)==-1) { /* no link opened yet, implicitly open one */ - ht = 0; - php_sybase_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); - } - return SybCtG(default_link); -} - - -/* {{{ proto int sybase_connect([string host [, string user [, string password [, string charset [, string appname [, bool new]]]]]]) - Open Sybase server connection */ -PHP_FUNCTION(sybase_connect) -{ - php_sybase_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} - -/* }}} */ - -/* {{{ proto int sybase_pconnect([string host [, string user [, string password [, string charset [, string appname]]]]]) - Open persistent Sybase connection */ -PHP_FUNCTION(sybase_pconnect) -{ - php_sybase_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} - -/* }}} */ - -inline static int php_sybase_connection_id(zval *sybase_link_index, int *id) -{ - if (NULL == sybase_link_index) { - if (-1 == SybCtG(default_link)) { - return FAILURE; - } - *id = SybCtG(default_link); - } else { - *id = -1; /* explicit resource number */ - } - return SUCCESS; -} - -/* {{{ proto bool sybase_close([resource link_id]) - Close Sybase connection */ -PHP_FUNCTION(sybase_close) -{ - zval *sybase_link_index = NULL; - sybase_link *sybase_ptr; - int id; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &sybase_link_index) == FAILURE) { - return; - } - - if (php_sybase_connection_id(sybase_link_index, &id) == FAILURE) { - php_error_docref(NULL, E_WARNING, "Sybase: No connection to close"); - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, &sybase_link_index, id, "Sybase-Link", le_link, le_plink); - - if (id == -1) { - zend_list_delete(Z_RESVAL_P(sybase_link_index)); - } - if (id != -1 || (sybase_link_index && Z_RESVAL_P(sybase_link_index) == SybCtG(default_link))) { - zend_list_delete(SybCtG(default_link)); - SybCtG(default_link) = -1; - } - - RETURN_TRUE; -} - -/* }}} */ - - -static int exec_cmd(sybase_link *sybase_ptr, char *cmdbuf) -{ - CS_RETCODE retcode; - CS_INT restype; - int failure=0; - - /* Fail if we already marked this connection dead. */ - - if (sybase_ptr->dead) { - return FAILURE; - } - - /* - ** Get a command handle, store the command string in it, and - ** send it to the server. - */ - - if (ct_command(sybase_ptr->cmd, CS_LANG_CMD, cmdbuf, CS_NULLTERM, CS_UNUSED)!=CS_SUCCEED) { - sybase_ptr->dead = 1; - return FAILURE; - } - if (ct_send(sybase_ptr->cmd)!=CS_SUCCEED) { - sybase_ptr->dead = 1; - return FAILURE; - } - - while ((retcode = ct_results(sybase_ptr->cmd, &restype))==CS_SUCCEED) { - switch ((int) restype) { - case CS_CMD_SUCCEED: - case CS_CMD_DONE: - break; - - case CS_CMD_FAIL: - failure=1; - break; - - case CS_STATUS_RESULT: - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_CURRENT); - break; - - default: - failure=1; - break; - } - if (failure) { - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - return FAILURE; - } - } - - switch (retcode) { - case CS_END_RESULTS: - return SUCCESS; - break; - - case CS_FAIL: - /* Hopefully this either cleans up the connection, or the - * connection ends up marked dead so it will be reopened - * if it is persistent. We may want to do - * ct_close(CS_FORCE_CLOSE) if ct_cancel() fails; see the - * doc for ct_results()==CS_FAIL. - */ - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - /* Don't take chances with the vagaries of ct-lib. Mark it - * dead ourselves. - */ - sybase_ptr->dead = 1; - return FAILURE; - - default: - return FAILURE; - } -} - - -/* {{{ proto bool sybase_select_db(string database [, resource link_id]) - Select Sybase database */ -PHP_FUNCTION(sybase_select_db) -{ - zval *sybase_link_index = NULL; - char *db, *cmdbuf; - int id, len; - sybase_link *sybase_ptr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|r", &db, &len, &sybase_link_index) == FAILURE) { - return; - } - - if (php_sybase_connection_id(sybase_link_index, &id) == FAILURE) { - php_error_docref(NULL, E_WARNING, "Sybase: No connection"); - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, &sybase_link_index, id, "Sybase-Link", le_link, le_plink); - - spprintf(&cmdbuf, 4 + len + 1, "use %s", db); - if (exec_cmd(sybase_ptr, cmdbuf) == FAILURE) { - efree(cmdbuf); - RETURN_FALSE; - } else { - efree(cmdbuf); - RETURN_TRUE; - } -} - -/* }}} */ - -static int php_sybase_finish_results(sybase_result *result) -{ - int i, fail; - CS_RETCODE retcode; - CS_INT restype; - - efree_n(result->datafmt); - efree_n(result->lengths); - efree_n(result->indicators); - efree_n(result->numerics); - efree_n(result->types); - for (i=0; inum_fields; i++) { - efree(result->tmp_buffer[i]); - } - efree_n(result->tmp_buffer); - - /* Indicate we have read all rows */ - result->sybase_ptr->active_result_index= 0; - - /* The only restype we should get now is CS_CMD_DONE, possibly - * followed by a CS_STATUS_RESULT/CS_CMD_SUCCEED/CS_CMD_DONE - * sequence if the command was a stored procedure call. But we - * still need to read and discard unexpected results. We might - * want to return a failure in this case because the application - * won't be getting all the results it asked for. - */ - fail = 0; - while ((retcode = ct_results(result->sybase_ptr->cmd, &restype))==CS_SUCCEED) { - switch ((int) restype) { - case CS_CMD_SUCCEED: - case CS_CMD_DONE: - break; - - case CS_CMD_FAIL: - php_error_docref(NULL, E_WARNING, "Sybase: Command failed, canceling rest"); - ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL); - fail = 1; - break; - - case CS_COMPUTE_RESULT: - case CS_CURSOR_RESULT: - case CS_PARAM_RESULT: - case CS_ROW_RESULT: - /* Unexpected results, cancel them. */ - php_error_docref(NULL, E_NOTICE, "Sybase: Unexpected results, canceling current"); - ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_CURRENT); - break; - - case CS_STATUS_RESULT: - /* Status result from a stored procedure, cancel it but do not tell user */ - ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_CURRENT); - break; - - default: - php_error_docref(NULL, E_NOTICE, "Sybase: Unexpected results, canceling all"); - ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL); - break; - } - - if (fail) { - break; - } - } - - switch (retcode) { - case CS_END_RESULTS: - /* Normal. */ - break; - - case CS_FAIL: - /* Hopefully this either cleans up the connection, or the - * connection ends up marked dead so it will be reopened - * if it is persistent. We may want to do - * ct_close(CS_FORCE_CLOSE) if ct_cancel() fails; see the - * doc for ct_results()==CS_FAIL. - */ - ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL); - /* Don't take chances with the vagaries of ct-lib. Mark it - * dead ourselves. - */ - result->sybase_ptr->dead = 1; - - case CS_CANCELED: - default: - retcode = CS_FAIL; - break; - } - - return retcode; -} - -#define RETURN_DOUBLE_VAL(result, buf, length) \ - if ((length - 1) <= EG(precision)) { \ - errno = 0; \ - Z_DVAL(result) = zend_strtod(buf, NULL); \ - if (errno != ERANGE) { \ - Z_TYPE(result) = IS_DOUBLE; \ - } else { \ - ZVAL_STRINGL(&result, buf, length- 1, 1); \ - } \ - } else { \ - ZVAL_STRINGL(&result, buf, length- 1, 1); \ - } - -static int php_sybase_fetch_result_row(sybase_result *result, int numrows) -{ - int i, j; - CS_INT retcode; - - /* We've already fetched everything */ - if (result->last_retcode == CS_END_DATA || result->last_retcode == CS_END_RESULTS) { - return result->last_retcode; - } - - if (numrows!=-1) numrows+= result->num_rows; - while ((retcode=ct_fetch(result->sybase_ptr->cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, NULL))==CS_SUCCEED || retcode == CS_ROW_FAIL) { - result->num_rows++; - i= result->store ? result->num_rows- 1 : 0; - if (i >= result->blocks_initialized*SYBASE_ROWS_BLOCK) { - result->data = (zval **) safe_erealloc(result->data, SYBASE_ROWS_BLOCK*(++result->blocks_initialized), sizeof(zval *), 0); - } - if (result->store || 1 == result->num_rows) { - result->data[i] = (zval *) safe_emalloc(sizeof(zval), result->num_fields, 0); - } - - for (j = 0; j < result->num_fields; j++) { - - /* If we are in non-storing mode, free the previous result */ - if (!result->store && result->num_rows > 1 && Z_TYPE(result->data[i][j]) == IS_STRING) { - efree(Z_STRVAL(result->data[i][j])); - } - - if (result->indicators[j] == -1) { /* null value */ - ZVAL_NULL(&result->data[i][j]); - } else { - switch (result->numerics[j]) { - case 1: { - /* This indicates a long */ - ZVAL_LONG(&result->data[i][j], strtol(result->tmp_buffer[j], NULL, 10)); - break; - } - - case 2: { - /* This indicates a float */ - RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); - break; - } - - case 3: { - /* This indicates either a long or a float, which ever fits */ - errno = 0; - Z_LVAL(result->data[i][j]) = strtol(result->tmp_buffer[j], NULL, 10); - if (errno == ERANGE) { - - /* An overflow occurred, so try to fit it into a double */ - RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); - break; - } - Z_TYPE(result->data[i][j]) = IS_LONG; - break; - } - - default: { - /* This indicates anything else, return it as string - * FreeTDS doesn't correctly set result->indicators[j] correctly - * for NULL fields in some version in conjunction with ASE 12.5 - * but instead sets result->lengths[j] to 0, which would lead to - * a negative memory allocation (and thus a segfault). - */ - if (result->lengths[j] < 1) { - ZVAL_NULL(&result->data[i][j]); - } else { - ZVAL_STRINGL(&result->data[i][j], result->tmp_buffer[j], result->lengths[j]- 1, 1); - } - break; - } - } - } - } - if (numrows!=-1 && result->num_rows>=numrows) break; - } - - if (retcode==CS_ROW_FAIL) { - php_error_docref(NULL, E_WARNING, "Sybase: Error reading row %d", result->num_rows); - return retcode; - } - result->last_retcode= retcode; - switch (retcode) { - case CS_END_DATA: - retcode = php_sybase_finish_results(result); - break; - - case CS_ROW_FAIL: - case CS_SUCCEED: - break; - - default: - FREE_SYBASE_RESULT(result); - result = NULL; - retcode = CS_FAIL; /* Just to be sure */ - break; - } - - return retcode; -} - -static sybase_result * php_sybase_fetch_result_set(sybase_link *sybase_ptr, int buffered, int store) -{ - int num_fields; - sybase_result *result; - int i, j; - CS_INT retcode; - - /* The following (if unbuffered) is more or less the equivalent of mysql_store_result(). - * fetch all rows from the server into the row buffer, thus: - * 1) Being able to fire up another query without explicitly reading all rows - * 2) Having numrows accessible - */ - if (ct_res_info(sybase_ptr->cmd, CS_NUMDATA, &num_fields, CS_UNUSED, NULL)!=CS_SUCCEED) { - return NULL; - } - - result = (sybase_result *) emalloc(sizeof(sybase_result)); - result->data = (zval **) safe_emalloc(sizeof(zval *), SYBASE_ROWS_BLOCK, 0); - result->fields = NULL; - result->sybase_ptr = sybase_ptr; - result->cur_field=result->cur_row=result->num_rows=0; - result->num_fields = num_fields; - result->last_retcode = 0; - result->store= store; - result->blocks_initialized= 1; - result->tmp_buffer = (char **) safe_emalloc(sizeof(char *), num_fields, 0); - result->lengths = (CS_INT *) safe_emalloc(sizeof(CS_INT), num_fields, 0); - result->indicators = (CS_SMALLINT *) safe_emalloc(sizeof(CS_INT), num_fields, 0); - result->datafmt = (CS_DATAFMT *) safe_emalloc(sizeof(CS_DATAFMT), num_fields, 0); - result->numerics = (unsigned char *) safe_emalloc(sizeof(unsigned char), num_fields, 0); - result->types = (CS_INT *) safe_emalloc(sizeof(CS_INT), num_fields, 0); - - for (i=0; icmd, i+1, &result->datafmt[i]); - result->types[i] = result->datafmt[i].datatype; - switch (result->datafmt[i].datatype) { - case CS_CHAR_TYPE: - case CS_VARCHAR_TYPE: - case CS_TEXT_TYPE: - case CS_IMAGE_TYPE: - result->datafmt[i].maxlength++; - result->numerics[i] = 0; - break; - case CS_BINARY_TYPE: - case CS_VARBINARY_TYPE: - result->datafmt[i].maxlength *= 2; - result->datafmt[i].maxlength++; - result->numerics[i] = 0; - break; - case CS_BIT_TYPE: - case CS_TINYINT_TYPE: - result->datafmt[i].maxlength = 4; - result->numerics[i] = 1; - break; - case CS_SMALLINT_TYPE: - result->datafmt[i].maxlength = 7; - result->numerics[i] = 1; - break; - case CS_INT_TYPE: - result->datafmt[i].maxlength = 12; - result->numerics[i] = 1; - break; - case CS_REAL_TYPE: - case CS_FLOAT_TYPE: - result->datafmt[i].maxlength = 24; - result->numerics[i] = 2; - break; - case CS_MONEY_TYPE: - case CS_MONEY4_TYPE: - result->datafmt[i].maxlength = 24; - result->numerics[i] = 2; - break; - case CS_DATETIME_TYPE: - case CS_DATETIME4_TYPE: - result->datafmt[i].maxlength = 30; - result->numerics[i] = 0; - break; - case CS_NUMERIC_TYPE: - case CS_DECIMAL_TYPE: - result->datafmt[i].maxlength = result->datafmt[i].precision + 3; - /* numeric(10) vs numeric(10, 1) */ - result->numerics[i] = (result->datafmt[i].scale == 0) ? 3 : 2; - break; - default: - result->datafmt[i].maxlength++; - result->numerics[i] = 0; - break; - } - result->tmp_buffer[i] = (char *)emalloc(result->datafmt[i].maxlength); - result->datafmt[i].datatype = CS_CHAR_TYPE; - result->datafmt[i].format = CS_FMT_NULLTERM; - ct_bind(sybase_ptr->cmd, i+1, &result->datafmt[i], result->tmp_buffer[i], &result->lengths[i], &result->indicators[i]); - } - - result->fields = (sybase_field *) safe_emalloc(sizeof(sybase_field), num_fields, 0); - j=0; - for (i=0; idatafmt[i].namelen>0) { - result->fields[i].name = estrndup(result->datafmt[i].name, result->datafmt[i].namelen); - } else { - if (j>0) { - snprintf(computed_buf, 16, "computed%d", j); - } else { - strcpy(computed_buf, "computed"); - } - result->fields[i].name = estrdup(computed_buf); - j++; - } - result->fields[i].column_source = STR_EMPTY_ALLOC(); - result->fields[i].max_length = result->datafmt[i].maxlength-1; - result->fields[i].numeric = result->numerics[i]; - Z_TYPE(result->fields[i]) = result->types[i]; - } - - if (buffered) { - retcode = CS_SUCCEED; - } else { - if ((retcode = php_sybase_fetch_result_row(result, -1)) == CS_FAIL) { - return NULL; - } - } - - result->last_retcode = retcode; - return result; -} - -static void php_sybase_query (INTERNAL_FUNCTION_PARAMETERS, int buffered) -{ - zval *sybase_link_index = NULL; - zend_bool store = 1; - char *query; - size_t len, id, deadlock_count; - sybase_link *sybase_ptr; - sybase_result *result; - CS_INT restype; - CS_RETCODE retcode; - enum { - Q_RESULT, /* Success with results. */ - Q_SUCCESS, /* Success but no results. */ - Q_FAILURE, /* Failure, no results. */ - } status; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|rb", &query, &len, &sybase_link_index, &store) == FAILURE) { - return; - } - - if (!store && !buffered) { - php_error_docref(NULL, E_NOTICE, "Sybase: Cannot use non-storing mode with buffered queries"); - store = 1; - } - - if (php_sybase_connection_id(sybase_link_index, &id) == FAILURE) { - php_error_docref(NULL, E_WARNING, "Sybase: No connection"); - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, &sybase_link_index, id, "Sybase-Link", le_link, le_plink); - - /* Fail if we already marked this connection dead. */ - if (sybase_ptr->dead) { - RETURN_FALSE; - } - - /* Check to see if a previous sybase_unbuffered_query has read all rows */ - if (sybase_ptr->active_result_index) { - zval *tmp = NULL; - - php_error_docref(NULL, E_NOTICE, "Sybase: Called without first fetching all rows from a previous unbuffered query"); - if (sybase_ptr->cmd) { - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - } - - /* Get the resultset and free it */ - ALLOC_ZVAL(tmp); - Z_LVAL_P(tmp)= sybase_ptr->active_result_index; - Z_TYPE_P(tmp)= IS_RESOURCE; - INIT_PZVAL(tmp); - ZEND_FETCH_RESOURCE(result, sybase_result *, &tmp, -1, "Sybase result", le_result); - - if (result) { - php_sybase_finish_results(result); - } - - zval_ptr_dtor(&tmp); - zend_list_delete(sybase_ptr->active_result_index); - sybase_ptr->active_result_index= 0; - } - - /* Repeat until we don't deadlock. */ - deadlock_count= 0; - for (;;) { - result = NULL; - sybase_ptr->deadlock = 0; - sybase_ptr->affected_rows = 0; - - /* On Solaris 11.5, ct_command() can be moved outside the - * loop, but not on Linux 11.0. - */ - if (ct_command(sybase_ptr->cmd, CS_LANG_CMD, query, CS_NULLTERM, CS_UNUSED)!=CS_SUCCEED) { - /* If this didn't work, the connection is screwed but - * ct-lib might not set CS_CONSTAT_DEAD. So set our own - * flag. This happens sometimes when the database is restarted - * and/or its machine is rebooted, and ct_command() returns - * CS_BUSY for some reason. - */ - sybase_ptr->dead = 1; - php_error_docref(NULL, E_WARNING, "Sybase: Connection is dead"); - RETURN_FALSE; - } - - if (ct_send(sybase_ptr->cmd)!=CS_SUCCEED) { - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - sybase_ptr->dead = 1; - php_error_docref(NULL, E_WARNING, "Sybase: Cannot send command"); - RETURN_FALSE; - } - - /* Use the first result set or succeed/fail status and discard the - * others. Applications really shouldn't be making calls that - * return multiple result sets, but if they do then we need to - * properly read or cancel them or the connection will become - * unusable. - */ - if (ct_results(sybase_ptr->cmd, &restype)!=CS_SUCCEED) { - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - sybase_ptr->dead = 1; - php_error_docref(NULL, E_WARNING, "Sybase: Cannot read results"); - RETURN_FALSE; - } - switch ((int) restype) { - case CS_CMD_FAIL: - default: - status = Q_FAILURE; - break; - case CS_CMD_SUCCEED: - case CS_CMD_DONE: { - CS_INT row_count; - if (ct_res_info(sybase_ptr->cmd, CS_ROW_COUNT, &row_count, CS_UNUSED, NULL)==CS_SUCCEED) { - sybase_ptr->affected_rows = (long)row_count; - } - } - /* Fall through */ - case CS_COMPUTEFMT_RESULT: - case CS_ROWFMT_RESULT: - case CS_DESCRIBE_RESULT: - case CS_MSG_RESULT: - buffered= 0; /* These queries have no need for buffering */ - status = Q_SUCCESS; - break; - case CS_COMPUTE_RESULT: - case CS_CURSOR_RESULT: - case CS_PARAM_RESULT: - case CS_ROW_RESULT: - case CS_STATUS_RESULT: - result = php_sybase_fetch_result_set(sybase_ptr, buffered, store); - if (result == NULL) { - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - RETURN_FALSE; - } - status = Q_RESULT; - break; - } - - /* Check for left-over results */ - if (!buffered && status != Q_RESULT) { - while ((retcode = ct_results(sybase_ptr->cmd, &restype))==CS_SUCCEED) { - switch ((int) restype) { - case CS_CMD_SUCCEED: - case CS_CMD_DONE: - break; - - case CS_CMD_FAIL: - status = Q_FAILURE; - break; - - case CS_COMPUTE_RESULT: - case CS_CURSOR_RESULT: - case CS_PARAM_RESULT: - case CS_ROW_RESULT: - if (status != Q_RESULT) { - result = php_sybase_fetch_result_set(sybase_ptr, buffered, store); - if (result == NULL) { - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - sybase_ptr->dead = 1; - RETURN_FALSE; - } - status = Q_RESULT; - retcode = result->last_retcode; - } else { - /* Unexpected results, cancel them. */ - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_CURRENT); - } - break; - case CS_STATUS_RESULT: - /* Unexpected results, cancel them. */ - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_CURRENT); - break; - - default: - status = Q_FAILURE; - break; - } - if (status == Q_FAILURE) { - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - } - if (retcode == CS_END_RESULTS) { - break; - } - } - switch (retcode) { - case CS_END_RESULTS: - /* Normal. */ - break; - - case CS_FAIL: - /* Hopefully this either cleans up the connection, or the - * connection ends up marked dead so it will be reopened - * if it is persistent. We may want to do - * ct_close(CS_FORCE_CLOSE) if ct_cancel() fails; see the - * doc for ct_results()==CS_FAIL. - */ - ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL); - /* Don't take chances with the vagaries of ct-lib. Mark it - * dead ourselves. - */ - sybase_ptr->dead = 1; - case CS_CANCELED: - default: - status = Q_FAILURE; - break; - } - } - - /* Retry deadlocks up until deadlock_retry_count times */ - if (sybase_ptr->deadlock && SybCtG(deadlock_retry_count) != -1 && ++deadlock_count > SybCtG(deadlock_retry_count)) { - php_error_docref(NULL, E_WARNING, "Sybase: Retried deadlock %d times [max: %ld], giving up", deadlock_count- 1, SybCtG(deadlock_retry_count)); - FREE_SYBASE_RESULT(result); - break; - } - - /* If query completed without deadlock, break out of the loop. - * Sometimes deadlock results in failures and sometimes not, - * it seems to depend on the server flavor. But we want to - * retry all deadlocks. - */ - if (sybase_ptr->dead || sybase_ptr->deadlock == 0) { - break; - } - - /* Get rid of any results we may have fetched. This happens: - * e.g., our result set may be a stored procedure status which - * is returned even if the stored procedure deadlocks. As an - * optimization, we could try not to fetch results in known - * deadlock conditions, but deadlock is (should be) rare. - */ - FREE_SYBASE_RESULT(result); - } - - if (status == Q_SUCCESS) { - RETURN_TRUE; - } - - if (status == Q_FAILURE) { - FREE_SYBASE_RESULT(result); - RETURN_FALSE; - } - - /* Indicate we have data in case of buffered queries */ - id= ZEND_REGISTER_RESOURCE(return_value, result, le_result); - sybase_ptr->active_result_index= buffered ? id : 0; -} - -/* {{{ proto int sybase_query(string query [, resource link_id]) - Send Sybase query */ -PHP_FUNCTION(sybase_query) -{ - php_sybase_query(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto int sybase_unbuffered_query(string query [, resource link_id]) - Send Sybase query */ -PHP_FUNCTION(sybase_unbuffered_query) -{ - php_sybase_query(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} - -/* {{{ proto bool sybase_free_result(resource result) - Free result memory */ -PHP_FUNCTION(sybase_free_result) -{ - zval *sybase_result_index = NULL; - sybase_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &sybase_result_index) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - /* Did we fetch up until the end? */ - if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) { - /* php_error_docref(NULL, E_WARNING, "Sybase: canceling the rest of the results"); */ - ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL); - php_sybase_finish_results(result); - } - - zend_list_delete(Z_LVAL_P(sybase_result_index)); - RETURN_TRUE; -} - -/* }}} */ - -/* {{{ proto string sybase_get_last_message(void) - Returns the last message from server (over min_message_severity) */ -PHP_FUNCTION(sybase_get_last_message) -{ - RETURN_STRING(SybCtG(server_message), 1); -} -/* }}} */ - -/* {{{ proto int sybase_num_rows(resource result) - Get number of rows in result */ -PHP_FUNCTION(sybase_num_rows) -{ - zval *sybase_result_index = NULL; - sybase_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &sybase_result_index) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - Z_LVAL_P(return_value) = result->num_rows; - Z_TYPE_P(return_value) = IS_LONG; -} - -/* }}} */ - -/* {{{ proto int sybase_num_fields(resource result) - Get number of fields in result */ -PHP_FUNCTION(sybase_num_fields) -{ - zval *sybase_result_index = NULL; - sybase_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &sybase_result_index) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - Z_LVAL_P(return_value) = result->num_fields; - Z_TYPE_P(return_value) = IS_LONG; -} - -/* }}} */ - -/* {{{ proto array sybase_fetch_row(resource result) - Get row as enumerated array */ -PHP_FUNCTION(sybase_fetch_row) -{ - zval *sybase_result_index = NULL; - int i; - sybase_result *result; - zval *field_content; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &sybase_result_index) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - /* Unbuffered? */ - if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) { - php_sybase_fetch_result_row(result, 1); - } - - /* At the end? */ - if (result->cur_row >= result->num_rows) { - RETURN_FALSE; - } - - array_init(return_value); - for (i=0; inum_fields; i++) { - ALLOC_ZVAL(field_content); - *field_content = result->data[result->store ? result->cur_row : 0][i]; - INIT_PZVAL(field_content); - zval_copy_ctor(field_content); - zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *) &field_content, sizeof(zval* ), NULL); - } - result->cur_row++; -} - -/* }}} */ - -static void php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int numerics) -{ - zval *sybase_result_index = NULL; - sybase_result *result; - int i, j; - zval *tmp; - char name[32]; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &sybase_result_index) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - /* Unbuffered ? Fetch next row */ - if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) { - php_sybase_fetch_result_row(result, 1); - } - - /* At the end? */ - if (result->cur_row >= result->num_rows) { - RETURN_FALSE; - } - - array_init(return_value); - - j= 1; - for (i=0; inum_fields; i++) { - ALLOC_ZVAL(tmp); - *tmp = result->data[result->store ? result->cur_row : 0][i]; - INIT_PZVAL(tmp); - zval_copy_ctor(tmp); - if (numerics) { - zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *) &tmp, sizeof(zval *), NULL); - Z_ADDREF_P(tmp); - } - - if (zend_hash_exists(Z_ARRVAL_P(return_value), result->fields[i].name, strlen(result->fields[i].name)+1)) { - snprintf(name, 32, "%s%d", result->fields[i].name, j); - result->fields[i].name= estrdup(name); - j++; - } - zend_hash_update(Z_ARRVAL_P(return_value), result->fields[i].name, strlen(result->fields[i].name)+1, (void *) &tmp, sizeof(zval *), NULL); - } - result->cur_row++; -} - - -/* {{{ proto object sybase_fetch_object(resource result [, mixed object]) - Fetch row as object */ -PHP_FUNCTION(sybase_fetch_object) -{ - zval *object = NULL; - zval *sybase_result_index = NULL; - zend_class_entry *ce = NULL; - sybase_result *result; - - /* Was a second parameter given? */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|z", &sybase_result_index, &object) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - ce = ZEND_STANDARD_CLASS_DEF_PTR; - if (NULL != object) { - switch (Z_TYPE_P(object)) { - case IS_OBJECT: { - ce = Z_OBJCE_P(object); - break; - } - - case IS_NULL: { - /* Use default (ZEND_STANDARD_CLASS_DEF_PTR) */ - break; - } - - default: { - zend_class_entry **pce = NULL; - convert_to_string(object); - - if (zend_lookup_class(Z_STRVAL_P(object), Z_STRLEN_P(object), &pce) == FAILURE) { - php_error_docref(NULL, E_NOTICE, "Sybase: Class %s has not been declared", Z_STRVAL_P(object)); - /* Use default (ZEND_STANDARD_CLASS_DEF_PTR) */ - } else { - ce = *pce; - } - } - } - } - - /* Reset no. of arguments to 1 so that we can use INTERNAL_FUNCTION_PARAM_PASSTHRU */ - ht= 1; - php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); - if (Z_TYPE_P(return_value) == IS_ARRAY) { - object_and_properties_init(return_value, ce, Z_ARRVAL_P(return_value)); - } -} -/* }}} */ - -/* {{{ proto array sybase_fetch_array(resource result) - Fetch row as array */ -PHP_FUNCTION(sybase_fetch_array) -{ - php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto array sybase_fetch_assoc(resource result) - Fetch row as array without numberic indices */ -PHP_FUNCTION(sybase_fetch_assoc) -{ - php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto bool sybase_data_seek(resource result, int offset) - Move internal row pointer */ -PHP_FUNCTION(sybase_data_seek) -{ - zval *sybase_result_index = NULL; - long offset; - sybase_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &sybase_result_index, &offset) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - /* Unbuffered ? */ - if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS && offset >= result->num_rows) { - php_sybase_fetch_result_row(result, offset+ 1); - } - - if (offset < 0 || offset >= result->num_rows) { - php_error_docref(NULL, E_WARNING, "Sybase: Bad row offset %ld, must be betweem 0 and %d", offset, result->num_rows - 1); - RETURN_FALSE; - } - - result->cur_row = offset; - RETURN_TRUE; -} -/* }}} */ - -static char *php_sybase_get_field_name(CS_INT type) -{ - switch (type) { - case CS_CHAR_TYPE: - case CS_VARCHAR_TYPE: - case CS_TEXT_TYPE: - return "string"; - break; - case CS_IMAGE_TYPE: - return "image"; - break; - case CS_BINARY_TYPE: - case CS_VARBINARY_TYPE: - return "blob"; - break; - case CS_BIT_TYPE: - return "bit"; - break; - case CS_TINYINT_TYPE: - case CS_SMALLINT_TYPE: - case CS_INT_TYPE: - return "int"; - break; - case CS_REAL_TYPE: - case CS_FLOAT_TYPE: - case CS_NUMERIC_TYPE: - case CS_DECIMAL_TYPE: - return "real"; - break; - case CS_MONEY_TYPE: - case CS_MONEY4_TYPE: - return "money"; - break; - case CS_DATETIME_TYPE: - case CS_DATETIME4_TYPE: - return "datetime"; - break; - default: - return "unknown"; - break; - } -} - - -/* {{{ proto object sybase_fetch_field(resource result [, int offset]) - Get field information */ -PHP_FUNCTION(sybase_fetch_field) -{ - zval *sybase_result_index = NULL; - long field_offset = -1; - sybase_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &sybase_result_index, &field_offset) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - if (field_offset == -1) { - field_offset = result->cur_field; - result->cur_field++; - } - - if (field_offset < 0 || field_offset >= result->num_fields) { - if (ZEND_NUM_ARGS() == 2) { /* field specified explicitly */ - php_error_docref(NULL, E_WARNING, "Sybase: Bad column offset"); - } - RETURN_FALSE; - } - - object_init(return_value); - - add_property_string(return_value, "name", result->fields[field_offset].name); - add_property_long(return_value, "max_length", result->fields[field_offset].max_length); - add_property_string(return_value, "column_source", result->fields[field_offset].column_source); - add_property_long(return_value, "numeric", result->fields[field_offset].numeric); - add_property_string(return_value, "type", php_sybase_get_field_name(Z_TYPE(result->fields[field_offset]))); -} -/* }}} */ - - -/* {{{ proto bool sybase_field_seek(resource result, int offset) - Set field offset */ -PHP_FUNCTION(sybase_field_seek) -{ - zval *sybase_result_index = NULL; - long field_offset; - sybase_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &sybase_result_index, &field_offset) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - if (field_offset < 0 || field_offset >= result->num_fields) { - php_error_docref(NULL, E_WARNING, "Sybase: Bad column offset"); - RETURN_FALSE; - } - - result->cur_field = field_offset; - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ proto string sybase_result(resource result, int row, mixed field) - Get result data */ -PHP_FUNCTION(sybase_result) -{ - zval *field; - zval *sybase_result_index = NULL; - long row; - int field_offset = 0; - sybase_result *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &sybase_result_index, &row, &field) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", le_result); - - /* Unbuffered ? */ - if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS && row >= result->num_rows) { - php_sybase_fetch_result_row(result, row); - } - - if (row < 0 || row >= result->num_rows) { - php_error_docref(NULL, E_WARNING, "Sybase: Bad row offset (%ld)", row); - RETURN_FALSE; - } - - switch(Z_TYPE_P(field)) { - case IS_STRING: { - int i; - - for (i = 0; i < result->num_fields; i++) { - if (strcasecmp(result->fields[i].name, Z_STRVAL_P(field)) == 0) { - field_offset = i; - break; - } - } - if (i >= result->num_fields) { /* no match found */ - php_error_docref(NULL, E_WARNING, "Sybase: %s field not found in result", Z_STRVAL_P(field)); - RETURN_FALSE; - } - break; - } - default: - convert_to_long(field); - field_offset = Z_LVAL_P(field); - if (field_offset < 0 || field_offset >= result->num_fields) { - php_error_docref(NULL, E_WARNING, "Sybase: Bad column offset specified"); - RETURN_FALSE; - } - break; - } - - *return_value = result->data[row][field_offset]; - zval_copy_ctor(return_value); -} -/* }}} */ - - -/* {{{ proto int sybase_affected_rows([resource link_id]) - Get number of affected rows in last query */ -PHP_FUNCTION(sybase_affected_rows) -{ - zval *sybase_link_index = NULL; - sybase_link *sybase_ptr; - int id; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &sybase_link_index) == FAILURE) { - return; - } - - if (php_sybase_connection_id(sybase_link_index, &id) == FAILURE) { - php_error_docref(NULL, E_WARNING, "Sybase: No connection"); - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, &sybase_link_index, id, "Sybase-Link", le_link, le_plink); - - Z_LVAL_P(return_value) = sybase_ptr->affected_rows; - Z_TYPE_P(return_value) = IS_LONG; -} -/* }}} */ - - -PHP_MINFO_FUNCTION(sybase) -{ - char buf[32]; - - php_info_print_table_start(); - php_info_print_table_header(2, "Sybase_CT Support", "enabled" ); - snprintf(buf, sizeof(buf), "%ld", SybCtG(num_persistent)); - php_info_print_table_row(2, "Active Persistent Links", buf); - snprintf(buf, sizeof(buf), "%ld", SybCtG(num_links)); - php_info_print_table_row(2, "Active Links", buf); - snprintf(buf, sizeof(buf), "%ld", SybCtG(min_server_severity)); - php_info_print_table_row(2, "Min server severity", buf); - snprintf(buf, sizeof(buf), "%ld", SybCtG(min_client_severity)); - php_info_print_table_row(2, "Min client severity", buf); - php_info_print_table_row(2, "Application Name", SybCtG(appname)); - snprintf(buf, sizeof(buf), "%ld", SybCtG(deadlock_retry_count)); - php_info_print_table_row(2, "Deadlock retry count", buf); - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); -} - - -/* {{{ proto void sybase_min_client_severity(int severity) - Sets minimum client severity */ -PHP_FUNCTION(sybase_min_client_severity) -{ - long severity; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &severity) == FAILURE) { - return; - } - - SybCtG(min_client_severity) = severity; -} -/* }}} */ - - -/* {{{ proto void sybase_min_server_severity(int severity) - Sets minimum server severity */ -PHP_FUNCTION(sybase_min_server_severity) -{ - long severity; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &severity) == FAILURE) { - return; - } - - SybCtG(min_server_severity) = severity; -} -/* }}} */ - -/* {{{ proto void sybase_deadlock_retry_count(int retry_count) - Sets deadlock retry count */ -PHP_FUNCTION(sybase_deadlock_retry_count) -{ - long retry_count; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &retry_count) == FAILURE) { - return; - } - - SybCtG(deadlock_retry_count) = retry_count; -} -/* }}} */ - - -/* {{{ proto bool sybase_set_message_handler(mixed error_func [, resource connection]) - Set the error handler, to be called when a server message is raised. - If error_func is NULL the handler will be deleted */ -PHP_FUNCTION(sybase_set_message_handler) -{ - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache cache = empty_fcall_info_cache; - zval *sybase_link_index= NULL; - sybase_link *sybase_ptr; - zval **callback; - int id; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "f!|r", &fci, &cache, &sybase_link_index) == FAILURE) { - return; - } - - if (php_sybase_connection_id(sybase_link_index, &id) == FAILURE) { - - /* Doesn't matter if we're not connected yet, use default */ - callback= &SybCtG(callback_name); - } else if (-1 == id) { - - /* Connection-based message handler */ - ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, &sybase_link_index, id, "Sybase-Link", le_link, le_plink); - callback= &sybase_ptr->callback_name; - } else { - - /* Default message handler */ - callback= &SybCtG(callback_name); - } - - /* Clean old callback */ - if (*callback) { - zval_ptr_dtor(callback); - *callback = NULL; - } - - if (ZEND_FCI_INITIALIZED(fci)) { - ALLOC_ZVAL(*callback); - **callback = *fci.function_name; - INIT_PZVAL(*callback); - zval_copy_ctor(*callback); - } else { - callback= NULL; - } - - RETURN_TRUE; -} -/* }}} */ - - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/sybase_ct/php_sybase_ct.h b/ext/sybase_ct/php_sybase_ct.h deleted file mode 100644 index a517f3e637e7c..0000000000000 --- a/ext/sybase_ct/php_sybase_ct.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Zeev Suraski | - | Timm Friebe | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_SYBASE_CT_H -#define PHP_SYBASE_CT_H - -#if HAVE_SYBASE_CT - -#define CTLIB_VERSION CS_VERSION_100 - -extern zend_module_entry sybase_module_entry; -#define sybase_module_ptr &sybase_module_entry - -PHP_MINIT_FUNCTION(sybase); -PHP_MSHUTDOWN_FUNCTION(sybase); -PHP_RINIT_FUNCTION(sybase); -PHP_RSHUTDOWN_FUNCTION(sybase); -PHP_MINFO_FUNCTION(sybase); - -PHP_FUNCTION(sybase_connect); -PHP_FUNCTION(sybase_pconnect); -PHP_FUNCTION(sybase_close); -PHP_FUNCTION(sybase_select_db); -PHP_FUNCTION(sybase_query); -PHP_FUNCTION(sybase_unbuffered_query); -PHP_FUNCTION(sybase_free_result); -PHP_FUNCTION(sybase_get_last_message); -PHP_FUNCTION(sybase_num_rows); -PHP_FUNCTION(sybase_num_fields); -PHP_FUNCTION(sybase_fetch_row); -PHP_FUNCTION(sybase_fetch_array); -PHP_FUNCTION(sybase_fetch_assoc); -PHP_FUNCTION(sybase_fetch_object); -PHP_FUNCTION(sybase_data_seek); -PHP_FUNCTION(sybase_result); -PHP_FUNCTION(sybase_affected_rows); -PHP_FUNCTION(sybase_field_seek); -PHP_FUNCTION(sybase_min_client_severity); -PHP_FUNCTION(sybase_min_server_severity); -PHP_FUNCTION(sybase_fetch_field); -PHP_FUNCTION(sybase_set_message_handler); -PHP_FUNCTION(sybase_deadlock_retry_count); - -#include - -ZEND_BEGIN_MODULE_GLOBALS(sybase) - long default_link; - long num_links,num_persistent; - long max_links,max_persistent; - long login_timeout; - long allow_persistent; - char *appname; - char *hostname; - char *server_message; - long min_server_severity, min_client_severity; - long deadlock_retry_count; - zval *callback_name; - CS_CONTEXT *context; -ZEND_END_MODULE_GLOBALS(sybase) - -typedef struct { - CS_CONNECTION *connection; - CS_COMMAND *cmd; - int valid; - int deadlock; - int dead; - int active_result_index; - long affected_rows; - zval *callback_name; -} sybase_link; - -#define SYBASE_ROWS_BLOCK 128 - -typedef struct { - char *name,*column_source; - int max_length, numeric; - CS_INT type; -} sybase_field; - -typedef struct { - zval **data; - sybase_field *fields; - sybase_link *sybase_ptr; - int cur_row,cur_field; - int num_rows,num_fields; - - /* For unbuffered reads */ - CS_INT *lengths; - CS_SMALLINT *indicators; - char **tmp_buffer; - unsigned char *numerics; - CS_INT *types; - CS_DATAFMT *datafmt; - int blocks_initialized; - CS_RETCODE last_retcode; - int store; -} sybase_result; - -#ifdef ZTS -# define SybCtG(v) TSRMG(sybase_globals_id, zend_sybase_globals *, v) -#else -# define SybCtG(v) (sybase_globals.v) -#endif - -#else - -#define sybase_module_ptr NULL - -#endif - -#define phpext_sybase_ct_ptr sybase_module_ptr - -#endif /* PHP_SYBASE_CT_H */ diff --git a/ext/sybase_ct/tests/bug22403.phpt b/ext/sybase_ct/tests/bug22403.phpt deleted file mode 100644 index 20d5248ff42a2..0000000000000 --- a/ext/sybase_ct/tests/bug22403.phpt +++ /dev/null @@ -1,88 +0,0 @@ ---TEST-- -Sybase-CT bug #22403 (crash when executing a stored procedure without parameters) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) -Stored procedure %s -bool(true) ->>> Query: exec %s -*** Caught Sybase Server Message #201 [Severity 16, state 2] at line 0 - %s -<<< Return: boolean -bool(false) ->>> Query: exec %s "foo" -*** Caught Sybase Server Message #257 [Severity 16, state 1] at line 0 - %s -<<< Return: boolean -bool(false) ->>> Query: exec does_not_exist -*** Caught Sybase Server Message #2812 [Severity 16, state %d] at line 1 - %s -<<< Return: boolean -bool(false) ->>> Query: exec %s NULL -<<< Return: resource -array(1) { - [0]=> - array(1) { - ["computed"]=> - NULL - } -} ->>> Query: exec %s 1 -<<< Return: resource -array(1) { - [0]=> - array(1) { - ["computed"]=> - int(1) - } -} -bool(true) diff --git a/ext/sybase_ct/tests/bug26407.phpt b/ext/sybase_ct/tests/bug26407.phpt deleted file mode 100644 index 27f5f99b9d1ff..0000000000000 --- a/ext/sybase_ct/tests/bug26407.phpt +++ /dev/null @@ -1,91 +0,0 @@ ---TEST-- -Sybase-CT bug #26407 (Result set fetching broken around transactions) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) ->>> Query: - begin transaction - -- anything producing a result set here will fail; - -- however, print or update statements will work - select "foo" - commit - -- anything afterwards will fail, too - -<<< Return: resource -array(1) { - [0]=> - array(1) { - ["computed"]=> - string(3) "foo" - } -} ->>> Query: - begin transaction - -- no result returned... - update #phpt_bug26407 set the_big_answer=42 - commit - -<<< Return: boolean -bool(true) ->>> Query: - select "foo" - begin transaction - -- do anything, even return a result set - commit - select "bar" - - -Notice: sybase_query(): Sybase: Unexpected results, canceling current in %stest.inc on line %d -<<< Return: resource -array(1) { - [0]=> - array(1) { - ["computed"]=> - string(3) "foo" - } -} diff --git a/ext/sybase_ct/tests/bug27843.phpt b/ext/sybase_ct/tests/bug27843.phpt deleted file mode 100644 index 861d1f95e7da3..0000000000000 --- a/ext/sybase_ct/tests/bug27843.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -Sybase-CT bug #27843 (notices when query is a stored procedure) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) -Stored procedure %s -bool(true) ->>> Query: exec phpt_bug27843 -<<< Return: resource -array(1) { - [0]=> - array(1) { - ["computed"]=> - int(1) - } -} -bool(true) diff --git a/ext/sybase_ct/tests/bug28354.phpt b/ext/sybase_ct/tests/bug28354.phpt deleted file mode 100644 index 018f7bddec6aa..0000000000000 --- a/ext/sybase_ct/tests/bug28354.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -Sybase-CT bug #28354 (sybase_free_result crash) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) -Stored procedure %s -bool(true) -int(0) -string(%d) "%s" diff --git a/ext/sybase_ct/tests/bug29064.phpt b/ext/sybase_ct/tests/bug29064.phpt deleted file mode 100644 index df13d28a1d8c7..0000000000000 --- a/ext/sybase_ct/tests/bug29064.phpt +++ /dev/null @@ -1,143 +0,0 @@ ---TEST-- -Sybase-CT bug #29064 (Exact numeric/decimal/money datatypes lose precision) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) -bool(true) -bool(true) ->>> Query: select * from #test -<<< Return: resource -array(2) { - [0]=> - array(10) { - ["test_decimal"]=> - string(39) "12345678901234567890123456789012.123456" - ["test_numeric"]=> - string(39) "12345678901234567890123456.123456789012" - ["test_money"]=> - string(18) "123456789012345.12" - ["test_bigint"]=> - string(38) "12345678901234567890123456789012345678" - ["test_int"]=> - int(1234567890) - ["test_smallmoney"]=> - float(123456.12) - ["test_smallint"]=> - int(12345) - ["test_tinyint"]=> - int(123) - ["test_real"]=> - string(18) "123456789.12345679" - ["test_double"]=> - string(18) "123456789.12345679" - } - [1]=> - array(10) { - ["test_decimal"]=> - string(40) "-12345678901234567890123456789012.123456" - ["test_numeric"]=> - string(40) "-12345678901234567890123456.123456789012" - ["test_money"]=> - string(19) "-123456789012345.12" - ["test_bigint"]=> - string(39) "-12345678901234567890123456789012345678" - ["test_int"]=> - int(-1234567890) - ["test_smallmoney"]=> - float(-123456.12) - ["test_smallint"]=> - int(-12345) - ["test_tinyint"]=> - int(255) - ["test_real"]=> - string(19) "-123456789.12345679" - ["test_double"]=> - string(19) "-123456789.12345679" - } -} -bool(true) diff --git a/ext/sybase_ct/tests/bug30312-withfree.phpt b/ext/sybase_ct/tests/bug30312-withfree.phpt deleted file mode 100644 index 0017865da424d..0000000000000 --- a/ext/sybase_ct/tests/bug30312-withfree.phpt +++ /dev/null @@ -1,34 +0,0 @@ ---TEST-- -Sybase-CT bug #30312 (sybase_unbuffered_query calls, with free) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -int(%d) -array(2) { - [0]=> - int(%d) - [1]=> - int(%d) -} diff --git a/ext/sybase_ct/tests/bug30312.phpt b/ext/sybase_ct/tests/bug30312.phpt deleted file mode 100644 index 273b579d610a4..0000000000000 --- a/ext/sybase_ct/tests/bug30312.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Sybase-CT bug #30312 (sybase_unbuffered_query calls) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -int(%d) -int(%d) diff --git a/ext/sybase_ct/tests/bug43578.phpt b/ext/sybase_ct/tests/bug43578.phpt deleted file mode 100644 index 9f75b9c0ea06d..0000000000000 --- a/ext/sybase_ct/tests/bug43578.phpt +++ /dev/null @@ -1,65 +0,0 @@ ---TEST-- -Sybase-CT bug #43578 (Incurred fault #6 - if returned textfield ist empty) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) -bool(true) -bool(true) ->>> Query: select DC_Rights from #Resource where Resource_ID = 122 -<<< Return: resource -array(0) { -} ->>> Query: select DC_Rights from #Resource where Resource_ID = 123 -<<< Return: resource -array(1) { - [0]=> - array(1) { - ["DC_Rights"]=> - NULL - } -} ->>> Query: select DC_Rights from #Resource where Resource_ID = 124 -<<< Return: resource -array(1) { - [0]=> - array(1) { - ["DC_Rights"]=> - string(1) " " - } -} -bool(true) diff --git a/ext/sybase_ct/tests/bug6339.phpt b/ext/sybase_ct/tests/bug6339.phpt deleted file mode 100644 index 3b0a072b4a10e..0000000000000 --- a/ext/sybase_ct/tests/bug6339.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Sybase-CT bug #6339 (invalid Sybase-link resource) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -array(1) { - [0]=> - int(1) -} diff --git a/ext/sybase_ct/tests/skipif.inc b/ext/sybase_ct/tests/skipif.inc deleted file mode 100644 index 55bf53aa7798a..0000000000000 --- a/ext/sybase_ct/tests/skipif.inc +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/ext/sybase_ct/tests/test.inc b/ext/sybase_ct/tests/test.inc deleted file mode 100644 index 8dd2f7fadfc62..0000000000000 --- a/ext/sybase_ct/tests/test.inc +++ /dev/null @@ -1,86 +0,0 @@ ->> Query: %s\n", $query); - $h= sybase_query($query, $dbh); - printf("<<< Return: %s\n", gettype($h)); - flush(); - if (!is_resource($h)) return $h; - - $return= array(); - while ($row= sybase_fetch_assoc($h)) { - $return[]= $row; - } - return $return; - } - - // {{{ mixed sybase_select_single(resource dbh, string query) - // Fires an SQL query and returns the first value from the first row - function sybase_select_single($dbh, $query) { - $a = sybase_fetch_row(sybase_query($query, $dbh)); - return array_shift($a); - } - // }}} -?> diff --git a/ext/sybase_ct/tests/test_appname.phpt b/ext/sybase_ct/tests/test_appname.phpt deleted file mode 100644 index 71f5c32f4de84..0000000000000 --- a/ext/sybase_ct/tests/test_appname.phpt +++ /dev/null @@ -1,55 +0,0 @@ ---TEST-- -Sybase-CT application name ---SKIPIF-- - ---FILE-- - ---EXPECTF-- ->>> Query: - select - hostname, - program_name - from - master..sysprocesses - where - program_name = "phpt_test" -<<< Return: resource -bool(true) -bool(true) diff --git a/ext/sybase_ct/tests/test_close.phpt b/ext/sybase_ct/tests/test_close.phpt deleted file mode 100644 index e2c3ebcb60eb3..0000000000000 --- a/ext/sybase_ct/tests/test_close.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Sybase-CT close ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -resource(%d) of type (sybase-ct link) -resource(%d) of type (Unknown) - -Warning: sybase_query(): %d is not a valid Sybase-Link resource in %s on line %d -bool(false) diff --git a/ext/sybase_ct/tests/test_close_default.phpt b/ext/sybase_ct/tests/test_close_default.phpt deleted file mode 100644 index a726a4747b7ad..0000000000000 --- a/ext/sybase_ct/tests/test_close_default.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Sybase-CT close default connection ---SKIPIF-- - ---FILE-- - ---EXPECTF-- - -Warning: sybase_query(): Sybase: No connection in %s on line %d -bool(false) diff --git a/ext/sybase_ct/tests/test_close_notopen.phpt b/ext/sybase_ct/tests/test_close_notopen.phpt deleted file mode 100644 index 13b4571bc9ac2..0000000000000 --- a/ext/sybase_ct/tests/test_close_notopen.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Sybase-CT close not open ---SKIPIF-- - ---FILE-- - ---EXPECTF-- - -Warning: sybase_close(): Sybase: No connection to close in %s on line %d diff --git a/ext/sybase_ct/tests/test_connect.phpt b/ext/sybase_ct/tests/test_connect.phpt deleted file mode 100644 index e1e3eead389cc..0000000000000 --- a/ext/sybase_ct/tests/test_connect.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Sybase-CT connectivity ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -resource(%d) of type (sybase-ct link) diff --git a/ext/sybase_ct/tests/test_connection_caching.phpt b/ext/sybase_ct/tests/test_connection_caching.phpt deleted file mode 100644 index d59aedebf6ddf..0000000000000 --- a/ext/sybase_ct/tests/test_connection_caching.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Sybase-CT connection caching ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -resource(%d) of type (sybase-ct link) -resource(%d) of type (sybase-ct link) -resource(%d) of type (sybase-ct link) -bool(true) -bool(false) diff --git a/ext/sybase_ct/tests/test_connectionbased_msghandler.phpt b/ext/sybase_ct/tests/test_connectionbased_msghandler.phpt deleted file mode 100644 index 72e6b3a8dc12b..0000000000000 --- a/ext/sybase_ct/tests/test_connectionbased_msghandler.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Sybase-CT connection-based server message handler ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -resource(%d) of type (sybase-ct link) -bool(true) ->>> Query: select getdate(NULL) -*** Caught Sybase Server Message #%d [Severity %d, state %d] at line %d - %s -<<< Return: boolean -bool(false) diff --git a/ext/sybase_ct/tests/test_fetch_object.phpt b/ext/sybase_ct/tests/test_fetch_object.phpt deleted file mode 100644 index 2d225cd9cf445..0000000000000 --- a/ext/sybase_ct/tests/test_fetch_object.phpt +++ /dev/null @@ -1,74 +0,0 @@ ---TEST-- -Sybase-CT sybase_fetch_object ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -stdClass::__set_state(array( - 'id' => 1, - 'caption' => 'Hello', - 'author' => 'timm', - 'lastchange' => '%s', -)) -article::__set_state(array( - 'id' => 1, - 'caption' => 'Hello', - 'author' => 'timm', - 'lastchange' => '%s', -)) -article::__set_state(array( - 'id' => 1, - 'caption' => 'Hello', - 'author' => 'timm', - 'lastchange' => '%s', -)) - -Notice: sybase_fetch_object(): Sybase: Class *** has not been declared in %stest_fetch_object.php on line %d -stdClass::__set_state(array( - 'id' => 1, - 'caption' => 'Hello', - 'author' => 'timm', - 'lastchange' => '%s', -)) diff --git a/ext/sybase_ct/tests/test_fields.phpt b/ext/sybase_ct/tests/test_fields.phpt deleted file mode 100644 index 46e932b85d50f..0000000000000 --- a/ext/sybase_ct/tests/test_fields.phpt +++ /dev/null @@ -1,76 +0,0 @@ ---TEST-- -Sybase-CT sybase_field_* functions ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -resource(%d) of type (sybase-ct result) -int(4) -stdClass::__set_state(array( - 'name' => 'id', - 'max_length' => 11, - 'column_source' => '', - 'numeric' => 1, - 'type' => 'int', -)) -stdClass::__set_state(array( - 'name' => 'caption', - 'max_length' => 5, - 'column_source' => '', - 'numeric' => 0, - 'type' => 'string', -)) -stdClass::__set_state(array( - 'name' => 'author', - 'max_length' => 4, - 'column_source' => '', - 'numeric' => 0, - 'type' => 'string', -)) -stdClass::__set_state(array( - 'name' => 'lastchange', - 'max_length' => 29, - 'column_source' => '', - 'numeric' => 0, - 'type' => 'datetime', -)) -bool(true) -stdClass::__set_state(array( - 'name' => 'caption', - 'max_length' => 5, - 'column_source' => '', - 'numeric' => 0, - 'type' => 'string', -)) diff --git a/ext/sybase_ct/tests/test_long.phpt b/ext/sybase_ct/tests/test_long.phpt deleted file mode 100644 index de59bb93cbdf0..0000000000000 --- a/ext/sybase_ct/tests/test_long.phpt +++ /dev/null @@ -1,80 +0,0 @@ ---TEST-- -Sybase-CT select LONG_MAX / LONG_MIN ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) ->>> Query: select value from test_long -<<< Return: resource -array(6) { - [0]=> - array(1) { - ["value"]=> - int(%s) - } - [1]=> - array(1) { - ["value"]=> - int(%s) - } - [2]=> - array(1) { - ["value"]=> - float(%s) - } - [3]=> - array(1) { - ["value"]=> - int(-%s) - } - [4]=> - array(1) { - ["value"]=> - int(-%s) - } - [5]=> - array(1) { - ["value"]=> - float(-%s) - } -} -bool(true) diff --git a/ext/sybase_ct/tests/test_msghandler.phpt b/ext/sybase_ct/tests/test_msghandler.phpt deleted file mode 100644 index 3189aaac210bb..0000000000000 --- a/ext/sybase_ct/tests/test_msghandler.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -Sybase-CT server message handler ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Nonexistent: -Warning: sybase_set_message_handler() expects parameter 1 to be a valid callback, function 'function_does_not_exist' not found or invalid function name in %stest.inc on line %d -NULL -Static method: bool(true) -Instance method: bool(true) -Lambda function: bool(true) -Unset: bool(true) -Incorrect type: -Warning: sybase_set_message_handler() expects parameter 1 to be a valid callback, no array or string given in %stest.inc on line %d -NULL -Function: bool(true) ->>> Query: select getdate(NULL) -*** Caught Sybase Server Message #%d [Severity %d, state %d] at line %d - %s -<<< Return: boolean -bool(false) diff --git a/ext/sybase_ct/tests/test_msghandler_handled.phpt b/ext/sybase_ct/tests/test_msghandler_handled.phpt deleted file mode 100644 index 5952c3b00b6e5..0000000000000 --- a/ext/sybase_ct/tests/test_msghandler_handled.phpt +++ /dev/null @@ -1,69 +0,0 @@ ---TEST-- -Sybase-CT server message handler ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) ->>> Query: select getdate(NULL) -*** Caught '%s' -<<< Return: boolean -bool(false) ->>> Query: print "Hi" -!!! Hi -<<< Return: boolean -bool(true) ->>> Query: use NULL -Cannot handle message #156 - -Warning: sybase_query(): Sybase: Server message: Incorrect syntax near the keyword 'NULL'. - (severity 15, procedure N/A) in %s on line %d -<<< Return: boolean -bool(false) ->>> Query: select convert(datetime, "notadate") -Cannot handle message #249 - -Warning: sybase_query(): Sybase: Server message: Syntax error during explicit conversion of VARCHAR value 'notadate' to a DATETIME field. - (severity 16, procedure N/A) in %s on line %d -<<< Return: boolean -bool(false) diff --git a/ext/sybase_ct/tests/test_query_nostore.phpt b/ext/sybase_ct/tests/test_query_nostore.phpt deleted file mode 100644 index 9d717ec2fd64a..0000000000000 --- a/ext/sybase_ct/tests/test_query_nostore.phpt +++ /dev/null @@ -1,98 +0,0 @@ ---TEST-- -Sybase-CT query without storing ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -bool(true) -bool(true) -bool(true) -bool(true) -resource(%d) of type (sybase-ct result) -array(5) { - ["id"]=> - int(1) - ["caption"]=> - string(5) "Hello" - ["author"]=> - string(4) "timm" - ["link"]=> - NULL - ["lastchange"]=> - string(%d) "%s" -} -array(5) { - ["id"]=> - int(2) - ["caption"]=> - string(5) "World" - ["author"]=> - string(6) "thekid" - ["link"]=> - string(17) "http://thekid.de/" - ["lastchange"]=> - string(%d) "%s" -} -array(5) { - ["id"]=> - int(3) - ["caption"]=> - string(3) "PHP" - ["author"]=> - string(6) "friebe" - ["link"]=> - NULL - ["lastchange"]=> - string(%d) "%s" -} -bool(true) diff --git a/ext/sybase_ct/tests/test_types.phpt b/ext/sybase_ct/tests/test_types.phpt deleted file mode 100644 index 735c02d8437a4..0000000000000 --- a/ext/sybase_ct/tests/test_types.phpt +++ /dev/null @@ -1,87 +0,0 @@ ---TEST-- -Sybase-CT select and types ---SKIPIF-- - ---FILE-- - ---EXPECTF-- ->>> Query: select - 1 as "integer", - -%s as "integer_min", - -%s as "integer_min_exceed", - %s as "integer_max", - %s as "integer_max_exceed", - 1.0 as "float", - 12345678901234567890123456789012.123456 as "large_float", - $22.36 as "money", - "Binford" as "string", - convert(datetime, "2004-01-23") as "date", - NULL as "null", - convert(bit, 1) as "bit", - convert(smalldatetime, "2004-01-23") as "smalldate", - convert(char(10), "char") as "char10" - -<<< Return: resource -array(1) { - [0]=> - array(%d) { - ["integer"]=> - int(1) - ["integer_min"]=> - int(-%s) - ["integer_min_exceed"]=> - float(-%s) - ["integer_max"]=> - int(%s) - ["integer_max_exceed"]=> - float(%s) - ["float"]=> - float(1) - ["large_float"]=> - string(39) "12345678901234567890123456789012.123456" - ["money"]=> - float(22.36) - ["string"]=> - string(7) "Binford" - ["date"]=> - string(19) "Jan 23 2004 12:00AM" - ["null"]=> - NULL - ["bit"]=> - int(1) - ["smalldate"]=> - string(19) "Jan 23 2004 12:00AM" - ["char10"]=> - string(10) "char " - } -} diff --git a/ext/sybase_ct/tests/test_unbuffered_no_full_fetch.phpt b/ext/sybase_ct/tests/test_unbuffered_no_full_fetch.phpt deleted file mode 100644 index 5faf8fe4ded6e..0000000000000 --- a/ext/sybase_ct/tests/test_unbuffered_no_full_fetch.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -Sybase-CT unbuffered query without full fetching ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -resource(%d) of type (sybase-ct link) -resource(%d) of type (sybase-ct result) -string(4) "name" - -Notice: sybase_unbuffered_query(): Sybase: Called without first fetching all rows from a previous unbuffered query in %s on line %d -resource(%d) of type (sybase-ct result) -string(4) "name" -resource(%d) of type (sybase-ct result) -string(4) "name" -CLOSED diff --git a/ext/sybase_ct/tests/test_unbuffered_query.phpt b/ext/sybase_ct/tests/test_unbuffered_query.phpt deleted file mode 100644 index b2be2f2304bf5..0000000000000 --- a/ext/sybase_ct/tests/test_unbuffered_query.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -Sybase-CT unbuffered query ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -resource(%d) of type (sybase-ct link) -resource(%d) of type (sybase-ct result) -int(%d) -int(%d) -bool(true) -resource(%d) of type (sybase-ct result) -resource(%d) of type (Unknown) - -Warning: sybase_num_rows(): %d is not a valid Sybase result resource in %stest_unbuffered_query.php on line %d -bool(true) -resource(%d) of type (sybase-ct result) -int(%d) -int(%d) -int(4) diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index 5eeb3ca4ed794..5eccbedc32915 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -936,7 +936,7 @@ static void *php_tidy_get_opt_val(PHPTidyDoc *ptdoc, TidyOption opt, TidyOptionT break; case TidyInteger: - return (void *) tidyOptGetInt(ptdoc->doc, tidyOptGetId(opt)); + return (void *) (uintptr_t) tidyOptGetInt(ptdoc->doc, tidyOptGetId(opt)); break; case TidyBoolean: diff --git a/main/output.c b/main/output.c index 50d4e5f1b3d46..09f8c9df6e471 100644 --- a/main/output.c +++ b/main/output.c @@ -545,7 +545,6 @@ PHPAPI void php_output_handler_set_context(php_output_handler *handler, void *op * Starts the set up output handler and pushes it on top of the stack. Checks for any conflicts regarding the output handler to start */ PHPAPI int php_output_handler_start(php_output_handler *handler) { - HashPosition pos; HashTable *rconflicts; php_output_handler_conflict_check_t conflict; @@ -558,14 +557,11 @@ PHPAPI int php_output_handler_start(php_output_handler *handler) } } if (NULL != (rconflicts = zend_hash_find_ptr(&php_output_handler_reverse_conflicts, handler->name))) { - for (zend_hash_internal_pointer_reset_ex(rconflicts, &pos); - (conflict = zend_hash_get_current_data_ptr_ex(rconflicts, &pos)) != NULL; - zend_hash_move_forward_ex(rconflicts, &pos) - ) { + ZEND_HASH_FOREACH_PTR(rconflicts, conflict) { if (SUCCESS != conflict(handler->name->val, handler->name->len)) { return FAILURE; } - } + } ZEND_HASH_FOREACH_END(); } /* zend_stack_push returns stack level */ handler->level = zend_stack_push(&OG(handlers), &handler); diff --git a/main/php_ini.c b/main/php_ini.c index 5703d1fc0df99..9c16aa327d2cf 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -782,16 +782,11 @@ PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int { zend_string *str; zval *data; - zend_ulong num_index; /* Walk through config hash and alter matching ini entries using the values found in the hash */ - for (zend_hash_internal_pointer_reset(source_hash); - zend_hash_get_current_key(source_hash, &str, &num_index) == HASH_KEY_IS_STRING; - zend_hash_move_forward(source_hash) - ) { - data = zend_hash_get_current_data(source_hash); + ZEND_HASH_FOREACH_STR_KEY_VAL(source_hash, str, data) { zend_alter_ini_entry_ex(str, Z_STR_P(data), modify_type, stage, 0); - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ diff --git a/main/streams/streams.c b/main/streams/streams.c index f1008a6631da8..7821c44c2ebb0 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -123,28 +123,21 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream * if ((le = zend_hash_str_find_ptr(&EG(persistent_list), persistent_id, strlen(persistent_id))) != NULL) { if (le->type == le_pstream) { if (stream) { - HashPosition pos; - zend_resource *regentry; + zend_resource *regentry = NULL; /* see if this persistent resource already has been loaded to the * regular list; allowing the same resource in several entries in the * regular list causes trouble (see bug #54623) */ - zend_hash_internal_pointer_reset_ex(&EG(regular_list), &pos); - while ((regentry = zend_hash_get_current_data_ptr_ex(&EG(regular_list), &pos)) != NULL) { + *stream = (php_stream*)le->ptr; + ZEND_HASH_FOREACH_PTR(&EG(regular_list), regentry) { if (regentry->ptr == le->ptr) { - break; + GC_REFCOUNT(regentry)++; + (*stream)->res = regentry; + return PHP_STREAM_PERSISTENT_SUCCESS; } - zend_hash_move_forward_ex(&EG(regular_list), &pos); - } - - *stream = (php_stream*)le->ptr; - if (!regentry) { /* not found in regular list */ - GC_REFCOUNT(le)++; - (*stream)->res = zend_register_resource(*stream, le_pstream); - } else { - GC_REFCOUNT(regentry)++; - (*stream)->res = regentry; - } + } ZEND_HASH_FOREACH_END(); + GC_REFCOUNT(le)++; + (*stream)->res = zend_register_resource(*stream, le_pstream); } return PHP_STREAM_PERSISTENT_SUCCESS; } diff --git a/pear/install-pear-nozlib.phar b/pear/install-pear-nozlib.phar index 0cab736063aae..f018d863ed8aa 100644 --- a/pear/install-pear-nozlib.phar +++ b/pear/install-pear-nozlib.phar @@ -1234,11 +1234,9 @@ if (extension_loaded('phar')) {if (isset($_SERVER) && isset($_SERVER['REQUEST_UR require_once 'phar://install-pear-nozlib.phar/index.php'; -__HALT_COMPILER();Finstall-pear-nozlib.pharArchive/Tar.phpº>‹ÅTº>ÌugmArchive_Tar-1.3.13.tarÆ‹ÅTÆø¥õ~mConsole/Getopt.phpÂ4‹ÅTÂ4èÌl1mConsole_Getopt-1.3.1.tarT‹ÅTTΞm index.php&‹ÅT&ˆþm OS/Guess.php“)‹ÅT“) £]ÞmPEAR-1.9.5.tar‹ÅTöxw*mPEAR.php†„‹ÅT†„´Ž2³mPEAR/ChannelFile.phpºÇ‹ÅTºÇo|œºmPEAR/ChannelFile/Parser.php ‹ÅT &K}8mPEAR/Command.phpÚ1‹ÅTÚ1Ñ6)ðmPEAR/Command/Common.phpZ ‹ÅTZ k˾7mPEAR/Command/Install.php—È‹ÅT—È´?¥DmPEAR/Command/Install.xml~!‹ÅT~!2¡VmPEAR/Common.phpðe‹ÅTðen;+mPEAR/Config.php” -‹ÅT” -6… mPEAR/Dependency2.phpÖÅ‹ÅTÖÅmèFmPEAR/DependencyDB.phpï_‹ÅTï_âƒ~3mPEAR/Downloader.phpì‹ÅTìŸJòmPEAR/Downloader/Package.phpy*‹ÅTy*žãñmPEAR/ErrorStack.phph„‹ÅTh„l­‹zmPEAR/Frontend.php3‹ÅT3\¡mPEAR/Frontend/CLI.php‡d‹ÅT‡d¹Z ÙmPEAR/Installer.phpv‹ÅTvuamPEAR/Installer/Role.phpv‹ÅTvú\mPEAR/Installer/Role/Common.phpl‹ÅTl‚ÞöúmPEAR/Installer/Role/Data.php&‹ÅT&žÕï©mPEAR/Installer/Role/Data.xml’‹ÅT’fszmPEAR/Installer/Role/Doc.php$‹ÅT$4DmPEAR/Installer/Role/Doc.xml‘‹ÅT‘h&P*mPEAR/Installer/Role/Php.php$‹ÅT$çÒ_×mPEAR/Installer/Role/Php.xml­‹ÅT­zqmPEAR/Installer/Role/Script.php*‹ÅT*ôxx’mPEAR/Installer/Role/Script.xml°‹ÅT°@v§ÐmPEAR/Installer/Role/Test.php&‹ÅT&M.mPEAR/Installer/Role/Test.xml’‹ÅT’B] mPEAR/PackageFile.php²>‹ÅT²>b7œm!PEAR/PackageFile/Generator/v1.phpKÅ‹ÅTKÅöy|üm!PEAR/PackageFile/Generator/v2.php6ƒ‹ÅT6ƒÿVeÐmPEAR/PackageFile/Parser/v1.phpÁ@‹ÅTÁ@a¹îmPEAR/PackageFile/Parser/v2.php§ ‹ÅT§ É¥såmPEAR/PackageFile/v1.php4È‹ÅT4ÈcFÎymPEAR/PackageFile/v2.phpD‹ÅTD¯AUm!PEAR/PackageFile/v2/Validator.phpQP‹ÅTQPŒCmPEAR/Registry.phpÉ,‹ÅTÉ,l˜‚m PEAR/REST.phpE‹ÅTE0A!mPEAR/REST/10.php€‹ÅT€fyµmPEAR/Start.php:9‹ÅT:9­0o?mPEAR/Start/CLI.phpUS‹ÅTUSoFfÍmPEAR/Task/Common.phpÔ‹ÅTÔÀ65mPEAR/Task/Postinstallscript.phpb8‹ÅTb8}ÈQ„m"PEAR/Task/Postinstallscript/rw.phpËÅTÃá@ʵmPEAR/Task/Replace.php‹ÅTÿ3mPEAR/Task/Replace/rw.phpG‹ÅTGz80ÓmPEAR/Task/Unixeol.phpÖ‹ÅTÖ¤]mPEAR/Task/Unixeol/rw.phpW‹ÅTWõ&ímPEAR/Task/Windowseol.phpÏ‹ÅTÏÅT¬ümPEAR/Task/Windowseol/rw.phpl‹ÅTlÏJLŠmPEAR/Validate.phpFV‹ÅTFVºã0ómPEAR/Validator/PECL.phpu‹ÅTuÂÃfmPEAR/XMLParser.php‹ÅT -0¤/m PEAR5.php?‹ÅT?ßxÊmStructures/Graph.php½‹ÅT½r À*m,Structures/Graph/Manipulator/AcyclicTest.phpß‹ÅTß1sÏm2Structures/Graph/Manipulator/TopologicalSorter.phpº‹ÅTº¥EûmStructures/Graph/Node.phpr+‹ÅTr+ûD_mStructures_Graph-1.0.4.tar,‹ÅT,‰”f‘m -System.php«Q‹ÅT«Që Öm XML/Util.phpv‹ÅTv‡f„mXML_Util-1.2.3.tarÞ‹ÅTÞO}ð!mVÏÙTº>ÌugmArchive_Tar-1.3.13.tarÆVÏÙTÆø¥õ~mConsole/Getopt.phpÂ4VÏÙTÂ4èÌl1mConsole_Getopt-1.3.1.tarTVÏÙTTΞm index.php&VÏÙT&RÆ8am OS/Guess.php“)VÏÙT“) £]ÞmPEAR-1.9.5.tarVÏÙTnb6dmPEAR.php†„VÏÙT†„´Ž2³mPEAR/ChannelFile.phpµÇVÏÙTµÇFiYýmPEAR/ChannelFile/Parser.php VÏÙT &K}8mPEAR/Command.phpØ1VÏÙTØ1KûjtmPEAR/Command/Common.phpZ VÏÙTZ k˾7mPEAR/Command/Install.php”ÈVÏÙT”ÈVÏÙT²>b7œm!PEAR/PackageFile/Generator/v1.phpJÅVÏÙTJÅš9R]m!PEAR/PackageFile/Generator/v2.php4ƒVÏÙT4ƒ¥@;mPEAR/PackageFile/Parser/v1.phpÁ@VÏÙTÁ@a¹îmPEAR/PackageFile/Parser/v2.php§ VÏÙT§ É¥såmPEAR/PackageFile/v1.php1ÈVÏÙT1È÷dg»mPEAR/PackageFile/v2.php>VÏÙT> þÛm!PEAR/PackageFile/v2/Validator.php…PVÏÙT…PÌRrÁmPEAR/Registry.php¢)VÏÙT¢)ÏUþûm PEAR/REST.phpEVÏÙTE0A!mPEAR/REST/10.php€VÏÙT€>oNmPEAR/Start.php:9VÏÙT:9­0o?mPEAR/Start/CLI.phpUSVÏÙTUSoFfÍmPEAR/Task/Common.phpÔVÏÙTÔÀ65mPEAR/Task/Postinstallscript.phpb8VÏÙTb8}ÈQ„m"PEAR/Task/Postinstallscript/rw.phpÃVÏÙTÃá@ʵmPEAR/Task/Replace.phpVÏÙTÿ3mPEAR/Task/Replace/rw.phpGVÏÙTGz80ÓmPEAR/Task/Unixeol.phpÖVÏÙTÖ¤]mPEAR/Task/Unixeol/rw.phpWVÏÙTWõ&ímPEAR/Task/Windowseol.phpÏVÏÙTÏÅT¬ümPEAR/Task/Windowseol/rw.phplVÏÙTlÏJLŠmPEAR/Validate.phpFVVÏÙTFVºã0ómPEAR/Validator/PECL.phpuVÏÙTuÂÃfmPEAR/XMLParser.phpVÏÙT +0¤/m PEAR5.php?VÏÙT?ßxÊmStructures/Graph.php½VÏÙT½r À*m,Structures/Graph/Manipulator/AcyclicTest.phpßVÏÙTß1sÏm2Structures/Graph/Manipulator/TopologicalSorter.phpºVÏÙTº¥EûmStructures/Graph/Node.phpr+VÏÙTr+ûD_mStructures_Graph-1.0.4.tar,VÏÙT,‰”f‘m +System.php«QVÏÙT«Që Öm XML/Util.phpvVÏÙTv‡f„mXML_Util-1.2.3.tarÞVÏÙTÞO}ð!mgetRegistry('default'); } @@ -8557,7 +8555,7 @@ class OS_Guess * indent-tabs-mode: nil * c-basic-offset: 4 * End: - */package.xml0000644000076500000240000014160512461216534012371 0ustar tyraelstaff + */package.xml0000644000076500000240000014127412466347403012400 0ustar tyraelstaff PEAR pear.php.net @@ -8646,8 +8644,8 @@ class OS_Guess mj@php.net no - 2015-01-25 - + 2015-02-10 + 1.9.5 1.9.5 @@ -8690,7 +8688,7 @@ Bug fixes in 1.9.5.dev1: - + @@ -8701,11 +8699,11 @@ Bug fixes in 1.9.5.dev1: - + - + @@ -8713,27 +8711,27 @@ Bug fixes in 1.9.5.dev1: - + - + - + - + - + - + @@ -8781,10 +8779,10 @@ Bug fixes in 1.9.5.dev1: - + - + @@ -8793,22 +8791,22 @@ Bug fixes in 1.9.5.dev1: - + - + - + - + - + - + @@ -8844,31 +8842,31 @@ Bug fixes in 1.9.5.dev1: - + - + - + - + - + - + - + - + - + @@ -8877,26 +8875,26 @@ Bug fixes in 1.9.5.dev1: - - + + - + - + - + - + @@ -8944,7 +8942,7 @@ Bug fixes in 1.9.5.dev1: - + @@ -8963,7 +8961,7 @@ Bug fixes in 1.9.5.dev1: - + @@ -8973,14 +8971,7 @@ Bug fixes in 1.9.5.dev1: - 4.4.0 - 5.0 - 5.1.0 - 5.1.1 - 5.1.2 - 5.1.3 - 5.1.4 - 5.1.5 + 5.4.0 1.4.3 @@ -9555,7 +9546,7 @@ Bug fixes in 1.9.5.dev1: -PEAR-1.9.5/OS/Guess.php0000644000076500000240000002455612461216534013600 0ustar tyraelstaffsetPackagefile($file, $archive); return $ret; } -}PEAR-1.9.5/PEAR/Command/Auth.xml0000644000076500000240000000231412461216534015174 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Auth.xml0000644000076500000240000000231412466347403015201 0ustar tyraelstaff Connects and authenticates to remote server [Deprecated in favor of channel-login] doLogin @@ -9988,7 +9979,7 @@ Logs out from the remote server. This command does not actually connect to the remote server, it only deletes the stored username and password from your user configuration. -PEAR-1.9.5/PEAR/Command/Auth.php0000644000076500000240000000506112461216534015165 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Auth.php0000644000076500000240000000506112466347403015172 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Build.xml0000644000076500000240000000040412466347403015335 0ustar tyraelstaff Build an Extension From C Source doBuild @@ -10077,7 +10068,7 @@ password from your user configuration.', [package.xml] Builds one or more extensions contained in a package. -PEAR-1.9.5/PEAR/Command/Build.php0000644000076500000240000000437512461216534015332 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Build.php0000644000076500000240000000437412466347403015336 0ustar tyraelstaffui); + $builder = new PEAR_Builder($this->ui); $this->debug = $this->config->get('verbose'); $err = $builder->build($params[0], array(&$this, 'buildCallback')); if (PEAR::isError($err)) { @@ -10161,7 +10152,7 @@ Builds one or more extensions contained in a package.' $this->ui->outputData(rtrim($data), 'build'); } } -}PEAR-1.9.5/PEAR/Command/Channels.xml0000644000076500000240000001017212461216534016027 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Channels.xml0000644000076500000240000001017212466347403016034 0ustar tyraelstaff List Available Channels doList @@ -10283,7 +10274,7 @@ the default channel is used. This command does not actually connect to the remote server, it only deletes the stored username and password from your user configuration. -PEAR-1.9.5/PEAR/Command/Channels.php0000644000076500000240000010131612461216534016017 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Channels.php0000644000076500000240000010131612466347403016024 0ustar tyraelstaffconfig->store(); return true; } -}PEAR-1.9.5/PEAR/Command/Common.php0000644000076500000240000002006512461216534015515 0ustar tyraelstaff$func($command, $options, $params); } -}PEAR-1.9.5/PEAR/Command/Config.xml0000644000076500000240000000646612461216534015514 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Config.xml0000644000076500000240000000646612466347403015521 0ustar tyraelstaff Show All Settings doConfigShow @@ -11528,7 +11519,7 @@ PEAR installation (using the --remoteconfig option of install, upgrade, and uninstall). -PEAR-1.9.5/PEAR/Command/Config.php0000644000076500000240000003607712461216534015504 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Config.php0000644000076500000240000003607612466347403015510 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Install.xml0000644000076500000240000002057612466347403015720 0ustar tyraelstaff Install Package doInstall @@ -12216,7 +12207,7 @@ package if needed. Run post-installation scripts in package <package>, if any exist. -PEAR-1.9.5/PEAR/Command/Install.php0000644000076500000240000014400312461216534015672 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Install.php0000644000076500000240000014400012466347403015674 0ustar tyraelstaff, if any exist. if (!class_exists('PEAR_Downloader')) { require_once 'PEAR/Downloader.php'; } - $a = &new PEAR_Downloader($ui, $options, $config); + $a = new PEAR_Downloader($ui, $options, $config); return $a; } @@ -12558,7 +12549,7 @@ Run post-installation scripts in package , if any exist. if (!class_exists('PEAR_Installer')) { require_once 'PEAR/Installer.php'; } - $a = &new PEAR_Installer($ui); + $a = new PEAR_Installer($ui); return $a; } @@ -13361,7 +13352,7 @@ Run post-installation scripts in package , if any exist. $dest .= DIRECTORY_SEPARATOR . $pkgname; $orig = $pkgname . '-' . $pkgversion; - $tar = &new Archive_Tar($pkgfile->getArchiveFile()); + $tar = new Archive_Tar($pkgfile->getArchiveFile()); if (!$tar->extractModify($dest, $orig)) { return $this->raiseError('unable to unpack ' . $pkgfile->getArchiveFile()); } @@ -13491,7 +13482,7 @@ Run post-installation scripts in package , if any exist. return $ret; } } -PEAR-1.9.5/PEAR/Command/Mirror.xml0000644000076500000240000000115112461216534015543 0ustar tyraelstaff +PEAR-1.9.5/PEAR/Command/Mirror.xml0000644000076500000240000000115112466347403015550 0ustar tyraelstaff Downloads each available package from the default channel doDownloadAll @@ -13508,7 +13499,7 @@ Requests a list of available packages from the default channel ({config default_ and downloads them to current working directory. Note: only packages within preferred_state ({config preferred_state}) will be downloaded -PEAR-1.9.5/PEAR/Command/Mirror.php0000644000076500000240000001070412461216534015536 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Mirror.php0000644000076500000240000001070412466347403015543 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Package.xml0000644000076500000240000001606612466347403015644 0ustar tyraelstaff Build Package doPackage @@ -13882,7 +13873,7 @@ This is not the most intelligent conversion, and should only be used for automated conversion or learning the format. -PEAR-1.9.5/PEAR/Command/Package.php0000644000076500000240000011644512461216534015630 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Package.php0000644000076500000240000011644012466347403015630 0ustar tyraelstaffui = $this->ui; $a->setLogger($common); @@ -14256,7 +14247,7 @@ used for automated conversion or learning the format. $info = $obj->fromPackageFile($params[0], PEAR_VALIDATE_NORMAL); } else { $archive = $info->getArchiveFile(); - $tar = &new Archive_Tar($archive); + $tar = new Archive_Tar($archive); $tar->extract(dirname($info->getPackageFile())); $info->setPackageFile(dirname($info->getPackageFile()) . DIRECTORY_SEPARATOR . $info->getPackage() . '-' . $info->getVersion() . DIRECTORY_SEPARATOR . @@ -14915,7 +14906,7 @@ used for automated conversion or learning the format. if (!class_exists('PEAR_Installer')) { require_once 'PEAR/Installer.php'; } - $a = &new PEAR_Installer($ui); + $a = new PEAR_Installer($ui); return $a; } @@ -14932,7 +14923,7 @@ used for automated conversion or learning the format. } if (class_exists('PEAR_Command_Packaging')) { - $a = &new PEAR_Command_Packaging($ui, $config); + $a = new PEAR_Command_Packaging($ui, $config); } else { $a = null; } @@ -15006,7 +14997,7 @@ used for automated conversion or learning the format. return true; } } -PEAR-1.9.5/PEAR/Command/Pickle.xml0000644000076500000240000000223312461216534015502 0ustar tyraelstaff +PEAR-1.9.5/PEAR/Command/Pickle.xml0000644000076500000240000000223312466347403015507 0ustar tyraelstaff Build PECL Package doPackage @@ -15041,7 +15032,7 @@ uses any of these features, you are best off using PEAR_PackageFileManager to generate both package.xml. -PEAR-1.9.5/PEAR/Command/Pickle.php0000644000076500000240000003707712461216534015507 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Pickle.php0000644000076500000240000003707512466347403015512 0ustar tyraelstaffui = $this->ui; $a->setLogger($common); @@ -15461,7 +15452,7 @@ generate both package.xml. $gen = &$pf->getDefaultGenerator(); $gen->toPackageFile('.'); } -}PEAR-1.9.5/PEAR/Command/Registry.xml0000644000076500000240000000337612461216534016114 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Registry.xml0000644000076500000240000000337612466347403016121 0ustar tyraelstaff List Installed Packages In The Default Channel doList @@ -15518,7 +15509,7 @@ Displays information about a package. The package argument may be a local package file, an URL to a package file, or the name of an installed package. -PEAR-1.9.5/PEAR/Command/Registry.php0000644000076500000240000013233512461216534016101 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Registry.php0000644000076500000240000013233312466347403016104 0ustar tyraelstaffconfig, $this->_debug); + $pkg = new PEAR_PackageFile($this->config, $this->_debug); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); @@ -15955,7 +15946,7 @@ installed package.' require_once 'PEAR/PackageFile.php'; } - $pkg = &new PEAR_PackageFile($this->config, $this->_debug); + $pkg = new PEAR_PackageFile($this->config, $this->_debug); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); @@ -16662,7 +16653,7 @@ installed package.' $data['raw'] = $obj->getArray(); // no validation needed $this->ui->outputData($data, 'package-info'); } -}PEAR-1.9.5/PEAR/Command/Remote.xml0000644000076500000240000000635712461216534015541 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Remote.xml0000644000076500000240000000635712466347403015546 0ustar tyraelstaff Information About Remote Packages doRemoteInfo @@ -16770,7 +16761,7 @@ Clear the XML-RPC/REST cache. See also the cache_ttl configuration parameter. -PEAR-1.9.5/PEAR/Command/Remote.php0000644000076500000240000007250712461216534015530 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Remote.php0000644000076500000240000007250612466347403015534 0ustar tyraelstaffui, $options, $this->config); + $a = new PEAR_Downloader($this->ui, $options, $this->config); return $a; } @@ -17579,7 +17570,7 @@ parameter. $this->ui->outputData(rtrim($output), $command); return $num; } -}PEAR-1.9.5/PEAR/Command/Test.xml0000644000076500000240000000315112461216534015212 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Command/Test.xml0000644000076500000240000000315112466347403015217 0ustar tyraelstaff Run Regression Tests doRunTests @@ -17632,7 +17623,7 @@ If none is found, all .phpt tests will be tried instead. [testfile|dir ...] Run regression tests with PHP's regression testing script (run-tests.php). -PEAR-1.9.5/PEAR/Command/Test.php0000644000076500000240000002723012461216534015205 0ustar tyraelstaffPEAR-1.9.5/PEAR/Command/Test.php0000644000076500000240000002736112466347403015217 0ustar tyraelstaffraiseError('Some tests failed'); } -}PEAR-1.9.5/PEAR/Downloader/Package.php0000644000076500000240000022456612461216534016354 0ustar tyraelstaffsetExplicitState($s); } - $obj = &new PEAR_Downloader_Package($params[$i]->getDownloader()); + $obj = new PEAR_Downloader_Package($params[$i]->getDownloader()); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); if (PEAR::isError($dir = $dl->getDownloadDir())) { PEAR::popErrorHandling(); @@ -19370,10 +19364,9 @@ class PEAR_Downloader_Package continue; } - $j = &$obj; - if (!PEAR_Downloader_Package::willDownload($j, - array_merge($params, $newparams)) && !$param->isInstalled($j)) { - $newparams[] = &$j; + if (!PEAR_Downloader_Package::willDownload($obj, + array_merge($params, $newparams)) && !$param->isInstalled($obj)) { + $newparams[] = $obj; } } } @@ -19407,7 +19400,7 @@ class PEAR_Downloader_Package // convert the dependencies into PEAR_Downloader_Package objects for the next time around $params[$i]->_downloadDeps = array(); foreach ($newdeps as $dep) { - $obj = &new PEAR_Downloader_Package($params[$i]->getDownloader()); + $obj = new PEAR_Downloader_Package($params[$i]->getDownloader()); if ($s = $params[$i]->explicitState()) { $obj->setExplicitState($s); } @@ -19429,8 +19422,7 @@ class PEAR_Downloader_Package } } - $j = &$obj; - $newparams[] = &$j; + $newparams[] = $obj; } } @@ -19471,7 +19463,7 @@ class PEAR_Downloader_Package */ function &getPackagefileObject(&$c, $d) { - $a = &new PEAR_PackageFile($c, $d); + $a = new PEAR_PackageFile($c, $d); return $a; } @@ -19546,7 +19538,7 @@ class PEAR_Downloader_Package if ($this->_rawpackagefile) { require_once 'Archive/Tar.php'; - $tar = &new Archive_Tar($file); + $tar = new Archive_Tar($file); $packagexml = $tar->extractInString('package2.xml'); if (!$packagexml) { $packagexml = $tar->extractInString('package.xml'); @@ -19955,7 +19947,7 @@ class PEAR_Downloader_Package return $info; } -}PEAR-1.9.5/PEAR/Frontend/CLI.php0000644000076500000240000006214212461216534015077 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Cfg.xml0000644000076500000240000000064512461216534016257 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Cfg.xml0000644000076500000240000000064512466347403016264 0ustar tyraelstaff php extsrc extbin @@ -20892,7 +20884,7 @@ class PEAR_Installer_Role_Common -PEAR-1.9.5/PEAR/Installer/Role/Cfg.php0000644000076500000240000000762612461216534016254 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Cfg.php0000644000076500000240000000762612466347403016261 0ustar tyraelstaff +}PEAR-1.9.5/PEAR/Installer/Role/Data.xml0000644000076500000240000000062212466347403016431 0ustar tyraelstaff php extsrc extbin @@ -21011,7 +21003,7 @@ class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common -PEAR-1.9.5/PEAR/Installer/Role/Data.php0000644000076500000240000000144612461216534016420 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Data.php0000644000076500000240000000144612466347403016425 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Doc.xml0000644000076500000240000000062112461216534016257 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Doc.xml0000644000076500000240000000062112466347403016264 0ustar tyraelstaff php extsrc extbin @@ -21052,7 +21044,7 @@ class PEAR_Installer_Role_Data extends PEAR_Installer_Role_Common {} -PEAR-1.9.5/PEAR/Installer/Role/Doc.php0000644000076500000240000000144412461216534016252 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Doc.php0000644000076500000240000000144412466347403016257 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Ext.xml0000644000076500000240000000050212461216534016310 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Ext.xml0000644000076500000240000000050212466347403016315 0ustar tyraelstaff extbin zendextbin 1 @@ -21090,7 +21082,7 @@ class PEAR_Installer_Role_Doc extends PEAR_Installer_Role_Common {} 1 -PEAR-1.9.5/PEAR/Installer/Role/Ext.php0000644000076500000240000000144412461216534016305 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Ext.php0000644000076500000240000000144412466347403016312 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Php.xml0000644000076500000240000000065512461216534016310 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Php.xml0000644000076500000240000000065512466347403016315 0ustar tyraelstaff php extsrc extbin @@ -21131,7 +21123,7 @@ class PEAR_Installer_Role_Ext extends PEAR_Installer_Role_Common {} -PEAR-1.9.5/PEAR/Installer/Role/Php.php0000644000076500000240000000144412461216534016274 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Php.php0000644000076500000240000000144412466347403016301 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Script.xml0000644000076500000240000000066012461216534017021 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Script.xml0000644000076500000240000000066012466347403017026 0ustar tyraelstaff php extsrc extbin @@ -21172,7 +21164,7 @@ class PEAR_Installer_Role_Php extends PEAR_Installer_Role_Common {} 1 -PEAR-1.9.5/PEAR/Installer/Role/Script.php0000644000076500000240000000145212461216534017010 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Script.php0000644000076500000240000000145212466347403017015 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Src.xml0000644000076500000240000000044212461216534016302 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Src.xml0000644000076500000240000000044212466347403016307 0ustar tyraelstaff extsrc zendextsrc 1 @@ -21210,7 +21202,7 @@ class PEAR_Installer_Role_Script extends PEAR_Installer_Role_Common {} -PEAR-1.9.5/PEAR/Installer/Role/Src.php0000644000076500000240000000161112461216534016270 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Src.php0000644000076500000240000000161112466347403016275 0ustar tyraelstaffsource_files++; } } -?>PEAR-1.9.5/PEAR/Installer/Role/Test.xml0000644000076500000240000000062212461216534016472 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Test.xml0000644000076500000240000000062212466347403016477 0ustar tyraelstaff php extsrc extbin @@ -21257,7 +21249,7 @@ class PEAR_Installer_Role_Src extends PEAR_Installer_Role_Common -PEAR-1.9.5/PEAR/Installer/Role/Test.php0000644000076500000240000000144612461216534016466 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Test.php0000644000076500000240000000144612466347403016473 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Www.xml0000644000076500000240000000064412461216534016343 0ustar tyraelstaff +?>PEAR-1.9.5/PEAR/Installer/Role/Www.xml0000644000076500000240000000064412466347403016350 0ustar tyraelstaff php extsrc extbin @@ -21298,7 +21290,7 @@ class PEAR_Installer_Role_Test extends PEAR_Installer_Role_Common {} -PEAR-1.9.5/PEAR/Installer/Role/Www.php0000644000076500000240000000144012461216534016325 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role/Www.php0000644000076500000240000000144012466347403016332 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role.php0000644000076500000240000001740712461216534015553 0ustar tyraelstaffPEAR-1.9.5/PEAR/Installer/Role.php0000644000076500000240000001740712466347403015560 0ustar tyraelstafftoPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true); if ($packagexml) { - $tar =& new Archive_Tar($dest_package, $compress); + $tar = new Archive_Tar($dest_package, $compress); $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors // ----- Creates with the package.xml file $ok = $tar->createModify(array($packagexml), '', $where); @@ -22883,7 +22875,7 @@ class PEAR_PackageFile_Generator_v1 return $ret; } } -?>PEAR-1.9.5/PEAR/PackageFile/Generator/v2.php0000644000076500000240000010130712461216534017316 0ustar tyraelstaffPEAR-1.9.5/PEAR/PackageFile/Generator/v2.php0000644000076500000240000010130512466347403017321 0ustar tyraelstaff_packagefile->getTasksNs() . ':', '-'), array('', '_'), $tag); $task = "PEAR_Task_$tag"; - $task = &new $task($this->_packagefile->_config, + $task = new $task($this->_packagefile->_config, $this->_packagefile->_logger, PEAR_TASK_PACKAGE); $task->init($raw, $atts, null); @@ -23154,7 +23146,7 @@ http://pear.php.net/dtd/package-2.0.xsd', $name = $pf1 !== null ? 'package2.xml' : 'package.xml'; $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name); if ($packagexml) { - $tar =& new Archive_Tar($dest_package, $compress); + $tar = new Archive_Tar($dest_package, $compress); $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors // ----- Creates with the package.xml file $ok = $tar->createModify(array($packagexml), '', $where); @@ -23776,7 +23768,7 @@ http://pear.php.net/dtd/package-2.0.xsd', return $tag; } } -PEAR-1.9.5/PEAR/PackageFile/Parser/v1.php0000644000076500000240000004024112461216534016622 0ustar tyraelstaffPEAR-1.9.5/PEAR/PackageFile/Parser/v2.php0000644000076500000240000000614212461216534016625 0ustar tyraelstaffPEAR-1.9.5/PEAR/PackageFile/Parser/v2.php0000644000076500000240000000614212466347403016632 0ustar tyraelstaffsetPackagefile($file, $archive); return $ret; } -}PEAR-1.9.5/PEAR/PackageFile/v2/rw.php0000644000076500000240000017313512461216534016030 0ustar tyraelstaff $maintainer) { - if ($maintainer['user'] == $handle) { + if (is_array($maintainer) && $maintainer['user'] == $handle) { $found = $i; break 2; } @@ -25949,7 +25941,7 @@ class PEAR_PackageFile_v2_rw extends PEAR_PackageFile_v2 { unset($this->_packageInfo['changelog']); } -}PEAR-1.9.5/PEAR/PackageFile/v2/Validator.php0000644000076500000240000025012112461216534017314 0ustar tyraelstaff_pf->_config); + $pkg = new PEAR_PackageFile($this->_pf->_config); foreach ($info as $package) { if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $package)) { $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $package); @@ -28103,7 +28096,7 @@ class PEAR_PackageFile_v2_Validator return $providesret; } } -PEAR-1.9.5/PEAR/PackageFile/v1.php0000644000076500000240000014370512461216534015377 0ustar tyraelstaff_stack = &new PEAR_ErrorStack('PEAR_PackageFile_v1'); + $this->_stack = new PEAR_ErrorStack('PEAR_PackageFile_v1'); $this->_stack->setErrorMessageTemplate($this->_getErrorMessage()); $this->_isValid = 0; } @@ -29413,7 +29406,7 @@ class PEAR_PackageFile_v1 if (!class_exists('PEAR_PackageFile_Generator_v1')) { require_once 'PEAR/PackageFile/Generator/v1.php'; } - $a = &new PEAR_PackageFile_Generator_v1($this); + $a = new PEAR_PackageFile_Generator_v1($this); return $a; } @@ -29436,7 +29429,7 @@ class PEAR_PackageFile_v1 if (!class_exists('Archive_Tar')) { require_once 'Archive/Tar.php'; } - $tar = &new Archive_Tar($this->_archiveFile); + $tar = new Archive_Tar($this->_archiveFile); $tar->pushErrorHandling(PEAR_ERROR_RETURN); if ($file != 'package.xml' && $file != 'package2.xml') { $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file; @@ -29715,7 +29708,7 @@ class PEAR_PackageFile_v1 // }}} } ?> -PEAR-1.9.5/PEAR/PackageFile/v2.php0000644000076500000240000021004012461216534015363 0ustar tyraelstaff $raw) { $task = $this->getTask($tag); - $task = &new $task($this->_config, $common, PEAR_TASK_INSTALL); + $task = new $task($this->_config, $common, PEAR_TASK_INSTALL); if ($task->isScript()) { $ret[] = $filelist[$name]['installed_as']; } @@ -30327,7 +30320,7 @@ class PEAR_PackageFile_v2 $atts = $filelist[$name]; foreach ($tasks as $tag => $raw) { $taskname = $this->getTask($tag); - $task = &new $taskname($this->_config, $common, PEAR_TASK_INSTALL); + $task = new $taskname($this->_config, $common, PEAR_TASK_INSTALL); if (!$task->isScript()) { continue; // scripts are only handled after installation } @@ -31571,7 +31564,7 @@ class PEAR_PackageFile_v2 return implode('', file($file)); } } else { // tgz - $tar = &new Archive_Tar($this->_archiveFile); + $tar = new Archive_Tar($this->_archiveFile); $tar->pushErrorHandling(PEAR_ERROR_RETURN); if ($file != 'package.xml' && $file != 'package2.xml') { $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file; @@ -31610,7 +31603,7 @@ class PEAR_PackageFile_v2 if (!class_exists('PEAR_PackageFile_Generator_v2')) { require_once 'PEAR/PackageFile/Generator/v2.php'; } - $a = &new PEAR_PackageFile_Generator_v2($this); + $a = new PEAR_PackageFile_Generator_v2($this); return $a; } @@ -31764,7 +31757,7 @@ class PEAR_PackageFile_v2 } } ?> -PEAR-1.9.5/PEAR/REST/10.php0000644000076500000240000007765112461216534013721 0ustar tyraelstaff_rest = &new PEAR_REST($config, $options); + $this->_rest = new PEAR_REST($config, $options); } /** @@ -32634,7 +32627,7 @@ class PEAR_REST_10 return 1; } } -}PEAR-1.9.5/PEAR/REST/11.php0000644000076500000240000002600112461216534013701 0ustar tyraelstaff_rest = &new PEAR_REST($config, $options); + $this->_rest = new PEAR_REST($config, $options); } function listAll($base, $dostable, $basic = true, $searchpackage = false, $searchsummary = false, $channel = false) @@ -32974,7 +32967,7 @@ class PEAR_REST_11 return array_slice($states, $i + 1); } } -?>PEAR-1.9.5/PEAR/REST/13.php0000644000076500000240000002647112461216534013716 0ustar tyraelstaffPEAR-1.9.5/PEAR/REST/13.php0000644000076500000240000002647112466347403013723 0ustar tyraelstaff_returnDownloadURL($base, $package, $release, $info, $found, $skippedphp, $channel); } -}PEAR-1.9.5/PEAR/Task/Postinstallscript/rw.php0000644000076500000240000001323612461216534020004 0ustar tyraelstaff - read/write version * @@ -33440,7 +33433,7 @@ class PEAR_Task_Postinstallscript_rw extends PEAR_Task_Postinstallscript ); } } -?>PEAR-1.9.5/PEAR/Task/Replace/rw.php0000644000076500000240000000304212461216534015610 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Replace/rw.php0000644000076500000240000000304212466347403015615 0ustar tyraelstaff - read/write version * @@ -33500,7 +33493,7 @@ class PEAR_Task_Replace_rw extends PEAR_Task_Replace return $this->_params; } } -?>PEAR-1.9.5/PEAR/Task/Unixeol/rw.php0000644000076500000240000000246212461216534015665 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Unixeol/rw.php0000644000076500000240000000246212466347403015672 0ustar tyraelstaff - read/write version * @@ -33555,7 +33548,7 @@ class PEAR_Task_Unixeol_rw extends PEAR_Task_Unixeol return ''; } } -?>PEAR-1.9.5/PEAR/Task/Windowseol/rw.php0000644000076500000240000000250712461216534016374 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Windowseol/rw.php0000644000076500000240000000250712466347403016401 0ustar tyraelstaff - read/write version * @@ -33610,7 +33603,7 @@ class PEAR_Task_Windowseol_rw extends PEAR_Task_Windowseol return ''; } } -?>PEAR-1.9.5/PEAR/Task/Common.php0000644000076500000240000001365712461216534015052 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Common.php0000644000076500000240000001365712466347403015057 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Postinstallscript.php0000644000076500000240000003403012461216534017347 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Postinstallscript.php0000644000076500000240000003403012466347403017354 0ustar tyraelstaff * @@ -34133,7 +34126,7 @@ class PEAR_Task_Postinstallscript extends PEAR_Task_Common { } } -?>PEAR-1.9.5/PEAR/Task/Replace.php0000644000076500000240000001515212461216534015165 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Replace.php0000644000076500000240000001515212466347403015172 0ustar tyraelstaff * @@ -34308,7 +34301,7 @@ class PEAR_Task_Replace extends PEAR_Task_Common return $contents; } } -?>PEAR-1.9.5/PEAR/Task/Unixeol.php0000644000076500000240000000426112461216534015234 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Unixeol.php0000644000076500000240000000426112466347403015241 0ustar tyraelstaff * @@ -34384,7 +34377,7 @@ class PEAR_Task_Unixeol extends PEAR_Task_Common return preg_replace("/\r\n|\n\r|\r|\n/", "\n", $contents); } } -?>PEAR-1.9.5/PEAR/Task/Windowseol.php0000644000076500000240000000425212461216534015743 0ustar tyraelstaffPEAR-1.9.5/PEAR/Task/Windowseol.php0000644000076500000240000000425212466347403015750 0ustar tyraelstaff * @@ -34460,7 +34453,7 @@ class PEAR_Task_Windowseol extends PEAR_Task_Common return preg_replace("/\r\n|\n\r|\r|\n/", "\r\n", $contents); } } -?>PEAR-1.9.5/PEAR/Validator/PECL.php0000644000076500000240000000412012461216534015351 0ustar tyraelstaffPEAR-1.9.5/PEAR/Validator/PECL.php0000644000076500000240000000412012466347403015356 0ustar tyraelstaffPEAR-1.9.5/PEAR/Autoloader.php0000644000076500000240000001456212461216534015013 0ustar tyraelstaffPEAR-1.9.5/PEAR/Autoloader.php0000644000076500000240000001456112466347403015017 0ustar tyraelstaff -PEAR-1.9.5/PEAR/Builder.php0000644000076500000240000004060612461216534014300 0ustar tyraelstaffgetPackageFile(); } else { - $pf = &new PEAR_PackageFile($this->config, $this->debug); + $pf = new PEAR_PackageFile($this->config, $this->debug); $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; @@ -35021,7 +35014,7 @@ class PEAR_Builder extends PEAR_Common $this->addTempFile($dir); } } else { - $pf = &new PEAR_PackageFile($this->config); + $pf = new PEAR_PackageFile($this->config); $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; @@ -35229,7 +35222,7 @@ class PEAR_Builder extends PEAR_Common return PEAR_Common::log($level, $msg); } } -PEAR-1.9.5/PEAR/ChannelFile.php0000644000076500000240000014326712461216534015071 0ustar tyraelstaff_stack = &new PEAR_ErrorStack('PEAR_ChannelFile'); + $this->_stack = new PEAR_ErrorStack('PEAR_ChannelFile'); $this->_stack->setErrorMessageTemplate($this->_getErrorMessage()); $this->_isValid = false; } @@ -36732,7 +36725,7 @@ class PEAR_ChannelFile if (isset($this->_channelInfo['validatepackage'])) { if ($package == $this->_channelInfo['validatepackage']) { // channel validation packages are always validated by PEAR_Validate - $val = &new PEAR_Validate; + $val = new PEAR_Validate; return $val; } @@ -36744,7 +36737,7 @@ class PEAR_ChannelFile $this->_channelInfo['validatepackage']['_content']) . '.php'; $vclass = str_replace('.', '_', $this->_channelInfo['validatepackage']['_content']); - $val = &new $vclass; + $val = new $vclass; } else { $a = false; return $a; @@ -36752,10 +36745,10 @@ class PEAR_ChannelFile } else { $vclass = str_replace('.', '_', $this->_channelInfo['validatepackage']['_content']); - $val = &new $vclass; + $val = new $vclass; } } else { - $val = &new PEAR_Validate; + $val = new PEAR_Validate; } return $val; @@ -36787,7 +36780,7 @@ class PEAR_ChannelFile return time(); } -}PEAR-1.9.5/PEAR/Command.php0000644000076500000240000003055312461216534014270 0ustar tyraelstaffconfig); + $packagefile = new PEAR_PackageFile($this->config); $pf = &$packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL); return $this->_postProcessChecks($pf); } @@ -37710,7 +37703,7 @@ class PEAR_Common extends PEAR */ function infoFromDescriptionFile($descfile) { - $packagefile = &new PEAR_PackageFile($this->config); + $packagefile = new PEAR_PackageFile($this->config); $pf = &$packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); return $this->_postProcessChecks($pf); } @@ -37729,7 +37722,7 @@ class PEAR_Common extends PEAR */ function infoFromString($data) { - $packagefile = &new PEAR_PackageFile($this->config); + $packagefile = new PEAR_PackageFile($this->config); $pf = &$packagefile->fromXmlString($data, PEAR_VALIDATE_NORMAL, false); return $this->_postProcessChecks($pf); } @@ -37773,7 +37766,7 @@ class PEAR_Common extends PEAR function infoFromAny($info) { if (is_string($info) && file_exists($info)) { - $packagefile = &new PEAR_PackageFile($this->config); + $packagefile = new PEAR_PackageFile($this->config); $pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); @@ -37806,7 +37799,7 @@ class PEAR_Common extends PEAR function xmlFromInfo($pkginfo) { $config = &PEAR_Config::singleton(); - $packagefile = &new PEAR_PackageFile($config); + $packagefile = new PEAR_PackageFile($config); $pf = &$packagefile->fromArray($pkginfo); $gen = &$pf->getDefaultGenerator(); return $gen->toXml(PEAR_VALIDATE_PACKAGING); @@ -37828,7 +37821,7 @@ class PEAR_Common extends PEAR function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '') { $config = &PEAR_Config::singleton(); - $packagefile = &new PEAR_PackageFile($config); + $packagefile = new PEAR_PackageFile($config); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); if (strpos($info, 'fromXmlString($info, PEAR_VALIDATE_NORMAL, ''); @@ -38036,7 +38029,7 @@ class PEAR_Common extends PEAR } require_once 'PEAR/Config.php'; -require_once 'PEAR/PackageFile.php';PEAR-1.9.5/PEAR/Config.php0000644000076500000240000020462112461216534014116 0ustar tyraelstaffconfiguration['default'][$key] = $info['default']; } - $this->_registry['default'] = &new PEAR_Registry($this->configuration['default']['php_dir']); + $this->_registry['default'] = new PEAR_Registry($this->configuration['default']['php_dir']); $this->_registry['default']->setConfig($this, false); $this->_regInitialized['default'] = false; //$GLOBALS['_PEAR_Config_instance'] = &$this; @@ -38732,7 +38725,7 @@ class PEAR_Config extends PEAR return $GLOBALS['_PEAR_Config_instance']; } - $t_conf = &new PEAR_Config($user_file, $system_file, false, $strict); + $t_conf = new PEAR_Config($user_file, $system_file, false, $strict); if ($t_conf->_errorsFound > 0) { return $t_conf->lastError; } @@ -38792,7 +38785,7 @@ class PEAR_Config extends PEAR $this->configuration[$layer] = $data; $this->_setupChannels(); if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) { - $this->_registry[$layer] = &new PEAR_Registry($phpdir); + $this->_registry[$layer] = new PEAR_Registry($phpdir); $this->_registry[$layer]->setConfig($this, false); $this->_regInitialized[$layer] = false; } else { @@ -38821,7 +38814,7 @@ class PEAR_Config extends PEAR return PEAR::raiseError('PEAR_RemoteInstaller must be installed to use remote config'); } - $this->_ftp = &new PEAR_FTP; + $this->_ftp = new PEAR_FTP; $this->_ftp->pushErrorHandling(PEAR_ERROR_RETURN); $e = $this->_ftp->init($path); if (PEAR::isError($e)) { @@ -38949,7 +38942,7 @@ class PEAR_Config extends PEAR $this->_setupChannels(); if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) { - $this->_registry[$layer] = &new PEAR_Registry($phpdir); + $this->_registry[$layer] = new PEAR_Registry($phpdir); $this->_registry[$layer]->setConfig($this, false); $this->_regInitialized[$layer] = false; } else { @@ -39060,20 +39053,12 @@ class PEAR_Config extends PEAR } $size = filesize($file); - if (function_exists('set_magic_quotes_runtime')) { - $rt = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - } fclose($fp); $contents = file_get_contents($file); if (empty($contents)) { return $this->raiseError('Configuration file "' . $file . '" is empty'); } - if (function_exists('set_magic_quotes_runtime')) { - set_magic_quotes_runtime($rt); - } - $version = false; if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) { $version = $matches[1]; @@ -39616,7 +39601,7 @@ class PEAR_Config extends PEAR if ($key == 'php_dir' && !$this->_noRegistry) { if (!isset($this->_registry[$layer]) || $value != $this->_registry[$layer]->install_dir) { - $this->_registry[$layer] = &new PEAR_Registry($value); + $this->_registry[$layer] = new PEAR_Registry($value); $this->_regInitialized[$layer] = false; $this->_registry[$layer]->setConfig($this, false); } @@ -39646,7 +39631,7 @@ class PEAR_Config extends PEAR if (!is_object($this->_registry[$layer])) { if ($phpdir = $this->get('php_dir', $layer, 'pear.php.net')) { - $this->_registry[$layer] = &new PEAR_Registry($phpdir); + $this->_registry[$layer] = new PEAR_Registry($phpdir); $this->_registry[$layer]->setConfig($this, false); $this->_regInitialized[$layer] = false; } else { @@ -40077,7 +40062,7 @@ class PEAR_Config extends PEAR require_once 'PEAR/REST/' . $version . '.php'; } - $remote = &new $class($this, $options); + $remote = new $class($this, $options); return $remote; } @@ -40130,14 +40115,14 @@ class PEAR_Config extends PEAR continue; } $this->_registry[$layer] = - &new PEAR_Registry($this->get('php_dir', $layer, 'pear.php.net')); + new PEAR_Registry($this->get('php_dir', $layer, 'pear.php.net')); $this->_registry[$layer]->setConfig($this, false); $this->_regInitialized[$layer] = false; } } } } -PEAR-1.9.5/PEAR/DependencyDB.php0000644000076500000240000005764512461216534015211 0ustar tyraelstaff_depdb)); - if (function_exists('set_magic_quotes_runtime')) { - set_magic_quotes_runtime($rt); - } $this->_cache = $data; return $data; } @@ -40720,14 +40698,7 @@ class PEAR_DependencyDB return PEAR::raiseError("Could not open dependencies file `".$this->_depdb."' for writing"); } - if (function_exists('set_magic_quotes_runtime')) { - $rt = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - } fwrite($fp, serialize($deps)); - if (function_exists('set_magic_quotes_runtime')) { - set_magic_quotes_runtime($rt); - } fclose($fp); $this->_unlock(); $this->_cache = $deps; @@ -40913,7 +40884,7 @@ class PEAR_DependencyDB ); } } -}PEAR-1.9.5/PEAR/Dependency2.php0000644000076500000240000014243512461216534015055 0ustar tyraelstaffsetPackageFile($downloaded[$i]); - $params[$i] = &$dp; + $params[$i] = $dp; } // check cache @@ -42090,7 +42061,7 @@ class PEAR_Dependency2 require_once 'PEAR/Downloader/Package.php'; } - $dp = &new PEAR_Downloader_Package($dl); + $dp = new PEAR_Downloader_Package($dl); if (is_object($pkg)) { $dp->setPackageFile($pkg); } else { @@ -42114,7 +42085,7 @@ class PEAR_Dependency2 } foreach ($ds as $d) { - $checker = &new PEAR_Dependency2($this->_config, $this->_options, + $checker = new PEAR_Dependency2($this->_config, $this->_options, array('channel' => $channel, 'package' => $package), $this->_state); $dep = $d['dep']; $required = $d['type'] == 'required'; @@ -42271,7 +42242,7 @@ class PEAR_Dependency2 $this->_currentPackage, true))); } } -PEAR-1.9.5/PEAR/Downloader.php0000644000076500000240000020174612461216534015014 0ustar tyraelstaffpushCallback(array('PEAR_ErrorStack', '_handleError')); ?> -PEAR-1.9.5/PEAR/Exception.php0000644000076500000240000003320412461216534014644 0ustar tyraelstaffgetTraceAsString(); } -}PEAR-1.9.5/PEAR/FixPHP5PEARWarnings.php0000644000076500000240000000023112461216534016244 0ustar tyraelstaffPEAR-1.9.5/PEAR/Frontend.php0000644000076500000240000001501612461216534014466 0ustar tyraelstaffPEAR-1.9.5/PEAR/Frontend.php0000644000076500000240000001501512466347403014472 0ustar tyraelstaff $raw) { $tag = str_replace(array($pkg->getTasksNs() . ':', '-'), array('', '_'), $tag); $task = "PEAR_Task_$tag"; - $task = &new $task($this->config, $this, PEAR_TASK_INSTALL); + $task = new $task($this->config, $this, PEAR_TASK_INSTALL); if (!$task->isScript()) { // scripts are only handled after installation $task->init($raw, $attribs, $pkg->getLastInstalledVersion()); $res = $task->startSession($pkg, $contents, $final_dest_file); @@ -46829,7 +46800,7 @@ class PEAR_Installer extends PEAR_Downloader $this->config->setInstallRoot(false); $this->_registry = &$this->config->getRegistry(); if (isset($this->_options['packagingroot'])) { - $installregistry = &new PEAR_Registry($regdir); + $installregistry = new PEAR_Registry($regdir); if (!$installregistry->channelExists($channel, true)) { // we need to fake a channel-discover of this channel $chanobj = $this->_registry->getChannel($channel, true); @@ -46918,7 +46889,7 @@ class PEAR_Installer extends PEAR_Downloader } } - $pfk = &new PEAR_PackageFile($this->config); + $pfk = new PEAR_PackageFile($this->config); $parentpkg = &$pfk->fromArray($parentreg); $installregistry->updatePackage2($parentpkg); } @@ -47182,7 +47153,7 @@ class PEAR_Installer extends PEAR_Downloader { require_once 'PEAR/Builder.php'; $this->log(1, "$this->source_files source files, building"); - $bob = &new PEAR_Builder($this->ui); + $bob = new PEAR_Builder($this->ui); $bob->debug = $this->debug; $built = $bob->build($filelist, array(&$this, '_buildCallback')); if (PEAR::isError($built)) { @@ -47326,7 +47297,7 @@ class PEAR_Installer extends PEAR_Downloader require_once 'PEAR/Dependency2.php'; } - $depchecker = &new PEAR_Dependency2($this->config, $options, + $depchecker = new PEAR_Dependency2($this->config, $options, array('channel' => $channel, 'package' => $package), PEAR_VALIDATE_UNINSTALLING); $e = $depchecker->validatePackageUninstall($this); @@ -47467,7 +47438,7 @@ class PEAR_Installer extends PEAR_Downloader } // }}} -}PEAR-1.9.5/PEAR/PackageFile.php0000644000076500000240000003677112461216534015055 0ustar tyraelstaffconfig, $this->debug); + $pkg = new PEAR_PackageFile($this->config, $this->debug); $pf = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); $main = &$pf; PEAR::staticPopErrorHandling(); @@ -48158,7 +48129,7 @@ class PEAR_Packager extends PEAR_Common return $dest_package; } -}PEAR-1.9.5/PEAR/Registry.php0000644000076500000240000022474512461216534014532 0ustar tyraelstaff_config) { // never used? $file = OS_WINDOWS ? 'pear.ini' : '.pearrc'; - $this->_config = &new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR . + $this->_config = new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR . $file); $this->_config->setRegistry($this); $this->_config->set('php_dir', $this->install_dir); @@ -48942,16 +48913,9 @@ class PEAR_Registry extends PEAR } clearstatcache(); - if (function_exists('set_magic_quotes_runtime')) { - $rt = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - } $fsize = filesize($this->filemap); fclose($fp); $data = file_get_contents($this->filemap); - if (function_exists('set_magic_quotes_runtime')) { - set_magic_quotes_runtime($rt); - } $tmp = unserialize($data); if (!$tmp && $fsize > 7) { return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data); @@ -49300,16 +49264,9 @@ class PEAR_Registry extends PEAR return null; } - if (function_exists('set_magic_quotes_runtime')) { - $rt = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - } clearstatcache(); $this->_closePackageFile($fp); $data = file_get_contents($this->_packageFileName($package, $channel)); - if (function_exists('set_magic_quotes_runtime')) { - set_magic_quotes_runtime($rt); - } $data = unserialize($data); if ($key === null) { return $data; @@ -49343,16 +49300,9 @@ class PEAR_Registry extends PEAR return null; } - if (function_exists('set_magic_quotes_runtime')) { - $rt = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - } clearstatcache(); $this->_closeChannelFile($fp); $data = file_get_contents($this->_channelFileName($channel)); - if (function_exists('set_magic_quotes_runtime')) { - set_magic_quotes_runtime($rt); - } $data = unserialize($data); return $data; } @@ -49619,7 +49569,7 @@ class PEAR_Registry extends PEAR $a = $this->_config; if (!$a) { - $this->_config = &new PEAR_Config; + $this->_config = new PEAR_Config; $this->_config->set('php_dir', $this->statedir); } @@ -49627,7 +49577,7 @@ class PEAR_Registry extends PEAR require_once 'PEAR/PackageFile.php'; } - $pkg = &new PEAR_PackageFile($this->_config); + $pkg = new PEAR_PackageFile($this->_config); $pf = &$pkg->fromArray($info); return $pf; } @@ -50564,7 +50514,7 @@ class PEAR_Registry extends PEAR } return $ret; } -}PEAR-1.9.5/PEAR/REST.php0000644000076500000240000004227112461216534013467 0ustar tyraelstaff_dataStack[$this->_depth] .= $cdata; } -}PEAR-1.9.5/scripts/pear.bat0000755000076500000240000001036112461216534014556 0ustar tyraelstaff@ECHO OFF +}PEAR-1.9.5/scripts/pear.bat0000755000076500000240000001036112466347403014563 0ustar tyraelstaff@ECHO OFF REM ---------------------------------------------------------------------- REM PHP version 5 @@ -53027,7 +52976,7 @@ GOTO END :RUN "%PHP_PEAR_PHP_BIN%" -C -d date.timezone=UTC -d output_buffering=1 -d safe_mode=0 -d open_basedir="" -d auto_prepend_file="" -d auto_append_file="" -d variables_order=EGPCS -d register_argc_argv="On" -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -f "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9 :END -@ECHO ONPEAR-1.9.5/scripts/peardev.bat0000644000076500000240000001113712461216534015254 0ustar tyraelstaff@ECHO OFF +@ECHO ONPEAR-1.9.5/scripts/peardev.bat0000644000076500000240000001113712466347403015261 0ustar tyraelstaff@ECHO OFF REM ---------------------------------------------------------------------- REM PHP version 5 @@ -53141,7 +53090,7 @@ GOTO END :RUN "%PHP_PEAR_PHP_BIN%" -C -d date.timezone=UTC -d memory_limit="-1" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" -d variables_order=EGPCS -d open_basedir="" -d output_buffering=1 -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -f "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9 :END -@ECHO ONPEAR-1.9.5/scripts/pecl.bat0000644000076500000240000001103012461216534014541 0ustar tyraelstaff@ECHO OFF +@ECHO ONPEAR-1.9.5/scripts/pecl.bat0000644000076500000240000001103012466347403014546 0ustar tyraelstaff@ECHO OFF REM ---------------------------------------------------------------------- REM PHP version 5 @@ -53255,7 +53204,7 @@ GOTO END :RUN "%PHP_PEAR_PHP_BIN%" -C -n -d date.timezone=UTC -d output_buffering=1 -d safe_mode=0 -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -d register_argc_argv="On" -d variables_order=EGPCS -f "%PHP_PEAR_INSTALL_DIR%\peclcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9 :END -@ECHO ONPEAR-1.9.5/scripts/pear.sh0000644000076500000240000000140412461216534014415 0ustar tyraelstaff#!/bin/sh +@ECHO ONPEAR-1.9.5/scripts/pear.sh0000755000076500000240000000140412466347403014425 0ustar tyraelstaff#!/bin/sh # first find which PHP binary to use if test "x$PHP_PEAR_PHP_BIN" != "x"; then @@ -53283,7 +53232,7 @@ else fi exec $PHP -C -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" $INCDIR/pearcmd.php "$@" -PEAR-1.9.5/scripts/peardev.sh0000644000076500000240000000143112461216534015114 0ustar tyraelstaff#!/bin/sh +PEAR-1.9.5/scripts/peardev.sh0000755000076500000240000000143112466347403015124 0ustar tyraelstaff#!/bin/sh # first find which PHP binary to use if test "x$PHP_PEAR_PHP_BIN" != "x"; then @@ -53311,7 +53260,7 @@ else fi exec $PHP -d date.timezone=UTC -d memory_limit="-1" -C -q $INCARG -d output_buffering=1 -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d variables_order=EGPCS -d auto_append_file="" $INCDIR/pearcmd.php "$@" -PEAR-1.9.5/scripts/pecl.sh0000644000076500000240000000130512461216534014411 0ustar tyraelstaff#!/bin/sh +PEAR-1.9.5/scripts/pecl.sh0000755000076500000240000000130512466347403014421 0ustar tyraelstaff#!/bin/sh # first find which PHP binary to use if test "x$PHP_PEAR_PHP_BIN" != "x"; then @@ -53339,7 +53288,7 @@ else fi exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@" -PEAR-1.9.5/scripts/pearcmd.php0000644000076500000240000003643512461216534015272 0ustar tyraelstaff -PEAR-1.9.5/LICENSE0000644000076500000240000000270512461216534012455 0ustar tyraelstaffCopyright (c) 1997-2009, +PEAR-1.9.5/LICENSE0000644000076500000240000000270512466347403012462 0ustar tyraelstaffCopyright (c) 1997-2009, Stig Bakken , Gregory Beaver , Helgi Þormar Þorbjörnsson , @@ -53922,7 +53870,7 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -PEAR-1.9.5/INSTALL0000644000076500000240000000417512461216534012504 0ustar tyraelstaffPEAR - The PEAR Installer +PEAR-1.9.5/INSTALL0000644000076500000240000000417512466347403012511 0ustar tyraelstaffPEAR - The PEAR Installer ========================= Installing the PEAR Installer. @@ -53975,7 +53923,7 @@ related issues. Happy PHPing, we hope PEAR will be a great tool for your development work! -$Id$PEAR-1.9.5/package.dtd0000644000076500000240000000647712461216534013552 0ustar tyraelstaff - * in mod_include. It does an Apache sub-request. It is useful - * for including CGI scripts or .shtml files, or anything else - * that you'd parse through Apache (for .phtml files, you'd probably - * want to use . This only works when PHP is compiled - * as an Apache module, since it uses the Apache API for doing - * sub requests. - */ -PHP_FUNCTION(virtual) -{ - char *filename; - int filename_len; - request_rec *rr = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - if (rr->status != 200) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - php_output_end_all(); - php_header(); - - if (run_sub_req(rr)) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - if (rr) - destroy_sub_req (rr); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto array getallheaders(void) - Alias for apache_request_headers() */ -/* }}} */ - -/* {{{ proto array apache_request_headers(void) - Fetch all HTTP request headers */ -PHP_FUNCTION(apache_request_headers) -{ - array_header *env_arr; - table_entry *tenv; - int i; - - array_init(return_value); - env_arr = table_elts(((request_rec *) SG(server_context))->headers_in); - tenv = (table_entry *)env_arr->elts; - for (i = 0; i < env_arr->nelts; ++i) { - if (!tenv[i].key) { - continue; - } - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { - RETURN_FALSE; - } - } -} -/* }}} */ - -/* {{{ proto array apache_response_headers(void) - Fetch all HTTP response headers */ -PHP_FUNCTION(apache_response_headers) -{ - array_header *env_arr; - table_entry *tenv; - int i; - - array_init(return_value); - env_arr = table_elts(((request_rec *) SG(server_context))->headers_out); - tenv = (table_entry *)env_arr->elts; - for (i = 0; i < env_arr->nelts; ++i) { - if (!tenv[i].key) continue; - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { - RETURN_FALSE; - } - } -} -/* }}} */ - -/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) - Set an Apache subprocess_env variable */ -PHP_FUNCTION(apache_setenv) -{ - int var_len, val_len; - zend_bool top=0; - char *var = NULL, *val = NULL; - request_rec *r = (request_rec *) SG(server_context); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { - return; - } - - while(top) { - if(r->prev) r = r->prev; - else break; - } - - ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto object apache_lookup_uri(string URI) - Perform a partial request of the given URI to obtain information about it */ -PHP_FUNCTION(apache_lookup_uri) -{ - char *filename; - int filename_len; - request_rec *rr=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL, E_WARNING, "URI lookup failed '%s'", filename); - RETURN_FALSE; - } - - object_init(return_value); - add_property_long(return_value,"status", rr->status); - - if (rr->the_request) { - add_property_string(return_value,"the_request", rr->the_request); - } - if (rr->status_line) { - add_property_string(return_value,"status_line", (char *)rr->status_line); - } - if (rr->method) { - add_property_string(return_value,"method", (char *)rr->method); - } - if (rr->content_type) { - add_property_string(return_value,"content_type", (char *)rr->content_type); - } - if (rr->handler) { - add_property_string(return_value,"handler", (char *)rr->handler); - } - if (rr->uri) { - add_property_string(return_value,"uri", rr->uri); - } - if (rr->filename) { - add_property_string(return_value,"filename", rr->filename); - } - if (rr->path_info) { - add_property_string(return_value,"path_info", rr->path_info); - } - if (rr->args) { - add_property_string(return_value,"args", rr->args); - } - if (rr->boundary) { - add_property_string(return_value,"boundary", rr->boundary); - } - - add_property_long(return_value,"no_cache", rr->no_cache); - add_property_long(return_value,"no_local_copy", rr->no_local_copy); - add_property_long(return_value,"allowed", rr->allowed); - add_property_long(return_value,"sent_bodyct", rr->sent_bodyct); - add_property_long(return_value,"bytes_sent", rr->bytes_sent); - add_property_long(return_value,"byterange", rr->byterange); - add_property_long(return_value,"clength", rr->clength); - -#if MODULE_MAGIC_NUMBER >= 19980324 - if (rr->unparsed_uri) { - add_property_string(return_value,"unparsed_uri", rr->unparsed_uri); - } - if(rr->mtime) { - add_property_long(return_value,"mtime", rr->mtime); - } -#endif - if(rr->request_time) { - add_property_long(return_value,"request_time", rr->request_time); - } - - destroy_sub_req(rr); -} -/* }}} */ - - -#if 0 -/* -This function is most likely a bad idea. Just playing with it for now. -*/ -PHP_FUNCTION(apache_exec_uri) -{ - char *filename; - int filename_len; - request_rec *rr=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - if(!(rr = ap_sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { - php_error_docref(NULL, E_WARNING, "URI lookup failed", filename); - RETURN_FALSE; - } - - RETVAL_LONG(ap_run_sub_req(rr)); - ap_destroy_sub_req(rr); -} -#endif - -/* {{{ proto string apache_get_version(void) - Fetch Apache version */ -PHP_FUNCTION(apache_get_version) -{ - char *apv = (char *) ap_get_server_version(); - - if (apv && *apv) { - RETURN_STRING(apv); - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto array apache_get_modules(void) - Get a list of loaded Apache modules */ -PHP_FUNCTION(apache_get_modules) -{ - int n; - char *p; - - array_init(return_value); - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s)); - } else { - add_next_index_string(return_value, s); - } - } -} -/* }}} */ - -/* {{{ proto bool apache_reset_timeout(void) - Reset the Apache write timer */ -PHP_FUNCTION(apache_reset_timeout) -{ - ap_reset_timeout((request_rec *)SG(server_context)); - RETURN_TRUE; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/apache/php_apache_http.h b/sapi/apache/php_apache_http.h deleted file mode 100644 index 00bb9ca91a8bd..0000000000000 --- a/sapi/apache/php_apache_http.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf | - | Stig Sæther Bakken | - | David Sklar | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#define NO_REGEX_EXTRA_H - -#ifdef WIN32 -#include -#endif - -#ifdef NETWARE -#include -#endif - -#include "zend.h" -#include "ext/ereg/php_regex.h" -#include "php_compat.h" - -#ifdef HAVE_OPENSSL_EXT -/* zlib typedefs free_func which causes problems if the SSL includes happen - * after zlib.h is included */ -# include -#endif - -#ifdef regex_t -#undef regex_t -#endif - -#include "httpd.h" -#include "http_config.h" - -#if MODULE_MAGIC_NUMBER > 19980712 -# include "ap_compat.h" -#else -# if MODULE_MAGIC_NUMBER > 19980324 -# include "compat.h" -# endif -#endif - -#include "http_core.h" -#include "http_main.h" -#include "http_protocol.h" -#include "http_request.h" -#include "http_log.h" -#include "util_script.h" - -#include "php_variables.h" -#include "php_main.h" -#include "php_ini.h" -#include "ext/standard/php_standard.h" - -#include "mod_php7.h" diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c deleted file mode 100644 index 302055ef25ccb..0000000000000 --- a/sapi/apache/sapi_apache.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf | - | (with helpful hints from Dean Gaudet | - | PHP 4.0 patches by: | - | Zeev Suraski | - | Stig Bakken | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -/* {{{ apache_php_module_main - */ -int apache_php_module_main(request_rec *r, int display_source_mode) -{ - int retval = OK; - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return FAILURE; - } - /* sending a file handle to another dll is not working - so let zend open it. */ - - if (display_source_mode) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - php_get_highlight_struct(&syntax_highlighter_ini); - if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini) != SUCCESS) { - retval = NOT_FOUND; - } - } else { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.handle.fd = 0; - file_handle.filename = SG(request_info).path_translated; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - - (void) php_execute_script(&file_handle); - } - - AP(in_request) = 0; - - zend_try { - php_request_shutdown(NULL); - } zend_end_try(); - - return retval; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/apache2filter/CREDITS b/sapi/apache2filter/CREDITS deleted file mode 100644 index c298a9bf6a8a2..0000000000000 --- a/sapi/apache2filter/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Apache 2.0 Filter -Sascha Schumann, Aaron Bannert diff --git a/sapi/apache2filter/EXPERIMENTAL b/sapi/apache2filter/EXPERIMENTAL deleted file mode 100644 index 293159a693dec..0000000000000 --- a/sapi/apache2filter/EXPERIMENTAL +++ /dev/null @@ -1,5 +0,0 @@ -this module is experimental, -its functions may change their names -or move to extension all together -so do not rely to much on them -you have been warned! diff --git a/sapi/apache2filter/README b/sapi/apache2filter/README deleted file mode 100644 index bd6eb17066db7..0000000000000 --- a/sapi/apache2filter/README +++ /dev/null @@ -1,71 +0,0 @@ -WHAT IS THIS? - - This module exploits the layered I/O support in Apache 2.0. - -HOW DOES IT WORK? - - In Apache 2.0, you have handlers which generate content (like - reading a script from disk). The content goes then through - a chain of filters. PHP can be such a filter, so that it processes - your script and hands the output to the next filter (which will - usually cause a write to the network). - -DOES IT WORK? - - It is experimental as interfaces in Apache 2.0 might change in the - future. - -HOW TO INSTALL - - This SAPI module is known to work with Apache 2.0.40. - - $ cd apache-2.x - $ cd src - $ ./configure --enable-so - $ make install - - For testing purposes, you might want to use --with-mpm=prefork. - (Albeit PHP also works with threaded MPMs.) - - Configure PHP 4: - - $ cd php-4.x - $ ./configure --with-apxs2=/path/to/apache-2.0/bin/apxs - $ make install - - At the end of conf/httpd.conf, add: - - AddType application/x-httpd-php .php - - If you would like to enable source code highlighting functionality add: - - AddType application/x-httpd-php-source .phps - - That's it. Now start bin/httpd. - -HOW TO CONFIGURE - - The Apache 2.0 PHP module supports a new configuration directive that - allows an admin to override the php.ini search path. For example, - place your php.ini file in Apache's ServerRoot/conf directory and - add this to your httpd.conf file: - - PHPINIDir "conf" - -DEBUGGING APACHE AND PHP - - To debug Apache, we recommend: - - 1. Use the Prefork MPM (Apache 1.3-like process model) by - configuring Apache with '--with-mpm=prefork'. - 2. Start httpd using -DONE_PROCESS (e.g. (gdb) r -DONE_PROCESS). - - If you want to debug a part of the PHP startup procedure, set a - breakpoint on 'load_module'. Step through it until apr_dso_load() is - done. Then you can set a breakpoint on any PHP-related symbol. - -TODO - - PHP functions like apache_sub_req (see php_functions.c) - Protocol handlers - Passing script data to engine without temporary file diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c deleted file mode 100644 index ed27616d16d8e..0000000000000 --- a/sapi/apache2filter/apache_config.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "php_ini.h" -#include "php_apache.h" - -#include "apr_strings.h" -#include "ap_config.h" -#include "util_filter.h" -#include "httpd.h" -#include "http_config.h" -#include "http_request.h" -#include "http_core.h" -#include "http_protocol.h" -#include "http_log.h" -#include "http_main.h" -#include "util_script.h" -#include "http_core.h" - -#ifdef PHP_AP_DEBUG -#define phpapdebug(a) fprintf a -#else -#define phpapdebug(a) -#endif - -typedef struct { - HashTable config; -} php_conf_rec; - -typedef struct { - char *value; - size_t value_len; - char status; - char htaccess; -} php_dir_entry; - -static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, const char *value, int status) -{ - php_conf_rec *d = dummy; - php_dir_entry e; - - phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config))); - - if (!strncasecmp(value, "none", sizeof("none"))) { - value = ""; - } - - e.value = apr_pstrdup(cmd->pool, value); - e.value_len = strlen(value); - e.status = status; - e.htaccess = ((cmd->override & (RSRC_CONF|ACCESS_CONF)) == 0); - - zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, sizeof(e), NULL); - return NULL; -} - -static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR); -} - -static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); -} - -static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, const char *arg2, int status) -{ - char bool_val[2]; - - if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) { - bool_val[0] = '1'; - } else { - bool_val[0] = '0'; - } - bool_val[1] = 0; - - return real_value_hnd(cmd, dummy, arg1, bool_val, status); -} - -static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR); -} - -static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) -{ - return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); -} - -static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const char *arg) -{ - if (apache2_php_ini_path_override) { - return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored"; - } - apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg); - return NULL; -} - - -void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) -{ - php_conf_rec *d = base_conf, *e = new_conf, *n = NULL; - php_dir_entry *pe; - php_dir_entry *data; - char *str; - uint str_len; - ulong num_index; - - n = create_php_config(p, "merge_php_config"); - zend_hash_copy(&n->config, &e->config, NULL, NULL, sizeof(php_dir_entry)); - - phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n)); - for (zend_hash_internal_pointer_reset(&d->config); - zend_hash_get_current_key(&d->config, &str, &str_len, - &num_index) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&d->config)) { - pe = NULL; - zend_hash_get_current_data(&d->config, (void **) &data); - if ((pe = zend_hash_find(&n->config, str, str_len) != NULL) != NULL) { - if (pe->status >= data->status) continue; - } - zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL); - phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1)); - } - - return n; -} - -char *get_php_config(void *conf, char *name, size_t name_len) -{ - php_conf_rec *d = conf; - php_dir_entry *pe; - - if ((pe = zend_hash_find(&d->config, name, name_len)) != NULL) { - return pe->value; - } - - return ""; -} - -void apply_config(void *dummy) -{ - php_conf_rec *d = dummy; - char *str; - uint str_len; - php_dir_entry *data; - - for (zend_hash_internal_pointer_reset(&d->config); - zend_hash_get_current_key(&d->config, &str, &str_len, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&d->config)) { - zend_hash_get_current_data(&d->config, (void **) &data); - phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); - if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { - phpapdebug((stderr, "..FAILED\n")); - } - } -} - -const command_rec php_dir_cmds[] = -{ - AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"), - AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, "PHP Flag Modifier"), - AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"), - AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"), - AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, "Directory containing the php.ini file"), - {NULL} -}; - -static apr_status_t destroy_php_config(void *data) -{ - php_conf_rec *d = data; - - phpapdebug((stderr, "Destroying config %p\n", data)); - zend_hash_destroy(&d->config); - - return APR_SUCCESS; -} - -void *create_php_config(apr_pool_t *p, char *dummy) -{ - php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx)); - - phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy)); - zend_hash_init(&newx->config, 0, NULL, NULL, 1); - apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null); - return (void *) newx; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/apache2filter/config.m4 b/sapi/apache2filter/config.m4 deleted file mode 100644 index 11cc051015a1c..0000000000000 --- a/sapi/apache2filter/config.m4 +++ /dev/null @@ -1,139 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(apxs2filter,, -[ --with-apxs2filter[=FILE] - EXPERIMENTAL: Build shared Apache 2.0 Filter module. FILE is the optional - pathname to the Apache apxs tool [apxs]], no, no) - -AC_MSG_CHECKING([for Apache 2.0 filter-module support via DSO through APXS]) - -if test "$PHP_APXS2FILTER" != "no"; then - if test "$PHP_APXS2FILTER" = "yes"; then - APXS=apxs - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0" && test -x /usr/sbin/apxs; then - APXS=/usr/sbin/apxs - fi - else - PHP_EXPAND_PATH($PHP_APXS2FILTER, APXS) - fi - - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0"; then - AC_MSG_RESULT() - AC_MSG_RESULT() - AC_MSG_RESULT([Sorry, I cannot run apxs. Possible reasons follow:]) - AC_MSG_RESULT() - AC_MSG_RESULT([1. Perl is not installed]) - AC_MSG_RESULT([2. apxs was not found. Try to pass the path using --with-apxs2filter=/path/to/apxs]) - AC_MSG_RESULT([3. Apache was not built using --enable-so (the apxs usage page is displayed)]) - AC_MSG_RESULT() - AC_MSG_RESULT([The output of $APXS follows:]) - $APXS -q CFLAGS - AC_MSG_ERROR([Aborting]) - fi - - APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` - APXS_BINDIR=`$APXS -q BINDIR` - APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET` - APXS_CFLAGS=`$APXS -q CFLAGS` - APU_BINDIR=`$APXS -q APU_BINDIR` - APR_BINDIR=`$APXS -q APR_BINDIR` - - # Pick up ap[ru]-N-config if using httpd >=2.1 - APR_CONFIG=`$APXS -q APR_CONFIG 2>/dev/null || - echo $APR_BINDIR/apr-config` - APU_CONFIG=`$APXS -q APU_CONFIG 2>/dev/null || - echo $APU_BINDIR/apu-config` - - APR_CFLAGS="`$APR_CONFIG --cppflags --includes`" - APU_CFLAGS="`$APU_CONFIG --includes`" - - for flag in $APXS_CFLAGS; do - case $flag in - -D*) APACHE_CPPFLAGS="$APACHE_CPPFLAGS $flag";; - esac - done - - APACHE_CFLAGS="$APACHE_CPPFLAGS -I$APXS_INCLUDEDIR $APR_CFLAGS $APU_CFLAGS" - - # Test that we're trying to configure with apache 2.x - PHP_AP_EXTRACT_VERSION($APXS_HTTPD) - if test "$APACHE_VERSION" -le 2000000; then - AC_MSG_ERROR([You have enabled Apache 2 support while your server is Apache 1.3. Please use the appropriate switch --with-apxs (without the 2)]) - elif test "$APACHE_VERSION" -lt 2000040; then - AC_MSG_ERROR([Please note that Apache version >= 2.0.40 is required]) - fi - - APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` - if test -z `$APXS -q SYSCONFDIR`; then - INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php7" - else - APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` - INSTALL_IT="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php7" - fi - - case $host_alias in - *aix*) - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp" - PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" - ;; - *darwin*) - dnl When using bundles on Darwin, we must resolve all symbols. However, - dnl the linker does not recursively look at the bundle loader and - dnl pull in its dependencies. Therefore, we must pull in the APR - dnl and APR-util libraries. - if test -x "$APR_CONFIG"; then - MH_BUNDLE_FLAGS="`$APR_CONFIG --ldflags --link-ld --libs`" - fi - if test -x "$APU_CONFIG"; then - MH_BUNDLE_FLAGS="`$APU_CONFIG --ldflags --link-ld --libs` $MH_BUNDLE_FLAGS" - fi - MH_BUNDLE_FLAGS="-bundle -bundle_loader $APXS_HTTPD $MH_BUNDLE_FLAGS" - PHP_SUBST(MH_BUNDLE_FLAGS) - PHP_SELECT_SAPI(apache2filter, bundle, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - SAPI_SHARED=libs/libphp7.so - INSTALL_IT="$INSTALL_IT $SAPI_SHARED" - ;; - *beos*) - if test -f _APP_; then `rm _APP_`; fi - `ln -s $APXS_BINDIR/httpd _APP_` - EXTRA_LIBS="$EXTRA_LIBS _APP_" - PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" - ;; - *) - PHP_SELECT_SAPI(apache2filter, shared, sapi_apache2.c apache_config.c php_functions.c, $APACHE_CFLAGS) - INSTALL_IT="$INSTALL_IT $SAPI_LIBTOOL" - ;; - esac - - if test "$APACHE_VERSION" -lt 2004001; then - APXS_MPM=`$APXS -q MPM_NAME` - if test "$APXS_MPM" != "prefork" && test "$APXS_MPM" != "peruser" && test "$APXS_MPM" != "itk"; then - PHP_BUILD_THREAD_SAFE - fi - else - APACHE_THREADED_MPM=`$APXS_HTTPD -V | grep 'threaded:.*yes'` - if test -n "$APACHE_THREADED_MPM"; then - PHP_BUILD_THREAD_SAFE - fi - fi - AC_MSG_RESULT(yes) - PHP_SUBST(APXS) -else - AC_MSG_RESULT(no) -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/apache2filter/config.w32 b/sapi/apache2filter/config.w32 deleted file mode 100755 index 361d03107420e..0000000000000 --- a/sapi/apache2filter/config.w32 +++ /dev/null @@ -1,39 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_ENABLE('apache2filter', 'Build Apache 2.x filter', 'no'); - -if (PHP_APACHE2FILTER != "no") { - if (PHP_ZTS == "no") { - WARNING("Apache2 module requires an --enable-zts build of PHP on windows"); - } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2FILTER", PHP_PHP_BUILD + "\\include\\apache2") && - CHECK_LIB("libhttpd.lib", "apache2filter", PHP_PHP_BUILD + "\\lib\\apache2") && - CHECK_LIB("libapr.lib", "apache2filter", PHP_PHP_BUILD + "\\lib\\apache2") && - CHECK_LIB("libaprutil.lib", "apache2filter", PHP_PHP_BUILD + "\\lib\\apache2") - ) { - SAPI('apache2filter', 'sapi_apache2.c apache_config.c php_functions.c', - 'php' + PHP_VERSION + 'apache2_filter.dll', - '/D PHP_APACHE2_EXPORTS /I win32'); - } else { - WARNING("Could not find apache2 filter libraries/headers"); - } -} - -ARG_ENABLE('apache2-2filter', 'Build Apache 2.2.x filter', 'no'); - -if (PHP_APACHE2_2FILTER != "no") { - if (PHP_ZTS == "no") { - WARNING("Apache2 module requires an --enable-zts build of PHP on windows"); - } else if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE2_2FILTER", PHP_PHP_BUILD + "\\include\\apache2_2") && - CHECK_LIB("libhttpd.lib", "apache2_2filter", PHP_PHP_BUILD + "\\lib\\apache2_2") && - CHECK_LIB("libapr-1.lib", "apache2_2filter", PHP_PHP_BUILD + "\\lib\\apache2_2") && - CHECK_LIB("libaprutil-1.lib", "apache2_2filter", PHP_PHP_BUILD + "\\lib\\apache2_2") - ) { - SAPI('apache2_2filter', 'sapi_apache2.c apache_config.c php_functions.c', - 'php' + PHP_VERSION + 'apache2_2_filter.dll', - '/D PHP_APACHE2_EXPORTS /I win32', - 'sapi\\apache2_2filter'); - } else { - WARNING("Could not find apache2.2 filter libraries/headers"); - } -} diff --git a/sapi/apache2filter/php.sym b/sapi/apache2filter/php.sym deleted file mode 100644 index 1469b0314d5a4..0000000000000 --- a/sapi/apache2filter/php.sym +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h deleted file mode 100644 index 72d4896820111..0000000000000 --- a/sapi/apache2filter/php_apache.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_APACHE_H -#define PHP_APACHE_H - -#include "httpd.h" -#include "http_config.h" -#include "http_core.h" - -/* Declare this so we can get to it from outside the sapi_apache2.c file */ -extern module AP_MODULE_DECLARE_DATA php7_module; - -/* A way to specify the location of the php.ini dir in an apache directive */ -extern char *apache2_php_ini_path_override; - -/* The server_context used by PHP */ -typedef struct php_struct { - int state; - request_rec *r; - ap_filter_t *f; /* downstream output filters after the PHP filter. */ - /* stat structure of the current file */ - struct stat finfo; - /* Set-aside request body bucket brigade */ - apr_bucket_brigade *post_data; - /* Whether or not we've processed PHP in the output filters yet. */ - int request_processed; -} php_struct; - -typedef struct _php_apr_bucket_brigade { - apr_bucket_brigade *bb; -} php_apr_bucket_brigade; - -void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf); -void *create_php_config(apr_pool_t *p, char *dummy); -char *get_php_config(void *conf, char *name, size_t name_len); -void apply_config(void *); -extern const command_rec php_dir_cmds[]; - -static size_t php_apache_read_stream(void *, char *, size_t); -static size_t php_apache_fsizer_stream(void *); - -#define APR_ARRAY_FOREACH_OPEN(arr, key, val) \ -{ \ - apr_table_entry_t *elts; \ - int i; \ - elts = (apr_table_entry_t *) arr->elts; \ - for (i = 0; i < arr->nelts; i++) { \ - key = elts[i].key; \ - val = elts[i].val; - -#define APR_ARRAY_FOREACH_CLOSE() }} - -/* fix for gcc4 visibility patch */ -#ifndef PHP_WIN32 -# undef AP_MODULE_DECLARE_DATA -# define AP_MODULE_DECLARE_DATA PHPAPI -#endif - -#endif /* PHP_APACHE_H */ diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c deleted file mode 100644 index 061fc7b26c87b..0000000000000 --- a/sapi/apache2filter/php_functions.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "zend_smart_str.h" -#include "ext/standard/info.h" -#include "SAPI.h" - -#define CORE_PRIVATE -#include "apr_strings.h" -#include "apr_time.h" -#include "ap_config.h" -#include "util_filter.h" -#include "httpd.h" -#include "http_config.h" -#include "http_request.h" -#include "http_core.h" -#include "http_protocol.h" -#include "http_log.h" -#include "http_main.h" -#include "util_script.h" -#include "http_core.h" - -#include "php_apache.h" - -static request_rec *php_apache_lookup_uri(char *filename) -{ - php_struct *ctx; - - if (!filename) { - return NULL; - } - - ctx = SG(server_context); - return ap_sub_req_lookup_uri(filename, ctx->f->r, ctx->f->next); -} - -/* {{{ proto bool virtual(string uri) - Perform an apache sub-request */ -PHP_FUNCTION(virtual) -{ - char *filename; - int filename_len; - request_rec *rr; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = php_apache_lookup_uri(filename))) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); - RETURN_FALSE; - } - - if (rr->status == HTTP_OK) { - if (ap_run_sub_req(rr)) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename); - ap_destroy_sub_req(rr); - RETURN_FALSE; - } - ap_destroy_sub_req(rr); - RETURN_TRUE; - } - - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); - ap_destroy_sub_req(rr); - RETURN_FALSE; -} -/* }}} */ - -#define ADD_LONG(name) \ - add_property_long(return_value, #name, rr->name) -#define ADD_TIME(name) \ - add_property_long(return_value, #name, apr_time_sec(rr->name)); -#define ADD_STRING(name) \ - if (rr->name) add_property_string(return_value, #name, (char *) rr->name) - -PHP_FUNCTION(apache_lookup_uri) -{ - request_rec *rr; - char *filename; - int filename_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = php_apache_lookup_uri(filename))) { - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); - RETURN_FALSE; - } - - if (rr->status == HTTP_OK) { - object_init(return_value); - - ADD_LONG(status); - ADD_STRING(the_request); - ADD_STRING(status_line); - ADD_STRING(method); - ADD_TIME(mtime); - ADD_LONG(clength); -#if MODULE_MAGIC_NUMBER < 20020506 - ADD_STRING(boundary); -#endif - ADD_STRING(range); - ADD_LONG(chunked); - ADD_STRING(content_type); - ADD_STRING(handler); - ADD_LONG(no_cache); - ADD_LONG(no_local_copy); - ADD_STRING(unparsed_uri); - ADD_STRING(uri); - ADD_STRING(filename); - ADD_STRING(path_info); - ADD_STRING(args); - ADD_LONG(allowed); - ADD_LONG(sent_bodyct); - ADD_LONG(bytes_sent); - ADD_LONG(mtime); - ADD_TIME(request_time); - - ap_destroy_sub_req(rr); - return; - } - - php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); - ap_destroy_sub_req(rr); - RETURN_FALSE; -} - -/* {{{ proto array getallheaders(void) - Fetch all HTTP request headers */ -PHP_FUNCTION(apache_request_headers) -{ - php_struct *ctx; - const apr_array_header_t *arr; - char *key, *val; - - array_init(return_value); - - ctx = SG(server_context); - arr = apr_table_elts(ctx->f->r->headers_in); - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = ""; - add_assoc_string(return_value, key, val); - APR_ARRAY_FOREACH_CLOSE() -} -/* }}} */ - -/* {{{ proto array apache_response_headers(void) - Fetch all HTTP response headers */ -PHP_FUNCTION(apache_response_headers) -{ - php_struct *ctx; - const apr_array_header_t *arr; - char *key, *val; - - array_init(return_value); - - ctx = SG(server_context); - arr = apr_table_elts(ctx->f->r->headers_out); - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) val = ""; - add_assoc_string(return_value, key, val); - APR_ARRAY_FOREACH_CLOSE() -} -/* }}} */ - -/* {{{ proto string apache_note(string note_name [, string note_value]) - Get and set Apache request notes */ -PHP_FUNCTION(apache_note) -{ - php_struct *ctx; - char *note_name, *note_val = NULL; - int note_name_len, note_val_len; - char *old_note_val=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { - return; - } - - ctx = SG(server_context); - - old_note_val = (char *) apr_table_get(ctx->r->notes, note_name); - - if (note_val) { - apr_table_set(ctx->r->notes, note_name, note_val); - } - - if (old_note_val) { - RETURN_STRING(old_note_val, 1); - } - - RETURN_FALSE; -} -/* }}} */ - - -/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) - Set an Apache subprocess_env variable */ -PHP_FUNCTION(apache_setenv) -{ - php_struct *ctx; - char *variable=NULL, *string_val=NULL; - int variable_len, string_val_len; - zend_bool walk_to_top = 0; - int arg_count = ZEND_NUM_ARGS(); - - if (zend_parse_parameters(arg_count, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { - return; - } - - ctx = SG(server_context); - - if (arg_count == 3 && walk_to_top) { - while(ctx->f->r->prev) { - ctx->f->r = ctx->f->r->prev; - } - } - - apr_table_set(ctx->r->subprocess_env, variable, string_val); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool apache_getenv(string variable [, bool walk_to_top]) - Get an Apache subprocess_env variable */ -PHP_FUNCTION(apache_getenv) -{ - php_struct *ctx; - char *variable=NULL; - int variable_len; - zend_bool walk_to_top = 0; - int arg_count = ZEND_NUM_ARGS(); - char *env_val=NULL; - - if (zend_parse_parameters(arg_count, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { - return; - } - - ctx = SG(server_context); - - if (arg_count == 2 && walk_to_top) { - while(ctx->f->r->prev) { - ctx->f->r = ctx->f->r->prev; - } - } - - env_val = (char*) apr_table_get(ctx->r->subprocess_env, variable); - if (env_val != NULL) { - RETURN_STRING(env_val, 1); - } - - RETURN_FALSE; -} -/* }}} */ - -static char *php_apache_get_version() -{ -#if MODULE_MAGIC_NUMBER_MAJOR >= 20060905 - return (char *) ap_get_server_banner(); -#else - return (char *) ap_get_server_version(); -#endif -} - -/* {{{ proto string apache_get_version(void) - Fetch Apache version */ -PHP_FUNCTION(apache_get_version) -{ - char *apv = php_apache_get_version(); - - if (apv && *apv) { - RETURN_STRING(apv, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto array apache_get_modules(void) - Get a list of loaded Apache modules */ -PHP_FUNCTION(apache_get_modules) -{ - int n; - char *p; - - array_init(return_value); - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s)); - } else { - add_next_index_string(return_value, s); - } - } -} -/* }}} */ - -PHP_MINFO_FUNCTION(apache) -{ - char *apv = php_apache_get_version(); - smart_str tmp1 = {0}; - int n; - char *p; - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - smart_str_appendl(&tmp1, s, (p - s)); - } else { - smart_str_appends(&tmp1, s); - } - smart_str_appendc(&tmp1, ' '); - } - if ((tmp1.len - 1) >= 0) { - tmp1.c[tmp1.len - 1] = '\0'; - } - - php_info_print_table_start(); - if (apv && *apv) { - php_info_print_table_row(2, "Apache Version", apv); - } - php_info_print_table_row(2, "Loaded Modules", tmp1.c); - smart_str_free(&tmp1); - php_info_print_table_end(); -} - -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_lookup_uri, 0, 0, 1) - ZEND_ARG_INFO(0, filename) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_virtual, 0, 0, 1) - ZEND_ARG_INFO(0, uri) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_getallheaders, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_response_headers, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_note, 0, 0, 1) - ZEND_ARG_INFO(0, note_name) - ZEND_ARG_INFO(0, note_value) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_setenv, 0, 0, 2) - ZEND_ARG_INFO(0, variable) - ZEND_ARG_INFO(0, value) - ZEND_ARG_INFO(0, walk_to_top) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apache2filter_getenv, 0, 0, 1) - ZEND_ARG_INFO(0, variable) - ZEND_ARG_INFO(0, walk_to_top) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_get_version, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_apache2filter_get_modules, 0) -ZEND_END_ARG_INFO() -/* }}} */ - -static const zend_function_entry apache_functions[] = { - PHP_FE(apache_lookup_uri, arginfo_apache2filter_lookup_uri) - PHP_FE(virtual, arginfo_apache2filter_virtual) - PHP_FE(apache_request_headers, arginfo_apache2filter_getallheaders) - PHP_FE(apache_response_headers, arginfo_apache2filter_response_headers) - PHP_FE(apache_setenv, arginfo_apache2filter_setenv) - PHP_FE(apache_getenv, arginfo_apache2filter_getenv) - PHP_FE(apache_note, arginfo_apache2filter_note) - PHP_FE(apache_get_version, arginfo_apache2filter_get_version) - PHP_FE(apache_get_modules, arginfo_apache2filter_get_modules) - PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apache2filter_getallheaders) - {NULL, NULL, NULL} -}; - -zend_module_entry php_apache_module = { - STANDARD_MODULE_HEADER, - "apache2filter", - apache_functions, - NULL, - NULL, - NULL, - NULL, - PHP_MINFO(apache), - NULL, - STANDARD_MODULE_PROPERTIES -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c deleted file mode 100644 index 3b639db61a513..0000000000000 --- a/sapi/apache2filter/sapi_apache2.c +++ /dev/null @@ -1,756 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann | - | Parts based on Apache 1.3 SAPI module by | - | Rasmus Lerdorf and Zeev Suraski | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "php_main.h" -#include "php_ini.h" -#include "php_variables.h" -#include "SAPI.h" - -#include "zend_smart_str.h" -#ifndef NETWARE -#include "ext/standard/php_standard.h" -#else -#include "ext/standard/basic_functions.h" -#endif - -#include "apr_strings.h" -#include "ap_config.h" -#include "apr_buckets.h" -#include "util_filter.h" -#include "httpd.h" -#include "http_config.h" -#include "http_request.h" -#include "http_core.h" -#include "http_protocol.h" -#include "http_log.h" -#include "http_main.h" -#include "util_script.h" -#include "http_core.h" -#include "ap_mpm.h" - -#include "php_apache.h" - -/* UnixWare and Netware define shutdown to _shutdown, which causes problems later - * on when using a structure member named shutdown. Since this source - * file does not use the system call shutdown, it is safe to #undef it. - */ -#undef shutdown - -/* A way to specify the location of the php.ini dir in an apache directive */ -char *apache2_php_ini_path_override = NULL; - -static int -php_apache_sapi_ub_write(const char *str, uint str_length) -{ - apr_bucket *b; - apr_bucket_brigade *bb; - apr_bucket_alloc_t *ba; - ap_filter_t *f; /* remaining output filters */ - php_struct *ctx; - - ctx = SG(server_context); - f = ctx->f; - - if (str_length == 0) return 0; - - ba = f->c->bucket_alloc; - bb = apr_brigade_create(ctx->r->pool, ba); - - b = apr_bucket_transient_create(str, str_length, ba); - APR_BRIGADE_INSERT_TAIL(bb, b); - - if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { - php_handle_aborted_connection(); - } - - return str_length; /* we always consume all the data passed to us. */ -} - -static int -php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) -{ - php_struct *ctx; - char *val, *ptr; - - ctx = SG(server_context); - - switch(op) { - case SAPI_HEADER_DELETE: - apr_table_unset(ctx->r->headers_out, sapi_header->header); - return 0; - - case SAPI_HEADER_DELETE_ALL: - apr_table_clear(ctx->r->headers_out); - return 0; - - case SAPI_HEADER_ADD: - case SAPI_HEADER_REPLACE: - val = strchr(sapi_header->header, ':'); - - if (!val) { - sapi_free_header(sapi_header); - return 0; - } - ptr = val; - - *val = '\0'; - - do { - val++; - } while (*val == ' '); - - if (!strcasecmp(sapi_header->header, "content-type")) - ctx->r->content_type = apr_pstrdup(ctx->r->pool, val); - else if (!strcasecmp(sapi_header->header, "content-length")) - ap_set_content_length(ctx->r, strtol(val, (char **)NULL, 10)); - else if (op == SAPI_HEADER_REPLACE) - apr_table_set(ctx->r->headers_out, sapi_header->header, val); - else - apr_table_add(ctx->r->headers_out, sapi_header->header, val); - - *ptr = ':'; - return SAPI_HEADER_ADD; - - default: - return 0; - } -} - -static int -php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - php_struct *ctx = SG(server_context); - - ctx->r->status = SG(sapi_headers).http_response_code; - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int -php_apache_sapi_read_post(char *buf, uint count_bytes) -{ - apr_size_t len; - php_struct *ctx = SG(server_context); - apr_bucket_brigade *brigade; - apr_bucket *partition; - - brigade = ctx->post_data; - len = count_bytes; - - switch (apr_brigade_partition(ctx->post_data, count_bytes, &partition)) { - case APR_SUCCESS: - apr_brigade_flatten(ctx->post_data, buf, &len); - brigade = apr_brigade_split(ctx->post_data, partition); - apr_brigade_destroy(ctx->post_data); - ctx->post_data = brigade; - break; - case APR_INCOMPLETE: - apr_brigade_flatten(ctx->post_data, buf, &len); - apr_brigade_cleanup(ctx->post_data); - break; - } - - return len; -} -static struct stat* -php_apache_sapi_get_stat(void) -{ - php_struct *ctx = SG(server_context); - - ctx->finfo.st_uid = ctx->r->finfo.user; - ctx->finfo.st_gid = ctx->r->finfo.group; - ctx->finfo.st_dev = ctx->r->finfo.device; - ctx->finfo.st_ino = ctx->r->finfo.inode; -#ifdef NETWARE - ctx->finfo.st_atime.tv_sec = apr_time_sec(ctx->r->finfo.atime); - ctx->finfo.st_mtime.tv_sec = apr_time_sec(ctx->r->finfo.mtime); - ctx->finfo.st_ctime.tv_sec = apr_time_sec(ctx->r->finfo.ctime); -#else - ctx->finfo.st_atime = apr_time_sec(ctx->r->finfo.atime); - ctx->finfo.st_mtime = apr_time_sec(ctx->r->finfo.mtime); - ctx->finfo.st_ctime = apr_time_sec(ctx->r->finfo.ctime); -#endif - - ctx->finfo.st_size = ctx->r->finfo.size; - ctx->finfo.st_nlink = ctx->r->finfo.nlink; - - return &ctx->finfo; -} - -static char * -php_apache_sapi_read_cookies(void) -{ - php_struct *ctx = SG(server_context); - const char *http_cookie; - - http_cookie = apr_table_get(ctx->r->headers_in, "cookie"); - - /* The SAPI interface should use 'const char *' */ - return (char *) http_cookie; -} - -static char * -php_apache_sapi_getenv(char *name, size_t name_len) -{ - php_struct *ctx = SG(server_context); - const char *env_var; - - env_var = apr_table_get(ctx->r->subprocess_env, name); - - return (char *) env_var; -} - -static void -php_apache_sapi_register_variables(zval *track_vars_array) -{ - php_struct *ctx = SG(server_context); - const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env); - char *key, *val; - unsigned int new_val_len; - - APR_ARRAY_FOREACH_OPEN(arr, key, val) - if (!val) { - val = ""; - } - if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len)) { - php_register_variable_safe(key, val, new_val_len, track_vars_array); - } - APR_ARRAY_FOREACH_CLOSE() - - php_register_variable("PHP_SELF", ctx->r->uri, track_vars_array); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len)) { - php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array); - } -} - -static void -php_apache_sapi_flush(void *server_context) -{ - php_struct *ctx; - apr_bucket_brigade *bb; - apr_bucket_alloc_t *ba; - apr_bucket *b; - ap_filter_t *f; /* output filters */ - - ctx = server_context; - - /* If we haven't registered a server_context yet, - * then don't bother flushing. */ - if (!server_context) - return; - - sapi_send_headers(); - - ctx->r->status = SG(sapi_headers).http_response_code; - SG(headers_sent) = 1; - - f = ctx->f; - - /* Send a flush bucket down the filter chain. The current default - * handler seems to act on the first flush bucket, but ignores - * all further flush buckets. - */ - - ba = ctx->r->connection->bucket_alloc; - bb = apr_brigade_create(ctx->r->pool, ba); - b = apr_bucket_flush_create(ba); - APR_BRIGADE_INSERT_TAIL(bb, b); - if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { - php_handle_aborted_connection(); - } -} - -static void php_apache_sapi_log_message(char *msg) -{ - php_struct *ctx; - - ctx = SG(server_context); - - if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */ - ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL, "%s", msg); - } - else { - ap_log_error(APLOG_MARK, APLOG_ERR, 0, ctx->r->server, "%s", msg); - } -} - -static int -php_apache_disable_caching(ap_filter_t *f) -{ - /* Identify PHP scripts as non-cacheable, thus preventing - * Apache from sending a 304 status when the browser sends - * If-Modified-Since header. - */ - f->r->no_local_copy = 1; - - return OK; -} - -static double php_apache_sapi_get_request_time(void) -{ - php_struct *ctx = SG(server_context); - return ((double) apr_time_as_msec(ctx->r->request_time)) / 1000.0; -} - -extern zend_module_entry php_apache_module; - -static int php_apache2_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_apache_module, 1)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - -static sapi_module_struct apache2_sapi_module = { - "apache2filter", - "Apache 2.0 Filter", - - php_apache2_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - php_apache_sapi_ub_write, /* unbuffered write */ - php_apache_sapi_flush, /* flush */ - php_apache_sapi_get_stat, /* get uid */ - php_apache_sapi_getenv, /* getenv */ - - php_error, /* error handler */ - - php_apache_sapi_header_handler, /* header handler */ - php_apache_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - php_apache_sapi_read_post, /* read POST data */ - php_apache_sapi_read_cookies, /* read Cookies */ - - php_apache_sapi_register_variables, - php_apache_sapi_log_message, /* Log message */ - php_apache_sapi_get_request_time, /* Get Request Time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, - ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes) -{ - php_struct *ctx; - apr_status_t rv; - - if (f->r->proxyreq) { - return ap_get_brigade(f->next, bb, mode, block, readbytes); - } - - ctx = SG(server_context); - if (ctx == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, - "php failed to get server context"); - return HTTP_INTERNAL_SERVER_ERROR; - } - - if ((rv = ap_get_brigade(f->next, bb, mode, block, readbytes)) != APR_SUCCESS) { - return rv; - } - - if (!ctx->post_data) { - ctx->post_data = apr_brigade_create(f->r->pool, f->c->bucket_alloc); - } - if ((rv = ap_save_brigade(f, &ctx->post_data, &bb, f->r->pool)) != APR_SUCCESS) { - return rv; - } - apr_brigade_cleanup(bb); - APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_eos_create(bb->bucket_alloc)); - - return APR_SUCCESS; -} - -static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx) -{ - char *content_type; - char *content_length; - const char *auth; - - PG(during_request_startup) = 0; - SG(sapi_headers).http_response_code = !f->r->status ? HTTP_OK : f->r->status; - SG(request_info).content_type = apr_table_get(f->r->headers_in, "Content-Type"); -#undef safe_strdup -#define safe_strdup(x) ((x)?strdup((x)):NULL) - SG(request_info).query_string = safe_strdup(f->r->args); - SG(request_info).request_method = f->r->method; - SG(request_info).proto_num = f->r->proto_num; - SG(request_info).request_uri = safe_strdup(f->r->uri); - SG(request_info).path_translated = safe_strdup(f->r->filename); - f->r->no_local_copy = 1; - content_type = sapi_get_default_content_type(); - f->r->content_type = apr_pstrdup(f->r->pool, content_type); - - efree(content_type); - - content_length = (char *) apr_table_get(f->r->headers_in, "Content-Length"); - SG(request_info).content_length = (content_length ? atol(content_length) : 0); - - apr_table_unset(f->r->headers_out, "Content-Length"); - apr_table_unset(f->r->headers_out, "Last-Modified"); - apr_table_unset(f->r->headers_out, "Expires"); - apr_table_unset(f->r->headers_out, "ETag"); - - auth = apr_table_get(f->r->headers_in, "Authorization"); - php_handle_auth_data(auth); - - if (SG(request_info).auth_user == NULL && f->r->user) { - SG(request_info).auth_user = estrdup(f->r->user); - } - - ctx->r->user = apr_pstrdup(ctx->r->pool, SG(request_info).auth_user); - - php_request_startup(); -} - -static void php_apache_request_dtor(ap_filter_t *f) -{ - php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)f->ctx; - - php_request_shutdown(NULL); - - if (SG(request_info).query_string) { - free(SG(request_info).query_string); - } - if (SG(request_info).request_uri) { - free(SG(request_info).request_uri); - } - if (SG(request_info).path_translated) { - free(SG(request_info).path_translated); - } - - apr_brigade_destroy(pbb->bb); -} - -static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) -{ - php_struct *ctx; - void *conf = ap_get_module_config(f->r->per_dir_config, &php7_module); - char *p = get_php_config(conf, "engine", sizeof("engine")); - zend_file_handle zfd; - php_apr_bucket_brigade *pbb; - apr_bucket *b; - - if (f->r->proxyreq) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return ap_pass_brigade(f->next, bb); - } - - /* handle situations where user turns the engine off */ - if (*p == '0') { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return ap_pass_brigade(f->next, bb); - } - - if(f->ctx) { - pbb = (php_apr_bucket_brigade *)f->ctx; - } else { - pbb = f->ctx = apr_palloc(f->r->pool, sizeof(*pbb)); - pbb->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc); - } - - if(ap_save_brigade(NULL, &pbb->bb, &bb, f->r->pool) != APR_SUCCESS) { - /* Bad */ - } - - apr_brigade_cleanup(bb); - - /* Check to see if the last bucket in this brigade, it not - * we have to wait until then. */ - if(!APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pbb->bb))) { - return 0; - } - - /* Setup the CGI variables if this is the main request.. */ - if (f->r->main == NULL || - /* .. or if the sub-request envinronment differs from the main-request. */ - f->r->subprocess_env != f->r->main->subprocess_env - ) { - /* setup standard CGI variables */ - ap_add_common_vars(f->r); - ap_add_cgi_vars(f->r); - } - - ctx = SG(server_context); - if (ctx == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, - "php failed to get server context"); - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return HTTP_INTERNAL_SERVER_ERROR; - } - - ctx->f = f->next; /* save whatever filters are after us in the chain. */ - - if (ctx->request_processed) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return ap_pass_brigade(f->next, bb); - } - - apply_config(conf); - php_apache_request_ctor(f, ctx); - - /* It'd be nice if we could highlight based of a zend_file_handle here.... - * ...but we can't. */ - - zfd.type = ZEND_HANDLE_STREAM; - - zfd.handle.stream.handle = pbb; - zfd.handle.stream.reader = php_apache_read_stream; - zfd.handle.stream.closer = NULL; - zfd.handle.stream.fsizer = php_apache_fsizer_stream; - zfd.handle.stream.isatty = 0; - - zfd.filename = f->r->filename; - zfd.opened_path = NULL; - zfd.free_filename = 0; - - php_execute_script(&zfd); - - apr_table_set(ctx->r->notes, "mod_php_memory_usage", - apr_psprintf(ctx->r->pool, "%lu", (unsigned long) zend_memory_peak_usage(1))); - - php_apache_request_dtor(f); - - if (!f->r->main) { - ctx->request_processed = 1; - } - - b = apr_bucket_eos_create(f->c->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(pbb->bb, b); - - /* Pass whatever is left on the brigade. */ - return ap_pass_brigade(f->next, pbb->bb); -} - -static apr_status_t -php_apache_server_shutdown(void *tmp) -{ - apache2_sapi_module.shutdown(&apache2_sapi_module); - sapi_shutdown(); -#ifdef ZTS - tsrm_shutdown(); -#endif - return APR_SUCCESS; -} - -static void php_apache_add_version(apr_pool_t *p) -{ - if (PG(expose_php)) { - ap_add_version_component(p, "PHP/" PHP_VERSION); - } -} - -static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) -{ -#ifndef ZTS - int threaded_mpm; - - ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm); - if(threaded_mpm) { - ap_log_error(APLOG_MARK, APLOG_CRIT, 0, 0, "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP."); - return DONE; - } -#endif - /* When this is NULL, apache won't override the hard-coded default - * php.ini path setting. */ - apache2_php_ini_path_override = NULL; - return OK; -} - -static int -php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, - apr_pool_t *ptemp, server_rec *s) -{ - void *data = NULL; - const char *userdata_key = "apache2filter_post_config"; - - /* Apache will load, unload and then reload a DSO module. This - * prevents us from starting PHP until the second load. */ - apr_pool_userdata_get(&data, userdata_key, s->process->pool); - if (data == NULL) { - /* We must use set() here and *not* setn(), otherwise the - * static string pointed to by userdata_key will be mapped - * to a different location when the DSO is reloaded and the - * pointers won't match, causing get() to return NULL when - * we expected it to return non-NULL. */ - apr_pool_userdata_set((const void *)1, userdata_key, - apr_pool_cleanup_null, s->process->pool); - return OK; - } - - /* Set up our overridden path. */ - if (apache2_php_ini_path_override) { - apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override; - } -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache2_sapi_module); - apache2_sapi_module.startup(&apache2_sapi_module); - apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null); - php_apache_add_version(pconf); - - return OK; -} - -static void php_add_filter(request_rec *r, ap_filter_t *f) -{ - int output = (f == r->output_filters); - - /* for those who still have Set*Filter PHP configured */ - while (f) { - if (strcmp(f->frec->name, "PHP") == 0) { - ap_log_error(APLOG_MARK, APLOG_WARNING, - 0, r->server, - "\"Set%sFilter PHP\" already configured for %s", - output ? "Output" : "Input", r->uri); - return; - } - f = f->next; - } - - if (output) { - ap_add_output_filter("PHP", NULL, r, r->connection); - } else { - ap_add_input_filter("PHP", NULL, r, r->connection); - } -} - -static void php_insert_filter(request_rec *r) -{ - int content_type_len = strlen("application/x-httpd-php"); - - if (r->content_type && !strncmp(r->content_type, "application/x-httpd-php", content_type_len-1)) { - if (r->content_type[content_type_len] == '\0' || !strncmp(r->content_type+content_type_len, "-source", sizeof("-source"))) { - php_add_filter(r, r->output_filters); - php_add_filter(r, r->input_filters); - } - } -} - -static apr_status_t php_server_context_cleanup(void *data_) -{ - void **data = data_; - *data = NULL; - return APR_SUCCESS; -} - -static int php_post_read_request(request_rec *r) -{ - php_struct *ctx; - - /* Initialize filter context */ - SG(server_context) = ctx = apr_pcalloc(r->pool, sizeof(*ctx)); - - /* register a cleanup so we clear out the SG(server_context) - * after each request. Note: We pass in the pointer to the - * server_context in case this is handled by a different thread. */ - apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), - php_server_context_cleanup, - apr_pool_cleanup_null); - - /* Save the entire request, so we can get the input or output - * filters if we need them. */ - ctx->r = r; - - return OK; -} - -static void php_register_hook(apr_pool_t *p) -{ - ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_insert_filter(php_insert_filter, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE); - ap_register_output_filter("PHP", php_output_filter, php_apache_disable_caching, AP_FTYPE_RESOURCE); - ap_register_input_filter("PHP", php_input_filter, php_apache_disable_caching, AP_FTYPE_RESOURCE); -} - -static size_t php_apache_read_stream(void *handle, char *buf, size_t wantlen) -{ - php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)handle; - apr_bucket_brigade *rbb; - apr_size_t readlen; - apr_bucket *b = NULL; - - rbb = pbb->bb; - - if((apr_brigade_partition(pbb->bb, wantlen, &b) == APR_SUCCESS) && b){ - pbb->bb = apr_brigade_split(rbb, b); - } - - readlen = wantlen; - apr_brigade_flatten(rbb, buf, &readlen); - apr_brigade_cleanup(rbb); - - return readlen; -} - -static size_t php_apache_fsizer_stream(void *handle) -{ - php_apr_bucket_brigade *pbb = (php_apr_bucket_brigade *)handle; - apr_off_t actual = 0; - - if (apr_brigade_length(pbb->bb, 1, &actual) == APR_SUCCESS) { - return actual; - } - - return 0; -} - -AP_MODULE_DECLARE_DATA module php7_module = { - STANDARD20_MODULE_STUFF, - create_php_config, /* create per-directory config structure */ - merge_php_config, /* merge per-directory config structures */ - NULL, /* create per-server config structure */ - NULL, /* merge per-server config structures */ - php_dir_cmds, /* command apr_table_t */ - php_register_hook /* register hooks */ -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c index de7546b5cd496..636eee2d4b410 100644 --- a/sapi/apache2handler/apache_config.c +++ b/sapi/apache2handler/apache_config.c @@ -139,13 +139,6 @@ static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, zval *zv, void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) { php_conf_rec *d = base_conf, *e = new_conf, *n = NULL; -#if STAS_0 - php_dir_entry *pe; - php_dir_entry *data; - char *str; - uint str_len; - ulong num_index; -#endif n = create_php_config(p, "merge_php_config"); /* copy old config */ @@ -155,20 +148,6 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n)); zend_hash_merge_ex(&n->config, &e->config, NULL, should_overwrite_per_dir_entry, NULL); //??? zend_hash_merge_ex(&n->config, &e->config, NULL, sizeof(php_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL); -#if STAS_0 - for (zend_hash_internal_pointer_reset(&d->config); - zend_hash_get_current_key(&d->config, &str, &str_len, - &num_index) == HASH_KEY_IS_STRING; - zend_hash_move_forward(&d->config)) { - pe = NULL; - zend_hash_get_current_data(&d->config, (void **) &data); - if (zend_hash_find(&n->config, str, str_len, (void **) &pe) == SUCCESS) { - if (pe->status >= data->status) continue; - } - phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1)); - zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL); - } -#endif return n; } diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index f5fc78695b1a4..4361b78d333d2 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -220,8 +220,13 @@ php_apache_sapi_get_stat(void) { php_struct *ctx = SG(server_context); +#ifdef PHP_WIN32 + ctx->finfo.st_uid = 0; + ctx->finfo.st_gid = 0; +#else ctx->finfo.st_uid = ctx->r->finfo.user; ctx->finfo.st_gid = ctx->r->finfo.group; +#endif ctx->finfo.st_dev = ctx->r->finfo.device; ctx->finfo.st_ino = ctx->r->finfo.inode; #if defined(NETWARE) && defined(CLIB_STAT_PATCH) @@ -546,7 +551,7 @@ static int php_handler(request_rec *r) request_rec * volatile parent_req = NULL; #ifdef ZTS /* initial resource fetch */ - void ***tsrm_ls = ts_resource(0); + (void)ts_resource(0); ZEND_TSRMLS_CACHE_UPDATE; #endif diff --git a/sapi/apache_hooks/CREDITS b/sapi/apache_hooks/CREDITS deleted file mode 100644 index 86ac27d0b7332..0000000000000 --- a/sapi/apache_hooks/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Apache 1.3 (apache_hooks) -Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar, George Schlossnagle, Lukas Schroeder diff --git a/sapi/apache_hooks/README b/sapi/apache_hooks/README deleted file mode 100644 index 9a5a3e2b64423..0000000000000 --- a/sapi/apache_hooks/README +++ /dev/null @@ -1,206 +0,0 @@ -This is very beta documentation. Clearly better stuff can and will follow. - -INTRO: - -apache_hooks is a full super-set enhancement of the apache 1.3 sapi that allows for -php code to be run on the apache request object at every stage of the apache -request. It supports all of the apache 1.3 sapi commands and configurations, and -additionally supports the following httpd.conf directives: - - -HTTPD.CONF DIRECTIEVS: - -phpRequire /path/to/file = requires a file at the beginning of an -initial apache request - -phpUriHandler /path/to/file = registers a hook that will run the -specified file at the uri translation stage of the apache request -phpUriHandler Class::Method = registers a hook to run Class::Method at -the uri translation stage of the apache request - -phpPostReadHandler /path/to/file = hook for post-read phase -phpPostReadHandlerMethod Class::Method - -phpHeaderHandler = hook for header parsing phase -phpHeaderHandlerMethod - -phpAuthHandler = hook for authentication phase -phpAuthHandlerMethod - -phpAccessHandler = hook for access control phase -phpAccessHandlerMethod - -phpTypeHandler = hook for Type Checking phase -phpTypeHandlerMethod - -phpFixupHandler = hook for 'fixup' phase -phpFixupHandlerMethod - -phpLoggerHandler = hook for logging phase -phpLoggerHandlerMethod - -AddHandler php-script = set's up a special type handler -phpResponseHandler /path/to/file = sets file to be called to handle -response phase -phpResponseHandlerMethod Class::Method - - -All handlers may be stacked, i.e. you can list multiple handler directives -in a single scope and they will be run in order. - - -EXAMPLES: - -So, to set up a 'hello world' location handler (so that any request to -/hello/* returns hello world) you can: - -phpRequire /tmp/setup.php - -AddHandler php-script -phpResponseHandlerMethod Hello::World - - -with -#/tmp/setup.php -send_http_header(); - echo "Hello World"; - } -} -?> - -$request is the apache request. It is instantiated at all stages -automatically. The methods of that class are: - -getallheaders -args -boundary -content_encoding -content_type -filename -handler -hostname -method -path_info -protocol -status_line -the_request -unparsed_uri -uri -allowed -bytes_sent -chunked -content_length -header_only -method_number -mtime -no_cache -no_local_copy -proto_num -proxyreq -read_body -remaining -request_time -status -headers_in -headers_out -err_headers_out -auth_name -auth_type -basic_auth_pw -discard_request_body -is_initial_req -meets_conditions -remote_host -satisfies -server_port -set_etag -set_last_modified -some_auth_required -update_mtime -send_http_header -basic_http_header -send_header_field -send_http_trace -send_http_options -send_error_response -set_content_length -set_keepalive -rputs -log_error -lookup_uri -lookup_file -method_uri -run -internal_redirect - - -These all wrap the ap_* apache EXPORT_API functions using the same -semantics (and are also the same as the Apache::Request methods in -mod_perl if you are familiar with that) - -So, a uri handler to redirect all non-local traffic to /404.php (an -error page) would be - -phpUriHandler /tmp/uri.php - -#/tmp/uri.php -uri('/404.php'); - } - return OK; -?> - -It's important to note that since this is called from the uri -translations phase, this validation is performed for every request to -the server, not just for php pages. - -Also, scope is shared between all the hooks. So in the above, we could -merge the two and do something like: - -#/tmp/uri.php - - -and then: - -#/tmp/setup.php -send_http_header(); - echo "Hello $whoami"; - } -} -?> - -These variables are also in the same scope as a script if your script is -being handled by the standard application/x-httpd-php handler. - -This allows you to make decisions and pass data between your handlers -and scripts at all stages. - -The above are clearly trite examples, but hopefully give you a starting -point. - -One note: all handlers can be validly re-entered 'in sub-requests'. -For this reason you should not define functions/classes here without -anti-redefinition guards (I would just recommend putting them in an -include and using include_one). This is not true for phpRequire, which -is only entered once, at the main request, and so it is safe to make -function/class declarations there (in fact that's what it's for). - -Hope that helps! diff --git a/sapi/apache_hooks/apMakefile.libdir b/sapi/apache_hooks/apMakefile.libdir deleted file mode 100644 index 7b5254013a3b6..0000000000000 --- a/sapi/apache_hooks/apMakefile.libdir +++ /dev/null @@ -1,4 +0,0 @@ -This is a place-holder which indicates to Configure that it shouldn't -provide the default targets when building the Makefile in this directory. -Instead it'll just prepend all the important variable definitions, and -copy the Makefile.tmpl onto the end. diff --git a/sapi/apache_hooks/apMakefile.tmpl b/sapi/apache_hooks/apMakefile.tmpl deleted file mode 100644 index 1e5e465f65882..0000000000000 --- a/sapi/apache_hooks/apMakefile.tmpl +++ /dev/null @@ -1,77 +0,0 @@ -## -## Apache 1.3 Makefile template for PHP 4.0 Module -## [src/modules/php7/Makefile.tmpl] -## - -# the parametrized target -LIB=libphp7.$(LIBEXT) - -# objects for building the static library -OBJS=mod_php7.o -OBJS_LIB=libmodphp7.a - -# objects for building the shared object library -SHLIB_OBJS=mod_php7.so-o -SHLIB_OBJS_LIB=libmodphp7.a - -# the general targets -all: lib -lib: $(LIB) - -# build the static library by merging the object files -libphp7.a: $(OBJS) $(OBJS_LIB) - cp $(OBJS_LIB) $@ - ar r $@ $(OBJS) - $(RANLIB) $@ - -# ugly hack to support older Apache-1.3 betas that don't set $LIBEXT -libphp7.: $(OBJS) $(OBJS_LIB) - cp $(OBJS_LIB) $@ - ar r $@ $(OBJS) - $(RANLIB) $@ - cp libphp7. libphp7.a - -# build the shared object library by linking the object files -libphp7.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) - rm -f $@ - $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(PHP_LIBS) - -# 1. extension .o for shared objects cannot be used here because -# first these files aren't still shared objects and second we -# have to use a different name to trigger the different -# implicit Make rule -# 2. extension -so.o (as used elsewhere) cannot be used because -# the suffix feature of Make really wants just .x, so we use -# extension .so-o -.SUFFIXES: .o .so-o -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< -.c.so-o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< && mv $*.o $*.so-o - -# cleanup -clean: - -rm -f $(OBJS) $(SHLIB_OBJS) $(LIB) - -# We really don't expect end users to use this rule. It works only with -# gcc, and rebuilds Makefile.tmpl. You have to re-run Configure after -# using it. -depend: - cp Makefile.tmpl Makefile.tmpl.bak \ - && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \ - && gcc -MM $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) *.c >> Makefile.new \ - && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' Makefile.new \ - > Makefile.tmpl \ - && rm Makefile.new - -#Dependencies - -$(OBJS): Makefile - -# DO NOT REMOVE -mod_php7.o: mod_php7.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ - $(INCDIR)/buff.h \ - $(INCDIR)/http_config.h \ - $(INCDIR)/http_core.h $(INCDIR)/http_main.h \ - $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \ - $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php7.h diff --git a/sapi/apache_hooks/config.m4 b/sapi/apache_hooks/config.m4 deleted file mode 100644 index a1ee213492fd2..0000000000000 --- a/sapi/apache_hooks/config.m4 +++ /dev/null @@ -1,275 +0,0 @@ -dnl -dnl $Id$ -dnl -AC_DEFUN([PHP_APACHE_FD_CHECK], [ -AC_CACHE_CHECK([for member fd in BUFF *],ac_cv_php_fd_in_buff,[ - save=$CPPFLAGS - if test -n "$APXS_INCLUDEDIR"; then - CPPFLAGS="$CPPFLAGS -I$APXS_INCLUDEDIR" - else - CPPFLAGS="$CPPFLAGS $APACHE_INCLUDE" - fi - AC_TRY_COMPILE([#include ],[conn_rec *c; int fd = c->client->fd;],[ - ac_cv_php_fd_in_buff=yes],[ac_cv_php_fd_in_buff=no],[ac_cv_php_fd_in_buff=no]) - CPPFLAGS=$save -]) -if test "$ac_cv_php_fd_in_buff" = "yes"; then - AC_DEFINE(PHP_APACHE_HAVE_CLIENT_FD,1,[ ]) -fi -]) - -dnl Apache 1.x shared module -PHP_ARG_WITH(apache-hooks,, -[ --with-apache-hooks[=FILE] - EXPERIMENTAL: Build shared Apache 1.x module. FILE is the optional - pathname to the Apache apxs tool [apxs]], no, no) - -AC_MSG_CHECKING([for Apache 1.x (hooks) module support via DSO through APXS]) - -if test "$PHP_APACHE_HOOKS" != "no"; then - if test "$PHP_APACHE_HOOKS" = "yes"; then - APXS=apxs - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0" && test -x /usr/sbin/apxs; then #SUSE 6.x - APXS=/usr/sbin/apxs - fi - else - PHP_EXPAND_PATH($PHP_APACHE_HOOKS, APXS) - fi - - $APXS -q CFLAGS >/dev/null 2>&1 - if test "$?" != "0"; then - AC_MSG_RESULT() - AC_MSG_RESULT() - AC_MSG_RESULT([Sorry, I was not able to successfully run APXS. Possible reasons:]) - AC_MSG_RESULT() - AC_MSG_RESULT([1. Perl is not installed;]) - AC_MSG_RESULT([2. Apache was not compiled with DSO support (--enable-module=so);]) - AC_MSG_RESULT([3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs]) - AC_MSG_RESULT([The output of $APXS follows]) - $APXS -q CFLAGS - AC_MSG_ERROR([Aborting]) - fi - - APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@" - APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` - APXS_CFLAGS=`$APXS -q CFLAGS` - APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET` - APACHE_INCLUDE=-I$APXS_INCLUDEDIR - - # Test that we're trying to configure with apache 1.x - PHP_AP_EXTRACT_VERSION($APXS_HTTPD) - if test "$APACHE_VERSION" -ge 2000000; then - AC_MSG_ERROR([You have enabled Apache 1.3 support while your server is Apache 2. Please use the appropriate switch --with-apxs2]) - fi - - for flag in $APXS_CFLAGS; do - case $flag in - -D*) APACHE_CPPFLAGS="$APACHE_CPPFLAGS $flag";; - esac - done - - case $host_alias in - *aix*) - APXS_LIBEXECDIR=`$APXS -q LIBEXECDIR` - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp" - PHP_AIX_LDFLAGS="-Wl,-brtl" - build_type=shared - ;; - *darwin*) - MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD" - PHP_SUBST(MH_BUNDLE_FLAGS) - SAPI_SHARED=libs/libphp7.so - build_type=bundle - ;; - *) - build_type=shared - ;; - esac - - PHP_SELECT_SAPI(apache_hooks, $build_type, sapi_apache.c mod_php7.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) - - # Test whether apxs support -S option - $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1 - - if test "$?" != "0"; then - APACHE_HOOKS_INSTALL="$APXS -i -a -n php7 $SAPI_SHARED" # Old apxs does not have -S option - else - APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` - if test -z `$APXS -q SYSCONFDIR`; then - APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -i -n php7 $SAPI_SHARED" - else - APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` - APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ - \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ - $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ - -S SYSCONFDIR='$APXS_SYSCONFDIR' \ - -i -a -n php7 $SAPI_SHARED" - fi - fi - - if test -z "`$APXS -q LD_SHLIB`" || test "`$APXS -q LIBEXECDIR`" = "modules"; then - PHP_APXS_BROKEN=yes - fi - STRONGHOLD= - AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) - AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ]) - AC_DEFINE(HAVE_APACHE_HOOKS,1,[ ]) - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi - -dnl Apache 1.x static module -PHP_ARG_WITH(apache-hooks-static,, -[ --with-apache-hooks-static[=DIR] - EXPERIMENTAL: Build Apache 1.x module. DIR is the top-level Apache - build directory [/usr/local/apache]], no, no) - -AC_MSG_CHECKING(for Apache 1.x (hooks) module support) - -if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$PHP_APACHE_HOOKS_STATIC" != "no"; then - - if test "$PHP_APACHE_HOOKS_STATIC" = "yes"; then - # Apache's default directory - PHP_APACHE_HOOKS_STATIC=/usr/local/apache - fi - - APACHE_HOOKS_INSTALL_FILES="\$(srcdir)/sapi/apache_hooks/mod_php7.* sapi/apache_hooks/libphp7.module" - - AC_DEFINE(HAVE_APACHE,1,[ ]) - APACHE_HOOKS_MODULE=yes - PHP_EXPAND_PATH($PHP_APACHE_HOOKS_STATIC, PHP_APACHE_HOOKS_STATIC) - # For Apache 1.2.x - if test -f $PHP_APACHE_HOOKS_STATIC/src/httpd.h; then - APACHE_INCLUDE=-I$PHP_APACHE_HOOKS_STATIC/src - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET" - PHP_LIBS="-L. -lphp3" - AC_MSG_RESULT([yes - Apache 1.2.x]) - STRONGHOLD= - if test -f $PHP_APACHE_HOOKS_STATIC/src/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) - fi - # For Apache 2.0.x - elif test -f $PHP_APACHE_HOOKS_STATIC/include/httpd.h && test -f $PHP_APACHE_HOOKS_STATIC/srclib/apr/include/apr_general.h ; then - AC_MSG_ERROR([Use --with-apxs2 with Apache 2.x!]) - # For Apache 1.3.x - elif test -f $PHP_APACHE_HOOKS_STATIC/src/main/httpd.h; then - APACHE_HAS_REGEX=1 - APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/main -I$PHP_APACHE_HOOKS_STATIC/src/os/unix -I$PHP_APACHE_HOOKS_STATIC/src/ap" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php7 - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - AC_MSG_RESULT([yes - Apache 1.3.x]) - STRONGHOLD= - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - # Also for Apache 1.3.x - elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/httpd.h; then - APACHE_HAS_REGEX=1 - APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/include -I$PHP_APACHE_HOOKS_STATIC/src/os/unix" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php7 - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - AC_MSG_RESULT([yes - Apache 1.3.x]) - STRONGHOLD= - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - # For StrongHold 2.2 - elif test -f $PHP_APACHE_HOOKS_STATIC/apache/httpd.h; then - APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/apache -I$PHP_APACHE_HOOKS_STATIC/ssl/include" - APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/apache - PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php7.c php_apache.c, $APACHE_INCLUDE) - PHP_LIBS="-Lmodules/php7 -L../modules/php7 -L../../modules/php7 -lmodphp7" - APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp7.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET" - STRONGHOLD=-DSTRONGHOLD=1 - AC_MSG_RESULT([yes - StrongHold]) - if test -f $PHP_APACHE_HOOKS_STATIC/apache/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) - fi - if test -f $PHP_APACHE_HOOKS_STATIC/src/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) - if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then - AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) - fi - elif test -f $PHP_APACHE_HOOKS_STATIC/src/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) - fi - else - AC_MSG_RESULT(no) - AC_MSG_ERROR([Invalid Apache directory - unable to find httpd.h under $PHP_APACHE_HOOKS_STATIC]) - fi -else - AC_MSG_RESULT(no) -fi - -# compatibility -if test -z "$enable_mod_charset" && test "$with_mod_charset"; then - enable_mod_charset=$with_mod_charset -fi - -PHP_ARG_ENABLE(mod-charset, whether to enable Apache charset compatibility option, -[ --enable-mod-charset APACHE (hooks): Enable transfer tables for mod_charset (Rus Apache)], no, no) - -if test "$PHP_MOD_CHARSET" = "yes"; then - AC_DEFINE(USE_TRANSFER_TABLES, 1, [ ]) -fi - -dnl Build as static module -if test "$APACHE_HOOKS_MODULE" = "yes"; then - PHP_TARGET_RDYNAMIC - $php_shtool mkdir -p sapi/apache_hooks - PHP_OUTPUT(sapi/apache_hooks/libphp7.module) -fi - -dnl General -if test -n "$APACHE_HOOKS_INSTALL"; then - if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then - APXS_EXP=-bE:sapi/apache_hooks/mod_php7.exp - fi - - PHP_APACHE_FD_CHECK - INSTALL_IT=$APACHE_HOOKS_INSTALL - - PHP_SUBST(APXS_EXP) - PHP_SUBST(APACHE_INCLUDE) - PHP_SUBST(APACHE_TARGET) - PHP_SUBST(APXS) - PHP_SUBST(APXS_LDFLAGS) - PHP_SUBST(APACHE_HOOKS_INSTALL) - PHP_SUBST(STRONGHOLD) -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/apache_hooks/config.w32 b/sapi/apache_hooks/config.w32 deleted file mode 100644 index 1c9129e615509..0000000000000 --- a/sapi/apache_hooks/config.w32 +++ /dev/null @@ -1,21 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_WITH('apache-hooks', 'Build Apache 1.3.x (hooks) version of PHP', 'no'); - -if (PHP_APACHE_HOOKS != "no") { - if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE_HOOKS", php_usual_include_suspects + - ";" + PROGRAM_FILES + "\\Apache Group\\Apache\\include" + - ";" + PHP_PHP_BUILD + "\\apache\\src\\include") && - CHECK_LIB("ApacheCore.lib", "apache_hooks", php_usual_lib_suspects + - ';' + PROGRAM_FILES + '\\Apache Group\\Apache\\libexec' + - ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) { - // We need to play tricks to get our readdir.h used by apache - // headers - SAPI('apache_hooks', 'mod_php7.c sapi_apache.c php_apache.c', - 'php' + PHP_VERSION + 'apache_hooks.dll', - '/D APACHEPHP7_EXPORTS /D APACHE_READDIR_H /I win32'); - } else { - WARNING("Could not find apache libraries/headers"); - } -} diff --git a/sapi/apache_hooks/libphp7.module.in b/sapi/apache_hooks/libphp7.module.in deleted file mode 100644 index 5bea79ef950a6..0000000000000 --- a/sapi/apache_hooks/libphp7.module.in +++ /dev/null @@ -1,11 +0,0 @@ -Name: php7_module -ConfigStart - RULE_WANTHSREGEX=no - RULE_HIDE=yes - PHP_LIBS="@NATIVE_RPATHS@ @PHP_LDFLAGS@ @PHP_LIBS@ @EXTRA_LIBS@ $LIBS" - PHP_CFLAGS="$CFLAGS @OPENSSL_INCDIR_OPT@ -I@php_abs_top_builddir@/main -I@php_abs_top_builddir@/Zend -I@php_abs_top_builddir@/TSRM -I@php_abs_top_srcdir@ -I@php_abs_top_srcdir@/sapi/apache -I@php_abs_top_srcdir@/main -I@php_abs_top_srcdir@/Zend -I@php_abs_top_srcdir@/TSRM" - my_outfile="Makefile.config" - echo "PHP_CFLAGS=$PHP_CFLAGS" >>$my_outfile - echo "PHP_LIBS=$PHP_LIBS" >>$my_outfile - LIBS=$PHP_LIBS -ConfigEnd diff --git a/sapi/apache_hooks/mod_php7.c b/sapi/apache_hooks/mod_php7.c deleted file mode 100644 index 6eb15f3ef8d7f..0000000000000 --- a/sapi/apache_hooks/mod_php7.c +++ /dev/null @@ -1,1478 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf | - | (with helpful hints from Dean Gaudet | - | PHP 4.0 patches by Zeev Suraski | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -#ifdef NETWARE -#define SIGPIPE SIGINT -#endif - -#undef shutdown - -/* {{{ Prototypes - */ -int apache_php_module_main(request_rec *r, int display_source_mode); -static void php_save_umask(void); -static void php_restore_umask(void); -static int sapi_apache_read_post(char *buffer, uint count_bytes); -static char *sapi_apache_read_cookies(void); -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers); -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers); -static int send_php(request_rec *r, int display_source_mode, char *filename); -static int send_parsed_php(request_rec * r); -static int send_parsed_php_source(request_rec * r); -static int php_xbithack_handler(request_rec * r); -static void php_init_handler(server_rec *s, pool *p); -/* }}} */ - -#if MODULE_MAGIC_NUMBER >= 19970728 -static void php_child_exit_handler(server_rec *s, pool *p); -#endif - -#if MODULE_MAGIC_NUMBER > 19961007 -#define CONST_PREFIX const -#else -#define CONST_PREFIX -#endif - - -typedef struct _sapi_stack { - int top, max, persistent; - void **elements; -} sapi_stack; - -typedef struct _php_per_dir_config { - HashTable *ini_settings; - sapi_stack headers_handlers; - sapi_stack auth_handlers; - sapi_stack access_handlers; - sapi_stack type_handlers; - sapi_stack fixup_handlers; - sapi_stack logger_handlers; - sapi_stack post_read_handlers; - sapi_stack response_handlers; -} php_per_dir_config; - -typedef struct _php_per_server_config { - sapi_stack uri_handlers; - sapi_stack requires; -} php_per_server_config; - - -static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); -static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); -static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); -static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2); - -/* ### these should be defined in mod_php7.h or somewhere else */ -#define USE_PATH 1 -#define IGNORE_URL 2 - -module MODULE_VAR_EXPORT php7_module; - -int saved_umask; -/* static int setup_env = 0; */ -static unsigned char apache_php_initialized; - -typedef struct _php_per_dir_entry { - char *key; - char *value; - uint key_length; - uint value_length; - int type; -} php_per_dir_entry; - -/* some systems are missing these from their header files */ - -/* {{{ zend stack utility functions - */ - -/* This code is ripped part and parcel from zend_stack.[ch]. Assuming that the - patch supporting zend_stack_init_ex is applied, all but the bottom two - module-specific iterators will be removed - */ - -int sapi_stack_init_ex(sapi_stack *stack, int persistent) -{ - stack->top = 0; - stack->persistent = persistent; - stack->elements = (void **) pemalloc(sizeof(void **) * STACK_BLOCK_SIZE, persistent); - if (!stack->elements) { - return FAILURE; - } else { - stack->max = STACK_BLOCK_SIZE; - return SUCCESS; - } -} -int sapi_stack_push(sapi_stack *stack, void *element) -{ - if (stack->top >= stack->max) { /* we need to allocate more memory */ - stack->elements = (void **) perealloc(stack->elements, - (sizeof(void **) * (stack->max += STACK_BLOCK_SIZE)), stack->persistent); - if (!stack->elements) { - return FAILURE; - } - } - stack->elements[stack->top] = (void *) element; - return stack->top++; -} -void* sapi_stack_pop(sapi_stack *stack) { - if(stack->top == 0) { - return NULL; - } - else { - return stack->elements[--stack->top]; - } -} - -int sapi_stack_destroy(sapi_stack *stack) -{ - return SUCCESS; -} - -int sapi_stack_apply_with_argument_all(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg) -{ - int i, retval; - - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - retval = apply_function(stack->elements[i], arg); - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; itop; i++) { - retval = apply_function(stack->elements[i], arg); - } - break; - } - return retval; -} - - -int sapi_stack_apply_with_argument_stop_if_equals(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg, int stopval) -{ - int i; - int ret = DECLINED; - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - if ((ret = apply_function(stack->elements[i], arg)) == stopval) { - break; - } - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; itop; i++) { - if ((ret = apply_function(stack->elements[i], arg)) == stopval) { - break; - } - } - break; - } - return ret; -} - -int sapi_stack_apply_with_argument_stop_if_http_error(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg) -{ - int i; - int ret = DECLINED; - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - if ((ret = apply_function(stack->elements[i], arg)) > 0) { - break; - } - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; itop; i++) { - if ((ret = apply_function(stack->elements[i], arg)) > 0) { - break; - } - } - break; - } - return ret; -} - -void php_handler_stack_destroy(sapi_stack *stack) -{ - php_handler *ph; - while((ph = (php_handler *)sapi_stack_pop(stack)) != NULL) { - free(ph->name); - free(ph); - } -} -/* }}} */ - -/* {{{ php_save_umask - */ -static void php_save_umask(void) -{ - saved_umask = umask(077); - umask(saved_umask); -} -/* }}} */ - -/* {{{ sapi_apache_ub_write - */ -static int sapi_apache_ub_write(const char *str, uint str_length) -{ - int ret=0; - - if (SG(server_context)) { - ret = rwrite(str, str_length, (request_rec *) SG(server_context)); - } - if (ret != str_length) { - php_handle_aborted_connection(); - } - return ret; -} -/* }}} */ - -/* {{{ sapi_apache_flush - */ -static void sapi_apache_flush(void *server_context) -{ - if (server_context) { -#if MODULE_MAGIC_NUMBER > 19970110 - rflush((request_rec *) server_context); -#else - bflush((request_rec *) server_context->connection->client); -#endif - } -} -/* }}} */ - -/* {{{ sapi_apache_read_post - */ -static int sapi_apache_read_post(char *buffer, uint count_bytes) -{ - uint total_read_bytes=0, read_bytes; - request_rec *r = (request_rec *) SG(server_context); - void (*handler)(int); - - /* - * This handles the situation where the browser sends a Expect: 100-continue header - * and needs to receive confirmation from the server on whether or not it can send - * the rest of the request. RFC 2616 - * - */ - if (!SG(read_post_bytes) && !ap_should_client_block(r)) { - return total_read_bytes; - } - - handler = signal(SIGPIPE, SIG_IGN); - while (total_read_bytessubprocess_env, "HTTP_COOKIE"); -} -/* }}} */ - -/* {{{ sapi_apache_header_handler - */ -static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content, *p; - request_rec *r = (request_rec *) SG(server_context); - if(!r) { - return 0; - } - - switch(op) { - case SAPI_HEADER_DELETE_ALL: - clear_table(r->headers_out); - return 0; - - case SAPI_HEADER_DELETE: - table_unset(r->headers_out, sapi_header->header); - return 0; - - case SAPI_HEADER_ADD: - case SAPI_HEADER_REPLACE: - header_name = sapi_header->header; - - header_content = p = strchr(header_name, ':'); - if (!p) { - return 0; - } - - *p = 0; - do { - header_content++; - } while (*header_content==' '); - - if (!strcasecmp(header_name, "Content-Type")) { - r->content_type = pstrdup(r->pool, header_content); - } else if (!strcasecmp(header_name, "Set-Cookie")) { - table_add(r->headers_out, header_name, header_content); - } else if (op == SAPI_HEADER_REPLACE) { - table_set(r->headers_out, header_name, header_content); - } else { - table_add(r->headers_out, header_name, header_content); - } - - *p = ':'; /* a well behaved header handler shouldn't change its original arguments */ - - return SAPI_HEADER_ADD; - - default: - return 0; - } -} -/* }}} */ - -/* {{{ sapi_apache_send_headers - */ -static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers) -{ - if(SG(server_context) == NULL) { /* server_context is not here anymore */ - return SAPI_HEADER_SEND_FAILED; - } - - ((request_rec *) SG(server_context))->status = SG(sapi_headers).http_response_code; - /* check that we haven't sent headers already, we use our own - * headers_sent since we may send headers at anytime - */ - if(!AP(headers_sent)) { - send_http_header((request_rec *) SG(server_context)); - AP(headers_sent) = 1; - } - return SAPI_HEADER_SENT_SUCCESSFULLY; -} -/* }}} */ - -/* {{{ sapi_apache_register_server_variables - */ -static void sapi_apache_register_server_variables(zval *track_vars_array) -{ - register int i; - array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env); - table_entry *elts = (table_entry *) arr->elts; - zval **path_translated; - HashTable *symbol_table; - - for (i = 0; i < arr->nelts; i++) { - char *val; - - if (elts[i].val) { - val = elts[i].val; - } else { - val = ""; - } - php_register_variable(elts[i].key, val, track_vars_array ); - } - - /* If PATH_TRANSLATED doesn't exist, copy it from SCRIPT_FILENAME */ - if (track_vars_array) { - symbol_table = track_vars_array->value.ht; - } else { - symbol_table = NULL; - } - if (symbol_table - && !zend_hash_exists(symbol_table, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED")) - && zend_hash_find(symbol_table, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &path_translated)==SUCCESS) { - php_register_variable("PATH_TRANSLATED", Z_STRVAL_PP(path_translated), track_vars_array); - } - - php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array); -} -/* }}} */ - -/* {{{ php_apache_startup - */ -static int php_apache_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &apache_module_entry, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} -/* }}} */ - -/* {{{ php_apache_log_message - */ -static void php_apache_log_message(char *message) -{ - if (SG(server_context)) { -#if MODULE_MAGIC_NUMBER >= 19970831 - aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message); -#else - log_error(message, ((request_rec *) SG(server_context))->server); -#endif - } else { - fprintf(stderr, "%s", message); - fprintf(stderr, "\n"); - } -} -/* }}} */ - -/* {{{ php_apache_request_shutdown - */ -static void php_apache_request_shutdown(void *dummy) -{ - AP(current_hook) = AP_CLEANUP; - php_output_set_status(PHP_OUTPUT_DISABLED); - SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */ - if(SG(sapi_started)) { - php_request_shutdown(dummy); - SG(sapi_started) = 0; - } - AP(in_request) = 0; - if(AP(setup_env)) { - AP(setup_env) = 0; - } - AP(current_hook) = AP_WAITING_FOR_REQUEST; - AP(headers_sent) = 0; -} -/* }}} */ - -/* {{{ php_apache_sapi_activate - */ -static int php_apache_sapi_activate(void) -{ - request_rec *r = (request_rec *) SG(server_context); - - /* - * For the Apache module version, this bit of code registers a cleanup - * function that gets triggered when our request pool is destroyed. - * We need this because at any point in our code we can be interrupted - * and that may happen before we have had time to free our memory. - * The php_request_shutdown function needs to free all outstanding allocated - * memory. - */ - block_alarms(); - register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec); - AP(in_request)=1; - unblock_alarms(); - - /* Override the default headers_only value - sometimes "GET" requests should actually only - * send headers. - */ - SG(request_info).headers_only = r->header_only; - return SUCCESS; -} -/* }}} */ - -/* {{{ php_apache_get_stat - */ -static struct stat *php_apache_get_stat(void) -{ - return &((request_rec *) SG(server_context))->finfo; -} -/* }}} */ - -/* {{{ php_apache_getenv - */ -static char *php_apache_getenv(char *name, size_t name_len) -{ - return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name); -} -/* }}} */ - -/* {{{ sapi_module_struct apache_sapi_module - */ -static sapi_module_struct apache_sapi_module = { - "apache", /* name */ - "Apache", /* pretty name */ - - php_apache_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - php_apache_sapi_activate, /* activate */ - NULL, /* deactivate */ - - sapi_apache_ub_write, /* unbuffered write */ - sapi_apache_flush, /* flush */ - php_apache_get_stat, /* get uid */ - php_apache_getenv, /* getenv */ - - php_error, /* error handler */ - - sapi_apache_header_handler, /* header handler */ - sapi_apache_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_apache_read_post, /* read POST data */ - sapi_apache_read_cookies, /* read Cookies */ - - sapi_apache_register_server_variables, /* register server variables */ - php_apache_log_message, /* Log message */ - NULL, /* Get request time */ - NULL, /* child terminate */ - - NULL, /* php.ini path override */ - -#ifdef PHP_WIN32 - NULL, - NULL, -#else - block_alarms, /* Block interruptions */ - unblock_alarms, /* Unblock interruptions */ -#endif - - NULL, /* default post reader */ - NULL, /* treat data */ - NULL, /* exe location */ - 0, /* ini ignore */ - NULL - -}; -/* }}} */ - -/* {{{ php_restore_umask - */ -static void php_restore_umask(void) -{ - umask(saved_umask); -} -/* }}} */ - -/* {{{ init_request_info - */ -static void init_request_info(void) -{ - request_rec *r = ((request_rec *) SG(server_context)); - char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH"); - const char *authorization=NULL; - char *tmp, *tmp_user; - - SG(request_info).query_string = r->args; - SG(request_info).path_translated = r->filename; - SG(request_info).request_uri = r->uri; - SG(request_info).request_method = (char *)r->method; - SG(request_info).proto_num = r->proto_num; - SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE"); - SG(request_info).content_length = (content_length ? atol(content_length) : 0); - SG(sapi_headers).http_response_code = r->status; - - if (r->headers_in) { - authorization = table_get(r->headers_in, "Authorization"); - } - - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - - if (authorization && !auth_type(r)) { - if (!strcasecmp(getword(r->pool, &authorization, ' '), "Basic")) { - tmp = uudecode(r->pool, authorization); - tmp_user = getword_nulls_nc(r->pool, &tmp, ':'); - if (tmp_user) { - r->connection->user = pstrdup(r->connection->pool, tmp_user); - r->connection->ap_auth_type = "Basic"; - SG(request_info).auth_user = estrdup(tmp_user); - } - if (tmp) { - SG(request_info).auth_password = estrdup(tmp); - } - } else if (!strcasecmp(getword(r->pool, &authorization, ' '), "Digest")) { - r->connection->ap_auth_type = "Digest"; - SG(request_info).auth_digest = estrdup(authorization); - } - } -} -/* }}} */ - -/* {{{ php_apache_alter_ini_entries - */ -static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry) -{ - zend_alter_ini_entry(per_dir_entry->key, per_dir_entry->key_length+1, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, PHP_INI_STAGE_ACTIVATE); - return 0; -} -/* }}} */ - -/* {{{ php_apache_get_default_mimetype - */ -static char *php_apache_get_default_mimetype(request_rec *r) -{ - - char *mimetype; - if (SG(default_mimetype) || SG(default_charset)) { - /* Assume output will be of the default MIME type. Individual - scripts may change this later. */ - char *tmpmimetype; - tmpmimetype = sapi_get_default_content_type(); - mimetype = pstrdup(r->pool, tmpmimetype); - efree(tmpmimetype); - } else { - mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET; - } - return mimetype; -} -/* }}} */ - -/* {{{ send_php - */ -static int send_php(request_rec *r, int display_source_mode, char *filename) -{ - int retval; - php_per_dir_config *per_dir_conf; - if (AP(in_request)) { - zend_file_handle fh; - - fh.filename = r->filename; - fh.opened_path = NULL; - fh.free_filename = 0; - fh.type = ZEND_HANDLE_FILENAME; - - zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &fh); - return OK; - } - - zend_first_try { - - /* Make sure file exists */ - if (filename == NULL && r->finfo.st_mode == 0) { - return DECLINED; - } - - per_dir_conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - if (per_dir_conf) { - zend_hash_apply((HashTable *) per_dir_conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); - } - - /* If PHP parser engine has been turned off with an "engine off" - * directive, then decline to handle this request - */ - if (!AP(engine)) { - r->content_type = php_apache_get_default_mimetype(r); - r->allowed |= (1 << METHODS) - 1; - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return DECLINED; - } - if (filename == NULL) { - filename = r->filename; - } - - /* Apache 1.2 has a more complex mechanism for reading POST data */ -#if MODULE_MAGIC_NUMBER > 19961007 - if ((retval = setup_client_block(r, REQUEST_CHUNKED_ERROR))) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return retval; - } -#endif - - if (AP(last_modified)) { -#if MODULE_MAGIC_NUMBER < 19970912 - if ((retval = set_last_modified(r, r->finfo.st_mtime))) { - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return retval; - } -#else - update_mtime (r, r->finfo.st_mtime); - set_last_modified(r); - set_etag(r); -#endif - } - /* Assume output will be of the default MIME type. Individual - scripts may change this later in the request. */ - r->content_type = php_apache_get_default_mimetype(r); - - /* Init timeout */ - hard_timeout("send", r); - - SG(server_context) = r; - - php_save_umask(); - if(!AP(setup_env)) { - AP(setup_env) = 1; - add_common_vars(r); - add_cgi_vars(r); - } - init_request_info(); - apache_php_module_main(r, display_source_mode); - - /* Done, restore umask, turn off timeout, close file and return */ - php_restore_umask(); - kill_timeout(r); - } zend_end_try(); - - return OK; -} -/* }}} */ - -/* {{{ send_parsed_php - */ -static int send_parsed_php(request_rec * r) -{ - int result = send_php(r, 0, NULL); - - ap_table_setn(r->notes, "mod_php_memory_usage", - ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1))); - - return result; -} -/* }}} */ - -/* {{{ send_parsed_php_source - */ -static int send_parsed_php_source(request_rec * r) -{ - return send_php(r, 1, NULL); -} -/* }}} */ - - -/* {{{ destroy_per_dir_entry - */ -static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry) -{ - free(per_dir_entry->key); - free(per_dir_entry->value); -} -/* }}} */ - -/* {{{ copy_per_dir_entry - */ -static void copy_per_dir_entry(php_per_dir_entry *per_dir_entry) -{ - php_per_dir_entry tmp = *per_dir_entry; - - per_dir_entry->key = (char *) malloc(tmp.key_length+1); - memcpy(per_dir_entry->key, tmp.key, tmp.key_length); - per_dir_entry->key[per_dir_entry->key_length] = 0; - - per_dir_entry->value = (char *) malloc(tmp.value_length+1); - memcpy(per_dir_entry->value, tmp.value, tmp.value_length); - per_dir_entry->value[per_dir_entry->value_length] = 0; -} -/* }}} */ - -/* {{{ should_overwrite_per_dir_entry; - - */ -static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_per_dir_entry *orig_per_dir_entry, zend_hash_key *hash_key, void *pData) -{ - php_per_dir_entry *new_per_dir_entry; - - if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &new_per_dir_entry)==FAILURE) { - return 1; /* does not exist in dest, copy from source */ - } - - if (new_per_dir_entry->type==PHP_INI_SYSTEM - && orig_per_dir_entry->type!=PHP_INI_SYSTEM) { - return 1; - } else { - return 0; - } -} -/* }}} */ -/* {{{ php_destroy_per_server_info - */ -static void php_destroy_per_server_info(php_per_server_config *conf) -{ - php_handler_stack_destroy(&conf->requires); - php_handler_stack_destroy(&conf->uri_handlers); -} -/* }}} */ - -/* {{{ php_destroy_per_dir_info - */ -static void php_destroy_per_dir_info(php_per_dir_config *conf) -{ - zend_hash_destroy(conf->ini_settings); - php_handler_stack_destroy(&conf->response_handlers); - php_handler_stack_destroy(&conf->auth_handlers); - php_handler_stack_destroy(&conf->access_handlers); - php_handler_stack_destroy(&conf->type_handlers); - php_handler_stack_destroy(&conf->fixup_handlers); - php_handler_stack_destroy(&conf->logger_handlers); - php_handler_stack_destroy(&conf->post_read_handlers); - php_handler_stack_destroy(&conf->headers_handlers); - free(conf->ini_settings); -} -/* }}} */ - -/* {{{ php_create_server - */ -static void *php_create_server(pool *p, char *dummy) -{ - php_per_server_config *conf; - conf = (php_per_server_config *) malloc(sizeof(php_per_server_config)); - register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_server_info, (void (*)(void *)) php_destroy_per_server_info); - - sapi_stack_init_ex(&conf->requires, 1); - sapi_stack_init_ex(&conf->uri_handlers, 1); - return conf; -} - -/* }}} */ - - -/* {{{ php_create_dir - */ -static void *php_create_dir(pool *p, char *dummy) -{ - php_per_dir_config *conf; - conf = (php_per_dir_config *) malloc(sizeof(php_per_dir_config)); - conf->ini_settings = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(conf->ini_settings, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1, 0); - sapi_stack_init_ex(&conf->response_handlers, 1); - sapi_stack_init_ex(&conf->headers_handlers, 1); - sapi_stack_init_ex(&conf->auth_handlers, 1); - sapi_stack_init_ex(&conf->access_handlers, 1); - sapi_stack_init_ex(&conf->type_handlers, 1); - sapi_stack_init_ex(&conf->fixup_handlers, 1); - sapi_stack_init_ex(&conf->logger_handlers, 1); - sapi_stack_init_ex(&conf->post_read_handlers, 1); - register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) php_destroy_per_dir_info); - - return conf; -} - -/* }}} */ - -/* {{{ php_merge_dir - */ -static void *php_merge_dir(pool *p, void *basev, void *addv) -{ - php_per_dir_config *a = (php_per_dir_config *) addv; - php_per_dir_config *b = (php_per_dir_config *) basev; - /* This function *must* return addv, and not modify basev */ - zend_hash_merge_ex((HashTable *) a->ini_settings, (HashTable *) b->ini_settings, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL); - a->headers_handlers = (a->headers_handlers.top)?a->headers_handlers:b->headers_handlers; - a->auth_handlers = (a->auth_handlers.top)?a->auth_handlers:b->auth_handlers; - a->access_handlers = (a->access_handlers.top)?a->access_handlers:b->access_handlers; - a->type_handlers = (a->type_handlers.top)?a->type_handlers:b->type_handlers; - a->fixup_handlers = (a->fixup_handlers.top)?a->fixup_handlers:b->fixup_handlers; - a->logger_handlers = (a->logger_handlers.top)?a->logger_handlers:b->logger_handlers; - a->post_read_handlers = (a->post_read_handlers.top)?a->post_read_handlers:b->post_read_handlers; - a->response_handlers = (a->response_handlers.top)?a->response_handlers:b->response_handlers; - return a; -} -/* }}} */ - -/* {{{ php_apache_value_handler_ex - */ -static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) -{ - php_per_dir_entry per_dir_entry; - - if (!apache_php_initialized) { - apache_php_initialized = 1; -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache_sapi_module); - php_apache_startup(&apache_sapi_module); - } - per_dir_entry.type = mode; - - if (strcasecmp(arg2, "none") == 0) { - arg2 = ""; - } - - per_dir_entry.key_length = strlen(arg1); - per_dir_entry.value_length = strlen(arg2); - - per_dir_entry.key = (char *) malloc(per_dir_entry.key_length+1); - memcpy(per_dir_entry.key, arg1, per_dir_entry.key_length); - per_dir_entry.key[per_dir_entry.key_length] = 0; - - per_dir_entry.value = (char *) malloc(per_dir_entry.value_length+1); - memcpy(per_dir_entry.value, arg2, per_dir_entry.value_length); - per_dir_entry.value[per_dir_entry.value_length] = 0; - - zend_hash_update(conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry), NULL); - return NULL; -} -/* }}} */ - -static CONST_PREFIX char *php_set_server_handler(server_rec *s, char *arg1, long handler_stage, long handler_type) -{ - php_per_server_config *conf; - php_handler *handler; - handler = (php_handler *) malloc(sizeof(php_handler)); - handler->type = handler_type; - handler->stage = handler_stage; - handler->name = strdup(arg1); - conf = get_module_config(s->module_config, &php7_module); - switch(handler_stage) { - case AP_URI_TRANS: - sapi_stack_push(&conf->uri_handlers, handler); - break; - default: - sapi_stack_push(&conf->requires, handler); - break; - } - return NULL; -} - -static CONST_PREFIX char *php_set_dir_handler(php_per_dir_config *conf, char *arg1, long handler_stage, long handler_type) -{ - php_handler *handler; - handler = (php_handler *) malloc(sizeof(php_handler)); - handler->type = handler_type; - handler->stage = handler_stage; - handler->name = strdup(arg1); - switch(handler_stage) { - case AP_POST_READ: - sapi_stack_push(&conf->post_read_handlers, handler); - break; - case AP_HEADER_PARSE: - sapi_stack_push(&conf->headers_handlers, handler); - break; - case AP_ACCESS_CONTROL: - sapi_stack_push(&conf->access_handlers, handler); - break; - case AP_AUTHENTICATION: - sapi_stack_push(&conf->auth_handlers, handler); - break; - case AP_AUTHORIZATION: - break; - case AP_TYPE_CHECKING: - sapi_stack_push(&conf->type_handlers, handler); - break; - case AP_FIXUP: - sapi_stack_push(&conf->fixup_handlers, handler); - break; - case AP_RESPONSE: - sapi_stack_push(&conf->response_handlers, handler); - break; - case AP_LOGGING: - sapi_stack_push(&conf->logger_handlers, handler); - break; - default: - break; - } - return NULL; -} - -/* {{{ php_set_uri_handler - */ -static CONST_PREFIX char *php_set_uri_handler(cmd_parms *cmd, void *dummy, char *arg1) -{ - return php_set_server_handler(cmd->server, arg1, AP_URI_TRANS, AP_HANDLER_TYPE_FILE); -} -/* }}} */ - -/* {{{ php_set_uri_handler_code */ -static CONST_PREFIX char *php_set_uri_handler_code(cmd_parms *cmd, void *dummy, char *arg1) -{ - return php_set_server_handler(cmd->server, arg1, AP_URI_TRANS, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_set_header_handler - */ -static CONST_PREFIX char *php_set_header_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_HEADER_PARSE, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_header_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_HEADER_PARSE, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_set_auth_handler - */ -static CONST_PREFIX char *php_set_auth_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_AUTHENTICATION, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_auth_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_AUTHENTICATION, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_access_handler - */ -static CONST_PREFIX char *php_set_access_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_ACCESS_CONTROL, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_access_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_ACCESS_CONTROL, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_type_handler - */ -static CONST_PREFIX char *php_set_type_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_TYPE_CHECKING, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_type_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_TYPE_CHECKING, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_fixup_handler - */ -static CONST_PREFIX char *php_set_fixup_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_FIXUP, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_fixup_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_FIXUP, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_set_logger_handler - */ -static CONST_PREFIX char *php_set_logger_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_LOGGING, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_logger_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_LOGGING, AP_HANDLER_TYPE_METHOD); -} - -/* }}} */ - -/* {{{ php_set_post_read_handler - */ -static CONST_PREFIX char *php_set_post_read_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_POST_READ, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_post_read_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_POST_READ, AP_HANDLER_TYPE_METHOD); -} - - -/* }}} */ - -/* {{{ php_set_require - */ - -static CONST_PREFIX char *php_set_require(cmd_parms *cmd, void *dummy, char *arg1) -{ - return php_set_server_handler(cmd->server, arg1, 0, AP_HANDLER_TYPE_FILE); -} -/* }}} */ - -/* {{{ php_set_response_handler - */ -static CONST_PREFIX char *php_set_response_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_RESPONSE, AP_HANDLER_TYPE_FILE); -} -static CONST_PREFIX char *php_set_response_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1) -{ - return php_set_dir_handler(conf, arg1, AP_RESPONSE, AP_HANDLER_TYPE_METHOD); -} -/* }}} */ - -/* {{{ php_apache_value_handler - */ -static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_value_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_PERDIR); -} -/* }}} */ - -/* {{{ php_apache_admin_value_handler - */ -static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_value_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_SYSTEM); -} -/* }}} */ - -/* {{{ php_apache_flag_handler_ex - */ -static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) -{ - char bool_val[2]; - - if (!strcasecmp(arg2, "On")) { - bool_val[0] = '1'; - } else { - bool_val[0] = '0'; - } - bool_val[1] = 0; - - return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode); -} -/* }}} */ - -/* {{{ php_apache_flag_handler - */ -static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_flag_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_PERDIR); -} -/* }}} */ - -/* {{{ php_apache_admin_flag_handler - */ -static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2) -{ - return php_apache_flag_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_SYSTEM); -} -/* }}} */ - -/* {{{ php_apache_phpini_set - */ -static CONST_PREFIX char *php_apache_phpini_set(cmd_parms *cmd, HashTable *conf, char *arg) -{ - if (apache_sapi_module.php_ini_path_override) { - return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored"; - } - apache_sapi_module.php_ini_path_override = ap_server_root_relative(cmd->pool, arg); - return NULL; -} -/* }}} */ - -/* {{{ int php_xbithack_handler(request_rec * r) - */ -static int php_xbithack_handler(request_rec * r) -{ - php_per_dir_config *conf; - - if (!(r->finfo.st_mode & S_IXUSR)) { - r->allowed |= (1 << METHODS) - 1; - return DECLINED; - } - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - if (conf) { - zend_hash_apply((HashTable *) conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); - } - if(!AP(xbithack)) { - r->allowed |= (1 << METHODS) - 1; - zend_try { - zend_ini_deactivate(); - } zend_end_try(); - return DECLINED; - } - return send_parsed_php(r); -} -/* }}} */ - -/* {{{ apache_php_module_shutdown_wrapper - */ -static void apache_php_module_shutdown_wrapper(void) -{ - apache_php_initialized = 0; - apache_sapi_module.shutdown(&apache_sapi_module); - -#if MODULE_MAGIC_NUMBER >= 19970728 - /* This function is only called on server exit if the apache API - * child_exit handler exists, so shutdown globally - */ - sapi_shutdown(); -#endif - -#ifdef ZTS - tsrm_shutdown(); -#endif -} -/* }}} */ - -#if MODULE_MAGIC_NUMBER >= 19970728 -/* {{{ php_child_exit_handler - */ -static void php_child_exit_handler(server_rec *s, pool *p) -{ -/* apache_php_initialized = 0; */ - apache_sapi_module.shutdown(&apache_sapi_module); - -#ifdef ZTS - tsrm_shutdown(); -#endif -} -/* }}} */ -#endif - -/* {{{ void php_init_handler(server_rec *s, pool *p) - */ -static void php_init_handler(server_rec *s, pool *p) -{ - register_cleanup(p, NULL, (void (*)(void *))apache_php_module_shutdown_wrapper, (void (*)(void *))php_module_shutdown_for_exec); - if (!apache_php_initialized) { - apache_php_initialized = 1; -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#endif - sapi_startup(&apache_sapi_module); - php_apache_startup(&apache_sapi_module); - } -#if MODULE_MAGIC_NUMBER >= 19980527 - { - if (PG(expose_php)) { - ap_add_version_component("PHP/" PHP_VERSION); - } - } -#endif -} -/* }}} */ - -static int php_run_hook(php_handler *handler, request_rec *r) -{ - zval *ret = NULL; - php_per_dir_config *conf; - - - if(!AP(apache_config_loaded)) { - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - if (conf) - zend_hash_apply((HashTable *)conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries); - AP(apache_config_loaded) = 1; - } - if (!handler->name) { - return DECLINED; - } - php_save_umask(); - if (!AP(setup_env)) { - AP(setup_env) = 1; - add_common_vars(r); - add_cgi_vars(r); - } - SG(server_context) = r; - init_request_info(); - apache_php_module_hook(r, handler, &ret); - php_restore_umask(); - kill_timeout(r); - if (ret) { - convert_to_long(ret); - return Z_LVAL_P(ret); - } - return HTTP_INTERNAL_SERVER_ERROR; -} - - -static int php_uri_translation(request_rec *r) -{ - php_per_server_config *conf; - AP(current_hook) = AP_URI_TRANS; - conf = (php_per_server_config *) get_module_config(r->server->module_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->uri_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r, OK); -} - -static int php_header_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_HEADER_PARSE; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->headers_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r); -} - -static int php_auth_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_AUTHENTICATION; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->auth_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r, OK); -} - -static int php_access_hook(request_rec *r) -{ - php_per_dir_config *conf; - int status = DECLINED; - AP(current_hook) = AP_ACCESS_CONTROL; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - status = sapi_stack_apply_with_argument_stop_if_http_error(&conf->access_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r); - return status; - -} - -static int php_type_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_TYPE_CHECKING; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_equals(&conf->type_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, - r, OK); -} - -static int php_fixup_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_FIXUP; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->fixup_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, - r); -} - -static int php_logger_hook(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_LOGGING; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->logger_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, - r); -} - -static int php_post_read_hook(request_rec *r) -{ - php_per_dir_config *conf; - php_per_server_config *svr; - AP(current_hook) = AP_POST_READ; - svr = get_module_config(r->server->module_config, &php7_module); - if(ap_is_initial_req(r)) { - sapi_stack_apply_with_argument_all(&svr->requires, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); - } - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_stop_if_http_error(&conf->post_read_handlers, - ZEND_STACK_APPLY_BOTTOMUP, - (int (*)(void *element, void *)) php_run_hook, r); -} - -static int php_response_handler(request_rec *r) -{ - php_per_dir_config *conf; - AP(current_hook) = AP_RESPONSE; - conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php7_module); - return sapi_stack_apply_with_argument_all(&conf->response_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r); -} - -/* {{{ handler_rec php_handlers[] - */ -handler_rec php_handlers[] = -{ - {"application/x-httpd-php", send_parsed_php}, - {"application/x-httpd-php-source", send_parsed_php_source}, - {"text/html", php_xbithack_handler}, - {"php-script", php_response_handler}, - {NULL} -}; -/* }}} */ - -/* {{{ command_rec php_commands[] - */ -command_rec php_commands[] = -{ - {"php_value", php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"}, - {"phpUriHandler", php_set_uri_handler, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"}, - {"phpUriHandlerMethod", php_set_uri_handler_code, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"}, -#if MODULE_MAGIC_NUMBER >= 19970103 - {"phpHeaderHandler", php_set_header_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpHeaderHandlerMethod", php_set_header_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, -#endif - {"phpAuthHandler", php_set_auth_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpAuthHandlerMethod", php_set_auth_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpAccessHandler", php_set_access_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpAccessHandlerMethod", php_set_access_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpTypeHandler", php_set_type_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpTypeHandlerMethod", php_set_type_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpFixupHandler", php_set_fixup_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpFixupHandlerMethod", php_set_fixup_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpLoggerHandler", php_set_logger_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpLoggerHandlerMethod", php_set_logger_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, -#if MODULE_MAGIC_NUMBER >= 19970902 - {"phpPostReadHandler", php_set_post_read_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpPostReadHandlerMethod", php_set_post_read_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpRequire", php_set_require, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpResponseHandler", php_set_response_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, - {"phpResponseHandlerMethod", php_set_response_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"}, -#endif - {"php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"}, - {"php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"}, - {"php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"}, - {"PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, TAKE1, "Directory containing the php.ini file"}, - {NULL} -}; -/* }}} */ - -/* {{{ module MODULE_VAR_EXPORT php7_module - */ -module MODULE_VAR_EXPORT php7_module = -{ - STANDARD_MODULE_STUFF, - php_init_handler, /* initializer */ - php_create_dir, /* per-directory config creator */ - php_merge_dir, /* dir merger */ - php_create_server, /* per-server config creator */ - NULL, /* merge server config */ - php_commands, /* command table */ - php_handlers, /* handlers */ - php_uri_translation, /* filename translation */ - NULL, /* check_user_id */ - php_auth_hook, /* check auth */ - php_access_hook, /* check access */ - php_type_hook, /* type_checker */ - php_fixup_hook, /* fixups */ - php_logger_hook /* logger */ -#if MODULE_MAGIC_NUMBER >= 19970103 - , php_header_hook /* header parser */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970719 - , NULL /* child_init */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970728 - , php_child_exit_handler /* child_exit */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970902 - , php_post_read_hook /* post read-request */ -#endif -}; -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/apache_hooks/mod_php7.exp b/sapi/apache_hooks/mod_php7.exp deleted file mode 100644 index 1469b0314d5a4..0000000000000 --- a/sapi/apache_hooks/mod_php7.exp +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache_hooks/mod_php7.h b/sapi/apache_hooks/mod_php7.h deleted file mode 100644 index 34fc20bd31ce2..0000000000000 --- a/sapi/apache_hooks/mod_php7.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef MOD_PHP7_H -#define MOD_PHP7_H - -#if !defined(WIN32) && !defined(WINNT) -#ifndef MODULE_VAR_EXPORT -#define MODULE_VAR_EXPORT -#endif -#endif - -typedef struct { - long engine; - long last_modified; - long xbithack; - long terminate_child; - long setup_env; - long current_hook; - zend_bool in_request; - zend_bool apache_config_loaded; - zend_bool headers_sent; -} php_apache_info_struct; - -typedef struct _php_handler { - long type; - long stage; - char *name; -} php_handler; - -#define AP_HANDLER_TYPE_FILE 0 -#define AP_HANDLER_TYPE_METHOD 1 - -extern zend_module_entry apache_module_entry; - -#ifdef ZTS -extern int php_apache_info_id; -#define AP(v) TSRMG(php_apache_info_id, php_apache_info_struct *, v) -#else -extern php_apache_info_struct php_apache_info; -#define AP(v) (php_apache_info.v) -#endif - -/* defines for the various stages of the apache request */ -#define AP_WAITING_FOR_REQUEST 0 -#define AP_POST_READ 1 -#define AP_URI_TRANS 2 -#define AP_HEADER_PARSE 3 -#define AP_ACCESS_CONTROL 4 -#define AP_AUTHENTICATION 5 -#define AP_AUTHORIZATION 6 -#define AP_TYPE_CHECKING 7 -#define AP_FIXUP 8 -#define AP_RESPONSE 9 -#define AP_LOGGING 10 -#define AP_CLEANUP 11 - - -/* fix for gcc4 visibility patch */ -#ifndef PHP_WIN32 -# undef MODULE_VAR_EXPORT -# define MODULE_VAR_EXPORT PHPAPI -#endif - -#endif /* MOD_PHP7_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/sapi/apache_hooks/php.sym b/sapi/apache_hooks/php.sym deleted file mode 100644 index 1469b0314d5a4..0000000000000 --- a/sapi/apache_hooks/php.sym +++ /dev/null @@ -1 +0,0 @@ -php7_module diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c deleted file mode 100644 index 55581b9bb8a54..0000000000000 --- a/sapi/apache_hooks/php_apache.c +++ /dev/null @@ -1,1970 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf | - | Stig Sæther Bakken | - | David Sklar | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -#if defined(PHP_WIN32) || defined(NETWARE) -#include "zend.h" -#include "ap_compat.h" -#else -#include -#endif - -#ifdef ZTS -int php_apache_info_id; -#else -php_apache_info_struct php_apache_info; -#endif - -#define SECTION(name) PUTS("

" name "

\n") - -#undef offsetof -#define offsetof(s_type,field) ((size_t)&(((s_type*)0)->field)) - -extern module *top_module; -extern module **ap_loaded_modules; -static int le_apachereq; -static zend_class_entry *apacherequest_class_entry; - -static void apache_table_to_zval(table *, zval *return_value); - -PHP_FUNCTION(virtual); -PHP_FUNCTION(apache_request_headers); -PHP_FUNCTION(apache_response_headers); -PHP_FUNCTION(apachelog); -PHP_FUNCTION(apache_note); -PHP_FUNCTION(apache_lookup_uri); -PHP_FUNCTION(apache_child_terminate); -PHP_FUNCTION(apache_setenv); -PHP_FUNCTION(apache_get_version); -PHP_FUNCTION(apache_get_modules); - -PHP_MINFO_FUNCTION(apache); - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_virtual, 0, 0, 1) - ZEND_ARG_INFO(0, filename) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_setenv, 0, 0, 2) - ZEND_ARG_INFO(0, variable) - ZEND_ARG_INFO(0, value) - ZEND_ARG_INFO(0, walk_to_top) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_lookup_uri, 0, 0, 1) - ZEND_ARG_INFO(0, uri) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_apachehooks__void, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_note, 0, 0, 1) - ZEND_ARG_INFO(0, note_name) - ZEND_ARG_INFO(0, note_value) -ZEND_END_ARG_INFO() - -const zend_function_entry apache_functions[] = { - PHP_FE(virtual, arginfo_apachehooks_virtual) - PHP_FE(apache_request_headers, arginfo_apachehooks__void) - PHP_FE(apache_note, arginfo_apachehooks_note) - PHP_FE(apache_lookup_uri, arginfo_apachehooks_lookup_uri) - PHP_FE(apache_child_terminate, arginfo_apachehooks__void) - PHP_FE(apache_setenv, arginfo_apachehooks_setenv) - PHP_FE(apache_response_headers, arginfo_apachehooks__void) - PHP_FE(apache_get_version, arginfo_apachehooks__void) - PHP_FE(apache_get_modules, arginfo_apachehooks__void) - PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apachehooks__void) - {NULL, NULL, NULL} -}; - -/* {{{ php_apache ini entries - */ -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache_info_struct, php_apache_info) - STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateLong, terminate_child, php_apache_info_struct, php_apache_info) -PHP_INI_END() -/* }}} */ - -static void php_apache_globals_ctor(php_apache_info_struct *apache_globals) -{ - apache_globals->in_request = 0; -} - - -#define APREQ_GET_THIS(ZVAL) if (NULL == (ZVAL = getThis())) { \ - php_error(E_WARNING, "%s(): underlying ApacheRequest object missing", \ - get_active_function_name()); \ - RETURN_FALSE; \ - } -#define APREQ_GET_REQUEST(ZVAL, R) APREQ_GET_THIS(ZVAL); \ - R = get_apache_request(ZVAL) - -static void php_apache_request_free(zend_rsrc_list_entry *rsrc) -{ - zval *z = (zval *)rsrc->ptr; -/* fprintf(stderr, "%s() %p\n", __FUNCTION__, z); */ - zval_ptr_dtor(&z); -} - -static request_rec *get_apache_request(zval *z) -{ - request_rec *r; - zval **addr; - - if (NULL == z) { - php_error(E_WARNING, "get_apache_request() invalid wrapper passed"); - return NULL; - } - - if (Z_TYPE_P(z) != IS_OBJECT) { - php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name()); - return NULL; - } - - if (zend_hash_index_find(Z_OBJPROP_P(z), 0, (void **)&addr) == FAILURE) { - php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name()); - return NULL; - } - - r = (request_rec *)Z_LVAL_PP(addr); - if (!r) { - php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name()); - return NULL; - } - - return r; -} - -/* {{{ php_apache_request_new(request_rec *r) - * create a new zval-instance for ApacheRequest that wraps request_rec - */ -zval *php_apache_request_new(request_rec *r) -{ - zval *req; - zval *addr; - - MAKE_STD_ZVAL(addr); - Z_TYPE_P(addr) = IS_LONG; - Z_LVAL_P(addr) = (int) r; - - MAKE_STD_ZVAL(req); - object_init_ex(req, apacherequest_class_entry); - zend_hash_index_update(Z_OBJPROP_P(req), 0, &addr, sizeof(zval *), NULL); - - return req; -} -/* }}} */ - -/* {{{ apache_request_read_string_slot() - */ -static void apache_request_read_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - char *s; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - s = *(char **)((char*)r + offset); - - if (s) { - RETURN_STRING(s, 1); - } - - RETURN_EMPTY_STRING(); -} -/* }}} */ - - -/* {{{ apache_request_string_slot() - */ -static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - char *old_value, *new_value = NULL; - int new_value_len; - char **target; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &new_value, &new_value_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - target = (char **)((char*)r + offset); - old_value = *target; - - if (new_value) { - *target = ap_pstrdup(r->pool, new_value); - } - - if (old_value) { - RETURN_STRING(old_value, 1); - } - - RETURN_EMPTY_STRING(); -} -/* }}} */ - -/* {{{ apache_request_read_int_slot() - */ -static void apache_request_read_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - long l; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - l = *(long *)((char*)r + offset); - - RETURN_LONG(l); -} -/* }}} */ - -/* {{{ apache_request_int_slot() - */ -static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *id; - request_rec *r; - long old_value, new_value; - long *target; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &new_value) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - target = (long *)((char*)r + offset); - old_value = *target; - - switch (ZEND_NUM_ARGS()) { - case 0: - break; - case 1: - *target = new_value; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - RETURN_LONG(old_value); -} -/* }}} */ - - -/* {{{ access string slots of request rec - */ - -/* {{{ proto string ApacheRequest::filename([string new_filename]) - */ -PHP_FUNCTION(apache_request_filename) -{ - apache_request_string_slot(offsetof(request_rec, filename), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::uri([string new_uri]) - */ -PHP_FUNCTION(apache_request_uri) -{ - apache_request_string_slot(offsetof(request_rec, uri), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::unparsed_uri([string new_unparsed_uri]) - */ -PHP_FUNCTION(apache_request_unparsed_uri) -{ - apache_request_string_slot(offsetof(request_rec, unparsed_uri), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::path_info([string new_path_info]) - */ -PHP_FUNCTION(apache_request_path_info) -{ - apache_request_string_slot(offsetof(request_rec, path_info), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::args([string new_args]) - */ -PHP_FUNCTION(apache_request_args) -{ - apache_request_string_slot(offsetof(request_rec, args), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::boundary() - */ -PHP_FUNCTION(apache_request_boundary) -{ - apache_request_read_string_slot(offsetof(request_rec, boundary), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* {{{ proto string ApacheRequest::content_type([string new_type]) - */ -PHP_FUNCTION(apache_request_content_type) -{ - apache_request_string_slot(offsetof(request_rec, content_type), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::content_encoding([string new_encoding]) - */ -PHP_FUNCTION(apache_request_content_encoding) -{ - apache_request_string_slot(offsetof(request_rec, content_encoding), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::handler([string new_handler]) - */ -PHP_FUNCTION(apache_request_handler) -{ - apache_request_string_slot(offsetof(request_rec, handler), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::the_request() - */ -PHP_FUNCTION(apache_request_the_request) -{ - apache_request_read_string_slot(offsetof(request_rec, the_request), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::protocol() - */ -PHP_FUNCTION(apache_request_protocol) -{ - apache_request_read_string_slot(offsetof(request_rec, protocol), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::hostname() - */ -PHP_FUNCTION(apache_request_hostname) -{ - apache_request_read_string_slot(offsetof(request_rec, hostname), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::status_line([string new_status_line]) - */ -PHP_FUNCTION(apache_request_status_line) -{ - apache_request_string_slot(offsetof(request_rec, status_line), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string ApacheRequest::method() - */ -PHP_FUNCTION(apache_request_method) -{ - apache_request_read_string_slot(offsetof(request_rec, method), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* }}} access string slots of request rec */ - -/* {{{ access int slots of request_rec - */ - -/* {{{ proto int ApacheRequest::proto_num() - */ -PHP_FUNCTION(apache_request_proto_num) -{ - apache_request_read_int_slot(offsetof(request_rec, proto_num), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::assbackwards() - */ -PHP_FUNCTION(apache_request_assbackwards) -{ - apache_request_read_int_slot(offsetof(request_rec, assbackwards), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* {{{ proto int ApacheRequest::proxyreq([int new_proxyreq]) - */ -PHP_FUNCTION(apache_request_proxyreq) -{ - apache_request_int_slot(offsetof(request_rec, proxyreq), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::chunked() - */ -PHP_FUNCTION(apache_request_chunked) -{ - apache_request_read_int_slot(offsetof(request_rec, chunked), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* {{{ proto int ApacheRequest::header_only() - */ -PHP_FUNCTION(apache_request_header_only) -{ - apache_request_read_int_slot(offsetof(request_rec, header_only), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::request_time() - */ -PHP_FUNCTION(apache_request_request_time) -{ - apache_request_read_int_slot(offsetof(request_rec, request_time), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::status([int new_status]) - */ -PHP_FUNCTION(apache_request_status) -{ - apache_request_int_slot(offsetof(request_rec, status), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::method_number([int method_number]) - */ -PHP_FUNCTION(apache_request_method_number) -{ - apache_request_read_int_slot(offsetof(request_rec, method_number), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::allowed([int allowed]) - */ -PHP_FUNCTION(apache_request_allowed) -{ - apache_request_int_slot(offsetof(request_rec, allowed), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::bytes_sent() - */ -PHP_FUNCTION(apache_request_bytes_sent) -{ - apache_request_read_int_slot(offsetof(request_rec, bytes_sent), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::mtime() - */ -PHP_FUNCTION(apache_request_mtime) -{ - apache_request_read_int_slot(offsetof(request_rec, mtime), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::content_length([int new_content_length]) - */ -PHP_FUNCTION(apache_request_content_length) -{ - zval *id; - long zlen; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &zlen) == FAILURE) { - return; - } - - if (ZEND_NUM_ARGS() == 0) { - apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU); - } else { - APREQ_GET_REQUEST(id, r); - - (void)ap_set_content_length(r, zlen); - RETURN_TRUE; - } -} -/* }}} */ - -/* {{{ proto int ApacheRequest::remaining() - */ -PHP_FUNCTION(apache_request_remaining) -{ - apache_request_read_int_slot(offsetof(request_rec, remaining), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::no_cache() - */ -PHP_FUNCTION(apache_request_no_cache) -{ - apache_request_int_slot(offsetof(request_rec, no_cache), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::no_local_copy() - */ -PHP_FUNCTION(apache_request_no_local_copy) -{ - apache_request_int_slot(offsetof(request_rec, no_local_copy), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int ApacheRequest::read_body() - */ -PHP_FUNCTION(apache_request_read_body) -{ - apache_request_int_slot(offsetof(request_rec, read_body), INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - - -/* }}} access int slots of request_rec */ - - -/* {{{ proto array apache_request_headers_in() - * fetch all incoming request headers - */ -PHP_FUNCTION(apache_request_headers_in) -{ - zval *id; - request_rec *r; - - APREQ_GET_REQUEST(id, r); - - apache_table_to_zval(r->headers_in, return_value); -} -/* }}} */ - - -/* {{{ add_header_to_table -*/ -static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *first = NULL; - zval *second = NULL; - zval **entry, **value; - char *string_key; - uint string_key_len; - ulong num_key; - - zend_bool replace = 0; - HashPosition pos; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|zb", &first, &second, &replace) == FAILURE) { - RETURN_FALSE; - } - - if (Z_TYPE_P(first) == IS_ARRAY) { - switch(ZEND_NUM_ARGS()) { - case 1: - case 3: - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(first), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(first), (void **)&entry, &pos) == SUCCESS) { - switch(zend_hash_get_current_key_ex(Z_ARRVAL_P(first), &string_key, &string_key_len, &num_key, &pos)) { - case HASH_KEY_IS_STRING: - if (zend_hash_find(Z_ARRVAL_P(first), string_key, string_key_len, (void **)&value) == FAILURE) { - zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos); - continue; - } - if (!value) { - zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos); - continue; - } - - convert_to_string_ex(value); - if (replace) { - ap_table_set(t, string_key, Z_STRVAL_PP(value)); - } else { - ap_table_merge(t, string_key, Z_STRVAL_PP(value)); - } - break; - case HASH_KEY_IS_LONG: - default: - php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name()); - break; - } - - zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos); - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - } else if (Z_TYPE_P(first) == IS_STRING) { - switch(ZEND_NUM_ARGS()) { - case 2: - case 3: - convert_to_string_ex(&second); - if (replace) { - ap_table_set(t, Z_STRVAL_P(first), Z_STRVAL_P(second)); - } else { - ap_table_merge(t, Z_STRVAL_P(first), Z_STRVAL_P(second)); - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - } else { - RETURN_FALSE; - } -} - -/* }}} */ - - -/* {{{ proto array apache_request_headers_out([{string name|array list} [, string value [, bool replace = false]]]) - * fetch all outgoing request headers - */ -PHP_FUNCTION(apache_request_headers_out) -{ - zval *id; - request_rec *r; - - APREQ_GET_REQUEST(id, r); - - if (ZEND_NUM_ARGS() > 0) { - add_header_to_table(r->headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU); - } - - apache_table_to_zval(r->headers_out, return_value); -} -/* }}} */ - - -/* {{{ proto array apache_request_err_headers_out([{string name|array list} [, string value [, bool replace = false]]]) - * fetch all headers that go out in case of an error or a subrequest - */ -PHP_FUNCTION(apache_request_err_headers_out) -{ - zval *id; - request_rec *r; - - APREQ_GET_REQUEST(id, r); - - if (ZEND_NUM_ARGS() > 0) { - add_header_to_table(r->err_headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU); - } - - apache_table_to_zval(r->err_headers_out, return_value); -} -/* }}} */ - - -/* {{{ proxy functions for the ap_* functions family - */ - -/* {{{ proto int apache_request_server_port() - */ -PHP_FUNCTION(apache_request_server_port) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_get_server_port(r)); -} -/* }}} */ - -/* {{{ proto int apache_request_remote_host([int type]) - */ -PHP_FUNCTION(apache_request_remote_host) -{ - zval *id; - long type = 0; - request_rec *r; - char *res; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &type) == FAILURE) { - return; - } - - if (!type) { - type = REMOTE_NAME; - } - - APREQ_GET_REQUEST(id, r); - - res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, (int)type); - - if (res) { - RETURN_STRING(res, 1); - } - - RETURN_EMPTY_STRING(); -} -/* }}} */ - -/* {{{ proto long apache_request_update_mtime([int dependency_mtime]) - */ -PHP_FUNCTION(apache_request_update_mtime) -{ - zval *id; - request_rec *r; - long mtime = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mtime) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_update_mtime(r, (int) mtime)); -} -/* }}} */ - - -/* {{{ proto void apache_request_set_etag() - */ -PHP_FUNCTION(apache_request_set_etag) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_set_etag(r); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto void apache_request_set_last_modified() - */ -PHP_FUNCTION(apache_request_set_last_modified) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_set_last_modified(r); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto long apache_request_meets_conditions() - */ -PHP_FUNCTION(apache_request_meets_conditions) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_meets_conditions(r)); -} -/* }}} */ - -/* {{{ proto long apache_request_discard_request_body() - */ -PHP_FUNCTION(apache_request_discard_request_body) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_discard_request_body(r)); -} -/* }}} */ - -/* {{{ proto long apache_request_satisfies() - */ -PHP_FUNCTION(apache_request_satisfies) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_LONG(ap_satisfies(r)); -} -/* }}} */ - - -/* {{{ proto bool apache_request_is_initial_req() - */ -PHP_FUNCTION(apache_request_is_initial_req) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_BOOL(ap_is_initial_req(r)); -} -/* }}} */ - -/* {{{ proto bool apache_request_some_auth_required() - */ -PHP_FUNCTION(apache_request_some_auth_required) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - RETURN_BOOL(ap_some_auth_required(r)); -} -/* }}} */ - -/* {{{ proto string apache_request_auth_type() - */ -PHP_FUNCTION(apache_request_auth_type) -{ - zval *id; - request_rec *r; - char *t; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - t = (char *)ap_auth_type(r); - if (!t) { - RETURN_NULL(); - } - - RETURN_STRING(t, 1); -} -/* }}} */ - -/* {{{ proto string apache_request_auth_name() - */ -PHP_FUNCTION(apache_request_auth_name) -{ - zval *id; - request_rec *r; - char *t; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - t = (char *)ap_auth_name(r); - if (!t) { - RETURN_NULL(); - } - - RETURN_STRING(t, 1); -} -/* }}} */ - -/* {{{ proto apache_request_basic_auth_pw() - */ -PHP_FUNCTION(apache_request_basic_auth_pw) -{ - zval *id, *zpw; - request_rec *r; - const char *pw; - long status; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zpw) == FAILURE) { - return; - } - - if (!PZVAL_IS_REF(zpw)) { - zend_error(E_WARNING, "Parameter wasn't passed by reference"); - RETURN_NULL(); - } - - APREQ_GET_REQUEST(id, r); - - pw = NULL; - status = ap_get_basic_auth_pw(r, &pw); - if (status == OK && pw) { - ZVAL_STRING(zpw, (char *)pw, 1); - } else { - ZVAL_NULL(zpw); - } - RETURN_LONG(status); -} -/* }}} */ - - -/* http_protocol.h */ - -PHP_FUNCTION(apache_request_send_http_header) -{ - zval *id; - request_rec *r; - char *type = NULL; - int typelen; - - if (zend_parse_parameters(ZEND_NUM_ARGS() , "|s", &type, &typelen) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - if(type) { - r->content_type = pstrdup(r->pool, type); - } - ap_send_http_header(r); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_basic_http_header) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_basic_http_header((request_rec *)SG(server_context)); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_send_http_trace) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_send_http_trace((request_rec *)SG(server_context)); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_send_http_options) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_send_http_options((request_rec *)SG(server_context)); - SG(headers_sent) = 1; - AP(headers_sent) = 1; - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_send_error_response) -{ - zval *id; - request_rec *r; - long rec = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &rec) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - ap_send_error_response(r, (int) rec); - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_set_content_length) -{ - long length; - zval *id; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &length) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_set_content_length(r, length); - RETURN_TRUE; -} - -PHP_FUNCTION(apache_request_set_keepalive) -{ - zval *id; - request_rec *r; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - ap_set_keepalive(r); - RETURN_TRUE; -} - -/* This stuff should use streams or however this is implemented now - -PHP_FUNCTION(apache_request_send_fd) -{ -} - -PHP_FUNCTION(apache_request_send_fd_length) -{ -} -*/ - -/* These are for overriding default output behaviour */ -PHP_FUNCTION(apache_request_rputs) -{ - char *buffer; - int buffer_len; - zval *id; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &buffer, &buffer_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - ap_rwrite(buffer, buffer_len, (request_rec*)SG(server_context)); -} - -/* This stuff would be useful for custom POST handlers, - which should be supported. Probably by not using - sapi_activate at all inside a phpResponseHandler - and instead using a builtin composed of the below - calls as a apache_read_request_body() and allow - people to custom craft their own. - -PHP_FUNCTION(apache_request_setup_client_block) -{ -} - -PHP_FUNCTION(apache_request_should_client_block) -{ -} - -PHP_FUNCTION(apache_request_get_client_block) -{ -} - -PHP_FUNCTION(apache_request_discard_request_body) -{ -} -*/ - -/* http_log.h */ - -/* {{{ proto boolean apache_request_log_error(string message, [long facility]) - */ -PHP_FUNCTION(apache_request_log_error) -{ - zval *id; - char *z_errstr; - int z_errstr_len; - long facility = APLOG_ERR; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - ap_log_error(APLOG_MARK, (int) facility, r->server, "%s", z_errstr); - RETURN_TRUE; -} -/* }}} */ -/* http_main.h */ - -/* {{{ proto object apache_request_sub_req_lookup_uri(string uri) - Returns sub-request for the specified uri. You would - need to run it yourself with run() -*/ -PHP_FUNCTION(apache_request_sub_req_lookup_uri) -{ - zval *id; - char *file; - int file_len; - request_rec *r, *sub_r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - sub_r = ap_sub_req_lookup_uri(file, r); - - if (!sub_r) { - RETURN_FALSE; - } - return_value = php_apache_request_new(sub_r); -} -/* }}} */ - -/* {{{ proto object apache_request_sub_req_lookup_file(string file) - Returns sub-request for the specified file. You would - need to run it yourself with run(). -*/ -PHP_FUNCTION(apache_request_sub_req_lookup_file) -{ - zval *id; - char *file; - int file_len; - request_rec *r, *sub_r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - sub_r = ap_sub_req_lookup_file(file, r); - - if (!sub_r) { - RETURN_FALSE; - } - return_value = php_apache_request_new(sub_r); -} -/* }}} */ - -/* {{{ proto object apache_request_sub_req_method_uri(string method, string uri) - Returns sub-request for the specified file. You would - need to run it yourself with run(). -*/ -PHP_FUNCTION(apache_request_sub_req_method_uri) -{ - zval *id; - char *file, *method; - int file_len, method_len; - request_rec *r, *sub_r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &method, &method_len, &file, &file_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - sub_r = ap_sub_req_method_uri(method, file, r); - - if (!sub_r) { - RETURN_FALSE; - } - return_value = php_apache_request_new(sub_r); -} -/* }}} */ - -/* {{{ proto long apache_request_run() - This is a wrapper for ap_sub_run_req and ap_destory_sub_req. It takes - sub_request, runs it, destroys it, and returns it's status. -*/ -PHP_FUNCTION(apache_request_run) -{ - zval *id; - request_rec *r; - int status; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - if (!r || ap_is_initial_req(r)) { - RETURN_FALSE; - } - status = ap_run_sub_req(r); - ap_destroy_sub_req(r); - RETURN_LONG(status); -} -/* }}} */ - -PHP_FUNCTION(apache_request_internal_redirect) -{ - zval *id; - char *new_uri; - int new_uri_len; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &new_uri, &new_uri_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_internal_redirect(new_uri, r); -} - -PHP_FUNCTION(apache_request_send_header_field) -{ - char *fieldname, *fieldval; - int fieldname_len, fieldval_len; - zval *id; - request_rec *r; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) { - return; - } - - APREQ_GET_REQUEST(id, r); - - ap_send_header_field(r, fieldname, fieldval); - SG(headers_sent) = 1; - AP(headers_sent) = 1; -} - - - -/* }}} */ - -/* {{{ php_apache_request_class_functions - */ -const static zend_function_entry php_apache_request_class_functions[] = { - /* string slots */ - PHP_FALIAS(args, apache_request_args, NULL) - PHP_FALIAS(boundary, apache_request_boundary, NULL) - PHP_FALIAS(content_encoding, apache_request_content_encoding, NULL) - PHP_FALIAS(content_type, apache_request_content_type, NULL) - PHP_FALIAS(filename, apache_request_filename, NULL) - PHP_FALIAS(handler, apache_request_handler, NULL) - PHP_FALIAS(hostname, apache_request_hostname, NULL) - PHP_FALIAS(method, apache_request_method, NULL) - PHP_FALIAS(path_info, apache_request_path_info, NULL) - PHP_FALIAS(protocol, apache_request_protocol, NULL) - PHP_FALIAS(status_line, apache_request_status_line, NULL) - PHP_FALIAS(the_request, apache_request_the_request, NULL) - PHP_FALIAS(unparsed_uri, apache_request_unparsed_uri, NULL) - PHP_FALIAS(uri, apache_request_uri, NULL) - - /* int slots */ - PHP_FALIAS(allowed, apache_request_allowed, NULL) - PHP_FALIAS(bytes_sent, apache_request_bytes_sent, NULL) - PHP_FALIAS(chunked, apache_request_chunked, NULL) - PHP_FALIAS(content_length, apache_request_content_length, NULL) - PHP_FALIAS(header_only, apache_request_header_only, NULL) - PHP_FALIAS(method_number, apache_request_method_number, NULL) - PHP_FALIAS(mtime, apache_request_mtime, NULL) - PHP_FALIAS(no_cache, apache_request_no_cache, NULL) - PHP_FALIAS(no_local_copy, apache_request_no_local_copy, NULL) - PHP_FALIAS(proto_num, apache_request_proto_num, NULL) - PHP_FALIAS(proxyreq, apache_request_proxyreq, NULL) - PHP_FALIAS(read_body, apache_request_read_body, NULL) - PHP_FALIAS(remaining, apache_request_remaining, NULL) - PHP_FALIAS(request_time, apache_request_request_time, NULL) - PHP_FALIAS(status, apache_request_status, NULL) - - /* tables & arrays */ - PHP_FALIAS(headers_in, apache_request_headers_in, NULL) - PHP_FALIAS(headers_out, apache_request_headers_out, NULL) - PHP_FALIAS(err_headers_out, apache_request_err_headers_out, NULL) - - - /* proxy functions for the ap_* functions family */ -#undef auth_name -#undef auth_type -#undef discard_request_body -#undef is_initial_req -#undef meets_conditions -#undef satisfies -#undef set_etag -#undef set_last_modified -#undef some_auth_required -#undef update_mtime -#undef send_http_header -#undef send_header_field -#undef basic_http_header -#undef send_http_trace -#undef send_http_options -#undef send_error_response -#undef set_content_length -#undef set_keepalive -#undef rputs -#undef log_error -#undef lookup_uri -#undef lookup_file -#undef method_uri -#undef run -#undef internal_redirect - PHP_FALIAS(auth_name, apache_request_auth_name, NULL) - PHP_FALIAS(auth_type, apache_request_auth_type, NULL) - PHP_FALIAS(basic_auth_pw, apache_request_basic_auth_pw, NULL) - PHP_FALIAS(discard_request_body, apache_request_discard_request_body, NULL) - PHP_FALIAS(is_initial_req, apache_request_is_initial_req, NULL) - PHP_FALIAS(meets_conditions, apache_request_meets_conditions, NULL) - PHP_FALIAS(remote_host, apache_request_remote_host, NULL) - PHP_FALIAS(satisfies, apache_request_satisfies, NULL) - PHP_FALIAS(server_port, apache_request_server_port, NULL) - PHP_FALIAS(set_etag, apache_request_set_etag, NULL) - PHP_FALIAS(set_last_modified, apache_request_set_last_modified, NULL) - PHP_FALIAS(some_auth_required, apache_request_some_auth_required, NULL) - PHP_FALIAS(update_mtime, apache_request_update_mtime, NULL) - PHP_FALIAS(send_http_header, apache_request_send_http_header, NULL) - PHP_FALIAS(basic_http_header, apache_request_basic_http_header, NULL) - PHP_FALIAS(send_header_field, apache_request_send_header_field, NULL) - PHP_FALIAS(send_http_trace, apache_request_send_http_trace, NULL) - PHP_FALIAS(send_http_options, apache_request_send_http_trace, NULL) - PHP_FALIAS(send_error_response, apache_request_send_error_response, NULL) - PHP_FALIAS(set_content_length, apache_request_set_content_length, NULL) - PHP_FALIAS(set_keepalive, apache_request_set_keepalive, NULL) - PHP_FALIAS(rputs, apache_request_rputs, NULL) - PHP_FALIAS(log_error, apache_request_log_error, NULL) - PHP_FALIAS(lookup_uri, apache_request_sub_req_lookup_uri, NULL) - PHP_FALIAS(lookup_file, apache_request_sub_req_lookup_file, NULL) - PHP_FALIAS(method_uri, apache_request_sub_req_method_uri, NULL) - PHP_FALIAS(run, apache_request_run, NULL) - PHP_FALIAS(internal_redirect, apache_request_internal_redirect, NULL) - PHP_FE_END -}; -/* }}} */ - - -static PHP_MINIT_FUNCTION(apache) -{ - zend_class_entry ce; - -#ifdef ZTS - ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL); -#else - php_apache_globals_ctor(&php_apache_info); -#endif - REGISTER_INI_ENTRIES(); - - - le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number); - INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL); - apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL); - - REGISTER_LONG_CONSTANT("OK", OK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DECLINED", DECLINED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FORBIDDEN", FORBIDDEN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AUTH_REQUIRED", AUTH_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DONE", DONE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SERVER_ERROR", SERVER_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REDIRECT", REDIRECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("BAD_REQUEST", BAD_REQUEST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("NOT_FOUND", NOT_FOUND, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_CONTINUE", HTTP_CONTINUE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_SWITCHING_PROTOCOLS", HTTP_SWITCHING_PROTOCOLS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PROCESSING", HTTP_PROCESSING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_OK", HTTP_OK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_CREATED", HTTP_CREATED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_ACCEPTED", HTTP_ACCEPTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NON_AUTHORITATIVE", HTTP_NON_AUTHORITATIVE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NO_CONTENT", HTTP_NO_CONTENT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_RESET_CONTENT", HTTP_RESET_CONTENT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PARTIAL_CONTENT", HTTP_PARTIAL_CONTENT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MULTI_STATUS", HTTP_MULTI_STATUS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MULTIPLE_CHOICES", HTTP_MULTIPLE_CHOICES, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MOVED_PERMANENTLY", HTTP_MOVED_PERMANENTLY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_MOVED_TEMPORARILY", HTTP_MOVED_TEMPORARILY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_SEE_OTHER", HTTP_SEE_OTHER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_MODIFIED", HTTP_NOT_MODIFIED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_USE_PROXY", HTTP_USE_PROXY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_TEMPORARY_REDIRECT", HTTP_TEMPORARY_REDIRECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_BAD_REQUEST", HTTP_BAD_REQUEST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_UNAUTHORIZED", HTTP_UNAUTHORIZED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PAYMENT_REQUIRED", HTTP_PAYMENT_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_FORBIDDEN", HTTP_FORBIDDEN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_FOUND", HTTP_NOT_FOUND, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_METHOD_NOT_ALLOWED", HTTP_METHOD_NOT_ALLOWED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_ACCEPTABLE", HTTP_NOT_ACCEPTABLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PROXY_AUTHENTICATION_REQUIRED", HTTP_PROXY_AUTHENTICATION_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_REQUEST_TIME_OUT", HTTP_REQUEST_TIME_OUT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_CONFLICT", HTTP_CONFLICT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_GONE", HTTP_GONE, CONST_CS | CONST_PERSISTENT);REGISTER_LONG_CONSTANT("HTTP_LENGTH_REQUIRED", HTTP_LENGTH_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_PRECONDITION_FAILED", HTTP_PRECONDITION_FAILED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_REQUEST_ENTITY_TOO_LARGE", HTTP_REQUEST_ENTITY_TOO_LARGE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_REQUEST_URI_TOO_LARGE", HTTP_REQUEST_URI_TOO_LARGE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_UNSUPPORTED_MEDIA_TYPE", HTTP_UNSUPPORTED_MEDIA_TYPE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_RANGE_NOT_SATISFIABLE", HTTP_RANGE_NOT_SATISFIABLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_EXPECTATION_FAILED", HTTP_EXPECTATION_FAILED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_UNPROCESSABLE_ENTITY", HTTP_UNPROCESSABLE_ENTITY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_LOCKED", HTTP_LOCKED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_FAILED_DEPENDENCY", HTTP_FAILED_DEPENDENCY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_INTERNAL_SERVER_ERROR", HTTP_INTERNAL_SERVER_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_IMPLEMENTED", HTTP_NOT_IMPLEMENTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_BAD_GATEWAY", HTTP_BAD_GATEWAY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_SERVICE_UNAVAILABLE", HTTP_SERVICE_UNAVAILABLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_GATEWAY_TIME_OUT", HTTP_GATEWAY_TIME_OUT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_VERSION_NOT_SUPPORTED", HTTP_VERSION_NOT_SUPPORTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_VARIANT_ALSO_VARIES", HTTP_VARIANT_ALSO_VARIES, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_INSUFFICIENT_STORAGE", HTTP_INSUFFICIENT_STORAGE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_NOT_EXTENDED", HTTP_NOT_EXTENDED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_EMERG", APLOG_EMERG, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_ALERT", APLOG_ALERT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_CRIT", APLOG_CRIT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_ERR", APLOG_ERR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_WARNING", APLOG_WARNING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_NOTICE", APLOG_NOTICE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_INFO", APLOG_INFO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APLOG_DEBUG", APLOG_DEBUG, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_GET", M_GET, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PUT", M_PUT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_POST", M_POST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_DELETE", M_DELETE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_CONNECT", M_CONNECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_OPTIONS", M_OPTIONS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_TRACE", M_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PATCH", M_PATCH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PROPFIND", M_PROPFIND, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_PROPPATCH", M_PROPPATCH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_MKCOL", M_MKCOL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_COPY", M_COPY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_MOVE", M_MOVE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_LOCK", M_LOCK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_UNLOCK", M_UNLOCK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("M_INVALID", M_INVALID, CONST_CS | CONST_PERSISTENT); - - /* Possible values for request_rec.read_body (set by handling module): - * REQUEST_NO_BODY Send 413 error if message has any body - * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length - * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me. - * REQUEST_CHUNKED_PASS Pass the chunks to me without removal. - */ - REGISTER_LONG_CONSTANT("REQUEST_NO_BODY", REQUEST_NO_BODY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_ERROR", REQUEST_CHUNKED_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_DECHUNK", REQUEST_CHUNKED_DECHUNK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_PASS", REQUEST_CHUNKED_PASS, CONST_CS | CONST_PERSISTENT); - - /* resolve types for remote_host() */ - REGISTER_LONG_CONSTANT("REMOTE_HOST", REMOTE_HOST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REMOTE_NAME", REMOTE_NAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REMOTE_NOLOOKUP", REMOTE_NOLOOKUP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("REMOTE_DOUBLE_REV", REMOTE_DOUBLE_REV, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; -} - - -static PHP_MSHUTDOWN_FUNCTION(apache) -{ - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} - -zend_module_entry apache_module_entry = { - STANDARD_MODULE_HEADER, - "apache", - apache_functions, - PHP_MINIT(apache), - PHP_MSHUTDOWN(apache), - NULL, - NULL, - PHP_MINFO(apache), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -/* {{{ proto bool apache_child_terminate(void) - Terminate apache process after this request */ -PHP_FUNCTION(apache_child_terminate) -{ -#ifndef MULTITHREAD - if (AP(terminate_child)) { - ap_child_terminate( ((request_rec *)SG(server_context)) ); - RETURN_TRUE; - } else { /* tell them to get lost! */ - php_error(E_WARNING, "apache.child_terminate is disabled"); - RETURN_FALSE; - } -#else - php_error(E_WARNING, "apache_child_terminate() is not supported in this build"); - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto string apache_note(string note_name [, string note_value]) - Get and set Apache request notes */ -PHP_FUNCTION(apache_note) -{ - char *arg_name, *arg_val = NULL; - int arg_name_len, arg_val_len; - char *note_val; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) { - return; - } - - note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, arg_name); - - if (arg_val) { - table_set(((request_rec *)SG(server_context))->notes, arg_name, arg_val); - } - - if (!note_val) { - RETURN_FALSE; - } - - RETURN_STRING(note_val, 1); -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(apache) -{ - module *modp = NULL; - char output_buf[128]; -#if !defined(WIN32) && !defined(WINNT) - char name[64]; - char modulenames[1024]; - char *p; -#endif - server_rec *serv; - extern char server_root[MAX_STRING_LEN]; - extern uid_t user_id; - extern char *user_name; - extern gid_t group_id; - extern int max_requests_per_child; - - serv = ((request_rec *) SG(server_context))->server; - - - php_info_print_table_start(); - -#ifdef PHP_WIN32 - php_info_print_table_row(1, "Apache for Windows 95/NT"); - php_info_print_table_end(); - php_info_print_table_start(); -#elif defined(NETWARE) - php_info_print_table_row(1, "Apache for NetWare"); - php_info_print_table_end(); - php_info_print_table_start(); -#else - php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE); - php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET); -#endif - - php_info_print_table_row(2, "Apache Version", SERVER_VERSION); - -#ifdef APACHE_RELEASE - snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE); - php_info_print_table_row(2, "Apache Release", output_buf); -#endif - snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER); - php_info_print_table_row(2, "Apache API Version", output_buf); - snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port); - php_info_print_table_row(2, "Hostname:Port", output_buf); -#if !defined(WIN32) && !defined(WINNT) - snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id); - php_info_print_table_row(2, "User/Group", output_buf); - snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); - php_info_print_table_row(2, "Max Requests", output_buf); -#endif - snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); - php_info_print_table_row(2, "Timeouts", output_buf); -#if !defined(WIN32) && !defined(WINNT) -/* - This block seems to be working on NetWare; But it seems to be showing - all modules instead of just the loaded ones -*/ - php_info_print_table_row(2, "Server Root", server_root); - - strcpy(modulenames, ""); - for(modp = top_module; modp; modp = modp->next) { - strlcpy(name, modp->name, sizeof(name)); - if ((p = strrchr(name, '.'))) { - *p='\0'; /* Cut off ugly .c extensions on module names */ - } - strlcat(modulenames, name, sizeof(modulenames)); - if (modp->next) { - strlcat(modulenames, ", ", sizeof(modulenames)); - } - } - php_info_print_table_row(2, "Loaded Modules", modulenames); -#endif - - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); - - { - register int i; - array_header *arr; - table_entry *elts; - request_rec *r; - - r = ((request_rec *) SG(server_context)); - arr = table_elts(r->subprocess_env); - elts = (table_entry *)arr->elts; - - SECTION("Apache Environment"); - php_info_print_table_start(); - php_info_print_table_header(2, "Variable", "Value"); - for (i=0; i < arr->nelts; i++) { - php_info_print_table_row(2, elts[i].key, elts[i].val); - } - php_info_print_table_end(); - } - - { - array_header *env_arr; - table_entry *env; - int i; - request_rec *r; - - r = ((request_rec *) SG(server_context)); - SECTION("HTTP Headers Information"); - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "HTTP Request Headers"); - php_info_print_table_row(2, "HTTP Request", r->the_request); - env_arr = table_elts(r->headers_in); - env = (table_entry *)env_arr->elts; - for (i = 0; i < env_arr->nelts; ++i) { - if (env[i].key) { - php_info_print_table_row(2, env[i].key, env[i].val); - } - } - php_info_print_table_colspan_header(2, "HTTP Response Headers"); - env_arr = table_elts(r->headers_out); - env = (table_entry *)env_arr->elts; - for(i = 0; i < env_arr->nelts; ++i) { - if (env[i].key) { - php_info_print_table_row(2, env[i].key, env[i].val); - } - } - php_info_print_table_end(); - } -} -/* }}} */ - -/* {{{ proto bool virtual(string filename) - Perform an Apache sub-request */ -/* This function is equivalent to - * in mod_include. It does an Apache sub-request. It is useful - * for including CGI scripts or .shtml files, or anything else - * that you'd parse through Apache (for .phtml files, you'd probably - * want to use . This only works when PHP is compiled - * as an Apache module, since it uses the Apache API for doing - * sub requests. - */ -PHP_FUNCTION(virtual) -{ - char *filename; - int filename_len; - request_rec *rr = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) { - php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - if (rr->status != 200) { - php_error(E_WARNING, "Unable to include '%s' - error finding URI", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - php_output_end_all(); - php_header(); - - if (run_sub_req(rr)) { - php_error(E_WARNING, "Unable to include '%s' - request execution failed", filename); - if (rr) - destroy_sub_req (rr); - RETURN_FALSE; - } - - if (rr) - destroy_sub_req (rr); - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ apache_table_to_zval(table *, zval *return_value) - Fetch all HTTP request headers */ -static void apache_table_to_zval(table *t, zval *return_value) -{ - array_header *env_arr; - table_entry *tenv; - int i; - - array_init(return_value); - env_arr = table_elts(t); - tenv = (table_entry *)env_arr->elts; - for (i = 0; i < env_arr->nelts; ++i) { - if (!tenv[i].key) { - continue; - } - if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val)==FAILURE) { - RETURN_FALSE; - } - } - -} -/* }}} */ - - -/* {{{ proto array getallheaders(void) -*/ -/* Alias for apache_request_headers() */ -/* }}} */ - -/* {{{ proto array apache_request_headers(void) - Fetch all HTTP request headers */ -PHP_FUNCTION(apache_request_headers) -{ - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, return_value); -} -/* }}} */ - -/* {{{ proto array apache_response_headers(void) - Fetch all HTTP response headers */ -PHP_FUNCTION(apache_response_headers) -{ - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - apache_table_to_zval(((request_rec *) SG(server_context))->headers_out, return_value); -} -/* }}} */ - -/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) - Set an Apache subprocess_env variable */ -PHP_FUNCTION(apache_setenv) -{ - int var_len, val_len; - zend_bool top=0; - char *var = NULL, *val = NULL; - request_rec *r = (request_rec *) SG(server_context); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { - RETURN_FALSE; - } - - while(top) { - if (r->prev) { - r = r->prev; - } - else break; - } - - ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto object apache_lookup_uri(string URI) - Perform a partial request of the given URI to obtain information about it */ -PHP_FUNCTION(apache_lookup_uri) -{ - char *filename; - int filename_len; - request_rec *rr=NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { - return; - } - - if(!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { - php_error(E_WARNING, "URI lookup failed", filename); - RETURN_FALSE; - } - - object_init(return_value); - add_property_long(return_value,"status", rr->status); - - if (rr->the_request) { - add_property_string(return_value,"the_request", rr->the_request); - } - if (rr->status_line) { - add_property_string(return_value,"status_line", (char *)rr->status_line); - } - if (rr->method) { - add_property_string(return_value,"method", (char *)rr->method); - } - if (rr->content_type) { - add_property_string(return_value,"content_type", (char *)rr->content_type); - } - if (rr->handler) { - add_property_string(return_value,"handler", (char *)rr->handler); - } - if (rr->uri) { - add_property_string(return_value,"uri", rr->uri); - } - if (rr->filename) { - add_property_string(return_value,"filename", rr->filename); - } - if (rr->path_info) { - add_property_string(return_value,"path_info", rr->path_info); - } - if (rr->args) { - add_property_string(return_value,"args", rr->args); - } - if (rr->boundary) { - add_property_string(return_value,"boundary", rr->boundary); - } - add_property_long(return_value,"no_cache", rr->no_cache); - add_property_long(return_value,"no_local_copy", rr->no_local_copy); - add_property_long(return_value,"allowed", rr->allowed); - add_property_long(return_value,"sent_bodyct", rr->sent_bodyct); - add_property_long(return_value,"bytes_sent", rr->bytes_sent); - add_property_long(return_value,"byterange", rr->byterange); - add_property_long(return_value,"clength", rr->clength); - -#if MODULE_MAGIC_NUMBER >= 19980324 - if (rr->unparsed_uri) { - add_property_string(return_value,"unparsed_uri", rr->unparsed_uri); - } - if(rr->mtime) { - add_property_long(return_value,"mtime", rr->mtime); - } -#endif - if(rr->request_time) { - add_property_long(return_value,"request_time", rr->request_time); - } - - destroy_sub_req(rr); -} -/* }}} */ - - -#if 0 -/* -This function is most likely a bad idea. Just playing with it for now. -*/ - -PHP_FUNCTION(apache_exec_uri) -{ - zval **filename; - request_rec *rr=NULL; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) { - php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val); - RETURN_FALSE; - } - RETVAL_LONG(ap_run_sub_req(rr)); - ap_destroy_sub_req(rr); -} -#endif - -/* {{{ proto string apache_get_version(void) - Fetch Apache version */ -PHP_FUNCTION(apache_get_version) -{ - char *apv = (char *) ap_get_server_version(); - - if (apv && *apv) { - RETURN_STRING(apv, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto array apache_get_modules(void) - Get a list of loaded Apache modules */ -PHP_FUNCTION(apache_get_modules) -{ - int n; - char *p; - - array_init(return_value); - - for (n = 0; ap_loaded_modules[n]; ++n) { - char *s = (char *) ap_loaded_modules[n]->name; - if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s)); - } else { - add_next_index_string(return_value, s); - } - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/apache_hooks/php_apache_http.h b/sapi/apache_hooks/php_apache_http.h deleted file mode 100644 index 5684de9179cad..0000000000000 --- a/sapi/apache_hooks/php_apache_http.h +++ /dev/null @@ -1,44 +0,0 @@ -#define NO_REGEX_EXTRA_H - -#ifdef WIN32 -#include -#include -#endif - -#ifdef NETWARE -#include -#endif - -#include "zend.h" -#include "zend_stack.h" -#include "ext/ereg/php_regex.h" - -#include "httpd.h" -#include "http_config.h" - -#if MODULE_MAGIC_NUMBER > 19980712 -# include "ap_compat.h" -#else -# if MODULE_MAGIC_NUMBER > 19980324 -# include "compat.h" -# endif -#endif - -#include "http_core.h" -#include "http_main.h" -#include "http_protocol.h" -#include "http_request.h" -#include "http_log.h" -#include "util_script.h" - -#include "php_variables.h" -#include "php_main.h" -#include "php_ini.h" -#include "ext/standard/php_standard.h" - -#include "mod_php7.h" - - -zval *php_apache_request_new(request_rec *r); - -int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret); diff --git a/sapi/apache_hooks/sapi_apache.c b/sapi/apache_hooks/sapi_apache.c deleted file mode 100644 index dd5a6b60ea484..0000000000000 --- a/sapi/apache_hooks/sapi_apache.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf | - | (with helpful hints from Dean Gaudet | - | PHP 4.0 patches by: | - | Zeev Suraski | - | Stig Bakken | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php_apache_http.h" - -/* {{{ apache_php_module_main - */ -int apache_php_module_main(request_rec *r, int display_source_mode) -{ - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return FAILURE; - } - /* sending a file handle to another dll is not working - so let zend open it. */ - - if (display_source_mode) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - php_get_highlight_struct(&syntax_highlighter_ini); - if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini)){ - return OK; - } else { - return NOT_FOUND; - } - } else { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.handle.fd = 0; - file_handle.filename = SG(request_info).path_translated; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - (void) php_execute_script(&file_handle); - } - AP(in_request) = 0; - - return (OK); -} -/* }}} */ - -/* {{{ apache_php_module_hook - */ -int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret) -{ - zend_file_handle file_handle; - zval *req; - char *tmp; - -#if PHP_SIGCHILD - signal(SIGCHLD, sigchld_handler); -#endif - if(AP(current_hook) == AP_RESPONSE) { - if (php_request_startup_for_hook() == FAILURE) - return FAILURE; - } - else { - if (php_request_startup_for_hook() == FAILURE) - return FAILURE; - } - - req = php_apache_request_new(r); - php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER]); - - switch(handler->type) { - case AP_HANDLER_TYPE_FILE: - php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER]); - memset(&file_handle, 0, sizeof(file_handle)); - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = handler->name; - (void) php_execute_simple_script(&file_handle, ret); - break; - case AP_HANDLER_TYPE_METHOD: - if( (tmp = strstr(handler->name, "::")) != NULL && *(tmp+2) != '\0' ) { - zval *class; - zval *method; - *tmp = '\0'; - ALLOC_ZVAL(class); - ZVAL_STRING(class, handler->name, 1); - ALLOC_ZVAL(method); - ZVAL_STRING(method, tmp +2, 1); - *tmp = ':'; - call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL); - zval_dtor(class); - zval_dtor(method); - } - else { - php_error(E_ERROR, "Unable to call %s - not a Class::Method\n", handler->name); - /* not a class::method */ - } - break; - default: - /* not a valid type */ - assert(0); - break; - } - zval_dtor(req); - AP(in_request) = 0; - - return OK; -} - -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/caudium/CREDITS b/sapi/caudium/CREDITS deleted file mode 100644 index 45789dbdfed33..0000000000000 --- a/sapi/caudium/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Caudium / Roxen -David Hedbor diff --git a/sapi/caudium/README b/sapi/caudium/README deleted file mode 100644 index 86ef65655d42e..0000000000000 --- a/sapi/caudium/README +++ /dev/null @@ -1,16 +0,0 @@ -Embedded Caudium PHP support. It seems to work but isn't tested -much. Due to a design choice it requires _Pike_ threads and a -thread-safe PHP. It doesn't however require _Caudium_ to run in -threaded mode. Due to the design, utilization of multiple processors -should be pretty good. - -It requires a new Pike 7.0 and Caudium. It will not work with -Roxen. Also, with the help of the VIRTUAL_DIR code in PHP, PHP -execution should be very similar to that of mod_php or the cgi -script. - -If you have any questions, please contact me, David Hedbor -(neotron@php.net or neotron@caudium.net). For more information on -Caudium, see http://caudium.net/ and http://caudium.org/. - - diff --git a/sapi/caudium/TODO b/sapi/caudium/TODO deleted file mode 100644 index b8217c5934927..0000000000000 --- a/sapi/caudium/TODO +++ /dev/null @@ -1,30 +0,0 @@ -TODO: - -- per-virtual-server configuration -- configurable limit of number of concurrent PHP executions -- fix setting of auth info. - -FIXED: -+ => fixed -- => not fixed and no fix planned -? => Maybe fixed, maybe not. - -+ Allow multiple headers - This is now fixed. -+ fix backtraces - Uses th_farm, thus problem is fixed -+ exit in PHP exits Caudium - Name conflict with do_exit in Pike and PHP. Reported to both teams. -+ POST newline added? - Was a Caudium bug. -+ use th_farm - Yeppers. Works great. -- change cwd in single threaded mode - There will be no single threaded mode support. The Caudium module - will requite PHP ZTS and Pike threads to run. Single threaded PHP - is rather uninteresting anyway. -? Recursive mutex lock problem: - Dunno if this is fixed. Major rewrite so it would have to be - retested. - - diff --git a/sapi/caudium/caudium.c b/sapi/caudium/caudium.c deleted file mode 100644 index 9a00b1620a9e4..0000000000000 --- a/sapi/caudium/caudium.c +++ /dev/null @@ -1,782 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: David Hedbor | - | Based on aolserver SAPI by Sascha Schumann | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#ifdef HAVE_CAUDIUM - -#include "php_ini.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_main.h" -#include "ext/standard/info.h" - -#include "php_version.h" - -/* Pike Include Files - * - * conflicts with pike avoided by only using long names. Requires a new - * Pike 0.7 since it was implemented for this interface only. - * - */ -#define NO_PIKE_SHORTHAND - -/* Ok, we are now using Pike level threads to handle PHP7 since - * the nice th_farm threads aren't working on Linux with glibc 2.2 - * (why this is I don't know). - */ -#define USE_PIKE_LEVEL_THREADS - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if (PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION == 1 && PIKE_BUILD_VERSION >= 12) || PIKE_MAJOR_VERSION > 7 || (PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION > 1) -# include "pike_error.h" -#else -# include "error.h" -# ifndef Pike_error -# define Pike_error error -# endif -#endif - -/* Pike 7.x and newer */ -#define MY_MAPPING_LOOP(md, COUNT, KEY) \ - for(COUNT=0;COUNT < md->data->hashsize; COUNT++ ) \ - for(KEY=md->data->hash[COUNT];KEY;KEY=KEY->next) - -#ifndef ZTS -/* Need thread safety */ -#error You need to compile PHP with threads. -#endif - -#ifndef PIKE_THREADS -#error The PHP7 module requires that your Pike has thread support. -#endif - -#undef HIDE_GLOBAL_VARIABLES -#undef REVEAL_GLOBAL_VARIABLES -#define HIDE_GLOBAL_VARIABLES() -#define REVEAL_GLOBAL_VARIABLES() - -/* php_caudium_request is per-request object storage */ - -typedef struct -{ - struct mapping *request_data; - struct object *my_fd_obj; - struct svalue done_cb; - struct pike_string *filename; - int my_fd; - int written; - TSRMLS_D; -} php_caudium_request; - - -void pike_module_init(void); -void pike_module_exit(void); -static void free_struct(void); -void f_php_caudium_request_handler(INT32 args); - -/* Defines to get to the data supplied when the script is started. */ - -/* Per thread storage area id... */ -static int caudium_globals_id; - -#define GET_THIS() php_caudium_request *_request = ts_resource(caudium_globals_id) -#define THIS _request -#define PTHIS ((php_caudium_request *)(Pike_fp->current_storage)) -/* File descriptor integer. Used to write directly to the FD without - * passing Pike - */ -#define MY_FD (THIS->my_fd) - -/* FD object. Really a PHPScript object from Pike which implements a couple - * of functions to handle headers, writing and buffering. - */ -#define MY_FD_OBJ ((struct object *)(THIS->my_fd_obj)) - -/* Mapping with data supplied from the calling Caudium module. Contains - * a mapping with headers, an FD object etc. - */ -#define REQUEST_DATA ((struct mapping *)(THIS->request_data)) - -extern int fd_from_object(struct object *o); -static unsigned char caudium_php_initialized; - -#ifndef mt_lock_interpreter -#define mt_lock_interpreter() mt_lock(&interpreter_lock); -#define mt_unlock_interpreter() mt_unlock(&interpreter_lock); -#endif - - -/* This allows calling of pike functions from the PHP callbacks, - * which requires the Pike interpreter to be locked. - */ -#define THREAD_SAFE_RUN(COMMAND, what) do {\ - struct thread_state *state;\ - if((state = thread_state_for_id(th_self()))!=NULL) {\ - if(!state->swapped) {\ - COMMAND;\ - } else {\ - mt_lock_interpreter();\ - SWAP_IN_THREAD(state);\ - COMMAND;\ - SWAP_OUT_THREAD(state);\ - mt_unlock_interpreter();\ - }\ - }\ -} while(0) - - - -/* Low level header lookup. Basically looks for the named header in the mapping - * headers in the supplied options mapping. - */ - -INLINE static struct svalue *lookup_header(char *headername) -{ - struct svalue *headers, *value; - struct pike_string *sind; - GET_THIS(); - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(!headers || headers->type != PIKE_T_MAPPING) return NULL; - sind = make_shared_string(headername); - value = low_mapping_string_lookup(headers->u.mapping, sind); - free_string(sind); - if(!value) return NULL; - return value; -} - -/* Lookup a header in the mapping and return the value as a string, or - * return the default if it's missing - */ -INLINE static char *lookup_string_header(char *headername, char *default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_STRING) - return default_value; - return head->u.string->str; -} - -/* Lookup a header in the mapping and return the value as if it's an integer - * and otherwise return the default. - */ -INLINE static int lookup_integer_header(char *headername, int default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_INT) - return default_value; - return head->u.integer; -} - -/* - * php_caudium_low_ub_write() writes data to the client connection. Might be - * rewritten to do more direct IO to save CPU and the need to lock the - * interpreter for better threading. - */ - -INLINE static int -php_caudium_low_ub_write(const char *str, uint str_length) { - int sent_bytes = 0; - struct pike_string *to_write = NULL; - GET_THIS(); - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - to_write = make_shared_binary_string(str, str_length); - push_string(to_write); - safe_apply(MY_FD_OBJ, "write", 1); - if(Pike_sp[-1].type == PIKE_T_INT) - sent_bytes = Pike_sp[-1].u.integer; - pop_stack(); - if(sent_bytes != str_length) { - /* This means the connection is closed. Dead. Gone. *sniff* */ - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - } - return sent_bytes; -} - -/* - * php_caudium_sapi_ub_write() calls php_caudium_low_ub_write in a Pike thread - * safe manner or writes directly to the output FD if RXML post-parsing is - * disabled. - */ - -static int -php_caudium_sapi_ub_write(const char *str, uint str_length) -{ - GET_THIS(); - int sent_bytes = 0, fd = MY_FD; - if(fd) - { - for(sent_bytes=0;sent_bytes < str_length;) - { - int written; - written = fd_write(fd, str + sent_bytes, str_length - sent_bytes); - if(written < 0) - { - switch(errno) - { - default: - /* This means the connection is closed. Dead. Gone. *sniff* */ - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - THIS->written += sent_bytes; - return sent_bytes; - case EINTR: - case EWOULDBLOCK: - continue; - } - } else { - sent_bytes += written; - } - } - THIS->written += sent_bytes; - } else { - THREAD_SAFE_RUN(sent_bytes = php_caudium_low_ub_write(str, str_length), - "write"); - } - return sent_bytes; -} - -/* php_caudium_set_header() sets a header in the header mapping. Called in a - * thread safe manner from php_caudium_sapi_header_handler. - */ -INLINE static void -php_caudium_set_header(char *header_name, char *value, char *p) -{ - struct svalue hsval; - struct pike_string *hval, *ind, *hind; - struct mapping *headermap; - struct svalue *s_headermap, *soldval; - int vallen; - GET_THIS(); - /* hval = make_shared_string(value); */ - ind = make_shared_string(" _headers"); - hind = make_shared_binary_string(header_name, - (int)(p - header_name)); - - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - if(!s_headermap || s_headermap->type != PIKE_T_MAPPING) - { - struct svalue mappie; - mappie.type = PIKE_T_MAPPING; - headermap = allocate_mapping(1); - mappie.u.mapping = headermap; - mapping_string_insert(REQUEST_DATA, ind, &mappie); - free_mapping(headermap); - hval = make_shared_string(value); - } else { - headermap = s_headermap->u.mapping; - soldval = low_mapping_string_lookup(headermap, hind); - vallen = strlen(value); - if(soldval != NULL && - soldval->type == PIKE_T_STRING && - soldval->u.string->size_shift == 0) { - /* Existing, valid header. Prepend.*/ - hval = begin_shared_string(soldval->u.string->len + 1 + vallen); - MEMCPY(hval->str, soldval->u.string->str, soldval->u.string->len); - STR0(hval)[soldval->u.string->len] = '\0'; - MEMCPY(hval->str+soldval->u.string->len+1, value, vallen); - hval = end_shared_string(hval); - } else { - hval = make_shared_string(value); - } - } - hsval.type = PIKE_T_STRING; - hsval.u.string = hval; - - mapping_string_insert(headermap, hind, &hsval); - - free_string(hval); - free_string(ind); - free_string(hind); -} - -/* - * php_caudium_sapi_header_handler() sets a HTTP reply header to be - * sent to the client. - */ -static int -php_caudium_sapi_header_handler(sapi_header_struct *sapi_header, - sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content, *p; - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - - if(p) { - do { - header_content++; - } while(*header_content == ' '); - THREAD_SAFE_RUN(php_caudium_set_header(header_name, header_content, p), "header handler"); - } - sapi_free_header(sapi_header); - return 0; -} - -/* - * php_caudium_sapi_send_headers() flushes the headers to the client. - * Called before real content is sent by PHP. - */ - -INLINE static int -php_caudium_low_send_headers(sapi_headers_struct *sapi_headers) -{ - struct pike_string *ind; - struct svalue *s_headermap; - GET_THIS(); - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return SAPI_HEADER_SEND_FAILED; - } - ind = make_shared_string(" _headers"); - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - free_string(ind); - - push_int(SG(sapi_headers).http_response_code); - if(s_headermap && s_headermap->type == PIKE_T_MAPPING) - ref_push_mapping(s_headermap->u.mapping); - else - push_int(0); - safe_apply(MY_FD_OBJ, "send_headers", 2); - pop_stack(); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int -php_caudium_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - int res = 0; - THREAD_SAFE_RUN(res = php_caudium_low_send_headers(sapi_headers), "send headers"); - return res; -} - -/* - * php_caudium_sapi_read_post() reads a specified number of bytes from - * the client. Used for POST/PUT requests. - */ - -INLINE static int php_caudium_low_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; - GET_THIS(); - - if(!MY_FD_OBJ->prog) - { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - push_int(count_bytes); - safe_apply(MY_FD_OBJ, "read_post", 1); - if(Pike_sp[-1].type == PIKE_T_STRING) { - MEMCPY(buf, Pike_sp[-1].u.string->str, - (total_read = Pike_sp[-1].u.string->len)); - buf[total_read] = '\0'; - } else - total_read = 0; - pop_stack(); - return total_read; -} - -static int -php_caudium_sapi_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; - THREAD_SAFE_RUN(total_read = php_caudium_low_read_post(buf, count_bytes), "read post"); - return total_read; -} - -/* - * php_caudium_sapi_read_cookies() returns the Cookie header from - * the HTTP request header - */ - -static char * -php_caudium_sapi_read_cookies(void) -{ - char *cookies; - cookies = lookup_string_header("HTTP_COOKIE", NULL); - return cookies; -} - -static void php_info_caudium(ZEND_MODULE_INFO_FUNC_ARGS) -{ - /* char buf[512]; */ - php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", "$Id$"); - /* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate()); - php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile()); - php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog()); - php_info_print_table_row(2, "Installation path", Ns_InfoHomePath()); - php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname()); - php_info_print_table_row(2, "Source code label", Ns_InfoLabel()); - php_info_print_table_row(2, "Server platform", Ns_InfoPlatform()); - snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion()); - php_info_print_table_row(2, "Server version", buf); - snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", - uptime / 86400, - (uptime / 3600) % 24, - (uptime / 60) % 60, - uptime % 60); - php_info_print_table_row(2, "Server uptime", buf); - */ - php_info_print_table_end(); -} - -static zend_module_entry php_caudium_module = { - STANDARD_MODULE_HEADER, - "Caudium", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_caudium, - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -INLINE static void low_sapi_caudium_register_variables(zval *track_vars_array) -{ - int i; - struct keypair *k; - struct svalue *headers; - struct pike_string *sind; - struct svalue *ind; - struct svalue *val; - GET_THIS(); - php_register_variable("PHP_SELF", SG(request_info).request_uri, - track_vars_array); - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", - track_vars_array); - php_register_variable("REQUEST_METHOD", - (char *) SG(request_info).request_method, - track_vars_array); - php_register_variable("REQUEST_URI", SG(request_info).request_uri, - track_vars_array); - php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, - track_vars_array); - - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(headers && headers->type == PIKE_T_MAPPING) { - MY_MAPPING_LOOP(headers->u.mapping, i, k) { - ind = &k->ind; - val = &k->val; - if(ind && ind->type == PIKE_T_STRING && - val && val->type == PIKE_T_STRING) { - php_register_variable(ind->u.string->str, val->u.string->str, - track_vars_array ); - } - } - } -} - -static void sapi_caudium_register_variables(zval *track_vars_array) -{ - THREAD_SAFE_RUN(low_sapi_caudium_register_variables(track_vars_array), "register_variables"); -} - - -static int php_caudium_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_caudium_module, 1)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - - -/* this structure is static (as in "it does not change") */ -static sapi_module_struct caudium_sapi_module = { - "caudium", - "Caudium", - php_caudium_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - NULL, /* deactivate */ - php_caudium_sapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - php_error, /* error handler */ - php_caudium_sapi_header_handler, /* header handler */ - php_caudium_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - php_caudium_sapi_read_post, /* read POST data */ - php_caudium_sapi_read_cookies, /* read cookies */ - sapi_caudium_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -/* - * php_caudium_module_main() is called by the per-request handler and - * "executes" the script - */ - -static void php_caudium_module_main(php_caudium_request *ureq) -{ - int res; - zend_file_handle file_handle; -#ifndef USE_PIKE_LEVEL_THREADS - struct thread_state *state; - extern struct program *thread_id_prog; -#endif - GET_THIS(); - THIS->filename = ureq->filename; - THIS->done_cb = ureq->done_cb; - THIS->my_fd_obj = ureq->my_fd_obj; - THIS->my_fd = ureq->my_fd; - THIS->request_data = ureq->request_data; - free(ureq); - -#ifndef USE_PIKE_LEVEL_THREADS - mt_lock_interpreter(); - init_interpreter(); -#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1 - thread_id = low_clone(thread_id_prog); - state = OBJ2THREAD(thread_id); - Pike_stack_top=((char *)&state)+ (thread_stack_size-16384) * STACK_DIRECTION; - recoveries = NULL; - call_c_initializers(thread_id); - OBJ2THREAD(thread_id)->id=th_self(); - num_threads++; - thread_table_insert(thread_id); - state->status=THREAD_RUNNING; -#else - Pike_interpreter.thread_id = low_clone(thread_id_prog); - state = OBJ2THREAD(Pike_interpreter.thread_id); - Pike_interpreter.stack_top=((char *)&state)+ (thread_stack_size-16384) * STACK_DIRECTION; - Pike_interpreter.recoveries = NULL; - call_c_initializers(Pike_interpreter.thread_id); - state->id=th_self(); - /* SWAP_OUT_THREAD(OBJ2THREAD(Pike_interpreter.thread_id)); */ - num_threads++; - thread_table_insert(Pike_interpreter.thread_id); - state->status=THREAD_RUNNING; -#endif - state->swapped = 0; -#endif - SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0); - SG(server_context) = (void *)1; /* avoid server_context == NULL */ - - /* path_translated is apparently the absolute path to the file, not - the translated PATH_INFO - */ - SG(request_info).path_translated = - lookup_string_header("SCRIPT_FILENAME", NULL); - SG(request_info).request_uri = lookup_string_header("DOCUMENT_URI", NULL); - if(!SG(request_info).request_uri) - SG(request_info).request_uri = lookup_string_header("SCRIPT_NAME", NULL); - SG(request_info).request_method = lookup_string_header("REQUEST_METHOD", "GET"); - SG(request_info).content_length = lookup_integer_header("HTTP_CONTENT_LENGTH", 0); - SG(request_info).content_type = lookup_string_header("HTTP_CONTENT_TYPE", NULL); - SG(sapi_headers).http_response_code = 200; - if (!strcmp(SG(request_info).request_method, "HEAD")) { - SG(request_info).headers_only = 1; - } else { - SG(request_info).headers_only = 0; - } - - /* Let PHP7 handle the deconding of the AUTH */ - php_handle_auth_data(lookup_string_header("HTTP_AUTHORIZATION", NULL), ); - /* Swap out this thread and release the interpreter lock to allow - * Pike threads to run. We wait since the above would otherwise require - * a lot of unlock/lock. - */ -#ifndef USE_PIKE_LEVEL_THREADS - SWAP_OUT_THREAD(state); - mt_unlock_interpreter(); -#else - THREADS_ALLOW(); -#endif - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = THIS->filename->str; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - - THIS->written = 0; - res = php_request_startup(); - - if(res == FAILURE) { - THREAD_SAFE_RUN({ - apply_svalue(&THIS->done_cb, 0); - pop_stack(); - free_struct(); - }, "Negative run response"); - } else { - php_execute_script(&file_handle); - php_request_shutdown(NULL); - THREAD_SAFE_RUN({ - push_int(THIS->written); - apply_svalue(&THIS->done_cb, 1); - pop_stack(); - free_struct(); - }, "positive run response"); - } - -#ifndef USE_PIKE_LEVEL_THREADS - mt_lock_interpreter(); - SWAP_IN_THREAD(state); -#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1 - state->status=THREAD_EXITED; - co_signal(& state->status_change); - thread_table_delete(thread_id); - free_object(thread_id); - thread_id=NULL; -#else - state->status=THREAD_EXITED; - co_signal(& state->status_change); - thread_table_delete(Pike_interpreter.thread_id); - free_object(Pike_interpreter.thread_id); - Pike_interpreter.thread_id=NULL; -#endif - cleanup_interpret(); - num_threads--; - mt_unlock_interpreter(); -#else - THREADS_DISALLOW(); -#endif -} - -/* - * The php_caudium_request_handler() is called per request and handles - * everything for one request. - */ - -void f_php_caudium_request_handler(INT32 args) -{ - struct object *my_fd_obj; - struct mapping *request_data; - struct svalue *done_callback; - struct pike_string *script; - struct svalue *raw_fd; - struct pike_string *ind; - php_caudium_request *_request; - THIS = malloc(sizeof(php_caudium_request)); - if(THIS == NULL) - Pike_error("Out of memory."); - - get_all_args("PHP5.Interpreter->run", args, "%S%m%O%*", &script, - &request_data, &my_fd_obj, &done_callback); - if(done_callback->type != PIKE_T_FUNCTION) - Pike_error("PHP5.Interpreter->run: Bad argument 4, expected function.\n"); - add_ref(request_data); - add_ref(my_fd_obj); - add_ref(script); - - THIS->request_data = request_data; - THIS->my_fd_obj = my_fd_obj; - THIS->filename = script; - assign_svalue_no_free(&THIS->done_cb, done_callback); - - ind = make_shared_binary_string("my_fd", 5); - raw_fd = low_mapping_string_lookup(THIS->request_data, ind); - if(raw_fd && raw_fd->type == PIKE_T_OBJECT) - { - int fd = fd_from_object(raw_fd->u.object); - if(fd == -1) - THIS->my_fd = 0; /* Don't send directly to this FD... */ - else - THIS->my_fd = fd; - } else - THIS->my_fd = 0; -#ifdef USE_PIKE_LEVEL_THREADS - php_caudium_module_main(THIS); -#else - th_farm((void (*)(void *))php_caudium_module_main, THIS); -#endif - pop_n_elems(args); -} - -static void free_struct(void) -{ - GET_THIS(); - if(THIS->request_data) free_mapping(THIS->request_data); - if(THIS->my_fd_obj) free_object(THIS->my_fd_obj); - free_svalue(&THIS->done_cb); - if(THIS->filename) free_string(THIS->filename); - MEMSET(THIS, 0, sizeof(php_caudium_request)); -} - - -/* - * pike_module_init() is called by Pike once at startup - * - * This functions allocates basic structures - */ - -void pike_module_init( void ) -{ - if (!caudium_php_initialized) { - caudium_php_initialized = 1; - tsrm_startup(1, 1, 0, NULL); - ts_allocate_id(&caudium_globals_id, sizeof(php_caudium_request), NULL, NULL); - sapi_startup(&caudium_sapi_module); - sapi_module.startup(&caudium_sapi_module); - } - start_new_program(); /* Text */ - pike_add_function("run", f_php_caudium_request_handler, - "function(string, mapping, object, function:void)", 0); - end_class("Interpreter", 0); -} - -/* - * pike_module_exit() performs the last steps before the - * server exists. Shutdowns basic services and frees memory - */ - -void pike_module_exit(void) -{ - caudium_php_initialized = 0; - sapi_module.shutdown(&caudium_sapi_module); - tsrm_shutdown(); -} -#endif diff --git a/sapi/caudium/config.m4 b/sapi/caudium/config.m4 deleted file mode 100644 index 13a6b2943e60f..0000000000000 --- a/sapi/caudium/config.m4 +++ /dev/null @@ -1,98 +0,0 @@ -dnl -dnl $Id$ -dnl - -RESULT=no -PHP_ARG_WITH(caudium,, -[ --with-caudium[=DIR] Build PHP as a Pike module for use with Caudium. - DIR is the Caudium server dir [/usr/local/caudium/server]], no, no) - -AC_MSG_CHECKING([for Caudium support]) - -if test "$PHP_CAUDIUM" != "no"; then - if test "$prefix" = "NONE"; then CPREF=/usr/local/; fi - if test ! -d $PHP_CAUDIUM ; then - if test "$prefix" = "NONE"; then - PHP_CAUDIUM=/usr/local/caudium/server/ - else - PHP_CAUDIUM=$prefix/caudium/server/ - fi - fi - if test -f $PHP_CAUDIUM/bin/caudium; then - PIKE=$PHP_CAUDIUM/bin/caudium - elif test -f $PHP_CAUDIUM/bin/pike; then - PIKE=$PHP_CAUDIUM/bin/pike - else - AC_MSG_ERROR([Could not find a pike in $PHP_CAUDIUM/bin/]) - fi - if $PIKE -e 'float v; int rel;sscanf(version(), "Pike v%f release %d", v, rel);v += rel/10000.0; if(v < 7.0268) exit(1); exit(0);'; then - PIKE_MODULE_DIR=`$PIKE --show-paths 2>&1| grep '^Module' | sed -e 's/.*: //'` - PIKE_INCLUDE_DIR=`echo $PIKE_MODULE_DIR | sed -e 's,lib/pike/modules,include/pike,' -e 's,lib/modules,include/pike,' ` - if test -z "$PIKE_INCLUDE_DIR" || test -z "$PIKE_MODULE_DIR"; then - AC_MSG_ERROR(Failed to figure out Pike module and include directories) - fi - AC_MSG_RESULT(yes) - PIKE=`echo $PIKE | pike -e 'int tries=100; - string orig,pike=Stdio.File("stdin")->read()-"\n"; - orig=pike; - if(search(orig, "/")) - orig = combine_path(getcwd(), orig); - while(!catch(pike=readlink(pike)) && tries--) - ; - write(combine_path(dirname(orig), pike)); '` - PHP_ADD_INCLUDE($PIKE_INCLUDE_DIR) - if test "$prefix" != "NONE"; then - PIKE_C_INCLUDE=$prefix/include/`basename $PIKE` - else - PIKE_C_INCLUDE=/usr/local/include/`basename $PIKE` - fi - AC_MSG_CHECKING([for C includes in $PIKE_C_INCLUDE]) - if test -f $PIKE_C_INCLUDE/version.h; then - PIKE_TEST_VER=`$PIKE -e 'string v; int rel;sscanf(version(), "Pike v%s release %d", v, rel); write(v+"."+rel);'` - ###### VERSION MATCH CHECK ####### - PMAJOR="^#define PIKE_MAJOR_VERSION" - PMINOR="^#define PIKE_MINOR_VERSION" - PBUILD="^#define PIKE_BUILD_VERSION" - - PIKE_CMAJOR_VERSION=0 - PIKE_CMINOR_VERSION=0 - PIKE_CBUILD_VERSION=0 - - PIKE_CMAJOR_VERSION=`grep "$PMAJOR" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'` - if test -z "$PIKE_CMAJOR_VERSION"; then - if test -n "`grep f_version $PIKE_C_INCLUDE/version.h`"; then - PIKE_CMAJOR_VERSION=6 - fi - else - PIKE_CMINOR_VERSION=`grep "$PMINOR" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'` - PIKE_CBUILD_VERSION=`grep "$PBUILD" $PIKE_C_INCLUDE/version.h | sed -e 's/\(#define.*N \)\(.*\)/\2/'` - fi - - if test "$PIKE_TEST_VER" = "${PIKE_CMAJOR_VERSION}.${PIKE_CMINOR_VERSION}.${PIKE_CBUILD_VERSION}"; then - PHP_ADD_INCLUDE($PIKE_C_INCLUDE) - PIKE_INCLUDE_DIR="$PIKE_INCLUDE_DIR, $PIKE_C_INCLUDE" - AC_MSG_RESULT(found) - else - AC_MSG_RESULT(version mismatch) - fi - else - AC_MSG_RESULT(not found) - fi - else - AC_MSG_ERROR([Caudium PHP7 requires Pike 7.0 or newer]) - fi - PIKE_VERSION=`$PIKE -e 'string v; int rel;sscanf(version(), "Pike v%s release %d", v, rel); write(v+"."+rel);'` - AC_DEFINE(HAVE_CAUDIUM,1,[Whether to compile with Caudium support]) - PHP_SELECT_SAPI(caudium, shared, caudium.c) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_CAUDIUM/lib/$PIKE_VERSION/PHP7.so" - RESULT=" *** Pike binary used: $PIKE - *** Pike include dir(s) used: $PIKE_INCLUDE_DIR - *** Pike version: $PIKE_VERSION" - dnl Always use threads since thread-free support really blows. - PHP_BUILD_THREAD_SAFE -fi -AC_MSG_RESULT($RESULT) - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index a0bba17f06b1d..6b934085680f7 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1668,9 +1668,6 @@ PHP_FUNCTION(apache_response_headers) /* {{{ */ return; } - if (!&SG(sapi_headers).headers) { - RETURN_FALSE; - } array_init(return_value); zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value); } diff --git a/sapi/continuity/CREDITS b/sapi/continuity/CREDITS deleted file mode 100644 index 35335e926682f..0000000000000 --- a/sapi/continuity/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Continuity -Alex Leigh (based on nsapi code) diff --git a/sapi/continuity/capi.c b/sapi/continuity/capi.c deleted file mode 100644 index 2f943e3be0d8a..0000000000000 --- a/sapi/continuity/capi.c +++ /dev/null @@ -1,507 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Alex Leigh | - +----------------------------------------------------------------------+ -*/ - -/* For more information on Continuity: http://www.ashpool.com/ */ - -/* - * This code is based on the PHP5 SAPI module for NSAPI by Jayakumar - * Muthukumarasamy - */ - -/* PHP includes */ -#define CONTINUITY 1 -#define CAPI_DEBUG - -/* Define for CDP specific extensions */ -#undef CONTINUITY_CDPEXT - -#include "php.h" -#include "php_variables.h" -#include "ext/standard/info.h" -#include "php_ini.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_version.h" -#include "TSRM.h" -#include "ext/standard/php_standard.h" - -/* - * CAPI includes - */ -#include -#include - -#define NSLS_D struct capi_request_context *request_context -#define NSLS_DC , NSLS_D -#define NSLS_C request_context -#define NSLS_CC , NSLS_C -#define NSG(v) (request_context->v) - -/* - * ZTS needs to be defined for CAPI to work - */ -#if !defined(ZTS) -#error "CAPI module needs ZTS to be defined" -#endif - -/* - * Structure to encapsulate the CAPI request in SAPI - */ -typedef struct capi_request_context { - httpTtrans *t; - int read_post_bytes; -} capi_request_context; - -/**************/ - -PHP_MINIT_FUNCTION(continuity); -PHP_MSHUTDOWN_FUNCTION(continuity); -PHP_RINIT_FUNCTION(continuity); -PHP_RSHUTDOWN_FUNCTION(continuity); -PHP_MINFO_FUNCTION(continuity); - -PHP_FUNCTION(continuity_virtual); -PHP_FUNCTION(continuity_request_headers); -PHP_FUNCTION(continuity_response_headers); - -const zend_function_entry continuity_functions[] = { - {NULL, NULL, NULL} -}; - -zend_module_entry continuity_module_entry = { - STANDARD_MODULE_HEADER, - "continuity", - continuity_functions, - PHP_MINIT(continuity), - PHP_MSHUTDOWN(continuity), - NULL, - NULL, - PHP_MINFO(continuity), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -PHP_MINIT_FUNCTION(continuity) -{ - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(continuity) -{ - return SUCCESS; -} - -PHP_MINFO_FUNCTION(continuity) -{ - php_info_print_table_start(); - php_info_print_table_row(2, "Continuity Module Revision", "$Id$"); - php_info_print_table_row(2, "Server Version", conFget_build()); -#ifdef CONTINUITY_CDPEXT - php_info_print_table_row(2,"CDP Extensions", "enabled"); -#else - php_info_print_table_row(2,"CDP Extensions", "disabled"); -#endif - php_info_print_table_end(); - -/* DISPLAY_INI_ENTRIES(); */ -} - -/**************/ - -/* - * sapi_capi_ub_write: Write len bytes to the connection output. - */ -static int sapi_capi_ub_write(const char *str, unsigned int str_length) -{ - int retval; - capi_request_context *rc; - - rc = (capi_request_context *) SG(server_context); - retval = httpFwrite(rc->t, (char *) str, str_length); - if (retval == -1 || retval == 0) - php_handle_aborted_connection(); - return retval; -} - -/* - * sapi_capi_header_handler: Add/update response headers with those provided - * by the PHP engine. - */ -static int sapi_capi_header_handler(sapi_header_struct * sapi_header, sapi_headers_struct * sapi_headers) -{ - char *header_name, *header_content, *p; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - lstFset_delete_key(rc->t->res_hdrs, "Content-Type"); - - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - if (p == NULL) { - return 0; - } - *p = 0; - do { - header_content++; - } while (*header_content == ' '); - - lstFset_add(rc->t->res_hdrs, header_name, header_content); - - *p = ':'; /* restore '*p' */ - - efree(sapi_header->header); - - return 0; /* don't use the default SAPI mechanism, CAPI - * duplicates this functionality */ -} - -/* - * sapi_capi_send_headers: Transmit the headers to the client. This has the - * effect of starting the response under Continuity. - */ -static int sapi_capi_send_headers(sapi_headers_struct * sapi_headers) -{ - int retval; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - /* - * We could probably just do this in the header_handler. But, I don't know - * what the implication of doing it there is. - */ - - if (SG(sapi_headers).send_default_content_type) { - /* lstFset_delete_key(rc->t->res_hdrs, "Content-Type"); */ - lstFset_update(rc->t->res_hdrs, "Content-Type", "text/html"); - } - httpFset_status(rc->t, SG(sapi_headers).http_response_code, NULL); - httpFstart_response(rc->t); - - return SAPI_HEADER_SENT_SUCCESSFULLY; - -} - -static int sapi_capi_read_post(char *buffer, uint count_bytes) -{ - unsigned int max_read, total_read = 0; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - if (rc->read_post_bytes == -1) { - max_read = MIN(count_bytes, SG(request_info).content_length); - } else { - if (rc->read_post_bytes == 0) - return 0; - max_read = MIN(count_bytes, (SG(request_info).content_length - rc->read_post_bytes)); - } - - total_read = httpFread(rc->t, buffer, max_read); - - if (total_read < 0) - total_read = -1; - else - rc->read_post_bytes = total_read; - - return total_read; -} - -/* - * sapi_capi_read_cookies: Return cookie information into PHP. - */ -static char *sapi_capi_read_cookies(void) -{ - char *cookie_string; - capi_request_context *rc = (capi_request_context *) SG(server_context); - - cookie_string = lstFset_get(rc->t->req_hdrs, "cookie"); - return cookie_string; -} - -static void sapi_capi_register_server_variables(zval * track_vars_array) -{ - capi_request_context *rc = (capi_request_context *) SG(server_context); - size_t i; - char *value; - char buf[128]; - - /* PHP_SELF and REQUEST_URI */ - value = lstFset_get(rc->t->vars, "uri"); - if (value != NULL) { - php_register_variable("PHP_SELF", value, track_vars_array); - php_register_variable("REQUEST_URI", value, track_vars_array); - } - - /* COUNTRY CODE */ - value = lstFset_get(rc->t->vars, "ccode"); - if(value!=NULL) - php_register_variable("COUNTRY_CODE", value, track_vars_array); - - /* argv */ - value = lstFset_get(rc->t->vars, "query"); - if (value != NULL) - php_register_variable("argv", value, track_vars_array); - - /* GATEWAY_INTERFACE */ - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); - - /* SERVER_NAME and HTTP_HOST */ - value = lstFset_get(rc->t->req_hdrs, "host"); - if (value != NULL) { - php_register_variable("HTTP_HOST", value, track_vars_array); - /* TODO: This should probably scrub the port value if one is present. */ - php_register_variable("SERVER_NAME", value, track_vars_array); - } - /* SERVER_SOFTWARE */ - value = lstFset_get(rc->t->res_hdrs, "Server"); - if (value != NULL) - php_register_variable("SERVER_SOFTWARE", value, track_vars_array); - - /* SERVER_PROTOCOL */ - value = lstFset_get(rc->t->vars, "protocol"); - if (value != NULL) - php_register_variable("SERVER_PROTOCOL", value, track_vars_array); - - /* REQUEST_METHOD */ - value = lstFset_get(rc->t->vars, "method"); - if (value != NULL) - php_register_variable("REQUEST_METHOD", value, track_vars_array); - - /* QUERY_STRING */ - value = lstFset_get(rc->t->vars, "query"); - if (value != NULL) - php_register_variable("QUERY_STRING", value, track_vars_array); - - /* DOCUMENT_ROOT */ - value = lstFset_get(rc->t->vars, "docroot"); - if (value != NULL) - php_register_variable("DOCUMENT_ROOT", value, track_vars_array); - - /* HTTP_ACCEPT */ - value = lstFset_get(rc->t->req_hdrs, "accept"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT", value, track_vars_array); - - /* HTTP_ACCEPT_CHARSET */ - value = lstFset_get(rc->t->req_hdrs, "accept-charset"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT_CHARSET", value, track_vars_array); - - /* HTTP_ACCEPT_ENCODING */ - value = lstFset_get(rc->t->req_hdrs, "accept-encoding"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT_ENCODING", value, track_vars_array); - - /* HTTP_ACCEPT_LANGUAGE */ - value = lstFset_get(rc->t->req_hdrs, "accept-language"); - if (value != NULL) - php_register_variable("HTTP_ACCEPT_LANGUAGE", value, track_vars_array); - - /* HTTP_CONNECTION */ - value = lstFset_get(rc->t->req_hdrs, "connection"); - if (value != NULL) - php_register_variable("HTTP_CONNECTION", value, track_vars_array); - - /* HTTP_REFERER */ - value = lstFset_get(rc->t->req_hdrs, "referer"); - if (value != NULL) - php_register_variable("HTTP_REFERER", value, track_vars_array); - - /* HTTP_USER_AGENT */ - value = lstFset_get(rc->t->req_hdrs, "user-agent"); - if (value != NULL) - php_register_variable("HTTP_USER_AGENT", value, track_vars_array); - - /* REMOTE_ADDR */ - utlFip_to_str(rc->t->cli_ipv4_addr, buf, sizeof(buf)); - php_register_variable("REMOTE_ADDR", buf, track_vars_array); - - /* REMOTE_PORT */ - - /* SCRIPT_FILENAME and PATH_TRANSLATED */ - value = lstFset_get(rc->t->vars, "path"); - if (value != NULL) { - php_register_variable("SCRIPT_FILENAME", value, track_vars_array); - php_register_variable("PATH_TRANSLATED", value, track_vars_array); - } - /* SERVER_ADMIN */ - /* Not applicable */ - - /* SERVER_PORT */ - -} - -static void capi_log_message(char *message) -{ - capi_request_context *rc = (capi_request_context *) SG(server_context); - logFmsg(0, "mod/php: %s", message); -} - -static int php_capi_startup(sapi_module_struct *sapi_module); - -sapi_module_struct capi_sapi_module = { - "Continuity", /* name */ - "Continuity Server Enterprise Edition", /* pretty name */ - - php_capi_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_capi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - sapi_capi_header_handler, /* header handler */ - sapi_capi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_capi_read_post, /* read POST data */ - sapi_capi_read_cookies, /* read Cookies */ - - sapi_capi_register_server_variables, /* register server variables */ - capi_log_message, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -static int php_capi_startup(sapi_module_struct *sapi_module) { - if(php_module_startup(sapi_module,&continuity_module_entry,1)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - - -static char * - capi_strdup(char *str) -{ - if (str != NULL) - return strFcopy(str); - return NULL; -} - -static void capi_free(void *addr) -{ - if (addr != NULL) - free(addr); -} - -static void capi_request_ctor(NSLS_D) -{ - char *query_string = lstFset_get(NSG(t->vars), "query"); - char *uri = lstFset_get(NSG(t->vars), "uri"); - char *path_info = lstFset_get(NSG(t->vars), "path-info"); - char *path_translated = lstFset_get(NSG(t->vars), "path"); - char *request_method = lstFset_get(NSG(t->vars), "method"); - char *content_type = lstFset_get(NSG(t->req_hdrs), "content-type"); - char *content_length = lstFset_get(NSG(t->req_hdrs), "content-length"); - - SG(request_info).query_string = capi_strdup(query_string); - SG(request_info).request_uri = capi_strdup(uri); - SG(request_info).request_method = capi_strdup(request_method); - SG(request_info).path_translated = capi_strdup(path_translated); - SG(request_info).content_type = capi_strdup(content_type); - SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0); - SG(sapi_headers).http_response_code = 200; -} - -static void capi_request_dtor(NSLS_D) -{ - capi_free(SG(request_info).query_string); - capi_free(SG(request_info).request_uri); - capi_free(SG(request_info).request_method); - capi_free(SG(request_info).path_translated); - capi_free(SG(request_info).content_type); -} - -int capi_module_main(NSLS_D) -{ - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return FAILURE; - } - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - php_request_shutdown(NULL); - - return SUCCESS; -} - -int phpFinit(lstTset * opt) -{ - php_core_globals *core_globals; - - tsrm_startup(128, 1, 0, NULL); - core_globals = ts_resource(core_globals_id); - - logFmsg(0, "mod/php: PHP Interface v3 (module)"); - logFmsg(0, "mod/php: Copyright (c) 1999-2015 The PHP Group. All rights reserved."); - - sapi_startup(&capi_sapi_module); - capi_sapi_module.startup(&capi_sapi_module); - - return STATUS_PROCEED; -} - -int phpFservice(httpTtrans * t, lstTset * opts) -{ - int retval; - capi_request_context *request_context; - - - request_context = (capi_request_context *) malloc(sizeof(capi_request_context)); - request_context->t = t; - request_context->read_post_bytes = -1; - - SG(server_context) = request_context; - - capi_request_ctor(NSLS_C); - retval = capi_module_main(NSLS_C); - capi_request_dtor(NSLS_C); - - free(request_context); - - /* - * This call is ostensibly provided to free the memory from PHP/TSRM when - * the thread terminated, but, it leaks a structure in some hash list - * according to the developers. Not calling this will leak the entire - * interpreter, around 100k, but calling it and then terminating the - * thread will leak the struct (around a k). The only answer with the - * current TSRM implementation is to reuse the threads that allocate TSRM - * resources. - */ - /* ts_free_thread(); */ - - if (retval == SUCCESS) { - return STATUS_EXIT; - } else { - return STATUS_ERROR; - } -} diff --git a/sapi/continuity/config.m4 b/sapi/continuity/config.m4 deleted file mode 100644 index 8d2741921ae4a..0000000000000 --- a/sapi/continuity/config.m4 +++ /dev/null @@ -1,28 +0,0 @@ -dnl ## $Id$ -*- sh -*- - -PHP_ARG_WITH(continuity, for Continuity support, -[ --with-continuity=DIR Build PHP as Continuity Server module. - DIR is path to the installed Continuity Server root], no, no) - -if test "$PHP_CONTINUITY" != "no"; then - if test ! -d $PHP_CONTINUITY; then - AC_MSG_ERROR([Please specify the path to the root of your Continuity server using --with-continuity=DIR]) - fi - AC_MSG_CHECKING([for Continuity include files]) - if test -d $PHP_CONTINUITY/include ; then - CAPI_INCLUDE=$PHP_CONTINUITY/include - AC_MSG_RESULT([Continuity Binary Distribution]) - else - AC_MSG_ERROR([Cannot find your CAPI include files in either DIR/src or DIR/include]) - fi - - PHP_SELECT_SAPI(continuity, shared, capi.c) - PHP_ADD_INCLUDE($CAPI_INCLUDE) - PHP_BUILD_THREAD_SAFE - AC_DEFINE(HAVE_CONTINUITY, 1, [Whether you have a Continuity Server]) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHP_CONTINUITY/lib/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/isapi/CREDITS b/sapi/isapi/CREDITS deleted file mode 100644 index 11c6fdc73c599..0000000000000 --- a/sapi/isapi/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -ISAPI -Andi Gutmans, Zeev Suraski diff --git a/sapi/isapi/config.m4 b/sapi/isapi/config.m4 deleted file mode 100644 index 4073173eafc61..0000000000000 --- a/sapi/isapi/config.m4 +++ /dev/null @@ -1,24 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(isapi, for Zeus ISAPI support, -[ --with-isapi[=DIR] Build PHP as an ISAPI module for use with Zeus], no, no) - -if test "$PHP_ISAPI" != "no"; then - if test "$PHP_ISAPI" = "yes"; then - ZEUSPATH=/usr/local/zeus # the default - else - ZEUSPATH=$PHP_ISAPI - fi - test -f "$ZEUSPATH/web/include/httpext.h" || AC_MSG_ERROR(Unable to find httpext.h in $ZEUSPATH/web/include) - PHP_BUILD_THREAD_SAFE - AC_DEFINE(WITH_ZEUS, 1, [ ]) - PHP_ADD_INCLUDE($ZEUSPATH/web/include) - PHP_SELECT_SAPI(isapi, shared, php7isapi.c) - INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$ZEUSPATH/web/bin/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/isapi/config.w32 b/sapi/isapi/config.w32 deleted file mode 100644 index 5a359f11b2070..0000000000000 --- a/sapi/isapi/config.w32 +++ /dev/null @@ -1,13 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_ENABLE('isapi', 'Build ISAPI version of PHP', 'no'); - -if (PHP_ISAPI == "yes") { - if (PHP_ZTS == "no") { - WARNING("ISAPI module requires an --enable-zts build of PHP"); - } else { - SAPI('isapi', 'php7isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP7ISAPI_EXPORTS'); - ADD_FLAG('LDFLAGS_ISAPI', '/DEF:sapi\\isapi\\php7isapi.def'); - } -} diff --git a/sapi/isapi/php.sym b/sapi/isapi/php.sym deleted file mode 100644 index 34b50b851cad0..0000000000000 --- a/sapi/isapi/php.sym +++ /dev/null @@ -1,5 +0,0 @@ -GetFilterVersion -HttpFilterProc -GetExtensionVersion -HttpExtensionProc -ZSLMain diff --git a/sapi/isapi/php7isapi.c b/sapi/isapi/php7isapi.c deleted file mode 100644 index 627c20c18cc62..0000000000000 --- a/sapi/isapi/php7isapi.c +++ /dev/null @@ -1,971 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Authors: Zeev Suraski | - | Ben Mansell (Zeus Support) | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" -#include -#include -#include -#include "php_main.h" -#include "SAPI.h" -#include "php_globals.h" -#include "ext/standard/info.h" -#include "php_variables.h" -#include "php_ini.h" - -#ifdef PHP_WIN32 -# include -#else -# define __try -# define __except(val) -# define __declspec(foo) -#endif - - -#ifdef WITH_ZEUS -# include "httpext.h" -# include -# define GetLastError() errno -#endif - -#ifdef PHP_WIN32 -#define PHP_ENABLE_SEH -#endif - -/* -uncomment the following lines to turn off -exception trapping when running under a debugger - -#ifdef _DEBUG -#undef PHP_ENABLE_SEH -#endif -*/ - -#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST POSSIBLE STATUS DESCRIPTION") -#define ISAPI_SERVER_VAR_BUF_SIZE 1024 -#define ISAPI_POST_DATA_BUF 1024 - -static zend_bool bFilterLoaded=0; -static zend_bool bTerminateThreadsOnError=0; - -static char *isapi_special_server_variable_names[] = { - "ALL_HTTP", - "HTTPS", -#ifndef WITH_ZEUS - "SCRIPT_NAME", -#endif - NULL -}; - -#define NUM_SPECIAL_VARS (sizeof(isapi_special_server_variable_names)/sizeof(char *)) -#define SPECIAL_VAR_ALL_HTTP 0 -#define SPECIAL_VAR_HTTPS 1 -#define SPECIAL_VAR_PHP_SELF 2 - -static char *isapi_server_variable_names[] = { - "AUTH_PASSWORD", - "AUTH_TYPE", - "AUTH_USER", - "CONTENT_LENGTH", - "CONTENT_TYPE", - "PATH_TRANSLATED", - "QUERY_STRING", - "REMOTE_ADDR", - "REMOTE_HOST", - "REMOTE_USER", - "REQUEST_METHOD", - "SERVER_NAME", - "SERVER_PORT", - "SERVER_PROTOCOL", - "SERVER_SOFTWARE", -#ifndef WITH_ZEUS - "APPL_MD_PATH", - "APPL_PHYSICAL_PATH", - "INSTANCE_ID", - "INSTANCE_META_PATH", - "LOGON_USER", - "REQUEST_URI", - "URL", -#else - "DOCUMENT_ROOT", -#endif - NULL -}; - - -static char *isapi_secure_server_variable_names[] = { - "CERT_COOKIE", - "CERT_FLAGS", - "CERT_ISSUER", - "CERT_KEYSIZE", - "CERT_SECRETKEYSIZE", - "CERT_SERIALNUMBER", - "CERT_SERVER_ISSUER", - "CERT_SERVER_SUBJECT", - "CERT_SUBJECT", - "HTTPS_KEYSIZE", - "HTTPS_SECRETKEYSIZE", - "HTTPS_SERVER_ISSUER", - "HTTPS_SERVER_SUBJECT", - "SERVER_PORT_SECURE", -#ifdef WITH_ZEUS - "SSL_CLIENT_CN", - "SSL_CLIENT_EMAIL", - "SSL_CLIENT_OU", - "SSL_CLIENT_O", - "SSL_CLIENT_L", - "SSL_CLIENT_ST", - "SSL_CLIENT_C", - "SSL_CLIENT_I_CN", - "SSL_CLIENT_I_EMAIL", - "SSL_CLIENT_I_OU", - "SSL_CLIENT_I_O", - "SSL_CLIENT_I_L", - "SSL_CLIENT_I_ST", - "SSL_CLIENT_I_C", -#endif - NULL -}; - - -static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS) -{ - char **p; - char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len; - char **all_variables[] = { - isapi_server_variable_names, - isapi_special_server_variable_names, - isapi_secure_server_variable_names, - NULL - }; - char ***server_variable_names; - LPEXTENSION_CONTROL_BLOCK lpECB; - - lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - - php_info_print_table_start(); - php_info_print_table_header(2, "Server Variable", "Value"); - server_variable_names = all_variables; - while (*server_variable_names) { - p = *server_variable_names; - while (*p) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, *p, variable_buf); - } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - char *tmp_variable_buf; - - tmp_variable_buf = (char *) emalloc(variable_len); - if (lpECB->GetServerVariable(lpECB->ConnID, *p, tmp_variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, *p, tmp_variable_buf); - } - efree(tmp_variable_buf); - } - p++; - } - server_variable_names++; - } - php_info_print_table_end(); -} - - -static zend_module_entry php_isapi_module = { - STANDARD_MODULE_HEADER, - "ISAPI", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_isapi, - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -static int sapi_isapi_ub_write(const char *str, uint str_length) -{ - DWORD num_bytes = str_length; - LPEXTENSION_CONTROL_BLOCK ecb; - - ecb = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - if (ecb->WriteClient(ecb->ConnID, (char *) str, &num_bytes, HSE_IO_SYNC) == FALSE) { - php_handle_aborted_connection(); - } - return num_bytes; -} - - -static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers) -{ - return SAPI_HEADER_ADD; -} - - - -static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length) -{ - *total_length += sapi_header->header_len+2; -} - - -static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr) -{ - memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); - *combined_headers_ptr += sapi_header->header_len; - **combined_headers_ptr = '\r'; - (*combined_headers_ptr)++; - **combined_headers_ptr = '\n'; - (*combined_headers_ptr)++; -} - - -static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers) -{ - uint total_length = 2; /* account for the trailing \r\n */ - char *combined_headers, *combined_headers_ptr; - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - HSE_SEND_HEADER_EX_INFO header_info; - sapi_header_struct default_content_type; - char *status_buf = NULL; - - /* Obtain headers length */ - if (SG(sapi_headers).send_default_content_type) { - sapi_get_default_content_type_header(&default_content_type); - accumulate_header_length(&default_content_type, (void *) &total_length); - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length); - - /* Generate headers */ - combined_headers = (char *) emalloc(total_length+1); - combined_headers_ptr = combined_headers; - if (SG(sapi_headers).send_default_content_type) { - concat_header(&default_content_type, (void *) &combined_headers_ptr); - sapi_free_header(&default_content_type); /* we no longer need it */ - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr); - *combined_headers_ptr++ = '\r'; - *combined_headers_ptr++ = '\n'; - *combined_headers_ptr = 0; - - switch (SG(sapi_headers).http_response_code) { - case 200: - header_info.pszStatus = "200 OK"; - break; - case 302: - header_info.pszStatus = "302 Moved Temporarily"; - break; - case 401: - header_info.pszStatus = "401 Authorization Required"; - break; - default: { - const char *sline = SG(sapi_headers).http_status_line; - int sline_len; - - /* httpd requires that r->status_line is set to the first digit of - * the status-code: */ - if (sline && ((sline_len = strlen(sline)) > 12) && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') { - if ((sline_len - 9) > MAX_STATUS_LENGTH) { - status_buf = estrndup(sline + 9, MAX_STATUS_LENGTH); - } else { - status_buf = estrndup(sline + 9, sline_len - 9); - } - } else { - status_buf = emalloc(MAX_STATUS_LENGTH + 1); - snprintf(status_buf, MAX_STATUS_LENGTH, "%d Undescribed", SG(sapi_headers).http_response_code); - } - header_info.pszStatus = status_buf; - break; - } - } - header_info.cchStatus = strlen(header_info.pszStatus); - header_info.pszHeader = combined_headers; - header_info.cchHeader = total_length; - header_info.fKeepConn = FALSE; - lpECB->dwHttpStatusCode = SG(sapi_headers).http_response_code; - - lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); - - efree(combined_headers); - if (status_buf) { - efree(status_buf); - } - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - - -static int php_isapi_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_isapi_module, 1)==FAILURE) { - return FAILURE; - } else { - bTerminateThreadsOnError = (zend_bool) INI_INT("isapi.terminate_threads_on_error"); - return SUCCESS; - } -} - - -static int sapi_isapi_read_post(char *buffer, uint count_bytes) -{ - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - DWORD read_from_buf=0; - DWORD read_from_input=0; - DWORD total_read=0; - - if ((DWORD) SG(read_post_bytes) < lpECB->cbAvailable) { - read_from_buf = MIN(lpECB->cbAvailable-SG(read_post_bytes), count_bytes); - memcpy(buffer, lpECB->lpbData+SG(read_post_bytes), read_from_buf); - total_read += read_from_buf; - } - if (read_from_bufcbTotalBytes) { - DWORD cbRead=0, cbSize; - - read_from_input = MIN(count_bytes-read_from_buf, lpECB->cbTotalBytes-SG(read_post_bytes)-read_from_buf); - while (cbRead < read_from_input) { - cbSize = read_from_input - cbRead; - if (!lpECB->ReadClient(lpECB->ConnID, buffer+read_from_buf+cbRead, &cbSize) || cbSize==0) { - break; - } - cbRead += cbSize; - } - total_read += cbRead; - } - return total_read; -} - - -static char *sapi_isapi_read_cookies(void) -{ - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - - if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) { - return estrndup(variable_buf, variable_len); - } else if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) { - char *tmp_variable_buf = (char *) emalloc(variable_len+1); - - if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) { - tmp_variable_buf[variable_len] = 0; - return tmp_variable_buf; - } else { - efree(tmp_variable_buf); - } - } - return STR_EMPTY_ALLOC(); -} - - -#ifdef WITH_ZEUS - -static void sapi_isapi_register_zeus_ssl_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) -{ - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - char static_cons_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - /* - * We need to construct the /C=.../ST=... - * DN's for SSL_CLIENT_DN and SSL_CLIENT_I_DN - */ - strcpy( static_cons_buf, "/C=" ); - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE); - } - strlcat( static_cons_buf, "/ST=", ISAPI_SERVER_VAR_BUF_SIZE); - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); - } - php_register_variable( "SSL_CLIENT_DN", static_cons_buf, track_vars_array ); - - strcpy( static_cons_buf, "/C=" ); - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_C", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); - } - strlcat( static_cons_buf, "/ST=", ISAPI_SERVER_VAR_BUF_SIZE); - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if( lpECB->GetServerVariable( lpECB->ConnID, "SSL_CLIENT_I_ST", static_variable_buf, &variable_len ) && static_variable_buf[0] ) { - strlcat( static_cons_buf, static_variable_buf, ISAPI_SERVER_VAR_BUF_SIZE ); - } - php_register_variable( "SSL_CLIENT_I_DN", static_cons_buf, track_vars_array ); -} - -static void sapi_isapi_register_zeus_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) -{ - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD scriptname_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD pathinfo_len = 0; - char *strtok_buf = NULL; - - /* Get SCRIPT_NAME, we use this to work out which bit of the URL - * belongs in PHP's version of PATH_INFO - */ - lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &scriptname_len); - - /* Adjust Zeus' version of PATH_INFO, set PHP_SELF, - * and generate REQUEST_URI - */ - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - - /* PHP_SELF is just PATH_INFO */ - php_register_variable( "PHP_SELF", static_variable_buf, track_vars_array ); - - /* Chop off filename to get just the 'real' PATH_INFO' */ - pathinfo_len = variable_len - scriptname_len; - php_register_variable( "PATH_INFO", static_variable_buf + scriptname_len - 1, track_vars_array ); - /* append query string to give url... extra byte for '?' */ - if ( strlen(lpECB->lpszQueryString) + variable_len + 1 < ISAPI_SERVER_VAR_BUF_SIZE ) { - /* append query string only if it is present... */ - if ( strlen(lpECB->lpszQueryString) ) { - static_variable_buf[ variable_len - 1 ] = '?'; - strcpy( static_variable_buf + variable_len, lpECB->lpszQueryString ); - } - php_register_variable( "URL", static_variable_buf, track_vars_array ); - php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array ); - } - } - - /* Get and adjust PATH_TRANSLATED to what PHP wants */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - static_variable_buf[ variable_len - pathinfo_len - 1 ] = '\0'; - php_register_variable( "PATH_TRANSLATED", static_variable_buf, track_vars_array ); - } - - /* Bring in the AUTHENTICATION stuff as needed */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_USER", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "PHP_AUTH_USER", static_variable_buf, track_vars_array ); - } - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_PASSWORD", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "PHP_AUTH_PW", static_variable_buf, track_vars_array ); - } - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "AUTH_TYPE", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "AUTH_TYPE", static_variable_buf, track_vars_array ); - } - - /* And now, for the SSL variables (if applicable) */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "CERT_COOKIE", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - sapi_isapi_register_zeus_ssl_variables( lpECB, track_vars_array ); - } - /* Copy some of the variables we need to meet Apache specs */ - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "SERVER_SOFTWARE", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "SERVER_SIGNATURE", static_variable_buf, track_vars_array ); - } -} -#else - -static void sapi_isapi_register_iis_variables(LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array) -{ - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - char path_info_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD scriptname_len = ISAPI_SERVER_VAR_BUF_SIZE; - DWORD pathinfo_len = 0; - HSE_URL_MAPEX_INFO humi; - - /* Get SCRIPT_NAME, we use this to work out which bit of the URL - * belongs in PHP's version of PATH_INFO. SCRIPT_NAME also becomes PHP_SELF. - */ - lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &scriptname_len); - php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array); - - /* Adjust IIS' version of PATH_INFO, set PHP_SELF, - * and generate REQUEST_URI - * Get and adjust PATH_TRANSLATED to what PHP wants - */ - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_INFO", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - - /* Chop off filename to get just the 'real' PATH_INFO' */ - php_register_variable( "ORIG_PATH_INFO", static_variable_buf, track_vars_array ); - pathinfo_len = variable_len - scriptname_len; - strncpy(path_info_buf, static_variable_buf + scriptname_len - 1, sizeof(path_info_buf)-1); - php_register_variable( "PATH_INFO", path_info_buf, track_vars_array ); - /* append query string to give url... extra byte for '?' */ - if ( strlen(lpECB->lpszQueryString) + variable_len + 1 < ISAPI_SERVER_VAR_BUF_SIZE ) { - /* append query string only if it is present... */ - if ( strlen(lpECB->lpszQueryString) ) { - static_variable_buf[ variable_len - 1 ] = '?'; - strcpy( static_variable_buf + variable_len, lpECB->lpszQueryString ); - } - php_register_variable( "URL", static_variable_buf, track_vars_array ); - php_register_variable( "REQUEST_URI", static_variable_buf, track_vars_array ); - } - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if ( lpECB->GetServerVariable(lpECB->ConnID, "PATH_TRANSLATED", static_variable_buf, &variable_len) && static_variable_buf[0] ) { - php_register_variable( "ORIG_PATH_TRANSLATED", static_variable_buf, track_vars_array ); - } - if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, path_info_buf, &pathinfo_len, (LPDWORD) &humi)) { - /* Remove trailing \ */ - if (humi.lpszPath[variable_len-2] == '\\') { - humi.lpszPath[variable_len-2] = 0; - } - php_register_variable("PATH_TRANSLATED", humi.lpszPath, track_vars_array); - } - } - - static_variable_buf[0] = '/'; - static_variable_buf[1] = 0; - variable_len = 2; - if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, static_variable_buf, &variable_len, (LPDWORD) &humi)) { - /* Remove trailing \ */ - if (humi.lpszPath[variable_len-2] == '\\') { - humi.lpszPath[variable_len-2] = 0; - } - php_register_variable("DOCUMENT_ROOT", humi.lpszPath, track_vars_array); - } - - if (!SG(request_info).auth_user || !SG(request_info).auth_password || - !SG(request_info).auth_user[0] || !SG(request_info).auth_password[0]) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_AUTHORIZATION", static_variable_buf, &variable_len) - && static_variable_buf[0]) { - php_handle_auth_data(static_variable_buf); - } - } - - if (SG(request_info).auth_user) { - php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, track_vars_array ); - } - if (SG(request_info).auth_password) { - php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, track_vars_array ); - } -} -#endif - -static void sapi_isapi_register_server_variables2(char **server_variables, LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array, char **recorded_values) -{ - char **p=server_variables; - DWORD variable_len; - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; - char *variable_buf; - - while (*p) { - variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - if (lpECB->GetServerVariable(lpECB->ConnID, *p, static_variable_buf, &variable_len) - && static_variable_buf[0]) { - php_register_variable(*p, static_variable_buf, track_vars_array); - if (recorded_values) { - recorded_values[p-server_variables] = estrndup(static_variable_buf, variable_len); - } - } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - variable_buf = (char *) emalloc(variable_len+1); - if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) - && variable_buf[0]) { - php_register_variable(*p, variable_buf, track_vars_array); - } - if (recorded_values) { - recorded_values[p-server_variables] = variable_buf; - } else { - efree(variable_buf); - } - } else { /* for compatibility with Apache SAPIs */ - php_register_variable(*p, "", track_vars_array); - } - p++; - } -} - - -static void sapi_isapi_register_server_variables(zval *track_vars_array) -{ - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - char *variable; - char *strtok_buf = NULL; - char *isapi_special_server_variables[NUM_SPECIAL_VARS]; - LPEXTENSION_CONTROL_BLOCK lpECB; - - lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - - /* Register the special ISAPI variables */ - memset(isapi_special_server_variables, 0, sizeof(isapi_special_server_variables)); - sapi_isapi_register_server_variables2(isapi_special_server_variable_names, lpECB, track_vars_array, isapi_special_server_variables); - if (SG(request_info).cookie_data) { - php_register_variable("HTTP_COOKIE", SG(request_info).cookie_data, track_vars_array); - } - - /* Register the standard ISAPI variables */ - sapi_isapi_register_server_variables2(isapi_server_variable_names, lpECB, track_vars_array, NULL); - - if (isapi_special_server_variables[SPECIAL_VAR_HTTPS] - && (atoi(isapi_special_server_variables[SPECIAL_VAR_HTTPS]) - || !strcasecmp(isapi_special_server_variables[SPECIAL_VAR_HTTPS], "on")) - ) { - /* Register SSL ISAPI variables */ - sapi_isapi_register_server_variables2(isapi_secure_server_variable_names, lpECB, track_vars_array, NULL); - } - - if (isapi_special_server_variables[SPECIAL_VAR_HTTPS]) { - efree(isapi_special_server_variables[SPECIAL_VAR_HTTPS]); - } - - -#ifdef WITH_ZEUS - sapi_isapi_register_zeus_variables(lpECB, track_vars_array); -#else - sapi_isapi_register_iis_variables(lpECB, track_vars_array); -#endif - - /* PHP_SELF support */ - if (isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]) { - php_register_variable("PHP_SELF", isapi_special_server_variables[SPECIAL_VAR_PHP_SELF], track_vars_array); - efree(isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]); - } - - if (isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]) { - /* Register the internal bits of ALL_HTTP */ - variable = php_strtok_r(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP], "\r\n", &strtok_buf); - while (variable) { - char *colon = strchr(variable, ':'); - - if (colon) { - char *value = colon+1; - - while (*value==' ') { - value++; - } - *colon = 0; - php_register_variable(variable, value, track_vars_array); - *colon = ':'; - } - variable = php_strtok_r(NULL, "\r\n", &strtok_buf); - } - efree(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]); - } -} - - -static sapi_module_struct isapi_sapi_module = { - "isapi", /* name */ - "ISAPI", /* pretty name */ - - php_isapi_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_isapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - sapi_isapi_header_handler, /* header handler */ - sapi_isapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_isapi_read_post, /* read POST data */ - sapi_isapi_read_cookies, /* read Cookies */ - - sapi_isapi_register_server_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - - -BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion) -{ - bFilterLoaded = 1; - pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION; - strcpy(pFilterVersion->lpszFilterDesc, isapi_sapi_module.pretty_name); - pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS); - return TRUE; -} - - -DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification) -{ - - switch (notificationType) { - case SF_NOTIFY_PREPROC_HEADERS: - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - SG(request_info).auth_digest = NULL; - break; - case SF_NOTIFY_AUTHENTICATION: { - char *auth_user = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszUser; - char *auth_password = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszPassword; - - if (auth_user && auth_user[0]) { - SG(request_info).auth_user = estrdup(auth_user); - } - if (auth_password && auth_password[0]) { - SG(request_info).auth_password = estrdup(auth_password); - } - return SF_STATUS_REQ_HANDLED_NOTIFICATION; - } - break; - } - return SF_STATUS_REQ_NEXT_NOTIFICATION; -} - - -static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB) -{ - DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; - char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; -#ifndef WITH_ZEUS - HSE_URL_MAPEX_INFO humi; -#endif - - SG(request_info).request_method = lpECB->lpszMethod; - SG(request_info).query_string = lpECB->lpszQueryString; - SG(request_info).request_uri = lpECB->lpszPathInfo; - SG(request_info).content_type = lpECB->lpszContentType; - SG(request_info).content_length = lpECB->cbTotalBytes; - SG(sapi_headers).http_response_code = 200; /* I think dwHttpStatusCode is invalid at this stage -RL */ - if (!bFilterLoaded) { /* we don't have valid ISAPI Filter information */ - SG(request_info).auth_user = SG(request_info).auth_password = SG(request_info).auth_digest = NULL; - } - -#ifdef WITH_ZEUS - /* PATH_TRANSLATED can contain extra PATH_INFO stuff after the - * file being loaded, so we must use SCRIPT_FILENAME instead - */ - if(lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_FILENAME", static_variable_buf, &variable_len)) { - SG(request_info).path_translated = estrdup(static_variable_buf); - } else -#else - /* happily, IIS gives us SCRIPT_NAME which is correct (without PATH_INFO stuff) - so we can just map that to the physical path and we have our filename */ - - lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len); - if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, static_variable_buf, &variable_len, (LPDWORD) &humi)) { - SG(request_info).path_translated = estrdup(humi.lpszPath); - } else -#endif - /* if mapping fails, default to what the server tells us */ - SG(request_info).path_translated = estrdup(lpECB->lpszPathTranslated); - - /* some server configurations allow '..' to slip through in the - translated path. We'll just refuse to handle such a path. */ - if (strstr(SG(request_info).path_translated,"..")) { - SG(sapi_headers).http_response_code = 404; - efree(SG(request_info).path_translated); - SG(request_info).path_translated = NULL; - } -} - - -static void php_isapi_report_exception(char *message, int message_len) -{ - if (!SG(headers_sent)) { - HSE_SEND_HEADER_EX_INFO header_info; - LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); - - header_info.pszStatus = "500 Internal Server Error"; - header_info.cchStatus = strlen(header_info.pszStatus); - header_info.pszHeader = "Content-Type: text/html\r\n\r\n"; - header_info.cchHeader = strlen(header_info.pszHeader); - - lpECB->dwHttpStatusCode = 500; - lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); - SG(headers_sent)=1; - } - sapi_isapi_ub_write(message, message_len); -} - - -BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) -{ - pVer->dwExtensionVersion = HSE_VERSION; -#ifdef WITH_ZEUS - strncpy( pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); -#else - lstrcpyn(pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); -#endif - return TRUE; -} - - -static void my_endthread() -{ -#ifdef PHP_WIN32 - if (bTerminateThreadsOnError) { - _endthread(); - } -#endif -} - -#ifdef PHP_WIN32 -/* ep is accessible only in the context of the __except expression, - * so we have to call this function to obtain it. - */ -BOOL exceptionhandler(LPEXCEPTION_POINTERS *e, LPEXCEPTION_POINTERS ep) -{ - *e=ep; - return TRUE; -} -#endif - -DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) -{ - zend_file_handle file_handle; - zend_bool stack_overflown=0; - int retval = FAILURE; -#ifdef PHP_ENABLE_SEH - LPEXCEPTION_POINTERS e; -#endif - - zend_first_try { -#ifdef PHP_ENABLE_SEH - __try { -#endif - init_request_info(lpECB); - SG(server_context) = lpECB; - - php_request_startup(); - - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - - /* open the script here so we can 404 if it fails */ - if (file_handle.filename) - retval = php_fopen_primary_script(&file_handle); - - if (!file_handle.filename || retval == FAILURE) { - SG(sapi_headers).http_response_code = 404; - PUTS("No input file specified.\n"); - } else { - php_execute_script(&file_handle); - } - - if (SG(request_info).cookie_data) { - efree(SG(request_info).cookie_data); - } - if (SG(request_info).path_translated) - efree(SG(request_info).path_translated); -#ifdef PHP_ENABLE_SEH - } __except(exceptionhandler(&e, GetExceptionInformation())) { - char buf[1024]; - if (_exception_code()==EXCEPTION_STACK_OVERFLOW) { - LPBYTE lpPage; - static SYSTEM_INFO si; - static MEMORY_BASIC_INFORMATION mi; - static DWORD dwOldProtect; - - GetSystemInfo(&si); - - /* Get page ESP is pointing to */ - _asm mov lpPage, esp; - - /* Get stack allocation base */ - VirtualQuery(lpPage, &mi, sizeof(mi)); - - /* Go to the page below the current page */ - lpPage = (LPBYTE) (mi.BaseAddress) - si.dwPageSize; - - /* Free pages below current page */ - if (!VirtualFree(mi.AllocationBase, (LPBYTE)lpPage - (LPBYTE) mi.AllocationBase, MEM_DECOMMIT)) { - _endthread(); - } - - /* Restore the guard page */ - if (!VirtualProtect(lpPage, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &dwOldProtect)) { - _endthread(); - } - - CG(unclean_shutdown)=1; - _snprintf(buf, sizeof(buf)-1,"PHP has encountered a Stack overflow"); - php_isapi_report_exception(buf, strlen(buf)); - } else if (_exception_code()==EXCEPTION_ACCESS_VIOLATION) { - _snprintf(buf, sizeof(buf)-1,"PHP has encountered an Access Violation at %p", e->ExceptionRecord->ExceptionAddress); - php_isapi_report_exception(buf, strlen(buf)); - my_endthread(); - } else { - _snprintf(buf, sizeof(buf)-1,"PHP has encountered an Unhandled Exception Code %d at %p", e->ExceptionRecord->ExceptionCode , e->ExceptionRecord->ExceptionAddress); - php_isapi_report_exception(buf, strlen(buf)); - my_endthread(); - } - } -#endif -#ifdef PHP_ENABLE_SEH - __try { - php_request_shutdown(NULL); - } __except(EXCEPTION_EXECUTE_HANDLER) { - my_endthread(); - } -#else - php_request_shutdown(NULL); -#endif - } zend_catch { - zend_try { - php_request_shutdown(NULL); - } zend_end_try(); - return HSE_STATUS_ERROR; - } zend_end_try(); - - return HSE_STATUS_SUCCESS; -} - - - -__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - switch (fdwReason) { - case DLL_PROCESS_ATTACH: -#ifdef WITH_ZEUS - tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "TSRM.log"); -#else - tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log"); -#endif - sapi_startup(&isapi_sapi_module); - if (isapi_sapi_module.startup) { - isapi_sapi_module.startup(&sapi_module); - } - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - ts_free_thread(); - break; - case DLL_PROCESS_DETACH: - if (isapi_sapi_module.shutdown) { - isapi_sapi_module.shutdown(&sapi_module); - } - sapi_shutdown(); - tsrm_shutdown(); - break; - } - return TRUE; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/sapi/isapi/php7isapi.def b/sapi/isapi/php7isapi.def deleted file mode 100644 index 596023ef55489..0000000000000 --- a/sapi/isapi/php7isapi.def +++ /dev/null @@ -1,5 +0,0 @@ -EXPORTS -HttpFilterProc -GetFilterVersion -HttpExtensionProc -GetExtensionVersion diff --git a/sapi/isapi/stresstest/getopt.c b/sapi/isapi/stresstest/getopt.c deleted file mode 100644 index 21056bf883f6a..0000000000000 --- a/sapi/isapi/stresstest/getopt.c +++ /dev/null @@ -1,175 +0,0 @@ -/* Borrowed from Apache NT Port */ - -#include -#include -#include -#include -#include "getopt.h" -#define OPTERRCOLON (1) -#define OPTERRNF (2) -#define OPTERRARG (3) - - -char *ap_optarg; -int ap_optind = 1; -static int ap_opterr = 1; -static int ap_optopt; - -static int -ap_optiserr(int argc, char * const *argv, int oint, const char *optstr, - int optchr, int err) -{ - if (ap_opterr) - { - fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1); - switch(err) - { - case OPTERRCOLON: - fprintf(stderr, ": in flags\n"); - break; - case OPTERRNF: - fprintf(stderr, "option not found %c\n", argv[oint][optchr]); - break; - case OPTERRARG: - fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]); - break; - default: - fprintf(stderr, "unknown\n"); - break; - } - } - ap_optopt = argv[oint][optchr]; - return('?'); -} - -int ap_getopt(int argc, char* const *argv, const char *optstr) -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - - char *cp; - - if (ap_optind >= argc) - return(EOF); - if (!dash && (argv[ap_optind][0] != '-')) - return(EOF); - if (!dash && (argv[ap_optind][0] == '-') && !argv[ap_optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return(EOF); - } - if ((argv[ap_optind][0] == '-') && (argv[ap_optind][1] == '-')) - { - /* -- indicates end of args */ - ap_optind++; - return(EOF); - } - if (!dash) - { - assert((argv[ap_optind][0] == '-') && argv[ap_optind][1]); - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - assert(dash); - if (argv[ap_optind][optchr] == ':') - { - dash = 0; - ap_optind++; - return(ap_optiserr(argc, argv, ap_optind-1, optstr, optchr, OPTERRCOLON)); - } - if (!(cp = strchr(optstr, argv[ap_optind][optchr]))) - { - int errind = ap_optind; - int errchr = optchr; - - if (!argv[ap_optind][optchr+1]) - { - dash = 0; - ap_optind++; - } - else - optchr++; - return(ap_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF)); - } - if (cp[1] == ':') - { - /* Check for cases where the value of the argument - is in the form - or in the form - */ - dash = 0; - if(!argv[ap_optind][2]) { - ap_optind++; - if (ap_optind == argc) - return(ap_optiserr(argc, argv, ap_optind-1, optstr, optchr, OPTERRARG)); - ap_optarg = argv[ap_optind++]; - } - else - { - ap_optarg = &argv[ap_optind][2]; - ap_optind++; - } - return(*cp); - } - else - { - if (!argv[ap_optind][optchr+1]) - { - dash = 0; - ap_optind++; - } - else - optchr++; - return(*cp); - } - assert(0); - return(0); -} - -#ifdef TESTGETOPT -int - main (int argc, char **argv) - { - int c; - extern char *ap_optarg; - extern int ap_optind; - int aflg = 0; - int bflg = 0; - int errflg = 0; - char *ofile = NULL; - - while ((c = ap_getopt(argc, argv, "abo:")) != EOF) - switch (c) { - case 'a': - if (bflg) - errflg++; - else - aflg++; - break; - case 'b': - if (aflg) - errflg++; - else - bflg++; - break; - case 'o': - ofile = ap_optarg; - (void)printf("ofile = %s\n", ofile); - break; - case '?': - errflg++; - } - if (errflg) { - (void)fprintf(stderr, - "usage: cmd [-a|-b] [-o ] files...\n"); - exit (2); - } - for ( ; ap_optind < argc; ap_optind++) - (void)printf("%s\n", argv[ap_optind]); - return 0; - } - -#endif /* TESTGETOPT */ diff --git a/sapi/isapi/stresstest/getopt.h b/sapi/isapi/stresstest/getopt.h deleted file mode 100644 index 6d4139bfe0dca..0000000000000 --- a/sapi/isapi/stresstest/getopt.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Borrowed from Apache NT Port */ -#ifdef __cplusplus -extern "C" { -#endif -extern char *ap_optarg; -extern int ap_optind; - -int ap_getopt(int argc, char* const *argv, const char *optstr); - -#ifdef __cplusplus -} -#endif diff --git a/sapi/isapi/stresstest/notes.txt b/sapi/isapi/stresstest/notes.txt deleted file mode 100644 index e6d10dd486a08..0000000000000 --- a/sapi/isapi/stresstest/notes.txt +++ /dev/null @@ -1,56 +0,0 @@ -This stress test program is for debugging threading issues with the ISAPI -module. - -2 ways to use it: - -1: test any php script file on multiple threads -2: run the php test scripts bundled with the source code - - - -GLOBAL SETTINGS -=============== - -If you need to set special environement variables, in addition to your -regular environment, create a file that contains them, one setting per line: - -MY_ENV_VAR=XXXXXXXX - -This can be used to simulate ISAPI environment variables if need be. - -By default, stress test uses 10 threads. To change this, change the define -NUM_THREADS in stresstest.cpp. - - - -1: Test any php script file on multiple threads -=============================================== - -Create a file that contains a list of php script files, one per line. If -you need to provide input, place the GET data, or Query String, after the -filename. File contents would look like: - -e:\inetpub\pages\index.php -e:\inetpub\pages\info.php -e:\inetpub\pages\test.php a=1&b=2 - -Run: stresstest L files.txt - - - -2: Run the php test scripts bundled with the source code -======================================================== - -supply the path to the parent of the "tests" directory (expect a couple -long pauses for a couple of the larger tests) - -Run: stresstest T c:\php7-source - - - -TODO: - -* Make more options configurable: number of threads, iterations, etc. -* Improve stdout output to make it more useful -* Implement support for SKIPIF -* Improve speed of CompareFile function (too slow on big files). diff --git a/sapi/isapi/stresstest/stresstest.cpp b/sapi/isapi/stresstest/stresstest.cpp deleted file mode 100644 index ddb06473c2d71..0000000000000 --- a/sapi/isapi/stresstest/stresstest.cpp +++ /dev/null @@ -1,936 +0,0 @@ -/* - * ======================================================================= * - * File: stress .c * - * stress tester for isapi dll's * - * based on cgiwrap * - * ======================================================================= * - * -*/ -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#include -#include -#include -#include -#include "getopt.h" - -// These are things that go out in the Response Header -// -#define HTTP_VER "HTTP/1.0" -#define SERVER_VERSION "Http-Srv-Beta2/1.0" - -// -// Simple wrappers for the heap APIS -// -#define xmalloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (s)) -#define xfree(s) HeapFree(GetProcessHeap(), 0, (s)) - -// -// The mandatory exports from the ISAPI DLL -// -DWORD numThreads = 1; -DWORD iterations = 1; - -HANDLE StartNow; -// quick and dirty environment -typedef CMapStringToString TEnvironment; -TEnvironment IsapiEnvironment; - -typedef struct _TResults { - LONG ok; - LONG bad; -} TResults; - -CStringArray IsapiFileList; // list of filenames -CStringArray TestNames; // --TEST-- -CStringArray IsapiGetData; // --GET-- -CStringArray IsapiPostData; // --POST-- -CStringArray IsapiMatchData; // --EXPECT-- -CArray Results; - -typedef struct _TIsapiContext { - HANDLE in; - HANDLE out; - DWORD tid; - TEnvironment env; - HANDLE waitEvent; -} TIsapiContext; - -// -// Prototypes of the functions this sample implements -// -extern "C" { -HINSTANCE hDll; -typedef BOOL (WINAPI *VersionProc)(HSE_VERSION_INFO *) ; -typedef DWORD (WINAPI *HttpExtProc)(EXTENSION_CONTROL_BLOCK *); -typedef BOOL (WINAPI *TerminateProc) (DWORD); -BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *, TIsapiContext *) ; -BOOL WINAPI GetServerVariable(HCONN, LPSTR, LPVOID, LPDWORD ); -BOOL WINAPI ReadClient(HCONN, LPVOID, LPDWORD); -BOOL WINAPI WriteClient(HCONN, LPVOID, LPDWORD, DWORD); -BOOL WINAPI ServerSupportFunction(HCONN, DWORD, LPVOID, LPDWORD, LPDWORD); -VersionProc IsapiGetExtensionVersion; -HttpExtProc IsapiHttpExtensionProc; -TerminateProc TerminateExtensionProc; -HSE_VERSION_INFO version_info; -} - -char * MakeDateStr(VOID); -char * GetEnv(char *); - - - - -DWORD CALLBACK IsapiThread(void *); -int stress_main(const char *filename, - const char *arg, - const char *postfile, - const char *matchdata); - - - -BOOL bUseTestFiles = FALSE; -char temppath[MAX_PATH]; - -void stripcrlf(char *line) -{ - DWORD l = strlen(line)-1; - if (line[l]==10 || line[l]==13) line[l]=0; - l = strlen(line)-1; - if (line[l]==10 || line[l]==13) line[l]=0; -} - -#define COMPARE_BUF_SIZE 1024 - -BOOL CompareFiles(const char*f1, const char*f2) -{ - FILE *fp1, *fp2; - bool retval; - char buf1[COMPARE_BUF_SIZE], buf2[COMPARE_BUF_SIZE]; - int length1, length2; - - if ((fp1=fopen(f1, "r"))==NULL) { - return FALSE; - } - - if ((fp2=fopen(f2, "r"))==NULL) { - fclose(fp1); - return FALSE; - } - - retval = TRUE; // success oriented - while (true) { - length1 = fread(buf1, 1, sizeof(buf1), fp1); - length2 = fread(buf2, 1, sizeof(buf2), fp2); - - // check for end of file - if (feof(fp1)) { - if (!feof(fp2)) { - retval = FALSE; - } - break; - } else if (feof(fp2)) { - if (!feof(fp1)) { - retval = FALSE; - } - break; - } - - // compare data - if (length1!=length2 - || memcmp(buf1, buf2, length1)!=0) { - retval = FALSE; - break; - } - } - fclose(fp1); - fclose(fp2); - - return retval; -} - - -BOOL CompareStringWithFile(const char *filename, const char *str, unsigned int str_length) -{ - FILE *fp; - bool retval; - char buf[COMPARE_BUF_SIZE]; - unsigned int offset=0, readbytes; - fprintf(stderr, "test %s\n",filename); - if ((fp=fopen(filename, "rb"))==NULL) { - fprintf(stderr, "Error opening %s\n",filename); - return FALSE; - } - - retval = TRUE; // success oriented - while (true) { - readbytes = fread(buf, 1, sizeof(buf), fp); - - // check for end of file - - if (offset+readbytes > str_length - || memcmp(buf, str+offset, readbytes)!=NULL) { - fprintf(stderr, "File missmatch %s\n",filename); - retval = FALSE; - break; - } - if (feof(fp)) { - if (!retval) fprintf(stderr, "File zero length %s\n",filename); - break; - } - } - fclose(fp); - - return retval; -} - - -BOOL ReadGlobalEnvironment(const char *environment) -{ - if (environment) { - FILE *fp = fopen(environment, "r"); - DWORD i=0; - if (fp) { - char line[2048]; - while (fgets(line, sizeof(line)-1, fp)) { - // file.php arg1 arg2 etc. - char *p = strchr(line, '='); - if (p) { - *p=0; - IsapiEnvironment[line]=p+1; - } - } - fclose(fp); - return IsapiEnvironment.GetCount() > 0; - } - } - return FALSE; -} - -BOOL ReadFileList(const char *filelist) -{ - FILE *fp = fopen(filelist, "r"); - if (!fp) { - printf("Unable to open %s\r\n", filelist); - } - char line[2048]; - int i=0; - while (fgets(line, sizeof(line)-1, fp)) { - // file.php arg1 arg2 etc. - stripcrlf(line); - if (strlen(line)>3) { - char *p = strchr(line, ' '); - if (p) { - *p = 0; - // get file - - IsapiFileList.Add(line); - IsapiGetData.Add(p+1); - } else { - // just a filename is all - IsapiFileList.Add(line); - IsapiGetData.Add(""); - } - } - - // future use - IsapiPostData.Add(""); - IsapiMatchData.Add(""); - TestNames.Add(""); - - i++; - } - Results.SetSize(TestNames.GetSize()); - - fclose(fp); - return IsapiFileList.GetSize() > 0; -} - -void DoThreads() { - - if (IsapiFileList.GetSize() == 0) { - printf("No Files to test\n"); - return; - } - - printf("Starting Threads...\n"); - // loop creating threads - DWORD tid; - HANDLE *threads = new HANDLE[numThreads]; - DWORD i; - for (i=0; i< numThreads; i++) { - threads[i]=CreateThread(NULL, 0, IsapiThread, NULL, CREATE_SUSPENDED, &tid); - } - for (i=0; i< numThreads; i++) { - if (threads[i]) ResumeThread(threads[i]); - } - // wait for threads to finish - WaitForMultipleObjects(numThreads, threads, TRUE, INFINITE); - for (i=0; i< numThreads; i++) { - CloseHandle(threads[i]); - } - delete [] threads; -} - -void DoFileList(const char *filelist, const char *environment) -{ - // read config files - - if (!ReadFileList(filelist)) { - printf("No Files to test!\r\n"); - return; - } - - ReadGlobalEnvironment(environment); - - DoThreads(); -} - - -/** - * ParseTestFile - * parse a single phpt file and add it to the arrays - */ -BOOL ParseTestFile(const char *path, const char *fn) -{ - // parse the test file - char filename[MAX_PATH]; - _snprintf(filename, sizeof(filename)-1, "%s\\%s", path, fn); - char line[1024]; - memset(line, 0, sizeof(line)); - CString cTest, cSkipIf, cPost, cGet, cFile, cExpect; - printf("Reading %s\r\n", filename); - - enum state {none, test, skipif, post, get, file, expect} parsestate = none; - - FILE *fp = fopen(filename, "rb"); - char *tn = _tempnam(temppath,"pht."); - char *en = _tempnam(temppath,"exp."); - FILE *ft = fopen(tn, "wb+"); - FILE *fe = fopen(en, "wb+"); - if (fp && ft && fe) { - while (fgets(line, sizeof(line)-1, fp)) { - if (line[0]=='-') { - if (_strnicmp(line, "--TEST--", 8)==0) { - parsestate = test; - continue; - } else if (_strnicmp(line, "--SKIPIF--", 10)==0) { - parsestate = skipif; - continue; - } else if (_strnicmp(line, "--POST--", 8)==0) { - parsestate = post; - continue; - } else if (_strnicmp(line, "--GET--", 7)==0) { - parsestate = get; - continue; - } else if (_strnicmp(line, "--FILE--", 8)==0) { - parsestate = file; - continue; - } else if (_strnicmp(line, "--EXPECT--", 10)==0) { - parsestate = expect; - continue; - } - } - switch (parsestate) { - case test: - stripcrlf(line); - cTest = line; - break; - case skipif: - cSkipIf += line; - break; - case post: - cPost += line; - break; - case get: - cGet += line; - break; - case file: - fputs(line, ft); - break; - case expect: - fputs(line, fe); - break; - } - } - - fclose(fp); - fclose(ft); - fclose(fe); - - if (!cTest.IsEmpty()) { - IsapiFileList.Add(tn); - TestNames.Add(cTest); - IsapiGetData.Add(cGet); - IsapiPostData.Add(cPost); - IsapiMatchData.Add(en); - free(tn); - free(en); - return TRUE; - } - } - free(tn); - free(en); - return FALSE; -} - - -/** - * GetTestFiles - * Recurse through the path and subdirectories, parse each phpt file - */ -BOOL GetTestFiles(const char *path) -{ - // find all files .phpt under testpath\tests - char FindPath[MAX_PATH]; - WIN32_FIND_DATA fd; - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - - _snprintf(FindPath, sizeof(FindPath)-1, "%s\\*.*", path); - HANDLE fh = FindFirstFile(FindPath, &fd); - if (fh != INVALID_HANDLE_VALUE) { - do { - if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && - !strchr(fd.cFileName, '.')) { - // subdirectory, recurse into it - char NewFindPath[MAX_PATH]; - _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", path, fd.cFileName); - GetTestFiles(NewFindPath); - } else if (strstr(fd.cFileName, ".phpt")) { - // got test file, parse it now - if (ParseTestFile(path, fd.cFileName)) { - printf("Test File Added: %s\\%s\r\n", path, fd.cFileName); - } - } - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - } while (FindNextFile(fh, &fd) != 0); - FindClose(fh); - } - return IsapiFileList.GetSize() > 0; -} - -void DeleteTempFiles(const char *mask) -{ - char FindPath[MAX_PATH]; - WIN32_FIND_DATA fd; - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - - _snprintf(FindPath, sizeof(FindPath)-1, "%s\\%s", temppath, mask); - HANDLE fh = FindFirstFile(FindPath, &fd); - if (fh != INVALID_HANDLE_VALUE) { - do { - char NewFindPath[MAX_PATH]; - _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", temppath, fd.cFileName); - DeleteFile(NewFindPath); - memset(&fd, 0, sizeof(WIN32_FIND_DATA)); - } while (FindNextFile(fh, &fd) != 0); - FindClose(fh); - } -} - -void DoTestFiles(const char *filelist, const char *environment) -{ - if (!GetTestFiles(filelist)) { - printf("No Files to test!\r\n"); - return; - } - - Results.SetSize(IsapiFileList.GetSize()); - - ReadGlobalEnvironment(environment); - - DoThreads(); - - printf("\r\nRESULTS:\r\n"); - // show results: - DWORD r = Results.GetSize(); - for (DWORD i=0; i< r; i++) { - TResults result = Results.GetAt(i); - printf("%s\r\nOK: %d FAILED: %d\r\n", TestNames.GetAt(i), result.ok, result.bad); - } - - // delete temp files - printf("Deleting Temp Files\r\n"); - DeleteTempFiles("exp.*"); - DeleteTempFiles("pht.*"); - printf("Done\r\n"); -} - -#define OPTSTRING "m:f:d:h:t:i:" -static void _usage(char *argv0) -{ - char *prog; - - prog = strrchr(argv0, '/'); - if (prog) { - prog++; - } else { - prog = "stresstest"; - } - - printf("Usage: %s -m -d|-l [-t ] [-i ]\n" - " -m path to isapi dll\n" - " -d php directory (to run php test files).\n" - " -f file containing list of files to run\n" - " -t number of threads to use (default=1)\n" - " -i number of iterations per thread (default=1)\n" - " -h This help\n", prog); -} -int main(int argc, char* argv[]) -{ - LPVOID lpMsgBuf; - char *filelist=NULL, *environment=NULL, *module=NULL; - int c = NULL; - while ((c=ap_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case 'd': - bUseTestFiles = TRUE; - filelist = strdup(ap_optarg); - break; - case 'f': - bUseTestFiles = FALSE; - filelist = strdup(ap_optarg); - break; - case 'e': - environment = strdup(ap_optarg); - break; - case 't': - numThreads = atoi(ap_optarg); - break; - case 'i': - iterations = atoi(ap_optarg); - break; - case 'm': - module = strdup(ap_optarg); - break; - case 'h': - _usage(argv[0]); - exit(0); - break; - } - } - if (!module || !filelist) { - _usage(argv[0]); - exit(0); - } - - GetTempPath(sizeof(temppath), temppath); - hDll = LoadLibrary(module); // Load our DLL - - if (!hDll) { - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - fprintf(stderr,"Error: Dll 'php7isapi.dll' not found -%d\n%s\n", GetLastError(), lpMsgBuf); - free (module); - free(filelist); - LocalFree( lpMsgBuf ); - return -1; - } - - // - // Find the exported functions - - IsapiGetExtensionVersion = (VersionProc)GetProcAddress(hDll,"GetExtensionVersion"); - if (!IsapiGetExtensionVersion) { - fprintf(stderr,"Can't Get Extension Version %d\n", GetLastError()); - free (module); - free(filelist); - return -1; - } - IsapiHttpExtensionProc = (HttpExtProc)GetProcAddress(hDll,"HttpExtensionProc"); - if (!IsapiHttpExtensionProc) { - fprintf(stderr,"Can't Get Extension proc %d\n", GetLastError()); - free (module); - free(filelist); - return -1; - } - TerminateExtensionProc = (TerminateProc) GetProcAddress(hDll, - "TerminateExtension"); - - // This should really check if the version information matches what we - // expect. - // - if (!IsapiGetExtensionVersion(&version_info) ) { - fprintf(stderr,"Fatal: GetExtensionVersion failed\n"); - free (module); - free(filelist); - return -1; - } - - if (bUseTestFiles) { - char TestPath[MAX_PATH]; - if (filelist != NULL) - _snprintf(TestPath, sizeof(TestPath)-1, "%s\\tests", filelist); - else strcpy(TestPath, "tests"); - DoTestFiles(TestPath, environment); - } else { - DoFileList(filelist, environment); - } - - // cleanup - if (TerminateExtensionProc) TerminateExtensionProc(0); - - // We should really free memory (e.g., from GetEnv), but we'll be dead - // soon enough - - FreeLibrary(hDll); - free (module); - free(filelist); - return 0; -} - - -DWORD CALLBACK IsapiThread(void *p) -{ - DWORD filecount = IsapiFileList.GetSize(); - - for (DWORD j=0; jenv.Lookup(lpszVariableName, value)) { - rc = value.GetLength(); - strncpy((char *)lpBuffer, value, *lpdwSize-1); - } else - rc = GetEnvironmentVariable(lpszVariableName, (char *)lpBuffer, *lpdwSize) ; - - if (!rc) { // return of 0 indicates the variable was not found - SetLastError(ERROR_NO_DATA); - return FALSE; - } - - if (rc > *lpdwSize) { - SetLastError(ERROR_INSUFFICIENT_BUFFER); - return FALSE; - } - - *lpdwSize =rc + 1 ; // GetEnvironmentVariable does not count the NULL - - return TRUE; - -} -// -// Again, we don't have an HCONN, so we simply wrap ReadClient() to -// ReadFile on stdin. The semantics of the two functions are the same -// -BOOL WINAPI ReadClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize) { - TIsapiContext *c = (TIsapiContext *)hConn; - if (!c) return FALSE; - - if (c->in != INVALID_HANDLE_VALUE) - return ReadFile(c->in, lpBuffer, (*lpdwSize), lpdwSize, NULL); - - return FALSE; -} -// -// ditto for WriteClient() -// -BOOL WINAPI WriteClient(HCONN hConn, LPVOID lpBuffer, LPDWORD lpdwSize, - DWORD dwReserved) { - TIsapiContext *c = (TIsapiContext *)hConn; - if (!c) return FALSE; - - if (c->out != INVALID_HANDLE_VALUE) - return WriteFile(c->out, lpBuffer, *lpdwSize, lpdwSize, NULL); - return FALSE; -} -// -// This is a special callback function used by the DLL for certain extra -// functionality. Look at the API help for details. -// -BOOL WINAPI ServerSupportFunction(HCONN hConn, DWORD dwHSERequest, - LPVOID lpvBuffer, LPDWORD lpdwSize, LPDWORD lpdwDataType){ - - TIsapiContext *c = (TIsapiContext *)hConn; - char *lpszRespBuf; - char * temp = NULL; - DWORD dwBytes; - BOOL bRet = TRUE; - - switch(dwHSERequest) { - case (HSE_REQ_SEND_RESPONSE_HEADER) : - lpszRespBuf = (char *)xmalloc(*lpdwSize);//+ 80);//accommodate our header - if (!lpszRespBuf) - return FALSE; - wsprintf(lpszRespBuf,"%s", - //HTTP_VER, - - /* Default response is 200 Ok */ - - //lpvBuffer?lpvBuffer:"200 Ok", - - /* Create a string for the time. */ - //temp=MakeDateStr(), - - //SERVER_VERSION, - - /* If this exists, it is a pointer to a data buffer to - be sent. */ - lpdwDataType?(char *)lpdwDataType:NULL); - - if (temp) xfree(temp); - - dwBytes = strlen(lpszRespBuf); - bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0); - xfree(lpszRespBuf); - - break; - // - // A real server would do cleanup here - case (HSE_REQ_DONE_WITH_SESSION): - SetEvent(c->waitEvent); - //ExitThread(0); - break; - - // - // This sends a redirect (temporary) to the client. - // The header construction is similar to RESPONSE_HEADER above. - // - case (HSE_REQ_SEND_URL_REDIRECT_RESP): - lpszRespBuf = (char *)xmalloc(*lpdwSize +80) ; - if (!lpszRespBuf) - return FALSE; - wsprintf(lpszRespBuf,"%s %s %s\r\n", - HTTP_VER, - "302 Moved Temporarily", - (lpdwSize > 0)?lpvBuffer:0); - xfree(temp); - dwBytes = strlen(lpszRespBuf); - bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0); - xfree(lpszRespBuf); - break; - default: - return FALSE; - break; - } - return bRet; - -} -// -// Makes a string of the date and time from GetSystemTime(). -// This is in UTC, as required by the HTTP spec.` -// -char * MakeDateStr(void){ - SYSTEMTIME systime; - char *szDate= (char *)xmalloc(64); - - char * DaysofWeek[] = {"Sun","Mon","Tue","Wed","Thurs","Fri","Sat"}; - char * Months[] = {"NULL","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug", - "Sep","Oct","Nov","Dec"}; - - GetSystemTime(&systime); - - wsprintf(szDate,"%s, %d %s %d %d:%d.%d", DaysofWeek[systime.wDayOfWeek], - systime.wDay, - Months[systime.wMonth], - systime.wYear, - systime.wHour, systime.wMinute, - systime.wSecond ); - - return szDate; -} -// -// Fill the ECB up -// -BOOL WINAPI FillExtensionControlBlock(EXTENSION_CONTROL_BLOCK *ECB, TIsapiContext *context) { - - char * temp; - ECB->cbSize = sizeof(EXTENSION_CONTROL_BLOCK); - ECB->dwVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR); - ECB->ConnID = (void *)context; - // - // Pointers to the functions the DLL will call. - // - ECB->GetServerVariable = GetServerVariable; - ECB->ReadClient = ReadClient; - ECB->WriteClient = WriteClient; - ECB->ServerSupportFunction = ServerSupportFunction; - - // - // Fill in the standard CGI environment variables - // - ECB->lpszMethod = GetEnv("REQUEST_METHOD"); - if (!ECB->lpszMethod) ECB->lpszMethod = "GET"; - - ECB->lpszQueryString = GetEnv("QUERY_STRING"); - ECB->lpszPathInfo = GetEnv("PATH_INFO"); - ECB->lpszPathTranslated = GetEnv("PATH_TRANSLATED"); - ECB->cbTotalBytes=( (temp=GetEnv("CONTENT_LENGTH")) ? (atoi(temp)): 0); - ECB->cbAvailable = 0; - ECB->lpbData = (unsigned char *)""; - ECB->lpszContentType = GetEnv("CONTENT_TYPE"); - return TRUE; - -} - -// -// Works like _getenv(), but uses win32 functions instead. -// -char *GetEnv(LPSTR lpszEnvVar) -{ - - char *var, dummy; - DWORD dwLen; - - if (!lpszEnvVar) - return ""; - - dwLen =GetEnvironmentVariable(lpszEnvVar, &dummy, 1); - - if (dwLen == 0) - return ""; - - var = (char *)xmalloc(dwLen); - if (!var) - return ""; - (void)GetEnvironmentVariable(lpszEnvVar, var, dwLen); - - return var; -} diff --git a/sapi/milter/CREDITS b/sapi/milter/CREDITS deleted file mode 100644 index cd00d6774b2f5..0000000000000 --- a/sapi/milter/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Sendmail Milter -Harald Radi diff --git a/sapi/milter/EXPERIMENTAL b/sapi/milter/EXPERIMENTAL deleted file mode 100644 index 293159a693dec..0000000000000 --- a/sapi/milter/EXPERIMENTAL +++ /dev/null @@ -1,5 +0,0 @@ -this module is experimental, -its functions may change their names -or move to extension all together -so do not rely to much on them -you have been warned! diff --git a/sapi/milter/Makefile.frag b/sapi/milter/Makefile.frag deleted file mode 100644 index f193f56b01bb3..0000000000000 --- a/sapi/milter/Makefile.frag +++ /dev/null @@ -1,8 +0,0 @@ -milter: $(SAPI_MILTER_PATH) - -$(SAPI_MILTER_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_MILTER_OBJS) - $(BUILD_MILTER) - -install-milter: $(SAPI_MILTER_PATH) - @$(INSTALL) -m 0755 $(SAPI_MILTER_PATH) $(INSTALL_ROOT)$(bindir)/php-milter - diff --git a/sapi/milter/TODO b/sapi/milter/TODO deleted file mode 100644 index 4a427ea131a71..0000000000000 --- a/sapi/milter/TODO +++ /dev/null @@ -1,5 +0,0 @@ -threaded version still leaks mem, don't know why -extensions aren't loaded -stdout to syslog -testing -documentation \ No newline at end of file diff --git a/sapi/milter/config.m4 b/sapi/milter/config.m4 deleted file mode 100644 index a69ab2e1e7591..0000000000000 --- a/sapi/milter/config.m4 +++ /dev/null @@ -1,31 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(milter, for Milter support, -[ --with-milter[=DIR] Build PHP as Milter application], no, no) - -if test "$PHP_MILTER" != "no"; then - if test "$PHP_MILTER" = "yes"; then - if test -f /usr/lib/libmilter.a ; then - MILTERPATH=/usr/lib - else - if test -f /usr/lib/libmilter/libmilter.a ; then - MILTERPATH=/usr/lib/libmilter - else - AC_MSG_ERROR([Unable to find libmilter.a]) - fi - fi - else - MILTERPATH=$PHP_MILTER - fi - - SAPI_MILTER_PATH=sapi/milter/php-milter - PHP_BUILD_THREAD_SAFE - PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/milter/Makefile.frag,$abs_srcdir/sapi/milter,sapi/milter) - PHP_SELECT_SAPI(milter, program, php_milter.c getopt.c,,'$(SAPI_MILTER_PATH)') - PHP_ADD_LIBRARY_WITH_PATH(milter, $MILTERPATH,) - BUILD_MILTER="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_MILTER_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_MILTER_PATH)" - PHP_SUBST(SAPI_MILTER_PATH) - PHP_SUBST(BUILD_MILTER) -fi diff --git a/sapi/milter/getopt.c b/sapi/milter/getopt.c deleted file mode 100644 index df2c77f94ca69..0000000000000 --- a/sapi/milter/getopt.c +++ /dev/null @@ -1,173 +0,0 @@ -/* Borrowed from Apache NT Port */ - -#include -#include -#include -#include -#include "php_getopt.h" -#define OPTERRCOLON (1) -#define OPTERRNF (2) -#define OPTERRARG (3) - - -char *ap_php_optarg; -int ap_php_optind = 1; -static int ap_php_opterr = 1; - -static int -ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr, - int optchr, int err) -{ - if (ap_php_opterr) - { - fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1); - switch(err) - { - case OPTERRCOLON: - fprintf(stderr, ": in flags\n"); - break; - case OPTERRNF: - fprintf(stderr, "option not found %c\n", argv[oint][optchr]); - break; - case OPTERRARG: - fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]); - break; - default: - fprintf(stderr, "unknown\n"); - break; - } - } - return('?'); -} - -int ap_php_getopt(int argc, char* const *argv, const char *optstr) -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - - char *cp; - - if (ap_php_optind >= argc) - return(EOF); - if (!dash && (argv[ap_php_optind][0] != '-')) - return(EOF); - if (!dash && (argv[ap_php_optind][0] == '-') && !argv[ap_php_optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return(EOF); - } - if ((argv[ap_php_optind][0] == '-') && (argv[ap_php_optind][1] == '-')) - { - /* -- indicates end of args */ - ap_php_optind++; - return(EOF); - } - if (!dash) - { - assert((argv[ap_php_optind][0] == '-') && argv[ap_php_optind][1]); - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - assert(dash); - if (argv[ap_php_optind][optchr] == ':') - { - dash = 0; - ap_php_optind++; - return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRCOLON)); - } - if (!(cp = strchr(optstr, argv[ap_php_optind][optchr]))) - { - int errind = ap_php_optind; - int errchr = optchr; - - if (!argv[ap_php_optind][optchr+1]) - { - dash = 0; - ap_php_optind++; - } - else - optchr++; - return(ap_php_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF)); - } - if (cp[1] == ':') - { - /* Check for cases where the value of the argument - is in the form - or in the form - */ - dash = 0; - if(!argv[ap_php_optind][2]) { - ap_php_optind++; - if (ap_php_optind == argc) - return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG)); - ap_php_optarg = argv[ap_php_optind++]; - } - else - { - ap_php_optarg = &argv[ap_php_optind][2]; - ap_php_optind++; - } - return(*cp); - } - else - { - if (!argv[ap_php_optind][optchr+1]) - { - dash = 0; - ap_php_optind++; - } - else - optchr++; - return(*cp); - } - assert(0); - return(0); /* never reached */ -} - -#ifdef TESTGETOPT -int - main (int argc, char **argv) - { - int c; - extern char *ap_php_optarg; - extern int ap_php_optind; - int aflg = 0; - int bflg = 0; - int errflg = 0; - char *ofile = NULL; - - while ((c = ap_php_getopt(argc, argv, "abo:")) != EOF) - switch (c) { - case 'a': - if (bflg) - errflg++; - else - aflg++; - break; - case 'b': - if (aflg) - errflg++; - else - bflg++; - break; - case 'o': - ofile = ap_php_optarg; - (void)printf("ofile = %s\n", ofile); - break; - case '?': - errflg++; - } - if (errflg) { - (void)fprintf(stderr, - "usage: cmd [-a|-b] [-o ] files...\n"); - exit (2); - } - for ( ; ap_php_optind < argc; ap_php_optind++) - (void)printf("%s\n", argv[ap_php_optind]); - return 0; - } - -#endif /* TESTGETOPT */ diff --git a/sapi/milter/milter.php b/sapi/milter/milter.php deleted file mode 100644 index 0878f2a4d9558..0000000000000 --- a/sapi/milter/milter.php +++ /dev/null @@ -1,132 +0,0 @@ - $arg) { - milter_log("\targs[$ix] = $arg"); - } -} - -/** - * is called once per recipient, hence one or more times per message, - * immediately after milter_envfrom - */ -function milter_envrcpt($args) -{ - milter_log("milter_envrcpt(args[])"); - foreach ($args as $ix => $arg) { - milter_log("\targs[$ix] = $arg"); - } -} - -/** - * is called zero or more times between milter_envrcpt and milter_eoh, - * once per message header - */ -function milter_header($header, $value) -{ - milter_log("milter_header('$header', '$value')"); -} - -/** - * is called once after all headers have been sent and processed. - */ -function milter_eoh() -{ - milter_log("milter_eoh()"); -} - -/** - * is called zero or more times between milter_eoh and milter_eom. - */ -function milter_body($bodypart) -{ - milter_log("milter_body('$bodypart')"); -} - -/** - * is called once after all calls to milter_body for a given message. - * most of the api functions, that alter the message can only be called - * within this callback. - */ -function milter_eom() -{ - milter_log("milter_eom()"); - /* add PHP header to the message */ - smfi_addheader("X-PHP", phpversion()); -} - -/** - * may be called at any time during message processing - * (i.e. between some message-oriented routine and milter_eom). - */ -function milter_abort() -{ - milter_log("milter_abort()"); -} - -/** - * is always called once at the end of each connection. - */ -function milter_close() -{ - milter_log("milter_close()"); -} -?> diff --git a/sapi/milter/php_getopt.h b/sapi/milter/php_getopt.h deleted file mode 100644 index 40da432b596da..0000000000000 --- a/sapi/milter/php_getopt.h +++ /dev/null @@ -1,7 +0,0 @@ -/* Borrowed from Apache NT Port */ -#include "php.h" - -extern char *ap_php_optarg; -extern int ap_php_optind; - -int ap_php_getopt(int argc, char* const *argv, const char *optstr); diff --git a/sapi/milter/php_milter.c b/sapi/milter/php_milter.c deleted file mode 100644 index 73a0667326400..0000000000000 --- a/sapi/milter/php_milter.c +++ /dev/null @@ -1,1196 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Harald Radi | - | Parts based on CGI SAPI Module by | - | Rasmus Lerdorf, Stig Bakken and Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "php_variables.h" -#include "zend_modules.h" - -#ifndef ZTS -#error SRM sapi module is only useable in thread-safe mode -#endif - -#include "SAPI.h" - -#include -#include "php.h" -#if HAVE_SYS_TIME_H -#include -#endif -#if HAVE_UNISTD_H -#include -#endif -#if HAVE_SIGNAL_H -#include -#endif -#if HAVE_SETLOCALE -#include -#endif -#include "zend.h" -#include "zend_extensions.h" -#include "php_ini.h" -#include "php_globals.h" -#include "php_main.h" -#include "fopen_wrappers.h" -#include "ext/standard/php_standard.h" - -#ifdef __riscos__ -#include -#endif - -#include "zend_compile.h" -#include "zend_execute.h" -#include "zend_highlight.h" -#include "zend_indent.h" - -#include "libmilter/mfapi.h" - -#include "php_getopt.h" - -#define OPTSTRING "ac:d:Def:hnp:vVz:?" -#define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v) - -#define IS_NONE "%s(): This function must not be called outside of a milter callback function's scope" -#define NOT_EOM "%s(): This function can only be used inside the milter_eom callback's scope" -#define NOT_INIT "%s(): This function can only be used inside the milter_init callback's scope" - -#define MLFI_NONE 0 -#define MLFI_CONNECT 1 -#define MLFI_HELO 2 -#define MLFI_ENVFROM 3 -#define MLFI_ENVRCPT 4 -#define MLFI_HEADER 5 -#define MLFI_EOH 6 -#define MLFI_BODY 7 -#define MLFI_EOM 8 -#define MLFI_ABORT 9 -#define MLFI_CLOSE 10 -#define MLFI_INIT 11 - -/* {{{ globals - */ -extern char *ap_php_optarg; -extern int ap_php_optind; - -static int flag_debug=0; -static char *filename = NULL; - -/* per thread */ -ZEND_BEGIN_MODULE_GLOBALS(milter) - SMFICTX *ctx; - int state; - int initialized; -ZEND_END_MODULE_GLOBALS(milter) - -ZEND_DECLARE_MODULE_GLOBALS(milter) -/* }}} */ - -/* this method is called only once when the milter starts */ -/* {{{ Init Milter -*/ -static int mlfi_init() -{ - int ret = 0; - zend_file_handle file_handle; - zval function_name, retval; - int status; - - /* request startup */ - if (php_request_startup()==FAILURE) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - php_request_shutdown((void *) 0); - - return -1; - } - - /* disable headers */ - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - - if (filename == NULL) { - php_printf("No input file specified"); - return SMFIS_TEMPFAIL; - } - - if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) { - php_printf("Could not open input file: %s\n", filename); - return SMFIS_TEMPFAIL; - } - - file_handle.type = ZEND_HANDLE_FP; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - - /* call userland */ - INIT_ZVAL(function_name); - - ZVAL_STRING(&function_name, "milter_init", 0); - - /* set the milter context for possible use in API functions */ - MG(state) = MLFI_INIT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - MG(initialized) = 1; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - ret = Z_LVAL(retval); - } - - php_request_shutdown((void *) 0); - - return ret; -} -/* }}} */ - -/* {{{ Milter callback functions - */ - -/* connection info filter, is called whenever sendmail connects to the milter */ -/* {{{ mlfi_connect() -*/ -static sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) -{ - zend_file_handle file_handle; - zval function_name, retval, *param[1]; - int status; - - /* request startup */ - if (php_request_startup()==FAILURE) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - php_request_shutdown((void *) 0); - - return SMFIS_TEMPFAIL; - } - - /* disable headers */ - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - - if (filename == NULL) { - php_printf("No input file specified"); - return SMFIS_TEMPFAIL; - } - - if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) { - php_printf("Could not open input file: %s\n", filename); - return SMFIS_TEMPFAIL; - } - - file_handle.type = ZEND_HANDLE_FP; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_connect", 0); - ZVAL_STRING(param[0], hostname, 1); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_CONNECT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - zval_ptr_dtor(param); - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* SMTP HELO command filter */ -/* {{{ mlfi_helo() -*/ -static sfsistat mlfi_helo(SMFICTX *ctx, char *helohost) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_helo", 0); - ZVAL_STRING(param[0], helohost, 1); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_HELO; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* envelope sender filter */ -/* {{{ mlfi_envform() -*/ -static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_envfrom", 0); - array_init(param[0]); - - while (*argv) { - add_next_index_string(param[0], *argv); - argv++; - } - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_ENVFROM; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* envelope recipient filter */ -/* {{{ mlfi_envrcpt() -*/ -static sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_envrcpt", 0); - array_init(param[0]); - - while (*argv) { - add_next_index_string(param[0], *argv); - argv++; - } - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_ENVRCPT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* header filter */ -/* {{{ mlfi_header() -*/ -static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv) -{ - zval function_name, retval, *param[2]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - ALLOC_ZVAL(param[1]); - INIT_PZVAL(param[0]); - INIT_PZVAL(param[1]); - - ZVAL_STRING(&function_name, "milter_header", 0); - ZVAL_STRING(param[0], headerf, 1); - ZVAL_STRING(param[1], headerv, 1); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_HEADER; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param); - - MG(state) = MLFI_NONE; - - zval_ptr_dtor(¶m[0]); - zval_ptr_dtor(¶m[1]); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* end of header */ -/* {{{ mlfi_eoh() -*/ -static sfsistat mlfi_eoh(SMFICTX *ctx) -{ - zval function_name, retval; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_eoh", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_EOH; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* body block */ -/* {{{ mlfi_body() -*/ -static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len) -{ - zval function_name, retval, *param[1]; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - - ALLOC_ZVAL(param[0]); - INIT_PZVAL(param[0]); - - ZVAL_STRING(&function_name, "milter_body", 0); - ZVAL_STRINGL(param[0], (char*)bodyp, len, 1); /*alex*/ - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_BODY; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param); - - MG(state) = MLFI_NONE; - - zval_ptr_dtor(param); - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* end of message */ -/* {{{ mlfi_eom() -*/ -static sfsistat mlfi_eom(SMFICTX *ctx) -{ - zval function_name, retval; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_eom", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_EOM; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* message aborted */ -/* {{{ mlfi_abort() -*/ -static sfsistat mlfi_abort(SMFICTX *ctx) -{ - zval function_name, retval; - int status; - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_abort", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_ABORT; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - return Z_LVAL(retval); - } - - return SMFIS_CONTINUE; -} -/* }}} */ - -/* connection cleanup */ -/* {{{ mlfi_close() -*/ -static sfsistat mlfi_close(SMFICTX *ctx) -{ - int ret = SMFIS_CONTINUE; - zval function_name, retval; - int status; - - if (!SG(sapi_started) && SUCCESS != php_request_startup()) { - return ret; - } - - /* call userland */ - INIT_ZVAL(function_name); - ZVAL_STRING(&function_name, "milter_close", 0); - - /* set the milter context for possible use in API functions */ - MG(ctx) = ctx; - MG(state) = MLFI_CLOSE; - - status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL); - - MG(state) = MLFI_NONE; - - if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) { - ret = Z_LVAL(retval); - } - - php_request_shutdown((void *) 0); - - return ret; -} -/* }}} */ -/* }}} */ - -/* {{{ Milter entry struct - */ -static struct smfiDesc smfilter = { - "php-milter", /* filter name */ - SMFI_VERSION, /* version code -- leave untouched */ - 0, /* flags */ - mlfi_connect, /* info filter callback */ - mlfi_helo, /* HELO filter callback */ - mlfi_envfrom, /* envelope filter callback */ - mlfi_envrcpt, /* envelope recipient filter callback */ - mlfi_header, /* header filter callback */ - mlfi_eoh, /* end of header callback */ - mlfi_body, /* body filter callback */ - mlfi_eom, /* end of message callback */ - mlfi_abort, /* message aborted callback */ - mlfi_close, /* connection cleanup callback */ -}; -/* }}} */ - -/* {{{ PHP Milter API - */ - -/* {{{ proto void smfi_setflags(long flags) - Sets the flags describing the actions the filter may take. */ -PHP_FUNCTION(smfi_setflags) -{ - long flags; - - /* valid only in the init callback */ - if (MG(state) != MLFI_INIT) { - php_error(E_WARNING, NOT_INIT, get_active_function_name()); - } else if (zend_parse_parameters(1, "l", &flags) == SUCCESS) { - flags = flags & (SMFIF_ADDHDRS|SMFIF_CHGHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT); - smfilter.xxfi_flags = flags; - } -} -/* }}} */ - -/* {{{ proto void smfi_settimeout(long timeout) - Sets the number of seconds libmilter will wait for an MTA connection before timing out a socket. */ -PHP_FUNCTION(smfi_settimeout) -{ - long timeout; - - /* valid only in the init callback */ - if (MG(state) != MLFI_INIT) { - php_error(E_WARNING, NOT_INIT, get_active_function_name()); - } else if (zend_parse_parameters(1, "l", &timeout) == SUCCESS) { - smfi_settimeout(timeout); - } -} -/* }}} */ - -/* {{{ proto string smfi_getsymval(string macro) - Returns the value of the given macro or NULL if the macro is not defined. */ -PHP_FUNCTION(smfi_getsymval) -{ - char *symname, *ret; - int len; - - /* valid in any callback */ - if (MG(state) == MLFI_NONE) { - php_error(E_WARNING, IS_NONE, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &symname, &len) == SUCCESS) { - if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) { - RETURN_STRING(ret, 1); - } - } - - RETURN_NULL(); -} -/* }}} */ - -/* {{{ proto bool smfi_setreply(string rcode, string xcode, string message) - Directly set the SMTP error reply code for this connection. - This code will be used on subsequent error replies resulting from actions taken by this filter. */ -PHP_FUNCTION(smfi_setreply) -{ - char *rcode, *xcode, *message; - int len; - - /* valid in any callback */ - if (MG(state) == MLFI_NONE) { - php_error(E_WARNING, IS_NONE, get_active_function_name()); - } else if (zend_parse_parameters(3, "sss", &rcode, &len, &xcode, &len, &message, &len) == SUCCESS) { - if (smfi_setreply(MG(ctx), rcode, xcode, message) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_addheader(string headerf, string headerv) - Adds a header to the current message. */ -PHP_FUNCTION(smfi_addheader) -{ - char *f, *v; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(2, "ss", &f, &len, &v, &len) == SUCCESS) { - if (smfi_addheader(MG(ctx), f, v) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_chgheader(string headerf, string headerv) - Changes a header's value for the current message. */ -PHP_FUNCTION(smfi_chgheader) -{ - char *f, *v; - long idx; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(3, "sls", &f, &len, &idx, &v, &len) == SUCCESS) { - if (smfi_chgheader(MG(ctx), f, idx, v) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_addrcpt(string rcpt) - Add a recipient to the message envelope. */ -PHP_FUNCTION(smfi_addrcpt) -{ - char *rcpt; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &rcpt, &len) == SUCCESS) { - if (smfi_addrcpt(MG(ctx), rcpt) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_delrcpt(string rcpt) - Removes the named recipient from the current message's envelope. */ -PHP_FUNCTION(smfi_delrcpt) -{ - char *rcpt; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &rcpt, &len) == SUCCESS) { - if (smfi_delrcpt(MG(ctx), rcpt) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool smfi_replacebody(string body) - Replaces the body of the current message. If called more than once, - subsequent calls result in data being appended to the new body. */ -PHP_FUNCTION(smfi_replacebody) -{ - char *body; - int len; - - /* valid only in milter_eom */ - if (MG(state) != MLFI_EOM) { - php_error(E_WARNING, NOT_EOM, get_active_function_name()); - } else if (zend_parse_parameters(1, "s", &body, &len) == SUCCESS) { - if (smfi_replacebody(MG(ctx), (u_char*)body, len) == MI_SUCCESS) { - RETURN_TRUE; - } - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(milter) -{ - REGISTER_LONG_CONSTANT("SMFIS_CONTINUE", SMFIS_CONTINUE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_REJECT", SMFIS_REJECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_DISCARD", SMFIS_DISCARD, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_ACCEPT", SMFIS_ACCEPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIS_TEMPFAIL", SMFIS_TEMPFAIL, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("SMFIF_ADDHDRS", SMFIF_ADDHDRS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_CHGHDRS", SMFIF_CHGHDRS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_CHGBODY", SMFIF_CHGBODY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_ADDRCPT", SMFIF_ADDRCPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SMFIF_DELRCPT", SMFIF_DELRCPT, CONST_CS | CONST_PERSISTENT); - - ZEND_INIT_MODULE_GLOBALS(milter, NULL, NULL); - - MG(state) = MLFI_NONE; - MG(initialized) = 0; - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(milter) -{ - php_info_print_table_start(); - php_info_print_table_header(2, "Milter support", "enabled"); - php_info_print_table_end(); -} -/* }}} */ -/* }}} */ - -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_setflags, 0, 0, 1) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_settimeout, 0, 0, 1) - ZEND_ARG_INFO(0, timeout) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_getsymval, 0, 0, 1) - ZEND_ARG_INFO(0, macro) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_setreply, 0, 0, 3) - ZEND_ARG_INFO(0, rcode) - ZEND_ARG_INFO(0, xcode) - ZEND_ARG_INFO(0, message) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_addheader, 0, 0, 2) - ZEND_ARG_INFO(0, headerf) - ZEND_ARG_INFO(0, headerv) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_chgheader, 0, 0, 2) - ZEND_ARG_INFO(0, headerf) - ZEND_ARG_INFO(0, headerv) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_addrcpt, 0, 0, 1) - ZEND_ARG_INFO(0, rcpt) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_delrcpt, 0, 0, 1) - ZEND_ARG_INFO(0, rcpt) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_smfi_replacebody, 0, 0, 1) - ZEND_ARG_INFO(0, body) -ZEND_END_ARG_INFO() -/* }}} */ - -/* {{{ milter_functions[] -*/ -const static zend_function_entry milter_functions[] = { - PHP_FE(smfi_setflags, arginfo_smfi_setflags) - PHP_FE(smfi_settimeout, arginfo_smfi_settimeout) - PHP_FE(smfi_getsymval, arginfo_smfi_getsymval) - PHP_FE(smfi_setreply, arginfo_smfi_setreply) - PHP_FE(smfi_addheader, arginfo_smfi_addheader) - PHP_FE(smfi_chgheader, arginfo_smfi_chgheader) - PHP_FE(smfi_addrcpt, arginfo_smfi_addrcpt) - PHP_FE(smfi_delrcpt, arginfo_smfi_delrcpt) - PHP_FE(smfi_replacebody, arginfo_smfi_replacebody) - PHP_FE_END -}; -/* }}} */ - -/* {{{ Zend module entry -*/ -static zend_module_entry php_milter_module = { - STANDARD_MODULE_HEADER, - "Milter", - milter_functions, - PHP_MINIT(milter), - NULL, - NULL, - NULL, - PHP_MINFO(milter), - "0.1.0", - STANDARD_MODULE_PROPERTIES -}; -/* }}} */ - -/* {{{ Milter SAPI -*/ -static int sapi_milter_ub_write(const char *str, uint str_length) -{ - return str_length; -} - -static void sapi_milter_register_variables(zval *track_vars_array) -{ - php_register_variable ("SERVER_SOFTWARE", "Sendmail Milter", track_vars_array); -} - -static int sapi_milter_post_read(char *buf, uint count_bytes) -{ - return 0; -} - -static char* sapi_milter_read_cookies(void) -{ - return NULL; -} - -static int sapi_milter_send_headers(sapi_headers_struct *sapi_headers) -{ - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int php_milter_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_milter_module, 1) == FAILURE) { - return FAILURE; - } - return SUCCESS; -} -/* }}} */ - -/* {{{ sapi_module_struct milter_sapi_module -*/ -static sapi_module_struct milter_sapi_module = { - "milter", /* name */ - "Sendmail Milter SAPI", /* pretty name */ - - php_milter_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_milter_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - NULL, /* header handler */ - sapi_milter_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - sapi_milter_post_read, /* read POST data */ - sapi_milter_read_cookies, /* read Cookies */ - - sapi_milter_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; -/* }}} */ - -/**** -* ripped from cli, has to be cleaned up ! -*/ - -/* {{{ php_milter_usage -*/ -static void php_milter_usage(char *argv0) -{ - char *prog; - - prog = strrchr(argv0, '/'); - if (prog) { - prog++; - } else { - prog = "php-milter"; - } - - printf( "Usage: %s [options] [-f] [args...]\n" - " %s [options] [-- args...]\n" - " -a Run interactively\n" - " -c | Look for php.ini file in this directory\n" - " -n No php.ini file will be used\n" - " -d foo[=bar] Define INI entry foo with value 'bar'\n" - " -D run as daemon\n" - " -e Generate extended information for debugger/profiler\n" - " -f Parse .\n" - " -h This help\n" - " -p path to create socket\n" - " -v Version number\n" - " -V set debug level to n (1 or 2).\n" - " -z Load Zend extension .\n" - " args... Arguments passed to script. Use -- args when first argument \n" - " starts with - or script is read from stdin\n" - , prog, prog); -} -/* }}} */ - -static void define_command_line_ini_entry(char *arg) /* {{{ */ -{ - char *name, *value; - - name = arg; - value = strchr(arg, '='); - if (value) { - *value = 0; - value++; - } else { - value = "1"; - } - zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); -} -/* }}} */ - -/* {{{ main -*/ -int main(int argc, char *argv[]) -{ - char *sock = NULL; - int dofork = 0; - - int exit_status = SUCCESS; - int c; -/* temporary locals */ - int orig_optind=ap_php_optind; - char *orig_optarg=ap_php_optarg; - int interactive=0; - char *param_error=NULL; -/* end of temporary locals */ - - void ***tsrm_ls; - -#ifdef HAVE_SIGNAL_H -#if defined(SIGPIPE) && defined(SIG_IGN) - signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so - that sockets created via fsockopen() - don't kill PHP if the remote site - closes it. in apache|apxs mode apache - does that for us! thies@thieso.net - 20000419 */ -#endif -#endif - - - tsrm_startup(1, 1, 0, NULL); - tsrm_ls = ts_resource(0); - sapi_startup(&milter_sapi_module); - - while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case 'c': - milter_sapi_module.php_ini_path_override = strdup(ap_php_optarg); - break; - case 'n': - milter_sapi_module.php_ini_ignore = 1; - break; - } - } - ap_php_optind = orig_optind; - ap_php_optarg = orig_optarg; - - milter_sapi_module.executable_location = argv[0]; - - - sapi_module.startup(&milter_sapi_module); - - zend_first_try { - while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case '?': - php_output_tearup(); - SG(headers_sent) = 1; - php_milter_usage(argv[0]); - php_output_teardown(); - exit(1); - break; - } - } - ap_php_optind = orig_optind; - ap_php_optarg = orig_optarg; - - /* Set some CLI defaults */ - SG(options) |= SAPI_OPTION_NO_CHDIR; - zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - - zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */ - - while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) { - switch (c) { - - case 'a': /* interactive mode */ - printf("Interactive mode enabled\n\n"); - interactive=1; - break; - - case 'C': /* don't chdir to the script directory */ - /* This is default so NOP */ - break; - case 'd': /* define ini entries on command line */ - define_command_line_ini_entry(ap_php_optarg); - break; - - case 'D': /* daemon */ - dofork = 1; - break; - - case 'e': /* enable extended info output */ - CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; - break; - - case 'f': /* parse file */ - filename = ap_php_optarg; - break; - - case 'h': /* help & quit */ - case '?': - php_output_tearup(); - SG(headers_sent) = 1; - php_milter_usage(argv[0]); - php_output_teardown(); - exit(1); - break; - - case 'p': /* socket */ - sock = strdup(ap_php_optarg); - break; - - case 'v': /* show php version & quit */ - if (php_request_startup()==FAILURE) { - zend_ini_deactivate(); - php_module_shutdown(); - sapi_shutdown(); - tsrm_shutdown(); - - exit(1); - } - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2015 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); - php_output_teardown(); - exit(1); - break; - - case 'V': /* verbose */ - flag_debug = atoi(ap_php_optarg); - break; - - case 'z': /* load extension file */ - zend_load_extension(ap_php_optarg); - break; - - default: - break; - } - } - - if (param_error) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - PUTS(param_error); - exit(1); - } - - /* only set script_file if not set already and not in direct mode and not at end of parameter list */ - if (argc > ap_php_optind && !filename) { - filename=argv[ap_php_optind]; - ap_php_optind++; - } - - /* check if file exists, exit else */ - - if (dofork) { - switch(fork()) { - case -1: /* Uh-oh, we have a problem forking. */ - fprintf(stderr, "Uh-oh, couldn't fork!\n"); - exit(errno); - break; - case 0: /* Child */ - break; - default: /* Parent */ - exit(0); - } - } - - if (sock) { - struct stat junk; - if (stat(sock,&junk) == 0) unlink(sock); - } - - openlog("php-milter", LOG_PID, LOG_MAIL); - - if ((exit_status = mlfi_init())) { - syslog(1, "mlfi_init failed."); - closelog(); - goto err; - } - - smfi_setconn(sock); - if (smfi_register(smfilter) == MI_FAILURE) { - syslog(1, "smfi_register failed."); - fprintf(stderr, "smfi_register failed\n"); - closelog(); - goto err; - } else { - exit_status = smfi_main(); - } - - closelog(); - - if (milter_sapi_module.php_ini_path_override) { - free(milter_sapi_module.php_ini_path_override); - } - - } zend_catch { - exit_status = EG(exit_status); - } zend_end_try(); - -err: - php_module_shutdown(); - sapi_shutdown(); - tsrm_shutdown(); - - exit(exit_status); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/milter/php_milter.h b/sapi/milter/php_milter.h deleted file mode 100644 index 72d7ac51eeb50..0000000000000 --- a/sapi/milter/php_milter.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef PHP_MILTER_H -#define PHP_MILTER_H - -#include "libmilter/mfapi.h" - -#define MLFI_NONE 0 -#define MLFI_CONNECT 1 -#define MLFI_HELO 2 -#define MLFI_ENVFROM 3 -#define MLFI_ENVRCPT 4 -#define MLFI_HEADER 5 -#define MLFI_EOH 6 -#define MLFI_BODY 7 -#define MLFI_EOM 8 -#define MLFI_ABORT 9 -#define MLFI_CLOSE 10 -#define MLFI_INIT 11 - -#define MG(v) TSRMG(milter_globals_id, zend_milter_globals *, v) - -typedef struct { - pthread_t thread; - MUTEX_T receiver; - MUTEX_T sender; - SMFICTX *ctx; - sfsistat retval; - int message; - void **args; -} worker_thread; - -#endif diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index f2f18b944e363..3337f05cdc8fa 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -21,6 +21,7 @@ #if !defined(ZEND_SIGNALS) || defined(_WIN32) # include #endif + #include "phpdbg.h" #include "phpdbg_prompt.h" #include "phpdbg_bp.h" @@ -32,6 +33,8 @@ #include "zend_alloc.h" #include "phpdbg_eol.h" +#include "ext/standard/basic_functions.h" + /* {{{ remote console headers */ #ifndef _WIN32 # include diff --git a/sapi/phttpd/CREDITS b/sapi/phttpd/CREDITS deleted file mode 100644 index 134cc54825cdb..0000000000000 --- a/sapi/phttpd/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -phttpd -Thies C. Arntzen diff --git a/sapi/phttpd/README b/sapi/phttpd/README deleted file mode 100644 index cdb6f7c381da7..0000000000000 --- a/sapi/phttpd/README +++ /dev/null @@ -1,5 +0,0 @@ -phttpd sapi module. - -THIS IS BY NO MEANS COMPLETE NOR USABLE RIGHT NOW! - -thies@thieso.net 03.01.2000 diff --git a/sapi/phttpd/config.m4 b/sapi/phttpd/config.m4 deleted file mode 100644 index 91339a5278050..0000000000000 --- a/sapi/phttpd/config.m4 +++ /dev/null @@ -1,21 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(phttpd, for PHTTPD support, -[ --with-phttpd=DIR Build PHP as phttpd module], no, no) - -if test "$PHP_PHTTPD" != "no"; then - if test ! -d $PHP_PHTTPD ; then - AC_MSG_ERROR([You did not specify a directory]) - fi - PHP_BUILD_THREAD_SAFE - PHP_ADD_INCLUDE($PHP_PHTTPD/include) - AC_DEFINE(HAVE_PHTTPD, 1, [Whether you have phttpd]) - PHP_SELECT_SAPI(phttpd, shared, phttpd.c) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PHP_PHTTPD/modules/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/phttpd/php.sym b/sapi/phttpd/php.sym deleted file mode 100644 index f10b883a9930c..0000000000000 --- a/sapi/phttpd/php.sym +++ /dev/null @@ -1,4 +0,0 @@ -pm_init -pm_exit -pm_request - diff --git a/sapi/phttpd/php_phttpd.h b/sapi/phttpd/php_phttpd.h deleted file mode 100644 index af53d188e2767..0000000000000 --- a/sapi/phttpd/php_phttpd.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_PHTTPD_H -#define PHP_PHTTPD_H - -#include - -#endif diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c deleted file mode 100644 index d47cdc94cc2b0..0000000000000 --- a/sapi/phttpd/phttpd.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen | - | Based on aolserver SAPI by Sascha Schumann | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" - -#ifdef HAVE_PHTTPD - -#include "ext/standard/info.h" - -#ifndef ZTS -#error PHTTPD module is only useable in thread-safe mode -#endif - -#include "php_phttpd.h" - -typedef struct { - struct connectioninfo *cip; - struct stat sb; -} phttpd_globals_struct; - -static int ph_globals_id; - -#define PHG(v) TSRMG(ph_globals_id, phttpd_globals_struct *, v) - -static int -php_phttpd_startup(sapi_module_struct *sapi_module) -{ - fprintf(stderr,"***php_phttpd_startup\n"); - - if (php_module_startup(sapi_module, NULL, 0)) { - return FAILURE; - } else { - return SUCCESS; - } -} - -static int -php_phttpd_sapi_ub_write(const char *str, uint str_length) -{ - int sent_bytes; - - sent_bytes = fd_write(PHG(cip)->fd, str, str_length); - - if (sent_bytes == -1) { - php_handle_aborted_connection(); - } - - return sent_bytes; -} - -static int -php_phttpd_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content; - char *p; - - http_sendheaders(PHG(cip)->fd, PHG(cip), SG(sapi_headers).http_response_code, NULL); - - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - - if (p) { - *p = '\0'; - do { - header_content++; - } while (*header_content == ' '); - - fd_printf(PHG(cip)->fd,"%s: %s\n", header_name, header_content); - - *p = ':'; - } - - sapi_free_header(sapi_header); - - return 0; -} - -static int -php_phttpd_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - if (SG(sapi_headers).send_default_content_type) { - fd_printf(PHG(cip)->fd,"Content-Type: text/html\n"); - } - - fd_putc('\n', PHG(cip)->fd); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static char * -php_phttpd_sapi_read_cookies(void) -{ - -/* - int i; - char *http_cookie = NULL; - - i = Ns_SetIFind(NSG(conn->headers), "cookie"); - if(i != -1) { - http_cookie = Ns_SetValue(NSG(conn->headers), i); - } - - return http_cookie; -*/ - fprintf(stderr,"***php_phttpd_sapi_read_cookies\n"); - - return 0; -} - -static int -php_phttpd_sapi_read_post(char *buf, uint count_bytes) -{ -/* - uint max_read; - uint total_read = 0; - - max_read = MIN(NSG(data_avail), count_bytes); - - total_read = Ns_ConnRead(NSG(conn), buf, max_read); - - if(total_read == NS_ERROR) { - total_read = -1; - } else { - NSG(data_avail) -= total_read; - } - - return total_read; -*/ - fprintf(stderr,"***php_phttpd_sapi_read_post\n"); - return 0; -} - -static sapi_module_struct phttpd_sapi_module = { - "phttpd", - "PHTTPD", - - php_phttpd_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - php_phttpd_sapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - php_phttpd_sapi_header_handler, /* header handler */ - php_phttpd_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - - php_phttpd_sapi_read_post, /* read POST data */ - php_phttpd_sapi_read_cookies, /* read Cookies */ - - NULL, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -static void -php_phttpd_request_ctor(void) -{ - memset(&SG(request_info), 0, sizeof(sapi_globals_struct)); /* pfusch! */ - - SG(request_info).query_string = PHG(cip)->hip->request; - SG(request_info).request_method = PHG(cip)->hip->method; - SG(request_info).path_translated = malloc(MAXPATHLEN); - SG(sapi_headers).http_response_code = 200; - if (url_expand(PHG(cip)->hip->url, SG(request_info).path_translated, MAXPATHLEN, &PHG(sb), NULL, NULL) == NULL) { - /* handle error */ - } - -#if 0 - char *server; - Ns_DString ds; - char *root; - int index; - char *tmp; - - server = Ns_ConnServer(NSG(conn)); - - Ns_DStringInit(&ds); - Ns_UrlToFile(&ds, server, NSG(conn->request->url)); - - /* path_translated is the absolute path to the file */ - SG(request_info).path_translated = strdup(Ns_DStringValue(&ds)); - Ns_DStringFree(&ds); - root = Ns_PageRoot(server); - SG(request_info).request_uri = SG(request_info).path_translated + strlen(root); - SG(request_info).content_length = Ns_ConnContentLength(NSG(conn)); - index = Ns_SetIFind(NSG(conn)->headers, "content-type"); - SG(request_info).content_type = index == -1 ? NULL : - Ns_SetValue(NSG(conn)->headers, index); - - tmp = Ns_ConnAuthUser(NSG(conn)); - if(tmp) { - tmp = estrdup(tmp); - } - SG(request_info).auth_user = tmp; - - tmp = Ns_ConnAuthPasswd(NSG(conn)); - if(tmp) { - tmp = estrdup(tmp); - } - SG(request_info).auth_password = tmp; - - NSG(data_avail) = SG(request_info).content_length; -#endif -} - -static void -php_phttpd_request_dtor(void) -{ - free(SG(request_info).path_translated); -} - - -int php_doit(void) -{ - struct stat sb; - zend_file_handle file_handle; - struct httpinfo *hip = PHG(cip)->hip; - - if (php_request_startup() == FAILURE) { - return -1; - } - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - -/* - php_phttpd_hash_environment(); -*/ - php_execute_script(&file_handle); - php_request_shutdown(NULL); - - return SG(sapi_headers).http_response_code; -} - -int pm_init(const char **argv) -{ - tsrm_startup(1, 1, 0, NULL); - sapi_startup(&phttpd_sapi_module); - phttpd_sapi_module.startup(&phttpd_sapi_module); - - ts_allocate_id(&ph_globals_id, sizeof(phttpd_globals_struct), NULL, NULL); - - return 0; -} - -void pm_exit(void) -{ - fprintf(stderr,"***pm_exit\n"); -} - -int pm_request(struct connectioninfo *cip) -{ - struct httpinfo *hip = cip->hip; - int status; - - if (strcasecmp(hip->method, "GET") == 0 || - strcasecmp(hip->method, "HEAD") == 0 || - strcasecmp(hip->method, "POST") == 0) { - PHG(cip) = cip; - - php_phttpd_request_ctor(); - status = php_doit(); - php_phttpd_request_dtor(); - - return status; - } else { - return -2; - } -} - -#endif diff --git a/sapi/pi3web/CREDITS b/sapi/pi3web/CREDITS deleted file mode 100644 index c4541f89da76b..0000000000000 --- a/sapi/pi3web/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -pi3web -Holger Zimmermann diff --git a/sapi/pi3web/README b/sapi/pi3web/README deleted file mode 100644 index e7726edcf4cca..0000000000000 --- a/sapi/pi3web/README +++ /dev/null @@ -1,50 +0,0 @@ -PHP7 Module -========== -This module requires PHP7 as thread safe shared library. Have a look -into the INSTALL file which accompanies that distribution. - -If you distribute this software bundled with the PHP software in source -or binary form, then you must adhere to the PHP copyright conditions - -the terms are reasonable. - -You should have checked out and built the PHP7 source package from the -PHP CVS tree into the Pi3Web source directory called 'PHP7' first. Then -build PHP7 as Pi3Web module and after that build the Pi3Web PHP7 wrapper: - -1. Checkout PHP7 -================ -cvs -d :pserver:cvsread@cvs.php.net:/repository login -The required password is phpfi - -cvs -z3 -d :pserver:cvsread@cvs.php.net:/repository co php7 - -You must also checkout the TSRM and the ZEND module from the ZEND cvs tree -into the PHP7 root directory - -cvs -d :pserver:cvsread@cvs.zend.com:/repository login -The required password is zend - -cvs -z3 -d :pserver:cvsread@cvs.zend.com:/repository co Zend TSRM - -2. Build PHP7 -============= -2.1 POSIX ---------- -cd ./php7 -./buildconf -./configure --with-pi3web -make - -2.2 Win32 ---------- -other required downloads from the php website - - bison 1.25 - - bindlib32 - - number4.tar.gz -nmake php7dllts.mak - -3. Build Pi3Web PHP7 wrapper -============================ -Run make in the Pi3Web /Source/PHP7 directory. - -For further information refer to http://www.php.net/version4/ diff --git a/sapi/pi3web/config.m4 b/sapi/pi3web/config.m4 deleted file mode 100644 index 42ff164394fe1..0000000000000 --- a/sapi/pi3web/config.m4 +++ /dev/null @@ -1,27 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(pi3web, for Pi3Web support, -[ --with-pi3web[=DIR] Build PHP as Pi3Web module], no, no) - -if test "$PHP_PI3WEB" != "no"; then - if test "$PHP_PI3WEB" = "yes"; then - PI3PATH=../.. # the default - else - PI3PATH=$PHP_PI3WEB - fi - test -f "$PI3PATH/PiAPI/PiAPI.h" || AC_MSG_ERROR([Unable to find PiAPI.h in $PI3PATH/PiAPI]) - PHP_BUILD_THREAD_SAFE - AC_DEFINE(WITH_PI3WEB, 1, [whether you want Pi3Web support]) - PHP_ADD_INCLUDE($PI3PATH/PiAPI) - PHP_ADD_INCLUDE($PI3PATH/Pi2API) - PHP_ADD_INCLUDE($PI3PATH/Pi3API) - PHP_ADD_INCLUDE($PI3PATH/PHP7) - PHP_SELECT_SAPI(pi3web, shared, pi3web_sapi.c) - INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_SHARED \$(INSTALL_ROOT)$PI3PATH/bin/" -fi - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/pi3web/config.w32 b/sapi/pi3web/config.w32 deleted file mode 100644 index 9441784468fdd..0000000000000 --- a/sapi/pi3web/config.w32 +++ /dev/null @@ -1,16 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_WITH('pi3web', 'Pi3Web', 'no'); - -if (PHP_PI3WEB != "no") { - if (CHECK_HEADER_ADD_INCLUDE('PiAPI.h', 'CFLAGS_PI3WEB', PHP_PHP_BUILD + "\\Pi3Web\\include;" + PHP_PI3WEB) && - CHECK_LIB('piapi.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB) && - CHECK_LIB('pi2api.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB) && - CHECK_LIB('pi3api.lib', 'pi3web', PHP_PHP_BUILD + "\\Pi3Web\\lib;" + PHP_PI3WEB)) { - SAPI('pi3web', 'pi3web_sapi.c', 'php' + PHP_VERSION + 'pi3web.dll', '/D PHP7PI3WEB_EXPORTS'); - AC_DEFINE('WITH_PI3WEB', 1); - } else { - WARNING('Pi3Web not enabled; headers/libraries not found'); - } -} diff --git a/sapi/pi3web/php.sym b/sapi/pi3web/php.sym deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c deleted file mode 100644 index a91660ca6fd17..0000000000000 --- a/sapi/pi3web/pi3web_sapi.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Pi3Web version 2.0 | - +----------------------------------------------------------------------+ - | This file is committed by the Pi3 development group. | - | (pi3web.sourceforge.net) | - | | - | Author: Holger Zimmermann (zimpel@users.sourceforge.net) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "php_main.h" -#include "php_variables.h" -#include "SAPI.h" -#include "php_globals.h" -#include "ext/standard/info.h" -#include "zend_highlight.h" -#include "zend_indent.h" -#include "zend_alloc.h" -#include "ext/standard/basic_functions.h" -#include "TSRM/TSRM.h" -#include "PiAPI.h" -#include "Pi3API.h" - -#include "pi3web_sapi.h" - -#define PI3WEB_SERVER_VAR_BUF_SIZE 1024 - -int IWasLoaded=0; - - -static void php_info_pi3web(ZEND_MODULE_INFO_FUNC_ARGS) -{ - char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; - DWORD variable_len; - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID); - PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 ); - - PUTS("\n"); - PUTS("\n"); - php_info_print_table_header(2, "Information Field", "Value"); - php_info_print_table_row(2, "Pi3Web SAPI module version", "$Id$"); - php_info_print_table_row(2, "Server Name Stamp", HTTPCore_getServerStamp()); - snprintf(variable_buf, 511, "%d", HTTPCore_debugEnabled()); - php_info_print_table_row(2, "Debug Enabled", variable_buf); - PIPlatform_getCurrentDirectory( variable_buf, PI3WEB_SERVER_VAR_BUF_SIZE); - php_info_print_table_row(2, "Current Path", variable_buf); - if (lpCB->GetServerVariable(lpCB->ConnID, "SERVER_NAME", variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, "Main Virtual Hostname", variable_buf); - }; - snprintf(variable_buf, 511, "%d", PIPlatform_getProcessId()); - php_info_print_table_row(2, "Server PID", variable_buf); - php_info_print_table_row(2, "Server Platform", PIPlatform_getDescription()); - - PUTS("
Pi3Web Server Information

"); - - PUTS("\n"); - PUTS("\n"); - php_info_print_table_row(2, "HTTP Request Line", lpCB->lpszReq); - PUTS("\n"); - php_info_print_table_header(2, "Server Variable", "Value"); - - /* --- loop over all registered server variables --- */ - for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) - { - PCHAR pKey; - PIDBIterator_current( pIter, &pKey ); - if ( !pKey ) { /* sanity */ continue; }; - - variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, pKey, variable_buf); - } else if (PIPlatform_getLastError() == PIAPI_EINVAL) { - char *tmp_variable_buf; - - tmp_variable_buf = (char *) emalloc(variable_len); - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, tmp_variable_buf, &variable_len) - && variable_buf[0]) { - php_info_print_table_row(2, pKey, tmp_variable_buf); - } - efree(tmp_variable_buf); - } - } - - PUTS("
HTTP Request Information
HTTP Headers
"); -} - - -static zend_module_entry php_pi3web_module = { - STANDARD_MODULE_HEADER, - "PI3WEB", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_pi3web, - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -static int zend_pi3web_ub_write(const char *str, uint str_length) -{ - DWORD num_bytes = str_length; - LPCONTROL_BLOCK cb; - - cb = (LPCONTROL_BLOCK) SG(server_context); - - if ( !IWasLoaded ) return 0; - cb->WriteClient(cb->ConnID, (char *) str, &num_bytes, 0 ); - - if (num_bytes != str_length) - php_handle_aborted_connection(); - return num_bytes; -} - - -static int sapi_pi3web_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers) -{ - return SAPI_HEADER_ADD; -} - - -static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length) -{ - *total_length += sapi_header->header_len+2; -} - - -static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr) -{ - memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); - *combined_headers_ptr += sapi_header->header_len; - **combined_headers_ptr = '\r'; - (*combined_headers_ptr)++; - **combined_headers_ptr = '\n'; - (*combined_headers_ptr)++; -} - - -static int sapi_pi3web_send_headers(sapi_headers_struct *sapi_headers) -{ - uint total_length = 2; /* account for the trailing \r\n */ - char *combined_headers, *combined_headers_ptr; - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - sapi_header_struct default_content_type; - - if ( !IWasLoaded ) return SAPI_HEADER_SENT_SUCCESSFULLY; - - - if (SG(sapi_headers).send_default_content_type) { - sapi_get_default_content_type_header(&default_content_type); - accumulate_header_length(&default_content_type, (void *) &total_length); - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length); - - /* Generate headers */ - combined_headers = (char *) emalloc(total_length+1); - combined_headers_ptr = combined_headers; - if (SG(sapi_headers).send_default_content_type) { - concat_header(&default_content_type, (void *) &combined_headers_ptr); - sapi_free_header(&default_content_type); /* we no longer need it */ - } - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr); - *combined_headers_ptr++ = '\r'; - *combined_headers_ptr++ = '\n'; - *combined_headers_ptr = 0; - - lpCB->dwHttpStatusCode = SG(sapi_headers).http_response_code; - lpCB->SendHeaderFunction(lpCB->ConnID, &total_length, (LPDWORD) combined_headers); - - efree(combined_headers); - if (SG(sapi_headers).http_status_line) { - efree(SG(sapi_headers).http_status_line); - SG(sapi_headers).http_status_line = 0; - } - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - - -static int php_pi3web_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, &php_pi3web_module, 1)==FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - - -static int sapi_pi3web_read_post(char *buffer, uint count_bytes) -{ - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - DWORD read_from_buf=0; - DWORD read_from_input=0; - DWORD total_read=0; - - if ((DWORD)SG(read_post_bytes) < lpCB->cbAvailable) { - read_from_buf = MIN(lpCB->cbAvailable-SG(read_post_bytes), count_bytes); - memcpy(buffer, lpCB->lpbData+SG(read_post_bytes), read_from_buf); - total_read += read_from_buf; - } - if (read_from_bufcbTotalBytes) { - DWORD cbRead=0, cbSize; - - read_from_input = MIN(count_bytes-read_from_buf, lpCB->cbTotalBytes-SG(read_post_bytes)-read_from_buf); - while (cbRead < read_from_input) { - cbSize = read_from_input - cbRead; - if (!lpCB->ReadClient(lpCB->ConnID, buffer+read_from_buf+cbRead, &cbSize) || cbSize==0) { - break; - } - cbRead += cbSize; - } - total_read += cbRead; - } - - /* removed after re-testing POST with Pi3Web 2.0.2 */ - /* SG(read_post_bytes) += total_read; */ - return total_read; -} - - -static char *sapi_pi3web_read_cookies(void) -{ - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - char variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; - DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - - if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) { - return estrndup(variable_buf, variable_len); - } else if (PIPlatform_getLastError()==PIAPI_EINVAL) { - char *tmp_variable_buf = (char *) emalloc(variable_len+1); - - if (lpCB->GetServerVariable(lpCB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) { - tmp_variable_buf[variable_len] = 0; - return tmp_variable_buf; - } else { - efree(tmp_variable_buf); - } - } - return NULL; -} - -static void init_request_info(LPCONTROL_BLOCK lpCB) -{ - SG(server_context) = lpCB; - SG(request_info).request_method = lpCB->lpszMethod; - SG(request_info).query_string = lpCB->lpszQueryString; - SG(request_info).path_translated = lpCB->lpszPathTranslated; - SG(request_info).request_uri = lpCB->lpszUri; - SG(request_info).content_type = lpCB->lpszContentType; - SG(request_info).content_length = lpCB->cbTotalBytes; - SG(request_info).auth_user = (lpCB->lpszUser) ? (char *)estrdup((const char *)(lpCB->lpszUser)) : 0; - SG(request_info).auth_password = (lpCB->lpszPassword) ? (char *)estrdup((const char *)(lpCB->lpszPassword)) : 0; - SG(sapi_headers).http_response_code = 200; -} - -static void sapi_pi3web_register_variables(zval *track_vars_array) -{ - char static_variable_buf[PI3WEB_SERVER_VAR_BUF_SIZE]; - char *variable_buf; - DWORD variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - LPCONTROL_BLOCK lpCB = (LPCONTROL_BLOCK) SG(server_context); - PIDB *pDB = (PIDB *)lpCB->GetVariableNames(lpCB->ConnID); - PIDBIterator *pIter = PIDB_getIterator( pDB, PIDBTYPE_STRING, 0, 0 ); - - /* --- loop over all registered server variables --- */ - for(; pIter && PIDBIterator_atValidElement( pIter ); PIDBIterator_next( pIter ) ) - { - PCHAR pKey; - PIDBIterator_current( pIter, &pKey ); - if ( !pKey ) { /* sanity */ continue; }; - - variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, static_variable_buf, &variable_len) - && (variable_len > 1)) { - php_register_variable(pKey, static_variable_buf, track_vars_array); - } else if (PIPlatform_getLastError()==PIAPI_EINVAL) { - variable_buf = (char *) emalloc(variable_len); - if (lpCB->GetServerVariable(lpCB->ConnID, pKey, variable_buf, &variable_len)) { - php_register_variable(pKey, variable_buf, track_vars_array); - } - efree(variable_buf); - } - - } - - - /* PHP_SELF support */ - variable_len = PI3WEB_SERVER_VAR_BUF_SIZE; - if (lpCB->GetServerVariable(lpCB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len) - && (variable_len > 1)) { - php_register_variable("PHP_SELF", static_variable_buf, track_vars_array); - } -} - -static sapi_module_struct pi3web_sapi_module = { - "pi3web", /* name */ - "PI3WEB", /* pretty name */ - - php_pi3web_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - NULL, /* deactivate */ - zend_pi3web_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - php_error, /* error handler */ - sapi_pi3web_header_handler, /* header handler */ - sapi_pi3web_send_headers, /* send headers handler */ - NULL, /* send header handler */ - sapi_pi3web_read_post, /* read POST data */ - sapi_pi3web_read_cookies, /* read Cookies */ - sapi_pi3web_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -MODULE_API DWORD PHP7_wrapper(LPCONTROL_BLOCK lpCB) -{ - zend_file_handle file_handle = {0}; - int iRet = PIAPI_COMPLETED; - - zend_first_try { - file_handle.filename = lpCB->lpszFileName; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - - init_request_info(lpCB); - php_request_startup(); - - switch ( lpCB->dwBehavior ) { - case PHP_MODE_STANDARD: - iRet = ( php_execute_script( &file_handle ) ) ? - PIAPI_COMPLETED : PIAPI_ERROR; - break; - case PHP_MODE_HIGHLIGHT: { - zend_syntax_highlighter_ini syntax_highlighter_ini; - if ( open_file_for_scanning( &file_handle ) == SUCCESS ) - { - php_get_highlight_struct( &syntax_highlighter_ini ); - zend_highlight( &syntax_highlighter_ini ); - } - else - { - iRet = PIAPI_ERROR; - }; - }; - break; - case PHP_MODE_INDENT: { - sapi_header_line ctr = {0}; - - ctr.line = "Content-Type: text/plain"; - ctr.line_len = strlen(ctr.line); - - sapi_header_op(SAPI_HEADER_REPLACE, &ctr); - } - if ( open_file_for_scanning( &file_handle ) == SUCCESS ) - { - zend_indent(); - } - else - { - iRet = PIAPI_ERROR; - }; - break; - case PHP_MODE_LINT: - iRet = (php_lint_script(&file_handle) == SUCCESS) ? - PIAPI_COMPLETED : PIAPI_ERROR; - break; - default: - iRet = PIAPI_ERROR;; - } - - if (SG(request_info).cookie_data) { - efree(SG(request_info).cookie_data); - }; - - php_request_shutdown(NULL); - } zend_catch { - iRet = PIAPI_ERROR; - } zend_end_try(); - return iRet; -} - -MODULE_API BOOL PHP7_startup() { - tsrm_startup(1, 1, 0, NULL); - sapi_startup(&pi3web_sapi_module); - if (pi3web_sapi_module.startup) { - pi3web_sapi_module.startup(&pi3web_sapi_module); - }; - IWasLoaded = 1; - return IWasLoaded; -}; - -MODULE_API BOOL PHP7_shutdown() { - if (pi3web_sapi_module.shutdown) { - pi3web_sapi_module.shutdown(&pi3web_sapi_module); - }; - sapi_shutdown(); - tsrm_shutdown(); - IWasLoaded = 0; - return !IWasLoaded; -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/sapi/pi3web/pi3web_sapi.h b/sapi/pi3web/pi3web_sapi.h deleted file mode 100644 index 70eec611b4e4f..0000000000000 --- a/sapi/pi3web/pi3web_sapi.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _PI3WEB_SAPI_H_ -#define _PI3WEB_SAPI_H_ - -#ifdef PHP_WIN32 -# include -# ifdef PHP7PI3WEB_EXPORTS -# define MODULE_API __declspec(dllexport) -# else -# define MODULE_API __declspec(dllimport) -# endif -#else -# if defined(__GNUC__) && __GNUC__ >= 4 -# define MODULE_API __attribute__ ((visibility("default"))) -# else -# define MODULE_API -# endif -# define far - - typedef int BOOL; - typedef void far *LPVOID; - typedef unsigned long DWORD; - typedef DWORD far *LPDWORD; - typedef char CHAR; - typedef CHAR *LPSTR; - typedef unsigned char BYTE; - typedef BYTE far *LPBYTE; -#endif - - typedef LPVOID HCONN; - -#ifdef __cplusplus -extern "C" { -#endif - -#define PHP_MODE_STANDARD 1 -#define PHP_MODE_HIGHLIGHT 2 -#define PHP_MODE_INDENT 3 -#define PHP_MODE_LINT 4 - -// -// passed to the procedure on a new request -// -typedef struct _CONTROL_BLOCK { - DWORD cbSize; // size of this struct. - HCONN ConnID; // Context number not to be modified! - DWORD dwHttpStatusCode; // HTTP Status code - CHAR lpszLogData[80]; // null terminated log info - - LPSTR lpszMethod; // REQUEST_METHOD - LPSTR lpszQueryString; // QUERY_STRING - LPSTR lpszPathInfo; // PATH_INFO - LPSTR lpszPathTranslated; // PATH_TRANSLATED - LPSTR lpszFileName; // FileName to PHP3 physical file - LPSTR lpszUri; // The request URI - LPSTR lpszReq; // The whole HTTP request line - LPSTR lpszUser; // The authenticated user - LPSTR lpszPassword; // The authenticated password - - DWORD cbTotalBytes; // Total bytes indicated from client - DWORD cbAvailable; // Available number of bytes - LPBYTE lpbData; // pointer to cbAvailable bytes - - LPSTR lpszContentType; // Content type of client data - DWORD dwBehavior; // PHP behavior (standard, highlight, intend - - - LPVOID (* GetVariableNames) (HCONN hConn); - - BOOL (* GetServerVariable) ( HCONN hConn, - LPSTR lpszVariableName, - LPVOID lpvBuffer, - LPDWORD lpdwSize ); - - BOOL (* WriteClient) ( HCONN hConn, - LPVOID lpvBuffer, - LPDWORD lpdwBytes, - DWORD dwReserved ); - - BOOL (* ReadClient) ( HCONN hConn, - LPVOID lpvBuffer, - LPDWORD lpdwSize ); - - BOOL (* SendHeaderFunction)( HCONN hConn, - LPDWORD lpdwSize, - LPDWORD lpdwDataType ); - -} CONTROL_BLOCK, *LPCONTROL_BLOCK; - -MODULE_API DWORD PHP7_wrapper(LPCONTROL_BLOCK lpCB); -MODULE_API BOOL PHP7_startup(); -MODULE_API BOOL PHP7_shutdown(); - -// the following type declaration is for the server side -typedef DWORD ( * PFN_WRAPPERFUNC )( CONTROL_BLOCK *pCB ); - - - -#ifdef __cplusplus -} -#endif - -#endif // end definition _PI3WEB_SAPI_H_ diff --git a/sapi/roxen/README b/sapi/roxen/README deleted file mode 100644 index 59c215cba0e80..0000000000000 --- a/sapi/roxen/README +++ /dev/null @@ -1,18 +0,0 @@ -Roxen PHP support. Early version. Don't expect to be able to get it to -work. Requires Pike 0.7.79 and Roxen 1.4. Anything less won't work. - -The module is now thread safe, in a couple of different modes. First -mode, the default, uses a process global PHP lock in the Roxen -module. This means that all PHP-requests are serialized (ie only one -script is executed at any one time). The second option is using ZTS -(Zend Thread Safe mode). Unless --enable-roxen-zts is specified, this -won't be used. - -This solution now works fine and is recommended. Multiple PHP7 -requests will be run in parallell. The maximum number of parallell -PHP7-execution is limited to the number of handle threads Roxen is -started with. - -Support for this module is lacking. Please contact Roxen Internet -Software for support and help. See http://www.roxen.com/company/contact/ -for contact information. diff --git a/sapi/roxen/TODO b/sapi/roxen/TODO deleted file mode 100644 index 47143f1be10da..0000000000000 --- a/sapi/roxen/TODO +++ /dev/null @@ -1,33 +0,0 @@ -BUGS: - -- fix backtraces -- exit in PHP exits Roxen -- POST newline added? -- Rewriting header handling so that more than one header with the same - name can be set (most importantly, cookies). -- Recursive mutex lock problem: - - And another error (when trying to include a class) - - Recursive mutex locks! - /Usr/local/pike/7.0.54/lib/modules/PHP7.so.Interpreter: - run("/home/www/www.tx.pl/news/test.php",mapping[3],modules/scripting/php7.pike.PHPScript(),modules/scripting/php7.pike.PHPScript.done) - modules/scripting/php7.pike:169: run() - base_server/roxen.pike:569: handler_thread(3). - - And after this every access to any php script (on other virtual sites - also) ends (of course there is no proper output) with this error: - - Php4.Interpreter->run: Tried to run a PHP-script from a PHP - callback!/usr/local/pike/7.0.54/lib/modules/PHP7.so.Interpreter: - run("/home/www/biall.com.pl/index.php3",mapping[2],modules/scripting/php7.pike.PHPScript(),modules/scripting/php7.pike.PHPScript.done) - modules/scripting/php7.pike:169: run() - base_server/roxen.pike:569: handler_thread(3). - - -ADDITIONS: - -- use th_farm -- change cwd in single threaded mode -- per-virtual-server configuration - diff --git a/sapi/roxen/config.m4 b/sapi/roxen/config.m4 deleted file mode 100644 index d536ac571b8f3..0000000000000 --- a/sapi/roxen/config.m4 +++ /dev/null @@ -1,55 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(roxen,, -[ --with-roxen=DIR Build PHP as a Pike module. DIR is the base Roxen - directory, normally /usr/local/roxen/server], no, no) - -PHP_ARG_ENABLE(roxen-zts, whether Roxen module is build using ZTS, -[ --enable-roxen-zts ROXEN: Build the Roxen module using Zend Thread Safety], no, no) - -RESULT= -AC_MSG_CHECKING([for Roxen/Pike support]) -if test "$PHP_ROXEN" != "no"; then - if test ! -d $PHP_ROXEN ; then - AC_MSG_ERROR([You did not specify a directory]) - fi - if test -f $PHP_ROXEN/bin/roxen; then - PIKE=$PHP_ROXEN/bin/roxen - elif test -f $PHP_ROXEN/bin/pike; then - PIKE=$PHP_ROXEN/bin/pike - else - AC_MSG_ERROR([Could not find a pike in $PHP_ROXEN/bin/]) - fi - - if $PIKE -e 'float v; catch(v = __VERSION__ + (__BUILD__/10000.0)); if(v < 0.7079) exit(1); exit(0);'; then - PIKE_MODULE_DIR=`$PIKE --show-paths 2>&1| grep '^Module' | sed -e 's/.*: //'` - PIKE_INCLUDE_DIR=`echo $PIKE_MODULE_DIR | sed -e 's,lib/pike/modules,include/pike,' -e 's,lib/modules,include/pike,'` - if test -z "$PIKE_INCLUDE_DIR" || test -z "$PIKE_MODULE_DIR"; then - AC_MSG_ERROR([Failed to figure out Pike module and include directories]) - fi - else - AC_MSG_ERROR([Roxen/PHP requires Pike 0.7.79 or newer]) - fi - - PHP_ADD_INCLUDE($PIKE_INCLUDE_DIR) - AC_DEFINE(HAVE_ROXEN, 1, [Whether you use Roxen]) - PHP_SELECT_SAPI(roxen, shared, roxen.c) - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PIKE_MODULE_DIR/PHP7.so" - RESULT="yes - Pike binary used: $PIKE - Pike include dir: $PIKE_INCLUDE_DIR - Pike module directory: $PIKE_MODULE_DIR" - PIKE_INCLUDE_DIR=" -I$PIKE_INCLUDE_DIR " - - if test "$PHP_ROXEN_ZTS" != "no"; then - PHP_BUILD_THREAD_SAFE - AC_DEFINE(ROXEN_USE_ZTS, 1, [Whether to use Roxen in ZTS mode]) - fi -fi -AC_MSG_RESULT([$RESULT]) - -dnl ## Local Variables: -dnl ## tab-width: 4 -dnl ## End: diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c deleted file mode 100644 index 4afba3829c952..0000000000000 --- a/sapi/roxen/roxen.c +++ /dev/null @@ -1,725 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: David Hedbor | - | Based on aolserver SAPI by Sascha Schumann | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#ifdef HAVE_ROXEN - -#include "php_ini.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_main.h" -#include "ext/standard/info.h" - -#include "php_version.h" - -#ifndef ZTS -/* Only valid if thread safety is enabled. */ -#undef ROXEN_USE_ZTS -#endif - - -/* Pike Include Files - * - * conflicts with pike avoided by only using long names. Requires a new - * Pike 0.7 since it was implemented for this interface only. - * - */ -#define NO_PIKE_SHORTHAND - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#undef HIDE_GLOBAL_VARIABLES -#undef REVEAL_GLOBAL_VARIABLES -#define HIDE_GLOBAL_VARIABLES() -#define REVEAL_GLOBAL_VARIABLES() - -/* php_roxen_request is per-request object storage */ - -typedef struct -{ - struct mapping *request_data; - struct object *my_fd_obj; - int my_fd; - char *filename; -} php_roxen_request; - - -/* Defines to get to the data supplied when the script is started. */ - -#ifdef ROXEN_USE_ZTS - -/* ZTS does work now, but it seems like it's faster using the "serialization" - * method I previously used. Thus it's not used unless ROXEN_USE_ZTS is defined. - */ - -/* Per thread storage area id... */ -static int roxen_globals_id; - -# define GET_THIS() php_roxen_request *_request = ts_resource(roxen_globals_id) -# define THIS _request -#else -static php_roxen_request *current_request = NULL; - -# define GET_THIS() current_request = ((php_roxen_request *)Pike_fp->current_storage) -# define THIS current_request -#endif - -/* File descriptor integer. Used to write directly to the FD without - * passing Pike - */ -#define MY_FD (THIS->my_fd) - -/* FD object. Really a PHPScript object from Pike which implements a couple - * of functions to handle headers, writing and buffering. - */ -#define MY_FD_OBJ ((struct object *)(THIS->my_fd_obj)) - -/* Mapping with data supplied from the calling Roxen module. Contains - * a mapping with headers, an FD object etc. - */ -#define REQUEST_DATA ((struct mapping *)(THIS->request_data)) - - -#if defined(_REENTRANT) && !defined(ROXEN_USE_ZTS) -/* Lock used to serialize the PHP execution. If ROXEN_USE_ZTS is defined, we - * are using the PHP thread safe mechanism instead. - */ -static PIKE_MUTEX_T roxen_php_execution_lock; -# define PHP_INIT_LOCK() mt_init(&roxen_php_execution_lock) -# define PHP_LOCK(X) THREADS_ALLOW();mt_lock(&roxen_php_execution_lock);THREADS_DISALLOW() -# define PHP_UNLOCK(X) mt_unlock(&roxen_php_execution_lock); -# define PHP_DESTROY() mt_destroy(&roxen_php_execution_lock) -#else /* !_REENTRANT */ -# define PHP_INIT_LOCK() -# define PHP_LOCK(X) -# define PHP_UNLOCK(X) -# define PHP_DESTROY() -#endif /* _REENTRANT */ - -extern int fd_from_object(struct object *o); -static unsigned char roxen_php_initialized; - -/* This allows calling of pike functions from the PHP callbacks, - * which requires the Pike interpreter to be locked. - */ -#define THREAD_SAFE_RUN(COMMAND, what) do {\ - struct thread_state *state;\ - if((state = thread_state_for_id(th_self()))!=NULL) {\ - if(!state->swapped) {\ - COMMAND;\ - } else {\ - mt_lock(&interpreter_lock);\ - SWAP_IN_THREAD(state);\ - COMMAND;\ - SWAP_OUT_THREAD(state);\ - mt_unlock(&interpreter_lock);\ - }\ - }\ -} while(0) - -struct program *php_program; - - -/* To avoid executing a PHP script from a PHP callback, which would - * create a deadlock, a global thread id is used. If the thread calling the - * php-script is the same as the current thread, it fails. - */ -static int current_thread = -1; - - -/* Low level header lookup. Basically looks for the named header in the mapping - * headers in the supplied options mapping. - */ - -static INLINE struct svalue *lookup_header(char *headername) -{ - struct svalue *headers, *value; - struct pike_string *sind; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(!headers || headers->type != PIKE_T_MAPPING) return NULL; - sind = make_shared_string(headername); - value = low_mapping_string_lookup(headers->u.mapping, sind); - free_string(sind); - if(!value) return NULL; - return value; -} - -/* Lookup a header in the mapping and return the value as a string, or - * return the default if it's missing - */ -INLINE static char *lookup_string_header(char *headername, char *default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_STRING) - return default_value; - return head->u.string->str; -} - -/* Lookup a header in the mapping and return the value as if it's an integer - * and otherwise return the default. - */ -INLINE static int lookup_integer_header(char *headername, int default_value) -{ - struct svalue *head = NULL; - THREAD_SAFE_RUN(head = lookup_header(headername), "header lookup"); - if(!head || head->type != PIKE_T_INT) - return default_value; - return head->u.integer; -} - -/* - * php_roxen_low_ub_write() writes data to the client connection. Might be - * rewritten to do more direct IO to save CPU and the need to lock the * - * interpreter for better threading. - */ - -static int -php_roxen_low_ub_write(const char *str, uint str_length) { - int sent_bytes = 0; - struct pike_string *to_write = NULL; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - to_write = make_shared_binary_string(str, str_length); - push_string(to_write); - safe_apply(MY_FD_OBJ, "write", 1); - if(Pike_sp[-1].type == PIKE_T_INT) - sent_bytes = Pike_sp[-1].u.integer; - pop_stack(); - if(sent_bytes != str_length) { - /* This means the connection is closed. Dead. Gone. *sniff* */ - php_handle_aborted_connection(); - } - return sent_bytes; -} - -/* - * php_roxen_sapi_ub_write() calls php_roxen_low_ub_write in a Pike thread - * safe manner. - */ - -static int -php_roxen_sapi_ub_write(const char *str, uint str_length) -{ -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - int sent_bytes = 0, fd = MY_FD; - if(fd) - { - for(sent_bytes=0;sent_bytes < str_length;) - { - int written; - written = fd_write(fd, str + sent_bytes, str_length - sent_bytes); - if(written < 0) - { - switch(errno) - { - default: - /* This means the connection is closed. Dead. Gone. *sniff* */ - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return sent_bytes; - case EINTR: - case EWOULDBLOCK: - continue; - } - - } else { - sent_bytes += written; - } - } - } else { - THREAD_SAFE_RUN(sent_bytes = php_roxen_low_ub_write(str, str_length), - "write"); - } - return sent_bytes; -} - -/* php_roxen_set_header() sets a header in the header mapping. Called in a - * thread safe manner from php_roxen_sapi_header_handler. - */ -static void php_roxen_set_header(char *header_name, char *value, char *p) -{ - struct svalue hsval; - struct pike_string *hval, *ind, *hind; - struct mapping *headermap; - struct svalue *s_headermap; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - hval = make_shared_string(value); - ind = make_shared_string(" _headers"); - hind = make_shared_binary_string(header_name, - (int)(p - header_name)); - - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - if(!s_headermap) - { - struct svalue mappie; - mappie.type = PIKE_T_MAPPING; - headermap = allocate_mapping(1); - mappie.u.mapping = headermap; - mapping_string_insert(REQUEST_DATA, ind, &mappie); - free_mapping(headermap); - } else - headermap = s_headermap->u.mapping; - - hsval.type = PIKE_T_STRING; - hsval.u.string = hval; - mapping_string_insert(headermap, hind, &hsval); - - free_string(hval); - free_string(ind); - free_string(hind); -} - -/* - * php_roxen_sapi_header_handler() sets a HTTP reply header to be - * sent to the client. - */ -static int -php_roxen_sapi_header_handler(sapi_header_struct *sapi_header, - sapi_headers_struct *sapi_headers) -{ - char *header_name, *header_content, *p; - header_name = sapi_header->header; - header_content = p = strchr(header_name, ':'); - - if(p) { - do { - header_content++; - } while(*header_content == ' '); - THREAD_SAFE_RUN(php_roxen_set_header(header_name, header_content, p), "header handler"); - } - sapi_free_header(sapi_header); - return 0; -} - -/* - * php_roxen_sapi_send_headers() flushes the headers to the client. - * Called before real content is sent by PHP. - */ - -static int -php_roxen_low_send_headers(sapi_headers_struct *sapi_headers) -{ - struct pike_string *ind; - struct svalue *s_headermap; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(!MY_FD_OBJ->prog) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return SAPI_HEADER_SEND_FAILED; - } - ind = make_shared_string(" _headers"); - s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind); - free_string(ind); - - push_int(SG(sapi_headers).http_response_code); - if(s_headermap && s_headermap->type == PIKE_T_MAPPING) - ref_push_mapping(s_headermap->u.mapping); - else - push_int(0); - safe_apply(MY_FD_OBJ, "send_headers", 2); - pop_stack(); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int -php_roxen_sapi_send_headers(sapi_headers_struct *sapi_headers) -{ - int res = 0; - THREAD_SAFE_RUN(res = php_roxen_low_send_headers(sapi_headers), "send headers"); - return res; -} - -/* - * php_roxen_sapi_read_post() reads a specified number of bytes from - * the client. Used for POST/PUT requests. - */ - -INLINE static int php_roxen_low_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(!MY_FD_OBJ->prog) - { - PG(connection_status) = PHP_CONNECTION_ABORTED; - zend_bailout(); - return -1; - } - push_int(count_bytes); - safe_apply(MY_FD_OBJ, "read_post", 1); - if(Pike_sp[-1].type == PIKE_T_STRING) { - MEMCPY(buf, Pike_sp[-1].u.string->str, - (total_read = Pike_sp[-1].u.string->len)); - buf[total_read] = '\0'; - } else - total_read = 0; - pop_stack(); - return total_read; -} - -static int -php_roxen_sapi_read_post(char *buf, uint count_bytes) -{ - uint total_read = 0; - THREAD_SAFE_RUN(total_read = php_roxen_low_read_post(buf, count_bytes), "read post"); - return total_read; -} - -/* - * php_roxen_sapi_read_cookies() returns the Cookie header from - * the HTTP request header - */ - -static char * -php_roxen_sapi_read_cookies(void) -{ - char *cookies; - cookies = lookup_string_header("HTTP_COOKIE", NULL); - return cookies; -} - -static void php_info_roxen(ZEND_MODULE_INFO_FUNC_ARGS) -{ - /* char buf[512]; */ - php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", "$Id$"); - /* php_info_print_table_row(2, "Build date", Ns_InfoBuildDate()); - php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile()); - php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog()); - php_info_print_table_row(2, "Installation path", Ns_InfoHomePath()); - php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname()); - php_info_print_table_row(2, "Source code label", Ns_InfoLabel()); - php_info_print_table_row(2, "Server platform", Ns_InfoPlatform()); - snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion()); - php_info_print_table_row(2, "Server version", buf); - snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", - uptime / 86400, - (uptime / 3600) % 24, - (uptime / 60) % 60, - uptime % 60); - php_info_print_table_row(2, "Server uptime", buf); - */ - php_info_print_table_end(); -} - -static zend_module_entry php_roxen_module = { - STANDARD_MODULE_HEADER, - "Roxen", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_roxen, - NULL, - STANDARD_MODULE_PROPERTIES -}; - -static int php_roxen_startup(sapi_module_struct *sapi_module) -{ - if(php_module_startup(sapi_module, &php_roxen_module, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - -/* this structure is static (as in "it does not change") */ - -static sapi_module_struct roxen_sapi_module = { - "roxen", - "Roxen", - php_roxen_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - NULL, /* activate */ - NULL, /* deactivate */ - php_roxen_sapi_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - php_error, /* error handler */ - php_roxen_sapi_header_handler, /* header handler */ - php_roxen_sapi_send_headers, /* send headers handler */ - NULL, /* send header handler */ - php_roxen_sapi_read_post, /* read POST data */ - php_roxen_sapi_read_cookies, /* read Cookies */ - NULL, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -/* - * php_roxen_hash_environment() populates the php script environment - * with a number of variables. HTTP_* variables are created for - * the HTTP header data, so that a script can access these. - */ -#define ADD_STRING(name) \ - MAKE_STD_ZVAL(zvalue); \ - zvalue->type = IS_STRING; \ - zvalue->value.str.len = strlen(buf); \ - zvalue->value.str.val = estrndup(buf, zvalue->value.str.len); \ - zend_hash_update(&EG(symbol_table), name, sizeof(name), \ - &zvalue, sizeof(zval *), NULL) - -static void -php_roxen_hash_environment(void) -{ - int i; - char buf[512]; - zval *zvalue; - struct svalue *headers; - struct pike_string *sind; - struct array *indices; - struct svalue *ind, *val; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - sind = make_shared_string("env"); - headers = low_mapping_string_lookup(REQUEST_DATA, sind); - free_string(sind); - if(headers && headers->type == PIKE_T_MAPPING) { - indices = mapping_indices(headers->u.mapping); - for(i = 0; i < indices->size; i++) { - ind = &indices->item[i]; - val = low_mapping_lookup(headers->u.mapping, ind); - if(ind && ind->type == PIKE_T_STRING && - val && val->type == PIKE_T_STRING) { - int buf_len; - buf_len = MIN(511, ind->u.string->len); - strncpy(buf, ind->u.string->str, buf_len); - buf[buf_len] = '\0'; /* Terminate correctly */ - MAKE_STD_ZVAL(zvalue); - zvalue->type = IS_STRING; - zvalue->value.str.len = val->u.string->len; - zvalue->value.str.val = estrndup(val->u.string->str, zvalue->value.str.len); - - zend_hash_update(&EG(symbol_table), buf, buf_len + 1, &zvalue, sizeof(zval *), NULL); - } - } - free_array(indices); - } - - /* - MAKE_STD_ZVAL(zvalue); - zvalue->type = IS_LONG; - zvalue->value.lval = Ns_InfoBootTime(); - zend_hash_update(&EG(symbol_table), "SERVER_BOOTTIME", sizeof("SERVER_BOOTTIME"), &zvalue, sizeof(zval *), NULL); - */ -} - -/* - * php_roxen_module_main() is called by the per-request handler and - * "executes" the script - */ - -static int php_roxen_module_main(void) -{ - int res, len; - char *dir; - zend_file_handle file_handle; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = THIS->filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - THREADS_ALLOW(); - res = php_request_startup(); - THREADS_DISALLOW(); - if(res == FAILURE) { - return 0; - } - php_roxen_hash_environment(); - THREADS_ALLOW(); - php_execute_script(&file_handle); - php_request_shutdown(NULL); - THREADS_DISALLOW(); - return 1; -} - -/* - * The php_roxen_request_handler() is called per request and handles - * everything for one request. - */ - -void f_php_roxen_request_handler(INT32 args) -{ - struct object *my_fd_obj; - struct mapping *request_data; - struct svalue *done_callback, *raw_fd; - struct pike_string *script, *ind; - int status = 1; -#ifdef ROXEN_USE_ZTS - GET_THIS(); -#endif - - if(current_thread == th_self()) - php_error(E_WARNING, "PHP7.Interpreter->run: Tried to run a PHP-script from a PHP " - "callback!"); - get_all_args("PHP7.Interpreter->run", args, "%S%m%O%*", &script, - &request_data, &my_fd_obj, &done_callback); - if(done_callback->type != PIKE_T_FUNCTION) - php_error(E_WARNING, "PHP7.Interpreter->run: Bad argument 4, expected function.\n"); - PHP_LOCK(THIS); /* Need to lock here or reusing the same object might cause - * problems in changing stuff in that object */ -#ifndef ROXEN_USE_ZTS - GET_THIS(); -#endif - THIS->request_data = request_data; - THIS->my_fd_obj = my_fd_obj; - THIS->filename = script->str; - current_thread = th_self(); - SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0); - SG(server_context) = (void *)1; /* avoid server_context == NULL */ - - /* path_translated is apparently the absolute path to the file, not - the translated PATH_INFO - */ - SG(request_info).path_translated = - lookup_string_header("SCRIPT_FILENAME", NULL); - SG(request_info).request_uri = lookup_string_header("DOCUMENT_URI", NULL); - if(!SG(request_info).request_uri) - SG(request_info).request_uri = lookup_string_header("SCRIPT_NAME", NULL); - SG(request_info).request_method = lookup_string_header("REQUEST_METHOD", "GET"); - SG(request_info).content_length = lookup_integer_header("HTTP_CONTENT_LENGTH", 0); - SG(request_info).content_type = lookup_string_header("HTTP_CONTENT_TYPE", NULL); - SG(sapi_headers).http_response_code = 200; - - /* FIXME: Check for auth stuff needs to be fixed... */ - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - - ind = make_shared_binary_string("my_fd", 5); - raw_fd = low_mapping_string_lookup(THIS->request_data, ind); - if(raw_fd && raw_fd->type == PIKE_T_OBJECT) - { - int fd = fd_from_object(raw_fd->u.object); - if(fd == -1) - php_error(E_WARNING, "PHP7.Interpreter->run: my_fd object not open or not an FD.\n"); - THIS->my_fd = fd; - } else - THIS->my_fd = 0; - - status = php_roxen_module_main(); - current_thread = -1; - - apply_svalue(done_callback, 0); - pop_stack(); - pop_n_elems(args); - push_int(status); - PHP_UNLOCK(THIS); -} - - -/* Clear the object global struct */ -static void clear_struct(struct object *o) -{ - MEMSET(Pike_fp->current_storage, 0, sizeof(php_roxen_request)); -} - - -/* - * pike_module_init() is called by Pike once at startup - * - * This functions allocates basic structures - */ - -void pike_module_init( void ) -{ - if (!roxen_php_initialized) { -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); -#ifdef ROXEN_USE_ZTS - ts_allocate_id(&roxen_globals_id, sizeof(php_roxen_request), NULL, NULL); -#endif -#endif - sapi_startup(&roxen_sapi_module); - /*php_roxen_startup(&roxen_sapi_module); removed - should be called from SAPI activation*/ - roxen_php_initialized = 1; - PHP_INIT_LOCK(); - } - start_new_program(); /* Text */ - ADD_STORAGE(php_roxen_request); - set_init_callback(clear_struct); - pike_add_function("run", f_php_roxen_request_handler, - "function(string, mapping, object, function:int)", 0); - add_program_constant("Interpreter", (php_program = end_program()), 0); -} - -/* - * pike_module_exit() performs the last steps before the - * server exists. Shutdowns basic services and frees memory - */ - -void pike_module_exit(void) -{ - roxen_php_initialized = 0; - roxen_sapi_module.shutdown(&roxen_sapi_module); - if(php_program) free_program(php_program); -#ifdef ZTS - tsrm_shutdown(); -#endif - PHP_DESTROY(); -} -#endif diff --git a/sapi/thttpd/CREDITS b/sapi/thttpd/CREDITS deleted file mode 100644 index 8f02f36f4fb5a..0000000000000 --- a/sapi/thttpd/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -thttpd -Sascha Schumann diff --git a/sapi/thttpd/README b/sapi/thttpd/README deleted file mode 100644 index 1e80a01956eeb..0000000000000 --- a/sapi/thttpd/README +++ /dev/null @@ -1,85 +0,0 @@ -README FOR THTTPD MODULE (by Sascha Schumann) -($Date$) - - This is a SAPI module for PHP 4.x supporting thttpd, the tiny, - turbo, throttling HTTP server by Jef Poskanzer. - - NOTE: All HTTP requests will be serialized. That means, one long running - script will block all other requests. Choose another web server, - if you want to execute arbitrarily long running scripts. - - The module contains a patch against version 2.21b of thttpd. The patch - fixes a number of bugs and adds some functionality: - - - HTTP/1.1 Persistent Connection/Pipeline Support - - PHP Scripting (**.php by default) - - Highlighting PHP Scripts (**.phps by default) - - Fast Accept Loop (unique to PHP) - - Periodic Connection Expiring (unique to PHP) - - Log to stdout (logfile=-) - - Fixes the Host: header vulnerability (affects vhosts only) - - Asynchronous request body handling (e.g. for POSTs) - - Accept filter for Linux - - Fix for non-blocking sending of thttpd-generated responses - - You can configure the filename extensions by creating a config file for - thttpd and setting these entries: - - phppat=PATTERN - phpspat=PATTERN - - The PATTERN has the same format as defined here: - - http://acme.com/software/thttpd/options.html#CGI_PATTERN - - "**.php" means: match any file ending in .php in any directory. - Setting the pattern from the command line is not supported. - - NOTE: This version supports *only* thttpd 2.21b, no prior or later - version. - - This is a functional and stable module (it runs a large application - like IMP 2.2.0 without any problems). Its original intention was to - demonstrate the ability of PHP to work in every web server environment. - -REQUIRED DOWNLOADS - - 1. thttpd 2.21b (2.20 or +2.22beta will _not_ work) - - Full Distribution: - http://www.acme.com/software/thttpd/thttpd-2.21b.tar.gz - - 2. PHP 4.x - - Download: - http://www.php.net/ - - Snapshots from CVS: - http://snaps.php.net/ - - -BUILD INSTRUCTIONS - - 1. Extract software packages - - $ gunzip -c thttpd-2.xx.tar.gz | tar xf - - $ gunzip -c php-*.tar.gz | tar xf - - - 2. Prepare PHP - - $ cd php-* - $ ./configure \ - --with-thttpd=../thttpd-2.xx \ - - $ make install - $ cd .. - - You can see the list of valid PHP options by executing - - $ ./configure --help - - 3. Configure, compile, install thttpd - - Now follow the thttpd instructions. The Makefile template of - thttpd was changed to automatically use the components - required by PHP. diff --git a/sapi/thttpd/config.m4 b/sapi/thttpd/config.m4 deleted file mode 100644 index fddb709d92b40..0000000000000 --- a/sapi/thttpd/config.m4 +++ /dev/null @@ -1,39 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(thttpd,, -[ --with-thttpd=SRCDIR Build PHP as thttpd module], no, no) - -AC_MSG_CHECKING([for thttpd]) - -if test "$PHP_THTTPD" != "no"; then - if test ! -d $PHP_THTTPD; then - AC_MSG_RESULT(thttpd directory does not exist ($PHP_THTTPD)) - fi - - PHP_EXPAND_PATH($PHP_THTTPD, THTTPD) - - if grep thttpd.2.21b $PHP_THTTPD/version.h >/dev/null; then - patch="test -f $THTTPD/php_patched || \ - (cd $THTTPD && patch -p1 < $abs_srcdir/sapi/thttpd/thttpd_patch && touch php_patched)" - - elif grep Premium $PHP_THTTPD/version.h >/dev/null; then - patch= - else - AC_MSG_ERROR([This version only supports thttpd-2.21b and Premium thttpd]) - fi - PHP_TARGET_RDYNAMIC - INSTALL_IT="\ - echo 'PHP_LIBS = -L. -lphp7 \$(PHP_LIBS) \$(EXTRA_LIBS)' > $THTTPD/php_makefile; \ - echo 'PHP_LDFLAGS = \$(NATIVE_RPATHS) \$(PHP_LDFLAGS)' >> $THTTPD/php_makefile; \ - echo 'PHP_CFLAGS = \$(COMMON_FLAGS) \$(CFLAGS_CLEAN) \$(CPPFLAGS) \$(EXTRA_CFLAGS)' >> $THTTPD/php_makefile; \ - rm -f $THTTPD/php_thttpd.c $THTTPD/php_thttpd.h $THTTPD/libphp7.a; \ - \$(LN_S) $abs_srcdir/sapi/thttpd/thttpd.c $THTTPD/php_thttpd.c; \ - \$(LN_S) $abs_srcdir/sapi/thttpd/php_thttpd.h $abs_builddir/$SAPI_STATIC $THTTPD/;\ - $patch" - PHP_THTTPD="yes, using $THTTPD" - PHP_ADD_INCLUDE($THTTPD) - PHP_SELECT_SAPI(thttpd, static) -fi -AC_MSG_RESULT($PHP_THTTPD) diff --git a/sapi/thttpd/php.sym b/sapi/thttpd/php.sym deleted file mode 100644 index 2214d3964dc12..0000000000000 --- a/sapi/thttpd/php.sym +++ /dev/null @@ -1,3 +0,0 @@ -thttpd_php_request -thttpd_php_init -thttpd_php_shutdown diff --git a/sapi/thttpd/php_thttpd.h b/sapi/thttpd/php_thttpd.h deleted file mode 100644 index ace252a356c6a..0000000000000 --- a/sapi/thttpd/php_thttpd.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_THTTPD_H -#define PHP_THTTPD_H - -#include -#include -#include - -void thttpd_php_shutdown(void); -void thttpd_php_init(void); -off_t thttpd_php_request(httpd_conn *hc, int show_source); - -void thttpd_register_on_close(void (*)(int)); -void thttpd_closed_conn(int fd); -int thttpd_get_fd(void); -void thttpd_set_dont_close(void); - -#endif diff --git a/sapi/thttpd/stub.c b/sapi/thttpd/stub.c deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c deleted file mode 100644 index ad4e8e366ef9e..0000000000000 --- a/sapi/thttpd/thttpd.c +++ /dev/null @@ -1,766 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_thttpd.h" -#include "php_variables.h" -#include "version.h" -#include "php_ini.h" -#include "zend_highlight.h" - -#include "zend_smart_str.h" - -#include -#include -#include -#include -#include - -#ifdef HAVE_GETNAMEINFO -#include -#include -#endif - -typedef struct { - httpd_conn *hc; - void (*on_close)(int); - - size_t unconsumed_length; - smart_str sbuf; - int seen_cl; - int seen_cn; -} php_thttpd_globals; - -#define PHP_SYS_CALL(x) do { x } while (n == -1 && errno == EINTR) - -#ifdef PREMIUM_THTTPD -# define do_keep_alive persistent -#endif - -#ifdef ZTS -static int thttpd_globals_id; -#define TG(v) TSRMG(thttpd_globals_id, php_thttpd_globals *, v) -#else -static php_thttpd_globals thttpd_globals; -#define TG(v) (thttpd_globals.v) -#endif - -static int sapi_thttpd_ub_write(const char *str, uint str_length) -{ - int n; - uint sent = 0; - - if (TG(sbuf).c != 0) { - smart_str_appendl_ex(&TG(sbuf), str, str_length, 1); - return str_length; - } - - while (str_length > 0) { - PHP_SYS_CALL(n = send(TG(hc)->conn_fd, str, str_length, 0);); - - if (n == -1) { - if (errno == EAGAIN) { - smart_str_appendl_ex(&TG(sbuf), str, str_length, 1); - - return sent + str_length; - } else - php_handle_aborted_connection(); - } - - TG(hc)->bytes_sent += n; - str += n; - sent += n; - str_length -= n; - } - - return sent; -} - -#define COMBINE_HEADERS 64 - -#if defined(IOV_MAX) -# if IOV_MAX - 64 <= 0 -# define SERIALIZE_HEADERS -# endif -#endif - -static int do_writev(struct iovec *vec, int nvec, int len) -{ - int n; - - assert(nvec <= IOV_MAX); - - if (TG(sbuf).c == 0) { - PHP_SYS_CALL(n = writev(TG(hc)->conn_fd, vec, nvec);); - - if (n == -1) { - if (errno == EAGAIN) { - n = 0; - } else { - php_handle_aborted_connection(); - } - } - - - TG(hc)->bytes_sent += n; - } else { - n = 0; - } - - if (n < len) { - int i; - - /* merge all unwritten data into sbuf */ - for (i = 0; i < nvec; vec++, i++) { - /* has this vector been written completely? */ - if (n >= vec->iov_len) { - /* yes, proceed */ - n -= vec->iov_len; - continue; - } - - if (n > 0) { - /* adjust vector */ - vec->iov_base = (char *) vec->iov_base + n; - vec->iov_len -= n; - n = 0; - } - - smart_str_appendl_ex(&TG(sbuf), vec->iov_base, vec->iov_len, 1); - } - } - - return 0; -} - -#ifdef SERIALIZE_HEADERS -# define ADD_VEC(str,l) smart_str_appendl(&vec_str, (str), (l)) -# define VEC_BASE() smart_str vec_str = {0} -# define VEC_FREE() smart_str_free(&vec_str) -#else -# define ADD_VEC(str,l) vec[n].iov_base=str;len += (vec[n].iov_len=l); n++ -# define VEC_BASE() struct iovec vec[COMBINE_HEADERS] -# define VEC_FREE() do {} while (0) -#endif - -#define ADD_VEC_S(str) ADD_VEC((str), sizeof(str)-1) - -#define CL_TOKEN "Content-length: " -#define CN_TOKEN "Connection: " -#define KA_DO "Connection: keep-alive\r\n" -#define KA_NO "Connection: close\r\n" -#define DEF_CT "Content-Type: text/html\r\n" - -static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers) -{ - char buf[1024], *p; - VEC_BASE(); - int n = 0; - zend_llist_position pos; - sapi_header_struct *h; - size_t len = 0; - - if (!SG(sapi_headers).http_status_line) { - ADD_VEC_S("HTTP/1.1 "); - p = zend_print_long_to_buf(buf+sizeof(buf)-1, - SG(sapi_headers).http_response_code); - ADD_VEC(p, strlen(p)); - ADD_VEC_S(" HTTP\r\n"); - } else { - ADD_VEC(SG(sapi_headers).http_status_line, - strlen(SG(sapi_headers).http_status_line)); - ADD_VEC("\r\n", 2); - } - TG(hc)->status = SG(sapi_headers).http_response_code; - - if (SG(sapi_headers).send_default_content_type) { - ADD_VEC(DEF_CT, strlen(DEF_CT)); - } - - h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); - while (h) { - - switch (h->header[0]) { - case 'c': case 'C': - if (!TG(seen_cl) && strncasecmp(h->header, CL_TOKEN, sizeof(CL_TOKEN)-1) == 0) { - TG(seen_cl) = 1; - } else if (!TG(seen_cn) && strncasecmp(h->header, CN_TOKEN, sizeof(CN_TOKEN)-1) == 0) { - TG(seen_cn) = 1; - } - } - - ADD_VEC(h->header, h->header_len); -#ifndef SERIALIZE_HEADERS - if (n >= COMBINE_HEADERS - 1) { - len = do_writev(vec, n, len); - n = 0; - } -#endif - ADD_VEC("\r\n", 2); - - h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); - } - - if (TG(seen_cl) && !TG(seen_cn) && TG(hc)->do_keep_alive) { - ADD_VEC(KA_DO, sizeof(KA_DO)-1); - } else { - TG(hc)->do_keep_alive = 0; - ADD_VEC(KA_NO, sizeof(KA_NO)-1); - } - - ADD_VEC("\r\n", 2); - -#ifdef SERIALIZE_HEADERS - sapi_thttpd_ub_write(vec_str.c, vec_str.len); -#else - do_writev(vec, n, len); -#endif - - VEC_FREE(); - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -/* to understand this, read cgi_interpose_input() in libhttpd.c */ -#define SIZEOF_UNCONSUMED_BYTES() (TG(hc)->read_idx - TG(hc)->checked_idx) -#define CONSUME_BYTES(n) do { TG(hc)->checked_idx += (n); } while (0) - - -static int sapi_thttpd_read_post(char *buffer, uint count_bytes) -{ - size_t read_bytes = 0; - - if (TG(unconsumed_length) > 0) { - read_bytes = MIN(TG(unconsumed_length), count_bytes); - memcpy(buffer, TG(hc)->read_buf + TG(hc)->checked_idx, read_bytes); - TG(unconsumed_length) -= read_bytes; - CONSUME_BYTES(read_bytes); - } - - return read_bytes; -} - -static char *sapi_thttpd_read_cookies(void) -{ - return TG(hc)->cookie; -} - -#define BUF_SIZE 512 -#define ADD_STRING_EX(name,buf) \ - php_register_variable(name, buf, track_vars_array) -#define ADD_STRING(name) ADD_STRING_EX((name), buf) - -static void sapi_thttpd_register_variables(zval *track_vars_array) -{ - char buf[BUF_SIZE + 1]; - char *p; - - php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array); - php_register_variable("SERVER_SOFTWARE", SERVER_SOFTWARE, track_vars_array); - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); - php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array); - php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array); - php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array); - - if (TG(hc)->one_one) { - php_register_variable("SERVER_PROTOCOL", "HTTP/1.1", track_vars_array); - } else { - php_register_variable("SERVER_PROTOCOL", "HTTP/1.0", track_vars_array); - } - - p = httpd_ntoa(&TG(hc)->client_addr); - - ADD_STRING_EX("REMOTE_ADDR", p); - ADD_STRING_EX("REMOTE_HOST", p); - - ADD_STRING_EX("SERVER_PORT", - zend_print_long_to_buf(buf + sizeof(buf) - 1, - TG(hc)->hs->port)); - - buf[0] = '/'; - memcpy(buf + 1, TG(hc)->pathinfo, strlen(TG(hc)->pathinfo) + 1); - ADD_STRING("PATH_INFO"); - - buf[0] = '/'; - memcpy(buf + 1, TG(hc)->origfilename, strlen(TG(hc)->origfilename) + 1); - ADD_STRING("SCRIPT_NAME"); - -#define CONDADD(name, field) \ - if (TG(hc)->field[0]) { \ - php_register_variable(#name, TG(hc)->field, track_vars_array); \ - } - - CONDADD(QUERY_STRING, query); - CONDADD(HTTP_HOST, hdrhost); - CONDADD(HTTP_REFERER, referer); - CONDADD(HTTP_USER_AGENT, useragent); - CONDADD(HTTP_ACCEPT, accept); - CONDADD(HTTP_ACCEPT_LANGUAGE, acceptl); - CONDADD(HTTP_ACCEPT_ENCODING, accepte); - CONDADD(HTTP_COOKIE, cookie); - CONDADD(CONTENT_TYPE, contenttype); - CONDADD(REMOTE_USER, remoteuser); - CONDADD(SERVER_PROTOCOL, protocol); - - if (TG(hc)->contentlength != -1) { - ADD_STRING_EX("CONTENT_LENGTH", - zend_print_long_to_buf(buf + sizeof(buf) - 1, - TG(hc)->contentlength)); - } - - if (TG(hc)->authorization[0]) - php_register_variable("AUTH_TYPE", "Basic", track_vars_array); -} - -static PHP_MINIT_FUNCTION(thttpd) -{ - return SUCCESS; -} - -static zend_module_entry php_thttpd_module = { - STANDARD_MODULE_HEADER, - "thttpd", - NULL, - PHP_MINIT(thttpd), - NULL, - NULL, - NULL, - NULL, /* info */ - NULL, - STANDARD_MODULE_PROPERTIES -}; - -static int php_thttpd_startup(sapi_module_struct *sapi_module) -{ -#if PHP_API_VERSION >= 20020918 - if (php_module_startup(sapi_module, &php_thttpd_module, 1) == FAILURE) { -#else - /* No here to zend_startup_module() as 5.6 and older does not have that parameter */ - if (php_module_startup(sapi_module) == FAILURE - || zend_startup_module(&php_thttpd_module) == FAILURE) { -#endif - return FAILURE; - } - return SUCCESS; -} - -static int sapi_thttpd_get_fd(int *nfd) -{ - if (nfd) *nfd = TG(hc)->conn_fd; - return SUCCESS; -} - -static sapi_module_struct thttpd_sapi_module = { - "thttpd", - "thttpd", - - php_thttpd_startup, - php_module_shutdown_wrapper, - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_thttpd_ub_write, - NULL, - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, - - NULL, - sapi_thttpd_send_headers, - NULL, - sapi_thttpd_read_post, - sapi_thttpd_read_cookies, - - sapi_thttpd_register_variables, - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - NULL, /* php.ini path override */ - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - NULL, - NULL, - NULL, - 0, - sapi_thttpd_get_fd -}; - -static void thttpd_module_main(int show_source) -{ - zend_file_handle file_handle; - - if (php_request_startup() == FAILURE) { - return; - } - - if (show_source) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - php_get_highlight_struct(&syntax_highlighter_ini); - highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini); - } else { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - php_execute_script(&file_handle); - } - - php_request_shutdown(NULL); -} - -static void thttpd_request_ctor(void) -{ - smart_str s = {0}; - - TG(seen_cl) = 0; - TG(seen_cn) = 0; - TG(sbuf).c = 0; - SG(request_info).query_string = TG(hc)->query?strdup(TG(hc)->query):NULL; - - smart_str_appends_ex(&s, TG(hc)->hs->cwd, 1); - smart_str_appends_ex(&s, TG(hc)->expnfilename, 1); - smart_str_0(&s); - SG(request_info).path_translated = s.c; - - s.c = NULL; - smart_str_appendc_ex(&s, '/', 1); - smart_str_appends_ex(&s, TG(hc)->origfilename, 1); - smart_str_0(&s); - SG(request_info).request_uri = s.c; - SG(request_info).request_method = httpd_method_str(TG(hc)->method); - if (TG(hc)->one_one) SG(request_info).proto_num = 1001; - else SG(request_info).proto_num = 1000; - SG(sapi_headers).http_response_code = 200; - if (TG(hc)->contenttype) - SG(request_info).content_type = strdup(TG(hc)->contenttype); - SG(request_info).content_length = TG(hc)->contentlength == -1 ? 0 - : TG(hc)->contentlength; - - TG(unconsumed_length) = SG(request_info).content_length; - - php_handle_auth_data(TG(hc)->authorization); -} - -static void thttpd_request_dtor(void) -{ - smart_str_free(&TG(sbuf)); - if (SG(request_info).query_string) - free(SG(request_info).query_string); - free(SG(request_info).request_uri); - free(SG(request_info).path_translated); - if (SG(request_info).content_type) - free(SG(request_info).content_type); -} - -#ifdef ZTS - -#ifdef TSRM_ST -#define thread_create_simple_detached(n) st_thread_create(n, NULL, 0, 0) -#define thread_usleep(n) st_usleep(n) -#define thread_exit() st_thread_exit(NULL) -/* No preemption, simple operations are safe */ -#define thread_atomic_inc(n) (++n) -#define thread_atomic_dec(n) (--n) -#else -#error No thread primitives available -#endif - -/* We might want to replace this with a STAILQ */ -typedef struct qreq { - httpd_conn *hc; - struct qreq *next; -} qreq_t; - -static MUTEX_T qr_lock; -static qreq_t *queued_requests; -static qreq_t *last_qr; -static int nr_free_threads; -static int nr_threads; -static int max_threads = 50; - -#define HANDLE_STRINGS() { \ - HANDLE_STR(encodedurl); \ - HANDLE_STR(decodedurl); \ - HANDLE_STR(origfilename); \ - HANDLE_STR(expnfilename); \ - HANDLE_STR(pathinfo); \ - HANDLE_STR(query); \ - HANDLE_STR(referer); \ - HANDLE_STR(useragent); \ - HANDLE_STR(accept); \ - HANDLE_STR(accepte); \ - HANDLE_STR(acceptl); \ - HANDLE_STR(cookie); \ - HANDLE_STR(contenttype); \ - HANDLE_STR(authorization); \ - HANDLE_STR(remoteuser); \ - } - -static httpd_conn *duplicate_conn(httpd_conn *hc, httpd_conn *nhc) -{ - memcpy(nhc, hc, sizeof(*nhc)); - -#define HANDLE_STR(m) nhc->m = nhc->m ? strdup(nhc->m) : NULL - HANDLE_STRINGS(); -#undef HANDLE_STR - - return nhc; -} - -static void destroy_conn(httpd_conn *hc) -{ -#define HANDLE_STR(m) if (hc->m) free(hc->m) - HANDLE_STRINGS(); -#undef HANDLE_STR -} - -static httpd_conn *dequeue_request(void) -{ - httpd_conn *ret = NULL; - qreq_t *m; - - tsrm_mutex_lock(qr_lock); - if (queued_requests) { - m = queued_requests; - ret = m->hc; - if (!(queued_requests = m->next)) - last_qr = NULL; - free(m); - } - tsrm_mutex_unlock(qr_lock); - - return ret; -} - -static void *worker_thread(void *); - -static void queue_request(httpd_conn *hc) -{ - qreq_t *m; - httpd_conn *nhc; - - /* Mark as long-running request */ - hc->file_address = (char *) 1; - - /* - * We cannot synchronously revoke accesses to hc in the worker - * thread, so we need to pass a copy of hc to the worker thread. - */ - nhc = malloc(sizeof *nhc); - duplicate_conn(hc, nhc); - - /* Allocate request queue container */ - m = malloc(sizeof *m); - m->hc = nhc; - m->next = NULL; - - tsrm_mutex_lock(qr_lock); - /* Create new threads when reaching a certain threshold */ - if (nr_threads < max_threads && nr_free_threads < 2) { - nr_threads++; /* protected by qr_lock */ - - thread_atomic_inc(nr_free_threads); - thread_create_simple_detached(worker_thread); - } - /* Insert container into request queue */ - if (queued_requests) - last_qr->next = m; - else - queued_requests = m; - last_qr = m; - tsrm_mutex_unlock(qr_lock); -} - -static off_t thttpd_real_php_request(httpd_conn *hc, int); - -static void *worker_thread(void *dummy) -{ - int do_work = 50; - httpd_conn *hc; - - while (do_work) { - hc = dequeue_request(); - - if (!hc) { -/* do_work--; */ - thread_usleep(500000); - continue; - } -/* do_work = 50; */ - - thread_atomic_dec(nr_free_threads); - - thttpd_real_php_request(hc, 0); - shutdown(hc->conn_fd, 0); - destroy_conn(hc); - free(hc); - - thread_atomic_inc(nr_free_threads); - } - thread_atomic_dec(nr_free_threads); - thread_atomic_dec(nr_threads); - thread_exit(); -} - -static void remove_dead_conn(int fd) -{ - qreq_t *m, *prev = NULL; - - tsrm_mutex_lock(qr_lock); - m = queued_requests; - while (m) { - if (m->hc->conn_fd == fd) { - if (prev) - if (!(prev->next = m->next)) - last_qr = prev; - else - if (!(queued_requests = m->next)) - last_qr = NULL; - destroy_conn(m->hc); - free(m->hc); - free(m); - break; - } - prev = m; - m = m->next; - } - tsrm_mutex_unlock(qr_lock); -} - -#endif - -static off_t thttpd_real_php_request(httpd_conn *hc, int show_source) -{ - TG(hc) = hc; - hc->bytes_sent = 0; - - if (hc->contentlength != -1) { - hc->should_linger = 1; - hc->do_keep_alive = 0; - } - - if (hc->contentlength != -1 - && SIZEOF_UNCONSUMED_BYTES() < hc->contentlength) { - hc->read_body_into_mem = 1; - return 0; - } - - thttpd_request_ctor(); - - thttpd_module_main(show_source); - - /* disable kl, if no content-length was seen or Connection: was set */ - if (TG(seen_cl) == 0 || TG(seen_cn) == 1) { - TG(hc)->do_keep_alive = 0; - } - - if (TG(sbuf).c != 0) { - if (TG(hc)->response) - free(TG(hc)->response); - - TG(hc)->response = TG(sbuf).c; - TG(hc)->responselen = TG(sbuf).len; - TG(hc)->maxresponse = TG(sbuf).a; - - TG(sbuf).c = 0; - TG(sbuf).len = 0; - TG(sbuf).a = 0; - } - - thttpd_request_dtor(); - - return 0; -} - -off_t thttpd_php_request(httpd_conn *hc, int show_source) -{ -#ifdef ZTS - queue_request(hc); -#else - return thttpd_real_php_request(hc, show_source); -#endif -} - -void thttpd_register_on_close(void (*arg)(int)) -{ - TG(on_close) = arg; -} - -void thttpd_closed_conn(int fd) -{ - if (TG(on_close)) TG(on_close)(fd); -} - -int thttpd_get_fd(void) -{ - return TG(hc)->conn_fd; -} - -void thttpd_set_dont_close(void) -{ -#ifndef PREMIUM_THTTPD - TG(hc)->file_address = (char *) 1; -#endif -} - - -void thttpd_php_init(void) -{ - char *ini; - -#ifdef ZTS - tsrm_startup(1, 1, 0, NULL); - ts_allocate_id(&thttpd_globals_id, sizeof(php_thttpd_globals), NULL, NULL); - qr_lock = tsrm_mutex_alloc(); - thttpd_register_on_close(remove_dead_conn); -#endif - - if ((ini = getenv("PHP_INI_PATH"))) { - thttpd_sapi_module.php_ini_path_override = ini; - } - - sapi_startup(&thttpd_sapi_module); - thttpd_sapi_module.startup(&thttpd_sapi_module); - - { - - SG(server_context) = (void *) 1; - } -} - -void thttpd_php_shutdown(void) -{ - - if (SG(server_context) != NULL) { - thttpd_sapi_module.shutdown(&thttpd_sapi_module); - sapi_shutdown(); -#ifdef ZTS - tsrm_shutdown(); -#endif - } -} diff --git a/sapi/thttpd/thttpd_patch b/sapi/thttpd/thttpd_patch deleted file mode 100644 index 1463d8fe0a59e..0000000000000 --- a/sapi/thttpd/thttpd_patch +++ /dev/null @@ -1,2377 +0,0 @@ -diff -ur thttpd-2.21b/Makefile.in thttpd-2.21b-cool/Makefile.in ---- thttpd-2.21b/Makefile.in Thu Mar 29 20:36:21 2001 -+++ thttpd-2.21b-cool/Makefile.in Sat Sep 20 14:43:20 2003 -@@ -46,13 +46,15 @@ - - # You shouldn't need to edit anything below here. - -+include php_makefile -+ - CC = @CC@ - CCOPT = @V_CCOPT@ - DEFS = @DEFS@ --INCLS = -I. -+INCLS = -I. $(PHP_CFLAGS) - CFLAGS = $(CCOPT) $(DEFS) $(INCLS) --LDFLAGS = @LDFLAGS@ --LIBS = @LIBS@ -+LDFLAGS = @LDFLAGS@ $(PHP_LDFLAGS) -+LIBS = @LIBS@ $(PHP_LIBS) - NETLIBS = @V_NETLIBS@ - INSTALL = @INSTALL@ - -@@ -62,7 +64,7 @@ - @rm -f $@ - $(CC) $(CFLAGS) -c $*.c - --SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c -+SRC = thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c php_thttpd.c - - OBJ = $(SRC:.c=.o) @LIBOBJS@ - -@@ -77,7 +79,7 @@ - all: this subdirs - this: $(ALL) - --thttpd: $(OBJ) -+thttpd: $(OBJ) libphp7.a - @rm -f $@ - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(NETLIBS) - -diff -ur thttpd-2.21b/config.h thttpd-2.21b-cool/config.h ---- thttpd-2.21b/config.h Mon Apr 9 23:57:36 2001 -+++ thttpd-2.21b-cool/config.h Sat Sep 20 14:43:20 2003 -@@ -82,6 +82,11 @@ - */ - #define IDLE_READ_TIMELIMIT 60 - -+/* CONFIGURE: How many seconds to allow for reading the subsequent requests -+** on a keep-alive connection. Should be simiar to LINGER_TIME -+*/ -+#define IDLE_KEEPALIVE_TIMELIMIT 2 -+ - /* CONFIGURE: How many seconds before an idle connection gets closed. - */ - #define IDLE_SEND_TIMELIMIT 300 -@@ -316,7 +321,7 @@ - /* CONFIGURE: A list of index filenames to check. The files are searched - ** for in this order. - */ --#define INDEX_NAMES "index.html", "index.htm", "Default.htm", "index.cgi" -+#define INDEX_NAMES "index.php", "index.html", "index.htm", "Default.htm", "index.cgi" - - /* CONFIGURE: If this is defined then thttpd will automatically generate - ** index pages for directories that don't have an explicit index file. -diff -ur thttpd-2.21b/configure thttpd-2.21b-cool/configure ---- thttpd-2.21b/configure Sat Apr 21 02:07:14 2001 -+++ thttpd-2.21b-cool/configure Sat Sep 20 14:43:20 2003 -@@ -1021,7 +1021,7 @@ - fi - echo "$ac_t""$CPP" 1>&6 - --for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h -+for ac_hdr in fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h - do - ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` - echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -diff -ur thttpd-2.21b/configure.in thttpd-2.21b-cool/configure.in ---- thttpd-2.21b/configure.in Sat Apr 21 02:06:23 2001 -+++ thttpd-2.21b-cool/configure.in Sat Sep 20 14:43:20 2003 -@@ -64,7 +64,7 @@ - AC_MSG_RESULT(no) - fi - --AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h) -+AC_CHECK_HEADERS(fcntl.h grp.h memory.h paths.h poll.h sys/poll.h sys/event.h osreldate.h netinet/tcp.h) - AC_HEADER_TIME - AC_HEADER_DIRENT - -diff -ur thttpd-2.21b/fdwatch.c thttpd-2.21b-cool/fdwatch.c ---- thttpd-2.21b/fdwatch.c Fri Apr 13 07:36:08 2001 -+++ thttpd-2.21b-cool/fdwatch.c Sat Sep 20 14:43:20 2003 -@@ -419,6 +419,7 @@ - if ( pollfds == (struct pollfd*) 0 || poll_fdidx == (int*) 0 || - poll_rfdidx == (int*) 0 ) - return -1; -+ memset(pollfds, 0, sizeof(struct pollfd) * nfiles); - return 0; - } - -@@ -460,7 +461,7 @@ - - ridx = 0; - for ( i = 0; i < npollfds; ++i ) -- if ( pollfds[i].revents & ( POLLIN | POLLOUT ) ) -+ if ( pollfds[i].revents & ( POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL ) ) - poll_rfdidx[ridx++] = pollfds[i].fd; - - return r; -@@ -472,8 +473,8 @@ - { - switch ( fd_rw[fd] ) - { -- case FDW_READ: return pollfds[poll_fdidx[fd]].revents & POLLIN; -- case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & POLLOUT; -+ case FDW_READ: return pollfds[poll_fdidx[fd]].revents & ( POLLIN | POLLERR | POLLHUP | POLLNVAL ); -+ case FDW_WRITE: return pollfds[poll_fdidx[fd]].revents & ( POLLOUT | POLLERR | POLLHUP | POLLNVAL ); - default: return 0; - } - } -diff -ur thttpd-2.21b/libhttpd.c thttpd-2.21b-cool/libhttpd.c ---- thttpd-2.21b/libhttpd.c Tue Apr 24 00:42:40 2001 -+++ thttpd-2.21b-cool/libhttpd.c Sat Sep 20 14:43:29 2003 -@@ -56,6 +56,10 @@ - #include - #include - -+#ifdef HAVE_NETINET_TCP_H -+#include -+#endif -+ - #ifdef HAVE_OSRELDATE_H - #include - #endif /* HAVE_OSRELDATE_H */ -@@ -85,6 +89,12 @@ - #include "match.h" - #include "tdate_parse.h" - -+#include "php_thttpd.h" -+ -+#ifdef __CYGWIN__ -+# define timezone _timezone -+#endif -+ - #ifndef STDIN_FILENO - #define STDIN_FILENO 0 - #endif -@@ -111,7 +121,7 @@ - static int initialize_listen_socket( httpd_sockaddr* saP ); - static void unlisten( httpd_server* hs ); - static void add_response( httpd_conn* hc, char* str ); --static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod ); -+static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod, const char *, size_t ); - static void send_response( httpd_conn* hc, int status, char* title, char* extraheads, char* form, char* arg ); - static void send_response_tail( httpd_conn* hc ); - static void defang( char* str, char* dfstr, int dfsize ); -@@ -242,6 +252,10 @@ - free( (void*) hs->cwd ); - if ( hs->cgi_pattern != (char*) 0 ) - free( (void*) hs->cgi_pattern ); -+ if ( hs->php_pattern != (char*) 0 ) -+ free( (void*) hs->php_pattern ); -+ if ( hs->phps_pattern != (char*) 0 ) -+ free( (void*) hs->phps_pattern ); - if ( hs->charset != (char*) 0 ) - free( (void*) hs->charset ); - if ( hs->url_pattern != (char*) 0 ) -@@ -249,6 +263,7 @@ - if ( hs->local_pattern != (char*) 0 ) - free( (void*) hs->local_pattern ); - free( (void*) hs ); -+ thttpd_php_shutdown(); - } - - -@@ -257,7 +272,8 @@ - char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port, - char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp, - int no_symlink, int vhost, int global_passwd, char* url_pattern, -- char* local_pattern, int no_empty_referers ) -+ char* local_pattern, int no_empty_referers, char* php_pattern, -+ char* phps_pattern ) - { - httpd_server* hs; - static char ghnbuf[256]; -@@ -312,6 +328,8 @@ - } - - hs->port = port; -+ hs->php_pattern = strdup(php_pattern); -+ hs->phps_pattern = strdup(phps_pattern); - if ( cgi_pattern == (char*) 0 ) - hs->cgi_pattern = (char*) 0; - else -@@ -329,7 +347,7 @@ - while ( ( cp = strstr( hs->cgi_pattern, "|/" ) ) != (char*) 0 ) - (void) strcpy( cp + 1, cp + 2 ); - } -- hs->charset = strdup( charset ); -+ hs->charset = strdup( charset ); - hs->cwd = strdup( cwd ); - if ( hs->cwd == (char*) 0 ) - { -@@ -385,6 +403,8 @@ - return (httpd_server*) 0; - } - -+ thttpd_php_init(); -+ - /* Done initializing. */ - if ( hs->binding_hostname == (char*) 0 ) - syslog( LOG_INFO, "%.80s starting on port %d", SERVER_SOFTWARE, hs->port ); -@@ -418,6 +438,11 @@ - } - (void) fcntl( listen_fd, F_SETFD, 1 ); - -+#if defined(TCP_DEFER_ACCEPT) && defined(SOL_TCP) -+ on = 30; /* give clients 30s to send first data packet */ -+ setsockopt(listen_fd, SOL_TCP, TCP_DEFER_ACCEPT, &on, sizeof(on)); -+#endif -+ - /* Allow reuse of local addresses. */ - on = 1; - if ( setsockopt( -@@ -582,6 +607,9 @@ - /* And send it, if necessary. */ - if ( hc->responselen > 0 ) - { -+/* -+printf("**RESPONSE [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->responselen, hc->response); -+*/ - (void) write( hc->conn_fd, hc->response, hc->responselen ); - hc->responselen = 0; - } -@@ -619,18 +647,22 @@ - } - } - -+extern time_t httpd_time_now; -+extern char httpd_now_buf[]; -+ -+#define SMART_STR_USE_REALLOC -+ -+#include "zend_smart_str.h" - - static void --send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod ) -+send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type, int length, time_t mod, const char *last_modified, size_t last_modified_len) - { -- time_t now; - const char* rfc1123fmt = "%a, %d %b %Y %H:%M:%S GMT"; -- char nowbuf[100]; - char modbuf[100]; -- char fixed_type[500]; -- char buf[1000]; - int partial_content; -- -+ smart_str s = {0}; -+ int type_len; -+ - hc->status = status; - hc->bytes_to_send = length; - if ( hc->mime_flag ) -@@ -649,41 +681,89 @@ - else - partial_content = 0; - -- now = time( (time_t*) 0 ); - if ( mod == (time_t) 0 ) -- mod = now; -- (void) strftime( nowbuf, sizeof(nowbuf), rfc1123fmt, gmtime( &now ) ); -- (void) strftime( modbuf, sizeof(modbuf), rfc1123fmt, gmtime( &mod ) ); -- (void) my_snprintf( -- fixed_type, sizeof(fixed_type), type, hc->hs->charset ); -- (void) my_snprintf( buf, sizeof(buf), -- "%.20s %d %s\r\nServer: %s\r\nContent-Type: %s\r\nDate: %s\r\nLast-Modified: %s\r\nAccept-Ranges: bytes\r\nConnection: close\r\n", -- hc->protocol, status, title, EXPOSED_SERVER_SOFTWARE, fixed_type, -- nowbuf, modbuf ); -- add_response( hc, buf ); -+ mod = httpd_time_now; -+ -+ if (last_modified == 0) { -+ (void) strftime( modbuf, sizeof(modbuf), rfc1123fmt, gmtime( &mod ) ); -+ last_modified = modbuf; -+ last_modified_len = strlen(modbuf); -+ } -+ -+ type_len = strlen(type); -+ -+ if (hc->response) { -+ s.c = hc->response; -+ s.len = 0; -+ s.a = hc->maxresponse; -+ hc->response = 0; -+ hc->maxresponse = 0; -+ } -+ -+ smart_str_appends(&s, "HTTP/1.1 "); -+ smart_str_append_long(&s, status); -+ smart_str_appends(&s, " HTTP\r\nServer: " EXPOSED_SERVER_SOFTWARE "\r\n" -+ "Content-Type: "); -+ -+ if (type[type_len-2] == '%' && type[type_len-1] == 's') { -+ smart_str_appendl(&s, type, type_len - 2); -+ smart_str_appends(&s, hc->hs->charset); -+ } else { -+ smart_str_appendl(&s, type, type_len); -+ } -+ -+ -+ smart_str_appends(&s, "\r\nDate: "); -+ smart_str_appends(&s, httpd_now_buf); -+ smart_str_appends(&s, "\r\nLast-Modified: "); -+ smart_str_appendl(&s, last_modified, last_modified_len); -+ smart_str_appends(&s, "\r\nAccept-Ranges: bytes\r\n"); -+ - if ( encodings[0] != '\0' ) - { -- (void) my_snprintf( buf, sizeof(buf), -- "Content-Encoding: %s\r\n", encodings ); -- add_response( hc, buf ); -+ smart_str_appends(&s, "Content-Encoding: "); -+ smart_str_appends(&s, encodings); -+ smart_str_appends(&s, "\r\n"); - } - if ( partial_content ) - { -- (void) my_snprintf( buf, sizeof(buf), -- "Content-Range: bytes %ld-%ld/%d\r\nContent-Length: %ld\r\n", -- (long) hc->init_byte_loc, (long) hc->end_byte_loc, length, -- (long) ( hc->end_byte_loc - hc->init_byte_loc + 1 ) ); -- add_response( hc, buf ); -+ -+ smart_str_appends(&s, "Content-Range: bytes "); -+ smart_str_append_long(&s, hc->init_byte_loc); -+ smart_str_appendc(&s, '-'); -+ smart_str_append_long(&s, hc->end_byte_loc); -+ smart_str_appendc(&s, '/'); -+ smart_str_append_long(&s, length); -+ smart_str_appends(&s, "\r\nContent-Length: "); -+ smart_str_append_long(&s, hc->end_byte_loc - hc->init_byte_loc + 1); -+ smart_str_appends(&s, "\r\n"); -+ - } - else if ( length >= 0 ) - { -- (void) my_snprintf( buf, sizeof(buf), -- "Content-Length: %d\r\n", length ); -- add_response( hc, buf ); -+ smart_str_appends(&s, "Content-Length: "); -+ smart_str_append_long(&s, length); -+ smart_str_appends(&s, "\r\n"); - } -+ else { -+ hc->do_keep_alive = 0; -+ } - if ( extraheads[0] != '\0' ) -- add_response( hc, extraheads ); -- add_response( hc, "\r\n" ); -+ smart_str_appends(&s, extraheads); -+ if (hc->do_keep_alive) { -+ smart_str_appends(&s, "Connection: keep-alive\r\n\r\n" ); -+ } else { -+ smart_str_appends(&s, "Connection: close\r\n\r\n" ); -+ } -+ smart_str_0(&s); -+ -+ if (hc->response) { -+ free(hc->response); -+ } -+ hc->response = s.c; -+ hc->maxresponse = s.a; -+ hc->responselen = s.len; -+ - } - } - -@@ -725,7 +805,7 @@ - { - char defanged_arg[1000], buf[2000]; - -- send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 ); -+ send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 ); - (void) my_snprintf( buf, sizeof(buf), - "%d %s\n

%d %s

\n", - status, title, status, title ); -@@ -764,7 +844,7 @@ - char* cp2; - - for ( cp1 = str, cp2 = dfstr; -- *cp1 != '\0' && cp2 - dfstr < dfsize - 1; -+ *cp1 != '\0' && cp2 - dfstr < dfsize - 5; - ++cp1, ++cp2 ) - { - switch ( *cp1 ) -@@ -834,7 +914,7 @@ - fp = fopen( filename, "r" ); - if ( fp == (FILE*) 0 ) - return 0; -- send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 ); -+ send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 ); - for (;;) - { - r = fread( buf, 1, sizeof(buf) - 1, fp ); -@@ -1336,6 +1416,9 @@ - if ( hc->tildemapped ) - return 1; - -+ if ( hc->hostname[0] == '.' || strchr( hc->hostname, '/' ) != (char*) 0 ) -+ return 0; -+ - /* Figure out the host directory. */ - #ifdef VHOST_DIRLEVELS - httpd_realloc_str( -@@ -1436,7 +1519,7 @@ - restlen = strlen( path ); - httpd_realloc_str( &rest, &maxrest, restlen ); - (void) strcpy( rest, path ); -- if ( rest[restlen - 1] == '/' ) -+ if ( restlen > 0 && rest[restlen - 1] == '/' ) - rest[--restlen] = '\0'; /* trim trailing slash */ - if ( ! tildemapped ) - /* Remove any leading slashes. */ -@@ -1603,6 +1686,70 @@ - - - int -+httpd_request_reset(httpd_conn* hc, int preserve_read_buf ) -+{ -+ if (!preserve_read_buf) { -+ hc->read_idx = 0; -+ hc->checked_idx = 0; -+ } -+ -+ if (hc->read_buf_is_mmap) { -+ hc->read_buf_is_mmap = 0; -+ munmap(hc->read_buf, hc->read_size); -+ hc->read_buf = NULL; -+ hc->read_size = 0; -+ httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 ); -+ } -+ hc->checked_state = CHST_FIRSTWORD; -+ hc->method = METHOD_UNKNOWN; -+ hc->status = 0; -+ hc->bytes_to_send = 0; -+ hc->bytes_sent = 0; -+ hc->encodedurl = ""; -+ hc->decodedurl[0] = '\0'; -+ hc->protocol = "UNKNOWN"; -+ hc->origfilename[0] = '\0'; -+ hc->expnfilename[0] = '\0'; -+ hc->encodings[0] = '\0'; -+ hc->pathinfo[0] = '\0'; -+ hc->query[0] = '\0'; -+ hc->referer = ""; -+ hc->useragent = ""; -+ hc->accept[0] = '\0'; -+ hc->accepte[0] = '\0'; -+ hc->acceptl = ""; -+ hc->cookie = ""; -+ hc->contenttype = ""; -+ hc->reqhost[0] = '\0'; -+ hc->hdrhost = ""; -+ hc->hostdir[0] = '\0'; -+ hc->authorization = ""; -+ hc->remoteuser[0] = '\0'; -+ hc->response[0] = '\0'; -+#ifdef TILDE_MAP_2 -+ hc->altdir[0] = '\0'; -+#endif /* TILDE_MAP_2 */ -+ hc->responselen = 0; -+ hc->if_modified_since = (time_t) -1; -+ hc->range_if = (time_t) -1; -+ hc->contentlength = -1; -+ hc->type = ""; -+ hc->hostname = (char*) 0; -+ hc->mime_flag = 1; -+ hc->one_one = 0; -+ hc->got_range = 0; -+ hc->tildemapped = 0; -+ hc->init_byte_loc = 0; -+ hc->end_byte_loc = -1; -+ hc->keep_alive = 0; -+ hc->do_keep_alive = 0; -+ hc->should_linger = 0; -+ hc->file_address = (char*) 0; -+ hc->read_body_into_mem = 0; -+ return GC_OK; -+} -+ -+int - httpd_get_conn( httpd_server* hs, int listen_fd, httpd_conn* hc ) - { - httpd_sockaddr sa; -@@ -1612,6 +1759,7 @@ - { - hc->read_size = 0; - httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 ); -+ hc->read_buf_is_mmap = 0; - hc->maxdecodedurl = - hc->maxorigfilename = hc->maxexpnfilename = hc->maxencodings = - hc->maxpathinfo = hc->maxquery = hc->maxaccept = -@@ -1631,12 +1779,19 @@ - httpd_realloc_str( &hc->reqhost, &hc->maxreqhost, 0 ); - httpd_realloc_str( &hc->hostdir, &hc->maxhostdir, 0 ); - httpd_realloc_str( &hc->remoteuser, &hc->maxremoteuser, 0 ); -- httpd_realloc_str( &hc->response, &hc->maxresponse, 0 ); -+ httpd_realloc_str( &hc->response, &hc->maxresponse, 350 ); - #ifdef TILDE_MAP_2 - httpd_realloc_str( &hc->altdir, &hc->maxaltdir, 0 ); - #endif /* TILDE_MAP_2 */ - hc->initialized = 1; - } -+ if (hc->read_buf_is_mmap) { -+ hc->read_buf_is_mmap = 0; -+ munmap(hc->read_buf, hc->read_size); -+ hc->read_buf = NULL; -+ hc->read_size = 0; -+ httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 ); -+ } - - /* Accept the new connection. */ - sz = sizeof(sa); -@@ -1657,53 +1812,12 @@ - hc->hs = hs; - memset( &hc->client_addr, 0, sizeof(hc->client_addr) ); - memcpy( &hc->client_addr, &sa, sockaddr_len( &sa ) ); -- hc->read_idx = 0; -- hc->checked_idx = 0; -- hc->checked_state = CHST_FIRSTWORD; -- hc->method = METHOD_UNKNOWN; -- hc->status = 0; -- hc->bytes_to_send = 0; -- hc->bytes_sent = 0; -- hc->encodedurl = ""; -- hc->decodedurl[0] = '\0'; -- hc->protocol = "UNKNOWN"; -- hc->origfilename[0] = '\0'; -- hc->expnfilename[0] = '\0'; -- hc->encodings[0] = '\0'; -- hc->pathinfo[0] = '\0'; -- hc->query[0] = '\0'; -- hc->referer = ""; -- hc->useragent = ""; -- hc->accept[0] = '\0'; -- hc->accepte[0] = '\0'; -- hc->acceptl = ""; -- hc->cookie = ""; -- hc->contenttype = ""; -- hc->reqhost[0] = '\0'; -- hc->hdrhost = ""; -- hc->hostdir[0] = '\0'; -- hc->authorization = ""; -- hc->remoteuser[0] = '\0'; -- hc->response[0] = '\0'; --#ifdef TILDE_MAP_2 -- hc->altdir[0] = '\0'; --#endif /* TILDE_MAP_2 */ -- hc->responselen = 0; -- hc->if_modified_since = (time_t) -1; -- hc->range_if = (time_t) -1; -- hc->contentlength = -1; -- hc->type = ""; -- hc->hostname = (char*) 0; -- hc->mime_flag = 1; -- hc->one_one = 0; -- hc->got_range = 0; -- hc->tildemapped = 0; -- hc->init_byte_loc = 0; -- hc->end_byte_loc = -1; -- hc->keep_alive = 0; -- hc->should_linger = 0; -- hc->file_address = (char*) 0; -- return GC_OK; -+ -+/* -+printf("doing httpd_get_con(%d)\n", hc->conn_fd); -+*/ -+ -+ return httpd_request_reset(hc, 0); - } - - -@@ -1720,6 +1834,9 @@ - { - char c; - -+/* -+printf("**REQUEST [%d]**\n%*.*s\n", hc->conn_fd, hc->read_idx, hc->read_idx, hc->read_buf); -+*/ - for ( ; hc->checked_idx < hc->read_idx; ++hc->checked_idx ) - { - c = hc->read_buf[hc->checked_idx]; -@@ -1912,8 +2029,11 @@ - eol = strpbrk( protocol, " \t\n\r" ); - if ( eol != (char*) 0 ) - *eol = '\0'; -- if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 ) -+ if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 ) { - hc->one_one = 1; -+ hc->keep_alive = 1; -+ hc->do_keep_alive = 1; -+ } - } - } - /* Check for HTTP/1.1 absolute URL. */ -@@ -2129,6 +2249,7 @@ - cp = &buf[11]; - cp += strspn( cp, " \t" ); - if ( strcasecmp( cp, "keep-alive" ) == 0 ) -+ hc->do_keep_alive = 1; - hc->keep_alive = 1; - } - #ifdef LOG_UNKNOWN_HEADERS -@@ -2168,6 +2289,9 @@ - } - } - -+/* -+printf("one_one = %d keep_alive = %d\n", hc->one_one, hc->keep_alive); -+*/ - if ( hc->one_one ) - { - /* Check that HTTP/1.1 requests specify a host, as required. */ -@@ -2177,14 +2301,14 @@ - return -1; - } - -- /* If the client wants to do keep-alives, it might also be doing -- ** pipelining. There's no way for us to tell. Since we don't -- ** implement keep-alives yet, if we close such a connection there -- ** might be unread pipelined requests waiting. So, we have to -- ** do a lingering close. -+ /* -+ ** Disable keep alive support for bad browsers, -+ ** list taken from Apache 1.3.19 - */ -- if ( hc->keep_alive ) -- hc->should_linger = 1; -+ if ( hc->do_keep_alive && -+ ( strstr(hc->useragent, "Mozilla/2") != NULL || -+ strstr(hc->useragent, "MSIE 4.0b2;") != NULL)) -+ hc->do_keep_alive = 0; - } - - /* Ok, the request has been parsed. Now we resolve stuff that -@@ -2349,15 +2473,24 @@ - - - void --httpd_close_conn( httpd_conn* hc, struct timeval* nowP ) -- { -- make_log_entry( hc, nowP ); -+httpd_complete_request( httpd_conn* hc, struct timeval* nowP) -+{ -+ if (hc->method != METHOD_UNKNOWN) -+ make_log_entry( hc, nowP ); - -- if ( hc->file_address != (char*) 0 ) -+ if ( hc->file_address == (char*) 1 ) -+ { -+ thttpd_closed_conn(hc->conn_fd); -+ } else if ( hc->file_address != (char*) 0 ) - { - mmc_unmap( hc->file_address, &(hc->sb), nowP ); - hc->file_address = (char*) 0; - } -+ } -+ -+void -+httpd_close_conn( httpd_conn* hc, struct timeval* nowP ) -+{ - if ( hc->conn_fd >= 0 ) - { - (void) close( hc->conn_fd ); -@@ -2370,7 +2503,12 @@ - { - if ( hc->initialized ) - { -- free( (void*) hc->read_buf ); -+ -+ if ( hc->read_buf_is_mmap ) { -+ munmap( hc->read_buf, hc->read_size ); -+ } else { -+ free( (void*) hc->read_buf ); -+ } - free( (void*) hc->decodedurl ); - free( (void*) hc->origfilename ); - free( (void*) hc->expnfilename ); -@@ -2556,7 +2694,7 @@ - return -1; - } - -- send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime ); -+ send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime, 0, 0 ); - if ( hc->method == METHOD_HEAD ) - closedir( dirp ); - else if ( hc->method == METHOD_GET ) -@@ -3026,11 +3164,9 @@ - post_post_garbage_hack( httpd_conn* hc ) - { - char buf[2]; -- int r; - -- r = recv( hc->conn_fd, buf, sizeof(buf), MSG_PEEK ); -- if ( r > 0 ) -- (void) read( hc->conn_fd, buf, r ); -+ fcntl(hc->conn_fd, F_SETFL, O_NONBLOCK); -+ (void) read( hc->conn_fd, buf, 2 ); - } - - -@@ -3313,6 +3449,11 @@ - int r; - ClientData client_data; - -+ /* -+ ** We are not going to leave the socket open after a CGI... too hard -+ */ -+ hc->do_keep_alive = 0; -+ - if ( hc->method == METHOD_GET || hc->method == METHOD_POST ) - { - httpd_clear_ndelay( hc->conn_fd ); -@@ -3369,6 +3510,7 @@ - int expnlen, indxlen; - char* cp; - char* pi; -+ int nocache = 0; - - expnlen = strlen( hc->expnfilename ); - -@@ -3561,6 +3703,16 @@ - match( hc->hs->cgi_pattern, hc->expnfilename ) ) - return cgi( hc ); - -+ if ( hc->hs->php_pattern != (char*) 0 && -+ match( hc->hs->php_pattern, hc->expnfilename)) { -+ return thttpd_php_request( hc, 0 ); -+ } -+ -+ if ( hc->hs->phps_pattern != (char*) 0 && -+ match( hc->hs->phps_pattern, hc->expnfilename)) { -+ return thttpd_php_request( hc, 1 ); -+ } -+ - /* It's not CGI. If it's executable or there's pathinfo, someone's - ** trying to either serve or run a non-CGI file as CGI. Either case - ** is prohibited. -@@ -3594,32 +3746,46 @@ - hc->end_byte_loc = hc->sb.st_size - 1; - - figure_mime( hc ); -+ if ( strncmp(hc->decodedurl, "/nocache/", sizeof("/nocache/") - 1 ) == 0 ) -+ nocache = 1; - - if ( hc->method == METHOD_HEAD ) - { - send_mime( - hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size, -- hc->sb.st_mtime ); -+ hc->sb.st_mtime, 0, 0 ); - } -- else if ( hc->if_modified_since != (time_t) -1 && -+ else if ( !nocache && hc->if_modified_since != (time_t) -1 && - hc->if_modified_since >= hc->sb.st_mtime ) - { -- hc->method = METHOD_HEAD; - send_mime( -- hc, 304, err304title, hc->encodings, "", hc->type, hc->sb.st_size, -- hc->sb.st_mtime ); -+ hc, 304, err304title, hc->encodings, "", hc->type, -1, -+ hc->sb.st_mtime, 0, 0 ); - } - else - { -- hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP ); -+ char *extraheads = ""; -+ char *lm; -+ size_t lml; -+ -+ if ( nocache ) -+ { -+ extraheads = "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n" -+ "Cache-Control: no-store, no-cache, must-revalidate, " -+ "post-check=0, pre-check=0\r\n" -+ "Pragma: no-cache\r\n"; -+ } -+ -+ hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP, nocache, &lm, &lml ); - if ( hc->file_address == (char*) 0 ) - { - httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl ); - return -1; - } -+ - send_mime( -- hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size, -- hc->sb.st_mtime ); -+ hc, 200, ok200title, hc->encodings, extraheads, hc->type, hc->sb.st_size, -+ hc->sb.st_mtime, lm, lml ); - } - - return 0; -@@ -3638,6 +3804,9 @@ - return r; - } - -+#define smart_str_append_const(a,b) smart_str_appendl(a,b,sizeof(b)-1) -+ -+static smart_str bentries; - - static void - make_log_entry( httpd_conn* hc, struct timeval* nowP ) -@@ -3648,88 +3817,62 @@ - - if ( hc->hs->no_log ) - return; -- -- /* This is straight CERN Combined Log Format - the only tweak -- ** being that if we're using syslog() we leave out the date, because -- ** syslogd puts it in. The included syslogtocern script turns the -- ** results into true CERN format. -- */ -- - /* Format remote user. */ - if ( hc->remoteuser[0] != '\0' ) -- ru = hc->remoteuser; -+ ru = hc->remoteuser; - else -- ru = "-"; -+ ru = "-"; - /* If we're vhosting, prepend the hostname to the url. This is - ** a little weird, perhaps writing separate log files for - ** each vhost would make more sense. - */ -- if ( hc->hs->vhost && ! hc->tildemapped ) -- (void) my_snprintf( url, sizeof(url), -- "/%.100s%.200s", -- hc->hostname == (char*) 0 ? hc->hs->server_hostname : hc->hostname, -- hc->encodedurl ); -- else -- (void) my_snprintf( url, sizeof(url), -- "%.200s", hc->encodedurl ); -- /* Format the bytes. */ -- if ( (long) hc->bytes_sent >= 0 ) -- (void) my_snprintf( bytes, sizeof(bytes), -- "%ld", (long) hc->bytes_sent ); -- else -- (void) strcpy( bytes, "-" ); - - /* Logfile or syslog? */ - if ( hc->hs->logfp != (FILE*) 0 ) -- { -- time_t now; -- struct tm* t; -- const char* cernfmt_nozone = "%d/%b/%Y:%H:%M:%S"; -- char date_nozone[100]; -- int zone; -- char sign; -- char date[100]; -- -- /* Get the current time, if necessary. */ -- if ( nowP != (struct timeval*) 0 ) -- now = nowP->tv_sec; -- else -- now = time( (time_t*) 0 ); -- /* Format the time, forcing a numeric timezone (some log analyzers -- ** are stoooopid about this). -- */ -- t = localtime( &now ); -- (void) strftime( date_nozone, sizeof(date_nozone), cernfmt_nozone, t ); --#ifdef HAVE_TM_GMTOFF -- zone = t->tm_gmtoff / 60L; --#else -- zone = -timezone / 60L; -- /* Probably have to add something about daylight time here. */ --#endif -- if ( zone >= 0 ) -- sign = '+'; -- else -- { -- sign = '-'; -- zone = -zone; -- } -- zone = ( zone / 60 ) * 100 + zone % 60; -- (void) my_snprintf( date, sizeof(date), -- "%s %c%04d", date_nozone, sign, zone ); -- /* And write the log entry. */ -- (void) fprintf( hc->hs->logfp, -- "%.80s - %.80s [%s] \"%.80s %.300s %.80s\" %d %s \"%.200s\" \"%.80s\"\n", -- httpd_ntoa( &hc->client_addr ), ru, date, -- httpd_method_str( hc->method ), url, hc->protocol, -- hc->status, bytes, hc->referer, hc->useragent ); -- (void) fflush( hc->hs->logfp ); /* don't need to flush every time */ -- } -- else -- syslog( LOG_INFO, -- "%.80s - %.80s \"%.80s %.200s %.80s\" %d %s \"%.200s\" \"%.80s\"", -- httpd_ntoa( &hc->client_addr ), ru, -- httpd_method_str( hc->method ), url, hc->protocol, -- hc->status, bytes, hc->referer, hc->useragent ); -+ { -+ /* XXXXXXX */ -+ -+ smart_str_appends(&bentries, httpd_ntoa(&hc->client_addr)); -+ smart_str_append_const(&bentries, " - "); -+ smart_str_appends(&bentries, ru); -+ smart_str_append_const(&bentries, " ["); -+ smart_str_appendl(&bentries, hc->hs->log_date, hc->hs->log_date_len); -+ smart_str_append_const(&bentries, "] \""); -+ smart_str_appends(&bentries, httpd_method_str(hc->method)); -+ smart_str_appendc(&bentries, ' '); -+ -+ if (hc->hs->vhost && ! hc->tildemapped) { -+ smart_str_appendc(&bentries, '/'); -+ if (hc->hostname) -+ smart_str_appends(&bentries, hc->hostname); -+ else -+ smart_str_appends(&bentries, hc->hs->server_hostname); -+ } -+ smart_str_appends(&bentries, hc->encodedurl); -+ -+ smart_str_appendc(&bentries, ' '); -+ smart_str_appends(&bentries, hc->protocol); -+ smart_str_append_const(&bentries, "\" "); -+ smart_str_append_long(&bentries, hc->status); -+ if (hc->bytes_sent >= 0) { -+ smart_str_appendc(&bentries, ' '); -+ smart_str_append_long(&bentries, hc->bytes_sent); -+ smart_str_append_const(&bentries, " \""); -+ } else { -+ smart_str_append_const(&bentries, " - \""); -+ } -+ smart_str_appends(&bentries, hc->referer); -+ smart_str_append_const(&bentries, "\" \""); -+ smart_str_appends(&bentries, hc->useragent); -+ smart_str_append_const(&bentries, "\"\n"); -+ -+ if (bentries.len > 16384) { -+ int fd = fileno(hc->hs->logfp); -+ write(fd, bentries.c, bentries.len); -+ bentries.len = 0; -+ } -+ } -+ - } - - -@@ -3840,7 +3983,24 @@ - { - #ifdef HAVE_GETNAMEINFO - static char str[200]; -+ static smart_str httpd_ntoa_buf; -+ -+ if (saP->sa_in.sin_family == AF_INET) { -+ unsigned long n = ntohl(saP->sa_in.sin_addr.s_addr); - -+ httpd_ntoa_buf.len = 0; -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 24)); -+ smart_str_appendc(&httpd_ntoa_buf, '.'); -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 16) & 255); -+ smart_str_appendc(&httpd_ntoa_buf, '.'); -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 8) & 255); -+ smart_str_appendc(&httpd_ntoa_buf, '.'); -+ smart_str_append_long(&httpd_ntoa_buf, (n >> 0) & 255); -+ smart_str_0(&httpd_ntoa_buf); -+ -+ return httpd_ntoa_buf.c; -+ } -+ - if ( getnameinfo( &saP->sa, sockaddr_len( saP ), str, sizeof(str), 0, 0, NI_NUMERICHOST ) != 0 ) - { - str[0] = '?'; -diff -ur thttpd-2.21b/libhttpd.h thttpd-2.21b-cool/libhttpd.h ---- thttpd-2.21b/libhttpd.h Tue Apr 24 00:36:50 2001 -+++ thttpd-2.21b-cool/libhttpd.h Sat Sep 20 14:43:20 2003 -@@ -69,6 +69,8 @@ - char* server_hostname; - int port; - char* cgi_pattern; -+ char* php_pattern; -+ char* phps_pattern; - char* charset; - char* cwd; - int listen4_fd, listen6_fd; -@@ -80,6 +82,8 @@ - char* url_pattern; - char* local_pattern; - int no_empty_referers; -+ size_t log_date_len; -+ char log_date[100]; - } httpd_server; - - /* A connection. */ -@@ -88,6 +92,7 @@ - httpd_server* hs; - httpd_sockaddr client_addr; - char* read_buf; -+ char read_buf_is_mmap; - int read_size, read_idx, checked_idx; - int checked_state; - int method; -@@ -132,11 +137,12 @@ - int got_range; - int tildemapped; /* this connection got tilde-mapped */ - off_t init_byte_loc, end_byte_loc; -- int keep_alive; -+ int keep_alive, do_keep_alive; - int should_linger; - struct stat sb; - int conn_fd; - char* file_address; -+ char read_body_into_mem; - } httpd_conn; - - /* Methods. */ -@@ -168,7 +174,8 @@ - char* hostname, httpd_sockaddr* sa4P, httpd_sockaddr* sa6P, int port, - char* cgi_pattern, char* charset, char* cwd, int no_log, FILE* logfp, - int no_symlink, int vhost, int global_passwd, char* url_pattern, -- char* local_pattern, int no_empty_referers ); -+ char* local_pattern, int no_empty_referers, char* php_pattern, -+ char* phps_pattern ); - - /* Change the log file. */ - extern void httpd_set_logfp( httpd_server* hs, FILE* logfp ); -@@ -229,6 +236,8 @@ - ** If you don't have a current timeval handy just pass in 0. - */ - extern void httpd_close_conn( httpd_conn* hc, struct timeval* nowP ); -+void httpd_complete_request( httpd_conn* hc, struct timeval* nowP); -+int httpd_request_reset(httpd_conn* hc,int ); - - /* Call this to de-initialize a connection struct and *really* free the - ** mallocced strings. -diff -ur thttpd-2.21b/mime_encodings.txt thttpd-2.21b-cool/mime_encodings.txt ---- thttpd-2.21b/mime_encodings.txt Wed May 10 03:22:28 2000 -+++ thttpd-2.21b-cool/mime_encodings.txt Sat Sep 20 14:43:20 2003 -@@ -3,6 +3,6 @@ - # A list of file extensions followed by the corresponding MIME encoding. - # Extensions not found in the table proceed to the mime_types table. - --Z x-compress --gz x-gzip -+Z compress -+gz gzip - uu x-uuencode -diff -ur thttpd-2.21b/mime_types.txt thttpd-2.21b-cool/mime_types.txt ---- thttpd-2.21b/mime_types.txt Sat Apr 14 04:53:30 2001 -+++ thttpd-2.21b-cool/mime_types.txt Sat Sep 20 14:43:20 2003 -@@ -1,135 +1,138 @@ --# mime_types.txt --# --# A list of file extensions followed by the corresponding MIME type. --# Extensions not found in the table are returned as text/plain. -- --html text/html; charset=%s --htm text/html; charset=%s --txt text/plain; charset=%s --rtx text/richtext --etx text/x-setext --tsv text/tab-separated-values --css text/css --xml text/xml --dtd text/xml -- --gif image/gif --jpg image/jpeg --jpeg image/jpeg --jpe image/jpeg --jfif image/jpeg --tif image/tiff --tiff image/tiff --pbm image/x-portable-bitmap --pgm image/x-portable-graymap --ppm image/x-portable-pixmap --pnm image/x-portable-anymap --xbm image/x-xbitmap --xpm image/x-xpixmap --xwd image/x-xwindowdump --ief image/ief --png image/png -- --au audio/basic --snd audio/basic --aif audio/x-aiff --aiff audio/x-aiff --aifc audio/x-aiff --ra audio/x-pn-realaudio --ram audio/x-pn-realaudio --rm audio/x-pn-realaudio --rpm audio/x-pn-realaudio-plugin --wav audio/wav --mid audio/midi --midi audio/midi --kar audio/midi --mpga audio/mpeg --mp2 audio/mpeg --mp3 audio/mpeg -- --mpeg video/mpeg --mpg video/mpeg --mpe video/mpeg --qt video/quicktime --mov video/quicktime --avi video/x-msvideo --movie video/x-sgi-movie --mv video/x-sgi-movie --vx video/x-rad-screenplay -- --a application/octet-stream -+ez application/andrew-inset -+hqx application/mac-binhex40 -+cpt application/mac-compactpro -+doc application/msword - bin application/octet-stream -+dms application/octet-stream -+lha application/octet-stream -+lzh application/octet-stream - exe application/octet-stream --dump application/octet-stream --o application/octet-stream --class application/java --js application/x-javascript -+class application/octet-stream -+so application/octet-stream -+dll application/octet-stream -+oda application/oda -+pdf application/pdf - ai application/postscript - eps application/postscript - ps application/postscript --dir application/x-director -+smi application/smil -+smil application/smil -+mif application/vnd.mif -+xls application/vnd.ms-excel -+ppt application/vnd.ms-powerpoint -+wbxml application/vnd.wap.wbxml -+wmlc application/vnd.wap.wmlc -+wmlsc application/vnd.wap.wmlscriptc -+bcpio application/x-bcpio -+vcd application/x-cdlink -+pgn application/x-chess-pgn -+cpio application/x-cpio -+csh application/x-csh - dcr application/x-director -+dir application/x-director - dxr application/x-director --fgd application/x-director --aam application/x-authorware-map --aas application/x-authorware-seg --aab application/x-authorware-bin --fh4 image/x-freehand --fh7 image/x-freehand --fh5 image/x-freehand --fhc image/x-freehand --fh image/x-freehand --spl application/futuresplash --swf application/x-shockwave-flash - dvi application/x-dvi -+spl application/x-futuresplash - gtar application/x-gtar - hdf application/x-hdf --hqx application/mac-binhex40 --iv application/x-inventor -+js application/x-javascript -+skp application/x-koan -+skd application/x-koan -+skt application/x-koan -+skm application/x-koan - latex application/x-latex --man application/x-troff-man --me application/x-troff-me --mif application/x-mif --ms application/x-troff-ms --oda application/oda --pdf application/pdf --rtf application/rtf --bcpio application/x-bcpio --cpio application/x-cpio --sv4cpio application/x-sv4cpio --sv4crc application/x-sv4crc --sh application/x-shar -+nc application/x-netcdf -+cdf application/x-netcdf -+sh application/x-sh - shar application/x-shar -+swf application/x-shockwave-flash - sit application/x-stuffit -+sv4cpio application/x-sv4cpio -+sv4crc application/x-sv4crc - tar application/x-tar -+tcl application/x-tcl - tex application/x-tex --texi application/x-texinfo - texinfo application/x-texinfo -+texi application/x-texinfo -+t application/x-troff - tr application/x-troff - roff application/x-troff - man application/x-troff-man - me application/x-troff-me - ms application/x-troff-ms --zip application/x-zip-compressed --tsp application/dsptype --wsrc application/x-wais-source - ustar application/x-ustar --cdf application/x-netcdf --nc application/x-netcdf --doc application/msword --ppt application/powerpoint -- --crt application/x-x509-ca-cert --crl application/x-pkcs7-crl -- -+src application/x-wais-source -+xhtml application/xhtml+xml -+xht application/xhtml+xml -+zip application/zip -+au audio/basic -+snd audio/basic -+mid audio/midi -+midi audio/midi -+kar audio/midi -+mpga audio/mpeg -+mp2 audio/mpeg -+mp3 audio/mpeg -+aif audio/x-aiff -+aiff audio/x-aiff -+aifc audio/x-aiff -+m3u audio/x-mpegurl -+ram audio/x-pn-realaudio -+rm audio/x-pn-realaudio -+rpm audio/x-pn-realaudio-plugin -+ra audio/x-realaudio -+wav audio/x-wav -+pdb chemical/x-pdb -+xyz chemical/x-xyz -+bmp image/bmp -+gif image/gif -+ief image/ief -+jpeg image/jpeg -+jpg image/jpeg -+jpe image/jpeg -+png image/png -+tiff image/tiff -+tif image/tiff -+djvu image/vnd.djvu -+djv image/vnd.djvu -+wbmp image/vnd.wap.wbmp -+ras image/x-cmu-raster -+pnm image/x-portable-anymap -+pbm image/x-portable-bitmap -+pgm image/x-portable-graymap -+ppm image/x-portable-pixmap -+rgb image/x-rgb -+xbm image/x-xbitmap -+xpm image/x-xpixmap -+xwd image/x-xwindowdump -+igs model/iges -+iges model/iges -+msh model/mesh -+mesh model/mesh -+silo model/mesh - wrl model/vrml - vrml model/vrml --mime message/rfc822 -- --pac application/x-ns-proxy-autoconfig -- -+css text/css -+html text/html; charset=%s -+htm text/html; charset=%s -+asc text/plain; charset=%s -+txt text/plain; charset=%s -+rtx text/richtext -+rtf text/rtf -+sgml text/sgml -+sgm text/sgml -+tsv text/tab-separated-values - wml text/vnd.wap.wml --wmlc application/vnd.wap.wmlc - wmls text/vnd.wap.wmlscript --wmlsc application/vnd.wap.wmlscriptc --wbmp image/vnd.wap.wbmp -+etx text/x-setext -+xml text/xml -+xsl text/xml -+mpeg video/mpeg -+mpg video/mpeg -+mpe video/mpeg -+qt video/quicktime -+mov video/quicktime -+mxu video/vnd.mpegurl -+avi video/x-msvideo -+movie video/x-sgi-movie -+ice x-conference/x-cooltalk -diff -ur thttpd-2.21b/mmc.c thttpd-2.21b-cool/mmc.c ---- thttpd-2.21b/mmc.c Fri Apr 13 23:02:15 2001 -+++ thttpd-2.21b-cool/mmc.c Sat Sep 20 14:43:20 2003 -@@ -70,6 +70,9 @@ - unsigned int hash; - int hash_idx; - struct MapStruct* next; -+ char nocache; -+ size_t last_modified_len; -+ char last_modified[100]; - } Map; - - -@@ -93,12 +96,13 @@ - - - void* --mmc_map( char* filename, struct stat* sbP, struct timeval* nowP ) -+mmc_map( char* filename, struct stat* sbP, struct timeval* nowP, int nocache, char **last_modified, size_t *last_modified_len ) - { - time_t now; - struct stat sb; - Map* m; - int fd; -+ const char* rfc1123fmt = "%a, %d %b %Y %H:%M:%S GMT"; - - /* Stat the file, if necessary. */ - if ( sbP != (struct stat*) 0 ) -@@ -130,7 +134,7 @@ - /* Yep. Just return the existing map */ - ++m->refcount; - m->reftime = now; -- return m->addr; -+ goto done; - } - - /* Open the file. */ -@@ -167,12 +171,13 @@ - m->ctime = sb.st_ctime; - m->refcount = 1; - m->reftime = now; -+ m->nocache = (char) nocache; - - /* Avoid doing anything for zero-length files; some systems don't like - ** to mmap them, other systems dislike mallocing zero bytes. - */ - if ( m->size == 0 ) -- m->addr = (void*) 1; /* arbitrary non-NULL address */ -+ m->addr = (void*) 5; /* arbitrary non-NULL address */ - else - { - #ifdef HAVE_MMAP -@@ -223,6 +228,13 @@ - maps = m; - ++map_count; - -+ strftime( m->last_modified, sizeof(m->last_modified), rfc1123fmt, gmtime( &sb.st_mtime ) ); -+ m->last_modified_len = strlen(m->last_modified); -+ -+done: -+ *last_modified = m->last_modified; -+ *last_modified_len = m->last_modified_len; -+ - /* And return the address. */ - return m->addr; - } -@@ -231,27 +243,32 @@ - void - mmc_unmap( void* addr, struct stat* sbP, struct timeval* nowP ) - { -- Map* m = (Map*) 0; -+ Map* m = (Map*) 0, **mm = &maps; - - /* Find the Map entry for this address. First try a hash. */ - if ( sbP != (struct stat*) 0 ) - { - m = find_hash( sbP->st_ino, sbP->st_dev, sbP->st_size, sbP->st_ctime ); -- if ( m != (Map*) 0 && m->addr != addr ) -+ if ( m != (Map*) 0 && ( m->addr != addr || m->nocache == 1 ) ) - m = (Map*) 0; - } - /* If that didn't work, try a full search. */ - if ( m == (Map*) 0 ) -- for ( m = maps; m != (Map*) 0; m = m->next ) -+ for ( m = maps; m != (Map*) 0; m = m->next ) { - if ( m->addr == addr ) - break; -+ mm = &m->next; -+ } - if ( m == (Map*) 0 ) - syslog( LOG_ERR, "mmc_unmap failed to find entry!" ); - else if ( m->refcount <= 0 ) - syslog( LOG_ERR, "mmc_unmap found zero or negative refcount!" ); - else - { -- --m->refcount; -+ if ( --m->refcount == 0 && m->nocache == 1 ) { -+ really_unmap( mm ); -+ return; -+ } - if ( nowP != (struct timeval*) 0 ) - m->reftime = nowP->tv_sec; - else -diff -ur thttpd-2.21b/mmc.h thttpd-2.21b-cool/mmc.h ---- thttpd-2.21b/mmc.h Fri Apr 13 07:36:54 2001 -+++ thttpd-2.21b-cool/mmc.h Sat Sep 20 14:43:20 2003 -@@ -31,8 +31,9 @@ - /* Returns an mmap()ed area for the given file, or (void*) 0 on errors. - ** If you have a stat buffer on the file, pass it in, otherwise pass 0. - ** Same for the current time. -+** Set nocache to 1, if this entry is supposed to be removed quickly. - */ --extern void* mmc_map( char* filename, struct stat* sbP, struct timeval* nowP ); -+extern void* mmc_map( char* filename, struct stat* sbP, struct timeval* nowP, int nocache, char **last_modified, size_t *last_modified_len ); - - /* Done with an mmap()ed area that was returned by mmc_map(). - ** If you have a stat buffer on the file, pass it in, otherwise pass 0. -diff -ur thttpd-2.21b/thttpd.c thttpd-2.21b-cool/thttpd.c ---- thttpd-2.21b/thttpd.c Tue Apr 24 00:41:57 2001 -+++ thttpd-2.21b-cool/thttpd.c Sat Sep 20 14:43:20 2003 -@@ -53,6 +53,10 @@ - #endif - #include - -+#include -+ -+#include -+ - #include "fdwatch.h" - #include "libhttpd.h" - #include "mmc.h" -@@ -66,6 +70,8 @@ - static char* dir; - static int do_chroot, no_log, no_symlink, do_vhost, do_global_passwd; - static char* cgi_pattern; -+static char* php_pattern; -+static char* phps_pattern; - static char* url_pattern; - static int no_empty_referers; - static char* local_pattern; -@@ -95,10 +101,10 @@ - httpd_conn* hc; - int tnums[MAXTHROTTLENUMS]; /* throttle indexes */ - int numtnums; -+ int keep_alive; - long limit; - time_t started_at; -- Timer* idle_read_timer; -- Timer* idle_send_timer; -+ time_t last_io; - Timer* wakeup_timer; - Timer* linger_timer; - long wouldblock_delay; -@@ -106,17 +112,22 @@ - off_t bytes_sent; - off_t bytes_to_send; - } connecttab; --static connecttab* connects; -+static connecttab* connects, **free_connects; -+static int next_free_connect; - static int numconnects, maxconnects; - static int httpd_conn_count; - - /* The connection states. */ --#define CNST_FREE 0 --#define CNST_READING 1 --#define CNST_SENDING 2 --#define CNST_PAUSING 3 --#define CNST_LINGERING 4 -- -+enum { -+ CNST_FREE = 0, -+ CNST_READING, -+ CNST_SENDING, -+ CNST_PAUSING, -+ CNST_LINGERING, -+ CNST_SENDING_RESP, -+ CNST_READING_BODY, -+ CNST_TOTAL_NR -+}; - - static httpd_server* hs = (httpd_server*) 0; - int terminate = 0; -@@ -140,23 +151,32 @@ - static int handle_newconnect( struct timeval* tvP, int listen_fd ); - static void handle_read( connecttab* c, struct timeval* tvP ); - static void handle_send( connecttab* c, struct timeval* tvP ); -+static void handle_send_resp( connecttab* c, struct timeval* tvP ); -+static void handle_read_body( connecttab* c, struct timeval* tvP ); - static void handle_linger( connecttab* c, struct timeval* tvP ); - static int check_throttles( connecttab* c ); -+static void timeout_conns( ClientData client_data, struct timeval* nowP ); - static void clear_throttles( connecttab* c, struct timeval* tvP ); - static void update_throttles( ClientData client_data, struct timeval* nowP ); --static void clear_connection( connecttab* c, struct timeval* tvP ); -+static void clear_connection( connecttab* c, struct timeval* tvP, int ); - static void really_clear_connection( connecttab* c, struct timeval* tvP ); --static void idle_read_connection( ClientData client_data, struct timeval* nowP ); --static void idle_send_connection( ClientData client_data, struct timeval* nowP ); - static void wakeup_connection( ClientData client_data, struct timeval* nowP ); - static void linger_clear_connection( ClientData client_data, struct timeval* nowP ); - static void occasional( ClientData client_data, struct timeval* nowP ); -+static void periodic_jobs( ClientData client_data, struct timeval* nowP ); - #ifdef STATS_TIME - static void show_stats( ClientData client_data, struct timeval* nowP ); - #endif /* STATS_TIME */ - static void logstats( struct timeval* nowP ); - static void thttpd_logstats( long secs ); -+static void boot_request(connecttab *c, struct timeval *tvP); -+ -+typedef void (*handler_func)(connecttab*, struct timeval *); -+ -+handler_func handler_array[CNST_TOTAL_NR] = -+{NULL, handle_read, handle_send, NULL, handle_linger, handle_send_resp, handle_read_body}; - -+#define RUN_HANDLER(type, c) if (handler_array[type]) handler_array[type](c, &tv) - - static void - handle_term( int sig ) -@@ -177,7 +197,7 @@ - return; - - /* Re-open the log file. */ -- if ( logfile != (char*) 0 ) -+ if ( logfile != (char*) 0 && strcmp(logfile, "-") != 0) - { - logfp = fopen( logfile, "a" ); - if ( logfp == (FILE*) 0 ) -@@ -198,6 +218,8 @@ - } - - -+time_t httpd_time_now; -+ - static void - handle_usr2( int sig ) - { -@@ -217,7 +239,6 @@ - int num_ready; - int cnum, ridx; - connecttab* c; -- httpd_conn* hc; - httpd_sockaddr sa4; - httpd_sockaddr sa6; - int gotv4, gotv6; -@@ -270,7 +291,9 @@ - no_log = 1; - logfp = (FILE*) 0; - } -- else -+ else if (strcmp(logfile, "-") == 0) { -+ logfp = stdout; -+ } else - { - logfp = fopen( logfile, "a" ); - if ( logfp == (FILE*) 0 ) -@@ -420,7 +443,8 @@ - hostname, - gotv4 ? &sa4 : (httpd_sockaddr*) 0, gotv6 ? &sa6 : (httpd_sockaddr*) 0, - port, cgi_pattern, charset, cwd, no_log, logfp, no_symlink, do_vhost, -- do_global_passwd, url_pattern, local_pattern, no_empty_referers ); -+ do_global_passwd, url_pattern, local_pattern, no_empty_referers, -+ php_pattern, phps_pattern); - if ( hs == (httpd_server*) 0 ) - exit( 1 ); - -@@ -430,6 +454,12 @@ - syslog( LOG_CRIT, "tmr_create(occasional) failed" ); - exit( 1 ); - } -+ -+ if (tmr_create(0, timeout_conns, JunkClientData, 30 * 1000, 1) == 0) { -+ syslog(LOG_CRIT, "tmr_create(timeout_conns) failed"); -+ exit(1); -+ } -+ - if ( numthrottles > 0 ) - { - /* Set up the throttles timer. */ -@@ -439,6 +469,12 @@ - exit( 1 ); - } - } -+ -+ if (tmr_create(0, periodic_jobs, JunkClientData, 2000, 1) == 0) { -+ syslog(LOG_CRIT, "tmr_create failed"); -+ exit(1); -+ } -+ - #ifdef STATS_TIME - /* Set up the stats timer. */ - if ( tmr_create( (struct timeval*) 0, show_stats, JunkClientData, STATS_TIME * 1000L, 1 ) == (Timer*) 0 ) -@@ -454,12 +490,14 @@ - /* If we're root, try to become someone else. */ - if ( getuid() == 0 ) - { -+#ifndef __CYGWIN__ - /* Set aux groups to null. */ - if ( setgroups( 0, (const gid_t*) 0 ) < 0 ) - { - syslog( LOG_CRIT, "setgroups - %m" ); - exit( 1 ); - } -+#endif - /* Set primary group. */ - if ( setgid( gid ) < 0 ) - { -@@ -495,13 +533,17 @@ - } - maxconnects -= SPARE_FDS; - connects = NEW( connecttab, maxconnects ); -+ free_connects = malloc(sizeof(connecttab *) * maxconnects); -+ next_free_connect = maxconnects; - if ( connects == (connecttab*) 0 ) - { - syslog( LOG_CRIT, "out of memory allocating a connecttab" ); - exit( 1 ); - } -+ - for ( cnum = 0; cnum < maxconnects; ++cnum ) - { -+ free_connects[cnum] = &connects[maxconnects - cnum - 1]; - connects[cnum].conn_state = CNST_FREE; - connects[cnum].hc = (httpd_conn*) 0; - } -@@ -518,6 +560,9 @@ - - /* Main loop. */ - (void) gettimeofday( &tv, (struct timezone*) 0 ); -+ httpd_time_now = tv.tv_sec; -+ periodic_jobs(JunkClientData, &tv); -+ - while ( ( ! terminate ) || numconnects > 0 ) - { - /* Do the fd watch. */ -@@ -530,6 +575,7 @@ - exit( 1 ); - } - (void) gettimeofday( &tv, (struct timezone*) 0 ); -+ httpd_time_now = tv.tv_sec; - if ( num_ready == 0 ) - { - /* No fd's are ready - run the timers. */ -@@ -565,16 +611,10 @@ - c = (connecttab*) fdwatch_get_client_data( ridx ); - if ( c == (connecttab*) 0 ) - continue; -- hc = c->hc; -- if ( c->conn_state == CNST_READING && -- fdwatch_check_fd( hc->conn_fd ) ) -- handle_read( c, &tv ); -- else if ( c->conn_state == CNST_SENDING && -- fdwatch_check_fd( hc->conn_fd ) ) -- handle_send( c, &tv ); -- else if ( c->conn_state == CNST_LINGERING && -- fdwatch_check_fd( hc->conn_fd ) ) -- handle_linger( c, &tv ); -+#if DO_UNNECESSARY_CHECK_FD -+ fdwatch_check_fd(c->hc->conn_fd); -+#endif -+ RUN_HANDLER(c->conn_state, c); - } - tmr_run( &tv ); - -@@ -627,6 +667,8 @@ - #else /* CGI_PATTERN */ - cgi_pattern = (char*) 0; - #endif /* CGI_PATTERN */ -+ php_pattern = "**.php"; -+ phps_pattern = "**.phps"; - url_pattern = (char*) 0; - no_empty_referers = 0; - local_pattern = (char*) 0; -@@ -833,6 +875,16 @@ - value_required( name, value ); - cgi_pattern = e_strdup( value ); - } -+ else if ( strcasecmp( name, "phppat" ) == 0 ) -+ { -+ value_required( name, value ); -+ php_pattern = e_strdup( value ); -+ } -+ else if ( strcasecmp( name, "phpspat" ) == 0 ) -+ { -+ value_required( name, value ); -+ phps_pattern = e_strdup( value ); -+ } - else if ( strcasecmp( name, "urlpat" ) == 0 ) - { - value_required( name, value ); -@@ -1196,8 +1248,10 @@ - logstats( &tv ); - for ( cnum = 0; cnum < maxconnects; ++cnum ) - { -- if ( connects[cnum].conn_state != CNST_FREE ) -+ if ( connects[cnum].conn_state != CNST_FREE ) { -+ httpd_complete_request( connects[cnum].hc, &tv ); - httpd_close_conn( connects[cnum].hc, &tv ); -+ } - if ( connects[cnum].hc != (httpd_conn*) 0 ) - { - httpd_destroy_conn( connects[cnum].hc ); -@@ -1214,6 +1268,7 @@ - } - mmc_destroy(); - tmr_destroy(); -+ free( (void*) free_connects ); - free( (void*) connects ); - if ( throttles != (throttletab*) 0 ) - free( (void*) throttles ); -@@ -1234,7 +1289,7 @@ - for (;;) - { - /* Is there room in the connection table? */ -- if ( numconnects >= maxconnects ) -+ if ( numconnects >= maxconnects || next_free_connect == 0 ) - { - /* Out of connection slots. Run the timers, then the - ** existing connections, and maybe we'll free up a slot -@@ -1245,10 +1300,10 @@ - return 0; - } - /* Find a free connection entry. */ -- for ( cnum = 0; cnum < maxconnects; ++cnum ) -- if ( connects[cnum].conn_state == CNST_FREE ) -- break; -- c = &connects[cnum]; -+ -+ c = free_connects[--next_free_connect]; -+ free_connects[next_free_connect] = NULL; -+ - /* Make the httpd_conn if necessary. */ - if ( c->hc == (httpd_conn*) 0 ) - { -@@ -1267,24 +1322,18 @@ - { - case GC_FAIL: - case GC_NO_MORE: -+ free_connects[next_free_connect++] = c; - return 1; - } - c->conn_state = CNST_READING; - ++numconnects; - client_data.p = c; -- c->idle_read_timer = tmr_create( -- tvP, idle_read_connection, client_data, IDLE_READ_TIMELIMIT * 1000L, -- 0 ); -- if ( c->idle_read_timer == (Timer*) 0 ) -- { -- syslog( LOG_CRIT, "tmr_create(idle_read_connection) failed" ); -- exit( 1 ); -- } -- c->idle_send_timer = (Timer*) 0; - c->wakeup_timer = (Timer*) 0; - c->linger_timer = (Timer*) 0; - c->bytes_sent = 0; - c->numtnums = 0; -+ c->keep_alive = 0; -+ c->last_io = httpd_time_now; - - /* Set the connection file descriptor to no-delay mode. */ - httpd_set_ndelay( c->hc->conn_fd ); -@@ -1298,11 +1347,100 @@ - } - - -+#define FIXUP(x) if (hc->x >= oldptr && hc->x < pe) hc->x += d -+ -+static void -+realign_hc(httpd_conn *hc, char *oldptr) -+{ -+ int d = hc->read_buf - oldptr; -+ char *pe = oldptr + hc->checked_idx; -+ -+ FIXUP(encodedurl); -+ FIXUP(protocol); -+ FIXUP(referer); -+ FIXUP(useragent); -+ FIXUP(acceptl); -+ FIXUP(cookie); -+ FIXUP(contenttype); -+ FIXUP(hdrhost); -+ FIXUP(authorization); -+} -+ -+#undef FIXUP -+ -+static void -+setup_read_body(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; -+ int already, missing; -+ char *oldptr = hc->read_buf; -+ -+ c->conn_state = CNST_READING_BODY; -+ -+ hc->read_body_into_mem = 0; -+ -+ already = hc->read_idx - hc->checked_idx; -+ missing = hc->contentlength - already; -+ -+ if (missing > 16384) { -+ char filename[] = "/tmp/thttpd.upload.XXXXXX"; -+ int tmp = mkstemp(filename); -+ -+ if (tmp >= 0) { -+ void *p; -+ size_t sz = hc->contentlength + hc->checked_idx + 10; -+ -+ unlink(filename); -+ -+ ftruncate(tmp, sz); -+ p = mmap(NULL, sz, -+ PROT_READ|PROT_WRITE, MAP_PRIVATE, tmp, 0); -+ -+ if (p != MAP_FAILED) { -+ memcpy(p, hc->read_buf, hc->read_idx); -+ free(hc->read_buf); -+ hc->read_size = sz; -+ hc->read_buf = p; -+ hc->read_buf_is_mmap = 1; -+ } -+ close(tmp); -+ } -+ -+ if (!hc->read_buf_is_mmap) { -+ clear_connection( c, tvP, 0 ); -+ return; -+ } -+ } else if (missing > 0) { -+ httpd_realloc_str(&hc->read_buf, &hc->read_size, hc->checked_idx + hc->contentlength + 10); -+ } -+ if (oldptr != hc->read_buf) realign_hc(hc, oldptr); -+ -+ fdwatch_del_fd( hc->conn_fd ); -+ fdwatch_add_fd( hc->conn_fd, c, FDW_READ ); -+} -+ -+static void -+setup_sending(connecttab *c, int state, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; -+ ClientData client_data; -+ -+ c->conn_state = state; -+ c->started_at = tvP->tv_sec; -+ c->wouldblock_delay = 0; -+ client_data.p = c; -+ -+ fdwatch_del_fd( hc->conn_fd ); -+ fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE ); -+} -+ -+static void handle_request( connecttab *c, struct timeval *tvP); -+ -+ - static void - handle_read( connecttab* c, struct timeval* tvP ) - { - int sz; -- ClientData client_data; - httpd_conn* hc = c->hc; - - /* Is there room in our buffer to read more bytes? */ -@@ -1311,7 +1449,7 @@ - if ( hc->read_size > 5000 ) - { - httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - httpd_realloc_str( -@@ -1327,14 +1465,53 @@ - ** EWOULDBLOCK; however, this apparently can happen if a packet gets - ** garbled. - */ -- if ( sz == 0 || ( sz < 0 && ( errno != EWOULDBLOCK ) ) ) -- { -- httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -- clear_connection( c, tvP ); -+ if ( sz == 0 ) { -+ if (! c->keep_alive) { -+ httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -+ } -+ clear_connection( c, tvP, 0 ); -+ return; -+ } else if ( sz < 0 ) { -+ if (errno != EWOULDBLOCK) { -+ clear_connection( c, tvP, 0 ); -+ } - return; -+ } -+ -+ /* If this is a persistent PHP connection, we must not receive -+ ** any further requests on this connection. Some broken HTTP/1.1 -+ ** implementations (e.g. Mozilla 1.0.1) are known to do -+ ** pipelining on a connection, although a prior response included -+ ** Connection: close -+ */ -+ if (c->hc->file_address == (char *) 1) { -+ return; -+ } -+ -+ c->last_io = httpd_time_now; -+ if (sz > 0) hc->read_idx += sz; -+ -+ /* -+ ** if we start getting new data on this socket, "promote" it -+ ** to read timeout -+ */ -+ if ( hc->keep_alive ) { -+ ClientData client_data; -+ -+ -+ client_data.p = c; -+ -+ hc->keep_alive = 0; -+ } -+ handle_request(c, tvP); - } -- hc->read_idx += sz; - -+ -+static void -+handle_request( connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn* hc = c->hc; -+ - /* Do we have a complete request yet? */ - switch ( httpd_got_request( hc ) ) - { -@@ -1342,14 +1519,14 @@ - return; - case GR_BAD_REQUEST: - httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - - /* Yes. Try parsing and resolving it. */ - if ( httpd_parse_request( hc ) < 0 ) - { -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - -@@ -1358,18 +1535,28 @@ - { - httpd_send_err( - hc, 503, httpd_err503title, "", httpd_err503form, hc->encodedurl ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } -+ boot_request(c, tvP); -+} - -+static void boot_request(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; - /* Start the connection going. */ - if ( httpd_start_request( hc, tvP ) < 0 ) - { - /* Something went wrong. Close down the connection. */ -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - -+ if ( hc->read_body_into_mem ) { -+ setup_read_body( c, tvP ); -+ return; -+ } -+ - /* Fill in bytes_to_send. */ - if ( hc->got_range ) - { -@@ -1384,37 +1571,25 @@ - { - /* No file address means someone else is handling it. */ - c->bytes_sent = hc->bytes_sent; -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 1 ); - return; - } -+ if (hc->file_address == (char *) 1) { -+ c->last_io = (time_t) LONG_MAX; -+ c->wouldblock_delay = 0; -+ return; -+ } - if ( c->bytes_sent >= c->bytes_to_send ) - { - /* There's nothing to send. */ -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 1 ); - return; - } - - /* Cool, we have a valid connection and a file to send to it. */ -- c->conn_state = CNST_SENDING; -- c->started_at = tvP->tv_sec; -- c->wouldblock_delay = 0; -- client_data.p = c; -- tmr_cancel( c->idle_read_timer ); -- c->idle_read_timer = (Timer*) 0; -- c->idle_send_timer = tmr_create( -- tvP, idle_send_connection, client_data, IDLE_SEND_TIMELIMIT * 1000L, -- 0 ); -- if ( c->idle_send_timer == (Timer*) 0 ) -- { -- syslog( LOG_CRIT, "tmr_create(idle_send_connection) failed" ); -- exit( 1 ); -- } -- -- fdwatch_del_fd( hc->conn_fd ); -- fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE ); -+ setup_sending(c, CNST_SENDING, tvP); - } - -- - static void - handle_send( connecttab* c, struct timeval* tvP ) - { -@@ -1443,6 +1618,9 @@ - iv[1].iov_base = &(hc->file_address[c->bytes_sent]); - iv[1].iov_len = MIN( c->bytes_to_send - c->bytes_sent, c->limit ); - sz = writev( hc->conn_fd, iv, 2 ); -+/* -+printf("**RESPONSE2 [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->responselen, hc->response); -+*/ - } - - if ( sz == 0 || -@@ -1486,12 +1664,12 @@ - */ - if ( errno != EPIPE && errno != EINVAL && errno != ECONNRESET ) - syslog( LOG_ERR, "write - %m sending %.80s", hc->encodedurl ); -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 0 ); - return; - } - - /* Ok, we wrote something. */ -- tmr_reset( tvP, c->idle_send_timer ); -+ c->last_io = httpd_time_now; - /* Was this a headers + file writev()? */ - if ( hc->responselen > 0 ) - { -@@ -1500,7 +1678,7 @@ - { - /* Yes; move the unwritten part to the front of the buffer. */ - int newlen = hc->responselen - sz; -- (void) memcpy( hc->response, &(hc->response[sz]), newlen ); -+ (void) memmove( hc->response, &(hc->response[sz]), newlen ); - hc->responselen = newlen; - sz = 0; - } -@@ -1519,7 +1697,7 @@ - if ( c->bytes_sent >= c->bytes_to_send ) - { - /* This connection is finished! */ -- clear_connection( c, tvP ); -+ clear_connection( c, tvP, 1 ); - return; - } - -@@ -1560,6 +1738,9 @@ - char buf[1024]; - int r; - -+/* -+printf("*LINGER read\n"); -+*/ - /* In lingering-close mode we just read and ignore bytes. An error - ** or EOF ends things, otherwise we go until a timeout. - */ -@@ -1569,6 +1750,63 @@ - } - - -+static void -+handle_read_body(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn *hc = c->hc; -+ int n; -+ -+ n = read(hc->conn_fd, hc->read_buf + hc->read_idx, -+ hc->contentlength - (hc->read_idx - hc->checked_idx)); -+ -+ if (n <= 0) { -+ if (errno == EAGAIN) -+ return; -+ clear_connection(c, tvP, 0); -+ return; -+ } -+ -+ c->last_io = httpd_time_now; -+ -+ hc->read_idx += n; -+ -+ if (hc->contentlength == hc->read_idx - hc->checked_idx) { -+ boot_request(c, tvP); -+ return; -+ } -+} -+ -+static void -+handle_send_resp(connecttab *c, struct timeval *tvP) -+{ -+ httpd_conn* hc = c->hc; -+ int n = send(hc->conn_fd, hc->response, hc->responselen, 0); -+ int dokeep = 1; -+ -+ if (n < 0) { -+ if (errno == EAGAIN) -+ return; -+ -+ dokeep = 0; -+ goto clear; -+ } -+ -+ c->last_io = httpd_time_now; -+ -+ if (n == hc->responselen) { -+clear: -+ hc->response = realloc(hc->response, hc->maxresponse + 1); -+ hc->responselen = 0; -+ -+ clear_connection(c, tvP, dokeep); -+ return; -+ } -+ -+ hc->responselen -= n; -+ -+ memmove(hc->response, hc->response + n, hc->responselen); -+} -+ - static int - check_throttles( connecttab* c ) - { -@@ -1635,23 +1873,18 @@ - - - static void --clear_connection( connecttab* c, struct timeval* tvP ) -+clear_connection( connecttab* c, struct timeval* tvP, int doKeep ) - { - ClientData client_data; -+ int linger; - - /* If we haven't actually sent the buffered response yet, do so now. */ -- httpd_write_response( c->hc ); -+ if (c->hc->responselen && c->conn_state != CNST_SENDING_RESP) { -+ setup_sending(c, CNST_SENDING_RESP, tvP); - -- if ( c->idle_read_timer != (Timer*) 0 ) -- { -- tmr_cancel( c->idle_read_timer ); -- c->idle_read_timer = 0; -- } -- if ( c->idle_send_timer != (Timer*) 0 ) -- { -- tmr_cancel( c->idle_send_timer ); -- c->idle_send_timer = 0; -+ return; - } -+ - if ( c->wakeup_timer != (Timer*) 0 ) - { - tmr_cancel( c->wakeup_timer ); -@@ -1669,13 +1902,36 @@ - ** circumstances that make a lingering close necessary. If the flag - ** isn't set we do the real close now. - */ -- if ( c->hc->should_linger ) -+ -+ if ( c->hc->do_keep_alive && doKeep) - { -- c->conn_state = CNST_LINGERING; -+ httpd_conn *hc = c->hc; -+ c->conn_state = CNST_READING; -+ -+ client_data.p = c; -+ c->bytes_sent = 0; -+ c->numtnums = 0; -+ c->keep_alive = 1; -+ -+ httpd_complete_request( c->hc, tvP ); -+ - fdwatch_del_fd( c->hc->conn_fd ); - fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ ); -+ -+ httpd_request_reset( c->hc, 1 ); -+ -+ hc->read_idx -= hc->checked_idx; -+ memmove(hc->read_buf, hc->read_buf + hc->checked_idx, hc->read_idx); -+ hc->checked_idx = 0; -+ - /* Make sure we are still in no-delay mode. */ - httpd_set_ndelay( c->hc->conn_fd ); -+ handle_request(c, tvP); -+ } -+ else if ( c->hc->should_linger ) -+ { -+ c->conn_state = CNST_LINGERING; -+ - client_data.p = c; - c->linger_timer = tmr_create( - tvP, linger_clear_connection, client_data, LINGER_TIME * 1000L, 0 ); -@@ -1684,9 +1940,19 @@ - syslog( LOG_CRIT, "tmr_create(linger_clear_connection) failed" ); - exit( 1 ); - } -+ -+ httpd_complete_request( c->hc, tvP ); -+ -+ fdwatch_del_fd( c->hc->conn_fd ); -+ fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ ); -+ /* Make sure we are still in no-delay mode. */ -+ httpd_set_ndelay( c->hc->conn_fd ); - } -- else -+ else -+ { -+ httpd_complete_request( c->hc, tvP ); - really_clear_connection( c, tvP ); -+ } - } - - -@@ -1702,45 +1968,12 @@ - tmr_cancel( c->linger_timer ); - c->linger_timer = 0; - } -+ free_connects[next_free_connect++] = c; - c->conn_state = CNST_FREE; - --numconnects; - } - - --static void --idle_read_connection( ClientData client_data, struct timeval* nowP ) -- { -- connecttab* c; -- -- c = (connecttab*) client_data.p; -- c->idle_read_timer = (Timer*) 0; -- if ( c->conn_state != CNST_FREE ) -- { -- syslog( LOG_INFO, -- "%.80s connection timed out reading", -- httpd_ntoa( &c->hc->client_addr ) ); -- httpd_send_err( c->hc, 408, httpd_err408title, "", httpd_err408form, "" ); -- clear_connection( c, nowP ); -- } -- } -- -- --static void --idle_send_connection( ClientData client_data, struct timeval* nowP ) -- { -- connecttab* c; -- -- c = (connecttab*) client_data.p; -- c->idle_send_timer = (Timer*) 0; -- if ( c->conn_state != CNST_FREE ) -- { -- syslog( LOG_INFO, -- "%.80s connection timed out sending", -- httpd_ntoa( &c->hc->client_addr ) ); -- clear_connection( c, nowP ); -- } -- } -- - - static void - wakeup_connection( ClientData client_data, struct timeval* nowP ) -@@ -1783,6 +2016,43 @@ - } - #endif /* STATS_TIME */ - -+char httpd_now_buf[100]; -+ -+ -+ -+static void -+periodic_jobs( ClientData client_data, struct timeval* nowP ) -+{ -+ const char* rfc1123fmt = "%a, %d %b %Y %H:%M:%S GMT"; -+ struct tm *t; -+ char date_nozone[100]; -+ const char* cernfmt_nozone = "%d/%b/%Y:%H:%M:%S"; -+ char data[100]; -+ int zone; -+ char sign; -+ -+ strftime( httpd_now_buf, sizeof(httpd_now_buf), rfc1123fmt, gmtime( &nowP->tv_sec ) ); -+ -+ t = localtime(&nowP->tv_sec); -+ strftime( date_nozone, sizeof(date_nozone), cernfmt_nozone, t ); -+#ifdef HAVE_TM_GMTOFF -+ zone = t->tm_gmtoff / 60L; -+#else -+ zone = -timezone / 60L; -+ /* Probably have to add something about daylight time here. */ -+#endif -+ if ( zone >= 0 ) -+ sign = '+'; -+ else -+ { -+ sign = '-'; -+ zone = -zone; -+ } -+ zone = ( zone / 60 ) * 100 + zone % 60; -+ hs->log_date_len = sprintf( hs->log_date, "%s %c%04d", date_nozone, sign, -+ zone ); -+} -+ - - /* Generate debugging statistics syslog messages for all packages. */ - static void -@@ -1826,3 +2096,42 @@ - stats_connections = stats_bytes = 0L; - stats_simultaneous = 0; - } -+ -+static void -+timeout_conns(ClientData client_data, struct timeval *nowP) -+{ -+ connecttab *c = connects, *ce = c + maxconnects; -+ time_t now = nowP->tv_sec; -+ int r = 0, w = 0; -+ int checked = 0; -+ -+ while (c < ce) { -+ switch (c->conn_state) { -+ case CNST_SENDING: -+ case CNST_SENDING_RESP: -+ checked++; -+ if ((now - c->last_io) > IDLE_SEND_TIMELIMIT) { -+ clear_connection( c, nowP, 0 ); -+ w++; -+ } -+ break; -+ case CNST_READING: -+ case CNST_READING_BODY: -+ checked++; -+ if ((now - c->last_io) > IDLE_READ_TIMELIMIT) { -+ clear_connection( c, nowP, 0 ); -+ r++; -+ } -+ break; -+ case CNST_FREE: break; -+ default: checked++; break; -+ } -+ c++; -+ if (checked >= numconnects) break; -+ } -+ -+ if (r > 0 || w > 0) { -+ syslog(LOG_INFO, "Expired %d/%d connections in read/write state", r, w); -+ } -+} -+ -diff -ur thttpd-2.21b/version.h thttpd-2.21b-cool/version.h ---- thttpd-2.21b/version.h Tue Apr 24 04:05:23 2001 -+++ thttpd-2.21b-cool/version.h Sat Sep 20 14:43:20 2003 -@@ -3,7 +3,7 @@ - #ifndef _VERSION_H_ - #define _VERSION_H_ - --#define SERVER_SOFTWARE "thttpd/2.21b 23apr2001" -+#define SERVER_SOFTWARE "thttpd/2.21b PHP/20030920" - #define SERVER_ADDRESS "http://www.acme.com/software/thttpd/" - - #endif /* _VERSION_H_ */ diff --git a/sapi/tux/CREDITS b/sapi/tux/CREDITS deleted file mode 100644 index 3b7aa70c01bbe..0000000000000 --- a/sapi/tux/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -tux -Sascha Schumann diff --git a/sapi/tux/README b/sapi/tux/README deleted file mode 100644 index 3c5ebc56ba97b..0000000000000 --- a/sapi/tux/README +++ /dev/null @@ -1,86 +0,0 @@ -README FOR THE TUX MODULE (by Sascha Schumann) -($Date$) - - This is a SAPI module for the TUX web-server by Ingo Molnar. - - The special thing about TUX is that it is integrated into the Linux - kernel and thus provides high-speed serving of static files. - - The web-server provides a user-space API which allows arbitrary - plug-ins to be made available. - - All requests to the PHP userspace module are currently serialized. - - This module is of alpha quality. Due to incomplete APIs, HTTP - authentication and handling of POST requests has not been - implemented yet. - - SECURITY NOTE: PHP will happily run everything under the - web-root through the parser; so be careful what you put - there. - - Note that requests are served in a chroot'ed environment. - The initialization of PHP does not take place in the chroot'ed - environment, so that e.g. /usr/local/lib/php.ini is treated - as usual. - -REQUIRED DOWNLOADS - - 1. TUX - - http://people.redhat.com/~mingo/TUX-patches/QuickStart-TUX.txt - - 2. PHP 4.0.x - - Download: - http://www.php.net/ - - Snapshots from CVS: - http://snaps.php.net/ - - -BUILD INSTRUCTIONS - - 1. Install TUX as outlined in the QuickStart text. - Create /tux-modules where modules will reside. - - 2. Prepare PHP - - $ cd php-* - $ ./configure \ - --with-tux=/tux-modules \ - - # make install - - You can see the list of valid PHP options by executing - - $ ./configure --help - - 3. Touch a file in your web-root 'php7.tux'. This will - cause requests to '/php7.tux' to be redirected to the - userspace module php7.tux. - - 4. Start TUX with something like - - # tux -d -t 8 -r /www -m /tux-modules php7.tux - - (daemon mode, eight threads, web-root /www, modules in - /tux-modules, load php7.tux) - - BEFORE running this command, the kernel side of TUX has to - be properly setup. - - 5. Try to access - - http://yourserver/php7.tux?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000 - - It should display the PHP credits page. - - To access a script /foo/bar.php, use - - http://yourserver/php7.tux?/foo/bar.php - - Parameters can be appended: - - http://yourserver/php7.tux?/foo/bar.php&var=value - diff --git a/sapi/tux/config.m4 b/sapi/tux/config.m4 deleted file mode 100644 index db4be82cf1a7a..0000000000000 --- a/sapi/tux/config.m4 +++ /dev/null @@ -1,16 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(tux,, -[ --with-tux=MODULEDIR Build PHP as a TUX module (Linux only)], no, no) - -AC_MSG_CHECKING([for TUX]) -if test "$PHP_TUX" != "no"; then - INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_TUX/php7.tux.so" - AC_CHECK_HEADERS(tuxmodule.h,[:],[AC_MSG_ERROR([Cannot find tuxmodule.h])]) - PHP_SELECT_SAPI(tux, shared, php_tux.c) - AC_MSG_RESULT([$PHP_TUX]) -else - AC_MSG_RESULT(no) -fi diff --git a/sapi/tux/php.sym b/sapi/tux/php.sym deleted file mode 100644 index b968c5f5a2bc8..0000000000000 --- a/sapi/tux/php.sym +++ /dev/null @@ -1,2 +0,0 @@ -TUXAPI_handle_events -TUXAPI_init diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c deleted file mode 100644 index 11755e18e2767..0000000000000 --- a/sapi/tux/php_tux.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_variables.h" - -#include "zend_smart_str.h" - -#include "tuxmodule.h" - -#include - -#if 0 -#include -#endif - -void tux_closed_conn(int fd); - -enum { - PHP_TUX_BACKGROUND_CONN = 1 -}; - -typedef struct { - user_req_t *req; - void (*on_close)(int); - int tux_action; - struct iovec *header_vec; - int number_vec; -} php_tux_globals; - -static php_tux_globals tux_globals; - -#define TG(v) (tux_globals.v) - -static int sapi_tux_ub_write(const char *str, uint str_length) -{ - int n; - int m; - const char *estr; - - /* combine headers and body */ - if (TG(number_vec)) { - struct iovec *vec = TG(header_vec); - - n = TG(number_vec); - vec[n].iov_base = (void *) str; - vec[n++].iov_len = str_length; - - /* XXX: this might need more complete error handling */ - if ((m = writev(TG(req)->sock, vec, n)) == -1 && errno == EPIPE) - php_handle_aborted_connection(); - - if (m > 0) - TG(req)->bytes_sent += str_length; - - TG(number_vec) = 0; - return str_length; - } - - estr = str + str_length; - - while (str < estr) { - n = send(TG(req)->sock, str, estr - str, 0); - - if (n == -1 && errno == EPIPE) - php_handle_aborted_connection(); - if (n == -1 && errno == EAGAIN) - continue; - if (n <= 0) - return n; - - str += n; - } - - n = str_length - (estr - str); - - TG(req)->bytes_sent += n; - - return n; -} - -static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers) -{ - char buf[1024]; - struct iovec *vec; - int n; - int max_headers; - zend_llist_position pos; - sapi_header_struct *h; - size_t len; - char *status_line; - int locate_cl; - - max_headers = 30; - n = 1; - - vec = malloc(sizeof(struct iovec) * max_headers); - status_line = malloc(30); - - /* safe sprintf use */ - len = slprintf(status_line, 30, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code); - - vec[0].iov_base = status_line; - vec[0].iov_len = len; - - TG(req)->http_status = SG(sapi_headers).http_response_code; - - if (TG(tux_action) == TUX_ACTION_FINISH_CLOSE_REQ && TG(req)->http_version == HTTP_1_1) - locate_cl = 1; - else - locate_cl = 0; - - h = zend_llist_get_first_ex(&sapi_headers->headers, &pos); - while (h) { - if (locate_cl - && strncasecmp(h->header, "Content-length:", sizeof("Content-length:")-1) == 0) { - TG(tux_action) = TUX_ACTION_FINISH_REQ; - locate_cl = 0; - } - - vec[n].iov_base = h->header; - vec[n++].iov_len = h->header_len; - if (n >= max_headers - 3) { - max_headers *= 2; - vec = realloc(vec, sizeof(struct iovec) * max_headers); - } - vec[n].iov_base = "\r\n"; - vec[n++].iov_len = 2; - - h = zend_llist_get_next_ex(&sapi_headers->headers, &pos); - } - - vec[n].iov_base = "\r\n"; - vec[n++].iov_len = 2; - - TG(number_vec) = n; - TG(header_vec) = vec; - - - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static int sapi_tux_read_post(char *buffer, uint count_bytes) -{ -#if 0 - int amount = 0; - - TG(req)->objectlen = count_bytes; - TG(req)->object_addr = buffer; - if (tux(TUX_ACTION_READ_POST_DATA, TG(req))) - return 0; - - TG(read_post_data) = 1; - - return TG(req)->objectlen; -#else - return 0; -#endif -} - -static char *sapi_tux_read_cookies(void) -{ - return TG(req)->cookies; -} - -#define BUF_SIZE 512 -#define ADD_STRING(name) \ - php_register_variable(name, buf, track_vars_array) - -static void sapi_tux_register_variables(zval *track_vars_array) -{ - char buf[BUF_SIZE + 1]; - char *p; - sapi_header_line ctr = {0}; - - ctr.line = buf; - ctr.line_len = slprintf(buf, sizeof(buf), "Server: %s", TUXAPI_version); - sapi_header_op(SAPI_HEADER_REPLACE, &ctr); - - php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array); - php_register_variable("SERVER_SOFTWARE", TUXAPI_version, track_vars_array); - php_register_variable("GATEWAY_INTERFACE", "CGI/1.1", track_vars_array); - php_register_variable("REQUEST_METHOD", (char *) SG(request_info).request_method, track_vars_array); - php_register_variable("DOCUMENT_ROOT", TUXAPI_docroot, track_vars_array); - php_register_variable("SERVER_NAME", TUXAPI_servername, track_vars_array); - php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array); - php_register_variable("PATH_TRANSLATED", SG(request_info).path_translated, track_vars_array); - - p = inet_ntoa(TG(req)->client_host); - /* string representation of IPs are never larger than 512 bytes */ - if (p) { - memcpy(buf, p, strlen(p) + 1); - ADD_STRING("REMOTE_ADDR"); - ADD_STRING("REMOTE_HOST"); - } - - snprintf(buf, sizeof(buf), "%d", CGI_SERVER_PORT(TG(req))); - ADD_STRING("SERVER_PORT"); - -#if 0 - snprintf(buf, BUF_SIZE, "/%s", TG(hc)->pathinfo); - ADD_STRING("PATH_INFO"); - - snprintf(buf, BUF_SIZE, "/%s", TG(hc)->origfilename); - ADD_STRING("SCRIPT_NAME"); -#endif - -#define CONDADD(name, field) \ - if (TG(req)->field[0]) { \ - php_register_variable(#name, TG(req)->field, track_vars_array); \ - } - - CONDADD(HTTP_REFERER, referer); - CONDADD(HTTP_USER_AGENT, user_agent); - CONDADD(HTTP_ACCEPT, accept); - CONDADD(HTTP_ACCEPT_ENCODING, accept_encoding); - CONDADD(HTTP_ACCEPT_LANGUAGE, accept_language); - CONDADD(HTTP_COOKIE, cookies); - CONDADD(CONTENT_TYPE, content_type); - -#if 0 - if (TG(hc)->contentlength != -1) { - snprintf(buf, sizeof(buf), "%ld", (long) TG(hc)->contentlength); - ADD_STRING("CONTENT_LENGTH"); - } -#endif - -#if 0 - if (TG(hc)->authorization[0]) - php_register_variable("AUTH_TYPE", "Basic", track_vars_array); -#endif -} - - -static int php_tux_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, NULL, 0)==FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - -static sapi_module_struct tux_sapi_module = { - "tux", - "tux", - - php_tux_startup, - php_module_shutdown_wrapper, - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_tux_ub_write, - NULL, - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, - - NULL, - sapi_tux_send_headers, - NULL, - sapi_tux_read_post, - sapi_tux_read_cookies, - - sapi_tux_register_variables, - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -static void tux_module_main(void) -{ - zend_file_handle file_handle; - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - if (php_request_startup() == FAILURE) { - return; - } - - php_execute_script(&file_handle); - php_request_shutdown(NULL); -} - -static void tux_request_ctor(void) -{ - char buf[1024]; - int offset; - size_t filename_len; - size_t cwd_len; - smart_str s = {0}; - char *p; - - TG(number_vec) = 0; - TG(header_vec) = NULL; - SG(request_info).query_string = strdup(TG(req)->query); - - smart_str_appends_ex(&s, "/", 1); - smart_str_appends_ex(&s, TG(req)->query, 1); - smart_str_0(&s); - p = strchr(s.c, '&'); - if (p) - *p = '\0'; - SG(request_info).path_translated = s.c; - - s.c = NULL; - smart_str_appendc_ex(&s, '/', 1); - smart_str_appends_ex(&s, TG(req)->objectname, 1); - smart_str_0(&s); - SG(request_info).request_uri = s.c; - SG(request_info).request_method = CGI_REQUEST_METHOD(TG(req)); - if(TG(req)->http_version == HTTP_1_1) SG(request_info).proto_num = 1001; - else SG(request_info).proto_num = 1000; - SG(sapi_headers).http_response_code = 200; - SG(request_info).content_type = TG(req)->content_type; - SG(request_info).content_length = 0; /* TG(req)->contentlength; */ - -#if 0 - php_handle_auth_data(TG(hc)->authorization); -#endif -} - -static void tux_request_dtor(void) -{ - if (TG(header_vec)) { - /* free status_line */ - free(TG(header_vec)[0].iov_base); - free(TG(header_vec)); - } - if (SG(request_info).query_string) - free(SG(request_info).query_string); - free(SG(request_info).request_uri); - free(SG(request_info).path_translated); -} - -#if 0 -static void *separate_thread(void *bla) -{ - int fd; - int i = 0; - - fd = (int) bla; - - while (i++ < 5) { - send(fd, "test
\n", 9, 0); - sleep(1); - } - - tux(TUX_ACTION_CONTINUE_REQ, (user_req_t *) fd); - /* We HAVE to trigger some event on the fd. Otherwise - fast_thread won't wake up, so that the eventloop - won't be entered -> TUX hangs */ - shutdown(fd, 2); - pthread_exit(NULL); -} -#endif - -int TUXAPI_handle_events(user_req_t *req) -{ - - if (req->event == PHP_TUX_BACKGROUND_CONN) { - tux_closed_conn(req->sock); - return tux(TUX_ACTION_FINISH_CLOSE_REQ, req); - } - - TG(req) = req; - TG(tux_action) = TUX_ACTION_FINISH_CLOSE_REQ; - - tux_request_ctor(); - - tux_module_main(); - - tux_request_dtor(); - - return tux(TG(tux_action), req); -} - -void tux_register_on_close(void (*arg)(int)) -{ - TG(on_close) = arg; -} - -void tux_closed_conn(int fd) -{ - - if (TG(on_close)) TG(on_close)(fd); -} - -int tux_get_fd(void) -{ - - return TG(req)->sock; -} - -void tux_set_dont_close(void) -{ - - TG(req)->event = PHP_TUX_BACKGROUND_CONN; - tux(TUX_ACTION_POSTPONE_REQ, TG(req)); - TG(tux_action) = TUX_ACTION_EVENTLOOP; -} - -void TUXAPI_init(void) -{ - sapi_startup(&tux_sapi_module); - tux_sapi_module.startup(&tux_sapi_module); - SG(server_context) = (void *) 1; -} - -void doesnotmatter_fini(void) -{ - if (SG(server_context) != NULL) { - tux_sapi_module.shutdown(&tux_sapi_module); - sapi_shutdown(); - } -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/webjames/CREDITS b/sapi/webjames/CREDITS deleted file mode 100644 index 73a7983e9250a..0000000000000 --- a/sapi/webjames/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -WebJames -Alex Waugh diff --git a/sapi/webjames/README b/sapi/webjames/README deleted file mode 100644 index 15a7be3de0e48..0000000000000 --- a/sapi/webjames/README +++ /dev/null @@ -1,28 +0,0 @@ -README for WebJames SAPI module -by Alex Waugh - -This is a SAPI module for the WebJames HTTP server, which runs on the -RISC OS operating system. - - -DOWNLOADS - -A recent (February 2002 or later) version of the GCCSDK cross compiler -http://www.hard-mofo.dsvr.net/ - -WebJames 0.35 or later -http://www.webjames.alexwaugh.com/ - - -BUILDING - -$ cd php7 -$ ./configure \ - --host=arm-riscos-aof \ - --with-webjames=../webjames/src \ - --with-config-file-path=/Choices: \ - other PHP options -$ make install -$ cd ../webjames -$ ./configure --enable-php -$ make diff --git a/sapi/webjames/config.m4 b/sapi/webjames/config.m4 deleted file mode 100644 index 78c8a1936d97a..0000000000000 --- a/sapi/webjames/config.m4 +++ /dev/null @@ -1,21 +0,0 @@ -dnl -dnl $Id$ -dnl - -PHP_ARG_WITH(webjames,, -[ --with-webjames=SRCDIR Build PHP as a WebJames module (RISC OS only)], no, no) - -AC_MSG_CHECKING([for webjames]) - -if test "$PHP_WEBJAMES" != "no"; then - PHP_EXPAND_PATH($PHP_WEBJAMES, PHP_WEBJAMES) - INSTALL_IT="\ - echo 'PHP_LIBS = -l$abs_srcdir/$SAPI_STATIC \$(PHP_LIBS) \$(EXTRA_LIBS)' > $PHP_WEBJAMES/build/php; \ - echo 'PHP_LDFLAGS = \$(NATIVE_RPATHS) \$(PHP_LDFLAGS)' >> $PHP_WEBJAMES/build/php; \ - echo 'PHP_CFLAGS = -DPHP \$(COMMON_FLAGS) \$(EXTRA_CFLAGS) -I$abs_srcdir/sapi/webjames' >> $PHP_WEBJAMES/build/php;" - PHP_ADD_INCLUDE($PHP_WEBJAMES) - PHP_SELECT_SAPI(webjames, static, webjames.c) - AC_MSG_RESULT([yes, using $PHP_WEBJAMES]) -else - AC_MSG_RESULT(no) -fi diff --git a/sapi/webjames/php_webjames.h b/sapi/webjames/php_webjames.h deleted file mode 100644 index 63a9b047fbc9e..0000000000000 --- a/sapi/webjames/php_webjames.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Alex Waugh | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_WEBJAMES_H -#define PHP_WEBJAMES_H - -#include "webjames.h" - -void webjames_php_shutdown(void); -int webjames_php_init(void); -void webjames_php_request(struct connection *conn); - -#endif diff --git a/sapi/webjames/webjames.c b/sapi/webjames/webjames.c deleted file mode 100644 index 02c7dcf1c1e9d..0000000000000 --- a/sapi/webjames/webjames.c +++ /dev/null @@ -1,327 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | 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. | - +----------------------------------------------------------------------+ - | Author: Alex Waugh | - +----------------------------------------------------------------------+ -*/ - - -#include "php.h" -#include "SAPI.h" -#include "php_main.h" -#include "php_variables.h" - -#define WEBJAMES_PHP_ONLY -#include "php_webjames.h" - -#include - -#define WEBJAMES_SAPI_VERSION "1.0.2" - -typedef struct { - struct connection *conn; /*structure holding all the details of the current request*/ - int bodyread; /*amount of POST body read*/ - closefn oldclose; /*function to call to close the connection*/ -} php_webjames_globals; - -static php_webjames_globals webjames_globals; - -#define WG(v) (webjames_globals.v) - -static int sapi_webjames_ub_write(const char *str, uint str_length) -/*unbuffered write - send data straight out to socket*/ -{ - int totalbytes = 0; - - do { - int bytes; - bytes = webjames_writebuffer(WG(conn),str,str_length); - if (bytes<0) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - if (!PG(ignore_user_abort)) { - zend_bailout(); - } - return bytes; - } - str += bytes; - str_length -= bytes; - totalbytes += bytes; - } while (str_length); - return totalbytes; -} - -static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context) -/*send an HTTP header*/ -{ - char *header = sapi_header->header; - int len = sapi_header->header_len; - if (WG(conn)->flags.outputheaders) { - while (sapi_header && len > 0) { - int bytes; - bytes = webjames_writebuffer(WG(conn), header, len); - if (bytes<0) { - PG(connection_status) = PHP_CONNECTION_ABORTED; - if (!PG(ignore_user_abort)) { - zend_bailout(); - } - return; - } - header += bytes; - len -= bytes; - } - webjames_writestring(WG(conn), "\r\n"); - } -} - -static int sapi_webjames_read_post(char *buffer, uint count_bytes) -/*read some of the post data*/ -{ - if (WG(conn)->body==NULL) return 0; - if (count_bytes+WG(bodyread)>WG(conn)->bodysize) count_bytes=WG(conn)->bodysize-WG(bodyread); - memcpy(buffer, WG(conn)->body+WG(bodyread), count_bytes); - WG(bodyread)+=count_bytes; - return count_bytes; -} - -static char *sapi_webjames_read_cookies(void) -{ - return WG(conn)->cookie; -} - -#define BUF_SIZE 512 -#define ADD_STRING(name,string)\ - php_register_variable(name, string, track_vars_array) - -#define ADD_NUM(name,field) {\ - snprintf(buf, BUF_SIZE, "%d", WG(conn)->field);\ - php_register_variable(name, buf, track_vars_array);\ -} - -#define ADD_FIELD(name, field) \ - if (WG(conn)->field) { \ - php_register_variable(name, WG(conn)->field, track_vars_array); \ - } - -static void sapi_webjames_register_variables(zval *track_vars_array) -{ - char buf[BUF_SIZE + 1]; - char *docroot; - - buf[BUF_SIZE] = '\0'; - - ADD_STRING("SERVER_SOFTWARE", configuration.server); - ADD_STRING("SERVER_NAME", configuration.serverip); - ADD_FIELD("SERVER_PROTOCOL", protocol); - ADD_NUM("SERVER_PORT", port); - ADD_STRING("SERVER_ADMIN",configuration.webmaster); - ADD_STRING("GATEWAY_INTERFACE", "CGI/1.1"); - - docroot = __unixify(WG(conn)->homedir,0,NULL,1024,0); - if (docroot) ADD_STRING("DOCUMENT_ROOT", docroot); - - ADD_FIELD("REQUEST_METHOD", methodstr); - ADD_FIELD("REQUEST_URI", requesturi); - ADD_STRING("PATH_TRANSLATED", SG(request_info).path_translated); - ADD_FIELD("SCRIPT_NAME", uri); - ADD_FIELD("PHP_SELF", uri); - ADD_FIELD("QUERY_STRING", args); - - - snprintf(buf, BUF_SIZE, "%d.%d.%d.%d", WG(conn)->ipaddr[0], WG(conn)->ipaddr[1], WG(conn)->ipaddr[2], WG(conn)->ipaddr[3]); - ADD_STRING("REMOTE_ADDR", buf); - if (WG(conn)->dnsstatus == DNS_OK) ADD_FIELD("REMOTE_HOST", host); - - if ((WG(conn)->method == METHOD_POST) || (WG(conn)->method == METHOD_PUT)) { - ADD_NUM("CONTENT_LENGTH", bodysize); - ADD_FIELD("CONTENT_TYPE", type); - } - - if ((WG(conn)->method == METHOD_PUT) || (WG(conn)->method == METHOD_DELETE)) ADD_FIELD("ENTITY_PATH", requesturi); - - if (WG(conn)->pwd) { - ADD_STRING("AUTH_TYPE", "basic"); - ADD_FIELD("REMOTE_USER", authorization); - } - - ADD_FIELD("HTTP_COOKIE", cookie); - ADD_FIELD("HTTP_USER_AGENT", useragent); - ADD_FIELD("HTTP_REFERER", referer); - ADD_FIELD("HTTP_ACCEPT", accept); - ADD_FIELD("HTTP_ACCEPT_LANGUAGE", acceptlanguage); - ADD_FIELD("HTTP_ACCEPT_CHARSET", acceptcharset); - ADD_FIELD("HTTP_ACCEPT_ENCODING", acceptencoding); -} - -static void webjames_module_main(void) -{ - zend_file_handle file_handle; - FILE *fp=NULL; - char *path; - - /* Convert filename to Unix format*/ - __riscosify_control|=__RISCOSIFY_STRICT_UNIX_SPECS; - path = __unixify(WG(conn)->filename,0,NULL,1024,0); - if (path) SG(request_info).path_translated = estrdup(path); - - SG(request_info).query_string = WG(conn)->args; - SG(request_info).request_uri = WG(conn)->requesturi; - SG(request_info).request_method = WG(conn)->methodstr; - if (WG(conn)->method==METHOD_HEAD) { - SG(request_info).headers_only = 1; - } else { - SG(request_info).headers_only = 0; - } - SG(sapi_headers).http_response_code = 200; - SG(request_info).content_type = WG(conn)->type; - SG(request_info).content_length = WG(conn)->bodysize; - - SG(request_info).auth_user = NULL; - SG(request_info).auth_password = NULL; - if (WG(conn)->authorization) { - char *colon=strchr(WG(conn)->authorization,':'); - if (colon) { - SG(request_info).auth_user = emalloc(colon-WG(conn)->authorization+1); - if (SG(request_info).auth_user) { - memcpy(SG(request_info).auth_user,WG(conn)->authorization,colon-WG(conn)->authorization); - SG(request_info).auth_user[colon-WG(conn)->authorization]='\0'; - SG(request_info).auth_password = estrdup(colon+1); - } - } - } - - /*ensure that syslog calls get logged separately from WebJames' main log */ - openlog("PHP",0,0); - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - - if (php_request_startup() == FAILURE) { - return; - } - - php_execute_script(&file_handle); - php_request_shutdown(NULL); -} - -static void webjames_php_close(struct connection *conn, int force) -/*called by webjames if it wants to close the connection*/ -{ - - php_request_shutdown(NULL); - WG(oldclose)(conn,force); -} - -void webjames_php_request(struct connection *conn) -/*called by WebJames to start handler*/ -{ - - WG(conn) = conn; - WG(bodyread) = 0; - WG(oldclose) = conn->close; - conn->close=webjames_php_close; - - webjames_module_main(); - - WG(oldclose)(WG(conn), 0); -} - -static void php_info_webjames(ZEND_MODULE_INFO_FUNC_ARGS) -{ - php_info_print_table_start(); - php_info_print_table_row(2, "SAPI module version", WEBJAMES_SAPI_VERSION); - php_info_print_table_row(2, "WebJames version", WEBJAMES_VERSION " (" WEBJAMES_DATE ")"); - php_info_print_table_end(); -} - -static zend_module_entry php_webjames_module = { -#if ZEND_MODULE_API_NO >= 20010901 - STANDARD_MODULE_HEADER, -#endif - "WebJames", - NULL, - NULL, - NULL, - NULL, - NULL, - php_info_webjames, -#if ZEND_MODULE_API_NO >= 20010901 - WEBJAMES_SAPI_VERSION, -#endif - STANDARD_MODULE_PROPERTIES -}; - - -static int php_webjames_startup(sapi_module_struct *sapi_module) -{ - if(php_module_startup(sapi_module, &php_webjames_module, 1) == FAILURE) { - return FAILURE; - } else { - return SUCCESS; - } -} - -static sapi_module_struct sapi_module = { - "webjames", /* name */ - "WebJames", /* pretty name */ - - php_webjames_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - NULL, /* deactivate */ - - sapi_webjames_ub_write, /* unbuffered write */ - NULL, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - NULL, /* header handler */ - NULL, /* send headers handler */ - sapi_webjames_send_header, /* send header handler */ - sapi_webjames_read_post, /* read POST data */ - sapi_webjames_read_cookies, /* read Cookies */ - - sapi_webjames_register_variables, /* register server variables */ - NULL, /* Log message */ - NULL, /* Get request time */ - NULL, /* Child terminate */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; - -int webjames_php_init(void) -/*called when WebJames initialises*/ -{ - if (strcmp(configuration.webjames_h_revision,WEBJAMES_H_REVISION)!=0) { - /*This file was compiled against a different revision of - webjames.h than webjames was, which could be bad news*/ - webjames_writelog(0,"PHP module is compiled for WebJames (%s) and was linked with a different version (%s)",WEBJAMES_H_REVISION,configuration.webjames_h_revision); - return 0; /*failed to initialise*/ - } - sapi_startup(&sapi_module); - sapi_module.startup(&sapi_module); - SG(server_context) = (void *) 1; - return 1; /*initialised correctly*/ -} - -void webjames_php_shutdown(void) -/*called when WebJames is about to quit*/ -{ - sapi_module.shutdown(&sapi_module); - sapi_shutdown(); -} diff --git a/tests/lang/bug23624.phpt b/tests/lang/bug23624.phpt index 4ddb82e8c6885..f8778fffe380b 100644 --- a/tests/lang/bug23624.phpt +++ b/tests/lang/bug23624.phpt @@ -9,4 +9,4 @@ Bug #23624 (foreach leaves current array key as null) ?> --EXPECT-- string(3) "one" -bool(false) +string(3) "one" diff --git a/tests/lang/foreachLoop.001.phpt b/tests/lang/foreachLoop.001.phpt index b24f14e81d6b4..d35f26116dcdc 100644 --- a/tests/lang/foreachLoop.001.phpt +++ b/tests/lang/foreachLoop.001.phpt @@ -60,5 +60,5 @@ string(1) "f" int(2) string(1) "f" -bool(false) -bool(false) +string(1) "a" +string(1) "a" diff --git a/tests/lang/foreachLoop.009.phpt b/tests/lang/foreachLoop.009.phpt index 4586a35a10f86..df51fd6be4f95 100644 --- a/tests/lang/foreachLoop.009.phpt +++ b/tests/lang/foreachLoop.009.phpt @@ -55,6 +55,7 @@ foreach ($refedArray as $k=>&$v4) { Remove elements from a referenced array during loop key: 0; value: original.0 key: 1; value: original.1 +key: 2; value: original.2 Remove elements from a referenced array during loop, using &$value key: 0; value: original.0 @@ -64,11 +65,6 @@ Add elements to a referenced array during loop key: 0; value: original.0 key: 1; value: original.1 key: 2; value: original.2 -key: 3; value: new.0 -key: 4; value: new.1 -key: 5; value: new.2 -key: 6; value: new.3 -Loop detected, as expected. Add elements to a referenced array during loop, using &$value key: 0; value: original.0 diff --git a/tests/lang/foreachLoop.011.phpt b/tests/lang/foreachLoop.011.phpt index 671cfaf354edd..8527a8833e4a7 100644 --- a/tests/lang/foreachLoop.011.phpt +++ b/tests/lang/foreachLoop.011.phpt @@ -25,10 +25,9 @@ foreach ($a as $v) { Change from array to non iterable: int(1) - -Warning: Invalid argument supplied for foreach() in %s on line 5 +int(2) +int(3) Change from object to non iterable: int(1) - -Warning: Invalid argument supplied for foreach() in %s on line 15 +int(2) diff --git a/tests/lang/foreachLoop.013.phpt b/tests/lang/foreachLoop.013.phpt index b0c5e8dcf51c1..ea728156f0f4e 100644 --- a/tests/lang/foreachLoop.013.phpt +++ b/tests/lang/foreachLoop.013.phpt @@ -1,7 +1,5 @@ --TEST-- Directly modifying an unreferenced array when foreach'ing over it while using &$value syntax. ---XFAIL-- -Needs major foreach changes to get sane behavior --FILE-- ---EXPECTF-- +--EXPECT-- Popping elements off end of an unreferenced array, using &$value. ---( Array with 1 element(s): )--- @@ -95,9 +93,10 @@ array(2) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=v.0 --> State of array after loop: -array(0) { +array(1) { + [0]=> + &string(3) "v.0" } ---( Array with 3 element(s): )--- @@ -134,10 +133,12 @@ array(4) { --> Do loop: iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 - iteration 2: $k=0; $v=v.0 - iteration 3: $k=0; $v=v.0 --> State of array after loop: -array(0) { +array(2) { + [0]=> + string(3) "v.0" + [1]=> + &string(3) "v.1" } @@ -289,12 +290,28 @@ array(1) { } --> Do loop: iteration 0: $k=0; $v=v.0 + iteration 1: $k=1; $v=new.0 + iteration 2: $k=2; $v=new.1 + iteration 3: $k=3; $v=new.2 + iteration 4: $k=4; $v=new.3 + iteration 5: $k=5; $v=new.4 + ** Stuck in a loop! ** --> State of array after loop: -array(2) { +array(7) { [0]=> - &string(3) "v.0" + string(3) "v.0" [1]=> string(5) "new.0" + [2]=> + string(5) "new.1" + [3]=> + string(5) "new.2" + [4]=> + string(5) "new.3" + [5]=> + &string(5) "new.4" + [6]=> + string(5) "new.5" } ---( Array with 2 element(s): )--- @@ -446,30 +463,17 @@ array(2) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=2; $v=v.1 --> State of array after loop: -array(8) { +array(4) { [0]=> - string(5) "new.5" - [1]=> - &string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> - string(5) "new.2" - [4]=> string(5) "new.1" - [5]=> + [1]=> string(5) "new.0" - [6]=> + [2]=> string(3) "v.0" - [7]=> - string(3) "v.1" + [3]=> + &string(3) "v.1" } ---( Array with 3 element(s): )--- @@ -484,32 +488,19 @@ array(3) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=3; $v=v.2 --> State of array after loop: -array(9) { +array(5) { [0]=> - string(5) "new.5" - [1]=> - &string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> - string(5) "new.2" - [4]=> string(5) "new.1" - [5]=> + [1]=> string(5) "new.0" - [6]=> + [2]=> string(3) "v.0" - [7]=> + [3]=> string(3) "v.1" - [8]=> - string(3) "v.2" + [4]=> + &string(3) "v.2" } ---( Array with 4 element(s): )--- @@ -526,32 +517,19 @@ array(4) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=4; $v=v.3 --> State of array after loop: -array(10) { +array(6) { [0]=> - string(5) "new.5" - [1]=> - &string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> - string(5) "new.2" - [4]=> string(5) "new.1" - [5]=> + [1]=> string(5) "new.0" - [6]=> + [2]=> string(3) "v.0" - [7]=> + [3]=> string(3) "v.1" - [8]=> + [4]=> string(3) "v.2" - [9]=> - string(3) "v.3" + [5]=> + &string(3) "v.3" } diff --git a/tests/lang/foreachLoop.014.phpt b/tests/lang/foreachLoop.014.phpt index d32ea635fda7f..9b179ab22a7f9 100644 --- a/tests/lang/foreachLoop.014.phpt +++ b/tests/lang/foreachLoop.014.phpt @@ -1,7 +1,5 @@ --TEST-- Directly modifying a REFERENCED array when foreach'ing over it. ---XFAIL-- -Needs major foreach changes to get sane behavior --FILE-- Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=v.0 + iteration 1: $k=1; $v=v.1 --> State of array after loop: array(0) { } @@ -114,10 +112,9 @@ array(3) { --> Do loop: iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 + iteration 2: $k=2; $v=v.2 --> State of array after loop: -array(1) { - [0]=> - string(3) "v.0" +array(0) { } ---( Array with 4 element(s): )--- @@ -135,8 +132,8 @@ array(4) { --> Do loop: iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 - iteration 2: $k=0; $v=v.0 - iteration 3: $k=0; $v=v.0 + iteration 2: $k=2; $v=v.2 + iteration 3: $k=3; $v=v.3 --> State of array after loop: array(0) { } @@ -166,7 +163,7 @@ array(2) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=v.1 + iteration 1: $k=1; $v=v.1 --> State of array after loop: array(0) { } @@ -183,8 +180,8 @@ array(3) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=v.1 - iteration 2: $k=0; $v=v.2 + iteration 1: $k=1; $v=v.1 + iteration 2: $k=2; $v=v.2 --> State of array after loop: array(0) { } @@ -203,9 +200,9 @@ array(4) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=v.1 - iteration 2: $k=0; $v=v.2 - iteration 3: $k=0; $v=v.3 + iteration 1: $k=1; $v=v.1 + iteration 2: $k=2; $v=v.2 + iteration 3: $k=3; $v=v.3 --> State of array after loop: array(0) { } @@ -309,13 +306,8 @@ array(2) { --> Do loop: iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 - iteration 2: $k=2; $v=new.0 - iteration 3: $k=3; $v=new.1 - iteration 4: $k=4; $v=new.2 - iteration 5: $k=5; $v=new.3 - ** Stuck in a loop! ** --> State of array after loop: -array(8) { +array(4) { [0]=> string(3) "v.0" [1]=> @@ -324,14 +316,6 @@ array(8) { string(5) "new.0" [3]=> string(5) "new.1" - [4]=> - string(5) "new.2" - [5]=> - string(5) "new.3" - [6]=> - string(5) "new.4" - [7]=> - string(5) "new.5" } ---( Array with 3 element(s): )--- @@ -348,12 +332,8 @@ array(3) { iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 iteration 2: $k=2; $v=v.2 - iteration 3: $k=3; $v=new.0 - iteration 4: $k=4; $v=new.1 - iteration 5: $k=5; $v=new.2 - ** Stuck in a loop! ** --> State of array after loop: -array(9) { +array(6) { [0]=> string(3) "v.0" [1]=> @@ -366,12 +346,6 @@ array(9) { string(5) "new.1" [5]=> string(5) "new.2" - [6]=> - string(5) "new.3" - [7]=> - string(5) "new.4" - [8]=> - string(5) "new.5" } ---( Array with 4 element(s): )--- @@ -391,11 +365,8 @@ array(4) { iteration 1: $k=1; $v=v.1 iteration 2: $k=2; $v=v.2 iteration 3: $k=3; $v=v.3 - iteration 4: $k=4; $v=new.0 - iteration 5: $k=5; $v=new.1 - ** Stuck in a loop! ** --> State of array after loop: -array(10) { +array(8) { [0]=> string(3) "v.0" [1]=> @@ -412,10 +383,6 @@ array(10) { string(5) "new.2" [7]=> string(5) "new.3" - [8]=> - string(5) "new.4" - [9]=> - string(5) "new.5" } @@ -447,29 +414,16 @@ array(2) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=1; $v=v.1 --> State of array after loop: -array(8) { +array(4) { [0]=> - string(5) "new.5" - [1]=> - string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> - string(5) "new.2" - [4]=> string(5) "new.1" - [5]=> + [1]=> string(5) "new.0" - [6]=> + [2]=> string(3) "v.0" - [7]=> + [3]=> string(3) "v.1" } @@ -485,31 +439,21 @@ array(3) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=1; $v=v.1 + iteration 2: $k=2; $v=v.2 --> State of array after loop: -array(9) { +array(6) { [0]=> - string(5) "new.5" - [1]=> - string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> string(5) "new.2" - [4]=> + [1]=> string(5) "new.1" - [5]=> + [2]=> string(5) "new.0" - [6]=> + [3]=> string(3) "v.0" - [7]=> + [4]=> string(3) "v.1" - [8]=> + [5]=> string(3) "v.2" } @@ -527,32 +471,25 @@ array(4) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=1; $v=v.1 + iteration 2: $k=2; $v=v.2 + iteration 3: $k=3; $v=v.3 --> State of array after loop: -array(10) { +array(8) { [0]=> - string(5) "new.5" - [1]=> - string(5) "new.4" - [2]=> string(5) "new.3" - [3]=> + [1]=> string(5) "new.2" - [4]=> + [2]=> string(5) "new.1" - [5]=> + [3]=> string(5) "new.0" - [6]=> + [4]=> string(3) "v.0" - [7]=> + [5]=> string(3) "v.1" - [8]=> + [6]=> string(3) "v.2" - [9]=> + [7]=> string(3) "v.3" } diff --git a/tests/lang/foreachLoop.015.phpt b/tests/lang/foreachLoop.015.phpt index 5b12a2b0c269f..a4ee09d6a9690 100644 --- a/tests/lang/foreachLoop.015.phpt +++ b/tests/lang/foreachLoop.015.phpt @@ -1,7 +1,5 @@ --TEST-- Directly modifying a REFERENCED array when foreach'ing over it while using &$value syntax. ---XFAIL-- -Needs major foreach changes to get sane behavior --FILE-- ---EXPECTF-- +--EXPECT-- Popping elements off end of a referenced array, using &$value ---( Array with 1 element(s): )--- @@ -97,9 +95,10 @@ array(2) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=v.0 --> State of array after loop: -array(0) { +array(1) { + [0]=> + &string(3) "v.0" } ---( Array with 3 element(s): )--- @@ -136,10 +135,12 @@ array(4) { --> Do loop: iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 - iteration 2: $k=0; $v=v.0 - iteration 3: $k=0; $v=v.0 --> State of array after loop: -array(0) { +array(2) { + [0]=> + string(3) "v.0" + [1]=> + &string(3) "v.1" } @@ -291,12 +292,28 @@ array(1) { } --> Do loop: iteration 0: $k=0; $v=v.0 + iteration 1: $k=1; $v=new.0 + iteration 2: $k=2; $v=new.1 + iteration 3: $k=3; $v=new.2 + iteration 4: $k=4; $v=new.3 + iteration 5: $k=5; $v=new.4 + ** Stuck in a loop! ** --> State of array after loop: -array(2) { +array(7) { [0]=> - &string(3) "v.0" + string(3) "v.0" [1]=> string(5) "new.0" + [2]=> + string(5) "new.1" + [3]=> + string(5) "new.2" + [4]=> + string(5) "new.3" + [5]=> + &string(5) "new.4" + [6]=> + string(5) "new.5" } ---( Array with 2 element(s): )--- @@ -448,30 +465,17 @@ array(2) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=2; $v=v.1 --> State of array after loop: -array(8) { +array(4) { [0]=> - string(5) "new.5" - [1]=> - &string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> - string(5) "new.2" - [4]=> string(5) "new.1" - [5]=> + [1]=> string(5) "new.0" - [6]=> + [2]=> string(3) "v.0" - [7]=> - string(3) "v.1" + [3]=> + &string(3) "v.1" } ---( Array with 3 element(s): )--- @@ -486,32 +490,19 @@ array(3) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=3; $v=v.2 --> State of array after loop: -array(9) { +array(5) { [0]=> - string(5) "new.5" - [1]=> - &string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> - string(5) "new.2" - [4]=> string(5) "new.1" - [5]=> + [1]=> string(5) "new.0" - [6]=> + [2]=> string(3) "v.0" - [7]=> + [3]=> string(3) "v.1" - [8]=> - string(3) "v.2" + [4]=> + &string(3) "v.2" } ---( Array with 4 element(s): )--- @@ -528,32 +519,19 @@ array(4) { } --> Do loop: iteration 0: $k=0; $v=v.0 - iteration 1: $k=0; $v=new.0 - iteration 2: $k=0; $v=new.1 - iteration 3: $k=0; $v=new.2 - iteration 4: $k=0; $v=new.3 - iteration 5: $k=0; $v=new.4 - ** Stuck in a loop! ** + iteration 1: $k=4; $v=v.3 --> State of array after loop: -array(10) { +array(6) { [0]=> - string(5) "new.5" - [1]=> - &string(5) "new.4" - [2]=> - string(5) "new.3" - [3]=> - string(5) "new.2" - [4]=> string(5) "new.1" - [5]=> + [1]=> string(5) "new.0" - [6]=> + [2]=> string(3) "v.0" - [7]=> + [3]=> string(3) "v.1" - [8]=> + [4]=> string(3) "v.2" - [9]=> - string(3) "v.3" + [5]=> + &string(3) "v.3" } diff --git a/tests/lang/foreachLoopObjects.006.phpt b/tests/lang/foreachLoopObjects.006.phpt index 8218b44dab929..5204aca9caf1e 100644 --- a/tests/lang/foreachLoopObjects.006.phpt +++ b/tests/lang/foreachLoopObjects.006.phpt @@ -70,16 +70,12 @@ var_dump($obj); ?> --EXPECTF-- - Substituting the iterated object for a different object. string(10) "Original a" string(10) "Original b" -string(5) "new a" -string(5) "new b" -string(5) "new c" -string(5) "new d" -string(5) "new e" -string(5) "new f" +string(10) "Original c" +string(10) "Original d" +string(10) "Original e" object(stdClass)#%d (6) { ["a"]=> string(5) "new a" @@ -98,14 +94,9 @@ object(stdClass)#%d (6) { Substituting the iterated object for an array. string(10) "Original a" string(10) "Original b" -int(1) -int(2) -int(3) -int(4) -int(5) -int(6) -int(7) -int(8) +string(10) "Original c" +string(10) "Original d" +string(10) "Original e" array(8) { [0]=> int(1) @@ -128,11 +119,12 @@ array(8) { Substituting the iterated array for an object. int(1) int(2) -string(10) "Original a" -string(10) "Original b" -string(10) "Original c" -string(10) "Original d" -string(10) "Original e" +int(3) +int(4) +int(5) +int(6) +int(7) +int(8) object(C)#%d (5) { ["a"]=> string(10) "Original a" diff --git a/travis/compile.sh b/travis/compile.sh index 2a78beeea5a9e..77ff49ab15ee4 100755 --- a/travis/compile.sh +++ b/travis/compile.sh @@ -62,4 +62,5 @@ $TS \ --with-xpm-dir=/usr \ --with-kerberos \ --enable-sysvmsg -make --quiet +make -j2 --quiet +sudo make install diff --git a/win32/registry.c b/win32/registry.c index 272246420b3fb..3d4496094b650 100644 --- a/win32/registry.c +++ b/win32/registry.c @@ -239,21 +239,11 @@ void UpdateIniFromRegistry(char *path) if (pht != NULL) { HashTable *ht = pht; zend_string *index; - zend_ulong num; zval *data; - ZEND_HASH_FOREACH_KEY_VAL(ht, num, index, data) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, index, data) { zend_alter_ini_entry(index, Z_STR_P(data), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); } ZEND_HASH_FOREACH_END(); -/* - for (zend_hash_internal_pointer_reset_ex(ht, &pos); - zend_hash_get_current_data_ex(ht, (void**)&data, &pos) == SUCCESS && - zend_hash_get_current_key_ex(ht, &index, &index_len, &num, 0, &pos) == HASH_KEY_IS_STRING; - zend_hash_move_forward_ex(ht, &pos)) { - zend_alter_ini_entry(index, index_len, Z_STRVAL_PP(data), Z_STRLEN_PP(data), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - } - break; -*/ } if (--path_len > 0) { diff --git a/win32/sendmail.c b/win32/sendmail.c index 0254d82ee907e..fd7424dda7306 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -168,15 +168,16 @@ static zend_string *php_win32_mail_trim_header(char *header) regex = zend_string_init(PHP_WIN32_MAIL_UNIFY_PATTERN, sizeof(PHP_WIN32_MAIL_UNIFY_PATTERN)-1, 0); result = php_pcre_replace(regex, - header, (int)strlen(header), + NULL, header, (int)strlen(header), &replace, 0, -1, NULL); + zval_ptr_dtor(&replace); + zend_string_release(regex); + if (NULL == result) { - zval_ptr_dtor(&replace); - zend_string_free(regex); return NULL; } @@ -184,12 +185,16 @@ static zend_string *php_win32_mail_trim_header(char *header) regex = zend_string_init(PHP_WIN32_MAIL_RMVDBL_PATTERN, sizeof(PHP_WIN32_MAIL_RMVDBL_PATTERN)-1, 0); result2 = php_pcre_replace(regex, - result->val, (int)result->len, + result, result->val, (int)result->len, &replace, 0, -1, NULL); - return result; + zval_ptr_dtor(&replace); + zend_string_release(regex); + zend_string_release(result); + + return result2; #else /* In case we don't have PCRE support (for whatever reason...) simply do nothing and return the unmodified header */ return estrdup(header); From 4ab69372845849e8285ceefe559c147873f4317e Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sat, 14 Feb 2015 03:11:05 +0000 Subject: [PATCH 29/29] Void return type --- Zend/tests/return_types/void.phpt | 20 ++++++++++++++++ Zend/tests/return_types/void2.phpt | 13 +++++++++++ Zend/tests/return_types/void3.phpt | 13 +++++++++++ Zend/tests/return_types/void_reserved.phpt | 8 +++++++ .../void_reserved_class_alias.phpt | 9 ++++++++ .../tests/return_types/void_reserved_use.phpt | 8 +++++++ Zend/zend_API.c | 2 ++ Zend/zend_compile.c | 4 ++++ Zend/zend_execute.c | 23 ++++++++++++++++++- Zend/zend_execute.h | 1 + Zend/zend_types.h | 1 + 11 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/return_types/void.phpt create mode 100644 Zend/tests/return_types/void2.phpt create mode 100644 Zend/tests/return_types/void3.phpt create mode 100644 Zend/tests/return_types/void_reserved.phpt create mode 100644 Zend/tests/return_types/void_reserved_class_alias.phpt create mode 100644 Zend/tests/return_types/void_reserved_use.phpt diff --git a/Zend/tests/return_types/void.phpt b/Zend/tests/return_types/void.phpt new file mode 100644 index 0000000000000..6f4fd32b88353 --- /dev/null +++ b/Zend/tests/return_types/void.phpt @@ -0,0 +1,20 @@ +--TEST-- +void return type: allowed +--FILE-- +type_hint = type; goto done; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index c37eeb357365f..8b657d4157185 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -830,6 +830,25 @@ ZEND_API void zend_verify_return_error(int error_type, const zend_function *zf, fclass, fsep, fname, need_msg, need_kind, returned_msg, returned_kind); } +ZEND_API void zend_verify_void_return_error(int error_type, const zend_function *zf, const char *returned_kind) +{ + const char *fname = zf->common.function_name->val; + const char *fsep; + const char *fclass; + + if (zf->common.scope) { + fsep = "::"; + fclass = zf->common.scope->name->val; + } else { + fsep = ""; + fclass = ""; + } + + zend_error(error_type, + "%s%s%s() must not return a value, %s returned", + fclass, fsep, fname, returned_kind); +} + #if ZEND_DEBUG static int zend_verify_internal_return_type(zend_function *zf, zval *ret) { @@ -900,6 +919,8 @@ static void zend_verify_return_type(zend_function *zf, zval *ret, zend_bool stri if (!zend_is_callable(ret, IS_CALLABLE_CHECK_SILENT, NULL) && (Z_TYPE_P(ret) != IS_NULL || !ret_info->allow_null)) { zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be callable", "", zend_zval_type_name(ret), ""); } + } else if (ret_info->type_hint == IS_VOID) { + zend_verify_void_return_error(E_RECOVERABLE_ERROR, zf, zend_zval_type_name(ret)); } else if (UNEXPECTED(!ZEND_SAME_FAKE_TYPE(ret_info->type_hint, Z_TYPE_P(ret)))) { if (Z_TYPE_P(ret) == IS_NULL) { if (!ret_info->allow_null) { @@ -927,7 +948,7 @@ static inline int zend_verify_missing_return_type(zend_function *zf) need_msg = zend_verify_arg_class_kind(ret_info, &class_name, &ce); zend_verify_return_error(E_RECOVERABLE_ERROR, zf, need_msg, class_name, "no value", ""); return 0; - } else if (ret_info->type_hint) { + } else if (ret_info->type_hint && ret_info->type_hint != IS_VOID) { if (ret_info->type_hint == IS_ARRAY) { zend_verify_return_error(E_RECOVERABLE_ERROR, zf, "be of the type array", "", "no value", ""); } else if (ret_info->type_hint == IS_CALLABLE) { diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h index 0fdf76453d0c4..d411717ae0599 100644 --- a/Zend/zend_execute.h +++ b/Zend/zend_execute.h @@ -51,6 +51,7 @@ ZEND_API char * zend_verify_internal_arg_class_kind(const zend_internal_arg_info ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, char **class_name, zend_class_entry **pce); ZEND_API void zend_verify_arg_error(int error_type, const zend_function *zf, uint32_t arg_num, const char *need_msg, const char *need_kind, const char *given_msg, const char *given_kind, zval *arg); ZEND_API void zend_verify_return_error(int error_type, const zend_function *zf, const char *need_msg, const char *need_kind, const char *returned_msg, const char *returned_kind); +ZEND_API void zend_verify_void_return_error(int error_type, const zend_function *zf, const char *returned_kind); static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type) { diff --git a/Zend/zend_types.h b/Zend/zend_types.h index f4668b3d37e9a..51170f1817dbf 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -239,6 +239,7 @@ struct _zend_ast_ref { /* fake types */ #define _IS_BOOL 13 #define IS_CALLABLE 14 +#define IS_VOID 18 /* internal types */ #define IS_INDIRECT 15