summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Hirokawa <hirokawa@php.net>2001-01-14 07:40:16 +0000
committerRui Hirokawa <hirokawa@php.net>2001-01-14 07:40:16 +0000
commitc61a557808f5c4a73c2b923bac0310440c46644f (patch)
treef67f8e6e930d04b93a08f0149a022031610e668d
parent00db616ac4a7b80f6da9dd41c2e47266f76e6065 (diff)
downloadphp-git-c61a557808f5c4a73c2b923bac0310440c46644f.tar.gz
added iconv_get_encoding and supported initialization from php.ini
-rw-r--r--ext/iconv/iconv.c86
-rw-r--r--ext/iconv/php_iconv.h21
2 files changed, 59 insertions, 48 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 072c15eb49..e1d6f51273 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -18,6 +18,7 @@
*/
#include "php.h"
+#include "php_config.h"
#if HAVE_ICONV
@@ -35,6 +36,7 @@ static int le_iconv;
function_entry iconv_functions[] = {
PHP_FE(iconv, NULL)
PHP_FE(ob_iconv_handler, NULL)
+ PHP_FE(iconv_get_encoding, NULL)
PHP_FE(iconv_set_encoding, NULL)
{NULL, NULL, NULL}
};
@@ -57,48 +59,22 @@ ZEND_GET_MODULE(iconv)
int php_iconv_string(char *, char **, char *, char *);
-static PHP_INI_MH(OnUpdateIconvOutputEncoding)
-{
- ICONVLS_FETCH();
-
- if (ICONVG(iconv_output_encoding)) {
- free(ICONVG(iconv_output_encoding));
- }
- ICONVG(iconv_output_encoding) = zend_strndup(new_value, new_value_length);
- return SUCCESS;
-}
-
-static PHP_INI_MH(OnUpdateIconvInternalEncoding)
-{
- ICONVLS_FETCH();
-
- if (ICONVG(iconv_internal_encoding)) {
- free(ICONVG(iconv_internal_encoding));
- }
- ICONVG(iconv_internal_encoding) = zend_strndup(new_value, new_value_length);
- return SUCCESS;
-}
-
-
PHP_INI_BEGIN()
- PHP_INI_ENTRY_EX("iconv.output_encoding", ICONV_OUTPUT_ENCODING, PHP_INI_SYSTEM, OnUpdateIconvOutputEncoding, NULL)
- PHP_INI_ENTRY_EX("iconv.internal_encoding", ICONV_INTERNAL_ENCODING, PHP_INI_SYSTEM, OnUpdateIconvInternalEncoding, NULL)
+ STD_PHP_INI_ENTRY("iconv.input_encoding", ICONV_INPUT_ENCODING, PHP_INI_ALL, OnUpdateString, input_encoding, zend_iconv_globals, iconv_globals)
+ STD_PHP_INI_ENTRY("iconv.output_encoding", ICONV_OUTPUT_ENCODING, PHP_INI_ALL, OnUpdateString, output_encoding, zend_iconv_globals, iconv_globals)
+ STD_PHP_INI_ENTRY("iconv.internal_encoding", ICONV_INTERNAL_ENCODING, PHP_INI_ALL, OnUpdateString, internal_encoding, zend_iconv_globals, iconv_globals)
PHP_INI_END()
PHP_MINIT_FUNCTION(iconv)
{
-/* Remove comments if you have entries in php.ini
REGISTER_INI_ENTRIES();
-*/
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(iconv)
{
-/* Remove comments if you have entries in php.ini
UNREGISTER_INI_ENTRIES();
-*/
return SUCCESS;
}
@@ -172,6 +148,7 @@ PHP_FUNCTION(iconv)
RETURN_FALSE;
}
}
+/* }}} */
/* {{{ proto string ob_iconv_handler(string contents)
Returns str in output buffer converted to the iconv.output_encoding character set */
@@ -187,8 +164,8 @@ PHP_FUNCTION(ob_iconv_handler)
}
if (php_iconv_string(Z_STRVAL_PP(zv_string), &out_buffer,
- ICONVG(iconv_internal_encoding),
- ICONVG(iconv_output_encoding))==SUCCESS) {
+ ICONVG(internal_encoding),
+ ICONVG(output_encoding))==SUCCESS) {
RETVAL_STRING(out_buffer, 0);
} else {
zval_dtor(return_value);
@@ -197,6 +174,7 @@ PHP_FUNCTION(ob_iconv_handler)
}
}
+/* }}} */
/* {{{ proto bool iconv_set_encoding(string int_charset, string out_charset)
Sets internal encoding and output encoding for ob_iconv_handler() */
@@ -212,20 +190,54 @@ PHP_FUNCTION(iconv_set_encoding)
convert_to_string_ex(int_charset);
convert_to_string_ex(out_charset);
- if (ICONVG(iconv_internal_encoding)) {
- free(ICONVG(iconv_internal_encoding));
+ if (ICONVG(internal_encoding)) {
+ free(ICONVG(internal_encoding));
}
- ICONVG(iconv_internal_encoding) = estrndup(Z_STRVAL_PP(int_charset), Z_STRLEN_PP(int_charset));
+ ICONVG(internal_encoding) = estrndup(Z_STRVAL_PP(int_charset), Z_STRLEN_PP(int_charset));
- if (ICONVG(iconv_output_encoding)) {
- free(ICONVG(iconv_output_encoding));
+ if (ICONVG(output_encoding)) {
+ free(ICONVG(output_encoding));
}
- ICONVG(iconv_output_encoding) = estrndup(Z_STRVAL_PP(out_charset),Z_STRLEN_PP(out_charset));
+ ICONVG(output_encoding) = estrndup(Z_STRVAL_PP(out_charset),Z_STRLEN_PP(out_charset));
RETURN_TRUE;
}
+/* }}} */
+
+/* {{{ proto array iconv_get_encoding([string type])
+ Get internal encoding and output encoding for ob_iconv_handler() */
+PHP_FUNCTION(iconv_get_encoding)
+{
+ zval **type;
+ int argc = ZEND_NUM_ARGS();
+ ICONVLS_FETCH();
+
+ if (argc < 0 || argc > 1 || zend_get_parameters_ex(1, &type) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_string_ex(type);
+
+ if (argc == 0 || !strcasecmp("all",Z_STRVAL_PP(type))) {
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_string(return_value, "output_encoding",
+ ICONVG(output_encoding), 1);
+ add_assoc_string(return_value, "internal_encoding",
+ ICONVG(internal_encoding), 1);
+ } else if (!strcasecmp("output_encoding",Z_STRVAL_PP(type))) {
+ RETVAL_STRING(ICONVG(output_encoding), 1);
+ } else if (!strcasecmp("internal_encoding",Z_STRVAL_PP(type))) {
+ RETVAL_STRING(ICONVG(internal_encoding), 1);
+ } else {
+ RETURN_FALSE;
+ }
+}
/* }}} */
+
+
#endif
diff --git a/ext/iconv/php_iconv.h b/ext/iconv/php_iconv.h
index 271bf74d24..7d4fb470c5 100644
--- a/ext/iconv/php_iconv.h
+++ b/ext/iconv/php_iconv.h
@@ -40,29 +40,28 @@ PHP_MINFO_FUNCTION(iconv);
PHP_FUNCTION(iconv);
PHP_FUNCTION(ob_iconv_handler);
+PHP_FUNCTION(iconv_get_encoding);
PHP_FUNCTION(iconv_set_encoding);
ZEND_BEGIN_MODULE_GLOBALS(iconv)
- char *iconv_internal_encoding;
- char *iconv_output_encoding;
- int global_variable;
+ char *input_encoding;
+ char *internal_encoding;
+ char *output_encoding;
ZEND_END_MODULE_GLOBALS(iconv)
-/* In every function that needs to use variables in php_iconv_globals,
- do call ICONVLS_FETCH(); after declaring other variables used by
- that function, and always refer to them as ICONVG(variable).
- You are encouraged to rename these macros something shorter, see
- examples in any other php module directory.
-*/
-
#ifdef ZTS
+#define ICONVLS_D zend_iconv_globals *iconv_globals
+#define ICONVLS_C iconv_globals
#define ICONVG(v) (iconv_globals->v)
-#define ICONVLS_FETCH() php_iconv_globals *iconv_globals = ts_resource(iconv_globals_id)
+#define ICONVLS_FETCH() zend_iconv_globals *iconv_globals = ts_resource(iconv_globals_id)
#else
+#define ICONVLS_D
+#define ICONVLS_C
#define ICONVG(v) (iconv_globals.v)
#define ICONVLS_FETCH()
#endif
+#define ICONV_INPUT_ENCODING "ISO-8859-1"
#define ICONV_OUTPUT_ENCODING "ISO-8859-1"
#define ICONV_INTERNAL_ENCODING "ISO-8859-1"