pollita Mon Oct 2 00:32:13 2006 UTC
Modified files:
/php-src/ext/standard md5.c sha1.c
Log:
Allow unicode-ascii to binary conversion and do proper path conversion for
file variants
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/md5.c?r1=1.47&r2=1.48&diff_format=u
Index: php-src/ext/standard/md5.c
diff -u php-src/ext/standard/md5.c:1.47 php-src/ext/standard/md5.c:1.48
--- php-src/ext/standard/md5.c:1.47 Sun Sep 24 17:09:46 2006
+++ php-src/ext/standard/md5.c Mon Oct 2 00:32:13 2006
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: md5.c,v 1.47 2006/09/24 17:09:46 pollita Exp $ */
+/* $Id: md5.c,v 1.48 2006/10/02 00:32:13 pollita Exp $ */
/*
* md5.c - Copyright 1997 Lachlan Roche
@@ -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 @@
{
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 @@
{
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 @@
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;
}
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/sha1.c?r1=1.18&r2=1.19&diff_format=u
Index: php-src/ext/standard/sha1.c
diff -u php-src/ext/standard/sha1.c:1.18 php-src/ext/standard/sha1.c:1.19
--- php-src/ext/standard/sha1.c:1.18 Sun Sep 24 17:09:46 2006
+++ php-src/ext/standard/sha1.c Mon Oct 2 00:32:13 2006
@@ -16,9 +16,10 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sha1.c,v 1.18 2006/09/24 17:09:46 pollita Exp $ */
+/* $Id: sha1.c,v 1.19 2006/10/02 00:32:13 pollita Exp $ */
#include "php.h"
+#include "ext/standard/file.h"
/* This code is heavily based on the PHP md5 implementation */
@@ -42,26 +43,38 @@
{
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 @@
{
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 @@
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;
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php