1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 4.0 |
+----------------------------------------------------------------------+
| Copyright (c) 2000 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Sascha Schumann <sascha@schumann.cx> |
+----------------------------------------------------------------------+
*/
#include "php.h"
#if COMPILE_DL
#include <dl/phpdl.h>
#undef HAVE_LIBMHASH
#define HAVE_LIBMHASH 1
#endif
#if HAVE_LIBMHASH
#include "php_mhash.h"
#include <mhash.h>
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},
};
static int php_minit_mhash(INIT_FUNC_ARGS);
zend_module_entry mhash_module_entry = {
"mhash",
mhash_functions,
php_minit_mhash, NULL,
NULL, NULL,
NULL,
STANDARD_MODULE_PROPERTIES,
};
#if COMPILE_DL
DLEXPORT zend_module_entry *get_module(void) { return &mhash_module_entry; }
#endif
#define MHASH_FAILED_MSG "mhash initialization failed"
static int php_minit_mhash(INIT_FUNC_ARGS)
{
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);
php3_register_long_constant(buf, strlen(buf) + 1, i, CONST_PERSISTENT, module_number);
free(name);
}
}
return SUCCESS;
}
/* {{{ proto int mhash_count(void)
Get the number of available hashes */
PHP_FUNCTION(mhash_count)
{
RETURN_LONG(mhash_count());
}
/* }}} */
/* {{{ proto int mhash_get_block_size(int hash)
Get the block size of hash */
PHP_FUNCTION(mhash_get_block_size)
{
pval *hash;
if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &hash) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(hash);
RETURN_LONG(mhash_get_block_size(hash->value.lval));
}
/* }}} */
/* {{{ proto string 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 string mhash(int hash, string data)
Hash data with hash */
PHP_FUNCTION(mhash)
{
pval *hash, *data;
MHASH td;
int bsize;
unsigned char *hash_data;
if(ARG_COUNT(ht) != 2 || getParameters(ht, 2, &hash, &data) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(hash);
convert_to_string(data);
bsize = mhash_get_block_size(hash->value.lval);
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 = (unsigned char *) mhash_end(td);
if (hash_data) {
RETVAL_STRINGL(hash_data, bsize, 1);
free(hash_data);
} else {
RETURN_FALSE;
}
}
/* }}} */
#endif
|