hirokawa                Sat Jan 13 23:40:16 2001 EDT

  Modified files:              
    /php4/ext/iconv     iconv.c php_iconv.h 
  Log:
  added iconv_get_encoding and supported initialization from php.ini
  
Index: php4/ext/iconv/iconv.c
diff -u php4/ext/iconv/iconv.c:1.3 php4/ext/iconv/iconv.c:1.4
--- php4/ext/iconv/iconv.c:1.3  Tue Jan  9 07:53:09 2001
+++ php4/ext/iconv/iconv.c      Sat Jan 13 23:40:16 2001
@@ -18,6 +18,7 @@
  */
 
 #include "php.h"
+#include "php_config.h"
 
 #if HAVE_ICONV
 
@@ -35,6 +36,7 @@
 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 @@
 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 @@
                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 @@
        }
 
        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 @@
        }
        
 }
+/* }}} */
 
 /* {{{ 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 @@
        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
 
 
Index: php4/ext/iconv/php_iconv.h
diff -u php4/ext/iconv/php_iconv.h:1.1 php4/ext/iconv/php_iconv.h:1.2
--- php4/ext/iconv/php_iconv.h:1.1      Tue Jan  9 07:22:45 2001
+++ php4/ext/iconv/php_iconv.h  Sat Jan 13 23:40:16 2001
@@ -40,29 +40,28 @@
 
 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" 
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to