mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
@ - added session_set_userdata() which enables you to specify one variable
@ that will be kept in the browser in addition to the session-id. This @ only works when using trans-sid sessions (no cookie). (thies)
This commit is contained in:
parent
22182fc78d
commit
eb105693b8
4 changed files with 72 additions and 9 deletions
|
@ -93,6 +93,8 @@ typedef struct _php_ps_globals {
|
||||||
char *save_path;
|
char *save_path;
|
||||||
char *session_name;
|
char *session_name;
|
||||||
char *id;
|
char *id;
|
||||||
|
char *udata_name;
|
||||||
|
char *udata_value;
|
||||||
char *extern_referer_chk;
|
char *extern_referer_chk;
|
||||||
char *entropy_file;
|
char *entropy_file;
|
||||||
char *cache_limiter;
|
char *cache_limiter;
|
||||||
|
@ -141,6 +143,7 @@ PHP_FUNCTION(session_cache_limiter);
|
||||||
PHP_FUNCTION(session_set_cookie_params);
|
PHP_FUNCTION(session_set_cookie_params);
|
||||||
PHP_FUNCTION(session_get_cookie_params);
|
PHP_FUNCTION(session_get_cookie_params);
|
||||||
PHP_FUNCTION(session_write_close);
|
PHP_FUNCTION(session_write_close);
|
||||||
|
PHP_FUNCTION(session_set_userdata);
|
||||||
|
|
||||||
#ifdef ZTS
|
#ifdef ZTS
|
||||||
#define PS(v) TSRMG(ps_globals_id, php_ps_globals *, v)
|
#define PS(v) TSRMG(ps_globals_id, php_ps_globals *, v)
|
||||||
|
|
|
@ -71,10 +71,13 @@ function_entry session_functions[] = {
|
||||||
PHP_FE(session_set_cookie_params, NULL)
|
PHP_FE(session_set_cookie_params, NULL)
|
||||||
PHP_FE(session_get_cookie_params, NULL)
|
PHP_FE(session_get_cookie_params, NULL)
|
||||||
PHP_FE(session_write_close, NULL)
|
PHP_FE(session_write_close, NULL)
|
||||||
|
PHP_FE(session_set_userdata, NULL)
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
#define SAFE_STRING(s) ((s)?(s):"")
|
||||||
|
|
||||||
ZEND_DECLARE_MODULE_GLOBALS(ps);
|
ZEND_DECLARE_MODULE_GLOBALS(ps);
|
||||||
|
|
||||||
static ps_module *_php_find_ps_module(char *name TSRMLS_DC);
|
static ps_module *_php_find_ps_module(char *name TSRMLS_DC);
|
||||||
|
@ -84,7 +87,7 @@ static void php_session_end_output_handler(TSRMLS_D);
|
||||||
static void php_session_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
|
static void php_session_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
|
||||||
{
|
{
|
||||||
if ((PS(session_status) == php_session_active)) {
|
if ((PS(session_status) == php_session_active)) {
|
||||||
*handled_output = url_adapt_ext_ex(output, output_len, PS(session_name), PS(id), handled_output_len, (zend_bool) (mode&PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC);
|
*handled_output = url_adapt_ext_ex(output, output_len, PS(session_name), PS(id), SAFE_STRING(PS(udata_name)), SAFE_STRING(PS(udata_value)), handled_output_len, (zend_bool) (mode&PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC);
|
||||||
} else {
|
} else {
|
||||||
*handled_output = NULL;
|
*handled_output = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1403,11 +1406,32 @@ PHP_FUNCTION(session_unset)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ proto bool session_set_userdata(string var, string value)
|
||||||
|
sets one additional variable that will be added by in trans-SID mode */
|
||||||
|
PHP_FUNCTION(session_set_userdata)
|
||||||
|
{
|
||||||
|
zval **str;
|
||||||
|
zval **val;
|
||||||
|
|
||||||
|
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &str, &val) == FAILURE)
|
||||||
|
WRONG_PARAM_COUNT;
|
||||||
|
|
||||||
|
if ((Z_TYPE_PP(str) != IS_STRING) || (Z_TYPE_PP(val) != IS_STRING)) {
|
||||||
|
php_error(E_ERROR,"session_set_userdata expects both parameters to be strings");
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PS(udata_name) = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
|
||||||
|
PS(udata_value) = estrndup(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
|
||||||
|
|
||||||
|
RETURN_TRUE;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t *newlen TSRMLS_DC)
|
PHPAPI void session_adapt_url(const char *url, size_t urllen, char **new, size_t *newlen TSRMLS_DC)
|
||||||
{
|
{
|
||||||
if (PS(apply_trans_sid) && (PS(session_status) == php_session_active)) {
|
if (PS(apply_trans_sid) && (PS(session_status) == php_session_active)) {
|
||||||
*new = url_adapt_single_url(url, urllen, PS(session_name), PS(id), newlen TSRMLS_CC);
|
*new = url_adapt_single_url(url, urllen, PS(session_name), PS(id), PS(udata_name), PS(udata_value), newlen TSRMLS_CC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1430,6 +1454,17 @@ static void php_rshutdown_session_globals(TSRMLS_D)
|
||||||
if (PS(id)) {
|
if (PS(id)) {
|
||||||
efree(PS(id));
|
efree(PS(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PS(udata_name)) {
|
||||||
|
efree(PS(udata_name));
|
||||||
|
PS(udata_name) = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PS(udata_value)) {
|
||||||
|
efree(PS(udata_value));
|
||||||
|
PS(udata_value) = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
zend_hash_destroy(&PS(vars));
|
zend_hash_destroy(&PS(vars));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ PHP_MSHUTDOWN_FUNCTION(url_scanner_ex);
|
||||||
int php_url_scanner_ex_activate(TSRMLS_D);
|
int php_url_scanner_ex_activate(TSRMLS_D);
|
||||||
int php_url_scanner_ex_deactivate(TSRMLS_D);
|
int php_url_scanner_ex_deactivate(TSRMLS_D);
|
||||||
|
|
||||||
char *url_adapt_ext_ex(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen, zend_bool do_flush TSRMLS_DC);
|
char *url_adapt_ext_ex(const char *src, size_t srclen, const char *name, const char *value, char *udata_name, char *udata_value, size_t *newlen, zend_bool do_flush TSRMLS_DC);
|
||||||
|
|
||||||
char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC);
|
char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, char *udata_name, char *udata_value, size_t *newlen TSRMLS_DC);
|
||||||
|
|
||||||
char *url_adapt_flush(size_t * TSRMLS_DC);
|
char *url_adapt_flush(size_t * TSRMLS_DC);
|
||||||
|
|
||||||
|
@ -46,6 +46,9 @@ typedef struct {
|
||||||
smart_str q_name;
|
smart_str q_name;
|
||||||
smart_str q_value;
|
smart_str q_value;
|
||||||
|
|
||||||
|
smart_str q_udata_name;
|
||||||
|
smart_str q_udata_value;
|
||||||
|
|
||||||
char *lookup_data;
|
char *lookup_data;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ alpha = [a-zA-Z];
|
||||||
#define YYLIMIT q
|
#define YYLIMIT q
|
||||||
#define YYMARKER r
|
#define YYMARKER r
|
||||||
|
|
||||||
static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *name, smart_str *val, const char *separator)
|
static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *name, smart_str *val, smart_str *udata_name, smart_str *udata_value, const char *separator)
|
||||||
{
|
{
|
||||||
register const char *p, *q;
|
register const char *p, *q;
|
||||||
const char *bash = NULL;
|
const char *bash = NULL;
|
||||||
|
@ -128,6 +128,12 @@ done:
|
||||||
smart_str_append(dest, name);
|
smart_str_append(dest, name);
|
||||||
smart_str_appendc(dest, '=');
|
smart_str_appendc(dest, '=');
|
||||||
smart_str_append(dest, val);
|
smart_str_append(dest, val);
|
||||||
|
if (udata_name->len && udata_value->len) {
|
||||||
|
smart_str_appends(dest, separator);
|
||||||
|
smart_str_append(dest, udata_name);
|
||||||
|
smart_str_appendc(dest, '=');
|
||||||
|
smart_str_append(dest, udata_value);
|
||||||
|
}
|
||||||
|
|
||||||
if (bash)
|
if (bash)
|
||||||
smart_str_appendl(dest, bash, q - bash);
|
smart_str_appendl(dest, bash, q - bash);
|
||||||
|
@ -150,7 +156,7 @@ static inline void tag_arg(url_adapt_state_ex_t *ctx, char quotes, char type TSR
|
||||||
if (quotes)
|
if (quotes)
|
||||||
smart_str_appendc(&ctx->result, type);
|
smart_str_appendc(&ctx->result, type);
|
||||||
if (f) {
|
if (f) {
|
||||||
append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator).output);
|
append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, &ctx->q_udata_name, &ctx->q_udata_value, PG(arg_separator).output);
|
||||||
} else {
|
} else {
|
||||||
smart_str_append(&ctx->result, &ctx->val);
|
smart_str_append(&ctx->result, &ctx->val);
|
||||||
}
|
}
|
||||||
|
@ -190,6 +196,14 @@ static inline void handle_form(STD_PARA)
|
||||||
smart_str_appends(&ctx->result, "\" value=\"");
|
smart_str_appends(&ctx->result, "\" value=\"");
|
||||||
smart_str_append(&ctx->result, &ctx->q_value);
|
smart_str_append(&ctx->result, &ctx->q_value);
|
||||||
smart_str_appends(&ctx->result, "\" />");
|
smart_str_appends(&ctx->result, "\" />");
|
||||||
|
|
||||||
|
if (ctx->q_udata_name.len) {
|
||||||
|
smart_str_appends(&ctx->result, "<input type=\"hidden\" name=\"");
|
||||||
|
smart_str_append(&ctx->result, &ctx->q_udata_name);
|
||||||
|
smart_str_appends(&ctx->result, "\" value=\"");
|
||||||
|
smart_str_append(&ctx->result, &ctx->q_udata_value);
|
||||||
|
smart_str_appends(&ctx->result, "\" />");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,18 +332,22 @@ stop:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
|
char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, char *udata_name, char *udata_value, size_t *newlen TSRMLS_DC)
|
||||||
{
|
{
|
||||||
smart_str surl = {0};
|
smart_str surl = {0};
|
||||||
smart_str buf = {0};
|
smart_str buf = {0};
|
||||||
smart_str sname = {0};
|
smart_str sname = {0};
|
||||||
smart_str sval = {0};
|
smart_str sval = {0};
|
||||||
|
smart_str aname = {0};
|
||||||
|
smart_str avalue = {0};
|
||||||
|
|
||||||
smart_str_setl(&surl, url, urllen);
|
smart_str_setl(&surl, url, urllen);
|
||||||
smart_str_sets(&sname, name);
|
smart_str_sets(&sname, name);
|
||||||
smart_str_sets(&sval, value);
|
smart_str_sets(&sval, value);
|
||||||
|
smart_str_sets(&aname, udata_name);
|
||||||
|
smart_str_sets(&avalue, udata_value);
|
||||||
|
|
||||||
append_modified_url(&surl, &buf, &sname, &sval, PG(arg_separator).output);
|
append_modified_url(&surl, &buf, &sname, &sval, &aname, &avalue, PG(arg_separator).output);
|
||||||
|
|
||||||
smart_str_0(&buf);
|
smart_str_0(&buf);
|
||||||
if (newlen) *newlen = buf.len;
|
if (newlen) *newlen = buf.len;
|
||||||
|
@ -337,7 +355,7 @@ char *url_adapt_single_url(const char *url, size_t urllen, const char *name, con
|
||||||
return buf.c;
|
return buf.c;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen, zend_bool do_flush TSRMLS_DC)
|
char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, char *udata_name, char *udata_value, size_t *newlen, zend_bool do_flush TSRMLS_DC)
|
||||||
{
|
{
|
||||||
url_adapt_state_ex_t *ctx;
|
url_adapt_state_ex_t *ctx;
|
||||||
char *retval;
|
char *retval;
|
||||||
|
@ -346,6 +364,10 @@ char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char
|
||||||
|
|
||||||
smart_str_sets(&ctx->q_name, name);
|
smart_str_sets(&ctx->q_name, name);
|
||||||
smart_str_sets(&ctx->q_value, value);
|
smart_str_sets(&ctx->q_value, value);
|
||||||
|
|
||||||
|
smart_str_sets(&ctx->q_udata_name, udata_name);
|
||||||
|
smart_str_sets(&ctx->q_udata_value, udata_value);
|
||||||
|
|
||||||
xx_mainloop(ctx, src, srclen TSRMLS_CC);
|
xx_mainloop(ctx, src, srclen TSRMLS_CC);
|
||||||
|
|
||||||
*newlen = ctx->result.len;
|
*newlen = ctx->result.len;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue