1f06271f9527183f12c9c5c2a46506b14a674b74
[m6w6/ext-http] / php_http_url.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
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 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 #ifdef PHP_HTTP_HAVE_IDN
16 # include <idna.h>
17 #endif
18
19 #ifdef PHP_HTTP_HAVE_WCHAR
20 # include <wchar.h>
21 # include <wctype.h>
22 #endif
23
24 #ifdef HAVE_ARPA_INET_H
25 # include <arpa/inet.h>
26 #endif
27
28 #include "php_http_utf8.h"
29
30 static inline char *localhostname(void)
31 {
32 char hostname[1024] = {0};
33
34 #ifdef PHP_WIN32
35 if (SUCCESS == gethostname(hostname, lenof(hostname))) {
36 return estrdup(hostname);
37 }
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';
47 }
48 return estrdup(hostname);
49 }
50 }
51 # endif
52 if (strcmp(hostname, "(none)")) {
53 return estrdup(hostname);
54 }
55 }
56 #endif
57 return estrndup("localhost", lenof("localhost"));
58 }
59
60 static php_url *php_http_url_from_env(php_url *url TSRMLS_DC)
61 {
62 zval *https, *zhost, *zport;
63 long port;
64
65 if (!url) {
66 url = ecalloc(1, sizeof(*url));
67 }
68
69 /* port */
70 zport = php_http_env_get_server_var(ZEND_STRL("SERVER_PORT"), 1 TSRMLS_CC);
71 if (zport && IS_LONG == is_numeric_string(Z_STRVAL_P(zport), Z_STRLEN_P(zport), &port, NULL, 0)) {
72 url->port = port;
73 }
74
75 /* scheme */
76 https = php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1 TSRMLS_CC);
77 if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) {
78 url->scheme = estrndup("https", lenof("https"));
79 } else {
80 url->scheme = estrndup("http", lenof("http"));
81 }
82
83 /* host */
84 if ((((zhost = php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1 TSRMLS_CC)) ||
85 (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1 TSRMLS_CC)) ||
86 (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1 TSRMLS_CC)))) && Z_STRLEN_P(zhost)) {
87 size_t stop_at = strspn(Z_STRVAL_P(zhost), "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.");
88
89 url->host = estrndup(Z_STRVAL_P(zhost), stop_at);
90 } else {
91 url->host = localhostname();
92 }
93
94 /* path */
95 if (SG(request_info).request_uri && SG(request_info).request_uri[0]) {
96 const char *q = strchr(SG(request_info).request_uri, '?');
97
98 if (q) {
99 url->path = estrndup(SG(request_info).request_uri, q - SG(request_info).request_uri);
100 } else {
101 url->path = estrdup(SG(request_info).request_uri);
102 }
103 }
104
105 /* query */
106 if (SG(request_info).query_string && SG(request_info).query_string[0]) {
107 url->query = estrdup(SG(request_info).query_string);
108 }
109
110 return url;
111 }
112
113 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)
114 {
115 php_url *url, *tmp_url = NULL;
116
117 /* set from env if requested */
118 if (flags & PHP_HTTP_URL_FROM_ENV) {
119 php_url *env_url = php_http_url_from_env(NULL TSRMLS_CC);
120
121 php_http_url(flags ^ PHP_HTTP_URL_FROM_ENV, env_url, old_url, &tmp_url, NULL, NULL TSRMLS_CC);
122
123 php_url_free(env_url);
124 old_url = tmp_url;
125 }
126
127 url = ecalloc(1, sizeof(*url));
128
129 #define __URLSET(u,n) \
130 ((u)&&(u)->n)
131 #define __URLCPY(n) \
132 url->n = __URLSET(new_url,n) ? estrdup(new_url->n) : (__URLSET(old_url,n) ? estrdup(old_url->n) : NULL)
133
134 if (!(flags & PHP_HTTP_URL_STRIP_PORT)) {
135 url->port = __URLSET(new_url, port) ? new_url->port : ((old_url) ? old_url->port : 0);
136 }
137 if (!(flags & PHP_HTTP_URL_STRIP_USER)) {
138 __URLCPY(user);
139 }
140 if (!(flags & PHP_HTTP_URL_STRIP_PASS)) {
141 __URLCPY(pass);
142 }
143
144 __URLCPY(scheme);
145 __URLCPY(host);
146
147 if (!(flags & PHP_HTTP_URL_STRIP_PATH)) {
148 if ((flags & PHP_HTTP_URL_JOIN_PATH) && __URLSET(old_url, path) && __URLSET(new_url, path) && *new_url->path != '/') {
149 size_t old_path_len = strlen(old_url->path), new_path_len = strlen(new_url->path);
150
151 url->path = ecalloc(1, old_path_len + new_path_len + 1 + 1);
152
153 strcat(url->path, old_url->path);
154 if (url->path[old_path_len - 1] != '/') {
155 php_dirname(url->path, old_path_len);
156 strcat(url->path, "/");
157 }
158 strcat(url->path, new_url->path);
159 } else {
160 __URLCPY(path);
161 }
162 }
163 if (!(flags & PHP_HTTP_URL_STRIP_QUERY)) {
164 if ((flags & PHP_HTTP_URL_JOIN_QUERY) && __URLSET(new_url, query) && __URLSET(old_url, query)) {
165 zval qarr, qstr;
166
167 INIT_PZVAL(&qstr);
168 INIT_PZVAL(&qarr);
169 array_init(&qarr);
170
171 ZVAL_STRING(&qstr, old_url->query, 0);
172 php_http_querystring_update(&qarr, &qstr, NULL TSRMLS_CC);
173 ZVAL_STRING(&qstr, new_url->query, 0);
174 php_http_querystring_update(&qarr, &qstr, NULL TSRMLS_CC);
175
176 ZVAL_NULL(&qstr);
177 php_http_querystring_update(&qarr, NULL, &qstr TSRMLS_CC);
178 url->query = Z_STRVAL(qstr);
179 zval_dtor(&qarr);
180 } else {
181 __URLCPY(query);
182 }
183 }
184 if (!(flags & PHP_HTTP_URL_STRIP_FRAGMENT)) {
185 __URLCPY(fragment);
186 }
187
188 /* done with copy & combine & strip */
189
190 if (flags & PHP_HTTP_URL_FROM_ENV) {
191 /* free old_url we tainted above */
192 php_url_free(tmp_url);
193 }
194
195 /* set some sane defaults */
196
197 if (!url->scheme) {
198 url->scheme = estrndup("http", lenof("http"));
199 }
200
201 if (!url->host) {
202 url->host = estrndup("localhost", lenof("localhost"));
203 }
204
205 if (!url->path) {
206 url->path = estrndup("/", 1);
207 } else if (url->path[0] != '/') {
208 size_t plen = strlen(url->path);
209 char *path = emalloc(plen + 1 + 1);
210
211 path[0] = '/';
212 memcpy(&path[1], url->path, plen + 1);
213 STR_SET(url->path, path);
214 }
215 /* replace directory references if path is not a single slash */
216 if ((flags & PHP_HTTP_URL_SANITIZE_PATH)
217 && url->path[0] && (url->path[0] != '/' || url->path[1])) {
218 char *ptr, *end = url->path + strlen(url->path) + 1;
219
220 for (ptr = strchr(url->path, '/'); ptr; ptr = strchr(ptr, '/')) {
221 switch (ptr[1]) {
222 case '/':
223 memmove(&ptr[1], &ptr[2], end - &ptr[2]);
224 break;
225
226 case '.':
227 switch (ptr[2]) {
228 case '\0':
229 ptr[1] = '\0';
230 break;
231
232 case '/':
233 memmove(&ptr[1], &ptr[3], end - &ptr[3]);
234 break;
235
236 case '.':
237 if (ptr[3] == '/') {
238 char *pos = &ptr[4];
239 while (ptr != url->path) {
240 if (*--ptr == '/') {
241 break;
242 }
243 }
244 memmove(&ptr[1], pos, end - pos);
245 break;
246 } else if (!ptr[3]) {
247 /* .. at the end */
248 ptr[1] = '\0';
249 }
250 /* no break */
251
252 default:
253 /* something else */
254 ++ptr;
255 break;
256 }
257 break;
258
259 default:
260 ++ptr;
261 break;
262 }
263 }
264 }
265 /* unset default ports */
266 if (url->port) {
267 if ( ((url->port == 80) && !strcmp(url->scheme, "http"))
268 || ((url->port ==443) && !strcmp(url->scheme, "https"))
269 ) {
270 url->port = 0;
271 }
272 }
273
274 if (url_str) {
275 php_http_url_to_string(url, url_str, url_len TSRMLS_CC);
276 }
277
278 if (url_ptr) {
279 *url_ptr = url;
280 } else {
281 php_url_free(url);
282 }
283 }
284
285 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)
286 {
287 const char *arg_sep_str;
288 size_t arg_sep_len;
289 php_http_buffer_t *qstr = php_http_buffer_new();
290
291 php_http_url_argsep(&arg_sep_str, &arg_sep_len TSRMLS_CC);
292
293 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)) {
294 php_http_buffer_free(&qstr);
295 return FAILURE;
296 }
297
298 php_http_buffer_data(qstr, encoded_str, encoded_len);
299 php_http_buffer_free(&qstr);
300
301 return SUCCESS;
302 }
303
304 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)
305 {
306 if (pre_encoded_len && pre_encoded_str) {
307 php_http_buffer_append(qstr, pre_encoded_str, pre_encoded_len);
308 }
309
310 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)) {
311 return FAILURE;
312 }
313
314 return SUCCESS;
315 }
316
317 void php_http_url_free(php_http_url_t **url)
318 {
319 if (*url) {
320 efree(*url);
321 *url = NULL;
322 }
323 }
324
325 static size_t parse_mb_utf8(php_http_url_t *url, const char *ptr, const char *end, zend_bool idn)
326 {
327 unsigned wchar;
328 size_t consumed = utf8towc(&wchar, (const unsigned char *) ptr, end - ptr);
329
330 if (!consumed || consumed == (size_t) -1) {
331 return 0;
332 }
333 if (!idn && !isualnum(wchar)) {
334 return 0;
335 }
336
337 return consumed;
338 }
339
340 #ifdef PHP_HTTP_HAVE_WCHAR
341 static size_t parse_mb_loc(php_http_url_t *url, const char *ptr, const char *end, zend_bool idn)
342 {
343 wchar_t wchar;
344 size_t consumed = 0;
345 #if defined(HAVE_MBRTOWC)
346 mbstate_t ps = {0};
347
348 consumed = mbrtowc(&wchar, ptr, end - ptr, &ps);
349 #elif defined(HAVE_MBTOWC)
350 consumed = mbtowc(&wchar, ptr, end - ptr);
351 #endif
352
353 if (!consumed || consumed == (size_t) -1) {
354 return 0;
355 }
356 if (!idn && !iswalnum(wchar)) {
357 return 0;
358 }
359
360 return consumed;
361 }
362 #endif
363
364 typedef enum parse_mb_what {
365 PARSE_SCHEME,
366 PARSE_USERINFO,
367 PARSE_HOSTINFO,
368 PARSE_PATH,
369 PARSE_QUERY,
370 PARSE_FRAGMENT
371 } parse_mb_what_t;
372
373 static const char * const parse_what[] = {
374 "scheme",
375 "userinfo",
376 "hostinfo",
377 "path",
378 "query",
379 "fragment"
380 };
381
382 static const char parse_xdigits[] = "0123456789ABCDEF";
383
384 static size_t parse_mb(php_http_url_t *url, parse_mb_what_t what, const char *ptr, const char *end, const char *begin, zend_bool silent)
385 {
386 size_t consumed = 0;
387 zend_bool idn = (what == PARSE_HOSTINFO) && (url->flags & PHP_HTTP_URL_PARSE_TOIDN);
388
389 if (url->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
390 consumed = parse_mb_utf8(url, ptr, end, idn);
391 }
392 #ifdef PHP_HTTP_HAVE_WCHAR
393 else if (url->flags & PHP_HTTP_URL_PARSE_MBLOC) {
394 consumed = parse_mb_loc(url, ptr, end, idn);
395 }
396 #endif
397
398 if (consumed) {
399 if (!(url->flags & PHP_HTTP_URL_PARSE_TOPCT) || what == PARSE_HOSTINFO || what == PARSE_SCHEME) {
400 PHP_HTTP_DUFF(consumed, url->buffer[url->offset++] = *ptr++);
401 } else {
402 int i = 0;
403
404 PHP_HTTP_DUFF(consumed,
405 url->buffer[url->offset++] = '%';
406 url->buffer[url->offset++] = parse_xdigits[((unsigned char) ptr[i]) >> 4];
407 url->buffer[url->offset++] = parse_xdigits[((unsigned char) ptr[i]) & 0xf];
408 ++i;
409 );
410 }
411 } else if (!silent) {
412 TSRMLS_FETCH_FROM_CTX(url->ts);
413 php_error_docref(NULL TSRMLS_CC, E_WARNING,
414 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
415 parse_what[what], (unsigned char) *ptr, (unsigned) (ptr - begin), begin);
416 }
417
418 return consumed;
419 }
420
421 static STATUS parse_userinfo(php_http_url_t *url, const char *ptr)
422 {
423 size_t mb;
424 const char *password = NULL, *end = url->ptr, *tmp = ptr;
425 TSRMLS_FETCH_FROM_CTX(url->ts);
426
427 url->user = &url->buffer[url->offset];
428
429 do {
430 switch (*ptr) {
431 case ':':
432 if (password) {
433 php_error_docref(NULL TSRMLS_CC, E_WARNING,
434 "Failed to parse password; duplicate ':' at pos %u in '%s'",
435 (unsigned) (ptr - tmp), tmp);
436 return FAILURE;
437 }
438 password = ptr + 1;
439 url->buffer[url->offset++] = 0;
440 url->pass = &url->buffer[url->offset];
441 break;
442
443 case '%':
444 if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
445 php_error_docref(NULL TSRMLS_CC, E_WARNING,
446 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
447 (unsigned) (ptr - tmp), tmp);
448 return FAILURE;
449 }
450 url->buffer[url->offset++] = *ptr++;
451 url->buffer[url->offset++] = *ptr++;
452 url->buffer[url->offset++] = *ptr;
453 break;
454
455 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
456 case '+': case ',': case ';': case '=': /* sub-delims */
457 case '-': case '.': case '_': case '~': /* unreserved */
458 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
459 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
460 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
461 case 'V': case 'W': case 'X': case 'Y': case 'Z':
462 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
463 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
464 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
465 case 'v': case 'w': case 'x': case 'y': case 'z':
466 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
467 case '7': case '8': case '9':
468 /* allowed */
469 url->buffer[url->offset++] = *ptr;
470 break;
471
472 default:
473 if (!(mb = parse_mb(url, PARSE_USERINFO, ptr, end, tmp, 0))) {
474 return FAILURE;
475 }
476 ptr += mb - 1;
477 }
478 } while(++ptr != end);
479
480
481 url->buffer[url->offset++] = 0;
482
483 return SUCCESS;
484 }
485
486 static STATUS parse_hostinfo(php_http_url_t *url, const char *ptr)
487 {
488 size_t mb, len;
489 const char *end = url->ptr, *tmp = ptr, *port = NULL;
490 TSRMLS_FETCH_FROM_CTX(url->ts);
491
492
493 #ifdef HAVE_INET_PTON
494 if (*ptr == '[') {
495 char *error = NULL, *tmp = memchr(ptr, ']', end - ptr);
496
497 if (tmp) {
498 size_t addrlen = tmp - ptr + 1;
499 char buf[16], *addr = estrndup(ptr + 1, addrlen - 2);
500 int rv = inet_pton(AF_INET6, addr, buf);
501
502 efree(addr);
503 if (rv == 1) {
504 url->buffer[url->offset] = '[';
505 url->host = &url->buffer[url->offset];
506 inet_ntop(AF_INET6, buf, url->host + 1, url->maxlen - url->offset);
507 url->offset += strlen(url->host);
508 url->buffer[url->offset++] = ']';
509 url->buffer[url->offset++] = 0;
510 ptr = tmp + 1;
511 } else if (rv == -1) {
512 error = strerror(errno);
513 } else {
514 error = "unexpected '['";
515 }
516 } else {
517 error = "expected ']'";
518 }
519
520 if (error) {
521 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse hostinfo; %s", error);
522 return FAILURE;
523 }
524 }
525 #endif
526 if (ptr != end) do {
527 switch (*ptr) {
528 case ':':
529 if (port) {
530 php_error_docref(NULL TSRMLS_CC, E_WARNING,
531 "Failed to parse port; unexpected ':' at pos %u in '%s'",
532 (unsigned) (ptr - tmp), tmp);
533 return FAILURE;
534 }
535 port = ptr + 1;
536 break;
537
538 case '%':
539 if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
540 php_error_docref(NULL TSRMLS_CC, E_WARNING,
541 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
542 (unsigned) (ptr - tmp), tmp);
543 return FAILURE;
544 }
545 url->buffer[url->offset++] = *ptr++;
546 url->buffer[url->offset++] = *ptr++;
547 url->buffer[url->offset++] = *ptr;
548 break;
549
550 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
551 case '+': case ',': case ';': case '=': /* sub-delims */
552 case '-': case '.': case '_': case '~': /* unreserved */
553 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
554 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
555 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
556 case 'V': case 'W': case 'X': case 'Y': case 'Z':
557 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
558 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
559 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
560 case 'v': case 'w': case 'x': case 'y': case 'z':
561 if (port) {
562 php_error_docref(NULL TSRMLS_CC, E_WARNING,
563 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
564 (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
565 return FAILURE;
566 }
567 /* no break */
568 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
569 case '7': case '8': case '9':
570 /* allowed */
571 if (port) {
572 url->port *= 10;
573 url->port += *ptr - '0';
574 } else {
575 url->buffer[url->offset++] = *ptr;
576 }
577 break;
578
579 default:
580 if (port) {
581 php_error_docref(NULL TSRMLS_CC, E_WARNING,
582 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
583 (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
584 return FAILURE;
585 } else if (!(mb = parse_mb(url, PARSE_HOSTINFO, ptr, end, tmp, 0))) {
586 return FAILURE;
587 }
588 ptr += mb - 1;
589 }
590 } while (++ptr != end);
591
592 if (!url->host) {
593 len = (port ? port - tmp - 1 : end - tmp);
594 url->host = &url->buffer[url->offset - len];
595 url->buffer[url->offset++] = 0;
596 }
597
598 #ifdef PHP_HTTP_HAVE_IDN
599 if (url->flags & PHP_HTTP_URL_PARSE_TOIDN) {
600 char *idn = NULL;
601 int rv = -1;
602
603 if (url->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
604 rv = idna_to_ascii_8z(url->host, &idn, IDNA_ALLOW_UNASSIGNED|IDNA_USE_STD3_ASCII_RULES);
605 }
606 # ifdef PHP_HTTP_HAVE_WCHAR
607 else if (url->flags & PHP_HTTP_URL_PARSE_MBLOC) {
608 rv = idna_to_ascii_lz(url->host, &idn, IDNA_ALLOW_UNASSIGNED|IDNA_USE_STD3_ASCII_RULES);
609 }
610 # endif
611 if (rv != IDNA_SUCCESS) {
612 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
613 return FAILURE;
614 } else {
615 size_t idnlen = strlen(idn);
616 memcpy(url->host, idn, idnlen + 1);
617 free(idn);
618 url->offset += idnlen - len;
619 }
620 }
621 #endif
622
623 return SUCCESS;
624 }
625
626 static const char *parse_authority(php_http_url_t *url)
627 {
628 const char *tmp = url->ptr, *host = NULL;
629
630 do {
631 switch (*url->ptr) {
632 case '@':
633 /* userinfo delimiter */
634 if (host) {
635 TSRMLS_FETCH_FROM_CTX(url->ts);
636 php_error_docref(NULL TSRMLS_CC, E_WARNING,
637 "Failed to parse userinfo; unexpected '@'");
638 return NULL;
639 }
640 host = url->ptr + 1;
641 if (tmp != url->ptr && SUCCESS != parse_userinfo(url, tmp)) {
642 return NULL;
643 }
644 tmp = url->ptr + 1;
645 break;
646
647 case '/':
648 case '?':
649 case '#':
650 case '\0':
651 /* host delimiter */
652 if (tmp != url->ptr && SUCCESS != parse_hostinfo(url, tmp)) {
653 return NULL;
654 }
655 return url->ptr;
656 }
657 } while (++url->ptr <= url->end);
658
659 return NULL;
660 }
661
662 static const char *parse_path(php_http_url_t *url)
663 {
664 size_t mb;
665 const char *tmp;
666 TSRMLS_FETCH_FROM_CTX(url->ts);
667
668 /* is there actually a path to parse? */
669 if (!*url->ptr) {
670 return url->ptr;
671 }
672 tmp = url->ptr;
673 url->path = &url->buffer[url->offset];
674
675 do {
676 switch (*url->ptr) {
677 case '#':
678 case '?':
679 case '\0':
680 /* did we have any path component ? */
681 if (tmp != url->ptr) {
682 url->buffer[url->offset++] = 0;
683 } else {
684 url->path = NULL;
685 }
686 return url->ptr;
687
688 case '%':
689 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
690 php_error_docref(NULL TSRMLS_CC, E_WARNING,
691 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
692 (unsigned) (url->ptr - tmp), tmp);
693 return NULL;
694 }
695 url->buffer[url->offset++] = *url->ptr++;
696 url->buffer[url->offset++] = *url->ptr++;
697 url->buffer[url->offset++] = *url->ptr;
698 break;
699
700 case '/': /* yeah, well */
701 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
702 case '+': case ',': case ';': case '=': /* sub-delims */
703 case '-': case '.': case '_': case '~': /* unreserved */
704 case ':': case '@': /* pchar */
705 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
706 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
707 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
708 case 'V': case 'W': case 'X': case 'Y': case 'Z':
709 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
710 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
711 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
712 case 'v': case 'w': case 'x': case 'y': case 'z':
713 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
714 case '7': case '8': case '9':
715 /* allowed */
716 url->buffer[url->offset++] = *url->ptr;
717 break;
718
719 default:
720 if (!(mb = parse_mb(url, PARSE_PATH, url->ptr, url->end, tmp, 0))) {
721 return NULL;
722 }
723 url->ptr += mb - 1;
724 }
725 } while (++url->ptr <= url->end);
726
727 return NULL;
728 }
729
730 static const char *parse_query(php_http_url_t *url)
731 {
732 size_t mb;
733 const char *tmp = url->ptr + !!*url->ptr;
734 TSRMLS_FETCH_FROM_CTX(url->ts);
735
736 /* is there actually a query to parse? */
737 if (*url->ptr != '?') {
738 return url->ptr;
739 }
740
741 /* skip initial '?' */
742 tmp = ++url->ptr;
743 url->query = &url->buffer[url->offset];
744
745 do {
746 switch (*url->ptr) {
747 case '#':
748 case '\0':
749 url->buffer[url->offset++] = 0;
750 return url->ptr;
751
752 case '%':
753 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
754 php_error_docref(NULL TSRMLS_CC, E_WARNING,
755 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
756 (unsigned) (url->ptr - tmp), tmp);
757 return NULL;
758 }
759 url->buffer[url->offset++] = *url->ptr++;
760 url->buffer[url->offset++] = *url->ptr++;
761 url->buffer[url->offset++] = *url->ptr;
762 break;
763
764 case '?': case '/': /* yeah, well */
765 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
766 case '+': case ',': case ';': case '=': /* sub-delims */
767 case '-': case '.': case '_': case '~': /* unreserved */
768 case ':': case '@': /* pchar */
769 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
770 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
771 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
772 case 'V': case 'W': case 'X': case 'Y': case 'Z':
773 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
774 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
775 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
776 case 'v': case 'w': case 'x': case 'y': case 'z':
777 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
778 case '7': case '8': case '9':
779 /* allowed */
780 url->buffer[url->offset++] = *url->ptr;
781 break;
782
783 default:
784 if (!(mb = parse_mb(url, PARSE_QUERY, url->ptr, url->end, tmp, 0))) {
785 return NULL;
786 }
787 url->ptr += mb - 1;
788 }
789 } while (++url->ptr <= url->end);
790
791 return NULL;
792 }
793
794 static const char *parse_fragment(php_http_url_t *url)
795 {
796 size_t mb;
797 const char *tmp;
798 TSRMLS_FETCH_FROM_CTX(url->ts);
799
800 /* is there actually a fragment to parse? */
801 if (*url->ptr != '#') {
802 return url->ptr;
803 }
804
805 /* skip initial '#' */
806 tmp = ++url->ptr;
807 url->fragment = &url->buffer[url->offset];
808
809 do {
810 switch (*url->ptr) {
811 case '\0':
812 url->buffer[url->offset++] = 0;
813 return url->ptr;
814
815 case '%':
816 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
817 php_error_docref(NULL TSRMLS_CC, E_WARNING,
818 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
819 (unsigned) (url->ptr - tmp), tmp);
820 return NULL;
821 }
822 url->buffer[url->offset++] = *url->ptr++;
823 url->buffer[url->offset++] = *url->ptr++;
824 url->buffer[url->offset++] = *url->ptr;
825 break;
826
827 case '?': case '/':
828 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
829 case '+': case ',': case ';': case '=': /* sub-delims */
830 case '-': case '.': case '_': case '~': /* unreserved */
831 case ':': case '@': /* pchar */
832 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
833 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
834 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
835 case 'V': case 'W': case 'X': case 'Y': case 'Z':
836 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
837 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
838 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
839 case 'v': case 'w': case 'x': case 'y': case 'z':
840 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
841 case '7': case '8': case '9':
842 /* allowed */
843 url->buffer[url->offset++] = *url->ptr;
844 break;
845
846 default:
847 if (!(mb = parse_mb(url, PARSE_FRAGMENT, url->ptr, url->end, tmp, 0))) {
848 return NULL;
849 }
850 url->ptr += mb - 1;
851 }
852 } while (++url->ptr <= url->end);
853
854 return NULL;
855 }
856
857 static const char *parse_hier(php_http_url_t *url)
858 {
859 if (*url->ptr == '/') {
860 if (url->end - url->ptr > 1) {
861 if (*(url->ptr + 1) == '/') {
862 url->ptr += 2;
863 if (!(url->ptr = parse_authority(url))) {
864 return NULL;
865 }
866 }
867 }
868 }
869 return parse_path(url);
870 }
871
872 static const char *parse_scheme(php_http_url_t *url)
873 {
874 size_t mb;
875 const char *tmp = url->ptr;
876
877 do {
878 switch (*url->ptr) {
879 case ':':
880 /* scheme delimiter */
881 url->scheme = &url->buffer[0];
882 url->buffer[url->offset++] = 0;
883 return ++url->ptr;
884
885 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
886 case '7': case '8': case '9':
887 case '+': case '-': case '.':
888 if (url->ptr == tmp) {
889 return tmp;
890 }
891 /* no break */
892 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
893 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
894 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
895 case 'V': case 'W': case 'X': case 'Y': case 'Z':
896 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
897 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
898 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
899 case 'v': case 'w': case 'x': case 'y': case 'z':
900 /* scheme part */
901 url->buffer[url->offset++] = *url->ptr;
902 break;
903
904 default:
905 if (!(mb = parse_mb(url, PARSE_SCHEME, url->ptr, url->end, tmp, 1))) {
906 /* soft fail; parse path next */
907 return tmp;
908 }
909 url->ptr += mb - 1;
910 }
911 } while (++url->ptr != url->end);
912
913 return tmp;
914 }
915
916 struct parser_state {
917 };
918
919 php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags TSRMLS_DC)
920 {
921 size_t maxlen = 3 * len;
922 php_http_url_t *url = ecalloc(1, sizeof(*url) + maxlen);
923
924 url->end = str + len;
925 url->ptr = str;
926 url->flags = flags;
927 url->maxlen = maxlen;
928 TSRMLS_SET_CTX(url->ts);
929
930 if (!parse_scheme(url)) {
931 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL scheme: '%s'", url->ptr);
932 php_http_url_free(&url);
933 return NULL;
934 }
935
936 if (!parse_hier(url)) {
937 php_http_url_free(&url);
938 return NULL;
939 }
940
941 if (!parse_query(url)) {
942 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL query: '%s'", url->ptr);
943 php_http_url_free(&url);
944 return NULL;
945 }
946
947 if (!parse_fragment(url)) {
948 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL fragment: '%s'", url->ptr);
949 php_http_url_free(&url);
950 return NULL;
951 }
952
953 return url;
954 }
955
956 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct, 0, 0, 0)
957 ZEND_ARG_INFO(0, old_url)
958 ZEND_ARG_INFO(0, new_url)
959 ZEND_ARG_INFO(0, flags)
960 ZEND_END_ARG_INFO();
961 PHP_METHOD(HttpUrl, __construct)
962 {
963 zval *new_url = NULL, *old_url = NULL;
964 long flags = PHP_HTTP_URL_FROM_ENV;
965 zend_error_handling zeh;
966
967 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
968
969 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
970 {
971 php_url *res_purl, *new_purl = NULL, *old_purl = NULL;
972
973 if (new_url) {
974 switch (Z_TYPE_P(new_url)) {
975 case IS_OBJECT:
976 case IS_ARRAY:
977 new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
978 break;
979 default: {
980 zval *cpy = php_http_ztyp(IS_STRING, new_url);
981
982 new_purl = php_url_parse(Z_STRVAL_P(cpy));
983 zval_ptr_dtor(&cpy);
984 break;
985 }
986 }
987 if (!new_purl) {
988 zend_restore_error_handling(&zeh TSRMLS_CC);
989 return;
990 }
991 }
992 if (old_url) {
993 switch (Z_TYPE_P(old_url)) {
994 case IS_OBJECT:
995 case IS_ARRAY:
996 old_purl = php_http_url_from_struct(NULL, HASH_OF(old_url) TSRMLS_CC);
997 break;
998 default: {
999 zval *cpy = php_http_ztyp(IS_STRING, old_url);
1000
1001 old_purl = php_url_parse(Z_STRVAL_P(cpy));
1002 zval_ptr_dtor(&cpy);
1003 break;
1004 }
1005 }
1006 if (!old_purl) {
1007 if (new_purl) {
1008 php_url_free(new_purl);
1009 }
1010 zend_restore_error_handling(&zeh TSRMLS_CC);
1011 return;
1012 }
1013 }
1014
1015 php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
1016 php_http_url_to_struct(res_purl, getThis() TSRMLS_CC);
1017
1018 php_url_free(res_purl);
1019 if (old_purl) {
1020 php_url_free(old_purl);
1021 }
1022 if (new_purl) {
1023 php_url_free(new_purl);
1024 }
1025 }
1026 zend_restore_error_handling(&zeh TSRMLS_CC);
1027 }
1028
1029 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod, 0, 0, 1)
1030 ZEND_ARG_INFO(0, more_url_parts)
1031 ZEND_ARG_INFO(0, flags)
1032 ZEND_END_ARG_INFO();
1033 PHP_METHOD(HttpUrl, mod)
1034 {
1035 zval *new_url = NULL;
1036 long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY;
1037 zend_error_handling zeh;
1038
1039 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags), invalid_arg, return);
1040
1041 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1042 {
1043 php_url *new_purl = NULL, *old_purl = NULL;
1044
1045 if (new_url) {
1046 switch (Z_TYPE_P(new_url)) {
1047 case IS_OBJECT:
1048 case IS_ARRAY:
1049 new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
1050 break;
1051 default: {
1052 zval *cpy = php_http_ztyp(IS_STRING, new_url);
1053
1054 new_purl = php_url_parse(Z_STRVAL_P(new_url));
1055 zval_ptr_dtor(&cpy);
1056 break;
1057 }
1058 }
1059 if (!new_purl) {
1060 zend_restore_error_handling(&zeh TSRMLS_CC);
1061 return;
1062 }
1063 }
1064
1065 if ((old_purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC))) {
1066 php_url *res_purl;
1067
1068 ZVAL_OBJVAL(return_value, zend_objects_clone_obj(getThis() TSRMLS_CC), 0);
1069
1070 php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
1071 php_http_url_to_struct(res_purl, return_value TSRMLS_CC);
1072
1073 php_url_free(res_purl);
1074 php_url_free(old_purl);
1075 }
1076 if (new_purl) {
1077 php_url_free(new_purl);
1078 }
1079 }
1080 zend_restore_error_handling(&zeh TSRMLS_CC);
1081 }
1082
1083 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString, 0, 0, 0)
1084 ZEND_END_ARG_INFO();
1085 PHP_METHOD(HttpUrl, toString)
1086 {
1087 if (SUCCESS == zend_parse_parameters_none()) {
1088 php_url *purl;
1089
1090 if ((purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC))) {
1091 char *str;
1092 size_t len;
1093
1094 php_http_url(0, purl, NULL, NULL, &str, &len TSRMLS_CC);
1095 php_url_free(purl);
1096 RETURN_STRINGL(str, len, 0);
1097 }
1098 }
1099 RETURN_EMPTY_STRING();
1100 }
1101
1102 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray, 0, 0, 0)
1103 ZEND_END_ARG_INFO();
1104 PHP_METHOD(HttpUrl, toArray)
1105 {
1106 php_url *purl;
1107
1108 if (SUCCESS != zend_parse_parameters_none()) {
1109 return;
1110 }
1111
1112 /* strip any non-URL properties */
1113 purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC);
1114 php_http_url_to_struct(purl, return_value TSRMLS_CC);
1115 php_url_free(purl);
1116 }
1117
1118 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_parse, 0, 0, 1)
1119 ZEND_ARG_INFO(0, url)
1120 ZEND_ARG_INFO(0, flags)
1121 ZEND_END_ARG_INFO();
1122 PHP_METHOD(HttpUrl, parse)
1123 {
1124 char *str;
1125 int len;
1126 long flags = 0;
1127 php_http_url_t *url;
1128 zend_error_handling zeh;
1129
1130 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, &flags), invalid_arg, return);
1131
1132 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1133 if ((url = php_http_url_parse(str, len, flags TSRMLS_CC))) {
1134 object_init_ex(return_value, php_http_url_class_entry);
1135 if (url->scheme) {
1136 zend_update_property_string(php_http_url_class_entry, return_value,
1137 ZEND_STRL("scheme"), url->scheme TSRMLS_CC);
1138 }
1139 if (url->user) {
1140 zend_update_property_string(php_http_url_class_entry, return_value,
1141 ZEND_STRL("user"), url->user TSRMLS_CC);
1142 }
1143 if (url->pass) {
1144 zend_update_property_string(php_http_url_class_entry, return_value,
1145 ZEND_STRL("pass"), url->pass TSRMLS_CC);
1146 }
1147 if (url->host) {
1148 zend_update_property_string(php_http_url_class_entry, return_value,
1149 ZEND_STRL("host"), url->host TSRMLS_CC);
1150 }
1151 if (url->port) {
1152 zend_update_property_long(php_http_url_class_entry, return_value,
1153 ZEND_STRL("port"), url->port TSRMLS_CC);
1154 }
1155 if (url->path) {
1156 zend_update_property_string(php_http_url_class_entry, return_value,
1157 ZEND_STRL("path"), url->path TSRMLS_CC);
1158 }
1159 if (url->query) {
1160 zend_update_property_string(php_http_url_class_entry, return_value,
1161 ZEND_STRL("query"), url->query TSRMLS_CC);
1162 }
1163 if (url->fragment) {
1164 zend_update_property_string(php_http_url_class_entry, return_value,
1165 ZEND_STRL("fragment"), url->fragment TSRMLS_CC);
1166 }
1167 php_http_url_free(&url);
1168 }
1169 zend_restore_error_handling(&zeh TSRMLS_CC);
1170 }
1171
1172 static zend_function_entry php_http_url_methods[] = {
1173 PHP_ME(HttpUrl, __construct, ai_HttpUrl___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
1174 PHP_ME(HttpUrl, mod, ai_HttpUrl_mod, ZEND_ACC_PUBLIC)
1175 PHP_ME(HttpUrl, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1176 ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1177 PHP_ME(HttpUrl, toArray, ai_HttpUrl_toArray, ZEND_ACC_PUBLIC)
1178 PHP_ME(HttpUrl, parse, ai_HttpUrl_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1179 EMPTY_FUNCTION_ENTRY
1180 };
1181
1182 zend_class_entry *php_http_url_class_entry;
1183
1184 PHP_MINIT_FUNCTION(http_url)
1185 {
1186 zend_class_entry ce = {0};
1187
1188 INIT_NS_CLASS_ENTRY(ce, "http", "Url", php_http_url_methods);
1189 php_http_url_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
1190
1191 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC);
1192 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
1193 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC);
1194 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC);
1195 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC);
1196 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC);
1197 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
1198 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC);
1199
1200 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC);
1201 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC);
1202 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC);
1203 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC);
1204 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC);
1205 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC);
1206 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC);
1207 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC);
1208 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC);
1209 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC);
1210 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC);
1211 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
1212 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC);
1213
1214 #ifdef PHP_HTTP_HAVE_WCHAR
1215 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC);
1216 #endif
1217 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC);
1218 #ifdef PHP_HTTP_HAVE_IDN
1219 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC);
1220 #endif
1221 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC);
1222
1223 return SUCCESS;
1224 }
1225
1226
1227 /*
1228 * Local variables:
1229 * tab-width: 4
1230 * c-basic-offset: 4
1231 * End:
1232 * vim600: noet sw=4 ts=4 fdm=marker
1233 * vim<600: noet sw=4 ts=4
1234 */
1235