-correct length for ASCII

-global encoding variables
#will become ini settings explanation on what to set follows then
This commit is contained in:
Marcus Boerger 2002-04-05 17:59:29 +00:00
parent 1185a30687
commit 8a388954ea

View File

@ -122,6 +122,9 @@ PHP_MINFO_FUNCTION(exif)
} }
/* }}} */ /* }}} */
static char * exif_encoding_unicode = "ISO-8859-15";
static char * exif_encoding_jis = NULL; /* default to internal encoding */
/* {{{ PHP_MINIT_FUNCTION(exif) /* {{{ PHP_MINIT_FUNCTION(exif)
Get the size of an image as 4-element array */ Get the size of an image as 4-element array */
PHP_MINIT_FUNCTION(exif) PHP_MINIT_FUNCTION(exif)
@ -538,7 +541,7 @@ static char * exif_get_tagname(int tag_num, char *ret, int len)
/* {{{ exif_char_dump /* {{{ exif_char_dump
* Do not use! This is a debug function... */ * Do not use! This is a debug function... */
#ifdef EXIF_DEBUG //#ifdef EXIF_DEBUG
static unsigned char* exif_char_dump( unsigned char * addr, int len, int hex) static unsigned char* exif_char_dump( unsigned char * addr, int len, int hex)
{ {
static unsigned char buf[1024+1]; static unsigned char buf[1024+1];
@ -563,7 +566,7 @@ static unsigned char* exif_char_dump( unsigned char * addr, int len, int hex)
buf[sizeof(buf)-1]=0; buf[sizeof(buf)-1]=0;
return buf; return buf;
} }
#endif //#endif
/* }}} */ /* }}} */
/* {{{ php_jpg_get16 /* {{{ php_jpg_get16
@ -2003,7 +2006,7 @@ static int exif_process_string_raw(char **result,char *value,size_t byte_count)
/* {{{ exif_process_string /* {{{ exif_process_string
* Copy a string in Exif header to a character string and return length of allocated buffer if any. * Copy a string in Exif header to a character string and return length of allocated buffer if any.
* In contrast to exif_process_undefined this function does allways return a string buffer */ * In contrast to exif_process_string this function does allways return a string buffer */
static int exif_process_string(char **result,char *value,size_t byte_count) { static int exif_process_string(char **result,char *value,size_t byte_count) {
/* we cannot use strlcpy - here the problem is that we cannot use strlen to /* we cannot use strlcpy - here the problem is that we cannot use strlen to
* determin length of string and we cannot use strlcpy with len=byte_count+1 * determin length of string and we cannot use strlcpy with len=byte_count+1
@ -2026,7 +2029,7 @@ static int exif_process_string(char **result,char *value,size_t byte_count) {
/* {{{ exif_process_user_comment /* {{{ exif_process_user_comment
* Process UserComment in IFD. */ * Process UserComment in IFD. */
static int exif_process_user_comment(char **pszInfoPtr, char **szEncoding, char *szValuePtr, int ByteCount, int motorola_intel TSRMLS_DC) static int exif_process_user_comment(char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount, int motorola_intel TSRMLS_DC)
{ {
int a; int a;
@ -2034,38 +2037,45 @@ static int exif_process_user_comment(char **pszInfoPtr, char **szEncoding, char
size_t len;; size_t len;;
#endif #endif
*pszEncoding = NULL;
/* Copy the comment */ /* Copy the comment */
if ( ByteCount>=8) { if ( ByteCount>=8) {
if (!memcmp(szValuePtr, "UNICODE\0", 8)) { if (!memcmp(szValuePtr, "UNICODE\0", 8)) {
*szEncoding= estrdup((const char*)szValuePtr); *pszEncoding = estrdup((const char*)szValuePtr);
szValuePtr = szValuePtr+8; szValuePtr = szValuePtr+8;
ByteCount -= 8; ByteCount -= 8;
#ifdef HAVE_MBSTRING #ifdef HAVE_MBSTRING
if ( motorola_intel) { if ( motorola_intel) {
*pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, "ISO-8859-15", "UCS-2BE", &len TSRMLS_CC); *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, exif_encoding_unicode, "UCS-2BE", &len TSRMLS_CC);
} else { } else {
*pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, "ISO-8859-15", "UCS-2LE", &len TSRMLS_CC); *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, exif_encoding_unicode, "UCS-2LE", &len TSRMLS_CC);
} }
/*php_error(E_NOTICE,"converted(%d,%s): %s", len, *pszEncoding, *pszInfoPtr);*/
return len; return len;
#else #else
return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
#endif #endif
} else } else
if ( !memcmp(szValuePtr, "ASCII\0\0\0", 8)) { if ( !memcmp(szValuePtr, "ASCII\0\0\0", 8)) {
*szEncoding= estrdup((const char*)szValuePtr); *pszEncoding = estrdup((const char*)szValuePtr);
szValuePtr = szValuePtr+8; szValuePtr = szValuePtr+8;
ByteCount -= 8; ByteCount -= 8;
} else } else
if ( !memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) { if ( !memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) {
/* JIS should be tanslated to MB or we leave it to the user - leave it to the user */ /* JIS should be tanslated to MB or we leave it to the user - leave it to the user */
*szEncoding= estrdup((const char*)szValuePtr); *pszEncoding = estrdup((const char*)szValuePtr);
szValuePtr = szValuePtr+8; szValuePtr = szValuePtr+8;
ByteCount -= 8; ByteCount -= 8;
#ifdef HAVE_MBSTRING
*pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, exif_encoding_jis, "JIS", &len TSRMLS_CC);
return len;
#else
return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
#endif
} else } else
if ( !memcmp(szValuePtr,"\0\0\0\0\0\0\0\0",8)) { if ( !memcmp(szValuePtr,"\0\0\0\0\0\0\0\0",8)) {
/* 8 NULL means undefined and should be ASCII... */ /* 8 NULL means undefined and should be ASCII... */
*szEncoding= estrdup((const char*)szValuePtr); *pszEncoding = estrdup("UNDEFINED");
szValuePtr = szValuePtr+8; szValuePtr = szValuePtr+8;
ByteCount -= 8; ByteCount -= 8;
} }
@ -2075,7 +2085,8 @@ static int exif_process_user_comment(char **pszInfoPtr, char **szEncoding, char
if (ByteCount>0) for (a=ByteCount-1;a && szValuePtr[a]==' ';a--) (szValuePtr)[a] = '\0'; if (ByteCount>0) for (a=ByteCount-1;a && szValuePtr[a]==' ';a--) (szValuePtr)[a] = '\0';
/* normal text without encoding */ /* normal text without encoding */
return exif_process_string(pszInfoPtr, szValuePtr, ByteCount); exif_process_string(pszInfoPtr, szValuePtr, ByteCount);
return strlen(*pszInfoPtr);
} }
/* }}} */ /* }}} */