]> granicus.if.org Git - php/commitdiff
@added function overload in mbstring to add multibyte support for string and mail...
authorRui Hirokawa <hirokawa@php.net>
Sun, 23 Dec 2001 15:32:08 +0000 (15:32 +0000)
committerRui Hirokawa <hirokawa@php.net>
Sun, 23 Dec 2001 15:32:08 +0000 (15:32 +0000)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.h

index cc3afabd262ef94de1d55c48f5abd9cd2fff87d0..3e2636bc73cc6026af570d9cd84693234c67e6c5 100644 (file)
@@ -84,11 +84,20 @@ SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler);
 
 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 @@ php_mbstring_init_globals(zend_mbstring_globals *pglobals)
        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 @@ PHP_RINIT_FUNCTION(mbstring)
 {
        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 @@ PHP_RINIT_FUNCTION(mbstring)
                }
        }
 
-       /* 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 56cc557d9d1eec4d0714a6f934786f5aef0e6342..0ce6024569dc34595823a062af44825a37a77ed8 100644 (file)
@@ -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 @@ ZEND_BEGIN_MODULE_GLOBALS(mbstring)
        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)