Thread: Module: Curl
View Single Post
Author Message
Levenus Supremus
Junior Member
Join Date: Jan 2012
Location: St.Petersburg
Old 07-27-2016 , 06:20   Module: Curl
Reply With Quote #1

UPDATE
Note the new module https://github.com/Next21Team/AmxxEasyHttp
It has new easy to use API! Without read/write callbacks, problems with certificates and does not require clearing resources.

Description:
AmxxCurl module is a wrapper over libcurl easy interface for amxmodx. Module performs curl's in non-blocking mode.

Download latest version here.

Few words about libcurl (from wiki page):
Quote:
libcurl is a free client-side URL transfer library, supporting FTP, FTPS, Gopher, HTTP, HTTPS, SCP, SFTP, TFTP, Telnet, DICT, the file URI scheme, LDAP, LDAPS, IMAP, POP3, SMTP and RTSP. The library supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, Kerberos, HTTP form-based upload, proxies, cookies, user-plus-password authentication, file transfer resume, and HTTP proxy tunneling.
So, this means that with this module you can send/check mails via IMAP, POP3 protocols; perform HTTPS requests (example); download/upload files over FTP (example). And it's only general capabilities. Here some examples written on C, but it almost that Pawn)

Natives:
All natives you can find in curl.inc, they have the same behaviour that C functions.

Except for some:
1)
Code:
native void:curl_easy_perform(const CURL:handle, const callbackComplite[], const data[] = {}, const data_len = 0)
The function starts curl perform, and upon completion of the transfer will be call callback callbackComplite. In third parameter you can specify an array of user data, wich will be transferred to callbackComplite, and fourth parameter is array length.

If user data set, callback should have the signature:
Code:
public compliteCallback(CURL:curl, CURLcode:code, data[])
else:
Code:
public compliteCallback(CURL:curl, CURLcode:code)
2)
Code:
native CURLcode:curl_easy_getinfo(const CURL:handle, const CURLINFO:info, any:...)
For string type of CURLINFO option, you must set fourth argument - string size:
Code:
new url[64]
curl_easy_getinfo(curl,CURLINFO_EFFECTIVE_URL, url, charsmax(url))
Important things
1) if you are using callback WRITEFUNCTION, always specify the option CURLOPT_BUFFERSIZE. Specify something about 512-1024, or risk getting a stack overflow error.
2) If you are would like to use READFUNCTION callback, set pragma dynamic in 16536 or more:
Code:
#pragma dynamic 16536
Author: Polarhigh (aka Levenus Supremus)
Source code: https://github.com/Polarhigh/AmxxCurl
Releases: https://github.com/Polarhigh/AmxxCurl/releases

Last edited by Levenus Supremus; 02-09-2022 at 05:02. Reason: removed dependence on SoLoader
Levenus Supremus is offline