]> granicus.if.org Git - php/commitdiff
- Also add the optional raw output parameter to md5_file and sha1_file.
authorDerick Rethans <derick@php.net>
Thu, 20 Feb 2003 10:32:35 +0000 (10:32 +0000)
committerDerick Rethans <derick@php.net>
Thu, 20 Feb 2003 10:32:35 +0000 (10:32 +0000)
NEWS
ext/standard/md5.c
ext/standard/sha1.c

diff --git a/NEWS b/NEWS
index 1ecb7e78a5a639f659ede1c31efd6d0eeeb64f34..7c56744ca11a6cced83c1f830a038030e1b2fc15 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,8 +20,9 @@ PHP 4                                                                      NEWS
 - Added lightweight streaming input abstraction to the Zend Engine scanners
   that provides uniform support for include()'ing data from PHP streams across
   all platforms (Wez, Zend Engine).
-- Added optional parameter to sha1() and md5() which makes them return 
-  the digest as binary data. (Michael Bretterklieber <mbretter@jawa.at>, Derick)
+- Added optional parameter to sha1(), sha1_file(), md5() and md5_file() which
+  makes them return the digest as binary data. (Michael Bretterklieber
+  <mbretter@jawa.at>, Derick)
 - Added proc_nice() function. Changes priority of the current process. (Ilia)
 - Added pcntl_getpriority() and pcntl_setpriority() functions. (Ilia)
 - Added idate(), date_sunrise() and date_sunset() functions. (Moshe Doron)
index 1bde1f6809a8c042bf8487d762c0238c57f7725b..78f8c3141b48da8fe9ad8ec47f96b6bc7bce76b8 100644 (file)
@@ -69,11 +69,13 @@ PHP_NAMED_FUNCTION(php_if_md5)
 }
 /* }}} */
 
-/* {{{ proto string md5_file(string filename)
+/* {{{ proto string md5_file(string filename [, bool raw_output])
    Calculate the md5 hash of given filename */
 PHP_NAMED_FUNCTION(php_if_md5_file)
 {
-       zval          **arg;
+       char          *arg;
+       int           arg_len;
+       zend_bool raw_output = 0;
        char          md5str[33];
        unsigned char buf[1024];
        unsigned char digest[16];
@@ -81,21 +83,19 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
        int           n;
        FILE          *fp;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) {
+               return;
        }
 
-       convert_to_string_ex(arg);
-
-       if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
+       if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
                RETURN_FALSE;
        }
 
-       if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) {
+       if (php_check_open_basedir(arg TSRMLS_CC)) {
                RETURN_FALSE;
        }
 
-       if ((fp = VCWD_FOPEN(Z_STRVAL_PP(arg), "rb")) == NULL) {
+       if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file");
                RETURN_FALSE;
        }
@@ -115,9 +115,12 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
 
        fclose(fp);
 
-       make_digest(md5str, digest);
-
-       RETVAL_STRING(md5str, 1);
+       if (raw_output) {
+               RETURN_STRINGL(digest, 20, 1);
+       } else {
+               make_digest(md5str, digest);
+               RETVAL_STRING(md5str, 1);
+       }
 }
 /* }}} */
 
index 77b3fbb4f93c8c768e81435dbaf7dc6b243492ad..38027f247f2268705db62377c096bf9a2aa1a08f 100644 (file)
@@ -67,11 +67,13 @@ PHP_FUNCTION(sha1)
 
 /* }}} */
 
-/* {{{ proto string sha1_file(string filename)
+/* {{{ proto string sha1_file(string filename [, bool raw_output])
    Calculate the sha1 hash of given filename */
 PHP_FUNCTION(sha1_file)
 {
-       zval          **arg;
+       char          *arg;
+       int           arg_len;
+       zend_bool raw_output = 0;
        char          sha1str[41];
        unsigned char buf[1024];
        unsigned char digest[20];
@@ -79,21 +81,19 @@ PHP_FUNCTION(sha1_file)
        int           n;
        FILE          *fp;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) {
+               return;
        }
 
-       convert_to_string_ex(arg);
-
-       if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
+       if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
                RETURN_FALSE;
        }
 
-       if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) {
+       if (php_check_open_basedir(arg TSRMLS_CC)) {
                RETURN_FALSE;
        }
 
-       if ((fp = VCWD_FOPEN(Z_STRVAL_PP(arg), "rb")) == NULL) {
+       if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file");
                RETURN_FALSE;
        }
@@ -113,9 +113,12 @@ PHP_FUNCTION(sha1_file)
 
        fclose(fp);
 
-       make_sha1_digest(sha1str, digest);
-
-       RETVAL_STRING(sha1str, 1);
+       if (raw_output) {
+               RETURN_STRINGL(digest, 20, 1);
+       } else {
+               make_sha1_digest(sha1str, digest);
+               RETVAL_STRING(sha1str, 1);
+       }
 }
 /* }}} */