thetaphi                Sat Apr 16 05:49:56 2005 EDT

  Modified files:              (Branch: PHP_4_3)
    /php-src    NEWS 
    /php-src/ext/standard       md5.c sha1.c 
  Log:
  MFH: use streams api for md5_file() and sha1_file()
  
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1247.2.877&r2=1.1247.2.878&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1247.2.877 php-src/NEWS:1.1247.2.878
--- php-src/NEWS:1.1247.2.877   Thu Apr 14 11:48:38 2005
+++ php-src/NEWS        Sat Apr 16 05:49:49 2005
@@ -1,6 +1,7 @@
 PHP 4                                                                      NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 20??, Version 4.?.?
+- Changed sha1_file() / md5_file() to use streams instead of low level IO (Uwe)
 - Added the sorting flag SORT_LOCALE_STRING to the sort() functions which makes
   them sort based on the current locale. (Derick)
 - Fixed bug #32699 (pg_affected_rows() was defined when it was not available).
http://cvs.php.net/diff.php/php-src/ext/standard/md5.c?r1=1.28.4.4&r2=1.28.4.5&ty=u
Index: php-src/ext/standard/md5.c
diff -u php-src/ext/standard/md5.c:1.28.4.4 php-src/ext/standard/md5.c:1.28.4.5
--- php-src/ext/standard/md5.c:1.28.4.4 Fri Apr 15 05:44:45 2005
+++ php-src/ext/standard/md5.c  Sat Apr 16 05:49:53 2005
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: md5.c,v 1.28.4.4 2005/04/15 09:44:45 thetaphi Exp $ */
+/* $Id: md5.c,v 1.28.4.5 2005/04/16 09:49:53 thetaphi Exp $ */
 
 /* 
  * md5.c - Copyright 1997 Lachlan Roche 
@@ -24,9 +24,6 @@
  */
 
 #include "php.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include "md5.h"
 
 PHPAPI void make_digest(char *md5str, unsigned char *digest)
@@ -73,7 +70,8 @@
        unsigned char buf[1024];
        unsigned char digest[16];
        PHP_MD5_CTX   context;
-       int           n,fd;
+       int           n;
+       php_stream    *stream;
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) 
{
                WRONG_PARAM_COUNT;
@@ -81,34 +79,25 @@
 
        convert_to_string_ex(arg);
 
-       if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
-               RETURN_FALSE;
-       }
-
-       if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) {
-               RETURN_FALSE;
-       }
-
-       if ((fd = VCWD_OPEN(Z_STRVAL_PP(arg), O_RDONLY)) == -1) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open 
file");
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg), "rb", REPORT_ERRORS 
| ENFORCE_SAFE_MODE, NULL);
+       if (!stream) {
                RETURN_FALSE;
        }
 
        PHP_MD5Init(&context);
 
-       while ((n = read(fd, buf, sizeof(buf))) > 0) {
+       while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
                PHP_MD5Update(&context, buf, n);
        }
 
        PHP_MD5Final(digest, &context);
 
+       php_stream_close(stream);
+
        if (n<0) {
-               close(fd);
                RETURN_FALSE;
        }
 
-       close(fd);
-
        make_digest(md5str, digest);
 
        RETVAL_STRING(md5str, 1);
http://cvs.php.net/diff.php/php-src/ext/standard/sha1.c?r1=1.3.4.3&r2=1.3.4.4&ty=u
Index: php-src/ext/standard/sha1.c
diff -u php-src/ext/standard/sha1.c:1.3.4.3 php-src/ext/standard/sha1.c:1.3.4.4
--- php-src/ext/standard/sha1.c:1.3.4.3 Fri Apr 15 05:24:45 2005
+++ php-src/ext/standard/sha1.c Sat Apr 16 05:49:53 2005
@@ -16,12 +16,9 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: sha1.c,v 1.3.4.3 2005/04/15 09:24:45 thetaphi Exp $ */
+/* $Id: sha1.c,v 1.3.4.4 2005/04/16 09:49:53 thetaphi Exp $ */
 
 #include "php.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 
 /* This code is heavily based on the PHP md5 implementation */ 
 
@@ -72,7 +69,8 @@
        unsigned char buf[1024];
        unsigned char digest[20];
        PHP_SHA1_CTX   context;
-       int           n, fd;
+       int           n;
+       php_stream    *stream;
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) 
{
                WRONG_PARAM_COUNT;
@@ -80,34 +78,25 @@
 
        convert_to_string_ex(arg);
 
-       if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
-               RETURN_FALSE;
-       }
-
-       if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) {
-               RETURN_FALSE;
-       }
-
-       if ((fd = VCWD_OPEN(Z_STRVAL_PP(arg), O_RDONLY)) == -1) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open 
file");
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg), "rb", REPORT_ERRORS 
| ENFORCE_SAFE_MODE, NULL);
+       if (!stream) {
                RETURN_FALSE;
        }
 
        PHP_SHA1Init(&context);
 
-       while ((n = read(fd, buf, sizeof(buf))) > 0) {
+       while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
                PHP_SHA1Update(&context, buf, n);
        }
 
        PHP_SHA1Final(digest, &context);
 
+       php_stream_close(stream);
+
        if (n<0) {
-               close(fd);
                RETURN_FALSE;
        }
 
-       close(fd);
-
        make_sha1_digest(sha1str, digest);
 
        RETVAL_STRING(sha1str, 1);

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

Reply via email to