#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 */
/* {{{ proto void header(string header[, bool replace])
Send a raw HTTP header */
-PHP_FUNCTION(Header)
+PHP_FUNCTION(header)
{
pval **arg1, **arg2;
zend_bool replace = 1;
}
/* }}} */
-/* {{{ php_header
- */
PHPAPI int php_header()
{
SLS_FETCH();
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) */
/* {{{ proto void setcookie(string name [, string value [, int expires [, string path [, string domain [, string secure]]]]])
int len=sizeof("Set-Cookie: ");
time_t t;
char *dt;
- char *name = NULL, *value = NULL, *path = NULL, *domain = NULL;
time_t expires = 0;
int secure = 0;
pval **arg[6];
int arg_count;
+ zval **z_name=NULL, **z_value=NULL, **z_path=NULL, **z_domain=NULL;
+ SLS_FETCH();
arg_count = ZEND_NUM_ARGS();
if (arg_count < 1 || arg_count > 6 || zend_get_parameters_array_ex(arg_count, arg) == FAILURE) {
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) {
case 6:
convert_to_boolean_ex(arg[5]);
- secure = (*arg[5])->value.lval;
+ secure = Z_LVAL_PP(arg[5]);
/* break missing intentionally */
case 5:
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 */
case 4:
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 */
case 3:
convert_to_long_ex(arg[2]);
- expires = (*arg[2])->value.lval;
+ expires = Z_LVAL_PP(arg[2]);
/* break missing intentionally */
case 2:
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 */
case 1:
convert_to_string_ex(arg[0]);
- name = estrndup((*arg[0])->value.str.val,(*arg[0])->value.str.len);
+ z_name = arg[0];
break;
}
-#if 0
- php_push_cookie_list(name, value, expires, path, domain, secure);
-#else
- if (name) {
- len += strlen(name);
+ if (z_name) {
+ len += Z_STRLEN_PP(z_name);
}
- if (value) {
- encoded_value = php_url_encode(value, strlen (value));
- len += strlen(encoded_value);
+ if (z_value) {
+ int encoded_value_len;
+
+ encoded_value = php_url_encode(Z_STRVAL_PP(z_value), Z_STRLEN_PP(z_value), &encoded_value_len);
+ len += encoded_value_len;
}
- if (path) {
- len += strlen(path);
+ if (z_path) {
+ len += Z_STRLEN_PP(z_path);
}
- if (domain) {
- len += strlen(domain);
+ if (z_domain) {
+ len += Z_STRLEN_PP(z_domain);
}
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
* 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
*/
- sprintf(cookie, "Set-Cookie: %s=deleted", name);
- strcat(cookie, "; expires=");
t = time(NULL) - 31536001;
dt = php_std_date(t);
- strcat(cookie, dt);
+ sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", Z_STRVAL_PP(z_name), dt);
efree(dt);
} else {
/* FIXME: XXX: this is not binary data safe */
- sprintf(cookie, "Set-Cookie: %s=%s", name, value ? encoded_value : "");
- if (value) efree(value);
- value=NULL;
- if (name) efree(name);
- name=NULL;
+ sprintf(cookie, "Set-Cookie: %s=%s", Z_STRVAL_PP(z_name), Z_STRVAL_PP(z_value) ? encoded_value : "");
if (expires > 0) {
strcat(cookie, "; expires=");
dt = php_std_date(expires);
}
}
- if (encoded_value) efree(encoded_value);
+ if (encoded_value) {
+ efree(encoded_value);
+ }
- if (path && strlen(path)) {
+ if (Z_STRVAL_PP(z_path) && Z_STRLEN_PP(z_path)>0) {
strcat(cookie, "; path=");
- strcat(cookie, path);
- efree(path);
- path=NULL;
+ strcat(cookie, Z_STRVAL_PP(z_path));
}
- if (domain && strlen(domain)) {
+ if (Z_STRVAL_PP(z_domain) && Z_STRLEN_PP(z_domain)>0) {
strcat(cookie, "; domain=");
- strcat(cookie, domain);
- efree(domain);
- domain=NULL;
+ strcat(cookie, Z_STRVAL_PP(z_domain));
}
if (secure) {
strcat(cookie, "; secure");
} else {
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)
Return true if headers have already been sent, false otherwise */
* Local variables:
* tab-width: 4
* c-basic-offset: 4
- * End:
* 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:
*/
/* {{{ free_url
*/
-PHPAPI void php_url_free(php_url * theurl)
+PHPAPI void php_url_free(php_url *theurl)
{
if (theurl->scheme)
efree(theurl->scheme);
/* {{{ 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;
unsigned char *str;
#endif /*CHARSET_EBCDIC*/
}
str[y] = '\0';
+ if (new_length) {
+ *new_length = y;
+ }
return ((char *) str);
}
/* }}} */
{
pval **arg;
char *str;
+ int str_len;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
var_reset(return_value);
return;
}
- str = php_url_encode((*arg)->value.str.val, (*arg)->value.str.len);
- RETVAL_STRING(str, 1);
+ str = php_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &str_len);
+ RETVAL_STRINGL(str, str_len, 0);
efree(str);
}
/* }}} */
/* {{{ 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;
unsigned char *str;
}
}
str[y] = '\0';
+ if (new_length) {
+ *new_length = y;
+ }
return ((char *) str);
}
/* }}} */
{
pval **arg;
char *str;
+ int new_len;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
if (!(*arg)->value.str.len) {
RETURN_FALSE;
}
- str = php_raw_url_encode((*arg)->value.str.val, (*arg)->value.str.len);
- RETVAL_STRING(str, 1);
- efree(str);
+ str = php_raw_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &new_len);
+ RETVAL_STRINGL(str, new_len, 0);
}
/* }}} */