summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoriyoshi Koizumi <moriyoshi@php.net>2003-01-06 15:47:25 +0000
committerMoriyoshi Koizumi <moriyoshi@php.net>2003-01-06 15:47:25 +0000
commit4c2d6cfea8bf73b3a9cf6379833f439fdf5d574f (patch)
tree5a08651603a8be56bc5009d7fdcec82445ee3b16
parentd0570815af9e426b2b92568550e432df217d724b (diff)
downloadphp-git-4c2d6cfea8bf73b3a9cf6379833f439fdf5d574f.tar.gz
Moved php_quot_print_decode() to quot_print.c so that it can be used
outside the iconv module
-rw-r--r--ext/iconv/iconv.c70
-rw-r--r--ext/standard/quot_print.c70
-rw-r--r--ext/standard/quot_print.h2
3 files changed, 73 insertions, 69 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index acb1347a5f..0e55a2ac3c 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -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
@@ -230,75 +231,6 @@ PHP_MINFO_FUNCTION(miconv)
}
/* }}} */
-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)
{
diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c
index c57cf1fb48..b60bc517d0 100644
--- a/ext/standard/quot_print.c
+++ b/ext/standard/quot_print.c
@@ -50,6 +50,76 @@ static char php_hex2int(int c)
}
}
+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;
+}
+
+
/*
*
* Decoding Quoted-printable string.
diff --git a/ext/standard/quot_print.h b/ext/standard/quot_print.h
index d7a0087743..9ca350c6a2 100644
--- a/ext/standard/quot_print.h
+++ b/ext/standard/quot_print.h
@@ -21,6 +21,8 @@
#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);
#endif /* QUOT_PRINT_H */