Annotation of embedaddon/php/ext/intl/spoofchecker/spoofchecker_class.c, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>