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_LIBIDN
18 #if PHP_HTTP_HAVE_LIBIDN2
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 inline 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 inline 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 inline size_t parse_mb(struct parse_state
*state
, parse_mb_what_t what
, const char *ptr
, const char *end
, const char *begin
, zend_bool force_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
)) {
756 memcpy(&state
->buffer
[state
->offset
], ptr
, consumed
);
757 state
->offset
+= consumed
;
761 for (i
= 0; i
< consumed
; ++i
) {
762 state
->buffer
[state
->offset
++] = '%';
763 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) >> 4];
764 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) & 0xf];
771 if (!force_silent
&& !(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
773 php_error_docref(NULL
, E_WARNING
,
774 "Failed to parse %s; unexpected multibyte sequence 0x%x at pos %u in '%s'",
775 parse_what
[what
], wchar
, (unsigned) (ptr
- begin
), begin
);
777 php_error_docref(NULL
, E_WARNING
,
778 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
779 parse_what
[what
], (unsigned char) *ptr
, (unsigned) (ptr
- begin
), begin
);
783 if (state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
) {
784 state
->buffer
[state
->offset
++] = *ptr
;
791 static ZEND_RESULT_CODE
parse_userinfo(struct parse_state
*state
, const char *ptr
)
794 const char *password
= NULL
, *end
= state
->ptr
, *tmp
= ptr
;
796 state
->url
.user
= &state
->buffer
[state
->offset
];
802 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
803 php_error_docref(NULL
, E_WARNING
,
804 "Failed to parse password; duplicate ':' at pos %u in '%s'",
805 (unsigned) (ptr
- tmp
), tmp
);
807 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
810 state
->buffer
[state
->offset
++] = *ptr
;
814 state
->buffer
[state
->offset
++] = 0;
815 state
->url
.pass
= &state
->buffer
[state
->offset
];
819 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
820 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
821 php_error_docref(NULL
, E_WARNING
,
822 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
823 (unsigned) (ptr
- tmp
), tmp
);
825 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
828 state
->buffer
[state
->offset
++] = *ptr
++;
831 state
->buffer
[state
->offset
++] = *ptr
++;
832 state
->buffer
[state
->offset
++] = *ptr
++;
833 state
->buffer
[state
->offset
++] = *ptr
;
837 if ((mb
= parse_mb(state
, PARSE_USERINFO
, ptr
, end
, tmp
, 0))) {
841 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
845 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
846 case '+': case ',': case ';': case '=': /* sub-delims */
847 case '-': case '.': case '_': case '~': /* unreserved */
848 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
849 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
850 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
851 case 'V': case 'W': case 'X': case 'Y': case 'Z':
852 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
853 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
854 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
855 case 'v': case 'w': case 'x': case 'y': case 'z':
856 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
857 case '7': case '8': case '9':
859 state
->buffer
[state
->offset
++] = *ptr
;
863 } while(++ptr
< end
);
866 state
->buffer
[state
->offset
++] = 0;
871 #if PHP_WIN32 || HAVE_UIDNA_IDNTOASCII
872 typedef size_t (*parse_mb_func
)(unsigned *wc
, const char *ptr
, const char *end
);
873 static ZEND_RESULT_CODE
to_utf16(parse_mb_func fn
, const char *u8
, uint16_t **u16
, size_t *len
)
875 size_t offset
= 0, u8_len
= strlen(u8
);
877 *u16
= ecalloc(4 * sizeof(uint16_t), u8_len
+ 1);
880 while (offset
< u8_len
) {
882 uint16_t buf
[2], *ptr
= buf
;
883 size_t consumed
= fn(&wc
, &u8
[offset
], &u8
[u8_len
]);
887 php_error_docref(NULL
, E_WARNING
, "Failed to parse UTF-8 at pos %zu of '%s'", offset
, u8
);
893 switch (wctoutf16(buf
, wc
)) {
895 (*u16
)[(*len
)++] = *ptr
++;
898 (*u16
)[(*len
)++] = *ptr
++;
903 php_error_docref(NULL
, E_WARNING
, "Failed to convert UTF-32 'U+%X' to UTF-16", wc
);
912 #if PHP_HTTP_HAVE_LIBIDN2
914 __attribute__ ((unused
))
916 static ZEND_RESULT_CODE
parse_gidn_2008(struct parse_state
*state
, size_t prev_len
)
921 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
922 rv
= idn2_lookup_u8((const unsigned char *) state
->url
.host
, (unsigned char **) &idn
, IDN2_NFC_INPUT
);
924 # if PHP_HTTP_HAVE_WCHAR
925 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
926 rv
= idn2_lookup_ul(state
->url
.host
, &idn
, 0);
930 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
931 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (IDNA2008); %s", idn2_strerror(rv
));
933 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
937 size_t idnlen
= strlen(idn
);
938 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
940 state
->offset
+= idnlen
- prev_len
;
946 #if PHP_HTTP_HAVE_LIBIDN
948 __attribute__ ((unused
))
950 static ZEND_RESULT_CODE
parse_gidn_2003(struct parse_state
*state
, size_t prev_len
)
955 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
956 rv
= idna_to_ascii_8z(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
);
958 # if PHP_HTTP_HAVE_WCHAR
959 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
960 rv
= idna_to_ascii_lz(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
);
963 if (rv
!= IDNA_SUCCESS
) {
964 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
965 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (IDNA2003); %s", idna_strerror(rv
));
967 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
971 size_t idnlen
= strlen(idn
);
972 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
974 state
->offset
+= idnlen
- prev_len
;
980 #if HAVE_UIDNA_IDNTOASCII
981 # if !PHP_HTTP_HAVE_LIBICU
982 typedef uint16_t UChar
;
983 typedef enum { U_ZERO_ERROR
= 0 } UErrorCode
;
984 int32_t uidna_IDNToASCII(const UChar
*src
, int32_t srcLength
, UChar
*dest
, int32_t destCapacity
, int32_t options
, void *parseError
, UErrorCode
*status
);
986 static ZEND_RESULT_CODE
parse_uidn_2003(struct parse_state
*state
, size_t prev_len
)
988 char ebuf
[64] = {0}, *error
= NULL
;
989 uint16_t *uhost_str
, ahost_str
[256];
990 size_t uhost_len
, ahost_len
;
991 UErrorCode rc
= U_ZERO_ERROR
;
993 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
994 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
995 error
= "failed to convert to UTF-16";
998 #if PHP_HTTP_HAVE_WCHAR
999 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1000 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1001 error
= "failed to convert to UTF-16";
1006 error
= "codepage not specified";
1011 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1013 ahost_len
= uidna_IDNToASCII(uhost_str
, uhost_len
, ahost_str
, 256, 3, NULL
, &rc
);
1015 # pragma GCC diagnostic pop
1019 if (error
> U_ZERO_ERROR
) {
1023 state
->url
.host
[ahost_len
] = '\0';
1024 state
->offset
+= ahost_len
- prev_len
;
1025 while (ahost_len
--) {
1026 state
->url
.host
[ahost_len
] = ahost_str
[ahost_len
];
1033 slprintf(ebuf
, sizeof(ebuf
)-1, "errorcode: %d", rc
);
1036 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2003); %s", error
);
1042 #if PHP_HTTP_HAVE_LIBICU && HAVE_UIDNA_NAMETOASCII_UTF8
1043 static ZEND_RESULT_CODE
parse_uidn_2008(struct parse_state
*state
, size_t prev_len
)
1045 char *error
= NULL
, ebuf
[64] = {0};
1046 UErrorCode rc
= U_ZERO_ERROR
;
1047 UIDNAInfo info
= UIDNA_INFO_INITIALIZER
;
1048 UIDNA
*uidna
= uidna_openUTS46(UIDNA_ALLOW_UNASSIGNED
, &rc
);
1050 if (!uidna
|| U_FAILURE(rc
)) {
1054 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1055 char ahost_str
[256];
1056 size_t ahost_len
= uidna_nameToASCII_UTF8(uidna
, state
->url
.host
, -1, ahost_str
, sizeof(ahost_str
)-1, &info
, &rc
);
1058 if (U_FAILURE(rc
) || info
.errors
) {
1062 memcpy(state
->url
.host
, ahost_str
, ahost_len
);
1063 state
->url
.host
[ahost_len
] = '\0';
1064 state
->offset
+= ahost_len
- prev_len
;
1066 #if PHP_HTTP_HAVE_WCHAR
1067 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1068 uint16_t *uhost_str
, whost_str
[256];
1069 size_t uhost_len
, whost_len
;
1071 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1072 error
= "could not convert to UTF-16";
1076 whost_len
= uidna_nameToASCII(uidna
, uhost_str
, uhost_len
, whost_str
, sizeof(whost_str
)-1, &info
, &rc
);
1079 if (U_FAILURE(rc
) || info
.errors
) {
1083 state
->url
.host
[whost_len
] = '\0';
1084 state
->offset
+= whost_len
- prev_len
;
1085 while (whost_len
--) {
1086 state
->url
.host
[whost_len
] = whost_str
[whost_len
];
1090 error
= "codepage not specified";
1099 if (U_FAILURE(rc
)) {
1100 slprintf(ebuf
, sizeof(ebuf
)-1, "%s", u_errorName(rc
));
1102 } else if (info
.errors
) {
1103 slprintf(ebuf
, sizeof(ebuf
)-1, "ICU IDNA error codes: 0x%x", info
.errors
);
1106 error
= "unknown error";
1109 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN (ICU IDNA2008); %s", error
);
1116 #if PHP_HTTP_HAVE_LIBIDNKIT || PHP_HTTP_HAVE_LIBIDNKIT2
1118 __attribute__ ((unused
))
1120 static ZEND_RESULT_CODE
parse_kidn(struct parse_state
*state
, size_t prev_len
)
1123 #if PHP_HTTP_HAVE_LIBIDNKIT
1124 int actions
= IDN_DELIMMAP
|IDN_LOCALMAP
|IDN_NAMEPREP
|IDN_IDNCONV
|IDN_LENCHECK
;
1125 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1126 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
;
1128 char ahost_str
[256] = {0};
1130 if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1131 #if PHP_HTTP_HAVE_LIBIDNKIT
1132 actions
|= IDN_LOCALCONV
;
1133 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1134 actions
|= IDN_UNICODECONV
;
1138 rc
= idn_encodename(actions
, state
->url
.host
, ahost_str
, 256);
1139 if (rc
== idn_success
) {
1140 size_t ahost_len
= strlen(ahost_str
);
1142 memcpy(state
->url
.host
, ahost_str
, ahost_len
+ 1);
1143 state
->offset
+= ahost_len
- prev_len
;
1147 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN; %s", idn_result_tostring(rc
));
1154 static ZEND_RESULT_CODE
parse_widn_2003(struct parse_state
*state
, size_t prev_len
)
1157 uint16_t *uhost_str
, ahost_str
[256];
1158 size_t uhost_len
, ahost_len
;
1160 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
1161 if (SUCCESS
!= to_utf16(parse_mb_utf8
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1162 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1165 #if PHP_HTTP_HAVE_WCHAR
1166 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
1167 if (SUCCESS
!= to_utf16(parse_mb_loc
, state
->url
.host
, &uhost_str
, &uhost_len
)) {
1168 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1173 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1177 if (!IdnToAscii(IDN_ALLOW_UNASSIGNED
, uhost_str
, uhost_len
, ahost_str
, 256)) {
1179 php_error_docref(NULL
, E_WARNING
, "Failed to parse IDN");
1184 ahost_len
= wcslen(ahost_str
);
1185 state
->url
.host
[ahost_len
] = '\0';
1186 state
->offset
+= ahost_len
- prev_len
;
1187 while (ahost_len
--) {
1188 state
->url
.host
[ahost_len
] = ahost_str
[ahost_len
];
1195 static ZEND_RESULT_CODE
parse_idna(struct parse_state
*state
, size_t len
)
1197 #if PHP_HTTP_HAVE_IDNA2008
1198 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
) == PHP_HTTP_URL_PARSE_TOIDN_2008
1199 # if PHP_HTTP_HAVE_IDNA2003
1200 || (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
) != PHP_HTTP_URL_PARSE_TOIDN_2003
1203 #if PHP_HTTP_HAVE_LIBICU && HAVE_UIDNA_NAMETOASCII_UTF8
1204 return parse_uidn_2008(state
, len
);
1205 #elif PHP_HTTP_HAVE_LIBIDN2
1206 return parse_gidn_2008(state
, len
);
1207 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1208 return parse_kidn(state
, len
);
1213 #if PHP_HTTP_HAVE_IDNA2003
1214 if ((state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2003
) == PHP_HTTP_URL_PARSE_TOIDN_2003
1215 # if PHP_HTTP_HAVE_IDNA2008
1216 || (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN_2008
) != PHP_HTTP_URL_PARSE_TOIDN_2008
1219 #if HAVE_UIDNA_IDNTOASCII
1220 return parse_uidn_2003(state
, len
);
1221 #elif PHP_HTTP_HAVE_LIBIDN
1222 return parse_gidn_2003(state
, len
);
1223 #elif PHP_HTTP_HAVE_LIBIDNKIT
1224 return parse_kidn(state
, len
);
1230 return parse_widn_2003(state
, len
);
1233 #if PHP_HTTP_HAVE_LIBICU && HAVE_UIDNA_NAMETOASCII_UTF8
1234 return parse_uidn_2008(state
, len
);
1235 #elif PHP_HTTP_HAVE_LIBIDN2
1236 return parse_gidn_2008(state
, len
);
1237 #elif PHP_HTTP_HAVE_LIBIDNKIT2
1238 return parse_kidn(state
, len
);
1239 #elif HAVE_UIDNA_IDNTOASCII
1240 return parse_uidn_2003(state
, len
);
1241 #elif PHP_HTTP_HAVE_LIBIDN
1242 return parse_gidn_2003(state
, len
);
1243 #elif PHP_HTTP_HAVE_LIBIDNKIT
1244 return parse_kidn(state
, len
);
1251 static const char *parse_ip6(struct parse_state
*state
, const char *ptr
)
1254 const char *error
= NULL
, *end
= state
->ptr
, *tmp
= memchr(ptr
, ']', end
- ptr
);
1257 size_t addrlen
= tmp
- ptr
+ 1;
1258 char buf
[16], *addr
= estrndup(ptr
+ 1, addrlen
- 2);
1259 int rv
= inet_pton(AF_INET6
, addr
, buf
);
1262 state
->buffer
[state
->offset
] = '[';
1263 state
->url
.host
= &state
->buffer
[state
->offset
];
1264 inet_ntop(AF_INET6
, buf
, state
->url
.host
+ 1, state
->maxlen
- state
->offset
);
1265 state
->offset
+= strlen(state
->url
.host
);
1266 state
->buffer
[state
->offset
++] = ']';
1267 state
->buffer
[state
->offset
++] = 0;
1269 } else if (rv
== -1) {
1271 error
= strerror(errno
);
1273 error
= "unexpected '['";
1278 error
= "expected ']'";
1282 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1283 php_error_docref(NULL
, E_WARNING
, "Failed to parse hostinfo; %s at pos %u in '%s'", error
, pos
, ptr
);
1292 static ZEND_RESULT_CODE
parse_hostinfo(struct parse_state
*state
, const char *ptr
)
1294 size_t mb
, len
= state
->offset
;
1295 const char *end
= state
->ptr
, *tmp
= ptr
, *port
= NULL
, *label
= NULL
;
1298 if (*ptr
== '[' && !(ptr
= parse_ip6(state
, ptr
))) {
1299 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1306 if (ptr
!= end
) do {
1310 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1311 php_error_docref(NULL
, E_WARNING
,
1312 "Failed to parse port; unexpected ':' at pos %u in '%s'",
1313 (unsigned) (ptr
- tmp
), tmp
);
1315 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1323 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
1324 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1325 php_error_docref(NULL
, E_WARNING
,
1326 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
1327 (unsigned) (ptr
- tmp
), tmp
);
1329 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1332 state
->buffer
[state
->offset
++] = *ptr
++;
1335 state
->buffer
[state
->offset
++] = *ptr
++;
1336 state
->buffer
[state
->offset
++] = *ptr
++;
1337 state
->buffer
[state
->offset
++] = *ptr
;
1341 if (port
|| !label
) {
1342 /* sort of a compromise, just ensure we don't end up
1343 * with a dot at the beginning or two consecutive dots
1345 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1346 php_error_docref(NULL
, E_WARNING
,
1347 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1348 port
? "port" : "host",
1349 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1351 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1356 state
->buffer
[state
->offset
++] = *ptr
;
1362 /* sort of a compromise, just ensure we don't end up
1363 * with a hyphen at the beginning
1365 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1366 php_error_docref(NULL
, E_WARNING
,
1367 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1368 port
? "port" : "host",
1369 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1371 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1377 case '_': case '~': /* unreserved */
1378 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1379 case '+': case ',': case ';': case '=': /* sub-delims */
1380 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1381 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1382 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1383 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1384 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1385 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1386 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1387 case 'v': case 'w': case 'x': case 'y': case 'z':
1389 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1390 php_error_docref(NULL
, E_WARNING
,
1391 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
1392 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1394 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1400 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1401 case '7': case '8': case '9':
1404 state
->url
.port
*= 10;
1405 state
->url
.port
+= *ptr
- '0';
1408 state
->buffer
[state
->offset
++] = *ptr
;
1416 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1417 php_error_docref(NULL
, E_WARNING
,
1418 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
1419 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
1421 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1425 } else if (!(mb
= parse_mb(state
, PARSE_HOSTINFO
, ptr
, end
, tmp
, 0))) {
1426 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1434 } while (++ptr
< end
);
1436 if (!state
->url
.host
) {
1437 len
= state
->offset
- len
;
1438 state
->url
.host
= &state
->buffer
[state
->offset
- len
];
1439 state
->buffer
[state
->offset
++] = 0;
1442 if (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
) {
1443 return parse_idna(state
, len
);
1449 static const char *parse_authority(struct parse_state
*state
)
1451 const char *tmp
= state
->ptr
, *host
= NULL
;
1454 switch (*state
->ptr
) {
1456 /* userinfo delimiter */
1458 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1459 php_error_docref(NULL
, E_WARNING
,
1460 "Failed to parse userinfo; unexpected '@'");
1462 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1467 host
= state
->ptr
+ 1;
1468 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_userinfo(state
, tmp
)) {
1471 tmp
= state
->ptr
+ 1;
1479 /* host delimiter */
1480 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_hostinfo(state
, tmp
)) {
1485 } while (++state
->ptr
<= state
->end
);
1491 static const char *parse_path(struct parse_state
*state
)
1496 /* is there actually a path to parse? */
1501 state
->url
.path
= &state
->buffer
[state
->offset
];
1504 switch (*state
->ptr
) {
1510 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1511 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1512 php_error_docref(NULL
, E_WARNING
,
1513 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
1514 (unsigned) (state
->ptr
- tmp
), tmp
);
1516 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1519 state
->buffer
[state
->offset
++] = *state
->ptr
;
1522 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1523 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1524 state
->buffer
[state
->offset
++] = *state
->ptr
;
1527 case '/': /* yeah, well */
1528 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1529 case '+': case ',': case ';': case '=': /* sub-delims */
1530 case '-': case '.': case '_': case '~': /* unreserved */
1531 case ':': case '@': /* pchar */
1532 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1533 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1534 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1535 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1536 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1537 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1538 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1539 case 'v': case 'w': case 'x': case 'y': case 'z':
1540 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1541 case '7': case '8': case '9':
1543 state
->buffer
[state
->offset
++] = *state
->ptr
;
1547 if (!(mb
= parse_mb(state
, PARSE_PATH
, state
->ptr
, state
->end
, tmp
, 0))) {
1548 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1553 state
->ptr
+= mb
- 1;
1555 } while (++state
->ptr
< state
->end
);
1558 /* did we have any path component ? */
1559 if (tmp
!= state
->ptr
) {
1560 state
->buffer
[state
->offset
++] = 0;
1562 state
->url
.path
= NULL
;
1567 static const char *parse_query(struct parse_state
*state
)
1570 const char *tmp
= state
->ptr
+ !!*state
->ptr
;
1572 /* is there actually a query to parse? */
1573 if (*state
->ptr
!= '?') {
1577 /* skip initial '?' */
1579 state
->url
.query
= &state
->buffer
[state
->offset
];
1581 while (state
->ptr
< state
->end
) {
1582 switch (*state
->ptr
) {
1587 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1588 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1589 php_error_docref(NULL
, E_WARNING
,
1590 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
1591 (unsigned) (state
->ptr
- tmp
), tmp
);
1593 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1596 /* fallthrough, pct-encode the percent sign */
1598 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1599 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1600 state
->buffer
[state
->offset
++] = *state
->ptr
;
1607 case '|': case '\\': case '^': case '`': case '"': case ' ':
1608 /* RFC1738 unsafe */
1609 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1610 state
->buffer
[state
->offset
++] = '%';
1611 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1612 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1617 case '?': case '/': /* yeah, well */
1618 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1619 case '+': case ',': case ';': case '=': /* sub-delims */
1620 case '-': case '.': case '_': case '~': /* unreserved */
1621 case ':': case '@': /* pchar */
1622 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1623 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1624 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1625 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1626 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1627 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1628 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1629 case 'v': case 'w': case 'x': case 'y': case 'z':
1630 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1631 case '7': case '8': case '9':
1633 state
->buffer
[state
->offset
++] = *state
->ptr
;
1637 if (!(mb
= parse_mb(state
, PARSE_QUERY
, state
->ptr
, state
->end
, tmp
, 0))) {
1638 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1643 state
->ptr
+= mb
- 1;
1650 state
->buffer
[state
->offset
++] = 0;
1654 static const char *parse_fragment(struct parse_state
*state
)
1659 /* is there actually a fragment to parse? */
1660 if (*state
->ptr
!= '#') {
1664 /* skip initial '#' */
1666 state
->url
.fragment
= &state
->buffer
[state
->offset
];
1669 switch (*state
->ptr
) {
1671 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1672 php_error_docref(NULL
, E_WARNING
,
1673 "Failed to parse fragment; invalid fragment identifier at pos %u in '%s'",
1674 (unsigned) (state
->ptr
- tmp
), tmp
);
1676 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1679 state
->buffer
[state
->offset
++] = *state
->ptr
;
1683 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1684 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1685 php_error_docref(NULL
, E_WARNING
,
1686 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
1687 (unsigned) (state
->ptr
- tmp
), tmp
);
1689 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1694 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1695 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1696 state
->buffer
[state
->offset
++] = *state
->ptr
;
1704 case '|': case '\\': case '^': case '`': case '"': case ' ':
1705 /* RFC1738 unsafe */
1706 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1707 state
->buffer
[state
->offset
++] = '%';
1708 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1709 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1715 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1716 case '+': case ',': case ';': case '=': /* sub-delims */
1717 case '-': case '.': case '_': case '~': /* unreserved */
1718 case ':': case '@': /* pchar */
1719 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1720 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1721 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1722 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1723 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1724 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1725 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1726 case 'v': case 'w': case 'x': case 'y': case 'z':
1727 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1728 case '7': case '8': case '9':
1730 state
->buffer
[state
->offset
++] = *state
->ptr
;
1734 if (!(mb
= parse_mb(state
, PARSE_FRAGMENT
, state
->ptr
, state
->end
, tmp
, 0))) {
1735 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1740 state
->ptr
+= mb
- 1;
1742 } while (++state
->ptr
< state
->end
);
1744 state
->buffer
[state
->offset
++] = 0;
1748 static const char *parse_hier(struct parse_state
*state
)
1750 if (*state
->ptr
== '/') {
1751 if (state
->end
- state
->ptr
> 1) {
1752 if (*(state
->ptr
+ 1) == '/') {
1754 if (!(state
->ptr
= parse_authority(state
))) {
1760 return parse_path(state
);
1763 static const char *parse_scheme(struct parse_state
*state
)
1766 const char *tmp
= state
->ptr
;
1769 switch (*state
->ptr
) {
1771 /* scheme delimiter */
1772 state
->url
.scheme
= &state
->buffer
[0];
1773 state
->buffer
[state
->offset
++] = 0;
1774 return ++state
->ptr
;
1776 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1777 case '7': case '8': case '9':
1778 case '+': case '-': case '.':
1779 if (state
->ptr
== tmp
) {
1783 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1784 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1785 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1786 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1787 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1788 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1789 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1790 case 'v': case 'w': case 'x': case 'y': case 'z':
1792 state
->buffer
[state
->offset
++] = *state
->ptr
;
1796 if (!(mb
= parse_mb(state
, PARSE_SCHEME
, state
->ptr
, state
->end
, tmp
, 1))) {
1799 state
->ptr
+= mb
- 1;
1801 } while (++state
->ptr
< state
->end
);
1805 return state
->ptr
= tmp
;
1808 php_http_url_t
*php_http_url_parse(const char *str
, size_t len
, unsigned flags
)
1810 size_t maxlen
= 3 * len
+ 8 /* null bytes for all components */;
1811 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1813 state
->end
= str
+ len
;
1815 state
->flags
= flags
;
1816 state
->maxlen
= maxlen
;
1818 if (!parse_scheme(state
)) {
1819 if (!(flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1820 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL scheme: '%s'", state
->ptr
);
1826 if (!parse_hier(state
)) {
1831 if (!parse_query(state
)) {
1832 if (!(flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1833 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL query: '%s'", state
->ptr
);
1839 if (!parse_fragment(state
)) {
1840 if (!(flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1841 php_error_docref(NULL
, E_WARNING
, "Failed to parse URL fragment: '%s'", state
->ptr
);
1847 return (php_http_url_t
*) state
;
1850 php_http_url_t
*php_http_url_parse_authority(const char *str
, size_t len
, unsigned flags
)
1852 size_t maxlen
= 3 * len
;
1853 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1855 state
->end
= str
+ len
;
1857 state
->flags
= flags
;
1858 state
->maxlen
= maxlen
;
1860 if (!(state
->ptr
= parse_authority(state
))) {
1865 if (state
->ptr
!= state
->end
) {
1866 if (!(state
->flags
& PHP_HTTP_URL_SILENT_ERRORS
)) {
1867 php_error_docref(NULL
, E_WARNING
,
1868 "Failed to parse URL authority, unexpected character at pos %u in '%s'",
1869 (unsigned) (state
->ptr
- str
), str
);
1871 if (!(state
->flags
& PHP_HTTP_URL_IGNORE_ERRORS
)) {
1877 return (php_http_url_t
*) state
;
1880 static zend_class_entry
*php_http_url_class_entry
;
1881 static zend_class_entry
*php_http_env_url_class_entry
;
1883 zend_class_entry
*php_http_url_get_class_entry(void)
1885 return php_http_url_class_entry
;
1888 zend_class_entry
*php_http_get_env_url_class_entry(void)
1890 return php_http_env_url_class_entry
;
1893 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct
, 0, 0, 0)
1894 ZEND_ARG_INFO(0, old_url
)
1895 ZEND_ARG_INFO(0, new_url
)
1896 ZEND_ARG_INFO(0, flags
)
1897 ZEND_END_ARG_INFO();
1898 PHP_METHOD(HttpUrl
, __construct
)
1900 zval
*new_url
= NULL
, *old_url
= NULL
;
1901 zend_long flags
= 0;
1902 zend_error_handling zeh
;
1904 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|z!z!l", &old_url
, &new_url
, &flags
), invalid_arg
, return);
1906 /* always set http\Url::FROM_ENV for instances of http\Env\Url */
1907 if (instanceof_function(Z_OBJCE_P(getThis()), php_http_env_url_class_entry
)) {
1908 flags
|= PHP_HTTP_URL_FROM_ENV
;
1911 if (flags
& (PHP_HTTP_URL_SILENT_ERRORS
|PHP_HTTP_URL_IGNORE_ERRORS
)) {
1912 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1914 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1917 php_http_url_t
*res_purl
, *new_purl
= NULL
, *old_purl
= NULL
;
1920 new_purl
= php_http_url_from_zval(new_url
, flags
);
1922 zend_restore_error_handling(&zeh
);
1927 old_purl
= php_http_url_from_zval(old_url
, flags
);
1930 php_http_url_free(&new_purl
);
1932 zend_restore_error_handling(&zeh
);
1937 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1938 php_http_url_to_struct(res_purl
, getThis());
1940 php_http_url_free(&res_purl
);
1942 php_http_url_free(&old_purl
);
1945 php_http_url_free(&new_purl
);
1948 zend_restore_error_handling(&zeh
);
1951 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod
, 0, 0, 1)
1952 ZEND_ARG_INFO(0, more_url_parts
)
1953 ZEND_ARG_INFO(0, flags
)
1954 ZEND_END_ARG_INFO();
1955 PHP_METHOD(HttpUrl
, mod
)
1957 zval
*new_url
= NULL
;
1958 zend_long flags
= PHP_HTTP_URL_JOIN_PATH
| PHP_HTTP_URL_JOIN_QUERY
| PHP_HTTP_URL_SANITIZE_PATH
;
1959 zend_error_handling zeh
;
1961 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url
, &flags
), invalid_arg
, return);
1963 if (flags
& (PHP_HTTP_URL_SILENT_ERRORS
|PHP_HTTP_URL_IGNORE_ERRORS
)) {
1964 zend_replace_error_handling(EH_NORMAL
, NULL
, &zeh
);
1966 zend_replace_error_handling(EH_THROW
, php_http_get_exception_bad_url_class_entry(), &zeh
);
1969 php_http_url_t
*new_purl
= NULL
, *old_purl
= NULL
;
1972 new_purl
= php_http_url_from_zval(new_url
, flags
);
1974 zend_restore_error_handling(&zeh
);
1979 if ((old_purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1980 php_http_url_t
*res_purl
;
1982 ZVAL_OBJ(return_value
, zend_objects_clone_obj(getThis()));
1984 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags
);
1985 php_http_url_to_struct(res_purl
, return_value
);
1987 php_http_url_free(&res_purl
);
1988 php_http_url_free(&old_purl
);
1991 php_http_url_free(&new_purl
);
1994 zend_restore_error_handling(&zeh
);
1997 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString
, 0, 0, 0)
1998 ZEND_END_ARG_INFO();
1999 PHP_METHOD(HttpUrl
, toString
)
2001 if (SUCCESS
== zend_parse_parameters_none()) {
2002 php_http_url_t
*purl
;
2004 if ((purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
2008 php_http_url_to_string(purl
, &str
, &len
, 0);
2009 php_http_url_free(&purl
);
2010 RETURN_STR(php_http_cs2zs(str
, len
));
2013 RETURN_EMPTY_STRING();
2016 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray
, 0, 0, 0)
2017 ZEND_END_ARG_INFO();
2018 PHP_METHOD(HttpUrl
, toArray
)
2020 php_http_url_t
*purl
;
2022 if (SUCCESS
!= zend_parse_parameters_none()) {
2026 /* strip any non-URL properties */
2027 purl
= php_http_url_from_struct(HASH_OF(getThis()));
2028 php_http_url_to_struct(purl
, return_value
);
2029 php_http_url_free(&purl
);
2032 static zend_function_entry php_http_url_methods
[] = {
2033 PHP_ME(HttpUrl
, __construct
, ai_HttpUrl___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
2034 PHP_ME(HttpUrl
, mod
, ai_HttpUrl_mod
, ZEND_ACC_PUBLIC
)
2035 PHP_ME(HttpUrl
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
2036 ZEND_MALIAS(HttpUrl
, __toString
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
2037 PHP_ME(HttpUrl
, toArray
, ai_HttpUrl_toArray
, ZEND_ACC_PUBLIC
)
2038 EMPTY_FUNCTION_ENTRY
2041 PHP_MINIT_FUNCTION(http_url
)
2043 zend_class_entry ce
= {0};
2045 INIT_NS_CLASS_ENTRY(ce
, "http", "Url", php_http_url_methods
);
2046 php_http_url_class_entry
= zend_register_internal_class(&ce
);
2048 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC
);
2049 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("user"), ZEND_ACC_PUBLIC
);
2050 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("pass"), ZEND_ACC_PUBLIC
);
2051 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("host"), ZEND_ACC_PUBLIC
);
2052 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("port"), ZEND_ACC_PUBLIC
);
2053 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("path"), ZEND_ACC_PUBLIC
);
2054 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("query"), ZEND_ACC_PUBLIC
);
2055 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC
);
2057 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE
);
2058 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH
);
2059 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY
);
2060 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER
);
2061 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS
);
2062 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH
);
2063 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT
);
2064 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH
);
2065 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY
);
2066 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT
);
2067 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL
);
2068 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV
);
2069 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH
);
2071 #if PHP_HTTP_HAVE_WCHAR
2072 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC
);
2074 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8
);
2075 #if PHP_HTTP_HAVE_LIBIDN2 || PHP_HTTP_HAVE_LIBIDN || PHP_HTTP_HAVE_LIBIDNKIT || PHP_HTTP_HAVE_LIBIDNKIT2 || HAVE_UIDNA_IDNTOASCII || HAVE_UIDNA_NAMETOASCII_UTF8
2076 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN
);
2077 # if PHP_HTTP_HAVE_IDNA2003
2078 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2003"), PHP_HTTP_URL_PARSE_TOIDN_2003
);
2080 # if PHP_HTTP_HAVE_IDNA2008
2081 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN_2008"), PHP_HTTP_URL_PARSE_TOIDN_2008
);
2084 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT
);
2086 INIT_NS_CLASS_ENTRY(ce
, "http\\Env", "Url", php_http_url_methods
);
2087 php_http_env_url_class_entry
= zend_register_internal_class_ex(&ce
, php_http_url_class_entry
);
2089 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("IGNORE_ERRORS"), PHP_HTTP_URL_IGNORE_ERRORS
);
2090 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SILENT_ERRORS"), PHP_HTTP_URL_SILENT_ERRORS
);
2092 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STDFLAGS"), PHP_HTTP_URL_STDFLAGS
);
2103 * vim600: noet sw=4 ts=4 fdm=marker
2104 * vim<600: noet sw=4 ts=4