switch (type) {
case PHP_HTTP_REQUEST:
- mbody = php_http_env_get_request_body(TSRMLS_C);
+ mbody = php_http_env_get_request_body();
php_http_message_body_addref(mbody);
- message = php_http_message_init(message, type, mbody TSRMLS_CC);
- if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1 TSRMLS_CC)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
- php_http_version_parse(&message->http.version, Z_STRVAL_P(sval) TSRMLS_CC);
+ message = php_http_message_init(message, type, mbody);
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
+ php_http_version_parse(&message->http.version, Z_STRVAL_P(sval));
}
- if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1 TSRMLS_CC))) {
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1))) {
message->http.info.request.method = estrdup(Z_STRVAL_P(sval));
}
- if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1 TSRMLS_CC))) {
- message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), PHP_HTTP_URL_STDFLAGS TSRMLS_CC);
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1))) {
- message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), ~0);
++ message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), PHP_HTTP_URL_STDFLAGS);
}
- php_http_env_get_request_headers(&message->hdrs TSRMLS_CC);
+ php_http_env_get_request_headers(&message->hdrs);
break;
case PHP_HTTP_RESPONSE:
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
- PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, ~0));
- PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, PHP_HTTP_URL_STDFLAGS TSRMLS_CC));
++ PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, PHP_HTTP_URL_STDFLAGS));
}
}
-static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message) && obj->message->http.info.response.status) {
- RETVAL_STRING(obj->message->http.info.response.status, 1);
+ RETVAL_STRING(obj->message->http.info.response.status);
} else {
RETVAL_NULL();
}
RETVAL_ZVAL(getThis(), 1, 0);
}
-static inline void php_http_message_object_add_header(php_http_message_object_t *obj, const char *name_str, size_t name_len, zval *zvalue TSRMLS_DC)
++static inline void php_http_message_object_add_header(php_http_message_object_t *obj, const char *name_str, size_t name_len, zval *zvalue)
+ {
+ char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
- zval *header, *cpy;
++ zend_string *hstr, *vstr;
++ zval *header, tmp;
+
+ if (Z_TYPE_P(zvalue) == IS_NULL) {
+ return;
+ }
+
- cpy = php_http_header_value_to_string(zvalue TSRMLS_CC);
++ vstr = php_http_header_value_to_string(zvalue);
+
+ if ((name_len != lenof("Set-Cookie") && strcmp(name, "Set-Cookie"))
- && (header = php_http_message_header(obj->message, name, name_len, 1))) {
- zval *tmp;
++ && (hstr = php_http_message_header_string(obj->message, name, name_len))) {
+ char *hdr_str;
- size_t hdr_len = spprintf(&hdr_str, 0, "%s, %s", Z_STRVAL_P(header), Z_STRVAL_P(cpy));
-
- MAKE_STD_ZVAL(tmp);
- ZVAL_STRINGL(tmp, hdr_str, hdr_len, 0);
- zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &tmp, sizeof(void *), NULL);
- zval_ptr_dtor(&header);
- zval_ptr_dtor(&cpy);
- } else if ((header = php_http_message_header(obj->message, name, name_len, 0))) {
++ size_t hdr_len = spprintf(&hdr_str, 0, "%s, %s", hstr->val, vstr->val);
++
++ ZVAL_STR(&tmp, php_http_cs2zs(hdr_str, hdr_len));
++ zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp);
++ zend_string_release(hstr);
++ zend_string_release(vstr);
++ } else if ((header = php_http_message_header(obj->message, name, name_len))) {
+ convert_to_array(header);
- zend_hash_next_index_insert(Z_ARRVAL_P(header), &cpy, sizeof(void *), NULL);
- zval_ptr_dtor(&header);
++ ZVAL_STR(&tmp, vstr);
++ zend_hash_next_index_insert(Z_ARRVAL_P(header), &tmp);
+ } else {
- zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &cpy, sizeof(void *), NULL);
++ ZVAL_STR(&tmp, vstr);
++ zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp);
+ }
+ efree(name);
+ }
+
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeader, 0, 0, 2)
ZEND_ARG_INFO(0, header)
ZEND_ARG_INFO(0, value)
{
zval *zvalue;
char *name_str;
- int name_len;
+ size_t name_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name_str, &name_len, &zvalue)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name_str, &name_len, &zvalue)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
- zend_string *hstr, *vstr = php_http_header_value_to_string(zvalue);
- zval tmp, *header;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- if ((name_len != lenof("Set-Cookie") && strcmp(name, "Set-Cookie"))
- && (hstr = php_http_message_header_string(obj->message, name, name_len))) {
- char *hdr_str;
- size_t hdr_len = spprintf(&hdr_str, 0, "%s, %s", hstr->val, vstr->val);
-
- ZVAL_STR(&tmp, php_http_cs2zs(hdr_str, hdr_len));
- zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp);
- zend_string_release(hstr);
- zend_string_release(vstr);
- } else if ((header = php_http_message_header(obj->message, name, name_len))) {
- convert_to_array(header);
- ZVAL_STR(&tmp, vstr);
- zend_hash_next_index_insert(Z_ARRVAL_P(header), &tmp);
- } else {
- ZVAL_STR(&tmp, vstr);
- zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp);
- }
- efree(name);
- php_http_message_object_add_header(obj, name_str, name_len, zvalue TSRMLS_CC);
++ php_http_message_object_add_header(obj, name_str, name_len, zvalue);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, append, ARRAY_JOIN_STRONLY|ARRAY_JOIN_PRETTIFY);
+ if (append) {
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **val;
-
- FOREACH_KEYVAL(pos, new_headers, key, val) {
- php_http_array_hashkey_stringify(&key);
- php_http_message_object_add_header(obj, key.str, key.len-1, *val TSRMLS_CC);
- php_http_array_hashkey_stringfree(&key);
++ php_http_arrkey_t key = {0};
++ zval *val;
++
++ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(new_headers), key.h, key.key, val)
++ {
++ php_http_arrkey_stringify(&key, NULL);
++ php_http_message_object_add_header(obj, key.key->val, key.key->len, val);
++ php_http_arrkey_dtor(&key);
+ }
++ ZEND_HASH_FOREACH_END();
+ } else {
+ array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, 0, ARRAY_JOIN_PRETTIFY|ARRAY_JOIN_STRONLY);
+ }
}
RETVAL_ZVAL(getThis(), 1, 0);
}
return;
}
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
- url = php_http_url_from_zval(zurl, PHP_HTTP_URL_STDFLAGS TSRMLS_CC);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
- url = php_http_url_from_zval(zurl, ~0);
++ url = php_http_url_from_zval(zurl, PHP_HTTP_URL_STDFLAGS);
+ zend_restore_error_handling(&zeh);
if (url && php_http_url_is_empty(url)) {
php_http_url_free(&url);
switch (*ptr) {
case ':':
if (password) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse password; duplicate ':' at pos %u in '%s'",
- (unsigned) (ptr - tmp), tmp);
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse password; duplicate ':' at pos %u in '%s'",
+ (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ state->buffer[state->offset++] = *ptr;
+ break;
}
password = ptr + 1;
state->buffer[state->offset++] = 0;
case '%':
if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
- (unsigned) (ptr - tmp), tmp);
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
+ (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ state->buffer[state->offset++] = *ptr++;
+ break;
}
state->buffer[state->offset++] = *ptr++;
state->buffer[state->offset++] = *ptr++;
}
# endif
if (rv != IDN2_OK) {
- php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
++ php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
} else {
size_t idnlen = strlen(idn);
memcpy(state->url.host, idn, idnlen + 1);
}
# endif
if (rv != IDNA_SUCCESS) {
- php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
++ php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
} else {
size_t idnlen = strlen(idn);
memcpy(state->url.host, idn, idnlen + 1);
#ifdef HAVE_INET_PTON
static const char *parse_ip6(struct parse_state *state, const char *ptr)
{
+ unsigned pos = 0;
const char *error = NULL, *end = state->ptr, *tmp = memchr(ptr, ']', end - ptr);
- TSRMLS_FETCH_FROM_CTX(state->ts);
if (tmp) {
size_t addrlen = tmp - ptr + 1;
}
if (error) {
- php_error_docref(NULL, E_WARNING, "Failed to parse hostinfo; %s", error);
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse hostinfo; %s at pos %u in '%s'", error, pos, ptr);
++ php_error_docref(NULL, E_WARNING, "Failed to parse hostinfo; %s at pos %u in '%s'", error, pos, ptr);
+ }
return NULL;
}
static ZEND_RESULT_CODE parse_hostinfo(struct parse_state *state, const char *ptr)
{
- size_t mb, len;
+ size_t mb, len = state->offset;
const char *end = state->ptr, *tmp = ptr, *port = NULL, *label = NULL;
- TSRMLS_FETCH_FROM_CTX(state->ts);
#ifdef HAVE_INET_PTON
if (*ptr == '[' && !(ptr = parse_ip6(state, ptr))) {
switch (*ptr) {
case ':':
if (port) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse port; unexpected ':' at pos %u in '%s'",
- (unsigned) (ptr - tmp), tmp);
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse port; unexpected ':' at pos %u in '%s'",
+ (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
}
port = ptr + 1;
break;
case '%':
if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
- (unsigned) (ptr - tmp), tmp);
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
+ (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ state->buffer[state->offset++] = *ptr++;
+ break;
}
state->buffer[state->offset++] = *ptr++;
state->buffer[state->offset++] = *ptr++;
/* sort of a compromise, just ensure we don't end up
* with a dot at the beginning or two consecutive dots
*/
- php_error_docref(NULL, E_WARNING,
- "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
- port ? "port" : "host",
- (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
+ port ? "port" : "host",
+ (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ break;
}
state->buffer[state->offset++] = *ptr;
label = NULL;
/* sort of a compromise, just ensure we don't end up
* with a hyphen at the beginning
*/
- php_error_docref(NULL, E_WARNING,
- "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
- port ? "port" : "host",
- (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
+ port ? "port" : "host",
+ (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ break;
}
/* no break */
case '_': case '~': /* unreserved */
case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
case 'v': case 'w': case 'x': case 'y': case 'z':
if (port) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
- (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
+ (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ break;
}
/* no break */
case '0': case '1': case '2': case '3': case '4': case '5': case '6':
if (ptr == end) {
break;
} else if (port) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
- (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
- return FAILURE;
- } else if (!(mb = parse_mb(state, PARSE_HOSTINFO, ptr, end, tmp, 0))) {
- return FAILURE;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
+ (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ break;
+ } else if (!(mb = parse_mb(state, PARSE_HOSTINFO, ptr, end, tmp, state->flags & PHP_HTTP_URL_SILENT_ERRORS))) {
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return FAILURE;
+ }
+ break;
}
label = ptr;
ptr += mb - 1;
case '@':
/* userinfo delimiter */
if (host) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse userinfo; unexpected '@'");
- return NULL;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- TSRMLS_FETCH_FROM_CTX(state->ts);
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse userinfo; unexpected '@'");
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return NULL;
+ }
+ break;
}
host = state->ptr + 1;
if (tmp != state->ptr && SUCCESS != parse_userinfo(state, tmp)) {
case '%':
if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse path; invalid percent encoding at pos %u in '%s'",
- (unsigned) (state->ptr - tmp), tmp);
- return NULL;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse path; invalid percent encoding at pos %u in '%s'",
+ (unsigned) (state->ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return NULL;
+ }
+ state->buffer[state->offset++] = *state->ptr;
+ break;
}
state->buffer[state->offset++] = *state->ptr++;
state->buffer[state->offset++] = *state->ptr++;
case '%':
if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse query; invalid percent encoding at pos %u in '%s'",
- (unsigned) (state->ptr - tmp), tmp);
- return NULL;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse query; invalid percent encoding at pos %u in '%s'",
+ (unsigned) (state->ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return NULL;
+ }
+ /* fallthrough, pct-encode the percent sign */
+ } else {
+ state->buffer[state->offset++] = *state->ptr++;
+ state->buffer[state->offset++] = *state->ptr++;
+ state->buffer[state->offset++] = *state->ptr;
+ break;
}
- state->buffer[state->offset++] = *state->ptr++;
- state->buffer[state->offset++] = *state->ptr++;
- state->buffer[state->offset++] = *state->ptr;
- break;
-
- /* RFC1738 unsafe */
+ /* no break */
case '{': case '}':
case '<': case '>':
case '[': case ']':
do {
switch (*state->ptr) {
- case '%':
- if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
+ case '#':
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
- "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
+ "Failed to parse fragment; invalid fragment identifier at pos %u in '%s'",
(unsigned) (state->ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
return NULL;
}
- state->buffer[state->offset++] = *state->ptr++;
- state->buffer[state->offset++] = *state->ptr++;
state->buffer[state->offset++] = *state->ptr;
break;
- /* RFC1738 unsafe */
+ case '%':
+ if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
+ (unsigned) (state->ptr - tmp), tmp);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ return NULL;
+ }
+ /* fallthrough */
+ } else {
+ state->buffer[state->offset++] = *state->ptr++;
+ state->buffer[state->offset++] = *state->ptr++;
+ state->buffer[state->offset++] = *state->ptr;
+ break;
+ }
+ /* no break */
+
case '{': case '}':
case '<': case '>':
case '[': case ']':
}
if (state->ptr != state->end) {
- php_error_docref(NULL, E_WARNING,
- "Failed to parse URL authority, unexpected character at pos %u in '%s'",
- (unsigned) (state->ptr - str), str);
- efree(state);
- return NULL;
+ if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
++ php_error_docref(NULL, E_WARNING,
+ "Failed to parse URL authority, unexpected character at pos %u in '%s'",
+ (unsigned) (state->ptr - str), str);
+ }
+ if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
+ efree(state);
+ return NULL;
+ }
}
return (php_http_url_t *) state;
PHP_METHOD(HttpUrl, __construct)
{
zval *new_url = NULL, *old_url = NULL;
- long flags = PHP_HTTP_URL_FROM_ENV;
+ zend_long flags = 0;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
+
+ /* always set http\Url::FROM_ENV for instances of http\Env\Url */
+ if (instanceof_function(Z_OBJCE_P(getThis()), php_http_env_url_class_entry)) {
+ flags |= PHP_HTTP_URL_FROM_ENV;
+ }
- zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
+ if (flags & PHP_HTTP_URL_SILENT_ERRORS) {
- zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh TSRMLS_CC);
++ zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh);
+ } else if (flags & PHP_HTTP_URL_IGNORE_ERRORS) {
- zend_replace_error_handling(EH_NORMAL, NULL, &zeh TSRMLS_CC);
++ zend_replace_error_handling(EH_NORMAL, NULL, &zeh);
+ } else {
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
++ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
+ }
{
php_http_url_t *res_purl, *new_purl = NULL, *old_purl = NULL;
PHP_METHOD(HttpUrl, mod)
{
zval *new_url = NULL;
- long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY | PHP_HTTP_URL_SANITIZE_PATH;
+ zend_long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY | PHP_HTTP_URL_SANITIZE_PATH;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url, &flags), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
+ if (flags & PHP_HTTP_URL_SILENT_ERRORS) {
- zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh TSRMLS_CC);
++ zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh);
+ } else if (flags & PHP_HTTP_URL_IGNORE_ERRORS) {
- zend_replace_error_handling(EH_NORMAL, NULL, &zeh TSRMLS_CC);
++ zend_replace_error_handling(EH_NORMAL, NULL, &zeh);
+ } else {
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
++ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
+ }
{
php_http_url_t *new_purl = NULL, *old_purl = NULL;
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Url", php_http_url_methods);
- php_http_url_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
-
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC);
+ php_http_url_class_entry = zend_register_internal_class(&ce);
+
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC);
+
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH);
#ifdef PHP_HTTP_HAVE_WCHAR
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC);
#endif
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8);
#if defined(PHP_HTTP_HAVE_IDN2) || defined(PHP_HTTP_HAVE_IDN) || defined(HAVE_UIDNA_IDNTOASCII)
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN);
#endif
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT);
+
+ INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Url", php_http_url_methods);
+ php_http_env_url_class_entry = zend_register_internal_class_ex(&ce, php_http_url_class_entry);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("IGNORE_ERRORS"), PHP_HTTP_URL_IGNORE_ERRORS TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SILENT_ERRORS"), PHP_HTTP_URL_SILENT_ERRORS TSRMLS_CC);
++ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("IGNORE_ERRORS"), PHP_HTTP_URL_IGNORE_ERRORS);
++ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SILENT_ERRORS"), PHP_HTTP_URL_SILENT_ERRORS);
+
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STDFLAGS"), PHP_HTTP_URL_STDFLAGS TSRMLS_CC);
++ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STDFLAGS"), PHP_HTTP_URL_STDFLAGS);
+
return SUCCESS;
}