Skip to content

Commit

Permalink
Remove --enable-yaf-debug, now users are able to change $_POST etc in…
Browse files Browse the repository at this point in the history
… place
  • Loading branch information
laruence committed Mar 15, 2020
1 parent fe53248 commit 82ed34b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 82 deletions.
11 changes: 0 additions & 11 deletions config.m4
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
PHP_ARG_ENABLE(yaf, whether to enable yaf support,
[ --enable-yaf Enable yaf support])

AC_ARG_ENABLE(yaf-debug,
[ --enable-yaf-debug Enable yaf debug mode default=no],
[PHP_YAF_DEBUG=$enableval],
[PHP_YAF_DEBUG="no"])

if test "$PHP_YAF" != "no"; then

if test "$PHP_YAF_DEBUG" = "yes"; then
AC_DEFINE(PHP_YAF_DEBUG,1,[define to 1 if you want to change the POST/GET by php script])
else
AC_DEFINE(PHP_YAF_DEBUG,0,[define to 1 if you want to change the POST/GET by php script])
fi

AC_MSG_CHECKING([PHP version])

tmp_version=$PHP_VERSION
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<file name="088.phpt" role="test" />
<file name="089.phpt" role="test" />
<file name="090.phpt" role="test" />
<file name="091.phpt" role="test" />
<file name="build.inc" role="test" />
<file name="bug61493.phpt" role="test" />
<file name="bug63381.phpt" role="test" />
Expand Down
38 changes: 38 additions & 0 deletions tests/091.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Check for Yaf_Request_getXXX
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--GET--
name=get
--POST--
name=raw
--FILE--
<?php
$_SERVER["name"] = "server";
$_COOKIE["name"] = "cookie";
$_POST["name"] = "post";
$_ENV["name"] = "env";
$_REQUEST["name"] = "request";

$request = new Yaf_Request_Http("/");

var_dump($request->getServer("name"));
var_dump($request->getQuery("name"));
var_dump($request->getCookie("name"));
var_dump($request->getPost("name"));
var_dump($request->getEnv("name"));
var_dump($request->getRequest("name"));
var_dump($request->getRaw());
?>
--EXPECT--
string(6) "server"
string(3) "get"
string(6) "cookie"
string(4) "post"
string(3) "env"
string(7) "request"
string(8) "name=raw"
96 changes: 29 additions & 67 deletions yaf_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,96 +176,58 @@ int yaf_request_set_base_uri(yaf_request_t *request, zend_string *base_uri, zend
}
/* }}} */

zval *yaf_request_query_ex(unsigned type, zend_bool fetch_type, void *name, size_t len) /* {{{ */ {
zval *carrier = NULL, *ret;

static inline zval* yaf_request_fetch_container(unsigned type) /* {{{ */ {
zend_bool jit_initialization = PG(auto_globals_jit);

/* for phpunit test requirements */
#if PHP_YAF_DEBUG
switch (type) {
case YAF_GLOBAL_VARS_POST:
carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_POST"));
break;
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_POST"));
case YAF_GLOBAL_VARS_GET:
carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_GET"));
break;
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_GET"));
case YAF_GLOBAL_VARS_COOKIE:
carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_COOKIE"));
break;
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_COOKIE"));
case YAF_GLOBAL_VARS_FILES:
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_FILES"));
case YAF_GLOBAL_VARS_SERVER:
if (jit_initialization) {
zend_is_auto_global_str(ZEND_STRL("_SERVER"));
}
carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER"));
break;
case YAF_GLOBAL_VARS_ENV:
if (jit_initialization) {
zend_is_auto_global_str(ZEND_STRL("_ENV"));
}
carrier = &PG(http_globals)[YAF_GLOBAL_VARS_ENV];
break;
case YAF_GLOBAL_VARS_FILES:
carrier = &PG(http_globals)[YAF_GLOBAL_VARS_FILES];
break;
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER"));
case YAF_GLOBAL_VARS_REQUEST:
if (jit_initialization) {
zend_is_auto_global_str(ZEND_STRL("_REQUEST"));
}
carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_REQUEST"));
break;
default:
break;
}
#else
switch (type) {
case YAF_GLOBAL_VARS_POST:
case YAF_GLOBAL_VARS_GET:
case YAF_GLOBAL_VARS_FILES:
case YAF_GLOBAL_VARS_COOKIE:
carrier = &PG(http_globals)[type];
break;
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_REQUEST"));
case YAF_GLOBAL_VARS_ENV:
if (jit_initialization) {
zend_is_auto_global_str(ZEND_STRL("_ENV"));
}
carrier = &PG(http_globals)[type];
break;
case YAF_GLOBAL_VARS_SERVER:
if (jit_initialization) {
zend_is_auto_global_str(ZEND_STRL("_SERVER"));
}
carrier = &PG(http_globals)[type];
break;
case YAF_GLOBAL_VARS_REQUEST:
if (jit_initialization) {
zend_is_auto_global_str(ZEND_STRL("_REQUEST"));
}
carrier = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_REQUEST"));
break;
return zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_ENV"));
default:
break;
return NULL;
}
#endif
}
/* }}} */

zval *yaf_request_query_str(unsigned type, const char *name, size_t len) /* {{{ */ {
zval *container = yaf_request_fetch_container(type);

if (!carrier) {
if (UNEXPECTED(!container)) {
return NULL;
}

if (!name) {
return carrier;
}
return zend_hash_str_find(Z_ARRVAL_P(container), name, len);
}
/* }}} */

if (EXPECTED(fetch_type)) {
if ((ret = zend_hash_find(Z_ARRVAL_P(carrier), (zend_string *)name)) == NULL) {
return NULL;
}
} else {
if ((ret = zend_hash_str_find(Z_ARRVAL_P(carrier), (char *)name, len)) == NULL) {
return NULL;
}
zval *yaf_request_query(unsigned type, zend_string *name) /* {{{ */ {
zval *container = yaf_request_fetch_container(type);

if (UNEXPECTED(!container)) {
return NULL;
}
return ret;

return zend_hash_find(Z_ARRVAL_P(container), name);
}
/* }}} */

Expand All @@ -286,11 +248,11 @@ zval *yaf_request_get_language(yaf_request_t *instance, zval *accept_language) /
} else if (UNEXPECTED(IS_STRING != Z_TYPE_P(accept_langs) || !Z_STRLEN_P(accept_langs))) {
return NULL;
} else {
char *ptrptr, *seg;
char *ptrptr, *seg;
unsigned prefer_len = 0;
double max_qvlaue = 0;
char *prefer = NULL;
char *langs = estrndup(Z_STRVAL_P(accept_langs), Z_STRLEN_P(accept_langs));
char *prefer = NULL;
char *langs = estrndup(Z_STRVAL_P(accept_langs), Z_STRLEN_P(accept_langs));

seg = php_strtok_r(langs, ",", &ptrptr);
while (seg) {
Expand Down
7 changes: 3 additions & 4 deletions yaf_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ extern PHPAPI void php_session_start();

yaf_request_t *yaf_request_instance(yaf_request_t *this_ptr, zend_string *info);
int yaf_request_set_base_uri(yaf_request_t *request, zend_string *base_uri, zend_string *request_uri);
zval *yaf_request_query_ex(unsigned type, zend_bool fetch_type, void *name, size_t len);

zval *yaf_request_query(unsigned type, zend_string *name);
zval *yaf_request_query_str(unsigned type, const char *name, size_t len);

zval *yaf_request_get_method(yaf_request_t *instance);
zval *yaf_request_get_param(yaf_request_t *instance, zend_string *key);
Expand All @@ -60,9 +62,6 @@ int yaf_request_set_params_single(yaf_request_t *instance, zend_string *key, zva
int yaf_request_set_params_multi(yaf_request_t *instance, zval *values);
const char *yaf_request_get_request_method(void);

#define yaf_request_query(type, name) yaf_request_query_ex((type), 1, (name), 0)
#define yaf_request_query_str(type, name, len) yaf_request_query_ex((type), 0, (name), (len))

#define YAF_REQUEST_IS_METHOD(x) \
PHP_METHOD(yaf_request, is##x) {\
zval *method = zend_read_property(Z_OBJCE_P(getThis()), \
Expand Down

0 comments on commit 82ed34b

Please sign in to comment.