mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
- Also add the optional raw output parameter to md5_file and sha1_file.
This commit is contained in:
parent
b7885999cb
commit
b4b33b11ef
5
NEWS
5
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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user