Monthly Target: $400 Donations: $13
 3% 

[EXTENSION] cURL & Hash


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
raydan
Senior Member
Join Date: Aug 2006
Old 03-06-2011 , 04:41   [EXTENSION] cURL & Hash
Reply With Quote #1


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


Last edited by raydan; 01-07-2012 at 06:44.
raydan is offline
Thrawn2
Veteran Member
Join Date: Apr 2009
Old 03-06-2011 , 11:24   Re: [EXTENSION] cURL
Reply With Quote #2

thanks. surely will come in handy here or there.
__________________
einmal mit profis arbeiten. einmal.
Thrawn2 is offline
raydan
Senior Member
Join Date: Aug 2006
Old 03-11-2011 , 05:24   Re: [EXTENSION] cURL & Hash
Reply With Quote #3

on next version, all file handle, httppost handle, curl_slist handle can use CloseHandle() to close

Also, i try make a curl + msn example
raydan is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 03-16-2011 , 14:44   Re: [EXTENSION] cURL & Hash
Reply With Quote #4

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!
GoD-Tony is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 03-18-2011 , 03:18   Re: [EXTENSION] cURL & Hash
Reply With Quote #5

Quote:
Originally Posted by GoD-Tony View Post
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
KyleS is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 04-05-2011 , 08:03   Re: [EXTENSION] cURL & Hash
Reply With Quote #6

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.
GoD-Tony is offline
raydan
Senior Member
Join Date: Aug 2006
Old 04-07-2011 , 09:29   Re: [EXTENSION] cURL & Hash
Reply With Quote #7

Quote:
Originally Posted by GoD-Tony View Post
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
__________________
too slow
raydan is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 04-07-2011 , 10:34   Re: [EXTENSION] cURL & Hash
Reply With Quote #8

Quote:
Originally Posted by raydan View Post
next version will support write/read function
Great!
GoD-Tony is offline
Astridax
Member
Join Date: Dec 2009
Old 07-17-2011 , 12:24   Re: [EXTENSION] cURL & Hash
Reply With Quote #9

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.
Astridax is offline
unt0uch4bl3
Junior Member
Join Date: Apr 2009
Old 09-05-2011 , 01:27   Re: [EXTENSION] cURL & Hash
Reply With Quote #10

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
???
unt0uch4bl3 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:07.


Powered by vBulletin®
Copyright ©2000 - 2015, vBulletin Solutions, Inc.
Theme made by Freecode