66
66
#include "ext/standard/php_image.h"
67
67
#include "ext/standard/info.h"
68
68
69
- #if defined(PHP_WIN32 ) || (HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING ))
70
- #define EXIF_USE_MBSTRING 1
71
- #else
72
- #define EXIF_USE_MBSTRING 0
73
- #endif
74
-
75
- #if EXIF_USE_MBSTRING
76
- #include "ext/mbstring/mbstring.h"
77
- #endif
78
-
79
69
/* needed for ssize_t definition */
80
70
#include <sys/types.h>
81
71
@@ -176,23 +166,19 @@ ZEND_DECLARE_MODULE_GLOBALS(exif)
176
166
177
167
ZEND_INI_MH (OnUpdateEncode )
178
168
{
179
- #if EXIF_USE_MBSTRING
180
- if (new_value && strlen (new_value ) && !php_mb_check_encoding_list (new_value TSRMLS_CC )) {
169
+ if (new_value && strlen (new_value ) && !zend_multibyte_check_encoding_list (new_value TSRMLS_CC )) {
181
170
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Illegal encoding ignored: '%s'" , new_value );
182
171
return FAILURE ;
183
172
}
184
- #endif
185
173
return OnUpdateString (entry , new_value , new_value_length , mh_arg1 , mh_arg2 , mh_arg3 , stage TSRMLS_CC );
186
174
}
187
175
188
176
ZEND_INI_MH (OnUpdateDecode )
189
177
{
190
- #if EXIF_USE_MBSTRING
191
- if (!php_mb_check_encoding_list (new_value TSRMLS_CC )) {
178
+ if (!zend_multibyte_check_encoding_list (new_value TSRMLS_CC )) {
192
179
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Illegal encoding ignored: '%s'" , new_value );
193
180
return FAILURE ;
194
181
}
195
- #endif
196
182
return OnUpdateString (entry , new_value , new_value_length , mh_arg1 , mh_arg2 , mh_arg3 , stage TSRMLS_CC );
197
183
}
198
184
@@ -224,7 +210,11 @@ static PHP_GINIT_FUNCTION(exif)
224
210
PHP_MINIT_FUNCTION (exif )
225
211
{
226
212
REGISTER_INI_ENTRIES ();
227
- REGISTER_LONG_CONSTANT ("EXIF_USE_MBSTRING" , EXIF_USE_MBSTRING , CONST_CS | CONST_PERSISTENT );
213
+ if (zend_hash_exists (& module_registry , "mbstring" , sizeof ("mbstring" ))) {
214
+ REGISTER_LONG_CONSTANT ("EXIF_USE_MBSTRING" , 1 , CONST_CS | CONST_PERSISTENT );
215
+ } else {
216
+ REGISTER_LONG_CONSTANT ("EXIF_USE_MBSTRING" , 0 , CONST_CS | CONST_PERSISTENT );
217
+ }
228
218
return SUCCESS ;
229
219
}
230
220
/* }}} */
@@ -241,9 +231,7 @@ PHP_MSHUTDOWN_FUNCTION(exif)
241
231
/* {{{ exif dependencies */
242
232
static const zend_module_dep exif_module_deps [] = {
243
233
ZEND_MOD_REQUIRED ("standard" )
244
- #if EXIF_USE_MBSTRING
245
- ZEND_MOD_REQUIRED ("mbstring" )
246
- #endif
234
+ ZEND_MOD_OPTIONAL ("mbstring" )
247
235
{NULL , NULL , NULL }
248
236
};
249
237
/* }}} */
@@ -2588,7 +2576,6 @@ static int exif_process_undefined(char **result, char *value, size_t byte_count
2588
2576
2589
2577
/* {{{ exif_process_string_raw
2590
2578
* Copy a string in Exif header to a character string returns length of allocated buffer if any. */
2591
- #if !EXIF_USE_MBSTRING
2592
2579
static int exif_process_string_raw (char * * result , char * value , size_t byte_count ) {
2593
2580
/* we cannot use strlcpy - here the problem is that we have to copy NUL
2594
2581
* chars up to byte_count, we also have to add a single NUL character to
@@ -2602,7 +2589,6 @@ static int exif_process_string_raw(char **result, char *value, size_t byte_count
2602
2589
}
2603
2590
return 0 ;
2604
2591
}
2605
- #endif
2606
2592
/* }}} */
2607
2593
2608
2594
/* {{{ exif_process_string
@@ -2629,11 +2615,8 @@ static int exif_process_string(char **result, char *value, size_t byte_count TSR
2629
2615
static int exif_process_user_comment (image_info_type * ImageInfo , char * * pszInfoPtr , char * * pszEncoding , char * szValuePtr , int ByteCount TSRMLS_DC )
2630
2616
{
2631
2617
int a ;
2632
-
2633
- #if EXIF_USE_MBSTRING
2634
2618
char * decode ;
2635
2619
size_t len ;;
2636
- #endif
2637
2620
2638
2621
* pszEncoding = NULL ;
2639
2622
/* Copy the comment */
@@ -2642,7 +2625,6 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
2642
2625
* pszEncoding = estrdup ((const char * )szValuePtr );
2643
2626
szValuePtr = szValuePtr + 8 ;
2644
2627
ByteCount -= 8 ;
2645
- #if EXIF_USE_MBSTRING
2646
2628
/* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16)
2647
2629
* since we have no encoding support for the BOM yet we skip that.
2648
2630
*/
@@ -2659,34 +2641,38 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
2659
2641
} else {
2660
2642
decode = ImageInfo -> decode_unicode_le ;
2661
2643
}
2662
- * pszInfoPtr = php_mb_convert_encoding (szValuePtr , ByteCount , ImageInfo -> encode_unicode , decode , & len TSRMLS_CC );
2644
+ if (zend_multibyte_encoding_converter (
2645
+ pszInfoPtr ,
2646
+ & len ,
2647
+ szValuePtr ,
2648
+ ByteCount ,
2649
+ ImageInfo -> encode_unicode ,
2650
+ decode
2651
+ TSRMLS_DC ) != 0 ) {
2652
+ len = exif_process_string_raw (pszInfoPtr , szValuePtr , ByteCount );
2653
+ }
2663
2654
return len ;
2664
- #else
2665
- return exif_process_string_raw (pszInfoPtr , szValuePtr , ByteCount );
2666
- #endif
2667
- } else
2668
- if (!memcmp (szValuePtr , "ASCII\0\0\0" , 8 )) {
2655
+ } else if (!memcmp (szValuePtr , "ASCII\0\0\0" , 8 )) {
2669
2656
* pszEncoding = estrdup ((const char * )szValuePtr );
2670
2657
szValuePtr = szValuePtr + 8 ;
2671
2658
ByteCount -= 8 ;
2672
- } else
2673
- if (!memcmp (szValuePtr , "JIS\0\0\0\0\0" , 8 )) {
2659
+ } else if (!memcmp (szValuePtr , "JIS\0\0\0\0\0" , 8 )) {
2674
2660
/* JIS should be tanslated to MB or we leave it to the user - leave it to the user */
2675
2661
* pszEncoding = estrdup ((const char * )szValuePtr );
2676
2662
szValuePtr = szValuePtr + 8 ;
2677
2663
ByteCount -= 8 ;
2678
- #if EXIF_USE_MBSTRING
2679
- if (ImageInfo -> motorola_intel ) {
2680
- * pszInfoPtr = php_mb_convert_encoding (szValuePtr , ByteCount , ImageInfo -> encode_jis , ImageInfo -> decode_jis_be , & len TSRMLS_CC );
2681
- } else {
2682
- * pszInfoPtr = php_mb_convert_encoding (szValuePtr , ByteCount , ImageInfo -> encode_jis , ImageInfo -> decode_jis_le , & len TSRMLS_CC );
2664
+ if (zend_multibyte_encoding_converter (
2665
+ pszInfoPtr ,
2666
+ & len ,
2667
+ szValuePtr ,
2668
+ ByteCount ,
2669
+ ImageInfo -> encode_jis ,
2670
+ ImageInfo -> motorola_intel ? ImageInfo -> decode_jis_be : ImageInfo -> decode_jis_le
2671
+ TSRMLS_DC ) != 0 ) {
2672
+ len = exif_process_string_raw (pszInfoPtr , szValuePtr , ByteCount );
2683
2673
}
2684
2674
return len ;
2685
- #else
2686
- return exif_process_string_raw (pszInfoPtr , szValuePtr , ByteCount );
2687
- #endif
2688
- } else
2689
- if (!memcmp (szValuePtr , "\0\0\0\0\0\0\0\0" , 8 )) {
2675
+ } else if (!memcmp (szValuePtr , "\0\0\0\0\0\0\0\0" , 8 )) {
2690
2676
/* 8 NULL means undefined and should be ASCII... */
2691
2677
* pszEncoding = estrdup ("UNDEFINED" );
2692
2678
szValuePtr = szValuePtr + 8 ;
@@ -2714,19 +2700,17 @@ static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_fi
2714
2700
xp_field -> tag = tag ;
2715
2701
2716
2702
/* Copy the comment */
2717
- #if EXIF_USE_MBSTRING
2718
- /* What if MS supports big-endian with XP? */
2719
- /* if (ImageInfo->motorola_intel) {
2720
- xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_be, &xp_field->size TSRMLS_CC);
2721
- } else {
2722
- xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &xp_field->size TSRMLS_CC);
2723
- }*/
2724
- xp_field -> value = php_mb_convert_encoding (szValuePtr , ByteCount , ImageInfo -> encode_unicode , ImageInfo -> decode_unicode_le , & xp_field -> size TSRMLS_CC );
2725
- return xp_field -> size ;
2726
- #else
2727
- xp_field -> size = exif_process_string_raw (& xp_field -> value , szValuePtr , ByteCount );
2703
+ if (zend_multibyte_encoding_converter (
2704
+ & xp_field -> value ,
2705
+ & xp_field -> size ,
2706
+ szValuePtr ,
2707
+ ByteCount ,
2708
+ ImageInfo -> encode_unicode ,
2709
+ ImageInfo -> motorola_intel ? ImageInfo -> decode_unicode_be : ImageInfo -> decode_unicode_le
2710
+ TSRMLS_DC ) != 0 ) {
2711
+ xp_field -> size = exif_process_string_raw (& xp_field -> value , szValuePtr , ByteCount );
2712
+ }
2728
2713
return xp_field -> size ;
2729
- #endif
2730
2714
}
2731
2715
/* }}} */
2732
2716
0 commit comments