thetaphi                Sat Apr 16 05:50:13 2005 EDT

  Modified files:              (Branch: PHP_5_0)
    /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.1760.2.324&r2=1.1760.2.325&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1760.2.324 php-src/NEWS:1.1760.2.325
--- php-src/NEWS:1.1760.2.324   Thu Apr 14 11:48:55 2005
+++ php-src/NEWS        Sat Apr 16 05:50:12 2005
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2005, PHP 5.0.5
+- Changed sha1_file() / md5_file() to use streams instead of low level IO (Uwe)
 - Removed php_check_syntax() function, never worked properly. (Ilia)
 - Fixed bug #32699 (pg_affected_rows() was defined when it was not available).
   (Derick)
http://cvs.php.net/diff.php/php-src/ext/standard/md5.c?r1=1.35.2.1&r2=1.35.2.2&ty=u
Index: php-src/ext/standard/md5.c
diff -u php-src/ext/standard/md5.c:1.35.2.1 php-src/ext/standard/md5.c:1.35.2.2
--- php-src/ext/standard/md5.c:1.35.2.1 Fri Apr 15 05:14:53 2005
+++ php-src/ext/standard/md5.c  Sat Apr 16 05:50:13 2005
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: md5.c,v 1.35.2.1 2005/04/15 09:14:53 thetaphi Exp $ */
+/* $Id: md5.c,v 1.35.2.2 2005/04/16 09:50:13 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)
@@ -81,40 +78,32 @@
        unsigned char buf[1024];
        unsigned char digest[16];
        PHP_MD5_CTX   context;
-       int           n,fd;
+       int           n;
+       php_stream    *stream;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, 
&arg_len, &raw_output) == FAILURE) {
                return;
        }
-
-       if (PG(safe_mode) && (!php_checkuid(arg, NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
-               RETURN_FALSE;
-       }
-
-       if (php_check_open_basedir(arg TSRMLS_CC)) {
-               RETURN_FALSE;
-       }
-
-       if ((fd = VCWD_OPEN(arg, O_RDONLY)) == -1) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open 
file");
+       
+       stream = php_stream_open_wrapper(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);
-
        if (raw_output) {
                RETURN_STRINGL(digest, 16, 1);
        } else {
http://cvs.php.net/diff.php/php-src/ext/standard/sha1.c?r1=1.9.2.1&r2=1.9.2.2&ty=u
Index: php-src/ext/standard/sha1.c
diff -u php-src/ext/standard/sha1.c:1.9.2.1 php-src/ext/standard/sha1.c:1.9.2.2
--- php-src/ext/standard/sha1.c:1.9.2.1 Fri Apr 15 05:14:53 2005
+++ php-src/ext/standard/sha1.c Sat Apr 16 05:50:13 2005
@@ -16,12 +16,9 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: sha1.c,v 1.9.2.1 2005/04/15 09:14:53 thetaphi Exp $ */
+/* $Id: sha1.c,v 1.9.2.2 2005/04/16 09:50:13 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 */ 
 
@@ -69,6 +66,7 @@
 
 /* }}} */
 
+
 /* {{{ proto string sha1_file(string filename [, bool raw_output])
    Calculate the sha1 hash of given filename */
 PHP_FUNCTION(sha1_file)
@@ -80,40 +78,32 @@
        unsigned char buf[1024];
        unsigned char digest[20];
        PHP_SHA1_CTX   context;
-       int           n, fd;
+       int           n;
+       php_stream    *stream;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, 
&arg_len, &raw_output) == FAILURE) {
                return;
        }
-
-       if (PG(safe_mode) && (!php_checkuid(arg, NULL, 
CHECKUID_CHECK_FILE_AND_DIR))) {
-               RETURN_FALSE;
-       }
-
-       if (php_check_open_basedir(arg TSRMLS_CC)) {
-               RETURN_FALSE;
-       }
-
-       if ((fd = VCWD_OPEN(arg, O_RDONLY)) == -1) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open 
file");
+       
+       stream = php_stream_open_wrapper(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);
-
        if (raw_output) {
                RETURN_STRINGL(digest, 20, 1);
        } else {

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

Reply via email to