2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 #if PHP_HTTP_HAVE_LIBIDN2
18 #if PHP_HTTP_HAVE_LIBIDN
21 #if PHP_HTTP_HAVE_LIBICU
22 # include <unicode/uidna.h>
25 #ifdef PHP_HTTP_HAVE_WCHAR
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
34 #include "php_http_utf8.h"
36 static inline char *localhostname(void)
38 char hostname
[1024] = {0};
41 if (SUCCESS
== gethostname(hostname
, lenof(hostname
))) {
42 return estrdup(hostname
);
44 #elif defined(HAVE_GETHOSTNAME)
45 if (SUCCESS
== gethostname(hostname
, lenof(hostname
))) {
46 # if defined(HAVE_GETDOMAINNAME)
47 size_t hlen
= strlen(hostname
);
48 if (hlen
<= lenof(hostname
) - lenof("(none)")) {
49 hostname
[hlen
++] = '.';
50 if (SUCCESS
== getdomainname(&hostname
[hlen
], lenof(hostname
) - hlen
)) {
51 if (!strcmp(&hostname
[hlen
], "(none)")) {
52 hostname
[hlen
- 1] = '\0';
54 return estrdup(hostname
);
58 if (strcmp(hostname
, "(none)")) {
59 return estrdup(hostname
);
63 return estrndup("localhost", lenof("localhost"));
66 #define url(buf) ((php_http_url_t *) (buf).data)
68 static php_http_url_t
*php_http_url_from_env(void)
70 zval
*https
, *zhost
, *zport
;
72 php_http_buffer_t buf
;
74 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
75 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
76 memset(buf
.data
, 0, buf
.used
);
79 url(buf
)->scheme
= &buf
.data
[buf
.used
];
80 https
= php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1);
81 if (https
&& !strcasecmp(Z_STRVAL_P(https
), "ON")) {
82 php_http_buffer_append(&buf
, "https", sizeof("https"));
84 php_http_buffer_append(&buf
, "http", sizeof("http"));
88 url(buf
)->host
= &buf
.data
[buf
.used
];
89 if ((((zhost
= php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1)) ||
90 (zhost
= php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1)) ||
91 (zhost
= php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1)))) && Z_STRLEN_P(zhost
)) {
92 size_t stop_at
= strspn(Z_STRVAL_P(zhost
), "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.");
94 php_http_buffer_append(&buf
, Z_STRVAL_P(zhost
), stop_at
);
95 php_http_buffer_append(&buf
, "", 1);
97 char *host_str
= localhostname();
99 php_http_buffer_append(&buf
, host_str
, strlen(host_str
) + 1);
104 zport
= php_http_env_get_server_var(ZEND_STRL("SERVER_PORT"), 1);
105 if (zport
&& IS_LONG
== is_numeric_string(Z_STRVAL_P(zport
), Z_STRLEN_P(zport
), &port
, NULL
, 0)) {
106 url(buf
)->port
= port
;
110 if (SG(request_info
).request_uri
&& SG(request_info
).request_uri
[0]) {
111 const char *q
= strchr(SG(request_info
).request_uri
, '?');
113 url(buf
)->path
= &buf
.data
[buf
.used
];
116 php_http_buffer_append(&buf
, SG(request_info
).request_uri
, q
- SG(request_info
).request_uri
);
117 php_http_buffer_append(&buf
, "", 1);
119 php_http_buffer_append(&buf
, SG(request_info
).request_uri
, strlen(SG(request_info
).request_uri
) + 1);
124 if (SG(request_info
).query_string
&& SG(request_info
).query_string
[0]) {
125 url(buf
)->query
= &buf
.data
[buf
.used
];
126 php_http_buffer_append(&buf
, SG(request_info
).query_string
, strlen(SG(request_info
).query_string
) + 1);
132 #define url_isset(u,n) \
134 #define url_append(buf, append) do { \
135 char *_ptr = (buf)->data; \
136 php_http_url_t *_url = (php_http_url_t *) _ptr, _mem = *_url; \
139 if (_ptr != (buf)->data) { \
140 ptrdiff_t diff = (buf)->data - _ptr; \
141 _url = (php_http_url_t *) (buf)->data; \
142 if (_mem.scheme) _url->scheme += diff; \
143 if (_mem.user) _url->user += diff; \
144 if (_mem.pass) _url->pass += diff; \
145 if (_mem.host) _url->host += diff; \
146 if (_mem.path) _url->path += diff; \
147 if (_mem.query) _url->query += diff; \
148 if (_mem.fragment) _url->fragment += diff; \
151 #define url_copy(n) do { \
152 if (url_isset(new_url, n)) { \
153 url(buf)->n = &buf.data[buf.used]; \
154 url_append(&buf, php_http_buffer_append(&buf, new_url->n, strlen(new_url->n) + 1)); \
155 } else if (url_isset(old_url, n)) { \
156 url(buf)->n = &buf.data[buf.used]; \
157 url_append(&buf, php_http_buffer_append(&buf, old_url->n, strlen(old_url->n) + 1)); \
161 php_http_url_t
*php_http_url_mod(const php_http_url_t
*old_url
, const php_http_url_t
*new_url
, unsigned flags
)
163 php_http_url_t
*tmp_url
= NULL
;
164 php_http_buffer_t buf
;
166 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
167 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
168 memset(buf
.data
, 0, buf
.used
);
170 /* set from env if requested */
171 if (flags
& PHP_HTTP_URL_FROM_ENV
) {
172 php_http_url_t
*env_url
= php_http_url_from_env();
174 old_url
= tmp_url
= php_http_url_mod(env_url
, old_url
, flags
^ PHP_HTTP_URL_FROM_ENV
);
175 php_http_url_free(&env_url
);
180 if (!(flags
& PHP_HTTP_URL_STRIP_USER
)) {
184 if (!(flags
& PHP_HTTP_URL_STRIP_PASS
)) {
190 if (!(flags
& PHP_HTTP_URL_STRIP_PORT
)) {
191 url(buf
)->port
= url_isset(new_url
, port
) ? new_url
->port
: ((old_url
) ? old_url
->port
: 0);
194 if (!(flags
& PHP_HTTP_URL_STRIP_PATH
)) {
195 if ((flags
& PHP_HTTP_URL_JOIN_PATH
) && url_isset(old_url
, path
) && url_isset(new_url
, path
) && *new_url
->path
!= '/') {
196 size_t old_path_len
= strlen(old_url
->path
), new_path_len
= strlen(new_url
->path
);
197 char *path
= ecalloc(1, old_path_len
+ new_path_len
+ 1 + 1);
199 strcat(path
, old_url
->path
);
200 if (path
[old_path_len
- 1] != '/') {
201 php_dirname(path
, old_path_len
);
204 strcat(path
, new_url
->path
);
206 url(buf
)->path
= &buf
.data
[buf
.used
];
207 if (path
[0] != '/') {
208 url_append(&buf
, php_http_buffer_append(&buf
, "/", 1));
210 url_append(&buf
, php_http_buffer_append(&buf
, path
, strlen(path
) + 1));
213 const char *path
= NULL
;
215 if (url_isset(new_url
, path
)) {
216 path
= new_url
->path
;
217 } else if (url_isset(old_url
, path
)) {
218 path
= old_url
->path
;
222 url(buf
)->path
= &buf
.data
[buf
.used
];
224 url_append(&buf
, php_http_buffer_append(&buf
, path
, strlen(path
) + 1));
231 if (!(flags
& PHP_HTTP_URL_STRIP_QUERY
)) {
232 if ((flags
& PHP_HTTP_URL_JOIN_QUERY
) && url_isset(new_url
, query
) && url_isset(old_url
, query
)) {
237 ZVAL_STRING(&qstr
, old_url
->query
);
238 php_http_querystring_update(&qarr
, &qstr
, NULL
);
239 zval_ptr_dtor(&qstr
);
240 ZVAL_STRING(&qstr
, new_url
->query
);
241 php_http_querystring_update(&qarr
, &qstr
, NULL
);
242 zval_ptr_dtor(&qstr
);
245 php_http_querystring_update(&qarr
, NULL
, &qstr
);
247 url(buf
)->query
= &buf
.data
[buf
.used
];
248 url_append(&buf
, php_http_buffer_append(&buf
, Z_STRVAL(qstr
), Z_STRLEN(qstr
) + 1));
257 if (!(flags
& PHP_HTTP_URL_STRIP_FRAGMENT
)) {
261 /* done with copy & combine & strip */
263 if (flags
& PHP_HTTP_URL_FROM_ENV
) {
264 /* free old_url we tainted above */
265 php_http_url_free(&tmp_url
);
268 /* replace directory references if path is not a single slash */
269 if ((flags
& PHP_HTTP_URL_SANITIZE_PATH
)
271 && url(buf
)->path
[0] && url(buf
)->path
[1]) {
272 char *ptr
, *end
= url(buf
)->path
+ strlen(url(buf
)->path
) + 1;
274 for (ptr
= strchr(url(buf
)->path
, '/'); ptr
; ptr
= strchr(ptr
, '/')) {
277 memmove(&ptr
[1], &ptr
[2], end
- &ptr
[2]);
287 memmove(&ptr
[1], &ptr
[3], end
- &ptr
[3]);
293 while (ptr
!= url(buf
)->path
) {
298 memmove(&ptr
[1], pos
, end
- pos
);
300 } else if (!ptr
[3]) {
319 /* unset default ports */
320 if (url(buf
)->port
) {
321 if ( ((url(buf
)->port
== 80) && url(buf
)->scheme
&& !strcmp(url(buf
)->scheme
, "http"))
322 || ((url(buf
)->port
==443) && url(buf
)->scheme
&& !strcmp(url(buf
)->scheme
, "https"))
331 char *php_http_url_to_string(const php_http_url_t
*url
, char **url_str
, size_t *url_len
, zend_bool persistent
)
333 php_http_buffer_t buf
;
335 php_http_buffer_init_ex(&buf
, PHP_HTTP_BUFFER_DEFAULT_SIZE
, persistent
?
336 PHP_HTTP_BUFFER_INIT_PERSISTENT
: 0);
338 if (url
->scheme
&& *url
->scheme
) {
339 php_http_buffer_appendl(&buf
, url
->scheme
);
340 php_http_buffer_appends(&buf
, "://");
341 } else if ((url
->user
&& *url
->user
) || (url
->host
&& *url
->host
)) {
342 php_http_buffer_appends(&buf
, "//");
345 if (url
->user
&& *url
->user
) {
346 php_http_buffer_appendl(&buf
, url
->user
);
347 if (url
->pass
&& *url
->pass
) {
348 php_http_buffer_appends(&buf
, ":");
349 php_http_buffer_appendl(&buf
, url
->pass
);
351 php_http_buffer_appends(&buf
, "@");
354 if (url
->host
&& *url
->host
) {
355 php_http_buffer_appendl(&buf
, url
->host
);
357 php_http_buffer_appendf(&buf
, ":%hu", url
->port
);
361 if (url
->path
&& *url
->path
) {
362 if (*url
->path
!= '/') {
363 php_http_buffer_appends(&buf
, "/");
365 php_http_buffer_appendl(&buf
, url
->path
);
366 } else if (buf
.used
) {
367 php_http_buffer_appends(&buf
, "/");
370 if (url
->query
&& *url
->query
) {
371 php_http_buffer_appends(&buf
, "?");
372 php_http_buffer_appendl(&buf
, url
->query
);
375 if (url
->fragment
&& *url
->fragment
) {
376 php_http_buffer_appends(&buf
, "#");
377 php_http_buffer_appendl(&buf
, url
->fragment
);
380 php_http_buffer_shrink(&buf
);
381 php_http_buffer_fix(&buf
);
394 char *php_http_url_authority_to_string(const php_http_url_t
*url
, char **url_str
, size_t *url_len
)
396 php_http_buffer_t buf
;
398 php_http_buffer_init(&buf
);
400 if (url
->user
&& *url
->user
) {
401 php_http_buffer_appendl(&buf
, url
->user
);
402 if (url
->pass
&& *url
->pass
) {
403 php_http_buffer_appends(&buf
, ":");
404 php_http_buffer_appendl(&buf
, url
->pass
);
406 php_http_buffer_appends(&buf
, "@");
409 if (url
->host
&& *url
->host
) {
410 php_http_buffer_appendl(&buf
, url
->host
);
412 php_http_buffer_appendf(&buf
, ":%hu", url
->port
);
416 php_http_buffer_shrink(&buf
);
417 php_http_buffer_fix(&buf
);
430 php_http_url_t
*php_http_url_from_zval(zval
*value
, unsigned flags
)
433 php_http_url_t
*purl
;
435 switch (Z_TYPE_P(value
)) {
438 purl
= php_http_url_from_struct(HASH_OF(value
));
442 zs
= zval_get_string(value
);
443 purl
= php_http_url_parse(zs
->val
, zs
->len
, flags
);
444 zend_string_release(zs
);
450 php_http_url_t
*php_http_url_from_struct(HashTable
*ht
)
453 php_http_buffer_t buf
;
455 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
456 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
457 memset(buf
.data
, 0, buf
.used
);
459 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("scheme")))) {
460 zend_string
*zs
= zval_get_string(e
);
461 url(buf
)->scheme
= &buf
.data
[buf
.used
];
462 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
463 zend_string_release(zs
);
465 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("user")))) {
466 zend_string
*zs
= zval_get_string(e
);
467 url(buf
)->user
= &buf
.data
[buf
.used
];
468 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
469 zend_string_release(zs
);
471 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("pass")))) {
472 zend_string
*zs
= zval_get_string(e
);
473 url(buf
)->pass
= &buf
.data
[buf
.used
];
474 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
475 zend_string_release(zs
);
477 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("host")))) {
478 zend_string
*zs
= zval_get_string(e
);
479 url(buf
)->host
= &buf
.data
[buf
.used
];
480 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
481 zend_string_release(zs
);
483 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("port")))) {
484 url(buf
)->port
= (unsigned short) zval_get_long(e
);
486 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("path")))) {
487 zend_string
*zs
= zval_get_string(e
);
488 url(buf
)->path
= &buf
.data
[buf
.used
];
489 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
490 zend_string_release(zs
);
492 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("query")))) {
493 zend_string
*zs
= zval_get_string(e
);
494 url(buf
)->query
= &buf
.data
[buf
.used
];
495 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
496 zend_string_release(zs
);
498 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("fragment")))) {
499 zend_string
*zs
= zval_get_string(e
);
500 url(buf
)->fragment
= &buf
.data
[buf
.used
];
501 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
502 zend_string_release(zs
);
508 HashTable
*php_http_url_to_struct(const php_http_url_t
*url
, zval
*strct
)
510 HashTable
*ht
= NULL
;
514 switch (Z_TYPE_P(strct
)) {
526 zend_hash_init(ht
, 8, NULL
, ZVAL_PTR_DTOR
, 0);
529 #define url_struct_add(part) \
530 if (!strct || Z_TYPE_P(strct) == IS_ARRAY) { \
531 zend_hash_str_update(ht, part, lenof(part), &tmp); \
533 zend_update_property(Z_OBJCE_P(strct), strct, part, lenof(part), &tmp); \
534 zval_ptr_dtor(&tmp); \
539 ZVAL_STRING(&tmp
, url
->scheme
);
540 url_struct_add("scheme");
543 ZVAL_STRING(&tmp
, url
->user
);
544 url_struct_add("user");
547 ZVAL_STRING(&tmp
, url
->pass
);
548 url_struct_add("pass");
551 ZVAL_STRING(&tmp
, url
->host
);
552 url_struct_add("host");
555 ZVAL_LONG(&tmp
, url
->port
);
556 url_struct_add("port");
559 ZVAL_STRING(&tmp
, url
->path
);
560 url_struct_add("path");
563 ZVAL_STRING(&tmp
, url
->query
);
564 url_struct_add("query");
567 ZVAL_STRING(&tmp
, url
->fragment
);
568 url_struct_add("fragment");
575 ZEND_RESULT_CODE
php_http_url_encode_hash(HashTable
*hash
, const char *pre_encoded_str
, size_t pre_encoded_len
, char **encoded_str
, size_t *encoded_len
)
577 const char *arg_sep_str
= "&";
578 size_t arg_sep_len
= 1;
579 php_http_buffer_t
*qstr
= php_http_buffer_new();
581 php_http_url_argsep(&arg_sep_str
, &arg_sep_len
);
583 if (SUCCESS
!= php_http_url_encode_hash_ex(hash
, qstr
, arg_sep_str
, arg_sep_len
, "=", 1, pre_encoded_str
, pre_encoded_len
)) {
584 php_http_buffer_free(&qstr
);
588 php_http_buffer_data(qstr
, encoded_str
, encoded_len
);
589 php_http_buffer_free(&qstr
);
594 ZEND_RESULT_CODE
php_http_url_encode_hash_ex(HashTable
*hash
, php_http_buffer_t
*qstr
, const char *arg_sep_str
, size_t arg_sep_len
, const char *val_sep_str
, size_t val_sep_len
, const char *pre_encoded_str
, size_t pre_encoded_len
)
596 if (pre_encoded_len
&& pre_encoded_str
) {
597 php_http_buffer_append(qstr
, pre_encoded_str
, pre_encoded_len
);
600 if (!php_http_params_to_string(qstr
, hash
, arg_sep_str
, arg_sep_len
, "", 0, val_sep_str
, val_sep_len
, PHP_HTTP_PARAMS_QUERY
)) {
614 char buffer
[1]; /* last member */
617 void php_http_url_free(php_http_url_t
**url
)
625 php_http_url_t
*php_http_url_copy(const php_http_url_t
*url
, zend_bool persistent
)
628 const char *end
= NULL
, *url_ptr
= (const char *) url
;
631 end
= MAX(url
->scheme
, end
);
632 end
= MAX(url
->pass
, end
);
633 end
= MAX(url
->user
, end
);
634 end
= MAX(url
->host
, end
);
635 end
= MAX(url
->path
, end
);
636 end
= MAX(url
->query
, end
);
637 end
= MAX(url
->fragment
, end
);
640 end
+= strlen(end
) + 1;
641 cpy_ptr
= pecalloc(1, end
- url_ptr
, persistent
);
642 cpy
= (php_http_url_t
*) cpy_ptr
;
644 memcpy(cpy_ptr
+ sizeof(*cpy
), url_ptr
+ sizeof(*url
), end
- url_ptr
- sizeof(*url
));
646 cpy
->scheme
= url
->scheme
? cpy_ptr
+ (url
->scheme
- url_ptr
) : NULL
;
647 cpy
->pass
= url
->pass
? cpy_ptr
+ (url
->pass
- url_ptr
) : NULL
;
648 cpy
->user
= url
->user
? cpy_ptr
+ (url
->user
- url_ptr
) : NULL
;
649 cpy
->host
= url
->host
? cpy_ptr
+ (url
->host
- url_ptr
) : NULL
;
650 cpy
->path
= url
->path
? cpy_ptr
+ (url
->path
- url_ptr
) : NULL
;
651 cpy
->query
= url
->query
? cpy_ptr
+ (url
->query
- url_ptr
) : NULL
;
652 cpy
->fragment
= url
->fragment
? cpy_ptr
+ (url
->fragment
- url_ptr
) : NULL
;
654 cpy
= ecalloc(1, sizeof(*url
));
657 cpy
->port
= url
->port
;
662 static size_t parse_mb_utf8(unsigned *wc
, const char *ptr
, const char *end
)
665 size_t consumed
= utf8towc(&wchar
, (const unsigned char *) ptr
, end
- ptr
);
667 if (!consumed
|| consumed
== (size_t) -1) {
677 #ifdef PHP_HTTP_HAVE_WCHAR
678 static size_t parse_mb_loc(unsigned *wc
, const char *ptr
, const char *end
)
682 #if defined(HAVE_MBRTOWC)
685 memset(&ps
, 0, sizeof(ps
));
686 consumed
= mbrtowc(&wchar
, ptr
, end
- ptr
, &ps
);
687 #elif defined(HAVE_MBTOWC)
688 consumed
= mbtowc(&wchar
, ptr
, end
- ptr
);
691 if (!consumed
|| consumed
== (size_t) -1) {
702 typedef enum parse_mb_what
{
711 static const char * const parse_what
[] = {
720 static const char parse_xdigits
[] = "0123456789ABCDEF";
722 static size_t parse_mb(struct parse_state
*state
, parse_mb_what_t what
, const char *ptr
, const char *end
, const char *begin
, zend_bool silent
)
727 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
728 consumed
= parse_mb_utf8(&wchar
, ptr
, end
);
730 #ifdef PHP_HTTP_HAVE_WCHAR
731 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
732 consumed
= parse_mb_loc(&wchar
, ptr
, end
);
737 if (!(state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) || what
== PARSE_HOSTINFO
|| what
== PARSE_SCHEME
) {
738 if (what
== PARSE_HOSTINFO
&& (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
)) {
740 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
741 if (!isualnum(wchar
)) {
744 #ifdef PHP_HTTP_HAVE_WCHAR
745 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
746 if (!iswalnum(wchar
)) {
751 PHP_HTTP_DUFF(consumed
, state
->buffer
[state
->offset
++] = *ptr
++);
755 PHP_HTTP_DUFF(consumed
,
756 state
->buffer
[state
->offset
++] = '%';
757 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) >> 4];
758 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) & 0xf];
768 php_error_docref(NULL
, E_WARNING
,
769 "Failed to parse %s; unexpected multibyte sequence 0x%x at pos %u in '%s'",
770 parse_what
[what
], wchar
, (unsigned) (ptr
- begin
), begin
);
772 php_error_docref(NULL
, E_WARNING
,
773 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
774 parse_what
[what
], (unsigned char) *ptr
, (unsigned) (ptr
- begin
), begin
);
781 static ZEND_RESULT_CODE
parse_userinfo(struct parse_state
*state
, const char *ptr
)
784 const char *password
= NULL
, *end
= state
->ptr
, *tmp
= ptr
;
786 state
->url
.user
= &state
->buffer
[state
->offset
];
792 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
793 php_error_docref(NULL
, E_WARNING
,
794 "Failed to parse password; duplicate ':' at pos %u in '%s'",
795 (unsigned) (ptr
- tmp
), tmp
);
797 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
800 state
->buffer
[state
->offset
++] = *ptr
;
804 state
->buffer
[state
->offset
++] = 0;
805 state
->url
.pass
= &state
->buffer
[state
->offset
];
809 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
810 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
811 php_error_docref(NULL
, E_WARNING
,
812 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
813 (unsigned) (ptr
- tmp
), tmp
);
815 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
818 state
->buffer
[state
->offset
++] = *ptr
++;
821 state
->buffer
[state
->offset
++] = *ptr
++;
822 state
->buffer
[state
->offset
++] = *ptr
++;
823 state
->buffer
[state
->offset
++] = *ptr
;
827 if ((mb
= parse_mb(state
, PARSE_USERINFO
, ptr
, end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
831 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
835 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
836 case '+': case ',': case ';': case '=': /* sub-delims */
837 case '-': case '.': case '_': case '~': /* unreserved */
838 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
839 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
840 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
841 case 'V': case 'W': case 'X': case 'Y': case 'Z':
842 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
843 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
844 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
845 case 'v': case 'w': case 'x': case 'y': case 'z':
846 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
847 case '7': case '8': case '9':
849 state
->buffer
[state
->offset
++] = *ptr
;
853 } while(++ptr
!= end
);
856 state
->buffer
[state
->offset
++] = 0;
861 #if defined(PHP_WIN32) || defined(HAVE_UIDNA_IDNTOASCII)
862 typedef size_t (*parse_mb_func
)(unsigned *wc
, const char *ptr
, const char *end
);
863 static ZEND_RESULT_CODE
to_utf16(parse_mb_func fn
, const char *u8
, uint16_t **u16
, size_t *len
)
865 size_t offset
= 0, u8_len
= strlen(u8
);
867 *u16
= ecalloc(4 * sizeof(uint16_t), u8_len
+ 1);
870 while (offset
< u8_len
) {
872 uint16_t buf
[2], *ptr
= buf
;
873 size_t consumed
= fn(&wc
, &u8
[offset
], &u8
[u8_len
]);
877 php_error_docref(NULL
, E_WARNING
, "Failed to parse UTF-8 at pos %zu of '%s'", offset
, u8
);
883 switch (wctoutf16(buf
, wc
)) {
885 (*u16
)[(*len
)++] = *ptr
++;
888 (*u16
)[(*len
)++] = *ptr
++;
893 php_error_docref(NULL
, E_WARNING
, "Failed to convert UTF-32 'U+%X' to UTF-16", wc
);
902 #ifndef MAXHOSTNAMELEN
903 # define MAXHOSTNAMELEN 256
906 #if PHP_HTTP_HAVE_LIBIDN2
907 static ZEND_RESULT_CODE
parse_gidn_2008(struct parse_state
*state
, size_t prev_len
)
912 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
913 rv
= idn2_lookup_u8((const unsigned char *) state
->url
.host
, (unsigned char **) &idn
, IDN2_NFC_INPUT
);
915 # ifdef PHP_HTTP_HAVE_WCHAR
916 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
917 rv
= idn2_lookup_ul(state
->url
.host
, &idn
, 0);
921 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
922 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (IDNA2008); %s", idn2_strerror(rv
));
924 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
928 size_t idnlen
= strlen(idn
);
929 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
931 state
->offset
+= idnlen
- prev_len
;
937 #if PHP_HTTP_HAVE_LIBIDN
938 static ZEND_RESULT_CODE
parse_gidn_2003(struct parse_state
*state
, size_t prev_len
)
943 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
944 rv
= idna_to_ascii_8z(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
|IDNA_USE_STD3_ASCII_RULES
);
946 # ifdef PHP_HTTP_HAVE_WCHAR
947 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
948 rv
= idna_to_ascii_lz(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
|IDNA_USE_STD3_ASCII_RULES
);
951 if (rv
!= IDNA_SUCCESS
) {
952 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
953 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (IDNA2003); %s", idna_strerror(rv
));
955 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
959 size_t idnlen
= strlen(idn
);
960 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
962 state
->offset
+= idnlen
- prev_len
;
968 #ifdef HAVE_UIDNA_IDNTOASCII
969 # if PHP_HTTP_HAVE_LIBICU
970 # include <unicode/uidna.h>
972 typedef uint16_t UChar
;
973 typedef enum { U_ZERO_ERROR
= 0 } UErrorCode
;
974 int32_t uidna_IDNToASCII(const UChar
*src
, int32_t srcLength
, UChar
*dest
, int32_t destCapacity
, int32_t options
, void *parseError
, UErrorCode
*status
);
976 static ZEND_RESULT_CODE
parse_uidn_2003(struct parse_state
*state
)
978 char *host_ptr
= state
->url
.host
, ebuf
[64] = {0}, *error
= NULL
;
979 uint16_t *uhost_str
, ahost_str
[MAXHOSTNAMELEN
], *ahost_ptr
;
980 size_t uhost_len
, ahost_len
;
981 UErrorCode rc
= U_ZERO_ERROR
;
983 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
984 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
985 error
= "failed to convert to UTF-16";
988 #ifdef PHP_HTTP_HAVE_WCHAR
989 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
990 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
991 error
= "failed to convert to UTF-16";
996 error
= "codepage not specified";
1000 ahost_len
= uidna_IDNToASCII(uhost_str
, uhost_len
, ahost_str
, MAXHOSTNAMELEN
, 3, NULL
, &rc
);
1003 if (error
> U_ZERO_ERROR
) {
1007 ahost_ptr
= ahost_str
;
1008 PHP_HTTP_DUFF(ahost_len
, *host_ptr
++ = *ahost_ptr
++);
1010 state
->offset
+= host_ptr
- state
->url
.host
;
1016 slprintf(ebuf
, sizeof(ebuf
)-1, "errorcode: %d", rc
);
1019 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2003); %s", error
);
1025 #ifdef HAVE_UIDNA_IDNTOASCII
1026 # if PHP_HTTP_HAVE_LIBICU
1027 # include <unicode/uidna.h>
1029 static ZEND_RESULT_CODE
parse_uidn_2008(struct parse_state
*state
)
1031 char *host_ptr
, *error
= NULL
, ebuf
[64] = {0};
1032 UErrorCode rc
= U_ZERO_ERROR
;
1033 UIDNAInfo info
= UIDNA_INFO_INITIALIZER
;
1034 UIDNA
*uidna
= uidna_openUTS46(UIDNA_ALLOW_UNASSIGNED
|UIDNA_USE_STD3_RULES
, &rc
);
1036 if (!uidna
|| U_FAILURE(rc
)) {
1040 host_ptr
= state
->url
.host
;
1042 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1043 char ahost_str
[MAXHOSTNAMELEN
], *ahost_ptr
= &ahost_str
[0];
1044 size_t ahost_len
= uidna_nameToASCII_UTF8(uidna
, host_ptr
, -1, ahost_str
, sizeof(ahost_str
)-1, &info
, &rc
);
1046 if (U_FAILURE(rc
) || info
.errors
) {
1049 PHP_HTTP_DUFF(ahost_len
, *host_ptr
++ = *ahost_ptr
++);
1050 #ifdef PHP_HTTP_HAVE_WCHAR
1051 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1052 uint16_t *uhost_str
, whost_str
[MAXHOSTNAMELEN
], *whost_ptr
= &whost_str
[0];
1053 size_t uhost_len
, whost_len
;
1055 if (SUCCESS
!= to_utf16(parse_mb_loc
, host_ptr
, &uhost_str
, &uhost_len
)) {
1056 error
= "could not convert to UTF-16";
1060 whost_len
= uidna_nameToASCII(uidna
, uhost_str
, uhost_len
, whost_str
, sizeof(whost_str
)-1, &info
, &rc
);
1061 whost_ptr
= whost_str
;
1062 if (U_FAILURE(rc
) || info
.errors
) {
1065 PHP_HTTP_DUFF(whost_len
, *host_ptr
++ = *whost_ptr
++);
1068 error
= "codepage not specified";
1073 state
->offset
+= host_ptr
- state
->url
.host
;
1080 if (U_FAILURE(rc
)) {
1081 slprintf(ebuf
, sizeof(ebuf
)-1, "%s", u_errorName(rc
));
1083 } else if (info
.errors
) {
1084 slprintf(ebuf
, sizeof(ebuf
)-1, "ICU IDNA error codes: 0x%x", info
.errors
);
1087 error
= "unknown error";
1090 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2008); %s", error
);
1097 #if 0 && defined(PHP_WIN32)
1098 static ZEND_RESULT_CODE
parse_widn_2003(struct parse_state
*state
)
1101 uint16_t *uhost_str
, ahost_str
[MAXHOSTNAMELEN
], *ahost_ptr
;
1104 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1105 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1106 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1109 #ifdef PHP_HTTP_HAVE_WCHAR
1110 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1111 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1112 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1117 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1121 if (!IdnToAscii(IDN_ALLOW_UNASSIGNED
|IDN_USE_STD3_ASCII_RULES
, uhost_str
, uhost_len
, ahost_str
, MAXHOSTNAMELEN
)) {
1123 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1128 host_ptr
= state
->url
.host
;
1129 ahost_ptr
= ahost_str
;
1130 PHP_HTTP_DUFF(wcslen(ahost_str
), *host_ptr
++ = *ahost_ptr
++);
1134 state
->offset
+= host_ptr
- state
->url
.host
;
1140 static ZEND_RESULT_CODE
parse_idna(struct parse_state
*state
, size_t len
)
1142 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
)
1143 || !(state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
)
1145 #if HAVE_UIDNA_NAMETOASCII_UTF8
1146 return parse_uidn_2008(state
);
1147 #elif PHP_HTTP_HAVE_LIBIDN2
1148 return parse_gidn_2008(state
, len
);
1152 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
)
1153 || !(state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
)
1155 #if HAVE_UIDNA_IDNTOASCII
1156 return parse_uidn_2003(state
);
1157 #elif PHP_HTTP_HAVE_LIBIDN
1158 return parse_gidn_2003(state
, len
);
1162 #if 0 && defined(PHP_WIN32)
1163 return parse_widn_2003(state
);
1166 #if HAVE_UIDNA_NAMETOASCII_UTF8
1167 return parse_uidn_2008(state
);
1168 #elif PHP_HTTP_HAVE_LIBIDN2
1169 return parse_gidn_2008(state
, len
);
1170 #elif HAVE_UIDNA_IDNTOASCII
1171 return parse_uidn_2003(state
);
1172 #elif PHP_HTTP_HAVE_LIBIDN
1173 return parse_gidn_2003(state
, len
);
1179 #ifdef HAVE_INET_PTON
1180 static const char *parse_ip6(struct parse_state
*state
, const char *ptr
)
1183 const char *error
= NULL
, *end
= state
->ptr
, *tmp
= memchr(ptr
, ']', end
- ptr
);
1186 size_t addrlen
= tmp
- ptr
+ 1;
1187 char buf
[16], *addr
= estrndup(ptr
+ 1, addrlen
- 2);
1188 int rv
= inet_pton(AF_INET6
, addr
, buf
);
1191 state
->buffer
[state
->offset
] = '[';
1192 state
->url
.host
= &state
->buffer
[state
->offset
];
1193 inet_ntop(AF_INET6
, buf
, state
->url
.host
+ 1, state
->maxlen
- state
->offset
);
1194 state
->offset
+= strlen(state
->url
.host
);
1195 state
->buffer
[state
->offset
++] = ']';
1196 state
->buffer
[state
->offset
++] = 0;
1198 } else if (rv
== -1) {
1200 error
= strerror(errno
);
1202 error
= "unexpected '['";
1207 error
= "expected ']'";
1211 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1212 php_error_docref(NULL
, E_WARNING
, "Failed to parse hostinfo; %s at pos %u in '%s'", error
, pos
, ptr
);
1221 static ZEND_RESULT_CODE
parse_hostinfo(struct parse_state
*state
, const char *ptr
)
1223 size_t mb
, len
= state
->offset
;
1224 const char *end
= state
->ptr
, *tmp
= ptr
, *port
= NULL
, *label
= NULL
;
1226 #ifdef HAVE_INET_PTON
1227 if (*ptr
== '[' && !(ptr
= parse_ip6(state
, ptr
))) {
1228 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1235 if (ptr
!= end
) do {
1239 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1240 php_error_docref(NULL
, E_WARNING
,
1241 "Failed to parse port; unexpected ':' at pos %u in '%s'",
1242 (unsigned) (ptr
- tmp
), tmp
);
1244 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1252 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
1253 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1254 php_error_docref(NULL
, E_WARNING
,
1255 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
1256 (unsigned) (ptr
- tmp
), tmp
);
1258 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1261 state
->buffer
[state
->offset
++] = *ptr
++;
1264 state
->buffer
[state
->offset
++] = *ptr
++;
1265 state
->buffer
[state
->offset
++] = *ptr
++;
1266 state
->buffer
[state
->offset
++] = *ptr
;
1270 if (port
|| !label
) {
1271 /* sort of a compromise, just ensure we don't end up
1272 * with a dot at the beginning or two consecutive dots
1274 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1275 php_error_docref(NULL
, E_WARNING
,
1276 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1277 port
? "port" : "host",
1278 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1280 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1285 state
->buffer
[state
->offset
++] = *ptr
;
1291 /* sort of a compromise, just ensure we don't end up
1292 * with a hyphen at the beginning
1294 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1295 php_error_docref(NULL
, E_WARNING
,
1296 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1297 port
? "port" : "host",
1298 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1300 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1306 case '_': case '~': /* unreserved */
1307 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1308 case '+': case ',': case ';': case '=': /* sub-delims */
1309 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1310 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1311 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1312 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1313 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1314 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1315 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1316 case 'v': case 'w': case 'x': case 'y': case 'z':
1318 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1319 php_error_docref(NULL
, E_WARNING
,
1320 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
1321 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1323 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1329 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1330 case '7': case '8': case '9':
1333 state
->url
.port
*= 10;
1334 state
->url
.port
+= *ptr
- '0';
1337 state
->buffer
[state
->offset
++] = *ptr
;
1345 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1346 php_error_docref(NULL
, E_WARNING
,
1347 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
1348 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1350 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1354 } else if (!(mb
= parse_mb(state
, PARSE_HOSTINFO
, ptr
, end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1355 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1363 } while (++ptr
!= end
);
1365 if (!state
->url
.host
) {
1366 len
= state
->offset
- len
;
1367 state
->url
.host
= &state
->buffer
[state
->offset
- len
];
1368 state
->buffer
[state
->offset
++] = 0;
1371 if (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
) {
1372 return parse_idna(state
, len
);
1378 static const char *parse_authority(struct parse_state
*state
)
1380 const char *tmp
= state
->ptr
, *host
= NULL
;
1383 switch (*state
->ptr
) {
1385 /* userinfo delimiter */
1387 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1388 php_error_docref(NULL
, E_WARNING
,
1389 "Failed to parse userinfo; unexpected '@'");
1391 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1396 host
= state
->ptr
+ 1;
1397 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_userinfo(state
, tmp
)) {
1400 tmp
= state
->ptr
+ 1;
1408 /* host delimiter */
1409 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_hostinfo(state
, tmp
)) {
1414 } while (++state
->ptr
<= state
->end
);
1420 static const char *parse_path(struct parse_state
*state
)
1425 /* is there actually a path to parse? */
1430 state
->url
.path
= &state
->buffer
[state
->offset
];
1433 switch (*state
->ptr
) {
1439 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1440 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1441 php_error_docref(NULL
, E_WARNING
,
1442 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
1443 (unsigned) (state
->ptr
- tmp
), tmp
);
1445 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1448 state
->buffer
[state
->offset
++] = *state
->ptr
;
1451 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1452 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1453 state
->buffer
[state
->offset
++] = *state
->ptr
;
1456 case '/': /* yeah, well */
1457 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1458 case '+': case ',': case ';': case '=': /* sub-delims */
1459 case '-': case '.': case '_': case '~': /* unreserved */
1460 case ':': case '@': /* pchar */
1461 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1462 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1463 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1464 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1465 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1466 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1467 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1468 case 'v': case 'w': case 'x': case 'y': case 'z':
1469 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1470 case '7': case '8': case '9':
1472 state
->buffer
[state
->offset
++] = *state
->ptr
;
1476 if (!(mb
= parse_mb(state
, PARSE_PATH
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1477 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1482 state
->ptr
+= mb
- 1;
1484 } while (++state
->ptr
< state
->end
);
1487 /* did we have any path component ? */
1488 if (tmp
!= state
->ptr
) {
1489 state
->buffer
[state
->offset
++] = 0;
1491 state
->url
.path
= NULL
;
1496 static const char *parse_query(struct parse_state
*state
)
1499 const char *tmp
= state
->ptr
+ !!*state
->ptr
;
1501 /* is there actually a query to parse? */
1502 if (*state
->ptr
!= '?') {
1506 /* skip initial '?' */
1508 state
->url
.query
= &state
->buffer
[state
->offset
];
1510 while (state
->ptr
< state
->end
) {
1511 switch (*state
->ptr
) {
1516 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1517 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1518 php_error_docref(NULL
, E_WARNING
,
1519 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
1520 (unsigned) (state
->ptr
- tmp
), tmp
);
1522 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1525 /* fallthrough, pct-encode the percent sign */
1527 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1528 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1529 state
->buffer
[state
->offset
++] = *state
->ptr
;
1536 case '|': case '\\': case '^': case '`': case '"': case ' ':
1537 /* RFC1738 unsafe */
1538 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1539 state
->buffer
[state
->offset
++] = '%';
1540 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1541 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1546 case '?': case '/': /* yeah, well */
1547 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1548 case '+': case ',': case ';': case '=': /* sub-delims */
1549 case '-': case '.': case '_': case '~': /* unreserved */
1550 case ':': case '@': /* pchar */
1551 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1552 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1553 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1554 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1555 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1556 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1557 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1558 case 'v': case 'w': case 'x': case 'y': case 'z':
1559 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1560 case '7': case '8': case '9':
1562 state
->buffer
[state
->offset
++] = *state
->ptr
;
1566 if (!(mb
= parse_mb(state
, PARSE_QUERY
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1567 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1572 state
->ptr
+= mb
- 1;
1579 state
->buffer
[state
->offset
++] = 0;
1583 static const char *parse_fragment(struct parse_state
*state
)
1588 /* is there actually a fragment to parse? */
1589 if (*state
->ptr
!= '#') {
1593 /* skip initial '#' */
1595 state
->url
.fragment
= &state
->buffer
[state
->offset
];
1598 switch (*state
->ptr
) {
1600 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1601 php_error_docref(NULL
, E_WARNING
,
1602 "Failed to parse fragment; invalid fragment identifier at pos %u in '%s'",
1603 (unsigned) (state
->ptr
- tmp
), tmp
);
1605 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1608 state
->buffer
[state
->offset
++] = *state
->ptr
;
1612 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1613 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1614 php_error_docref(NULL
, E_WARNING
,
1615 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
1616 (unsigned) (state
->ptr
- tmp
), tmp
);
1618 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1623 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1624 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1625 state
->buffer
[state
->offset
++] = *state
->ptr
;
1633 case '|': case '\\': case '^': case '`': case '"': case ' ':
1634 /* RFC1738 unsafe */
1635 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1636 state
->buffer
[state
->offset
++] = '%';
1637 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1638 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1644 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1645 case '+': case ',': case ';': case '=': /* sub-delims */
1646 case '-': case '.': case '_': case '~': /* unreserved */
1647 case ':': case '@': /* pchar */
1648 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1649 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1650 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1651 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1652 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1653 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1654 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1655 case 'v': case 'w': case 'x': case 'y': case 'z':
1656 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1657 case '7': case '8': case '9':
1659 state
->buffer
[state
->offset
++] = *state
->ptr
;
1663 if (!(mb
= parse_mb(state
, PARSE_FRAGMENT
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1664 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1669 state
->ptr
+= mb
- 1;
1671 } while (++state
->ptr
< state
->end
);
1673 state
->buffer
[state
->offset
++] = 0;
1677 static const char *parse_hier(struct parse_state
*state
)
1679 if (*state
->ptr
== '/') {
1680 if (state
->end
- state
->ptr
> 1) {
1681 if (*(state
->ptr
+ 1) == '/') {
1683 if (!(state
->ptr
= parse_authority(state
))) {
1689 return parse_path(state
);
1692 static const char *parse_scheme(struct parse_state
*state
)
1695 const char *tmp
= state
->ptr
;
1698 switch (*state
->ptr
) {
1700 /* scheme delimiter */
1701 state
->url
.scheme
= &state
->buffer
[0];
1702 state
->buffer
[state
->offset
++] = 0;
1703 return ++state
->ptr
;
1705 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1706 case '7': case '8': case '9':
1707 case '+': case '-': case '.':
1708 if (state
->ptr
== tmp
) {
1712 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1713 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1714 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1715 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1716 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1717 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1718 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1719 case 'v': case 'w': case 'x': case 'y': case 'z':
1721 state
->buffer
[state
->offset
++] = *state
->ptr
;
1725 if (!(mb
= parse_mb(state
, PARSE_SCHEME
, state
->ptr
, state
->end
, tmp
, 1))) {
1728 state
->ptr
+= mb
- 1;
1730 } while (++state
->ptr
!= state
->end
);
1734 return state
->ptr
= tmp
;
1737 php_http_url_t
*php_http_url_parse(const char *str
, size_t len
, unsigned flags
)
1739 size_t maxlen
= 3 * len
+ 8 /* null bytes for all components */;
1740 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1742 state
->end
= str
+ len
;
1744 state
->flags
= flags
;
1745 state
->maxlen
= maxlen
;
1747 if (!parse_scheme(state
)) {
1748 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL scheme: '%s'", state
->ptr
);
1753 if (!parse_hier(state
)) {
1758 if (!parse_query(state
)) {
1759 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL query: '%s'", state
->ptr
);
1764 if (!parse_fragment(state
)) {
1765 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL fragment: '%s'", state
->ptr
);
1770 return (php_http_url_t
*) state
;
1773 php_http_url_t
*php_http_url_parse_authority(const char *str
, size_t len
, unsigned flags
)
1775 size_t maxlen
= 3 * len
;
1776 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1778 state
->end
= str
+ len
;
1780 state
->flags
= flags
;
1781 state
->maxlen
= maxlen
;
1783 if (!(state
->ptr
= parse_authority(state
))) {
1788 if (state
->ptr
!= state
->end
) {
1789 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1790 php_error_docref(NULL
, E_WARNING
,
1791 "Failed to parse URL authority, unexpected character at pos %u in '%s'",
1792 (unsigned) (state
->ptr
- str
), str
);
1794 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1800 return (php_http_url_t
*) state
;
1803 static zend_class_entry
*php_http_url_class_entry
;
1804 static zend_class_entry
*php_http_env_url_class_entry
;
1806 zend_class_entry
*php_http_url_get_class_entry(void)
1808 return php_http_url_class_entry
;
1811 zend_class_entry
*php_http_get_env_url_class_entry(void)
1813 return php_http_env_url_class_entry
;
1816 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct
, 0, 0, 0)
1817 ZEND_ARG_INFO(0, old_url
)
1818 ZEND_ARG_INFO(0, new_url
)
1819 ZEND_ARG_INFO(0, flags
)
1820 ZEND_END_ARG_INFO();
1821 PHP_METHOD(HttpUrl
, __construct
)
1823 zval
*new_url
= NULL
, *old_url
= NULL
;
1824 zend_long flags
= 0;
1825 zend_error_handling zeh
;
1827 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!z!l", &old_url
, &new_url
, &flags
), invalid_arg
, return);
1829 /* always set http\Url::FROM_ENV for instances of http\Env\Url */
1830 if (instanceof_function(Z_OBJCE_P(getThis()), php_http_env_url_class_entry
)) {
1831 flags
|= PHP_HTTP_URL_FROM_ENV
;
1834 if (flags
& PHP_HTTP_URL_SILENT_ERRORS
) {
1835 zend_replace_error_handling(EH_SUPPRESS
, NULL
, &zeh
);
1836 } else if (flags
& PHP_HTTP_URL_IGNORE_ERRORS
) {
1837 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1839 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1842 php_http_url_t
*res_purl
, *new_purl
= NULL
, *old_purl
= NULL
;
1845 new_purl
= php_http_url_from_zval(new_url
, flags
);
1847 zend_restore_error_handling(&zeh
);
1852 old_purl
= php_http_url_from_zval(old_url
, flags
);
1855 php_http_url_free(&new_purl
);
1857 zend_restore_error_handling(&zeh
);
1862 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1863 php_http_url_to_struct(res_purl
, getThis());
1865 php_http_url_free(&res_purl
);
1867 php_http_url_free(&old_purl
);
1870 php_http_url_free(&new_purl
);
1873 zend_restore_error_handling(&zeh
);
1876 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod
, 0, 0, 1)
1877 ZEND_ARG_INFO(0, more_url_parts
)
1878 ZEND_ARG_INFO(0, flags
)
1879 ZEND_END_ARG_INFO();
1880 PHP_METHOD(HttpUrl
, mod
)
1882 zval
*new_url
= NULL
;
1883 zend_long flags
= PHP_HTTP_URL_JOIN_PATH
| PHP_HTTP_URL_JOIN_QUERY
| PHP_HTTP_URL_SANITIZE_PATH
;
1884 zend_error_handling zeh
;
1886 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url
, &flags
), invalid_arg
, return);
1888 if (flags
& PHP_HTTP_URL_SILENT_ERRORS
) {
1889 zend_replace_error_handling(EH_SUPPRESS
, NULL
, &zeh
);
1890 } else if (flags
& PHP_HTTP_URL_IGNORE_ERRORS
) {
1891 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1893 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1896 php_http_url_t
*new_purl
= NULL
, *old_purl
= NULL
;
1899 new_purl
= php_http_url_from_zval(new_url
, flags
);
1901 zend_restore_error_handling(&zeh
);
1906 if ((old_purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1907 php_http_url_t
*res_purl
;
1909 ZVAL_OBJ(return_value
, zend_objects_clone_obj(getThis()));
1911 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1912 php_http_url_to_struct(res_purl
, return_value
);
1914 php_http_url_free(&res_purl
);
1915 php_http_url_free(&old_purl
);
1918 php_http_url_free(&new_purl
);
1921 zend_restore_error_handling(&zeh
);
1924 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString
, 0, 0, 0)
1925 ZEND_END_ARG_INFO();
1926 PHP_METHOD(HttpUrl
, toString
)
1928 if (SUCCESS
== zend_parse_parameters_none()) {
1929 php_http_url_t
*purl
;
1931 if ((purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1935 php_http_url_to_string(purl
, &str
, &len
, 0);
1936 php_http_url_free(&purl
);
1937 RETURN_STR(php_http_cs2zs(str
, len
));
1940 RETURN_EMPTY_STRING();
1943 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray
, 0, 0, 0)
1944 ZEND_END_ARG_INFO();
1945 PHP_METHOD(HttpUrl
, toArray
)
1947 php_http_url_t
*purl
;
1949 if (SUCCESS
!= zend_parse_parameters_none()) {
1953 /* strip any non-URL properties */
1954 purl
= php_http_url_from_struct(HASH_OF(getThis()));
1955 php_http_url_to_struct(purl
, return_value
);
1956 php_http_url_free(&purl
);
1959 static zend_function_entry php_http_url_methods
[] = {
1960 PHP_ME(HttpUrl
, __construct
, ai_HttpUrl___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
1961 PHP_ME(HttpUrl
, mod
, ai_HttpUrl_mod
, ZEND_ACC_PUBLIC
)
1962 PHP_ME(HttpUrl
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
1963 ZEND_MALIAS(HttpUrl
, __toString
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
1964 PHP_ME(HttpUrl
, toArray
, ai_HttpUrl_toArray
, ZEND_ACC_PUBLIC
)
1965 EMPTY_FUNCTION_ENTRY
1968 PHP_MINIT_FUNCTION(http_url
)
1970 zend_class_entry ce
= {0};
1972 INIT_NS_CLASS_ENTRY(ce
, "http", "Url", php_http_url_methods
);
1973 php_http_url_class_entry
= zend_register_internal_class(&ce
);
1975 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC
);
1976 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("user"), ZEND_ACC_PUBLIC
);
1977 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("pass"), ZEND_ACC_PUBLIC
);
1978 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("host"), ZEND_ACC_PUBLIC
);
1979 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("port"), ZEND_ACC_PUBLIC
);
1980 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("path"), ZEND_ACC_PUBLIC
);
1981 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("query"), ZEND_ACC_PUBLIC
);
1982 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC
);
1984 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE
);
1985 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH
);
1986 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY
);
1987 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER
);
1988 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS
);
1989 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH
);
1990 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT
);
1991 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH
);
1992 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY
);
1993 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT
);
1994 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL
);
1995 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV
);
1996 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH
);
1998 #ifdef PHP_HTTP_HAVE_WCHAR
1999 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC
);
2001 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8
);
2002 #if PHP_HTTP_HAVE_LIBIDN2 || PHP_HTTP_HAVE_LIBIDN || HAVE_UIDNA_IDNTOASCII || HAVE_UIDNA_NAMETOASCII_UTF8
2003 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN
);
2004 # if PHP_HTTP_HAVE_IDNA2003
2005 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2003"), PHP_HTTP_URL_PARSE_TOIDN_2003
);
2007 # if PHP_HTTP_HAVE_IDNA2008
2008 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2008"), PHP_HTTP_URL_PARSE_TOIDN_2008
);
2011 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT
);
2013 INIT_NS_CLASS_ENTRY(ce
, "http\\Env", "Url", php_http_url_methods
);
2014 php_http_env_url_class_entry
= zend_register_internal_class_ex(&ce
, php_http_url_class_entry
);
2016 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("IGNORE_ERRORS"), PHP_HTTP_URL_IGNORE_ERRORS
);
2017 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SILENT_ERRORS"), PHP_HTTP_URL_SILENT_ERRORS
);
2019 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STDFLAGS"), PHP_HTTP_URL_STDFLAGS
);
2030 * vim600: noet sw=4 ts=4 fdm=marker
2031 * vim<600: noet sw=4 ts=4