From: Michael Wallner Date: Mon, 11 Apr 2005 06:52:08 +0000 (+0000) Subject: - simplify X-Git-Tag: RELEASE_0_8_0~91 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8e0888ae0a13ad81856a3d4672d480b7b68f687b;p=m6w6%2Fext-http - simplify --- diff --git a/http_message_api.c b/http_message_api.c index b89e0a8..0a90f39 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -32,8 +32,8 @@ PHP_HTTP_API void _http_message_dtor(http_message *message) if (message) { zend_hash_destroy(&message->hdrs); phpstr_dtor(PHPSTR(message)); - if (message->dup && message->raw.dup) { - efree(message->raw.dup); + if (message->raw) { + efree(message->raw); } if (message->type == HTTP_MSG_REQUEST) { if (message->info.request.method) { @@ -71,9 +71,9 @@ PHP_HTTP_API http_message *_http_message_init_ex(http_message *message, http_mes return message; } -PHP_HTTP_API http_message *_http_message_parse_ex(const char *message, size_t length, zend_bool dup TSRMLS_DC) +PHP_HTTP_API http_message *_http_message_parse_ex(char *message, size_t length, zend_bool dup TSRMLS_DC) { - const char *message_start = message, *body = NULL; + char *message_start = message, *body = NULL; size_t message_length = length, header_length = 0; http_message *msg; @@ -90,6 +90,9 @@ PHP_HTTP_API http_message *_http_message_parse_ex(const char *message, size_t le msg = http_message_init(); + msg->len = length; + msg->raw = dup ? estrndup(message, length) : message; + // response if (!strncmp(message, "HTTP/1.", lenof("HTTP/1."))) { msg->type = HTTP_MSG_RESPONSE; @@ -112,14 +115,6 @@ PHP_HTTP_API http_message *_http_message_parse_ex(const char *message, size_t le message_start += lenof(HTTP_CRLF); message_length -= message_start - message; - if (msg->dup = dup) { - msg->len = length; - msg->raw.dup = estrndup(message, length); - } else { - msg->len = length; - msg->raw.ptr = message; - } - if (body = strstr(message_start, HTTP_CRLF HTTP_CRLF)) { body += lenof(HTTP_CRLF HTTP_CRLF); header_length = body - message_start; diff --git a/php_http_message_api.h b/php_http_message_api.h index b82f0a7..4de90bc 100644 --- a/php_http_message_api.h +++ b/php_http_message_api.h @@ -56,12 +56,7 @@ struct _http_message { } info; size_t len; - zend_bool dup; - - union { - char *dup; - const char *ptr; - } raw; + char *raw; http_message *nested; }; @@ -81,7 +76,7 @@ PHP_HTTP_API void _http_message_free(http_message *message); #define http_message_parse(m, l) http_message_parse_ex((m), (l), 1) #define http_message_parse_ex(m, l, d) _http_message_parse_ex((m), (l), (d) TSRMLS_CC) -PHP_HTTP_API http_message *_http_message_parse_ex(const char *message, size_t length, zend_bool duplicate TSRMLS_DC); +PHP_HTTP_API http_message *_http_message_parse_ex(char *message, size_t length, zend_bool duplicate TSRMLS_DC); #define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l)) PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);