[php-i18n-commits] cvs commit: php4/ext/mbstring post.c config.m4 mbstring.c

Back to archive index

Tsukada ttsuk****@users*****
2002年 6月 3日 (月) 17:54:35 JST


ttsukada    02/06/03 17:54:35

  Modified:    ext/mbstring config.m4 mbstring.c
  Added:       ext/mbstring post.c
  Log:
  move MBSTR_ENC_TRANS surpport functions to post.c
  
  Revision  Changes    Path
  1.7       +1 -1      php4/ext/mbstring/config.m4
  
  Index: config.m4
  ===================================================================
  RCS file: /cvsroot/php-i18n/php4/ext/mbstring/config.m4,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- config.m4	26 May 2002 09:27:13 -0000	1.6
  +++ config.m4	3 Jun 2002 08:54:35 -0000	1.7
  @@ -36,7 +36,7 @@
       mbfl/filter_ucs.c mbfl/filter_mime.c mbfl/filter_8859.c mbfl/filter_ja.c \
       encoding.c language.c buffer.c string.c filter.c mbfunction.c \
       mbfilter_cn.c mbfilter_kr.c mbfilter_tw.c mbstring.c mbregex.c \
  -    php_mbregex.c, $ext_shared)
  +    php_mbregex.c post.c, $ext_shared)
     PHP_ADD_INCLUDE($ext_srcdir/mbfl)
   else
     PHP_MBSTR_ENC_TRANS=no
  
  
  
  1.10      +3 -268    php4/ext/mbstring/mbstring.c
  
  Index: mbstring.c
  ===================================================================
  RCS file: /cvsroot/php-i18n/php4/ext/mbstring/mbstring.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- mbstring.c	2 Jun 2002 16:30:37 -0000	1.9
  +++ mbstring.c	3 Jun 2002 08:54:35 -0000	1.10
  @@ -52,6 +52,7 @@
   #include "php.h"
   #include "php_ini.h"
   #include "php_variables.h"
  +#include "php_output.h"
   #include "mbstring.h"
   #include "php_mb.h"
   #include "ext/standard/php_string.h"
  @@ -59,13 +60,6 @@
   #include "ext/standard/url.h"
   #include "ext/standard/info.h"
   
  -#include "php_output.h"
  -#include "php_variables.h"
  -#include "php_globals.h"
  -#include "rfc1867.h"
  -#include "php_content_types.h"
  -#include "SAPI.h"
  -
   /* #undef ZEND_MULTIBYTE temporary undef for ZE2 */
   
   #ifdef ZEND_MULTIBYTE
  @@ -79,14 +73,9 @@
   #if HAVE_MBREGEX
   static unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
   #endif
  -#if defined(MBSTR_ENC_TRANS)
  -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,	NULL,	rfc1867_post_handler },
  -	{ NULL, 0, NULL, NULL }
  -};
  +#if defined(MBSTR_ENC_TRANS)
  +extern sapi_post_entry php_mbstr_post_entries[];
   #endif
   
   static struct mb_overload_def mb_ovld[] = {
  @@ -1578,261 +1567,7 @@
   }
   /* }}} */
   
  -#if defined(MBSTR_ENC_TRANS)
  -static void
  -php_mbstr_encoding_handler(zval *array_ptr, char *res, char *separator TSRMLS_DC)
  -{
  -	char *var, *val, *strtok_buf, **val_list;
  -	int n, num, val_len, *len_list, elistsz;
  -	php_mb_enc *from_encoding, **elist;
  -	php_mb_detector *identd; 
  -	php_mb_bufconv *convd;
  -
  -	/* count the variables contained in the query */
  -	num = 1;
  -	var = res;
  -	while (*var != '\0') {
  -		val = separator;
  -		while (*val != '\0') {
  -			if (*var == *val) {
  -				num++;
  -			}
  -			val++;
  -		}
  -		var++;
  -	}
  -	num *= 2;
  -	val_list = (char **)ecalloc(num, sizeof(char *));
  -	len_list = (int *)ecalloc(num, sizeof(int));
  -
  -	/* split and decode the query */
  -	n = 0;
  -	strtok_buf = NULL;
  -	var = php_strtok_r(res, separator, &strtok_buf);
  -	while (var && n < num) {
  -		val = strchr(var, '=');
  -		if (val) { /* have a value */
  -			*val++ = '\0';
  -			val_list[n] = var;
  -			len_list[n] = php_url_decode(var, strlen(var));
  -			n++;
  -			val_list[n] = val;
  -			len_list[n] = php_url_decode(val, strlen(val));
  -		} else {
  -			val_list[n] = var;
  -			len_list[n] = php_url_decode(var, strlen(var));
  -			n++;
  -			val_list[n] = empty_string;
  -			len_list[n] = 0;
  -		}
  -		n++;
  -		var = php_strtok_r(NULL, separator, &strtok_buf);
  -	}
  -	num = n;
  -
  -	/* initialize converter */
  -	convd = NULL;
  -	from_encoding = NULL;
  -	if (MBSTRG(http_input) != NULL) {
  -		elist = NULL;
  -		elistsz = 0;
  -		php_mb_parse_encoding_list(MBSTRG(http_input), &elist, &elistsz, 0  TSRMLS_CC);
  -		if (elistsz == 1 && elist[0]->id != php_mb_encid_pass) {
  -			from_encoding = elist[0];
  -		} else if (elistsz > 1) {
  -			/* auto detect */
  -			identd = php_mb_detector_create(elist, elistsz TSRMLS_CC);
  -			if (identd != NULL) {
  -				n = 0;
  -				while (n < num) {
  -					if (php_mb_detector_feed(identd, val_list[n], len_list[n]  TSRMLS_CC)) {
  -						break;
  -					}
  -					n++;
  -				}
  -				from_encoding = php_mb_detector_judge(identd TSRMLS_CC);
  -				php_mb_detector_free(identd TSRMLS_CC);
  -				if (from_encoding == NULL) {
  -					php_error(E_WARNING, "http_input_handler: Unable to detect encoding");
  -				}
  -			}
  -		} else if (MBSTRG(http_input)[0] != '\0') {
  -			php_error(E_WARNING, "http_input_handler: mbstring.http_input is invalid");
  -		}
  -		if (from_encoding != NULL) {
  -			convd = php_mb_bufconv_create(MBSTRG(internal_encoding_r), from_encoding, 0 TSRMLS_CC);
  -			if (convd == NULL) {
  -				php_mb_error();
  -			}
  -		}
  -		if (elist != NULL) {
  -			efree(elist);
  -		}
  -	}
  -
  -	if (convd != NULL) {
  -		n = 0;
  -		while (n < num) {
  -			var = NULL;
  -			val = NULL;
  -			val_len = 0;
  -			if (php_mb_bufconv_feed(convd, val_list[n], len_list[n]  TSRMLS_CC) == SUCCESS) {
  -				php_mb_bufconv_flush(convd  TSRMLS_CC);
  -				php_mb_bufconv_extract(convd, &var, NULL  TSRMLS_CC);
  -			}
  -			php_mb_bufconv_clear(convd  TSRMLS_CC);
  -			n++;
  -			if (php_mb_bufconv_feed(convd, val_list[n], len_list[n]  TSRMLS_CC) == SUCCESS) {
  -				php_mb_bufconv_flush(convd  TSRMLS_CC);
  -				php_mb_bufconv_extract(convd, &val, &val_len  TSRMLS_CC);
  -			}
  -			php_mb_bufconv_clear(convd  TSRMLS_CC);
  -			n++;
  -			/* add variable to symbol table */
  -			if (var != NULL && val != NULL) {
  -				php_register_variable_safe(var, val, val_len, array_ptr TSRMLS_CC);
  -			}
  -			if (var != NULL){
  -				efree(var);
  -			}
  -			if (val != NULL){
  -				efree(val);
  -			}
  -		}
  -	} else {
  -		n = 0;
  -		while (n < num) {
  -			var = val_list[n];
  -			n++;
  -			val = val_list[n];
  -			val_len = len_list[n];
  -			n++;
  -			/* add variable to symbol table */
  -			php_register_variable_safe(var, val, val_len, array_ptr TSRMLS_CC);
  -		}
  -	}
  -	if (from_encoding != NULL) {
  -		MBSTRG(http_input_identify) = from_encoding;
  -	} else {
  -		MBSTRG(http_input_identify) = php_mb_enc_get(php_mb_encid_pass);
  -	}
  -
  -	if (convd != NULL) {
  -		php_mb_bufconv_free(convd TSRMLS_CC);
  -	}
  -	if (val_list != NULL) {
  -		efree(val_list);
  -	}
  -	if (len_list != NULL) {
  -		efree(len_list);
  -	}
  -}
  -
  -SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler)
  -{
  -	php_mbstr_encoding_handler(arg, SG(request_info).post_data, "&" TSRMLS_CC);
  -	MBSTRG(http_input_identify_post) = MBSTRG(http_input_identify);
  -}
  -
  -/* http input processing */
  -void mbstr_treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
  -{
  -	char *res = NULL, *separator=NULL;
  -	const char *c_var;
  -	zval *array_ptr;
  -	int free_buffer=0;
  -
  -	switch (arg) {
  -		case PARSE_POST:
  -		case PARSE_GET:
  -		case PARSE_COOKIE:
  -			ALLOC_ZVAL(array_ptr);
  -			array_init(array_ptr);
  -			INIT_PZVAL(array_ptr);
  -			switch (arg) {
  -				case PARSE_POST:
  -					PG(http_globals)[TRACK_VARS_POST] = array_ptr;
  -					break;
  -				case PARSE_GET:
  -					PG(http_globals)[TRACK_VARS_GET] = array_ptr;
  -					break;
  -				case PARSE_COOKIE:
  -					PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr;
  -					break;
  -			}
  -			break;
  -		default:
  -			array_ptr=destArray;
  -			break;
  -	}
  -
  -	if (arg==PARSE_POST) { 
  -		sapi_handle_post(array_ptr TSRMLS_CC);
  -		return;
  -	}
  -
  -	if (arg == PARSE_GET) {		/* GET data */
  -		c_var = SG(request_info).query_string;
  -		if (c_var && *c_var) {
  -			res = (char *) estrdup(c_var);
  -			free_buffer = 1;
  -		} else {
  -			free_buffer = 0;
  -		}
  -	} else if (arg == PARSE_COOKIE) {		/* Cookie data */
  -		c_var = SG(request_info).cookie_data;
  -		if (c_var && *c_var) {
  -			res = (char *) estrdup(c_var);
  -			free_buffer = 1;
  -		} else {
  -			free_buffer = 0;
  -		}
  -	} else if (arg == PARSE_STRING) {		/* String data */
  -		res = str;
  -		free_buffer = 1;
  -	}
  -
  -	if (!res) {
  -		return;
  -	}
  -
  -	switch (arg) {
  -	case PARSE_POST:
  -	case PARSE_GET:
  -	case PARSE_STRING:
  -		separator = (char *) estrdup(PG(arg_separator).input);
  -		break;
  -	case PARSE_COOKIE:
  -		separator = ";\0";
  -		break;
  -	}
  -
  -	php_mbstr_encoding_handler(array_ptr, res, separator TSRMLS_CC);
  -
  -	switch(arg){
  -	case PARSE_POST:
  -		MBSTRG(http_input_identify_post) = MBSTRG(http_input_identify);
  -		break;
  -	case PARSE_GET:
  -		MBSTRG(http_input_identify_get) = MBSTRG(http_input_identify);
  -		break;
  -	case PARSE_COOKIE:
  -		MBSTRG(http_input_identify_cookie) = MBSTRG(http_input_identify);
  -		break;
  -	case PARSE_STRING:
  -		MBSTRG(http_input_identify_string) = MBSTRG(http_input_identify);
  -		break;
  -	}
  -
  -	if(arg != PARSE_COOKIE) {
  -		efree(separator);
  -	}
   
  -	if (free_buffer) {
  -		efree(res);
  -	}
  -}
  -#endif
   
   /* {{{ proto bool mb_parse_str(string encoded_string [, array result])
      Parses GET/POST/COOKIE data and sets global variables */
  
  
  
  1.1                  php4/ext/mbstring/post.c
  
  Index: post.c
  ===================================================================
  /*
     +----------------------------------------------------------------------+
     | PHP Version 4                                                        |
     +----------------------------------------------------------------------+
     | Copyright (c) 2001 The PHP Group                                     |
     +----------------------------------------------------------------------+
     | This source file is subject to version 2.02 of the PHP license,      |
     | that is bundled with this package in the file LICENSE, and is        |
     | available at through the world-wide-web at                           |
     | http://www.php.net/license/2_02.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          |
     | licen****@php***** so we can mail you a copy immediately.               |
     +----------------------------------------------------------------------+
     | Author: Rui Hirokawa <hirok****@php*****>                              |
     +----------------------------------------------------------------------+
   */
  
  /* $Id$ */
  
  #ifdef HAVE_CONFIG_H
  #include "config.h"
  #endif
  
  #include "php.h"
  #include "php_globals.h"
  #include "php_variables.h"
  #include "SAPI.h"
  #include "rfc1867.h"
  #include "php_content_types.h"
  #include "php_mb.h"
  #include "ext/standard/url.h"
  
  #if defined(MBSTR_ENC_TRANS)
  static void
  php_mbstr_encoding_handler(zval *array_ptr, char *res, char *separator TSRMLS_DC)
  {
  	char *var, *val, *strtok_buf, **val_list;
  	int n, num, val_len, *len_list, elistsz;
  	php_mb_enc *from_encoding, **elist;
  	php_mb_detector *identd; 
  	php_mb_bufconv *convd;
  
  	/* count the variables contained in the query */
  	num = 1;
  	var = res;
  	while (*var != '\0') {
  		val = separator;
  		while (*val != '\0') {
  			if (*var == *val) {
  				num++;
  			}
  			val++;
  		}
  		var++;
  	}
  	num *= 2;
  	val_list = (char **)ecalloc(num, sizeof(char *));
  	len_list = (int *)ecalloc(num, sizeof(int));
  
  	/* split and decode the query */
  	n = 0;
  	strtok_buf = NULL;
  	var = php_strtok_r(res, separator, &strtok_buf);
  	while (var && n < num) {
  		val = strchr(var, '=');
  		if (val) { /* have a value */
  			*val++ = '\0';
  			val_list[n] = var;
  			len_list[n] = php_url_decode(var, strlen(var));
  			n++;
  			val_list[n] = val;
  			len_list[n] = php_url_decode(val, strlen(val));
  		} else {
  			val_list[n] = var;
  			len_list[n] = php_url_decode(var, strlen(var));
  			n++;
  			val_list[n] = empty_string;
  			len_list[n] = 0;
  		}
  		n++;
  		var = php_strtok_r(NULL, separator, &strtok_buf);
  	}
  	num = n;
  
  	/* initialize converter */
  	convd = NULL;
  	from_encoding = NULL;
  	if (MBSTRG(http_input) != NULL) {
  		elist = NULL;
  		elistsz = 0;
  		php_mb_parse_encoding_list(MBSTRG(http_input), &elist, &elistsz, 0  TSRMLS_CC);
  		if (elistsz == 1 && elist[0]->id != php_mb_encid_pass) {
  			from_encoding = elist[0];
  		} else if (elistsz > 1) {
  			/* auto detect */
  			identd = php_mb_detector_create(elist, elistsz TSRMLS_CC);
  			if (identd != NULL) {
  				n = 0;
  				while (n < num) {
  					if (php_mb_detector_feed(identd, val_list[n], len_list[n]  TSRMLS_CC)) {
  						break;
  					}
  					n++;
  				}
  				from_encoding = php_mb_detector_judge(identd TSRMLS_CC);
  				php_mb_detector_free(identd TSRMLS_CC);
  				if (from_encoding == NULL) {
  					php_error(E_WARNING, "http_input_handler: Unable to detect encoding");
  				}
  			}
  		} else if (MBSTRG(http_input)[0] != '\0') {
  			php_error(E_WARNING, "http_input_handler: mbstring.http_input is invalid");
  		}
  		if (from_encoding != NULL) {
  			convd = php_mb_bufconv_create(MBSTRG(internal_encoding_r), from_encoding, 0 TSRMLS_CC);
  			if (convd == NULL) {
  				php_mb_error();
  			}
  		}
  		if (elist != NULL) {
  			efree(elist);
  		}
  	}
  
  	if (convd != NULL) {
  		n = 0;
  		while (n < num) {
  			var = NULL;
  			val = NULL;
  			val_len = 0;
  			if (php_mb_bufconv_feed(convd, val_list[n], len_list[n]  TSRMLS_CC) == SUCCESS) {
  				php_mb_bufconv_flush(convd  TSRMLS_CC);
  				php_mb_bufconv_extract(convd, &var, NULL  TSRMLS_CC);
  			}
  			php_mb_bufconv_clear(convd  TSRMLS_CC);
  			n++;
  			if (php_mb_bufconv_feed(convd, val_list[n], len_list[n]  TSRMLS_CC) == SUCCESS) {
  				php_mb_bufconv_flush(convd  TSRMLS_CC);
  				php_mb_bufconv_extract(convd, &val, &val_len  TSRMLS_CC);
  			}
  			php_mb_bufconv_clear(convd  TSRMLS_CC);
  			n++;
  			/* add variable to symbol table */
  			if (var != NULL && val != NULL) {
  				php_register_variable_safe(var, val, val_len, array_ptr TSRMLS_CC);
  			}
  			if (var != NULL){
  				efree(var);
  			}
  			if (val != NULL){
  				efree(val);
  			}
  		}
  	} else {
  		n = 0;
  		while (n < num) {
  			var = val_list[n];
  			n++;
  			val = val_list[n];
  			val_len = len_list[n];
  			n++;
  			/* add variable to symbol table */
  			php_register_variable_safe(var, val, val_len, array_ptr TSRMLS_CC);
  		}
  	}
  	if (from_encoding != NULL) {
  		MBSTRG(http_input_identify) = from_encoding;
  	} else {
  		MBSTRG(http_input_identify) = php_mb_enc_get(php_mb_encid_pass);
  	}
  
  	if (convd != NULL) {
  		php_mb_bufconv_free(convd TSRMLS_CC);
  	}
  	if (val_list != NULL) {
  		efree(val_list);
  	}
  	if (len_list != NULL) {
  		efree(len_list);
  	}
  }
  
  SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler)
  {
  	php_mbstr_encoding_handler(arg, SG(request_info).post_data, "&" TSRMLS_CC);
  	MBSTRG(http_input_identify_post) = MBSTRG(http_input_identify);
  }
  
  /* http input processing */
  void mbstr_treat_data(int arg, char *str, zval* destArray TSRMLS_DC)
  {
  	char *res = NULL, *separator=NULL;
  	const char *c_var;
  	zval *array_ptr;
  	int free_buffer=0;
  
  	switch (arg) {
  		case PARSE_POST:
  		case PARSE_GET:
  		case PARSE_COOKIE:
  			ALLOC_ZVAL(array_ptr);
  			array_init(array_ptr);
  			INIT_PZVAL(array_ptr);
  			switch (arg) {
  				case PARSE_POST:
  					PG(http_globals)[TRACK_VARS_POST] = array_ptr;
  					break;
  				case PARSE_GET:
  					PG(http_globals)[TRACK_VARS_GET] = array_ptr;
  					break;
  				case PARSE_COOKIE:
  					PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr;
  					break;
  			}
  			break;
  		default:
  			array_ptr=destArray;
  			break;
  	}
  
  	if (arg==PARSE_POST) { 
  		sapi_handle_post(array_ptr TSRMLS_CC);
  		return;
  	}
  
  	if (arg == PARSE_GET) {		/* GET data */
  		c_var = SG(request_info).query_string;
  		if (c_var && *c_var) {
  			res = (char *) estrdup(c_var);
  			free_buffer = 1;
  		} else {
  			free_buffer = 0;
  		}
  	} else if (arg == PARSE_COOKIE) {		/* Cookie data */
  		c_var = SG(request_info).cookie_data;
  		if (c_var && *c_var) {
  			res = (char *) estrdup(c_var);
  			free_buffer = 1;
  		} else {
  			free_buffer = 0;
  		}
  	} else if (arg == PARSE_STRING) {		/* String data */
  		res = str;
  		free_buffer = 1;
  	}
  
  	if (!res) {
  		return;
  	}
  
  	switch (arg) {
  	case PARSE_POST:
  	case PARSE_GET:
  	case PARSE_STRING:
  		separator = (char *) estrdup(PG(arg_separator).input);
  		break;
  	case PARSE_COOKIE:
  		separator = ";\0";
  		break;
  	}
  
  	php_mbstr_encoding_handler(array_ptr, res, separator TSRMLS_CC);
  
  	switch(arg){
  	case PARSE_POST:
  		MBSTRG(http_input_identify_post) = MBSTRG(http_input_identify);
  		break;
  	case PARSE_GET:
  		MBSTRG(http_input_identify_get) = MBSTRG(http_input_identify);
  		break;
  	case PARSE_COOKIE:
  		MBSTRG(http_input_identify_cookie) = MBSTRG(http_input_identify);
  		break;
  	case PARSE_STRING:
  		MBSTRG(http_input_identify_string) = MBSTRG(http_input_identify);
  		break;
  	}
  
  	if(arg != PARSE_COOKIE) {
  		efree(separator);
  	}
  
  	if (free_buffer) {
  		efree(res);
  	}
  }
  
  
  sapi_post_entry php_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,	NULL,	rfc1867_post_handler },
  	{ NULL, 0, NULL, NULL }
  };
  
  #endif
  
  /*
   * Local variables:
   * tab-width: 4
   * c-basic-offset: 4
   * End:
   */
  
  
  



php-i18n-commits メーリングリストの案内
Back to archive index