Re[2]: [PHP-DEV] Upload Progress Meter Patch
| From: | Tom Rogers | Date: | Sat, 06 Nov 2004 03:55:21 +0000 |
| Subject: | Re[2]: [PHP-DEV] Upload Progress Meter Patch | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13749@lists.php.net to get a copy of this message | ||
Hi,
Saturday, November 6, 2004, 10:25:57 AM, you wrote:
MB> Hello Tom,
MB> can you please provide a unified diff (diff -u) which everyone here
MB> understands? Also it would help to see a diff against HEAD.
MB> regards
MB> marcus
This is against the latest cvs 4.3
--
regards,
Tom
Index: Zend/zend.c =================================================================== RCS file: /repository/Zend/Attic/zend.c,v retrieving revision 1.162.2.21 diff -u -w -b -u -r1.162.2.21 zend.c --- Zend/zend.c 9 Sep 2004 13:27:48 -0000 1.162.2.21 +++ Zend/zend.c 6 Nov 2004 02:27:38 -0000 @@ -80,6 +80,7 @@ ZEND_API int compiler_globals_id; ZEND_API int executor_globals_id; ZEND_API int alloc_globals_id; +ZEND_API int fus_globals_id; HashTable *global_function_table; HashTable *global_class_table; HashTable *global_constants_table; @@ -368,6 +369,15 @@ zend_ini_shutdown(TSRMLS_C); } +static void fus_globals_ctor(zend_fus_globals *fus_globals TSRMLS_DC) +{ + +} + +static void fus_globals_dtor(zend_executor_globals *fus_globals TSRMLS_DC) +{ + +} static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) { @@ -416,6 +426,7 @@ #ifdef ZTS zend_compiler_globals *compiler_globals; zend_executor_globals *executor_globals; + zend_fus_globals *fus_globals; void ***tsrm_ls; extern ZEND_API ts_rsrc_id ini_scanner_globals_id; extern ZEND_API ts_rsrc_id language_scanner_globals_id; @@ -483,10 +494,12 @@ global_constants_table = NULL; ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor); ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor); + ts_allocate_id(&fus_globals_id, sizeof(zend_fus_globals), (ts_allocate_ctor) fus_globals_ctor, (ts_allocate_dtor) fus_globals_dtor); ts_allocate_id(&language_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL); ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL); compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); + fus_globals = ts_resource(fus_globals_id); tsrm_ls = ts_resource_ex(0, NULL); compiler_globals_dtor(compiler_globals, tsrm_ls); compiler_globals->function_table = GLOBAL_FUNCTION_TABLE; Index: Zend/zend_globals.h =================================================================== RCS file: /repository/Zend/Attic/zend_globals.h,v retrieving revision 1.93.2.5 diff -u -w -b -u -r1.93.2.5 zend_globals.h --- Zend/zend_globals.h 3 Nov 2004 23:15:05 -0000 1.93.2.5 +++ Zend/zend_globals.h 6 Nov 2004 02:35:28 -0000 @@ -46,6 +46,7 @@ ZEND_API extern int compiler_globals_id; ZEND_API extern int executor_globals_id; ZEND_API extern int alloc_globals_id; +ZEND_API extern int fus_globals_id; END_EXTERN_C() #endif @@ -270,4 +271,10 @@ #endif /* ZEND_MULTIBYTE */ }; +struct _zend_fus_globals { + char *temp_file_dir; + char *temp_file_prefix; + char *hidden_variable_name; +}; + #endif /* ZEND_GLOBALS_H */ Index: Zend/zend_globals_macros.h =================================================================== RCS file: /repository/Zend/Attic/zend_globals_macros.h,v retrieving revision 1.17.8.1 diff -u -w -b -u -r1.17.8.1 zend_globals_macros.h --- Zend/zend_globals_macros.h 31 Dec 2002 16:23:02 -0000 1.17.8.1 +++ Zend/zend_globals_macros.h 6 Nov 2004 02:49:22 -0000 @@ -25,6 +25,8 @@ typedef struct _zend_executor_globals zend_executor_globals; typedef struct _zend_alloc_globals zend_alloc_globals; typedef struct _zend_scanner_globals zend_scanner_globals; +typedef struct _zend_fus_globals zend_fus_globals; + /* Compiler */ #ifdef ZTS @@ -56,6 +58,14 @@ extern ZEND_API zend_alloc_globals alloc_globals; #endif +/* File Upload */ +#ifdef ZTS +# define FUSG(v) TSRMG(fus_globals_id, zend_fus_globals *, v) +#else +# define FUSG(v) (fus_globals.v) +extern ZEND_API zend_fus_globals fus_globals; +#endif + /* Language Scanner */ #ifdef ZTS Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.512.2.56 diff -u -w -b -u -r1.512.2.56 main.c --- main/main.c 1 Oct 2004 14:27:13 -0000 1.512.2.56 +++ main/main.c 6 Nov 2004 02:35:28 -0000 @@ -362,6 +362,10 @@ STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals) +/* file upload status settings */ + STD_PHP_INI_ENTRY("file_upload_status.temp_file_dir", "/tmp", PHP_INI_ALL, OnUpdateString, temp_file_dir, zend_fus_globals, fus_globals) + STD_PHP_INI_ENTRY("file_upload_status.temp_file_prefix", "file_upload_status_", PHP_INI_ALL, OnUpdateString, temp_file_prefix, zend_fus_globals, fus_globals) + STD_PHP_INI_ENTRY("file_upload_status.hidden_variable_name", "file_upload_status_uniqueid", PHP_INI_ALL, OnUpdateString, hidden_variable_name, zend_fus_globals, fus_globals) PHP_INI_END() /* }}} */ @@ -1066,6 +1070,7 @@ void ***tsrm_ls; php_core_globals *core_globals; + zend_fus_globals *fus_globals; #endif #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) @@ -1120,6 +1125,7 @@ executor_globals = ts_resource(executor_globals_id); ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, NULL); core_globals = ts_resource(core_globals_id); + fus_globals = ts_resource(fus_globals_id); #endif EG(bailout_set) = 0; EG(error_reporting) = E_ALL & ~E_NOTICE; Index: main/rfc1867.c =================================================================== RCS file: /repository/php-src/main/rfc1867.c,v retrieving revision 1.122.2.26 diff -u -w -b -u -r1.122.2.26 rfc1867.c --- main/rfc1867.c 13 Sep 2004 16:00:50 -0000 1.122.2.26 +++ main/rfc1867.c 6 Nov 2004 02:20:20 -0000 @@ -779,6 +779,10 @@ zval *array_ptr = (zval *) arg; FILE *fp; zend_llist header; + /* file upload status variables */ + zend_bool file_upload_status = 0; + char *file_upload_status_filename = NULL; + FILE *file_upload_status_fp; if (SG(request_info).content_length > SG(post_max_size)) { sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size)); @@ -908,6 +912,13 @@ max_file_size = atol(value); } + /* Check for upload status hidden variable */ + if (strcasecmp(param, FUSG(hidden_variable_name)) == 0) { + file_upload_status = 1; + file_upload_status_filename = emalloc(strlen(FUSG(temp_file_dir)) + strlen(FUSG(temp_file_prefix)) + strlen(value) + 2); + sprintf(file_upload_status_filename, "%s/%s%s", FUSG(temp_file_dir), FUSG(temp_file_prefix), value); + } + efree(param); efree(value); continue; @@ -998,9 +1009,27 @@ total_bytes += wlen; } } + + /* Write file upload status to file */ + if (file_upload_status) { + file_upload_status_fp = fopen(file_upload_status_filename, "w"); + if(file_upload_status_fp) { + fprintf(file_upload_status_fp, "%li %li %li", SG(read_post_bytes), SG(request_info).content_length, 0); + fclose(file_upload_status_fp); + } + } } fclose(fp); + /* Write file upload "complete" status to file */ + if (file_upload_status) { + file_upload_status_fp = fopen(file_upload_status_filename, "w"); + if(file_upload_status_fp) { + fprintf(file_upload_status_fp, "%li %li %li",SG(read_post_bytes), SG(request_info).content_length,1); + fclose(file_upload_status_fp); + } + } + #ifdef DEBUG_FILE_UPLOAD if(strlen(filename) > 0 && total_bytes == 0) { sapi_module.sapi_error(E_WARNING, "Uploaded file size 0 - file [%s=%s] not saved", param, filename); @@ -1024,6 +1053,11 @@ */ is_arr_upload = (start_arr = strchr(param,'[')) && (param[strlen(param)-1] == ']'); + /* handle unterminated [ */ + if (!is_arr_upload && start_arr) { + *start_arr = '_'; + } + if (is_arr_upload) { array_len = strlen(start_arr); if (array_index) { Index: sapi/cli/php_cli.c =================================================================== RCS file: /repository/php-src/sapi/cli/php_cli.c,v retrieving revision 1.51.2.35 diff -u -w -b -u -r1.51.2.35 php_cli.c --- sapi/cli/php_cli.c 14 Jul 2004 22:38:18 -0000 1.51.2.35 +++ sapi/cli/php_cli.c 6 Nov 2004 02:56:18 -0000 @@ -517,6 +517,7 @@ zend_executor_globals *executor_globals; php_core_globals *core_globals; sapi_globals_struct *sapi_globals; + zend_fus_globals *fus_globals; void ***tsrm_ls; #endif @@ -569,6 +570,7 @@ executor_globals = ts_resource(executor_globals_id); core_globals = ts_resource(core_globals_id); sapi_globals = ts_resource(sapi_globals_id); + fus_globals = ts_resource(fus_globals_id); tsrm_ls = ts_resource(0); #endif
Index: Zend/zend.c =================================================================== RCS file: /repository/Zend/Attic/zend.c,v retrieving revision 1.162.2.21 diff -u -w -b -u -r1.162.2.21 zend.c --- Zend/zend.c 9 Sep 2004 13:27:48 -0000 1.162.2.21 +++ Zend/zend.c 6 Nov 2004 02:27:38 -0000 @@ -80,6 +80,7 @@ ZEND_API int compiler_globals_id; ZEND_API int executor_globals_id; ZEND_API int alloc_globals_id; +ZEND_API int fus_globals_id; HashTable *global_function_table; HashTable *global_class_table; HashTable *global_constants_table; @@ -368,6 +369,15 @@ zend_ini_shutdown(TSRMLS_C); } +static void fus_globals_ctor(zend_fus_globals *fus_globals TSRMLS_DC) +{ + +} + +static void fus_globals_dtor(zend_executor_globals *fus_globals TSRMLS_DC) +{ + +} static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) { @@ -416,6 +426,7 @@ #ifdef ZTS zend_compiler_globals *compiler_globals; zend_executor_globals *executor_globals; + zend_fus_globals *fus_globals; void ***tsrm_ls; extern ZEND_API ts_rsrc_id ini_scanner_globals_id; extern ZEND_API ts_rsrc_id language_scanner_globals_id; @@ -483,10 +494,12 @@ global_constants_table = NULL; ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor); ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor); + ts_allocate_id(&fus_globals_id, sizeof(zend_fus_globals), (ts_allocate_ctor) fus_globals_ctor, (ts_allocate_dtor) fus_globals_dtor); ts_allocate_id(&language_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL); ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL); compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); + fus_globals = ts_resource(fus_globals_id); tsrm_ls = ts_resource_ex(0, NULL); compiler_globals_dtor(compiler_globals, tsrm_ls); compiler_globals->function_table = GLOBAL_FUNCTION_TABLE; Index: Zend/zend_globals.h =================================================================== RCS file: /repository/Zend/Attic/zend_globals.h,v retrieving revision 1.93.2.5 diff -u -w -b -u -r1.93.2.5 zend_globals.h --- Zend/zend_globals.h 3 Nov 2004 23:15:05 -0000 1.93.2.5 +++ Zend/zend_globals.h 6 Nov 2004 02:35:28 -0000 @@ -46,6 +46,7 @@ ZEND_API extern int compiler_globals_id; ZEND_API extern int executor_globals_id; ZEND_API extern int alloc_globals_id; +ZEND_API extern int fus_globals_id; END_EXTERN_C() #endif @@ -270,4 +271,10 @@ #endif /* ZEND_MULTIBYTE */ }; +struct _zend_fus_globals { + char *temp_file_dir; + char *temp_file_prefix; + char *hidden_variable_name; +}; + #endif /* ZEND_GLOBALS_H */ Index: Zend/zend_globals_macros.h =================================================================== RCS file: /repository/Zend/Attic/zend_globals_macros.h,v retrieving revision 1.17.8.1 diff -u -w -b -u -r1.17.8.1 zend_globals_macros.h --- Zend/zend_globals_macros.h 31 Dec 2002 16:23:02 -0000 1.17.8.1 +++ Zend/zend_globals_macros.h 6 Nov 2004 02:49:22 -0000 @@ -25,6 +25,8 @@ typedef struct _zend_executor_globals zend_executor_globals; typedef struct _zend_alloc_globals zend_alloc_globals; typedef struct _zend_scanner_globals zend_scanner_globals; +typedef struct _zend_fus_globals zend_fus_globals; + /* Compiler */ #ifdef ZTS @@ -56,6 +58,14 @@ extern ZEND_API zend_alloc_globals alloc_globals; #endif +/* File Upload */ +#ifdef ZTS +# define FUSG(v) TSRMG(fus_globals_id, zend_fus_globals *, v) +#else +# define FUSG(v) (fus_globals.v) +extern ZEND_API zend_fus_globals fus_globals; +#endif + /* Language Scanner */ #ifdef ZTS Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.512.2.56 diff -u -w -b -u -r1.512.2.56 main.c --- main/main.c 1 Oct 2004 14:27:13 -0000 1.512.2.56 +++ main/main.c 6 Nov 2004 02:35:28 -0000 @@ -362,6 +362,10 @@ STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals) +/* file upload status settings */ + STD_PHP_INI_ENTRY("file_upload_status.temp_file_dir", "/tmp", PHP_INI_ALL, OnUpdateString, temp_file_dir, zend_fus_globals, fus_globals) + STD_PHP_INI_ENTRY("file_upload_status.temp_file_prefix", "file_upload_status_", PHP_INI_ALL, OnUpdateString, temp_file_prefix, zend_fus_globals, fus_globals) + STD_PHP_INI_ENTRY("file_upload_status.hidden_variable_name", "file_upload_status_uniqueid", PHP_INI_ALL, OnUpdateString, hidden_variable_name, zend_fus_globals, fus_globals) PHP_INI_END() /* }}} */ @@ -1066,6 +1070,7 @@ void ***tsrm_ls; php_core_globals *core_globals; + zend_fus_globals *fus_globals; #endif #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) @@ -1120,6 +1125,7 @@ executor_globals = ts_resource(executor_globals_id); ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, NULL); core_globals = ts_resource(core_globals_id); + fus_globals = ts_resource(fus_globals_id); #endif EG(bailout_set) = 0; EG(error_reporting) = E_ALL & ~E_NOTICE; Index: main/rfc1867.c =================================================================== RCS file: /repository/php-src/main/rfc1867.c,v retrieving revision 1.122.2.26 diff -u -w -b -u -r1.122.2.26 rfc1867.c --- main/rfc1867.c 13 Sep 2004 16:00:50 -0000 1.122.2.26 +++ main/rfc1867.c 6 Nov 2004 02:20:20 -0000 @@ -779,6 +779,10 @@ zval *array_ptr = (zval *) arg; FILE *fp; zend_llist header; + /* file upload status variables */ + zend_bool file_upload_status = 0; + char *file_upload_status_filename = NULL; + FILE *file_upload_status_fp; if (SG(request_info).content_length > SG(post_max_size)) { sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size)); @@ -908,6 +912,13 @@ max_file_size = atol(value); } + /* Check for upload status hidden variable */ + if (strcasecmp(param, FUSG(hidden_variable_name)) == 0) { + file_upload_status = 1; + file_upload_status_filename = emalloc(strlen(FUSG(temp_file_dir)) + strlen(FUSG(temp_file_prefix)) + strlen(value) + 2); + sprintf(file_upload_status_filename, "%s/%s%s", FUSG(temp_file_dir), FUSG(temp_file_prefix), value); + } + efree(param); efree(value); continue; @@ -998,9 +1009,27 @@ total_bytes += wlen; } } + + /* Write file upload status to file */ + if (file_upload_status) { + file_upload_status_fp = fopen(file_upload_status_filename, "w"); + if(file_upload_status_fp) { + fprintf(file_upload_status_fp, "%li %li %li", SG(read_post_bytes), SG(request_info).content_length, 0); + fclose(file_upload_status_fp); + } + } } fclose(fp); + /* Write file upload "complete" status to file */ + if (file_upload_status) { + file_upload_status_fp = fopen(file_upload_status_filename, "w"); + if(file_upload_status_fp) { + fprintf(file_upload_status_fp, "%li %li %li",SG(read_post_bytes), SG(request_info).content_length,1); + fclose(file_upload_status_fp); + } + } + #ifdef DEBUG_FILE_UPLOAD if(strlen(filename) > 0 && total_bytes == 0) { sapi_module.sapi_error(E_WARNING, "Uploaded file size 0 - file [%s=%s] not saved", param, filename); @@ -1024,6 +1053,11 @@ */ is_arr_upload = (start_arr = strchr(param,'[')) && (param[strlen(param)-1] == ']'); + /* handle unterminated [ */ + if (!is_arr_upload && start_arr) { + *start_arr = '_'; + } + if (is_arr_upload) { array_len = strlen(start_arr); if (array_index) { Index: sapi/cli/php_cli.c =================================================================== RCS file: /repository/php-src/sapi/cli/php_cli.c,v retrieving revision 1.51.2.35 diff -u -w -b -u -r1.51.2.35 php_cli.c --- sapi/cli/php_cli.c 14 Jul 2004 22:38:18 -0000 1.51.2.35 +++ sapi/cli/php_cli.c 6 Nov 2004 02:56:18 -0000 @@ -517,6 +517,7 @@ zend_executor_globals *executor_globals; php_core_globals *core_globals; sapi_globals_struct *sapi_globals; + zend_fus_globals *fus_globals; void ***tsrm_ls; #endif @@ -569,6 +570,7 @@ executor_globals = ts_resource(executor_globals_id); core_globals = ts_resource(core_globals_id); sapi_globals = ts_resource(sapi_globals_id); + fus_globals = ts_resource(fus_globals_id); tsrm_ls = ts_resource(0); #endif