version 1.1, 2012/02/21 23:47:56
|
version 1.1.1.3, 2013/07/22 01:31:52
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 112 ZEND_BEGIN_ARG_INFO(arginfo_iconv, 0)
|
Line 112 ZEND_BEGIN_ARG_INFO(arginfo_iconv, 0)
|
ZEND_ARG_INFO(0, str) |
ZEND_ARG_INFO(0, str) |
ZEND_END_ARG_INFO() |
ZEND_END_ARG_INFO() |
|
|
ZEND_BEGIN_ARG_INFO(arginfo_ob_iconv_handler, 0) |
|
ZEND_ARG_INFO(0, contents) |
|
ZEND_ARG_INFO(0, status) |
|
ZEND_END_ARG_INFO() |
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_iconv_set_encoding, 0) |
ZEND_BEGIN_ARG_INFO(arginfo_iconv_set_encoding, 0) |
ZEND_ARG_INFO(0, type) |
ZEND_ARG_INFO(0, type) |
ZEND_ARG_INFO(0, charset) |
ZEND_ARG_INFO(0, charset) |
Line 132 ZEND_END_ARG_INFO()
|
Line 127 ZEND_END_ARG_INFO()
|
*/ |
*/ |
const zend_function_entry iconv_functions[] = { |
const zend_function_entry iconv_functions[] = { |
PHP_RAW_NAMED_FE(iconv,php_if_iconv, arginfo_iconv) |
PHP_RAW_NAMED_FE(iconv,php_if_iconv, arginfo_iconv) |
PHP_FE(ob_iconv_handler, arginfo_ob_iconv_handler) |
|
PHP_FE(iconv_get_encoding, arginfo_iconv_get_encoding) |
PHP_FE(iconv_get_encoding, arginfo_iconv_get_encoding) |
PHP_FE(iconv_set_encoding, arginfo_iconv_set_encoding) |
PHP_FE(iconv_set_encoding, arginfo_iconv_set_encoding) |
PHP_FE(iconv_strlen, arginfo_iconv_strlen) |
PHP_FE(iconv_strlen, arginfo_iconv_strlen) |
Line 196 typedef enum _php_iconv_enc_scheme_t {
|
Line 190 typedef enum _php_iconv_enc_scheme_t {
|
#define PHP_ICONV_MIME_DECODE_STRICT (1<<0) |
#define PHP_ICONV_MIME_DECODE_STRICT (1<<0) |
#define PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR (1<<1) |
#define PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR (1<<1) |
|
|
/* {{{ prototypes */ | /* {{{ prototypes */ |
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd); |
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd); |
static php_iconv_err_t _php_iconv_appendc(smart_str *d, const char c, iconv_t cd); |
static php_iconv_err_t _php_iconv_appendc(smart_str *d, const char c, iconv_t cd); |
|
|
Line 214 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 208 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
|
|
static php_iconv_err_t php_iconv_stream_filter_register_factory(TSRMLS_D); |
static php_iconv_err_t php_iconv_stream_filter_register_factory(TSRMLS_D); |
static php_iconv_err_t php_iconv_stream_filter_unregister_factory(TSRMLS_D); |
static php_iconv_err_t php_iconv_stream_filter_unregister_factory(TSRMLS_D); |
|
|
|
static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC); |
|
static php_output_handler *php_iconv_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC); |
|
static int php_iconv_output_handler(void **nothing, php_output_context *output_context); |
/* }}} */ |
/* }}} */ |
|
|
/* {{{ static globals */ |
/* {{{ static globals */ |
Line 251 PHP_MINIT_FUNCTION(miconv)
|
Line 249 PHP_MINIT_FUNCTION(miconv)
|
{ |
{ |
static char buf[16]; |
static char buf[16]; |
snprintf(buf, sizeof(buf), "%d.%d", |
snprintf(buf, sizeof(buf), "%d.%d", |
((_libiconv_version >> 8) & 0x0f), (_libiconv_version & 0x0f)); | ((_libiconv_version >> 8) & 0x0f), (_libiconv_version & 0x0f)); |
version = buf; |
version = buf; |
} |
} |
#elif HAVE_GLIBC_ICONV |
#elif HAVE_GLIBC_ICONV |
Line 278 PHP_MINIT_FUNCTION(miconv)
|
Line 276 PHP_MINIT_FUNCTION(miconv)
|
return FAILURE; |
return FAILURE; |
} |
} |
|
|
|
php_output_handler_alias_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_handler_init TSRMLS_CC); |
|
php_output_handler_conflict_register(ZEND_STRL("ob_iconv_handler"), php_iconv_output_conflict TSRMLS_CC); |
|
|
return SUCCESS; |
return SUCCESS; |
} |
} |
/* }}} */ |
/* }}} */ |
Line 312 PHP_MINFO_FUNCTION(miconv)
|
Line 313 PHP_MINFO_FUNCTION(miconv)
|
} |
} |
/* }}} */ |
/* }}} */ |
|
|
|
static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len TSRMLS_DC) |
|
{ |
|
if (php_output_get_level(TSRMLS_C)) { |
|
if (php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("ob_iconv_handler") TSRMLS_CC) |
|
|| php_output_handler_conflict(handler_name, handler_name_len, ZEND_STRL("mb_output_handler") TSRMLS_CC)) { |
|
return FAILURE; |
|
} |
|
} |
|
return SUCCESS; |
|
} |
|
|
|
static php_output_handler *php_iconv_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC) |
|
{ |
|
return php_output_handler_create_internal(handler_name, handler_name_len, php_iconv_output_handler, chunk_size, flags TSRMLS_CC); |
|
} |
|
|
|
static int php_iconv_output_handler(void **nothing, php_output_context *output_context) |
|
{ |
|
char *s, *content_type, *mimetype = NULL; |
|
int output_status, mimetype_len = 0; |
|
PHP_OUTPUT_TSRMLS(output_context); |
|
|
|
if (output_context->op & PHP_OUTPUT_HANDLER_START) { |
|
output_status = php_output_get_status(TSRMLS_C); |
|
if (output_status & PHP_OUTPUT_SENT) { |
|
return FAILURE; |
|
} |
|
|
|
if (SG(sapi_headers).mimetype && !strncasecmp(SG(sapi_headers).mimetype, "text/", 5)) { |
|
if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){ |
|
mimetype = SG(sapi_headers).mimetype; |
|
} else { |
|
mimetype = SG(sapi_headers).mimetype; |
|
mimetype_len = s - SG(sapi_headers).mimetype; |
|
} |
|
} else if (SG(sapi_headers).send_default_content_type) { |
|
mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE; |
|
} |
|
|
|
if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) { |
|
int len; |
|
char *p = strstr(ICONVG(output_encoding), "//"); |
|
|
|
if (p) { |
|
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int)(p - ICONVG(output_encoding)), ICONVG(output_encoding)); |
|
} else { |
|
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, ICONVG(output_encoding)); |
|
} |
|
if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) { |
|
SG(sapi_headers).send_default_content_type = 0; |
|
php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL TSRMLS_CC); |
|
} |
|
} |
|
} |
|
|
|
if (output_context->in.used) { |
|
output_context->out.free = 1; |
|
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &output_context->out.data, &output_context->out.used, ICONVG(output_encoding), ICONVG(internal_encoding)), ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC); |
|
} |
|
|
|
return SUCCESS; |
|
} |
|
|
/* {{{ _php_iconv_appendl() */ |
/* {{{ _php_iconv_appendl() */ |
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd) |
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd) |
{ |
{ |
Line 336 static php_iconv_err_t _php_iconv_appendl(smart_str *d
|
Line 400 static php_iconv_err_t _php_iconv_appendl(smart_str *d
|
|
|
if (iconv(cd, (char **)&in_p, &in_left, (char **) &out_p, &out_left) == (size_t)-1) { |
if (iconv(cd, (char **)&in_p, &in_left, (char **) &out_p, &out_left) == (size_t)-1) { |
#if ICONV_SUPPORTS_ERRNO |
#if ICONV_SUPPORTS_ERRNO |
switch (errno) { | switch (errno) { |
case EINVAL: |
case EINVAL: |
return PHP_ICONV_ERR_ILLEGAL_CHAR; |
return PHP_ICONV_ERR_ILLEGAL_CHAR; |
|
|
Line 351 static php_iconv_err_t _php_iconv_appendl(smart_str *d
|
Line 415 static php_iconv_err_t _php_iconv_appendl(smart_str *d
|
} |
} |
#else |
#else |
if (prev_in_left == in_left) { |
if (prev_in_left == in_left) { |
return PHP_ICONV_ERR_UNKNOWN; | return PHP_ICONV_ERR_UNKNOWN; |
} |
} |
#endif |
#endif |
} |
} |
Line 382 static php_iconv_err_t _php_iconv_appendl(smart_str *d
|
Line 446 static php_iconv_err_t _php_iconv_appendl(smart_str *d
|
#else |
#else |
if (out_left != 0) { |
if (out_left != 0) { |
return PHP_ICONV_ERR_UNKNOWN; |
return PHP_ICONV_ERR_UNKNOWN; |
} | } |
#endif |
#endif |
} |
} |
(d)->len += (buf_growth - out_left); |
(d)->len += (buf_growth - out_left); |
Line 428 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
Line 492 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
in_size = in_len; |
in_size = in_len; |
|
|
cd = iconv_open(out_charset, in_charset); |
cd = iconv_open(out_charset, in_charset); |
| |
if (cd == (iconv_t)(-1)) { |
if (cd == (iconv_t)(-1)) { |
return PHP_ICONV_ERR_UNKNOWN; |
return PHP_ICONV_ERR_UNKNOWN; |
} |
} |
|
|
out_buffer = (char *) emalloc(out_size + 1); |
out_buffer = (char *) emalloc(out_size + 1); |
out_p = out_buffer; |
out_p = out_buffer; |
| |
#ifdef NETWARE |
#ifdef NETWARE |
result = iconv(cd, (char **) &in_p, &in_size, (char **) |
result = iconv(cd, (char **) &in_p, &in_size, (char **) |
#else |
#else |
result = iconv(cd, (const char **) &in_p, &in_size, (char **) |
result = iconv(cd, (const char **) &in_p, &in_size, (char **) |
#endif |
#endif |
&out_p, &out_left); |
&out_p, &out_left); |
| |
if (result == (size_t)(-1)) { |
if (result == (size_t)(-1)) { |
efree(out_buffer); |
efree(out_buffer); |
return PHP_ICONV_ERR_UNKNOWN; |
return PHP_ICONV_ERR_UNKNOWN; |
} |
} |
|
|
if (out_left < 8) { |
if (out_left < 8) { |
out_buffer = (char *) erealloc(out_buffer, out_size + 8); | size_t pos = out_p - out_buffer; |
| out_buffer = (char *) safe_erealloc(out_buffer, out_size, 1, 8); |
| out_p = out_buffer+pos; |
| out_size += 7; |
| out_left += 7; |
} |
} |
|
|
/* flush the shift-out sequences */ | /* flush the shift-out sequences */ |
result = iconv(cd, NULL, NULL, &out_p, &out_left); |
result = iconv(cd, NULL, NULL, &out_p, &out_left); |
|
|
if (result == (size_t)(-1)) { |
if (result == (size_t)(-1)) { |
Line 491 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
Line 559 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
} |
} |
} |
} |
in_left= in_len; |
in_left= in_len; |
out_left = in_len + 32; /* Avoid realloc() most cases */ | out_left = in_len + 32; /* Avoid realloc() most cases */ |
out_size = 0; |
out_size = 0; |
bsz = out_left; |
bsz = out_left; |
out_buf = (char *) emalloc(bsz+1); | out_buf = (char *) emalloc(bsz+1); |
out_p = out_buf; |
out_p = out_buf; |
|
|
while (in_left > 0) { |
while (in_left > 0) { |
Line 509 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
Line 577 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
out_p = out_buf = tmp_buf; |
out_p = out_buf = tmp_buf; |
out_p += out_size; |
out_p += out_size; |
out_left = bsz - out_size; |
out_left = bsz - out_size; |
continue; | continue; |
} |
} |
} |
} |
break; |
break; |
} |
} |
|
|
if (result != (size_t)(-1)) { |
if (result != (size_t)(-1)) { |
/* flush the shift-out sequences */ | /* flush the shift-out sequences */ |
for (;;) { |
for (;;) { |
result = iconv(cd, NULL, NULL, (char **) &out_p, &out_left); |
result = iconv(cd, NULL, NULL, (char **) &out_p, &out_left); |
out_size = bsz - out_left; |
out_size = bsz - out_left; |
Line 528 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
Line 596 PHP_ICONV_API php_iconv_err_t php_iconv_string(const c
|
if (errno == E2BIG) { |
if (errno == E2BIG) { |
bsz += 16; |
bsz += 16; |
tmp_buf = (char *) erealloc(out_buf, bsz); |
tmp_buf = (char *) erealloc(out_buf, bsz); |
| |
out_p = out_buf = tmp_buf; |
out_p = out_buf = tmp_buf; |
out_p += out_size; |
out_p += out_size; |
out_left = bsz - out_size; |
out_left = bsz - out_size; |
Line 620 static php_iconv_err_t _php_iconv_strlen(unsigned int
|
Line 688 static php_iconv_err_t _php_iconv_strlen(unsigned int
|
} |
} |
|
|
if (out_left > 0) { |
if (out_left > 0) { |
cnt -= out_left / GENERIC_SUPERSET_NBYTES; | cnt -= out_left / GENERIC_SUPERSET_NBYTES; |
} |
} |
|
|
#if ICONV_SUPPORTS_ERRNO |
#if ICONV_SUPPORTS_ERRNO |
Line 671 static php_iconv_err_t _php_iconv_substr(smart_str *pr
|
Line 739 static php_iconv_err_t _php_iconv_substr(smart_str *pr
|
|
|
unsigned int cnt; |
unsigned int cnt; |
int total_len; |
int total_len; |
| |
err = _php_iconv_strlen(&total_len, str, nbytes, enc); |
err = _php_iconv_strlen(&total_len, str, nbytes, enc); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
return err; |
return err; |
} |
} |
| |
if (len < 0) { |
if (len < 0) { |
if ((len += (total_len - offset)) < 0) { |
if ((len += (total_len - offset)) < 0) { |
return PHP_ICONV_ERR_SUCCESS; |
return PHP_ICONV_ERR_SUCCESS; |
Line 708 static php_iconv_err_t _php_iconv_substr(smart_str *pr
|
Line 776 static php_iconv_err_t _php_iconv_substr(smart_str *pr
|
smart_str_0(pretval); |
smart_str_0(pretval); |
return PHP_ICONV_ERR_SUCCESS; |
return PHP_ICONV_ERR_SUCCESS; |
} |
} |
| |
cd1 = iconv_open(GENERIC_SUPERSET_NAME, enc); |
cd1 = iconv_open(GENERIC_SUPERSET_NAME, enc); |
|
|
if (cd1 == (iconv_t)(-1)) { |
if (cd1 == (iconv_t)(-1)) { |
Line 793 static php_iconv_err_t _php_iconv_substr(smart_str *pr
|
Line 861 static php_iconv_err_t _php_iconv_substr(smart_str *pr
|
|
|
if (cd2 != (iconv_t)NULL) { |
if (cd2 != (iconv_t)NULL) { |
iconv_close(cd2); |
iconv_close(cd2); |
} | } |
return err; |
return err; |
} |
} |
|
|
Line 978 static php_iconv_err_t _php_iconv_strpos(unsigned int
|
Line 1046 static php_iconv_err_t _php_iconv_strpos(unsigned int
|
if (ndl_buf) { |
if (ndl_buf) { |
efree(ndl_buf); |
efree(ndl_buf); |
} |
} |
| |
iconv_close(cd); |
iconv_close(cd); |
|
|
return err; |
return err; |
Line 1025 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
Line 1093 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
if ((fname_nbytes + 2) >= max_line_len |
if ((fname_nbytes + 2) >= max_line_len |
|| (out_charset_len + 12) >= max_line_len) { |
|| (out_charset_len + 12) >= max_line_len) { |
/* field name is too long */ |
/* field name is too long */ |
err = PHP_ICONV_ERR_TOO_BIG; | err = PHP_ICONV_ERR_TOO_BIG; |
goto out; |
goto out; |
} |
} |
|
|
Line 1067 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
Line 1135 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
char_cnt -= 2; |
char_cnt -= 2; |
|
|
in_p = fval; |
in_p = fval; |
in_left = fval_nbytes; | in_left = fval_nbytes; |
|
|
do { |
do { |
size_t prev_in_left; |
size_t prev_in_left; |
Line 1078 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
Line 1146 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
smart_str_appendl(pretval, lfchars, lfchars_len); |
smart_str_appendl(pretval, lfchars, lfchars_len); |
smart_str_appendc(pretval, ' '); |
smart_str_appendc(pretval, ' '); |
char_cnt = max_line_len - 1; |
char_cnt = max_line_len - 1; |
} | } |
| |
smart_str_appendl(pretval, "=?", sizeof("=?") - 1); |
smart_str_appendl(pretval, "=?", sizeof("=?") - 1); |
char_cnt -= 2; |
char_cnt -= 2; |
smart_str_appendl(pretval, out_charset, out_charset_len); |
smart_str_appendl(pretval, out_charset, out_charset_len); |
Line 1231 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
Line 1299 static php_iconv_err_t _php_iconv_mime_encode(smart_st
|
goto out; |
goto out; |
} |
} |
break; |
break; |
| |
default: |
default: |
err = PHP_ICONV_ERR_UNKNOWN; |
err = PHP_ICONV_ERR_UNKNOWN; |
goto out; |
goto out; |
Line 1308 out:
|
Line 1376 out:
|
} |
} |
if (encoded != NULL) { |
if (encoded != NULL) { |
efree(encoded); |
efree(encoded); |
} | } |
if (buf != NULL) { |
if (buf != NULL) { |
efree(buf); |
efree(buf); |
} |
} |
Line 1327 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1395 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
size_t str_left; |
size_t str_left; |
unsigned int scan_stat = 0; |
unsigned int scan_stat = 0; |
const char *csname = NULL; |
const char *csname = NULL; |
size_t csname_len; | size_t csname_len; |
const char *encoded_text = NULL; |
const char *encoded_text = NULL; |
size_t encoded_text_len = 0; |
size_t encoded_text_len = 0; |
const char *encoded_word = NULL; |
const char *encoded_word = NULL; |
Line 1366 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1434 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
break; |
break; |
|
|
case '\n': |
case '\n': |
scan_stat = 8; | scan_stat = 8; |
break; |
break; |
|
|
case '=': /* first letter of an encoded chunk */ |
case '=': /* first letter of an encoded chunk */ |
Line 1391 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1459 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
|
|
case 1: /* expecting a delimiter */ |
case 1: /* expecting a delimiter */ |
if (*p1 != '?') { |
if (*p1 != '?') { |
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
goto out; |
goto out; |
} |
} |
Line 1406 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1474 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
csname = p1 + 1; |
csname = p1 + 1; |
scan_stat = 2; |
scan_stat = 2; |
break; |
break; |
| |
case 2: /* expecting a charset name */ |
case 2: /* expecting a charset name */ |
switch (*p1) { |
switch (*p1) { |
case '?': /* normal delimiter: encoding scheme follows */ |
case '?': /* normal delimiter: encoding scheme follows */ |
Line 1416 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1484 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
case '*': /* new style delimiter: locale id follows */ |
case '*': /* new style delimiter: locale id follows */ |
scan_stat = 10; |
scan_stat = 10; |
break; |
break; |
} | } |
if (scan_stat != 2) { |
if (scan_stat != 2) { |
char tmpbuf[80]; |
char tmpbuf[80]; |
|
|
Line 1429 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1497 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
|
|
if (csname_len > sizeof(tmpbuf) - 1) { |
if (csname_len > sizeof(tmpbuf) - 1) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
goto out; |
goto out; |
} |
} |
Line 1485 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1553 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
--str_left; |
--str_left; |
} |
} |
|
|
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
goto out; |
goto out; |
} |
} |
Line 1544 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1612 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
} |
} |
} |
} |
break; |
break; |
| |
case 4: /* expecting a delimiter */ |
case 4: /* expecting a delimiter */ |
if (*p1 != '?') { |
if (*p1 != '?') { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
/* pass the entire chunk through the converter */ |
/* pass the entire chunk through the converter */ |
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
goto out; |
goto out; |
} |
} |
Line 1605 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1673 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
if (*p1 != '=') { |
if (*p1 != '=') { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
/* pass the entire chunk through the converter */ |
/* pass the entire chunk through the converter */ |
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
goto out; |
goto out; |
} |
} |
Line 1632 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1700 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
switch (*p1) { |
switch (*p1) { |
default: |
default: |
/* Handle non-RFC-compliant formats |
/* Handle non-RFC-compliant formats |
* | * |
* RFC2047 requires the character that comes right |
* RFC2047 requires the character that comes right |
* after an encoded word (chunk) to be a whitespace, |
* after an encoded word (chunk) to be a whitespace, |
* while there are lots of broken implementations that |
* while there are lots of broken implementations that |
* generate such malformed headers that don't fulfill |
* generate such malformed headers that don't fulfill |
* that requirement. |
* that requirement. |
*/ | */ |
if (!eos) { | if (!eos) { |
if ((mode & PHP_ICONV_MIME_DECODE_STRICT)) { |
if ((mode & PHP_ICONV_MIME_DECODE_STRICT)) { |
/* pass the entire chunk through the converter */ |
/* pass the entire chunk through the converter */ |
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
goto out; |
goto out; |
} |
} |
Line 1674 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1742 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
if (decoded_text == NULL) { |
if (decoded_text == NULL) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
/* pass the entire chunk through the converter */ |
/* pass the entire chunk through the converter */ |
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl); |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
goto out; |
goto out; |
} |
} |
Line 1697 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1765 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) { |
/* pass the entire chunk through the converter */ |
/* pass the entire chunk through the converter */ |
err = _php_iconv_appendl(pretval, encoded_word, (size_t)(p1 - encoded_word), cd_pl); | err = _php_iconv_appendl(pretval, encoded_word, (size_t)(p1 - encoded_word), cd_pl); |
encoded_word = NULL; |
encoded_word = NULL; |
if (err != PHP_ICONV_ERR_SUCCESS) { |
if (err != PHP_ICONV_ERR_SUCCESS) { |
break; |
break; |
Line 1752 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
Line 1820 static php_iconv_err_t _php_iconv_mime_decode(smart_st
|
break; |
break; |
|
|
case '\n': |
case '\n': |
scan_stat = 8; | scan_stat = 8; |
break; |
break; |
|
|
case '=': /* first letter of an encoded chunk */ |
case '=': /* first letter of an encoded chunk */ |
Line 1892 PHP_FUNCTION(iconv_strlen)
|
Line 1960 PHP_FUNCTION(iconv_strlen)
|
char *charset = ICONVG(internal_encoding); |
char *charset = ICONVG(internal_encoding); |
int charset_len = 0; |
int charset_len = 0; |
char *str; |
char *str; |
int str_len; | int str_len; |
|
|
php_iconv_err_t err; |
php_iconv_err_t err; |
|
|
Line 1908 PHP_FUNCTION(iconv_strlen)
|
Line 1976 PHP_FUNCTION(iconv_strlen)
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
err = _php_iconv_strlen(&retval, str, str_len, charset); | err = _php_iconv_strlen(&retval, str, str_len, charset); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
if (err == PHP_ICONV_ERR_SUCCESS) { |
if (err == PHP_ICONV_ERR_SUCCESS) { |
RETVAL_LONG(retval); |
RETVAL_LONG(retval); |
Line 1925 PHP_FUNCTION(iconv_substr)
|
Line 1993 PHP_FUNCTION(iconv_substr)
|
char *charset = ICONVG(internal_encoding); |
char *charset = ICONVG(internal_encoding); |
int charset_len = 0; |
int charset_len = 0; |
char *str; |
char *str; |
int str_len; | int str_len; |
long offset, length = 0; |
long offset, length = 0; |
|
|
php_iconv_err_t err; |
php_iconv_err_t err; |
Line 1944 PHP_FUNCTION(iconv_substr)
|
Line 2012 PHP_FUNCTION(iconv_substr)
|
} |
} |
|
|
if (ZEND_NUM_ARGS() < 3) { |
if (ZEND_NUM_ARGS() < 3) { |
length = str_len; | length = str_len; |
} |
} |
|
|
err = _php_iconv_substr(&retval, str, str_len, offset, length, charset); | err = _php_iconv_substr(&retval, str, str_len, offset, length, charset); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
|
|
if (err == PHP_ICONV_ERR_SUCCESS && str != NULL && retval.c != NULL) { |
if (err == PHP_ICONV_ERR_SUCCESS && str != NULL && retval.c != NULL) { |
Line 1965 PHP_FUNCTION(iconv_strpos)
|
Line 2033 PHP_FUNCTION(iconv_strpos)
|
char *charset = ICONVG(internal_encoding); |
char *charset = ICONVG(internal_encoding); |
int charset_len = 0; |
int charset_len = 0; |
char *haystk; |
char *haystk; |
int haystk_len; | int haystk_len; |
char *ndl; |
char *ndl; |
int ndl_len; |
int ndl_len; |
long offset = 0; |
long offset = 0; |
Line 1995 PHP_FUNCTION(iconv_strpos)
|
Line 2063 PHP_FUNCTION(iconv_strpos)
|
} |
} |
|
|
err = _php_iconv_strpos(&retval, haystk, haystk_len, ndl, ndl_len, |
err = _php_iconv_strpos(&retval, haystk, haystk_len, ndl, ndl_len, |
offset, charset); | offset, charset); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
|
|
if (err == PHP_ICONV_ERR_SUCCESS && retval != (unsigned int)-1) { |
if (err == PHP_ICONV_ERR_SUCCESS && retval != (unsigned int)-1) { |
Line 2013 PHP_FUNCTION(iconv_strrpos)
|
Line 2081 PHP_FUNCTION(iconv_strrpos)
|
char *charset = ICONVG(internal_encoding); |
char *charset = ICONVG(internal_encoding); |
int charset_len = 0; |
int charset_len = 0; |
char *haystk; |
char *haystk; |
int haystk_len; | int haystk_len; |
char *ndl; |
char *ndl; |
int ndl_len; |
int ndl_len; |
|
|
Line 2037 PHP_FUNCTION(iconv_strrpos)
|
Line 2105 PHP_FUNCTION(iconv_strrpos)
|
} |
} |
|
|
err = _php_iconv_strpos(&retval, haystk, haystk_len, ndl, ndl_len, |
err = _php_iconv_strpos(&retval, haystk, haystk_len, ndl, ndl_len, |
-1, charset); | -1, charset); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
_php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset TSRMLS_CC); |
|
|
if (err == PHP_ICONV_ERR_SUCCESS && retval != (unsigned int)-1) { |
if (err == PHP_ICONV_ERR_SUCCESS && retval != (unsigned int)-1) { |
Line 2177 PHP_FUNCTION(iconv_mime_decode)
|
Line 2245 PHP_FUNCTION(iconv_mime_decode)
|
char *charset = ICONVG(internal_encoding); |
char *charset = ICONVG(internal_encoding); |
int charset_len = 0; |
int charset_len = 0; |
long mode = 0; |
long mode = 0; |
| |
smart_str retval = {0}; |
smart_str retval = {0}; |
|
|
php_iconv_err_t err; |
php_iconv_err_t err; |
Line 2218 PHP_FUNCTION(iconv_mime_decode_headers)
|
Line 2286 PHP_FUNCTION(iconv_mime_decode_headers)
|
char *charset = ICONVG(internal_encoding); |
char *charset = ICONVG(internal_encoding); |
int charset_len = 0; |
int charset_len = 0; |
long mode = 0; |
long mode = 0; |
| |
php_iconv_err_t err = PHP_ICONV_ERR_SUCCESS; |
php_iconv_err_t err = PHP_ICONV_ERR_SUCCESS; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", |
Line 2286 PHP_FUNCTION(iconv_mime_decode_headers)
|
Line 2354 PHP_FUNCTION(iconv_mime_decode_headers)
|
zend_hash_update(Z_ARRVAL_P(return_value), header_name, header_name_len, (void *)&new_elem, sizeof(new_elem), NULL); |
zend_hash_update(Z_ARRVAL_P(return_value), header_name, header_name_len, (void *)&new_elem, sizeof(new_elem), NULL); |
|
|
elem = &new_elem; |
elem = &new_elem; |
} | } |
add_next_index_stringl(*elem, header_value, header_value_len, 1); |
add_next_index_stringl(*elem, header_value, header_value_len, 1); |
} else { |
} else { |
add_assoc_stringl_ex(return_value, header_name, header_name_len, header_value, header_value_len, 1); |
add_assoc_stringl_ex(return_value, header_name, header_name_len, header_value, header_value_len, 1); |
} |
} |
} |
} |
encoded_str_len -= next_pos - encoded_str; |
encoded_str_len -= next_pos - encoded_str; |
encoded_str = next_pos; | encoded_str = next_pos; |
|
|
smart_str_free(&decoded_header); |
smart_str_free(&decoded_header); |
} |
} |
Line 2314 PHP_NAMED_FUNCTION(php_if_iconv)
|
Line 2382 PHP_NAMED_FUNCTION(php_if_iconv)
|
size_t out_len; |
size_t out_len; |
int in_charset_len = 0, out_charset_len = 0, in_buffer_len; |
int in_charset_len = 0, out_charset_len = 0, in_buffer_len; |
php_iconv_err_t err; |
php_iconv_err_t err; |
| |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", |
&in_charset, &in_charset_len, &out_charset, &out_charset_len, &in_buffer, &in_buffer_len) == FAILURE) |
&in_charset, &in_charset_len, &out_charset, &out_charset_len, &in_buffer, &in_buffer_len) == FAILURE) |
return; |
return; |
Line 2326 PHP_NAMED_FUNCTION(php_if_iconv)
|
Line 2394 PHP_NAMED_FUNCTION(php_if_iconv)
|
|
|
err = php_iconv_string(in_buffer, (size_t)in_buffer_len, |
err = php_iconv_string(in_buffer, (size_t)in_buffer_len, |
&out_buffer, &out_len, out_charset, in_charset); |
&out_buffer, &out_len, out_charset, in_charset); |
_php_iconv_show_error(err, out_charset, in_charset TSRMLS_CC); | _php_iconv_show_error(err, out_charset, in_charset TSRMLS_CC); |
if (out_buffer != NULL) { | if (err == PHP_ICONV_ERR_SUCCESS && out_buffer != NULL) { |
RETVAL_STRINGL(out_buffer, out_len, 0); |
RETVAL_STRINGL(out_buffer, out_len, 0); |
} else { |
} else { |
RETURN_FALSE; |
|
} |
|
} |
|
/* }}} */ |
|
|
|
/* {{{ proto string ob_iconv_handler(string contents, int status) |
|
Returns str in output buffer converted to the iconv.output_encoding character set */ |
|
PHP_FUNCTION(ob_iconv_handler) |
|
{ |
|
char *out_buffer, *content_type, *mimetype = NULL, *s; |
|
zval *zv_string; |
|
size_t out_len; |
|
int mimetype_alloced = 0; |
|
long status; |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &zv_string, &status) == FAILURE) |
|
return; |
|
|
|
convert_to_string(zv_string); |
|
|
|
if (SG(sapi_headers).mimetype && |
|
strncasecmp(SG(sapi_headers).mimetype, "text/", 5) == 0) { |
|
if ((s = strchr(SG(sapi_headers).mimetype,';')) == NULL){ |
|
mimetype = SG(sapi_headers).mimetype; |
|
} else { |
|
mimetype = estrndup(SG(sapi_headers).mimetype, s-SG(sapi_headers).mimetype); |
|
mimetype_alloced = 1; |
|
} |
|
} else if (SG(sapi_headers).send_default_content_type) { |
|
mimetype =(SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE); |
|
} |
|
if (mimetype != NULL) { |
|
php_iconv_err_t err = php_iconv_string(Z_STRVAL_P(zv_string), |
|
Z_STRLEN_P(zv_string), &out_buffer, &out_len, |
|
ICONVG(output_encoding), ICONVG(internal_encoding)); |
|
_php_iconv_show_error(err, ICONVG(output_encoding), ICONVG(internal_encoding) TSRMLS_CC); |
|
if (out_buffer != NULL) { |
if (out_buffer != NULL) { |
int len; | efree(out_buffer); |
char *p = strstr(ICONVG(output_encoding), "//"); | |
if (p) { | |
len = spprintf(&content_type, 0, "Content-Type:%s; charset=%.*s", mimetype, (int)(p - ICONVG(output_encoding)), ICONVG(output_encoding)); | |
} else { | |
len = spprintf(&content_type, 0, "Content-Type:%s; charset=%s", mimetype, ICONVG(output_encoding)); | |
} | |
if (content_type && sapi_add_header(content_type, len, 0) != FAILURE) { | |
SG(sapi_headers).send_default_content_type = 0; | |
} | |
if (mimetype_alloced) { | |
efree(mimetype); | |
} | |
RETURN_STRINGL(out_buffer, out_len, 0); | |
} |
} |
if (mimetype_alloced) { | RETURN_FALSE; |
efree(mimetype); | |
} | |
} |
} |
|
|
zval_dtor(return_value); |
|
*return_value = *zv_string; |
|
zval_copy_ctor(return_value); |
|
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 2521 static int php_iconv_stream_filter_append_bucket(
|
Line 2534 static int php_iconv_stream_filter_append_bucket(
|
char *pd, *pt; |
char *pd, *pt; |
size_t ocnt, prev_ocnt, icnt, tcnt; |
size_t ocnt, prev_ocnt, icnt, tcnt; |
size_t initial_out_buf_size; |
size_t initial_out_buf_size; |
| |
if (ps == NULL) { |
if (ps == NULL) { |
initial_out_buf_size = 64; |
initial_out_buf_size = 64; |
icnt = 1; |
icnt = 1; |
Line 2530 static int php_iconv_stream_filter_append_bucket(
|
Line 2543 static int php_iconv_stream_filter_append_bucket(
|
icnt = buf_len; |
icnt = buf_len; |
} |
} |
|
|
out_buf_size = ocnt = prev_ocnt = initial_out_buf_size; | out_buf_size = ocnt = prev_ocnt = initial_out_buf_size; |
if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) { |
if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) { |
return FAILURE; |
return FAILURE; |
} |
} |
Line 2817 static php_stream_filter *php_iconv_stream_filter_fact
|
Line 2830 static php_stream_filter *php_iconv_stream_filter_fact
|
pefree(inst, persistent); |
pefree(inst, persistent); |
} |
} |
|
|
return retval; | return retval; |
} |
} |
/* }}} */ |
/* }}} */ |
|
|