- simplify
authorMichael Wallner <mike@php.net>
Mon, 11 Apr 2005 06:52:08 +0000 (06:52 +0000)
committerMichael Wallner <mike@php.net>
Mon, 11 Apr 2005 06:52:08 +0000 (06:52 +0000)
http_message_api.c
php_http_message_api.h

index b89e0a89a5ec0d4c72ae7036710069defbc9d8ea..0a90f398729829867480207662eedd17eff96304 100644 (file)
@@ -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;
index b82f0a7bade7b2a18a9e452c57b43a49acc7a0fa..4de90bcd6fec13257fd9cc2dd014659c03679a03 100644 (file)
@@ -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);