spoofchecker_main.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include "php_intl.h"
  20. #include "spoofchecker_class.h"
  21. /* {{{ proto bool Spoofchecker::isSuspicious( string text[, int &error_code ] )
  22. * Checks if a given text contains any suspicious characters
  23. */
  24. PHP_METHOD(Spoofchecker, isSuspicious)
  25. {
  26. int ret;
  27. char *text;
  28. int text_len;
  29. zval *error_code = NULL;
  30. SPOOFCHECKER_METHOD_INIT_VARS;
  31. if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &text, &text_len, &error_code)) {
  32. return;
  33. }
  34. SPOOFCHECKER_METHOD_FETCH_OBJECT;
  35. ret = uspoof_checkUTF8(co->uspoof, text, text_len, NULL, SPOOFCHECKER_ERROR_CODE_P(co));
  36. if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
  37. php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
  38. RETURN_TRUE;
  39. }
  40. if (error_code) {
  41. zval_dtor(error_code);
  42. ZVAL_LONG(error_code, ret);
  43. }
  44. RETVAL_BOOL(ret != 0);
  45. }
  46. /* }}} */
  47. /* {{{ proto bool Spoofchecker::areConfusable( string str1, string str2[, int &error_code ] )
  48. * Checks if a given text contains any confusable characters
  49. */
  50. PHP_METHOD(Spoofchecker, areConfusable)
  51. {
  52. int ret;
  53. char *s1, *s2;
  54. int s1_len, s2_len;
  55. zval *error_code = NULL;
  56. SPOOFCHECKER_METHOD_INIT_VARS;
  57. if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z", &s1, &s1_len,
  58. &s2, &s2_len, &error_code)) {
  59. return;
  60. }
  61. SPOOFCHECKER_METHOD_FETCH_OBJECT;
  62. ret = uspoof_areConfusableUTF8(co->uspoof, s1, s1_len, s2, s2_len, SPOOFCHECKER_ERROR_CODE_P(co));
  63. if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
  64. php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
  65. RETURN_TRUE;
  66. }
  67. if (error_code) {
  68. zval_dtor(error_code);
  69. ZVAL_LONG(error_code, ret);
  70. }
  71. RETVAL_BOOL(ret != 0);
  72. }
  73. /* }}} */
  74. /* {{{ proto void Spoofchecker::setAllowedLocales( string locales )
  75. * Locales to use when running checks
  76. */
  77. PHP_METHOD(Spoofchecker, setAllowedLocales)
  78. {
  79. char *locales;
  80. int locales_len;
  81. SPOOFCHECKER_METHOD_INIT_VARS;
  82. if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &locales, &locales_len)) {
  83. return;
  84. }
  85. SPOOFCHECKER_METHOD_FETCH_OBJECT;
  86. uspoof_setAllowedLocales(co->uspoof, locales, SPOOFCHECKER_ERROR_CODE_P(co));
  87. if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
  88. php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
  89. return;
  90. }
  91. }
  92. /* }}} */
  93. /* {{{ proto void Spoofchecker::setChecks( int checks )
  94. * Set the checks to run
  95. */
  96. PHP_METHOD(Spoofchecker, setChecks)
  97. {
  98. long checks;
  99. SPOOFCHECKER_METHOD_INIT_VARS;
  100. if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &checks)) {
  101. return;
  102. }
  103. SPOOFCHECKER_METHOD_FETCH_OBJECT;
  104. uspoof_setChecks(co->uspoof, checks, SPOOFCHECKER_ERROR_CODE_P(co));
  105. if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
  106. php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
  107. }
  108. }
  109. /* }}} */
  110. /*
  111. * Local variables:
  112. * tab-width: 4
  113. * c-basic-offset: 4
  114. * End:
  115. * vim600: noet sw=4 ts=4 fdm=marker
  116. * vim<600: noet sw=4 ts=4
  117. */