Annotation of embedaddon/php/ext/intl/spoofchecker/spoofchecker_main.c, revision 1.1
1.1 ! misho 1: /*
! 2: +----------------------------------------------------------------------+
! 3: | PHP Version 5 |
! 4: +----------------------------------------------------------------------+
! 5: | This source file is subject to version 3.01 of the PHP license, |
! 6: | that is bundled with this package in the file LICENSE, and is |
! 7: | available through the world-wide-web at the following url: |
! 8: | http://www.php.net/license/3_01.txt |
! 9: | If you did not receive a copy of the PHP license and are unable to |
! 10: | obtain it through the world-wide-web, please send a note to |
! 11: | license@php.net so we can mail you a copy immediately. |
! 12: +----------------------------------------------------------------------+
! 13: | Authors: Scott MacVicar <scottmac@php.net> |
! 14: +----------------------------------------------------------------------+
! 15: */
! 16:
! 17: #ifdef HAVE_CONFIG_H
! 18: #include "config.h"
! 19: #endif
! 20:
! 21: #include "php_intl.h"
! 22: #include "spoofchecker_class.h"
! 23:
! 24: /* {{{ proto bool Spoofchecker::isSuspicious( string text[, int &error_code ] )
! 25: * Checks if a given text contains any suspicious characters
! 26: */
! 27: PHP_METHOD(Spoofchecker, isSuspicious)
! 28: {
! 29: int ret;
! 30: char *text;
! 31: int text_len;
! 32: zval *error_code = NULL;
! 33: SPOOFCHECKER_METHOD_INIT_VARS;
! 34:
! 35: if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &text, &text_len, &error_code)) {
! 36: return;
! 37: }
! 38:
! 39: SPOOFCHECKER_METHOD_FETCH_OBJECT;
! 40:
! 41: ret = uspoof_checkUTF8(co->uspoof, text, text_len, NULL, SPOOFCHECKER_ERROR_CODE_P(co));
! 42:
! 43: if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
! 44: php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
! 45: RETURN_TRUE;
! 46: }
! 47:
! 48: if (error_code) {
! 49: zval_dtor(error_code);
! 50: ZVAL_LONG(error_code, ret);
! 51: }
! 52: RETVAL_BOOL(ret != 0);
! 53: }
! 54: /* }}} */
! 55:
! 56: /* {{{ proto bool Spoofchecker::areConfusable( string str1, string str2[, int &error_code ] )
! 57: * Checks if a given text contains any confusable characters
! 58: */
! 59: PHP_METHOD(Spoofchecker, areConfusable)
! 60: {
! 61: int ret;
! 62: char *s1, *s2;
! 63: int s1_len, s2_len;
! 64: zval *error_code = NULL;
! 65: SPOOFCHECKER_METHOD_INIT_VARS;
! 66:
! 67: if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z", &s1, &s1_len,
! 68: &s2, &s2_len, &error_code)) {
! 69: return;
! 70: }
! 71:
! 72: SPOOFCHECKER_METHOD_FETCH_OBJECT;
! 73:
! 74: ret = uspoof_areConfusableUTF8(co->uspoof, s1, s1_len, s2, s2_len, SPOOFCHECKER_ERROR_CODE_P(co));
! 75:
! 76: if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
! 77: php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
! 78: RETURN_TRUE;
! 79: }
! 80:
! 81: if (error_code) {
! 82: zval_dtor(error_code);
! 83: ZVAL_LONG(error_code, ret);
! 84: }
! 85: RETVAL_BOOL(ret != 0);
! 86: }
! 87: /* }}} */
! 88:
! 89: /* {{{ proto void Spoofchecker::setAllowedLocales( string locales )
! 90: * Locales to use when running checks
! 91: */
! 92: PHP_METHOD(Spoofchecker, setAllowedLocales)
! 93: {
! 94: char *locales;
! 95: int locales_len;
! 96: SPOOFCHECKER_METHOD_INIT_VARS;
! 97:
! 98: if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &locales, &locales_len)) {
! 99: return;
! 100: }
! 101:
! 102: SPOOFCHECKER_METHOD_FETCH_OBJECT;
! 103:
! 104: uspoof_setAllowedLocales(co->uspoof, locales, SPOOFCHECKER_ERROR_CODE_P(co));
! 105:
! 106: if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
! 107: php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
! 108: return;
! 109: }
! 110: }
! 111: /* }}} */
! 112:
! 113: /* {{{ proto void Spoofchecker::setChecks( int checks )
! 114: * Set the checks to run
! 115: */
! 116: PHP_METHOD(Spoofchecker, setChecks)
! 117: {
! 118: long checks;
! 119: SPOOFCHECKER_METHOD_INIT_VARS;
! 120:
! 121: if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &checks)) {
! 122: return;
! 123: }
! 124:
! 125: SPOOFCHECKER_METHOD_FETCH_OBJECT;
! 126:
! 127: uspoof_setChecks(co->uspoof, checks, SPOOFCHECKER_ERROR_CODE_P(co));
! 128:
! 129: if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
! 130: php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
! 131: }
! 132: }
! 133: /* }}} */
! 134:
! 135: /*
! 136: * Local variables:
! 137: * tab-width: 4
! 138: * c-basic-offset: 4
! 139: * End:
! 140: * vim600: noet sw=4 ts=4 fdm=marker
! 141: * vim<600: noet sw=4 ts=4
! 142: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>