PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/intl/spoofchecker - spoofchecker_class.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 40 50 80.0 %
Date: 2014-08-04 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:06 +0000 (23 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.