brain wrecked
[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; duplicate ':' 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;
629
630 do {
631 switch (*url->ptr) {
632 case '@':
633 /* userinfo delimiter */
634 if (tmp != url->ptr && SUCCESS != parse_userinfo(url, tmp)) {
635 return NULL;
636 }
637 tmp = url->ptr + 1;
638 break;
639
640 case '/':
641 case '?':
642 case '#':
643 case '\0':
644 /* host delimiter */
645 if (tmp != url->ptr && SUCCESS != parse_hostinfo(url, tmp)) {
646 return NULL;
647 }
648 return url->ptr;
649 }
650 } while (++url->ptr <= url->end);
651
652 return NULL;
653 }
654
655 static const char *parse_path(php_http_url_t *url)
656 {
657 size_t mb;
658 const char *tmp;
659 TSRMLS_FETCH_FROM_CTX(url->ts);
660
661 /* is there actually a path to parse? */
662 if (!*url->ptr) {
663 return url->ptr;
664 }
665 tmp = url->ptr;
666 url->path = &url->buffer[url->offset];
667
668 do {
669 switch (*url->ptr) {
670 case '#':
671 case '?':
672 case '\0':
673 /* did we have any path component ? */
674 if (tmp != url->ptr) {
675 url->buffer[url->offset++] = 0;
676 } else {
677 url->path = NULL;
678 }
679 return url->ptr;
680
681 case '%':
682 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
683 php_error_docref(NULL TSRMLS_CC, E_WARNING,
684 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
685 (unsigned) (url->ptr - tmp), tmp);
686 return NULL;
687 }
688 url->buffer[url->offset++] = *url->ptr++;
689 url->buffer[url->offset++] = *url->ptr++;
690 url->buffer[url->offset++] = *url->ptr;
691 break;
692
693 case '/': /* yeah, well */
694 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
695 case '+': case ',': case ';': case '=': /* sub-delims */
696 case '-': case '.': case '_': case '~': /* unreserved */
697 case ':': case '@': /* pchar */
698 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
699 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
700 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
701 case 'V': case 'W': case 'X': case 'Y': case 'Z':
702 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
703 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
704 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
705 case 'v': case 'w': case 'x': case 'y': case 'z':
706 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
707 case '7': case '8': case '9':
708 /* allowed */
709 url->buffer[url->offset++] = *url->ptr;
710 break;
711
712 default:
713 if (!(mb = parse_mb(url, PARSE_PATH, url->ptr, url->end, tmp, 0))) {
714 return NULL;
715 }
716 url->ptr += mb - 1;
717 }
718 } while (++url->ptr <= url->end);
719
720 return NULL;
721 }
722
723 static const char *parse_query(php_http_url_t *url)
724 {
725 size_t mb;
726 const char *tmp = url->ptr + !!*url->ptr;
727 TSRMLS_FETCH_FROM_CTX(url->ts);
728
729 /* is there actually a query to parse? */
730 if (*url->ptr != '?') {
731 return url->ptr;
732 }
733
734 /* skip initial '?' */
735 tmp = ++url->ptr;
736 url->query = &url->buffer[url->offset];
737
738 do {
739 switch (*url->ptr) {
740 case '#':
741 case '\0':
742 url->buffer[url->offset++] = 0;
743 return url->ptr;
744
745 case '%':
746 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
747 php_error_docref(NULL TSRMLS_CC, E_WARNING,
748 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
749 (unsigned) (url->ptr - tmp), tmp);
750 return NULL;
751 }
752 url->buffer[url->offset++] = *url->ptr++;
753 url->buffer[url->offset++] = *url->ptr++;
754 url->buffer[url->offset++] = *url->ptr;
755 break;
756
757 case '?': case '/': /* yeah, well */
758 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
759 case '+': case ',': case ';': case '=': /* sub-delims */
760 case '-': case '.': case '_': case '~': /* unreserved */
761 case ':': case '@': /* pchar */
762 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
763 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
764 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
765 case 'V': case 'W': case 'X': case 'Y': case 'Z':
766 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
767 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
768 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
769 case 'v': case 'w': case 'x': case 'y': case 'z':
770 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
771 case '7': case '8': case '9':
772 /* allowed */
773 url->buffer[url->offset++] = *url->ptr;
774 break;
775
776 default:
777 if (!(mb = parse_mb(url, PARSE_QUERY, url->ptr, url->end, tmp, 0))) {
778 return NULL;
779 }
780 url->ptr += mb - 1;
781 }
782 } while (++url->ptr <= url->end);
783
784 return NULL;
785 }
786
787 static const char *parse_fragment(php_http_url_t *url)
788 {
789 size_t mb;
790 const char *tmp;
791 TSRMLS_FETCH_FROM_CTX(url->ts);
792
793 /* is there actually a fragment to parse? */
794 if (*url->ptr != '#') {
795 return url->ptr;
796 }
797
798 /* skip initial '#' */
799 tmp = ++url->ptr;
800 url->fragment = &url->buffer[url->offset];
801
802 do {
803 switch (*url->ptr) {
804 case '\0':
805 url->buffer[url->offset++] = 0;
806 return url->ptr;
807
808 case '%':
809 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
810 php_error_docref(NULL TSRMLS_CC, E_WARNING,
811 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
812 (unsigned) (url->ptr - tmp), tmp);
813 return NULL;
814 }
815 url->buffer[url->offset++] = *url->ptr++;
816 url->buffer[url->offset++] = *url->ptr++;
817 url->buffer[url->offset++] = *url->ptr;
818 break;
819
820 case '?': case '/':
821 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
822 case '+': case ',': case ';': case '=': /* sub-delims */
823 case '-': case '.': case '_': case '~': /* unreserved */
824 case ':': case '@': /* pchar */
825 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
826 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
827 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
828 case 'V': case 'W': case 'X': case 'Y': case 'Z':
829 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
830 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
831 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
832 case 'v': case 'w': case 'x': case 'y': case 'z':
833 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
834 case '7': case '8': case '9':
835 /* allowed */
836 url->buffer[url->offset++] = *url->ptr;
837 break;
838
839 default:
840 if (!(mb = parse_mb(url, PARSE_FRAGMENT, url->ptr, url->end, tmp, 0))) {
841 return NULL;
842 }
843 url->ptr += mb - 1;
844 }
845 } while (++url->ptr <= url->end);
846
847 return NULL;
848 }
849
850 static const char *parse_hier(php_http_url_t *url)
851 {
852 if (*url->ptr == '/') {
853 if (url->end - url->ptr > 1) {
854 if (*(url->ptr + 1) == '/') {
855 url->ptr += 2;
856 if (!(url->ptr = parse_authority(url))) {
857 return NULL;
858 }
859 }
860 }
861 }
862 return parse_path(url);
863 }
864
865 static const char *parse_scheme(php_http_url_t *url)
866 {
867 size_t mb;
868 const char *tmp = url->ptr;
869
870 do {
871 switch (*url->ptr) {
872 case ':':
873 /* scheme delimiter */
874 url->scheme = &url->buffer[0];
875 url->buffer[url->offset++] = 0;
876 return ++url->ptr;
877
878 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
879 case '7': case '8': case '9':
880 case '+': case '-': case '.':
881 if (url->ptr == tmp) {
882 return tmp;
883 }
884 /* no break */
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':
893 /* scheme part */
894 url->buffer[url->offset++] = *url->ptr;
895 break;
896
897 default:
898 if (!(mb = parse_mb(url, PARSE_SCHEME, url->ptr, url->end, tmp, 1))) {
899 /* soft fail; parse path next */
900 return tmp;
901 }
902 url->ptr += mb - 1;
903 }
904 } while (++url->ptr != url->end);
905
906 return tmp;
907 }
908
909 struct parser_state {
910 };
911
912 php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags TSRMLS_DC)
913 {
914 size_t maxlen = 3 * len;
915 php_http_url_t *url = ecalloc(1, sizeof(*url) + maxlen);
916
917 url->end = str + len;
918 url->ptr = str;
919 url->flags = flags;
920 url->maxlen = maxlen;
921 TSRMLS_SET_CTX(url->ts);
922
923 if (!parse_scheme(url)) {
924 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL scheme: '%s'", url->ptr);
925 php_http_url_free(&url);
926 return NULL;
927 }
928
929 if (!parse_hier(url)) {
930 php_http_url_free(&url);
931 return NULL;
932 }
933
934 if (!parse_query(url)) {
935 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL query: '%s'", url->ptr);
936 php_http_url_free(&url);
937 return NULL;
938 }
939
940 if (!parse_fragment(url)) {
941 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL fragment: '%s'", url->ptr);
942 php_http_url_free(&url);
943 return NULL;
944 }
945
946 return url;
947 }
948
949 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct, 0, 0, 0)
950 ZEND_ARG_INFO(0, old_url)
951 ZEND_ARG_INFO(0, new_url)
952 ZEND_ARG_INFO(0, flags)
953 ZEND_END_ARG_INFO();
954 PHP_METHOD(HttpUrl, __construct)
955 {
956 zval *new_url = NULL, *old_url = NULL;
957 long flags = PHP_HTTP_URL_FROM_ENV;
958 zend_error_handling zeh;
959
960 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
961
962 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
963 {
964 php_url *res_purl, *new_purl = NULL, *old_purl = NULL;
965
966 if (new_url) {
967 switch (Z_TYPE_P(new_url)) {
968 case IS_OBJECT:
969 case IS_ARRAY:
970 new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
971 break;
972 default: {
973 zval *cpy = php_http_ztyp(IS_STRING, new_url);
974
975 new_purl = php_url_parse(Z_STRVAL_P(cpy));
976 zval_ptr_dtor(&cpy);
977 break;
978 }
979 }
980 if (!new_purl) {
981 zend_restore_error_handling(&zeh TSRMLS_CC);
982 return;
983 }
984 }
985 if (old_url) {
986 switch (Z_TYPE_P(old_url)) {
987 case IS_OBJECT:
988 case IS_ARRAY:
989 old_purl = php_http_url_from_struct(NULL, HASH_OF(old_url) TSRMLS_CC);
990 break;
991 default: {
992 zval *cpy = php_http_ztyp(IS_STRING, old_url);
993
994 old_purl = php_url_parse(Z_STRVAL_P(cpy));
995 zval_ptr_dtor(&cpy);
996 break;
997 }
998 }
999 if (!old_purl) {
1000 if (new_purl) {
1001 php_url_free(new_purl);
1002 }
1003 zend_restore_error_handling(&zeh TSRMLS_CC);
1004 return;
1005 }
1006 }
1007
1008 php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
1009 php_http_url_to_struct(res_purl, getThis() TSRMLS_CC);
1010
1011 php_url_free(res_purl);
1012 if (old_purl) {
1013 php_url_free(old_purl);
1014 }
1015 if (new_purl) {
1016 php_url_free(new_purl);
1017 }
1018 }
1019 zend_restore_error_handling(&zeh TSRMLS_CC);
1020 }
1021
1022 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod, 0, 0, 1)
1023 ZEND_ARG_INFO(0, more_url_parts)
1024 ZEND_ARG_INFO(0, flags)
1025 ZEND_END_ARG_INFO();
1026 PHP_METHOD(HttpUrl, mod)
1027 {
1028 zval *new_url = NULL;
1029 long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY;
1030 zend_error_handling zeh;
1031
1032 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags), invalid_arg, return);
1033
1034 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1035 {
1036 php_url *new_purl = NULL, *old_purl = NULL;
1037
1038 if (new_url) {
1039 switch (Z_TYPE_P(new_url)) {
1040 case IS_OBJECT:
1041 case IS_ARRAY:
1042 new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
1043 break;
1044 default: {
1045 zval *cpy = php_http_ztyp(IS_STRING, new_url);
1046
1047 new_purl = php_url_parse(Z_STRVAL_P(new_url));
1048 zval_ptr_dtor(&cpy);
1049 break;
1050 }
1051 }
1052 if (!new_purl) {
1053 zend_restore_error_handling(&zeh TSRMLS_CC);
1054 return;
1055 }
1056 }
1057
1058 if ((old_purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC))) {
1059 php_url *res_purl;
1060
1061 ZVAL_OBJVAL(return_value, zend_objects_clone_obj(getThis() TSRMLS_CC), 0);
1062
1063 php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
1064 php_http_url_to_struct(res_purl, return_value TSRMLS_CC);
1065
1066 php_url_free(res_purl);
1067 php_url_free(old_purl);
1068 }
1069 if (new_purl) {
1070 php_url_free(new_purl);
1071 }
1072 }
1073 zend_restore_error_handling(&zeh TSRMLS_CC);
1074 }
1075
1076 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString, 0, 0, 0)
1077 ZEND_END_ARG_INFO();
1078 PHP_METHOD(HttpUrl, toString)
1079 {
1080 if (SUCCESS == zend_parse_parameters_none()) {
1081 php_url *purl;
1082
1083 if ((purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC))) {
1084 char *str;
1085 size_t len;
1086
1087 php_http_url(0, purl, NULL, NULL, &str, &len TSRMLS_CC);
1088 php_url_free(purl);
1089 RETURN_STRINGL(str, len, 0);
1090 }
1091 }
1092 RETURN_EMPTY_STRING();
1093 }
1094
1095 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray, 0, 0, 0)
1096 ZEND_END_ARG_INFO();
1097 PHP_METHOD(HttpUrl, toArray)
1098 {
1099 php_url *purl;
1100
1101 if (SUCCESS != zend_parse_parameters_none()) {
1102 return;
1103 }
1104
1105 /* strip any non-URL properties */
1106 purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC);
1107 php_http_url_to_struct(purl, return_value TSRMLS_CC);
1108 php_url_free(purl);
1109 }
1110
1111 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_parse, 0, 0, 1)
1112 ZEND_ARG_INFO(0, url)
1113 ZEND_ARG_INFO(0, flags)
1114 ZEND_END_ARG_INFO();
1115 PHP_METHOD(HttpUrl, parse)
1116 {
1117 char *str;
1118 int len;
1119 long flags = 0;
1120 php_http_url_t *url;
1121 zend_error_handling zeh;
1122
1123 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, &flags), invalid_arg, return);
1124
1125 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1126 if ((url = php_http_url_parse(str, len, flags TSRMLS_CC))) {
1127 object_init_ex(return_value, php_http_url_class_entry);
1128 if (url->scheme) {
1129 zend_update_property_string(php_http_url_class_entry, return_value,
1130 ZEND_STRL("scheme"), url->scheme TSRMLS_CC);
1131 }
1132 if (url->user) {
1133 zend_update_property_string(php_http_url_class_entry, return_value,
1134 ZEND_STRL("user"), url->user TSRMLS_CC);
1135 }
1136 if (url->pass) {
1137 zend_update_property_string(php_http_url_class_entry, return_value,
1138 ZEND_STRL("pass"), url->pass TSRMLS_CC);
1139 }
1140 if (url->host) {
1141 zend_update_property_string(php_http_url_class_entry, return_value,
1142 ZEND_STRL("host"), url->host TSRMLS_CC);
1143 }
1144 if (url->port) {
1145 zend_update_property_long(php_http_url_class_entry, return_value,
1146 ZEND_STRL("port"), url->port TSRMLS_CC);
1147 }
1148 if (url->path) {
1149 zend_update_property_string(php_http_url_class_entry, return_value,
1150 ZEND_STRL("path"), url->path TSRMLS_CC);
1151 }
1152 if (url->query) {
1153 zend_update_property_string(php_http_url_class_entry, return_value,
1154 ZEND_STRL("query"), url->query TSRMLS_CC);
1155 }
1156 if (url->fragment) {
1157 zend_update_property_string(php_http_url_class_entry, return_value,
1158 ZEND_STRL("fragment"), url->fragment TSRMLS_CC);
1159 }
1160 php_http_url_free(&url);
1161 }
1162 zend_restore_error_handling(&zeh TSRMLS_CC);
1163 }
1164
1165 static zend_function_entry php_http_url_methods[] = {
1166 PHP_ME(HttpUrl, __construct, ai_HttpUrl___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
1167 PHP_ME(HttpUrl, mod, ai_HttpUrl_mod, ZEND_ACC_PUBLIC)
1168 PHP_ME(HttpUrl, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1169 ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1170 PHP_ME(HttpUrl, toArray, ai_HttpUrl_toArray, ZEND_ACC_PUBLIC)
1171 PHP_ME(HttpUrl, parse, ai_HttpUrl_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1172 EMPTY_FUNCTION_ENTRY
1173 };
1174
1175 zend_class_entry *php_http_url_class_entry;
1176
1177 PHP_MINIT_FUNCTION(http_url)
1178 {
1179 zend_class_entry ce = {0};
1180
1181 INIT_NS_CLASS_ENTRY(ce, "http", "Url", php_http_url_methods);
1182 php_http_url_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
1183
1184 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC);
1185 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
1186 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC);
1187 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC);
1188 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC);
1189 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC);
1190 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
1191 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC);
1192
1193 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC);
1194 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC);
1195 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC);
1196 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC);
1197 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC);
1198 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC);
1199 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC);
1200 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC);
1201 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC);
1202 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC);
1203 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC);
1204 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
1205 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC);
1206
1207 #ifdef PHP_HTTP_HAVE_WCHAR
1208 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC);
1209 #endif
1210 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC);
1211 #ifdef PHP_HTTP_HAVE_IDN
1212 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC);
1213 #endif
1214 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC);
1215
1216 return SUCCESS;
1217 }
1218
1219
1220 /*
1221 * Local variables:
1222 * tab-width: 4
1223 * c-basic-offset: 4
1224 * End:
1225 * vim600: noet sw=4 ts=4 fdm=marker
1226 * vim<600: noet sw=4 ts=4
1227 */
1228