summaryrefslogtreecommitdiff
blob: 2f3a7c73a2404790b59b44f2679fe199594c4c0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
diff --git a/autoconf/pecl/libbrotli.m4 b/autoconf/pecl/libbrotli.m4
index f8916e2..575f635 100644
--- a/autoconf/pecl/libbrotli.m4
+++ b/autoconf/pecl/libbrotli.m4
@@ -1,5 +1,11 @@
 
 AC_DEFUN([PECL_CHECK_LIBBROTLI], [
+	dnl config.m4 calls PECL_CHECK_DONE once more
+	PECL_COUNT_CHECKS([+1])
+	PECL_SAVE_ENV([CPPFLAGS], [libbrotli])
+	PECL_SAVE_ENV([LDFLAGS], [libbrotli])
+	PECL_SAVE_ENV([LIBS], [libbrotli])
+
 	PECL_CHECK_LIBBROTLI_COMMON([$1], [$2])
 	PECL_CHECK_DONE(libbrotlicommon, [$PECL_VAR([HAVE_LIBBROTLI_COMMON])])
 	PECL_CHECK_LIBBROTLI_DEC([$1], [$2])
diff --git a/autoconf/pecl/libcurl.m4 b/autoconf/pecl/libcurl.m4
index 4d99207..8de9499 100644
--- a/autoconf/pecl/libcurl.m4
+++ b/autoconf/pecl/libcurl.m4
@@ -160,6 +160,26 @@ AC_DEFUN([PECL_HAVE_LIBCURL_SSL], [dnl
 				fi
 			fi
 		])
+
+		PECL_HAVE_CONST([curl/curl.h], [CURL_LOCK_DATA_SSL_SESSION], int, [
+			AC_CACHE_CHECK([whether curl_share accepts CURL_LOCK_DATA_SSL_SESSION], PECL_CACHE_VAR([LIBCURL_SHARE_SSL]), [
+				PECL_CACHE_VAR([LIBCURL_SHARE_SSL])=
+				AC_TRY_RUN([
+					#include <curl/curl.h>
+					int main(int argc, char *argv[]) {
+						CURLSH *ch = curl_share_init();
+						return curl_share_setopt(ch, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
+					}
+				], [
+					PECL_CACHE_VAR([LIBCURL_SHARE_SSL])=yes
+				], [
+					PECL_CACHE_VAR([LIBCURL_SHARE_SSL])=no
+				])
+			])
+			if test "$PECL_CACHE_VAR([LIBCURL_SHARE_SSL])" = yes; then
+				PECL_DEFINE([HAVE_LIBCURL_SHARE_SSL], [1])
+			fi
+		])
 	])
 ])
 dnl
diff --git a/autoconf/pecl/pecl.m4 b/autoconf/pecl/pecl.m4
index ffa45ac..d8735b0 100644
--- a/autoconf/pecl/pecl.m4
+++ b/autoconf/pecl/pecl.m4
@@ -70,6 +70,12 @@ AC_DEFUN([PECL_RESTORE_ENV], [
 	$1=$PECL_SAVE_VAR([$2_$1])
 ])
 dnl
+dnl PECL_COUNT_CHECKS(incdec)
+dnl
+AC_DEFUN([PECL_COUNT_CHECKS], [
+	PECL_VAR([_checks])=$(($PECL_VAR([_checks])$1))
+])
+dnl
 dnl PECL_EVAL_LIBLINE(libline)
 dnl
 AC_DEFUN([PECL_EVAL_LIBLINE], [
@@ -244,6 +250,7 @@ dnl
 dnl PECL_CHECK_CUSTOM(name, path, header, lib, version)
 dnl
 AC_DEFUN([PECL_CHECK_CUSTOM], [
+	PECL_COUNT_CHECKS([+1])
 	PECL_SAVE_ENV([CPPFLAGS], [$1])
 	PECL_SAVE_ENV([LDFLAGS], [$1])
 	PECL_SAVE_ENV([LIBS], [$1])
@@ -260,10 +267,10 @@ AC_DEFUN([PECL_CHECK_CUSTOM], [
 		done
 	])
 	if test -n "$PECL_CACHE_VAR([$1_prefix])"; then
-		CPPFLAGS="-I$PECL_CACHE_VAR([$1_prefix])/include"
-		LDFLAGS="-L$PECL_CACHE_VAR([$1_prefix])/$PHP_LIBDIR"
-		LIBS="-l$4"
-		PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
+		CPPFLAGS="$CPPFLAGS -I$PECL_CACHE_VAR([$1_prefix])/include"
+		LDFLAGS="$LDFLAGS -L$PECL_CACHE_VAR([$1_prefix])/$PHP_LIBDIR"
+		LIBS="$LIBS -l$4"
+		dnl PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
 		
 		AC_CACHE_VAL(PECL_CACHE_VAR([$1_version]), [
 			pushd $PECL_CACHE_VAR([$1_prefix]) >/dev/null
@@ -288,11 +295,11 @@ dnl
 dnl PECL_CHECK_CONFIG(name, prog-config, version-flag, cppflags-flag, ldflags-flag, libs-flag)
 dnl
 AC_DEFUN([PECL_CHECK_CONFIG], [
+	PECL_COUNT_CHECKS([+1])
 	PECL_SAVE_ENV([CPPFLAGS], [$1])
 	PECL_SAVE_ENV([LDFLAGS], [$1])
 	PECL_SAVE_ENV([LIBS], [$1])
 
-
 	AC_MSG_CHECKING([for $1])
 	ifelse($2, [$PKG_CONFIG $1], [
 		AC_CACHE_VAL(PECL_CACHE_VAR([$1_exists]), [
@@ -311,20 +318,22 @@ AC_DEFUN([PECL_CHECK_CONFIG], [
 		AC_CACHE_VAL(PECL_CACHE_VAR([$1_cppflags]), [
 			PECL_CACHE_VAR([$1_cppflags])=$($2 $4)
 		])
-		CPPFLAGS=$PECL_CACHE_VAR([$1_cppflags])
+		CPPFLAGS="$CPPFLAGS $PECL_CACHE_VAR([$1_cppflags])"
 		AC_CACHE_VAL(PECL_CACHE_VAR([$1_ldflags]), [
 			PECL_CACHE_VAR([$1_ldflags])=$($2 $5)
 		])
-		LDFLAGS=$PECL_CACHE_VAR([$1_ldflags])
+		LDFLAGS="$LDFLAGS $PECL_CACHE_VAR([$1_ldflags])"
 		AC_CACHE_VAL(PECL_CACHE_VAR([$1_libs]), [
 			PECL_CACHE_VAR([$1_libs])=$($2 $6)
 		])
-		LIBS=$PECL_CACHE_VAR([$1_libs])
-		PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
+		LIBS="$LIBS $PECL_CACHE_VAR([$1_libs])"
+		dnl PECL_EVAL_LIBLINE([$LDFLAGS $LIBS])
 	ifelse($2, [$PKG_CONFIG $1], [
 		fi
 	])
 
+	AC_MSG_RESULT([${PECL_CHECKED_VERSION([$1]):-no}])
+
 	if test -n "$PECL_CHECKED_VERSION([$1])"; then
 		PECL_VAR([HAVE_$1])=true
 		PECL_DEFINE([HAVE_$1])
@@ -332,8 +341,6 @@ AC_DEFUN([PECL_CHECK_CONFIG], [
 	else
 		PECL_VAR([HAVE_$1])=false
 	fi
-
-	AC_MSG_RESULT([${PECL_CHECKED_VERSION([$1]):-no}])
 ])
 dnl
 dnl PECL_CHECK_PKGCONFIG(pkg[, additional-pkg-config-path])
@@ -355,9 +362,25 @@ dnl
 dnl PECL_CHECK_DONE(name, success[, incline, libline])
 dnl
 AC_DEFUN([PECL_CHECK_DONE], [
-	if $2; then
-		incline=$CPPFLAGS
-		libline="$LDFLAGS $LIBS"
+	PECL_COUNT_CHECKS([-1])
+	success=$2
+	if $success && test -n "$LDFLAGS$LIBS"; then
+		AC_MSG_CHECKING([whether $1 can be linked])
+		AC_TRY_LINK([], [], [success=yes], [success=no])
+		AC_MSG_RESULT([$success])
+		if ! $success; then
+			AC_MSG_WARN([$1 was found, but fails to link with:])
+			AC_MSG_WARN([    LDFLAGS='$LDFLAGS'])
+			AC_MSG_WARN([    LIBS='$LIBS'])
+			AC_MSG_WARN([Missing or updated library paths?])
+		fi
+	fi
+	if $success; then
+		_cppflags=$PECL_SAVE_VAR([$1_CPPFLAGS])
+		_ldflags=$PECL_SAVE_VAR([$1_LDFLAGS])
+		_libs=$PECL_SAVE_VAR([$1_LIBS])
+		incline=${CPPFLAGS:${#_cppflags}}
+		libline=["${LDFLAGS:${#_ldflags}} ${LIBS:${#_libs}}"]
 		PECL_DEFINE([HAVE_$1])
 	else
 		incline=$3
diff --git a/config9.m4 b/config9.m4
index ef7d33e..695701b 100644
--- a/config9.m4
+++ b/config9.m4
@@ -24,6 +24,8 @@ if test "$PHP_HTTP" != "no"; then
 		AC_CHECK_LIB(nsl, getdomainname)
 	])
 	AC_CHECK_FUNCS(mbrtowc mbtowc iswalnum inet_pton)
+
+	CFLAGS="$CFLAGS -Wno-strict-prototypes"
 
 	dnl ZLIB
 	PHP_ARG_WITH([http-zlib-dir], [whether/where to check for zlib],
diff --git a/src/php_http_client_curl.c b/src/php_http_client_curl.c
index 0e79f19..8898b5d 100644
--- a/src/php_http_client_curl.c
+++ b/src/php_http_client_curl.c
@@ -17,6 +17,8 @@
 
 #if PHP_HTTP_HAVE_LIBCURL
 
+#define DEBUG_COOKIES 0
+
 #if PHP_HTTP_HAVE_LIBCURL_OPENSSL
 #	include <openssl/ssl.h>
 #endif
@@ -834,6 +836,9 @@ static ZEND_RESULT_CODE php_http_curle_option_set_cookiesession(php_http_option_
 		return FAILURE;
 	}
 	if (Z_TYPE_P(val) == IS_TRUE) {
+#if DEBUG_COOKIES
+		fprintf(stderr, "CURLOPT_COOKIELIST: SESS\n");
+#endif
 		if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIELIST, "SESS")) {
 			return FAILURE;
 		}
@@ -856,9 +861,19 @@ static ZEND_RESULT_CODE php_http_curle_option_set_cookiestore(php_http_option_t
 	} else {
 		storage->cookiestore = NULL;
 	}
-	if (	CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEFILE, storage->cookiestore)
-		||	CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEJAR, storage->cookiestore)
-	) {
+
+#if DEBUG_COOKIES
+	fprintf(stderr, "CURLOPT_COOKIEFILE: %s\n", cookiestore);
+#endif
+	// does NOT enable ch->data.cookies until transfer; adds to ch->stsate.cookielist
+	if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEFILE, storage->cookiestore ? storage->cookiestore : "")) {
+		return FAILURE;
+	}
+#if DEBUG_COOKIES
+	fprintf(stderr, "CURLOPT_COOKIEJAR: %s\n", cookiestore);
+#endif
+	// enables ch->data.cookies
+	if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIEJAR, storage->cookiestore)) {
 		return FAILURE;
 	}
 
@@ -1919,7 +1934,7 @@ static ZEND_RESULT_CODE php_http_curlm_option_set_share_cookies(php_http_option_
 	return SUCCESS;
 }
 
-#if PHP_HTTP_CURL_VERSION(7,23,0)
+#if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
 static ZEND_RESULT_CODE php_http_curlm_option_set_share_ssl(php_http_option_t *opt, zval *value, void *userdata)
 {
 	php_http_client_t *client = userdata;
@@ -1994,7 +2009,7 @@ static void php_http_curlm_options_init(php_http_options_t *registry)
 		opt->setter = php_http_curlm_option_set_share_cookies;
 		ZVAL_TRUE(&opt->defval);
 	}
-#if PHP_HTTP_CURL_VERSION(7,23,0)
+#if PHP_HTTP_HAVE_LIBCURL_SHARE_SSL
 	if ((opt = php_http_option_register(registry, ZEND_STRL("share_ssl"), 0, _IS_BOOL))) {
 		opt->setter = php_http_curlm_option_set_share_ssl;
 		ZVAL_TRUE(&opt->defval);