helly           Sun May 14 01:42:03 2006 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/standard/tests/file    stream_rfc2397_003.gif 
                                        stream_rfc2397_003.phpt 

  Modified files:              
    /php-src/main/streams       memory.c 
  Log:
  - MFH RFC2397 decoding
  
http://cvs.php.net/viewcvs.cgi/php-src/main/streams/memory.c?r1=1.8.2.6.2.2&r2=1.8.2.6.2.3&diff_format=u
Index: php-src/main/streams/memory.c
diff -u php-src/main/streams/memory.c:1.8.2.6.2.2 
php-src/main/streams/memory.c:1.8.2.6.2.3
--- php-src/main/streams/memory.c:1.8.2.6.2.2   Sun May 14 01:06:09 2006
+++ php-src/main/streams/memory.c       Sun May 14 01:42:03 2006
@@ -16,11 +16,14 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: memory.c,v 1.8.2.6.2.2 2006/05/14 01:06:09 helly Exp $ */
+/* $Id: memory.c,v 1.8.2.6.2.3 2006/05/14 01:42:03 helly Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
 
+PHPAPI int php_url_decode(char *str, int len);
+PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, 
int *ret_length);
+
 /* Memory streams use a dynamic memory buffer to emulate a stream.
  * You can use php_stream_memory_open to create a readonly stream
  * from an existing memory buffer.
@@ -564,7 +567,7 @@
        size_t mlen, dlen, plen, vlen;
        off_t newoffs;
        zval *meta = NULL;
-       int base64 = 0;
+       int base64 = 0, ilen;
 
        if (memcmp(path, "data:", 5)) {
                return NULL;
@@ -654,7 +657,16 @@
                comma++;
                dlen--;
                /* store data */
-               php_stream_temp_write(stream, comma, dlen TSRMLS_CC);
+               if (base64) {
+                       comma = (char*)php_base64_decode((const unsigned char 
*)comma, dlen, &ilen);
+                       php_stream_temp_write(stream, comma, ilen TSRMLS_CC);
+                       efree(comma);
+               } else {
+                       comma = estrndup(comma, dlen);
+                       dlen = php_url_decode(comma, dlen);
+                       php_stream_temp_write(stream, comma, dlen TSRMLS_CC);
+                       efree(comma);
+               }
                php_stream_temp_seek(stream, 0, SEEK_SET, &newoffs TSRMLS_CC);
                /* set special stream stuff (enforce exact mode) */
                vlen = strlen(mode);

http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/tests/file/stream_rfc2397_003.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/file/stream_rfc2397_003.phpt
+++ php-src/ext/standard/tests/file/stream_rfc2397_003.phpt
--TEST--
Stream: RFC2397 decoding data
--FILE--
<?php

$streams = array(
        'data://,A%20brief%20note',
        
'data://application/vnd-xxx-query,select_vcount,fcol_from_fieldtable/local',
        'data://;base64,Zm9vYmFyIGZvb2Jhcg==',
        'stream_rfc2397_003.gif' => 
'data://image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw
AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz
ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp
a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl
ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis
F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH
hhx4dbgYKAAA7',
        );

foreach($streams as $original => $stream)
{
        if (is_string($original)) {
                var_dump(file_get_contents(dirname(__FILE__) . '/' . $original) 
== file_get_contents($stream));
        } else {
                var_dump(file_get_contents($stream));
        }
}

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(12) "A brief note"
string(40) "select_vcount,fcol_from_fieldtable/local"
string(13) "foobar foobar"
bool(true)
===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to