[PHP4BETA] CVS update: php4/ext/mhash
| From: | sas | Date: | Fri, 21 May 1999 20:09:23 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/ext/mhash | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-980@lists.php.net to get a copy of this message | ||
Date: Friday May 21, 1999 @ 16:09
Author: sas
Update of /repository/php4/ext/mhash
In directory php:/tmp/cvs-serv10685/ext/mhash
Modified Files:
config.m4 mhash.c php_mhash.h
Log Message:
add support for mhash 0.5.0
see http://sasweb.de/mhash/
Index: php4/ext/mhash/config.m4
diff -u php4/ext/mhash/config.m4:1.1 php4/ext/mhash/config.m4:1.2
--- php4/ext/mhash/config.m4:1.1 Sun May 16 08:01:25 1999
+++ php4/ext/mhash/config.m4 Fri May 21 16:09:22 1999
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.1 1999/05/16 12:01:25 sas Exp $
+dnl $Id: config.m4,v 1.2 1999/05/21 20:09:22 sas Exp $
dnl config.m4 for extension mhash
dnl don't forget to call PHP_EXTENSION(mhash)
@@ -8,7 +8,7 @@
install directory.],
[
if test "$withval" != "no"; then
- for i in /usr/local /usr $withval; do
+ for i in /usr/local /usr /opt/mhash $withval; do
if test -f $i/include/mhash.h; then
MHASH_DIR=$i
fi
Index: php4/ext/mhash/mhash.c
diff -u php4/ext/mhash/mhash.c:1.2 php4/ext/mhash/mhash.c:1.3
--- php4/ext/mhash/mhash.c:1.2 Fri May 21 04:20:12 1999
+++ php4/ext/mhash/mhash.c Fri May 21 16:09:23 1999
@@ -37,6 +37,8 @@
function_entry mhash_functions[] = {
PHP_FE(mhash_get_block_size, NULL)
+ PHP_FE(mhash_get_hash_name, NULL)
+ PHP_FE(mhash_count, NULL)
PHP_FE(mhash, NULL)
{0},
};
@@ -52,26 +54,33 @@
STANDARD_MODULE_PROPERTIES,
};
-#define MHASH_FAILED "mhash initialization failed"
+#define MHASH_FAILED_MSG "mhash initialization failed"
-#define MHASH_ENTRY(a) REGISTER_LONG_CONSTANT("MHASH_" #a, a, 0)
-
static int php_minit_mhash(INIT_FUNC_ARGS)
{
- /* hashes */
- MHASH_ENTRY(CRC32);
- MHASH_ENTRY(MD5);
- MHASH_ENTRY(SHA1);
- MHASH_ENTRY(HAVAL);
- MHASH_ENTRY(RIPEMD128);
- MHASH_ENTRY(RIPEMD160);
- MHASH_ENTRY(TIGER);
- MHASH_ENTRY(SNEFRU);
- MHASH_ENTRY(GOST);
+ int i;
+ char *name;
+ char buf[128];
+
+ for(i = 0; i <= mhash_count(); i++) {
+ name = mhash_get_hash_name(i);
+ if(name) {
+ snprintf(buf, 127, "MHASH_%s", name);
+ REGISTER_LONG_CONSTANT(buf, i, 0);
+ free(name);
+ }
+ }
return SUCCESS;
}
+/* proto mhash_count()
+ get the number of available hashes */
+PHP_FUNCTION(mhash_count)
+{
+ RETURN_LONG(mhash_count());
+}
+
/* proto mhash_get_block_size(int hash)
get the block size of hash */
PHP_FUNCTION(mhash_get_block_size)
@@ -87,12 +96,34 @@
RETURN_LONG(mhash_get_block_size(hash->value.lval));
}
+/* proto mhash_get_hash_name(int hash)
+ get the name of hash */
+PHP_FUNCTION(mhash_get_hash_name)
+{
+ pval *hash;
+ char *name;
+
+ if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &hash) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(hash);
+
+ name = mhash_get_hash_name(hash->value.lval);
+ if(name) {
+ RETVAL_STRING(name, 1);
+ free(name);
+ } else {
+ RETVAL_FALSE;
+ }
+}
+
/* proto mhash(int hash, string data)
hash data with hash */
PHP_FUNCTION(mhash)
{
pval *hash, *data;
- int td;
+ MHASH td;
int bsize;
unsigned char *hash_data;
int i;
@@ -105,15 +136,15 @@
convert_to_string(data);
bsize = mhash_get_block_size(hash->value.lval);
- td = init_mhash(hash->value.lval);
- if(td == -1) {
- php3_error(E_WARNING, MHASH_FAILED);
+ td = mhash_init(hash->value.lval);
+ if(td == MHASH_FAILED) {
+ php3_error(E_WARNING, MHASH_FAILED_MSG);
RETURN_FALSE;
}
mhash(td, data->value.str.val, data->value.str.len);
- hash_data = (char *) end_mhash(td);
+ hash_data = (unsigned char *) mhash_end(td);
RETVAL_STRINGL(hash_data, bsize, 1);
Index: php4/ext/mhash/php_mhash.h
diff -u php4/ext/mhash/php_mhash.h:1.1 php4/ext/mhash/php_mhash.h:1.2
--- php4/ext/mhash/php_mhash.h:1.1 Sun May 16 08:01:25 1999
+++ php4/ext/mhash/php_mhash.h Fri May 21 16:09:23 1999
@@ -13,6 +13,8 @@
#define mhash_module_ptr &mhash_module_entry
PHP_FUNCTION(mhash_get_block_size);
+PHP_FUNCTION(mhash_get_hash_name);
+PHP_FUNCTION(mhash_count);
PHP_FUNCTION(mhash);
#else
--
PHP 4 Beta