fix build issues with SSL, NSS etc.
authorMichael Wallner <mike@php.net>
Wed, 5 Oct 2016 11:13:55 +0000 (13:13 +0200)
committerMichael Wallner <mike@php.net>
Wed, 5 Oct 2016 11:13:55 +0000 (13:13 +0200)
close #53

autoconf/pecl/libcurl.m4
autoconf/pecl/pecl.m4
src/php_http_client_curl.c

index f9eee6e..22b24c6 100644 (file)
@@ -44,52 +44,88 @@ dnl
 dnl PECL_HAVE_LIBCURL_SSLLIB(ssllib-name, headers, libs)
 dnl
 AC_DEFUN([PECL_HAVE_LIBCURL_SSLLIB], [
-       AC_CACHE_CHECK([for $1 providing SSL in libcurl], PECL_CACHE_VAR([HAVE_LIBCURL_$1]), [
-               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->ssl_version && *data->ssl_version) {
-                                       const char *ptr = data->ssl_version;
-                                       while(*ptr == ' ') ++ptr;
-                                       return strncasecmp(ptr, "$1", sizeof("$1")-1);
+       if test -z "$PECL_VAR([LIBCURL_SSLLIB])"; then
+               AC_CACHE_CHECK([for $1 providing SSL in libcurl], PECL_CACHE_VAR([HAVE_LIBCURL_$1]), [
+                       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->ssl_version && *data->ssl_version) {
+                                               const char *ptr = data->ssl_version;
+                                               while(*ptr == ' ') ++ptr;
+                                               return strncasecmp(ptr, "$1", sizeof("$1")-1);
+                                       }
+                                       return 1;
                                }
-                               return 1;
-                       }
-               ], [
-                       PECL_CACHE_VAR([HAVE_LIBCURL_$1])=yes
-               ], [
-                       PECL_CACHE_VAR([HAVE_LIBCURL_$1])=no
-               ])
-       ])
-       PECL_VAR([HAVE_LIBCURL_$1])=$PECL_CACHE_VAR([HAVE_LIBCURL_$1])
-       if $PECL_VAR([HAVE_LIBCURL_$1]); then
-               PECL_DEFINE([HAVE_LIBCURL_$1])
-               m4_foreach_w(header, $2, [AC_CHECK_HEADER(header,, [
-                       PECL_VAR([HAVE_LIBCURL_$1])=false
-               ])])
-               ifelse([$3],,,[
-                       if $PECL_VAR([HAVE_LIBCURL_$1]); then
-                               m4_foreach_w(lib, $3, [
-                                       PHP_ADD_LIBRARY(lib, true, [AS_TR_CPP(PECL_NAME[_SHARED_LIBADD])])
-                               ])
-                       fi
+                       ], [
+                               PECL_CACHE_VAR([HAVE_LIBCURL_$1])=yes
+                       ], [
+                               PECL_CACHE_VAR([HAVE_LIBCURL_$1])=no
+                       ])
                ])
+               PECL_VAR([HAVE_LIBCURL_$1])=$PECL_CACHE_VAR([HAVE_LIBCURL_$1])
+               if $PECL_VAR([HAVE_LIBCURL_$1]); then
+                       PECL_VAR([LIBCURL_SSLLIB])="$1"
+                       PECL_DEFINE([HAVE_LIBCURL_$1])
+                       m4_foreach_w(header, $2, [AC_CHECK_HEADER(header,, [
+                               PECL_VAR([HAVE_LIBCURL_$1])=false
+                       ])])
+                       ifelse([$3],,,[
+                               if $PECL_VAR([HAVE_LIBCURL_$1]); then
+                                       m4_foreach_w(lib, $3, [
+                                               PHP_ADD_LIBRARY(lib, true, [AS_TR_CPP(PECL_NAME[_SHARED_LIBADD])])
+                                       ])
+                               fi
+                       ])
+               fi
        fi
 ])
 dnl
 dnl PECL_HAVE_LIBCURL_SSL
 dnl
-AC_DEFUN([PECL_HAVE_LIBCURL_SSL], [
+AC_DEFUN([PECL_HAVE_LIBCURL_SSL], [dnl
+       AC_REQUIRE([PECL_HAVE_LIBCURL_CA])dnl
        PECL_HAVE_LIBCURL_FEATURE([SSL], [
                PECL_HAVE_LIBCURL_SSLLIB([OpenSSL], [openssl/ssl.h openssl/crypto.h], [ssl crypto])
                PECL_HAVE_LIBCURL_SSLLIB([GnuTLS], [gnutls.h gcrypt.h], [gnutls gcrypt])
                PECL_HAVE_LIBCURL_SSLLIB([NSS])
                PECL_HAVE_LIBCURL_SSLLIB([SecureTransport])
                PECL_HAVE_LIBCURL_SSLLIB([GSKit])
+               PECL_HAVE_LIBCURL_SSLLIB([PolarSSL])
+               PECL_HAVE_LIBCURL_SSLLIB([WolfSSL])
+               PECL_HAVE_LIBCURL_SSLLIB([mbedTLS])
+               PECL_HAVE_LIBCURL_SSLLIB([axTLS])
+
+               case "$PECL_VAR([LIBCURL_SSLLIB])" in
+               OpenSSL|GnuTLS|PolarSSL)
+                       PECL_DEFINE([HAVE_LIBCURL_CAPATH])
+                       PECL_DEFINE([HAVE_LIBCURL_CAINFO])
+                       ;;
+               NSS)
+                       AC_CACHE_CHECK([whether NSS PEM is available], [PECL_CACHE_VAR([HAVE_LIBCURL_NSSPEM])], [
+                               PECL_SAVE_ENV([LIBS], [NSSPEM])
+                               LIBS="$LIBS -lnsspem"
+                               AC_TRY_LINK([], [(void)0;], [
+                                       PECL_CACHE_VAR([HAVE_LIBCURL_NSSPEM])=yes
+                               ], [
+                                       PECL_CACHE_VAR([HAVE_LIBCURL_NSSPEM])=no
+                               ])
+                               PECL_RESTORE_ENV([LIBS], [NSSPEM])
+                       ])
+                       if $PECL_CACHE_VAR([HAVE_LIBCURL_NSSPEM]); then
+                               PECL_DEFINE([HAVE_LIBCURL_CAINFO])
+                       else
+                               PECL_DEFINE([HAVE_LIBCURL_CAINFO], [0])
+                       fi
+                       PECL_DEFINE([HAVE_LIBCURL_CAPATH], [0])
+                       ;;
+               *)
+                       PECL_DEFINE([HAVE_LIBCURL_CAPATH], [0])
+                       PECL_DEFINE([HAVE_LIBCURL_CAINFO], [0])
+                       ;;
+               esac
 
                PECL_HAVE_CONST([curl/curl.h], [CURLOPT_TLSAUTH_TYPE], int, [
-                       PECL_DEFINE([HAVE_LIBCURL_TLSAUTH_TYPE])
                        AC_CACHE_CHECK([whether CURLOPT_TLSAUTH_TYPE expects CURL_TLSAUTH_SRP], PECL_CACHE_VAR([LIBCURL_TLSAUTH_SRP]), [
                                PECL_CACHE_VAR([LIBCURL_TLSAUTH_SRP])=
                                AC_TRY_RUN([
@@ -113,6 +149,7 @@ AC_DEFUN([PECL_HAVE_LIBCURL_SSL], [
                                ])
                        ])
                        if test -n "$PECL_CACHE_VAR([LIBCURL_TLSAUTH_SRP])"; then
+                               PECL_DEFINE([HAVE_LIBCURL_TLSAUTH_TYPE])
                                if $PECL_CACHE_VAR([LIBCURL_TLSAUTH_SRP]); then
                                        PECL_DEFINE([LIBCURL_TLSAUTH_SRP], [CURL_TLSAUTH_SRP])
                                        PECL_DEFINE([LIBCURL_TLSAUTH_DEF], [CURL_TLSAUTH_NONE])
@@ -133,7 +170,7 @@ AC_DEFUN([PECL_HAVE_LIBCURL_ARES], [
                        #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) {
+                               if (data && data->ares && data->ares_num) {
                                        return 0;
                                }
                                return 1;
@@ -159,7 +196,7 @@ dnl
 AC_DEFUN([PECL_HAVE_LIBCURL_CA], [
        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/.*=//')
+               CURL_CONFIG_CA=$($CURL_CONFIG --configure | $EGREP -o -- "--with-ca@<:@^\'@:>@*" | $SED 's/.*=//')
        fi
        PECL_CHECK_CA($CURL_CONFIG_CA, $CURL_CONFIG_CA)
        PECL_VAR([LIBCURL_CAPATH])=$PECL_VAR([CAPATH])
@@ -181,8 +218,8 @@ AC_DEFUN([PECL_CHECK_LIBCURL], [dnl
        PECL_CHECK_CONFIG(libcurl, $CURL_CONFIG,
                [--version | $SED -e 's/@<:@^0-9\.@:>@//g'],
                [--cflags],
-               [--libs | $EGREP -o -- '(^|\s)-L@<:@^ @:>@* ?'],
-               [--libs | $EGREP -o -- '(^|\s)-l@<:@^ @:>@* ?']dnl
+               [--libs | $EGREP -o -- '(^|\s)-L@<:@^ @:>@* ?' | xargs],
+               [--libs | $EGREP -o -- '(^|\s)-l@<:@^ @:>@* ?' | xargs]dnl
        )
        ifelse([$2],,,[
                PECL_HAVE_VERSION([libcurl], [$2])
index e6cd792..6721e1c 100644 (file)
@@ -184,6 +184,7 @@ AC_DEFUN([PECL_HAVE_CONST], [dnl
                        #include "$1"
                ], [
                        ]ifelse([$3],,int,[$3])[ _c = $2;
+                       (void) _c;
                ], [
                        PECL_CACHE_VAR([HAVE_$1_$2])=yes
                ], [
@@ -253,7 +254,8 @@ AC_DEFUN([PECL_CHECK_CUSTOM], [
                CPPFLAGS="-I$PECL_CACHE_VAR([$1_prefix])/include"
                LDFLAGS="-L$PECL_CACHE_VAR([$1_prefix])/$PHP_LIBDIR"
                LIBS="-l$4"
-
+               PHP_EVAL_LIBLINE([$LDFLAGS $LIBS])
+               
                AC_CACHE_VAL(PECL_CACHE_VAR([$1_version]), [
                        pushd $PECL_CACHE_VAR([$1_prefix]) >/dev/null
                        PECL_CACHE_VAR([$1_version])=$5
@@ -309,6 +311,8 @@ AC_DEFUN([PECL_CHECK_CONFIG], [
                        PECL_CACHE_VAR([$1_libs])=$($2 $6)
                ])
                LIBS=$PECL_CACHE_VAR([$1_libs])
+               
+               PHP_EVAL_LIBLINE([$LDFLAGS $LIBS])
        ifelse($2, [$PKG_CONFIG $1], [
                fi
        ])
index ca39e93..1626b71 100644 (file)
@@ -1395,6 +1395,7 @@ static void php_http_curle_options_init(php_http_options_t *registry)
                php_http_option_register(registry, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS, _IS_BOOL);
 #endif
                        php_http_option_register(registry, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST, IS_STRING);
+#if PHP_HTTP_HAVE_LIBCURL_CAINFO
                        if ((opt = php_http_option_register(registry, ZEND_STRL("cainfo"), CURLOPT_CAINFO, IS_STRING))) {
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
@@ -1402,13 +1403,16 @@ static void php_http_curle_options_init(php_http_options_t *registry)
                        ZVAL_PSTRING(&opt->defval, PHP_HTTP_CAINFO);
 #endif
                        }
+#endif
+#if PHP_HTTP_HAVE_LIBCURL_CAPATH
                        if ((opt = php_http_option_register(registry, ZEND_STRL("capath"), CURLOPT_CAPATH, IS_STRING))) {
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
 #ifdef PHP_HTTP_CAPATH
                        ZVAL_PSTRING(&opt->defval, PHP_HTTP_CAPATH);
 #endif
-               }
+                       }
+#endif
                        if ((opt = php_http_option_register(registry, ZEND_STRL("random_file"), CURLOPT_RANDOM_FILE, IS_STRING))) {
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
                                opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;