From 50d4a16be3fcf4ef8909f4a4785d1416c4de81fe Mon Sep 17 00:00:00 2001 From: Jan-E Date: Sun, 15 Mar 2015 21:50:48 +0100 Subject: [PATCH] PHP 7 support --- uploadprogress.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/uploadprogress.c b/uploadprogress.c index e66b724..864ebd7 100644 --- a/uploadprogress.c +++ b/uploadprogress.c @@ -71,7 +71,7 @@ PHPAPI extern int (*php_rfc1867_callback)(unsigned int , void *, void ** TSRMLS_ */ static int uploadprogress_php_rfc1867_file(unsigned int event, void *event_data, void **data TSRMLS_DC) { - zval handler; + //zval handler; char *callable = NULL; uploadprogress_data * progress; int read_bytes; @@ -301,7 +301,7 @@ PHP_FUNCTION(uploadprogress_get_info) { char * id; int id_lg; - char method; + //char method; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &id, &id_lg) == FAILURE) { return; @@ -417,7 +417,11 @@ static void uploadprogress_file_php_get_info(char * id, zval * return_value) v[index] = 0; } } +#if defined(ZEND_ENGINE_3) + add_assoc_string( return_value, k, v ); +#else add_assoc_string( return_value, k, v, 1 ); +#endif } fclose(F); } @@ -432,10 +436,18 @@ static void uploadprogress_file_php_get_info(char * id, zval * return_value) */ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long maxlen, zval *return_value) { +#if defined(ZEND_ENGINE_3) /* borrowed from phar/func_interceptors.c */ + char *filename, *template, *data_identifier; + zend_string *contents; +#else char *filename, *template, *contents, *data_identifier; +#endif php_stream *stream; int options = ENFORCE_SAFE_MODE; - int len, newlen; + int len; +#if PHP_API_VERSION < 20100412 + int newlen; +#endif TSRMLS_FETCH(); template = INI_STR("uploadprogress.file.contents_template"); @@ -455,7 +467,13 @@ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long } /* uses mmap if possible */ +#if defined(ZEND_ENGINE_3) + contents = php_stream_copy_to_mem(stream, maxlen, 0); + len = contents->len; + if (contents && len > 0) { +#else if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) { +#endif #if PHP_API_VERSION < 20100412 if (PG(magic_quotes_runtime)) { @@ -463,7 +481,11 @@ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long len = newlen; } #endif +#if defined(ZEND_ENGINE_3) + RETVAL_STRINGL((char *)contents, len); +#else RETVAL_STRINGL(contents, len, 0); +#endif } else if (len == 0) { RETVAL_EMPTY_STRING(); } else { From b8462d6631dc6ba4bfb6d0d23fa903efc9591e6f Mon Sep 17 00:00:00 2001 From: Jan-E Date: Sun, 15 Mar 2015 21:54:11 +0100 Subject: [PATCH] Tabs 2 spaces --- uploadprogress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/uploadprogress.c b/uploadprogress.c index 864ebd7..7b11ea9 100644 --- a/uploadprogress.c +++ b/uploadprogress.c @@ -436,9 +436,9 @@ static void uploadprogress_file_php_get_info(char * id, zval * return_value) */ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long maxlen, zval *return_value) { -#if defined(ZEND_ENGINE_3) /* borrowed from phar/func_interceptors.c */ +#if defined(ZEND_ENGINE_3) char *filename, *template, *data_identifier; - zend_string *contents; + zend_string *contents; #else char *filename, *template, *contents, *data_identifier; #endif @@ -468,9 +468,9 @@ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long /* uses mmap if possible */ #if defined(ZEND_ENGINE_3) - contents = php_stream_copy_to_mem(stream, maxlen, 0); - len = contents->len; - if (contents && len > 0) { + contents = php_stream_copy_to_mem(stream, maxlen, 0); + len = contents->len; + if (contents && len > 0) { #else if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) { #endif From ac54045b98863f647bdc0e5b1af2e841a68d3dcb Mon Sep 17 00:00:00 2001 From: Jan-E Date: Fri, 3 Apr 2015 02:10:58 +0200 Subject: [PATCH] ENFORCE_SAFE_MODE is dropped --- uploadprogress.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/uploadprogress.c b/uploadprogress.c index 7b11ea9..f164434 100644 --- a/uploadprogress.c +++ b/uploadprogress.c @@ -157,8 +157,12 @@ static int uploadprogress_php_rfc1867_file(unsigned int event, void *event_data if (get_contents) { php_stream *stream; +#if defined(ZEND_ENGINE_3) + int options = 0; +#else int options = ENFORCE_SAFE_MODE; - +#endif + stream = php_stream_open_wrapper(progress->data_filename, "ab", options, NULL); if (stream) { php_stream_write(stream, e_data->data, e_data->length); @@ -443,7 +447,11 @@ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long char *filename, *template, *contents, *data_identifier; #endif php_stream *stream; +#if defined(ZEND_ENGINE_3) + int options = 0; +#else int options = ENFORCE_SAFE_MODE; +#endif int len; #if PHP_API_VERSION < 20100412 int newlen; From 5f1e1fa97c8d32dacbed1fccd2e2f3bc2decd615 Mon Sep 17 00:00:00 2001 From: Jan-E Date: Thu, 9 Apr 2015 14:22:39 +0200 Subject: [PATCH] avoid duplication and memory leak --- uploadprogress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uploadprogress.c b/uploadprogress.c index f164434..849257e 100644 --- a/uploadprogress.c +++ b/uploadprogress.c @@ -490,7 +490,7 @@ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long } #endif #if defined(ZEND_ENGINE_3) - RETVAL_STRINGL((char *)contents, len); + RETVAL_STR(contents); #else RETVAL_STRINGL(contents, len, 0); #endif