summaryrefslogtreecommitdiff
path: root/ext/standard/quot_print.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/quot_print.c')
-rw-r--r--ext/standard/quot_print.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c
index 7f54ce4d21..0738ead2fd 100644
--- a/ext/standard/quot_print.c
+++ b/ext/standard/quot_print.c
@@ -51,7 +51,7 @@ static char php_hex2int(int c) /* {{{ */
}
/* }}} */
-PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length, int replace_us_by_ws) /* {{{ */
+PHPAPI zend_string *php_quot_print_decode(const unsigned char *str, size_t length, int replace_us_by_ws) /* {{{ */
{
register unsigned int i;
register unsigned const char *p1;
@@ -59,7 +59,7 @@ PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t len
register unsigned int h_nbl, l_nbl;
size_t decoded_len, buf_size;
- unsigned char *retval;
+ zend_string *retval;
static unsigned int hexval_tbl[256] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 16, 64, 64, 16, 64, 64,
@@ -96,8 +96,8 @@ PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t len
i--;
}
- retval = emalloc(buf_size + 1);
- i = length; p1 = str; p2 = retval;
+ retval = STR_ALLOC(buf_size, 0);
+ i = length; p1 = str; p2 = (unsigned char*)retval->val;
decoded_len = 0;
while (i > 0 && *p1 != '\0') {
@@ -138,21 +138,23 @@ PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t len
}
*p2 = '\0';
- *ret_length = decoded_len;
+ retval->len = decoded_len;
return retval;
}
/* }}} */
#define PHP_QPRINT_MAXL 75
-PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t length, size_t *ret_length) /* {{{ */
+PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t length) /* {{{ */
{
unsigned long lp = 0;
- unsigned char c, *ret, *d;
+ unsigned char c, *d;
char *hex = "0123456789ABCDEF";
+ zend_string *ret;
- ret = safe_emalloc(3, length + (((3 * length)/(PHP_QPRINT_MAXL-9)) + 1), 1);
- d = ret;
+//??? ret = safe_emalloc(3, length + (((3 * length)/(PHP_QPRINT_MAXL-9)) + 1), 1);
+ ret = STR_ALLOC(3 * (length + (((3 * length)/(PHP_QPRINT_MAXL-9)) + 1)), 0);
+ d = (unsigned char*)ret->val;
while (length--) {
if (((c = *str++) == '\015') && (*str == '\012') && length > 0) {
@@ -186,9 +188,7 @@ PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t len
}
}
*d = '\0';
- *ret_length = d - ret;
-
- ret = erealloc(ret, *ret_length + 1);
+ ret = STR_EREALLOC(ret, d - (unsigned char*)ret->val);
return ret;
}
/* }}} */
@@ -202,7 +202,8 @@ PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t len
Convert a quoted-printable string to an 8 bit string */
PHP_FUNCTION(quoted_printable_decode)
{
- char *arg1, *str_in, *str_out;
+ char *arg1, *str_in;
+ zend_string *str_out;
int arg1_len, i = 0, j = 0, k;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg1, &arg1_len) == FAILURE) {
@@ -215,7 +216,7 @@ PHP_FUNCTION(quoted_printable_decode)
}
str_in = arg1;
- str_out = emalloc(arg1_len + 1);
+ str_out = STR_ALLOC(arg1_len, 0);
while (str_in[i]) {
switch (str_in[i]) {
case '=':
@@ -223,7 +224,7 @@ PHP_FUNCTION(quoted_printable_decode)
isxdigit((int) str_in[i + 1]) &&
isxdigit((int) str_in[i + 2]))
{
- str_out[j++] = (php_hex2int((int) str_in[i + 1]) << 4)
+ str_out->val[j++] = (php_hex2int((int) str_in[i + 1]) << 4)
+ php_hex2int((int) str_in[i + 2]);
i += 3;
} else /* check for soft line break according to RFC 2045*/ {
@@ -245,26 +246,27 @@ PHP_FUNCTION(quoted_printable_decode)
i += k + 1;
}
else {
- str_out[j++] = str_in[i++];
+ str_out->val[j++] = str_in[i++];
}
}
break;
default:
- str_out[j++] = str_in[i++];
+ str_out->val[j++] = str_in[i++];
}
}
- str_out[j] = '\0';
+ str_out->val[j] = '\0';
+ str_out->len = j;
- RETVAL_STRINGL(str_out, j, 0);
+ RETVAL_STR(str_out);
}
/* }}} */
/* {{{ proto string quoted_printable_encode(string str) */
PHP_FUNCTION(quoted_printable_encode)
{
- char *str, *new_str;
+ char *str;
+ zend_string *new_str;
int str_len;
- size_t new_str_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) != SUCCESS) {
return;
@@ -274,8 +276,8 @@ PHP_FUNCTION(quoted_printable_encode)
RETURN_EMPTY_STRING();
}
- new_str = (char *)php_quot_print_encode((unsigned char *)str, (size_t)str_len, &new_str_len);
- RETURN_STRINGL(new_str, new_str_len, 0);
+ new_str = php_quot_print_encode((unsigned char *)str, (size_t)str_len);
+ RETURN_STR(new_str);
}
/* }}} */