aboutsummaryrefslogtreecommitdiff
path: root/pawn/scripting/include/cURL.inc
blob: 1d7909361a035e3bf5a114c94e0fd8cd39442016 (plain)
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

#if defined _cURL_included
  #endinput
#endif
#define _cURL_included

#include <cURL_header>


/*
========================================
The Following CURLOPT_* NOT support 
ERRORBUFFER              // use curl_get_error_buffer
WRITEINFO                // ???
PROGRESSFUNCTION         // unused
PROGRESSDATA             // same
HEADERFUNCTION           // unused
DEBUGFUNCTION            // unused
DEBUGDATA                // same
SHARE                    // unsupport
PRIVATE                  // unsupport
SSL_CTX_FUNC             // unused
SSL_CTX_DATA             // same
IOCTLFUNCTION            // unused
IOCTLDATA                // same
CONV_FROM_NETWORK_FUNC   // unused
CONV_TO_NETWORK_FUNC     // unused
CONV_FROM_UTF8_FUNC      // unused
SOCKOPTFUNCTION          // unused
SOCKOPTDATA              // unused
OPENSOCKETFUNCTION       // used
OPENSOCKETDATA           // used
COPYPOSTFIELDS           // unsupport
SEEKFUNCTION             // unused
SEEKDATA                 // unused
SOCKS5_GSSAPI_SERVICE    // unsupport
SOCKS5_GSSAPI_NEC        // unsupport
SSH_KEYFUNCTION          // unsupport
SSH_KEYDATA              // unsupport
INTERLEAVEFUNCTION       // unsupport
CHUNK_BGN_FUNC           // unsupport
CHUNK_END_FUNC           // unsupport
FNMATCH_FUNC             // unsupport
CHUNK_DATA               // unsupport
FNMATCH_DATA             // unsupport
TLSAUTH_USERNAME         // unsupport, require tls-srp
TLSAUTH_PASSWORD         // unsupport, require tls-srp
TLSAUTH_TYPE             // unsupport, require tls-srp
CLOSESOCKETFUNCTION      // unsupport
CLOSESOCKETDATA          // unsupport
========================================*/

/*
========================================
The Following CURLOPT_* supports the "file //" notation.
COOKIEFILE
COOKIEJAR
RANDOM_FILE
EGDSOCKET
SSLKEY
CAPATH
NETRC_FILE
SSH_PUBLIC_KEYFILE
SSH_PRIVATE_KEYFILE
_CRLFILE
ISSUERCERT
SSH_KNOWNHOSTS

========================================*/

/*
========================================
The Following CURLINFO_* NOT support 
CURLINFO_SLIST

========================================*/

/*
========================================
The Following CURLFORM_* NOT support 
CURLFORM_PTRNAME
CURLFORM_PTRCONTENTS
CURLFORM_ARRAY
CURLFORM_BUFFER
CURLFORM_BUFFERPTR
CURLFORM_BUFFERLENGTH
CURLFORM_STREAM

========================================*/




/*************************************************************************************************/
/******************************************** OPTIONS ********************************************/
/*************************************************************************************************/


/**
 * The Send & Receive Action
 * Using on CURL_OnSend, CURL_OnReceive
 * SendRecv_Act_GOTO_SEND = go to send
 * SendRecv_Act_GOTO_RECV = go to receive
 * SendRecv_Act_GOTO_WAIT = go to wait
 * SendRecv_Act_GOTO_END = end the connection
 * SendRecv_Act_GOTO_SEND_NO_WAIT = go to send but no select
 * SendRecv_Act_GOTO_RECV_NO_WAIT = go to receive but no select
 * To see how it work? see curl_echo_test.sp & curl_rcon_test.sp examples
 */
enum SendRecv_Act {
	SendRecv_Act_NOTHING = 0,

	SendRecv_Act_GOTO_SEND,
	SendRecv_Act_GOTO_RECV,
	SendRecv_Act_GOTO_WAIT,
	SendRecv_Act_GOTO_END,
	SendRecv_Act_GOTO_SEND_NO_WAIT,
	SendRecv_Act_GOTO_RECV_NO_WAIT,

	SendRecv_Act_LAST,
};

/**
 * Hash type for curl_hash_file, curl_hash_string
 */
enum Openssl_Hash {
	Openssl_Hash_MD5 = 0,
	Openssl_Hash_MD4,
	Openssl_Hash_MD2,
	Openssl_Hash_SHA,
	Openssl_Hash_SHA1,
	Openssl_Hash_SHA224,
	Openssl_Hash_SHA256,
	Openssl_Hash_SHA384,
	Openssl_Hash_SHA512,
	Openssl_Hash_RIPEMD160,
};


/*************************************************************************************************/
/******************************************* CALLBACKS *******************************************/
/*************************************************************************************************/


/**
 * called if curl_easy_perform_thread() or curl_easy_send_recv() Complete
 * @ param Handle	hndl		The curl handle
 * @ param CURLcode	code		The CURLcode code, see cURL_header.inc
 * @ param any		data		Data passed to curl_easy_perform_thread()
 * @ noreturn
 */
typeset CURL_OnComplete
{
	function void (Handle hndl, CURLcode code);
	function void (Handle hndl, CURLcode code , any data);
};

/**
 * called if curl_easy_send_recv() before sending data
 * @ param Handle	hndl				The curl handle
 * @ param CURLcode	code				The last CURLcode code, see cURL_header.inc
 * @ param cell_t	last_sent_dataSize	The last sent datasize
 * @ param any		data				Data passed to curl_easy_send_recv()
 * @ return 								SendRecv_Act
 */
typeset CURL_OnSend
{
	function SendRecv_Act (Handle hndl, CURLcode code, const int last_sent_dataSize);
	function SendRecv_Act (Handle hndl, CURLcode code, const int last_sent_dataSize, any data);
}

/**
 * called if curl_easy_send_recv() after received data
 * @ param Handle	hndl		The curl handle
 * @ param CURLcode	code		The CURLcode code, see cURL_header.inc
 * @ param String	dataSize	The received datasize
 * @ param any		data		Data passed to curl_easy_send_recv()
 * @ return 						SendRecv_Act
 */
typeset CURL_OnReceive
{
	function SendRecv_Act (Handle hndl, CURLcode code, const char[] receiveData, const int dataSize);
	function SendRecv_Act (Handle hndl, CURLcode code, const char[] receiveData, const int dataSize, any data);
}

/**
 * called if Openssl_Hash_file() after hashed the file
 * @ param bool		success		True on success, false if hash file fail
 * @ param String	buffer		The hash string
 * @ param any		data		Data passed to Openssl_Hash_file()
 * @ noreturn
 */
typeset Openssl_Hash_Complete
{
	function void (const bool success, const char[] buffer);
	function void (const bool success, const char[] buffer, any data);
}


typeset CURL_Function_CB
{
	// CURLOPT_WRITEFUNCTION
	function void (Handle hndl, const char[] buffer, const int bytes, const int nmemb);
	function void (Handle hndl, const char[] buffer, const int bytes, const int nmemb, any data);
	
	// CURLOPT_READFUNCTION
	function void (Handle hndl, const int bytes, const int nmemb);
	function void (Handle hndl, const int bytes, const int nmemb, any data);
}

/*************************************************************************************************/
/******************************************** NATIVES ********************************************/
/*************************************************************************************************/


/**
 * Create a curl handle
 * @ return Handle				The curl handle. Returns INVALID_HANDLE on failure
 */
native Handle curl_easy_init();

/**
 * Set a curl option for CURLOPTTYPE_OBJECTPOINT type
 *
 * @ param Handle		hndl	The handle of the curl to be used. May be INVALID_HANDLE if not essential.
 * @ param CURLoption	opt		The option to add (see enum CURLoption for details).
 * @ param String		buffer	The value to set the option to.
 * @ return bool				1 on success. 0 = The option not accept string or unsupport.
 */
native bool curl_easy_setopt_string(Handle hndl, CURLoption opt, const char[] buffer);

/**
 * Set a curl option for CURLOPTTYPE_LONG type
 *
 * @ param Handle		hndl	The handle of the curl to be used. May be INVALID_HANDLE if not essential.
 * @ param CURLoption	opt		The option to add (see enum CURLoption for details).
 * @ param cell_t		value	The value to set the option to.
 * @ return bool				1 on success. 0 = The option not accept integer or unsupport.
 */
native bool curl_easy_setopt_int(Handle hndl, CURLoption opt, int value);

/**
 * Set a curl option for CURLOPTTYPE_LONG type
 * @ example"
	new opt[][2] = {
		{_ CURLOPT_NOPROGRESS,1},
		{_ CURLOPT_VERBOSE,0}
	};
 *
 * @ param Handle		hndl		The handle of the curl to be used. May be INVALID_HANDLE if not essential.
 * @ param cell_t		array		The option array to add (see enum CURLoption for details).
 * @ param cell_t		array_size	The array size.
 * @ return bool					1 on success. 0 = The option not accept integer or unsupport.
 */
native bool curl_easy_setopt_int_array(Handle hndl, int[][] array, int array_size); // int array[][2]

/**
 * Set a curl option for CURLOPTTYPE_OFF_T type
 *
 * @ param Handle		hndl	The handle of the curl to be used. May be INVALID_HANDLE if not essential.
 * @ param CURLoption	opt		The option to add (see enum CURLoption for details).
 * @ param String		buffer	The value to set the option to.
 * @ return bool				1 on success. 0 = The option not accept string or unsupport.
 */
native bool curl_easy_setopt_int64(Handle hndl, CURLoption opt, const char buffer);

/**
 * Set a curl option for CURLOPTTYPE_OBJECTPOINT type
 * @ note only accept the following handle type
 	curl_OpenFile()
 	curl_httppost()
 	curl_slist()
 *
 * @ param Handle		hndl		The handle of the curl to be used. May be INVALID_HANDLE if not essential.
 * @ param CURLoption	opt			The option to add (see enum CURLoption for details).
 * @ param Handle		other_hndl	The other handle to set the option to.
 * @ return bool					1 on success. 0 = The option not accept string or unsupport.
 */
native bool curl_easy_setopt_handle(Handle hndl, CURLoption opt, Handle other_hndl);

/**
 * Set a curl option for CURLOPTTYPE_FUNCTIONPOINT type
 *
 * @ param Handle				hndl		The handle of the curl to be used. May be INVALID_HANDLE if not essential.
 * @ param CURLoption			opt			The option to add (see enum CURLoption for details).
 * @ param CURL_Function_CB		callback	The value to set the option to.
 * @ param cell_t				value		Value to set.
 * @ return bool							1 on success. 0 = The option unsupport or invalid callback function.
 */
native bool curl_easy_setopt_function(Handle hndl, CURLoption opt, CURL_Function_CB callback, any value=0);

/**
 * Load all CURLoption to curl Handle
 * @ note
 * 		Using curl_easy_perform_thread() will load option in thread
 * 		Use this on curl_easy_perform or check all CURLoption are valid or not
 * 		Only can use one time for each curl handle
 * @ return 		The CURLcode code, see cURL_header.inc
 */
native CURLcode curl_load_opt(Handle hndl);

/**
 * Perform a file transfer
 * @ return 		The CURLcode code, see cURL_header.inc
 */
native CURLcode curl_easy_perform(Handle hndl);

/**
 * Perform a file transfer, using thread
 * @ param Handle			hndl				The handle of the curl to be used. May be INVALID_HANDLE if not essential.
 * @ param CURL_OnComplete	perform_callback	The complete callback.
 * @ param cell_t			value				Value to set.
 * @ noreturn
 */
native void curl_easy_perform_thread(Handle hndl, CURL_OnComplete perform_callback, any value=0);

/**
 * Create a send & receive function for a connected curl handle
 * @ param Handle			hndl				The handle of the curl to be used.
 * @ param CURL_OnSend		send_callback		The send callback.
 * @ param CURL_OnReceive	receive_callback	The receive callback.
 * @ param CURL_OnComplete	complete_callback	The complete callback.
 * @ param SendRecv_Act		act 				The first SendRecv_Act action
 * @ param cell_t			send_timeout 		Send timeout value in milliseconds.
 * @ param cell_t			recv_timeout 		Receive timeout value in milliseconds.
 * @ param cenn_t			recv_buffer_Size	Receive buffer size.
 * @ param cell_t			value				Value to set.
 * @ noreturn
 */
native void curl_easy_send_recv(Handle hndl, CURL_OnSend send_callback, CURL_OnReceive receive_callback, CURL_OnComplete complete_callback, SendRecv_Act act, int send_timeout, int recv_timeout, int recv_buffer_Size = 1024, any value=0);

/**
 * Send a signal to a send & receive curl handle 
 * @ param Handle			hndl			The handle of the send & receive curl to be used.
 * @ param SendRecv_Act		act				The SendRecv_Act action after the singal
 * @ return bool							1 on success. 0 = not a curl_easy_send_recv() curl, or not running/waiting
 */
native bool curl_send_recv_Signal(Handle hndl, SendRecv_Act act);

/**
 * Check send & receive curl handle is Waiting or not
 * @ param Handle			hndl			The handle of the send & receive curl to be used.
 * @ return bool		1 = is waiting. 0 = not a curl_easy_send_recv() curl, or not running/waiting
 */
native bool curl_send_recv_IsWaiting(Handle hndl);

/**
 * Send the send buffer for send & receive curl handle
 * @ param Handle			hndl			The handle of the send & receive curl to be used.
 * @ param cell_t			data			The data to send
 * @ param cell_t			size			if specified the \0 terminator will not be included
 * @ noreturn
 */
native void curl_set_send_buffer(Handle hndl, const char[] data, int size=-1);

/**
 * Send the receive data size for send & receive curl handle
 * @ param Handle			hndl			The handle of the send & receive curl to be used.
 * @ param cell_t			size			The receive size
 * @ noreturn
 */
native void curl_set_receive_size(Handle hndl, int size);

/**
 * Set send timeout for curl_easy_send_recv()
 * @ param Handle			hndl			The handle of the send & receive curl to be used.
 * @ param cell_t			timeout			How long will try to send data before it timeout (milliseconds).
 * @ noreturn
 */
native void curl_set_send_timeout(Handle hndl, int timeout);

/**
 * Set receive timeout for curl_easy_send_recv()
 * @ param Handle			hndl			The handle of the send & receive curl to be used.
 * @ param cell_t			timeout			How long will try to receive data before it timeout (milliseconds).
 * @ noreturn
 */
native void curl_set_recv_timeout(Handle hndl, int timeout);

/**
 * Get CURLOPT_ERRORBUFFER error string in curl handle
 * @ param Handle		hndl		The handle of the curl to be used.
 * @ param String		buffer		Destination string buffer to copy to.
 * @ param cell_t		maxlen		Destination buffer length (includes null terminator).
 * @ noreturn
 */
native void curl_get_error_buffer(Handle hndl, char[] buffer, int maxlen);

/**
 * Extract information from a curl handle. (CURLINFO_STRING only)
 * @ param Handle		hndl		The handle of the curl to be used.
 * @ param CURLINFO		info		The enum CURLINFO, see cURL_header.inc
 * @ param String		buffer		Destination string buffer to copy to.
 * @ param cell_t		maxlen		Destination buffer length (includes null terminator).
 * @ return 						The CURLcode code, see cURL_header.inc
 */
native CURLcode curl_easy_getinfo_string(Handle hndl, CURLINFO info, char[] buffer, int maxlen);

/**
 * Extract information from a curl handle. (CURLINFO_LONG, CURLINFO_DOUBLE only)
 * @ param Handle		hndl		The handle of the curl to be used.
 * @ param CURLINFO		info		The enum CURLINFO, see cURL_header.inc
 * @ param 				value		Variable to store the value.
 * @ return 						The CURLcode code, see cURL_header.inc
 */
native CURLcode curl_easy_getinfo_int(Handle hndl, CURLINFO info, any &value);

/**
 * URL encodes the given string 
 * @ param Handle		hndl		The handle of the curl to be used.
 * @ param String		url			The string to encodes.
 * @ param String		buffer		Destination string buffer to copy to.
 * @ param cell_t		maxlen		Destination buffer length (includes null terminator).
 * @ return 						1 on success.
 */
native bool curl_easy_escape(Handle hndl, const char[] url, char[] buffer, int maxlen);

/**
 * URL decodes the given string 
 * @ param Handle		hndl		The handle of the curl to be used.
 * @ param String		url			The string to dencodes.
 * @ param String		buffer		Destination string buffer to copy to.
 * @ param cell_t		maxlen		Destination buffer length (includes null terminator).
 * @ return 						The output length.
 */
native int curl_easy_unescape(Handle hndl, const char[] url, char[] buffer, int maxlen);

/**
 * Return string describing error code
 * @ param CURLcode		code		The CURLcode code, see cURL_header.inc
 * @ param String		buffer		Destination string buffer to copy to.
 * @ param cell_t		maxlen		Destination buffer length (includes null terminator).
 * @ noreturn
 */
native void curl_easy_strerror(CURLcode code, char[] buffer, int maxlen);

/**
 * Returns the libcurl version string
 * @ param String		buffer		Destination string buffer to copy to.
 * @ param cell_t		maxlen		Destination buffer length (includes null terminator).
 * @ noreturn
 */
native void curl_version(char[] buffer, int maxlen);

/**
 * Returns the libcurl supported protocols string
 * @ param String		buffer		Destination string buffer to copy to.
 * @ param cell_t		maxlen		Destination buffer length (includes null terminator).
 * @ noreturn
 */
native void curl_protocols(char[] buffer, int maxlen);

/**
 * Returns the libcurl supported features
 * @ return			The currently features bits. see CURL_VERSION_*
 */
native int curl_features();

/**
 * This funcitopn same as Sourcemod OpenFile()
 * For the following CUROPT_* only
 * 		CURLOPT_WRITEDATA
 *		CURLOPT_HEADERDATA
 *		CURLOPT_READDATA
 *		CURLOPT_STDERR
 *		CURLOPT_INTERLEAVEDATA
 *
 * @ note
 * 		Should not share to another threaded curl handle.
 *
 * @ param file			File to open.
 * @ param mode			Open mode.
 * @ return				A Handle to the file, INVALID_HANDLE on open error.
 */
native Handle curl_OpenFile(const char[] file, const char[] mode);


/**
 * Create a curl_httppost struct
 * For the following CUROPT_* only
 * 		CURLOPT_HTTPPOST
 * @ note
 * 		Should not share to another threaded curl handle.
 *
 * @ return				A Handle to the curl_httppost, INVALID_HANDLE on error.
 */
native Handle curl_httppost();

/**
 * Add a section to a multipart/formdata HTTP POST
 * @ note
 *		Check enum CURLformoption (cURL_head.inc) to see which option supported
 *
 * @ param Handle		hndl		The handle of the curl_httppost to be used.
 * @ param 				...			Variable number of format parameters.
 * @ return 						The CURLFORMcode code, see cURL_header.inc
 */
native CURLFORMcode curl_formadd(Handle handl, any ...);

/**
 * Create a curl_slist struct
 * For the following CUROPT_* only
 * 		CURLOPT_QUOTE
 *		CURLOPT_HTTPHEADER
 *		CURLOPT_POSTQUOTE
 *		CURLOPT_TELNETOPTIONS
 *		CURLOPT_PREQUOTE
 *		CURLOPT_HTTP200ALIASES
 *		CURLOPT_MAIL_RCPT
 *		CURLOPT_RESOLVE
 *
 * @ note
 * 		Should not share to another threaded curl handle.
 *
 * @ return				A Handle to the curl_slist, INVALID_HANDLE on error.
 */
native Handle curl_slist();

/**
 *  Add a string to an slist
 * @ param Handle		hndl		The handle of the curl_slist to be used.
 * @ param String		buffer		The string to add
 * @ noreturn
 */
native void curl_slist_append(Handle hndl, const char[] buffer);

/**
 * Hash a file
 * @ parma String					file 				The file path. supports the "file //" notation.
 * @ param Openssl_Hash				algorithm			Hash Algorithm.
 * @ param Openssl_Hash_Complete	complete_callback	The complete callback.
 * @ param cell_t					value				Value to set.
 * @ noreturn
 */
native void curl_hash_file(const char[] file, Openssl_Hash algorithm, Openssl_Hash_Complete complete_callback, any value=0);

/**
 * Hash a string
 * @ parma String			input			The string to hash.
 * @ param cell_t			dataSize		The input string size.
 * @ param Openssl_Hash		algorithm		Hash Algorithm.
 * @ param String			buffer			Destination string buffer to copy to.
 * @ param cell_t			maxlen			Destination buffer length (includes null terminator).
 * @ return									1 on success
 */
native bool curl_hash_string(const char[] input, int dataSize, Openssl_Hash algorithm, char[] buffer, int maxlength);


/**
 * Do not edit below this line!
 */
public Extension __ext_curl = {
	name = "curl",
	file = "curl.ext",
#if defined AUTOLOAD_EXTENSIONS
	autoload = 1,
#else
	autoload = 0,
#endif
#if defined REQUIRE_EXTENSIONS
	required = 1,
#else
	required = 0,
#endif
};