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
15 #ifndef SPOOFCHECKER_CLASS_H
16 #define SPOOFCHECKER_CLASS_H
17
18 #include <php.h>
19
20 #include "intl_common.h"
21 #include "intl_error.h"
22 #include "intl_data.h"
23
24 #include <unicode/uspoof.h>
25
26 typedef struct {
27 // error handling
28 intl_error err;
29
30 // ICU Spoofchecker
31 USpoofChecker* uspoof;
32
33 zend_object zo;
34 } Spoofchecker_object;
35
php_intl_spoofchecker_fetch_object(zend_object * obj)36 static inline Spoofchecker_object *php_intl_spoofchecker_fetch_object(zend_object *obj) {
37 return (Spoofchecker_object *)((char*)(obj) - XtOffsetOf(Spoofchecker_object, zo));
38 }
39 #define Z_INTL_SPOOFCHECKER_P(zv) php_intl_spoofchecker_fetch_object((Z_OBJ_P(zv)))
40
41 #define SPOOFCHECKER_ERROR(co) (co)->err
42 #define SPOOFCHECKER_ERROR_P(co) &(SPOOFCHECKER_ERROR(co))
43
44 #define SPOOFCHECKER_ERROR_CODE(co) INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co))
45 #define SPOOFCHECKER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co)))
46
47 void spoofchecker_register_Spoofchecker_class(void);
48
49 void spoofchecker_object_init(Spoofchecker_object* co);
50 void spoofchecker_object_destroy(Spoofchecker_object* co);
51
52 extern zend_class_entry *Spoofchecker_ce_ptr;
53
54 /* Auxiliary macros */
55
56 #define SPOOFCHECKER_METHOD_INIT_VARS \
57 zval* object = ZEND_THIS; \
58 Spoofchecker_object* co = NULL; \
59 intl_error_reset(NULL); \
60
61 #define SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_SPOOFCHECKER, co)
62 #define SPOOFCHECKER_METHOD_FETCH_OBJECT \
63 SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \
64 if (co->uspoof == NULL) { \
65 zend_throw_error(NULL, "Found unconstructed Spoofchecker"); \
66 RETURN_THROWS(); \
67 }
68
69 // Macro to check return value of a ucol_* function call.
70 #define SPOOFCHECKER_CHECK_STATUS(co, msg) \
71 intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co)); \
72 if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { \
73 intl_errors_set_custom_msg(SPOOFCHECKER_ERROR_P(co), msg, 0); \
74 RETURN_FALSE; \
75 } \
76
77 #if U_ICU_VERSION_MAJOR_NUM >= 58
78 #define SPOOFCHECKER_DEFAULT_RESTRICTION_LEVEL USPOOF_HIGHLY_RESTRICTIVE
79 #endif
80
81 #endif // #ifndef SPOOFCHECKER_CLASS_H
82