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