spoofchecker_create.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  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. #include "spoofchecker_create.h"
  22. #include "intl_data.h"
  23. /* {{{ proto Spoofchecker::__construct()
  24. * Spoofchecker object constructor.
  25. */
  26. PHP_METHOD(Spoofchecker, __construct)
  27. {
  28. #if U_ICU_VERSION_MAJOR_NUM < 58
  29. int checks;
  30. #endif
  31. zend_error_handling error_handling;
  32. SPOOFCHECKER_METHOD_INIT_VARS;
  33. if (zend_parse_parameters_none_throw() == FAILURE) {
  34. return;
  35. }
  36. zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
  37. SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;
  38. co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
  39. INTL_METHOD_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker");
  40. #if U_ICU_VERSION_MAJOR_NUM >= 58
  41. /* TODO save it into the object for further suspiction check comparison. */
  42. /* ICU 58 removes WSC and MSC handling. However there are restriction
  43. levels as defined in
  44. http://www.unicode.org/reports/tr39/tr39-15.html#Restriction_Level_Detection
  45. and the default is high restrictive. In further, we might want to utilize
  46. uspoof_check2 APIs when it became stable, to use extended check result APIs.
  47. Subsequent changes in the unicode security algos are to be watched.*/
  48. uspoof_setRestrictionLevel(co->uspoof, SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL);
  49. #else
  50. /* Single-script enforcement is on by default. This fails for languages
  51. like Japanese that legally use multiple scripts within a single word,
  52. so we turn it off.
  53. */
  54. checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
  55. uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co));
  56. #endif
  57. zend_restore_error_handling(&error_handling);
  58. }
  59. /* }}} */
  60. /*
  61. * Local variables:
  62. * tab-width: 4
  63. * c-basic-offset: 4
  64. * End:
  65. * vim600: noet sw=4 ts=4 fdm=marker
  66. * vim<600: noet sw=4 ts=4
  67. */