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