code cleanup
[m6w6/ext-http] / php_http_curl_client.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-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 #define PHP_HTTP_CURL_OPT_STRING(OPTION, ldiff, obdc) \
16 { \
17 char *K = #OPTION; \
18 PHP_HTTP_CURL_OPT_STRING_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION, obdc); \
19 }
20 #define PHP_HTTP_CURL_OPT_STRING_EX(keyname, optname, obdc) \
21 if (!strcasecmp(key.str, keyname)) { \
22 zval *copy = cache_option(&curl->options.cache, keyname, strlen(keyname)+1, 0, php_http_ztyp(IS_STRING, *param)); \
23 if (obdc) { \
24 if (SUCCESS != php_check_open_basedir(Z_STRVAL_P(copy) TSRMLS_CC)) { \
25 return FAILURE; \
26 } \
27 } \
28 curl_easy_setopt(ch, optname, Z_STRVAL_P(copy)); \
29 zval_ptr_dtor(&copy); \
30 continue; \
31 }
32 #define PHP_HTTP_CURL_OPT_LONG(OPTION, ldiff) \
33 { \
34 char *K = #OPTION; \
35 PHP_HTTP_CURL_OPT_LONG_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION); \
36 }
37 #define PHP_HTTP_CURL_OPT_LONG_EX(keyname, optname) \
38 if (!strcasecmp(key.str, keyname)) { \
39 zval *copy = php_http_ztyp(IS_LONG, *param); \
40 curl_easy_setopt(ch, optname, Z_LVAL_P(copy)); \
41 zval_ptr_dtor(&copy); \
42 continue; \
43 }
44
45
46 /* resource_factory ops */
47
48 static void *php_http_curl_ctor(void *opaque TSRMLS_DC)
49 {
50 void *ch;
51
52 if ((ch = curl_easy_init())) {
53 get_storage(ch);
54 return ch;
55 }
56 return NULL;
57 }
58
59 static void *php_http_curl_copy(void *opaque, void *handle TSRMLS_DC)
60 {
61 void *ch;
62
63 if ((ch = curl_easy_duphandle(handle))) {
64 curl_easy_reset(ch);
65 get_storage(ch);
66 return ch;
67 }
68 return NULL;
69 }
70
71 static void php_http_curl_dtor(void *opaque, void *handle TSRMLS_DC)
72 {
73 php_http_curl_client_storage_t *st = get_storage(handle);
74
75 curl_easy_cleanup(handle);
76
77 if (st) {
78 if (st->url) {
79 pefree(st->url, 1);
80 }
81 if (st->cookiestore) {
82 pefree(st->cookiestore, 1);
83 }
84 pefree(st, 1);
85 }
86 }
87
88 /* callbacks */
89
90 static size_t php_http_curl_client_read_callback(void *data, size_t len, size_t n, void *ctx)
91 {
92 php_http_message_body_t *body = ctx;
93
94 if (body) {
95 TSRMLS_FETCH_FROM_CTX(body->ts);
96 return php_stream_read(php_http_message_body_stream(body), data, len * n);
97 }
98 return 0;
99 }
100
101 static int php_http_curl_client_progress_callback(void *ctx, double dltotal, double dlnow, double ultotal, double ulnow)
102 {
103 php_http_client_t *h = ctx;
104 php_http_curl_client_t *curl = h->ctx;
105 TSRMLS_FETCH_FROM_CTX(h->ts);
106
107 curl->progress.state.dl.total = dltotal;
108 curl->progress.state.dl.now = dlnow;
109 curl->progress.state.ul.total = ultotal;
110 curl->progress.state.ul.now = ulnow;
111
112 php_http_client_progress_notify(&curl->progress TSRMLS_CC);
113
114 return 0;
115 }
116
117 static curlioerr php_http_curl_client_ioctl_callback(CURL *ch, curliocmd cmd, void *ctx)
118 {
119 php_http_message_body_t *body = ctx;
120
121 if (cmd != CURLIOCMD_RESTARTREAD) {
122 return CURLIOE_UNKNOWNCMD;
123 }
124
125 if (body) {
126 TSRMLS_FETCH_FROM_CTX(body->ts);
127
128 if (SUCCESS == php_stream_rewind(php_http_message_body_stream(body))) {
129 return CURLIOE_OK;
130 }
131 }
132
133 return CURLIOE_FAILRESTART;
134 }
135
136 static int php_http_curl_client_raw_callback(CURL *ch, curl_infotype type, char *data, size_t length, void *ctx)
137 {
138 php_http_client_t *h = ctx;
139 php_http_curl_client_t *curl = h->ctx;
140 unsigned flags = 0;
141 TSRMLS_FETCH_FROM_CTX(h->ts);
142
143 /* catch progress */
144 switch (type) {
145 case CURLINFO_TEXT:
146 if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
147 curl->progress.state.info = "resolve";
148 } else if (php_memnstr(data, ZEND_STRL("Trying"), data + length)) {
149 curl->progress.state.info = "connect";
150 } else if (php_memnstr(data, ZEND_STRL("Connected"), data + length)) {
151 curl->progress.state.info = "connected";
152 } else if (php_memnstr(data, ZEND_STRL("left intact"), data + length)) {
153 curl->progress.state.info = "not disconnected";
154 } else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) {
155 curl->progress.state.info = "disconnected";
156 } else if (php_memnstr(data, ZEND_STRL("Issue another request"), data + length)) {
157 curl->progress.state.info = "redirect";
158 }
159 php_http_client_progress_notify(&curl->progress TSRMLS_CC);
160 break;
161 case CURLINFO_HEADER_OUT:
162 case CURLINFO_DATA_OUT:
163 case CURLINFO_SSL_DATA_OUT:
164 curl->progress.state.info = "send";
165 break;
166 case CURLINFO_HEADER_IN:
167 case CURLINFO_DATA_IN:
168 case CURLINFO_SSL_DATA_IN:
169 curl->progress.state.info = "receive";
170 break;
171 default:
172 break;
173 }
174 /* process data */
175 switch (type) {
176 case CURLINFO_HEADER_IN:
177 case CURLINFO_DATA_IN:
178 case CURLINFO_HEADER_OUT:
179 case CURLINFO_DATA_OUT:
180 php_http_buffer_append(h->buffer, data, length);
181
182 if (curl->options.redirects) {
183 flags |= PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS;
184 }
185
186 if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse(h->parser, h->buffer, flags, &h->message)) {
187 return -1;
188 }
189 break;
190 default:
191 break;
192 }
193
194 #if 0
195 /* debug */
196 _dpf(type, data, length);
197 #endif
198
199 return 0;
200 }
201
202 static int php_http_curl_client_dummy_callback(char *data, size_t n, size_t l, void *s)
203 {
204 return n*l;
205 }
206
207 static inline zval *cache_option(HashTable *cache, char *key, size_t keylen, ulong h, zval *opt)
208 {
209 Z_ADDREF_P(opt);
210
211 if (h) {
212 zend_hash_quick_update(cache, key, keylen, h, &opt, sizeof(zval *), NULL);
213 } else {
214 zend_hash_update(cache, key, keylen, &opt, sizeof(zval *), NULL);
215 }
216
217 return opt;
218 }
219
220 static inline zval *get_option(HashTable *cache, HashTable *options, char *key, size_t keylen, int type)
221 {
222 if (options) {
223 zval **zoption;
224 ulong h = zend_hash_func(key, keylen);
225
226 if (SUCCESS == zend_hash_quick_find(options, key, keylen, h, (void *) &zoption)) {
227 zval *option = php_http_ztyp(type, *zoption);
228
229 if (cache) {
230 zval *cached = cache_option(cache, key, keylen, h, option);
231
232 zval_ptr_dtor(&option);
233 return cached;
234 }
235 return option;
236 }
237 }
238
239 return NULL;
240 }
241
242 static STATUS set_options(php_http_client_t *h, HashTable *options)
243 {
244 zval *zoption;
245 php_http_curl_client_t *curl = h->ctx;
246 CURL *ch = curl->handle;
247 TSRMLS_FETCH_FROM_CTX(h->ts);
248
249 /* proxy */
250 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxyhost"), IS_STRING))) {
251 curl_easy_setopt(ch, CURLOPT_PROXY, Z_STRVAL_P(zoption));
252 }
253 /* type */
254 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxytype"), IS_LONG))) {
255 curl_easy_setopt(ch, CURLOPT_PROXYTYPE, Z_LVAL_P(zoption));
256 }
257 /* port */
258 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxyport"), IS_LONG))) {
259 curl_easy_setopt(ch, CURLOPT_PROXYPORT, Z_LVAL_P(zoption));
260 }
261 /* user:pass */
262 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxyauth"), IS_STRING)) && Z_STRLEN_P(zoption)) {
263 curl_easy_setopt(ch, CURLOPT_PROXYUSERPWD, Z_STRVAL_P(zoption));
264 }
265 /* auth method */
266 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxyauthtype"), IS_LONG))) {
267 curl_easy_setopt(ch, CURLOPT_PROXYAUTH, Z_LVAL_P(zoption));
268 }
269 /* tunnel */
270 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("proxytunnel"), IS_BOOL)) && Z_BVAL_P(zoption)) {
271 curl_easy_setopt(ch, CURLOPT_HTTPPROXYTUNNEL, 1L);
272 }
273 #if PHP_HTTP_CURL_VERSION(7,19,4)
274 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("noproxy"), IS_STRING))) {
275 curl_easy_setopt(ch, CURLOPT_NOPROXY, Z_STRVAL_P(zoption));
276 }
277 #endif
278
279 /* dns */
280 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("dns_cache_timeout"), IS_LONG))) {
281 curl_easy_setopt(ch, CURLOPT_DNS_CACHE_TIMEOUT, Z_LVAL_P(zoption));
282 }
283 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("ipresolve"), IS_LONG)) && Z_LVAL_P(zoption)) {
284 curl_easy_setopt(ch, CURLOPT_IPRESOLVE, Z_LVAL_P(zoption));
285 }
286 #if PHP_HTTP_CURL_VERSION(7,21,3)
287 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("resolve"), IS_ARRAY))) {
288 php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
289 HashPosition pos;
290 zval **data;
291
292 FOREACH_KEYVAL(pos, zoption, key, data) {
293 zval *cpy = php_http_ztyp(IS_STRING, *data);
294
295 curl->options.resolve = curl_slist_append(curl->options.resolve, Z_STRVAL_P(cpy));
296
297 zval_ptr_dtor(&cpy);
298 }
299
300 curl_easy_setopt(ch, CURLOPT_RESOLVE, curl->options.resolve);
301 }
302 #endif
303 #if PHP_HTTP_CURL_VERSION(7,24,0)
304 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("dns_servers"), IS_STRING)) && Z_STRLEN_P(zoption)) {
305 curl_easy_setopt(ch, CURLOPT_DNS_SERVERS, Z_STRVAL_P(zoption));
306 }
307 #endif
308
309 /* limits */
310 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("low_speed_limit"), IS_LONG))) {
311 curl_easy_setopt(ch, CURLOPT_LOW_SPEED_LIMIT, Z_LVAL_P(zoption));
312 }
313 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("low_speed_time"), IS_LONG))) {
314 curl_easy_setopt(ch, CURLOPT_LOW_SPEED_TIME, Z_LVAL_P(zoption));
315 }
316 /* LSF weirdance
317 if ((zoption = get_option(&curl->cache.options, options, ZEND_STRS("max_send_speed"), IS_LONG))) {
318 curl_easy_setopt(ch, CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
319 }
320 if ((zoption = get_option(&curl->cache.options, options, ZEND_STRS("max_recv_speed"), IS_LONG))) {
321 curl_easy_setopt(ch, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
322 }
323 */
324 /* crashes
325 if ((zoption = get_option(&curl->cache.options, options, ZEND_STRS("maxconnects"), IS_LONG))) {
326 curl_easy_setopt(ch, CURLOPT_MAXCONNECTS, Z_LVAL_P(zoption));
327 } */
328 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("fresh_connect"), IS_BOOL)) && Z_BVAL_P(zoption)) {
329 curl_easy_setopt(ch, CURLOPT_FRESH_CONNECT, 1L);
330 }
331 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("forbid_reuse"), IS_BOOL)) && Z_BVAL_P(zoption)) {
332 curl_easy_setopt(ch, CURLOPT_FORBID_REUSE, 1L);
333 }
334
335 /* outgoing interface */
336 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("interface"), IS_STRING))) {
337 curl_easy_setopt(ch, CURLOPT_INTERFACE, Z_STRVAL_P(zoption));
338 }
339 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("portrange"), IS_ARRAY))) {
340 zval **prs, **pre;
341
342 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption));
343 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &prs)) {
344 zend_hash_move_forward(Z_ARRVAL_P(zoption));
345 if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &pre)) {
346 zval *prs_cpy = php_http_ztyp(IS_LONG, *prs);
347 zval *pre_cpy = php_http_ztyp(IS_LONG, *pre);
348
349 if (Z_LVAL_P(prs_cpy) && Z_LVAL_P(pre_cpy)) {
350 curl_easy_setopt(ch, CURLOPT_LOCALPORT, MIN(Z_LVAL_P(prs_cpy), Z_LVAL_P(pre_cpy)));
351 curl_easy_setopt(ch, CURLOPT_LOCALPORTRANGE, labs(Z_LVAL_P(prs_cpy)-Z_LVAL_P(pre_cpy))+1L);
352 }
353 zval_ptr_dtor(&prs_cpy);
354 zval_ptr_dtor(&pre_cpy);
355 }
356 }
357 }
358
359 /* another port */
360 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("port"), IS_LONG))) {
361 curl_easy_setopt(ch, CURLOPT_PORT, Z_LVAL_P(zoption));
362 }
363
364 /* RFC4007 zone_id */
365 #if PHP_HTTP_CURL_VERSION(7,19,0)
366 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("address_scope"), IS_LONG))) {
367 curl_easy_setopt(ch, CURLOPT_ADDRESS_SCOPE, Z_LVAL_P(zoption));
368 }
369 #endif
370
371 /* auth */
372 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("httpauth"), IS_STRING)) && Z_STRLEN_P(zoption)) {
373 curl_easy_setopt(ch, CURLOPT_USERPWD, Z_STRVAL_P(zoption));
374 }
375 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("httpauthtype"), IS_LONG))) {
376 curl_easy_setopt(ch, CURLOPT_HTTPAUTH, Z_LVAL_P(zoption));
377 }
378
379 /* redirects, defaults to 0 */
380 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("redirect"), IS_LONG))) {
381 curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1L : 0L);
382 curl_easy_setopt(ch, CURLOPT_MAXREDIRS, curl->options.redirects = Z_LVAL_P(zoption));
383 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("unrestrictedauth"), IS_BOOL))) {
384 curl_easy_setopt(ch, CURLOPT_UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
385 }
386 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("postredir"), IS_BOOL))) {
387 #if PHP_HTTP_CURL_VERSION(7,19,1)
388 curl_easy_setopt(ch, CURLOPT_POSTREDIR, Z_BVAL_P(zoption) ? 1L : 0L);
389 #else
390 curl_easy_setopt(ch, CURLOPT_POST301, Z_BVAL_P(zoption) ? 1L : 0L);
391 #endif
392 }
393 }
394
395 /* retries, defaults to 0 */
396 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("retrycount"), IS_LONG))) {
397 curl->options.retry.count = Z_LVAL_P(zoption);
398 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("retrydelay"), IS_DOUBLE))) {
399 curl->options.retry.delay = Z_DVAL_P(zoption);
400 }
401 }
402
403 /* referer */
404 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("referer"), IS_STRING)) && Z_STRLEN_P(zoption)) {
405 curl_easy_setopt(ch, CURLOPT_REFERER, Z_STRVAL_P(zoption));
406 }
407
408 /* useragent, default "PECL::HTTP/version (PHP/version)" */
409 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("useragent"), IS_STRING))) {
410 /* allow to send no user agent, not even default one */
411 if (Z_STRLEN_P(zoption)) {
412 curl_easy_setopt(ch, CURLOPT_USERAGENT, Z_STRVAL_P(zoption));
413 } else {
414 curl_easy_setopt(ch, CURLOPT_USERAGENT, NULL);
415 }
416 }
417
418 /* resume */
419 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("resume"), IS_LONG)) && (Z_LVAL_P(zoption) > 0)) {
420 curl->options.range_request = 1;
421 curl_easy_setopt(ch, CURLOPT_RESUME_FROM, Z_LVAL_P(zoption));
422 }
423 /* or range of kind array(array(0,499), array(100,1499)) */
424 else if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("range"), IS_ARRAY)) && zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
425 HashPosition pos1, pos2;
426 zval **rr, **rb, **re;
427 php_http_buffer_t rs;
428
429 php_http_buffer_init(&rs);
430 FOREACH_VAL(pos1, zoption, rr) {
431 if (Z_TYPE_PP(rr) == IS_ARRAY) {
432 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(rr), &pos2);
433 if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void *) &rb, &pos2)) {
434 zend_hash_move_forward_ex(Z_ARRVAL_PP(rr), &pos2);
435 if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void *) &re, &pos2)) {
436 if ( ((Z_TYPE_PP(rb) == IS_LONG) || ((Z_TYPE_PP(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(rb), Z_STRLEN_PP(rb), NULL, NULL, 1))) &&
437 ((Z_TYPE_PP(re) == IS_LONG) || ((Z_TYPE_PP(re) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(re), Z_STRLEN_PP(re), NULL, NULL, 1)))) {
438 zval *rbl = php_http_ztyp(IS_LONG, *rb);
439 zval *rel = php_http_ztyp(IS_LONG, *re);
440
441 if ((Z_LVAL_P(rbl) >= 0) && (Z_LVAL_P(rel) >= 0)) {
442 php_http_buffer_appendf(&rs, "%ld-%ld,", Z_LVAL_P(rbl), Z_LVAL_P(rel));
443 }
444 zval_ptr_dtor(&rbl);
445 zval_ptr_dtor(&rel);
446 }
447 }
448 }
449 }
450 }
451
452 if (PHP_HTTP_BUFFER_LEN(&rs)) {
453 zval *cached_range;
454
455 curl->options.range_request = 1;
456 /* ditch last comma */
457 PHP_HTTP_BUFFER_VAL(&rs)[PHP_HTTP_BUFFER_LEN(&rs)-- -1] = '\0';
458 /* cache string */
459 MAKE_STD_ZVAL(cached_range);
460 ZVAL_STRINGL(cached_range, PHP_HTTP_BUFFER_VAL(&rs), PHP_HTTP_BUFFER_LEN(&rs), 0);
461 curl_easy_setopt(ch, CURLOPT_RANGE, Z_STRVAL_P(cache_option(&curl->options.cache, ZEND_STRS("range"), 0, cached_range)));
462 zval_ptr_dtor(&cached_range);
463 }
464 }
465
466 /* etag */
467 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("etag"), IS_STRING)) && Z_STRLEN_P(zoption)) {
468 zend_bool is_quoted = !((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"'));
469 php_http_buffer_t header;
470
471 php_http_buffer_init(&header);
472 php_http_buffer_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", curl->options.range_request?"If-Match":"If-None-Match", Z_STRVAL_P(zoption));
473 php_http_buffer_fix(&header);
474 curl->options.headers = curl_slist_append(curl->options.headers, PHP_HTTP_BUFFER_VAL(&header));
475 php_http_buffer_dtor(&header);
476 }
477 /* compression */
478 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("compress"), IS_BOOL)) && Z_LVAL_P(zoption)) {
479 curl->options.headers = curl_slist_append(curl->options.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5");
480 }
481 curl_easy_setopt(ch, CURLOPT_HTTPHEADER, curl->options.headers);
482
483 /* lastmodified */
484 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("lastmodified"), IS_LONG))) {
485 if (Z_LVAL_P(zoption)) {
486 if (Z_LVAL_P(zoption) > 0) {
487 curl_easy_setopt(ch, CURLOPT_TIMEVALUE, Z_LVAL_P(zoption));
488 } else {
489 curl_easy_setopt(ch, CURLOPT_TIMEVALUE, (long) PHP_HTTP_G->env.request.time + Z_LVAL_P(zoption));
490 }
491 curl_easy_setopt(ch, CURLOPT_TIMECONDITION, (long) (curl->options.range_request ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE));
492 } else {
493 curl_easy_setopt(ch, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
494 }
495 }
496
497 /* cookies, array('name' => 'value') */
498 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("cookies"), IS_ARRAY))) {
499 if (zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
500 zval *urlenc_cookies = NULL;
501 /* check whether cookies should not be urlencoded; default is to urlencode them */
502 if ((!(urlenc_cookies = get_option(&curl->options.cache, options, ZEND_STRS("encodecookies"), IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
503 if (SUCCESS == php_http_url_encode_hash_ex(HASH_OF(zoption), &curl->options.cookies, ZEND_STRL(";"), ZEND_STRL("="), NULL, 0 TSRMLS_CC)) {
504 php_http_buffer_fix(&curl->options.cookies);
505 curl_easy_setopt(ch, CURLOPT_COOKIE, curl->options.cookies.data);
506 }
507 } else {
508 HashPosition pos;
509 php_http_array_hashkey_t cookie_key = php_http_array_hashkey_init(0);
510 zval **cookie_val;
511
512 FOREACH_KEYVAL(pos, zoption, cookie_key, cookie_val) {
513 if (cookie_key.type == HASH_KEY_IS_STRING) {
514 zval *val = php_http_ztyp(IS_STRING, *cookie_val);
515 php_http_buffer_appendf(&curl->options.cookies, "%s=%s; ", cookie_key.str, Z_STRVAL_P(val));
516 zval_ptr_dtor(&val);
517 }
518 }
519
520 php_http_buffer_fix(&curl->options.cookies);
521 if (PHP_HTTP_BUFFER_LEN(&curl->options.cookies)) {
522 curl_easy_setopt(ch, CURLOPT_COOKIE, PHP_HTTP_BUFFER_VAL(&curl->options.cookies));
523 }
524 }
525 }
526 }
527
528 /* don't load session cookies from cookiestore */
529 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("cookiesession"), IS_BOOL)) && Z_BVAL_P(zoption)) {
530 curl_easy_setopt(ch, CURLOPT_COOKIESESSION, 1L);
531 }
532
533 /* cookiestore, read initial cookies from that file and store cookies back into that file */
534 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("cookiestore"), IS_STRING))) {
535 php_http_curl_client_storage_t *storage = get_storage(curl->handle);
536
537 if (Z_STRLEN_P(zoption)) {
538 if (SUCCESS != php_check_open_basedir(Z_STRVAL_P(zoption) TSRMLS_CC)) {
539 return FAILURE;
540 }
541 }
542 if (storage->cookiestore) {
543 pefree(storage->cookiestore, 1);
544 }
545 storage->cookiestore = pestrndup(Z_STRVAL_P(zoption), Z_STRLEN_P(zoption), 1);
546 curl_easy_setopt(ch, CURLOPT_COOKIEFILE, storage->cookiestore);
547 curl_easy_setopt(ch, CURLOPT_COOKIEJAR, storage->cookiestore);
548 }
549
550 /* maxfilesize */
551 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("maxfilesize"), IS_LONG))) {
552 curl_easy_setopt(ch, CURLOPT_MAXFILESIZE, Z_LVAL_P(zoption));
553 }
554
555 /* http protocol */
556 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("protocol"), IS_LONG))) {
557 curl_easy_setopt(ch, CURLOPT_HTTP_VERSION, Z_LVAL_P(zoption));
558 }
559
560 /* timeout, defaults to 0 */
561 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("timeout"), IS_DOUBLE))) {
562 curl_easy_setopt(ch, CURLOPT_TIMEOUT_MS, (long)(Z_DVAL_P(zoption)*1000));
563 }
564 /* connecttimeout, defaults to 0 */
565 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("connecttimeout"), IS_DOUBLE))) {
566 curl_easy_setopt(ch, CURLOPT_CONNECTTIMEOUT_MS, (long)(Z_DVAL_P(zoption)*1000));
567 }
568
569 /* ssl */
570 if ((zoption = get_option(&curl->options.cache, options, ZEND_STRS("ssl"), IS_ARRAY))) {
571 php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
572 zval **param;
573 HashPosition pos;
574
575 FOREACH_KEYVAL(pos, zoption, key, param) {
576 if (key.type == HASH_KEY_IS_STRING) {
577 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLCERT, 0, 1);
578 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLCERTTYPE, 0, 0);
579 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLCERTPASSWD, 0, 0);
580
581 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLKEY, 0, 0);
582 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLKEYTYPE, 0, 0);
583 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLKEYPASSWD, 0, 0);
584
585 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSLENGINE, 0, 0);
586 PHP_HTTP_CURL_OPT_LONG(CURLOPT_SSLVERSION, 0);
587
588 PHP_HTTP_CURL_OPT_LONG(CURLOPT_SSL_VERIFYPEER, 1);
589 PHP_HTTP_CURL_OPT_LONG(CURLOPT_SSL_VERIFYHOST, 1);
590 PHP_HTTP_CURL_OPT_STRING(CURLOPT_SSL_CIPHER_LIST, 1, 0);
591
592 PHP_HTTP_CURL_OPT_STRING(CURLOPT_CAINFO, -3, 1);
593 PHP_HTTP_CURL_OPT_STRING(CURLOPT_CAPATH, -3, 1);
594 PHP_HTTP_CURL_OPT_STRING(CURLOPT_RANDOM_FILE, -3, 1);
595 PHP_HTTP_CURL_OPT_STRING(CURLOPT_EGDSOCKET, -3, 1);
596 #if PHP_HTTP_CURL_VERSION(7,19,0)
597 PHP_HTTP_CURL_OPT_STRING(CURLOPT_ISSUERCERT, -3, 1);
598 #if defined(PHP_HTTP_HAVE_OPENSSL)
599 PHP_HTTP_CURL_OPT_STRING(CURLOPT_CRLFILE, -3, 1);
600 #endif
601 #endif
602 #if PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)
603 PHP_HTTP_CURL_OPT_LONG(CURLOPT_CERTINFO, -3);
604 #endif
605 }
606 }
607 }
608 return SUCCESS;
609 }
610
611 static STATUS get_info(CURL *ch, HashTable *info)
612 {
613 char *c;
614 long l;
615 double d;
616 struct curl_slist *s, *p;
617 zval *subarray, array;
618 INIT_PZVAL_ARRAY(&array, info);
619
620 /* BEGIN::CURLINFO */
621 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_EFFECTIVE_URL, &c)) {
622 add_assoc_string_ex(&array, "effective_url", sizeof("effective_url"), c ? c : "", 1);
623 }
624 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_RESPONSE_CODE, &l)) {
625 add_assoc_long_ex(&array, "response_code", sizeof("response_code"), l);
626 }
627 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_TOTAL_TIME, &d)) {
628 add_assoc_double_ex(&array, "total_time", sizeof("total_time"), d);
629 }
630 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_NAMELOOKUP_TIME, &d)) {
631 add_assoc_double_ex(&array, "namelookup_time", sizeof("namelookup_time"), d);
632 }
633 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONNECT_TIME, &d)) {
634 add_assoc_double_ex(&array, "connect_time", sizeof("connect_time"), d);
635 }
636 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRETRANSFER_TIME, &d)) {
637 add_assoc_double_ex(&array, "pretransfer_time", sizeof("pretransfer_time"), d);
638 }
639 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SIZE_UPLOAD, &d)) {
640 add_assoc_double_ex(&array, "size_upload", sizeof("size_upload"), d);
641 }
642 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SIZE_DOWNLOAD, &d)) {
643 add_assoc_double_ex(&array, "size_download", sizeof("size_download"), d);
644 }
645 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SPEED_DOWNLOAD, &d)) {
646 add_assoc_double_ex(&array, "speed_download", sizeof("speed_download"), d);
647 }
648 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SPEED_UPLOAD, &d)) {
649 add_assoc_double_ex(&array, "speed_upload", sizeof("speed_upload"), d);
650 }
651 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_HEADER_SIZE, &l)) {
652 add_assoc_long_ex(&array, "header_size", sizeof("header_size"), l);
653 }
654 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REQUEST_SIZE, &l)) {
655 add_assoc_long_ex(&array, "request_size", sizeof("request_size"), l);
656 }
657 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SSL_VERIFYRESULT, &l)) {
658 add_assoc_long_ex(&array, "ssl_verifyresult", sizeof("ssl_verifyresult"), l);
659 }
660 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_FILETIME, &l)) {
661 add_assoc_long_ex(&array, "filetime", sizeof("filetime"), l);
662 }
663 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
664 add_assoc_double_ex(&array, "content_length_download", sizeof("content_length_download"), d);
665 }
666 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONTENT_LENGTH_UPLOAD, &d)) {
667 add_assoc_double_ex(&array, "content_length_upload", sizeof("content_length_upload"), d);
668 }
669 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_STARTTRANSFER_TIME, &d)) {
670 add_assoc_double_ex(&array, "starttransfer_time", sizeof("starttransfer_time"), d);
671 }
672 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONTENT_TYPE, &c)) {
673 add_assoc_string_ex(&array, "content_type", sizeof("content_type"), c ? c : "", 1);
674 }
675 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REDIRECT_TIME, &d)) {
676 add_assoc_double_ex(&array, "redirect_time", sizeof("redirect_time"), d);
677 }
678 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REDIRECT_COUNT, &l)) {
679 add_assoc_long_ex(&array, "redirect_count", sizeof("redirect_count"), l);
680 }
681 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_HTTP_CONNECTCODE, &l)) {
682 add_assoc_long_ex(&array, "connect_code", sizeof("connect_code"), l);
683 }
684 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_HTTPAUTH_AVAIL, &l)) {
685 add_assoc_long_ex(&array, "httpauth_avail", sizeof("httpauth_avail"), l);
686 }
687 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PROXYAUTH_AVAIL, &l)) {
688 add_assoc_long_ex(&array, "proxyauth_avail", sizeof("proxyauth_avail"), l);
689 }
690 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_OS_ERRNO, &l)) {
691 add_assoc_long_ex(&array, "os_errno", sizeof("os_errno"), l);
692 }
693 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_NUM_CONNECTS, &l)) {
694 add_assoc_long_ex(&array, "num_connects", sizeof("num_connects"), l);
695 }
696 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SSL_ENGINES, &s)) {
697 MAKE_STD_ZVAL(subarray);
698 array_init(subarray);
699 for (p = s; p; p = p->next) {
700 if (p->data) {
701 add_next_index_string(subarray, p->data, 1);
702 }
703 }
704 add_assoc_zval_ex(&array, "ssl_engines", sizeof("ssl_engines"), subarray);
705 curl_slist_free_all(s);
706 }
707 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_COOKIELIST, &s)) {
708 MAKE_STD_ZVAL(subarray);
709 array_init(subarray);
710 for (p = s; p; p = p->next) {
711 if (p->data) {
712 add_next_index_string(subarray, p->data, 1);
713 }
714 }
715 add_assoc_zval_ex(&array, "cookies", sizeof("cookies"), subarray);
716 curl_slist_free_all(s);
717 }
718 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REDIRECT_URL, &c)) {
719 add_assoc_string_ex(&array, "redirect_url", sizeof("redirect_url"), c ? c : "", 1);
720 }
721 #if PHP_HTTP_CURL_VERSION(7,19,0)
722 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRIMARY_IP, &c)) {
723 add_assoc_string_ex(&array, "primary_ip", sizeof("primary_ip"), c ? c : "", 1);
724 }
725 #endif
726 #if PHP_HTTP_CURL_VERSION(7,19,0)
727 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_APPCONNECT_TIME, &d)) {
728 add_assoc_double_ex(&array, "appconnect_time", sizeof("appconnect_time"), d);
729 }
730 #endif
731 #if PHP_HTTP_CURL_VERSION(7,19,4)
732 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONDITION_UNMET, &l)) {
733 add_assoc_long_ex(&array, "condition_unmet", sizeof("condition_unmet"), l);
734 }
735 #endif
736 #if PHP_HTTP_CURL_VERSION(7,21,0)
737 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRIMARY_PORT, &l)) {
738 add_assoc_long_ex(&array, "primary_port", sizeof("primary_port"), l);
739 }
740 #endif
741 #if PHP_HTTP_CURL_VERSION(7,21,0)
742 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_LOCAL_IP, &c)) {
743 add_assoc_string_ex(&array, "local_ip", sizeof("local_ip"), c ? c : "", 1);
744 }
745 #endif
746 #if PHP_HTTP_CURL_VERSION(7,21,0)
747 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_LOCAL_PORT, &l)) {
748 add_assoc_long_ex(&array, "local_port", sizeof("local_port"), l);
749 }
750 #endif
751
752 /* END::CURLINFO */
753
754 #if PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)
755 {
756 int i;
757 zval *ci_array;
758 struct curl_certinfo *ci;
759 char *colon, *keyname;
760
761 if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CERTINFO, &ci)) {
762 MAKE_STD_ZVAL(ci_array);
763 array_init(ci_array);
764
765 for (i = 0; i < ci->num_of_certs; ++i) {
766 s = ci->certinfo[i];
767
768 MAKE_STD_ZVAL(subarray);
769 array_init(subarray);
770 for (p = s; p; p = p->next) {
771 if (p->data) {
772 if ((colon = strchr(p->data, ':'))) {
773 keyname = estrndup(p->data, colon - p->data);
774 add_assoc_string_ex(subarray, keyname, colon - p->data + 1, colon + 1, 1);
775 efree(keyname);
776 } else {
777 add_next_index_string(subarray, p->data, 1);
778 }
779 }
780 }
781 add_next_index_zval(ci_array, subarray);
782 }
783 add_assoc_zval_ex(&array, "certinfo", sizeof("certinfo"), ci_array);
784 }
785 }
786 #endif
787 add_assoc_string_ex(&array, "error", sizeof("error"), get_storage(ch)->errorbuffer, 1);
788
789 return SUCCESS;
790 }
791
792
793 /* request handler ops */
794
795 static STATUS php_http_curl_client_reset(php_http_client_t *h);
796
797 static php_http_client_t *php_http_curl_client_init(php_http_client_t *h, void *handle)
798 {
799 php_http_curl_client_t *ctx;
800 TSRMLS_FETCH_FROM_CTX(h->ts);
801
802 if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) {
803 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "could not initialize curl handle");
804 return NULL;
805 }
806
807 ctx = ecalloc(1, sizeof(*ctx));
808 ctx->handle = handle;
809 php_http_buffer_init(&ctx->options.cookies);
810 zend_hash_init(&ctx->options.cache, 0, NULL, ZVAL_PTR_DTOR, 0);
811 h->ctx = ctx;
812
813 #if defined(ZTS)
814 curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
815 #endif
816 curl_easy_setopt(handle, CURLOPT_HEADER, 0L);
817 curl_easy_setopt(handle, CURLOPT_FILETIME, 1L);
818 curl_easy_setopt(handle, CURLOPT_AUTOREFERER, 1L);
819 curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L);
820 curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
821 curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, NULL);
822 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, php_http_curl_client_dummy_callback);
823 curl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, php_http_curl_client_raw_callback);
824 curl_easy_setopt(handle, CURLOPT_READFUNCTION, php_http_curl_client_read_callback);
825 curl_easy_setopt(handle, CURLOPT_IOCTLFUNCTION, php_http_curl_client_ioctl_callback);
826 curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, php_http_curl_client_progress_callback);
827 curl_easy_setopt(handle, CURLOPT_DEBUGDATA, h);
828 curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, h);
829
830 php_http_curl_client_reset(h);
831
832 return h;
833 }
834
835 static php_http_client_t *php_http_curl_client_copy(php_http_client_t *from, php_http_client_t *to)
836 {
837 php_http_curl_client_t *ctx = from->ctx;
838 void *copy;
839 TSRMLS_FETCH_FROM_CTX(from->ts);
840
841 if (!(copy = php_http_resource_factory_handle_copy(from->rf, ctx->handle TSRMLS_CC))) {
842 return NULL;
843 }
844
845 if (to) {
846 return php_http_curl_client_init(to, copy);
847 } else {
848 return php_http_client_init(NULL, from->ops, from->rf, copy TSRMLS_CC);
849 }
850 }
851
852 static void php_http_curl_client_dtor(php_http_client_t *h)
853 {
854 php_http_curl_client_t *ctx = h->ctx;
855 TSRMLS_FETCH_FROM_CTX(h->ts);
856
857 curl_easy_setopt(ctx->handle, CURLOPT_NOPROGRESS, 1L);
858 curl_easy_setopt(ctx->handle, CURLOPT_PROGRESSFUNCTION, NULL);
859 curl_easy_setopt(ctx->handle, CURLOPT_VERBOSE, 0L);
860 curl_easy_setopt(ctx->handle, CURLOPT_DEBUGFUNCTION, NULL);
861
862 php_http_resource_factory_handle_dtor(h->rf, ctx->handle TSRMLS_CC);
863
864 php_http_buffer_dtor(&ctx->options.cookies);
865 zend_hash_destroy(&ctx->options.cache);
866
867 if (ctx->options.headers) {
868 curl_slist_free_all(ctx->options.headers);
869 ctx->options.headers = NULL;
870 }
871 php_http_client_progress_dtor(&ctx->progress TSRMLS_CC);
872
873 efree(ctx);
874 h->ctx = NULL;
875 }
876 static STATUS php_http_curl_client_reset(php_http_client_t *h)
877 {
878 php_http_curl_client_t *curl = h->ctx;
879 CURL *ch = curl->handle;
880 php_http_curl_client_storage_t *st;
881
882 if ((st = get_storage(ch))) {
883 if (st->url) {
884 pefree(st->url, 1);
885 st->url = NULL;
886 }
887 if (st->cookiestore) {
888 pefree(st->cookiestore, 1);
889 st->cookiestore = NULL;
890 }
891 st->errorbuffer[0] = '\0';
892 }
893
894 curl_easy_setopt(ch, CURLOPT_URL, NULL);
895 #if PHP_HTTP_CURL_VERSION(7,19,4)
896 curl_easy_setopt(ch, CURLOPT_NOPROXY, NULL);
897 #endif
898 curl_easy_setopt(ch, CURLOPT_PROXY, NULL);
899 curl_easy_setopt(ch, CURLOPT_PROXYPORT, 0L);
900 curl_easy_setopt(ch, CURLOPT_PROXYTYPE, 0L);
901 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
902 #if PHP_HTTP_CURL_VERSION(7,19,1)
903 curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, NULL);
904 curl_easy_setopt(ch, CURLOPT_PROXYPASSWORD, NULL);
905 #endif
906 curl_easy_setopt(ch, CURLOPT_PROXYAUTH, 0L);
907 curl_easy_setopt(ch, CURLOPT_HTTPPROXYTUNNEL, 0L);
908 curl_easy_setopt(ch, CURLOPT_DNS_CACHE_TIMEOUT, 60L);
909 curl_easy_setopt(ch, CURLOPT_IPRESOLVE, 0);
910 #if PHP_HTTP_CURL_VERSION(7,21,3)
911 curl_easy_setopt(ch, CURLOPT_RESOLVE, NULL);
912 #endif
913 #if PHP_HTTP_CURL_VERSION(7,24,0)
914 curl_easy_setopt(ch, CURLOPT_DNS_SERVERS, NULL);
915 #endif
916 curl_easy_setopt(ch, CURLOPT_LOW_SPEED_LIMIT, 0L);
917 curl_easy_setopt(ch, CURLOPT_LOW_SPEED_TIME, 0L);
918 /* LFS weirdance
919 curl_easy_setopt(ch, CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) 0);
920 curl_easy_setopt(ch, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) 0);
921 */
922 /* crashes
923 curl_easy_setopt(ch, CURLOPT_MAXCONNECTS, 5L); */
924 curl_easy_setopt(ch, CURLOPT_FRESH_CONNECT, 0L);
925 curl_easy_setopt(ch, CURLOPT_FORBID_REUSE, 0L);
926 curl_easy_setopt(ch, CURLOPT_INTERFACE, NULL);
927 curl_easy_setopt(ch, CURLOPT_PORT, 0L);
928 #if PHP_HTTP_CURL_VERSION(7,19,0)
929 curl_easy_setopt(ch, CURLOPT_ADDRESS_SCOPE, 0L);
930 #endif
931 curl_easy_setopt(ch, CURLOPT_LOCALPORT, 0L);
932 curl_easy_setopt(ch, CURLOPT_LOCALPORTRANGE, 0L);
933 /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
934 #if PHP_HTTP_CURL_VERSION(7,19,1)
935 curl_easy_setopt(ch, CURLOPT_USERNAME, NULL);
936 curl_easy_setopt(ch, CURLOPT_PASSWORD, NULL);
937 #endif
938 curl_easy_setopt(ch, CURLOPT_HTTPAUTH, 0L);
939 curl_easy_setopt(ch, CURLOPT_ENCODING, NULL);
940 /* we do this ourself anyway */
941 curl_easy_setopt(ch, CURLOPT_HTTP_CONTENT_DECODING, 0L);
942 curl_easy_setopt(ch, CURLOPT_HTTP_TRANSFER_DECODING, 0L);
943 curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 0L);
944 #if PHP_HTTP_CURL_VERSION(7,19,1)
945 curl_easy_setopt(ch, CURLOPT_POSTREDIR, 0L);
946 #else
947 curl_easy_setopt(ch, CURLOPT_POST301, 0L);
948 #endif
949 curl_easy_setopt(ch, CURLOPT_UNRESTRICTED_AUTH, 0L);
950 curl_easy_setopt(ch, CURLOPT_REFERER, NULL);
951 curl_easy_setopt(ch, CURLOPT_USERAGENT, "PECL::HTTP/" PHP_HTTP_EXT_VERSION " (PHP/" PHP_VERSION ")");
952 curl_easy_setopt(ch, CURLOPT_HTTPHEADER, NULL);
953 curl_easy_setopt(ch, CURLOPT_COOKIE, NULL);
954 curl_easy_setopt(ch, CURLOPT_COOKIESESSION, 0L);
955 /* these options would enable curl's cookie engine by default which we don't want
956 curl_easy_setopt(ch, CURLOPT_COOKIEFILE, NULL);
957 curl_easy_setopt(ch, CURLOPT_COOKIEJAR, NULL); */
958 curl_easy_setopt(ch, CURLOPT_COOKIELIST, NULL);
959 curl_easy_setopt(ch, CURLOPT_RANGE, NULL);
960 curl_easy_setopt(ch, CURLOPT_RESUME_FROM, 0L);
961 curl_easy_setopt(ch, CURLOPT_MAXFILESIZE, 0L);
962 curl_easy_setopt(ch, CURLOPT_TIMECONDITION, 0L);
963 curl_easy_setopt(ch, CURLOPT_TIMEVALUE, 0L);
964 curl_easy_setopt(ch, CURLOPT_TIMEOUT, 0L);
965 curl_easy_setopt(ch, CURLOPT_CONNECTTIMEOUT, 3);
966 curl_easy_setopt(ch, CURLOPT_SSLCERT, NULL);
967 curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, NULL);
968 curl_easy_setopt(ch, CURLOPT_SSLCERTPASSWD, NULL);
969 curl_easy_setopt(ch, CURLOPT_SSLKEY, NULL);
970 curl_easy_setopt(ch, CURLOPT_SSLKEYTYPE, NULL);
971 curl_easy_setopt(ch, CURLOPT_SSLKEYPASSWD, NULL);
972 curl_easy_setopt(ch, CURLOPT_SSLENGINE, NULL);
973 curl_easy_setopt(ch, CURLOPT_SSLVERSION, 0L);
974 curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 0L);
975 curl_easy_setopt(ch, CURLOPT_SSL_VERIFYHOST, 0L);
976 curl_easy_setopt(ch, CURLOPT_SSL_CIPHER_LIST, NULL);
977 #if PHP_HTTP_CURL_VERSION(7,19,0)
978 curl_easy_setopt(ch, CURLOPT_ISSUERCERT, NULL);
979 #if defined(PHP_HTTP_HAVE_OPENSSL)
980 curl_easy_setopt(ch, CURLOPT_CRLFILE, NULL);
981 #endif
982 #endif
983 #if PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)
984 curl_easy_setopt(ch, CURLOPT_CERTINFO, NULL);
985 #endif
986 #ifdef PHP_HTTP_CURL_CAINFO
987 curl_easy_setopt(ch, CURLOPT_CAINFO, PHP_HTTP_CURL_CAINFO);
988 #else
989 curl_easy_setopt(ch, CURLOPT_CAINFO, NULL);
990 #endif
991 curl_easy_setopt(ch, CURLOPT_CAPATH, NULL);
992 curl_easy_setopt(ch, CURLOPT_RANDOM_FILE, NULL);
993 curl_easy_setopt(ch, CURLOPT_EGDSOCKET, NULL);
994 curl_easy_setopt(ch, CURLOPT_POSTFIELDS, NULL);
995 curl_easy_setopt(ch, CURLOPT_POSTFIELDSIZE, 0L);
996 curl_easy_setopt(ch, CURLOPT_HTTPPOST, NULL);
997 curl_easy_setopt(ch, CURLOPT_IOCTLDATA, NULL);
998 curl_easy_setopt(ch, CURLOPT_READDATA, NULL);
999 curl_easy_setopt(ch, CURLOPT_INFILESIZE, 0L);
1000 curl_easy_setopt(ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
1001 curl_easy_setopt(ch, CURLOPT_CUSTOMREQUEST, NULL);
1002 curl_easy_setopt(ch, CURLOPT_NOBODY, 0L);
1003 curl_easy_setopt(ch, CURLOPT_POST, 0L);
1004 curl_easy_setopt(ch, CURLOPT_UPLOAD, 0L);
1005 curl_easy_setopt(ch, CURLOPT_HTTPGET, 1L);
1006
1007 #if PHP_HTTP_CURL_VERSION(7,21,3)
1008 if (curl->options.resolve) {
1009 curl_slist_free_all(curl->options.resolve);
1010 curl->options.resolve = NULL;
1011 }
1012 #endif
1013 curl->options.retry.count = 0;
1014 curl->options.retry.delay = 0;
1015 curl->options.redirects = 0;
1016
1017 if (curl->options.headers) {
1018 curl_slist_free_all(curl->options.headers);
1019 curl->options.headers = NULL;
1020 }
1021
1022 php_http_buffer_reset(&curl->options.cookies);
1023
1024 return SUCCESS;
1025 }
1026
1027 PHP_HTTP_API STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_message_t *msg)
1028 {
1029 size_t body_size;
1030 php_http_curl_client_t *curl = h->ctx;
1031 php_http_curl_client_storage_t *storage = get_storage(curl->handle);
1032 TSRMLS_FETCH_FROM_CTX(h->ts);
1033
1034 /* request url */
1035 if (!PHP_HTTP_INFO(msg).request.url) {
1036 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Cannot request empty URL");
1037 return FAILURE;
1038 }
1039 storage->errorbuffer[0] = '\0';
1040 if (storage->url) {
1041 pefree(storage->url, 1);
1042 }
1043 storage->url = pestrdup(PHP_HTTP_INFO(msg).request.url, 1);
1044 curl_easy_setopt(curl->handle, CURLOPT_URL, storage->url);
1045
1046 /* request method */
1047 switch (php_http_select_str(PHP_HTTP_INFO(msg).request.method, 4, "GET", "HEAD", "POST", "PUT")) {
1048 case 0:
1049 curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L);
1050 break;
1051
1052 case 1:
1053 curl_easy_setopt(curl->handle, CURLOPT_NOBODY, 1L);
1054 break;
1055
1056 case 2:
1057 curl_easy_setopt(curl->handle, CURLOPT_POST, 1L);
1058 break;
1059
1060 case 3:
1061 curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L);
1062 break;
1063
1064 default: {
1065 if (PHP_HTTP_INFO(msg).request.method) {
1066 curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, PHP_HTTP_INFO(msg).request.method);
1067 } else {
1068 php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Cannot use empty request method");
1069 return FAILURE;
1070 }
1071 break;
1072 }
1073 }
1074
1075 /* request headers */
1076 if (zend_hash_num_elements(&msg->hdrs)) {
1077 php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0);
1078 zval **header_val;
1079 HashPosition pos;
1080 php_http_buffer_t header;
1081
1082 php_http_buffer_init(&header);
1083 FOREACH_HASH_KEYVAL(pos, &msg->hdrs, header_key, header_val) {
1084 if (header_key.type == HASH_KEY_IS_STRING) {
1085 zval *header_cpy = php_http_ztyp(IS_STRING, *header_val);
1086
1087 php_http_buffer_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
1088 php_http_buffer_fix(&header);
1089 curl->options.headers = curl_slist_append(curl->options.headers, PHP_HTTP_BUFFER_VAL(&header));
1090 php_http_buffer_reset(&header);
1091
1092 zval_ptr_dtor(&header_cpy);
1093 }
1094 }
1095 php_http_buffer_dtor(&header);
1096 curl_easy_setopt(curl->handle, CURLOPT_HTTPHEADER, curl->options.headers);
1097 }
1098
1099 /* attach request body */
1100 if ((body_size = php_http_message_body_size(&msg->body))) {
1101 /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
1102 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
1103 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
1104 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
1105 * does not allow a request body.
1106 */
1107 php_stream_rewind(php_http_message_body_stream(&msg->body));
1108 curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, &msg->body);
1109 curl_easy_setopt(curl->handle, CURLOPT_READDATA, &msg->body);
1110 curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
1111 curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
1112 }
1113
1114 return SUCCESS;
1115 }
1116
1117 static STATUS php_http_curl_client_exec(php_http_client_t *h, php_http_message_t *msg)
1118 {
1119 uint tries = 0;
1120 CURLcode result;
1121 php_http_curl_client_t *curl = h->ctx;
1122 php_http_curl_client_storage_t *storage = get_storage(curl->handle);
1123 TSRMLS_FETCH_FROM_CTX(h->ts);
1124
1125 if (SUCCESS != php_http_curl_client_prepare(h, msg)) {
1126 return FAILURE;
1127 }
1128
1129 retry:
1130 if (CURLE_OK != (result = curl_easy_perform(curl->handle))) {
1131 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "%s; %s (%s)", curl_easy_strerror(result), storage->errorbuffer, storage->url);
1132
1133 if (EG(exception)) {
1134 add_property_long(EG(exception), "curlCode", result);
1135 }
1136
1137 if (curl->options.retry.count > tries++) {
1138 switch (result) {
1139 case CURLE_COULDNT_RESOLVE_PROXY:
1140 case CURLE_COULDNT_RESOLVE_HOST:
1141 case CURLE_COULDNT_CONNECT:
1142 case CURLE_WRITE_ERROR:
1143 case CURLE_READ_ERROR:
1144 case CURLE_OPERATION_TIMEDOUT:
1145 case CURLE_SSL_CONNECT_ERROR:
1146 case CURLE_GOT_NOTHING:
1147 case CURLE_SSL_ENGINE_SETFAILED:
1148 case CURLE_SEND_ERROR:
1149 case CURLE_RECV_ERROR:
1150 case CURLE_SSL_ENGINE_INITFAILED:
1151 case CURLE_LOGIN_DENIED:
1152 if (curl->options.retry.delay >= PHP_HTTP_DIFFSEC) {
1153 php_http_sleep(curl->options.retry.delay);
1154 }
1155 goto retry;
1156 default:
1157 break;
1158 }
1159 } else {
1160 return FAILURE;
1161 }
1162 }
1163
1164 return SUCCESS;
1165 }
1166
1167 static STATUS php_http_curl_client_setopt(php_http_client_t *h, php_http_client_setopt_opt_t opt, void *arg)
1168 {
1169 php_http_curl_client_t *curl = h->ctx;
1170 TSRMLS_FETCH_FROM_CTX(h->ts);
1171
1172 switch (opt) {
1173 case PHP_HTTP_CLIENT_OPT_SETTINGS:
1174 return set_options(h, arg);
1175 break;
1176
1177 case PHP_HTTP_CLIENT_OPT_PROGRESS_CALLBACK:
1178 if (curl->progress.in_cb) {
1179 php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Cannot change progress callback while executing it");
1180 return FAILURE;
1181 }
1182 if (curl->progress.callback) {
1183 php_http_client_progress_dtor(&curl->progress TSRMLS_CC);
1184 }
1185 curl->progress.callback = arg;
1186 break;
1187
1188 case PHP_HTTP_CLIENT_OPT_COOKIES_ENABLE:
1189 /* are cookies already enabled anyway? */
1190 if (!get_storage(curl->handle)->cookiestore) {
1191 if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_COOKIEFILE, "")) {
1192 return FAILURE;
1193 }
1194 }
1195 break;
1196
1197 case PHP_HTTP_CLIENT_OPT_COOKIES_RESET:
1198 if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_COOKIELIST, "ALL")) {
1199 return FAILURE;
1200 }
1201 break;
1202
1203 case PHP_HTTP_CLIENT_OPT_COOKIES_RESET_SESSION:
1204 if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_COOKIELIST, "SESS")) {
1205 return FAILURE;
1206 }
1207 break;
1208
1209 case PHP_HTTP_CLIENT_OPT_COOKIES_FLUSH:
1210 if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_COOKIELIST, "FLUSH")) {
1211 return FAILURE;
1212 }
1213 break;
1214
1215 default:
1216 return FAILURE;
1217 }
1218
1219 return SUCCESS;
1220 }
1221
1222 static STATUS php_http_curl_client_getopt(php_http_client_t *h, php_http_client_getopt_opt_t opt, void *arg)
1223 {
1224 php_http_curl_client_t *curl = h->ctx;
1225
1226 switch (opt) {
1227 case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO:
1228 *((php_http_client_progress_t **) arg) = &curl->progress;
1229 break;
1230
1231 case PHP_HTTP_CLIENT_OPT_TRANSFER_INFO:
1232 get_info(curl->handle, arg);
1233 break;
1234
1235 default:
1236 return FAILURE;
1237 }
1238
1239 return SUCCESS;
1240 }
1241
1242 static php_http_resource_factory_ops_t php_http_curl_client_resource_factory_ops = {
1243 php_http_curl_ctor,
1244 php_http_curl_copy,
1245 php_http_curl_dtor
1246 };
1247
1248 static php_http_client_ops_t php_http_curl_client_ops = {
1249 &php_http_curl_client_resource_factory_ops,
1250 php_http_curl_client_init,
1251 php_http_curl_client_copy,
1252 php_http_curl_client_dtor,
1253 php_http_curl_client_reset,
1254 php_http_curl_client_exec,
1255 php_http_curl_client_setopt,
1256 php_http_curl_client_getopt,
1257 (php_http_new_t) php_http_curl_client_object_new_ex,
1258 php_http_curl_client_get_class_entry
1259 };
1260
1261 PHP_HTTP_API php_http_client_ops_t *php_http_curl_client_get_ops(void)
1262 {
1263 return &php_http_curl_client_ops;
1264 }
1265
1266
1267 #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpClientCURL, method, 0, req_args)
1268 #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpClientCURL, method, 0)
1269 #define PHP_HTTP_CURL_CLIENT_ME(method, visibility) PHP_ME(HttpClientCURL, method, PHP_HTTP_ARGS(HttpClientCURL, method), visibility)
1270 #define PHP_HTTP_CURL_CLIENT_CLIENT_MALIAS(me, vis) ZEND_FENTRY(me, ZEND_MN(HttpClient_##me), PHP_HTTP_ARGS(HttpClientCURL, me), vis)
1271
1272 PHP_HTTP_BEGIN_ARGS(send, 1)
1273 PHP_HTTP_ARG_VAL(request, 0)
1274 PHP_HTTP_END_ARGS;
1275
1276 static zend_class_entry *php_http_curl_client_class_entry;
1277
1278 zend_class_entry *php_http_curl_client_get_class_entry(void)
1279 {
1280 return php_http_curl_client_class_entry;
1281 }
1282
1283 static zend_function_entry php_http_curl_client_method_entry[] = {
1284 PHP_HTTP_CURL_CLIENT_CLIENT_MALIAS(send, ZEND_ACC_PUBLIC)
1285 EMPTY_FUNCTION_ENTRY
1286 };
1287
1288 zend_object_value php_http_curl_client_object_new(zend_class_entry *ce TSRMLS_DC)
1289 {
1290 return php_http_curl_client_object_new_ex(ce, NULL, NULL TSRMLS_CC);
1291 }
1292
1293 zend_object_value php_http_curl_client_object_new_ex(zend_class_entry *ce, php_http_client_t *r, php_http_client_object_t **ptr TSRMLS_DC)
1294 {
1295 zend_object_value ov;
1296 php_http_client_object_t *o;
1297
1298 o = ecalloc(1, sizeof(php_http_client_object_t));
1299 zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
1300 object_properties_init((zend_object *) o, ce);
1301
1302 if (!(o->client = r)) {
1303 o->client = php_http_client_init(NULL, &php_http_curl_client_ops, NULL, NULL TSRMLS_CC);
1304 }
1305
1306 if (ptr) {
1307 *ptr = o;
1308 }
1309
1310 ov.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC);
1311 ov.handlers = php_http_client_get_object_handlers();
1312
1313 return ov;
1314 }
1315
1316
1317 PHP_MINIT_FUNCTION(http_curl_client)
1318 {
1319 if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_client.curl"), &php_http_curl_client_resource_factory_ops, NULL, NULL)) {
1320 return FAILURE;
1321 }
1322
1323 PHP_HTTP_REGISTER_CLASS(http\\Curl, Client, http_curl_client, php_http_client_get_class_entry(), 0);
1324 php_http_curl_client_class_entry->create_object = php_http_curl_client_object_new;
1325
1326 /*
1327 * HTTP Protocol Version Constants
1328 */
1329 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("HTTP_VERSION_1_0"), CURL_HTTP_VERSION_1_0 TSRMLS_CC);
1330 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("HTTP_VERSION_1_1"), CURL_HTTP_VERSION_1_1 TSRMLS_CC);
1331 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("HTTP_VERSION_NONE"), CURL_HTTP_VERSION_NONE TSRMLS_CC); /* to be removed */
1332 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("HTTP_VERSION_ANY"), CURL_HTTP_VERSION_NONE TSRMLS_CC);
1333
1334 /*
1335 * SSL Version Constants
1336 */
1337 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("SSL_VERSION_TLSv1"), CURL_SSLVERSION_TLSv1 TSRMLS_CC);
1338 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("SSL_VERSION_SSLv2"), CURL_SSLVERSION_SSLv2 TSRMLS_CC);
1339 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("SSL_VERSION_SSLv3"), CURL_SSLVERSION_SSLv3 TSRMLS_CC);
1340 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("SSL_VERSION_ANY"), CURL_SSLVERSION_DEFAULT TSRMLS_CC);
1341
1342 /*
1343 * DNS IPvX resolving
1344 */
1345 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("IPRESOLVE_V4"), CURL_IPRESOLVE_V4 TSRMLS_CC);
1346 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("IPRESOLVE_V6"), CURL_IPRESOLVE_V6 TSRMLS_CC);
1347 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("IPRESOLVE_ANY"), CURL_IPRESOLVE_WHATEVER TSRMLS_CC);
1348
1349 /*
1350 * Auth Constants
1351 */
1352 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("AUTH_BASIC"), CURLAUTH_BASIC TSRMLS_CC);
1353 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("AUTH_DIGEST"), CURLAUTH_DIGEST TSRMLS_CC);
1354 #if PHP_HTTP_CURL_VERSION(7,19,3)
1355 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("AUTH_DIGEST_IE"), CURLAUTH_DIGEST_IE TSRMLS_CC);
1356 #endif
1357 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("AUTH_NTLM"), CURLAUTH_NTLM TSRMLS_CC);
1358 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("AUTH_GSSNEG"), CURLAUTH_GSSNEGOTIATE TSRMLS_CC);
1359 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("AUTH_ANY"), CURLAUTH_ANY TSRMLS_CC);
1360
1361 /*
1362 * Proxy Type Constants
1363 */
1364 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("PROXY_SOCKS4"), CURLPROXY_SOCKS4 TSRMLS_CC);
1365 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("PROXY_SOCKS4A"), CURLPROXY_SOCKS5 TSRMLS_CC);
1366 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("PROXY_SOCKS5_HOSTNAME"), CURLPROXY_SOCKS5 TSRMLS_CC);
1367 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("PROXY_SOCKS5"), CURLPROXY_SOCKS5 TSRMLS_CC);
1368 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("PROXY_HTTP"), CURLPROXY_HTTP TSRMLS_CC);
1369 # if PHP_HTTP_CURL_VERSION(7,19,4)
1370 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("PROXY_HTTP_1_0"), CURLPROXY_HTTP_1_0 TSRMLS_CC);
1371 # endif
1372
1373 /*
1374 * Post Redirection Constants
1375 */
1376 #if PHP_HTTP_CURL_VERSION(7,19,1)
1377 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("POSTREDIR_301"), CURL_REDIR_POST_301 TSRMLS_CC);
1378 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("POSTREDIR_302"), CURL_REDIR_POST_302 TSRMLS_CC);
1379 zend_declare_class_constant_long(php_http_curl_client_class_entry, ZEND_STRL("POSTREDIR_ALL"), CURL_REDIR_POST_ALL TSRMLS_CC);
1380 #endif
1381
1382 return SUCCESS;
1383 }
1384
1385 /*
1386 * Local variables:
1387 * tab-width: 4
1388 * c-basic-offset: 4
1389 * End:
1390 * vim600: noet sw=4 ts=4 fdm=marker
1391 * vim<600: noet sw=4 ts=4
1392 */