summaryrefslogtreecommitdiffstats
path: root/uploadprogress-php7.patch
blob: aebc544fe28fe427ca09ba395b7a1e67d97dfac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
From 50d4a16be3fcf4ef8909f4a4785d1416c4de81fe Mon Sep 17 00:00:00 2001
From: Jan-E <github@ehrhardt.nl>
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 <github@ehrhardt.nl>
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 <github@ehrhardt.nl>
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 <github@ehrhardt.nl>
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