cvs: php4 /ext/mbstring mbstring.c mbstring.h

From: Date: Sun, 23 Dec 2001 15:32:08 +0000
Subject: cvs: php4 /ext/mbstring mbstring.c mbstring.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-8788@lists.php.net to get a copy of this message
hirokawa Sun Dec 23 10:32:08 2001 EDT Modified files: /php4/ext/mbstring mbstring.c mbstring.h Log: @added function overload in mbstring to add multibyte support for string and mail functions. Index: php4/ext/mbstring/mbstring.c diff -u php4/ext/mbstring/mbstring.c:1.37 php4/ext/mbstring/mbstring.c:1.38 --- php4/ext/mbstring/mbstring.c:1.37 Mon Dec 17 10:30:08 2001 +++ php4/ext/mbstring/mbstring.c Sun Dec 23 10:32:08 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.c,v 1.37 2001/12/17 15:30:08 hirokawa Exp $ */ +/* $Id: mbstring.c,v 1.38 2001/12/23 15:32:08 hirokawa Exp $ */ /* * PHP4 Multibyte String module "mbstring" (currently only for Japanese) @@ -84,11 +84,20 @@ static sapi_post_entry mbstr_post_entries[] = { { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_mbstr_post_handler }, - { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, sapi_read_standard_form_data, rfc1867_post_handler }, - { NULL, 0, NULL } + { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, + { NULL, 0, NULL, NULL } }; #endif +static struct mb_overload_def mb_ovld[] = { + {MB_OVERLOAD_MAIL, "mail", "mb_send_mail", NULL}, + {MB_OVERLOAD_STRING, "strlen", "mb_strlen", NULL}, + {MB_OVERLOAD_STRING, "strpos", "mb_strpos", NULL}, + {MB_OVERLOAD_STRING, "strrpos", "mb_strrpos", NULL}, + {MB_OVERLOAD_STRING, "substr", "mb_substr", NULL}, + {0, NULL, NULL, NULL} +}; + function_entry mbstring_functions[] = { PHP_FE(mb_language, NULL) PHP_FE(mb_internal_encoding, NULL) @@ -408,7 +417,6 @@ pglobals->current_filter_illegal_mode = MBFL_OUTPUTFILTER_ILLEGAL_MODE_CHAR; pglobals->current_filter_illegal_substchar = 0x3f; /* '?' */ pglobals->func_overload = 0; - pglobals->orig_mail = (zend_function *)NULL; pglobals->outconv = NULL; } @@ -445,6 +453,8 @@ { int n, *list, *entry; zend_function *func; + struct mb_overload_def *p; + TSRMLS_FETCH(); MBSTRG(current_language) = MBSTRG(language); MBSTRG(current_internal_encoding) = MBSTRG(internal_encoding); @@ -471,17 +481,30 @@ } } - /* override original mail() function with mb_send_mail(). */ - if ((MBSTRG(func_overload) & MB_OVERLOAD_MAIL) == MB_OVERLOAD_MAIL && - !MBSTRG(orig_mail)){ - zend_hash_find(EG(function_table), "mb_send_mail", sizeof("mb_send_mail"), (void **)&func); - zend_hash_find(EG(function_table), "mail", sizeof("mail"), (void **)&MBSTRG(orig_mail)); - if (zend_hash_del(EG(function_table), "mail",sizeof("mail")) != FAILURE) { - zend_hash_add(EG(function_table), "mail",sizeof("mail"),func, sizeof(zend_function), NULL); - } else { - zend_error(E_ERROR, "mbtring couldn't replace mail()."); + /* override original function. */ + if (MBSTRG(func_overload)){ + p = &(mb_ovld[0]); + + while (p->type > 0) { + if ((MBSTRG(func_overload) & p->type) == p->type && !(p->orig)){ + if(zend_hash_find(EG(function_table), p->ovld_func, strlen(p->ovld_func)+1 , + (void **)&func) != SUCCESS) { + php_error(E_ERROR, "mbstring couldn't found function %s.", p->ovld_func); + } + + if (zend_hash_find(EG(function_table), p->orig_func, + strlen(p->orig_func)+1, (void **)&(p->orig)) != SUCCESS) { + php_error(E_ERROR, "mbstring couldn't found function %s.", p->orig_func); + } + + if (zend_hash_update(EG(function_table), p->orig_func, strlen(p->orig_func)+1, + func, sizeof(zend_function), NULL) == FAILURE){ + php_error(E_ERROR, "mbstring couldn't replace function %s.", p->orig_func); + } + } + p++; } - } + } return SUCCESS; } Index: php4/ext/mbstring/mbstring.h diff -u php4/ext/mbstring/mbstring.h:1.9 php4/ext/mbstring/mbstring.h:1.10 --- php4/ext/mbstring/mbstring.h:1.9 Sun Dec 16 17:58:24 2001 +++ php4/ext/mbstring/mbstring.h Sun Dec 23 10:32:08 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.h,v 1.9 2001/12/16 22:58:24 hirokawa Exp $ */ +/* $Id: mbstring.h,v 1.10 2001/12/23 15:32:08 hirokawa Exp $ */ /* * PHP4 Multibyte String module "mbstring" (currently only for Japanese) @@ -55,8 +55,6 @@ #include "mbfilter.h" -#define MB_OVERLOAD_MAIL 1 - extern zend_module_entry mbstring_module_entry; #define mbstring_module_ptr &mbstring_module_entry @@ -116,10 +114,18 @@ int current_filter_illegal_mode; int current_filter_illegal_substchar; int func_overload; - zend_function *orig_mail; mbfl_buffer_converter *outconv; ZEND_END_MODULE_GLOBALS(mbstring); +#define MB_OVERLOAD_MAIL 1 +#define MB_OVERLOAD_STRING 2 + +struct mb_overload_def { + int type; + char *orig_func; + char *ovld_func; + zend_function *orig; +}; #ifdef ZTS #define MBSTRG(v) TSRMG(mbstring_globals_id, zend_mbstring_globals *, v)

« previous php.cvs (#8788) next »