]> granicus.if.org Git - php/commitdiff
PHP6 updates for convert_uu(en|de)code()
authorSara Golemon <pollita@php.net>
Tue, 3 Oct 2006 19:51:35 +0000 (19:51 +0000)
committerSara Golemon <pollita@php.net>
Tue, 3 Oct 2006 19:51:35 +0000 (19:51 +0000)
ext/standard/uuencode.c

index 536ad4038bbbbe5dcb9a80d7c9fe33ba64cd20ce..7cfd4e70db73f5d81bcbce6f2e2033a9e807892d 100644 (file)
@@ -183,35 +183,60 @@ err:
        return -1;
 }
 
-/* {{{ proto string convert_uuencode(string data) 
+/* {{{ proto string convert_uuencode(string data) U
    uuencode a string */
 PHP_FUNCTION(convert_uuencode)
 {
        char *src, *dst;
        int src_len, dst_len;
+       zend_uchar src_type;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &src, &src_len) == FAILURE || src_len < 1) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &src, &src_len, &src_type) == FAILURE || src_len < 1) {
                RETURN_FALSE;
        }
 
+       if (src_type == IS_UNICODE) {
+               src = zend_unicode_to_ascii((UChar*)src, src_len TSRMLS_CC);
+               if (!src) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
+                       RETURN_FALSE;
+               }
+       }
+
        dst_len = php_uuencode(src, src_len, &dst);
+       if (src_type == IS_UNICODE) {
+               efree(src);
+       }
 
-       RETURN_STRINGL(dst, dst_len, 0);
+       RETURN_RT_STRINGL(dst, dst_len, ZSTR_AUTOFREE);
 }
 /* }}} */
 
-/* {{{ proto string convert_uudecode(string data)
+/* {{{ proto string convert_uudecode(string data) U
    decode a uuencoded string */
 PHP_FUNCTION(convert_uudecode)
 {
        char *src, *dst;
        int src_len, dst_len;
+       zend_uchar src_type;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &src, &src_len) == FAILURE || src_len < 1) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &src, &src_len, &src_type) == FAILURE || src_len < 1) {
                RETURN_FALSE;
        }
 
+       if (src_type == IS_UNICODE) {
+               src = zend_unicode_to_ascii((UChar*)src, src_len TSRMLS_CC);
+               if (!src) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
+                       RETURN_FALSE;
+               }
+       }
+
        dst_len = php_uudecode(src, src_len, &dst);
+       if (src_type == IS_UNICODE) {
+               efree(src);
+       }
+
        if (dst_len < 0) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "The given parameter is not a valid uuencoded string.");
                RETURN_FALSE;