[PHP-CVS] svn: /php/php-src/trunk/ext/session/ php_session.h session.c tests/rfc1867.phpt tests/rfc1867_cleanup.phpt tests/rfc1867_disabled.phpt tests/rfc1867_disabled_2.phpt tests/rfc1867_inter.phpt
lbarnaud Tue, 11 May 2010 16:39:07 + Revision: http://svn.php.net/viewvc?view=revision&revision=299255 Log: - code cleanups - cleanup progress data from session vars as soon as all post data has been readden (upload_progress.cleanup ini setting allows to disable this) Changed paths: U php/php-src/trunk/ext/session/php_session.h U php/php-src/trunk/ext/session/session.c U php/php-src/trunk/ext/session/tests/rfc1867.phpt A php/php-src/trunk/ext/session/tests/rfc1867_cleanup.phpt U php/php-src/trunk/ext/session/tests/rfc1867_disabled.phpt U php/php-src/trunk/ext/session/tests/rfc1867_disabled_2.phpt A php/php-src/trunk/ext/session/tests/rfc1867_inter.phpt U php/php-src/trunk/ext/session/tests/rfc1867_no_name.phpt U php/php-src/trunk/ext/session/tests/rfc1867_sid_cookie.phpt U php/php-src/trunk/ext/session/tests/rfc1867_sid_get.phpt U php/php-src/trunk/ext/session/tests/rfc1867_sid_get_2.phpt U php/php-src/trunk/ext/session/tests/rfc1867_sid_invalid.phpt U php/php-src/trunk/ext/session/tests/rfc1867_sid_only_cookie.phpt U php/php-src/trunk/ext/session/tests/rfc1867_sid_only_cookie_2.phpt U php/php-src/trunk/ext/session/tests/rfc1867_sid_post.phpt Modified: php/php-src/trunk/ext/session/php_session.h === --- php/php-src/trunk/ext/session/php_session.h 2010-05-11 16:09:43 UTC (rev 299254) +++ php/php-src/trunk/ext/session/php_session.h 2010-05-11 16:39:07 UTC (rev 299255) @@ -166,6 +166,7 @@ php_session_rfc1867_progress *rfc1867_progress; zend_bool rfc1867_enabled; /* session.upload_progress.enabled */ + zend_bool rfc1867_cleanup; /* session.upload_progress.cleanup */ smart_str rfc1867_prefix; /* session.upload_progress.prefix */ smart_str rfc1867_name;/* session.upload_progress.name */ long rfc1867_freq; /* session.upload_progress.freq */ Modified: php/php-src/trunk/ext/session/session.c === --- php/php-src/trunk/ext/session/session.c 2010-05-11 16:09:43 UTC (rev 299254) +++ php/php-src/trunk/ext/session/session.c 2010-05-11 16:39:07 UTC (rev 299255) @@ -707,6 +707,8 @@ /* Upload progress */ STD_PHP_INI_BOOLEAN("session.upload_progress.enabled", "1", ZEND_INI_PERDIR, OnUpdateBool,rfc1867_enabled, php_ps_globals, ps_globals) + STD_PHP_INI_BOOLEAN("session.upload_progress.cleanup", + "1", ZEND_INI_PERDIR, OnUpdateBool,rfc1867_cleanup, php_ps_globals, ps_globals) STD_PHP_INI_ENTRY("session.upload_progress.prefix", "upload_progress_", ZEND_INI_PERDIR, OnUpdateSmartStr, rfc1867_prefix, php_ps_globals, ps_globals) STD_PHP_INI_ENTRY("session.upload_progress.name", @@ -2057,17 +2059,30 @@ * Upload hook handling * */ -static void php_session_rfc1867_early_find_sid(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ +static zend_bool early_find_sid_in(zval *dest, int where, php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ { zval **ppid; + if (!PG(http_globals)[where]) { + return 0; + } + + if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[where]), PS(session_name), progress->sname_len+1, (void **)&ppid) == SUCCESS + && Z_TYPE_PP(ppid) == IS_STRING) { + zval_dtor(dest); + ZVAL_ZVAL(dest, *ppid, 1, 0); + return 1; + } + + return 0; +} /* }}} */ + +static void php_session_rfc1867_early_find_sid(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ +{ + if (PS(use_cookies)) { sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); - if (PG(http_globals)[TRACK_VARS_COOKIE] - && zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), PS(session_name), progress->sname_len+1, (void **)&ppid) == SUCCESS) { - zval_dtor(&progress->sid); - ZVAL_ZVAL(&progress->sid, *ppid, 1, 0); - convert_to_string(&progress->sid); + if (early_find_sid_in(&progress->sid, TRACK_VARS_COOKIE, progress TSRMLS_CC)) { progress->apply_trans_sid = 0; return; } @@ -2076,16 +2091,10 @@ return; } sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); - if (PG(http_globals)[TRACK_VARS_GET] - && zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), PS(session_name), progress->sname_len+1, (void **)&ppid) == SUCCESS) { - - zval_dtor(&progress->sid); - ZVAL_ZVAL(&progress->sid, *ppid, 1, 0); - convert_to_string(&progress->sid); - } + early_find_sid_in(&progress->sid, TRACK_VARS_GET, progress TSRMLS_CC); } /* }}} */ -static zend_bool php_session_rfc1867_check_cancel_upload(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ +static zend_bool php_check_cancel_upload(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */ { zval **progress_ary, **cancel_upload; @@ -2098,8
Re: [PHP-CVS] svn: /php/php-src/trunk/ext/session/ php_session.h session.c
On Mon, May 10, 2010 at 18:09, Arnaud Le Blanc wrote: > lbarnaud Mon, 10 May 2010 16:09:00 + > > Revision: http://svn.php.net/viewvc?view=revision&revision=299218 > > Log: > Added upload progress feedback in session data as describied > in RFC : http://wiki.php.net/rfc/session_upload_progress > > Changed paths: > U php/php-src/trunk/ext/session/php_session.h > U php/php-src/trunk/ext/session/session.c > NEWS and UPGRADE please :) -Hannes -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] svn: /php/php-src/trunk/ext/session/ php_session.h session.c
lbarnaud Mon, 10 May 2010 16:09:00 + Revision: http://svn.php.net/viewvc?view=revision&revision=299218 Log: Added upload progress feedback in session data as describied in RFC : http://wiki.php.net/rfc/session_upload_progress Changed paths: U php/php-src/trunk/ext/session/php_session.h U php/php-src/trunk/ext/session/session.c Modified: php/php-src/trunk/ext/session/php_session.h === --- php/php-src/trunk/ext/session/php_session.h 2010-05-10 16:00:23 UTC (rev 299217) +++ php/php-src/trunk/ext/session/php_session.h 2010-05-10 16:09:00 UTC (rev 299218) @@ -95,6 +95,26 @@ php_session_active } php_session_status; +typedef struct _php_session_rfc1867_progress { + + size_tsname_len; + zval sid; + smart_str key; + + long update_step; + long next_update; + doublenext_update_time; + zend_bool cancel_upload; + zend_bool apply_trans_sid; + size_tcontent_length; + + zval *data; /* the array exported to session data */ + zval *post_bytes_processed; /* data["bytes_processed"] */ + zval *files;/* data["files"] array */ + zval *current_file; /* array of currently uploading file */ + zval *current_file_bytes_processed; +} php_session_rfc1867_progress; + typedef struct _php_ps_globals { char *save_path; char *session_name; @@ -143,6 +163,13 @@ int send_cookie; int define_sid; zend_bool invalid_session_id; /* allows the driver to report about an invalid session id and request id regeneration */ + + php_session_rfc1867_progress *rfc1867_progress; + zend_bool rfc1867_enabled; /* session.upload_progress.enabled */ + smart_str rfc1867_prefix; /* session.upload_progress.prefix */ + smart_str rfc1867_name;/* session.upload_progress.name */ + long rfc1867_freq; /* session.upload_progress.freq */ + double rfc1867_min_freq; /* session.upload_progress.min_freq */ } php_ps_globals; typedef php_ps_globals zend_ps_globals; Modified: php/php-src/trunk/ext/session/session.c === --- php/php-src/trunk/ext/session/session.c 2010-05-10 16:00:23 UTC (rev 299217) +++ php/php-src/trunk/ext/session/session.c 2010-05-10 16:09:00 UTC (rev 299218) @@ -36,6 +36,8 @@ #include "php_ini.h" #include "SAPI.h" +#include "rfc1867.h" +#include "php_variables.h" #include "php_session.h" #include "ext/standard/md5.h" #include "ext/standard/sha1.h" @@ -57,6 +59,9 @@ PHPAPI ZEND_DECLARE_MODULE_GLOBALS(ps); +static int php_session_rfc1867_callback(unsigned int event, void *event_data, void **extra TSRMLS_DC); +static int (*php_session_rfc1867_orig_callback)(unsigned int event, void *event_data, void **extra TSRMLS_DC); + /* *** * Helpers * *** */ @@ -625,6 +630,45 @@ } /* }}} */ +static PHP_INI_MH(OnUpdateRfc1867Freq) /* {{{ */ +{ + int tmp; + tmp = zend_atoi(new_value, new_value_length); + if(tmp < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.upload_progress.freq must be greater than or equal to zero"); + return FAILURE; + } + if(new_value_length > 0 && new_value[new_value_length-1] == '%') { + if(tmp > 100) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "session.upload_progress.freq cannot be over 100%%"); + return FAILURE; + } + PS(rfc1867_freq) = -tmp; + } else { + PS(rfc1867_freq) = tmp; + } + return SUCCESS; +} /* }}} */ + +static ZEND_INI_MH(OnUpdateSmartStr) /* {{{ */ +{ + smart_str *p; +#ifndef ZTS + char *base = (char *) mh_arg2; +#else + char *base; + + base = (char *) ts_resource(*((int *) mh_arg2)); +#endif + + p = (smart_str *) (base+(size_t) mh_arg1); + + smart_str_sets(p, new_value); + + return SUCCESS; +} +/* }}} */ + /* {{{ PHP_INI */ PHP_INI_BEGIN() @@ -660,6 +704,17 @@ PHP_INI_ENTRY("session.hash_function", "0", PHP_INI_ALL, OnUpdateHashFunc) STD_PHP_INI_ENTRY("session.hash_bits_per_character", "4",PHP_INI_ALL, OnUpdateLong, hash_bits_per_character, php_ps_globals, ps_globals) + /* Upload progress */ + STD_PHP_INI_BOOLEAN("session.upload_progress.enabled", + "1", ZEND_INI_PERDIR, OnUpdateBool,rfc1867_enabled, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.prefix", + "upload_progress_", ZEND_INI_PERDIR, OnUpdateSmartStr, rfc1867_prefix, php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.name", + "PHP_SESSION_UPLOAD_PROGRESS", ZEND_INI_PERDIR, OnUpdateSmartStr, rfc1867_name,php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.freq", "1%", ZEND_INI_PERDIR, OnUpdateRfc1867Freq, rfc1867_freq,php_ps_globals, ps_globals) + STD_PHP_INI_ENTRY("session.upload_progress.min_freq", + "1", ZEND_INI_PERDIR,