Add Spoofchecker to intl extension.

Implements part of Unicode TR36 and TR39
This commit is contained in:
Scott MacVicar 2011-01-13 06:53:09 +00:00
parent c6544fad1a
commit d90394851c
16 changed files with 718 additions and 2 deletions

4
NEWS
View File

@ -140,6 +140,10 @@ PHP NEWS
. Added FNV-1 hash support. (Michael Maclean)
. Made Adler32 algorithm faster. FR #53213. (zavasek at yandex dot ru)
- Improved intl extension:
. Added Spoofchecker, allows checking for visibly confusable characters and
other security issues. (Scott)
- Improved JSON extension:
. Added JsonSerializable interface. (Sara)
. Added JSON_BIGINT_AS_STRING, extended json_decode() sig with $options.

View File

@ -58,7 +58,11 @@ if test "$PHP_INTL" != "no"; then
transliterator/transliterator.c \
transliterator/transliterator_class.c \
transliterator/transliterator_methods.c \
idn/idn.c, $ext_shared,,$ICU_INCS)
idn/idn.c \
spoofchecker/spoofchecker_class.c \
spoofchecker/spoofchecker.c\
spoofchecker/spoofchecker_create.c\
spoofchecker/spoofchecker_main.c, $ext_shared,,$ICU_INCS)
PHP_ADD_BUILD_DIR($ext_builddir/collator)
PHP_ADD_BUILD_DIR($ext_builddir/common)
@ -71,4 +75,5 @@ if test "$PHP_INTL" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/resourcebundle)
PHP_ADD_BUILD_DIR($ext_builddir/transliterator)
PHP_ADD_BUILD_DIR($ext_builddir/idn)
PHP_ADD_BUILD_DIR($ext_builddir/spoofchecker)
fi

View File

@ -71,6 +71,12 @@ if (PHP_INTL != "no") {
resourcebundle_class.c \
resourcebundle_iterator.c",
"intl");
ADD_SOURCES(configure_module_dirname + "/spoofchecker", "\
spoofchecker.c \
spoofchecker_class.c \
spoofchecker_create.c \
spoofchecker_main.c",
"intl");
ADD_SOURCES(configure_module_dirname + "/transliterator", "\
transliterator.c \
transliterator_class.c \

View File

@ -70,6 +70,11 @@
#include "idn/idn.h"
#include "spoofchecker/spoofchecker_class.h"
#include "spoofchecker/spoofchecker.h"
#include "spoofchecker/spoofchecker_create.h"
#include "spoofchecker/spoofchecker_main.h"
#include "msgformat/msgformat.h"
#include "common/common_error.h"
@ -511,7 +516,7 @@ zend_function_entry intl_functions[] = {
PHP_FE( resourcebundle_locales, arginfo_resourcebundle_locales_proc )
PHP_FE( resourcebundle_get_error_code, arginfo_resourcebundle_get_error_code_proc )
PHP_FE( resourcebundle_get_error_message, arginfo_resourcebundle_get_error_message_proc )
/* Transliterator functions */
PHP_FE( transliterator_create, arginfo_transliterator_create )
PHP_FE( transliterator_create_from_rules, arginfo_transliterator_create_from_rules )
@ -633,6 +638,12 @@ PHP_MINIT_FUNCTION( intl )
/* Expose IDN constants to PHP scripts. */
idn_register_constants(INIT_FUNC_ARGS_PASSTHRU);
/* Register 'Spoofchecker' PHP class */
spoofchecker_register_Spoofchecker_class( TSRMLS_C );
/* Expose Spoofchecker constants to PHP scripts */
spoofchecker_register_constants( INIT_FUNC_ARGS_PASSTHRU );
/* Global error handling. */
intl_error_init( NULL TSRMLS_CC );

View File

@ -0,0 +1,60 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "spoofchecker_class.h"
#include "spoofchecker.h"
#include <unicode/uspoof.h>
/* {{{ spoofchecker_register_constants
* Register constants
*/
void spoofchecker_register_constants(INIT_FUNC_ARGS)
{
if (!Spoofchecker_ce_ptr)
{
zend_error(E_ERROR, "Spoofchecker class not defined");
return;
}
#define SPOOFCHECKER_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long(Spoofchecker_ce_ptr, ZEND_STRS( #x ) - 1, USPOOF_##x TSRMLS_CC);
SPOOFCHECKER_EXPOSE_CLASS_CONST(SINGLE_SCRIPT_CONFUSABLE)
SPOOFCHECKER_EXPOSE_CLASS_CONST(MIXED_SCRIPT_CONFUSABLE)
SPOOFCHECKER_EXPOSE_CLASS_CONST(WHOLE_SCRIPT_CONFUSABLE)
SPOOFCHECKER_EXPOSE_CLASS_CONST(ANY_CASE)
SPOOFCHECKER_EXPOSE_CLASS_CONST(SINGLE_SCRIPT)
SPOOFCHECKER_EXPOSE_CLASS_CONST(INVISIBLE)
SPOOFCHECKER_EXPOSE_CLASS_CONST(CHAR_LIMIT)
#undef SPOOFCHECKER_EXPOSE_CLASS_CONST
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

View File

@ -0,0 +1,24 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef SPOOFCHECKER_SPOOFCHECKER_H
#define SPOOFCHECKER_SPOOFCHECKER_H
#include <php.h>
void spoofchecker_register_constants(INIT_FUNC_ARGS);
#endif // SPOOFCHECKER_SPOOFCHECKER_H

View File

@ -0,0 +1,185 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#include "spoofchecker_class.h"
#include "spoofchecker_main.h"
#include "spoofchecker_create.h"
#include "php_intl.h"
#include "intl_error.h"
#include <unicode/uspoof.h>
zend_class_entry *Spoofchecker_ce_ptr = NULL;
static zend_object_handlers Spoofchecker_handlers;
/*
* Auxiliary functions needed by objects of 'Spoofchecker' class
*/
/* {{{ Spoofchecker_objects_dtor */
static void Spoofchecker_objects_dtor(
void *object,
zend_object_handle handle TSRMLS_DC)
{
zend_objects_destroy_object(object, handle TSRMLS_CC);
}
/* }}} */
/* {{{ Spoofchecker_objects_free */
void Spoofchecker_objects_free(zend_object *object TSRMLS_DC)
{
Spoofchecker_object* co = (Spoofchecker_object*)object;
zend_object_std_dtor(&co->zo TSRMLS_CC);
spoofchecker_object_destroy(co TSRMLS_CC);
efree(co);
}
/* }}} */
/* {{{ Spoofchecker_object_create */
zend_object_value Spoofchecker_object_create(
zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
Spoofchecker_object* intern;
intern = ecalloc(1, sizeof(Spoofchecker_object));
intl_error_init(SPOOFCHECKER_ERROR_P(intern) TSRMLS_CC);
zend_object_std_init(&intern->zo, ce TSRMLS_CC);
retval.handle = zend_objects_store_put(
intern,
Spoofchecker_objects_dtor,
(zend_objects_free_object_storage_t)Spoofchecker_objects_free,
NULL TSRMLS_CC);
retval.handlers = &Spoofchecker_handlers;
return retval;
}
/* }}} */
/*
* 'Spoofchecker' class registration structures & functions
*/
/* {{{ Spoofchecker methods arguments info */
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_0_args, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_checks, 0, 0, 1)
ZEND_ARG_INFO(0, checks)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_allowed_locales, 0, 0, 1)
ZEND_ARG_INFO(0, locale_list)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_is_suspicous, 0, 0, 1)
ZEND_ARG_INFO(0, text)
ZEND_ARG_INFO(1, error)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_are_confusable, 0, 0, 2)
ZEND_ARG_INFO(0, s1)
ZEND_ARG_INFO(0, s2)
ZEND_ARG_INFO(1, error)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ Spoofchecker_class_functions
* Every 'Spoofchecker' class method has an entry in this table
*/
zend_function_entry Spoofchecker_class_functions[] = {
PHP_ME(Spoofchecker, __construct, spoofchecker_0_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Spoofchecker, isSuspicious, spoofchecker_is_suspicous, ZEND_ACC_PUBLIC)
PHP_ME(Spoofchecker, areConfusable, spoofchecker_are_confusable, ZEND_ACC_PUBLIC)
PHP_ME(Spoofchecker, setAllowedLocales, spoofchecker_set_allowed_locales, ZEND_ACC_PUBLIC)
PHP_ME(Spoofchecker, setChecks, spoofchecker_set_checks, ZEND_ACC_PUBLIC)
{ NULL, NULL, NULL }
};
/* }}} */
/* {{{ spoofchecker_register_Spoofchecker_class
* Initialize 'Spoofchecker' class
*/
void spoofchecker_register_Spoofchecker_class(TSRMLS_D)
{
zend_class_entry ce;
/* Create and register 'Spoofchecker' class. */
INIT_CLASS_ENTRY(ce, "Spoofchecker", Spoofchecker_class_functions);
ce.create_object = Spoofchecker_object_create;
Spoofchecker_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
memcpy(&Spoofchecker_handlers, zend_get_std_object_handlers(),
sizeof Spoofchecker_handlers);
/* Doesn't make sense to clone */
Spoofchecker_handlers.clone_obj = NULL;
if (!Spoofchecker_ce_ptr) {
zend_error(E_ERROR,
"Spoofchecker: attempt to create properties "
"on a non-registered class.");
return;
}
}
/* }}} */
/* {{{ void spoofchecker_object_init( Spoofchecker_object* co )
* Initialize internals of Spoofchecker_object.
* Must be called before any other call to 'spoofchecker_object_...' functions.
*/
void spoofchecker_object_init(Spoofchecker_object* co TSRMLS_DC)
{
if (!co) {
return;
}
intl_error_init(SPOOFCHECKER_ERROR_P(co) TSRMLS_CC);
}
/* }}} */
/* {{{ void spoofchecker_object_destroy( Spoofchecker_object* co )
* Clean up mem allocted by internals of Spoofchecker_object
*/
void spoofchecker_object_destroy(Spoofchecker_object* co TSRMLS_DC)
{
if (!co) {
return;
}
if (co->uspoof) {
uspoof_close(co->uspoof);
co->uspoof = NULL;
}
intl_error_reset(SPOOFCHECKER_ERROR_P(co) TSRMLS_CC);
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

View File

@ -0,0 +1,70 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef SPOOFCHECKER_CLASS_H
#define SPOOFCHECKER_CLASS_H
#include <php.h>
#include "intl_common.h"
#include "spoofchecker_create.h"
#include "intl_error.h"
#include <unicode/uspoof.h>
typedef struct {
zend_object zo;
// error handling
intl_error err;
// ICU Spoofchecker
USpoofChecker* uspoof;
} Spoofchecker_object;
#define SPOOFCHECKER_ERROR(co) (co)->err
#define SPOOFCHECKER_ERROR_P(co) &(SPOOFCHECKER_ERROR(co))
#define SPOOFCHECKER_ERROR_CODE(co) INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co))
#define SPOOFCHECKER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co)))
void spoofchecker_register_Spoofchecker_class(TSRMLS_D);
void spoofchecker_object_init(Spoofchecker_object* co TSRMLS_DC);
void spoofchecker_object_destroy(Spoofchecker_object* co TSRMLS_DC);
extern zend_class_entry *Spoofchecker_ce_ptr;
/* Auxiliary macros */
#define SPOOFCHECKER_METHOD_INIT_VARS \
zval* object = getThis(); \
Spoofchecker_object* co = NULL; \
intl_error_reset(NULL TSRMLS_CC); \
#define SPOOFCHECKER_METHOD_FETCH_OBJECT \
co = (Spoofchecker_object *) zend_object_store_get_object(object TSRMLS_CC); \
intl_error_reset(SPOOFCHECKER_ERROR_P(co) TSRMLS_CC); \
// Macro to check return value of a ucol_* function call.
#define SPOOFCHECKER_CHECK_STATUS(co, msg) \
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co) TSRMLS_CC); \
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { \
intl_errors_set_custom_msg(SPOOFCHECKER_ERROR_P(co), msg, 0 TSRMLS_CC); \
RETURN_FALSE; \
} \
#endif // #ifndef SPOOFCHECKER_CLASS_H

View File

@ -0,0 +1,59 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php_intl.h"
#include "spoofchecker_class.h"
#include "spoofchecker_create.h"
#include "intl_data.h"
/* {{{ proto Spoofchecker Spoofchecker::__construct()
* Spoofchecker object constructor.
*/
PHP_METHOD(Spoofchecker, __construct)
{
int checks;
SPOOFCHECKER_METHOD_INIT_VARS
if (zend_parse_parameters_none() == FAILURE) {
return;
}
SPOOFCHECKER_METHOD_FETCH_OBJECT
co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker");
/* Single-script enforcement is on by default. This fails for languages
like Japanese that legally use multiple scripts within a single word,
so we turn it off.
*/
checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co));
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

View File

@ -0,0 +1,24 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef SPOOFCHECKER_CREATE_H
#define SPOOFCHECKER_CREATE_H
#include <php.h>
PHP_METHOD(Spoofchecker, __construct);
#endif // SPOOFCHECKER_CREATE_H

View File

@ -0,0 +1,145 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php_intl.h"
#include "spoofchecker_class.h"
/* {{{ proto void Spoofchecker::isSuspicious( string $text[, int $error_code ] )
* Checks if a given text contains any suspicious characters
*/
PHP_METHOD(Spoofchecker, isSuspicious)
{
int ret;
char *text;
int text_len;
zval *issued_found = NULL;
SPOOFCHECKER_METHOD_INIT_VARS
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &text, &text_len, &issued_found)) {
return;
}
SPOOFCHECKER_METHOD_FETCH_OBJECT
ret = uspoof_checkUTF8(co->uspoof, text, text_len, NULL, SPOOFCHECKER_ERROR_CODE_P(co));
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C), u_errorName(SPOOFCHECKER_ERROR_CODE(co)), SPOOFCHECKER_ERROR_CODE(co) TSRMLS_CC);
return;
}
if (issued_found) {
zval_dtor(issued_found);
ZVAL_LONG(issued_found, ret);
}
RETVAL_BOOL(ret != 0);
}
/* }}} */
/* {{{ proto void Spoofchecker::areConfusable( string $str1, string $str2[, int $error_code ] )
* Checks if a given text contains any confusable characters
*/
PHP_METHOD(Spoofchecker, areConfusable)
{
int ret;
char *s1, *s2;
int s1_len, s2_len;
zval *issued_found = NULL;
SPOOFCHECKER_METHOD_INIT_VARS
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z", &s1, &s1_len,
&s2, &s2_len, &issued_found)) {
return;
}
SPOOFCHECKER_METHOD_FETCH_OBJECT
ret = uspoof_areConfusableUTF8(co->uspoof, s1, s1_len, s2, s2_len, SPOOFCHECKER_ERROR_CODE_P(co));
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C), u_errorName(SPOOFCHECKER_ERROR_CODE(co)), SPOOFCHECKER_ERROR_CODE(co) TSRMLS_CC);
return;
}
if (issued_found) {
zval_dtor(issued_found);
ZVAL_LONG(issued_found, ret);
}
RETVAL_BOOL(ret != 0);
}
/* }}} */
/* {{{ proto void Spoofchecker::setAllowedLocales( string $locales )
* Locales to use when running checks
*/
PHP_METHOD(Spoofchecker, setAllowedLocales)
{
int ret;
char *locales;
int locales_len;
SPOOFCHECKER_METHOD_INIT_VARS
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &locales, &locales_len)) {
return;
}
SPOOFCHECKER_METHOD_FETCH_OBJECT
uspoof_setAllowedLocales(co->uspoof, locales, SPOOFCHECKER_ERROR_CODE_P(co));
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C), u_errorName(SPOOFCHECKER_ERROR_CODE(co)), SPOOFCHECKER_ERROR_CODE(co) TSRMLS_CC);
return;
}
}
/* }}} */
/* {{{ proto void Spoofchecker::setChecks( int $checks )
* Set the checks to run
*/
PHP_METHOD(Spoofchecker, setChecks)
{
int ret;
long checks;
SPOOFCHECKER_METHOD_INIT_VARS
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &checks)) {
return;
}
SPOOFCHECKER_METHOD_FETCH_OBJECT
uspoof_setChecks(co->uspoof, checks, SPOOFCHECKER_ERROR_CODE_P(co));
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C), u_errorName(SPOOFCHECKER_ERROR_CODE(co)), SPOOFCHECKER_ERROR_CODE(co) TSRMLS_CC);
return;
}
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

View File

@ -0,0 +1,27 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef SPOOFCHECKER_MAIN_H
#define SPOOFCHECKER_MAIN_H
#include <php.h>
PHP_METHOD(Spoofchecker, isSuspicious);
PHP_METHOD(Spoofchecker, areConfusable);
PHP_METHOD(Spoofchecker, setAllowedLocales);
PHP_METHOD(Spoofchecker, setChecks);
#endif // SPOOFCHECKER_MAIN_H

View File

@ -0,0 +1,23 @@
--TEST--
spoofchecker suspicious character checker
--SKIPIF--
<?php if(!extension_loaded('intl')) print 'skip'; ?>
--FILE--
<?php
$url = "http://www.payp\xD0\xB0l.com";
$x = new Spoofchecker();
echo "paypal with Cyrillic spoof characters\n";
var_dump($x->isSuspicious($url));
echo "certain all-uppercase Latin sequences can be spoof of Greek\n";
var_dump($x->isSuspicious("NAPKIN PEZ"));
var_dump($x->isSuspicious("napkin pez"));
?>
--EXPECTF--
paypal with Cyrillic spoof characters
bool(true)
certain all-uppercase Latin sequences can be spoof of Greek
bool(true)
bool(false)

View File

@ -0,0 +1,20 @@
--TEST--
spoofchecker confusable tests
--SKIPIF--
<?php if(!extension_loaded('intl')) print 'skip'; ?>
--FILE--
<?php
$url = "http://www.payp\xD0\xB0l.com";
$x = new Spoofchecker();
echo "Checking if words are confusable\n";
var_dump($x->areConfusable("hello, world", "goodbye, world"));
var_dump($x->areConfusable("hello, world", "hello, world"));
var_dump($x->areConfusable("hello, world", "he11o, wor1d"));
?>
--EXPECTF--
Checking if words are confusable
bool(false)
bool(true)
bool(true)

View File

@ -0,0 +1,25 @@
--TEST--
spoofchecker with locale settings
--SKIPIF--
<?php if(!extension_loaded('intl')) print 'skip'; ?>
--FILE--
<?php
$korean = "\xED\x95\x9C" . "\xEA\xB5\xAD" . "\xEB\xA7\x90";
$x = new Spoofchecker();
echo "Is suspcious, en_US\n";
$x->setAllowedLocales('en_US');
var_dump($x->isSuspicious($korean));
echo "Is suspcious, ko_KR\n";
$x->setAllowedLocales('en_US, ko_KR');
var_dump($x->isSuspicious($korean));
?>
--EXPECTF--
Is suspcious, en_US
bool(true)
Is suspcious, ko_KR
bool(false)

View File

@ -0,0 +1,28 @@
--TEST--
spoofchecker with settings changed
--SKIPIF--
<?php if(!extension_loaded('intl')) print 'skip'; ?>
--FILE--
<?php
$korean = "\xED\x95\x9C" . "\xEA\xB5\xAD" . "\xEB\xA7\x90";
$x = new Spoofchecker();
echo "Check with default settings\n";
var_dump($x->areConfusable("HELLO", "H\xD0\x95LLO"));
var_dump($x->areConfusable("hello", "h\xD0\xB5llo"));
echo "Change confusable settings\n";
$x->setChecks(Spoofchecker::MIXED_SCRIPT_CONFUSABLE |
Spoofchecker::WHOLE_SCRIPT_CONFUSABLE |
Spoofchecker::SINGLE_SCRIPT_CONFUSABLE);
var_dump($x->areConfusable("HELLO", "H\xD0\x95LLO"));
var_dump($x->areConfusable("hello", "h\xD0\xB5llo"));
?>
--EXPECTF--
Check with default settings
bool(true)
bool(true)
Change confusable settings
bool(false)
bool(true)