-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ext_curl.cpp
1653 lines (1466 loc) · 56.7 KB
/
ext_curl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
| Copyright (c) 1997-2010 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/ext/curl/ext_curl.h"
#include "hphp/runtime/ext/curl/curl-multi-await.h"
#include "hphp/runtime/ext/curl/curl-multi-resource.h"
#include "hphp/runtime/ext/curl/curl-pool.h"
#include "hphp/runtime/ext/curl/curl-resource.h"
#include "hphp/runtime/ext/curl/curl-share-resource.h"
#include "hphp/runtime/ext/asio/socket-event.h"
#include "hphp/runtime/base/array-init.h"
#include "hphp/runtime/base/array-iterator.h"
#include "hphp/runtime/base/builtin-functions.h"
#include "hphp/runtime/base/file-util.h"
#include "hphp/runtime/base/plain-file.h"
#include "hphp/runtime/base/string-buffer.h"
#include "hphp/runtime/base/string-util.h"
#include "hphp/runtime/base/req-ptr.h"
#include "hphp/runtime/base/libevent-http-client.h"
#include "hphp/runtime/base/runtime-option.h"
#include "hphp/runtime/base/stack-logger.h"
#include "hphp/runtime/ext/extension-registry.h"
#include "hphp/runtime/server/server-stats.h"
#include "hphp/runtime/vm/jit/translator-inline.h"
#include "hphp/util/compatibility.h"
#include "hphp/util/lock.h"
#include <boost/algorithm/string.hpp>
#include <boost/variant.hpp>
#include <folly/Optional.h>
#include <folly/portability/OpenSSL.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <curl/multi.h>
#include <memory>
#include <vector>
#define CURLOPT_MUTE -2
#define CURLOPT_PASSWDFUNCTION -3
namespace HPHP {
using std::string;
using std::vector;
///////////////////////////////////////////////////////////////////////////////
#define CHECK_RESOURCE(curl) \
auto curl = dyn_cast_or_null<CurlResource>(ch); \
if (curl == nullptr) { \
raise_warning("supplied argument is not a valid cURL handle resource"); \
return false; \
} \
#define CHECK_RESOURCE_RETURN_VOID(curl) \
auto curl = dyn_cast_or_null<CurlResource>(ch); \
if (curl == nullptr) { \
raise_warning("supplied argument is not a valid cURL handle resource"); \
return; \
} \
Variant HHVM_FUNCTION(curl_init, const Variant& url /* = null_string */) {
if (url.isNull()) {
return Variant(req::make<CurlResource>(null_string));
} else {
return Variant(req::make<CurlResource>(url.toString()));
}
}
Variant HHVM_FUNCTION(curl_init_pooled,
const String& poolName,
const Variant& url /* = null_string */)
{
CurlHandlePoolPtr pool;
{
std::string cppPoolName = poolName.toCppString();
ReadLock lock(CurlHandlePool::namedPoolsMutex);
bool poolExists = (CurlHandlePool::namedPools.find(cppPoolName) !=
CurlHandlePool::namedPools.end());
if (!poolExists) {
raise_warning("Attempting to use connection pooling without "
"specifying an existent connection pool!");
return false;
}
pool = CurlHandlePool::namedPools.at(cppPoolName);
}
if (url.isNull()) {
return Variant(req::make<CurlResource>(null_string, pool));
} else {
return Variant(req::make<CurlResource>(url.toString(), pool));
}
}
void HHVM_FUNCTION(curl_create_pool, const String& poolName,
int size /* = 5 */, int connGetTimeout /* = 5000 */,
int reuseLimit /* = 500 */) {
auto hp = std::make_shared<CurlHandlePool>(size, connGetTimeout, reuseLimit);
WriteLock lock(CurlHandlePool::namedPoolsMutex);
CurlHandlePool::namedPools[poolName.toCppString()] = hp;
}
bool HHVM_FUNCTION(curl_destroy_pool, const String& poolName) {
WriteLock lock(CurlHandlePool::namedPoolsMutex);
return CurlHandlePool::namedPools.erase(poolName.toCppString()) > 0;
}
const StaticString
s_size("size"),
s_connGetTimeout("connGetTimeout"),
s_reuseLimit("reuseLimit"),
s_stats("stats"),
s_fetches("fetches"),
s_empty("empty"),
s_fetchMs("fetchMs");
Array HHVM_FUNCTION(curl_list_pools) {
ReadLock lock(CurlHandlePool::namedPoolsMutex);
auto size = CurlHandlePool::namedPools.size();
if (!size) return empty_dict_array();
DArrayInit ret(size);
for (auto it: CurlHandlePool::namedPools) {
auto pool = it.second;
auto stats = make_darray(
s_fetches, pool->statsFetches(),
s_empty, pool->statsEmpty(),
s_fetchMs, pool->statsFetchUs() / 1000
);
ret.set(String(it.first), make_darray(s_size, pool->size(),
s_connGetTimeout,
pool->connGetTimeout(),
s_reuseLimit,
pool->reuseLimit(),
s_stats, stats));
}
return ret.toArray();
}
Variant HHVM_FUNCTION(curl_copy_handle, const Resource& ch) {
CHECK_RESOURCE(curl);
return Variant(req::make<CurlResource>(curl));
}
const StaticString
s_version_number("version_number"),
s_age("age"),
s_features("features"),
s_ssl_version_number("ssl_version_number"),
s_version("version"),
s_host("host"),
s_ssl_version("ssl_version"),
s_libz_version("libz_version"),
s_protocols("protocols");
Variant HHVM_FUNCTION(curl_version, int uversion /* = CURLVERSION_NOW */) {
curl_version_info_data *d = curl_version_info((CURLversion)uversion);
if (d == nullptr) {
return false;
}
ArrayInit ret(9, ArrayInit::Map{});
ret.set(s_version_number, (int)d->version_num);
ret.set(s_age, d->age);
ret.set(s_features, d->features);
ret.set(s_ssl_version_number, d->ssl_version_num);
ret.set(s_version, d->version);
ret.set(s_host, d->host);
ret.set(s_ssl_version, d->ssl_version);
ret.set(s_libz_version, d->libz_version);
// Add an array of protocols
char **p = (char **) d->protocols;
Array protocol_list;
while (*p != nullptr) {
protocol_list.append(String(*p++, CopyString));
}
ret.set(s_protocols, protocol_list);
return ret.toVariant();
}
bool HHVM_FUNCTION(curl_setopt, const Resource& ch, int option, const Variant& value) {
CHECK_RESOURCE(curl);
return curl->setOption(option, value);
}
bool HHVM_FUNCTION(curl_setopt_array, const Resource& ch, const Array& options) {
CHECK_RESOURCE(curl);
for (ArrayIter iter(options); iter; ++iter) {
if (!curl->setOption(iter.first().toInt32(), iter.second())) {
return false;
}
}
return true;
}
Variant HHVM_FUNCTION(fb_curl_getopt, const Resource& ch, int64_t opt /* = 0 */) {
CHECK_RESOURCE(curl);
return curl->getOption(opt);
}
Variant HHVM_FUNCTION(curl_exec, const Resource& ch) {
CHECK_RESOURCE(curl);
return curl->execute();
}
#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
Array create_certinfo(struct curl_certinfo *ci) {
Array ret = Array::CreateVec();
if (ci) {
for (int i = 0; i < ci->num_of_certs; i++) {
struct curl_slist *slist = ci->certinfo[i];
Array certData = Array::CreateDict();
while (slist) {
Array parts = StringUtil::Explode(
String(slist->data, CopyString),
":",
2).toArray();
if (parts.size() == 2) {
certData.set(parts.lookup(0), parts.lookup(1));
} else {
raise_warning("Could not extract hash key from certificate info");
}
slist = slist->next;
}
ret.append(certData);
}
}
return ret;
}
#endif
const StaticString
s_url("url"),
s_content_type("content_type"),
s_http_code("http_code"),
s_header_size("header_size"),
s_request_size("request_size"),
s_filetime("filetime"),
s_ssl_verify_result("ssl_verify_result"),
s_redirect_count("redirect_count"),
s_total_time("total_time"),
s_namelookup_time("namelookup_time"),
s_connect_time("connect_time"),
s_pretransfer_time("pretransfer_time"),
s_size_upload("size_upload"),
s_size_download("size_download"),
s_speed_download("speed_download"),
s_speed_upload("speed_upload"),
s_download_content_length("download_content_length"),
s_upload_content_length("upload_content_length"),
s_starttransfer_time("starttransfer_time"),
s_redirect_time("redirect_time"),
s_redirect_url("redirect_url"),
s_primary_ip("primary_ip"),
s_primary_port("primary_port"),
s_local_ip("local_ip"),
s_local_port("local_port"),
s_certinfo("certinfo"),
s_request_header("request_header");
Variant HHVM_FUNCTION(curl_getinfo, const Resource& ch, int opt /* = 0 */) {
CHECK_RESOURCE(curl);
CURL *cp = curl->get();
if (opt == 0) {
char *s_code;
long l_code;
double d_code;
#if LIBCURL_VERSION_NUM > 0x071301 /* Available since 7.19.1 */
struct curl_certinfo *ci = nullptr;
#endif
Array ret;
if (curl_easy_getinfo(cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) {
ret.set(s_url, String(s_code, CopyString));
}
if (curl_easy_getinfo(cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) {
if (s_code != nullptr) {
ret.set(s_content_type, String(s_code, CopyString));
} else {
ret.set(s_content_type, init_null());
}
}
if (curl_easy_getinfo(cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) {
ret.set(s_http_code, l_code);
}
if (curl_easy_getinfo(cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) {
ret.set(s_header_size, l_code);
}
if (curl_easy_getinfo(cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) {
ret.set(s_request_size, l_code);
}
if (curl_easy_getinfo(cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) {
ret.set(s_filetime, l_code);
}
if (curl_easy_getinfo(cp, CURLINFO_SSL_VERIFYRESULT, &l_code) ==
CURLE_OK) {
ret.set(s_ssl_verify_result, l_code);
}
if (curl_easy_getinfo(cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) {
ret.set(s_redirect_count, l_code);
}
if (curl_easy_getinfo(cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) {
ret.set(s_total_time, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) {
ret.set(s_namelookup_time, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) {
ret.set(s_connect_time, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_PRETRANSFER_TIME, &d_code) ==
CURLE_OK) {
ret.set(s_pretransfer_time, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) {
ret.set(s_size_upload, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
ret.set(s_size_download, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
ret.set(s_speed_download, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) {
ret.set(s_speed_upload, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) ==
CURLE_OK) {
ret.set(s_download_content_length, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) ==
CURLE_OK) {
ret.set(s_upload_content_length, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_STARTTRANSFER_TIME, &d_code) ==
CURLE_OK) {
ret.set(s_starttransfer_time, d_code);
}
if (curl_easy_getinfo(cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
ret.set(s_redirect_time, d_code);
}
#if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
if (curl_easy_getinfo(cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) {
ret.set(s_redirect_url, String(s_code, CopyString));
}
#endif
#if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
if (curl_easy_getinfo(cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) {
ret.set(s_primary_ip, String(s_code, CopyString));
}
#endif
#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
if (curl_easy_getinfo(cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
ret.set(s_certinfo, create_certinfo(ci));
}
#endif
#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
if (curl_easy_getinfo(cp, CURLINFO_PRIMARY_PORT, &l_code) == CURLE_OK) {
ret.set(s_primary_port, l_code);
}
if (curl_easy_getinfo(cp, CURLINFO_LOCAL_IP, &s_code) == CURLE_OK) {
ret.set(s_local_ip, String(s_code, CopyString));
}
if (curl_easy_getinfo(cp, CURLINFO_LOCAL_PORT, &l_code) == CURLE_OK) {
ret.set(s_local_port, l_code);
}
#endif
String header = curl->getHeader();
if (!header.empty()) {
ret.set(s_request_header, header);
}
return ret;
}
switch (opt) {
case CURLINFO_HEADER_OUT: {
String header = curl->getHeader();
if (!header.empty()) {
return header;
}
return false;
}
#if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
case CURLINFO_CERTINFO: {
struct curl_certinfo *ci = nullptr;
if (curl_easy_getinfo(cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
return create_certinfo(ci);
}
return false;
}
#endif
}
switch (CURLINFO_TYPEMASK & opt) {
case CURLINFO_STRING: {
char *s_code = nullptr;
if (curl_easy_getinfo(cp, (CURLINFO)opt, &s_code) == CURLE_OK &&
s_code) {
return String(s_code, CopyString);
}
return false;
}
case CURLINFO_LONG: {
long code = 0;
if (curl_easy_getinfo(cp, (CURLINFO)opt, &code) == CURLE_OK) {
return code;
}
return false;
}
case CURLINFO_DOUBLE: {
double code = 0.0;
if (curl_easy_getinfo(cp, (CURLINFO)opt, &code) == CURLE_OK) {
return code;
}
return false;
}
#if LIBCURL_VERSION_NUM >= 0x070c03 /* Available since 7.12.3 */
case CURLINFO_SLIST: {
struct curl_slist *slist;
Array ret = Array::CreateVec();
if (curl_easy_getinfo(cp, (CURLINFO)opt, &slist) == CURLE_OK) {
while (slist) {
ret.append(slist->data);
slist = slist->next;
}
curl_slist_free_all(slist);
return ret;
}
return false;
}
#endif
#if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
case CURLINFO_OFF_T: {
curl_off_t code = 0;
if (curl_easy_getinfo(cp, (CURLINFO)opt, &code) == CURLE_OK) {
return code;
}
return false;
}
#endif
default:
return false;
}
}
Variant HHVM_FUNCTION(curl_errno, const Resource& ch) {
CHECK_RESOURCE(curl);
return curl->getError();
}
Variant HHVM_FUNCTION(curl_error, const Resource& ch) {
CHECK_RESOURCE(curl);
return curl->getErrorString();
}
String HHVM_FUNCTION(curl_strerror, int code) {
return curl_easy_strerror((CURLcode)code);
}
Variant HHVM_FUNCTION(curl_close, const Resource& ch) {
CHECK_RESOURCE(curl);
curl->close();
return init_null();
}
void HHVM_FUNCTION(curl_reset, const Resource& ch) {
CHECK_RESOURCE_RETURN_VOID(curl);
curl->reset();
}
///////////////////////////////////////////////////////////////////////////////
#define CURLM_ARG_WARNING "expects parameter 1 to be cURL multi resource"
#define CHECK_MULTI_RESOURCE(curlm) \
auto curlm = dyn_cast_or_null<CurlMultiResource>(mh); \
if (!curlm || curlm->isInvalid()) { \
raise_warning(CURLM_ARG_WARNING); \
return init_null(); \
}
#define CHECK_MULTI_RESOURCE_RETURN_VOID(curlm) \
auto curlm = dyn_cast_or_null<CurlMultiResource>(mh); \
if (!curlm || curlm->isInvalid()) { \
raise_warning(CURLM_ARG_WARNING); \
return; \
}
#define CHECK_MULTI_RESOURCE_THROW(curlm) \
auto curlm = dyn_cast_or_null<CurlMultiResource>(mh); \
if (!curlm || curlm->isInvalid()) { \
SystemLib::throwExceptionObject(CURLM_ARG_WARNING); \
}
Resource HHVM_FUNCTION(curl_multi_init) {
return Resource(req::make<CurlMultiResource>());
}
Variant HHVM_FUNCTION(curl_multi_strerror, int64_t code) {
const char *str = curl_multi_strerror((CURLMcode)code);
if (str) {
return str;
} else {
return init_null();
}
}
Variant HHVM_FUNCTION(curl_multi_add_handle, const Resource& mh,
const Resource& ch) {
CHECK_MULTI_RESOURCE(curlm);
auto curle = cast<CurlResource>(ch);
curlm->add(ch);
return curl_multi_add_handle(curlm->get(), curle->get());
}
Variant HHVM_FUNCTION(curl_multi_remove_handle, const Resource& mh,
const Resource& ch) {
CHECK_MULTI_RESOURCE(curlm);
auto curle = cast<CurlResource>(ch);
curlm->remove(curle);
return curl_multi_remove_handle(curlm->get(), curle->get());
}
Variant HHVM_FUNCTION(curl_multi_exec, const Resource& mh,
int64_t& still_running) {
CHECK_MULTI_RESOURCE(curlm);
int running = 0;
IOStatusHelper io("curl_multi_exec");
SYNC_VM_REGS_SCOPED();
if (curlm->anyInExec()) {
log_native_stack("unexpected reentry into curl_multi_exec");
}
curlm->setInExec(true);
// T29358191: curl_multi_perform should not throw... trust but verify
int result;
try {
result = curl_multi_perform(curlm->get(), &running);
} catch (...) {
curlm->setInExec(false);
log_native_stack("unexpected exception from curl_multi_perform");
throw;
}
curlm->setInExec(false);
curlm->check_exceptions();
still_running = running;
return result;
}
bool HHVM_FUNCTION(curl_multi_setopt, const Resource& mh,
int option, const Variant& value) {
CHECK_MULTI_RESOURCE_THROW(curlm);
return curlm->setOption(option, value);
}
/* Fallback implementation of curl_multi_select()
*
* This allows the OSS build to work with older package
* versions of libcurl, but will fail with file descriptors
* over 1024.
*/
UNUSED
static void hphp_curl_multi_select(CURLM *mh, int timeout_ms, int *ret) {
fd_set read_fds, write_fds, except_fds;
int maxfds, nfds = -1;
struct timeval tv;
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
FD_ZERO(&except_fds);
tv.tv_sec = timeout_ms / 1000;
tv.tv_usec = (timeout_ms * 1000) % 1000000;
curl_multi_fdset(mh, &read_fds, &write_fds, &except_fds, &maxfds);
if (maxfds < 1024) {
nfds = select(maxfds + 1, &read_fds, &write_fds, &except_fds, &tv);
} else {
/* fd_set can only hold sockets from 0 to 1023,
* anything higher is ignored by FD_SET()
* avoid "unexplained" behavior by failing outright
*/
raise_warning("libcurl versions < 7.28.0 do not support selecting on "
"file descriptors of 1024 or higher.");
}
if (ret) {
*ret = nfds;
}
}
#ifndef HAVE_CURL_MULTI_SELECT
# ifdef HAVE_CURL_MULTI_WAIT
# define curl_multi_select_func(mh, tm, ret) curl_multi_wait((mh), nullptr, 0, (tm), (ret))
# else
# define curl_multi_select_func hphp_curl_multi_select
# endif
#else
#define curl_multi_select_func(mh, tm, ret) curl_multi_wait((mh), nullptr, 0, (tm), (ret))
#endif
Variant HHVM_FUNCTION(curl_multi_select, const Resource& mh,
double timeout /* = 1.0 */) {
CHECK_MULTI_RESOURCE(curlm);
int ret;
unsigned long timeout_ms = (unsigned long)(timeout * 1000.0);
IOStatusHelper io("curl_multi_select");
curl_multi_select_func(curlm->get(), timeout_ms, &ret);
return ret;
}
Object HHVM_FUNCTION(curl_multi_await, const Resource& mh,
double timeout /*=1.0*/) {
CHECK_MULTI_RESOURCE_THROW(curlm);
auto ev = new CurlMultiAwait(curlm, timeout);
try {
return Object{ev->getWaitHandle()};
} catch (...) {
assertx(false);
ev->abandon();
throw;
}
}
Variant HHVM_FUNCTION(curl_multi_getcontent, const Resource& ch) {
CHECK_RESOURCE(curl);
return curl->getContents();
}
Array curl_convert_fd_to_stream(fd_set *fd, int max_fd) {
Array ret = Array::CreateVec();
for (int i=0; i<=max_fd; i++) {
if (FD_ISSET(i, fd)) {
ret.append(Variant(req::make<BuiltinFile>(i)));
}
}
return ret;
}
Variant HHVM_FUNCTION(fb_curl_multi_fdset, const Resource& mh,
Array& read_fd_set,
Array& write_fd_set,
Array& exc_fd_set,
int64_t& max_fd) {
CHECK_MULTI_RESOURCE(curlm);
fd_set read_set;
fd_set write_set;
fd_set exc_set;
int max = 0;
FD_ZERO(&read_set);
FD_ZERO(&write_set);
FD_ZERO(&exc_set);
int r = curl_multi_fdset(curlm->get(), &read_set, &write_set, &exc_set, &max);
read_fd_set = curl_convert_fd_to_stream(&read_set, max);
write_fd_set = curl_convert_fd_to_stream(&write_set, max);
exc_fd_set = curl_convert_fd_to_stream(&exc_set, max);
max_fd = max;
return r;
}
const StaticString
s_msg("msg"),
s_result("result"),
s_handle("handle");
Variant HHVM_FUNCTION(curl_multi_info_read, const Resource& mh,
int64_t& msgs_in_queue) {
CHECK_MULTI_RESOURCE(curlm);
int queued_msgs;
CURLMsg *tmp_msg = curl_multi_info_read(curlm->get(), &queued_msgs);
curlm->check_exceptions();
if (tmp_msg == nullptr) {
return false;
}
msgs_in_queue = queued_msgs;
Array ret;
ret.set(s_msg, tmp_msg->msg);
ret.set(s_result, tmp_msg->data.result);
Resource curle = curlm->find(tmp_msg->easy_handle);
if (!curle.isNull()) {
ret.set(s_handle, curle);
}
return ret;
}
Variant HHVM_FUNCTION(curl_multi_close, const Resource& mh) {
CHECK_MULTI_RESOURCE(curlm);
curlm->close();
return init_null();
}
static std::string CURL_SHARE_Warning
= "expects parameter 1 to be cURL share resource";
Resource HHVM_FUNCTION(curl_share_init) {
return Resource(req::make<CurlShareResource>());
}
void HHVM_FUNCTION(curl_share_close, const Resource& sh) {
auto curlsh = dyn_cast_or_null<CurlShareResource>(sh);
if (!curlsh || curlsh->isInvalid()) {
raise_warning(CURL_SHARE_Warning);
}
curlsh->close();
}
bool HHVM_FUNCTION(curl_share_setopt, const Resource& sh,
int option, const Variant& value) {
auto curlsh = dyn_cast_or_null<CurlShareResource>(sh);
if (!curlsh || curlsh->isInvalid())
SystemLib::throwExceptionObject(CURL_SHARE_Warning);
return curlsh->setOption(option, value);
}
///////////////////////////////////////////////////////////////////////////////
static int s_sizeVal, s_connGetTimeoutVal, s_reuseLimitVal;
static std::string s_namedPools;
struct CurlExtension final : Extension {
CurlExtension() : Extension("curl") {}
void moduleInit() override {
/* See https://curl.haxx.se/libcurl/c/symbols-in-versions.html
or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
of options and which version they were introduced */
/* Constants for curl_setopt() */
HHVM_RC_INT_SAME(CURLOPT_AUTOREFERER);
HHVM_RC_INT_SAME(CURLOPT_BINARYTRANSFER);
HHVM_RC_INT_SAME(CURLOPT_BUFFERSIZE);
HHVM_RC_INT_SAME(CURLOPT_CAINFO);
HHVM_RC_INT_SAME(CURLOPT_CAPATH);
HHVM_RC_INT_SAME(CURLOPT_CONNECTTIMEOUT);
HHVM_RC_INT_SAME(CURLOPT_COOKIE);
HHVM_RC_INT_SAME(CURLOPT_COOKIEFILE);
HHVM_RC_INT_SAME(CURLOPT_COOKIEJAR);
HHVM_RC_INT_SAME(CURLOPT_COOKIESESSION);
HHVM_RC_INT_SAME(CURLOPT_CRLF);
HHVM_RC_INT_SAME(CURLOPT_CUSTOMREQUEST);
HHVM_RC_INT_SAME(CURLOPT_DNS_CACHE_TIMEOUT);
HHVM_RC_INT_SAME(CURLOPT_DNS_USE_GLOBAL_CACHE);
HHVM_RC_INT_SAME(CURLOPT_EGDSOCKET);
HHVM_RC_INT_SAME(CURLOPT_ENCODING);
HHVM_RC_INT_SAME(CURLOPT_FAILONERROR);
HHVM_RC_INT_SAME(CURLOPT_FILE);
HHVM_RC_INT_SAME(CURLOPT_FILETIME);
HHVM_RC_INT_SAME(CURLOPT_FOLLOWLOCATION);
HHVM_RC_INT_SAME(CURLOPT_FORBID_REUSE);
HHVM_RC_INT_SAME(CURLOPT_FRESH_CONNECT);
HHVM_RC_INT_SAME(CURLOPT_FTPAPPEND);
HHVM_RC_INT_SAME(CURLOPT_FTPLISTONLY);
HHVM_RC_INT_SAME(CURLOPT_FTPPORT);
HHVM_RC_INT_SAME(CURLOPT_FTP_USE_EPRT);
HHVM_RC_INT_SAME(CURLOPT_FTP_USE_EPSV);
HHVM_RC_INT_SAME(CURLOPT_HEADER);
HHVM_RC_INT_SAME(CURLOPT_HEADERFUNCTION);
HHVM_RC_INT_SAME(CURLOPT_HTTP200ALIASES);
HHVM_RC_INT_SAME(CURLOPT_HTTPGET);
HHVM_RC_INT_SAME(CURLOPT_HTTPHEADER);
HHVM_RC_INT_SAME(CURLOPT_HTTPPROXYTUNNEL);
HHVM_RC_INT_SAME(CURLOPT_HTTP_VERSION);
HHVM_RC_INT_SAME(CURLOPT_INFILE);
HHVM_RC_INT_SAME(CURLOPT_INFILESIZE);
HHVM_RC_INT_SAME(CURLOPT_INTERFACE);
HHVM_RC_INT_SAME(CURLOPT_KRB4LEVEL);
HHVM_RC_INT_SAME(CURLOPT_LOW_SPEED_LIMIT);
HHVM_RC_INT_SAME(CURLOPT_LOW_SPEED_TIME);
HHVM_RC_INT_SAME(CURLOPT_MAXCONNECTS);
HHVM_RC_INT_SAME(CURLOPT_MAXREDIRS);
HHVM_RC_INT_SAME(CURLOPT_NETRC);
HHVM_RC_INT_SAME(CURLOPT_NOBODY);
HHVM_RC_INT_SAME(CURLOPT_NOPROGRESS);
HHVM_RC_INT_SAME(CURLOPT_NOSIGNAL);
HHVM_RC_INT_SAME(CURLOPT_PORT);
HHVM_RC_INT_SAME(CURLOPT_POST);
HHVM_RC_INT_SAME(CURLOPT_POSTFIELDS);
HHVM_RC_INT_SAME(CURLOPT_POSTQUOTE);
HHVM_RC_INT_SAME(CURLOPT_PREQUOTE);
HHVM_RC_INT_SAME(CURLOPT_PRIVATE);
HHVM_RC_INT_SAME(CURLOPT_PROGRESSFUNCTION);
HHVM_RC_INT_SAME(CURLOPT_PROXY);
HHVM_RC_INT_SAME(CURLOPT_PROXYPORT);
HHVM_RC_INT_SAME(CURLOPT_PROXYTYPE);
HHVM_RC_INT_SAME(CURLOPT_PROXYUSERPWD);
HHVM_RC_INT_SAME(CURLOPT_PUT);
HHVM_RC_INT_SAME(CURLOPT_QUOTE);
HHVM_RC_INT_SAME(CURLOPT_RANDOM_FILE);
HHVM_RC_INT_SAME(CURLOPT_RANGE);
HHVM_RC_INT_SAME(CURLOPT_READDATA);
HHVM_RC_INT_SAME(CURLOPT_READFUNCTION);
HHVM_RC_INT_SAME(CURLOPT_REFERER);
HHVM_RC_INT_SAME(CURLOPT_RESUME_FROM);
HHVM_RC_INT_SAME(CURLOPT_RETURNTRANSFER);
HHVM_RC_INT_SAME(CURLOPT_SHARE);
HHVM_RC_INT_SAME(CURLOPT_SSLCERT);
HHVM_RC_INT_SAME(CURLOPT_SSLCERTPASSWD);
HHVM_RC_INT_SAME(CURLOPT_SSLCERTTYPE);
HHVM_RC_INT_SAME(CURLOPT_SSLENGINE);
HHVM_RC_INT_SAME(CURLOPT_SSLENGINE_DEFAULT);
HHVM_RC_INT_SAME(CURLOPT_SSLKEY);
HHVM_RC_INT_SAME(CURLOPT_SSLKEYPASSWD);
HHVM_RC_INT_SAME(CURLOPT_SSLKEYTYPE);
HHVM_RC_INT_SAME(CURLOPT_SSLVERSION);
HHVM_RC_INT_SAME(CURLOPT_SSL_CIPHER_LIST);
HHVM_RC_INT_SAME(CURLOPT_SSL_VERIFYHOST);
HHVM_RC_INT_SAME(CURLOPT_SSL_VERIFYPEER);
HHVM_RC_INT_SAME(CURLOPT_STDERR);
HHVM_RC_INT_SAME(CURLOPT_TELNETOPTIONS);
HHVM_RC_INT_SAME(CURLOPT_TIMECONDITION);
HHVM_RC_INT_SAME(CURLOPT_TIMEOUT);
HHVM_RC_INT_SAME(CURLOPT_TIMEVALUE);
HHVM_RC_INT_SAME(CURLOPT_TRANSFERTEXT);
HHVM_RC_INT_SAME(CURLOPT_UNRESTRICTED_AUTH);
HHVM_RC_INT_SAME(CURLOPT_UPLOAD);
HHVM_RC_INT_SAME(CURLOPT_URL);
HHVM_RC_INT_SAME(CURLOPT_USERAGENT);
HHVM_RC_INT_SAME(CURLOPT_USERPWD);
HHVM_RC_INT_SAME(CURLOPT_VERBOSE);
HHVM_RC_INT_SAME(CURLOPT_WRITEFUNCTION);
HHVM_RC_INT_SAME(CURLOPT_WRITEHEADER);
/* */
HHVM_RC_INT_SAME(CURLE_ABORTED_BY_CALLBACK);
HHVM_RC_INT_SAME(CURLE_BAD_CALLING_ORDER);
HHVM_RC_INT_SAME(CURLE_BAD_CONTENT_ENCODING);
HHVM_RC_INT_SAME(CURLE_BAD_DOWNLOAD_RESUME);
HHVM_RC_INT_SAME(CURLE_BAD_FUNCTION_ARGUMENT);
HHVM_RC_INT_SAME(CURLE_BAD_PASSWORD_ENTERED);
HHVM_RC_INT_SAME(CURLE_COULDNT_CONNECT);
HHVM_RC_INT_SAME(CURLE_COULDNT_RESOLVE_HOST);
HHVM_RC_INT_SAME(CURLE_COULDNT_RESOLVE_PROXY);
HHVM_RC_INT_SAME(CURLE_FAILED_INIT);
HHVM_RC_INT_SAME(CURLE_FILE_COULDNT_READ_FILE);
HHVM_RC_INT_SAME(CURLE_FTP_ACCESS_DENIED);
HHVM_RC_INT_SAME(CURLE_FTP_BAD_DOWNLOAD_RESUME);
HHVM_RC_INT_SAME(CURLE_FTP_CANT_GET_HOST);
HHVM_RC_INT_SAME(CURLE_FTP_CANT_RECONNECT);
HHVM_RC_INT_SAME(CURLE_FTP_COULDNT_GET_SIZE);
HHVM_RC_INT_SAME(CURLE_FTP_COULDNT_RETR_FILE);
HHVM_RC_INT_SAME(CURLE_FTP_COULDNT_SET_ASCII);
HHVM_RC_INT_SAME(CURLE_FTP_COULDNT_SET_BINARY);
HHVM_RC_INT_SAME(CURLE_FTP_COULDNT_STOR_FILE);
HHVM_RC_INT_SAME(CURLE_FTP_COULDNT_USE_REST);
HHVM_RC_INT_SAME(CURLE_FTP_PARTIAL_FILE);
HHVM_RC_INT_SAME(CURLE_FTP_PORT_FAILED);
HHVM_RC_INT_SAME(CURLE_FTP_QUOTE_ERROR);
HHVM_RC_INT_SAME(CURLE_FTP_USER_PASSWORD_INCORRECT);
HHVM_RC_INT_SAME(CURLE_FTP_WEIRD_227_FORMAT);
HHVM_RC_INT_SAME(CURLE_FTP_WEIRD_PASS_REPLY);
HHVM_RC_INT_SAME(CURLE_FTP_WEIRD_PASV_REPLY);
HHVM_RC_INT_SAME(CURLE_FTP_WEIRD_SERVER_REPLY);
HHVM_RC_INT_SAME(CURLE_FTP_WEIRD_USER_REPLY);
HHVM_RC_INT_SAME(CURLE_FTP_WRITE_ERROR);
HHVM_RC_INT_SAME(CURLE_FUNCTION_NOT_FOUND);
HHVM_RC_INT_SAME(CURLE_GOT_NOTHING);
HHVM_RC_INT_SAME(CURLE_HTTP_NOT_FOUND);
HHVM_RC_INT_SAME(CURLE_HTTP_PORT_FAILED);
HHVM_RC_INT_SAME(CURLE_HTTP_POST_ERROR);
HHVM_RC_INT_SAME(CURLE_HTTP_RANGE_ERROR);
HHVM_RC_INT_SAME(CURLE_HTTP_RETURNED_ERROR);
HHVM_RC_INT_SAME(CURLE_LDAP_CANNOT_BIND);
HHVM_RC_INT_SAME(CURLE_LDAP_SEARCH_FAILED);
HHVM_RC_INT_SAME(CURLE_LIBRARY_NOT_FOUND);
HHVM_RC_INT_SAME(CURLE_MALFORMAT_USER);
HHVM_RC_INT_SAME(CURLE_OBSOLETE);
HHVM_RC_INT_SAME(CURLE_OK);
HHVM_RC_INT_SAME(CURLE_OPERATION_TIMEDOUT);
HHVM_RC_INT_SAME(CURLE_OPERATION_TIMEOUTED);
HHVM_RC_INT_SAME(CURLE_OUT_OF_MEMORY);
HHVM_RC_INT_SAME(CURLE_PARTIAL_FILE);
HHVM_RC_INT_SAME(CURLE_READ_ERROR);
HHVM_RC_INT_SAME(CURLE_RECV_ERROR);
HHVM_RC_INT_SAME(CURLE_SEND_ERROR);
HHVM_RC_INT_SAME(CURLE_SHARE_IN_USE);
HHVM_RC_INT_SAME(CURLE_SSL_CACERT);
HHVM_RC_INT_SAME(CURLE_SSL_CERTPROBLEM);
HHVM_RC_INT_SAME(CURLE_SSL_CIPHER);
HHVM_RC_INT_SAME(CURLE_SSL_CONNECT_ERROR);
HHVM_RC_INT_SAME(CURLE_SSL_ENGINE_NOTFOUND);
HHVM_RC_INT_SAME(CURLE_SSL_ENGINE_SETFAILED);
if (CURLE_SSL_PEER_CERTIFICATE == CURLE_SSL_CACERT) {
// In older curl libraries, this was 51, but then it became
// equal to CURLE_SSL_CACERT, which breaks enums which include
// both values. Keep the old value for now. We can consider
// killing it later (after removing it from the hack code that
// uses it).
HHVM_RC_INT(CURLE_SSL_PEER_CERTIFICATE, 51);
} else {
HHVM_RC_INT_SAME(CURLE_SSL_PEER_CERTIFICATE);
}
HHVM_RC_INT_SAME(CURLE_TELNET_OPTION_SYNTAX);
HHVM_RC_INT_SAME(CURLE_TOO_MANY_REDIRECTS);
HHVM_RC_INT_SAME(CURLE_UNKNOWN_TELNET_OPTION);
HHVM_RC_INT_SAME(CURLE_UNSUPPORTED_PROTOCOL);
HHVM_RC_INT_SAME(CURLE_URL_MALFORMAT);
HHVM_RC_INT_SAME(CURLE_URL_MALFORMAT_USER);
HHVM_RC_INT_SAME(CURLE_WRITE_ERROR);
/* cURL info constants */
HHVM_RC_INT_SAME(CURLINFO_CONNECT_TIME);
HHVM_RC_INT_SAME(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
HHVM_RC_INT_SAME(CURLINFO_CONTENT_LENGTH_UPLOAD);
HHVM_RC_INT_SAME(CURLINFO_CONTENT_TYPE);
HHVM_RC_INT_SAME(CURLINFO_EFFECTIVE_URL);
HHVM_RC_INT_SAME(CURLINFO_FILETIME);
HHVM_RC_INT_SAME(CURLINFO_HEADER_OUT);
HHVM_RC_INT_SAME(CURLINFO_HEADER_SIZE);
HHVM_RC_INT_SAME(CURLINFO_HTTP_CODE);
HHVM_RC_INT_SAME(CURLINFO_LASTONE);
HHVM_RC_INT_SAME(CURLINFO_NAMELOOKUP_TIME);
HHVM_RC_INT_SAME(CURLINFO_PRETRANSFER_TIME);
HHVM_RC_INT_SAME(CURLINFO_PRIVATE);
HHVM_RC_INT_SAME(CURLINFO_REDIRECT_COUNT);
HHVM_RC_INT_SAME(CURLINFO_REDIRECT_TIME);
HHVM_RC_INT_SAME(CURLINFO_REQUEST_SIZE);
HHVM_RC_INT_SAME(CURLINFO_SIZE_DOWNLOAD);
HHVM_RC_INT_SAME(CURLINFO_SIZE_UPLOAD);
HHVM_RC_INT_SAME(CURLINFO_SPEED_DOWNLOAD);
HHVM_RC_INT_SAME(CURLINFO_SPEED_UPLOAD);
HHVM_RC_INT_SAME(CURLINFO_SSL_VERIFYRESULT);
HHVM_RC_INT_SAME(CURLINFO_STARTTRANSFER_TIME);
HHVM_RC_INT_SAME(CURLINFO_TOTAL_TIME);
/* Other */
HHVM_RC_INT_SAME(CURLMSG_DONE);
HHVM_RC_INT_SAME(CURLVERSION_NOW);
/* Curl Multi Constants */
HHVM_RC_INT_SAME(CURLM_BAD_EASY_HANDLE);
HHVM_RC_INT_SAME(CURLM_BAD_HANDLE);
HHVM_RC_INT_SAME(CURLM_CALL_MULTI_PERFORM);
HHVM_RC_INT_SAME(CURLM_INTERNAL_ERROR);
HHVM_RC_INT_SAME(CURLM_OK);
HHVM_RC_INT_SAME(CURLM_OUT_OF_MEMORY);
/* Curl proxy constants */
HHVM_RC_INT_SAME(CURLPROXY_HTTP);
HHVM_RC_INT_SAME(CURLPROXY_SOCKS4);
HHVM_RC_INT_SAME(CURLPROXY_SOCKS5);
#if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
HHVM_RC_INT_SAME(CURLPROXY_SOCKS4A);
HHVM_RC_INT_SAME(CURLPROXY_SOCKS5_HOSTNAME);
#endif
/* Curl Share constants */
HHVM_RC_INT_SAME(CURLSHOPT_NONE);
HHVM_RC_INT_SAME(CURLSHOPT_SHARE);
HHVM_RC_INT_SAME(CURLSHOPT_UNSHARE);
/* Curl Http Version constants (CURLOPT_HTTP_VERSION) */
HHVM_RC_INT_SAME(CURL_HTTP_VERSION_1_0);
HHVM_RC_INT_SAME(CURL_HTTP_VERSION_1_1);
HHVM_RC_INT_SAME(CURL_HTTP_VERSION_NONE);
/* Curl Lock constants */
HHVM_RC_INT_SAME(CURL_LOCK_DATA_COOKIE);
HHVM_RC_INT_SAME(CURL_LOCK_DATA_DNS);
HHVM_RC_INT_SAME(CURL_LOCK_DATA_SSL_SESSION);
/* Curl NETRC constants (CURLOPT_NETRC) */
HHVM_RC_INT_SAME(CURL_NETRC_IGNORED);
HHVM_RC_INT_SAME(CURL_NETRC_OPTIONAL);
HHVM_RC_INT_SAME(CURL_NETRC_REQUIRED);
/* Curl SSL Version constants (CURLOPT_SSLVERSION) */
HHVM_RC_INT_SAME(CURL_SSLVERSION_DEFAULT);
HHVM_RC_INT_SAME(CURL_SSLVERSION_SSLv2);
HHVM_RC_INT_SAME(CURL_SSLVERSION_SSLv3);
HHVM_RC_INT_SAME(CURL_SSLVERSION_TLSv1);
/* Curl TIMECOND constants (CURLOPT_TIMECONDITION) */
HHVM_RC_INT_SAME(CURL_TIMECOND_IFMODSINCE);
HHVM_RC_INT_SAME(CURL_TIMECOND_IFUNMODSINCE);
HHVM_RC_INT_SAME(CURL_TIMECOND_LASTMOD);
HHVM_RC_INT_SAME(CURL_TIMECOND_NONE);
/* Curl version constants */