spoofchecker_create.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. +----------------------------------------------------------------------+
  3. | This source file is subject to version 3.01 of the PHP license, |
  4. | that is bundled with this package in the file LICENSE, and is |
  5. | available through the world-wide-web at the following url: |
  6. | https://www.php.net/license/3_01.txt |
  7. | If you did not receive a copy of the PHP license and are unable to |
  8. | obtain it through the world-wide-web, please send a note to |
  9. | license@php.net so we can mail you a copy immediately. |
  10. +----------------------------------------------------------------------+
  11. | Authors: Scott MacVicar <scottmac@php.net> |
  12. +----------------------------------------------------------------------+
  13. */
  14. #ifdef HAVE_CONFIG_H
  15. #include "config.h"
  16. #endif
  17. #include "php_intl.h"
  18. #include "spoofchecker_class.h"
  19. #include "intl_data.h"
  20. /* {{{ Spoofchecker object constructor. */
  21. PHP_METHOD(Spoofchecker, __construct)
  22. {
  23. #if U_ICU_VERSION_MAJOR_NUM < 58
  24. int checks;
  25. #endif
  26. zend_error_handling error_handling;
  27. SPOOFCHECKER_METHOD_INIT_VARS;
  28. if (zend_parse_parameters_none() == FAILURE) {
  29. RETURN_THROWS();
  30. }
  31. zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
  32. SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;
  33. co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
  34. INTL_METHOD_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker");
  35. #if U_ICU_VERSION_MAJOR_NUM >= 58
  36. /* TODO save it into the object for further suspiction check comparison. */
  37. /* ICU 58 removes WSC and MSC handling. However there are restriction
  38. levels as defined in
  39. http://www.unicode.org/reports/tr39/tr39-15.html#Restriction_Level_Detection
  40. and the default is high restrictive. In further, we might want to utilize
  41. uspoof_check2 APIs when it became stable, to use extended check result APIs.
  42. Subsequent changes in the unicode security algos are to be watched.*/
  43. uspoof_setRestrictionLevel(co->uspoof, SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL);
  44. #else
  45. /* Single-script enforcement is on by default. This fails for languages
  46. like Japanese that legally use multiple scripts within a single word,
  47. so we turn it off.
  48. */
  49. checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
  50. uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co));
  51. #endif
  52. zend_restore_error_handling(&error_handling);
  53. }
  54. /* }}} */