simplify
[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 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)
383 {
384 size_t consumed = 0;
385 zend_bool idn = (what == PARSE_HOSTINFO) && (url->flags & PHP_HTTP_URL_PARSE_IDN);
386
387 if (url->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
388 consumed = parse_mb_utf8(url, ptr, end, idn);
389 }
390 #ifdef PHP_HTTP_HAVE_WCHAR
391 else if (url->flags & PHP_HTTP_URL_PARSE_MBLOC) {
392 consumed = parse_mb_loc(url, ptr, end, idn);
393 }
394 #endif
395
396 if (consumed) {
397 PHP_HTTP_DUFF(consumed, url->buffer[url->offset++] = *ptr++);
398 } else if (!silent) {
399 TSRMLS_FETCH_FROM_CTX(url->ts);
400 php_error_docref(NULL TSRMLS_CC, E_WARNING,
401 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
402 parse_what[what], (unsigned char) *ptr, (unsigned) (ptr - begin), begin);
403 }
404
405 return consumed;
406 }
407
408 static STATUS parse_userinfo(php_http_url_t *url, const char *ptr)
409 {
410 size_t mb;
411 const char *password = NULL, *end = url->ptr, *tmp = ptr;
412 TSRMLS_FETCH_FROM_CTX(url->ts);
413
414 do {
415 switch (*ptr) {
416 case ':':
417 if (password) {
418 php_error_docref(NULL TSRMLS_CC, E_WARNING,
419 "Failed to parse password; duplicate ':' at pos %u in '%s'",
420 (unsigned) (ptr - tmp), tmp);
421 return FAILURE;
422 }
423 password = ptr + 1;
424 url->buffer[url->offset++] = *ptr;
425 break;
426
427 case '%':
428 if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
429 php_error_docref(NULL TSRMLS_CC, E_WARNING,
430 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
431 (unsigned) (ptr - tmp), tmp);
432 return FAILURE;
433 }
434 url->buffer[url->offset++] = *ptr++;
435 url->buffer[url->offset++] = *ptr++;
436 url->buffer[url->offset++] = *ptr;
437 break;
438
439 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
440 case '+': case ',': case ';': case '=': /* sub-delims */
441 case '-': case '.': case '_': case '~': /* unreserved */
442 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
443 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
444 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
445 case 'V': case 'W': case 'X': case 'Y': case 'Z':
446 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
447 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
448 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
449 case 'v': case 'w': case 'x': case 'y': case 'z':
450 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
451 case '7': case '8': case '9':
452 /* allowed */
453 url->buffer[url->offset++] = *ptr;
454 break;
455
456 default:
457 if (!(mb = parse_mb(url, PARSE_USERINFO, ptr, end, tmp, 0))) {
458 return FAILURE;
459 }
460 ptr += mb - 1;
461 }
462 } while(++ptr != end);
463
464 if (password) {
465 url->user = &url->buffer[url->offset - (end - password) - (password - tmp)];
466 url->buffer[url->offset - (end - password) - 1] = 0;
467 url->pass = &url->buffer[url->offset - (end - password)];
468 url->buffer[url->offset++] = 0;
469 } else {
470 url->user = &url->buffer[url->offset - (end - tmp)];
471 url->buffer[url->offset++] = 0;
472 }
473
474 return SUCCESS;
475 }
476
477 static STATUS parse_hostinfo(php_http_url_t *url, const char *ptr)
478 {
479 size_t mb, len;
480 const char *end = url->ptr, *tmp = ptr, *port = NULL;
481 TSRMLS_FETCH_FROM_CTX(url->ts);
482
483
484 #ifdef HAVE_INET_PTON
485 if (*ptr == '[') {
486 char *error = NULL, *tmp = memchr(ptr, ']', end - ptr);
487
488 if (tmp) {
489 size_t addrlen = tmp - ptr + 1;
490 char buf[16], *addr = estrndup(ptr + 1, addrlen - 2);
491 int rv = inet_pton(AF_INET6, addr, buf);
492
493 efree(addr);
494 if (rv == 1) {
495 url->buffer[url->offset] = '[';
496 url->host = &url->buffer[url->offset];
497 inet_ntop(AF_INET6, buf, url->host + 1, url->maxlen - url->offset);
498 url->offset += strlen(url->host);
499 url->buffer[url->offset++] = ']';
500 url->buffer[url->offset++] = 0;
501 ptr = tmp + 1;
502 } else if (rv == -1) {
503 error = strerror(errno);
504 } else {
505 error = "unexpected '['";
506 }
507 } else {
508 error = "expected ']'";
509 }
510
511 if (error) {
512 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse hostinfo; %s", error);
513 return FAILURE;
514 }
515 }
516 #endif
517 if (ptr != end) do {
518 switch (*ptr) {
519 case ':':
520 if (port) {
521 php_error_docref(NULL TSRMLS_CC, E_WARNING,
522 "Failed to parse port; duplicate ':' at pos %u in '%s'",
523 (unsigned) (ptr - tmp), tmp);
524 return FAILURE;
525 }
526 port = ptr + 1;
527 break;
528
529 case '%':
530 if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
531 php_error_docref(NULL TSRMLS_CC, E_WARNING,
532 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
533 (unsigned) (ptr - tmp), tmp);
534 return FAILURE;
535 }
536 url->buffer[url->offset++] = *ptr++;
537 url->buffer[url->offset++] = *ptr++;
538 url->buffer[url->offset++] = *ptr;
539 break;
540
541 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
542 case '+': case ',': case ';': case '=': /* sub-delims */
543 case '-': case '.': case '_': case '~': /* unreserved */
544 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
545 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
546 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
547 case 'V': case 'W': case 'X': case 'Y': case 'Z':
548 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
549 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
550 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
551 case 'v': case 'w': case 'x': case 'y': case 'z':
552 if (port) {
553 php_error_docref(NULL TSRMLS_CC, E_WARNING,
554 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
555 (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
556 return FAILURE;
557 }
558 /* no break */
559 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
560 case '7': case '8': case '9':
561 /* allowed */
562 if (port) {
563 url->port *= 10;
564 url->port += *ptr - '0';
565 } else {
566 url->buffer[url->offset++] = *ptr;
567 }
568 break;
569
570 default:
571 if (port) {
572 php_error_docref(NULL TSRMLS_CC, E_WARNING,
573 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
574 (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
575 return FAILURE;
576 } else if (!(mb = parse_mb(url, PARSE_HOSTINFO, ptr, end, tmp, 0))) {
577 return FAILURE;
578 }
579 ptr += mb - 1;
580 }
581 } while (++ptr != end);
582
583 if (!url->host) {
584 len = (port ? port - tmp - 1 : end - tmp);
585 url->host = &url->buffer[url->offset - len];
586 url->buffer[url->offset++] = 0;
587 }
588
589 #ifdef PHP_HTTP_HAVE_IDN
590 if (url->flags & PHP_HTTP_URL_PARSE_IDN) {
591 char *idn = NULL;
592 int rv = -1;
593
594 if (url->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
595 rv = idna_to_ascii_8z(url->host, &idn, IDNA_ALLOW_UNASSIGNED|IDNA_USE_STD3_ASCII_RULES);
596 }
597 # ifdef PHP_HTTP_HAVE_WCHAR
598 else if (url->flags & PHP_HTTP_URL_PARSE_MBLOC) {
599 rv = idna_to_ascii_lz(url->host, &idn, IDNA_ALLOW_UNASSIGNED|IDNA_USE_STD3_ASCII_RULES);
600 }
601 # endif
602 if (rv != IDNA_SUCCESS) {
603 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
604 return FAILURE;
605 } else {
606 size_t idnlen = strlen(idn);
607 memcpy(url->host, idn, idnlen + 1);
608 free(idn);
609 url->offset += idnlen - len;
610 }
611 }
612 #endif
613
614 return SUCCESS;
615 }
616
617 static const char *parse_authority(php_http_url_t *url)
618 {
619 const char *tmp = url->ptr;
620
621 do {
622 switch (*url->ptr) {
623 case '@':
624 /* userinfo delimiter */
625 if (tmp != url->ptr && SUCCESS != parse_userinfo(url, tmp)) {
626 return NULL;
627 }
628 tmp = url->ptr + 1;
629 break;
630
631 case '/':
632 case '?':
633 case '#':
634 case '\0':
635 /* host delimiter */
636 if (tmp != url->ptr && SUCCESS != parse_hostinfo(url, tmp)) {
637 return NULL;
638 }
639 return url->ptr;
640 }
641 } while (++url->ptr <= url->end);
642
643 return NULL;
644 }
645
646 static const char *parse_path(php_http_url_t *url)
647 {
648 size_t mb;
649 const char *tmp;
650 TSRMLS_FETCH_FROM_CTX(url->ts);
651
652 /* is there actually a path to parse? */
653 if (!*url->ptr) {
654 return url->ptr;
655 }
656 tmp = url->ptr;
657
658 do {
659 switch (*url->ptr) {
660 case '?':
661 case '\0':
662 /* did we have any path component ? */
663 if (tmp != url->ptr) {
664 url->path = &url->buffer[url->offset - (url->ptr - tmp)];
665 url->buffer[url->offset++] = 0;
666 }
667 return url->ptr;
668
669 case '%':
670 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
671 php_error_docref(NULL TSRMLS_CC, E_WARNING,
672 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
673 (unsigned) (url->ptr - tmp), tmp);
674 return NULL;
675 }
676 url->buffer[url->offset++] = *url->ptr++;
677 url->buffer[url->offset++] = *url->ptr++;
678 url->buffer[url->offset++] = *url->ptr;
679 break;
680
681 case '/': /* yeah, well */
682 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
683 case '+': case ',': case ';': case '=': /* sub-delims */
684 case '-': case '.': case '_': case '~': /* unreserved */
685 case ':': case '@': /* pchar */
686 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
687 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
688 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
689 case 'V': case 'W': case 'X': case 'Y': case 'Z':
690 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
691 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
692 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
693 case 'v': case 'w': case 'x': case 'y': case 'z':
694 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
695 case '7': case '8': case '9':
696 /* allowed */
697 url->buffer[url->offset++] = *url->ptr;
698 break;
699
700 default:
701 if (!(mb = parse_mb(url, PARSE_PATH, url->ptr, url->end, tmp, 0))) {
702 return NULL;
703 }
704 url->ptr += mb - 1;
705 }
706 } while (++url->ptr <= url->end);
707
708 return NULL;
709 }
710
711 static const char *parse_query(php_http_url_t *url)
712 {
713 size_t mb;
714 const char *tmp = url->ptr + !!*url->ptr;
715 TSRMLS_FETCH_FROM_CTX(url->ts);
716
717 /* is there actually a query to parse ? */
718 if (!*url->ptr || *url->ptr != '?') {
719 return url->ptr;
720 }
721
722 /* skip initial '?' */
723 tmp = url->ptr + 1;
724
725 do {
726 switch (*url->ptr) {
727 case '#':
728 case '\0':
729 url->query = &url->buffer[url->offset - (url->ptr - tmp)];
730 url->buffer[url->offset++] = 0;
731 return url->ptr;
732
733 case '%':
734 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
735 php_error_docref(NULL TSRMLS_CC, E_WARNING,
736 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
737 (unsigned) (url->ptr - tmp), tmp);
738 return NULL;
739 }
740 url->buffer[url->offset++] = *url->ptr++;
741 url->buffer[url->offset++] = *url->ptr++;
742 url->buffer[url->offset++] = *url->ptr;
743 break;
744
745 case '?': case '/': /* yeah, well */
746 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
747 case '+': case ',': case ';': case '=': /* sub-delims */
748 case '-': case '.': case '_': case '~': /* unreserved */
749 case ':': case '@': /* pchar */
750 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
751 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
752 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
753 case 'V': case 'W': case 'X': case 'Y': case 'Z':
754 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
755 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
756 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
757 case 'v': case 'w': case 'x': case 'y': case 'z':
758 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
759 case '7': case '8': case '9':
760 /* allowed */
761 url->buffer[url->offset++] = *url->ptr;
762 break;
763
764 default:
765 if (!(mb = parse_mb(url, PARSE_QUERY, url->ptr, url->end, tmp, 0))) {
766 return NULL;
767 }
768 url->ptr += mb - 1;
769 }
770 } while (++url->ptr <= url->end);
771
772 return NULL;
773 }
774
775 static const char *parse_fragment(php_http_url_t *url)
776 {
777 size_t mb;
778 const char *tmp;
779 TSRMLS_FETCH_FROM_CTX(url->ts);
780
781 /* is there actually a fragment to parse */
782 if (!*url->ptr || *url->ptr != '#') {
783 return url->ptr;
784 }
785
786 /* skip initial '#' */
787 tmp = url->ptr + 1;
788
789 do {
790 switch (*url->ptr) {
791 case '\0':
792 url->fragment = &url->buffer[url->offset - (url->ptr - tmp)];
793 url->buffer[url->offset++] = 0;
794 return url->ptr;
795
796 case '%':
797 if (url->ptr[1] != '%' && (url->end - url->ptr <= 2 || !isxdigit(*(url->ptr+1)) || !isxdigit(*(url->ptr+2)))) {
798 php_error_docref(NULL TSRMLS_CC, E_WARNING,
799 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
800 (unsigned) (url->ptr - tmp), tmp);
801 return NULL;
802 }
803 url->buffer[url->offset++] = *url->ptr++;
804 url->buffer[url->offset++] = *url->ptr++;
805 url->buffer[url->offset++] = *url->ptr;
806 break;
807
808 case '?': case '/': /* yeah, well */
809 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
810 case '+': case ',': case ';': case '=': /* sub-delims */
811 case '-': case '.': case '_': case '~': /* unreserved */
812 case ':': case '@': /* pchar */
813 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
814 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
815 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
816 case 'V': case 'W': case 'X': case 'Y': case 'Z':
817 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
818 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
819 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
820 case 'v': case 'w': case 'x': case 'y': case 'z':
821 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
822 case '7': case '8': case '9':
823 /* allowed */
824 url->buffer[url->offset++] = *url->ptr;
825 break;
826
827 default:
828 if (!(mb = parse_mb(url, PARSE_FRAGMENT, url->ptr, url->end, tmp, 0))) {
829 return NULL;
830 }
831 url->ptr += mb - 1;
832 }
833 } while (++url->ptr <= url->end);
834
835 return NULL;
836 }
837
838 static const char *parse_hier(php_http_url_t *url)
839 {
840 if (*url->ptr == '/') {
841 if (url->end - url->ptr > 1) {
842 if (*(url->ptr + 1) == '/') {
843 url->ptr += 2;
844 if (!(url->ptr = parse_authority(url))) {
845 return NULL;
846 }
847 }
848 }
849 }
850 return parse_path(url);
851 }
852
853 static const char *parse_scheme(php_http_url_t *url)
854 {
855 size_t mb;
856 const char *tmp = url->ptr;
857
858 do {
859 switch (*url->ptr) {
860 case ':':
861 /* scheme delimiter */
862 url->scheme = &url->buffer[0];
863 url->buffer[url->offset++] = 0;
864 return ++url->ptr;
865
866 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
867 case '7': case '8': case '9':
868 case '+': case '-': case '.':
869 if (url->ptr == tmp) {
870 return tmp;
871 }
872 /* no break */
873 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
874 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
875 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
876 case 'V': case 'W': case 'X': case 'Y': case 'Z':
877 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
878 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
879 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
880 case 'v': case 'w': case 'x': case 'y': case 'z':
881 /* scheme part */
882 url->buffer[url->offset++] = *url->ptr;
883 break;
884
885 default:
886 if (!(mb = parse_mb(url, PARSE_SCHEME, url->ptr, url->end, tmp, 1))) {
887 /* soft fail; parse path next */
888 return tmp;
889 }
890 url->ptr += mb - 1;
891 }
892 } while (++url->ptr != url->end);
893
894 return tmp;
895 }
896
897 struct parser_state {
898 };
899
900 php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags TSRMLS_DC)
901 {
902 size_t maxlen = 3 * len;
903 php_http_url_t *url = ecalloc(1, sizeof(*url) + maxlen);
904
905 url->end = str + len;
906 url->ptr = str;
907 url->flags = flags;
908 url->maxlen = maxlen;
909 TSRMLS_SET_CTX(url->ts);
910
911 if (!parse_scheme(url)) {
912 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL scheme: '%s'", url->ptr);
913 php_http_url_free(&url);
914 return NULL;
915 }
916
917 if (!parse_hier(url)) {
918 php_http_url_free(&url);
919 return NULL;
920 }
921
922 if (!parse_query(url)) {
923 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL query: '%s'", url->ptr);
924 php_http_url_free(&url);
925 return NULL;
926 }
927
928 if (!parse_fragment(url)) {
929 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL fragment: '%s'", url->ptr);
930 php_http_url_free(&url);
931 return NULL;
932 }
933
934 return url;
935 }
936
937 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct, 0, 0, 0)
938 ZEND_ARG_INFO(0, old_url)
939 ZEND_ARG_INFO(0, new_url)
940 ZEND_ARG_INFO(0, flags)
941 ZEND_END_ARG_INFO();
942 PHP_METHOD(HttpUrl, __construct)
943 {
944 zval *new_url = NULL, *old_url = NULL;
945 long flags = PHP_HTTP_URL_FROM_ENV;
946 zend_error_handling zeh;
947
948 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
949
950 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
951 {
952 php_url *res_purl, *new_purl = NULL, *old_purl = NULL;
953
954 if (new_url) {
955 switch (Z_TYPE_P(new_url)) {
956 case IS_OBJECT:
957 case IS_ARRAY:
958 new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
959 break;
960 default: {
961 zval *cpy = php_http_ztyp(IS_STRING, new_url);
962
963 new_purl = php_url_parse(Z_STRVAL_P(cpy));
964 zval_ptr_dtor(&cpy);
965 break;
966 }
967 }
968 if (!new_purl) {
969 zend_restore_error_handling(&zeh TSRMLS_CC);
970 return;
971 }
972 }
973 if (old_url) {
974 switch (Z_TYPE_P(old_url)) {
975 case IS_OBJECT:
976 case IS_ARRAY:
977 old_purl = php_http_url_from_struct(NULL, HASH_OF(old_url) TSRMLS_CC);
978 break;
979 default: {
980 zval *cpy = php_http_ztyp(IS_STRING, old_url);
981
982 old_purl = php_url_parse(Z_STRVAL_P(cpy));
983 zval_ptr_dtor(&cpy);
984 break;
985 }
986 }
987 if (!old_purl) {
988 if (new_purl) {
989 php_url_free(new_purl);
990 }
991 zend_restore_error_handling(&zeh TSRMLS_CC);
992 return;
993 }
994 }
995
996 php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
997 php_http_url_to_struct(res_purl, getThis() TSRMLS_CC);
998
999 php_url_free(res_purl);
1000 if (old_purl) {
1001 php_url_free(old_purl);
1002 }
1003 if (new_purl) {
1004 php_url_free(new_purl);
1005 }
1006 }
1007 zend_restore_error_handling(&zeh TSRMLS_CC);
1008 }
1009
1010 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod, 0, 0, 1)
1011 ZEND_ARG_INFO(0, more_url_parts)
1012 ZEND_ARG_INFO(0, flags)
1013 ZEND_END_ARG_INFO();
1014 PHP_METHOD(HttpUrl, mod)
1015 {
1016 zval *new_url = NULL;
1017 long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY;
1018 zend_error_handling zeh;
1019
1020 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags), invalid_arg, return);
1021
1022 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1023 {
1024 php_url *new_purl = NULL, *old_purl = NULL;
1025
1026 if (new_url) {
1027 switch (Z_TYPE_P(new_url)) {
1028 case IS_OBJECT:
1029 case IS_ARRAY:
1030 new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
1031 break;
1032 default: {
1033 zval *cpy = php_http_ztyp(IS_STRING, new_url);
1034
1035 new_purl = php_url_parse(Z_STRVAL_P(new_url));
1036 zval_ptr_dtor(&cpy);
1037 break;
1038 }
1039 }
1040 if (!new_purl) {
1041 zend_restore_error_handling(&zeh TSRMLS_CC);
1042 return;
1043 }
1044 }
1045
1046 if ((old_purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC))) {
1047 php_url *res_purl;
1048
1049 ZVAL_OBJVAL(return_value, zend_objects_clone_obj(getThis() TSRMLS_CC), 0);
1050
1051 php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
1052 php_http_url_to_struct(res_purl, return_value TSRMLS_CC);
1053
1054 php_url_free(res_purl);
1055 php_url_free(old_purl);
1056 }
1057 if (new_purl) {
1058 php_url_free(new_purl);
1059 }
1060 }
1061 zend_restore_error_handling(&zeh TSRMLS_CC);
1062 }
1063
1064 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString, 0, 0, 0)
1065 ZEND_END_ARG_INFO();
1066 PHP_METHOD(HttpUrl, toString)
1067 {
1068 if (SUCCESS == zend_parse_parameters_none()) {
1069 php_url *purl;
1070
1071 if ((purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC))) {
1072 char *str;
1073 size_t len;
1074
1075 php_http_url(0, purl, NULL, NULL, &str, &len TSRMLS_CC);
1076 php_url_free(purl);
1077 RETURN_STRINGL(str, len, 0);
1078 }
1079 }
1080 RETURN_EMPTY_STRING();
1081 }
1082
1083 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray, 0, 0, 0)
1084 ZEND_END_ARG_INFO();
1085 PHP_METHOD(HttpUrl, toArray)
1086 {
1087 php_url *purl;
1088
1089 if (SUCCESS != zend_parse_parameters_none()) {
1090 return;
1091 }
1092
1093 /* strip any non-URL properties */
1094 purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC);
1095 php_http_url_to_struct(purl, return_value TSRMLS_CC);
1096 php_url_free(purl);
1097 }
1098
1099 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_parse, 0, 0, 1)
1100 ZEND_ARG_INFO(0, url)
1101 ZEND_ARG_INFO(0, flags)
1102 ZEND_END_ARG_INFO();
1103 PHP_METHOD(HttpUrl, parse)
1104 {
1105 char *str;
1106 int len;
1107 long flags = 0;
1108 php_http_url_t *url;
1109 zend_error_handling zeh;
1110
1111 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, &flags), invalid_arg, return);
1112
1113 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1114 if ((url = php_http_url_parse(str, len, flags TSRMLS_CC))) {
1115 object_init_ex(return_value, php_http_url_class_entry);
1116 if (url->scheme) {
1117 zend_update_property_string(php_http_url_class_entry, return_value,
1118 ZEND_STRL("scheme"), url->scheme TSRMLS_CC);
1119 }
1120 if (url->user) {
1121 zend_update_property_string(php_http_url_class_entry, return_value,
1122 ZEND_STRL("user"), url->user TSRMLS_CC);
1123 }
1124 if (url->pass) {
1125 zend_update_property_string(php_http_url_class_entry, return_value,
1126 ZEND_STRL("pass"), url->pass TSRMLS_CC);
1127 }
1128 if (url->host) {
1129 zend_update_property_string(php_http_url_class_entry, return_value,
1130 ZEND_STRL("host"), url->host TSRMLS_CC);
1131 }
1132 if (url->port) {
1133 zend_update_property_long(php_http_url_class_entry, return_value,
1134 ZEND_STRL("port"), url->port TSRMLS_CC);
1135 }
1136 if (url->path) {
1137 zend_update_property_string(php_http_url_class_entry, return_value,
1138 ZEND_STRL("path"), url->path TSRMLS_CC);
1139 }
1140 if (url->query) {
1141 zend_update_property_string(php_http_url_class_entry, return_value,
1142 ZEND_STRL("query"), url->query TSRMLS_CC);
1143 }
1144 if (url->fragment) {
1145 zend_update_property_string(php_http_url_class_entry, return_value,
1146 ZEND_STRL("fragment"), url->fragment TSRMLS_CC);
1147 }
1148 php_http_url_free(&url);
1149 }
1150 zend_restore_error_handling(&zeh TSRMLS_CC);
1151 }
1152
1153 static zend_function_entry php_http_url_methods[] = {
1154 PHP_ME(HttpUrl, __construct, ai_HttpUrl___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
1155 PHP_ME(HttpUrl, mod, ai_HttpUrl_mod, ZEND_ACC_PUBLIC)
1156 PHP_ME(HttpUrl, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1157 ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1158 PHP_ME(HttpUrl, toArray, ai_HttpUrl_toArray, ZEND_ACC_PUBLIC)
1159 PHP_ME(HttpUrl, parse, ai_HttpUrl_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1160 EMPTY_FUNCTION_ENTRY
1161 };
1162
1163 zend_class_entry *php_http_url_class_entry;
1164
1165 PHP_MINIT_FUNCTION(http_url)
1166 {
1167 zend_class_entry ce = {0};
1168
1169 INIT_NS_CLASS_ENTRY(ce, "http", "Url", php_http_url_methods);
1170 php_http_url_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
1171
1172 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC);
1173 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
1174 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC);
1175 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC);
1176 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC);
1177 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC);
1178 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
1179 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC);
1180
1181 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC);
1182 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC);
1183 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC);
1184 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC);
1185 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC);
1186 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC);
1187 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC);
1188 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC);
1189 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC);
1190 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC);
1191 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC);
1192 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
1193 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC);
1194
1195 #ifdef PHP_HTTP_HAVE_WCHAR
1196 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC);
1197 #endif
1198 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC);
1199 #ifdef PHP_HTTP_HAVE_IDN
1200 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_IDN"), PHP_HTTP_URL_PARSE_IDN TSRMLS_CC);
1201 #endif
1202
1203 return SUCCESS;
1204 }
1205
1206
1207 /*
1208 * Local variables:
1209 * tab-width: 4
1210 * c-basic-offset: 4
1211 * End:
1212 * vim600: noet sw=4 ts=4 fdm=marker
1213 * vim<600: noet sw=4 ts=4
1214 */
1215