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