1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <scottmac@php.net> |
+----------------------------------------------------------------------+
*/
#include "spoofchecker_class.h"
#include "spoofchecker_main.h"
#include "spoofchecker_create.h"
#include "php_intl.h"
#include "intl_error.h"
#include <unicode/uspoof.h>
zend_class_entry *Spoofchecker_ce_ptr = NULL;
static zend_object_handlers Spoofchecker_handlers;
/*
* Auxiliary functions needed by objects of 'Spoofchecker' class
*/
/* {{{ Spoofchecker_objects_dtor */
static void Spoofchecker_objects_dtor(
void *object,
zend_object_handle handle TSRMLS_DC)
{
zend_objects_destroy_object(object, handle TSRMLS_CC);
}
/* }}} */
/* {{{ Spoofchecker_objects_free */
void Spoofchecker_objects_free(zend_object *object TSRMLS_DC)
{
Spoofchecker_object* co = (Spoofchecker_object*)object;
zend_object_std_dtor(&co->zo TSRMLS_CC);
spoofchecker_object_destroy(co TSRMLS_CC);
efree(co);
}
/* }}} */
/* {{{ Spoofchecker_object_create */
zend_object_value Spoofchecker_object_create(
zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
Spoofchecker_object* intern;
intern = ecalloc(1, sizeof(Spoofchecker_object));
intl_error_init(SPOOFCHECKER_ERROR_P(intern) TSRMLS_CC);
zend_object_std_init(&intern->zo, ce TSRMLS_CC);
object_properties_init(&intern->zo, ce);
retval.handle = zend_objects_store_put(
intern,
Spoofchecker_objects_dtor,
(zend_objects_free_object_storage_t)Spoofchecker_objects_free,
NULL TSRMLS_CC);
retval.handlers = &Spoofchecker_handlers;
return retval;
}
/* }}} */
/*
* 'Spoofchecker' class registration structures & functions
*/
/* {{{ Spoofchecker methods arguments info */
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_0_args, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_checks, 0, 0, 1)
ZEND_ARG_INFO(0, checks)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_allowed_locales, 0, 0, 1)
ZEND_ARG_INFO(0, locale_list)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_is_suspicous, 0, 0, 1)
ZEND_ARG_INFO(0, text)
ZEND_ARG_INFO(1, error)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(spoofchecker_are_confusable, 0, 0, 2)
ZEND_ARG_INFO(0, s1)
ZEND_ARG_INFO(0, s2)
ZEND_ARG_INFO(1, error)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ Spoofchecker_class_functions
* Every 'Spoofchecker' class method has an entry in this table
*/
zend_function_entry Spoofchecker_class_functions[] = {
PHP_ME(Spoofchecker, __construct, spoofchecker_0_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Spoofchecker, isSuspicious, spoofchecker_is_suspicous, ZEND_ACC_PUBLIC)
PHP_ME(Spoofchecker, areConfusable, spoofchecker_are_confusable, ZEND_ACC_PUBLIC)
PHP_ME(Spoofchecker, setAllowedLocales, spoofchecker_set_allowed_locales, ZEND_ACC_PUBLIC)
PHP_ME(Spoofchecker, setChecks, spoofchecker_set_checks, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
static zend_object_value spoofchecker_clone_obj(zval *object TSRMLS_DC) /* {{{ */
{
zend_object_value new_obj_val;
zend_object_handle handle = Z_OBJ_HANDLE_P(object);
Spoofchecker_object *sfo, *new_sfo;
sfo = (Spoofchecker_object *) zend_object_store_get_object(object TSRMLS_CC);
intl_error_reset(SPOOFCHECKER_ERROR_P(sfo) TSRMLS_CC);
new_obj_val = Spoofchecker_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
new_sfo = (Spoofchecker_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
/* clone standard parts */
zend_objects_clone_members(&new_sfo->zo, new_obj_val, &sfo->zo, handle TSRMLS_CC);
/* clone internal object */
new_sfo->uspoof = uspoof_clone(sfo->uspoof, SPOOFCHECKER_ERROR_CODE_P(new_sfo));
if(U_FAILURE(SPOOFCHECKER_ERROR_CODE(new_sfo))) {
/* set up error in case error handler is interested */
intl_error_set( NULL, SPOOFCHECKER_ERROR_CODE(new_sfo), "Failed to clone SpoofChecker object", 0 TSRMLS_CC );
Spoofchecker_objects_dtor(new_sfo, new_obj_val.handle TSRMLS_CC); /* free new object */
zend_error(E_ERROR, "Failed to clone SpoofChecker object");
}
return new_obj_val;
}
/* }}} */
/* {{{ spoofchecker_register_Spoofchecker_class
* Initialize 'Spoofchecker' class
*/
void spoofchecker_register_Spoofchecker_class(TSRMLS_D)
{
zend_class_entry ce;
/* Create and register 'Spoofchecker' class. */
INIT_CLASS_ENTRY(ce, "Spoofchecker", Spoofchecker_class_functions);
ce.create_object = Spoofchecker_object_create;
Spoofchecker_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
memcpy(&Spoofchecker_handlers, zend_get_std_object_handlers(),
sizeof Spoofchecker_handlers);
Spoofchecker_handlers.clone_obj = spoofchecker_clone_obj;
if (!Spoofchecker_ce_ptr) {
zend_error(E_ERROR,
"Spoofchecker: attempt to create properties "
"on a non-registered class.");
return;
}
}
/* }}} */
/* {{{ void spoofchecker_object_init( Spoofchecker_object* co )
* Initialize internals of Spoofchecker_object.
* Must be called before any other call to 'spoofchecker_object_...' functions.
*/
void spoofchecker_object_init(Spoofchecker_object* co TSRMLS_DC)
{
if (!co) {
return;
}
intl_error_init(SPOOFCHECKER_ERROR_P(co) TSRMLS_CC);
}
/* }}} */
/* {{{ void spoofchecker_object_destroy( Spoofchecker_object* co )
* Clean up mem allocted by internals of Spoofchecker_object
*/
void spoofchecker_object_destroy(Spoofchecker_object* co TSRMLS_DC)
{
if (!co) {
return;
}
if (co->uspoof) {
uspoof_close(co->uspoof);
co->uspoof = NULL;
}
intl_error_reset(SPOOFCHECKER_ERROR_P(co) TSRMLS_CC);
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
|