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>
24 #if PHP_HTTP_HAVE_LIBIDNKIT || PHP_HTTP_HAVE_LIBIDNKIT2
26 # include <idn/result.h>
29 #if PHP_HTTP_HAVE_WCHAR
35 # include <arpa/inet.h>
38 #include "php_http_utf8.h"
40 static inline char *localhostname(void)
42 char hostname
[1024] = {0};
45 if (SUCCESS
== gethostname(hostname
, lenof(hostname
))) {
46 return estrdup(hostname
);
48 #elif HAVE_GETHOSTNAME
49 if (SUCCESS
== gethostname(hostname
, lenof(hostname
))) {
50 # if HAVE_GETDOMAINNAME
51 size_t hlen
= strlen(hostname
);
52 if (hlen
<= lenof(hostname
) - lenof("(none)")) {
53 hostname
[hlen
++] = '.';
54 if (SUCCESS
== getdomainname(&hostname
[hlen
], lenof(hostname
) - hlen
)) {
55 if (!strcmp(&hostname
[hlen
], "(none)")) {
56 hostname
[hlen
- 1] = '\0';
58 return estrdup(hostname
);
62 if (strcmp(hostname
, "(none)")) {
63 return estrdup(hostname
);
67 return estrndup("localhost", lenof("localhost"));
70 #define url(buf) ((php_http_url_t *) (buf).data)
72 static php_http_url_t
*php_http_url_from_env(void)
74 zval
*https
, *zhost
, *zport
;
76 php_http_buffer_t buf
;
78 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
79 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
80 memset(buf
.data
, 0, buf
.used
);
83 url(buf
)->scheme
= &buf
.data
[buf
.used
];
84 https
= php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1);
85 if (https
&& !strcasecmp(Z_STRVAL_P(https
), "ON")) {
86 php_http_buffer_append(&buf
, "https", sizeof("https"));
88 php_http_buffer_append(&buf
, "http", sizeof("http"));
92 url(buf
)->host
= &buf
.data
[buf
.used
];
93 if ((((zhost
= php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1)) ||
94 (zhost
= php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1)) ||
95 (zhost
= php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1)))) && Z_STRLEN_P(zhost
)) {
96 size_t stop_at
= strspn(Z_STRVAL_P(zhost
), "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.");
98 php_http_buffer_append(&buf
, Z_STRVAL_P(zhost
), stop_at
);
99 php_http_buffer_append(&buf
, "", 1);
101 char *host_str
= localhostname();
103 php_http_buffer_append(&buf
, host_str
, strlen(host_str
) + 1);
108 zport
= php_http_env_get_server_var(ZEND_STRL("SERVER_PORT"), 1);
109 if (zport
&& IS_LONG
== is_numeric_string(Z_STRVAL_P(zport
), Z_STRLEN_P(zport
), &port
, NULL
, 0)) {
110 url(buf
)->port
= port
;
114 if (SG(request_info
).request_uri
&& SG(request_info
).request_uri
[0]) {
115 const char *q
= strchr(SG(request_info
).request_uri
, '?');
117 url(buf
)->path
= &buf
.data
[buf
.used
];
120 php_http_buffer_append(&buf
, SG(request_info
).request_uri
, q
- SG(request_info
).request_uri
);
121 php_http_buffer_append(&buf
, "", 1);
123 php_http_buffer_append(&buf
, SG(request_info
).request_uri
, strlen(SG(request_info
).request_uri
) + 1);
128 if (SG(request_info
).query_string
&& SG(request_info
).query_string
[0]) {
129 url(buf
)->query
= &buf
.data
[buf
.used
];
130 php_http_buffer_append(&buf
, SG(request_info
).query_string
, strlen(SG(request_info
).query_string
) + 1);
136 #define url_isset(u,n) \
138 #define url_append(buf, append) do { \
139 char *_ptr = (buf)->data; \
140 php_http_url_t *_url = (php_http_url_t *) _ptr, _mem = *_url; \
143 if (_ptr != (buf)->data) { \
144 ptrdiff_t diff = (buf)->data - _ptr; \
145 _url = (php_http_url_t *) (buf)->data; \
146 if (_mem.scheme) _url->scheme += diff; \
147 if (_mem.user) _url->user += diff; \
148 if (_mem.pass) _url->pass += diff; \
149 if (_mem.host) _url->host += diff; \
150 if (_mem.path) _url->path += diff; \
151 if (_mem.query) _url->query += diff; \
152 if (_mem.fragment) _url->fragment += diff; \
155 #define url_copy(n) do { \
156 if (url_isset(new_url, n)) { \
157 url(buf)->n = &buf.data[buf.used]; \
158 url_append(&buf, php_http_buffer_append(&buf, new_url->n, strlen(new_url->n) + 1)); \
159 } else if (url_isset(old_url, n)) { \
160 url(buf)->n = &buf.data[buf.used]; \
161 url_append(&buf, php_http_buffer_append(&buf, old_url->n, strlen(old_url->n) + 1)); \
165 php_http_url_t
*php_http_url_mod(const php_http_url_t
*old_url
, const php_http_url_t
*new_url
, unsigned flags
)
167 php_http_url_t
*tmp_url
= NULL
;
168 php_http_buffer_t buf
;
170 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
171 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
172 memset(buf
.data
, 0, buf
.used
);
174 /* set from env if requested */
175 if (flags
& PHP_HTTP_URL_FROM_ENV
) {
176 php_http_url_t
*env_url
= php_http_url_from_env();
178 old_url
= tmp_url
= php_http_url_mod(env_url
, old_url
, flags
^ PHP_HTTP_URL_FROM_ENV
);
179 php_http_url_free(&env_url
);
184 if (!(flags
& PHP_HTTP_URL_STRIP_USER
)) {
188 if (!(flags
& PHP_HTTP_URL_STRIP_PASS
)) {
194 if (!(flags
& PHP_HTTP_URL_STRIP_PORT
)) {
195 url(buf
)->port
= url_isset(new_url
, port
) ? new_url
->port
: ((old_url
) ? old_url
->port
: 0);
198 if (!(flags
& PHP_HTTP_URL_STRIP_PATH
)) {
199 if ((flags
& PHP_HTTP_URL_JOIN_PATH
) && url_isset(old_url
, path
) && url_isset(new_url
, path
) && *new_url
->path
!= '/') {
200 size_t old_path_len
= strlen(old_url
->path
), new_path_len
= strlen(new_url
->path
);
201 char *path
= ecalloc(1, old_path_len
+ new_path_len
+ 1 + 1);
203 strcat(path
, old_url
->path
);
204 if (path
[old_path_len
- 1] != '/') {
205 php_dirname(path
, old_path_len
);
208 strcat(path
, new_url
->path
);
210 url(buf
)->path
= &buf
.data
[buf
.used
];
211 if (path
[0] != '/') {
212 url_append(&buf
, php_http_buffer_append(&buf
, "/", 1));
214 url_append(&buf
, php_http_buffer_append(&buf
, path
, strlen(path
) + 1));
217 const char *path
= NULL
;
219 if (url_isset(new_url
, path
)) {
220 path
= new_url
->path
;
221 } else if (url_isset(old_url
, path
)) {
222 path
= old_url
->path
;
226 url(buf
)->path
= &buf
.data
[buf
.used
];
228 url_append(&buf
, php_http_buffer_append(&buf
, path
, strlen(path
) + 1));
235 if (!(flags
& PHP_HTTP_URL_STRIP_QUERY
)) {
236 if ((flags
& PHP_HTTP_URL_JOIN_QUERY
) && url_isset(new_url
, query
) && url_isset(old_url
, query
)) {
241 ZVAL_STRING(&qstr
, old_url
->query
);
242 php_http_querystring_update(&qarr
, &qstr
, NULL
);
243 zval_ptr_dtor(&qstr
);
244 ZVAL_STRING(&qstr
, new_url
->query
);
245 php_http_querystring_update(&qarr
, &qstr
, NULL
);
246 zval_ptr_dtor(&qstr
);
249 php_http_querystring_update(&qarr
, NULL
, &qstr
);
251 url(buf
)->query
= &buf
.data
[buf
.used
];
252 url_append(&buf
, php_http_buffer_append(&buf
, Z_STRVAL(qstr
), Z_STRLEN(qstr
) + 1));
261 if (!(flags
& PHP_HTTP_URL_STRIP_FRAGMENT
)) {
265 /* done with copy & combine & strip */
267 if (flags
& PHP_HTTP_URL_FROM_ENV
) {
268 /* free old_url we tainted above */
269 php_http_url_free(&tmp_url
);
272 /* replace directory references if path is not a single slash */
273 if ((flags
& PHP_HTTP_URL_SANITIZE_PATH
)
275 && url(buf
)->path
[0] && url(buf
)->path
[1]) {
276 char *ptr
, *end
= url(buf
)->path
+ strlen(url(buf
)->path
) + 1;
278 for (ptr
= strchr(url(buf
)->path
, '/'); ptr
; ptr
= strchr(ptr
, '/')) {
281 memmove(&ptr
[1], &ptr
[2], end
- &ptr
[2]);
291 memmove(&ptr
[1], &ptr
[3], end
- &ptr
[3]);
297 while (ptr
!= url(buf
)->path
) {
302 memmove(&ptr
[1], pos
, end
- pos
);
304 } else if (!ptr
[3]) {
323 /* unset default ports */
324 if (url(buf
)->port
) {
325 if ( ((url(buf
)->port
== 80) && url(buf
)->scheme
&& !strcmp(url(buf
)->scheme
, "http"))
326 || ((url(buf
)->port
==443) && url(buf
)->scheme
&& !strcmp(url(buf
)->scheme
, "https"))
335 char *php_http_url_to_string(const php_http_url_t
*url
, char **url_str
, size_t *url_len
, zend_bool persistent
)
337 php_http_buffer_t buf
;
339 php_http_buffer_init_ex(&buf
, PHP_HTTP_BUFFER_DEFAULT_SIZE
, persistent
?
340 PHP_HTTP_BUFFER_INIT_PERSISTENT
: 0);
342 if (url
->scheme
&& *url
->scheme
) {
343 php_http_buffer_appendl(&buf
, url
->scheme
);
344 php_http_buffer_appends(&buf
, "://");
345 } else if ((url
->user
&& *url
->user
) || (url
->host
&& *url
->host
)) {
346 php_http_buffer_appends(&buf
, "//");
349 if (url
->user
&& *url
->user
) {
350 php_http_buffer_appendl(&buf
, url
->user
);
351 if (url
->pass
&& *url
->pass
) {
352 php_http_buffer_appends(&buf
, ":");
353 php_http_buffer_appendl(&buf
, url
->pass
);
355 php_http_buffer_appends(&buf
, "@");
358 if (url
->host
&& *url
->host
) {
359 php_http_buffer_appendl(&buf
, url
->host
);
361 php_http_buffer_appendf(&buf
, ":%hu", url
->port
);
365 if (url
->path
&& *url
->path
) {
366 if (*url
->path
!= '/') {
367 php_http_buffer_appends(&buf
, "/");
369 php_http_buffer_appendl(&buf
, url
->path
);
370 } else if (buf
.used
) {
371 php_http_buffer_appends(&buf
, "/");
374 if (url
->query
&& *url
->query
) {
375 php_http_buffer_appends(&buf
, "?");
376 php_http_buffer_appendl(&buf
, url
->query
);
379 if (url
->fragment
&& *url
->fragment
) {
380 php_http_buffer_appends(&buf
, "#");
381 php_http_buffer_appendl(&buf
, url
->fragment
);
384 php_http_buffer_shrink(&buf
);
385 php_http_buffer_fix(&buf
);
398 char *php_http_url_authority_to_string(const php_http_url_t
*url
, char **url_str
, size_t *url_len
)
400 php_http_buffer_t buf
;
402 php_http_buffer_init(&buf
);
404 if (url
->user
&& *url
->user
) {
405 php_http_buffer_appendl(&buf
, url
->user
);
406 if (url
->pass
&& *url
->pass
) {
407 php_http_buffer_appends(&buf
, ":");
408 php_http_buffer_appendl(&buf
, url
->pass
);
410 php_http_buffer_appends(&buf
, "@");
413 if (url
->host
&& *url
->host
) {
414 php_http_buffer_appendl(&buf
, url
->host
);
416 php_http_buffer_appendf(&buf
, ":%hu", url
->port
);
420 php_http_buffer_shrink(&buf
);
421 php_http_buffer_fix(&buf
);
434 php_http_url_t
*php_http_url_from_zval(zval
*value
, unsigned flags
)
437 php_http_url_t
*purl
;
439 switch (Z_TYPE_P(value
)) {
442 purl
= php_http_url_from_struct(HASH_OF(value
));
446 zs
= zval_get_string(value
);
447 purl
= php_http_url_parse(zs
->val
, zs
->len
, flags
);
448 zend_string_release(zs
);
454 php_http_url_t
*php_http_url_from_struct(HashTable
*ht
)
457 php_http_buffer_t buf
;
459 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
460 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
461 memset(buf
.data
, 0, buf
.used
);
463 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("scheme")))) {
464 zend_string
*zs
= zval_get_string(e
);
465 url(buf
)->scheme
= &buf
.data
[buf
.used
];
466 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
467 zend_string_release(zs
);
469 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("user")))) {
470 zend_string
*zs
= zval_get_string(e
);
471 url(buf
)->user
= &buf
.data
[buf
.used
];
472 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
473 zend_string_release(zs
);
475 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("pass")))) {
476 zend_string
*zs
= zval_get_string(e
);
477 url(buf
)->pass
= &buf
.data
[buf
.used
];
478 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
479 zend_string_release(zs
);
481 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("host")))) {
482 zend_string
*zs
= zval_get_string(e
);
483 url(buf
)->host
= &buf
.data
[buf
.used
];
484 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
485 zend_string_release(zs
);
487 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("port")))) {
488 url(buf
)->port
= (unsigned short) zval_get_long(e
);
490 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("path")))) {
491 zend_string
*zs
= zval_get_string(e
);
492 url(buf
)->path
= &buf
.data
[buf
.used
];
493 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
494 zend_string_release(zs
);
496 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("query")))) {
497 zend_string
*zs
= zval_get_string(e
);
498 url(buf
)->query
= &buf
.data
[buf
.used
];
499 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
500 zend_string_release(zs
);
502 if ((e
= zend_hash_str_find_ind(ht
, ZEND_STRL("fragment")))) {
503 zend_string
*zs
= zval_get_string(e
);
504 url(buf
)->fragment
= &buf
.data
[buf
.used
];
505 url_append(&buf
, php_http_buffer_append(&buf
, zs
->val
, zs
->len
+ 1));
506 zend_string_release(zs
);
512 HashTable
*php_http_url_to_struct(const php_http_url_t
*url
, zval
*strct
)
514 HashTable
*ht
= NULL
;
518 switch (Z_TYPE_P(strct
)) {
530 zend_hash_init(ht
, 8, NULL
, ZVAL_PTR_DTOR
, 0);
533 #define url_struct_add(part) \
534 if (!strct || Z_TYPE_P(strct) == IS_ARRAY) { \
535 zend_hash_str_update(ht, part, lenof(part), &tmp); \
537 zend_update_property(Z_OBJCE_P(strct), strct, part, lenof(part), &tmp); \
538 zval_ptr_dtor(&tmp); \
543 ZVAL_STRING(&tmp
, url
->scheme
);
544 url_struct_add("scheme");
547 ZVAL_STRING(&tmp
, url
->user
);
548 url_struct_add("user");
551 ZVAL_STRING(&tmp
, url
->pass
);
552 url_struct_add("pass");
555 ZVAL_STRING(&tmp
, url
->host
);
556 url_struct_add("host");
559 ZVAL_LONG(&tmp
, url
->port
);
560 url_struct_add("port");
563 ZVAL_STRING(&tmp
, url
->path
);
564 url_struct_add("path");
567 ZVAL_STRING(&tmp
, url
->query
);
568 url_struct_add("query");
571 ZVAL_STRING(&tmp
, url
->fragment
);
572 url_struct_add("fragment");
579 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
)
581 const char *arg_sep_str
= "&";
582 size_t arg_sep_len
= 1;
583 php_http_buffer_t
*qstr
= php_http_buffer_new();
585 php_http_url_argsep(&arg_sep_str
, &arg_sep_len
);
587 if (SUCCESS
!= php_http_url_encode_hash_ex(hash
, qstr
, arg_sep_str
, arg_sep_len
, "=", 1, pre_encoded_str
, pre_encoded_len
)) {
588 php_http_buffer_free(&qstr
);
592 php_http_buffer_data(qstr
, encoded_str
, encoded_len
);
593 php_http_buffer_free(&qstr
);
598 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
)
600 if (pre_encoded_len
&& pre_encoded_str
) {
601 php_http_buffer_append(qstr
, pre_encoded_str
, pre_encoded_len
);
604 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
)) {
618 char buffer
[1]; /* last member */
621 void php_http_url_free(php_http_url_t
**url
)
629 php_http_url_t
*php_http_url_copy(const php_http_url_t
*url
, zend_bool persistent
)
632 const char *end
= NULL
, *url_ptr
= (const char *) url
;
635 end
= MAX(url
->scheme
, end
);
636 end
= MAX(url
->pass
, end
);
637 end
= MAX(url
->user
, end
);
638 end
= MAX(url
->host
, end
);
639 end
= MAX(url
->path
, end
);
640 end
= MAX(url
->query
, end
);
641 end
= MAX(url
->fragment
, end
);
644 end
+= strlen(end
) + 1;
645 cpy_ptr
= pecalloc(1, end
- url_ptr
, persistent
);
646 cpy
= (php_http_url_t
*) cpy_ptr
;
648 memcpy(cpy_ptr
+ sizeof(*cpy
), url_ptr
+ sizeof(*url
), end
- url_ptr
- sizeof(*url
));
650 cpy
->scheme
= url
->scheme
? cpy_ptr
+ (url
->scheme
- url_ptr
) : NULL
;
651 cpy
->pass
= url
->pass
? cpy_ptr
+ (url
->pass
- url_ptr
) : NULL
;
652 cpy
->user
= url
->user
? cpy_ptr
+ (url
->user
- url_ptr
) : NULL
;
653 cpy
->host
= url
->host
? cpy_ptr
+ (url
->host
- url_ptr
) : NULL
;
654 cpy
->path
= url
->path
? cpy_ptr
+ (url
->path
- url_ptr
) : NULL
;
655 cpy
->query
= url
->query
? cpy_ptr
+ (url
->query
- url_ptr
) : NULL
;
656 cpy
->fragment
= url
->fragment
? cpy_ptr
+ (url
->fragment
- url_ptr
) : NULL
;
658 cpy
= ecalloc(1, sizeof(*url
));
661 cpy
->port
= url
->port
;
666 static size_t parse_mb_utf8(unsigned *wc
, const char *ptr
, const char *end
)
669 size_t consumed
= utf8towc(&wchar
, (const unsigned char *) ptr
, end
- ptr
);
671 if (!consumed
|| consumed
== (size_t) -1) {
681 #if PHP_HTTP_HAVE_WCHAR
682 static size_t parse_mb_loc(unsigned *wc
, const char *ptr
, const char *end
)
689 memset(&ps
, 0, sizeof(ps
));
690 consumed
= mbrtowc(&wchar
, ptr
, end
- ptr
, &ps
);
692 consumed
= mbtowc(&wchar
, ptr
, end
- ptr
);
695 if (!consumed
|| consumed
== (size_t) -1) {
706 typedef enum parse_mb_what
{
715 static const char * const parse_what
[] = {
724 static const char parse_xdigits
[] = "0123456789ABCDEF";
726 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
)
731 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
732 consumed
= parse_mb_utf8(&wchar
, ptr
, end
);
734 #if PHP_HTTP_HAVE_WCHAR
735 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
736 consumed
= parse_mb_loc(&wchar
, ptr
, end
);
741 if (!(state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) || what
== PARSE_HOSTINFO
|| what
== PARSE_SCHEME
) {
742 if (what
== PARSE_HOSTINFO
&& (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
)) {
744 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
745 if (!isualnum(wchar
)) {
748 #if PHP_HTTP_HAVE_WCHAR
749 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
750 if (!iswalnum(wchar
)) {
755 PHP_HTTP_DUFF(consumed
, state
->buffer
[state
->offset
++] = *ptr
++);
759 PHP_HTTP_DUFF(consumed
,
760 state
->buffer
[state
->offset
++] = '%';
761 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) >> 4];
762 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) & 0xf];
772 php_error_docref(NULL
, E_WARNING
,
773 "Failed to parse %s; unexpected multibyte sequence 0x%x at pos %u in '%s'",
774 parse_what
[what
], wchar
, (unsigned) (ptr
- begin
), begin
);
776 php_error_docref(NULL
, E_WARNING
,
777 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
778 parse_what
[what
], (unsigned char) *ptr
, (unsigned) (ptr
- begin
), begin
);
785 static ZEND_RESULT_CODE
parse_userinfo(struct parse_state
*state
, const char *ptr
)
788 const char *password
= NULL
, *end
= state
->ptr
, *tmp
= ptr
;
790 state
->url
.user
= &state
->buffer
[state
->offset
];
796 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
797 php_error_docref(NULL
, E_WARNING
,
798 "Failed to parse password; duplicate ':' at pos %u in '%s'",
799 (unsigned) (ptr
- tmp
), tmp
);
801 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
804 state
->buffer
[state
->offset
++] = *ptr
;
808 state
->buffer
[state
->offset
++] = 0;
809 state
->url
.pass
= &state
->buffer
[state
->offset
];
813 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
814 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
815 php_error_docref(NULL
, E_WARNING
,
816 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
817 (unsigned) (ptr
- tmp
), tmp
);
819 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
822 state
->buffer
[state
->offset
++] = *ptr
++;
825 state
->buffer
[state
->offset
++] = *ptr
++;
826 state
->buffer
[state
->offset
++] = *ptr
++;
827 state
->buffer
[state
->offset
++] = *ptr
;
831 if ((mb
= parse_mb(state
, PARSE_USERINFO
, ptr
, end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
835 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
839 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
840 case '+': case ',': case ';': case '=': /* sub-delims */
841 case '-': case '.': case '_': case '~': /* unreserved */
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 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
847 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
848 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
849 case 'v': case 'w': case 'x': case 'y': case 'z':
850 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
851 case '7': case '8': case '9':
853 state
->buffer
[state
->offset
++] = *ptr
;
857 } while(++ptr
< end
);
860 state
->buffer
[state
->offset
++] = 0;
865 #if PHP_WIN32 || HAVE_UIDNA_IDNTOASCII
866 typedef size_t (*parse_mb_func
)(unsigned *wc
, const char *ptr
, const char *end
);
867 static ZEND_RESULT_CODE
to_utf16(parse_mb_func fn
, const char *u8
, uint16_t **u16
, size_t *len
)
869 size_t offset
= 0, u8_len
= strlen(u8
);
871 *u16
= ecalloc(4 * sizeof(uint16_t), u8_len
+ 1);
874 while (offset
< u8_len
) {
876 uint16_t buf
[2], *ptr
= buf
;
877 size_t consumed
= fn(&wc
, &u8
[offset
], &u8
[u8_len
]);
881 php_error_docref(NULL
, E_WARNING
, "Failed to parse UTF-8 at pos %zu of '%s'", offset
, u8
);
887 switch (wctoutf16(buf
, wc
)) {
889 (*u16
)[(*len
)++] = *ptr
++;
892 (*u16
)[(*len
)++] = *ptr
++;
897 php_error_docref(NULL
, E_WARNING
, "Failed to convert UTF-32 'U+%X' to UTF-16", wc
);
906 #if PHP_HTTP_HAVE_LIBIDN2
908 __attribute__ ((unused
))
910 static ZEND_RESULT_CODE
parse_gidn_2008(struct parse_state
*state
, size_t prev_len
)
915 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
916 rv
= idn2_lookup_u8((const unsigned char *) state
->url
.host
, (unsigned char **) &idn
, IDN2_NFC_INPUT
);
918 # if PHP_HTTP_HAVE_WCHAR
919 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
920 rv
= idn2_lookup_ul(state
->url
.host
, &idn
, 0);
924 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
925 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (IDNA2008); %s", idn2_strerror(rv
));
927 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
931 size_t idnlen
= strlen(idn
);
932 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
934 state
->offset
+= idnlen
- prev_len
;
940 #if PHP_HTTP_HAVE_LIBIDN
942 __attribute__ ((unused
))
944 static ZEND_RESULT_CODE
parse_gidn_2003(struct parse_state
*state
, size_t prev_len
)
949 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
950 rv
= idna_to_ascii_8z(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
);
952 # if PHP_HTTP_HAVE_WCHAR
953 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
954 rv
= idna_to_ascii_lz(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
);
957 if (rv
!= IDNA_SUCCESS
) {
958 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
959 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (IDNA2003); %s", idna_strerror(rv
));
961 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
965 size_t idnlen
= strlen(idn
);
966 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
968 state
->offset
+= idnlen
- prev_len
;
974 #if HAVE_UIDNA_IDNTOASCII
975 # if !PHP_HTTP_HAVE_LIBICU
976 typedef uint16_t UChar
;
977 typedef enum { U_ZERO_ERROR
= 0 } UErrorCode
;
978 int32_t uidna_IDNToASCII(const UChar
*src
, int32_t srcLength
, UChar
*dest
, int32_t destCapacity
, int32_t options
, void *parseError
, UErrorCode
*status
);
980 static ZEND_RESULT_CODE
parse_uidn_2003(struct parse_state
*state
)
982 char *host_ptr
= state
->url
.host
, ebuf
[64] = {0}, *error
= NULL
;
983 uint16_t *uhost_str
, ahost_str
[256], *ahost_ptr
;
984 size_t uhost_len
, ahost_len
;
985 UErrorCode rc
= U_ZERO_ERROR
;
987 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
988 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
989 error
= "failed to convert to UTF-16";
992 #if PHP_HTTP_HAVE_WCHAR
993 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
994 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
995 error
= "failed to convert to UTF-16";
1000 error
= "codepage not specified";
1005 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1007 ahost_len
= uidna_IDNToASCII(uhost_str
, uhost_len
, ahost_str
, 256, 3, NULL
, &rc
);
1009 # pragma GCC diagnostic pop
1013 if (error
> U_ZERO_ERROR
) {
1017 ahost_ptr
= ahost_str
;
1018 PHP_HTTP_DUFF(ahost_len
, *host_ptr
++ = *ahost_ptr
++);
1020 state
->offset
+= host_ptr
- state
->url
.host
;
1026 slprintf(ebuf
, sizeof(ebuf
)-1, "errorcode: %d", rc
);
1029 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2003); %s", error
);
1035 #if PHP_HTTP_HAVE_LIBICU && HAVE_UIDNA_NAMETOASCII_UTF8
1036 static ZEND_RESULT_CODE
parse_uidn_2008(struct parse_state
*state
)
1038 char *host_ptr
, *error
= NULL
, ebuf
[64] = {0};
1039 UErrorCode rc
= U_ZERO_ERROR
;
1040 UIDNAInfo info
= UIDNA_INFO_INITIALIZER
;
1041 UIDNA
*uidna
= uidna_openUTS46(UIDNA_ALLOW_UNASSIGNED
, &rc
);
1043 if (!uidna
|| U_FAILURE(rc
)) {
1047 host_ptr
= state
->url
.host
;
1049 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1050 char ahost_str
[256], *ahost_ptr
= &ahost_str
[0];
1051 size_t ahost_len
= uidna_nameToASCII_UTF8(uidna
, host_ptr
, -1, ahost_str
, sizeof(ahost_str
)-1, &info
, &rc
);
1053 if (U_FAILURE(rc
) || info
.errors
) {
1056 PHP_HTTP_DUFF(ahost_len
, *host_ptr
++ = *ahost_ptr
++);
1057 #if PHP_HTTP_HAVE_WCHAR
1058 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1059 uint16_t *uhost_str
, whost_str
[256], *whost_ptr
= &whost_str
[0];
1060 size_t uhost_len
, whost_len
;
1062 if (SUCCESS
!= to_utf16(parse_mb_loc
, host_ptr
, &uhost_str
, &uhost_len
)) {
1063 error
= "could not convert to UTF-16";
1067 whost_len
= uidna_nameToASCII(uidna
, uhost_str
, uhost_len
, whost_str
, sizeof(whost_str
)-1, &info
, &rc
);
1068 whost_ptr
= whost_str
;
1070 if (U_FAILURE(rc
) || info
.errors
) {
1073 PHP_HTTP_DUFF(whost_len
, *host_ptr
++ = *whost_ptr
++);
1076 error
= "codepage not specified";
1081 state
->offset
+= host_ptr
- state
->url
.host
;
1088 if (U_FAILURE(rc
)) {
1089 slprintf(ebuf
, sizeof(ebuf
)-1, "%s", u_errorName(rc
));
1091 } else if (info
.errors
) {
1092 slprintf(ebuf
, sizeof(ebuf
)-1, "ICU IDNA error codes: 0x%x", info
.errors
);
1095 error
= "unknown error";
1098 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2008); %s", error
);
1105 #if PHP_HTTP_HAVE_LIBIDNKIT || PHP_HTTP_HAVE_LIBIDNKIT2
1107 __attribute__ ((unused
))
1109 static ZEND_RESULT_CODE
parse_kidn(struct parse_state
*state
)
1112 #if PHP_HTTP_HAVE_LIBIDNKIT
1113 int actions
= IDN_DELIMMAP
|IDN_LOCALMAP
|IDN_NAMEPREP
|IDN_IDNCONV
|IDN_LENCHECK
;
1114 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1115 int actions
= IDN_MAP
|IDN_ASCLOWER
|IDN_RTCONV
|IDN_PROHCHECK
|IDN_NFCCHECK
|IDN_PREFCHECK
|IDN_COMBCHECK
|IDN_CTXOLITECHECK
|IDN_BIDICHECK
|IDN_LOCALCHECK
|IDN_IDNCONV
|IDN_LENCHECK
|IDN_RTCHECK
;
1117 char ahost_str
[256] = {0}, *ahost_ptr
= &ahost_str
[0], *host_ptr
= state
->url
.host
;
1119 if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1120 #if PHP_HTTP_HAVE_LIBIDNKIT
1121 actions
|= IDN_LOCALCONV
;
1122 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1123 actions
|= IDN_UNICODECONV
;
1127 rc
= idn_encodename(actions
, state
->url
.host
, ahost_str
, 256);
1128 if (rc
== idn_success
) {
1129 PHP_HTTP_DUFF(strlen(ahost_str
), *host_ptr
++ = *ahost_ptr
++);
1132 state
->offset
+= host_ptr
- state
->url
.host
;
1136 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN; %s", idn_result_tostring(rc
));
1143 static ZEND_RESULT_CODE
parse_widn_2003(struct parse_state
*state
)
1146 uint16_t *uhost_str
, ahost_str
[256], *ahost_ptr
;
1149 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1150 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1151 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1154 #if PHP_HTTP_HAVE_WCHAR
1155 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1156 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1157 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1162 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1166 if (!IdnToAscii(IDN_ALLOW_UNASSIGNED
, uhost_str
, uhost_len
, ahost_str
, 256)) {
1168 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1173 host_ptr
= state
->url
.host
;
1174 ahost_ptr
= ahost_str
;
1175 PHP_HTTP_DUFF(wcslen(ahost_str
), *host_ptr
++ = *ahost_ptr
++);
1178 state
->offset
+= host_ptr
- state
->url
.host
;
1184 static ZEND_RESULT_CODE
parse_idna(struct parse_state
*state
, size_t len
)
1186 #if PHP_HTTP_HAVE_IDNA2008
1187 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
) == PHP_HTTP_URL_PARSE_TOIDN_2008
1188 # if PHP_HTTP_HAVE_IDNA2003
1189 || (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
) != PHP_HTTP_URL_PARSE_TOIDN_2003
1192 #if PHP_HTTP_HAVE_LIBICU && HAVE_UIDNA_NAMETOASCII_UTF8
1193 return parse_uidn_2008(state
);
1194 #elif PHP_HTTP_HAVE_LIBIDN2
1195 return parse_gidn_2008(state
, len
);
1196 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1197 return parse_kidn(state
);
1202 #if PHP_HTTP_HAVE_IDNA2003
1203 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
) == PHP_HTTP_URL_PARSE_TOIDN_2003
1204 # if PHP_HTTP_HAVE_IDNA2008
1205 || (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
) != PHP_HTTP_URL_PARSE_TOIDN_2008
1208 #if HAVE_UIDNA_IDNTOASCII
1209 return parse_uidn_2003(state
);
1210 #elif PHP_HTTP_HAVE_LIBIDN
1211 return parse_gidn_2003(state
, len
);
1212 #elif PHP_HTTP_HAVE_LIBIDNKIT
1213 return parse_kidn(state
);
1219 return parse_widn_2003(state
);
1222 #if PHP_HTTP_HAVE_LIBICU && HAVE_UIDNA_NAMETOASCII_UTF8
1223 return parse_uidn_2008(state
);
1224 #elif PHP_HTTP_HAVE_LIBIDN2
1225 return parse_gidn_2008(state
, len
);
1226 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1227 return parse_kidn(state
);
1228 #elif HAVE_UIDNA_IDNTOASCII
1229 return parse_uidn_2003(state
);
1230 #elif PHP_HTTP_HAVE_LIBIDN
1231 return parse_gidn_2003(state
, len
);
1232 #elif PHP_HTTP_HAVE_LIBIDNKIT
1233 return parse_kidn(state
);
1240 static const char *parse_ip6(struct parse_state
*state
, const char *ptr
)
1243 const char *error
= NULL
, *end
= state
->ptr
, *tmp
= memchr(ptr
, ']', end
- ptr
);
1246 size_t addrlen
= tmp
- ptr
+ 1;
1247 char buf
[16], *addr
= estrndup(ptr
+ 1, addrlen
- 2);
1248 int rv
= inet_pton(AF_INET6
, addr
, buf
);
1251 state
->buffer
[state
->offset
] = '[';
1252 state
->url
.host
= &state
->buffer
[state
->offset
];
1253 inet_ntop(AF_INET6
, buf
, state
->url
.host
+ 1, state
->maxlen
- state
->offset
);
1254 state
->offset
+= strlen(state
->url
.host
);
1255 state
->buffer
[state
->offset
++] = ']';
1256 state
->buffer
[state
->offset
++] = 0;
1258 } else if (rv
== -1) {
1260 error
= strerror(errno
);
1262 error
= "unexpected '['";
1267 error
= "expected ']'";
1271 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1272 php_error_docref(NULL
, E_WARNING
, "Failed to parse hostinfo; %s at pos %u in '%s'", error
, pos
, ptr
);
1281 static ZEND_RESULT_CODE
parse_hostinfo(struct parse_state
*state
, const char *ptr
)
1283 size_t mb
, len
= state
->offset
;
1284 const char *end
= state
->ptr
, *tmp
= ptr
, *port
= NULL
, *label
= NULL
;
1287 if (*ptr
== '[' && !(ptr
= parse_ip6(state
, ptr
))) {
1288 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1295 if (ptr
!= end
) do {
1299 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1300 php_error_docref(NULL
, E_WARNING
,
1301 "Failed to parse port; unexpected ':' at pos %u in '%s'",
1302 (unsigned) (ptr
- tmp
), tmp
);
1304 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1312 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
1313 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1314 php_error_docref(NULL
, E_WARNING
,
1315 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
1316 (unsigned) (ptr
- tmp
), tmp
);
1318 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1321 state
->buffer
[state
->offset
++] = *ptr
++;
1324 state
->buffer
[state
->offset
++] = *ptr
++;
1325 state
->buffer
[state
->offset
++] = *ptr
++;
1326 state
->buffer
[state
->offset
++] = *ptr
;
1330 if (port
|| !label
) {
1331 /* sort of a compromise, just ensure we don't end up
1332 * with a dot at the beginning or two consecutive dots
1334 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1335 php_error_docref(NULL
, E_WARNING
,
1336 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1337 port
? "port" : "host",
1338 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1340 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1345 state
->buffer
[state
->offset
++] = *ptr
;
1351 /* sort of a compromise, just ensure we don't end up
1352 * with a hyphen at the beginning
1354 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1355 php_error_docref(NULL
, E_WARNING
,
1356 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1357 port
? "port" : "host",
1358 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1360 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1366 case '_': case '~': /* unreserved */
1367 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1368 case '+': case ',': case ';': case '=': /* sub-delims */
1369 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1370 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1371 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1372 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1373 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1374 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1375 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1376 case 'v': case 'w': case 'x': case 'y': case 'z':
1378 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1379 php_error_docref(NULL
, E_WARNING
,
1380 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
1381 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1383 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1389 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1390 case '7': case '8': case '9':
1393 state
->url
.port
*= 10;
1394 state
->url
.port
+= *ptr
- '0';
1397 state
->buffer
[state
->offset
++] = *ptr
;
1405 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1406 php_error_docref(NULL
, E_WARNING
,
1407 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
1408 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1410 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1414 } else if (!(mb
= parse_mb(state
, PARSE_HOSTINFO
, ptr
, end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1415 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1423 } while (++ptr
< end
);
1425 if (!state
->url
.host
) {
1426 len
= state
->offset
- len
;
1427 state
->url
.host
= &state
->buffer
[state
->offset
- len
];
1428 state
->buffer
[state
->offset
++] = 0;
1431 if (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
) {
1432 return parse_idna(state
, len
);
1438 static const char *parse_authority(struct parse_state
*state
)
1440 const char *tmp
= state
->ptr
, *host
= NULL
;
1443 switch (*state
->ptr
) {
1445 /* userinfo delimiter */
1447 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1448 php_error_docref(NULL
, E_WARNING
,
1449 "Failed to parse userinfo; unexpected '@'");
1451 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1456 host
= state
->ptr
+ 1;
1457 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_userinfo(state
, tmp
)) {
1460 tmp
= state
->ptr
+ 1;
1468 /* host delimiter */
1469 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_hostinfo(state
, tmp
)) {
1474 } while (++state
->ptr
<= state
->end
);
1480 static const char *parse_path(struct parse_state
*state
)
1485 /* is there actually a path to parse? */
1490 state
->url
.path
= &state
->buffer
[state
->offset
];
1493 switch (*state
->ptr
) {
1499 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1500 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1501 php_error_docref(NULL
, E_WARNING
,
1502 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
1503 (unsigned) (state
->ptr
- tmp
), tmp
);
1505 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1508 state
->buffer
[state
->offset
++] = *state
->ptr
;
1511 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1512 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1513 state
->buffer
[state
->offset
++] = *state
->ptr
;
1516 case '/': /* yeah, well */
1517 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1518 case '+': case ',': case ';': case '=': /* sub-delims */
1519 case '-': case '.': case '_': case '~': /* unreserved */
1520 case ':': case '@': /* pchar */
1521 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1522 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1523 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1524 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1525 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1526 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1527 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1528 case 'v': case 'w': case 'x': case 'y': case 'z':
1529 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1530 case '7': case '8': case '9':
1532 state
->buffer
[state
->offset
++] = *state
->ptr
;
1536 if (!(mb
= parse_mb(state
, PARSE_PATH
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1537 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1542 state
->ptr
+= mb
- 1;
1544 } while (++state
->ptr
< state
->end
);
1547 /* did we have any path component ? */
1548 if (tmp
!= state
->ptr
) {
1549 state
->buffer
[state
->offset
++] = 0;
1551 state
->url
.path
= NULL
;
1556 static const char *parse_query(struct parse_state
*state
)
1559 const char *tmp
= state
->ptr
+ !!*state
->ptr
;
1561 /* is there actually a query to parse? */
1562 if (*state
->ptr
!= '?') {
1566 /* skip initial '?' */
1568 state
->url
.query
= &state
->buffer
[state
->offset
];
1570 while (state
->ptr
< state
->end
) {
1571 switch (*state
->ptr
) {
1576 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1577 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1578 php_error_docref(NULL
, E_WARNING
,
1579 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
1580 (unsigned) (state
->ptr
- tmp
), tmp
);
1582 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1585 /* fallthrough, pct-encode the percent sign */
1587 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1588 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1589 state
->buffer
[state
->offset
++] = *state
->ptr
;
1596 case '|': case '\\': case '^': case '`': case '"': case ' ':
1597 /* RFC1738 unsafe */
1598 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1599 state
->buffer
[state
->offset
++] = '%';
1600 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1601 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1606 case '?': case '/': /* yeah, well */
1607 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1608 case '+': case ',': case ';': case '=': /* sub-delims */
1609 case '-': case '.': case '_': case '~': /* unreserved */
1610 case ':': case '@': /* pchar */
1611 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1612 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1613 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1614 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1615 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1616 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1617 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1618 case 'v': case 'w': case 'x': case 'y': case 'z':
1619 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1620 case '7': case '8': case '9':
1622 state
->buffer
[state
->offset
++] = *state
->ptr
;
1626 if (!(mb
= parse_mb(state
, PARSE_QUERY
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1627 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1632 state
->ptr
+= mb
- 1;
1639 state
->buffer
[state
->offset
++] = 0;
1643 static const char *parse_fragment(struct parse_state
*state
)
1648 /* is there actually a fragment to parse? */
1649 if (*state
->ptr
!= '#') {
1653 /* skip initial '#' */
1655 state
->url
.fragment
= &state
->buffer
[state
->offset
];
1658 switch (*state
->ptr
) {
1660 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1661 php_error_docref(NULL
, E_WARNING
,
1662 "Failed to parse fragment; invalid fragment identifier at pos %u in '%s'",
1663 (unsigned) (state
->ptr
- tmp
), tmp
);
1665 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1668 state
->buffer
[state
->offset
++] = *state
->ptr
;
1672 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1673 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1674 php_error_docref(NULL
, E_WARNING
,
1675 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
1676 (unsigned) (state
->ptr
- tmp
), tmp
);
1678 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1683 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1684 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1685 state
->buffer
[state
->offset
++] = *state
->ptr
;
1693 case '|': case '\\': case '^': case '`': case '"': case ' ':
1694 /* RFC1738 unsafe */
1695 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1696 state
->buffer
[state
->offset
++] = '%';
1697 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1698 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1704 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1705 case '+': case ',': case ';': case '=': /* sub-delims */
1706 case '-': case '.': case '_': case '~': /* unreserved */
1707 case ':': case '@': /* pchar */
1708 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1709 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1710 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1711 case 'V': case 'W': case 'X': case 'Y': case 'Z':
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 '0': case '1': case '2': case '3': case '4': case '5': case '6':
1717 case '7': case '8': case '9':
1719 state
->buffer
[state
->offset
++] = *state
->ptr
;
1723 if (!(mb
= parse_mb(state
, PARSE_FRAGMENT
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1724 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1729 state
->ptr
+= mb
- 1;
1731 } while (++state
->ptr
< state
->end
);
1733 state
->buffer
[state
->offset
++] = 0;
1737 static const char *parse_hier(struct parse_state
*state
)
1739 if (*state
->ptr
== '/') {
1740 if (state
->end
- state
->ptr
> 1) {
1741 if (*(state
->ptr
+ 1) == '/') {
1743 if (!(state
->ptr
= parse_authority(state
))) {
1749 return parse_path(state
);
1752 static const char *parse_scheme(struct parse_state
*state
)
1755 const char *tmp
= state
->ptr
;
1758 switch (*state
->ptr
) {
1760 /* scheme delimiter */
1761 state
->url
.scheme
= &state
->buffer
[0];
1762 state
->buffer
[state
->offset
++] = 0;
1763 return ++state
->ptr
;
1765 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1766 case '7': case '8': case '9':
1767 case '+': case '-': case '.':
1768 if (state
->ptr
== tmp
) {
1772 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1773 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1774 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1775 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1776 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1777 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1778 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1779 case 'v': case 'w': case 'x': case 'y': case 'z':
1781 state
->buffer
[state
->offset
++] = *state
->ptr
;
1785 if (!(mb
= parse_mb(state
, PARSE_SCHEME
, state
->ptr
, state
->end
, tmp
, 1))) {
1788 state
->ptr
+= mb
- 1;
1790 } while (++state
->ptr
< state
->end
);
1794 return state
->ptr
= tmp
;
1797 php_http_url_t
*php_http_url_parse(const char *str
, size_t len
, unsigned flags
)
1799 size_t maxlen
= 3 * len
+ 8 /* null bytes for all components */;
1800 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1802 state
->end
= str
+ len
;
1804 state
->flags
= flags
;
1805 state
->maxlen
= maxlen
;
1807 if (!parse_scheme(state
)) {
1808 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL scheme: '%s'", state
->ptr
);
1813 if (!parse_hier(state
)) {
1818 if (!parse_query(state
)) {
1819 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL query: '%s'", state
->ptr
);
1824 if (!parse_fragment(state
)) {
1825 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL fragment: '%s'", state
->ptr
);
1830 return (php_http_url_t
*) state
;
1833 php_http_url_t
*php_http_url_parse_authority(const char *str
, size_t len
, unsigned flags
)
1835 size_t maxlen
= 3 * len
;
1836 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1838 state
->end
= str
+ len
;
1840 state
->flags
= flags
;
1841 state
->maxlen
= maxlen
;
1843 if (!(state
->ptr
= parse_authority(state
))) {
1848 if (state
->ptr
!= state
->end
) {
1849 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1850 php_error_docref(NULL
, E_WARNING
,
1851 "Failed to parse URL authority, unexpected character at pos %u in '%s'",
1852 (unsigned) (state
->ptr
- str
), str
);
1854 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1860 return (php_http_url_t
*) state
;
1863 static zend_class_entry
*php_http_url_class_entry
;
1864 static zend_class_entry
*php_http_env_url_class_entry
;
1866 zend_class_entry
*php_http_url_get_class_entry(void)
1868 return php_http_url_class_entry
;
1871 zend_class_entry
*php_http_get_env_url_class_entry(void)
1873 return php_http_env_url_class_entry
;
1876 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct
, 0, 0, 0)
1877 ZEND_ARG_INFO(0, old_url
)
1878 ZEND_ARG_INFO(0, new_url
)
1879 ZEND_ARG_INFO(0, flags
)
1880 ZEND_END_ARG_INFO();
1881 PHP_METHOD(HttpUrl
, __construct
)
1883 zval
*new_url
= NULL
, *old_url
= NULL
;
1884 zend_long flags
= 0;
1885 zend_error_handling zeh
;
1887 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!z!l", &old_url
, &new_url
, &flags
), invalid_arg
, return);
1889 /* always set http\Url::FROM_ENV for instances of http\Env\Url */
1890 if (instanceof_function(Z_OBJCE_P(getThis()), php_http_env_url_class_entry
)) {
1891 flags
|= PHP_HTTP_URL_FROM_ENV
;
1894 if (flags
& PHP_HTTP_URL_SILENT_ERRORS
) {
1895 zend_replace_error_handling(EH_SUPPRESS
, NULL
, &zeh
);
1896 } else if (flags
& PHP_HTTP_URL_IGNORE_ERRORS
) {
1897 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1899 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1902 php_http_url_t
*res_purl
, *new_purl
= NULL
, *old_purl
= NULL
;
1905 new_purl
= php_http_url_from_zval(new_url
, flags
);
1907 zend_restore_error_handling(&zeh
);
1912 old_purl
= php_http_url_from_zval(old_url
, flags
);
1915 php_http_url_free(&new_purl
);
1917 zend_restore_error_handling(&zeh
);
1922 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1923 php_http_url_to_struct(res_purl
, getThis());
1925 php_http_url_free(&res_purl
);
1927 php_http_url_free(&old_purl
);
1930 php_http_url_free(&new_purl
);
1933 zend_restore_error_handling(&zeh
);
1936 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod
, 0, 0, 1)
1937 ZEND_ARG_INFO(0, more_url_parts
)
1938 ZEND_ARG_INFO(0, flags
)
1939 ZEND_END_ARG_INFO();
1940 PHP_METHOD(HttpUrl
, mod
)
1942 zval
*new_url
= NULL
;
1943 zend_long flags
= PHP_HTTP_URL_JOIN_PATH
| PHP_HTTP_URL_JOIN_QUERY
| PHP_HTTP_URL_SANITIZE_PATH
;
1944 zend_error_handling zeh
;
1946 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url
, &flags
), invalid_arg
, return);
1948 if (flags
& PHP_HTTP_URL_SILENT_ERRORS
) {
1949 zend_replace_error_handling(EH_SUPPRESS
, NULL
, &zeh
);
1950 } else if (flags
& PHP_HTTP_URL_IGNORE_ERRORS
) {
1951 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1953 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1956 php_http_url_t
*new_purl
= NULL
, *old_purl
= NULL
;
1959 new_purl
= php_http_url_from_zval(new_url
, flags
);
1961 zend_restore_error_handling(&zeh
);
1966 if ((old_purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1967 php_http_url_t
*res_purl
;
1969 ZVAL_OBJ(return_value
, zend_objects_clone_obj(getThis()));
1971 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1972 php_http_url_to_struct(res_purl
, return_value
);
1974 php_http_url_free(&res_purl
);
1975 php_http_url_free(&old_purl
);
1978 php_http_url_free(&new_purl
);
1981 zend_restore_error_handling(&zeh
);
1984 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString
, 0, 0, 0)
1985 ZEND_END_ARG_INFO();
1986 PHP_METHOD(HttpUrl
, toString
)
1988 if (SUCCESS
== zend_parse_parameters_none()) {
1989 php_http_url_t
*purl
;
1991 if ((purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1995 php_http_url_to_string(purl
, &str
, &len
, 0);
1996 php_http_url_free(&purl
);
1997 RETURN_STR(php_http_cs2zs(str
, len
));
2000 RETURN_EMPTY_STRING();
2003 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray
, 0, 0, 0)
2004 ZEND_END_ARG_INFO();
2005 PHP_METHOD(HttpUrl
, toArray
)
2007 php_http_url_t
*purl
;
2009 if (SUCCESS
!= zend_parse_parameters_none()) {
2013 /* strip any non-URL properties */
2014 purl
= php_http_url_from_struct(HASH_OF(getThis()));
2015 php_http_url_to_struct(purl
, return_value
);
2016 php_http_url_free(&purl
);
2019 static zend_function_entry php_http_url_methods
[] = {
2020 PHP_ME(HttpUrl
, __construct
, ai_HttpUrl___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
2021 PHP_ME(HttpUrl
, mod
, ai_HttpUrl_mod
, ZEND_ACC_PUBLIC
)
2022 PHP_ME(HttpUrl
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
2023 ZEND_MALIAS(HttpUrl
, __toString
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
2024 PHP_ME(HttpUrl
, toArray
, ai_HttpUrl_toArray
, ZEND_ACC_PUBLIC
)
2025 EMPTY_FUNCTION_ENTRY
2028 PHP_MINIT_FUNCTION(http_url
)
2030 zend_class_entry ce
= {0};
2032 INIT_NS_CLASS_ENTRY(ce
, "http", "Url", php_http_url_methods
);
2033 php_http_url_class_entry
= zend_register_internal_class(&ce
);
2035 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC
);
2036 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("user"), ZEND_ACC_PUBLIC
);
2037 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("pass"), ZEND_ACC_PUBLIC
);
2038 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("host"), ZEND_ACC_PUBLIC
);
2039 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("port"), ZEND_ACC_PUBLIC
);
2040 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("path"), ZEND_ACC_PUBLIC
);
2041 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("query"), ZEND_ACC_PUBLIC
);
2042 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC
);
2044 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE
);
2045 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH
);
2046 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY
);
2047 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER
);
2048 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS
);
2049 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH
);
2050 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT
);
2051 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH
);
2052 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY
);
2053 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT
);
2054 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL
);
2055 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV
);
2056 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH
);
2058 #if PHP_HTTP_HAVE_WCHAR
2059 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC
);
2061 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8
);
2062 #if PHP_HTTP_HAVE_LIBIDN2 || PHP_HTTP_HAVE_LIBIDN || PHP_HTTP_HAVE_LIBIDNKIT || PHP_HTTP_HAVE_LIBIDNKIT2 || HAVE_UIDNA_IDNTOASCII || HAVE_UIDNA_NAMETOASCII_UTF8
2063 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN
);
2064 # if PHP_HTTP_HAVE_IDNA2003
2065 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2003"), PHP_HTTP_URL_PARSE_TOIDN_2003
);
2067 # if PHP_HTTP_HAVE_IDNA2008
2068 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2008"), PHP_HTTP_URL_PARSE_TOIDN_2008
);
2071 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT
);
2073 INIT_NS_CLASS_ENTRY(ce
, "http\\Env", "Url", php_http_url_methods
);
2074 php_http_env_url_class_entry
= zend_register_internal_class_ex(&ce
, php_http_url_class_entry
);
2076 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("IGNORE_ERRORS"), PHP_HTTP_URL_IGNORE_ERRORS
);
2077 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SILENT_ERRORS"), PHP_HTTP_URL_SILENT_ERRORS
);
2079 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STDFLAGS"), PHP_HTTP_URL_STDFLAGS
);
2090 * vim600: noet sw=4 ts=4 fdm=marker
2091 * vim<600: noet sw=4 ts=4