AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [EXTENSION] cURL & Hash (https://forums.alliedmods.net/showthread.php?t=152216)

raydan 03-06-2011 04:41

[EXTENSION] cURL & Hash
 

A cURL extension in Sourcemod

A free and easy-to-use client-side URL transfer library, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos), file transfer resume, http proxy tunneling and more!

cURL Website: http://curl.haxx.se/

Current Version: 1.3.0.0

This a a sourcemod extension, using libcurl
Current libcurl Information:
Version: libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5 libssh2/1.3.0
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp

The extension includes 2 hash function (file hash, string hash), provided by openssl library:
Code:

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,
};
 
native curl_hash_file(const String:file[], Openssl_Hash:algorithm, Openssl_Hash_Complete:complete_callback, any:value=0);
 
native bool:curl_hash_string(const String:input[], dataSize, Openssl_Hash:algorithm, String:buffer[], maxlength);

More natives in cURL.inc or here



Developer Notes
  • Downloload the curl_examples.zip to see how to use
  • curl_echo.sp echo client test
  • curl_rcon.sp make a source rcon query to other server
  • curl_gmail.sp use read function send a email
  • curl_udp.sp send A2S_INFO to source server & get the result
  • curl_write_function.sp use write function download files
  • see http://curl.haxx.se/libcurl/c/example.html
Self Test
  • compile curl_self_test.sp & run curl_self_test and curl_hash_test
  • All output test files in addons/sourcemod/data/curl_test
    Test #1 Get cURL version & supported protocols
    Test #2 Get a web page
    Test #3 Get ca-bundle.crt for #4
    Test #4 Verify a https website using ca-bundle.crt
    Test #5 Get a web page body & header content to file
    Test #6 Download a image for #7
    Test #7 Upload image using curl_httppost() & get the uploaded image url
    Test #8 Download a file using ftps://
Sourcecode
https://code.google.com/p/sourcemod-curl-extension/

Download
https://code.google.com/p/sourcemod-...downloads/list


the windows version should install the following package (thanks Thrawn2 to figure out)
Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package MFC Security Update
http://www.microsoft.com/download/en....aspx?id=26347

:3

Thrawn2 03-06-2011 11:24

Re: [EXTENSION] cURL
 
thanks. surely will come in handy here or there.

raydan 03-11-2011 05:24

Re: [EXTENSION] cURL & Hash
 
on next version, all file handle, httppost handle, curl_slist handle can use CloseHandle() to close

Also, i try make a curl + msn example

GoD-Tony 03-16-2011 14:44

Re: [EXTENSION] cURL & Hash
 
I was going to make a plugin that used Google Translate for various features. This extension will definitely be useful (and I'd prefer this over sockets). Thanks!

KyleS 03-18-2011 03:18

Re: [EXTENSION] cURL & Hash
 
Quote:

Originally Posted by GoD-Tony (Post 1434295)
I was going to make a plugin that used Google Translate for various features. This extension will definitely be useful (and I'd prefer this over sockets). Thanks!

If you get it functioning, please share it :wink:

GoD-Tony 04-05-2011 08:03

Re: [EXTENSION] cURL & Hash
 
On your Test #5 you save output to a file using fwrite:
Code:

CURL_DEFAULT_OPT(curl);
test_5_file_body = CreateTestFile("test5_body.txt", "w");
test_5_file_header = CreateTestFile("test5_header.txt", "w");
curl_easy_setopt_handle(curl, CURLOPT_WRITEDATA, test_5_file_body);
curl_easy_setopt_handle(curl, CURLOPT_HEADERDATA, test_5_file_header);
curl_easy_setopt_string(curl, CURLOPT_URL, "http://www.google.co.uk/index.html");

But I would like to change the callback function to something else. Normally when using libcurl it would be something like this:
Code:

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, mycallback)
Is it possible to do this using your extension? And how would I set up the callback?

My objective would be to fetch the contents of a page into a string.

raydan 04-07-2011 09:29

Re: [EXTENSION] cURL & Hash
 
Quote:

Originally Posted by GoD-Tony (Post 1444720)
On your Test #5 you save output to a file using fwrite:
Code:

CURL_DEFAULT_OPT(curl);
test_5_file_body = CreateTestFile("test5_body.txt", "w");
test_5_file_header = CreateTestFile("test5_header.txt", "w");
curl_easy_setopt_handle(curl, CURLOPT_WRITEDATA, test_5_file_body);
curl_easy_setopt_handle(curl, CURLOPT_HEADERDATA, test_5_file_header);
curl_easy_setopt_string(curl, CURLOPT_URL, "http://www.google.co.uk/index.html");

But I would like to change the callback function to something else. Normally when using libcurl it would be something like this:
Code:

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, mycallback)
Is it possible to do this using your extension? And how would I set up the callback?

My objective would be to fetch the contents of a page into a string.

next version will support write/read function

GoD-Tony 04-07-2011 10:34

Re: [EXTENSION] cURL & Hash
 
Quote:

Originally Posted by raydan (Post 1445729)
next version will support write/read function

Great! :)

Astridax 07-17-2011 12:24

Re: [EXTENSION] cURL & Hash
 
This might just help me immensely. However I'm a bit new to Sourcemod scripting. Can somebody explain how I would get data from a URL as follows:

http://makeavoice.com/shoutcast/webs...XXX&refresh=XX

It's to receive the track name from said website.

unt0uch4bl3 09-05-2011 01:27

Re: [EXTENSION] cURL & Hash
 
Code:

L 09/05/2011 - 00:23:59: [SM] Unable to load extension "curl.ext":
/.../orangebox/cstrike/addons/sourcemod/extensions/curl.ext.so: undefined
symbol: _ZN9__gnu_cxx18__exchange_and_addEPVii

???


All times are GMT -4. The time now is 04:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.