cvs: pecl /zip config.m4 php_zip.c php_zip.h /zip/examples fopen.php

From: Date: Mon, 16 Jan 2006 15:55:58 +0000
Subject: cvs: pecl /zip config.m4 php_zip.c php_zip.h /zip/examples fopen.php
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-4968@lists.php.net to get a copy of this message
pajoye Mon Jan 16 15:55:58 2006 UTC Added files: /pecl/zip/examples fopen.php Modified files: /pecl/zip config.m4 php_zip.c php_zip.h Log: - add stream support - Zip::getStream("entry", "r");, readonly for now http://cvs.php.net/viewcvs.cgi/pecl/zip/config.m4?r1=1.4&r2=1.5&diff_format=u Index: pecl/zip/config.m4 diff -u pecl/zip/config.m4:1.4 pecl/zip/config.m4:1.5 --- pecl/zip/config.m4:1.4 Sat Jan 14 15:13:17 2006 +++ pecl/zip/config.m4 Mon Jan 16 15:55:58 2006 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.4 2006/01/14 15:13:17 johannes Exp $ +dnl $Id: config.m4,v 1.5 2006/01/16 15:55:58 pajoye Exp $ dnl PHP_ARG_ENABLE(zip, for zip archive read/writesupport, @@ -41,6 +41,6 @@ lib/zip_new.c lib/zip_source_file.c lib/zip_stat_index.c" AC_DEFINE(HAVE_ZIP,1,[ ]) - PHP_NEW_EXTENSION(zip, php_zip.c $PHP_ZIP_SOURCES, $ext_shared) + PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c $PHP_ZIP_SOURCES, $ext_shared) PHP_SUBST(ZIP_SHARED_LIBADD) fi http://cvs.php.net/viewcvs.cgi/pecl/zip/php_zip.c?r1=1.4&r2=1.5&diff_format=u Index: pecl/zip/php_zip.c diff -u pecl/zip/php_zip.c:1.4 pecl/zip/php_zip.c:1.5 --- pecl/zip/php_zip.c:1.4 Sat Jan 14 14:31:38 2006 +++ pecl/zip/php_zip.c Mon Jan 16 15:55:58 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_zip.c,v 1.4 2006/01/14 14:31:38 johannes Exp $ */ +/* $Id: php_zip.c,v 1.5 2006/01/16 15:55:58 pajoye Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -30,17 +30,6 @@ #include "php_zip.h" #include "lib/zip.h" -typedef struct zip * zipPtr; - -static void _zip_real_path(char *path, char *resolved TSRMLS_DC) { - char resolved_path[MAXPATHLEN + 1]; - char *file_dest; - - if (!VCWD_REALPATH(path, resolved_path)) { - expand_filepath(path, resolved TSRMLS_CC); - } -} - /* {{{ SAFEMODE_CHECKFILE(filename) */ #define SAFEMODE_CHECKFILE(filename) \ (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(filename TSRMLS_CC) @@ -179,7 +168,7 @@ /* }}} */ /* {{{ zip_get_status */ -static int zip_status(zipPtr za TSRMLS_DC) { +static int zip_status(struct zip *za TSRMLS_DC) { int zep, syp; zip_error_get(za, &zep, &syp); @@ -188,7 +177,7 @@ /* }}} */ /* {{{ zip_get_status */ -static int zip_status_sys(zipPtr za TSRMLS_DC) { +static int zip_status_sys(struct zip *za TSRMLS_DC) { int zep, syp; zip_error_get(za, &zep, &syp); @@ -346,7 +335,8 @@ return; } if (intern->za) { - zip_close(intern->za); + zip_close(intern->za); + intern->za = NULL; } if (intern->buffers_cnt>0) { @@ -443,9 +433,7 @@ PHP_METHOD(zip, open) { struct zip *intern; - char *valid_file = NULL; char *filename; - char resolved_path[MAXPATHLEN + 1]; int filename_len; int err; @@ -752,7 +740,6 @@ ze_zip_object *ze_obj; zval *zval_files = NULL; zval **zval_file = NULL; - int zep, syp; char *pathto; char *file; int pathto_len; @@ -819,6 +806,44 @@ } /* }}} */ +/* {{{ proto resource getStream(string entryname) +get a stream for the given entry */ +PHP_METHOD(zip, getStream) +{ + struct zip *intern; + zval *this = getThis(); + struct zip_stat sb; + char *filename; + int filename_len; + char *mode; + int mode_len; + php_stream *stream; + ze_zip_object *obj; + + if (!this) { + RETURN_FALSE; + } + + ZIP_FROM_OBJECT(intern, this); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &filename, &filename_len, &mode, &mode_len) == FAILURE) { + WRONG_PARAM_COUNT; + return; + } + + if (zip_stat(intern, filename, 0, &sb)) { + RETURN_FALSE; + } + + obj = (ze_zip_object*) zend_object_store_get_object(this TSRMLS_CC); + + stream = php_stream_zip_open(obj->filename, filename, mode STREAMS_CC TSRMLS_CC); + if (stream) { + php_stream_to_zval(stream, return_value); + } +} +/* }}} */ + /* {{{ ze_zip_object_class_functions */ static zend_function_entry zip_class_functions[] = { PHP_ME(zip, open, NULL, ZEND_ACC_PUBLIC) @@ -830,12 +855,12 @@ PHP_ME(zip, stat, NULL, ZEND_ACC_PUBLIC) PHP_ME(zip, statIndex, NULL, ZEND_ACC_PUBLIC) PHP_ME(zip, extractTo, NULL, ZEND_ACC_PUBLIC) + PHP_ME(zip, getStream, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ -/* {{{ PHP_MINIT_FUNCTION - */ +/* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(zip) { zend_class_entry ce; @@ -875,6 +900,10 @@ REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE", ZIP_CM_DEFLATE); REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFLATE64", ZIP_CM_DEFLATE64); REGISTER_ZIP_CLASS_CONST_LONG("CM_PKWARE_IMPLODE", ZIP_CM_PKWARE_IMPLODE); + +#if ZIP_USE_WRAPPER + php_register_url_stream_wrapper("zip", &php_stream_zip_wrapper TSRMLS_CC); +#endif return SUCCESS; } /* }}} */ @@ -883,7 +912,10 @@ */ PHP_MSHUTDOWN_FUNCTION(zip) { +#if ZIP_USE_WRAPPER + php_unregister_url_stream_wrapper("zip" TSRMLS_CC); return SUCCESS; +#endif } /* }}} */ @@ -894,7 +926,7 @@ php_info_print_table_start(); { php_info_print_table_row(2, "Zip", "enabled"); - php_info_print_table_row(2, "$Id: php_zip.c,v 1.4 2006/01/14 14:31:38 johannes Exp $", "enabled"); + php_info_print_table_row(2, "$Id: php_zip.c,v 1.5 2006/01/16 15:55:58 pajoye Exp $", "enabled"); php_info_print_table_row(2, "Libzip version", "0.6.1"); } php_info_print_table_end(); http://cvs.php.net/viewcvs.cgi/pecl/zip/php_zip.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/zip/php_zip.h diff -u pecl/zip/php_zip.h:1.3 pecl/zip/php_zip.h:1.4 --- pecl/zip/php_zip.h:1.3 Sat Jan 14 02:28:20 2006 +++ pecl/zip/php_zip.h Mon Jan 16 15:55:58 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_zip.h,v 1.3 2006/01/14 02:28:20 pajoye Exp $ */ +/* $Id: php_zip.h,v 1.4 2006/01/16 15:55:58 pajoye Exp $ */ #ifndef PHP_ZIP_H #define PHP_ZIP_H @@ -47,13 +47,13 @@ int filename_len; } ze_zip_object; - - static void zip_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC); zend_class_entry *zip_class_entry_ce; -PHP_FUNCTION(zip_open); +php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); + +extern php_stream_wrapper php_stream_zip_wrapper; #endif /* PHP_ZIP_H */ http://cvs.php.net/viewcvs.cgi/pecl/zip/examples/fopen.php?view=markup&rev=1.1 Index: pecl/zip/examples/fopen.php +++ pecl/zip/examples/fopen.php <?php dl('zip.so'); if (0) { $fp = fopen('zip://test1.zip/test.txt', 'r'); while (!feof($fp)) { $contents .= fread($fp, 2); echo "$contents\n"; } fclose($fp); echo "done.\n"; } $content = ''; $z = new Zip(); $z->open('test1.zip'); $fp = $z->getStream('test.txt', "r"); var_dump($fp); if(!$fp) exit("\n"); while (!feof($fp)) { $contents .= fread($fp, 2); echo "$contents\n"; } fclose($fp); echo "done.\n";

« previous php.pecl.cvs (#4968) next »