X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_api.c;h=4032f787c08cd25f01e1695f5b3cc425d16215db;hp=b5c91643e8ec438b05a59df0489f9deb8efb762e;hb=a268ede6ed45dc674906efd6fc8710012841e75e;hpb=ea31ba145c26e01b14c8aaf49ee487a118a456a8 diff --git a/http_api.c b/http_api.c index b5c9164..4032f78 100644 --- a/http_api.c +++ b/http_api.c @@ -1378,35 +1378,36 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, /* {{{ proto STATUS http_split_response_ex(char *, size_t, zval *, zval *) */ PHP_HTTP_API STATUS _http_split_response_ex(char *response, - size_t response_len, zval *zheaders, zval *zbody TSRMLS_DC) + size_t response_len, HashTable *headers, char **body, size_t *body_len TSRMLS_DC) { - char *body = NULL; char *header = response; + *body = NULL; while (0 < (response_len - (response - header + 4))) { if ( (*response++ == '\r') && (*response++ == '\n') && (*response++ == '\r') && (*response++ == '\n')) { - body = response; + *body = response; break; } } - if (body && (response_len - (body - header))) { - ZVAL_STRINGL(zbody, body, response_len - (body - header) - 1, 1); - } else { - Z_TYPE_P(zbody) = IS_NULL; + if (*body && (*body_len = response_len - (*body - header))) { + *body = estrndup(*body, *body_len - 1); } - return http_parse_headers(header, body ? body - header : response_len, zheaders); + return http_parse_headers(header, *body ? *body - header : response_len, headers); } /* }}} */ /* {{{ STATUS http_parse_headers(char *, long, zval *) */ -PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *array TSRMLS_DC) +PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, HashTable *headers TSRMLS_DC) { char *colon = NULL, *line = NULL, *begin = header; + zval array; + + Z_ARRVAL(array) = headers; if (header_len < 2) { return FAILURE; @@ -1415,7 +1416,7 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *arra /* status code */ if (!strncmp(header, "HTTP/1.", 7)) { char *end = strstr(header, HTTP_CRLF); - add_assoc_stringl(array, "Status", + add_assoc_stringl(&array, "Status", header + sizeof("HTTP/1.x ") - 1, end - (header + sizeof("HTTP/1.x ") - 1), 1); header = end + 2; @@ -1445,9 +1446,9 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *arra if (value_len < 1) { /* hm, empty header? */ - add_assoc_stringl(array, key, "", 0, 1); + add_assoc_stringl(&array, key, "", 0, 1); } else { - add_assoc_stringl(array, key, colon, value_len, 1); + add_assoc_stringl(&array, key, colon, value_len, 1); } efree(key); } @@ -1572,7 +1573,7 @@ PHP_HTTP_API STATUS _http_auth_credentials(char **user, char **pass TSRMLS_DC) #ifndef ZEND_ENGINE_2 /* {{{ php_url_encode_hash - Author: Sarah Golemon */ + Author: Sara Golemon */ PHP_HTTP_API STATUS php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, const char *num_prefix, int num_prefix_len, const char *key_prefix, int key_prefix_len,