don't abuse STR_FREE; ditch http\Url::parse(); fix tests
authorMichael Wallner <mike@php.net>
Fri, 7 Nov 2014 19:37:07 +0000 (20:37 +0100)
committerMichael Wallner <mike@php.net>
Fri, 7 Nov 2014 19:37:37 +0000 (20:37 +0100)
29 files changed:
php_http_buffer.c
php_http_buffer.h
php_http_client_request.c
php_http_cookie.c
php_http_encoding.c
php_http_env.c
php_http_env_response.c
php_http_header_parser.c
php_http_info.c
php_http_message.c
php_http_message_body.c
php_http_message_parser.c
php_http_misc.c
php_http_misc.h
php_http_negotiate.c
php_http_negotiate.h
php_http_params.c
php_http_url.c
tests/url001.phpt
tests/urlparser001.phpt
tests/urlparser002.phpt
tests/urlparser003.phpt
tests/urlparser004.phpt
tests/urlparser005.phpt
tests/urlparser006.phpt
tests/urlparser007.phpt
tests/urlparser008.phpt
tests/urlparser009.phpt
tests/urlparser010.phpt

index 8ccee0847584b0e4f678596105ccfee8a5915251..6636e2c7dcfecd39a7e8b18bbdc45f00e1bd9e0e 100644 (file)
@@ -229,7 +229,7 @@ PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s,
 
        while ((got = php_http_buffer_chunk_buffer(s, data, data_len, &chunk, chunk_len))) {
                if (PHP_HTTP_BUFFER_PASS0 == passout(opaque, chunk, got TSRMLS_CC)) {
-                       STR_SET(chunk, NULL);
+                       PTR_SET(chunk, NULL);
                        return PHP_HTTP_BUFFER_PASS0;
                }
                ++passed;
@@ -240,9 +240,9 @@ PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s,
                }
                data = NULL;
                data_len = 0;
-               STR_SET(chunk, NULL);
+               PTR_SET(chunk, NULL);
        }
-       STR_FREE(chunk);
+       PTR_FREE(chunk);
        return passed;
 }
 
index cf9b45863b7af0f2752680be22a9c21b51257bf3..faf8992107675be7b39f744fc0ae069f9326a410 100644 (file)
 #define PHP_HTTP_BUFFER_NOMEM PHP_HTTP_BUFFER_ERROR
 #define PHP_HTTP_BUFFER_PASS0 PHP_HTTP_BUFFER_ERROR
 
-#ifndef STR_FREE
-#      define STR_FREE(STR) \
+#ifndef PTR_FREE
+#      define PTR_FREE(PTR) \
        { \
-               if (STR) { \
-                       efree(STR); \
+               if (PTR) { \
+                       efree(PTR); \
                } \
        }
 #endif
-#ifndef STR_SET
-#      define STR_SET(STR, SET) \
+#ifndef PTR_SET
+#      define PTR_SET(PTR, SET) \
        { \
-               STR_FREE(STR); \
-               STR = SET; \
+               PTR_FREE(PTR); \
+               PTR = SET; \
        }
 #endif
 #ifndef TSRMLS_D
index eaf71da9847f6f71b7f7166a40b282334c5fdd09..0e40cc5bc930778620321479e570da865b4686ac 100644 (file)
@@ -151,7 +151,7 @@ static PHP_METHOD(HttpClientRequest, setQuery)
                php_http_url_free(&old_url);
        }
        if (new_url.query != &empty[0]) {
-               STR_FREE(new_url.query);
+               PTR_FREE(new_url.query);
        }
 
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -208,7 +208,7 @@ static PHP_METHOD(HttpClientRequest, addQuery)
        if (old_url) {
                php_http_url_free(&old_url);
        }
-       STR_FREE(new_url.query);
+       PTR_FREE(new_url.query);
 
        RETVAL_ZVAL(getThis(), 1, 0);
 }
index 4bd8d80224606f7464a4470250da56d2eb1c07e1..354dfa6ed4f0315aa8dbb0e43fb4062281351316 100644 (file)
@@ -41,8 +41,8 @@ php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from,
        array_copy(&from->cookies, &to->cookies);
        array_copy(&from->extras, &to->extras);
 
-       STR_SET(to->path, from->path ? estrdup(from->path) : NULL);
-       STR_SET(to->domain, from->domain ? estrdup(from->domain) : NULL);
+       PTR_SET(to->path, from->path ? estrdup(from->path) : NULL);
+       PTR_SET(to->domain, from->domain ? estrdup(from->domain) : NULL);
        to->expires = from->expires;
        to->max_age = from->max_age;
        to->flags = from->flags;
@@ -56,8 +56,8 @@ void php_http_cookie_list_dtor(php_http_cookie_list_t *list)
                zend_hash_destroy(&list->cookies);
                zend_hash_destroy(&list->extras);
        
-               STR_SET(list->path, NULL);
-               STR_SET(list->domain, NULL);
+               PTR_SET(list->path, NULL);
+               PTR_SET(list->domain, NULL);
        }
 }
 
@@ -125,9 +125,9 @@ static void add_entry(php_http_cookie_list_t *list, char **allowed_extras, long
        }
 
        if _KEY_IS("path") {
-               STR_SET(list->path, estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg)));
+               PTR_SET(list->path, estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg)));
        } else if _KEY_IS("domain") {
-               STR_SET(list->domain, estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg)));
+               PTR_SET(list->domain, estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg)));
        } else if _KEY_IS("expires") {
                char *date = estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg));
                list->expires = php_parse_date(date, NULL);
@@ -782,7 +782,7 @@ static PHP_METHOD(HttpCookie, setDomain)
 
        PHP_HTTP_COOKIE_OBJECT_INIT(obj);
 
-       STR_SET(obj->list->domain, domain_str ? estrndup(domain_str, domain_len) : NULL);
+       PTR_SET(obj->list->domain, domain_str ? estrndup(domain_str, domain_len) : NULL);
 
        RETVAL_ZVAL(getThis(), 1, 0);
 }
@@ -821,7 +821,7 @@ static PHP_METHOD(HttpCookie, setPath)
 
        PHP_HTTP_COOKIE_OBJECT_INIT(obj);
 
-       STR_SET(obj->list->path, path_str ? estrndup(path_str, path_len) : NULL);
+       PTR_SET(obj->list->path, path_str ? estrndup(path_str, path_len) : NULL);
 
        RETVAL_ZVAL(getThis(), 1, 0);
 }
index 7f0462c78c1c5537e7ee2438fb74d2999836f368..b7050f6d769e737984bcddee1fd45996c0c3d179 100644 (file)
@@ -180,7 +180,7 @@ STATUS php_http_encoding_deflate(int flags, const char *data, size_t data_len, c
                        (*encoded)[*encoded_len = Z.total_out] = '\0';
                        return SUCCESS;
                } else {
-                       STR_SET(*encoded, NULL);
+                       PTR_SET(*encoded, NULL);
                        *encoded_len = 0;
                }
        }
@@ -513,7 +513,7 @@ static STATUS deflate_update(php_http_encoding_stream_t *s, const char *data, si
                        return SUCCESS;
        }
        
-       STR_SET(*encoded, NULL);
+       PTR_SET(*encoded, NULL);
        *encoded_len = 0;
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to update deflate stream: %s", zError(status));
        return FAILURE;
@@ -709,7 +709,7 @@ static STATUS deflate_flush(php_http_encoding_stream_t *s, char **encoded, size_
                        return SUCCESS;
        }
        
-       STR_SET(*encoded, NULL);
+       PTR_SET(*encoded, NULL);
        *encoded_len = 0;
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to flush deflate stream: %s", zError(status));
        return FAILURE;
@@ -766,7 +766,7 @@ static STATUS deflate_finish(php_http_encoding_stream_t *s, char **encoded, size
                return SUCCESS;
        }
        
-       STR_SET(*encoded, NULL);
+       PTR_SET(*encoded, NULL);
        *encoded_len = 0;
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish deflate stream: %s", zError(status));
        return FAILURE;
@@ -805,7 +805,7 @@ static STATUS inflate_finish(php_http_encoding_stream_t *s, char **decoded, size
                return SUCCESS;
        }
        
-       STR_SET(*decoded, NULL);
+       PTR_SET(*decoded, NULL);
        *decoded_len = 0;
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish inflate stream: %s", zError(status));
        return FAILURE;
@@ -1071,7 +1071,7 @@ static PHP_METHOD(HttpEncodingStream, finish)
                                                RETURN_EMPTY_STRING();
                                        }
                                } else {
-                                       STR_FREE(encoded_str);
+                                       PTR_FREE(encoded_str);
                                }
                        }
                }
index 2969d1a4fbe5b19bb0e5daf354e022ccabd948e2..25759a65e83c5da71bd866a876471d8ecc9c5de6 100644 (file)
@@ -70,7 +70,7 @@ PHP_RINIT_FUNCTION(http_env)
                }
        }
 
-       STR_SET(SG(request_info).content_type_dup, NULL);
+       PTR_SET(SG(request_info).content_type_dup, NULL);
 
        return SUCCESS;
 }
@@ -287,7 +287,7 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
                return PHP_HTTP_RANGE_NO;
        }
        if (strncmp(range, "bytes=", lenof("bytes="))) {
-               STR_FREE(range);
+               PTR_FREE(range);
                return PHP_HTTP_RANGE_NO;
        }
 
@@ -343,7 +343,7 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
                                                        switch (end) {
                                                                /* "0-" */
                                                                case -1:
-                                                                       STR_FREE(range);
+                                                                       PTR_FREE(range);
                                                                        return PHP_HTTP_RANGE_NO;
 
                                                                /* "0-0" */
@@ -364,7 +364,7 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
                                                case -1:
                                                        /* "-", "-0" */
                                                        if (end == -1 || end == -10) {
-                                                               STR_FREE(range);
+                                                               PTR_FREE(range);
                                                                return PHP_HTTP_RANGE_ERR;
                                                        }
                                                        begin = length - end;
@@ -374,13 +374,13 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
                                                /* "12345-(NNN)" */
                                                default:
                                                        if (length <= (size_t) begin) {
-                                                               STR_FREE(range);
+                                                               PTR_FREE(range);
                                                                return PHP_HTTP_RANGE_ERR;
                                                        }
                                                        switch (end) {
                                                                /* "12345-0" */
                                                                case -10:
-                                                                       STR_FREE(range);
+                                                                       PTR_FREE(range);
                                                                        return PHP_HTTP_RANGE_ERR;
 
                                                                /* "12345-" */
@@ -393,7 +393,7 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
                                                                        if (length <= (size_t) end) {
                                                                                end = length - 1;
                                                                        } else if (end <  begin) {
-                                                                               STR_FREE(range);
+                                                                               PTR_FREE(range);
                                                                                return PHP_HTTP_RANGE_ERR;
                                                                        }
                                                                        break;
@@ -415,12 +415,12 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
                                break;
 
                        default:
-                               STR_FREE(range);
+                               PTR_FREE(range);
                                return PHP_HTTP_RANGE_NO;
                }
        } while (c != 0);
 
-       STR_FREE(range);
+       PTR_FREE(range);
        return PHP_HTTP_RANGE_OK;
 }
 
@@ -573,7 +573,7 @@ STATUS php_http_env_set_response_header_value(long http_code, const char *name_s
                        ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
 
                        zval_ptr_dtor(&data);
-                       STR_FREE(h.line);
+                       PTR_FREE(h.line);
 
                        return ret;
                }
@@ -977,7 +977,7 @@ static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler)
                }
        }
 #if PHP_VERSION_ID >= 50600
-       STR_FREE(json_str);
+       PTR_FREE(json_str);
 #endif
 }
 
index 13a35c6af7054803de8760f6cc688ee2745ab954..83ebc6b64d7f7c893f118db997ba525ef505dfe5 100644 (file)
@@ -147,7 +147,7 @@ php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, c
                efree(etag);
        }
 
-       STR_FREE(header);
+       PTR_FREE(header);
        return ret;
 }
 
@@ -190,7 +190,7 @@ php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *o
                }
        }
 
-       STR_FREE(header);
+       PTR_FREE(header);
        return ret;
 }
 
@@ -254,7 +254,7 @@ static STATUS php_http_env_response_send_data(php_http_env_response_t *r, const
                        return SUCCESS;
                }
                chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
-               STR_FREE(enc_str);
+               PTR_FREE(enc_str);
        } else {
                chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
        }
@@ -303,8 +303,8 @@ void php_http_env_response_dtor(php_http_env_response_t *r)
        }
        php_http_buffer_free(&r->buffer);
        zval_ptr_dtor(&r->options);
-       STR_FREE(r->content.type);
-       STR_FREE(r->content.encoding);
+       PTR_FREE(r->content.type);
+       PTR_FREE(r->content.encoding);
        if (r->content.encoder) {
                php_http_encoding_stream_free(&r->content.encoder);
        }
index 2526835f90cf929cd096515ccdb050305112e8b6..df0837df2727430de080869760daa65f4f7b8969 100644 (file)
@@ -79,8 +79,8 @@ void php_http_header_parser_dtor(php_http_header_parser_t *parser)
 {
        zend_ptr_stack_destroy(&parser->stack);
        php_http_info_dtor(&parser->info);
-       STR_FREE(parser->_key.str);
-       STR_FREE(parser->_val.str);
+       PTR_FREE(parser->_key.str);
+       PTR_FREE(parser->_val.str);
 }
 
 void php_http_header_parser_free(php_http_header_parser_t **parser)
@@ -231,8 +231,8 @@ STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_b
                                        parser->_val.str = NULL;
                                }
 
-                               STR_SET(parser->_key.str, NULL);
-                               STR_SET(parser->_val.str, NULL);
+                               PTR_SET(parser->_key.str, NULL);
+                               PTR_SET(parser->_val.str, NULL);
 
                                php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_KEY);
                                break;
index 2f1b746fa95d185db515896b87c6ef2c2532133b..7efd70ec7914426f697a3a7718984400e5f24253 100644 (file)
@@ -27,12 +27,12 @@ void php_http_info_dtor(php_http_info_t *i)
 {
        switch (i->type) {
                case PHP_HTTP_REQUEST:
-                       STR_SET(PHP_HTTP_INFO(i).request.method, NULL);
-                       STR_SET(PHP_HTTP_INFO(i).request.url, NULL);
+                       PTR_SET(PHP_HTTP_INFO(i).request.method, NULL);
+                       PTR_SET(PHP_HTTP_INFO(i).request.url, NULL);
                        break;
                
                case PHP_HTTP_RESPONSE:
-                       STR_SET(PHP_HTTP_INFO(i).response.status, NULL);
+                       PTR_SET(PHP_HTTP_INFO(i).response.status, NULL);
                        break;
                
                default:
@@ -122,7 +122,7 @@ php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_head
                        if (http > url) {
                                PHP_HTTP_INFO(info).request.url = php_http_url_parse(url, http - url, ~0 TSRMLS_CC);
                        } else {
-                               STR_SET(PHP_HTTP_INFO(info).request.method, NULL);
+                               PTR_SET(PHP_HTTP_INFO(info).request.method, NULL);
                                return NULL;
                        }
                } else {
index 1219d5dcf59373e9476b1561c35adc9ffde7834d..8a7e564a761990743270c2e7c736de49cc2471ce 100644 (file)
@@ -253,12 +253,12 @@ void php_http_message_set_type(php_http_message_t *message, php_http_message_typ
                /* free request info */
                switch (message->type) {
                        case PHP_HTTP_REQUEST:
-                               STR_FREE(message->http.info.request.method);
-                               STR_FREE(message->http.info.request.url);
+                               PTR_FREE(message->http.info.request.method);
+                               PTR_FREE(message->http.info.request.url);
                                break;
                        
                        case PHP_HTTP_RESPONSE:
-                               STR_FREE(message->http.info.response.status);
+                               PTR_FREE(message->http.info.response.status);
                                break;
                        
                        default:
@@ -276,13 +276,13 @@ void php_http_message_set_info(php_http_message_t *message, php_http_info_t *inf
        message->http.version = info->http.version;
        switch (message->type) {
                case PHP_HTTP_REQUEST:
-                       STR_SET(PHP_HTTP_INFO(message).request.url, PHP_HTTP_INFO(info).request.url ? php_http_url_copy(PHP_HTTP_INFO(info).request.url, 0) : NULL);
-                       STR_SET(PHP_HTTP_INFO(message).request.method, PHP_HTTP_INFO(info).request.method ? estrdup(PHP_HTTP_INFO(info).request.method) : NULL);
+                       PTR_SET(PHP_HTTP_INFO(message).request.url, PHP_HTTP_INFO(info).request.url ? php_http_url_copy(PHP_HTTP_INFO(info).request.url, 0) : NULL);
+                       PTR_SET(PHP_HTTP_INFO(message).request.method, PHP_HTTP_INFO(info).request.method ? estrdup(PHP_HTTP_INFO(info).request.method) : NULL);
                        break;
                
                case PHP_HTTP_RESPONSE:
                        PHP_HTTP_INFO(message).response.code = PHP_HTTP_INFO(info).response.code;
-                       STR_SET(PHP_HTTP_INFO(message).response.status, PHP_HTTP_INFO(info).response.status ? estrdup(PHP_HTTP_INFO(info).response.status) : NULL);
+                       PTR_SET(PHP_HTTP_INFO(message).response.status, PHP_HTTP_INFO(info).response.status ? estrdup(PHP_HTTP_INFO(info).response.status) : NULL);
                        break;
                
                default:
@@ -338,12 +338,12 @@ static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
        switch (msg->type) {
                case PHP_HTTP_REQUEST:
                        php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF));
-                       STR_FREE(tmp);
+                       PTR_FREE(tmp);
                        break;
 
                case PHP_HTTP_RESPONSE:
                        php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF));
-                       STR_FREE(tmp);
+                       PTR_FREE(tmp);
                        break;
 
                default:
@@ -499,12 +499,12 @@ void php_http_message_dtor(php_http_message_t *message)
                
                switch (message->type) {
                        case PHP_HTTP_REQUEST:
-                               STR_SET(message->http.info.request.method, NULL);
-                               STR_SET(message->http.info.request.url, NULL);
+                               PTR_SET(message->http.info.request.method, NULL);
+                               PTR_SET(message->http.info.request.url, NULL);
                                break;
                        
                        case PHP_HTTP_RESPONSE:
-                               STR_SET(message->http.info.response.status, NULL);
+                               PTR_SET(message->http.info.response.status, NULL);
                                break;
                        
                        default:
@@ -564,7 +564,7 @@ static void php_http_message_object_prophandler_get_request_method(php_http_mess
 static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
        if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
                zval *cpy = php_http_ztyp(IS_STRING, value);
-               STR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
+               PTR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
                zval_ptr_dtor(&cpy);
        }
 }
@@ -580,7 +580,7 @@ static void php_http_message_object_prophandler_get_request_url(php_http_message
 }
 static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
        if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
-               STR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, ~0 TSRMLS_CC));
+               PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, ~0 TSRMLS_CC));
        }
 }
 static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
@@ -593,7 +593,7 @@ static void php_http_message_object_prophandler_get_response_status(php_http_mes
 static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
        if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
                zval *cpy = php_http_ztyp(IS_STRING, value);
-               STR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
+               PTR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
                zval_ptr_dtor(&cpy);
        }
 }
@@ -608,7 +608,7 @@ static void php_http_message_object_prophandler_set_response_code(php_http_messa
        if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
                zval *cpy = php_http_ztyp(IS_LONG, value);
                obj->message->http.info.response.code = Z_LVAL_P(cpy);
-               STR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code)));
+               PTR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code)));
                zval_ptr_dtor(&cpy);
        }
 }
@@ -1338,11 +1338,11 @@ static PHP_METHOD(HttpMessage, getInfo)
                switch (obj->message->type) {
                        case PHP_HTTP_REQUEST:
                                Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, tmp, ""));
-                               STR_FREE(tmp);
+                               PTR_FREE(tmp);
                                break;
                        case PHP_HTTP_RESPONSE:
                                Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, tmp, ""));
-                               STR_FREE(tmp);
+                               PTR_FREE(tmp);
                                break;
                        default:
                                RETURN_NULL();
@@ -1462,7 +1462,7 @@ static PHP_METHOD(HttpMessage, setResponseCode)
        }
 
        obj->message->http.info.response.code = code;
-       STR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
+       PTR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
 
        RETVAL_ZVAL(getThis(), 1, 0);
 }
@@ -1507,7 +1507,7 @@ static PHP_METHOD(HttpMessage, setResponseStatus)
                php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
        }
 
-       STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
+       PTR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
        RETVAL_ZVAL(getThis(), 1, 0);
 }
 
@@ -1558,7 +1558,7 @@ static PHP_METHOD(HttpMessage, setRequestMethod)
                return;
        }
 
-       STR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
+       PTR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
        RETVAL_ZVAL(getThis(), 1, 0);
 }
 
@@ -1617,7 +1617,7 @@ static PHP_METHOD(HttpMessage, setRequestUrl)
                php_http_url_free(&url);
                php_http_throw(invalid_arg, "Cannot set http\\Message's request url to an empty string", NULL);
        } else {
-               STR_SET(obj->message->http.info.request.url, url);
+               PTR_SET(obj->message->http.info.request.url, url);
        }
 
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -1854,7 +1854,7 @@ static PHP_METHOD(HttpMessage, splitMultipartBody)
 
        php_http_expect(msg = php_http_message_body_split(obj->message->body, boundary), bad_message, return);
 
-       STR_FREE(boundary);
+       PTR_FREE(boundary);
 
        RETURN_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0);
 }
index 4be45ef0ce0b7d26d688e4811b5e271db7036d58..84e84e4abece2361aef9bd0727dd87bd9153b3b0 100644 (file)
@@ -100,7 +100,7 @@ void php_http_message_body_free(php_http_message_body_t **body_ptr)
                        TSRMLS_FETCH_FROM_CTX(body->ts);
                        /* NOFIXME: shows leakinfo in DEBUG mode */
                        zend_list_delete(body->stream_id);
-                       STR_FREE(body->boundary);
+                       PTR_FREE(body->boundary);
                        efree(body);
                }
                *body_ptr = NULL;
@@ -557,7 +557,7 @@ php_http_message_t *php_http_message_body_split(php_http_message_body_t *body, c
        php_http_buffer_free(&tmp);
        php_http_message_parser_free(&arg.parser);
        php_http_buffer_dtor(&arg.buf);
-       STR_FREE(arg.boundary_str);
+       PTR_FREE(arg.boundary_str);
 
        return msg;
 }
index e73360eed1920ffb57a740d32fa629bca7d41ad4..57805eccc396267785b3efdc65f104f7003f7cf8 100644 (file)
@@ -389,7 +389,7 @@ php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_p
                                                }
 
                                                if (str != buffer->data) {
-                                                       STR_FREE(str);
+                                                       PTR_FREE(str);
                                                }
                                                str = dec_str;
                                                len = dec_len;
@@ -408,7 +408,7 @@ php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_p
                                }
 
                                if (str != buffer->data) {
-                                       STR_FREE(str);
+                                       PTR_FREE(str);
                                }
 
                                str = NULL;
index 51072cf53da8e59e6578849c28a31bf0d28edb91..c6e22700fdafeda8ada5baf65ec2eb74fa181095 100644 (file)
@@ -80,8 +80,8 @@ int php_http_match(const char *haystack_str, const char *needle_str, int flags)
                        }
                }
 
-               STR_FREE(haystack);
-               STR_FREE(needle);
+               PTR_FREE(haystack);
+               PTR_FREE(needle);
        }
 
        return result;
index 3bd77d8b931046006373445f7344476a7bd2a1b9..8e901da3c135e546ebb8f7b6bb239be6756c8a92 100644 (file)
@@ -41,10 +41,10 @@ PHP_HTTP_API void php_http_sleep(double s);
 
 /* STRING UTILITIES */
 
-#ifndef STR_SET
-#      define STR_SET(STR, SET) \
+#ifndef PTR_SET
+#      define PTR_SET(STR, SET) \
        { \
-               STR_FREE(STR); \
+               PTR_FREE(STR); \
                STR = SET; \
        }
 #endif
@@ -291,7 +291,7 @@ static inline void php_http_array_hashkey_stringify(php_http_array_hashkey_t *ke
 static inline void php_http_array_hashkey_stringfree(php_http_array_hashkey_t *key)
 {
        if (key->type != HASH_KEY_IS_STRING || key->dup) {
-               STR_FREE(key->str);
+               PTR_FREE(key->str);
        }
 }
 
index 76106a852adc07a4e72d4a44c43d0836d0e13fa6..a74875b7378647664a1fe35a63b72c8f17995d79 100644 (file)
@@ -141,7 +141,7 @@ HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable
                                add_index_double(&arr, key.num, q);
                        }
 
-                       STR_FREE(key.str);
+                       PTR_FREE(key.str);
                }
 
 #if 0
index 3a12ab7cd1992a01d48b409a71e32770dfd77ffa..f7405b54e5111a4f66f4fffe743bd3f436384da7 100644 (file)
@@ -24,7 +24,7 @@ static inline HashTable *php_http_negotiate_language(HashTable *supported, php_h
        if (value) {
                result = php_http_negotiate(value, length, supported, "-", 1 TSRMLS_CC);
        }
-       STR_FREE(value);
+       PTR_FREE(value);
 
        return result;
 }
@@ -38,7 +38,7 @@ static inline HashTable *php_http_negotiate_encoding(HashTable *supported, php_h
        if (value) {
                result = php_http_negotiate(value, length, supported, NULL, 0 TSRMLS_CC);
        }
-       STR_FREE(value);
+       PTR_FREE(value);
 
        return result;
 }
@@ -52,7 +52,7 @@ static inline HashTable *php_http_negotiate_charset(HashTable *supported, php_ht
        if (value) {
                result = php_http_negotiate(value, length, supported, NULL, 0 TSRMLS_CC);
        }
-       STR_FREE(value);
+       PTR_FREE(value);
 
        return result;
 }
@@ -66,7 +66,7 @@ static inline HashTable *php_http_negotiate_content_type(HashTable *supported, p
        if (value) {
                result = php_http_negotiate(value, length, supported, "/", 1 TSRMLS_CC);
        }
-       STR_FREE(value);
+       PTR_FREE(value);
 
        return result;
 }
index 523424423d3b21ce15704d4804cae4dd73fc1daa..ce785ecbe03efef1daad18b9acb0948fc5f9a61a 100644 (file)
@@ -347,7 +347,7 @@ static inline void sanitize_value(unsigned flags, char *str, size_t len, zval *z
                ZVAL_COPY_VALUE(tmp, zv);
                array_init(zv);
                add_assoc_zval(zv, language, tmp);
-               STR_FREE(language);
+               PTR_FREE(language);
        }
 }
 
@@ -885,7 +885,7 @@ void php_http_params_separator_free(php_http_params_token_t **separator)
        php_http_params_token_t **sep = separator;
        if (sep) {
                while (*sep) {
-                       STR_FREE((*sep)->str);
+                       PTR_FREE((*sep)->str);
                        efree(*sep);
                        ++sep;
                }
index a3750183985fa1bd135a7b544f6c27647fcca098..40fffbad92bd666c20cf5eceee6535e03b6890bd 100644 (file)
@@ -203,20 +203,15 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u
                } else {
                        const char *path = NULL;
 
-                       url(buf)->path = &buf.data[buf.used];
-
                        if (url_isset(new_url, path)) {
                                path = new_url->path;
                        } else if (url_isset(old_url, path)) {
                                path = old_url->path;
-                       } else {
-                               php_http_buffer_append(&buf, "/", sizeof("/"));
                        }
 
                        if (path) {
-                               if (path[0] != '/') {
-                                       php_http_buffer_append(&buf, "/", 1);
-                               }
+                               url(buf)->path = &buf.data[buf.used];
+
                                php_http_buffer_append(&buf, path, strlen(path) + 1);
                        }
 
@@ -261,22 +256,6 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u
                php_http_url_free(&tmp_url);
        }
 
-       /* set some sane defaults */
-
-       if (!url(buf)->scheme) {
-               url(buf)->scheme = &buf.data[buf.used];
-               php_http_buffer_append(&buf, "http", sizeof("http"));
-       }
-
-       if (!url(buf)->host) {
-               url(buf)->host = &buf.data[buf.used];
-               php_http_buffer_append(&buf, "localhost", sizeof("localhost"));
-       }
-
-       if (!url(buf)->path) {
-               url(buf)->path = &buf.data[buf.used];
-               php_http_buffer_append(&buf, "/", sizeof("/"));
-       }
        /* replace directory references if path is not a single slash */
        if ((flags & PHP_HTTP_URL_SANITIZE_PATH)
        &&      url(buf)->path[0] && url(buf)->path[1]) {
@@ -364,14 +343,18 @@ char *php_http_url_to_string(const php_http_url_t *url, char **url_str, size_t *
 
        if (url->host && *url->host) {
                php_http_buffer_appendl(&buf, url->host);
-       }
-
-       if (url->port) {
-               php_http_buffer_appendf(&buf, ":%hu", url->port);
+               if (url->port) {
+                       php_http_buffer_appendf(&buf, ":%hu", url->port);
+               }
        }
 
        if (url->path && *url->path) {
+               if (*url->path != '/') {
+                       php_http_buffer_appends(&buf, "/");
+               }
                php_http_buffer_appendl(&buf, url->path);
+       } else if (buf.used) {
+               php_http_buffer_appends(&buf, "/");
        }
 
        if (url->query && *url->query) {
@@ -1396,67 +1379,12 @@ PHP_METHOD(HttpUrl, toArray)
        php_http_url_free(&purl);
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_parse, 0, 0, 1)
-       ZEND_ARG_INFO(0, url)
-       ZEND_ARG_INFO(0, flags)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpUrl, parse)
-{
-       char *str;
-       int len;
-       long flags = 0;
-       php_http_url_t *url;
-       zend_error_handling zeh;
-
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, &flags), invalid_arg, return);
-
-       zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
-       if ((url = php_http_url_parse(str, len, flags TSRMLS_CC))) {
-               object_init_ex(return_value, php_http_url_class_entry);
-               if (url->scheme) {
-                       zend_update_property_string(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("scheme"), url->scheme TSRMLS_CC);
-               }
-               if (url->user) {
-                       zend_update_property_string(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("user"), url->user TSRMLS_CC);
-               }
-               if (url->pass) {
-                       zend_update_property_string(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("pass"), url->pass TSRMLS_CC);
-               }
-               if (url->host) {
-                       zend_update_property_string(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("host"), url->host TSRMLS_CC);
-               }
-               if (url->port) {
-                       zend_update_property_long(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("port"), url->port TSRMLS_CC);
-               }
-               if (url->path) {
-                       zend_update_property_string(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("path"), url->path TSRMLS_CC);
-               }
-               if (url->query) {
-                       zend_update_property_string(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("query"), url->query TSRMLS_CC);
-               }
-               if (url->fragment) {
-                       zend_update_property_string(php_http_url_class_entry, return_value,
-                                       ZEND_STRL("fragment"), url->fragment TSRMLS_CC);
-               }
-               php_http_url_free(&url);
-       }
-       zend_restore_error_handling(&zeh TSRMLS_CC);
-}
-
 static zend_function_entry php_http_url_methods[] = {
        PHP_ME(HttpUrl, __construct,  ai_HttpUrl___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_ME(HttpUrl, mod,          ai_HttpUrl_mod, ZEND_ACC_PUBLIC)
        PHP_ME(HttpUrl, toString,     ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
        ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
        PHP_ME(HttpUrl, toArray,      ai_HttpUrl_toArray, ZEND_ACC_PUBLIC)
-       PHP_ME(HttpUrl, parse,        ai_HttpUrl_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        EMPTY_FUNCTION_ENTRY
 };
 
index 5109d3ab60401b3fc1d67bd05cd91d6c079c4809..e1bc2504875273bcfc98f75593f222f5225d2a9e 100644 (file)
@@ -23,5 +23,5 @@ http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2
 http://example.com:55555/index?s=b&i=0&e=&a[]=1&a[]=2
 https://example.com/?s=b&i=0&e=&a[]=1&a[]=2
 http://example.com:55555/index.php/
-http://localhost/
+
 DONE
index 73bd9d4e81b318b09ef478cec300ac823951c69a..e7ccc5999a5cdd31e2b737bbc3e6031cbac073e3 100644 (file)
@@ -21,7 +21,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(http\Url::parse($url));
+       var_dump(new http\Url($url, null, 0));
 }
 
 ?>
index be1cd66f5b93941670f379cc5f687f9f6f0fdea6..92114dce1d296f08c1fa510a5a909c5d8dfe59c7 100644 (file)
@@ -22,7 +22,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(http\Url::parse($url));
+       var_dump(new http\Url($url, null, 0));
 }
 ?>
 DONE
index 68b1e4a526be5fb9d6d3151ce40cd9e79524535f..9a368a75f2338d2a2539273c79b12c807bd5548d 100644 (file)
@@ -25,7 +25,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(http\Url::parse($url));
+       var_dump(new http\Url($url, null, 0));
 }
 ?>
 DONE
index 3aa57fd3daa4a99abc2d6441e571c60d4b81e10b..d1cd1eea061a1ac4f362b6e49d2dc8913bf1f5cd 100644 (file)
@@ -20,7 +20,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(http\Url::parse($url, http\Url::PARSE_MBLOC));
+       var_dump(new http\Url($url, null, http\Url::PARSE_MBLOC));
 }
 ?>
 DONE
index ff18fe48cd4533fc6aba922011fac695395a2b4a..d6ec61f11ea1f1c9a3b724a33ee4d095ebc0eec3 100644 (file)
@@ -16,7 +16,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(http\Url::parse($url, http\Url::PARSE_MBUTF8));
+       var_dump(new http\Url($url, null, http\Url::PARSE_MBUTF8));
 }
 ?>
 DONE
index 72ee3580ae360e1c0c7172c795dbf885c45b4a22..c47e6a2f60876bf47fc9aa4727a0dae55be11ff4 100644 (file)
@@ -21,7 +21,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(http\Url::parse($url, http\Url::PARSE_MBLOC|http\Url::PARSE_TOIDN));
+       var_dump(new http\Url($url, null, http\Url::PARSE_MBLOC|http\Url::PARSE_TOIDN));
 }
 ?>
 DONE
index 518bb725671c141c47bd0459036c956df223558f..d7ec657e533c71ca8cfa672424df2170cd14a3a9 100644 (file)
@@ -19,7 +19,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(http\Url::parse($url, http\Url::PARSE_MBUTF8|http\Url::PARSE_TOIDN));
+       var_dump(new http\Url($url, null, http\Url::PARSE_MBUTF8|http\Url::PARSE_TOIDN));
 }
 ?>
 DONE
index 98382f43c4cb97823923e0555bd2ccb7d3ab7750..9646fa0d67aae97b4c56020cdc52d983270878c1 100644 (file)
@@ -18,7 +18,7 @@ $urls = array(
 foreach ($urls as $url) {
        try {
                printf("\n%s\n", $url);
-               var_dump(http\Url::parse($url));
+               var_dump(new http\Url($url, null, 0));
        } catch (Exception $e) {
                echo $e->getMessage(),"\n";
        }
@@ -29,10 +29,10 @@ DONE
 Test
 
 s://[a:80
-http\Url::parse(): Failed to parse hostinfo; expected ']'
+http\Url::__construct(): Failed to parse hostinfo; expected ']'
 
 s://[0]
-http\Url::parse(): Failed to parse hostinfo; unexpected '['
+http\Url::__construct(): Failed to parse hostinfo; unexpected '['
 
 s://[::1]:80
 object(http\Url)#%d (8) {
index f3e2b831d993073eaff789841dccf0d08063d862..57080f4a999212ec82a36403b317b0fb1eacd417 100644 (file)
@@ -26,7 +26,7 @@ $urls = array(
 foreach ($urls as $url) {
        try {
                printf("\n%s\n", $url);
-               var_dump(http\Url::parse($url));
+               var_dump(new http\Url($url, null, 0));
        } catch (Exception $e) {
                echo $e->getMessage(),"\n";
        }
index a82b7a86df7a42258e9620655f6bc0f6bb41cb65..71f6943a396b0b42a18ef31f6ec93a878150ef44 100644 (file)
@@ -13,7 +13,7 @@ $urls = array(
 );
 
 foreach ($urls as $url) {
-       var_dump(http\Url::parse($url, http\Url::PARSE_MBUTF8|http\Url::PARSE_TOPCT));
+       var_dump(new http\Url($url, null, http\Url::PARSE_MBUTF8|http\Url::PARSE_TOPCT));
 }
 ?>
 DONE