]> granicus.if.org Git - php/commitdiff
add mhash support
authorSascha Schumann <sas@php.net>
Sun, 16 May 1999 12:01:25 +0000 (12:01 +0000)
committerSascha Schumann <sas@php.net>
Sun, 16 May 1999 12:01:25 +0000 (12:01 +0000)
ext/mhash/Makefile.am [new file with mode: 0644]
ext/mhash/config.h.stub [new file with mode: 0644]
ext/mhash/config.m4 [new file with mode: 0644]
ext/mhash/mhash.c [new file with mode: 0644]
ext/mhash/php_mhash.h [new file with mode: 0644]
ext/mhash/setup.stub [new file with mode: 0644]

diff --git a/ext/mhash/Makefile.am b/ext/mhash/Makefile.am
new file mode 100644 (file)
index 0000000..18be949
--- /dev/null
@@ -0,0 +1,6 @@
+# $Id$
+
+INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend
+noinst_LIBRARIES=libphpext_mhash.a
+libphpext_mhash_a_SOURCES=mhash.c
+
diff --git a/ext/mhash/config.h.stub b/ext/mhash/config.h.stub
new file mode 100644 (file)
index 0000000..9785cc2
--- /dev/null
@@ -0,0 +1,2 @@
+/* define if you want to use the mhash extension */
+#undef HAVE_LIBMHASH
diff --git a/ext/mhash/config.m4 b/ext/mhash/config.m4
new file mode 100644 (file)
index 0000000..0678f87
--- /dev/null
@@ -0,0 +1,31 @@
+dnl $Id$
+dnl config.m4 for extension mhash
+dnl don't forget to call PHP_EXTENSION(mhash)
+
+AC_MSG_CHECKING(for mhash support)
+AC_ARG_WITH(mhash,
+[  --with-mhash[=DIR]     Include mhash support.  DIR is the mhash
+                          install directory.],
+[
+  if test "$withval" != "no"; then
+    for i in /usr/local /usr $withval; do
+      if test -f $i/include/mhash.h; then
+        MHASH_DIR=$i
+      fi
+    done
+    if test "$MHASH_DIR" = ""; then
+      AC_MSG_ERROR(Please reinstall libmhash - I cannot find mhash.h)
+    fi
+    INCLUDES="$INCLUDES -I$MHASH_DIR/include"
+    EXTRA_LIBS="$EXTRA_LIBS -L$MHASH_DIR/lib -lmhash"
+
+    AC_DEFINE(HAVE_LIBMHASH)
+
+    AC_MSG_RESULT(yes)
+    PHP_EXTENSION(mhash)
+  else
+    AC_MSG_RESULT(no)
+  fi
+],[
+  AC_MSG_RESULT(no)
+])
diff --git a/ext/mhash/mhash.c b/ext/mhash/mhash.c
new file mode 100644 (file)
index 0000000..39788a2
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP HTML Embedded Scripting Language Version 4.0                     |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1999 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.2ns.de>                    |
+   +----------------------------------------------------------------------+
+ */
+
+#include "php.h"
+
+#if HAVE_LIBMHASH
+
+#include "php_mhash.h"
+
+#include "mhash.h"
+
+function_entry mhash_functions[] = {
+       PHP_FE(mhash_get_block_size, 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,
+};
+
+#define MHASH_FAILED "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);
+       
+       return SUCCESS;
+}
+
+/* proto 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 mhash(int hash, string data)
+   hash data with hash */
+PHP_FUNCTION(mhash)
+{
+       pval *hash, *data;
+       int td;
+       int bsize;
+       unsigned char *hash_data;
+       int i;
+
+       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 = init_mhash(hash->value.lval);
+       if(td == -1) {
+               php3_error(E_WARNING, MHASH_FAILED);
+               RETURN_FALSE;
+       }
+
+       mhash(td, data->value.str.val, data->value.str.len);
+
+       hash_data = (char *) end_mhash(td);
+       
+       RETVAL_STRINGL(hash_data, bsize, 1);
+       
+       free(hash_data);
+}
+
+#endif
diff --git a/ext/mhash/php_mhash.h b/ext/mhash/php_mhash.h
new file mode 100644 (file)
index 0000000..f2ce9d4
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef PHP_MHASH_H
+#define PHP_MHASH_H
+
+#if HAVE_LIBMHASH
+
+#if PHP_API_VERSION < 19990421
+#define  zend_module_entry php3_module_entry
+#include "modules.h"
+#include "internal_functions.h"
+#endif
+
+extern zend_module_entry mhash_module_entry;
+#define mhash_module_ptr &mhash_module_entry
+
+PHP_FUNCTION(mhash_get_block_size);
+PHP_FUNCTION(mhash);
+
+#else
+#define mhash_module_ptr NULL
+#endif
+
+#define phpext_mhash_ptr mhash_module_ptr
+
+#endif
diff --git a/ext/mhash/setup.stub b/ext/mhash/setup.stub
new file mode 100644 (file)
index 0000000..1af26d8
--- /dev/null
@@ -0,0 +1,6 @@
+# $Source$
+# $Id$
+
+define_option with-mhash 'mhash support?' yesnodir no \
+'    Whether to build the mhash extension.'
+