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
, 0);
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 if (url_isset(new_url
, path
)) {
207 path
= new_url
->path
;
208 } else if (url_isset(old_url
, path
)) {
209 path
= old_url
->path
;
213 url(buf
)->path
= &buf
.data
[buf
.used
];
215 php_http_buffer_append(&buf
, path
, strlen(path
) + 1);
222 if (!(flags
& PHP_HTTP_URL_STRIP_QUERY
)) {
223 if ((flags
& PHP_HTTP_URL_JOIN_QUERY
) && url_isset(new_url
, query
) && url_isset(old_url
, query
)) {
230 ZVAL_STRING(&qstr
, old_url
->query
, 0);
231 php_http_querystring_update(&qarr
, &qstr
, NULL TSRMLS_CC
);
232 ZVAL_STRING(&qstr
, new_url
->query
, 0);
233 php_http_querystring_update(&qarr
, &qstr
, NULL TSRMLS_CC
);
236 php_http_querystring_update(&qarr
, NULL
, &qstr TSRMLS_CC
);
238 url(buf
)->query
= &buf
.data
[buf
.used
];
239 php_http_buffer_append(&buf
, Z_STRVAL(qstr
), Z_STRLEN(qstr
) + 1);
248 if (!(flags
& PHP_HTTP_URL_STRIP_FRAGMENT
)) {
252 /* done with copy & combine & strip */
254 if (flags
& PHP_HTTP_URL_FROM_ENV
) {
255 /* free old_url we tainted above */
256 php_http_url_free(&tmp_url
);
259 /* replace directory references if path is not a single slash */
260 if ((flags
& PHP_HTTP_URL_SANITIZE_PATH
)
261 && url(buf
)->path
[0] && url(buf
)->path
[1]) {
262 char *ptr
, *end
= url(buf
)->path
+ strlen(url(buf
)->path
) + 1;
264 for (ptr
= strchr(url(buf
)->path
, '/'); ptr
; ptr
= strchr(ptr
, '/')) {
267 memmove(&ptr
[1], &ptr
[2], end
- &ptr
[2]);
277 memmove(&ptr
[1], &ptr
[3], end
- &ptr
[3]);
283 while (ptr
!= url(buf
)->path
) {
288 memmove(&ptr
[1], pos
, end
- pos
);
290 } else if (!ptr
[3]) {
309 /* unset default ports */
310 if (url(buf
)->port
) {
311 if ( ((url(buf
)->port
== 80) && url(buf
)->scheme
&& !strcmp(url(buf
)->scheme
, "http"))
312 || ((url(buf
)->port
==443) && url(buf
)->scheme
&& !strcmp(url(buf
)->scheme
, "https"))
321 char *php_http_url_to_string(const php_http_url_t
*url
, char **url_str
, size_t *url_len
, zend_bool persistent
)
323 php_http_buffer_t buf
;
325 php_http_buffer_init_ex(&buf
, PHP_HTTP_BUFFER_DEFAULT_SIZE
, persistent
?
326 PHP_HTTP_BUFFER_INIT_PERSISTENT
: 0);
328 if (url
->scheme
&& *url
->scheme
) {
329 php_http_buffer_appendl(&buf
, url
->scheme
);
330 php_http_buffer_appends(&buf
, "://");
331 } else if ((url
->user
&& *url
->user
) || (url
->host
&& *url
->host
)) {
332 php_http_buffer_appends(&buf
, "//");
335 if (url
->user
&& *url
->user
) {
336 php_http_buffer_appendl(&buf
, url
->user
);
337 if (url
->pass
&& *url
->pass
) {
338 php_http_buffer_appends(&buf
, ":");
339 php_http_buffer_appendl(&buf
, url
->pass
);
341 php_http_buffer_appends(&buf
, "@");
344 if (url
->host
&& *url
->host
) {
345 php_http_buffer_appendl(&buf
, url
->host
);
347 php_http_buffer_appendf(&buf
, ":%hu", url
->port
);
351 if (url
->path
&& *url
->path
) {
352 if (*url
->path
!= '/') {
353 php_http_buffer_appends(&buf
, "/");
355 php_http_buffer_appendl(&buf
, url
->path
);
356 } else if (buf
.used
) {
357 php_http_buffer_appends(&buf
, "/");
360 if (url
->query
&& *url
->query
) {
361 php_http_buffer_appends(&buf
, "?");
362 php_http_buffer_appendl(&buf
, url
->query
);
365 if (url
->fragment
&& *url
->fragment
) {
366 php_http_buffer_appends(&buf
, "#");
367 php_http_buffer_appendl(&buf
, url
->fragment
);
370 php_http_buffer_shrink(&buf
);
371 php_http_buffer_fix(&buf
);
384 char *php_http_url_authority_to_string(const php_http_url_t
*url
, char **url_str
, size_t *url_len
)
386 php_http_buffer_t buf
;
388 php_http_buffer_init(&buf
);
390 if (url
->user
&& *url
->user
) {
391 php_http_buffer_appendl(&buf
, url
->user
);
392 if (url
->pass
&& *url
->pass
) {
393 php_http_buffer_appends(&buf
, ":");
394 php_http_buffer_appendl(&buf
, url
->pass
);
396 php_http_buffer_appends(&buf
, "@");
399 if (url
->host
&& *url
->host
) {
400 php_http_buffer_appendl(&buf
, url
->host
);
402 php_http_buffer_appendf(&buf
, ":%hu", url
->port
);
406 php_http_buffer_shrink(&buf
);
407 php_http_buffer_fix(&buf
);
420 php_http_url_t
*php_http_url_from_zval(zval
*value
, unsigned flags TSRMLS_DC
)
423 php_http_url_t
*purl
;
425 switch (Z_TYPE_P(value
)) {
428 purl
= php_http_url_from_struct(HASH_OF(value
));
432 zcpy
= php_http_ztyp(IS_STRING
, value
);
433 purl
= php_http_url_parse(Z_STRVAL_P(zcpy
), Z_STRLEN_P(zcpy
), flags TSRMLS_CC
);
434 zval_ptr_dtor(&zcpy
);
440 php_http_url_t
*php_http_url_from_struct(HashTable
*ht
)
443 php_http_buffer_t buf
;
445 php_http_buffer_init_ex(&buf
, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE
, sizeof(php_http_url_t
)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC
);
446 php_http_buffer_account(&buf
, sizeof(php_http_url_t
));
447 memset(buf
.data
, 0, buf
.used
);
449 if (SUCCESS
== zend_hash_find(ht
, "scheme", sizeof("scheme"), (void *) &e
)) {
450 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
451 url(buf
)->scheme
= &buf
.data
[buf
.used
];
452 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
455 if (SUCCESS
== zend_hash_find(ht
, "user", sizeof("user"), (void *) &e
)) {
456 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
457 url(buf
)->user
= &buf
.data
[buf
.used
];
458 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
461 if (SUCCESS
== zend_hash_find(ht
, "pass", sizeof("pass"), (void *) &e
)) {
462 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
463 url(buf
)->pass
= &buf
.data
[buf
.used
];
464 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
467 if (SUCCESS
== zend_hash_find(ht
, "host", sizeof("host"), (void *) &e
)) {
468 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
469 url(buf
)->host
= &buf
.data
[buf
.used
];
470 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
473 if (SUCCESS
== zend_hash_find(ht
, "port", sizeof("port"), (void *) &e
)) {
474 zval
*cpy
= php_http_ztyp(IS_LONG
, *e
);
475 url(buf
)->port
= (unsigned short) Z_LVAL_P(cpy
);
478 if (SUCCESS
== zend_hash_find(ht
, "path", sizeof("path"), (void *) &e
)) {
479 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
480 url(buf
)->path
= &buf
.data
[buf
.used
];
481 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
484 if (SUCCESS
== zend_hash_find(ht
, "query", sizeof("query"), (void *) &e
)) {
485 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
486 url(buf
)->query
= &buf
.data
[buf
.used
];
487 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
490 if (SUCCESS
== zend_hash_find(ht
, "fragment", sizeof("fragment"), (void *) &e
)) {
491 zval
*cpy
= php_http_ztyp(IS_STRING
, *e
);
492 url(buf
)->fragment
= &buf
.data
[buf
.used
];
493 php_http_buffer_append(&buf
, Z_STRVAL_P(cpy
), Z_STRLEN_P(cpy
) + 1);
500 HashTable
*php_http_url_to_struct(const php_http_url_t
*url
, zval
*strct TSRMLS_DC
)
505 switch (Z_TYPE_P(strct
)) {
512 INIT_PZVAL_ARRAY((&arr
), HASH_OF(strct
));
522 add_assoc_string(&arr
, "scheme", url
->scheme
, 1);
525 add_assoc_string(&arr
, "user", url
->user
, 1);
528 add_assoc_string(&arr
, "pass", url
->pass
, 1);
531 add_assoc_string(&arr
, "host", url
->host
, 1);
534 add_assoc_long(&arr
, "port", (long) url
->port
);
537 add_assoc_string(&arr
, "path", url
->path
, 1);
540 add_assoc_string(&arr
, "query", url
->query
, 1);
543 add_assoc_string(&arr
, "fragment", url
->fragment
, 1);
547 return Z_ARRVAL(arr
);
550 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
)
552 const char *arg_sep_str
;
554 php_http_buffer_t
*qstr
= php_http_buffer_new();
556 php_http_url_argsep(&arg_sep_str
, &arg_sep_len TSRMLS_CC
);
558 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
)) {
559 php_http_buffer_free(&qstr
);
563 php_http_buffer_data(qstr
, encoded_str
, encoded_len
);
564 php_http_buffer_free(&qstr
);
569 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
)
571 if (pre_encoded_len
&& pre_encoded_str
) {
572 php_http_buffer_append(qstr
, pre_encoded_str
, pre_encoded_len
);
575 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
)) {
592 char buffer
[1]; /* last member */
595 void php_http_url_free(php_http_url_t
**url
)
603 php_http_url_t
*php_http_url_copy(const php_http_url_t
*url
, zend_bool persistent
)
606 const char *end
= NULL
, *url_ptr
= (const char *) url
;
609 end
= MAX(url
->scheme
, end
);
610 end
= MAX(url
->pass
, end
);
611 end
= MAX(url
->user
, end
);
612 end
= MAX(url
->host
, end
);
613 end
= MAX(url
->path
, end
);
614 end
= MAX(url
->query
, end
);
615 end
= MAX(url
->fragment
, end
);
618 end
+= strlen(end
) + 1;
619 cpy_ptr
= pecalloc(1, end
- url_ptr
, persistent
);
620 cpy
= (php_http_url_t
*) cpy_ptr
;
622 memcpy(cpy_ptr
+ sizeof(*cpy
), url_ptr
+ sizeof(*url
), end
- url_ptr
- sizeof(*url
));
624 cpy
->scheme
= url
->scheme
? cpy_ptr
+ (url
->scheme
- url_ptr
) : NULL
;
625 cpy
->pass
= url
->pass
? cpy_ptr
+ (url
->pass
- url_ptr
) : NULL
;
626 cpy
->user
= url
->user
? cpy_ptr
+ (url
->user
- url_ptr
) : NULL
;
627 cpy
->host
= url
->host
? cpy_ptr
+ (url
->host
- url_ptr
) : NULL
;
628 cpy
->path
= url
->path
? cpy_ptr
+ (url
->path
- url_ptr
) : NULL
;
629 cpy
->query
= url
->query
? cpy_ptr
+ (url
->query
- url_ptr
) : NULL
;
630 cpy
->fragment
= url
->fragment
? cpy_ptr
+ (url
->fragment
- url_ptr
) : NULL
;
632 cpy
= ecalloc(1, sizeof(*url
));
635 cpy
->port
= url
->port
;
640 static size_t parse_mb_utf8(unsigned *wc
, const char *ptr
, const char *end
)
643 size_t consumed
= utf8towc(&wchar
, (const unsigned char *) ptr
, end
- ptr
);
645 if (!consumed
|| consumed
== (size_t) -1) {
655 #ifdef PHP_HTTP_HAVE_WCHAR
656 static size_t parse_mb_loc(unsigned *wc
, const char *ptr
, const char *end
)
660 #if defined(HAVE_MBRTOWC)
663 consumed
= mbrtowc(&wchar
, ptr
, end
- ptr
, &ps
);
664 #elif defined(HAVE_MBTOWC)
665 consumed
= mbtowc(&wchar
, ptr
, end
- ptr
);
668 if (!consumed
|| consumed
== (size_t) -1) {
679 typedef enum parse_mb_what
{
688 static const char * const parse_what
[] = {
697 static const char parse_xdigits
[] = "0123456789ABCDEF";
699 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
)
704 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
705 consumed
= parse_mb_utf8(&wchar
, ptr
, end
);
707 #ifdef PHP_HTTP_HAVE_WCHAR
708 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
709 consumed
= parse_mb_loc(&wchar
, ptr
, end
);
714 if (!(state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) || what
== PARSE_HOSTINFO
|| what
== PARSE_SCHEME
) {
715 if (what
== PARSE_HOSTINFO
&& (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
)) {
717 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
718 if (!isualnum(wchar
)) {
721 #ifdef PHP_HTTP_HAVE_WCHAR
722 } else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
723 if (!iswalnum(wchar
)) {
728 PHP_HTTP_DUFF(consumed
, state
->buffer
[state
->offset
++] = *ptr
++);
732 PHP_HTTP_DUFF(consumed
,
733 state
->buffer
[state
->offset
++] = '%';
734 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) >> 4];
735 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) ptr
[i
]) & 0xf];
744 TSRMLS_FETCH_FROM_CTX(state
->ts
);
745 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
746 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
747 parse_what
[what
], (unsigned char) *ptr
, (unsigned) (ptr
- begin
), begin
);
753 static STATUS
parse_userinfo(struct parse_state
*state
, const char *ptr
)
756 const char *password
= NULL
, *end
= state
->ptr
, *tmp
= ptr
;
757 TSRMLS_FETCH_FROM_CTX(state
->ts
);
759 state
->url
.user
= &state
->buffer
[state
->offset
];
765 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
766 "Failed to parse password; duplicate ':' at pos %u in '%s'",
767 (unsigned) (ptr
- tmp
), tmp
);
771 state
->buffer
[state
->offset
++] = 0;
772 state
->url
.pass
= &state
->buffer
[state
->offset
];
776 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
777 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
778 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
779 (unsigned) (ptr
- tmp
), tmp
);
782 state
->buffer
[state
->offset
++] = *ptr
++;
783 state
->buffer
[state
->offset
++] = *ptr
++;
784 state
->buffer
[state
->offset
++] = *ptr
;
787 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
788 case '+': case ',': case ';': case '=': /* sub-delims */
789 case '-': case '.': case '_': case '~': /* unreserved */
790 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
791 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
792 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
793 case 'V': case 'W': case 'X': case 'Y': case 'Z':
794 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
795 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
796 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
797 case 'v': case 'w': case 'x': case 'y': case 'z':
798 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
799 case '7': case '8': case '9':
801 state
->buffer
[state
->offset
++] = *ptr
;
805 if (!(mb
= parse_mb(state
, PARSE_USERINFO
, ptr
, end
, tmp
, 0))) {
810 } while(++ptr
!= end
);
813 state
->buffer
[state
->offset
++] = 0;
818 static STATUS
parse_hostinfo(struct parse_state
*state
, const char *ptr
)
821 const char *end
= state
->ptr
, *tmp
= ptr
, *port
= NULL
;
822 TSRMLS_FETCH_FROM_CTX(state
->ts
);
825 #ifdef HAVE_INET_PTON
827 char *error
= NULL
, *tmp
= memchr(ptr
, ']', end
- ptr
);
830 size_t addrlen
= tmp
- ptr
+ 1;
831 char buf
[16], *addr
= estrndup(ptr
+ 1, addrlen
- 2);
832 int rv
= inet_pton(AF_INET6
, addr
, buf
);
836 state
->buffer
[state
->offset
] = '[';
837 state
->url
.host
= &state
->buffer
[state
->offset
];
838 inet_ntop(AF_INET6
, buf
, state
->url
.host
+ 1, state
->maxlen
- state
->offset
);
839 state
->offset
+= strlen(state
->url
.host
);
840 state
->buffer
[state
->offset
++] = ']';
841 state
->buffer
[state
->offset
++] = 0;
843 } else if (rv
== -1) {
844 error
= strerror(errno
);
846 error
= "unexpected '['";
849 error
= "expected ']'";
853 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse hostinfo; %s", error
);
862 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
863 "Failed to parse port; unexpected ':' at pos %u in '%s'",
864 (unsigned) (ptr
- tmp
), tmp
);
871 if (ptr
[1] != '%' && (end
- ptr
<= 2 || !isxdigit(*(ptr
+1)) || !isxdigit(*(ptr
+2)))) {
872 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
873 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
874 (unsigned) (ptr
- tmp
), tmp
);
877 state
->buffer
[state
->offset
++] = *ptr
++;
878 state
->buffer
[state
->offset
++] = *ptr
++;
879 state
->buffer
[state
->offset
++] = *ptr
;
882 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
883 case '+': case ',': case ';': case '=': /* sub-delims */
884 case '-': case '.': case '_': case '~': /* unreserved */
885 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
886 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
887 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
888 case 'V': case 'W': case 'X': case 'Y': case 'Z':
889 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
890 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
891 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
892 case 'v': case 'w': case 'x': case 'y': case 'z':
894 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
895 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
896 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
900 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
901 case '7': case '8': case '9':
904 state
->url
.port
*= 10;
905 state
->url
.port
+= *ptr
- '0';
907 state
->buffer
[state
->offset
++] = *ptr
;
915 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
916 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
917 (unsigned char) *ptr
, (unsigned) (ptr
- tmp
), tmp
);
919 } else if (!(mb
= parse_mb(state
, PARSE_HOSTINFO
, ptr
, end
, tmp
, 0))) {
924 } while (++ptr
!= end
);
926 if (!state
->url
.host
) {
927 len
= (port
? port
- tmp
- 1 : end
- tmp
);
928 state
->url
.host
= &state
->buffer
[state
->offset
- len
];
929 state
->buffer
[state
->offset
++] = 0;
932 #ifdef PHP_HTTP_HAVE_IDN
933 if (state
->flags
& PHP_HTTP_URL_PARSE_TOIDN
) {
937 if (state
->flags
& PHP_HTTP_URL_PARSE_MBUTF8
) {
938 rv
= idna_to_ascii_8z(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
|IDNA_USE_STD3_ASCII_RULES
);
940 # ifdef PHP_HTTP_HAVE_WCHAR
941 else if (state
->flags
& PHP_HTTP_URL_PARSE_MBLOC
) {
942 rv
= idna_to_ascii_lz(state
->url
.host
, &idn
, IDNA_ALLOW_UNASSIGNED
|IDNA_USE_STD3_ASCII_RULES
);
945 if (rv
!= IDNA_SUCCESS
) {
946 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse IDN; %s", idna_strerror(rv
));
949 size_t idnlen
= strlen(idn
);
950 memcpy(state
->url
.host
, idn
, idnlen
+ 1);
952 state
->offset
+= idnlen
- len
;
960 static const char *parse_authority(struct parse_state
*state
)
962 const char *tmp
= state
->ptr
, *host
= NULL
;
965 switch (*state
->ptr
) {
967 /* userinfo delimiter */
969 TSRMLS_FETCH_FROM_CTX(state
->ts
);
970 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
971 "Failed to parse userinfo; unexpected '@'");
974 host
= state
->ptr
+ 1;
975 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_userinfo(state
, tmp
)) {
978 tmp
= state
->ptr
+ 1;
987 if (tmp
!= state
->ptr
&& SUCCESS
!= parse_hostinfo(state
, tmp
)) {
992 } while (++state
->ptr
<= state
->end
);
998 static const char *parse_path(struct parse_state
*state
)
1002 TSRMLS_FETCH_FROM_CTX(state
->ts
);
1004 /* is there actually a path to parse? */
1009 state
->url
.path
= &state
->buffer
[state
->offset
];
1012 switch (*state
->ptr
) {
1018 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1019 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1020 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
1021 (unsigned) (state
->ptr
- tmp
), tmp
);
1024 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1025 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1026 state
->buffer
[state
->offset
++] = *state
->ptr
;
1029 case '/': /* yeah, well */
1030 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1031 case '+': case ',': case ';': case '=': /* sub-delims */
1032 case '-': case '.': case '_': case '~': /* unreserved */
1033 case ':': case '@': /* pchar */
1034 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1035 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1036 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1037 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1038 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1039 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1040 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1041 case 'v': case 'w': case 'x': case 'y': case 'z':
1042 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1043 case '7': case '8': case '9':
1045 state
->buffer
[state
->offset
++] = *state
->ptr
;
1049 if (!(mb
= parse_mb(state
, PARSE_PATH
, state
->ptr
, state
->end
, tmp
, 0))) {
1052 state
->ptr
+= mb
- 1;
1054 } while (++state
->ptr
< state
->end
);
1057 /* did we have any path component ? */
1058 if (tmp
!= state
->ptr
) {
1059 state
->buffer
[state
->offset
++] = 0;
1061 state
->url
.path
= NULL
;
1066 static const char *parse_query(struct parse_state
*state
)
1069 const char *tmp
= state
->ptr
+ !!*state
->ptr
;
1070 TSRMLS_FETCH_FROM_CTX(state
->ts
);
1072 /* is there actually a query to parse? */
1073 if (*state
->ptr
!= '?') {
1077 /* skip initial '?' */
1079 state
->url
.query
= &state
->buffer
[state
->offset
];
1082 switch (*state
->ptr
) {
1087 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1088 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1089 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
1090 (unsigned) (state
->ptr
- tmp
), tmp
);
1093 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1094 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1095 state
->buffer
[state
->offset
++] = *state
->ptr
;
1100 if (state
->flags
& PHP_HTTP_URL_PARSE_TOPCT
) {
1101 state
->buffer
[state
->offset
++] = '%';
1102 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) >> 4];
1103 state
->buffer
[state
->offset
++] = parse_xdigits
[((unsigned char) *state
->ptr
) & 0xf];
1108 case '?': case '/': /* yeah, well */
1109 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1110 case '+': case ',': case ';': case '=': /* sub-delims */
1111 case '-': case '.': case '_': case '~': /* unreserved */
1112 case ':': case '@': /* pchar */
1113 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1114 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1115 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1116 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1117 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1118 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1119 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1120 case 'v': case 'w': case 'x': case 'y': case 'z':
1121 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1122 case '7': case '8': case '9':
1124 state
->buffer
[state
->offset
++] = *state
->ptr
;
1128 if (!(mb
= parse_mb(state
, PARSE_QUERY
, state
->ptr
, state
->end
, tmp
, 0))) {
1131 state
->ptr
+= mb
- 1;
1133 } while (++state
->ptr
< state
->end
);
1136 state
->buffer
[state
->offset
++] = 0;
1140 static const char *parse_fragment(struct parse_state
*state
)
1144 TSRMLS_FETCH_FROM_CTX(state
->ts
);
1146 /* is there actually a fragment to parse? */
1147 if (*state
->ptr
!= '#') {
1151 /* skip initial '#' */
1153 state
->url
.fragment
= &state
->buffer
[state
->offset
];
1156 switch (*state
->ptr
) {
1158 if (state
->ptr
[1] != '%' && (state
->end
- state
->ptr
<= 2 || !isxdigit(*(state
->ptr
+1)) || !isxdigit(*(state
->ptr
+2)))) {
1159 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1160 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
1161 (unsigned) (state
->ptr
- tmp
), tmp
);
1164 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1165 state
->buffer
[state
->offset
++] = *state
->ptr
++;
1166 state
->buffer
[state
->offset
++] = *state
->ptr
;
1170 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1171 case '+': case ',': case ';': case '=': /* sub-delims */
1172 case '-': case '.': case '_': case '~': /* unreserved */
1173 case ':': case '@': /* pchar */
1174 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1175 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1176 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1177 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1178 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1179 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1180 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1181 case 'v': case 'w': case 'x': case 'y': case 'z':
1182 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1183 case '7': case '8': case '9':
1185 state
->buffer
[state
->offset
++] = *state
->ptr
;
1189 if (!(mb
= parse_mb(state
, PARSE_FRAGMENT
, state
->ptr
, state
->end
, tmp
, 0))) {
1192 state
->ptr
+= mb
- 1;
1194 } while (++state
->ptr
< state
->end
);
1196 state
->buffer
[state
->offset
++] = 0;
1200 static const char *parse_hier(struct parse_state
*state
)
1202 if (*state
->ptr
== '/') {
1203 if (state
->end
- state
->ptr
> 1) {
1204 if (*(state
->ptr
+ 1) == '/') {
1206 if (!(state
->ptr
= parse_authority(state
))) {
1212 return parse_path(state
);
1215 static const char *parse_scheme(struct parse_state
*state
)
1218 const char *tmp
= state
->ptr
;
1221 switch (*state
->ptr
) {
1223 /* scheme delimiter */
1224 state
->url
.scheme
= &state
->buffer
[0];
1225 state
->buffer
[state
->offset
++] = 0;
1226 return ++state
->ptr
;
1228 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1229 case '7': case '8': case '9':
1230 case '+': case '-': case '.':
1231 if (state
->ptr
== tmp
) {
1235 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1236 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1237 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1238 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1239 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1240 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1241 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1242 case 'v': case 'w': case 'x': case 'y': case 'z':
1244 state
->buffer
[state
->offset
++] = *state
->ptr
;
1248 if (!(mb
= parse_mb(state
, PARSE_SCHEME
, state
->ptr
, state
->end
, tmp
, 1))) {
1249 /* soft fail; parse path next */
1252 state
->ptr
+= mb
- 1;
1254 } while (++state
->ptr
!= state
->end
);
1256 return state
->ptr
= tmp
;
1259 php_http_url_t
*php_http_url_parse(const char *str
, size_t len
, unsigned flags TSRMLS_DC
)
1261 size_t maxlen
= 3 * len
;
1262 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1264 state
->end
= str
+ len
;
1266 state
->flags
= flags
;
1267 state
->maxlen
= maxlen
;
1268 TSRMLS_SET_CTX(state
->ts
);
1270 if (!parse_scheme(state
)) {
1271 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse URL scheme: '%s'", state
->ptr
);
1276 if (!parse_hier(state
)) {
1281 if (!parse_query(state
)) {
1282 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse URL query: '%s'", state
->ptr
);
1287 if (!parse_fragment(state
)) {
1288 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Failed to parse URL fragment: '%s'", state
->ptr
);
1293 return (php_http_url_t
*) state
;
1296 php_http_url_t
*php_http_url_parse_authority(const char *str
, size_t len
, unsigned flags TSRMLS_DC
)
1298 size_t maxlen
= 3 * len
;
1299 struct parse_state
*state
= ecalloc(1, sizeof(*state
) + maxlen
);
1301 state
->end
= str
+ len
;
1303 state
->flags
= flags
;
1304 state
->maxlen
= maxlen
;
1305 TSRMLS_SET_CTX(state
->ts
);
1307 if (!(state
->ptr
= parse_authority(state
))) {
1312 if (state
->ptr
!= state
->end
) {
1313 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1314 "Failed to parse URL authority, unexpected character at pos %u in '%s'",
1315 (unsigned) (state
->ptr
- str
), str
);
1320 return (php_http_url_t
*) state
;
1323 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct
, 0, 0, 0)
1324 ZEND_ARG_INFO(0, old_url
)
1325 ZEND_ARG_INFO(0, new_url
)
1326 ZEND_ARG_INFO(0, flags
)
1327 ZEND_END_ARG_INFO();
1328 PHP_METHOD(HttpUrl
, __construct
)
1330 zval
*new_url
= NULL
, *old_url
= NULL
;
1331 long flags
= PHP_HTTP_URL_FROM_ENV
;
1332 zend_error_handling zeh
;
1334 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|z!z!l", &old_url
, &new_url
, &flags
), invalid_arg
, return);
1336 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_url_class_entry
, &zeh TSRMLS_CC
);
1338 php_http_url_t
*res_purl
, *new_purl
= NULL
, *old_purl
= NULL
;
1341 new_purl
= php_http_url_from_zval(new_url
, flags TSRMLS_CC
);
1343 zend_restore_error_handling(&zeh TSRMLS_CC
);
1348 old_purl
= php_http_url_from_zval(old_url
, flags TSRMLS_CC
);
1351 php_http_url_free(&new_purl
);
1353 zend_restore_error_handling(&zeh TSRMLS_CC
);
1358 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags TSRMLS_CC
);
1359 php_http_url_to_struct(res_purl
, getThis() TSRMLS_CC
);
1361 php_http_url_free(&res_purl
);
1363 php_http_url_free(&old_purl
);
1366 php_http_url_free(&new_purl
);
1369 zend_restore_error_handling(&zeh TSRMLS_CC
);
1372 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod
, 0, 0, 1)
1373 ZEND_ARG_INFO(0, more_url_parts
)
1374 ZEND_ARG_INFO(0, flags
)
1375 ZEND_END_ARG_INFO();
1376 PHP_METHOD(HttpUrl
, mod
)
1378 zval
*new_url
= NULL
;
1379 long flags
= PHP_HTTP_URL_JOIN_PATH
| PHP_HTTP_URL_JOIN_QUERY
;
1380 zend_error_handling zeh
;
1382 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z!|l", &new_url
, &flags
), invalid_arg
, return);
1384 zend_replace_error_handling(EH_THROW
, php_http_exception_bad_url_class_entry
, &zeh TSRMLS_CC
);
1386 php_http_url_t
*new_purl
= NULL
, *old_purl
= NULL
;
1389 new_purl
= php_http_url_from_zval(new_url
, flags TSRMLS_CC
);
1391 zend_restore_error_handling(&zeh TSRMLS_CC
);
1396 if ((old_purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1397 php_http_url_t
*res_purl
;
1399 ZVAL_OBJVAL(return_value
, zend_objects_clone_obj(getThis() TSRMLS_CC
), 0);
1401 res_purl
= php_http_url_mod(old_purl
, new_purl
, flags TSRMLS_CC
);
1402 php_http_url_to_struct(res_purl
, return_value TSRMLS_CC
);
1404 php_http_url_free(&res_purl
);
1405 php_http_url_free(&old_purl
);
1408 php_http_url_free(&new_purl
);
1411 zend_restore_error_handling(&zeh TSRMLS_CC
);
1414 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString
, 0, 0, 0)
1415 ZEND_END_ARG_INFO();
1416 PHP_METHOD(HttpUrl
, toString
)
1418 if (SUCCESS
== zend_parse_parameters_none()) {
1419 php_http_url_t
*purl
;
1421 if ((purl
= php_http_url_from_struct(HASH_OF(getThis())))) {
1425 php_http_url_to_string(purl
, &str
, &len
, 0);
1426 php_http_url_free(&purl
);
1427 RETURN_STRINGL(str
, len
, 0);
1430 RETURN_EMPTY_STRING();
1433 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray
, 0, 0, 0)
1434 ZEND_END_ARG_INFO();
1435 PHP_METHOD(HttpUrl
, toArray
)
1437 php_http_url_t
*purl
;
1439 if (SUCCESS
!= zend_parse_parameters_none()) {
1443 /* strip any non-URL properties */
1444 purl
= php_http_url_from_struct(HASH_OF(getThis()));
1445 php_http_url_to_struct(purl
, return_value TSRMLS_CC
);
1446 php_http_url_free(&purl
);
1449 static zend_function_entry php_http_url_methods
[] = {
1450 PHP_ME(HttpUrl
, __construct
, ai_HttpUrl___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
1451 PHP_ME(HttpUrl
, mod
, ai_HttpUrl_mod
, ZEND_ACC_PUBLIC
)
1452 PHP_ME(HttpUrl
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
1453 ZEND_MALIAS(HttpUrl
, __toString
, toString
, ai_HttpUrl_toString
, ZEND_ACC_PUBLIC
)
1454 PHP_ME(HttpUrl
, toArray
, ai_HttpUrl_toArray
, ZEND_ACC_PUBLIC
)
1455 EMPTY_FUNCTION_ENTRY
1458 zend_class_entry
*php_http_url_class_entry
;
1460 PHP_MINIT_FUNCTION(http_url
)
1462 zend_class_entry ce
= {0};
1464 INIT_NS_CLASS_ENTRY(ce
, "http", "Url", php_http_url_methods
);
1465 php_http_url_class_entry
= zend_register_internal_class(&ce TSRMLS_CC
);
1467 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1468 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1469 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1470 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1471 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1472 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1473 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1474 zend_declare_property_null(php_http_url_class_entry
, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC
);
1476 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC
);
1477 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC
);
1478 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC
);
1479 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC
);
1480 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC
);
1481 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC
);
1482 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC
);
1483 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC
);
1484 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC
);
1485 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC
);
1486 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC
);
1487 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC
);
1488 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC
);
1490 #ifdef PHP_HTTP_HAVE_WCHAR
1491 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC
);
1493 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC
);
1494 #ifdef PHP_HTTP_HAVE_IDN
1495 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC
);
1497 zend_declare_class_constant_long(php_http_url_class_entry
, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC
);
1508 * vim600: noet sw=4 ts=4 fdm=marker
1509 * vim<600: noet sw=4 ts=4