attempt to implement some personal standards
[m6w6/ext-http] / src / 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 #if PHP_HTTP_HAVE_IDN2
16 # include <idn2.h>
17 #elif PHP_HTTP_HAVE_IDN
18 # include <idna.h>
19 #endif
20
21 #ifdef PHP_HTTP_HAVE_WCHAR
22 # include <wchar.h>
23 # include <wctype.h>
24 #endif
25
26 #ifdef HAVE_ARPA_INET_H
27 # include <arpa/inet.h>
28 #endif
29
30 #include "php_http_utf8.h"
31
32 static inline char *localhostname(void)
33 {
34 char hostname[1024] = {0};
35
36 #ifdef PHP_WIN32
37 if (SUCCESS == gethostname(hostname, lenof(hostname))) {
38 return estrdup(hostname);
39 }
40 #elif defined(HAVE_GETHOSTNAME)
41 if (SUCCESS == gethostname(hostname, lenof(hostname))) {
42 # if defined(HAVE_GETDOMAINNAME)
43 size_t hlen = strlen(hostname);
44 if (hlen <= lenof(hostname) - lenof("(none)")) {
45 hostname[hlen++] = '.';
46 if (SUCCESS == getdomainname(&hostname[hlen], lenof(hostname) - hlen)) {
47 if (!strcmp(&hostname[hlen], "(none)")) {
48 hostname[hlen - 1] = '\0';
49 }
50 return estrdup(hostname);
51 }
52 }
53 # endif
54 if (strcmp(hostname, "(none)")) {
55 return estrdup(hostname);
56 }
57 }
58 #endif
59 return estrndup("localhost", lenof("localhost"));
60 }
61
62 #define url(buf) ((php_http_url_t *) (buf).data)
63
64 static php_http_url_t *php_http_url_from_env(TSRMLS_D)
65 {
66 zval *https, *zhost, *zport;
67 long port;
68 php_http_buffer_t buf;
69
70 php_http_buffer_init_ex(&buf, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE, sizeof(php_http_url_t)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC);
71 php_http_buffer_account(&buf, sizeof(php_http_url_t));
72 memset(buf.data, 0, buf.used);
73
74 /* scheme */
75 url(buf)->scheme = &buf.data[buf.used];
76 https = php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1 TSRMLS_CC);
77 if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) {
78 php_http_buffer_append(&buf, "https", sizeof("https"));
79 } else {
80 php_http_buffer_append(&buf, "http", sizeof("http"));
81 }
82
83 /* host */
84 url(buf)->host = &buf.data[buf.used];
85 if ((((zhost = php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1 TSRMLS_CC)) ||
86 (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1 TSRMLS_CC)) ||
87 (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1 TSRMLS_CC)))) && Z_STRLEN_P(zhost)) {
88 size_t stop_at = strspn(Z_STRVAL_P(zhost), "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.");
89
90 php_http_buffer_append(&buf, Z_STRVAL_P(zhost), stop_at);
91 php_http_buffer_append(&buf, "", 1);
92 } else {
93 char *host_str = localhostname();
94
95 php_http_buffer_append(&buf, host_str, strlen(host_str) + 1);
96 efree(host_str);
97 }
98
99 /* port */
100 zport = php_http_env_get_server_var(ZEND_STRL("SERVER_PORT"), 1 TSRMLS_CC);
101 if (zport && IS_LONG == is_numeric_string(Z_STRVAL_P(zport), Z_STRLEN_P(zport), &port, NULL, 0)) {
102 url(buf)->port = port;
103 }
104
105 /* path */
106 if (SG(request_info).request_uri && SG(request_info).request_uri[0]) {
107 const char *q = strchr(SG(request_info).request_uri, '?');
108
109 url(buf)->path = &buf.data[buf.used];
110
111 if (q) {
112 php_http_buffer_append(&buf, SG(request_info).request_uri, q - SG(request_info).request_uri);
113 php_http_buffer_append(&buf, "", 1);
114 } else {
115 php_http_buffer_append(&buf, SG(request_info).request_uri, strlen(SG(request_info).request_uri) + 1);
116 }
117 }
118
119 /* query */
120 if (SG(request_info).query_string && SG(request_info).query_string[0]) {
121 url(buf)->query = &buf.data[buf.used];
122 php_http_buffer_append(&buf, SG(request_info).query_string, strlen(SG(request_info).query_string) + 1);
123 }
124
125 return url(buf);
126 }
127
128 #define url_isset(u,n) \
129 ((u)&&(u)->n)
130 #define url_append(buf, append) do { \
131 char *_ptr = (buf)->data; \
132 php_http_url_t *_url = (php_http_url_t *) _ptr, _mem = *_url; \
133 append; \
134 /* relocate */ \
135 if (_ptr != (buf)->data) { \
136 ptrdiff_t diff = (buf)->data - _ptr; \
137 _url = (php_http_url_t *) (buf)->data; \
138 if (_mem.scheme) _url->scheme += diff; \
139 if (_mem.user) _url->user += diff; \
140 if (_mem.pass) _url->pass += diff; \
141 if (_mem.host) _url->host += diff; \
142 if (_mem.path) _url->path += diff; \
143 if (_mem.query) _url->query += diff; \
144 if (_mem.fragment) _url->fragment += diff; \
145 } \
146 } while (0)
147 #define url_copy(n) do { \
148 if (url_isset(new_url, n)) { \
149 url(buf)->n = &buf.data[buf.used]; \
150 url_append(&buf, php_http_buffer_append(&buf, new_url->n, strlen(new_url->n) + 1)); \
151 } else if (url_isset(old_url, n)) { \
152 url(buf)->n = &buf.data[buf.used]; \
153 url_append(&buf, php_http_buffer_append(&buf, old_url->n, strlen(old_url->n) + 1)); \
154 } \
155 } while (0)
156
157 php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_url_t *new_url, unsigned flags TSRMLS_DC)
158 {
159 php_http_url_t *tmp_url = NULL;
160 php_http_buffer_t buf;
161
162 php_http_buffer_init_ex(&buf, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE, sizeof(php_http_url_t)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC);
163 php_http_buffer_account(&buf, sizeof(php_http_url_t));
164 memset(buf.data, 0, buf.used);
165
166 /* set from env if requested */
167 if (flags & PHP_HTTP_URL_FROM_ENV) {
168 php_http_url_t *env_url = php_http_url_from_env(TSRMLS_C);
169
170 old_url = tmp_url = php_http_url_mod(env_url, old_url, flags ^ PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
171 php_http_url_free(&env_url);
172 }
173
174 url_copy(scheme);
175
176 if (!(flags & PHP_HTTP_URL_STRIP_USER)) {
177 url_copy(user);
178 }
179
180 if (!(flags & PHP_HTTP_URL_STRIP_PASS)) {
181 url_copy(pass);
182 }
183
184 url_copy(host);
185
186 if (!(flags & PHP_HTTP_URL_STRIP_PORT)) {
187 url(buf)->port = url_isset(new_url, port) ? new_url->port : ((old_url) ? old_url->port : 0);
188 }
189
190 if (!(flags & PHP_HTTP_URL_STRIP_PATH)) {
191 if ((flags & PHP_HTTP_URL_JOIN_PATH) && url_isset(old_url, path) && url_isset(new_url, path) && *new_url->path != '/') {
192 size_t old_path_len = strlen(old_url->path), new_path_len = strlen(new_url->path);
193 char *path = ecalloc(1, old_path_len + new_path_len + 1 + 1);
194
195 strcat(path, old_url->path);
196 if (path[old_path_len - 1] != '/') {
197 php_dirname(path, old_path_len);
198 strcat(path, "/");
199 }
200 strcat(path, new_url->path);
201
202 url(buf)->path = &buf.data[buf.used];
203 if (path[0] != '/') {
204 url_append(&buf, php_http_buffer_append(&buf, "/", 1));
205 }
206 url_append(&buf, php_http_buffer_append(&buf, path, strlen(path) + 1));
207 efree(path);
208 } else {
209 const char *path = NULL;
210
211 if (url_isset(new_url, path)) {
212 path = new_url->path;
213 } else if (url_isset(old_url, path)) {
214 path = old_url->path;
215 }
216
217 if (path) {
218 url(buf)->path = &buf.data[buf.used];
219
220 url_append(&buf, php_http_buffer_append(&buf, path, strlen(path) + 1));
221 }
222
223
224 }
225 }
226
227 if (!(flags & PHP_HTTP_URL_STRIP_QUERY)) {
228 if ((flags & PHP_HTTP_URL_JOIN_QUERY) && url_isset(new_url, query) && url_isset(old_url, query)) {
229 zval qarr, qstr;
230
231 INIT_PZVAL(&qstr);
232 INIT_PZVAL(&qarr);
233 array_init(&qarr);
234
235 ZVAL_STRING(&qstr, old_url->query, 0);
236 php_http_querystring_update(&qarr, &qstr, NULL TSRMLS_CC);
237 ZVAL_STRING(&qstr, new_url->query, 0);
238 php_http_querystring_update(&qarr, &qstr, NULL TSRMLS_CC);
239
240 ZVAL_NULL(&qstr);
241 php_http_querystring_update(&qarr, NULL, &qstr TSRMLS_CC);
242
243 url(buf)->query = &buf.data[buf.used];
244 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL(qstr), Z_STRLEN(qstr) + 1));
245
246 zval_dtor(&qstr);
247 zval_dtor(&qarr);
248 } else {
249 url_copy(query);
250 }
251 }
252
253 if (!(flags & PHP_HTTP_URL_STRIP_FRAGMENT)) {
254 url_copy(fragment);
255 }
256
257 /* done with copy & combine & strip */
258
259 if (flags & PHP_HTTP_URL_FROM_ENV) {
260 /* free old_url we tainted above */
261 php_http_url_free(&tmp_url);
262 }
263
264 /* replace directory references if path is not a single slash */
265 if ((flags & PHP_HTTP_URL_SANITIZE_PATH)
266 && url(buf)->path[0] && url(buf)->path[1]) {
267 char *ptr, *end = url(buf)->path + strlen(url(buf)->path) + 1;
268
269 for (ptr = strchr(url(buf)->path, '/'); ptr; ptr = strchr(ptr, '/')) {
270 switch (ptr[1]) {
271 case '/':
272 memmove(&ptr[1], &ptr[2], end - &ptr[2]);
273 break;
274
275 case '.':
276 switch (ptr[2]) {
277 case '\0':
278 ptr[1] = '\0';
279 break;
280
281 case '/':
282 memmove(&ptr[1], &ptr[3], end - &ptr[3]);
283 break;
284
285 case '.':
286 if (ptr[3] == '/') {
287 char *pos = &ptr[4];
288 while (ptr != url(buf)->path) {
289 if (*--ptr == '/') {
290 break;
291 }
292 }
293 memmove(&ptr[1], pos, end - pos);
294 break;
295 } else if (!ptr[3]) {
296 /* .. at the end */
297 ptr[1] = '\0';
298 }
299 /* no break */
300
301 default:
302 /* something else */
303 ++ptr;
304 break;
305 }
306 break;
307
308 default:
309 ++ptr;
310 break;
311 }
312 }
313 }
314 /* unset default ports */
315 if (url(buf)->port) {
316 if ( ((url(buf)->port == 80) && url(buf)->scheme && !strcmp(url(buf)->scheme, "http"))
317 || ((url(buf)->port ==443) && url(buf)->scheme && !strcmp(url(buf)->scheme, "https"))
318 ) {
319 url(buf)->port = 0;
320 }
321 }
322
323 return url(buf);
324 }
325
326 char *php_http_url_to_string(const php_http_url_t *url, char **url_str, size_t *url_len, zend_bool persistent)
327 {
328 php_http_buffer_t buf;
329
330 php_http_buffer_init_ex(&buf, PHP_HTTP_BUFFER_DEFAULT_SIZE, persistent ?
331 PHP_HTTP_BUFFER_INIT_PERSISTENT : 0);
332
333 if (url->scheme && *url->scheme) {
334 php_http_buffer_appendl(&buf, url->scheme);
335 php_http_buffer_appends(&buf, "://");
336 } else if ((url->user && *url->user) || (url->host && *url->host)) {
337 php_http_buffer_appends(&buf, "//");
338 }
339
340 if (url->user && *url->user) {
341 php_http_buffer_appendl(&buf, url->user);
342 if (url->pass && *url->pass) {
343 php_http_buffer_appends(&buf, ":");
344 php_http_buffer_appendl(&buf, url->pass);
345 }
346 php_http_buffer_appends(&buf, "@");
347 }
348
349 if (url->host && *url->host) {
350 php_http_buffer_appendl(&buf, url->host);
351 if (url->port) {
352 php_http_buffer_appendf(&buf, ":%hu", url->port);
353 }
354 }
355
356 if (url->path && *url->path) {
357 if (*url->path != '/') {
358 php_http_buffer_appends(&buf, "/");
359 }
360 php_http_buffer_appendl(&buf, url->path);
361 } else if (buf.used) {
362 php_http_buffer_appends(&buf, "/");
363 }
364
365 if (url->query && *url->query) {
366 php_http_buffer_appends(&buf, "?");
367 php_http_buffer_appendl(&buf, url->query);
368 }
369
370 if (url->fragment && *url->fragment) {
371 php_http_buffer_appends(&buf, "#");
372 php_http_buffer_appendl(&buf, url->fragment);
373 }
374
375 php_http_buffer_shrink(&buf);
376 php_http_buffer_fix(&buf);
377
378 if (url_len) {
379 *url_len = buf.used;
380 }
381
382 if (url_str) {
383 *url_str = buf.data;
384 }
385
386 return buf.data;
387 }
388
389 char *php_http_url_authority_to_string(const php_http_url_t *url, char **url_str, size_t *url_len)
390 {
391 php_http_buffer_t buf;
392
393 php_http_buffer_init(&buf);
394
395 if (url->user && *url->user) {
396 php_http_buffer_appendl(&buf, url->user);
397 if (url->pass && *url->pass) {
398 php_http_buffer_appends(&buf, ":");
399 php_http_buffer_appendl(&buf, url->pass);
400 }
401 php_http_buffer_appends(&buf, "@");
402 }
403
404 if (url->host && *url->host) {
405 php_http_buffer_appendl(&buf, url->host);
406 if (url->port) {
407 php_http_buffer_appendf(&buf, ":%hu", url->port);
408 }
409 }
410
411 php_http_buffer_shrink(&buf);
412 php_http_buffer_fix(&buf);
413
414 if (url_len) {
415 *url_len = buf.used;
416 }
417
418 if (url_str) {
419 *url_str = buf.data;
420 }
421
422 return buf.data;
423 }
424
425 php_http_url_t *php_http_url_from_zval(zval *value, unsigned flags TSRMLS_DC)
426 {
427 zval *zcpy;
428 php_http_url_t *purl;
429
430 switch (Z_TYPE_P(value)) {
431 case IS_ARRAY:
432 case IS_OBJECT:
433 purl = php_http_url_from_struct(HASH_OF(value));
434 break;
435
436 default:
437 zcpy = php_http_ztyp(IS_STRING, value);
438 purl = php_http_url_parse(Z_STRVAL_P(zcpy), Z_STRLEN_P(zcpy), flags TSRMLS_CC);
439 zval_ptr_dtor(&zcpy);
440 }
441
442 return purl;
443 }
444
445 php_http_url_t *php_http_url_from_struct(HashTable *ht)
446 {
447 zval **e;
448 php_http_buffer_t buf;
449
450 php_http_buffer_init_ex(&buf, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE, sizeof(php_http_url_t)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC);
451 php_http_buffer_account(&buf, sizeof(php_http_url_t));
452 memset(buf.data, 0, buf.used);
453
454 if (SUCCESS == zend_hash_find(ht, "scheme", sizeof("scheme"), (void *) &e)) {
455 zval *cpy = php_http_ztyp(IS_STRING, *e);
456 url(buf)->scheme = &buf.data[buf.used];
457 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
458 zval_ptr_dtor(&cpy);
459 }
460 if (SUCCESS == zend_hash_find(ht, "user", sizeof("user"), (void *) &e)) {
461 zval *cpy = php_http_ztyp(IS_STRING, *e);
462 url(buf)->user = &buf.data[buf.used];
463 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
464 zval_ptr_dtor(&cpy);
465 }
466 if (SUCCESS == zend_hash_find(ht, "pass", sizeof("pass"), (void *) &e)) {
467 zval *cpy = php_http_ztyp(IS_STRING, *e);
468 url(buf)->pass = &buf.data[buf.used];
469 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
470 zval_ptr_dtor(&cpy);
471 }
472 if (SUCCESS == zend_hash_find(ht, "host", sizeof("host"), (void *) &e)) {
473 zval *cpy = php_http_ztyp(IS_STRING, *e);
474 url(buf)->host = &buf.data[buf.used];
475 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
476 zval_ptr_dtor(&cpy);
477 }
478 if (SUCCESS == zend_hash_find(ht, "port", sizeof("port"), (void *) &e)) {
479 zval *cpy = php_http_ztyp(IS_LONG, *e);
480 url(buf)->port = (unsigned short) Z_LVAL_P(cpy);
481 zval_ptr_dtor(&cpy);
482 }
483 if (SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &e)) {
484 zval *cpy = php_http_ztyp(IS_STRING, *e);
485 url(buf)->path = &buf.data[buf.used];
486 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
487 zval_ptr_dtor(&cpy);
488 }
489 if (SUCCESS == zend_hash_find(ht, "query", sizeof("query"), (void *) &e)) {
490 zval *cpy = php_http_ztyp(IS_STRING, *e);
491 url(buf)->query = &buf.data[buf.used];
492 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
493 zval_ptr_dtor(&cpy);
494 }
495 if (SUCCESS == zend_hash_find(ht, "fragment", sizeof("fragment"), (void *) &e)) {
496 zval *cpy = php_http_ztyp(IS_STRING, *e);
497 url(buf)->fragment = &buf.data[buf.used];
498 url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
499 zval_ptr_dtor(&cpy);
500 }
501
502 return url(buf);
503 }
504
505 HashTable *php_http_url_to_struct(const php_http_url_t *url, zval *strct TSRMLS_DC)
506 {
507 zval arr;
508
509 if (strct) {
510 switch (Z_TYPE_P(strct)) {
511 default:
512 zval_dtor(strct);
513 array_init(strct);
514 /* no break */
515 case IS_ARRAY:
516 case IS_OBJECT:
517 INIT_PZVAL_ARRAY((&arr), HASH_OF(strct));
518 break;
519 }
520 } else {
521 INIT_PZVAL(&arr);
522 array_init(&arr);
523 }
524
525 if (url) {
526 if (url->scheme) {
527 add_assoc_string(&arr, "scheme", url->scheme, 1);
528 }
529 if (url->user) {
530 add_assoc_string(&arr, "user", url->user, 1);
531 }
532 if (url->pass) {
533 add_assoc_string(&arr, "pass", url->pass, 1);
534 }
535 if (url->host) {
536 add_assoc_string(&arr, "host", url->host, 1);
537 }
538 if (url->port) {
539 add_assoc_long(&arr, "port", (long) url->port);
540 }
541 if (url->path) {
542 add_assoc_string(&arr, "path", url->path, 1);
543 }
544 if (url->query) {
545 add_assoc_string(&arr, "query", url->query, 1);
546 }
547 if (url->fragment) {
548 add_assoc_string(&arr, "fragment", url->fragment, 1);
549 }
550 }
551
552 return Z_ARRVAL(arr);
553 }
554
555 ZEND_RESULT_CODE 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)
556 {
557 const char *arg_sep_str = "&";
558 size_t arg_sep_len = 1;
559 php_http_buffer_t *qstr = php_http_buffer_new();
560
561 php_http_url_argsep(&arg_sep_str, &arg_sep_len TSRMLS_CC);
562
563 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)) {
564 php_http_buffer_free(&qstr);
565 return FAILURE;
566 }
567
568 php_http_buffer_data(qstr, encoded_str, encoded_len);
569 php_http_buffer_free(&qstr);
570
571 return SUCCESS;
572 }
573
574 ZEND_RESULT_CODE 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)
575 {
576 if (pre_encoded_len && pre_encoded_str) {
577 php_http_buffer_append(qstr, pre_encoded_str, pre_encoded_len);
578 }
579
580 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)) {
581 return FAILURE;
582 }
583
584 return SUCCESS;
585 }
586
587 struct parse_state {
588 php_http_url_t url;
589 #ifdef ZTS
590 void ***ts;
591 #endif
592 const char *ptr;
593 const char *end;
594 size_t maxlen;
595 off_t offset;
596 unsigned flags;
597 char buffer[1]; /* last member */
598 };
599
600 void php_http_url_free(php_http_url_t **url)
601 {
602 if (*url) {
603 efree(*url);
604 *url = NULL;
605 }
606 }
607
608 php_http_url_t *php_http_url_copy(const php_http_url_t *url, zend_bool persistent)
609 {
610 php_http_url_t *cpy;
611 const char *end = NULL, *url_ptr = (const char *) url;
612 char *cpy_ptr;
613
614 end = MAX(url->scheme, end);
615 end = MAX(url->pass, end);
616 end = MAX(url->user, end);
617 end = MAX(url->host, end);
618 end = MAX(url->path, end);
619 end = MAX(url->query, end);
620 end = MAX(url->fragment, end);
621
622 if (end) {
623 end += strlen(end) + 1;
624 cpy_ptr = pecalloc(1, end - url_ptr, persistent);
625 cpy = (php_http_url_t *) cpy_ptr;
626
627 memcpy(cpy_ptr + sizeof(*cpy), url_ptr + sizeof(*url), end - url_ptr - sizeof(*url));
628
629 cpy->scheme = url->scheme ? cpy_ptr + (url->scheme - url_ptr) : NULL;
630 cpy->pass = url->pass ? cpy_ptr + (url->pass - url_ptr) : NULL;
631 cpy->user = url->user ? cpy_ptr + (url->user - url_ptr) : NULL;
632 cpy->host = url->host ? cpy_ptr + (url->host - url_ptr) : NULL;
633 cpy->path = url->path ? cpy_ptr + (url->path - url_ptr) : NULL;
634 cpy->query = url->query ? cpy_ptr + (url->query - url_ptr) : NULL;
635 cpy->fragment = url->fragment ? cpy_ptr + (url->fragment - url_ptr) : NULL;
636 } else {
637 cpy = ecalloc(1, sizeof(*url));
638 }
639
640 cpy->port = url->port;
641
642 return cpy;
643 }
644
645 static size_t parse_mb_utf8(unsigned *wc, const char *ptr, const char *end)
646 {
647 unsigned wchar;
648 size_t consumed = utf8towc(&wchar, (const unsigned char *) ptr, end - ptr);
649
650 if (!consumed || consumed == (size_t) -1) {
651 return 0;
652 }
653
654 if (wc) {
655 *wc = wchar;
656 }
657 return consumed;
658 }
659
660 #ifdef PHP_HTTP_HAVE_WCHAR
661 static size_t parse_mb_loc(unsigned *wc, const char *ptr, const char *end)
662 {
663 wchar_t wchar;
664 size_t consumed = 0;
665 #if defined(HAVE_MBRTOWC)
666 mbstate_t ps;
667
668 memset(&ps, 0, sizeof(ps));
669 consumed = mbrtowc(&wchar, ptr, end - ptr, &ps);
670 #elif defined(HAVE_MBTOWC)
671 consumed = mbtowc(&wchar, ptr, end - ptr);
672 #endif
673
674 if (!consumed || consumed == (size_t) -1) {
675 return 0;
676 }
677
678 if (wc) {
679 *wc = wchar;
680 }
681 return consumed;
682 }
683 #endif
684
685 typedef enum parse_mb_what {
686 PARSE_SCHEME,
687 PARSE_USERINFO,
688 PARSE_HOSTINFO,
689 PARSE_PATH,
690 PARSE_QUERY,
691 PARSE_FRAGMENT
692 } parse_mb_what_t;
693
694 static const char * const parse_what[] = {
695 "scheme",
696 "userinfo",
697 "hostinfo",
698 "path",
699 "query",
700 "fragment"
701 };
702
703 static const char parse_xdigits[] = "0123456789ABCDEF";
704
705 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)
706 {
707 unsigned wchar;
708 size_t consumed = 0;
709
710 if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
711 consumed = parse_mb_utf8(&wchar, ptr, end);
712 }
713 #ifdef PHP_HTTP_HAVE_WCHAR
714 else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
715 consumed = parse_mb_loc(&wchar, ptr, end);
716 }
717 #endif
718
719 while (consumed) {
720 if (!(state->flags & PHP_HTTP_URL_PARSE_TOPCT) || what == PARSE_HOSTINFO || what == PARSE_SCHEME) {
721 if (what == PARSE_HOSTINFO && (state->flags & PHP_HTTP_URL_PARSE_TOIDN)) {
722 /* idna */
723 } else if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
724 if (!isualnum(wchar)) {
725 break;
726 }
727 #ifdef PHP_HTTP_HAVE_WCHAR
728 } else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
729 if (!iswalnum(wchar)) {
730 break;
731 }
732 #endif
733 }
734 PHP_HTTP_DUFF(consumed, state->buffer[state->offset++] = *ptr++);
735 } else {
736 int i = 0;
737
738 PHP_HTTP_DUFF(consumed,
739 state->buffer[state->offset++] = '%';
740 state->buffer[state->offset++] = parse_xdigits[((unsigned char) ptr[i]) >> 4];
741 state->buffer[state->offset++] = parse_xdigits[((unsigned char) ptr[i]) & 0xf];
742 ++i;
743 );
744 }
745
746 return consumed;
747 }
748
749 if (!silent) {
750 TSRMLS_FETCH_FROM_CTX(state->ts);
751 if (consumed) {
752 php_error_docref(NULL TSRMLS_CC, E_WARNING,
753 "Failed to parse %s; unexpected multibyte sequence 0x%x at pos %u in '%s'",
754 parse_what[what], wchar, (unsigned) (ptr - begin), begin);
755 } else {
756 php_error_docref(NULL TSRMLS_CC, E_WARNING,
757 "Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
758 parse_what[what], (unsigned char) *ptr, (unsigned) (ptr - begin), begin);
759 }
760 }
761
762 return 0;
763 }
764
765 static ZEND_RESULT_CODE parse_userinfo(struct parse_state *state, const char *ptr)
766 {
767 size_t mb;
768 const char *password = NULL, *end = state->ptr, *tmp = ptr;
769 TSRMLS_FETCH_FROM_CTX(state->ts);
770
771 state->url.user = &state->buffer[state->offset];
772
773 do {
774 switch (*ptr) {
775 case ':':
776 if (password) {
777 php_error_docref(NULL TSRMLS_CC, E_WARNING,
778 "Failed to parse password; duplicate ':' at pos %u in '%s'",
779 (unsigned) (ptr - tmp), tmp);
780 return FAILURE;
781 }
782 password = ptr + 1;
783 state->buffer[state->offset++] = 0;
784 state->url.pass = &state->buffer[state->offset];
785 break;
786
787 case '%':
788 if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
789 php_error_docref(NULL TSRMLS_CC, E_WARNING,
790 "Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
791 (unsigned) (ptr - tmp), tmp);
792 return FAILURE;
793 }
794 state->buffer[state->offset++] = *ptr++;
795 state->buffer[state->offset++] = *ptr++;
796 state->buffer[state->offset++] = *ptr;
797 break;
798
799 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
800 case '+': case ',': case ';': case '=': /* sub-delims */
801 case '-': case '.': case '_': case '~': /* unreserved */
802 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
803 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
804 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
805 case 'V': case 'W': case 'X': case 'Y': case 'Z':
806 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
807 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
808 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
809 case 'v': case 'w': case 'x': case 'y': case 'z':
810 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
811 case '7': case '8': case '9':
812 /* allowed */
813 state->buffer[state->offset++] = *ptr;
814 break;
815
816 default:
817 if (!(mb = parse_mb(state, PARSE_USERINFO, ptr, end, tmp, 0))) {
818 return FAILURE;
819 }
820 ptr += mb - 1;
821 }
822 } while(++ptr != end);
823
824
825 state->buffer[state->offset++] = 0;
826
827 return SUCCESS;
828 }
829
830 #if defined(PHP_WIN32) || defined(HAVE_UIDNA_IDNTOASCII)
831 typedef size_t (*parse_mb_func)(unsigned *wc, const char *ptr, const char *end);
832 static ZEND_RESULT_CODE to_utf16(parse_mb_func fn, const char *u8, uint16_t **u16, size_t *len TSRMLS_DC)
833 {
834 size_t offset = 0, u8_len = strlen(u8);
835
836 *u16 = ecalloc(4 * sizeof(uint16_t), u8_len + 1);
837 *len = 0;
838
839 while (offset < u8_len) {
840 unsigned wc;
841 uint16_t buf[2], *ptr = buf;
842 size_t consumed = fn(&wc, &u8[offset], &u8[u8_len]);
843
844 if (!consumed) {
845 efree(*u16);
846 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse UTF-8 at pos %zu of '%s'", offset, u8);
847 return FAILURE;
848 } else {
849 offset += consumed;
850 }
851
852 switch (wctoutf16(buf, wc)) {
853 case 2:
854 (*u16)[(*len)++] = *ptr++;
855 /* no break */
856 case 1:
857 (*u16)[(*len)++] = *ptr++;
858 break;
859 case 0:
860 default:
861 efree(*u16);
862 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert UTF-32 'U+%X' to UTF-16", wc);
863 return FAILURE;
864 }
865 }
866
867 return SUCCESS;
868 }
869 #endif
870
871 #ifndef MAXHOSTNAMELEN
872 # define MAXHOSTNAMELEN 256
873 #endif
874
875 #if PHP_HTTP_HAVE_IDN2
876 static ZEND_RESULT_CODE parse_idn2(struct parse_state *state, size_t prev_len)
877 {
878 char *idn = NULL;
879 int rv = -1;
880 TSRMLS_FETCH_FROM_CTX(state->ts);
881
882 if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
883 rv = idn2_lookup_u8((const unsigned char *) state->url.host, (unsigned char **) &idn, IDN2_NFC_INPUT);
884 }
885 # ifdef PHP_HTTP_HAVE_WCHAR
886 else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
887 rv = idn2_lookup_ul(state->url.host, &idn, 0);
888 }
889 # endif
890 if (rv != IDN2_OK) {
891 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
892 return FAILURE;
893 } else {
894 size_t idnlen = strlen(idn);
895 memcpy(state->url.host, idn, idnlen + 1);
896 free(idn);
897 state->offset += idnlen - prev_len;
898 return SUCCESS;
899 }
900 }
901 #elif PHP_HTTP_HAVE_IDN
902 static ZEND_RESULT_CODE parse_idn(struct parse_state *state, size_t prev_len)
903 {
904 char *idn = NULL;
905 int rv = -1;
906 TSRMLS_FETCH_FROM_CTX(state->ts);
907
908 if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
909 rv = idna_to_ascii_8z(state->url.host, &idn, IDNA_ALLOW_UNASSIGNED|IDNA_USE_STD3_ASCII_RULES);
910 }
911 # ifdef PHP_HTTP_HAVE_WCHAR
912 else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
913 rv = idna_to_ascii_lz(state->url.host, &idn, IDNA_ALLOW_UNASSIGNED|IDNA_USE_STD3_ASCII_RULES);
914 }
915 # endif
916 if (rv != IDNA_SUCCESS) {
917 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
918 return FAILURE;
919 } else {
920 size_t idnlen = strlen(idn);
921 memcpy(state->url.host, idn, idnlen + 1);
922 free(idn);
923 state->offset += idnlen - prev_len;
924 return SUCCESS;
925 }
926 }
927 #endif
928
929 #ifdef HAVE_UIDNA_IDNTOASCII
930 # if HAVE_UNICODE_UIDNA_H
931 # include <unicode/uidna.h>
932 # else
933 typedef uint16_t UChar;
934 typedef enum { U_ZERO_ERROR = 0 } UErrorCode;
935 int32_t uidna_IDNToASCII(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, int32_t options, void *parseError, UErrorCode *status);
936 # endif
937 static ZEND_RESULT_CODE parse_uidn(struct parse_state *state)
938 {
939 char *host_ptr;
940 uint16_t *uhost_str, ahost_str[MAXHOSTNAMELEN], *ahost_ptr;
941 size_t uhost_len, ahost_len;
942 UErrorCode error = U_ZERO_ERROR;
943 TSRMLS_FETCH_FROM_CTX(state->ts);
944
945 if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
946 if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len TSRMLS_CC)) {
947 return FAILURE;
948 }
949 #ifdef PHP_HTTP_HAVE_WCHAR
950 } else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
951 if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len TSRMLS_CC)) {
952 return FAILURE;
953 }
954 #endif
955 } else {
956 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; codepage not specified");
957 return FAILURE;
958 }
959
960 ahost_len = uidna_IDNToASCII(uhost_str, uhost_len, ahost_str, MAXHOSTNAMELEN, 3, NULL, &error);
961 efree(uhost_str);
962
963 if (error != U_ZERO_ERROR) {
964 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; ICU error %d", error);
965 return FAILURE;
966 }
967
968 host_ptr = state->url.host;
969 ahost_ptr = ahost_str;
970 PHP_HTTP_DUFF(ahost_len, *host_ptr++ = *ahost_ptr++);
971
972 *host_ptr = '\0';
973 state->offset += host_ptr - state->url.host;
974
975 return SUCCESS;
976 }
977 #endif
978
979 #if 0 && defined(PHP_WIN32)
980 static ZEND_RESULT_CODE parse_widn(struct parse_state *state)
981 {
982 char *host_ptr;
983 uint16_t *uhost_str, ahost_str[MAXHOSTNAMELEN], *ahost_ptr;
984 size_t uhost_len;
985 TSRMLS_FETCH_FROM_CTX(state->ts);
986
987 if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
988 if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len)) {
989 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
990 return FAILURE;
991 }
992 #ifdef PHP_HTTP_HAVE_WCHAR
993 } else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
994 if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len)) {
995 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
996 return FAILURE;
997 }
998 #endif
999 } else {
1000 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
1001 return FAILURE;
1002 }
1003
1004 if (!IdnToAscii(IDN_ALLOW_UNASSIGNED|IDN_USE_STD3_ASCII_RULES, uhost_str, uhost_len, ahost_str, MAXHOSTNAMELEN)) {
1005 efree(uhost_str);
1006 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
1007 return FAILURE;
1008 }
1009
1010 efree(uhost_str);
1011 host_ptr = state->url.host;
1012 ahost_ptr = ahost_str;
1013 PHP_HTTP_DUFF(wcslen(ahost_str), *host_ptr++ = *ahost_ptr++);
1014 efree(ahost_str);
1015
1016 *host_ptr = '\0';
1017 state->offset += host_ptr - state->url.host;
1018
1019 return SUCCESS;
1020 }
1021 #endif
1022
1023 #ifdef HAVE_INET_PTON
1024 static const char *parse_ip6(struct parse_state *state, const char *ptr)
1025 {
1026 const char *error = NULL, *end = state->ptr, *tmp = memchr(ptr, ']', end - ptr);
1027 TSRMLS_FETCH_FROM_CTX(state->ts);
1028
1029 if (tmp) {
1030 size_t addrlen = tmp - ptr + 1;
1031 char buf[16], *addr = estrndup(ptr + 1, addrlen - 2);
1032 int rv = inet_pton(AF_INET6, addr, buf);
1033
1034 if (rv == 1) {
1035 state->buffer[state->offset] = '[';
1036 state->url.host = &state->buffer[state->offset];
1037 inet_ntop(AF_INET6, buf, state->url.host + 1, state->maxlen - state->offset);
1038 state->offset += strlen(state->url.host);
1039 state->buffer[state->offset++] = ']';
1040 state->buffer[state->offset++] = 0;
1041 ptr = tmp + 1;
1042 } else if (rv == -1) {
1043 error = strerror(errno);
1044 } else {
1045 error = "unexpected '['";
1046 }
1047 efree(addr);
1048 } else {
1049 error = "expected ']'";
1050 }
1051
1052 if (error) {
1053 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse hostinfo; %s", error);
1054 return NULL;
1055 }
1056
1057 return ptr;
1058 }
1059 #endif
1060
1061 static ZEND_RESULT_CODE parse_hostinfo(struct parse_state *state, const char *ptr)
1062 {
1063 size_t mb, len;
1064 const char *end = state->ptr, *tmp = ptr, *port = NULL, *label = NULL;
1065 TSRMLS_FETCH_FROM_CTX(state->ts);
1066
1067 #ifdef HAVE_INET_PTON
1068 if (*ptr == '[' && !(ptr = parse_ip6(state, ptr))) {
1069 return FAILURE;
1070 }
1071 #endif
1072
1073 if (ptr != end) do {
1074 switch (*ptr) {
1075 case ':':
1076 if (port) {
1077 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1078 "Failed to parse port; unexpected ':' at pos %u in '%s'",
1079 (unsigned) (ptr - tmp), tmp);
1080 return FAILURE;
1081 }
1082 port = ptr + 1;
1083 break;
1084
1085 case '%':
1086 if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
1087 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1088 "Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
1089 (unsigned) (ptr - tmp), tmp);
1090 return FAILURE;
1091 }
1092 state->buffer[state->offset++] = *ptr++;
1093 state->buffer[state->offset++] = *ptr++;
1094 state->buffer[state->offset++] = *ptr;
1095 break;
1096
1097 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1098 case '+': case ',': case ';': case '=': /* sub-delims */
1099 case '-': case '.': case '_': case '~': /* unreserved */
1100 if (port || !label) {
1101 /* sort of a compromise, just ensure we don't end up
1102 * with a dot at the beginning or two consecutive dots
1103 */
1104 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1105 "Failed to parse %s; unexpected '%c' at pos %u in '%s'",
1106 port ? "port" : "host",
1107 (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
1108 return FAILURE;
1109 }
1110 state->buffer[state->offset++] = *ptr;
1111 label = NULL;
1112 break;
1113
1114 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1115 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1116 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1117 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1118 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1119 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1120 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1121 case 'v': case 'w': case 'x': case 'y': case 'z':
1122 if (port) {
1123 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1124 "Failed to parse port; unexpected char '%c' at pos %u in '%s'",
1125 (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
1126 return FAILURE;
1127 }
1128 /* no break */
1129 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1130 case '7': case '8': case '9':
1131 /* allowed */
1132 if (port) {
1133 state->url.port *= 10;
1134 state->url.port += *ptr - '0';
1135 } else {
1136 label = ptr;
1137 state->buffer[state->offset++] = *ptr;
1138 }
1139 break;
1140
1141 default:
1142 if (ptr == end) {
1143 break;
1144 } else if (port) {
1145 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1146 "Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
1147 (unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
1148 return FAILURE;
1149 } else if (!(mb = parse_mb(state, PARSE_HOSTINFO, ptr, end, tmp, 0))) {
1150 return FAILURE;
1151 }
1152 label = ptr;
1153 ptr += mb - 1;
1154 }
1155 } while (++ptr != end);
1156
1157 if (!state->url.host) {
1158 len = (port ? port - tmp - 1 : end - tmp);
1159 state->url.host = &state->buffer[state->offset - len];
1160 state->buffer[state->offset++] = 0;
1161 }
1162
1163 if (state->flags & PHP_HTTP_URL_PARSE_TOIDN) {
1164 #if PHP_HTTP_HAVE_IDN2
1165 return parse_idn2(state, len);
1166 #elif PHP_HTTP_HAVE_IDN
1167 return parse_idn(state, len);
1168 #endif
1169 #ifdef HAVE_UIDNA_IDNTOASCII
1170 return parse_uidn(state);
1171 #endif
1172 #if 0 && defined(PHP_WIN32)
1173 return parse_widn(state);
1174 #endif
1175 }
1176
1177 return SUCCESS;
1178 }
1179
1180 static const char *parse_authority(struct parse_state *state)
1181 {
1182 const char *tmp = state->ptr, *host = NULL;
1183
1184 do {
1185 switch (*state->ptr) {
1186 case '@':
1187 /* userinfo delimiter */
1188 if (host) {
1189 TSRMLS_FETCH_FROM_CTX(state->ts);
1190 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1191 "Failed to parse userinfo; unexpected '@'");
1192 return NULL;
1193 }
1194 host = state->ptr + 1;
1195 if (tmp != state->ptr && SUCCESS != parse_userinfo(state, tmp)) {
1196 return NULL;
1197 }
1198 tmp = state->ptr + 1;
1199 break;
1200
1201 case '/':
1202 case '?':
1203 case '#':
1204 case '\0':
1205 EOD:
1206 /* host delimiter */
1207 if (tmp != state->ptr && SUCCESS != parse_hostinfo(state, tmp)) {
1208 return NULL;
1209 }
1210 return state->ptr;
1211 }
1212 } while (++state->ptr <= state->end);
1213
1214 --state->ptr;
1215 goto EOD;
1216 }
1217
1218 static const char *parse_path(struct parse_state *state)
1219 {
1220 size_t mb;
1221 const char *tmp;
1222 TSRMLS_FETCH_FROM_CTX(state->ts);
1223
1224 /* is there actually a path to parse? */
1225 if (!*state->ptr) {
1226 return state->ptr;
1227 }
1228 tmp = state->ptr;
1229 state->url.path = &state->buffer[state->offset];
1230
1231 do {
1232 switch (*state->ptr) {
1233 case '#':
1234 case '?':
1235 goto done;
1236
1237 case '%':
1238 if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
1239 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1240 "Failed to parse path; invalid percent encoding at pos %u in '%s'",
1241 (unsigned) (state->ptr - tmp), tmp);
1242 return NULL;
1243 }
1244 state->buffer[state->offset++] = *state->ptr++;
1245 state->buffer[state->offset++] = *state->ptr++;
1246 state->buffer[state->offset++] = *state->ptr;
1247 break;
1248
1249 case '/': /* yeah, well */
1250 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1251 case '+': case ',': case ';': case '=': /* sub-delims */
1252 case '-': case '.': case '_': case '~': /* unreserved */
1253 case ':': case '@': /* pchar */
1254 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1255 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1256 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1257 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1258 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1259 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1260 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1261 case 'v': case 'w': case 'x': case 'y': case 'z':
1262 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1263 case '7': case '8': case '9':
1264 /* allowed */
1265 state->buffer[state->offset++] = *state->ptr;
1266 break;
1267
1268 default:
1269 if (!(mb = parse_mb(state, PARSE_PATH, state->ptr, state->end, tmp, 0))) {
1270 return NULL;
1271 }
1272 state->ptr += mb - 1;
1273 }
1274 } while (++state->ptr < state->end);
1275
1276 done:
1277 /* did we have any path component ? */
1278 if (tmp != state->ptr) {
1279 state->buffer[state->offset++] = 0;
1280 } else {
1281 state->url.path = NULL;
1282 }
1283 return state->ptr;
1284 }
1285
1286 static const char *parse_query(struct parse_state *state)
1287 {
1288 size_t mb;
1289 const char *tmp = state->ptr + !!*state->ptr;
1290 TSRMLS_FETCH_FROM_CTX(state->ts);
1291
1292 /* is there actually a query to parse? */
1293 if (*state->ptr != '?') {
1294 return state->ptr;
1295 }
1296
1297 /* skip initial '?' */
1298 tmp = ++state->ptr;
1299 state->url.query = &state->buffer[state->offset];
1300
1301 while (state->ptr < state->end) {
1302 switch (*state->ptr) {
1303 case '#':
1304 goto done;
1305
1306 case '%':
1307 if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
1308 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1309 "Failed to parse query; invalid percent encoding at pos %u in '%s'",
1310 (unsigned) (state->ptr - tmp), tmp);
1311 return NULL;
1312 }
1313 state->buffer[state->offset++] = *state->ptr++;
1314 state->buffer[state->offset++] = *state->ptr++;
1315 state->buffer[state->offset++] = *state->ptr;
1316 break;
1317
1318 /* RFC1738 unsafe */
1319 case '{': case '}':
1320 case '<': case '>':
1321 case '[': case ']':
1322 case '|': case '\\': case '^': case '`': case '"': case ' ':
1323 if (state->flags & PHP_HTTP_URL_PARSE_TOPCT) {
1324 state->buffer[state->offset++] = '%';
1325 state->buffer[state->offset++] = parse_xdigits[((unsigned char) *state->ptr) >> 4];
1326 state->buffer[state->offset++] = parse_xdigits[((unsigned char) *state->ptr) & 0xf];
1327 break;
1328 }
1329 /* no break */
1330
1331 case '?': case '/': /* yeah, well */
1332 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1333 case '+': case ',': case ';': case '=': /* sub-delims */
1334 case '-': case '.': case '_': case '~': /* unreserved */
1335 case ':': case '@': /* pchar */
1336 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1337 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1338 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1339 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1340 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1341 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1342 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1343 case 'v': case 'w': case 'x': case 'y': case 'z':
1344 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1345 case '7': case '8': case '9':
1346 /* allowed */
1347 state->buffer[state->offset++] = *state->ptr;
1348 break;
1349
1350 default:
1351 if (!(mb = parse_mb(state, PARSE_QUERY, state->ptr, state->end, tmp, 0))) {
1352 return NULL;
1353 }
1354 state->ptr += mb - 1;
1355 }
1356
1357 ++state->ptr;
1358 }
1359
1360 done:
1361 state->buffer[state->offset++] = 0;
1362 return state->ptr;
1363 }
1364
1365 static const char *parse_fragment(struct parse_state *state)
1366 {
1367 size_t mb;
1368 const char *tmp;
1369 TSRMLS_FETCH_FROM_CTX(state->ts);
1370
1371 /* is there actually a fragment to parse? */
1372 if (*state->ptr != '#') {
1373 return state->ptr;
1374 }
1375
1376 /* skip initial '#' */
1377 tmp = ++state->ptr;
1378 state->url.fragment = &state->buffer[state->offset];
1379
1380 do {
1381 switch (*state->ptr) {
1382 case '%':
1383 if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
1384 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1385 "Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
1386 (unsigned) (state->ptr - tmp), tmp);
1387 return NULL;
1388 }
1389 state->buffer[state->offset++] = *state->ptr++;
1390 state->buffer[state->offset++] = *state->ptr++;
1391 state->buffer[state->offset++] = *state->ptr;
1392 break;
1393
1394 /* RFC1738 unsafe */
1395 case '{': case '}':
1396 case '<': case '>':
1397 case '[': case ']':
1398 case '|': case '\\': case '^': case '`': case '"': case ' ':
1399 if (state->flags & PHP_HTTP_URL_PARSE_TOPCT) {
1400 state->buffer[state->offset++] = '%';
1401 state->buffer[state->offset++] = parse_xdigits[((unsigned char) *state->ptr) >> 4];
1402 state->buffer[state->offset++] = parse_xdigits[((unsigned char) *state->ptr) & 0xf];
1403 break;
1404 }
1405 /* no break */
1406
1407 case '?': case '/':
1408 case '!': case '$': case '&': case '\'': case '(': case ')': case '*':
1409 case '+': case ',': case ';': case '=': /* sub-delims */
1410 case '-': case '.': case '_': case '~': /* unreserved */
1411 case ':': case '@': /* pchar */
1412 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1413 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1414 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1415 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1416 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1417 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1418 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1419 case 'v': case 'w': case 'x': case 'y': case 'z':
1420 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1421 case '7': case '8': case '9':
1422 /* allowed */
1423 state->buffer[state->offset++] = *state->ptr;
1424 break;
1425
1426 default:
1427 if (!(mb = parse_mb(state, PARSE_FRAGMENT, state->ptr, state->end, tmp, 0))) {
1428 return NULL;
1429 }
1430 state->ptr += mb - 1;
1431 }
1432 } while (++state->ptr < state->end);
1433
1434 state->buffer[state->offset++] = 0;
1435 return state->ptr;
1436 }
1437
1438 static const char *parse_hier(struct parse_state *state)
1439 {
1440 if (*state->ptr == '/') {
1441 if (state->end - state->ptr > 1) {
1442 if (*(state->ptr + 1) == '/') {
1443 state->ptr += 2;
1444 if (!(state->ptr = parse_authority(state))) {
1445 return NULL;
1446 }
1447 }
1448 }
1449 }
1450 return parse_path(state);
1451 }
1452
1453 static const char *parse_scheme(struct parse_state *state)
1454 {
1455 size_t mb;
1456 const char *tmp = state->ptr;
1457
1458 do {
1459 switch (*state->ptr) {
1460 case ':':
1461 /* scheme delimiter */
1462 state->url.scheme = &state->buffer[0];
1463 state->buffer[state->offset++] = 0;
1464 return ++state->ptr;
1465
1466 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
1467 case '7': case '8': case '9':
1468 case '+': case '-': case '.':
1469 if (state->ptr == tmp) {
1470 return tmp;
1471 }
1472 /* no break */
1473 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1474 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1475 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1476 case 'V': case 'W': case 'X': case 'Y': case 'Z':
1477 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1478 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1479 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1480 case 'v': case 'w': case 'x': case 'y': case 'z':
1481 /* scheme part */
1482 state->buffer[state->offset++] = *state->ptr;
1483 break;
1484
1485 default:
1486 if (!(mb = parse_mb(state, PARSE_SCHEME, state->ptr, state->end, tmp, 1))) {
1487 /* soft fail; parse path next */
1488 return tmp;
1489 }
1490 state->ptr += mb - 1;
1491 }
1492 } while (++state->ptr != state->end);
1493
1494 return state->ptr = tmp;
1495 }
1496
1497 php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags TSRMLS_DC)
1498 {
1499 size_t maxlen = 3 * len;
1500 struct parse_state *state = ecalloc(1, sizeof(*state) + maxlen);
1501
1502 state->end = str + len;
1503 state->ptr = str;
1504 state->flags = flags;
1505 state->maxlen = maxlen;
1506 TSRMLS_SET_CTX(state->ts);
1507
1508 if (!parse_scheme(state)) {
1509 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL scheme: '%s'", state->ptr);
1510 efree(state);
1511 return NULL;
1512 }
1513
1514 if (!parse_hier(state)) {
1515 efree(state);
1516 return NULL;
1517 }
1518
1519 if (!parse_query(state)) {
1520 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL query: '%s'", state->ptr);
1521 efree(state);
1522 return NULL;
1523 }
1524
1525 if (!parse_fragment(state)) {
1526 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL fragment: '%s'", state->ptr);
1527 efree(state);
1528 return NULL;
1529 }
1530
1531 return (php_http_url_t *) state;
1532 }
1533
1534 php_http_url_t *php_http_url_parse_authority(const char *str, size_t len, unsigned flags TSRMLS_DC)
1535 {
1536 size_t maxlen = 3 * len;
1537 struct parse_state *state = ecalloc(1, sizeof(*state) + maxlen);
1538
1539 state->end = str + len;
1540 state->ptr = str;
1541 state->flags = flags;
1542 state->maxlen = maxlen;
1543 TSRMLS_SET_CTX(state->ts);
1544
1545 if (!(state->ptr = parse_authority(state))) {
1546 efree(state);
1547 return NULL;
1548 }
1549
1550 if (state->ptr != state->end) {
1551 php_error_docref(NULL TSRMLS_CC, E_WARNING,
1552 "Failed to parse URL authority, unexpected character at pos %u in '%s'",
1553 (unsigned) (state->ptr - str), str);
1554 efree(state);
1555 return NULL;
1556 }
1557
1558 return (php_http_url_t *) state;
1559 }
1560
1561 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct, 0, 0, 0)
1562 ZEND_ARG_INFO(0, old_url)
1563 ZEND_ARG_INFO(0, new_url)
1564 ZEND_ARG_INFO(0, flags)
1565 ZEND_END_ARG_INFO();
1566 PHP_METHOD(HttpUrl, __construct)
1567 {
1568 zval *new_url = NULL, *old_url = NULL;
1569 long flags = PHP_HTTP_URL_FROM_ENV;
1570 zend_error_handling zeh;
1571
1572 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
1573
1574 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1575 {
1576 php_http_url_t *res_purl, *new_purl = NULL, *old_purl = NULL;
1577
1578 if (new_url) {
1579 new_purl = php_http_url_from_zval(new_url, flags TSRMLS_CC);
1580 if (!new_purl) {
1581 zend_restore_error_handling(&zeh TSRMLS_CC);
1582 return;
1583 }
1584 }
1585 if (old_url) {
1586 old_purl = php_http_url_from_zval(old_url, flags TSRMLS_CC);
1587 if (!old_purl) {
1588 if (new_purl) {
1589 php_http_url_free(&new_purl);
1590 }
1591 zend_restore_error_handling(&zeh TSRMLS_CC);
1592 return;
1593 }
1594 }
1595
1596 res_purl = php_http_url_mod(old_purl, new_purl, flags TSRMLS_CC);
1597 php_http_url_to_struct(res_purl, getThis() TSRMLS_CC);
1598
1599 php_http_url_free(&res_purl);
1600 if (old_purl) {
1601 php_http_url_free(&old_purl);
1602 }
1603 if (new_purl) {
1604 php_http_url_free(&new_purl);
1605 }
1606 }
1607 zend_restore_error_handling(&zeh TSRMLS_CC);
1608 }
1609
1610 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod, 0, 0, 1)
1611 ZEND_ARG_INFO(0, more_url_parts)
1612 ZEND_ARG_INFO(0, flags)
1613 ZEND_END_ARG_INFO();
1614 PHP_METHOD(HttpUrl, mod)
1615 {
1616 zval *new_url = NULL;
1617 long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY | PHP_HTTP_URL_SANITIZE_PATH;
1618 zend_error_handling zeh;
1619
1620 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags), invalid_arg, return);
1621
1622 zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
1623 {
1624 php_http_url_t *new_purl = NULL, *old_purl = NULL;
1625
1626 if (new_url) {
1627 new_purl = php_http_url_from_zval(new_url, flags TSRMLS_CC);
1628 if (!new_purl) {
1629 zend_restore_error_handling(&zeh TSRMLS_CC);
1630 return;
1631 }
1632 }
1633
1634 if ((old_purl = php_http_url_from_struct(HASH_OF(getThis())))) {
1635 php_http_url_t *res_purl;
1636
1637 ZVAL_OBJVAL(return_value, zend_objects_clone_obj(getThis() TSRMLS_CC), 0);
1638
1639 res_purl = php_http_url_mod(old_purl, new_purl, flags TSRMLS_CC);
1640 php_http_url_to_struct(res_purl, return_value TSRMLS_CC);
1641
1642 php_http_url_free(&res_purl);
1643 php_http_url_free(&old_purl);
1644 }
1645 if (new_purl) {
1646 php_http_url_free(&new_purl);
1647 }
1648 }
1649 zend_restore_error_handling(&zeh TSRMLS_CC);
1650 }
1651
1652 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString, 0, 0, 0)
1653 ZEND_END_ARG_INFO();
1654 PHP_METHOD(HttpUrl, toString)
1655 {
1656 if (SUCCESS == zend_parse_parameters_none()) {
1657 php_http_url_t *purl;
1658
1659 if ((purl = php_http_url_from_struct(HASH_OF(getThis())))) {
1660 char *str;
1661 size_t len;
1662
1663 php_http_url_to_string(purl, &str, &len, 0);
1664 php_http_url_free(&purl);
1665 RETURN_STRINGL(str, len, 0);
1666 }
1667 }
1668 RETURN_EMPTY_STRING();
1669 }
1670
1671 ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray, 0, 0, 0)
1672 ZEND_END_ARG_INFO();
1673 PHP_METHOD(HttpUrl, toArray)
1674 {
1675 php_http_url_t *purl;
1676
1677 if (SUCCESS != zend_parse_parameters_none()) {
1678 return;
1679 }
1680
1681 /* strip any non-URL properties */
1682 purl = php_http_url_from_struct(HASH_OF(getThis()));
1683 php_http_url_to_struct(purl, return_value TSRMLS_CC);
1684 php_http_url_free(&purl);
1685 }
1686
1687 static zend_function_entry php_http_url_methods[] = {
1688 PHP_ME(HttpUrl, __construct, ai_HttpUrl___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
1689 PHP_ME(HttpUrl, mod, ai_HttpUrl_mod, ZEND_ACC_PUBLIC)
1690 PHP_ME(HttpUrl, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1691 ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC)
1692 PHP_ME(HttpUrl, toArray, ai_HttpUrl_toArray, ZEND_ACC_PUBLIC)
1693 EMPTY_FUNCTION_ENTRY
1694 };
1695
1696 zend_class_entry *php_http_url_class_entry;
1697
1698 PHP_MINIT_FUNCTION(http_url)
1699 {
1700 zend_class_entry ce = {0};
1701
1702 INIT_NS_CLASS_ENTRY(ce, "http", "Url", php_http_url_methods);
1703 php_http_url_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
1704
1705 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC);
1706 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
1707 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC);
1708 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC);
1709 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC);
1710 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC);
1711 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
1712 zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC);
1713
1714 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC);
1715 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC);
1716 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC);
1717 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC);
1718 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC);
1719 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC);
1720 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC);
1721 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC);
1722 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC);
1723 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC);
1724 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC);
1725 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
1726 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC);
1727
1728 #ifdef PHP_HTTP_HAVE_WCHAR
1729 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC);
1730 #endif
1731 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC);
1732 #if defined(PHP_HTTP_HAVE_IDN2) || defined(PHP_HTTP_HAVE_IDN) || defined(HAVE_UIDNA_IDNTOASCII)
1733 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC);
1734 #endif
1735 zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC);
1736
1737 return SUCCESS;
1738 }
1739
1740
1741 /*
1742 * Local variables:
1743 * tab-width: 4
1744 * c-basic-offset: 4
1745 * End:
1746 * vim600: noet sw=4 ts=4 fdm=marker
1747 * vim<600: noet sw=4 ts=4
1748 */
1749