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 #ifdef PHP_HTTP_HAVE_IDN
19 #ifdef PHP_HTTP_HAVE_WCHAR
24 #ifdef HAVE_ARPA_INET_H
25 # include <arpa/inet.h>
28 #include "php_http_utf8.h"
30 static inline char *localhostname(void)
32 char hostname
[1024] = {0};
35 if (SUCCESS
== gethostname(hostname
, lenof(hostname
))) {
36 return estrdup(hostname
);
38 #elif defined(HAVE_GETHOSTNAME)
39 if (SUCCESS
== gethostname(hostname
, lenof(hostname
))) {
40 # if defined(HAVE_GETDOMAINNAME)
41 size_t hlen
= strlen(hostname
);
42 if (hlen
<= lenof(hostname
) - lenof("(none)")) {
43 hostname
[hlen
++] = '.';
44 if (SUCCESS
== getdomainname(&hostname
[hlen
], lenof(hostname
) - hlen
)) {
45 if (!strcmp(&hostname
[hlen
], "(none)")) {
46 hostname
[hlen
- 1] = '\0';
48 return estrdup(hostname
);
52 if (strcmp(hostname
, "(none)")) {
53 return estrdup(hostname
);
57 return estrndup("localhost", lenof("localhost"));
60 #define url(buf) ((php_http_url_t *) buf.data)
62 static php_http_url_t
*php_http_url_from_env(TSRMLS_D
)
64 zval
*https
, *zhost
, *zport
;
66 php_http_buffer_t buf
;
68 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
69 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
70 memset(buf
.data
, 0, buf
.used
);
73 url(buf
)->scheme
= &buf
.data
[buf
.used
];
74 https
= php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1 TSRMLS_CC
);
75 if (https
&& !strcasecmp(Z_STRVAL_P(https
), "ON")) {
76 php_http_buffer_append(&buf
, "https", sizeof("https"));
78 php_http_buffer_append(&buf
, "http", sizeof("http"));
82 url(buf
)->host
= &buf
.data
[buf
.used
];
83 if ((((zhost
= php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1 TSRMLS_CC
)) ||
84 (zhost
= php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1 TSRMLS_CC
)) ||
85 (zhost
= php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1 TSRMLS_CC
)))) && Z_STRLEN_P(zhost
)) {
86 size_t stop_at
= strspn(Z_STRVAL_P(zhost
), "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.");
88 php_http_buffer_append(&buf
, Z_STRVAL_P(zhost
), stop_at
);
89 php_http_buffer_append(&buf
, "", 1);
91 char *host_str
= localhostname();
93 php_http_buffer_append(&buf
, host_str
, strlen(host_str
) + 1);
98 zport
= php_http_env_get_server_var(ZEND_STRL("SERVER_PORT"), 1 TSRMLS_CC
);
99 if (zport
&& IS_LONG
== is_numeric_string(Z_STRVAL_P(zport
), Z_STRLEN_P(zport
), &port
, NULL
, 0)) {
100 url(buf
)->port
= port
;
104 if (SG(request_info
).request_uri
&& SG(request_info
).request_uri
[0]) {
105 const char *q
= strchr(SG(request_info
).request_uri
, '?');
107 url(buf
)->path
= &buf
.data
[buf
.used
];
110 php_http_buffer_append(&buf
, SG(request_info
).request_uri
, q
- SG(request_info
).request_uri
);
111 php_http_buffer_append(&buf
, "", 1);
113 php_http_buffer_append(&buf
, SG(request_info
).request_uri
, strlen(SG(request_info
).request_uri
) + 1);
118 if (SG(request_info
).query_string
&& SG(request_info
).query_string
[0]) {
119 url(buf
)->query
= &buf
.data
[buf
.used
];
120 php_http_buffer_append(&buf
, SG(request_info
).query_string
, strlen(SG(request_info
).query_string
) + 1);
126 void php_http_url(int flags
, const php_url
*old_url
, const php_url
*new_url
, php_url
**url_ptr
, char **url_str
, size_t *url_len TSRMLS_DC
)
128 php_http_url_t
*url
= php_http_url_mod((const php_http_url_t
*) old_url
, (const php_http_url_t
*) new_url
, flags TSRMLS_CC
);
131 *url_ptr
= php_http_url_to_php_url(url
);
134 php_http_url_to_string(url
, url_str
, url_len TSRMLS_CC
);
137 php_http_url_free(&url
);
140 #define url_isset(u,n) \
142 #define url_copy(n) do { \
143 if (url_isset(new_url, n)) { \
144 url(buf)->n = &buf.data[buf.used]; \
145 php_http_buffer_append(&buf, new_url->n, strlen(new_url->n) + 1); \
146 } else if (url_isset(old_url, n)) { \
147 url(buf)->n = &buf.data[buf.used]; \
148 php_http_buffer_append(&buf, old_url->n, strlen(old_url->n) + 1); \
152 php_http_url_t
*php_http_url_mod(const php_http_url_t
*old_url
, const php_http_url_t
*new_url
, unsigned flags TSRMLS_DC
)
154 php_http_url_t
*tmp_url
= NULL
;
155 php_http_buffer_t buf
;
157 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
158 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
159 memset(buf
.data
, 0, buf
.used
);
161 /* set from env if requested */
162 if (flags
& PHP_HTTP_URL_FROM_ENV
) {
163 php_http_url_t
*env_url
= php_http_url_from_env(TSRMLS_C
);
165 old_url
= tmp_url
= php_http_url_mod(env_url
, old_url
, flags
^ PHP_HTTP_URL_FROM_ENV TSRMLS_CC
);
166 php_http_url_free(&env_url
);
171 if (!(flags
& PHP_HTTP_URL_STRIP_USER
)) {
175 if (!(flags
& PHP_HTTP_URL_STRIP_PASS
)) {
181 if (!(flags
& PHP_HTTP_URL_STRIP_PORT
)) {
182 url(buf
)->port
= url_isset(new_url
, port
) ? new_url
->port
: ((old_url
) ? old_url
->port
: 0);
185 if (!(flags
& PHP_HTTP_URL_STRIP_PATH
)) {
186 if ((flags
& PHP_HTTP_URL_JOIN_PATH
) && url_isset(old_url
, path
) && url_isset(new_url
, path
) && *new_url
->path
!= '/') {
187 size_t old_path_len
= strlen(old_url
->path
), new_path_len
= strlen(new_url
->path
);
188 char *path
= ecalloc(1, old_path_len
+ new_path_len
+ 1 + 1);
190 strcat(path
, old_url
->path
);
191 if (path
[old_path_len
- 1] != '/') {
192 php_dirname(path
, old_path_len
);
195 strcat(path
, new_url
->path
);
197 url(buf
)->path
= &buf
.data
[buf
.used
];
198 if (path
[0] != '/') {
199 php_http_buffer_append(&buf
, "/", 1);
201 php_http_buffer_append(&buf
, path
, strlen(path
) + 1);
204 const char *path
= NULL
;
206 url(buf
)->path
= &buf
.data
[buf
.used
];
208 if (url_isset(new_url
, path
)) {
209 path
= new_url
->path
;
210 } else if (url_isset(old_url
, path
)) {
211 path
= old_url
->path
;
213 php_http_buffer_append(&buf
, "/", sizeof("/"));
217 if (path
[0] != '/') {
218 php_http_buffer_append(&buf
, "/", 1);
220 php_http_buffer_append(&buf
, path
, strlen(path
) + 1);
227 if (!(flags
& PHP_HTTP_URL_STRIP_QUERY
)) {
228 if ((flags
& PHP_HTTP_URL_JOIN_QUERY
) && url_isset(new_url
, query
) && url_isset(old_url
, query
)) {
235 ZVAL_STRING(&qstr
, old_url
->query
, 0);
236 php_http_querystring_update(&qarr
, &qstr
, NULL TSRMLS_CC
);
237 ZVAL_STRING(&qstr
, new_url
->query
, 0);
238 php_http_querystring_update(&qarr
, &qstr
, NULL TSRMLS_CC
);
241 php_http_querystring_update(&qarr
, NULL
, &qstr TSRMLS_CC
);
243 url(buf
)->query
= &buf
.data
[buf
.used
];
244 php_http_buffer_append(&buf
, Z_STRVAL(qstr
), Z_STRLEN(qstr
) + 1);
253 if (!(flags
& PHP_HTTP_URL_STRIP_FRAGMENT
)) {
257 /* done with copy & combine & strip */
259 if (flags
& PHP_HTTP_URL_FROM_ENV
) {
260 /* free old_url we tainted above */
261 php_http_url_free(&tmp_url
);
264 /* set some sane defaults */
266 if (!url(buf
)->scheme
) {
267 url(buf
)->scheme
= &buf
.data
[buf
.used
];
268 php_http_buffer_append(&buf
, "http", sizeof("http"));
271 if (!url(buf
)->host
) {
272 url(buf
)->host
= &buf
.data
[buf
.used
];
273 php_http_buffer_append(&buf
, "localhost", sizeof("localhost"));
276 if (!url(buf
)->path
) {
277 url(buf
)->path
= &buf
.data
[buf
.used
];
278 php_http_buffer_append(&buf
, "/", sizeof("/"));
280 /* replace directory references if path is not a single slash */
281 if ((flags
& PHP_HTTP_URL_SANITIZE_PATH
)
282 && url(buf
)->path
[0] && url(buf
)->path
[1]) {
283 char *ptr
, *end
= url(buf
)->path
+ strlen(url(buf
)->path
) + 1;
285 for (ptr
= strchr(url(buf
)->path
, '/'); ptr
; ptr
= strchr(ptr
, '/')) {
288 memmove(&ptr
[1], &ptr
[2], end
- &ptr
[2]);
298 memmove(&ptr
[1], &ptr
[3], end
- &ptr
[3]);
304 while (ptr
!= url(buf
)->path
) {
309 memmove(&ptr
[1], pos
, end
- pos
);
311 } else if (!ptr
[3]) {
330 /* unset default ports */
331 if (url(buf
)->port
) {
332 if ( ((url(buf
)->port
== 80) && !strcmp(url(buf
)->scheme
, "http"))
333 || ((url(buf
)->port
==443) && !strcmp(url(buf
)->scheme
, "https"))
342 void php_http_url_to_string(const php_http_url_t
*url
, char **url_str
, size_t *url_len TSRMLS_DC
)
344 php_http_buffer_t buf
;
346 php_http_buffer_init(&buf
);
348 if (url
->scheme
&& *url
->scheme
) {
349 php_http_buffer_appendl(&buf
, url
->scheme
);
350 php_http_buffer_appends(&buf
, "://");
352 php_http_buffer_appends(&buf
, "//");
355 if (url
->user
&& *url
->user
) {
356 php_http_buffer_appendl(&buf
, url
->user
);
357 if (url
->pass
&& *url
->pass
) {
358 php_http_buffer_appends(&buf
, ":");
359 php_http_buffer_appendl(&buf
, url
->pass
);
361 php_http_buffer_appends(&buf
, "@");
364 if (url
->host
&& *url
->host
) {
365 php_http_buffer_appendl(&buf
, url
->host
);
367 php_http_buffer_appends(&buf
, "localhost");
371 php_http_buffer_appendf(&buf
, ":%hu", url
->port
);
374 if (url
->path
&& *url
->path
) {
375 php_http_buffer_appendl(&buf
, url
->path
);
378 if (url
->query
&& *url
->query
) {
379 php_http_buffer_appends(&buf
, "?");
380 php_http_buffer_appendl(&buf
, url
->query
);
383 if (url
->fragment
&& *url
->fragment
) {
384 php_http_buffer_appends(&buf
, "#");
385 php_http_buffer_appendl(&buf
, url
->fragment
);
388 php_http_buffer_shrink(&buf
);
389 php_http_buffer_fix(&buf
);
398 php_http_buffer_dtor(&buf
);
402 php_http_url_t
*php_http_url_from_struct(HashTable
*ht TSRMLS_DC
)
405 php_http_buffer_t buf
;
407 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
408 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
409 memset(buf
.data
, 0, buf
.used
);
411 if (SUCCESS
== zend_hash_find(ht
, "scheme", sizeof("scheme"), (void *) &e
)) {
412 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
413 url(buf
)->scheme
= &buf
.data
[buf
.used
];
414 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
417 if (SUCCESS
== zend_hash_find(ht
, "user", sizeof("user"), (void *) &e
)) {
418 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
419 url(buf
)->user
= &buf
.data
[buf
.used
];
420 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
423 if (SUCCESS
== zend_hash_find(ht
, "pass", sizeof("pass"), (void *) &e
)) {
424 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
425 url(buf
)->pass
= &buf
.data
[buf
.used
];
426 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
429 if (SUCCESS
== zend_hash_find(ht
, "host", sizeof("host"), (void *) &e
)) {
430 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
431 url(buf
)->host
= &buf
.data
[buf
.used
];
432 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
435 if (SUCCESS
== zend_hash_find(ht
, "port", sizeof("port"), (void *) &e
)) {
436 zval
*cpy
= php_http_ztyp(IS_LONG
, *e
);
437 url(buf
)->port
= (unsigned short) Z_LVAL_P(cpy
);
440 if (SUCCESS
== zend_hash_find(ht
, "path", sizeof("path"), (void *) &e
)) {
441 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
442 url(buf
)->path
= &buf
.data
[buf
.used
];
443 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
446 if (SUCCESS
== zend_hash_find(ht
, "query", sizeof("query"), (void *) &e
)) {
447 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
448 url(buf
)->query
= &buf
.data
[buf
.used
];
449 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
452 if (SUCCESS
== zend_hash_find(ht
, "fragment", sizeof("fragment"), (void *) &e
)) {
453 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
454 url(buf
)->fragment
= &buf
.data
[buf
.used
];
455 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
462 HashTable
*php_http_url_to_struct(const php_http_url_t
*url
, zval
*strct TSRMLS_DC
)
467 switch (Z_TYPE_P(strct
)) {
474 INIT_PZVAL_ARRAY((&arr
), HASH_OF(strct
));
484 add_assoc_string(&arr
, "scheme", url
->scheme
, 1);
487 add_assoc_string(&arr
, "user", url
->user
, 1);
490 add_assoc_string(&arr
, "pass", url
->pass
, 1);
493 add_assoc_string(&arr
, "host", url
->host
, 1);
496 add_assoc_long(&arr
, "port", (long) url
->port
);
499 add_assoc_string(&arr
, "path", url
->path
, 1);
502 add_assoc_string(&arr
, "query", url
->query
, 1);
505 add_assoc_string(&arr
, "fragment", url
->fragment
, 1);
509 return Z_ARRVAL(arr
);
512 STATUS
php_http_url_encode_hash(HashTable
*hash
, const char *pre_encoded_str
, size_t pre_encoded_len
, char **encoded_str
, size_t *encoded_len TSRMLS_DC
)
514 const char *arg_sep_str
;
516 php_http_buffer_t
*qstr
= php_http_buffer_new();
518 php_http_url_argsep(&arg_sep_str
, &arg_sep_len TSRMLS_CC
);
520 if (SUCCESS
!= php_http_url_encode_hash_ex(hash
, qstr
, arg_sep_str
, arg_sep_len
, "=", 1, pre_encoded_str
, pre_encoded_len TSRMLS_CC
)) {
521 php_http_buffer_free(&qstr
);
525 php_http_buffer_data(qstr
, encoded_str
, encoded_len
);
526 php_http_buffer_free(&qstr
);
531 STATUS
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 TSRMLS_DC
)
533 if (pre_encoded_len
&& pre_encoded_str
) {
534 php_http_buffer_append(qstr
, pre_encoded_str
, pre_encoded_len
);
537 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 TSRMLS_CC
)) {
554 char buffer
[1]; /* last member */
557 void php_http_url_free(php_http_url_t
**url
)
565 static size_t parse_mb_utf8(unsigned *wc
, const char *ptr
, const char *end
)
568 size_t consumed
= utf8towc(&wchar
, (const unsigned char *) ptr
, end
- ptr
);
570 if (!consumed
|| consumed
== (size_t) -1) {
580 #ifdef PHP_HTTP_HAVE_WCHAR
581 static size_t parse_mb_loc(unsigned *wc
, const char *ptr
, const char *end
)
585 #if defined(HAVE_MBRTOWC)
588 consumed
= mbrtowc(&wchar
, ptr
, end
- ptr
, &ps
);
589 #elif defined(HAVE_MBTOWC)
590 consumed
= mbtowc(&wchar
, ptr
, end
- ptr
);
593 if (!consumed
|| consumed
== (size_t) -1) {
604 typedef enum parse_mb_what
{
613 static const char * const parse_what
[] = {
622 static const char parse_xdigits
[] = "0123456789ABCDEF";
624 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
)
629 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
630 consumed
= parse_mb_utf8(&wchar
, ptr
, end
);
632 #ifdef PHP_HTTP_HAVE_WCHAR
633 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
634 consumed
= parse_mb_loc(&wchar
, ptr
, end
);
639 if (!(state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) || what
== PARSE_HOSTINFO
|| what
== PARSE_SCHEME
) {
640 if (what
== PARSE_HOSTINFO
&& (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
)) {
642 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
643 if (!isualnum(wchar
)) {
646 #ifdef PHP_HTTP_HAVE_WCHAR
647 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
648 if (!iswalnum(wchar
)) {
653 PHP_HTTP_DUFF(consumed
, state
->buffer
[state
->offset
++] = *ptr
++);
657 PHP_HTTP_DUFF(consumed
,
658 state
->buffer
[state
->offset
++] = '%';
659 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) >> 4];
660 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) & 0xf];
669 TSRMLS_FETCH_FROM_CTX(state
->ts
);
670 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
671 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
672 parse_what
[what
], (unsigned char) *ptr
, (unsigned) (ptr
- begin
), begin
);
678 static STATUS
parse_userinfo(struct parse_state
*state
, const char *ptr
)
681 const char *password
= NULL
, *end
= state
->ptr
, *tmp
= ptr
;
682 TSRMLS_FETCH_FROM_CTX(state
->ts
);
684 state
->url
.user
= &state
->buffer
[state
->offset
];
690 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
691 "Failed to parse password; duplicate ':' at pos %u in '%s'",
692 (unsigned) (ptr
- tmp
), tmp
);
696 state
->buffer
[state
->offset
++] = 0;
697 state
->url
.pass
= &state
->buffer
[state
->offset
];
701 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
702 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
703 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
704 (unsigned) (ptr
- tmp
), tmp
);
707 state
->buffer
[state
->offset
++] = *ptr
++;
708 state
->buffer
[state
->offset
++] = *ptr
++;
709 state
->buffer
[state
->offset
++] = *ptr
;
712 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
713 case '+': case ',': case ';': case '=': /* sub-delims */
714 case '-': case '.': case '_': case '~': /* unreserved */
715 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
716 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
717 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
718 case 'V': case 'W': case 'X': case 'Y': case 'Z':
719 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
720 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
721 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
722 case 'v': case 'w': case 'x': case 'y': case 'z':
723 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
724 case '7': case '8': case '9':
726 state
->buffer
[state
->offset
++] = *ptr
;
730 if (!(mb
= parse_mb(state
, PARSE_USERINFO
, ptr
, end
, tmp
, 0))) {
735 } while(++ptr
!= end
);
738 state
->buffer
[state
->offset
++] = 0;
743 static STATUS
parse_hostinfo(struct parse_state
*state
, const char *ptr
)
746 const char *end
= state
->ptr
, *tmp
= ptr
, *port
= NULL
;
747 TSRMLS_FETCH_FROM_CTX(state
->ts
);
750 #ifdef HAVE_INET_PTON
752 char *error
= NULL
, *tmp
= memchr(ptr
, ']', end
- ptr
);
755 size_t addrlen
= tmp
- ptr
+ 1;
756 char buf
[16], *addr
= estrndup(ptr
+ 1, addrlen
- 2);
757 int rv
= inet_pton(AF_INET6
, addr
, buf
);
761 state
->buffer
[state
->offset
] = '[';
762 state
->url
.host
= &state
->buffer
[state
->offset
];
763 inet_ntop(AF_INET6
, buf
, state
->url
.host
+ 1, state
->maxlen
- state
->offset
);
764 state
->offset
+= strlen(state
->url
.host
);
765 state
->buffer
[state
->offset
++] = ']';
766 state
->buffer
[state
->offset
++] = 0;
768 } else if (rv
== -1) {
769 error
= strerror(errno
);
771 error
= "unexpected '['";
774 error
= "expected ']'";
778 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse hostinfo; %s", error
);
787 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
788 "Failed to parse port; unexpected ':' at pos %u in '%s'",
789 (unsigned) (ptr
- tmp
), tmp
);
796 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
797 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
798 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
799 (unsigned) (ptr
- tmp
), tmp
);
802 state
->buffer
[state
->offset
++] = *ptr
++;
803 state
->buffer
[state
->offset
++] = *ptr
++;
804 state
->buffer
[state
->offset
++] = *ptr
;
807 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
808 case '+': case ',': case ';': case '=': /* sub-delims */
809 case '-': case '.': case '_': case '~': /* unreserved */
810 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
811 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
812 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
813 case 'V': case 'W': case 'X': case 'Y': case 'Z':
814 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
815 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
816 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
817 case 'v': case 'w': case 'x': case 'y': case 'z':
819 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
820 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
821 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
825 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
826 case '7': case '8': case '9':
829 state
->url
.port
*= 10;
830 state
->url
.port
+= *ptr
- '0';
832 state
->buffer
[state
->offset
++] = *ptr
;
838 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
839 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
840 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
842 } else if (!(mb
= parse_mb(state
, PARSE_HOSTINFO
, ptr
, end
, tmp
, 0))) {
847 } while (++ptr
!= end
);
849 if (!state
->url
.host
) {
850 len
= (port
? port
- tmp
- 1 : end
- tmp
);
851 state
->url
.host
= &state
->buffer
[state
->offset
- len
];
852 state
->buffer
[state
->offset
++] = 0;
855 #ifdef PHP_HTTP_HAVE_IDN
856 if (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
) {
860 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
861 rv
= idna_to_ascii_8z(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
|IDNA_USE_STD3_ASCII_RULES
);
863 # ifdef PHP_HTTP_HAVE_WCHAR
864 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
865 rv
= idna_to_ascii_lz(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
|IDNA_USE_STD3_ASCII_RULES
);
868 if (rv
!= IDNA_SUCCESS
) {
869 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse IDN; %s", idna_strerror(rv
));
872 size_t idnlen
= strlen(idn
);
873 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
875 state
->offset
+= idnlen
- len
;
883 static const char *parse_authority(struct parse_state
*state
)
885 const char *tmp
= state
->ptr
, *host
= NULL
;
888 switch (*state
->ptr
) {
890 /* userinfo delimiter */
892 TSRMLS_FETCH_FROM_CTX(state
->ts
);
893 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
894 "Failed to parse userinfo; unexpected '@'");
897 host
= state
->ptr
+ 1;
898 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_userinfo(state
, tmp
)) {
901 tmp
= state
->ptr
+ 1;
909 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_hostinfo(state
, tmp
)) {
914 } while (++state
->ptr
<= state
->end
);
919 static const char *parse_path(struct parse_state
*state
)
923 TSRMLS_FETCH_FROM_CTX(state
->ts
);
925 /* is there actually a path to parse? */
930 state
->url
.path
= &state
->buffer
[state
->offset
];
933 switch (*state
->ptr
) {
937 /* did we have any path component ? */
938 if (tmp
!= state
->ptr
) {
939 state
->buffer
[state
->offset
++] = 0;
941 state
->url
.path
= NULL
;
946 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
947 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
948 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
949 (unsigned) (state
->ptr
- tmp
), tmp
);
952 state
->buffer
[state
->offset
++] = *state
->ptr
++;
953 state
->buffer
[state
->offset
++] = *state
->ptr
++;
954 state
->buffer
[state
->offset
++] = *state
->ptr
;
957 case '/': /* yeah, well */
958 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
959 case '+': case ',': case ';': case '=': /* sub-delims */
960 case '-': case '.': case '_': case '~': /* unreserved */
961 case ':': case '@': /* pchar */
962 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
963 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
964 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
965 case 'V': case 'W': case 'X': case 'Y': case 'Z':
966 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
967 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
968 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
969 case 'v': case 'w': case 'x': case 'y': case 'z':
970 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
971 case '7': case '8': case '9':
973 state
->buffer
[state
->offset
++] = *state
->ptr
;
977 if (!(mb
= parse_mb(state
, PARSE_PATH
, state
->ptr
, state
->end
, tmp
, 0))) {
980 state
->ptr
+= mb
- 1;
982 } while (++state
->ptr
<= state
->end
);
987 static const char *parse_query(struct parse_state
*state
)
990 const char *tmp
= state
->ptr
+ !!*state
->ptr
;
991 TSRMLS_FETCH_FROM_CTX(state
->ts
);
993 /* is there actually a query to parse? */
994 if (*state
->ptr
!= '?') {
998 /* skip initial '?' */
1000 state
->url
.query
= &state
->buffer
[state
->offset
];
1003 switch (*state
->ptr
) {
1006 state
->buffer
[state
->offset
++] = 0;
1010 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1011 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1012 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
1013 (unsigned) (state
->ptr
- tmp
), tmp
);
1016 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1017 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1018 state
->buffer
[state
->offset
++] = *state
->ptr
;
1023 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1024 state
->buffer
[state
->offset
++] = '%';
1025 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1026 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1031 case '?': case '/': /* yeah, well */
1032 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1033 case '+': case ',': case ';': case '=': /* sub-delims */
1034 case '-': case '.': case '_': case '~': /* unreserved */
1035 case ':': case '@': /* pchar */
1036 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1037 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1038 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1039 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1040 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1041 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1042 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1043 case 'v': case 'w': case 'x': case 'y': case 'z':
1044 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1045 case '7': case '8': case '9':
1047 state
->buffer
[state
->offset
++] = *state
->ptr
;
1051 if (!(mb
= parse_mb(state
, PARSE_QUERY
, state
->ptr
, state
->end
, tmp
, 0))) {
1054 state
->ptr
+= mb
- 1;
1056 } while (++state
->ptr
<= state
->end
);
1061 static const char *parse_fragment(struct parse_state
*state
)
1065 TSRMLS_FETCH_FROM_CTX(state
->ts
);
1067 /* is there actually a fragment to parse? */
1068 if (*state
->ptr
!= '#') {
1072 /* skip initial '#' */
1074 state
->url
.fragment
= &state
->buffer
[state
->offset
];
1077 switch (*state
->ptr
) {
1079 state
->buffer
[state
->offset
++] = 0;
1083 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1084 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1085 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
1086 (unsigned) (state
->ptr
- tmp
), tmp
);
1089 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1090 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1091 state
->buffer
[state
->offset
++] = *state
->ptr
;
1095 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1096 case '+': case ',': case ';': case '=': /* sub-delims */
1097 case '-': case '.': case '_': case '~': /* unreserved */
1098 case ':': case '@': /* pchar */
1099 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1100 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1101 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1102 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1103 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1104 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1105 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1106 case 'v': case 'w': case 'x': case 'y': case 'z':
1107 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1108 case '7': case '8': case '9':
1110 state
->buffer
[state
->offset
++] = *state
->ptr
;
1114 if (!(mb
= parse_mb(state
, PARSE_FRAGMENT
, state
->ptr
, state
->end
, tmp
, 0))) {
1117 state
->ptr
+= mb
- 1;
1119 } while (++state
->ptr
<= state
->end
);
1124 static const char *parse_hier(struct parse_state
*state
)
1126 if (*state
->ptr
== '/') {
1127 if (state
->end
- state
->ptr
> 1) {
1128 if (*(state
->ptr
+ 1) == '/') {
1130 if (!(state
->ptr
= parse_authority(state
))) {
1136 return parse_path(state
);
1139 static const char *parse_scheme(struct parse_state
*state
)
1142 const char *tmp
= state
->ptr
;
1145 switch (*state
->ptr
) {
1147 /* scheme delimiter */
1148 state
->url
.scheme
= &state
->buffer
[0];
1149 state
->buffer
[state
->offset
++] = 0;
1150 return ++state
->ptr
;
1152 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1153 case '7': case '8': case '9':
1154 case '+': case '-': case '.':
1155 if (state
->ptr
== tmp
) {
1159 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1160 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1161 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1162 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1163 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1164 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1165 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1166 case 'v': case 'w': case 'x': case 'y': case 'z':
1168 state
->buffer
[state
->offset
++] = *state
->ptr
;
1172 if (!(mb
= parse_mb(state
, PARSE_SCHEME
, state
->ptr
, state
->end
, tmp
, 1))) {
1173 /* soft fail; parse path next */
1176 state
->ptr
+= mb
- 1;
1178 } while (++state
->ptr
!= state
->end
);
1180 return state
->ptr
= tmp
;
1183 php_http_url_t
*php_http_url_parse(const char *str
, size_t len
, unsigned flags TSRMLS_DC
)
1185 size_t maxlen
= 3 * len
;
1186 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1188 state
->end
= str
+ len
;
1190 state
->flags
= flags
;
1191 state
->maxlen
= maxlen
;
1192 TSRMLS_SET_CTX(state
->ts
);
1194 if (!parse_scheme(state
)) {
1195 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse URL scheme: '%s'", state
->ptr
);
1200 if (!parse_hier(state
)) {
1205 if (!parse_query(state
)) {
1206 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse URL query: '%s'", state
->ptr
);
1211 if (!parse_fragment(state
)) {
1212 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse URL fragment: '%s'", state
->ptr
);
1217 return (php_http_url_t
*) state
;
1220 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct
, 0, 0, 0)
1221 ZEND_ARG_INFO(0, old_url
)
1222 ZEND_ARG_INFO(0, new_url
)
1223 ZEND_ARG_INFO(0, flags
)
1224 ZEND_END_ARG_INFO();
1225 PHP_METHOD(HttpUrl
, __construct
)
1227 zval
*new_url
= NULL
, *old_url
= NULL
;
1228 long flags
= PHP_HTTP_URL_FROM_ENV
;
1229 zend_error_handling zeh
;
1231 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|z!z!l", &old_url
, &new_url
, &flags
), invalid_arg
, return);
1233 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_url_class_entry
, &zeh TSRMLS_CC
);
1235 php_http_url_t
*res_purl
, *new_purl
= NULL
, *old_purl
= NULL
;
1238 switch (Z_TYPE_P(new_url
)) {
1241 new_purl
= php_http_url_from_struct(HASH_OF(new_url
) TSRMLS_CC
);
1244 zval
*cpy
= php_http_ztyp(IS_STRING
, new_url
);
1246 new_purl
= php_http_url_parse(Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
), flags TSRMLS_CC
);
1247 zval_ptr_dtor(&cpy
);
1252 zend_restore_error_handling(&zeh TSRMLS_CC
);
1257 switch (Z_TYPE_P(old_url
)) {
1260 old_purl
= php_http_url_from_struct(HASH_OF(old_url
) TSRMLS_CC
);
1263 zval
*cpy
= php_http_ztyp(IS_STRING
, old_url
);
1265 old_purl
= php_http_url_parse(Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
), flags TSRMLS_CC
);
1266 zval_ptr_dtor(&cpy
);
1272 php_http_url_free(&new_purl
);
1274 zend_restore_error_handling(&zeh TSRMLS_CC
);
1279 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags TSRMLS_CC
);
1280 php_http_url_to_struct(res_purl
, getThis() TSRMLS_CC
);
1282 php_http_url_free(&res_purl
);
1284 php_http_url_free(&old_purl
);
1287 php_http_url_free(&new_purl
);
1290 zend_restore_error_handling(&zeh TSRMLS_CC
);
1293 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod
, 0, 0, 1)
1294 ZEND_ARG_INFO(0, more_url_parts
)
1295 ZEND_ARG_INFO(0, flags
)
1296 ZEND_END_ARG_INFO();
1297 PHP_METHOD(HttpUrl
, mod
)
1299 zval
*new_url
= NULL
;
1300 long flags
= PHP_HTTP_URL_JOIN_PATH
| PHP_HTTP_URL_JOIN_QUERY
;
1301 zend_error_handling zeh
;
1303 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z!|l", &new_url
, &flags
), invalid_arg
, return);
1305 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_url_class_entry
, &zeh TSRMLS_CC
);
1307 php_http_url_t
*new_purl
= NULL
, *old_purl
= NULL
;
1310 switch (Z_TYPE_P(new_url
)) {
1313 new_purl
= php_http_url_from_struct(HASH_OF(new_url
) TSRMLS_CC
);
1316 zval
*cpy
= php_http_ztyp(IS_STRING
, new_url
);
1318 new_purl
= php_http_url_parse(Z_STRVAL_P(new_url
), Z_STRLEN_P(new_url
), flags TSRMLS_CC
);
1319 zval_ptr_dtor(&cpy
);
1324 zend_restore_error_handling(&zeh TSRMLS_CC
);
1329 if ((old_purl
= php_http_url_from_struct(HASH_OF(getThis()) TSRMLS_CC
))) {
1330 php_http_url_t
*res_purl
;
1332 ZVAL_OBJVAL(return_value
, zend_objects_clone_obj(getThis() TSRMLS_CC
), 0);
1334 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags TSRMLS_CC
);
1335 php_http_url_to_struct(res_purl
, return_value TSRMLS_CC
);
1337 php_http_url_free(&res_purl
);
1338 php_http_url_free(&old_purl
);
1341 php_http_url_free(&new_purl
);
1344 zend_restore_error_handling(&zeh TSRMLS_CC
);
1347 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString
, 0, 0, 0)
1348 ZEND_END_ARG_INFO();
1349 PHP_METHOD(HttpUrl
, toString
)
1351 if (SUCCESS
== zend_parse_parameters_none()) {
1352 php_http_url_t
*purl
;
1354 if ((purl
= php_http_url_from_struct(HASH_OF(getThis()) TSRMLS_CC
))) {
1358 php_http_url_to_string(purl
, &str
, &len TSRMLS_CC
);
1359 php_http_url_free(&purl
);
1360 RETURN_STRINGL(str
, len
, 0);
1363 RETURN_EMPTY_STRING();
1366 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray
, 0, 0, 0)
1367 ZEND_END_ARG_INFO();
1368 PHP_METHOD(HttpUrl
, toArray
)
1370 php_http_url_t
*purl
;
1372 if (SUCCESS
!= zend_parse_parameters_none()) {
1376 /* strip any non-URL properties */
1377 purl
= php_http_url_from_struct(HASH_OF(getThis()) TSRMLS_CC
);
1378 php_http_url_to_struct(purl
, return_value TSRMLS_CC
);
1379 php_http_url_free(&purl
);
1382 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_parse
, 0, 0, 1)
1383 ZEND_ARG_INFO(0, url
)
1384 ZEND_ARG_INFO(0, flags
)
1385 ZEND_END_ARG_INFO();
1386 PHP_METHOD(HttpUrl
, parse
)
1391 php_http_url_t
*url
;
1392 zend_error_handling zeh
;
1394 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|l", &str
, &len
, &flags
), invalid_arg
, return);
1396 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_url_class_entry
, &zeh TSRMLS_CC
);
1397 if ((url
= php_http_url_parse(str
, len
, flags TSRMLS_CC
))) {
1398 object_init_ex(return_value
, php_http_url_class_entry
);
1400 zend_update_property_string(php_http_url_class_entry
, return_value
,
1401 ZEND_STRL("scheme"), url
->scheme TSRMLS_CC
);
1404 zend_update_property_string(php_http_url_class_entry
, return_value
,
1405 ZEND_STRL("user"), url
->user TSRMLS_CC
);
1408 zend_update_property_string(php_http_url_class_entry
, return_value
,
1409 ZEND_STRL("pass"), url
->pass TSRMLS_CC
);
1412 zend_update_property_string(php_http_url_class_entry
, return_value
,
1413 ZEND_STRL("host"), url
->host TSRMLS_CC
);
1416 zend_update_property_long(php_http_url_class_entry
, return_value
,
1417 ZEND_STRL("port"), url
->port TSRMLS_CC
);
1420 zend_update_property_string(php_http_url_class_entry
, return_value
,
1421 ZEND_STRL("path"), url
->path TSRMLS_CC
);
1424 zend_update_property_string(php_http_url_class_entry
, return_value
,
1425 ZEND_STRL("query"), url
->query TSRMLS_CC
);
1427 if (url
->fragment
) {
1428 zend_update_property_string(php_http_url_class_entry
, return_value
,
1429 ZEND_STRL("fragment"), url
->fragment TSRMLS_CC
);
1431 php_http_url_free(&url
);
1433 zend_restore_error_handling(&zeh TSRMLS_CC
);
1436 static zend_function_entry php_http_url_methods
[] = {
1437 PHP_ME(HttpUrl
, __construct
, ai_HttpUrl___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
1438 PHP_ME(HttpUrl
, mod
, ai_HttpUrl_mod
, ZEND_ACC_PUBLIC
)
1439 PHP_ME(HttpUrl
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
1440 ZEND_MALIAS(HttpUrl
, __toString
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
1441 PHP_ME(HttpUrl
, toArray
, ai_HttpUrl_toArray
, ZEND_ACC_PUBLIC
)
1442 PHP_ME(HttpUrl
, parse
, ai_HttpUrl_parse
, ZEND_ACC_PUBLIC
|ZEND_ACC_STATIC
)
1443 EMPTY_FUNCTION_ENTRY
1446 zend_class_entry
*php_http_url_class_entry
;
1448 PHP_MINIT_FUNCTION(http_url
)
1450 zend_class_entry ce
= {0};
1452 INIT_NS_CLASS_ENTRY(ce
, "http", "Url", php_http_url_methods
);
1453 php_http_url_class_entry
= zend_register_internal_class(&ce TSRMLS_CC
);
1455 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1456 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1457 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1458 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1459 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1460 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1461 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1462 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1464 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC
);
1465 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC
);
1466 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC
);
1467 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC
);
1468 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC
);
1469 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC
);
1470 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC
);
1471 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC
);
1472 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC
);
1473 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC
);
1474 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC
);
1475 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC
);
1476 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC
);
1478 #ifdef PHP_HTTP_HAVE_WCHAR
1479 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC
);
1481 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC
);
1482 #ifdef PHP_HTTP_HAVE_IDN
1483 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC
);
1485 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC
);
1496 * vim600: noet sw=4 ts=4 fdm=marker
1497 * vim<600: noet sw=4 ts=4