* fix http_split_response[_ex]()
authorMichael Wallner <mike@php.net>
Sun, 6 Mar 2005 22:12:40 +0000 (22:12 +0000)
committerMichael Wallner <mike@php.net>
Sun, 6 Mar 2005 22:12:40 +0000 (22:12 +0000)
http_api.c
http_functions.c
php_http_api.h

index 2161d6d571d14f2807c022450122e174a0971e98..edeb00b34c1249f37857ca0e09487763134eeeec 100644 (file)
@@ -1388,7 +1388,7 @@ PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file,
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ proto STATUS http_chunked_decode(char *, size_t, char **, size_t *) */
+/* {{{ STATUS http_chunked_decode(char *, size_t, char **, size_t *) */
 PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded,
        const size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC)
 {
 PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded,
        const size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC)
 {
@@ -1452,28 +1452,39 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded,
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ proto STATUS http_split_response_ex(char *, size_t, zval *, zval *) */
+/* {{{ STATUS http_split_response(zval *, zval *, zval *) */
+PHP_HTTP_API STATUS _http_split_response(zval *response, zval *headers, zval *body TSRMLS_DC)
+{
+       char *b = NULL;
+       long l = 0;
+       STATUS status = http_split_response_ex(Z_STRVAL_P(response), Z_STRLEN_P(response), Z_ARRVAL_P(headers), &b, &l);
+       ZVAL_STRINGL(body, b, l, 0);
+       return status;
+}
+/* }}} */
+
+/* {{{ STATUS http_split_response(char *, size_t, HashTable *, char **, size_t *) */
 PHP_HTTP_API STATUS _http_split_response_ex(char *response,
        size_t response_len, HashTable *headers, char **body, size_t *body_len TSRMLS_DC)
 {
 PHP_HTTP_API STATUS _http_split_response_ex(char *response,
        size_t response_len, HashTable *headers, char **body, size_t *body_len TSRMLS_DC)
 {
-       char *header = response;
-       *body = NULL;
+       char *header = response, *real_body = NULL;
 
        while (0 < (response_len - (response - header + 4))) {
                if (    (*response++ == '\r') &&
                                (*response++ == '\n') &&
                                (*response++ == '\r') &&
                                (*response++ == '\n')) {
 
        while (0 < (response_len - (response - header + 4))) {
                if (    (*response++ == '\r') &&
                                (*response++ == '\n') &&
                                (*response++ == '\r') &&
                                (*response++ == '\n')) {
-                       *body = response;
+                       real_body = response;
                        break;
                }
        }
 
                        break;
                }
        }
 
-       if (*body && (*body_len = (response_len - (*body - header)))) {
-               *body = estrndup(*body, *body_len);
+       if (real_body && (*body_len = (response_len - (real_body - header)))) {
+               *body = ecalloc(1, *body_len + 1);
+               memcpy(*body, real_body, *body_len);
        }
 
        }
 
-       return http_parse_headers_ex(header, *body ? response_len - *body_len : response_len, headers, 1);
+       return http_parse_headers_ex(header, real_body ? response_len - *body_len : response_len, headers, 1);
 }
 /* }}} */
 
 }
 /* }}} */
 
index f4d32b202ef5a4313fe467a0d03db364543be8ad..2935626ecfb4eff1483540cd63d4fbc5dbc310e5 100644 (file)
@@ -598,7 +598,7 @@ PHP_FUNCTION(http_split_response)
                RETURN_FALSE;
        }
 
                RETURN_FALSE;
        }
 
-       convert_to_string_ex(&zresponse);
+       convert_to_string(zresponse);
 
        MAKE_STD_ZVAL(zbody);
        MAKE_STD_ZVAL(zheaders);
 
        MAKE_STD_ZVAL(zbody);
        MAKE_STD_ZVAL(zheaders);
@@ -608,7 +608,7 @@ PHP_FUNCTION(http_split_response)
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP response");
                RETURN_FALSE;
        }
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP response");
                RETURN_FALSE;
        }
-
+       
        array_init(return_value);
        add_index_zval(return_value, 0, zheaders);
        add_index_zval(return_value, 1, zbody);
        array_init(return_value);
        add_index_zval(return_value, 0, zheaders);
        add_index_zval(return_value, 1, zbody);
index 550f1d4e22af639d4ee4034b5b88d1362b77abbb..21cceab18dea1c155aafb0bb40ecf68ab9389d92 100644 (file)
@@ -131,7 +131,8 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, const size_t encod
 #define http_urlencode_hash_ex(h, o, p, pl, q, ql) _http_urlencode_hash_ex((h), (o), (p), (pl), (q), (ql) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, int override_argsep, char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC);
 
 #define http_urlencode_hash_ex(h, o, p, pl, q, ql) _http_urlencode_hash_ex((h), (o), (p), (pl), (q), (ql) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, int override_argsep, char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC);
 
-#define http_split_response(r, h, b) _http_split_response_ex(Z_STRVAL_P(r), Z_STRLEN_P(r), Z_ARRVAL_P(h), &Z_STRVAL_P(b), &Z_STRLEN_P(b) TSRMLS_CC)
+#define http_split_response(r, h, b) _http_split_response((r), (h), (b) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_split_response(zval *response, zval *headers, zval *body TSRMLS_DC);
 #define http_split_response_ex(r, rl, h, b, bl) _http_split_response_ex((r), (rl), (h), (b), (bl) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_split_response_ex(char *response, size_t repsonse_len, HashTable *headers, char **body, size_t *body_len TSRMLS_DC);
 
 #define http_split_response_ex(r, rl, h, b, bl) _http_split_response_ex((r), (rl), (h), (b), (bl) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_split_response_ex(char *response, size_t repsonse_len, HashTable *headers, char **body, size_t *body_len TSRMLS_DC);