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 # include <unicode/uidna.h>
978 typedef uint16_t UChar
;
979 typedef enum { U_ZERO_ERROR
= 0 } UErrorCode
;
980 int32_t uidna_IDNToASCII(const UChar
*src
, int32_t srcLength
, UChar
*dest
, int32_t destCapacity
, int32_t options
, void *parseError
, UErrorCode
*status
);
982 static ZEND_RESULT_CODE
parse_uidn_2003(struct parse_state
*state
)
984 char *host_ptr
= state
->url
.host
, ebuf
[64] = {0}, *error
= NULL
;
985 uint16_t *uhost_str
, ahost_str
[256], *ahost_ptr
;
986 size_t uhost_len
, ahost_len
;
987 UErrorCode rc
= U_ZERO_ERROR
;
989 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
990 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
991 error
= "failed to convert to UTF-16";
994 #if PHP_HTTP_HAVE_WCHAR
995 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
996 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
997 error
= "failed to convert to UTF-16";
1002 error
= "codepage not specified";
1007 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1009 ahost_len
= uidna_IDNToASCII(uhost_str
, uhost_len
, ahost_str
, 256, 3, NULL
, &rc
);
1011 # pragma GCC diagnostic pop
1015 if (error
> U_ZERO_ERROR
) {
1019 ahost_ptr
= ahost_str
;
1020 PHP_HTTP_DUFF(ahost_len
, *host_ptr
++ = *ahost_ptr
++);
1022 state
->offset
+= host_ptr
- state
->url
.host
;
1028 slprintf(ebuf
, sizeof(ebuf
)-1, "errorcode: %d", rc
);
1031 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2003); %s", error
);
1037 #if HAVE_UIDNA_IDNTOASCII
1038 # if PHP_HTTP_HAVE_LIBICU
1039 # include <unicode/uidna.h>
1041 static ZEND_RESULT_CODE
parse_uidn_2008(struct parse_state
*state
)
1043 char *host_ptr
, *error
= NULL
, ebuf
[64] = {0};
1044 UErrorCode rc
= U_ZERO_ERROR
;
1045 UIDNAInfo info
= UIDNA_INFO_INITIALIZER
;
1046 UIDNA
*uidna
= uidna_openUTS46(UIDNA_ALLOW_UNASSIGNED
, &rc
);
1048 if (!uidna
|| U_FAILURE(rc
)) {
1052 host_ptr
= state
->url
.host
;
1054 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1055 char ahost_str
[256], *ahost_ptr
= &ahost_str
[0];
1056 size_t ahost_len
= uidna_nameToASCII_UTF8(uidna
, host_ptr
, -1, ahost_str
, sizeof(ahost_str
)-1, &info
, &rc
);
1058 if (U_FAILURE(rc
) || info
.errors
) {
1061 PHP_HTTP_DUFF(ahost_len
, *host_ptr
++ = *ahost_ptr
++);
1062 #if PHP_HTTP_HAVE_WCHAR
1063 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1064 uint16_t *uhost_str
, whost_str
[256], *whost_ptr
= &whost_str
[0];
1065 size_t uhost_len
, whost_len
;
1067 if (SUCCESS
!= to_utf16(parse_mb_loc
, host_ptr
, &uhost_str
, &uhost_len
)) {
1068 error
= "could not convert to UTF-16";
1072 whost_len
= uidna_nameToASCII(uidna
, uhost_str
, uhost_len
, whost_str
, sizeof(whost_str
)-1, &info
, &rc
);
1073 whost_ptr
= whost_str
;
1075 if (U_FAILURE(rc
) || info
.errors
) {
1078 PHP_HTTP_DUFF(whost_len
, *host_ptr
++ = *whost_ptr
++);
1081 error
= "codepage not specified";
1086 state
->offset
+= host_ptr
- state
->url
.host
;
1093 if (U_FAILURE(rc
)) {
1094 slprintf(ebuf
, sizeof(ebuf
)-1, "%s", u_errorName(rc
));
1096 } else if (info
.errors
) {
1097 slprintf(ebuf
, sizeof(ebuf
)-1, "ICU IDNA error codes: 0x%x", info
.errors
);
1100 error
= "unknown error";
1103 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2008); %s", error
);
1110 #if PHP_HTTP_HAVE_LIBIDNKIT || PHP_HTTP_HAVE_LIBIDNKIT2
1112 __attribute__ ((unused
))
1114 static ZEND_RESULT_CODE
parse_kidn(struct parse_state
*state
)
1117 #if PHP_HTTP_HAVE_LIBIDNKIT
1118 int actions
= IDN_DELIMMAP
|IDN_LOCALMAP
|IDN_NAMEPREP
|IDN_IDNCONV
|IDN_LENCHECK
;
1119 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1120 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
;
1122 char ahost_str
[256] = {0}, *ahost_ptr
= &ahost_str
[0], *host_ptr
= state
->url
.host
;
1124 if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1125 #if PHP_HTTP_HAVE_LIBIDNKIT
1126 actions
|= IDN_LOCALCONV
;
1127 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1128 actions
|= IDN_UNICODECONV
;
1132 rc
= idn_encodename(actions
, state
->url
.host
, ahost_str
, 256);
1133 if (rc
== idn_success
) {
1134 PHP_HTTP_DUFF(strlen(ahost_str
), *host_ptr
++ = *ahost_ptr
++);
1137 state
->offset
+= host_ptr
- state
->url
.host
;
1141 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN; %s", idn_result_tostring(rc
));
1148 static ZEND_RESULT_CODE
parse_widn_2003(struct parse_state
*state
)
1151 uint16_t *uhost_str
, ahost_str
[256], *ahost_ptr
;
1154 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1155 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1156 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1159 #if PHP_HTTP_HAVE_WCHAR
1160 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1161 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1162 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1167 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1171 if (!IdnToAscii(IDN_ALLOW_UNASSIGNED
, uhost_str
, uhost_len
, ahost_str
, 256)) {
1173 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1178 host_ptr
= state
->url
.host
;
1179 ahost_ptr
= ahost_str
;
1180 PHP_HTTP_DUFF(wcslen(ahost_str
), *host_ptr
++ = *ahost_ptr
++);
1183 state
->offset
+= host_ptr
- state
->url
.host
;
1189 static ZEND_RESULT_CODE
parse_idna(struct parse_state
*state
, size_t len
)
1191 #if PHP_HTTP_HAVE_IDNA2008
1192 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
) == PHP_HTTP_URL_PARSE_TOIDN_2008
1193 # if PHP_HTTP_HAVE_IDNA2003
1194 || (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
) != PHP_HTTP_URL_PARSE_TOIDN_2003
1197 #if HAVE_UIDNA_NAMETOASCII_UTF8
1198 return parse_uidn_2008(state
);
1199 #elif PHP_HTTP_HAVE_LIBIDN2
1200 return parse_gidn_2008(state
, len
);
1201 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1202 return parse_kidn(state
);
1207 #if PHP_HTTP_HAVE_IDNA2003
1208 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
) == PHP_HTTP_URL_PARSE_TOIDN_2003
1209 # if PHP_HTTP_HAVE_IDNA2008
1210 || (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
) != PHP_HTTP_URL_PARSE_TOIDN_2008
1213 #if HAVE_UIDNA_IDNTOASCII
1214 return parse_uidn_2003(state
);
1215 #elif PHP_HTTP_HAVE_LIBIDN
1216 return parse_gidn_2003(state
, len
);
1217 #elif PHP_HTTP_HAVE_LIBIDNKIT
1218 return parse_kidn(state
);
1224 return parse_widn_2003(state
);
1227 #if HAVE_UIDNA_NAMETOASCII_UTF8
1228 return parse_uidn_2008(state
);
1229 #elif PHP_HTTP_HAVE_LIBIDN2
1230 return parse_gidn_2008(state
, len
);
1231 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1232 return parse_kidn(state
);
1233 #elif HAVE_UIDNA_IDNTOASCII
1234 return parse_uidn_2003(state
);
1235 #elif PHP_HTTP_HAVE_LIBIDN
1236 return parse_gidn_2003(state
, len
);
1237 #elif PHP_HTTP_HAVE_LIBIDNKIT
1238 return parse_kidn(state
);
1245 static const char *parse_ip6(struct parse_state
*state
, const char *ptr
)
1248 const char *error
= NULL
, *end
= state
->ptr
, *tmp
= memchr(ptr
, ']', end
- ptr
);
1251 size_t addrlen
= tmp
- ptr
+ 1;
1252 char buf
[16], *addr
= estrndup(ptr
+ 1, addrlen
- 2);
1253 int rv
= inet_pton(AF_INET6
, addr
, buf
);
1256 state
->buffer
[state
->offset
] = '[';
1257 state
->url
.host
= &state
->buffer
[state
->offset
];
1258 inet_ntop(AF_INET6
, buf
, state
->url
.host
+ 1, state
->maxlen
- state
->offset
);
1259 state
->offset
+= strlen(state
->url
.host
);
1260 state
->buffer
[state
->offset
++] = ']';
1261 state
->buffer
[state
->offset
++] = 0;
1263 } else if (rv
== -1) {
1265 error
= strerror(errno
);
1267 error
= "unexpected '['";
1272 error
= "expected ']'";
1276 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1277 php_error_docref(NULL
, E_WARNING
, "Failed to parse hostinfo; %s at pos %u in '%s'", error
, pos
, ptr
);
1286 static ZEND_RESULT_CODE
parse_hostinfo(struct parse_state
*state
, const char *ptr
)
1288 size_t mb
, len
= state
->offset
;
1289 const char *end
= state
->ptr
, *tmp
= ptr
, *port
= NULL
, *label
= NULL
;
1292 if (*ptr
== '[' && !(ptr
= parse_ip6(state
, ptr
))) {
1293 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1300 if (ptr
!= end
) do {
1304 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1305 php_error_docref(NULL
, E_WARNING
,
1306 "Failed to parse port; unexpected ':' at pos %u in '%s'",
1307 (unsigned) (ptr
- tmp
), tmp
);
1309 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1317 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
1318 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1319 php_error_docref(NULL
, E_WARNING
,
1320 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
1321 (unsigned) (ptr
- tmp
), tmp
);
1323 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1326 state
->buffer
[state
->offset
++] = *ptr
++;
1329 state
->buffer
[state
->offset
++] = *ptr
++;
1330 state
->buffer
[state
->offset
++] = *ptr
++;
1331 state
->buffer
[state
->offset
++] = *ptr
;
1335 if (port
|| !label
) {
1336 /* sort of a compromise, just ensure we don't end up
1337 * with a dot at the beginning or two consecutive dots
1339 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1340 php_error_docref(NULL
, E_WARNING
,
1341 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1342 port
? "port" : "host",
1343 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1345 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1350 state
->buffer
[state
->offset
++] = *ptr
;
1356 /* sort of a compromise, just ensure we don't end up
1357 * with a hyphen at the beginning
1359 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1360 php_error_docref(NULL
, E_WARNING
,
1361 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1362 port
? "port" : "host",
1363 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1365 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1371 case '_': case '~': /* unreserved */
1372 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1373 case '+': case ',': case ';': case '=': /* sub-delims */
1374 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1375 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1376 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1377 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1378 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1379 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1380 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1381 case 'v': case 'w': case 'x': case 'y': case 'z':
1383 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1384 php_error_docref(NULL
, E_WARNING
,
1385 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
1386 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1388 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1394 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1395 case '7': case '8': case '9':
1398 state
->url
.port
*= 10;
1399 state
->url
.port
+= *ptr
- '0';
1402 state
->buffer
[state
->offset
++] = *ptr
;
1410 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1411 php_error_docref(NULL
, E_WARNING
,
1412 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
1413 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1415 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1419 } else if (!(mb
= parse_mb(state
, PARSE_HOSTINFO
, ptr
, end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1420 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1428 } while (++ptr
< end
);
1430 if (!state
->url
.host
) {
1431 len
= state
->offset
- len
;
1432 state
->url
.host
= &state
->buffer
[state
->offset
- len
];
1433 state
->buffer
[state
->offset
++] = 0;
1436 if (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
) {
1437 return parse_idna(state
, len
);
1443 static const char *parse_authority(struct parse_state
*state
)
1445 const char *tmp
= state
->ptr
, *host
= NULL
;
1448 switch (*state
->ptr
) {
1450 /* userinfo delimiter */
1452 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1453 php_error_docref(NULL
, E_WARNING
,
1454 "Failed to parse userinfo; unexpected '@'");
1456 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1461 host
= state
->ptr
+ 1;
1462 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_userinfo(state
, tmp
)) {
1465 tmp
= state
->ptr
+ 1;
1473 /* host delimiter */
1474 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_hostinfo(state
, tmp
)) {
1479 } while (++state
->ptr
<= state
->end
);
1485 static const char *parse_path(struct parse_state
*state
)
1490 /* is there actually a path to parse? */
1495 state
->url
.path
= &state
->buffer
[state
->offset
];
1498 switch (*state
->ptr
) {
1504 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1505 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1506 php_error_docref(NULL
, E_WARNING
,
1507 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
1508 (unsigned) (state
->ptr
- tmp
), tmp
);
1510 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1513 state
->buffer
[state
->offset
++] = *state
->ptr
;
1516 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1517 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1518 state
->buffer
[state
->offset
++] = *state
->ptr
;
1521 case '/': /* yeah, well */
1522 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1523 case '+': case ',': case ';': case '=': /* sub-delims */
1524 case '-': case '.': case '_': case '~': /* unreserved */
1525 case ':': case '@': /* pchar */
1526 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1527 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1528 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1529 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1530 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1531 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1532 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1533 case 'v': case 'w': case 'x': case 'y': case 'z':
1534 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1535 case '7': case '8': case '9':
1537 state
->buffer
[state
->offset
++] = *state
->ptr
;
1541 if (!(mb
= parse_mb(state
, PARSE_PATH
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1542 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1547 state
->ptr
+= mb
- 1;
1549 } while (++state
->ptr
< state
->end
);
1552 /* did we have any path component ? */
1553 if (tmp
!= state
->ptr
) {
1554 state
->buffer
[state
->offset
++] = 0;
1556 state
->url
.path
= NULL
;
1561 static const char *parse_query(struct parse_state
*state
)
1564 const char *tmp
= state
->ptr
+ !!*state
->ptr
;
1566 /* is there actually a query to parse? */
1567 if (*state
->ptr
!= '?') {
1571 /* skip initial '?' */
1573 state
->url
.query
= &state
->buffer
[state
->offset
];
1575 while (state
->ptr
< state
->end
) {
1576 switch (*state
->ptr
) {
1581 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1582 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1583 php_error_docref(NULL
, E_WARNING
,
1584 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
1585 (unsigned) (state
->ptr
- tmp
), tmp
);
1587 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1590 /* fallthrough, pct-encode the percent sign */
1592 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1593 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1594 state
->buffer
[state
->offset
++] = *state
->ptr
;
1601 case '|': case '\\': case '^': case '`': case '"': case ' ':
1602 /* RFC1738 unsafe */
1603 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1604 state
->buffer
[state
->offset
++] = '%';
1605 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1606 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1611 case '?': case '/': /* yeah, well */
1612 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1613 case '+': case ',': case ';': case '=': /* sub-delims */
1614 case '-': case '.': case '_': case '~': /* unreserved */
1615 case ':': case '@': /* pchar */
1616 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1617 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1618 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1619 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1620 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1621 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1622 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1623 case 'v': case 'w': case 'x': case 'y': case 'z':
1624 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1625 case '7': case '8': case '9':
1627 state
->buffer
[state
->offset
++] = *state
->ptr
;
1631 if (!(mb
= parse_mb(state
, PARSE_QUERY
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1632 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1637 state
->ptr
+= mb
- 1;
1644 state
->buffer
[state
->offset
++] = 0;
1648 static const char *parse_fragment(struct parse_state
*state
)
1653 /* is there actually a fragment to parse? */
1654 if (*state
->ptr
!= '#') {
1658 /* skip initial '#' */
1660 state
->url
.fragment
= &state
->buffer
[state
->offset
];
1663 switch (*state
->ptr
) {
1665 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1666 php_error_docref(NULL
, E_WARNING
,
1667 "Failed to parse fragment; invalid fragment identifier at pos %u in '%s'",
1668 (unsigned) (state
->ptr
- tmp
), tmp
);
1670 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1673 state
->buffer
[state
->offset
++] = *state
->ptr
;
1677 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1678 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1679 php_error_docref(NULL
, E_WARNING
,
1680 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
1681 (unsigned) (state
->ptr
- tmp
), tmp
);
1683 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1688 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1689 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1690 state
->buffer
[state
->offset
++] = *state
->ptr
;
1698 case '|': case '\\': case '^': case '`': case '"': case ' ':
1699 /* RFC1738 unsafe */
1700 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1701 state
->buffer
[state
->offset
++] = '%';
1702 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1703 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1709 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1710 case '+': case ',': case ';': case '=': /* sub-delims */
1711 case '-': case '.': case '_': case '~': /* unreserved */
1712 case ':': case '@': /* pchar */
1713 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1714 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1715 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1716 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1717 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1718 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1719 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1720 case 'v': case 'w': case 'x': case 'y': case 'z':
1721 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1722 case '7': case '8': case '9':
1724 state
->buffer
[state
->offset
++] = *state
->ptr
;
1728 if (!(mb
= parse_mb(state
, PARSE_FRAGMENT
, state
->ptr
, state
->end
, tmp
, state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
))) {
1729 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1734 state
->ptr
+= mb
- 1;
1736 } while (++state
->ptr
< state
->end
);
1738 state
->buffer
[state
->offset
++] = 0;
1742 static const char *parse_hier(struct parse_state
*state
)
1744 if (*state
->ptr
== '/') {
1745 if (state
->end
- state
->ptr
> 1) {
1746 if (*(state
->ptr
+ 1) == '/') {
1748 if (!(state
->ptr
= parse_authority(state
))) {
1754 return parse_path(state
);
1757 static const char *parse_scheme(struct parse_state
*state
)
1760 const char *tmp
= state
->ptr
;
1763 switch (*state
->ptr
) {
1765 /* scheme delimiter */
1766 state
->url
.scheme
= &state
->buffer
[0];
1767 state
->buffer
[state
->offset
++] = 0;
1768 return ++state
->ptr
;
1770 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1771 case '7': case '8': case '9':
1772 case '+': case '-': case '.':
1773 if (state
->ptr
== tmp
) {
1777 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1778 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1779 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1780 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1781 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1782 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1783 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1784 case 'v': case 'w': case 'x': case 'y': case 'z':
1786 state
->buffer
[state
->offset
++] = *state
->ptr
;
1790 if (!(mb
= parse_mb(state
, PARSE_SCHEME
, state
->ptr
, state
->end
, tmp
, 1))) {
1793 state
->ptr
+= mb
- 1;
1795 } while (++state
->ptr
< state
->end
);
1799 return state
->ptr
= tmp
;
1802 php_http_url_t
*php_http_url_parse(const char *str
, size_t len
, unsigned flags
)
1804 size_t maxlen
= 3 * len
+ 8 /* null bytes for all components */;
1805 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1807 state
->end
= str
+ len
;
1809 state
->flags
= flags
;
1810 state
->maxlen
= maxlen
;
1812 if (!parse_scheme(state
)) {
1813 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL scheme: '%s'", state
->ptr
);
1818 if (!parse_hier(state
)) {
1823 if (!parse_query(state
)) {
1824 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL query: '%s'", state
->ptr
);
1829 if (!parse_fragment(state
)) {
1830 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL fragment: '%s'", state
->ptr
);
1835 return (php_http_url_t
*) state
;
1838 php_http_url_t
*php_http_url_parse_authority(const char *str
, size_t len
, unsigned flags
)
1840 size_t maxlen
= 3 * len
;
1841 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1843 state
->end
= str
+ len
;
1845 state
->flags
= flags
;
1846 state
->maxlen
= maxlen
;
1848 if (!(state
->ptr
= parse_authority(state
))) {
1853 if (state
->ptr
!= state
->end
) {
1854 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1855 php_error_docref(NULL
, E_WARNING
,
1856 "Failed to parse URL authority, unexpected character at pos %u in '%s'",
1857 (unsigned) (state
->ptr
- str
), str
);
1859 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1865 return (php_http_url_t
*) state
;
1868 static zend_class_entry
*php_http_url_class_entry
;
1869 static zend_class_entry
*php_http_env_url_class_entry
;
1871 zend_class_entry
*php_http_url_get_class_entry(void)
1873 return php_http_url_class_entry
;
1876 zend_class_entry
*php_http_get_env_url_class_entry(void)
1878 return php_http_env_url_class_entry
;
1881 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct
, 0, 0, 0)
1882 ZEND_ARG_INFO(0, old_url
)
1883 ZEND_ARG_INFO(0, new_url
)
1884 ZEND_ARG_INFO(0, flags
)
1885 ZEND_END_ARG_INFO();
1886 PHP_METHOD(HttpUrl
, __construct
)
1888 zval
*new_url
= NULL
, *old_url
= NULL
;
1889 zend_long flags
= 0;
1890 zend_error_handling zeh
;
1892 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!z!l", &old_url
, &new_url
, &flags
), invalid_arg
, return);
1894 /* always set http\Url::FROM_ENV for instances of http\Env\Url */
1895 if (instanceof_function(Z_OBJCE_P(getThis()), php_http_env_url_class_entry
)) {
1896 flags
|= PHP_HTTP_URL_FROM_ENV
;
1899 if (flags
& PHP_HTTP_URL_SILENT_ERRORS
) {
1900 zend_replace_error_handling(EH_SUPPRESS
, NULL
, &zeh
);
1901 } else if (flags
& PHP_HTTP_URL_IGNORE_ERRORS
) {
1902 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1904 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1907 php_http_url_t
*res_purl
, *new_purl
= NULL
, *old_purl
= NULL
;
1910 new_purl
= php_http_url_from_zval(new_url
, flags
);
1912 zend_restore_error_handling(&zeh
);
1917 old_purl
= php_http_url_from_zval(old_url
, flags
);
1920 php_http_url_free(&new_purl
);
1922 zend_restore_error_handling(&zeh
);
1927 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1928 php_http_url_to_struct(res_purl
, getThis());
1930 php_http_url_free(&res_purl
);
1932 php_http_url_free(&old_purl
);
1935 php_http_url_free(&new_purl
);
1938 zend_restore_error_handling(&zeh
);
1941 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod
, 0, 0, 1)
1942 ZEND_ARG_INFO(0, more_url_parts
)
1943 ZEND_ARG_INFO(0, flags
)
1944 ZEND_END_ARG_INFO();
1945 PHP_METHOD(HttpUrl
, mod
)
1947 zval
*new_url
= NULL
;
1948 zend_long flags
= PHP_HTTP_URL_JOIN_PATH
| PHP_HTTP_URL_JOIN_QUERY
| PHP_HTTP_URL_SANITIZE_PATH
;
1949 zend_error_handling zeh
;
1951 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url
, &flags
), invalid_arg
, return);
1953 if (flags
& PHP_HTTP_URL_SILENT_ERRORS
) {
1954 zend_replace_error_handling(EH_SUPPRESS
, NULL
, &zeh
);
1955 } else if (flags
& PHP_HTTP_URL_IGNORE_ERRORS
) {
1956 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1958 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1961 php_http_url_t
*new_purl
= NULL
, *old_purl
= NULL
;
1964 new_purl
= php_http_url_from_zval(new_url
, flags
);
1966 zend_restore_error_handling(&zeh
);
1971 if ((old_purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1972 php_http_url_t
*res_purl
;
1974 ZVAL_OBJ(return_value
, zend_objects_clone_obj(getThis()));
1976 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1977 php_http_url_to_struct(res_purl
, return_value
);
1979 php_http_url_free(&res_purl
);
1980 php_http_url_free(&old_purl
);
1983 php_http_url_free(&new_purl
);
1986 zend_restore_error_handling(&zeh
);
1989 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString
, 0, 0, 0)
1990 ZEND_END_ARG_INFO();
1991 PHP_METHOD(HttpUrl
, toString
)
1993 if (SUCCESS
== zend_parse_parameters_none()) {
1994 php_http_url_t
*purl
;
1996 if ((purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
2000 php_http_url_to_string(purl
, &str
, &len
, 0);
2001 php_http_url_free(&purl
);
2002 RETURN_STR(php_http_cs2zs(str
, len
));
2005 RETURN_EMPTY_STRING();
2008 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray
, 0, 0, 0)
2009 ZEND_END_ARG_INFO();
2010 PHP_METHOD(HttpUrl
, toArray
)
2012 php_http_url_t
*purl
;
2014 if (SUCCESS
!= zend_parse_parameters_none()) {
2018 /* strip any non-URL properties */
2019 purl
= php_http_url_from_struct(HASH_OF(getThis()));
2020 php_http_url_to_struct(purl
, return_value
);
2021 php_http_url_free(&purl
);
2024 static zend_function_entry php_http_url_methods
[] = {
2025 PHP_ME(HttpUrl
, __construct
, ai_HttpUrl___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
2026 PHP_ME(HttpUrl
, mod
, ai_HttpUrl_mod
, ZEND_ACC_PUBLIC
)
2027 PHP_ME(HttpUrl
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
2028 ZEND_MALIAS(HttpUrl
, __toString
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
2029 PHP_ME(HttpUrl
, toArray
, ai_HttpUrl_toArray
, ZEND_ACC_PUBLIC
)
2030 EMPTY_FUNCTION_ENTRY
2033 PHP_MINIT_FUNCTION(http_url
)
2035 zend_class_entry ce
= {0};
2037 INIT_NS_CLASS_ENTRY(ce
, "http", "Url", php_http_url_methods
);
2038 php_http_url_class_entry
= zend_register_internal_class(&ce
);
2040 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC
);
2041 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("user"), ZEND_ACC_PUBLIC
);
2042 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("pass"), ZEND_ACC_PUBLIC
);
2043 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("host"), ZEND_ACC_PUBLIC
);
2044 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("port"), ZEND_ACC_PUBLIC
);
2045 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("path"), ZEND_ACC_PUBLIC
);
2046 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("query"), ZEND_ACC_PUBLIC
);
2047 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC
);
2049 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE
);
2050 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH
);
2051 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY
);
2052 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER
);
2053 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS
);
2054 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH
);
2055 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT
);
2056 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH
);
2057 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY
);
2058 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT
);
2059 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL
);
2060 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV
);
2061 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH
);
2063 #if PHP_HTTP_HAVE_WCHAR
2064 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC
);
2066 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8
);
2067 #if PHP_HTTP_HAVE_LIBIDN2 || PHP_HTTP_HAVE_LIBIDN || PHP_HTTP_HAVE_LIBIDNKIT || PHP_HTTP_HAVE_LIBIDNKIT2 || HAVE_UIDNA_IDNTOASCII || HAVE_UIDNA_NAMETOASCII_UTF8
2068 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN
);
2069 # if PHP_HTTP_HAVE_IDNA2003
2070 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2003"), PHP_HTTP_URL_PARSE_TOIDN_2003
);
2072 # if PHP_HTTP_HAVE_IDNA2008
2073 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2008"), PHP_HTTP_URL_PARSE_TOIDN_2008
);
2076 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT
);
2078 INIT_NS_CLASS_ENTRY(ce
, "http\\Env", "Url", php_http_url_methods
);
2079 php_http_env_url_class_entry
= zend_register_internal_class_ex(&ce
, php_http_url_class_entry
);
2081 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("IGNORE_ERRORS"), PHP_HTTP_URL_IGNORE_ERRORS
);
2082 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SILENT_ERRORS"), PHP_HTTP_URL_SILENT_ERRORS
);
2084 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STDFLAGS"), PHP_HTTP_URL_STDFLAGS
);
2095 * vim600: noet sw=4 ts=4 fdm=marker
2096 * vim<600: noet sw=4 ts=4