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