moriyoshi Mon Jan 6 10:47:26 2003 EDT Modified files: /php4/ext/iconv iconv.c /php4/ext/standard quot_print.c quot_print.h Log: Moved php_quot_print_decode() to quot_print.c so that it can be used outside the iconv module Index: php4/ext/iconv/iconv.c diff -u php4/ext/iconv/iconv.c:1.79 php4/ext/iconv/iconv.c:1.80 --- php4/ext/iconv/iconv.c:1.79 Mon Jan 6 10:40:22 2003 +++ php4/ext/iconv/iconv.c Mon Jan 6 10:47:24 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: iconv.c,v 1.79 2003/01/06 15:40:22 moriyoshi Exp $ */ +/* $Id: iconv.c,v 1.80 2003/01/06 15:47:24 moriyoshi Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -52,6 +52,7 @@ #include "ext/standard/php_smart_str.h" #include "ext/standard/base64.h" +#include "ext/standard/quot_print.h" #ifdef HAVE_LIBICONV #define LIBICONV_PLUG @@ -229,75 +230,6 @@ zval_dtor(&iconv_ver); } /* }}} */ - -unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length) -{ - register unsigned int i; - register unsigned const char *p1; - register unsigned char *p2; - register unsigned int h_nbl, l_nbl; - - size_t decoded_len; - unsigned char *retval; - - static unsigned int hexval_tbl[256] = { - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 16, 16, 16, 16, 16, - 16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 - }; - - i = length, p1 = str; decoded_len = length; - - while (i > 0 && *p1 != '\0') { - if (*p1 == '=') { - decoded_len -= 2; - p1 += 2; - i -= 2; - } - p1++; - i--; - } - - retval = emalloc(decoded_len + 1); - i = length; p1 = str; p2 = retval; - - while (i > 0 && *p1 != '\0') { - if (*p1 == '=') { - if (i < 2 || - (h_nbl = hexval_tbl[p1[1]]) > 15 || - (l_nbl = hexval_tbl[p1[2]]) > 15) { - - efree(retval); - return NULL; - } - - *(p2++) = (h_nbl << 4) | l_nbl; - i -= 3; - p1 += 3; - } else { - *(p2++) = *p1; - i--; - p1++; - } - } - - *p2 = '\0'; - *ret_length = decoded_len; - return retval; -} /* {{{ _php_iconv_appendl() */ static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd) Index: php4/ext/standard/quot_print.c diff -u php4/ext/standard/quot_print.c:1.23 php4/ext/standard/quot_print.c:1.24 --- php4/ext/standard/quot_print.c:1.23 Tue Dec 31 11:07:54 2002 +++ php4/ext/standard/quot_print.c Mon Jan 6 10:47:25 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: quot_print.c,v 1.23 2002/12/31 16:07:54 sebastian Exp $ */ +/* $Id: quot_print.c,v 1.24 2003/01/06 15:47:25 moriyoshi Exp $ */ #include <stdlib.h> @@ -49,6 +49,76 @@ return -1; } } + +PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, +size_t *ret_length) +{ + register unsigned int i; + register unsigned const char *p1; + register unsigned char *p2; + register unsigned int h_nbl, l_nbl; + + size_t decoded_len; + unsigned char *retval; + + static unsigned int hexval_tbl[256] = { + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 16, 16, 16, 16, 16, + 16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 + }; + + i = length, p1 = str; decoded_len = length; + + while (i > 0 && *p1 != '\0') { + if (*p1 == '=') { + decoded_len -= 2; + p1 += 2; + i -= 2; + } + p1++; + i--; + } + + retval = emalloc(decoded_len + 1); + i = length; p1 = str; p2 = retval; + + while (i > 0 && *p1 != '\0') { + if (*p1 == '=') { + if (i < 2 || + (h_nbl = hexval_tbl[p1[1]]) > 15 || + (l_nbl = hexval_tbl[p1[2]]) > 15) { + + efree(retval); + return NULL; + } + + *(p2++) = (h_nbl << 4) | l_nbl; + i -= 3; + p1 += 3; + } else { + *(p2++) = *p1; + i--; + p1++; + } + } + + *p2 = '\0'; + *ret_length = decoded_len; + return retval; +} + /* * Index: php4/ext/standard/quot_print.h diff -u php4/ext/standard/quot_print.h:1.8 php4/ext/standard/quot_print.h:1.9 --- php4/ext/standard/quot_print.h:1.8 Tue Dec 31 11:07:54 2002 +++ php4/ext/standard/quot_print.h Mon Jan 6 10:47:25 2003 @@ -16,10 +16,12 @@ +----------------------------------------------------------------------+ */ -/* $Id: quot_print.h,v 1.8 2002/12/31 16:07:54 sebastian Exp $ */ +/* $Id: quot_print.h,v 1.9 2003/01/06 15:47:25 moriyoshi Exp $ */ #ifndef QUOT_PRINT_H #define QUOT_PRINT_H + +PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, +size_t *ret_length); PHP_FUNCTION(quoted_printable_decode);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php