derick Thu Feb 20 05:32:35 2003 EDT
Modified files:
/php4 NEWS
/php4/ext/standard md5.c sha1.c
Log:
- Also add the optional raw output parameter to md5_file and sha1_file.
Index: php4/NEWS
diff -u php4/NEWS:1.1352 php4/NEWS:1.1353
--- php4/NEWS:1.1352 Thu Feb 20 02:13:59 2003
+++ php4/NEWS Thu Feb 20 05:32:33 2003
@@ -20,8 +20,9 @@
- 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 <[EMAIL PROTECTED]>, Derick)
+- Added optional parameter to sha1(), sha1_file(), md5() and md5_file() which
+ makes them return the digest as binary data. (Michael Bretterklieber
+ <[EMAIL PROTECTED]>, 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: php4/ext/standard/md5.c
diff -u php4/ext/standard/md5.c:1.31 php4/ext/standard/md5.c:1.32
--- php4/ext/standard/md5.c:1.31 Thu Feb 20 01:56:37 2003
+++ php4/ext/standard/md5.c Thu Feb 20 05:32:35 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: md5.c,v 1.31 2003/02/20 06:56:37 derick Exp $ */
+/* $Id: md5.c,v 1.32 2003/02/20 10:32:35 derick Exp $ */
/*
* md5.c - Copyright 1997 Lachlan Roche
@@ -69,11 +69,13 @@
}
/* }}} */
-/* {{{ 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 @@
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 @@
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: php4/ext/standard/sha1.c
diff -u php4/ext/standard/sha1.c:1.6 php4/ext/standard/sha1.c:1.7
--- php4/ext/standard/sha1.c:1.6 Thu Feb 20 01:56:37 2003
+++ php4/ext/standard/sha1.c Thu Feb 20 05:32:35 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sha1.c,v 1.6 2003/02/20 06:56:37 derick Exp $ */
+/* $Id: sha1.c,v 1.7 2003/02/20 10:32:35 derick Exp $ */
#include <stdio.h>
#include "php.h"
@@ -67,11 +67,13 @@
/* }}} */
-/* {{{ 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 @@
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 @@
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);
+ }
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php