From: Michael Wallner Date: Fri, 7 Nov 2014 19:37:07 +0000 (+0100) Subject: don't abuse STR_FREE; ditch http\Url::parse(); fix tests X-Git-Tag: RELEASE_2_2_0_RC1~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b54d9ed0b0cd930f76754fe281e66f36a953085b;p=m6w6%2Fext-http don't abuse STR_FREE; ditch http\Url::parse(); fix tests --- diff --git a/php_http_buffer.c b/php_http_buffer.c index 8ccee08..6636e2c 100644 --- a/php_http_buffer.c +++ b/php_http_buffer.c @@ -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; } diff --git a/php_http_buffer.h b/php_http_buffer.h index cf9b458..faf8992 100644 --- a/php_http_buffer.h +++ b/php_http_buffer.h @@ -21,19 +21,19 @@ #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 diff --git a/php_http_client_request.c b/php_http_client_request.c index eaf71da..0e40cc5 100644 --- a/php_http_client_request.c +++ b/php_http_client_request.c @@ -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); } diff --git a/php_http_cookie.c b/php_http_cookie.c index 4bd8d80..354dfa6 100644 --- a/php_http_cookie.c +++ b/php_http_cookie.c @@ -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); } diff --git a/php_http_encoding.c b/php_http_encoding.c index 7f0462c..b7050f6 100644 --- a/php_http_encoding.c +++ b/php_http_encoding.c @@ -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); } } } diff --git a/php_http_env.c b/php_http_env.c index 2969d1a..25759a6 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -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 } diff --git a/php_http_env_response.c b/php_http_env_response.c index 13a35c6..83ebc6b 100644 --- a/php_http_env_response.c +++ b/php_http_env_response.c @@ -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); } diff --git a/php_http_header_parser.c b/php_http_header_parser.c index 2526835..df0837d 100644 --- a/php_http_header_parser.c +++ b/php_http_header_parser.c @@ -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; diff --git a/php_http_info.c b/php_http_info.c index 2f1b746..7efd70e 100644 --- a/php_http_info.c +++ b/php_http_info.c @@ -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 { diff --git a/php_http_message.c b/php_http_message.c index 1219d5d..8a7e564 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -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); } diff --git a/php_http_message_body.c b/php_http_message_body.c index 4be45ef..84e84e4 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -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; } diff --git a/php_http_message_parser.c b/php_http_message_parser.c index e73360e..57805ec 100644 --- a/php_http_message_parser.c +++ b/php_http_message_parser.c @@ -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; diff --git a/php_http_misc.c b/php_http_misc.c index 51072cf..c6e2270 100644 --- a/php_http_misc.c +++ b/php_http_misc.c @@ -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; diff --git a/php_http_misc.h b/php_http_misc.h index 3bd77d8..8e901da 100644 --- a/php_http_misc.h +++ b/php_http_misc.h @@ -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); } } diff --git a/php_http_negotiate.c b/php_http_negotiate.c index 76106a8..a74875b 100644 --- a/php_http_negotiate.c +++ b/php_http_negotiate.c @@ -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 diff --git a/php_http_negotiate.h b/php_http_negotiate.h index 3a12ab7..f7405b5 100644 --- a/php_http_negotiate.h +++ b/php_http_negotiate.h @@ -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; } diff --git a/php_http_params.c b/php_http_params.c index 5234244..ce785ec 100644 --- a/php_http_params.c +++ b/php_http_params.c @@ -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; } diff --git a/php_http_url.c b/php_http_url.c index a375018..40fffba 100644 --- a/php_http_url.c +++ b/php_http_url.c @@ -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 }; diff --git a/tests/url001.phpt b/tests/url001.phpt index 5109d3a..e1bc250 100644 --- a/tests/url001.phpt +++ b/tests/url001.phpt @@ -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 diff --git a/tests/urlparser001.phpt b/tests/urlparser001.phpt index 73bd9d4..e7ccc59 100644 --- a/tests/urlparser001.phpt +++ b/tests/urlparser001.phpt @@ -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)); } ?> diff --git a/tests/urlparser002.phpt b/tests/urlparser002.phpt index be1cd66..92114dc 100644 --- a/tests/urlparser002.phpt +++ b/tests/urlparser002.phpt @@ -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 diff --git a/tests/urlparser003.phpt b/tests/urlparser003.phpt index 68b1e4a..9a368a7 100644 --- a/tests/urlparser003.phpt +++ b/tests/urlparser003.phpt @@ -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 diff --git a/tests/urlparser004.phpt b/tests/urlparser004.phpt index 3aa57fd..d1cd1ee 100644 --- a/tests/urlparser004.phpt +++ b/tests/urlparser004.phpt @@ -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 diff --git a/tests/urlparser005.phpt b/tests/urlparser005.phpt index ff18fe4..d6ec61f 100644 --- a/tests/urlparser005.phpt +++ b/tests/urlparser005.phpt @@ -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 diff --git a/tests/urlparser006.phpt b/tests/urlparser006.phpt index 72ee358..c47e6a2 100644 --- a/tests/urlparser006.phpt +++ b/tests/urlparser006.phpt @@ -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 diff --git a/tests/urlparser007.phpt b/tests/urlparser007.phpt index 518bb72..d7ec657 100644 --- a/tests/urlparser007.phpt +++ b/tests/urlparser007.phpt @@ -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 diff --git a/tests/urlparser008.phpt b/tests/urlparser008.phpt index 98382f4..9646fa0 100644 --- a/tests/urlparser008.phpt +++ b/tests/urlparser008.phpt @@ -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) { diff --git a/tests/urlparser009.phpt b/tests/urlparser009.phpt index f3e2b83..57080f4 100644 --- a/tests/urlparser009.phpt +++ b/tests/urlparser009.phpt @@ -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"; } diff --git a/tests/urlparser010.phpt b/tests/urlparser010.phpt index a82b7a8..71f6943 100644 --- a/tests/urlparser010.phpt +++ b/tests/urlparser010.phpt @@ -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