- 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)
}
/* }}} */
-/* {{{ 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];
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;
}
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);
+ }
}
/* }}} */
/* }}} */
-/* {{{ 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];
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;
}
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);
+ }
}
/* }}} */