mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
Allow unicode-ascii to binary conversion and do proper path conversion for file variants
This commit is contained in:
parent
c7a97a7482
commit
a6a92fc458
@ -25,6 +25,7 @@
|
||||
|
||||
#include "php.h"
|
||||
#include "md5.h"
|
||||
#include "ext/standard/file.h"
|
||||
|
||||
PHPAPI void make_digest(char *md5str, unsigned char *digest)
|
||||
{
|
||||
@ -44,26 +45,38 @@ PHP_NAMED_FUNCTION(php_if_md5)
|
||||
{
|
||||
char *arg;
|
||||
int arg_len;
|
||||
zend_uchar arg_type;
|
||||
zend_bool raw_output = 0;
|
||||
char md5str[33];
|
||||
PHP_MD5_CTX context;
|
||||
unsigned char digest[16];
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &arg, &arg_len, &raw_output) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|b", &arg, &arg_len, &arg_type, &raw_output) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg_type == IS_UNICODE) {
|
||||
arg = zend_unicode_to_ascii((UChar*)arg, arg_len TSRMLS_CC);
|
||||
if (!arg) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
md5str[0] = '\0';
|
||||
PHP_MD5Init(&context);
|
||||
PHP_MD5Update(&context, (unsigned char*)arg, arg_len);
|
||||
PHP_MD5Final(digest, &context);
|
||||
if (raw_output) {
|
||||
RETURN_STRINGL((char*)digest, 16, 1);
|
||||
RETVAL_STRINGL((char*)digest, 16, 1);
|
||||
} else {
|
||||
make_digest(md5str, digest);
|
||||
RETVAL_ASCII_STRING(md5str, ZSTR_DUPLICATE);
|
||||
}
|
||||
|
||||
if (arg_type == IS_UNICODE) {
|
||||
efree(arg);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -73,6 +86,7 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
|
||||
{
|
||||
char *arg;
|
||||
int arg_len;
|
||||
zend_uchar arg_type;
|
||||
zend_bool raw_output = 0;
|
||||
char md5str[33];
|
||||
unsigned char buf[1024];
|
||||
@ -81,11 +95,20 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
|
||||
int n;
|
||||
php_stream *stream;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &arg, &arg_len, &raw_output) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|b", &arg, &arg_len, &arg_type, &raw_output) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg_type == IS_UNICODE) {
|
||||
if (php_stream_path_encode(NULL, &arg, &arg_len, (UChar*)arg, arg_len, REPORT_ERRORS, FG(default_context)) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS, NULL);
|
||||
if (arg_type == IS_UNICODE) {
|
||||
efree(arg);
|
||||
}
|
||||
if (!stream) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
/* $Id$ */
|
||||
|
||||
#include "php.h"
|
||||
#include "ext/standard/file.h"
|
||||
|
||||
/* This code is heavily based on the PHP md5 implementation */
|
||||
|
||||
@ -42,26 +43,38 @@ PHP_FUNCTION(sha1)
|
||||
{
|
||||
char *arg;
|
||||
int arg_len;
|
||||
zend_uchar arg_type;
|
||||
zend_bool raw_output = 0;
|
||||
char sha1str[41];
|
||||
PHP_SHA1_CTX context;
|
||||
unsigned char digest[20];
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &arg, &arg_len, &raw_output) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|b", &arg, &arg_len, &arg_type, &raw_output) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg_type == IS_UNICODE) {
|
||||
arg = zend_unicode_to_ascii((UChar*)arg, arg_len TSRMLS_CC);
|
||||
if (!arg) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
sha1str[0] = '\0';
|
||||
PHP_SHA1Init(&context);
|
||||
PHP_SHA1Update(&context, (unsigned char*)arg, arg_len);
|
||||
PHP_SHA1Final(digest, &context);
|
||||
if (raw_output) {
|
||||
RETURN_STRINGL((char*)digest, 20, 1);
|
||||
RETVAL_STRINGL((char*)digest, 20, 1);
|
||||
} else {
|
||||
make_sha1_digest(sha1str, digest);
|
||||
RETVAL_ASCII_STRING(sha1str, ZSTR_DUPLICATE);
|
||||
}
|
||||
|
||||
if (arg_type == IS_UNICODE) {
|
||||
efree(arg);
|
||||
}
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
@ -73,6 +86,7 @@ PHP_FUNCTION(sha1_file)
|
||||
{
|
||||
char *arg;
|
||||
int arg_len;
|
||||
zend_uchar arg_type;
|
||||
zend_bool raw_output = 0;
|
||||
char sha1str[41];
|
||||
unsigned char buf[1024];
|
||||
@ -81,11 +95,20 @@ PHP_FUNCTION(sha1_file)
|
||||
int n;
|
||||
php_stream *stream;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &arg, &arg_len, &raw_output) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|b", &arg, &arg_len, &arg_type, &raw_output) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg_type == IS_UNICODE) {
|
||||
if (php_stream_path_encode(NULL, &arg, &arg_len, (UChar*)arg, arg_len, REPORT_ERRORS, FG(default_context)) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS, NULL);
|
||||
if (arg_type == IS_UNICODE) {
|
||||
efree(arg);
|
||||
}
|
||||
if (!stream) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user