Skip to content

Commit

Permalink
Added horde_xxhash package
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 12, 2014
1 parent 27b7058 commit 548976c
Show file tree
Hide file tree
Showing 13 changed files with 983 additions and 0 deletions.
9 changes: 9 additions & 0 deletions framework/xxhash/CREDITS
@@ -0,0 +1,9 @@
horde_xxhash extension

This package is maintained by The Horde Project (http://www.horde.org/).
Copyright 2014 Horde LLC

The php-ext-xxhash package is released under the BSD License.

The xxHash C source was created by Yann Collet and released under the BSD
license.
29 changes: 29 additions & 0 deletions framework/xxhash/LICENSE
@@ -0,0 +1,29 @@
xxHash - Fast Hash algorithm
Copyright (C) 2012-2014, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

You can contact the author at :
- xxHash source repository : http://code.google.com/p/xxhash/
38 changes: 38 additions & 0 deletions framework/xxhash/README.md
@@ -0,0 +1,38 @@
# Horde xxhash Extension for PHP #

This extension allows for hashing via the xxHash algorithm.

Documentation for xxHash can be found at [» http://code.google.com/p/xxhash/](http://code.google.com/p/xxhash/).

## Configration ##

php.ini:

extension=horde_xxhash.so

## Function ##

* horde\_xxhash — xxHash computation

### horde\_xxhash — xxHash computation ###

#### Description ####

string **horde\_xxhash** (string _$data_)

xxHash computation.

#### Pameters ####

* _data_

The string to hash.

#### Return Values ####

Returns the 32-bit hash value (in hexidecimal), or FALSE if an error occurred.


## Examples ##

$hash = horde_xxhash('test');
37 changes: 37 additions & 0 deletions framework/xxhash/config.m4
@@ -0,0 +1,37 @@
dnl config.m4 for extension horde_xxhash

dnl Check PHP version:
AC_MSG_CHECKING(PHP version)
if test ! -z "$phpincludedir"; then
PHP_VERSION=`grep 'PHP_VERSION ' $phpincludedir/main/php_version.h | sed -e 's/.*"\([[0-9\.]]*\)".*/\1/g' 2>/dev/null`
elif test ! -z "$PHP_CONFIG"; then
PHP_VERSION=`$PHP_CONFIG --version 2>/dev/null`
fi

if test x"$PHP_VERSION" = "x"; then
AC_MSG_WARN([none])
else
PHP_MAJOR_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/g' 2>/dev/null`
PHP_MINOR_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/g' 2>/dev/null`
PHP_RELEASE_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/g' 2>/dev/null`
AC_MSG_RESULT([$PHP_VERSION])
fi

if test $PHP_MAJOR_VERSION -lt 5; then
AC_MSG_ERROR([need at least PHP 5 or newer])
fi

PHP_ARG_ENABLE(horde_xxhash, whether to enable horde_xxhash support,
[ --enable-horde_xxhash Enable horde_xxhash support])

if test "$PHP_HORDE_XXHASH" != "no"; then

PHP_NEW_EXTENSION(horde_xxhash, horde_xxhash.c xxhash.c, $ext_shared)

ifdef([PHP_INSTALL_HEADERS],
[
PHP_INSTALL_HEADERS([ext/horde_xxhash/], [horde_xxhash.h])
], [
PHP_ADD_MAKEFILE_FRAGMENT
])
fi
70 changes: 70 additions & 0 deletions framework/xxhash/horde_xxhash.c
@@ -0,0 +1,70 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "horde_xxhash.h"

/* xxhash */
#include "xxhash.h"


ZEND_BEGIN_ARG_INFO_EX(arginfo_horde_xxhash, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()


const zend_function_entry horde_xxhash_functions[] = {
PHP_FE(horde_xxhash, arginfo_horde_xxhash)
PHP_FE_END
};


zend_module_entry horde_xxhash_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"horde_xxhash",
horde_xxhash_functions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(horde_xxhash),
#if ZEND_MODULE_API_NO >= 20010901
HORDE_XXHASH_EXT_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_HORDE_XXHASH
ZEND_GET_MODULE(horde_xxhash)
#endif


PHP_MINFO_FUNCTION(horde_xxhash)
{
php_info_print_table_start();
php_info_print_table_row(2, "Horde xxHash support", "enabled");
php_info_print_table_row(2, "Extension Version", HORDE_XXHASH_EXT_VERSION);
php_info_print_table_end();
}


PHP_FUNCTION(horde_xxhash)
{
char *data;
char *hash = emalloc(9);
unsigned int data_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &data, &data_len) == FAILURE) {
RETURN_FALSE;
}

sprintf(hash, "%08x", XXH32(data, data_len, 0));

RETURN_STRINGL(hash, 8, 0);
}
25 changes: 25 additions & 0 deletions framework/xxhash/horde_xxhash.h
@@ -0,0 +1,25 @@
#ifndef PHP_HORDE_XXHASH_H
#define PHP_HORDE_XXHASH_H

extern zend_module_entry horde_xxhash_module_entry;
#define phpext_horde_xxhash_ptr &horde_xxhash_module_entry

#define HORDE_XXHASH_EXT_VERSION "1.0.0"

#ifdef PHP_WIN32
# define PHP_HORDE_XXHASH_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_HORDE_XXHASH_API __attribute__ ((visibility("default")))
#else
# define PHP_HORDE_XXHASH_API
#endif

#ifdef ZTS
#include "TSRM.h"
#endif

PHP_MINFO_FUNCTION(horde_xxhash);

PHP_FUNCTION(horde_xxhash);

#endif /* PHP_HORDE_XXHASH_H */
75 changes: 75 additions & 0 deletions framework/xxhash/package.xml
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.9.2" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>horde_xxhash</name>
<channel>pear.horde.org</channel>
<summary>Horde xxHash Extension</summary>
<description>PHP extension that implements the xxHash32 hashing algorithm.</description>
<lead>
<name>Michael Slusarz</name>
<user>slusarz</user>
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
<date>2014-02-11</date>
<version>
<release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
* [mms] First stable release.
</notes>
<contents>
<dir name="/">
<dir name="test">
<dir name="horde">
<dir name="xxhash">
<file name="AllTests.php" role="test" />
<file name="bootstrap.php" role="test" />
<file name="phpunit.xml" role="test" />
<file name="UnitTest.php" role="test" />
</dir> <!-- /test/horde/xxhash -->
</dir> <!-- /test/horde -->
</dir> <!-- /test -->
<file name="config.m4" role="src" />
<file name="CREDITS" role="doc" />
<file name="horde_xxhash.c" role="src" />
<file name="horde_xxhash.h" role="src" />
<file name="LICENSE" role="doc" />
<file name="README.md" role="doc" />
<file name="xxhash.c" role="src" />
<file name="xxhash.h" role="src" />
</dir> <!-- / -->
</contents>
<dependencies>
<required>
<php>
<min>5.0.0</min>
</php>
<pearinstaller>
<min>1.7.0</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>horde_xxhash</providesextension>
<extsrcrelease/>
<changelog>
<release>
<version>
<release>1.0.0</release>
<api>1.0.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2013-05-06</date>
<license uri="http://www.horde.org/licenses/bsd">BSD-2-Clause</license>
<notes>
* [mms] First stable release.
</notes>
</release>
</changelog>
</package>
3 changes: 3 additions & 0 deletions framework/xxhash/test/horde/xxhash/AllTests.php
@@ -0,0 +1,3 @@
<?php
require_once 'Horde/Test/AllTests.php';
Horde_Test_AllTests::init(__FILE__)->run();
54 changes: 54 additions & 0 deletions framework/xxhash/test/horde/xxhash/UnitTest.php
@@ -0,0 +1,54 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (BSD). If you
* did not receive this file, see http://www.horde.org/license/bsd.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package xxhash
* @subpackage UnitTests
*/

/**
* Tests for the horde_xxhash extension.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @ignore
* @license http://www.horde.org/licenses/bsd BSD
* @package xxhash
* @subpackage UnitTests
*/
class horde_xxhash_UnitTest extends PHPUnit_Framework_TestCase
{
private $data;

public function setUp()
{
if (!extension_loaded('horde_xxhash')) {
$this->markTestSkipped('horde_xxhash extension not installed.');
}
}

public function testXxhash()
{
$data = array(
'123' => 'b6855437',
'1234' => '01543429',
'ABC' => '80712ed5',
'ABCD' => 'aa960ca6'
);

foreach ($data as $key => $val) {
$this->assertEquals(
$val,
horde_xxhash($key)
);
}
}

}
3 changes: 3 additions & 0 deletions framework/xxhash/test/horde/xxhash/bootstrap.php
@@ -0,0 +1,3 @@
<?php
require_once 'Horde/Test/Bootstrap.php';
Horde_Test_Bootstrap::bootstrap(dirname(__FILE__));
1 change: 1 addition & 0 deletions framework/xxhash/test/horde/xxhash/phpunit.xml
@@ -0,0 +1 @@
<phpunit bootstrap="bootstrap.php"></phpunit>

0 comments on commit 548976c

Please sign in to comment.