@@ -707,6 +707,8 @@ PHP_INI_BEGIN()
707
707
/* Upload progress */
708
708
STD_PHP_INI_BOOLEAN ("session.upload_progress.enabled" ,
709
709
"1" , ZEND_INI_PERDIR , OnUpdateBool , rfc1867_enabled , php_ps_globals , ps_globals )
710
+ STD_PHP_INI_BOOLEAN ("session.upload_progress.cleanup" ,
711
+ "1" , ZEND_INI_PERDIR , OnUpdateBool , rfc1867_cleanup , php_ps_globals , ps_globals )
710
712
STD_PHP_INI_ENTRY ("session.upload_progress.prefix" ,
711
713
"upload_progress_" , ZEND_INI_PERDIR , OnUpdateSmartStr , rfc1867_prefix , php_ps_globals , ps_globals )
712
714
STD_PHP_INI_ENTRY ("session.upload_progress.name" ,
@@ -2057,17 +2059,30 @@ static const zend_module_dep session_deps[] = { /* {{{ */
2057
2059
* Upload hook handling *
2058
2060
************************ */
2059
2061
2060
- static void php_session_rfc1867_early_find_sid ( php_session_rfc1867_progress * progress TSRMLS_DC ) /* {{{ */
2062
+ static zend_bool early_find_sid_in ( zval * dest , int where , php_session_rfc1867_progress * progress TSRMLS_DC ) /* {{{ */
2061
2063
{
2062
2064
zval * * ppid ;
2063
2065
2066
+ if (!PG (http_globals )[where ]) {
2067
+ return 0 ;
2068
+ }
2069
+
2070
+ if (zend_hash_find (Z_ARRVAL_P (PG (http_globals )[where ]), PS (session_name ), progress -> sname_len + 1 , (void * * )& ppid ) == SUCCESS
2071
+ && Z_TYPE_PP (ppid ) == IS_STRING ) {
2072
+ zval_dtor (dest );
2073
+ ZVAL_ZVAL (dest , * ppid , 1 , 0 );
2074
+ return 1 ;
2075
+ }
2076
+
2077
+ return 0 ;
2078
+ } /* }}} */
2079
+
2080
+ static void php_session_rfc1867_early_find_sid (php_session_rfc1867_progress * progress TSRMLS_DC ) /* {{{ */
2081
+ {
2082
+
2064
2083
if (PS (use_cookies )) {
2065
2084
sapi_module .treat_data (PARSE_COOKIE , NULL , NULL TSRMLS_CC );
2066
- if (PG (http_globals )[TRACK_VARS_COOKIE ]
2067
- && zend_hash_find (Z_ARRVAL_P (PG (http_globals )[TRACK_VARS_COOKIE ]), PS (session_name ), progress -> sname_len + 1 , (void * * )& ppid ) == SUCCESS ) {
2068
- zval_dtor (& progress -> sid );
2069
- ZVAL_ZVAL (& progress -> sid , * ppid , 1 , 0 );
2070
- convert_to_string (& progress -> sid );
2085
+ if (early_find_sid_in (& progress -> sid , TRACK_VARS_COOKIE , progress TSRMLS_CC )) {
2071
2086
progress -> apply_trans_sid = 0 ;
2072
2087
return ;
2073
2088
}
@@ -2076,16 +2091,10 @@ static void php_session_rfc1867_early_find_sid(php_session_rfc1867_progress *pro
2076
2091
return ;
2077
2092
}
2078
2093
sapi_module .treat_data (PARSE_GET , NULL , NULL TSRMLS_CC );
2079
- if (PG (http_globals )[TRACK_VARS_GET ]
2080
- && zend_hash_find (Z_ARRVAL_P (PG (http_globals )[TRACK_VARS_GET ]), PS (session_name ), progress -> sname_len + 1 , (void * * )& ppid ) == SUCCESS ) {
2081
-
2082
- zval_dtor (& progress -> sid );
2083
- ZVAL_ZVAL (& progress -> sid , * ppid , 1 , 0 );
2084
- convert_to_string (& progress -> sid );
2085
- }
2094
+ early_find_sid_in (& progress -> sid , TRACK_VARS_GET , progress TSRMLS_CC );
2086
2095
} /* }}} */
2087
2096
2088
- static zend_bool php_session_rfc1867_check_cancel_upload (php_session_rfc1867_progress * progress TSRMLS_DC ) /* {{{ */
2097
+ static zend_bool php_check_cancel_upload (php_session_rfc1867_progress * progress TSRMLS_DC ) /* {{{ */
2089
2098
{
2090
2099
zval * * progress_ary , * * cancel_upload ;
2091
2100
@@ -2098,8 +2107,7 @@ static zend_bool php_session_rfc1867_check_cancel_upload(php_session_rfc1867_pro
2098
2107
if (zend_hash_find (Z_ARRVAL_PP (progress_ary ), "cancel_upload" , sizeof ("cancel_upload" ), (void * * )& cancel_upload ) != SUCCESS ) {
2099
2108
return 0 ;
2100
2109
}
2101
- return zend_is_true (* cancel_upload );
2102
-
2110
+ return Z_TYPE_PP (cancel_upload ) == IS_BOOL && Z_LVAL_PP (cancel_upload );
2103
2111
} /* }}} */
2104
2112
2105
2113
static void php_session_rfc1867_update (php_session_rfc1867_progress * progress , int force_update TSRMLS_DC ) /* {{{ */
@@ -2126,14 +2134,22 @@ static void php_session_rfc1867_update(php_session_rfc1867_progress *progress, i
2126
2134
php_session_initialize (TSRMLS_C );
2127
2135
PS (session_status ) = php_session_active ;
2128
2136
IF_SESSION_VARS () {
2129
- if (!progress -> cancel_upload && php_session_rfc1867_check_cancel_upload (progress TSRMLS_CC )) {
2130
- progress -> cancel_upload = 1 ;
2131
- }
2137
+ progress -> cancel_upload = php_check_cancel_upload (progress TSRMLS_CC );
2132
2138
ZEND_SET_SYMBOL_WITH_LENGTH (Z_ARRVAL_P (PS (http_session_vars )), progress -> key .c , progress -> key .len + 1 , progress -> data , 2 , 0 );
2133
2139
}
2134
2140
php_session_flush (TSRMLS_C );
2135
2141
} /* }}} */
2136
2142
2143
+ static void php_session_rfc1867_cleanup (php_session_rfc1867_progress * progress TSRMLS_DC ) /* {{{ */
2144
+ {
2145
+ php_session_initialize (TSRMLS_C );
2146
+ PS (session_status ) = php_session_active ;
2147
+ IF_SESSION_VARS () {
2148
+ zend_hash_del (Z_ARRVAL_P (PS (http_session_vars )), progress -> key .c , progress -> key .len + 1 );
2149
+ }
2150
+ php_session_flush (TSRMLS_C );
2151
+ } /* }}} */
2152
+
2137
2153
static int php_session_rfc1867_callback (unsigned int event , void * event_data , void * * extra TSRMLS_DC ) /* {{{ */
2138
2154
{
2139
2155
php_session_rfc1867_progress * progress ;
@@ -2161,6 +2177,10 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
2161
2177
multipart_event_formdata * data = (multipart_event_formdata * ) event_data ;
2162
2178
size_t value_len ;
2163
2179
2180
+ if (Z_TYPE (progress -> sid ) && progress -> key .c ) {
2181
+ break ;
2182
+ }
2183
+
2164
2184
/* orig callback may have modified *data->newlength */
2165
2185
if (data -> newlength ) {
2166
2186
value_len = * data -> newlength ;
@@ -2174,7 +2194,6 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
2174
2194
if (name_len == progress -> sname_len && memcmp (data -> name , PS (session_name ), name_len ) == 0 ) {
2175
2195
zval_dtor (& progress -> sid );
2176
2196
ZVAL_STRINGL (& progress -> sid , (* data -> value ), value_len , 1 );
2177
- convert_to_string (& progress -> sid );
2178
2197
2179
2198
} else if (name_len == PS (rfc1867_name ).len && memcmp (data -> name , PS (rfc1867_name ).c , name_len ) == 0 ) {
2180
2199
smart_str_free (& progress -> key );
@@ -2200,10 +2219,10 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
2200
2219
/* First FILE_START event, initializing data */
2201
2220
if (!progress -> data ) {
2202
2221
2203
- if (PS (rfc1867_freq ) = = 0 ) {
2204
- progress -> update_step = 0 ;
2222
+ if (PS (rfc1867_freq ) > = 0 ) {
2223
+ progress -> update_step = PS ( rfc1867_freq ) ;
2205
2224
} else if (PS (rfc1867_freq ) < 0 ) { // % of total size
2206
- progress -> update_step = progress -> content_length * PS (rfc1867_freq ) / 100 ;
2225
+ progress -> update_step = progress -> content_length * - PS (rfc1867_freq ) / 100 ;
2207
2226
}
2208
2227
progress -> next_update = 0 ;
2209
2228
progress -> next_update_time = 0.0 ;
@@ -2241,7 +2260,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
2241
2260
add_assoc_null_ex (progress -> current_file , "tmp_name" , sizeof ("tmp_name" ));
2242
2261
add_assoc_long_ex (progress -> current_file , "error" , sizeof ("error" ), 0 );
2243
2262
2244
- add_assoc_long_ex (progress -> current_file , "done" , sizeof ("done" ), 0 );
2263
+ add_assoc_bool_ex (progress -> current_file , "done" , sizeof ("done" ), 0 );
2245
2264
add_assoc_long_ex (progress -> current_file , "start_time" , sizeof ("start_time" ), (long )time (NULL ));
2246
2265
add_assoc_zval_ex (progress -> current_file , "bytes_processed" , sizeof ("bytes_processed" ), progress -> current_file_bytes_processed );
2247
2266
@@ -2287,9 +2306,13 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
2287
2306
multipart_event_end * data = (multipart_event_end * ) event_data ;
2288
2307
2289
2308
if (Z_TYPE (progress -> sid ) && progress -> key .c ) {
2290
- add_assoc_bool_ex (progress -> data , "done" , sizeof ("done" ), 1 );
2291
- Z_LVAL_P (progress -> post_bytes_processed ) = data -> post_bytes_processed ;
2292
- php_session_rfc1867_update (progress , 1 TSRMLS_CC );
2309
+ if (PS (rfc1867_cleanup )) {
2310
+ php_session_rfc1867_cleanup (progress TSRMLS_CC );
2311
+ } else {
2312
+ add_assoc_bool_ex (progress -> data , "done" , sizeof ("done" ), 1 );
2313
+ Z_LVAL_P (progress -> post_bytes_processed ) = data -> post_bytes_processed ;
2314
+ php_session_rfc1867_update (progress , 1 TSRMLS_CC );
2315
+ }
2293
2316
php_rshutdown_session_globals (TSRMLS_C );
2294
2317
}
2295
2318
0 commit comments