forked from RaptorX/cURL-Wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cURL.new
executable file
·1483 lines (1172 loc) · 71.9 KB
/
cURL.new
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
; Title: cURL Wrapper for AHK
/*
Function: Global_Init
Sets up the program environment that libcurl needs. Think of it as an extension of the library loader.
This function must be called at least once within a program (a program is all the code that shares a memory
space) before the program calls any other function in libcurl. The environment it sets up is constant for the
life of the program and is the same for every program, so multiple calls have the same effect as one call.
*This function is not thread safe.* You must not call it when any other thread in the program (i.e. a thread
sharing the same memory) is running. This doesn't just mean no other thread that is using libcurl. Because
*Global_Init()* calls functions of other libraries that are similarly thread unsafe, it could conflict with
any other thread that uses these other libraries.
See the description in libcurl(3) of global environment requirements for details of how to use this function.
See: <http://curl.haxx.se/libcurl/c/curl_global_init.html>
Parameters:
> cURL_Global_Init([DllPath, Flags])
DllPath - Optional location for the libcurl.dll file.
If not specified it will be assumed to be on *a_scriptdir*.
Flags - The flags option is a bit pattern that tells libcurl exactly what features to init, as
described below. Set the desired bits by ORing the values together.
In normal operation, you must specify *CURL_GLOBAL_ALL*.
Don't use any other value unless you are familiar with it and mean to control internal
operations of libcurl.
Accepted Flags:
- *CURL_GLOBAL_SSL*: (1<<0)
- *CURL_GLOBAL_WIN32*: (1<<1)
- *CURL_GLOBAL_ALL*: (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32)
- *CURL_GLOBAL_NOTHING*: 0
- *CURL_GLOBAL_DEFAULT*: CURL_GLOBAL_ALL
Returns:
*CURLE_OK* (zero) If this function returns non-zero, something went wrong and you cannot use
the other curl functions.
*/
cURL_Global_Init(DllPath="", Flags="CURL_GLOBAL_DEFAULT"){
DllPath := !DllPath ? "libcurl.dll" : inStr(DllPath, "libcurl.dll") ? DllPath : DllPath "\libcurl.dll"
if !hCurlModule:=DllCall("LoadLibrary", "Str", DllPath)
return A_ThisFunc "> Could not load library: " DllPath
; Initialize the program environment
return DllCall("libcurl\curl_global_init", "UInt", CURL(Flags))
}
/*
Function: Global_Cleanup
Releases resources acquired by <Global_Init()>.
You should call *Global_Cleanup()* once for each call you make to <Global_Init()>, after you are done
using libcurl.
*This function is not thread safe.* You must not call it when any other thread in the program
(i.e. a thread sharing the same memory) is running. This doesn't just mean no other thread that is using
libcurl. Because *Global_Cleanup()* calls functions of other libraries that are similarly thread unsafe,
it could conflict with any other thread that uses these other libraries.
See the description in libcurl(3) of global environment requirements for details of how to use this function.
See: <http://curl.haxx.se/libcurl/c/curl_global_cleanup.html>
Parameters:
> None
Returns:
Nothing is returned by this function.
*/
cURL_Global_Cleanup(){
return DllCall( "FreeLibrary", "UInt", hCurlModule ), DllCall("libcurl\curl_global_cleanup")
}
/*
Function: Version
Returns the libcurl version string.
Returns a human readable string with the version number of libcurl and some of its important components (like
OpenSSL version).
See: <http://curl.haxx.se/libcurl/c/curl_version.html>
Parameters:
> None
Returns:
A pointer to a zero terminated string.
*/
cURL_Version(){
return DllCall("libcurl\curl_version", Str)
}
/*
Function: Version_Info
Returns run-time libcurl version info.
Returns a pointer to a filled in struct with information about various run-time features in libcurl. type
should be set to the version of this functionality by the time you write your program. This way, libcurl will
always return a proper struct that your program understands, while programs in the future might get a different
struct. *CURLVERSION_NOW* will be the most recent one for the library you have installed:
> data := cURL_Version_Info("CURLVERSION_NOW")
Applications should use this information to judge if things are possible to do or not, instead of using
compile-time checks, as dynamic/DLL libraries can be changed independent of applications.
The curl_version_info_data struct looks like this
(start code)
typedef struct { CURLversion age; // see description below
// when 'age' is 0 or higher, the members below also exist:
const char *version; // human readable string
unsigned int version_num; // numeric representation
const char *host; // human readable string
int features; // bitmask, see below
char *ssl_version; // human readable string
long ssl_version_num; // not used, always zero
const char *libz_version; // human readable string
const char **protocols; // list of protocols
// when 'age' is 1 or higher, the members below also exist:
const char *ares; // human readable string
int ares_num; // number
// when 'age' is 2 or higher, the member below also exists:
const char *libidn; // human readable string
// when 'age' is 3 or higher, the members below also exist:
int iconv_ver_num; // '_libiconv_version' if iconv support enabled
const char *libssh_version; // human readable string
} curl_version_info_data;
(end)
age - describes what the age of this struct is. The number depends on how new the libcurl you're using is. You
are however guaranteed to get a struct that you have a matching struct for in the header, as you tell libcurl
your "age" with the vAge argument.
version - is just an ascii string for the libcurl version.
version_num - is a 24 bit number created like this: <8 bits major number> | <8 bits minor number> | <8 bits
patch number>. Version 7.9.8 is therefore returned as 0x070908.
host - is an ascii string showing what host information that this libcurl was built for. As discovered by a
configure script or set by the build environment.
features - can have none, one or more bits set, and the currently defined bits are:
- *CURL_VERSION_IPV6*: supports IPv6
- *CURL_VERSION_KERBEROS4*: supports kerberos4 (when using FTP)
- *CURL_VERSION_SSL*: supports SSL (HTTPS/FTPS) (Added in 7.10)
- *CURL_VERSION_LIBZ*: supports HTTP deflate using libz (Added in 7.10)
- *CURL_VERSION_NTLM*: supports HTTP NTLM (added in 7.10.6)
- *CURL_VERSION_GSSNEGOTIATE*: supports HTTP GSS-Negotiate (added in 7.10.6)
- *CURL_VERSION_DEBUG*: libcurl was built with debug capabilities (added in 7.10.6)
- *CURL_VERSION_CURLDEBUG*: libcurl was built with memory tracking debug capabilities. This is
mainly of interest for libcurl hackers. (added in 7.19.6)
- *CURL_VERSION_ASYNCHDNS*: libcurl was built with support for asynchronous name lookups, which
allows more exact timeouts (even on Windows) and less blocking when using the multi interface.
(added in 7.10.7)
- *CURL_VERSION_SPNEGO*: libcurl was built with support for SPNEGO authentication (Simple and
Protected GSS-API Negotiation Mechanism, defined in RFC 2478.) (added in 7.10.8)
- *CURL_VERSION_LARGEFILE*: libcurl was built with support for large files. (Added in 7.11.1)
- *CURL_VERSION_IDN*: libcurl was built with support for IDNA, domain names with international
letters. (Added in 7.12.0)
- *CURL_VERSION_SSPI*: libcurl was built with support for SSPI. This is only available on
Windows and makes libcurl use Windows-provided functions for NTLM authentication. It also
allows libcurl to use the current user and the current user's password without the app having
to pass them on. (Added in 7.13.2)
- *CURL_VERSION_CONV*: libcurl was built with support for character conversions, as provided by
the CURLOPT_CONV_* callbacks. (Added in 7.15.4)
ssl_version - is an ASCII string for the OpenSSL version used. If libcurl has no SSL support, this is *NULL*.
ssl_version_num - is the numerical OpenSSL version value as defined by the OpenSSL project. If libcurl has no
SSL support, this is 0.
libz_version - is an ASCII string (there is no numerical version). If libcurl has no libz support, this is *NULL*.
protocols - is a pointer to an array of char * pointers, containing the names protocols that libcurl supports (
using lowercase letters). The protocol names are the same as would be used in URLs. The array is terminated by
a *NULL* entry.
Returns:
A pointer to a curl_version_info_data struct.
*/
cURL_Version_Info(vAge){
return DllCall("libcurl\curl_version_info", "UInt", CURL(vAge))
}
/*
Function: FormAdd
Add a section to a multipart/formdata HTTP POST.
This function is used to append sections when building a multipart/formdata HTTP POST (referred to
as RFC2388-style posts). Append one section at a time until you've added all the sections you want included
and then you pass the fpost pointer as parameter to *CURLOPT_HTTPPOST*. lpost is set after each call and
on repeated invokes it should be left as set to allow repeated invokes to find the end of the list faster.
After the lpost pointer follow the real arguments.
All list-data will be allocated by the function itself. You must call <FormFree()> after the form post
has been done to free the resources.
Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with
*CURLOPT_HTTPHEADER* as usual.
First, there are some basics you need to understand about multipart/formdata posts. Each part consists of at
least a NAME and a CONTENTS part. If the part is made for file upload, there are also a stored CONTENT-TYPE
and a FILENAME. We'll discuss in the link below, what options you use to set these properties in the parts you
want to add to your post: <http://curl.haxx.se/libcurl/c/curl_formadd.html>
The options listed first are for making normal parts. The options from *CURLFORM_FILE* through
*CURLFORM_BUFFERLENGTH* are for file upload parts.
The last parameter of each call of this function must be *CURLFORM_END*.
Parameters:
> cURL_FormAdd(fpost, lpost, params)
fpost - Empty variable that will be filled with the info passed in params.
lpost - Empty variable that is also filled automatically by libcurl.
params - Actual list of parameters that will be passed to this function. Please read the link above
carefully and check the examples provided to get an idea of how to create multipart/formdata
lists with this function.
Returns:
*CURLE_OK* (zero) means everything was ok, non-zero means an error occurred corresponding to a *CURL_FORMADD_**
constant defined in <curl/curl.h>
*/
cURL_FormAdd(Byref fPost, Byref lPost, Params){
`(!fpost || !lpost) ? (VarSetCapacity(fpost, 4, 0), VarSetCapacity(lpost, 4, 0))
Loop, parse, params, `,
mod(a_index, 2) ? Fopt%a_index%:=CURL(a_loopfield) : Fval%a_index%:=a_loopfield
return DllCall("libcurl\curl_formadd"
,"UInt*",fpost
,"UInt*",lpost
,"UInt" ,%Fopt1% ,"Str" ,Fval2
,"UInt" ,%Fopt3% ,"Str" ,Fval4
,"UInt" ,%Fopt5% ,"Str" ,Fval6
,"UInt" ,%Fopt7% ,"Str" ,Fval8
,"UInt" ,%Fopt9% ,"Str" ,Fval10, CDecl)
}
/*
Function: FormFree
Free a previously build multipart/formdata HTTP POST chain.
Used to clean up data previously built/appended with <FormAdd()>. This must be called
when the data has been used, which typically means after <Easy_Perform()> has been called.
See: <http://curl.haxx.se/libcurl/c/curl_formfree.html>
Parameters:
cURL_FormFree(fPost)
fPost - Variable filled with a multipart/formdata list created with <FormAdd()>
Returns:
Nothing is returned by this function.
*/
cURL_FormFree(Byref fPost){
return DllCall("libcurl\curl_formfree", "UInt*", fPost, Cdecl)
}
/*
Function: Free
Reclaims memory that has been obtained through a libcurl call.
See: <http://curl.haxx.se/libcurl/c/curl_free.html>
Parameters:
> cURL_Free(Str)
Returns:
Nothing is returned by this function.
*/
cURL_Free(Byref Str){
return DllCall("libcurl\curl_free", "UInt*", Str, Cdecl)
}
/*
Function: GetDate
Convert a date string to number of seconds since January 1, 1970.
This function returns the number of seconds since January 1st 1970 in the UTC time zone, for the date and time
that the datestring parameter specifies. The now parameter is not used, pass a *NULL* there.
*NOTE:* This function was rewritten for the 7.12.2 release and this documentation covers the functionality of
the new one. The new one is not feature-complete with the old one, but most of the formats supported by the new
one was supported by the old too.
See: <http://curl.haxx.se/libcurl/c/curl_getdate.html>
Parameters:
> cURL_GetDate(Date)
Date - A "date" is a string containing several items separated by whitespace. The order of the items is
immaterial. A date string may contain many flavors of items:
- *Calendar Date items* Can be specified several ways. Month names can only be three-letter english
abbreviations, numbers can be zero-prefixed and the year may use 2 or 4 digits. Examples: 06 Nov 1994,
06-Nov-94 and Nov-94 6.
- *Time of the day items* This string specifies the time on a given day. You must specify it with 6 digits
with two colons: HH:MM:SS. To not include the time in a date string, will make the function assume 00:00:00.
Example: 18:19:21.
- *Time Zone items* Specifies international time zone. There are a few acronyms supported, but in general you
should instead use the specific relative time compared to UTC. Supported formats include: -1200, MST, +0100.
- *Day of the week items* Specifies a day of the week. Days of the week may be spelled out in full
(using english): `Sunday', `Monday', etc or they may be abbreviated to their first three letters. This is
usually not info that adds anything.
- *Pure numbers* If a decimal number of the form YYYYMMDD appears, then YYYY is read as the year, MM as the
month number and DD as the day of the month, for the specified calendar date.
Returns:
This function returns -1 when it fails to parse the date string. Otherwise it returns the number of seconds as
described.
If the year is larger than 2037 on systems with 32 bit time_t, this function will return 0x7fffffff (since
that is the largest possible signed 32 bit number).
Having a 64 bit time_t is not a guarantee that dates beyond 03:14:07 UTC, January 19, 2038 will work fine. On
systems with a 64 bit time_t but with a crippled mktime(), curl_getdate will return -1 in this case.
Examples:
(start code)
Sun, 06 Nov 1994 08:49:37 GMT
Sunday, 06-Nov-94 08:49:37 GMT
Sun Nov 6 08:49:37 1994
06 Nov 1994 08:49:37 GMT
06-Nov-94 08:49:37 GMT
Nov 6 08:49:37 1994
06 Nov 1994 08:49:37
06-Nov-94 08:49:37
1994 Nov 6 08:49:37
GMT 08:49:37 06-Nov-94 Sunday
94 6 Nov 08:49:37
1994 Nov 6
06-Nov-94
Sun Nov 6 94
1994.Nov.6
Sun/Nov/6/94/GMT
Sun, 06 Nov 1994 08:49:37 CET
06 Nov 1994 08:49:37 EST
Sun, 12 Sep 2004 15:05:58 -0700
Sat, 11 Sep 2004 21:32:11 +0200
20040912 15:05:58 -0700
20040911 +0200
(end)
Additional Notes:
- This parser was written to handle date formats specified in RFC 822 (including the update in RFC 1123) using
time zone name or time zone delta and RFC 850 (obsoleted by RFC 1036) and ANSI C's asctime() format.
These formats are the only ones RFC2616 says HTTP applications may use.
- The former version of this function was built with yacc and was not only very large, it was also never quite
understood and it wasn't possible to build with non-GNU tools since only GNU Bison could make it thread-safe!.
The rewrite was done for 7.12.2. The new one is much smaller and uses simpler code.
*/
cURL_GetDate(Date){
return DllCall("libcurl\curl_getdate", "Str", Date, "UInt", 0)
}
/*
Function: sList_Append
Add a string to a slist.
*sList_Append()* appends a specified string to a linked list of strings. The existing list should be passed as
the first argument while the new list is returned from this function. The specified string has been appended
when this function returns. *sList_Append()* copies the string.
The list should be freed again (after usage) with <sList_Free_All()>.
See: <http://curl.haxx.se/libcurl/c/curl_slist_append.html>
Parameters:
> cURL_sList_Append(pList, Str)
pList - Variable that will contain the list.
Str - String to be appended to the list.
Returns:
A *NULL* pointer is returned if anything went wrong, otherwise the new list pointer is returned.
*/
cURL_sList_Append(Byref pList, Byref Str){
pList ? : pList:=0
return DllCall("libcurl\curl_slist_append", "UInt*", pList, "UInt*", Str, Cdecl)
}
/*
Function: sList_Free_All
Free an entire curl_slist list.
*sList_Free_All()* removes all traces of a previously built curl_slist linked list.
See: <http://curl.haxx.se/libcurl/c/curl_slist_free_all.html>
Parameters:
> cURL_sList_Free_All(pList)
pList - Variable that contains the list.
Returns:
Nothing is returned by this function.
*/
cURL_sList_Free_All(Byref pList){
return DllCall("libcurl\curl_slist_free_all", "UInt*", pList, Cdecl)
}
; Group: Easy Interface
; *Interface for making single transfers with libcurl.*
; When using libcurl's "easy" interface you init your session and get a handle (referred to as an "easy
; handle"), which you use as input to the easy interface functions you use. Use <Easy_Init()> to get the handle.
; You continue by setting all the options you want in the upcoming transfer, the most important among them is
; the URL itself (you can't transfer anything without a specified URL as you may have figured out yourself). You
; might want to set some callbacks as well that will be called from the library when data is available etc.
; <Easy_SetOpt()> is used for all this.
; When all is setup, you tell libcurl to perform the transfer using <Easy_Perform()>. It will then do the
; entire operation and won't return until it is done (successfully or not).
; After the transfer has been made, you can set new options and make another transfer, or if you're done,
; cleanup the session by calling <Easy_Cleanup()>. If you want persistent connections, you don't cleanup
; immediately, but instead run ahead and perform other transfers using the same easy handle.
/*
Function: Easy_Init
Start a libcurl easy session.
Must be the first function called after <Global_Init()>. It returns a handle that
you must use as input to other easy-functions.
*Easy_Init()* initializes curl and this call *MUST* have a corresponding
call to <Easy_Cleanup()> when the operation is complete.
If you did not already call <Global_Init()>, *Easy_Init()* does it automatically. This may be lethal in
multi-threaded cases, since <Global_Init()> is not thread-safe, and it may result in resource
problems because there is no corresponding cleanup.
You are strongly advised to *not allow* this automatic behaviour, by calling <Global_Init()>
yourself properly.
See the description in libcurl(3) of global environment requirements for details of how to use this function.
See: <http://curl.haxx.se/libcurl/c/curl_easy_init.html>
Parameters:
> None
Returns:
cHandle - CURL handle.
If this function returns *NULL*, something went wrong and you cannot use the other curl functions.
*/
cURL_Easy_Init(){
return DllCall("libcurl\curl_easy_init")
}
/*
Function: Easy_Cleanup
End a libcurl easy session.
This function must be the last function to call for an easy session. It is the opposite of the
<Easy_Init()> function and must be called with the same handle as input that the <Easy_Init()> call
returned.
This will effectively close all connections this handle has used and possibly has kept open until now. Don't
call this function if you intend to transfer more files.
Any uses of the handle after this function has been called are illegal. This kills the handle and all memory
associated with it!
With libcurl versions prior to 7.17: when you've called this, you can safely remove all the strings you've
previously told libcurl to use, as it won't use them anymore now.
See: <http://curl.haxx.se/libcurl/c/curl_easy_cleanup.html>
Parameters:
> cURL_Easy_Cleanup(cHandle)
cHandle - CURL handle.
Returns:
Nothing is returned by this function.
*/
cURL_Easy_Cleanup(cHandle){
return DllCall("libcurl\curl_easy_cleanup", "UInt", cHandle)
}
/*
Function: Easy_DupHandle
Clone a libcurl session handle.
Returns a new curl handle, a duplicate, using all the options previously set in the input
curl handle. Both handles can subsequently be used independently and they must both be freed with
<Easy_Cleanup()>.
All strings that the input handle has been told to point to (as opposed to copy) with previous calls to
<Easy_SetOpt()> using char * inputs, will be pointed to by the new handle as well. You must therefore make
sure to keep the data around until both handles have been cleaned up.
The new handle will not inherit any state information, no connections, no SSL sessions and no cookies.
Note that even in multi-threaded programs, this function must be called in a synchronous way, the input handle
may not be in use when cloned.
See: <http://curl.haxx.se/libcurl/c/curl_easy_duphandle.html>
Parameters:
> cURL_Easy_DupHandle(cHandle)
cHandle - CURL handle.
Returns:
If this function returns *NULL*, something went wrong and you cannot use the other curl functions.
*/
cURL_Easy_DupHandle(cHandle){
return DllCall("libcurl\curl_easy_duphandle", "UInt", cHandle)
}
/*
Function: Easy_SetOpt
Set options for a curl easy handle.
*Easy_SetOpt()* is used to tell libcurl how to behave. By using the appropriate options to
*Easy_SetOpt()*, you can change libcurl's behavior. All options are set with the option followed by a
parameter. That parameter can be a long, a function pointer, an object pointer or a curl_off_t, depending on
what the specific option expects. Read this manual carefully as bad input values
may cause libcurl to behave badly!
You can only set one option in each function call. A typical application uses many *Easy_SetOpt()*
calls in the setup phase.
Options set with this function call are valid for all forthcoming transfers performed using this handle. The
options are not in any way reset between transfers, so if you want subsequent transfers with different
options, you must change them between the transfers. You can optionally reset all options back to internal
default with <Easy_Reset()>.
Strings passed to libcurl as 'char *' arguments, are copied by the library; thus the string storage associated
to the pointer argument may be overwritten after *Easy_SetOpt()* returns. Exceptions to this rule are
described in the option details found on the link below.
Before version 7.17.0, strings were not copied. Instead the user was forced keep them available until libcurl
no longer needed them.
The handle is the return code from a <Easy_Init()> or <Easy_DupHandle()> call.
See: <http://curl.haxx.se/libcurl/c/curl_easy_setopt.html>
Parameters:
> cURL_Easy_SetOpt(cHandle, Option, Param)
cHandle - CURL handle.
Option - A string containing a valid option name. the full list is in the documentation link above.
Read each option *carefully* since bad parameters might cause undesired effects.
Param - A parameter for the specified option.
Returns:
*CURLE_OK* (zero) means that the option was set properly, non-zero means an error occurred as <curl/curl.h>
defines. See the libcurl-errors(3) man page for the full list with descriptions.
If you try to set an option that libcurl doesn't know about, perhaps because the library is too old to support
it or the option was removed in a recent version, this function will return *CURLE_FAILED_INIT*.
Examples:
> cURL_Easy_SetOpt(cHandle, "CURLOPT_URL", "www.google.com")
> cURL_Easy_SetOpt(cHandle, "CURLOPT_VERBOSE", True)
*/
cURL_Easy_SetOpt(cHandle, Option, Param){
a_isunicode ? (VarSetCapacity(ParamA, StrPut(Param, "CP0")), StrPut(Param, &ParamA, "CP0"))
return DllCall("libcurl\curl_easy_setopt"
,"UInt" ,cHandle
,"UInt" ,CURL(Option)
,Param+0 ? "UInt" : "Str",(a_isunicode && param+0="") ? ParamA : Param)
}
/*
Function: Easy_Perform
Perform a file transfer.
This function is called after the init and all the <Easy_SetOpt()> calls are made, and will perform the
transfer as described in the options. It must be called with the same handle as input as the <Easy_Init()>
call returned.
You can do any amount of calls to *Easy_Perform()* while using the same handle. If you intend to transfer
more than one file, you are even encouraged to do so. libcurl will then attempt to re-use the same connection
for the following transfers, thus making the operations faster, less CPU intense and using less network
resources. Just note that you will have to use <Easy_SetOpt()> between the invokes to set options for the
following *Easy_Perform()*.
You must never call this function simultaneously from two places using the same handle. Let the function return
first before invoking it another time. If you want parallel transfers, you must use several curl handles.
See: <http://curl.haxx.se/libcurl/c/curl_easy_perform.html>
Parameters:
> cURL_Easy_Perform(cHandle)
cHandle - CURL handle.
Returns:
If *CURLE_OK* (zero) was returned then it means everything was ok.
Non-zero means an error occurred as <curl/curl.h> defines.
If the *CURLOPT_ERRORBUFFER* was set with curl_easy_setopt there will be a readable error message
in the error buffer when non-zero is returned.
*/
cURL_Easy_Perform(cHandle){
return DllCall("libcurl\curl_easy_perform", "UInt", cHandle)
}
/*
Function: Easy_GetInfo
Extract information from a curl handle.
Request internal information from the curl session with this function. The data pointed-to can be relied upon
only if the function returns *CURLE_OK* (zero). Use this function *after* a performed transfer if you want to
get transfer-oriented data.
You should not free the memory returned by this function unless it is explicitly mentioned in the link below.
See: <http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html>
Parameters:
> cURL_Easy_GetInfo(cHandle, Info, Byref Var)
cHandle - CURL handle.
Info - One of the available options shown in the original documentation link above.
Var - An empty variable that will be filled in with the internal information from the curl session
being queried.
Returns:
If the operation was successful, *CURLE_OK* (zero) is returned.
Otherwise an appropriate error code will be returned.
*/
cURL_Easy_GetInfo(cHandle, Info, Byref Var){
VarSetCapacity(Var, (CURL(Info) > 0x300000 && CURL(Info) < 0x400000) ? 8 : 4)
if CURLE_OK:=DllCall("libcurl\curl_easy_getinfo"
,"UInt" ,cHandle
,"UInt" ,Info
,"UInt" ,&Var, Cdecl)
return CURLE_OK
CURL(Info) < CURL("CURLINFO_LONG") ? Var:=DllCall("MulDiv", "Int", NumGet(Var), "Int", 1, "Int", 1, Str)
: CURL(Info) < CURL("CURLINFO_DOUBLE") || CURL(Info) > CURL("CURLINFO_SLIST") ? Var:=NumGet(Var)
: CURL(Info) < CURL("CURLINFO_SLIST") ? Var:=NumGet(Var, 0, "Double")
return CURLE_OK
}
/*
Function: Easy_Send
Rends raw data over an "easy" connection.
This function sends arbitrary data over the established connection. You may use it together with
<Easy_Recv()> to implement custom protocols using libcurl. This functionality can be particularly useful
if you use proxies and/or SSL encryption: libcurl will take care of proxy negotiation and connection set-up.
To establish the connection, set *CURLOPT_CONNECT_ONLY* option before calling <Easy_Perform()>. Note that
*Easy_Send()* will not work on connections that were created without this option.
You must ensure that the socket is writable before calling *Easy_Send()*, otherwise the call will return
*CURLE_AGAIN* (81) - the socket is used in non-blocking mode internally. Use <Easy_GetInfo()> with
*CURLINFO_LASTSOCKET* to obtain the socket; use your operating system facilities like select(2) to check if it
can be written to.
See: <http://curl.haxx.se/libcurl/c/curl_easy_send.html>
Parameters:
> cURL_Easy_Send(cHandle, Buffer, BufLen, SentBytes)
cHandle - CURL handle.
Buffer - Variable containing the data of size BufLen that will be sent.
BufLen - Is the size of the buffer that will be sent.
RecvBytes - A variable that will receive the number of sent bytes.
Returns:
On success, returns *CURLE_OK* (zero) and stores the number of bytes actually sent into *n.
Note that this may very well be less than the amount you wanted to send.
On failure, returns the appropriate error code.
Availability:
Added in 7.18.2.
*/
cURL_Easy_Send(cHandle, Byref Buffer, BufLen, Byref SentBytes){
VarSetCapacity(SentBytes, Buflen+1)
return DllCall("libcurl\curl_easy_send"
,"UInt" ,cHandle
,"UInt*",Buffer
,"UInt" ,BufLen
,"UInt*",SentBytes), SentBytes:=Numget(SentBytes)
}
/*
Function: Easy_Recv
Receives raw data on an "easy" connection.
This function receives raw data from the established connection. You may use it together with
<Easy_Send()> to implement custom protocols using libcurl. This functionality can be particularly useful
if you use proxies and/or SSL encryption: libcurl will take care of proxy negotiation and connection set-up.
To establish the connection, set *CURLOPT_CONNECT_ONLY* option before calling <Easy_Perform()>. Note that
*Easy_Recv()* does not work on connections that were created without this option.
You must ensure that the socket has data to read before calling *Easy_Recv()*, otherwise the call will
return *CURLE_AGAIN* (81) - the socket is used in non-blocking mode internally. Use <Easy_GetInfo()> with
*CURLINFO_LASTSOCKET* to obtain the socket; use your operating system facilities like select(2) to check if it
has any data you can read.
See: <http://curl.haxx.se/libcurl/c/curl_easy_recv.html>
Parameters:
> cURL_Easy_Recv(cHandle, Buffer, BufLen, RecvBytes)
cHandle - CURL handle.
Buffer - An empty variable that will get the received data.
BufLen - Is the maximum amount of data you can get in that buffer.
RecvBytes - A variable that will receive the number of received bytes.
Returns:
On success, returns *CURLE_OK* (zero), stores the received data into Buffer, and the number of bytes it actually read into RecvBytes.
On failure, returns the appropriate error code.
If there is no data to read, the function returns *CURLE_AGAIN* (81). Use your operating system facilities to
wait until the data is ready, and retry.
Availability:
Added in 7.18.2.
*/
cURL_Easy_Recv(cHandle, Byref Buffer, BufLen, Byref RecvBytes){
VarSetCapacity(Buffer, Buflen+1), VarSetCapacity(RecvBytes, Buflen+1)
return DllCall("libcurl\curl_easy_recv"
,"UInt" ,cHandle
,"UInt*",Buffer
,"UInt" ,BufLen
,"UInt*",RecvBytes), RecvBytes:=NumGet(RecvBytes)
}
/*
Function: Easy_Pause
Pause and unpause a connection.
Using this function, you can explicitly mark a running connection to get paused or unpaused.
A connection can be paused by using this function or by letting the read or the write callbacks return the
proper magic return code(*CURL_READFUNC_PAUSE* and *CURL_WRITEFUNC_PAUSE*). A write callback that returns pause
signals to the library that it couldn't take care of any data at all, and that data will then be delivered
again to the callback when the writing is later unpaused.
When this function is called to unpause reading, the chance is high that you will get your write callback
called before this function returns.
*NOTE*: while it may feel tempting, take care and notice that you cannot call this function from another thread.
See: <http://curl.haxx.se/libcurl/c/curl_easy_pause.html>
Parameters:
> cURL_Easy_Pause(cHandle, BitMask)
cHandle - CURL handle.
BitMask - This argument is a set of bits that sets the new state of the connection.
The following bits can be used:
- *CURLPAUSE_RECV*: Pause _receiving_ data.
There will be no data received on this connection until this function
is called again without this bit set. Thus, the write callback (CURLOPT_WRITEFUNCTION) won't
be called.
- *CURLPAUSE_SEND*: Pause _sending_ data. There will be no data sent on this connection until
this function is called again without this bit set. Thus, the read callback
(CURLOPT_READFUNCTION) won't be called.
- *CURLPAUSE_ALL*: Convenience define that pauses both directions.
- *CURLPAUSE_CONT*: Convenience define that unpauses both directions.
Returns:
*CURLE_OK* (zero) means that the option was set properly, and a non-zero return code means something wrong
occurred after the new state was set as <curl/curl.h> defines.
See the libcurl-errors(3) man page for the full list with descriptions.
Availability:
This function was added in libcurl 7.18.0. Before this version, there was no explicit support for pausing
transfers.
Memory Use:
When pausing a read by returning the magic return code from a write callback, the read data is already in
libcurl's internal buffers so it'll have to keep it in an allocated buffer until the reading is again unpaused
using this function.
If the downloaded data is compressed and is asked to get uncompressed automatically on download, libcurl will
continue to uncompress the entire downloaded chunk and it will cache the data uncompressed. This has the side-
effect that if you download something that is compressed a lot, it can result in a very large data
amount needing to be allocated to save the data during the pause. This said, you should probably consider not
using paused reading if you allow libcurl to uncompress data automatically.
*/
cURL_Easy_Pause(cHandle, BitMask){
return DllCall("libcurl\curl_easy_pause", "UInt", cHandle, "Uint", CURL(BitMask))
}
/*
Function: Easy_Reset
Reset all options of a libcurl session handle.
Re-initializes all options previously set on a specified CURL handle to the default values. This puts back the
handle to the same state as it was in when it was just created with <Easy_Init()>.
It does not change the following information kept in the handle: live connections, the Session ID cache, the
DNS cache, the cookies and shares.
See: <http://curl.haxx.se/libcurl/c/curl_easy_reset.html>
Parameters:
> cURL_Easy_Reset(cHandle)
cHandle - CURL handle.
Returns:
Nothing is returned by this function.
*/
cURL_Easy_Reset(cHandle){
return DllCall("libcurl\curl_easy_reset", "UInt", cHandle)
}
/*
Function: Easy_StrError
Return string describing error code.
The *Easy_StrError()* function returns a string describing the CURLcode error code passed in the argument
ErrCode.
See: <http://curl.haxx.se/libcurl/c/curl_easy_strerror.html>
Parameters:
> cURL_Easy_StrError(ErrCode)
ErrCode - CURLE code returned by any of the cURL functions.
Returns:
A pointer to a zero terminated string.
*/
cURL_Easy_StrError(ErrCode){
EStr:=DllCall("libcurl\curl_easy_strerror", "UInt", ErrCode, "Str")
return a_isunicode ? StrGet(&EStr, "CP0") : EStr
}
/*
Function: Easy_Escape
URL encodes the given string.
This function converts the given input string to an URL encoded string and returns that as a new allocated
string. All input characters that are not a-z, A-Z or 0-9 are converted to their "URL escaped" version (%NN
where NN is a two-digit hexadecimal number).
You must <Free()> the returned string when you're done with it.
See: <http://curl.haxx.se/libcurl/c/curl_easy_escape.html>
Parameters:
> cURL_Easy_Escape(cHandle, URL[, uLen])
cHandle - CURL handle.
URL - String you wish to convert to its "URL escaped" version (%NN where NN is two hex numbers).
uLen - Length of the string passed. If not given the function uses *StrLen()* to determine the size.
Returns:
A pointer to a zero terminated string or *NULL* if it failed.
Availability:
Added in 7.15.4 and replaces the old curl_escape(3) function.
*/
cURL_Easy_Escape(cHandle, URL, uLen=0){
return DllCall("libcurl\curl_easy_escape"
,"UInt", cHandle
,"Str" , URL
,"UInt", uLen ? uLen : StrLen(URL))
}
/*
Function: Easy_UnEscape
URL decodes the given string.
This function converts the given URL encoded input string to a "plain string" and returns that in an allocated
memory area. All input characters that are URL encoded (%NN where NN is a two-digit hexadecimal number) are
converted to their binary versions.
If outlength is non-*NULL*, the function will write the length of the returned string in the integer it points
to. This allows an escaped string containing %00 to still get used properly after unescaping.
You must <Free()> the returned string when you're done with it.
See: <http://curl.haxx.se/libcurl/c/curl_easy_unescape.html>
Parameters:
> cURL_Easy_UnEscape(cHandle, URL[, iLen, oLen])
cHandle - CURL handle.
URL - String you wish to convert to its "URL escaped" version (%NN where NN is two hex numbers).
iLen - Length of the string passed. If not given the function uses *StrLen()* to determine the size.
oLen - if this variable is not *NULL*, the function will write the length of the returned string in
the integer it points to. This allows an escaped string containing %00 to still get used
properly after unescaping.
Returns:
A pointer to a zero terminated string or *NULL* if it failed.
Availability:
Added in 7.15.4 and replaces the old curl_unescape(3) function.
*/
cURL_Easy_UnEscape(cHandle, URL, iLen=0, Byref oLen=0){
return DllCall("libcurl\curl_easy_unescape"
,"UInt" ,cHandle
,"Str" ,URL
,"UInt" ,iLen ? iLen : StrLen(URL)
,"UInt*",oLen)
}
cURL_CreateFile( sFile
,tCreate="CREATE_NEW"
,tAccess="GENERIC_RW"
,tShare="FILE_SHARE_READ"
,tFlags="FILE_ATTRIBUTE_NORMAL" ){
st:="Create,Access,Share,Flags"
Loop, Parse, st, `,
{
extLoopField:=a_loopfield, %extLoopField%:=0
Loop, Parse, t%a_loopfield%, %a_tab%%a_space%, %a_tab%%a_space%
%extLoopField% |= FILE(a_loopfield)
}
return DllCall("CreateFile"
,"Uint" ,&sFile
,"UInt" ,Access
,"UInt" ,Share
,"UInt" ,0
,"UInt" ,Create
,"UInt" ,Flags
,"UInt" ,0)
}
cURL_ReadFile(ptr, size, nmemb, hFile){
tRead := ""
DllCall("ReadFile"
,"UInt" ,hFile
,"UInt" ,ptr
,"UInt" ,size*nmemb