flush
authorMichael Wallner <mike@php.net>
Mon, 26 Sep 2016 10:29:22 +0000 (12:29 +0200)
committerMichael Wallner <mike@php.net>
Tue, 4 Oct 2016 08:25:11 +0000 (10:25 +0200)
17 files changed:
config9.m4
scripts/gen_travis_yml.php
src/php_http.c
src/php_http_api.h
src/php_http_client.c
src/php_http_client_curl.c
src/php_http_client_curl.h
src/php_http_client_curl_event.c
src/php_http_client_curl_event.h
src/php_http_client_curl_user.c
src/php_http_client_curl_user.h
src/php_http_curl.c
src/php_http_curl.h
src/php_http_url.c
src/php_http_url.h
tests/urlparser006.phpt
tests/urlparser007.phpt

index 3c02edc..73290e6 100644 (file)
@@ -12,6 +12,10 @@ PHP_ARG_WITH([http-libevent-dir], [],
 [  --with-http-libevent-dir[=DIR] HTTP: where to find libevent], $PHP_HTTP_LIBCURL_DIR, "")
 PHP_ARG_WITH([http-libidn-dir], [],
 [  --with-http-libidn-dir[=DIR]   HTTP: where to find libidn], $PHP_HTTP_LIBCURL_DIR, "")
+PHP_ARG_WITH([http-libidn2-dir], [],
+[  --with-http-libidn-dir[=DIR]   HTTP: where to find libidn2], $PHP_HTTP_LIBCURL_DIR, "")
+PHP_ARG_WITH([http-libicu-dir], [],
+[  --with-http-libidn-dir[=DIR]   HTTP: where to find libicu], $PHP_HTTP_LIBCURL_DIR, "")
 
 if test "$PHP_HTTP" != "no"; then
 
@@ -32,6 +36,10 @@ if test "$PHP_HTTP" != "no"; then
                ])
        ])
 
+       if test -z "$PKG_CONFIG"; then
+               AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
+       fi
+
        AC_PROG_CPP
 
        if test "$PHP_HTTP_SHARED_DEPS" != "no"; then
@@ -93,6 +101,102 @@ if test "$PHP_HTTP" != "no"; then
                fi
        ])
 
+       dnl
+       dnl HTTP_HAVE_VERSION(name, min-version[, code-if-yes[, code-if-not]])
+       dnl
+       AC_DEFUN([HTTP_HAVE_VERSION], [
+               aversion=$(printf "%s" "$AS_TR_CPP([PHP_HTTP_]$1[_VERSION])" | $AWK '{print $[]1*1000000 + $[]2*10000 + $[]3*100 + $[]4}')
+               mversion=$(printf "%s" "$2" | $AWK '{print $[]1*1000000 + $[]2*10000 + $[]3*100 + $[]4}')
+               AC_MSG_CHECKING([whether $1 version $]AS_TR_CPP([PHP_HTTP_]$1[_VERSION])[ is at least $2])
+               if test "$aversion" -lt "$mversion"; then
+                       ifelse($4,,AC_MSG_ERROR([$1 minimum version $mversion required; got $aversion]), [
+                               AC_MSG_RESULT([no])
+                               $4
+                       ])
+               else
+                       AC_MSG_RESULT([ok])
+                       $3
+               fi
+       ])
+
+       dnl
+       dnl HTTP_CHECK_CUSTOM(name, path, header, lib, version)
+       dnl
+       AC_DEFUN([HTTP_CHECK_CUSTOM], [
+               save_CPPFLAGS=$CPPFLAGS
+               save_LDFLAGS=$LDFLAGS
+               save_LIBS=$LIBS
+
+               for path in $2 /usr/local /usr /opt; do
+                       if test "$path" = "" || test "$path" = "yes" || test "$path" = "no"; then
+                               continue
+                       fi
+                       AC_MSG_CHECKING([for $1 in $path])
+                       if test -f "$path/include/$3"; then
+                               CPPFLAGS="-I$path"
+                               LDFLAGS="-L$path"
+                               LIBS="-l$4"
+
+                               AS_TR_CPP([PHP_HTTP_][$1][_VERSION])=$5
+                               AC_MSG_RESULT([${AS_TR_CPP([PHP_HTTP_][$1][_VERSION]):-no}])
+                               AC_DEFINE_UNQUOTED(AS_TR_CPP([PHP_HTTP_][$1][_VERSION]), "$AS_TR_CPP([PHP_HTTP_][$1][_VERSION])", [ ])
+                               break
+                       fi
+                       AC_MSG_RESULT([no])
+               done
+       ])
+
+       dnl
+       dnl HTTP_CHECK_CONFIG(name, prog-config, version-flag, cppflags-flag, ldflags-flag, libs-flag)
+       dnl
+       AC_DEFUN([HTTP_CHECK_CONFIG], [
+               AC_MSG_CHECKING([for $1])
+
+               save_CPPFLAGS=$CPPFLAGS
+               save_LDFLAGS=$LDFLAGS
+               save_LIBS=$LIBS
+               AS_TR_CPP([PHP_HTTP_][$1][_VERSION])=$($2 $3)
+               CPPFLAGS=$($2 $4)
+               LDFLAGS=$($2 $5)
+               LIBS=$($2 $6)
+
+               AC_MSG_RESULT([${AS_TR_CPP([PHP_HTTP_][$1][_VERSION]):-no}])
+               AC_DEFINE_UNQUOTED(AS_TR_CPP([PHP_HTTP_][$1][_VERSION]), "$AS_TR_CPP([PHP_HTTP_][$1][_VERSION])", [ ])
+       ])
+
+       dnl
+       dnl HTTP_CHECK_PKGCONFIG(pkg[, pkg_config_path])
+       dnl
+       AC_DEFUN([HTTP_CHECK_PKGCONFIG], [
+               ifelse($2,,,PKG_CONFIG_PATH="$2/lib/pkgconfig:$PKG_CONFIG_PATH")
+               if $($PKG_CONFIG $1 --exists); then
+                       AS_TR_CPP([PHP_HTTP_HAVE_$1])=true
+                       HTTP_CHECK_CONFIG([$1], [$PKG_CONFIG $1], [--modversion], [--cflags-only-I], [--libs-only-L], [--libs-only-l])
+               else
+                       AS_TR_CPP([PHP_HTTP_HAVE_$1])=false
+               fi
+       ])
+
+       dnl
+       dnl HTTP_CHECK_DONE(name, success[, incline, libline])
+       AC_DEFUN([HTTP_CHECK_DONE], [
+               if $2; then
+                       incline=$CPPFLAGS
+                       libline="$LDFLAGS $LIBS"
+                       AC_DEFINE(AS_TR_CPP([PHP_HTTP_HAVE_$1]), [1], [ ])
+               else
+                       incline=$3
+                       libline=$4
+               fi
+
+               CPPFLAGS=$save_CPPFLAGS
+               LDFLAGS=$save_LDFLAGS
+               LIBS=$save_LIBS
+
+               PHP_EVAL_INCLINE([$incline])
+               PHP_EVAL_LIBLINE([$libline], HTTP_SHARED_LIBLINE)
+       ])
+
        dnl
        dnl HTTP_CURL_SSL_LIB_CHECK(ssllib[, code-if-yes[, code-if-not])
        dnl
@@ -140,370 +244,226 @@ dnl ----
 dnl IDN
 dnl ----
 
-       AC_MSG_CHECKING([for idna.h])
-       IDNA_DIR=
-       for i in "$PHP_HTTP_LIBIDN_DIR" "$IDN_DIR" /usr/local /usr /opt; do
-               if test -f "$i/include/idna.h"; then
-                       IDNA_DIR=$i
-                       break;
-               fi
-       done
-       if test "x$IDNA_DIR" != "x"; then
-               AC_MSG_RESULT([found in $IDNA_DIR])
-               AC_DEFINE([PHP_HTTP_HAVE_IDN], [1], [Have libidn support])
-               PHP_ADD_INCLUDE($IDNA_DIR/include)
-               PHP_ADD_LIBRARY_WITH_PATH(idn, $IDNA_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
-               AC_MSG_CHECKING([for libidn version])
-               IDNA_VER=$(pkg-config --version libidn 2>/dev/null || echo unknown)
-               AC_MSG_RESULT([$IDNA_VER])
-               AC_DEFINE_UNQUOTED([PHP_HTTP_LIBIDN_VERSION], "$IDNA_VER", [ ])
-       else
-               AC_MSG_RESULT([not found])
-               AC_MSG_CHECKING([for idn2.h])
-               IDNA_DIR=
-               for i in "$PHP_HTTP_LIBIDN_DIR" "$IDN_DIR" /usr/local /usr /opt; do
-                       if test -f "$i/include/idn2.h"; then
-                               IDNA_DIR=$i
-                               break;
-                       fi
-               done
-               if test "x$IDNA_DIR" != "x"; then
-                       AC_MSG_RESULT([found in $IDNA_DIR])
-                       AC_DEFINE([PHP_HTTP_HAVE_IDN2], [1], [Have libidn2 support])
-                       PHP_ADD_INCLUDE($IDNA_DIR/include)
-                       PHP_ADD_LIBRARY_WITH_PATH(idn2, $IDNA_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
-                       AC_MSG_CHECKING([for libidn2 version])
-                       IDNA_VER=`$EGREP "define IDN2_VERSION " $IDNA_DIR/include/idn2.h | $SED -e's/^.*VERSION //g' -e 's/[[^0-9\.]]//g'`
-                       AC_MSG_RESULT([$IDNA_VER])
-                       AC_DEFINE_UNQUOTED([PHP_HTTP_LIBIDN2_VERSION], "$IDNA_VER", [ ])
-               else
-                       AC_MSG_RESULT([not found])
-                       AC_CHECK_HEADERS([unicode/uidna.h])
-                       case $host_os in
-                       darwin*)
-                               PHP_CHECK_FUNC(uidna_IDNToASCII, icucore);;
-                       *)
-                               AC_PATH_PROG(ICU_CONFIG, icu-config, no, [$PATH:/usr/local/bin])
-                               if test ! -x "$ICU_CONFIG"; then
-                                       ICU_CONFIG="icu-config"
-                               fi
-                               AC_MSG_CHECKING([for uidna_IDNToASCII])
-                               if ! test -x "$ICU_CONFIG"; then
-                                       ICU_CONFIG=icu-config
-                               fi
-                               if $ICU_CONFIG --exists 2>/dev/null >&2; then
-                                       save_LIBS=$LIBS
-                                       LIBS=$($ICU_CONFIG --ldflags)
-                                       AC_TRY_RUN([
-                                               #include <unicode/uidna.h>
-                                               int main(int argc, char *argv[]) {
-                                                       return uidna_IDNToASCII(0, 0, 0, 0, 0, 0, 0);
-                                               }
-                                       ], [
-                                               AC_MSG_RESULT([yes])
-                                               AC_DEFINE([HAVE_UIDNA_IDNTOASCII], [1], [ ])
-                                               LIBS=$save_LIBS
-                                               PHP_EVAL_LIBLINE(`$ICU_CONFIG --ldflags`, HTTP_SHARED_LIBADD)
-                                       ], [
-                                               LIBS=$save_LIBS
-                                               AC_MSG_RESULT([no])
-                                       ])
-                               fi
-                               ;;
-                       esac
-               fi
+       HTTP_CHECK_PKGCONFIG(libidn, [$PHP_HTTP_LIBIDN_DIR])
+       if $PHP_HTTP_HAVE_LIBIDN; then
+               AC_DEFINE([PHP_HTTP_HAVE_IDNA2003], [1], [ ])
        fi
+       HTTP_CHECK_DONE(libidn, $PHP_HTTP_HAVE_LIBIDN)
+
+       HTTP_CHECK_CUSTOM(libidn2, "$PHP_HTTP_LIBIDN2_DIR", idn2.h, idn2,
+               [$($EGREP "define IDN2_VERSION " $path/include/idn2.h | $SED -e's/^.*VERSION //g' -e 's/@<:@^0-9\.@:>@//g')])
+       if test -n "$PHP_HTTP_LIBIDN2_VERSION"; then
+               AC_DEFINE([PHP_HTTP_HAVE_IDNA2008], [1], [ ])
+       fi
+       HTTP_CHECK_DONE(libidn2, test -n "$PHP_HTTP_LIBIDN2_VERSION")
+
+       case $host_os in
+       darwin*)
+               PHP_CHECK_FUNC(uidna_IDNToASCII, icucore)
+               ;;
+       *)
+               AC_PATH_PROG(ICU_CONFIG, icu-config, false, [$PHP_HTTP_LIBICU_DIR/bin:$PATH:/usr/local/bin])
+
+               HTTP_CHECK_CONFIG(libicu, [$ICU_CONFIG], [--version], [--cppflags], [--ldflags-searchpath], [--ldflags-libsonly])
+               AC_MSG_CHECKING([for uidna_IDNToASCII])
+               AC_TRY_LINK([
+                       #include <unicode/uidna.h>
+               ], [
+                       uidna_IDNToASCII(0, 0, 0, 0, 0, 0, 0);
+               ], [
+                       AC_MSG_RESULT([yes])
+                       PHP_HTTP_HAVE_ICU=true
+                       AC_DEFINE([PHP_HTTP_HAVE_IDNA2003], [1], [ ])
+                       AC_DEFINE([HAVE_UIDNA_IDNTOASCII], [1], [ ])
+               ], [
+                       AC_MSG_RESULT([no])
+               ])
+               AC_MSG_CHECKING([for uidna_nameToASCII_UTF8])
+               AC_TRY_LINK([
+                       #include <unicode/uidna.h>
+               ], [
+                       uidna_nameToASCII_UTF8(0, 0, 0, 0, 0, 0, 0);
+               ], [
+                       AC_MSG_RESULT([yes])
+                       PHP_HTTP_HAVE_ICU=true
+                       AC_DEFINE([PHP_HTTP_HAVE_IDNA2008], [1], [ ])
+                       AC_DEFINE([HAVE_UIDNA_NAMETOASCII_UTF8], [1], [ ])
+               ], [
+                       AC_MSG_RESULT([no])
+               ])
+               HTTP_CHECK_DONE(libicu, [$PHP_HTTP_HAVE_LIBICU])
+               ;;
+       esac
 
 dnl ----
 dnl ZLIB
 dnl ----
-       AC_MSG_CHECKING([for zlib.h])
-       ZLIB_DIR=
-       for i in "$PHP_HTTP_ZLIB_DIR" "$PHP_ZLIB_DIR" "$PHP_ZLIB" /usr/local /usr /opt; do
-               if test -f "$i/include/zlib.h"; then
-                       ZLIB_DIR=$i
-                       break;
-               fi
-       done
-       if test "x$ZLIB_DIR" = "x"; then
-               AC_MSG_RESULT([not found])
-               AC_MSG_ERROR([could not find zlib.h])
-       else
-               AC_MSG_RESULT([found in $ZLIB_DIR])
-               AC_MSG_CHECKING([for zlib version >= 1.2.0.4])
-               ZLIB_VERSION=`$EGREP "define ZLIB_VERSION" $ZLIB_DIR/include/zlib.h | $SED -e 's/[[^0-9\.]]//g'`
-               AC_MSG_RESULT([$ZLIB_VERSION])
-               if test `echo $ZLIB_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*1000000 + $2*10000 + $3*100 + $4}'` -lt 1020004; then
-                       AC_MSG_ERROR([zlib version greater or equal to 1.2.0.4 required])
-               else
-                       PHP_ADD_INCLUDE($ZLIB_DIR/include)
-                       PHP_ADD_LIBRARY_WITH_PATH(z, $ZLIB_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
-               fi
-       fi
+       HTTP_CHECK_CUSTOM(zlib, ["$PHP_HTTP_ZLIB_DIR" "$PHP_ZLIB_DIR" "$PHP_ZLIB"], zlib.h, z,
+               [$($EGREP "define ZLIB_VERSION" "$path/include/zlib.h" | $SED -e 's/@<:@^0-9\.@:>@//g')])
+       HTTP_HAVE_VERSION(zlib, 1.2.0.4)
+       HTTP_CHECK_DONE(zlib, test -n "$PHP_HTTP_ZLIB_VERSION")
 
 dnl ----
 dnl CURL
 dnl ----
 
-       if test "$PHP_HTTP_LIBCURL_DIR" = "no"; then
-               AC_DEFINE([PHP_HTTP_HAVE_CURL], [0], [ ])
-       else
-               AC_MSG_CHECKING([for curl/curl.h])
-               CURL_DIR=
-               for i in "$PHP_HTTP_LIBCURL_DIR" /usr/local /usr /opt; do
-                       if test -f "$i/include/curl/curl.h"; then
-                               CURL_DIR=$i
-                               break
-                       fi
-               done
-               if test "x$CURL_DIR" = "x"; then
-                       AC_MSG_RESULT([not found])
-               else
-                       AC_MSG_RESULT([found in $CURL_DIR])
+       AC_PATH_PROG([CURL_CONFIG], [curl-config], false, [$PHP_HTTP_LIBCURL_DIR/bin:$PATH:/usr/local/bin])
 
-                       AC_MSG_CHECKING([for curl-config])
-                       CURL_CONFIG=
-                       for i in "$CURL_DIR/bin/curl-config" "$CURL_DIR/curl-config" `which curl-config`; do
-                               if test -x "$i"; then
-                                       CURL_CONFIG=$i
-                                       break
-                               fi
-                       done
-                       if test "x$CURL_CONFIG" = "x"; then
-                               AC_MSG_RESULT([not found])
-                               AC_MSG_ERROR([could not find curl-config])
-                       else
-                               AC_MSG_RESULT([found: $CURL_CONFIG])
-                       fi
+       if $CURL_CONFIG --protocols | $EGREP -q HTTP; then
+               HTTP_CHECK_CONFIG(libcurl, $CURL_CONFIG,
+                       [--version | $SED -e 's/@<:@^0-9\.@:>@//g'],
+                       [--cflags],
+                       [--libs | $EGREP -o -- '-L@<:@^ @:>@* ?'],
+                       [--libs | $EGREP -o -- '-l@<:@^ @:>@* ?']
+               )
+               HTTP_HAVE_VERSION(libcurl, 7.18.2)
 
-                       dnl RHEL6:         7.19.7
-                       dnl SUSE11:        7.19.7
-                       dnl Debian wheezy: 7.26.0
-                       dnl Debian sqeeze: 7.21.0
-                       dnl Debian ancient 7.18.2
-                       AC_MSG_CHECKING([for curl version >= 7.18.2])
-                       CURL_VERSION=`$CURL_CONFIG --version | $SED -e 's/[[^0-9\.]]//g'`
-                       AC_MSG_RESULT([$CURL_VERSION])
-                       if test `echo $CURL_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*10000 + $2*100 + $3}'` -lt 71802; then
-                               AC_MSG_ERROR([libcurl version greater or equal to 7.18.2 required])
-                       fi
+               AC_MSG_CHECKING([for HTTP2 support in libcurl])
+               if $CURL_CONFIG --feature | $EGREP -q HTTP2; then
+                       AC_MSG_RESULT([yes])
+                       AC_DEFINE([PHP_HTTP_HAVE_HTTP2], [1], [ ])
+               else
+                       AC_MSG_RESULT([no])
+               fi
 
-                       AC_MSG_CHECKING([for HTTP2 support in libcurl])
-                       if $CURL_CONFIG --features | $EGREP -q HTTP2; then
-                               AC_MSG_RESULT([yes])
-                               AC_DEFINE([PHP_HTTP_HAVE_HTTP2], [1], [ ])
-                       else
-                               AC_MSG_RESULT([no])
-                       fi
+               AC_MSG_CHECKING([for SSL support in libcurl])
+               if $CURL_CONFIG --feature | $EGREP -q SSL; then
+                       AC_MSG_RESULT([yes])
+                       AC_DEFINE([PHP_HTTP_HAVE_SSL], [1], [ ])
 
-                       dnl
-                       dnl compile tests
-                       dnl
-
-                       save_INCLUDES="$INCLUDES"
-                       INCLUDES=
-                       save_LIBS="$LIBS"
-                       LIBS=-lcurl
-                       save_CFLAGS="$CFLAGS"
-                       CFLAGS="$CFLAGS `$CURL_CONFIG --cflags`"
-                       save_LDFLAGS="$LDFLAGS"
-                       LDFLAGS="$ld_runpath_switch$CURL_DIR/$PHP_LIBDIR"
-
-                       AC_MSG_CHECKING([for SSL support in libcurl])
-                       CURL_SSL=`$CURL_CONFIG --feature | $EGREP SSL`
-                       CURL_SSL_LIBS=""
-                       if test "$CURL_SSL" = "SSL"; then
-                               AC_MSG_RESULT([yes])
-                               AC_DEFINE([PHP_HTTP_HAVE_SSL], [1], [ ])
-
-                               HTTP_CURL_SSL_LIB_CHECK(OpenSSL, [
-                                       AC_CHECK_HEADER([openssl/ssl.h], [
-                                               AC_CHECK_HEADER([openssl/crypto.h], [
-                                                       AC_DEFINE([PHP_HTTP_HAVE_OPENSSL], [1], [ ])
-                                                       CURL_SSL_LIBS="ssl crypto"
-                                               ])
+                       HTTP_CURL_SSL_LIB_CHECK(OpenSSL, [
+                               AC_CHECK_HEADER([openssl/ssl.h], [
+                                       AC_CHECK_HEADER([openssl/crypto.h], [
+                                               AC_DEFINE([PHP_HTTP_HAVE_OPENSSL], [1], [ ])
+                                               LIBS="$LIBS -lssl -lcrypto"
                                        ])
                                ])
-                               HTTP_CURL_SSL_LIB_CHECK(GnuTLS, [
-                                       AC_CHECK_HEADER([gnutls.h], [
-                                               AC_CHECK_HEADER([gcrypt.h], [
-                                                       AC_DEFINE([PHP_HTTP_HAVE_GNUTLS], [1], [ ])
-                                                       CURL_SSL_LIBS="gnutls gcrypt"
-                                               ])
+                       ])
+                       HTTP_CURL_SSL_LIB_CHECK(GnuTLS, [
+                               AC_CHECK_HEADER([gnutls.h], [
+                                       AC_CHECK_HEADER([gcrypt.h], [
+                                               AC_DEFINE([PHP_HTTP_HAVE_GNUTLS], [1], [ ])
+                                               LIBS="$LIBS -lgnutls -lgcrypt"
                                        ])
                                ])
-                               HTTP_CURL_SSL_LIB_CHECK(NSS, [
-                                       AC_DEFINE([PHP_HTTP_HAVE_NSS], [1], [ ])
-                               ])
-                               HTTP_CURL_SSL_LIB_CHECK(SecureTransport, [
-                                       AC_DEFINE([PHP_HTTP_HAVE_DARWINSSL], [1], [ ])
-                               ])
-                               HTTP_CURL_SSL_LIB_CHECK(GSKit, [
-                                       AC_DEFINE([PHP_HTTP_HAVE_GSKIT], [1], [ ])
-                               ])
-                       else
-                               dnl no CURL_SSL
-                               AC_MSG_RESULT([no])
-                       fi
+                       ])
+                       HTTP_CURL_SSL_LIB_CHECK(NSS, [
+                               AC_DEFINE([PHP_HTTP_HAVE_NSS], [1], [ ])
+                       ])
+                       HTTP_CURL_SSL_LIB_CHECK(SecureTransport, [
+                               AC_DEFINE([PHP_HTTP_HAVE_DARWINSSL], [1], [ ])
+                       ])
+                       HTTP_CURL_SSL_LIB_CHECK(GSKit, [
+                               AC_DEFINE([PHP_HTTP_HAVE_GSKIT], [1], [ ])
+                       ])
+               else
+                       dnl no CURL_SSL
+                       AC_MSG_RESULT([no])
+               fi
 
-                       AC_MSG_CHECKING([for ares support in libcurl])
-                       AC_TRY_RUN([
-                               #include <curl/curl.h>
-                               int main(int argc, char *argv[]) {
-                                       curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
-                                       if (data && data->ares && data->ares_num0) {
-                                               return 0;
-                                       }
-                                       return 1;
+               AC_MSG_CHECKING([for ares support in libcurl])
+               AC_TRY_RUN([
+                       #include <curl/curl.h>
+                       int main(int argc, char *argv[]) {
+                               curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
+                               if (data && data->ares && data->ares_num0) {
+                                       return 0;
                                }
-                       ], [
-                               AC_MSG_RESULT([yes])
-                               AC_DEFINE([PHP_HTTP_HAVE_ARES], [1], [ ])
-                       ], [
-                               AC_MSG_RESULT([no])
-                       ], [
-                               AC_MSG_RESULT([no])
-                       ])
+                               return 1;
+                       }
+               ], [
+                       AC_MSG_RESULT([yes])
+                       AC_DEFINE([PHP_HTTP_HAVE_ARES], [1], [ ])
+               ], [
+                       AC_MSG_RESULT([no])
+               ], [
+                       AC_MSG_RESULT([no])
+               ])
 
-                       AC_MSG_CHECKING([whether CURLOPT_TLSAUTH_TYPE expects CURL_TLSAUTH_SRP or literal "SRP"])
+               AC_MSG_CHECKING([whether CURLOPT_TLSAUTH_TYPE expects CURL_TLSAUTH_SRP or literal "SRP"])
+               AC_TRY_RUN([
+                       #include <curl/curl.h>
+                       int main(int argc, char *argv[]) {
+                               CURL *ch = curl_easy_init();
+                               return curl_easy_setopt(ch, CURLOPT_TLSAUTH_TYPE, CURL_TLSAUTH_SRP);
+                       }
+               ], [
+                       AC_MSG_RESULT([CURL_TLSAUTH_SRP])
+                       AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_SRP], [CURL_TLSAUTH_SRP], [ ])
+                       AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_DEF], [CURL_TLSAUTH_NONE], [ ])
+               ], [
                        AC_TRY_RUN([
                                #include <curl/curl.h>
                                int main(int argc, char *argv[]) {
                                        CURL *ch = curl_easy_init();
-                                       return curl_easy_setopt(ch, CURLOPT_TLSAUTH_TYPE, CURL_TLSAUTH_SRP);
+                                       return curl_easy_setopt(ch, CURLOPT_TLSAUTH_TYPE, "SRP");
                                }
                        ], [
-                               AC_MSG_RESULT([CURL_TLSAUTH_SRP])
-                               AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_SRP], [CURL_TLSAUTH_SRP], [ ])
-                               AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_DEF], [CURL_TLSAUTH_NONE], [ ])
+                               AC_MSG_RESULT(["SRP"])
+                               AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_SRP], ["SRP"], [ ])
+                               AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_DEF], [""], [ ])
                        ], [
-                               AC_TRY_RUN([
-                                       #include <curl/curl.h>
-                                       int main(int argc, char *argv[]) {
-                                               CURL *ch = curl_easy_init();
-                                               return curl_easy_setopt(ch, CURLOPT_TLSAUTH_TYPE, "SRP");
-                                       }
-                               ], [
-                                       AC_MSG_RESULT(["SRP"])
-                                       AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_SRP], ["SRP"], [ ])
-                                       AC_DEFINE([PHP_HTTP_CURL_TLSAUTH_DEF], [""], [ ])
-                               ], [
-                                       AC_MSG_RESULT([neither])
-                               ], [
-                                       AC_MSG_RESULT([neither])
-                               ])
+                               AC_MSG_RESULT([neither])
                        ], [
                                AC_MSG_RESULT([neither])
                        ])
+               ], [
+                       AC_MSG_RESULT([neither])
+               ])
 
-                       INCLUDES="$save_INCLUDES"
-                       LIBS="$save_LIBS"
-                       CFLAGS="$save_CFLAGS"
-                       LDFLAGS="$save_LDFLAGS"
-
-                       if test -n "$CURL_SSL_LIBS"; then
-                               for CURL_SSL_LIB in $CURL_SSL_LIBS; do
-                                       PHP_ADD_LIBRARY_WITH_PATH([$CURL_SSL_LIB], $CURL_DIR/$PHP_LIBDIR, PHP_HTTP_SHARED_LIBADD)
-                               done
-                       fi
-
-                       dnl end compile tests
-
-                       AC_MSG_CHECKING([for default SSL CA info/path])
-                       CURL_CA_PATH=
-                       CURL_CA_INFO=
-                       CURL_CONFIG_CA=$($CURL_CONFIG --ca)
-                       if test -z "$CURL_CONFIG_CA"; then
-                               CURL_CONFIG_CA=$($CURL_CONFIG --configure  | $EGREP -o -- "--with-ca@<:@^'@:>@*" | $SED 's/.*=//')
-                       fi
-                       for i in \
-                               "$CURL_CONFIG_CA" \
-                               /etc/ssl/certs \
-                               /etc/ssl/certs/ca-bundle.crt \
-                               /etc/ssl/certs/ca-certificates.crt \
-                               /etc/pki/tls/certs/ca-bundle.crt \
-                               /etc/pki/tls/certs/ca-bundle.trust.crt \
-                               /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem \
-                               /System/Library/OpenSSL
-                       do
-                               if test -z "$CURL_CA_PATH" && test -d "$i"; then
-                                       # check if it's actually a hashed directory
-                                       if ls "$i"/@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@.0 >/dev/null 2>&1; then
-                                               CURL_CA_PATH="$i"
-                                       fi
-                               elif test -z "$CURL_CA_INFO" && test -f "$i"; then
-                                       CURL_CA_INFO="$i"
+               AC_MSG_CHECKING([for default SSL CA info/path])
+               CURL_CA_PATH=
+               CURL_CA_INFO=
+               CURL_CONFIG_CA=$($CURL_CONFIG --ca)
+               if test -z "$CURL_CONFIG_CA"; then
+                       CURL_CONFIG_CA=$($CURL_CONFIG --configure  | $EGREP -o -- "--with-ca@<:@^'@:>@*" | $SED 's/.*=//')
+               fi
+               for i in \
+                       "$CURL_CONFIG_CA" \
+                       /etc/ssl/certs \
+                       /etc/ssl/certs/ca-bundle.crt \
+                       /etc/ssl/certs/ca-certificates.crt \
+                       /etc/pki/tls/certs/ca-bundle.crt \
+                       /etc/pki/tls/certs/ca-bundle.trust.crt \
+                       /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem \
+                       /System/Library/OpenSSL
+               do
+                       if test -z "$CURL_CA_PATH" && test -d "$i"; then
+                               # check if it's actually a hashed directory
+                               if ls "$i"/@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@@<:@0-9a-f@:>@.0 >/dev/null 2>&1; then
+                                       CURL_CA_PATH="$i"
                                fi
-                       done
-                       if test -n "$CURL_CA_PATH" && test -n "$CURL_CA_INFO"; then
-                               AC_MSG_RESULT([path:$CURL_CA_PATH, info:$CURL_CA_INFO])
-                               AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAPATH], ["$CURL_CA_PATH"], [path to default SSL CA path])
-                               AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAINFO], ["$CURL_CA_INFO"], [path to default SSL CA info])
-                       elif test -n "$CURL_CA_INFO"; then
-                               AC_MSG_RESULT([info:$CURL_CA_INFO])
-                               AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAINFO], ["$CURL_CA_INFO"], [path to default SSL CA info])
-                       elif test -n "$CURL_CA_PATH"; then
-                               AC_MSG_RESULT([path:$CURL_CA_PATH])
-                               AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAPATH], ["$CURL_CA_PATH"], [path to default SSL CA path])
-                       else
-                               AC_MSG_RESULT([none])
+                       elif test -z "$CURL_CA_INFO" && test -f "$i"; then
+                               CURL_CA_INFO="$i"
                        fi
-
-                       PHP_ADD_INCLUDE($CURL_DIR/include)
-                       PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
-                       PHP_EVAL_LIBLINE(`$CURL_CONFIG --libs`, HTTP_SHARED_LIBADD)
-                       AC_DEFINE([PHP_HTTP_HAVE_CURL], [1], [Have libcurl support])
-                       HTTP_HAVE_A_REQUEST_LIB=true
+               done
+               if test -n "$CURL_CA_PATH" && test -n "$CURL_CA_INFO"; then
+                       AC_MSG_RESULT([path:$CURL_CA_PATH, info:$CURL_CA_INFO])
+                       AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAPATH], ["$CURL_CA_PATH"], [path to default SSL CA path])
+                       AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAINFO], ["$CURL_CA_INFO"], [path to default SSL CA info])
+               elif test -n "$CURL_CA_INFO"; then
+                       AC_MSG_RESULT([info:$CURL_CA_INFO])
+                       AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAINFO], ["$CURL_CA_INFO"], [path to default SSL CA info])
+               elif test -n "$CURL_CA_PATH"; then
+                       AC_MSG_RESULT([path:$CURL_CA_PATH])
+                       AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAPATH], ["$CURL_CA_PATH"], [path to default SSL CA path])
+               else
+                       AC_MSG_RESULT([none])
                fi
+
+               HTTP_HAVE_A_REQUEST_LIB=true
        fi
+       HTTP_CHECK_DONE(libcurl, test -n "$PHP_HTTP_LIBCURL_VERSION")
 
 dnl ----
 dnl EVENT
 dnl ----
 
-       if test "$PHP_HTTP_LIBEVENT_DIR" = "no"; then
-               AC_DEFINE([PHP_HTTP_HAVE_EVENT], [0], [ ])
-       else
-               AC_MSG_CHECKING([for event2/event.h])
-               EVENT_DIR=
-               for i in "$PHP_HTTP_LIBEVENT_DIR" /usr/local /usr /opt; do
-                       if test -f "$i/include/event.h"; then
-                               EVENT_DIR=$i
-                               break
-                       fi
-               done
-               if test "x$EVENT_DIR" = "x"; then
-                       AC_MSG_RESULT([not found])
-                       AC_MSG_WARN([continuing without libevent support])
-                       AC_DEFINE([PHP_HTTP_HAVE_EVENT], [0], [ ])
-               else
-                       AC_MSG_RESULT([found in $EVENT_DIR])
-
-                       AC_MSG_CHECKING([for libevent version, roughly])
-
-                       if test -f "$EVENT_DIR/include/event2/event.h"; then
-                               EVENT_VER="`$AWK '/_EVENT_VERSION/ {gsub(/\"/,\"\",$3); print $3}' < $EVENT_DIR/include/event2/event-config.h`"
-                               AC_DEFINE([PHP_HTTP_HAVE_EVENT2], [1], [ ])
-                       else
-                               AC_DEFINE([PHP_HTTP_HAVE_EVENT2], [0], [ ])
-                               if test -f "$EVENT_DIR/include/evhttp.h" && test -f "$EVENT_DIR/include/evdns.h"; then
-                                       if test -f "$EVENT_DIR/include/evrpc.h"; then
-                                               EVENT_VER="1.4 or greater"
-                                       else
-                                               EVENT_VER="1.2 or greater"
-                                       fi
-                               else
-                                       EVENT_VER="1.1b or lower"
-                               fi
-                       fi
-                       AC_DEFINE_UNQUOTED([PHP_HTTP_EVENT_VERSION], ["$EVENT_VER"], [ ])
-                       AC_MSG_RESULT([$EVENT_VER])
-
-                       PHP_ADD_INCLUDE($EVENT_DIR/include)
-                       PHP_ADD_LIBRARY_WITH_PATH(event, $EVENT_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
-                       AC_DEFINE([PHP_HTTP_HAVE_EVENT], [1], [Have libevent support for cURL])
-               fi
-       fi
+       HTTP_CHECK_PKGCONFIG(libevent, [$PHP_HTTP_LIBEVENT_DIR])
+       HTTP_HAVE_VERSION(libevent, 2.0, [
+               AC_DEFINE([PHP_HTTP_HAVE_LIBEVENT2], [1], [ ])
+       ])
+       HTTP_CHECK_DONE(libevent, [$PHP_HTTP_HAVE_LIBEVENT])
 
 dnl ----
 dnl RAPHF
index 0b282e5..cd74848 100755 (executable)
@@ -10,8 +10,9 @@ addons:
    - php5-cli
    - php-pear
    - libcurl4-openssl-dev
-   - zlib1g-dev
    - libidn11-dev
+   - libidn2-0-dev
+   - libicu-dev
    - libevent-dev
 
 env:
index c376388..4130bce 100644 (file)
 
 #include <zlib.h>
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 #      include <curl/curl.h>
-#      if PHP_HTTP_HAVE_EVENT
-#              if PHP_HTTP_HAVE_EVENT2
+#      if PHP_HTTP_HAVE_LIBEVENT
+#              if PHP_HTTP_HAVE_LIBEVENT2
 #                      include <event2/event.h>
 #                      include <event2/event_struct.h>
 #              else
 #              endif
 #      endif
 #endif
-#if PHP_HTTP_HAVE_IDN2
+#if PHP_HTTP_HAVE_LIBICU
+#      include <unicode/uversion.h>
+#endif
+#if PHP_HTTP_HAVE_LIBIDN2
 #      include <idn2.h>
-#elif PHP_HTTP_HAVE_IDN
+#endif
+#if PHP_HTTP_HAVE_LIBIDN
 #      include <idna.h>
 #endif
 
@@ -140,7 +144,7 @@ PHP_MINIT_FUNCTION(http)
        || SUCCESS != PHP_MINIT_CALL(http_client)
        || SUCCESS != PHP_MINIT_CALL(http_client_request)
        || SUCCESS != PHP_MINIT_CALL(http_client_response)
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
        || SUCCESS != PHP_MINIT_CALL(http_curl)
        || SUCCESS != PHP_MINIT_CALL(http_client_curl)
        || SUCCESS != PHP_MINIT_CALL(http_client_curl_user)
@@ -165,7 +169,7 @@ PHP_MSHUTDOWN_FUNCTION(http)
        
        if (0
        || SUCCESS != PHP_MSHUTDOWN_CALL(http_message)
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
        || SUCCESS != PHP_MSHUTDOWN_CALL(http_client_curl)
        || SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
 #endif
@@ -202,7 +206,7 @@ PHP_MINFO_FUNCTION(http)
        php_info_print_table_start();
        php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
        php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
        {
                curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
                php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
@@ -211,22 +215,47 @@ PHP_MINFO_FUNCTION(http)
        php_info_print_table_row(3, "libcurl", "disabled", "disabled");
 #endif
 
-#if PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_LIBEVENT
        php_info_print_table_row(3, "libevent",
 #      ifdef LIBEVENT_VERSION
                        LIBEVENT_VERSION,
 #      else
-                       PHP_HTTP_EVENT_VERSION,
+                       PHP_HTTP_LIBEVENT_VERSION,
 #      endif
                        event_get_version());
 #else
        php_info_print_table_row(3, "libevent", "disabled", "disabled");
 #endif
 
-#if PHP_HTTP_HAVE_IDN2
+#if PHP_HTTP_HAVE_LIBICU
+       {
+               UVersionInfo uv = {0};
+               char us[U_MAX_VERSION_STRING_LENGTH] = {0};
+
+               u_getVersion(uv);
+               u_versionToString(uv, us);
+               php_info_print_table_row(3, "libicu "
+#if HAVE_UIDNA_NAMETOASCII_UTF8 && HAVE_UIDNA_IDNTOASCII
+                               "(IDNA2008/IDNA2003)"
+#elif HAVE_UIDNA_NAMETOASCII_UTF8
+                               "(IDNA2008)"
+#elif HAVE_UIDNA_IDNTOASCII
+                               "(IDNA2003)"
+#endif
+                               , U_ICU_VERSION, us);
+       }
+#else
+       php_info_print_table_row(3, "libicu (IDNA2008/IDNA2003)", "disabled", "disabled");
+#endif
+#if PHP_HTTP_HAVE_LIBIDN2
        php_info_print_table_row(3, "libidn2 (IDNA2008)", IDN2_VERSION, idn2_check_version(NULL));
-#elif PHP_HTTP_HAVE_IDN
+#else
+       php_info_print_table_row(3, "libidn2 (IDNA2008)", "disabled", "disabled");
+#endif
+#if PHP_HTTP_HAVE_LIBIDN
        php_info_print_table_row(3, "libidn (IDNA2003)", PHP_HTTP_LIBIDN_VERSION, "unknown");
+#else
+       php_info_print_table_row(3, "libidn (IDNA2003)", "disabled", "disabled");
 #endif
 
        php_info_print_table_end();
index 7fe3d10..717b64c 100644 (file)
@@ -110,7 +110,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_http)
        struct php_http_env_globals env;
 #ifdef PHP_HTTP_HAVE_CLIENT
        struct {
-#ifdef PHP_HTTP_HAVE_CURL
+#ifdef PHP_HTTP_HAVE_LIBCURL
                struct php_http_client_curl_globals curl;
 #endif
        } client;
index 4118ab1..7f8363e 100644 (file)
@@ -376,7 +376,7 @@ static HashTable *php_http_client_object_get_gc(zval *object, zval **table, int
        *n = 0;
        *table = obj->gc = erealloc(obj->gc, sizeof(zval) * count);
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
        if (obj->client->ops == php_http_client_curl_get_ops()) {
                php_http_client_curl_t *curl = obj->client->ctx;
 
index 71afd6f..641a9d8 100644 (file)
@@ -15,7 +15,7 @@
 #include "php_http_client_curl_event.h"
 #include "php_http_client_curl_user.h"
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 
 #ifdef PHP_HTTP_HAVE_OPENSSL
 #      include <openssl/ssl.h>
@@ -1638,7 +1638,7 @@ static ZEND_RESULT_CODE php_http_curlm_option_set_use_eventloop(php_http_option_
 
        if (value && Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), php_http_client_curl_user_get_class_entry())) {
                ev_ops = php_http_client_curl_user_ops_get();
-#if PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_LIBEVENT
        } else if (value && zend_is_true(value)) {
                ev_ops = php_http_client_curl_event_ops_get();
 #endif
@@ -2321,7 +2321,7 @@ static ZEND_RESULT_CODE php_http_client_curl_setopt(php_http_client_t *h, php_ht
                        break;
 
                case PHP_HTTP_CLIENT_OPT_USE_EVENTS:
-#if PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_LIBEVENT
                        return php_http_curlm_use_eventloop(h, (*(zend_bool *) arg)
                                        ? php_http_client_curl_event_ops_get()
                                        : NULL, NULL);
@@ -2605,7 +2605,7 @@ PHP_MSHUTDOWN_FUNCTION(http_client_curl)
        return SUCCESS;
 }
 
-#endif /* PHP_HTTP_HAVE_CURL */
+#endif /* PHP_HTTP_HAVE_LIBCURL */
 
 /*
  * Local variables:
index abd8f99..21b6834 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef PHP_HTTP_CLIENT_CURL_H
 #define PHP_HTTP_CLIENT_CURL_H
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 
 struct php_http_client_curl_globals {
        php_http_client_driver_t driver;
@@ -59,7 +59,7 @@ PHP_HTTP_API php_http_client_ops_t *php_http_client_curl_get_ops(void);
 PHP_MINIT_FUNCTION(http_client_curl);
 PHP_MSHUTDOWN_FUNCTION(http_client_curl);
 
-#endif /* PHP_HTTP_HAVE_CURL */
+#endif /* PHP_HTTP_HAVE_LIBCURL */
 
 #endif /* PHP_HTTP_CLIENT_CURL_H */
 
index e1ba505..ea5f6af 100644 (file)
@@ -12,9 +12,9 @@
 
 #include "php_http_api.h"
 
-#if PHP_HTTP_HAVE_CURL
-#if PHP_HTTP_HAVE_EVENT
-#      if !PHP_HTTP_HAVE_EVENT2 && /* just be really sure */ !(LIBEVENT_VERSION_NUMBER >= 0x02000000)
+#if PHP_HTTP_HAVE_LIBCURL
+#if PHP_HTTP_HAVE_LIBEVENT
+#      if !PHP_HTTP_HAVE_LIBEVENT2 && /* just be really sure */ !(LIBEVENT_VERSION_NUMBER >= 0x02000000)
 #              include <event.h>
 #              define event_base_new event_init
 #              define event_assign(e, b, s, a, cb, d) do {\
@@ -22,7 +22,7 @@
                        event_base_set(b, e); \
                } while(0)
 #      else
-#              if PHP_HTTP_HAVE_EVENT2
+#              if PHP_HTTP_HAVE_LIBEVENT2
 #                      include <event2/event.h>
 #                      include <event2/event_struct.h>
 #              else
@@ -314,8 +314,8 @@ php_http_client_curl_ops_t *php_http_client_curl_event_ops_get()
        return &php_http_client_curl_event_ops;
 }
 
-#endif /* PHP_HTTP_HAVE_EVENT */
-#endif /* PHP_HTTP_HAVE_CURL */
+#endif /* PHP_HTTP_HAVE_LIBEVENT */
+#endif /* PHP_HTTP_HAVE_LIBCURL */
 
 /*
  * Local variables:
index 4739f62..dc63bd4 100644 (file)
@@ -13,8 +13,8 @@
 #ifndef PHP_HTTP_CLIENT_CURL_EVENT_H
 #define PHP_HTTP_CLIENT_CURL_EVENT_H
 
-#if PHP_HTTP_HAVE_CURL
-#if PHP_HTTP_HAVE_EVENT
+#if PHP_HTTP_HAVE_LIBCURL
+#if PHP_HTTP_HAVE_LIBEVENT
 
 php_http_client_curl_ops_t *php_http_client_curl_event_ops_get();
 
index a0449a2..d44f3da 100644 (file)
@@ -15,7 +15,7 @@
 #include "php_network.h"
 #include "zend_closures.h"
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 
 typedef struct php_http_client_curl_user_ev {
        php_stream *socket;
@@ -316,7 +316,7 @@ PHP_MINIT_FUNCTION(http_client_curl_user)
        return SUCCESS;
 }
 
-#endif /* PHP_HTTP_HAVE_CURL */
+#endif /* PHP_HTTP_HAVE_LIBCURL */
 
 /*
  * Local variables:
index 39364be..a6ea847 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef PHP_HTTP_CLIENT_CURL_USER_H
 #define PHP_HTTP_CLIENT_CURL_USER_H
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 
 typedef struct php_http_client_curl_user_context {
        php_http_client_t *client;
index a995094..3a67443 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "php_http_api.h"
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 
 #if defined(ZTS) && defined(PHP_HTTP_HAVE_SSL)
 #      ifdef PHP_WIN32
@@ -133,7 +133,7 @@ PHP_MSHUTDOWN_FUNCTION(http_curl)
        return SUCCESS;
 }
 
-#endif /* PHP_HTTP_HAVE_CURL */
+#endif /* PHP_HTTP_HAVE_LIBCURL */
 
 /*
  * Local variables:
index 7a9821c..a76724c 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef PHP_HTTP_CURL_H
 #define PHP_HTTP_CURL_H
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 
 #include <curl/curl.h>
 #define PHP_HTTP_CURL_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= (((x)<<16) + ((y)<<8) + (z)))
@@ -26,7 +26,7 @@
 PHP_MINIT_FUNCTION(http_curl);
 PHP_MSHUTDOWN_FUNCTION(http_curl);
 
-#endif /* PHP_HTTP_HAVE_CURL */
+#endif /* PHP_HTTP_HAVE_LIBCURL */
 
 #endif /* PHP_HTTP_CURL_H */
 
index 2332fb5..738cfb0 100644 (file)
 
 #include "php_http_api.h"
 
-#if PHP_HTTP_HAVE_IDN2
+#if PHP_HTTP_HAVE_LIBIDN2
 #      include <idn2.h>
-#elif PHP_HTTP_HAVE_IDN
+#endif
+#if PHP_HTTP_HAVE_LIBIDN
 #      include <idna.h>
 #endif
+#if PHP_HTTP_HAVE_LIBICU
+#      include <unicode/uidna.h>
+#endif
 
 #ifdef PHP_HTTP_HAVE_WCHAR
 #      include <wchar.h>
@@ -899,8 +903,8 @@ static ZEND_RESULT_CODE to_utf16(parse_mb_func fn, const char *u8, uint16_t **u1
 #      define MAXHOSTNAMELEN 256
 #endif
 
-#if PHP_HTTP_HAVE_IDN2
-static ZEND_RESULT_CODE parse_idn2(struct parse_state *state, size_t prev_len)
+#if PHP_HTTP_HAVE_LIBIDN2
+static ZEND_RESULT_CODE parse_gidn_2008(struct parse_state *state, size_t prev_len)
 {
        char *idn = NULL;
        int rv = -1;
@@ -915,7 +919,7 @@ static ZEND_RESULT_CODE parse_idn2(struct parse_state *state, size_t prev_len)
 #      endif
        if (rv != IDN2_OK) {
                if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
-                       php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
+                       php_error_docref(NULL, E_WARNING, "Failed to parse IDN (IDNA2008); %s", idn2_strerror(rv));
                }
                if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
                        return FAILURE;
@@ -928,8 +932,10 @@ static ZEND_RESULT_CODE parse_idn2(struct parse_state *state, size_t prev_len)
        }
        return SUCCESS;
 }
-#elif PHP_HTTP_HAVE_IDN
-static ZEND_RESULT_CODE parse_idn(struct parse_state *state, size_t prev_len)
+#endif
+
+#if PHP_HTTP_HAVE_LIBIDN
+static ZEND_RESULT_CODE parse_gidn_2003(struct parse_state *state, size_t prev_len)
 {
        char *idn = NULL;
        int rv = -1;
@@ -944,7 +950,7 @@ static ZEND_RESULT_CODE parse_idn(struct parse_state *state, size_t prev_len)
 #      endif
        if (rv != IDNA_SUCCESS) {
                if (!(state->flags & PHP_HTTP_URL_SILENT_ERRORS)) {
-                       php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
+                       php_error_docref(NULL, E_WARNING, "Failed to parse IDN (IDNA2003); %s", idna_strerror(rv));
                }
                if (!(state->flags & PHP_HTTP_URL_IGNORE_ERRORS)) {
                        return FAILURE;
@@ -960,56 +966,136 @@ static ZEND_RESULT_CODE parse_idn(struct parse_state *state, size_t prev_len)
 #endif
 
 #ifdef HAVE_UIDNA_IDNTOASCII
-#      if HAVE_UNICODE_UIDNA_H
+#      if PHP_HTTP_HAVE_LIBICU
 #              include <unicode/uidna.h>
 #      else
 typedef uint16_t UChar;
 typedef enum { U_ZERO_ERROR = 0 } UErrorCode;
 int32_t uidna_IDNToASCII(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, int32_t options, void *parseError, UErrorCode *status);
 #      endif
-static ZEND_RESULT_CODE parse_uidn(struct parse_state *state)
+static ZEND_RESULT_CODE parse_uidn_2003(struct parse_state *state)
 {
-       char *host_ptr;
+       char *host_ptr = state->url.host, ebuf[64] = {0}, *error = NULL;
        uint16_t *uhost_str, ahost_str[MAXHOSTNAMELEN], *ahost_ptr;
        size_t uhost_len, ahost_len;
-       UErrorCode error = U_ZERO_ERROR;
+       UErrorCode rc = U_ZERO_ERROR;
 
        if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
                if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len)) {
-                       return FAILURE;
+                       error = "failed to convert to UTF-16";
+                       goto error;
                }
 #ifdef PHP_HTTP_HAVE_WCHAR
        } else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
                if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len)) {
-                       return FAILURE;
+                       error = "failed to convert to UTF-16";
+                       goto error;
                }
 #endif
        } else {
-               php_error_docref(NULL, E_WARNING, "Failed to parse IDN; codepage not specified");
-               return FAILURE;
+               error = "codepage not specified";
+               goto error;
        }
 
-       ahost_len = uidna_IDNToASCII(uhost_str, uhost_len, ahost_str, MAXHOSTNAMELEN, 3, NULL, &error);
+       ahost_len = uidna_IDNToASCII(uhost_str, uhost_len, ahost_str, MAXHOSTNAMELEN, 3, NULL, &rc);
        efree(uhost_str);
 
-       if (error != U_ZERO_ERROR) {
-               php_error_docref(NULL, E_WARNING, "Failed to parse IDN; ICU error %d", error);
-               return FAILURE;
+       if (error > U_ZERO_ERROR) {
+               goto error;
        }
 
-       host_ptr = state->url.host;
        ahost_ptr = ahost_str;
        PHP_HTTP_DUFF(ahost_len, *host_ptr++ = *ahost_ptr++);
+       *host_ptr = '\0';
+       state->offset += host_ptr - state->url.host;
+
+       return SUCCESS;
+
+       error:
+       if (!error) {
+               slprintf(ebuf, sizeof(ebuf)-1, "errorcode: %d", rc);
+               error = ebuf;
+       }
+       php_error_docref(NULL, E_WARNING, "Failed to parse IDN (ICU IDNA2003); %s", error);
+
+       return FAILURE;
+}
+#endif
+
+#ifdef HAVE_UIDNA_IDNTOASCII
+#      if PHP_HTTP_HAVE_LIBICU
+#              include <unicode/uidna.h>
+#      endif
+static ZEND_RESULT_CODE parse_uidn_2008(struct parse_state *state)
+{
+       char *host_ptr, *error = NULL, ebuf[64] = {0};
+       UErrorCode rc = U_ZERO_ERROR;
+       UIDNAInfo info = UIDNA_INFO_INITIALIZER;
+       UIDNA *uidna = uidna_openUTS46(UIDNA_ALLOW_UNASSIGNED|UIDNA_USE_STD3_RULES, &rc);
+
+       if (!uidna || U_FAILURE(rc)) {
+               return FAILURE;
+       }
+
+       host_ptr = state->url.host;
+
+       if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
+               char ahost_str[MAXHOSTNAMELEN], *ahost_ptr = &ahost_str[0];
+               size_t ahost_len = uidna_nameToASCII_UTF8(uidna, host_ptr, -1, ahost_str, sizeof(ahost_str)-1, &info, &rc);
+
+               if (U_FAILURE(rc) || info.errors) {
+                       goto error;
+               }
+               PHP_HTTP_DUFF(ahost_len, *host_ptr++ = *ahost_ptr++);
+#ifdef PHP_HTTP_HAVE_WCHAR
+       } else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
+               uint16_t *uhost_str, whost_str[MAXHOSTNAMELEN], *whost_ptr = &whost_str[0];
+               size_t uhost_len, whost_len;
+
+               if (SUCCESS != to_utf16(parse_mb_loc, host_ptr, &uhost_str, &uhost_len)) {
+                       error = "could not convert to UTF-16";
+                       goto error;
+               }
+
+               whost_len = uidna_nameToASCII(uidna, uhost_str, uhost_len, whost_str, sizeof(whost_str)-1, &info, &rc);
+               whost_ptr = whost_str;
+               if (U_FAILURE(rc) || info.errors) {
+                       goto error;
+               }
+               PHP_HTTP_DUFF(whost_len, *host_ptr++ = *whost_ptr++);
+#endif
+       } else {
+               error = "codepage not specified";
+               goto error;
+       }
 
        *host_ptr = '\0';
        state->offset += host_ptr - state->url.host;
 
+       uidna_close(uidna);
        return SUCCESS;
+
+       error:
+       if (!error) {
+               if (U_FAILURE(rc)) {
+                       slprintf(ebuf, sizeof(ebuf)-1, "%s", u_errorName(rc));
+                       error = ebuf;
+               } else if (info.errors) {
+                       slprintf(ebuf, sizeof(ebuf)-1, "ICU IDNA error codes: 0x%x", info.errors);
+                       error = ebuf;
+               } else {
+                       error = "unknown error";
+               }
+       }
+       php_error_docref(NULL, E_WARNING, "Failed to parse IDN (ICU IDNA2008); %s", error);
+
+       uidna_close(uidna);
+       return FAILURE;
 }
 #endif
 
 #if 0 && defined(PHP_WIN32)
-static ZEND_RESULT_CODE parse_widn(struct parse_state *state)
+static ZEND_RESULT_CODE parse_widn_2003(struct parse_state *state)
 {
        char *host_ptr;
        uint16_t *uhost_str, ahost_str[MAXHOSTNAMELEN], *ahost_ptr;
@@ -1051,6 +1137,45 @@ static ZEND_RESULT_CODE parse_widn(struct parse_state *state)
 }
 #endif
 
+static ZEND_RESULT_CODE parse_idna(struct parse_state *state, size_t len)
+{
+       if ((state->flags & PHP_HTTP_URL_PARSE_TOIDN_2008)
+       || !(state->flags & PHP_HTTP_URL_PARSE_TOIDN_2003)
+       ) {
+#if HAVE_UIDNA_NAMETOASCII_UTF8
+               return parse_uidn_2008(state);
+#elif PHP_HTTP_HAVE_LIBIDN2
+               return parse_gidn_2008(state, len);
+#endif
+       }
+
+       if ((state->flags & PHP_HTTP_URL_PARSE_TOIDN_2003)
+       || !(state->flags & PHP_HTTP_URL_PARSE_TOIDN_2008)
+       ) {
+#if HAVE_UIDNA_IDNTOASCII
+               return parse_uidn_2003(state);
+#elif PHP_HTTP_HAVE_LIBIDN
+               return parse_gidn_2003(state, len);
+#endif
+       }
+
+#if 0 && defined(PHP_WIN32)
+       return parse_widn_2003(state);
+#endif
+
+#if HAVE_UIDNA_NAMETOASCII_UTF8
+               return parse_uidn_2008(state);
+#elif PHP_HTTP_HAVE_LIBIDN2
+               return parse_gidn_2008(state, len);
+#elif HAVE_UIDNA_IDNTOASCII
+               return parse_uidn_2003(state);
+#elif PHP_HTTP_HAVE_LIBIDN
+               return parse_gidn_2003(state, len);
+#endif
+
+       return SUCCESS;
+}
+
 #ifdef HAVE_INET_PTON
 static const char *parse_ip6(struct parse_state *state, const char *ptr)
 {
@@ -1244,17 +1369,7 @@ static ZEND_RESULT_CODE parse_hostinfo(struct parse_state *state, const char *pt
        }
 
        if (state->flags & PHP_HTTP_URL_PARSE_TOIDN) {
-#if PHP_HTTP_HAVE_IDN2
-               return parse_idn2(state, len);
-#elif PHP_HTTP_HAVE_IDN
-               return parse_idn(state, len);
-#endif
-#ifdef HAVE_UIDNA_IDNTOASCII
-               return parse_uidn(state);
-#endif
-#if 0 && defined(PHP_WIN32)
-               return parse_widn(state);
-#endif
+               return parse_idna(state, len);
        }
 
        return SUCCESS;
@@ -1884,8 +1999,14 @@ PHP_MINIT_FUNCTION(http_url)
        zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC);
 #endif
        zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8);
-#if defined(PHP_HTTP_HAVE_IDN2) || defined(PHP_HTTP_HAVE_IDN) || defined(HAVE_UIDNA_IDNTOASCII)
+#if PHP_HTTP_HAVE_LIBIDN2 || PHP_HTTP_HAVE_LIBIDN || HAVE_UIDNA_IDNTOASCII || HAVE_UIDNA_NAMETOASCII_UTF8
        zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN);
+#      if PHP_HTTP_HAVE_IDNA2003
+       zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN_2003"), PHP_HTTP_URL_PARSE_TOIDN_2003);
+#      endif
+#      if PHP_HTTP_HAVE_IDNA2008
+       zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN_2008"), PHP_HTTP_URL_PARSE_TOIDN_2008);
+#      endif
 #endif
        zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT);
 
index afc0412..6d4b09d 100644 (file)
 /* percent encode multibyte sequences in userinfo, path, query and fragment */
 #define PHP_HTTP_URL_PARSE_TOPCT       0x200000
 
+#if PHP_HTTP_HAVE_IDNA2008
+#define PHP_HTTP_URL_PARSE_TOIDN_2008 \
+       (PHP_HTTP_URL_PARSE_TOIDN       |       0x400000)
+#endif
+#if PHP_HTTP_HAVE_IDNA2003
+#define PHP_HTTP_URL_PARSE_TOIDN_2003 \
+       (PHP_HTTP_URL_PARSE_TOIDN       |       0x800000)
+#endif
+
 /* ignore errors */
 #define PHP_HTTP_URL_IGNORE_ERRORS     0x10000000
 /* do not report errors */
index c47e6a2..57f6a8b 100644 (file)
@@ -5,6 +5,7 @@ url parser multibyte/locale/idna
 include "skipif.inc";
 if (!defined("http\\Url::PARSE_MBLOC") or
        !defined("http\\Url::PARSE_TOIDN") or
+       !defined("http\\Url::PARSE_TOIDN_2003") or
        !stristr(setlocale(LC_CTYPE, NULL), ".utf")) {
        die("skip need http\\Url::PARSE_MBLOC|http\\Url::PARSE_TOIDN support and LC_CTYPE=*.UTF-8");
 }
@@ -21,7 +22,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(new http\Url($url, null, http\Url::PARSE_MBLOC|http\Url::PARSE_TOIDN));
+       var_dump(new http\Url($url, null, http\Url::PARSE_MBLOC|http\Url::PARSE_TOIDN|http\Url::PARSE_TOIDN_2003));
 }
 ?>
 DONE
index d7ec657..c175545 100644 (file)
@@ -3,7 +3,7 @@ url parser multibyte/utf-8/idna
 --SKIPIF--
 <?php
 include "skipif.inc";
-if (!defined("http\\Url::PARSE_TOIDN")) {
+if (!defined("http\\Url::PARSE_TOIDN")||!defined("http\\Url::PARSE_TOIDN_2003")) {
        die("skip need http\\Url::PARSE_TOIDN support");
 }
 ?>
@@ -19,7 +19,7 @@ $urls = array(
 
 foreach ($urls as $url) {
        printf("\n%s\n", $url);
-       var_dump(new http\Url($url, null, http\Url::PARSE_MBUTF8|http\Url::PARSE_TOIDN));
+       var_dump(new http\Url($url, null, http\Url::PARSE_MBUTF8|http\Url::PARSE_TOIDN|http\Url::PARSE_TOIDN_2003));
 }
 ?>
 DONE