]> git.pld-linux.org Git - packages/php.git/blame - system-libzip.patch
- readline rebuild
[packages/php.git] / system-libzip.patch
CommitLineData
c638a5d4 1https://bugzilla.redhat.com/show_bug.cgi?id=551513
2https://bugs.php.net/bug.php?id=39388
3http://spot.fedorapeople.org/php-5.3.6-libzip.patch
4pld fixes: link with -lzip when using system lib, -lz otherwise
5
3f5c4b2e
ER
6diff -up php-5.4.5RC1/ext/zip/config.m4.systzip php-5.4.5RC1/ext/zip/config.m4
7--- php-5.4.5RC1/ext/zip/config.m4.systzip 2012-07-04 07:43:14.000000000 +0200
8+++ php-5.4.5RC1/ext/zip/config.m4 2012-07-07 15:56:41.418171233 +0200
9@@ -13,65 +13,105 @@ fi
c638a5d4 10 PHP_ARG_WITH(pcre-dir, pcre install prefix,
11 [ --with-pcre-dir ZIP: pcre install prefix], no, no)
12
3f5c4b2e 13-if test "$PHP_ZIP" != "no"; then
c638a5d4 14+PHP_ARG_WITH(libzip, libzip,
3f5c4b2e
ER
15+[ --with-libzip[=DIR] ZIP: use libzip], no, no)
16
17- if test "$PHP_ZLIB_DIR" != "no" && test "$PHP_ZLIB_DIR" != "yes"; then
18- if test -f "$PHP_ZLIB_DIR/include/zlib/zlib.h"; then
19- PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
20- PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include/zlib"
21- elif test -f "$PHP_ZLIB_DIR/include/zlib.h"; then
22- PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
23- PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include"
24+if test "$PHP_ZIP" != "no"; then
c638a5d4 25+ if test "$PHP_LIBZIP" != "no"; then
26+ dnl system libzip, depends on libzip
27+ if test -r $PHP_LIBZIP/include/zip.h; then
28+ LIBZIP_DIR=$PHP_LIBZIP
3f5c4b2e
ER
29 else
30- AC_MSG_ERROR([Can not find zlib headers under "$PHP_ZLIB_DIR"])
c638a5d4 31+ AC_MSG_CHECKING(for libzip in default path)
32+ for i in /usr/local /usr; do
33+ if test -r $i/include/zip.h; then
34+ LIBZIP_DIR=$i
35+ AC_MSG_RESULT(found in $i)
36+ break
37+ fi
38+ done
39+ fi
40+
41+ if test -z "$LIBZIP_DIR"; then
42+ AC_MSG_RESULT(not found)
43+ AC_MSG_ERROR(Please reinstall the libzip distribution)
3f5c4b2e
ER
44 fi
45+
c638a5d4 46+ dnl Could not think of a simple way to check libzip for overwrite support
47+ PHP_CHECK_LIBRARY(zip, zip_open,
48+ [
49+ PHP_ADD_INCLUDE($LIBZIP_DIR/include)
50+ PHP_ADD_LIBRARY_WITH_PATH(zip, $LIBZIP_DIR/$PHP_LIBDIR, ZIP_SHARED_LIBADD)
51+ AC_DEFINE(HAVE_LIBZIP,1,[ ])
52+ ], [
53+ AC_MSG_ERROR(could not find usable libzip)
54+ ], [
55+ -L$LIBZIP_DIR/$PHP_LIBDIR
56+ ])
57+
3f5c4b2e 58+ AC_DEFINE(HAVE_ZIP,1,[ ])
c638a5d4 59+ PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c, $ext_shared)
60+ PHP_SUBST(ZIP_SHARED_LIBADD)
3f5c4b2e
ER
61 else
62- for i in /usr/local /usr; do
63- if test -f "$i/include/zlib/zlib.h"; then
64- PHP_ZLIB_DIR="$i"
65- PHP_ZLIB_INCDIR="$i/include/zlib"
66- elif test -f "$i/include/zlib.h"; then
67- PHP_ZLIB_DIR="$i"
68- PHP_ZLIB_INCDIR="$i/include"
c638a5d4 69+
70+ dnl bundled libzip, depends on zlib
3f5c4b2e
ER
71+ if test "$PHP_ZLIB_DIR" != "no" && test "$PHP_ZLIB_DIR" != "yes"; then
72+ if test -f "$PHP_ZLIB_DIR/include/zlib/zlib.h"; then
73+ PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
74+ PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include/zlib"
75+ elif test -f "$PHP_ZLIB_DIR/include/zlib.h"; then
76+ PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
77+ PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include"
78+ else
79+ AC_MSG_ERROR([Can not find zlib headers under "$PHP_ZLIB_DIR"])
80 fi
81- done
82- fi
83+ else
84+ for i in /usr/local /usr; do
85+ if test -f "$i/include/zlib/zlib.h"; then
86+ PHP_ZLIB_DIR="$i"
87+ PHP_ZLIB_INCDIR="$i/include/zlib"
88+ elif test -f "$i/include/zlib.h"; then
89+ PHP_ZLIB_DIR="$i"
90+ PHP_ZLIB_INCDIR="$i/include"
91+ fi
92+ done
93+ fi
94
95- dnl # zlib
96- AC_MSG_CHECKING([for the location of zlib])
97- if test "$PHP_ZLIB_DIR" = "no"; then
98- AC_MSG_ERROR([zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located])
99- else
100- AC_MSG_RESULT([$PHP_ZLIB_DIR])
101- PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/$PHP_LIBDIR, ZIP_SHARED_LIBADD)
102- PHP_ADD_INCLUDE($PHP_ZLIB_INCDIR)
103- fi
104+ dnl # zlib
105+ AC_MSG_CHECKING([for the location of zlib])
106+ if test "$PHP_ZLIB_DIR" = "no"; then
107+ AC_MSG_ERROR([zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located])
108+ else
109+ AC_MSG_RESULT([$PHP_ZLIB_DIR])
110+ PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/$PHP_LIBDIR, ZIP_SHARED_LIBADD)
111+ PHP_ADD_INCLUDE($PHP_ZLIB_INCDIR)
112+ fi
c638a5d4 113
114- dnl This is PECL build, check if bundled PCRE library is used
115- old_CPPFLAGS=$CPPFLAGS
116- CPPFLAGS=$INCLUDES
117- AC_EGREP_CPP(yes,[
3f5c4b2e
ER
118+ dnl This is PECL build, check if bundled PCRE library is used
119+ old_CPPFLAGS=$CPPFLAGS
120+ CPPFLAGS=$INCLUDES
121+ AC_EGREP_CPP(yes,[
122 #include <main/php_config.h>
123 #if defined(HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
124 yes
125 #endif
c638a5d4 126- ],[
127- PHP_PCRE_REGEX=yes
128- ],[
129- AC_EGREP_CPP(yes,[
3f5c4b2e
ER
130+ ],[
131+ PHP_PCRE_REGEX=yes
132+ ],[
133+ AC_EGREP_CPP(yes,[
134 #include <main/php_config.h>
135 #if defined(HAVE_PCRE) && !defined(COMPILE_DL_PCRE)
136 yes
137 #endif
c638a5d4 138- ],[
139- PHP_PCRE_REGEX=pecl
140- ],[
141- PHP_PCRE_REGEX=no
3f5c4b2e
ER
142+ ],[
143+ PHP_PCRE_REGEX=pecl
144+ ],[
145+ PHP_PCRE_REGEX=no
146+ ])
147 ])
c638a5d4 148- ])
149- CPPFLAGS=$old_CPPFLAGS
3f5c4b2e
ER
150+ CPPFLAGS=$old_CPPFLAGS
151
c638a5d4 152- PHP_ZIP_SOURCES="$PHP_ZIP_SOURCES lib/zip_add.c lib/zip_error.c lib/zip_fclose.c \
153+ PHP_ZIP_SOURCES="$PHP_ZIP_SOURCES lib/zip_add.c lib/zip_error.c lib/zip_fclose.c \
154 lib/zip_fread.c lib/zip_open.c lib/zip_source_filep.c \
155 lib/zip_strerror.c lib/zip_close.c lib/zip_error_get.c \
156 lib/zip_file_error_get.c lib/zip_free.c lib/zip_rename.c \
3f5c4b2e
ER
157@@ -98,10 +138,11 @@ yes
158 lib/zip_source_open.c lib/zip_source_pkware.c lib/zip_source_pop.c \
159 lib/zip_source_read.c lib/zip_source_stat.c"
c638a5d4 160
161- AC_DEFINE(HAVE_ZIP,1,[ ])
162- PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c $PHP_ZIP_SOURCES, $ext_shared)
163- PHP_ADD_BUILD_DIR($ext_builddir/lib, 1)
164- PHP_SUBST(ZIP_SHARED_LIBADD)
165+ AC_DEFINE(HAVE_ZIP,1,[ ])
166+ PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c $PHP_ZIP_SOURCES, $ext_shared)
167+ PHP_ADD_BUILD_DIR($ext_builddir/lib, 1)
168+ PHP_SUBST(ZIP_SHARED_LIBADD)
169+ fi
170
171 dnl so we always include the known-good working hack.
172 PHP_ADD_MAKEFILE_FRAGMENT
3f5c4b2e
ER
173diff -up php-5.4.5RC1/ext/zip/php_zip.c.systzip php-5.4.5RC1/ext/zip/php_zip.c
174--- php-5.4.5RC1/ext/zip/php_zip.c.systzip 2012-07-04 07:43:14.000000000 +0200
175+++ php-5.4.5RC1/ext/zip/php_zip.c 2012-07-07 15:59:12.728676026 +0200
176@@ -29,8 +29,232 @@
177 #include "ext/standard/php_string.h"
178 #include "ext/pcre/php_pcre.h"
179 #include "php_zip.h"
180+#if defined(HAVE_LIBZIP)
181+#include <zip.h>
182+
183+/* Copied from libzip 0.10 */
184+
185+/* state of change of a file in zip archive */
186+
187+enum zip_state { ZIP_ST_UNCHANGED, ZIP_ST_DELETED, ZIP_ST_REPLACED,
188+ ZIP_ST_ADDED, ZIP_ST_RENAMED };
189+
190+/* error source for layered sources */
191+
192+enum zip_les { ZIP_LES_NONE, ZIP_LES_UPPER, ZIP_LES_LOWER, ZIP_LES_INVAL };
193+
194+typedef zip_int64_t (*zip_source_layered_callback)(struct zip_source *, void *,
195+ void *, zip_uint64_t,
196+ enum zip_source_cmd);
197+
198+struct zip_error {
199+ int zip_err; /* libzip error code (ZIP_ER_*) */
200+ int sys_err; /* copy of errno (E*) or zlib error code */
201+ char *str; /* string representation or NULL */
202+};
203+
204+/* zip archive, part of API */
205+
206+struct zip {
207+ char *zn; /* file name */
208+ FILE *zp; /* file */
209+ struct zip_error error; /* error information */
210+
211+ unsigned int flags; /* archive global flags */
212+ unsigned int ch_flags; /* changed archive global flags */
213+
214+ char *default_password; /* password used when no other supplied */
215+
216+ struct zip_cdir *cdir; /* central directory */
217+ char *ch_comment; /* changed archive comment */
218+ int ch_comment_len; /* length of changed zip archive
219+ * comment, -1 if unchanged */
220+ zip_uint64_t nentry; /* number of entries */
221+ zip_uint64_t nentry_alloc; /* number of entries allocated */
222+ struct zip_entry *entry; /* entries */
223+ int nfile; /* number of opened files within archive */
224+ int nfile_alloc; /* number of files allocated */
225+ struct zip_file **file; /* opened files within archive */
226+};
227+
228+/* file in zip archive, part of API */
229+
230+struct zip_file {
231+ struct zip *za; /* zip archive containing this file */
232+ struct zip_error error; /* error information */
233+ int eof;
234+ struct zip_source *src; /* data source */
235+};
236+
237+/* zip archive directory entry (central or local) */
238+
239+struct zip_dirent {
240+ unsigned short version_madeby; /* (c) version of creator */
241+ unsigned short version_needed; /* (cl) version needed to extract */
242+ unsigned short bitflags; /* (cl) general purpose bit flag */
243+ unsigned short comp_method; /* (cl) compression method used */
244+ time_t last_mod; /* (cl) time of last modification */
245+ unsigned int crc; /* (cl) CRC-32 of uncompressed data */
246+ unsigned int comp_size; /* (cl) size of commpressed data */
247+ unsigned int uncomp_size; /* (cl) size of uncommpressed data */
248+ char *filename; /* (cl) file name (NUL-terminated) */
249+ unsigned short filename_len; /* (cl) length of filename (w/o NUL) */
250+ char *extrafield; /* (cl) extra field */
251+ unsigned short extrafield_len; /* (cl) length of extra field */
252+ char *comment; /* (c) file comment */
253+ unsigned short comment_len; /* (c) length of file comment */
254+ unsigned short disk_number; /* (c) disk number start */
255+ unsigned short int_attrib; /* (c) internal file attributes */
256+ unsigned int ext_attrib; /* (c) external file attributes */
257+ unsigned int offset; /* (c) offset of local header */
258+};
259+
260+/* zip archive central directory */
261+
262+struct zip_cdir {
263+ struct zip_dirent *entry; /* directory entries */
264+ int nentry; /* number of entries */
265+
266+ unsigned int size; /* size of central direcotry */
267+ unsigned int offset; /* offset of central directory in file */
268+ char *comment; /* zip archive comment */
269+ unsigned short comment_len; /* length of zip archive comment */
270+};
271+
272+struct zip_source {
273+ struct zip_source *src;
274+ union {
275+ zip_source_callback f;
276+ zip_source_layered_callback l;
277+ } cb;
278+ void *ud;
279+ enum zip_les error_source;
280+ int is_open;
281+};
282+
283+/* entry in zip archive directory */
284+
285+struct zip_entry {
286+ enum zip_state state;
287+ struct zip_source *source;
288+ char *ch_filename;
289+ char *ch_extra;
290+ int ch_extra_len;
291+ char *ch_comment;
292+ int ch_comment_len;
293+};
294+
295+void _zip_dirent_finalize(struct zip_dirent *zde)
296+{
297+ free(zde->filename);
298+ zde->filename = NULL;
299+ free(zde->extrafield);
300+ zde->extrafield = NULL;
301+ free(zde->comment);
302+ zde->comment = NULL;
303+}
304+
305+void _zip_cdir_free(struct zip_cdir *cd)
306+{
307+ int i;
308+
309+ if (!cd)
310+ return;
311+
312+ for (i=0; i<cd->nentry; i++)
313+ _zip_dirent_finalize(cd->entry+i);
314+ free(cd->comment);
315+ free(cd->entry);
316+ free(cd);
317+}
318+
319+void _zip_error_fini(struct zip_error *err)
320+{
321+ free(err->str);
322+ err->str = NULL;
323+}
324+
325+void _zip_error_init(struct zip_error *err)
326+{
327+ err->zip_err = ZIP_ER_OK;
328+ err->sys_err = 0;
329+ err->str = NULL;
330+}
331+
332+void _zip_unchange_data(struct zip_entry *ze)
333+{
334+ if (ze->source) {
335+ zip_source_free(ze->source);
336+ ze->source = NULL;
337+ }
338+
339+ ze->state = ze->ch_filename ? ZIP_ST_RENAMED : ZIP_ST_UNCHANGED;
340+}
341+
342+void _zip_entry_free(struct zip_entry *ze)
343+{
344+ free(ze->ch_filename);
345+ ze->ch_filename = NULL;
346+ free(ze->ch_extra);
347+ ze->ch_extra = NULL;
348+ ze->ch_extra_len = -1;
349+ free(ze->ch_comment);
350+ ze->ch_comment = NULL;
351+ ze->ch_comment_len = -1;
352+
353+ _zip_unchange_data(ze);
354+}
355+
356+void
357+_zip_error_set(struct zip_error *err, int ze, int se)
358+{
359+ if (err) {
360+ err->zip_err = ze;
361+ err->sys_err = se;
362+ }
363+}
364+
365+void _zip_free(struct zip *za)
366+{
367+ int i;
368+
369+ if (za == NULL)
370+ return;
371+
372+ if (za->zn)
373+ free(za->zn);
374+
375+ if (za->zp)
376+ fclose(za->zp);
377+
378+ free(za->default_password);
379+ _zip_cdir_free(za->cdir);
380+ free(za->ch_comment);
381+
382+ if (za->entry) {
383+ for (i=0; i<za->nentry; i++) {
384+ _zip_entry_free(za->entry+i);
385+ }
386+ free(za->entry);
387+ }
388+
389+ for (i=0; i<za->nfile; i++) {
390+ if (za->file[i]->error.zip_err == ZIP_ER_OK) {
391+ _zip_error_set(&za->file[i]->error, ZIP_ER_ZIPCLOSED, 0);
392+ za->file[i]->za = NULL;
393+ }
394+ }
395+
396+ free(za->file);
397+ free(za);
398+ return;
399+}
400+
401+
402+#else
403 #include "lib/zip.h"
404 #include "lib/zipint.h"
405+#endif
406
407 /* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
408 static PHP_NAMED_FUNCTION(zif_zip_open);
409@@ -1624,6 +1848,10 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
410 }
411
412 idx = zip_stat(intern, s, 0, &sb);
413+ /* We don't care about the NOENT status error here. */
414+ if (intern->error.zip_err == ZIP_ER_NOENT) {
415+ _zip_error_set(&intern->error, ZIP_ER_OK, 0);
416+ }
417 if (idx >= 0) {
418 RETVAL_FALSE;
419 } else {
420@@ -1846,6 +2074,10 @@ static ZIPARCHIVE_METHOD(addFromString)
421 }
422
423 cur_idx = zip_name_locate(intern, (const char *)name, 0);
424+ /* We don't care about the NOENT status error here. */
425+ if (intern->error.zip_err == ZIP_ER_NOENT) {
426+ _zip_error_set(&intern->error, ZIP_ER_OK, 0);
427+ }
428 /* TODO: fix _zip_replace */
429 if (cur_idx >= 0) {
430 if (zip_delete(intern, cur_idx) == -1) {
431@@ -2868,7 +3100,11 @@ static PHP_MINFO_FUNCTION(zip)
432 php_info_print_table_row(2, "Zip", "enabled");
433 php_info_print_table_row(2, "Extension Version","$Id$");
434 php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION_STRING);
435- php_info_print_table_row(2, "Libzip version", LIBZIP_VERSION);
436+#if defined(HAVE_LIBZIP)
437+ php_info_print_table_row(2, "Compiled against libzip version", LIBZIP_VERSION);
438+#else
439+ php_info_print_table_row(2, "Bundled libzip version", LIBZIP_VERSION);
440+#endif
441
442 php_info_print_table_end();
443 }
444diff -up php-5.4.5RC1/ext/zip/php_zip.h.systzip php-5.4.5RC1/ext/zip/php_zip.h
445--- php-5.4.5RC1/ext/zip/php_zip.h.systzip 2012-07-04 07:43:14.000000000 +0200
446+++ php-5.4.5RC1/ext/zip/php_zip.h 2012-07-07 15:57:34.845319432 +0200
447@@ -28,7 +28,11 @@ extern zend_module_entry zip_module_entr
448 #include "TSRM.h"
449 #endif
450
451+#if defined(HAVE_LIBZIP)
452+#include <zip.h>
453+#else
454 #include "lib/zip.h"
455+#endif
456
457 #define PHP_ZIP_VERSION_STRING "1.11.0"
458
459diff -up php-5.4.5RC1/ext/zip/tests/bug38943.phpt.systzip php-5.4.5RC1/ext/zip/tests/bug38943.phpt
460--- php-5.4.5RC1/ext/zip/tests/bug38943.phpt.systzip 2012-07-04 07:43:14.000000000 +0200
461+++ php-5.4.5RC1/ext/zip/tests/bug38943.phpt 2012-07-07 15:56:41.422171242 +0200
462@@ -27,7 +27,7 @@ array(1) {
463 [0]=>
464 int(1)
465 }
466-object(myZip)#1 (%d) {
467+object(myZip)#%d (%d) {
468 ["test":"myZip":private]=>
469 int(0)
470 ["testp"]=>
471diff -up php-5.4.5RC1/ext/zip/tests/pecl12414.phpt.systzip php-5.4.5RC1/ext/zip/tests/pecl12414.phpt
472--- php-5.4.5RC1/ext/zip/tests/pecl12414.phpt.systzip 2012-07-04 07:43:14.000000000 +0200
473+++ php-5.4.5RC1/ext/zip/tests/pecl12414.phpt 2012-07-07 15:56:41.422171242 +0200
474@@ -5,6 +5,8 @@ Bug #12414 ( extracting files from damag
475 /*$ */
476 if(!extension_loaded('zip')) die('skip');
477 ?>
478+--XFAIL--
479+Doesn't work with system libzip (zip_readfile could not read from ...)
480 --FILE--
481 <?php
482 $filename = 'MYLOGOV2.GFX';
483diff -up php-5.4.5RC1/ext/zip/zip_stream.c.systzip php-5.4.5RC1/ext/zip/zip_stream.c
484--- php-5.4.5RC1/ext/zip/zip_stream.c.systzip 2012-07-04 07:43:14.000000000 +0200
485+++ php-5.4.5RC1/ext/zip/zip_stream.c 2012-07-07 15:56:41.423171244 +0200
486@@ -6,7 +6,11 @@
487 #if HAVE_ZIP
488 #ifdef ZEND_ENGINE_2
489
490+#if defined(HAVE_LIBZIP)
491+#include <zip.h>
492+#else
493 #include "lib/zip.h"
494+#endif
495
496 #include "php_streams.h"
497 #include "ext/standard/file.h"
This page took 0.098973 seconds and 4 git commands to generate.