mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
Clean-up
Remove a lot of 100% redundent code
This commit is contained in:
parent
a86a08cc06
commit
1093ed17fb
5 changed files with 56 additions and 164 deletions
|
@ -372,7 +372,7 @@ function_entry basic_functions[] = {
|
||||||
PHP_FE(print_r, NULL)
|
PHP_FE(print_r, NULL)
|
||||||
|
|
||||||
PHP_FE(setcookie, NULL)
|
PHP_FE(setcookie, NULL)
|
||||||
PHP_NAMED_FE(header, PHP_FN(Header), NULL)
|
PHP_FE(header, NULL)
|
||||||
PHP_FE(headers_sent, NULL)
|
PHP_FE(headers_sent, NULL)
|
||||||
|
|
||||||
PHP_FE(connection_aborted, NULL)
|
PHP_FE(connection_aborted, NULL)
|
||||||
|
@ -857,7 +857,6 @@ PHP_RINIT_FUNCTION(basic)
|
||||||
PHP_RINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
|
PHP_RINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PHP_RINIT(head)(INIT_FUNC_ARGS_PASSTHRU);
|
|
||||||
PHP_RINIT(filestat)(INIT_FUNC_ARGS_PASSTHRU);
|
PHP_RINIT(filestat)(INIT_FUNC_ARGS_PASSTHRU);
|
||||||
PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
|
PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
|
||||||
PHP_RINIT(assert)(INIT_FUNC_ARGS_PASSTHRU);
|
PHP_RINIT(assert)(INIT_FUNC_ARGS_PASSTHRU);
|
||||||
|
|
|
@ -34,34 +34,10 @@
|
||||||
#include "safe_mode.h"
|
#include "safe_mode.h"
|
||||||
|
|
||||||
|
|
||||||
/* need to figure out some nice way to get rid of these */
|
|
||||||
#ifndef THREAD_SAFE
|
|
||||||
static int php_header_printed = 0;
|
|
||||||
static int php_print_header = 1;
|
|
||||||
static CookieList *top = NULL;
|
|
||||||
static char *cont_type = NULL;
|
|
||||||
static int header_called = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void php_push_cookie_list(char *, char *, time_t, char *, char *, int);
|
|
||||||
CookieList *php_pop_cookie_list(void);
|
|
||||||
|
|
||||||
PHP_RINIT_FUNCTION(head)
|
|
||||||
{
|
|
||||||
php_header_printed = 0;
|
|
||||||
if (header_called == 0)
|
|
||||||
php_print_header = 1;
|
|
||||||
top = NULL;
|
|
||||||
cont_type = NULL;
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Implementation of the language Header() function */
|
/* Implementation of the language Header() function */
|
||||||
/* {{{ proto void header(string header[, bool replace])
|
/* {{{ proto void header(string header[, bool replace])
|
||||||
Send a raw HTTP header */
|
Send a raw HTTP header */
|
||||||
PHP_FUNCTION(Header)
|
PHP_FUNCTION(header)
|
||||||
{
|
{
|
||||||
pval **arg1, **arg2;
|
pval **arg1, **arg2;
|
||||||
zend_bool replace = 1;
|
zend_bool replace = 1;
|
||||||
|
@ -81,8 +57,6 @@ PHP_FUNCTION(Header)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ php_header
|
|
||||||
*/
|
|
||||||
PHPAPI int php_header()
|
PHPAPI int php_header()
|
||||||
{
|
{
|
||||||
SLS_FETCH();
|
SLS_FETCH();
|
||||||
|
@ -93,38 +67,8 @@ PHPAPI int php_header()
|
||||||
return 1; /* allow output */
|
return 1; /* allow output */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
/* {{{ php_push_cookie_list
|
|
||||||
*/
|
|
||||||
void php_push_cookie_list(char *name, char *value, time_t expires, char *path, char *domain, int secure)
|
|
||||||
{
|
|
||||||
CookieList *new;
|
|
||||||
|
|
||||||
new = emalloc(sizeof(CookieList));
|
|
||||||
new->next = top;
|
|
||||||
new->name = name;
|
|
||||||
new->value = value;
|
|
||||||
new->expires = expires;
|
|
||||||
new->path = path;
|
|
||||||
new->domain = domain;
|
|
||||||
new->secure = secure;
|
|
||||||
top = new;
|
|
||||||
}
|
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
/* {{{ php_pop_cookie_list
|
|
||||||
*/
|
|
||||||
CookieList *php_pop_cookie_list(void)
|
|
||||||
{
|
|
||||||
CookieList *ret;
|
|
||||||
|
|
||||||
ret = top;
|
|
||||||
if (top)
|
|
||||||
top = top->next;
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
/* php_set_cookie(name,value,expires,path,domain,secure) */
|
/* php_set_cookie(name,value,expires,path,domain,secure) */
|
||||||
/* {{{ proto void setcookie(string name [, string value [, int expires [, string path [, string domain [, string secure]]]]])
|
/* {{{ proto void setcookie(string name [, string value [, int expires [, string path [, string domain [, string secure]]]]])
|
||||||
|
@ -135,82 +79,72 @@ PHP_FUNCTION(setcookie)
|
||||||
int len=sizeof("Set-Cookie: ");
|
int len=sizeof("Set-Cookie: ");
|
||||||
time_t t;
|
time_t t;
|
||||||
char *dt;
|
char *dt;
|
||||||
char *name = NULL, *value = NULL, *path = NULL, *domain = NULL;
|
|
||||||
time_t expires = 0;
|
time_t expires = 0;
|
||||||
int secure = 0;
|
int secure = 0;
|
||||||
pval **arg[6];
|
pval **arg[6];
|
||||||
int arg_count;
|
int arg_count;
|
||||||
|
zval **z_name=NULL, **z_value=NULL, **z_path=NULL, **z_domain=NULL;
|
||||||
|
SLS_FETCH();
|
||||||
|
|
||||||
arg_count = ZEND_NUM_ARGS();
|
arg_count = ZEND_NUM_ARGS();
|
||||||
if (arg_count < 1 || arg_count > 6 || zend_get_parameters_array_ex(arg_count, arg) == FAILURE) {
|
if (arg_count < 1 || arg_count > 6 || zend_get_parameters_array_ex(arg_count, arg) == FAILURE) {
|
||||||
WRONG_PARAM_COUNT;
|
WRONG_PARAM_COUNT;
|
||||||
}
|
}
|
||||||
if (php_header_printed == 1) {
|
|
||||||
php_error(E_WARNING, "Oops, php_set_cookie called after header has been sent\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (arg_count) {
|
switch (arg_count) {
|
||||||
case 6:
|
case 6:
|
||||||
convert_to_boolean_ex(arg[5]);
|
convert_to_boolean_ex(arg[5]);
|
||||||
secure = (*arg[5])->value.lval;
|
secure = Z_LVAL_PP(arg[5]);
|
||||||
/* break missing intentionally */
|
/* break missing intentionally */
|
||||||
case 5:
|
case 5:
|
||||||
convert_to_string_ex(arg[4]);
|
convert_to_string_ex(arg[4]);
|
||||||
domain = estrndup((*arg[4])->value.str.val,(*arg[4])->value.str.len);
|
z_domain = arg[4];
|
||||||
/* break missing intentionally */
|
/* break missing intentionally */
|
||||||
case 4:
|
case 4:
|
||||||
convert_to_string_ex(arg[3]);
|
convert_to_string_ex(arg[3]);
|
||||||
path = estrndup((*arg[3])->value.str.val,(*arg[3])->value.str.len);
|
z_path = arg[3];
|
||||||
/* break missing intentionally */
|
/* break missing intentionally */
|
||||||
case 3:
|
case 3:
|
||||||
convert_to_long_ex(arg[2]);
|
convert_to_long_ex(arg[2]);
|
||||||
expires = (*arg[2])->value.lval;
|
expires = Z_LVAL_PP(arg[2]);
|
||||||
/* break missing intentionally */
|
/* break missing intentionally */
|
||||||
case 2:
|
case 2:
|
||||||
convert_to_string_ex(arg[1]);
|
convert_to_string_ex(arg[1]);
|
||||||
value = estrndup((*arg[1])->value.str.val,(*arg[1])->value.str.len);
|
z_value = arg[1];
|
||||||
/* break missing intentionally */
|
/* break missing intentionally */
|
||||||
case 1:
|
case 1:
|
||||||
convert_to_string_ex(arg[0]);
|
convert_to_string_ex(arg[0]);
|
||||||
name = estrndup((*arg[0])->value.str.val,(*arg[0])->value.str.len);
|
z_name = arg[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if 0
|
if (z_name) {
|
||||||
php_push_cookie_list(name, value, expires, path, domain, secure);
|
len += Z_STRLEN_PP(z_name);
|
||||||
#else
|
|
||||||
if (name) {
|
|
||||||
len += strlen(name);
|
|
||||||
}
|
}
|
||||||
if (value) {
|
if (z_value) {
|
||||||
encoded_value = php_url_encode(value, strlen (value));
|
int encoded_value_len;
|
||||||
len += strlen(encoded_value);
|
|
||||||
|
encoded_value = php_url_encode(Z_STRVAL_PP(z_value), Z_STRLEN_PP(z_value), &encoded_value_len);
|
||||||
|
len += encoded_value_len;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (z_path) {
|
||||||
len += strlen(path);
|
len += Z_STRLEN_PP(z_path);
|
||||||
}
|
}
|
||||||
if (domain) {
|
if (z_domain) {
|
||||||
len += strlen(domain);
|
len += Z_STRLEN_PP(z_domain);
|
||||||
}
|
}
|
||||||
cookie = emalloc(len + 100);
|
cookie = emalloc(len + 100);
|
||||||
if (!value || (value && !*value)) {
|
if (!Z_STRVAL_PP(z_value) || !Z_STRVAL_PP(z_value)[0]) {
|
||||||
/*
|
/*
|
||||||
* MSIE doesn't delete a cookie when you set it to a null value
|
* MSIE doesn't delete a cookie when you set it to a null value
|
||||||
* so in order to force cookies to be deleted, even on MSIE, we
|
* so in order to force cookies to be deleted, even on MSIE, we
|
||||||
* pick an expiry date 1 year and 1 second in the past
|
* pick an expiry date 1 year and 1 second in the past
|
||||||
*/
|
*/
|
||||||
sprintf(cookie, "Set-Cookie: %s=deleted", name);
|
|
||||||
strcat(cookie, "; expires=");
|
|
||||||
t = time(NULL) - 31536001;
|
t = time(NULL) - 31536001;
|
||||||
dt = php_std_date(t);
|
dt = php_std_date(t);
|
||||||
strcat(cookie, dt);
|
sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", Z_STRVAL_PP(z_name), dt);
|
||||||
efree(dt);
|
efree(dt);
|
||||||
} else {
|
} else {
|
||||||
/* FIXME: XXX: this is not binary data safe */
|
/* FIXME: XXX: this is not binary data safe */
|
||||||
sprintf(cookie, "Set-Cookie: %s=%s", name, value ? encoded_value : "");
|
sprintf(cookie, "Set-Cookie: %s=%s", Z_STRVAL_PP(z_name), Z_STRVAL_PP(z_value) ? encoded_value : "");
|
||||||
if (value) efree(value);
|
|
||||||
value=NULL;
|
|
||||||
if (name) efree(name);
|
|
||||||
name=NULL;
|
|
||||||
if (expires > 0) {
|
if (expires > 0) {
|
||||||
strcat(cookie, "; expires=");
|
strcat(cookie, "; expires=");
|
||||||
dt = php_std_date(expires);
|
dt = php_std_date(expires);
|
||||||
|
@ -219,19 +153,17 @@ PHP_FUNCTION(setcookie)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoded_value) efree(encoded_value);
|
if (encoded_value) {
|
||||||
|
efree(encoded_value);
|
||||||
if (path && strlen(path)) {
|
|
||||||
strcat(cookie, "; path=");
|
|
||||||
strcat(cookie, path);
|
|
||||||
efree(path);
|
|
||||||
path=NULL;
|
|
||||||
}
|
}
|
||||||
if (domain && strlen(domain)) {
|
|
||||||
|
if (Z_STRVAL_PP(z_path) && Z_STRLEN_PP(z_path)>0) {
|
||||||
|
strcat(cookie, "; path=");
|
||||||
|
strcat(cookie, Z_STRVAL_PP(z_path));
|
||||||
|
}
|
||||||
|
if (Z_STRVAL_PP(z_domain) && Z_STRLEN_PP(z_domain)>0) {
|
||||||
strcat(cookie, "; domain=");
|
strcat(cookie, "; domain=");
|
||||||
strcat(cookie, domain);
|
strcat(cookie, Z_STRVAL_PP(z_domain));
|
||||||
efree(domain);
|
|
||||||
domain=NULL;
|
|
||||||
}
|
}
|
||||||
if (secure) {
|
if (secure) {
|
||||||
strcat(cookie, "; secure");
|
strcat(cookie, "; secure");
|
||||||
|
@ -242,34 +174,9 @@ PHP_FUNCTION(setcookie)
|
||||||
} else {
|
} else {
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (domain) {
|
|
||||||
efree(domain);
|
|
||||||
}
|
|
||||||
if (path) {
|
|
||||||
efree(path);
|
|
||||||
}
|
|
||||||
if (name) {
|
|
||||||
efree(name);
|
|
||||||
}
|
|
||||||
if (value) {
|
|
||||||
efree(value);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ php_headers_unsent
|
|
||||||
*/
|
|
||||||
int php_headers_unsent(void)
|
|
||||||
{
|
|
||||||
if (php_header_printed!=1 || !php_print_header) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
/* {{{ proto int headers_sent(void)
|
/* {{{ proto int headers_sent(void)
|
||||||
Return true if headers have already been sent, false otherwise */
|
Return true if headers have already been sent, false otherwise */
|
||||||
|
@ -289,7 +196,6 @@ PHP_FUNCTION(headers_sent)
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* tab-width: 4
|
* tab-width: 4
|
||||||
* c-basic-offset: 4
|
* c-basic-offset: 4
|
||||||
* End:
|
|
||||||
* vim600: sw=4 ts=4 tw=78 fdm=marker
|
* vim600: sw=4 ts=4 tw=78 fdm=marker
|
||||||
* vim<600: sw=4 ts=4 tw=78
|
* vim<600: sw=4 ts=4 tw=78 * End:
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,31 +21,11 @@
|
||||||
#ifndef HEAD_H
|
#ifndef HEAD_H
|
||||||
#define HEAD_H
|
#define HEAD_H
|
||||||
|
|
||||||
/*
|
|
||||||
We are still using a PHP2-style Push/Pop list here as opposed
|
|
||||||
to the PHP built-in list functionality because of the nature
|
|
||||||
of this particular list. It is just used as a structured
|
|
||||||
buffer. Doing this with the built-in list code would require
|
|
||||||
some changes to allow a search for the first item with a
|
|
||||||
certain type. This type of search would not be optimal.
|
|
||||||
Private list management makes more sense here
|
|
||||||
*/
|
|
||||||
typedef struct CookieList {
|
|
||||||
char *name;
|
|
||||||
char *value;
|
|
||||||
time_t expires;
|
|
||||||
char *path;
|
|
||||||
char *domain;
|
|
||||||
int secure;
|
|
||||||
struct CookieList *next;
|
|
||||||
} CookieList;
|
|
||||||
|
|
||||||
extern PHP_RINIT_FUNCTION(head);
|
extern PHP_RINIT_FUNCTION(head);
|
||||||
PHP_FUNCTION(Header);
|
PHP_FUNCTION(header);
|
||||||
PHP_FUNCTION(setcookie);
|
PHP_FUNCTION(setcookie);
|
||||||
PHP_FUNCTION(headers_sent);
|
PHP_FUNCTION(headers_sent);
|
||||||
|
|
||||||
PHPAPI int php_header(void);
|
PHPAPI int php_header(void);
|
||||||
int php_headers_unsent(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -245,7 +245,7 @@ static unsigned char hexchars[] = "0123456789ABCDEF";
|
||||||
|
|
||||||
/* {{{ php_url_encode
|
/* {{{ php_url_encode
|
||||||
*/
|
*/
|
||||||
PHPAPI char *php_url_encode(char *s, int len)
|
PHPAPI char *php_url_encode(char *s, int len, int *new_length)
|
||||||
{
|
{
|
||||||
register int x, y;
|
register int x, y;
|
||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
|
@ -274,6 +274,9 @@ PHPAPI char *php_url_encode(char *s, int len)
|
||||||
#endif /*CHARSET_EBCDIC*/
|
#endif /*CHARSET_EBCDIC*/
|
||||||
}
|
}
|
||||||
str[y] = '\0';
|
str[y] = '\0';
|
||||||
|
if (new_length) {
|
||||||
|
*new_length = y;
|
||||||
|
}
|
||||||
return ((char *) str);
|
return ((char *) str);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -284,6 +287,7 @@ PHP_FUNCTION(urlencode)
|
||||||
{
|
{
|
||||||
pval **arg;
|
pval **arg;
|
||||||
char *str;
|
char *str;
|
||||||
|
int str_len;
|
||||||
|
|
||||||
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
|
||||||
WRONG_PARAM_COUNT;
|
WRONG_PARAM_COUNT;
|
||||||
|
@ -294,8 +298,8 @@ PHP_FUNCTION(urlencode)
|
||||||
var_reset(return_value);
|
var_reset(return_value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
str = php_url_encode((*arg)->value.str.val, (*arg)->value.str.len);
|
str = php_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &str_len);
|
||||||
RETVAL_STRING(str, 1);
|
RETVAL_STRINGL(str, str_len, 0);
|
||||||
efree(str);
|
efree(str);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -355,7 +359,7 @@ PHPAPI int php_url_decode(char *str, int len)
|
||||||
|
|
||||||
/* {{{ php_raw_url_encode
|
/* {{{ php_raw_url_encode
|
||||||
*/
|
*/
|
||||||
PHPAPI char *php_raw_url_encode(char *s, int len)
|
PHPAPI char *php_raw_url_encode(char *s, int len, int *new_length)
|
||||||
{
|
{
|
||||||
register int x, y;
|
register int x, y;
|
||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
|
@ -380,6 +384,9 @@ PHPAPI char *php_raw_url_encode(char *s, int len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str[y] = '\0';
|
str[y] = '\0';
|
||||||
|
if (new_length) {
|
||||||
|
*new_length = y;
|
||||||
|
}
|
||||||
return ((char *) str);
|
return ((char *) str);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -390,6 +397,7 @@ PHP_FUNCTION(rawurlencode)
|
||||||
{
|
{
|
||||||
pval **arg;
|
pval **arg;
|
||||||
char *str;
|
char *str;
|
||||||
|
int new_len;
|
||||||
|
|
||||||
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
|
||||||
WRONG_PARAM_COUNT;
|
WRONG_PARAM_COUNT;
|
||||||
|
@ -399,9 +407,8 @@ PHP_FUNCTION(rawurlencode)
|
||||||
if (!(*arg)->value.str.len) {
|
if (!(*arg)->value.str.len) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
str = php_raw_url_encode((*arg)->value.str.val, (*arg)->value.str.len);
|
str = php_raw_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &new_len);
|
||||||
RETVAL_STRING(str, 1);
|
RETVAL_STRINGL(str, new_len, 0);
|
||||||
efree(str);
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -31,12 +31,12 @@ typedef struct php_url {
|
||||||
char *fragment;
|
char *fragment;
|
||||||
} php_url;
|
} php_url;
|
||||||
|
|
||||||
PHPAPI void php_url_free(php_url *);
|
PHPAPI void php_url_free(php_url *theurl);
|
||||||
PHPAPI extern php_url *php_url_parse(char *);
|
PHPAPI php_url *php_url_parse(char *str);
|
||||||
PHPAPI extern int php_url_decode(char *, int); /* return value: length of decoded string */
|
PHPAPI int php_url_decode(char *str, int len); /* return value: length of decoded string */
|
||||||
PHPAPI extern char *php_url_encode(char *, int);
|
PHPAPI int php_raw_url_decode(char *str, int len); /* return value: length of decoded string */
|
||||||
PHPAPI extern int php_raw_url_decode(char *, int); /* return value: length of decoded string */
|
PHPAPI char *php_url_encode(char *s, int len, int *new_length);
|
||||||
PHPAPI extern char *php_raw_url_encode(char *, int);
|
PHPAPI char *php_raw_url_encode(char *s, int len, int *new_length);
|
||||||
|
|
||||||
PHP_FUNCTION(parse_url);
|
PHP_FUNCTION(parse_url);
|
||||||
PHP_FUNCTION(urlencode);
|
PHP_FUNCTION(urlencode);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue