Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/standard/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dnl $Id$ -*- autoconf -*-
dnl
dnl Check if flush should be called explicitly after buffered io
dnl
PHP_SETUP_ICU
AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io], ac_cv_flush_io,[
AC_TRY_RUN( [
#include <stdio.h>
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/ftp_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char
if (resource->port == 0)
resource->port = 21;

transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", resource->host, resource->port);
transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", resource->ascii_domain, resource->port);
stream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL);
efree(transport);
if (stream == NULL) {
Expand Down Expand Up @@ -552,7 +552,7 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa

/* open the data channel */
if (hoststart == NULL) {
hoststart = resource->host;
hoststart = resource->ascii_domain;
}
transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", hoststart, portno);
datastream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL);
Expand Down Expand Up @@ -719,7 +719,7 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat

/* open the data channel */
if (hoststart == NULL) {
hoststart = resource->host;
hoststart = resource->ascii_domain;
}
datastream = php_stream_sock_open_host(hoststart, portno, SOCK_STREAM, 0, 0);
if (datastream == NULL) {
Expand Down
14 changes: 7 additions & 7 deletions ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
transport_len = Z_STRLEN_P(tmpzval);
transport_string = estrndup(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval));
} else {
transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->host, resource->port);
transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->ascii_domain, resource->port);
}
}

Expand Down Expand Up @@ -240,12 +240,12 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,

/* Set peer_name or name verification will try to use the proxy server name */
if (!context || (tmpzval = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) {
ZVAL_STRING(&ssl_proxy_peer_name, resource->host);
ZVAL_STRING(&ssl_proxy_peer_name, resource->ascii_domain);
php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name);
}

smart_str_appendl(&header, "CONNECT ", sizeof("CONNECT ")-1);
smart_str_appends(&header, resource->host);
smart_str_appends(&header, resource->ascii_domain);
smart_str_appendc(&header, ':');
smart_str_append_unsigned(&header, resource->port);
smart_str_appendl(&header, " HTTP/1.0\r\n", sizeof(" HTTP/1.0\r\n")-1);
Expand Down Expand Up @@ -561,10 +561,10 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
if ((have_header & HTTP_HEADER_HOST) == 0) {
if ((use_ssl && resource->port != 443 && resource->port != 0) ||
(!use_ssl && resource->port != 80 && resource->port != 0)) {
if (snprintf(scratch, scratch_len, "Host: %s:%i\r\n", resource->host, resource->port) > 0)
if (snprintf(scratch, scratch_len, "Host: %s:%i\r\n", resource->ascii_domain, resource->port) > 0)
php_stream_write(stream, scratch, strlen(scratch));
} else {
if (snprintf(scratch, scratch_len, "Host: %s\r\n", resource->host) > 0) {
if (snprintf(scratch, scratch_len, "Host: %s\r\n", resource->ascii_domain) > 0) {
php_stream_write(stream, scratch, strlen(scratch));
}
}
Expand Down Expand Up @@ -836,9 +836,9 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
strlcpy(loc_path, location, sizeof(loc_path));
}
if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80)) {
snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", resource->scheme, resource->host, resource->port, loc_path);
snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", resource->scheme, resource->ascii_domain, resource->port, loc_path);
} else {
snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", resource->scheme, resource->host, loc_path);
snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", resource->scheme, resource->ascii_domain, loc_path);
}
} else {
strlcpy(new_path, location, sizeof(new_path));
Expand Down
13 changes: 13 additions & 0 deletions ext/standard/tests/http/idn.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
IDN support
--INI--
allow_url_fopen=1
--FILE--
<?php
$fd = fopen('http://académie-française.fr', 'rb');
$meta = stream_get_meta_data($fd);
var_dump($meta['wrapper_data'][0]);
fclose($fd);

--EXPECT--
string(15) "HTTP/1.1 200 OK"
26 changes: 25 additions & 1 deletion ext/standard/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Jim Winstead <jimw@php.net> |
| Authors: Jim Winstead <jimw@php.net> |
| Kévin Dunglas <dunglas@gmail.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
Expand All @@ -21,6 +22,7 @@
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <unicode/uidna.h>

#include "php.h"

Expand Down Expand Up @@ -51,6 +53,8 @@ PHPAPI void php_url_free(php_url *theurl)
efree(theurl->host);
if (theurl->path)
efree(theurl->path);
if (theurl->ascii_domain)
efree(theurl->ascii_domain);
if (theurl->query)
efree(theurl->query);
if (theurl->fragment)
Expand Down Expand Up @@ -99,6 +103,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
char port_buf[6];
php_url *ret = ecalloc(1, sizeof(php_url));
char const *s, *e, *p, *pp, *ue;
UErrorCode idn_error_code = U_ZERO_ERROR;
UIDNA *idn_uidna;
UIDNAInfo idn_uidna_info = UIDNA_INFO_INITIALIZER;
int32_t idn_domain_len;
int32_t idn_domain_capac = 255; /* no domain name may exceed this */

s = str;
ue = s + length;
Expand Down Expand Up @@ -307,6 +316,21 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)

ret->host = estrndup(s, (p-s));
php_replace_controlchars_ex(ret->host, (p - s));

/* convert IDN domain to ASCII */
idn_uidna = uidna_openUTS46(UIDNA_DEFAULT, &idn_error_code);
if (U_FAILURE(idn_error_code)) {
php_url_free(ret);
return NULL;
}

ret->ascii_domain = emalloc(idn_domain_capac);
idn_domain_len = uidna_nameToASCII_UTF8(idn_uidna, ret->host, p - s, ret->ascii_domain, idn_domain_capac, &idn_uidna_info, &idn_error_code);
if (U_FAILURE(idn_error_code) || idn_domain_len >= idn_domain_capac || idn_uidna_info.errors != 0) {
php_url_free(ret);
return NULL;
}
ret->ascii_domain[idn_domain_len] = '\0';

if (e == ue) {
return ret;
Expand Down
4 changes: 3 additions & 1 deletion ext/standard/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Jim Winstead <jimw@php.net> |
| Authors: Jim Winstead <jimw@php.net> |
| Kévin Dunglas <dunglas@gmail.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
Expand All @@ -25,6 +26,7 @@ typedef struct php_url {
char *user;
char *pass;
char *host;
char *ascii_domain;
unsigned short port;
char *path;
char *query;
Expand Down