Hi,
I am sorry but the output of "diff -u" against the current cvs snapshot was
somewhat confusing and too big in comparison what I really changed (because
of permanently changed code ofcourse). So I am going to explain the changes
without it. Once again, all changes are based on PHP4.0.6 sources and were
tested on Win2000, Apache 1.3 , php4apache.dll module.
The changes are tagged with /*shegalov .....*/ /*shegalov end*/ . Only
changed functions are listed below.
FILE ext/session/session.c
---------------------------
/*shegalov
* set an empty cookie with an exipire period "now - one hour" because
otherwise MSIE resend an empty cookie
*/
static void php_session_destroy_cookie(PSLS_D)
{
smart_str ncookie = {0};
char *date_fmt = NULL;
SLS_FETCH();
if (SG(headers_sent)) {
char *output_start_filename = php_get_output_start_filename();
int output_start_lineno = php_get_output_start_lineno();
if (output_start_filename) {
php_error(E_WARNING, "Cannot send session cookie - headers already sent
by (output started at %s:%d)",
output_start_filename, output_start_lineno);
} else {
php_error(E_WARNING, "Cannot send session cookie - headers already
sent");
}
return;
}
smart_str_appends(&ncookie, COOKIE_SET_COOKIE);
smart_str_appends(&ncookie, PS(session_name));
smart_str_appendc(&ncookie, '=');
smart_str_appends(&ncookie, PS(id));
date_fmt = php_std_date(time(NULL) - 3600);
smart_str_appends(&ncookie, COOKIE_EXPIRES);
smart_str_appends(&ncookie, date_fmt);
efree(date_fmt);
if (PS(cookie_path)[0]) {
smart_str_appends(&ncookie, COOKIE_PATH);
smart_str_appends(&ncookie, PS(cookie_path));
}
if (PS(cookie_domain)[0]) {
smart_str_appends(&ncookie, COOKIE_DOMAIN);
smart_str_appends(&ncookie, PS(cookie_domain));
}
if (PS(cookie_secure)) {
smart_str_appends(&ncookie, COOKIE_SECURE);
}
smart_str_0(&ncookie);
sapi_add_header(ncookie.c, ncookie.len, 0);
}
/*shegalov end*/
static void php_session_start(PSLS_D)
{
pval **ppid;
pval **data;
char *p;
int send_cookie = 1;
int define_sid = 1;
int module_number = PS(module_number);
int nrand;
int lensess;
ELS_FETCH();
if (PS(nr_open_sessions) != 0)
return;
lensess = strlen(PS(session_name));
/*
* Cookies are preferred, because initially
* cookie and get variables will be available.
*/
if (!PS(id)) {
if (zend_hash_find(&EG(symbol_table), "HTTP_COOKIE_VARS",
sizeof("HTTP_COOKIE_VARS"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY &&
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
lensess + 1, (void **) &ppid) == SUCCESS) {
PPID2SID;
define_sid = 0;
send_cookie = 0;
}
if (!PS(id) &&
zend_hash_find(&EG(symbol_table), "HTTP_GET_VARS",
sizeof("HTTP_GET_VARS"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY &&
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
lensess + 1, (void **) &ppid) == SUCCESS) {
PPID2SID;
}
if (!PS(id) &&
zend_hash_find(&EG(symbol_table), "HTTP_POST_VARS",
sizeof("HTTP_POST_VARS"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY &&
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
lensess + 1, (void **) &ppid) == SUCCESS) {
PPID2SID;
}
}
/* check the REQUEST_URI symbol for a string of the form
'<session-name>=<session-id>' to allow URLs of the form
http://yoursite/<session-name>=<session-id>/script.php */
if (!PS(id) &&
zend_hash_find(&EG(symbol_table), "REQUEST_URI",
sizeof("REQUEST_URI"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_STRING &&
(p = strstr(Z_STRVAL_PP(data), PS(session_name))) &&
p[lensess] == '=') {
char *q;
p += lensess + 1;
if ((q = strpbrk(p, "/?\\")))
PS(id) = estrndup(p, q - p);
}
/* check whether the current request was referred to by
an external site which invalidates the previously found id */
if (PS(id) &&
PS(extern_referer_chk)[0] != '\0' &&
zend_hash_find(&EG(symbol_table), "HTTP_REFERER",
sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_STRING &&
Z_STRLEN_PP(data) != 0 &&
strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL) {
efree(PS(id));
PS(id) = NULL;
send_cookie = 1;
define_sid = 1;
}
if (!PS(id))
PS(id) = _php_create_id(NULL PSLS_CC);
if (!PS(use_cookies) && send_cookie) {
define_sid = 1;
send_cookie = 0;
} else {
/* shegalov
* prevent fallback in the case where cookies do their work well
*/
define_sid = 0;
/* shegalov end*/
}
if (send_cookie)
php_session_send_cookie(PSLS_C);
if (define_sid) {
smart_str var = {0};
smart_str_appends(&var, PS(session_name));
smart_str_appendc(&var, '=');
smart_str_appends(&var, PS(id));
smart_str_0(&var);
REGISTER_STRING_CONSTANT("SID", var.c, 0);
} else
REGISTER_STRING_CONSTANT("SID", empty_string, 0);
PS(define_sid) = define_sid;
PS(nr_open_sessions)++;
php_session_cache_limiter(PSLS_C);
php_session_initialize(PSLS_C);
if (PS(mod_data) && PS(gc_probability) > 0) {
int nrdels = -1;
srand(time(NULL));
nrand = (int) (100.0*rand()/RAND_MAX);
if (nrand < PS(gc_probability)) {
PS(mod)->gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels);
#if 0
if (nrdels != -1)
php_error(E_NOTICE, "purged %d expired session objects\n", nrdels);
#endif
}
}
}
static zend_bool php_session_destroy(PSLS_D)
{
zend_bool retval = SUCCESS;
/* shegalov 19.07.2001
* no need to call session_start() before session_destroy()
* anymore. Simply use the same initialization routines as in
php_session_start.
* if the session_id was provided with a cookie, we have to unset it.
*/
pval **ppid;
pval **data;
char *p;
int send_cookie = 1;
int module_number = PS(module_number);
int lensess;
ELS_FETCH();
lensess = strlen(PS(session_name));
/*
* Cookies are preferred, because initially
* cookie and get variables will be available.
*/
if (!PS(id)) {
if (zend_hash_find(&EG(symbol_table), "HTTP_COOKIE_VARS",
sizeof("HTTP_COOKIE_VARS"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY &&
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
lensess + 1, (void **) &ppid) == SUCCESS) {
PPID2SID;
/* shegalov 20.07.2001 01:26
a session id has been found, unset it*/
send_cookie = 1;
/*end shegalov*/
}
if (!PS(id) &&
zend_hash_find(&EG(symbol_table), "HTTP_GET_VARS",
sizeof("HTTP_GET_VARS"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY &&
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
lensess + 1, (void **) &ppid) == SUCCESS) {
PPID2SID;
}
if (!PS(id) &&
zend_hash_find(&EG(symbol_table), "HTTP_POST_VARS",
sizeof("HTTP_POST_VARS"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_ARRAY &&
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
lensess + 1, (void **) &ppid) == SUCCESS) {
PPID2SID;
}
}
/* check the REQUEST_URI symbol for a string of the form
'<session-name>=<session-id>' to allow URLs of the form
http://yoursite/<session-name>=<session-id>/script.php */
if (!PS(id) &&
zend_hash_find(&EG(symbol_table), "REQUEST_URI",
sizeof("REQUEST_URI"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_STRING &&
(p = strstr(Z_STRVAL_PP(data), PS(session_name))) &&
p[lensess] == '=') {
char *q;
p += lensess + 1;
if ((q = strpbrk(p, "/?\\")))
PS(id) = estrndup(p, q - p);
}
/* check whether the current request was referred to by
an external site which invalidates the previously found id */
if (PS(id) &&
PS(extern_referer_chk)[0] != '\0' &&
zend_hash_find(&EG(symbol_table), "HTTP_REFERER",
sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS &&
Z_TYPE_PP(data) == IS_STRING &&
Z_STRLEN_PP(data) != 0 &&
strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL) {
efree(PS(id));
PS(id) = NULL;
send_cookie = 1;
}
if (!PS(use_cookies) && send_cookie) {
send_cookie = 0;
}
if(PS(id))
PS(nr_open_sessions)++;
php_session_cache_limiter(PSLS_C);
php_session_initialize(PSLS_C);
/*shegalov end*/
if (PS(nr_open_sessions) == 0) {
php_error(E_WARNING, "Trying to destroy uninitialized session");
return FAILURE;
}
if (PS(mod)->destroy(&PS(mod_data), PS(id)) == FAILURE) {
retval = FAILURE;
php_error(E_WARNING, "Session object destruction failed");
}
php_rshutdown_session_globals(PSLS_C);
php_rinit_session_globals(PSLS_C);
PS(id) = empty_string;
/*shegalov unsetting cookie and the SID constant*/
if (send_cookie)
php_session_destroy_cookie(PSLS_C);
REGISTER_STRING_CONSTANT("SID", empty_string, 0);
/*shegalov end*/
return retval;
}
/* {{{ proto bool session_register(mixed var_names [, mixed ...])
Adds varname(s) to the list of variables which are freezed at the session
end */
PHP_FUNCTION(session_register)
{
/*shegalov 25.07.2001
* if session_register('varname') has beem called you can
* can access the variable in the current scope by refering to $varname,
* but not by $HTTP_SESSION_VARS['varname']. this can be achieved by
calling
* php_set_session_var, which is done here. See below. I suppose
session_unregister
* will have to be changed also. However I have not checked for this yet.
*
*/
zval **current = NULL;
zval *null_val = NULL;
/*shegalov end*/
zval ***args;
int argc = ZEND_NUM_ARGS();
int i;
PSLS_FETCH();
PLS_FETCH();
if (argc <= 0)
RETURN_FALSE
else
args = (zval ***)emalloc(argc * sizeof(zval **));
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
efree(args);
WRONG_PARAM_COUNT;
}
if (PS(nr_open_sessions) == 0)
php_session_start(PSLS_C);
for (i = 0; i < argc; i++) {
if (Z_TYPE_PP(args[i]) == IS_ARRAY)
SEPARATE_ZVAL(args[i]);
php_register_var(args[i] PSLS_CC PLS_CC);
/*shegalov 25.07.2001 15:39
*
*/
if(zend_hash_find(&EG(symbol_table), Z_STRVAL_PP(args[i]),
Z_STRLEN_PP(args[i]) + 1, (void **)¤t) == FAILURE) {
MAKE_STD_ZVAL(null_val);
ZVAL_NULL(null_val);
current = &null_val;
}
php_set_session_var(Z_STRVAL_PP(args[i]), Z_STRLEN_PP(args[i]), *current
PSLS_CC);
/*shegalov*/
}
efree(args);
RETURN_TRUE;
}
/* }}} */
---------------------------------
END FILE ext/session/session.c
less important changes follow
FILE ext/standard/info.c
--------------------------
PHPAPI void php_print_info(int flag)
{
/* shegalov */
PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n<HTML>\n");
PUTS("<head>");
php_info_print_style();
PUTS("<title>phpinfo()</title></head><body>");
/*shegalov end*/
if (flag & PHP_INFO_GENERAL) {
char *zend_version = get_zend_version();
php_uname = php_get_uname();
/* shegalov 10.07.2001 14:46
* lines below should appear for all phpinfo arguments, hence it will be
put before
* INFO_GENERAL handling code
PUTS("<head>");
php_info_print_style();
PUTS("<title>phpinfo()</title></head><body>");
*/
.....
}
---------------------------------
END FILE ext/standard/info.c
FILE sapi/apache/php_apache.c
---------------------------------------
/* shegalov 13.07.2001 09:06 */
PHP_FUNCTION(getrequest);
/* shegalov end */
.....
function_entry apache_functions[] = {
PHP_FE(virtual, NULL)
/* shegalov 13.07.2001 09:06 */
PHP_FE(getrequest, NULL)
/* shegalov end */
PHP_FE(getallheaders, NULL)
PHP_FE(apache_note, NULL)
PHP_FE(apache_lookup_uri, NULL)
PHP_FE(apache_child_terminate, NULL)
{NULL, NULL, NULL}
};
.....
/*shegalov 13.07.2001 09:12
* fetch the request line. this function is complimentary to
getallheaders()
*/
PHP_FUNCTION(getrequest)
{
request_rec *r;
SLS_FETCH();
PLS_FETCH();
r = ((request_rec *) SG(server_context));
if(r->the_request)
RETURN_STRING(r->the_request, 1)
else
RETURN_FALSE;
}
/*shegalov end*/
---------------------------------------
END FILE sapi/apache/php_apache.c
That's it for now. I am looking forward to an interesting discussion.
German Shegalov
----- Original Message -----
From: "Markus Fischer" <[EMAIL PROTECTED]>
To: "Hojtsy Gábor" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, July 26, 2001 2:17 PM
Subject: Re: [PHP-DEV] FW: How to contribute to PHP?
> Just provide a unified diff against current CVS ( diff -u) and
> attach it to your mail describing what it does why, discussion
> and/or commiting if appropriate will start soon then.
>
> - Markus
>
> On Thu, Jul 26, 2001 at 09:41:46AM +0200, Hojtsy Gábor wrote :
> > This guy is offering some improvements. Maybe
> > the people here can get in contact with him.
> >
> > Goba [member of phpdoc and phpweb]
> >
> > -----Original Message-----
> > From: German Shegalov [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, July 25, 2001 8:08 PM
> > To: [EMAIL PROTECTED]
> > Subject: How to contribute to PHP?
> >
> >
> > Hello,
> > I would like to contribute to the PHP project. In my own work I use PHP
> > 4.0.6 and I already made some improvements which I would like to share
with
> > the whole php user community. The log of my changes follows:
> >
> > - HTML-output of phpinfo corrected (missing tags added);
> >
> > - Apache-specific function getrequest(); added to PHP ( the same style
as
> > getallheaders())
> > for debugging purposes
> >
> > - getting rid of annoying session_destroy behavior which requires
> > session_start to be called
> > before session_destroy on the same page in order to destroy a session.
> > session_destroy destroys also the session_cookie now.
> >
> > - as for now session variables are available in $HTTP_SESSION_VARS only
> > after they have
> > been read from the storage medium on the next page (not on the page
where
> > they have been registered) . More intutive behavior is to make them also
> > available just after being registered with session_register. And it
works.
> >
> > Sincerly,
> > German Shegalov
> >
> >
>
> --
> Markus Fischer, http://guru.josefine.at/~mfischer/
> EMail: [EMAIL PROTECTED]
> PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
> PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]