cvs: php4 /ext/iconv iconv.c

From: Date: Mon, 05 Aug 2002 18:26:07 +0000
Subject: cvs: php4 /ext/iconv iconv.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-13137@lists.php.net to get a copy of this message
helly Mon Aug 5 14:26:07 2002 EDT Modified files: /php4/ext/iconv iconv.c Log: -fix one warning -send Content-Type Header with charset Index: php4/ext/iconv/iconv.c diff -u php4/ext/iconv/iconv.c:1.42 php4/ext/iconv/iconv.c:1.43 --- php4/ext/iconv/iconv.c:1.42 Fri Jul 19 03:18:16 2002 +++ php4/ext/iconv/iconv.c Mon Aug 5 14:26:06 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: iconv.c,v 1.42 2002/07/19 07:18:16 derick Exp $ */ +/* $Id: iconv.c,v 1.43 2002/08/05 18:26:06 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -203,7 +203,7 @@ iconv_t cd; size_t in_left, out_size, out_left; char *out_p, *out_buf, *tmp_buf; - size_t bsz, result; + size_t bsz, result = 0; *err = 0; cd = icv_open(out_charset, in_charset); @@ -311,22 +311,37 @@ Returns str in output buffer converted to the iconv.output_encoding character set */ PHP_FUNCTION(ob_iconv_handler) { - char *out_buffer; + char *out_buffer, *content_type, *mimetype = NULL, *s; zval *zv_string; unsigned int out_len; - int err, status;; + int err, status; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &zv_string, &status) == FAILURE) return; convert_to_string_ex(&zv_string); - if (SG(sapi_headers).send_default_content_type && + if (SG(sapi_headers).mimetype && + strncmp(SG(sapi_headers).mimetype, "text/", 5) == 0) { + if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){ + mimetype = estrdup(SG(sapi_headers).mimetype); + } else { + mimetype = estrndup(SG(sapi_headers).mimetype,s-SG(sapi_headers).mimetype); + } + } else if (SG(sapi_headers).send_default_content_type) { + mimetype = estrdup(SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE); + } + if (mimetype && php_iconv_string(Z_STRVAL_P(zv_string), Z_STRLEN_P(zv_string), &out_buffer, &out_len, ICONVG(internal_encoding), ICONVG(output_encoding), &err TSRMLS_CC) == SUCCESS) { + spprintf(&content_type, 0, "Content-Type:%s;charset=%s", mimetype, ICONVG(output_encoding)); + if (content_type && sapi_add_header(content_type, strlen(content_type), 0) != FAILURE) { + SG(sapi_headers).send_default_content_type = 0; + } + efree(mimetype); RETVAL_STRINGL(out_buffer, out_len, 0); } else { zval_dtor(return_value);

« previous php.cvs (#13137) next »