Re: cvs: pecl /zip zip_stream.c /zip/examples fopen.php

From: Date: Sun, 12 Mar 2006 20:47:05 +0000
Subject: Re: cvs: pecl /zip zip_stream.c /zip/examples fopen.php
References: 1  Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-5433@lists.php.net to get a copy of this message
Hello Rob, we were having an interesting discussion with Pierre about that url layout and he claimed it was your idea to use the '#' as a separator between archive and entry. Now Pierre is wrong in saying that # denotes a fragment but the use is quite different from what he is using it for. In terms of the RFC the extensions stream handler is the server and the php script is the client. Now read what the RFC says about fragment: "4. URI References The term "URI-reference" is used here to denote the common usage of a resource identifier. A URI reference may be absolute or relative, and may have additional information attached in the form of a fragment identifier. However, "the URI" that results from such a reference includes only the absolute URI after the fragment identifier (if any) is removed and after any relative URI is resolved to its absolute form." [...] "4.1. Fragment Identifier When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch ("#") character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed." [...] This means two things: 1) The fragment is not taken into account on the server side. 2) The fragment is meant for the client side. Thus we (Derick, Greg, myself) suggest the use of '?'. "3.4. Query Component The query component is a string of information to be interpreted by the resource." Which pretty much matches since the archive is the resource. And from my opinion we are doing a query into the archive executed by the streams handler of pecl/zip. best regards marcus Sunday, March 12, 2006, 3:15:13 PM, you wrote: > pajoye Sun Mar 12 14:15:13 2006 UTC > Modified files: > /pecl/zip zip_stream.c > /pecl/zip/examples fopen.php > Log: > - enable streams by default > uses now the fragment to define the entry: > zip:///path/to/my.zip#entryname > > > > http://cvs.php.net/viewcvs.cgi/pecl/zip/zip_stream.c?r1=1.3&r2=1.4&diff_format=u > Index: pecl/zip/zip_stream.c > diff -u pecl/zip/zip_stream.c:1.3 pecl/zip/zip_stream.c:1.4 > --- pecl/zip/zip_stream.c:1.3 Tue Jan 17 01:06:57 2006 > +++ pecl/zip/zip_stream.c Sun Mar 12 14:15:13 2006 > @@ -1,4 +1,4 @@ > -/* $Id: zip_stream.c,v 1.3 2006/01/17 01:06:57 pajoye Exp $ */ > +/* $Id: zip_stream.c,v 1.4 2006/03/12 14:15:13 pajoye Exp $ */ > #ifdef HAVE_CONFIG_H > # include "config.h" > #endif > @@ -11,6 +11,9 @@ > #include "php_streams.h" > #include "ext/standard/file.h" > #include "fopen_wrappers.h" > + > +#include "ext/standard/url.h" > + > struct php_zip_stream_data_t { > struct zip *za; > struct zip_file *zf; > @@ -137,8 +140,6 @@ > } > /* }}} */ > > - > -#if ZIP_ZIP_USE_WRAPPER > /* {{{ php_stream_zip_opener */ > php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, > char *path, > @@ -156,39 +157,37 @@ > > struct zip *za; > struct zip_file *zf = NULL; > + char *fragment; > + int fragment_len; > int err; > > php_stream *stream = NULL; > struct php_zip_stream_data_t *self; > > + fragment = strchr(path, '#'); > + if (!fragment) { > + return NULL; > + } > > if (strncasecmp("zip://", path, 6) == 0) { > path += 6; > } > > - path_len = strlen(path); > - memcpy(file_dirname, path, path_len); > - > - file_dirname_len = php_dirname(file_dirname, path_len); > - > - php_basename(path, path_len, NULL, 0, &file_basename, &file_basename_len > TSRMLS_CC); > - > - > - printf("path: %s\n", path); > - printf("dirname: %s\n", file_dirname); > - printf("basename: %s\n", file_basename); > + fragment_len = strlen(fragment); > > + path_len = strlen(path); > > + memcpy(file_dirname, path, path_len - fragment_len); > + php_basename(path, path_len - fragment_len, NULL, 0, > &file_basename, &file_basename_len TSRMLS_CC); > + fragment++; > if (mode[0] != 'r') { > return NULL; > } > > za = zip_open(file_dirname, ZIP_CREATE, &err); > if (za) { > - printf("Zip %s opened.\n", file_dirname); > - zf = zip_fopen(za, file_basename, 0); > + zf = zip_fopen(za, fragment, 0); > if (zf) { > - printf("file opened.\n"); > self = emalloc(sizeof(*self)); > > self->za = za; > @@ -233,7 +232,5 @@ > NULL, > 0 /* is_url */ > }; > -#endif /* ZIP_USE_WRAPPER */ > - > #endif /* ZEND_ENGINE_2 */ > #endif /* HAVE_ZIP */ > > http://cvs.php.net/viewcvs.cgi/pecl/zip/examples/fopen.php?r1=1.2&r2=1.3&diff_format=u > Index: pecl/zip/examples/fopen.php > diff -u pecl/zip/examples/fopen.php:1.2 pecl/zip/examples/fopen.php:1.3 > --- pecl/zip/examples/fopen.php:1.2 Sat Mar 11 15:46:58 2006 > +++ pecl/zip/examples/fopen.php Sun Mar 12 14:15:13 2006 > @@ -4,16 +4,19 @@ > } > > > -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"; > +$fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', > 'r'); > +if (!$fp) { > + exit("cannot open\n"); > } > +while (!feof($fp)) { > + $contents .= fread($fp, 2); > + echo "$contents\n"; > +} > + > +fclose($fp); > +echo "done.\n"; > + > + > $content = ''; > $z = new Zip(); > $z->open(dirname(__FILE__) . '/test.zip'); Best regards, Marcus

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