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

アーカイブの一覧に戻る

Moriyoshi Koizumi moriy****@users*****
2002年 11月 24日 (日) 02:21:07 JST


moriyoshi    02/11/24 02:21:07

  Modified:    ext/mbstring mbstring.c
  Added:       ext/mbstring mb_gpc.c mb_gpc.h
  Removed:     ext/mbstring post.c post.h
  Log:
  File renaming
  
  Revision  Changes    Path
  1.20      +1 -1      php4/ext/mbstring/mbstring.c
  
  Index: mbstring.c
  ===================================================================
  RCS file: /cvsroot/php-i18n/php4/ext/mbstring/mbstring.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- mbstring.c	7 Oct 2002 20:53:18 -0000	1.19
  +++ mbstring.c	23 Nov 2002 17:21:07 -0000	1.20
  @@ -63,7 +63,7 @@
   #include "ext/standard/php_mail.h"
   #include "ext/standard/url.h"
   #include "ext/standard/info.h"
  -#include "post.h"
  +#include "mb_gpc.h"
   
   /* #undef ZEND_MULTIBYTE temporary undef for ZE2 */
   
  
  
  
  1.1                  php4/ext/mbstring/mb_gpc.c
  
  Index: mb_gpc.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"
  #include "php_mb_function.h"
  
  #if defined(MBSTR_ENC_TRANS)
  
  #ifdef STRING_LITERAL_CONCAT_ALLOWED
  #define _legacy_php_error(etype,func,msg) \
  	php_error((etype), func ": " msg TSRMLS_CC);
  #else
  #define _legacy_php_error(etype,func,msg) { \
  	char *____tmp_buf; \
  	spprintf( &____tmp_buf, 0, "%s: %s", (func), (msg) ); \
  	if (____tmp_buf) { \
  		php_error((etype), ____tmp_buf TSRMLS_CC); \
  		efree( ____tmp_buf ); \
  	} \
  }
  #endif
  
  /* {{{ count_separators(const char *, const char *, enum mbfl_no_language, php_mb_enc *) */ 
  static int count_separators(const char *res, const char *sep, php_mb_enc *enc)
  {
  	int retval = 1;
  	size_t nbytes;
  	const char *s1, *s2;
  
  	/* the separator may contain multiple chars. */
  	s1=res;
  
  	while (*s1 != '\0') {
  		nbytes = php_mb_mbchar_bytes_ex( s1, enc );
  		if ( nbytes == 1 ) {
  			for (s2=sep; *s2 != '\0'; s2++) {
  				if (*s1 == *s2) {
  					retval++;
  					break;
  				} 
  			}
  		}
  		while ( nbytes-- > 0 && *(++s1) != '\0' );
  	}
  	return retval;
  }
  /* }}} */
  
  /* {{{ php_mbstr_encoding_handler_ex(zval *, char *, const char *, int TSRMLS_DC) */ 
  int php_mbstr_encoding_handler_ex(zval *arg, char *res, const char *separator, int force_register_globals TSRMLS_DC) 
  {
  	char *var, *val;
  	php_mb_strtok_t strtok_buf;
  	zval *array_ptr = (zval *) arg;
  	int n, num, var_len, val_len;
  	int prev_rg_state;
  
  	struct var_list_t {
  		char *var;
  		int var_len;
  		char *val;
  		int val_len;
  	} *var_list;
  
  	int elistsz;
  	php_mb_enc **elist = NULL;
  
  	php_mb_enc *from_encoding = NULL, *to_encoding = NULL;
  	php_mb_bufconv *convd = NULL;
  
  	if (!res || *res == '\0') {
  		return 0;
  	}
  
  	if ( !PHP_MB_IS_VALID_ENCODING(to_encoding = MBSTRG(internal_encoding_r))) {
  		return 0;
  	}
   
  	/* initialize converter */
  	if (MBSTRG(http_input) != NULL) {
  		if( 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 {
  				/* auto detect */
  				php_mb_detector *identd = php_mb_detector_create(elist, elistsz TSRMLS_CC);
  
  				if (identd != NULL) {
  					if (php_mb_detector_feed(identd, res, strlen(res) TSRMLS_CC)) {
  						from_encoding = php_mb_detector_judge(identd TSRMLS_CC);
  					}
  					php_mb_detector_free(identd TSRMLS_CC);
  				}
  				if (! PHP_MB_IS_VALID_ENCODING(from_encoding)) {
  					_legacy_php_error(E_WARNING, "php_mb_encoding_handler_ex", "Unable to detect encoding");
  					/* php_mb_error(); */
  				}
  			}
  			if (elist != NULL) efree(elist);
  		} else {
  			php_mb_error();
  		}
  	}
  
  	/* need space for variable name and value */
  	num = count_separators( res, separator, to_encoding );
  	
  	var_list = (struct var_list_t *)ecalloc(num, sizeof(struct var_list_t));
  
  	/* split and decode the query */
  	n = 0;
  	var = php_mb_strtok_r_ex(res, separator, &strtok_buf, from_encoding);
  	while (var)  {
  		val = strchr(var, '=');
  		if (val) { /* have a value */
  			var_len = php_url_decode(var, val-var);
  			if (var_len >= 0) {
  				var[var_len] = '\0';
  			}
  			val++;
  
  			val_len = php_url_decode(val, strlen(val));
  		} else {
  			var_len = php_url_decode(var, strlen(var));
  			
  			val = "";
  			val_len = 0;
  		}
  
  		var_list[n].var = var;
  		var_list[n].var_len = var_len;
  		var_list[n].val = val;
  		var_list[n].val_len = val_len;
  		n++; 
  
  		var = php_mb_strtok_r_ex(NULL, separator, &strtok_buf, from_encoding);
  	} 
  	num = n; /* make sure to process initilized vars only */
  	
  	convd = NULL;
  
  	/* register_globals stuff
  	 * XXX: this feature is going to be deprecated? */
  
  	if( force_register_globals ) {
  		prev_rg_state = PG(register_globals);
  		PG(register_globals) = 1;
  	}
  
  	if (PHP_MB_IS_VALID_ENCODING(from_encoding)) {
  		convd = php_mb_bufconv_create( to_encoding, from_encoding, 0 TSRMLS_CC);
  		if (convd == NULL) {
  			php_mb_error();
  			/* _legacy_php_error(E_WARNING, "php_mbstr_encoding_handler_ex", "Unable to create converter"); */
  		}
  	
  		if ( convd != NULL ) {
  			for (n = 0; n < num; n++) {
  				int var_free_me = 0, val_free_me = 0;
  
  				if ( php_mb_bufconv_feed( convd, var_list[n].var, var_list[n].var_len TSRMLS_CC ) == SUCCESS ) {
  					php_mb_bufconv_flush( convd TSRMLS_CC );
  					php_mb_bufconv_extract( convd, &var, NULL TSRMLS_CC );
  					var_free_me = 1;
  				} else {
  					var = var_list[n].var;
  				}
  				php_mb_bufconv_clear( convd TSRMLS_CC );
  
  				if ( php_mb_bufconv_feed( convd, var_list[n].val, var_list[n].val_len TSRMLS_CC ) == SUCCESS ) {
  					php_mb_bufconv_flush( convd TSRMLS_CC );
  					php_mb_bufconv_extract( convd, &val, &val_len TSRMLS_CC );
  					val_free_me = 1;
  				} else {
  					val = var_list[n].val;
  					val_len = var_list[n].val_len;
  				}
  				php_mb_bufconv_clear( convd TSRMLS_CC );
  
  				if ( var != NULL && val != NULL ) {
  					php_register_variable_safe(var, val, val_len, array_ptr TSRMLS_CC);
  				}
  				if ( var_free_me ) efree( var );
  				if ( val_free_me ) efree( val );
  			}
  		}
  		php_mb_bufconv_free( convd TSRMLS_CC );
  
  		MBSTRG(http_input_identify) = from_encoding;
  	} else {
  		for (n = 0; n < num; n++) {
  			php_register_variable_safe(var_list[n].var, var_list[n].val,
  			                           var_list[n].val_len,
  			                           array_ptr TSRMLS_CC );
  		}
  	}
  
  	/* register_global stuff */
  	if ( force_register_globals ) {
  		PG(register_globals) = prev_rg_state;
  	}
  
  	/* clean-up */
  	if (var_list != NULL) efree((void *)var_list);
  
  	return 1;
  }
  /* }}} */
  
  SAPI_POST_HANDLER_FUNC(php_mbstr_post_handler)
  {
  	MBSTRG(http_input_identify_post) = NULL;
  
  	php_mbstr_encoding_handler_ex(arg, SG(request_info).post_data, "&", 0 TSRMLS_CC);
  
  	if (PHP_MB_IS_VALID_ENCODING(MBSTRG(http_input_identify))) {
  		MBSTRG(http_input_identify_post) = MBSTRG(http_input_identify);
  	}
  }
  /* }}} */
  
  /* http input processing */
  SAPI_API SAPI_TREAT_DATA_FUNC(mbstr_treat_data)
  {
  	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_ex(array_ptr, res, separator, 0 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:
   * vim600: ts=4 fdm=marker 
   */
  
  
  
  1.1                  php4/ext/mbstring/mb_gpc.h
  
  Index: mb_gpc.h
  ===================================================================
  #ifndef _MBSTR_POST_H
  #define _MBSTR_POST_H
  
  int php_mbstr_encoding_handler_ex(zval *arg, char *res, const char *separator, int force_register_globals TSRMLS_DC);
  
  #endif /* _MBSTR_POST_H */
  
  
  
  



php-i18n-commits メーリングリストの案内
アーカイブの一覧に戻る