libRevCurl

Find out what's going on with LiveCode (the company), product releases, announcements, and events.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

libRevCurl

Post by Mark Smith » Sat Aug 09, 2008 7:57 pm

I've released a beta version of a library that wraps the curl command line tool.

It's not intended as a replacement for libUrl, but has been developed to cover situations tha libUrl either doesn't at all, or doesn't quite:

http PUT,HEAD,DELETE,OPTIONS,TRACE
https - there still seem to be problems with secure sockets in Revolution, so this just gets around it.
http uploads from files on disc.

I won't try to describe the interface here, but I've included a short intro pdf with examples, and a dictionary. There's a lot of stuff in the library that I haven't yet documented, and some things I haven't yet been able to test, but they can be found if anyone wants to have a look at the code - a look at the curl man page might also give clues.

It also has a non-blocking approach which allows multiple parallel requests - but may take a little care to manage.

It only covers http operations for now, but I intend to include ftp and others in future.

All comments and suggestions welcome.

Mark

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Sat Aug 09, 2008 8:00 pm


Ivan Wong
Posts: 4
Joined: Tue Sep 16, 2008 5:18 pm

Post by Ivan Wong » Tue Sep 16, 2008 7:57 pm

Hi Mark,

Thanks for this library.

Is there any way to get it to work with Rev's built-in xmlrpc calls?


Regards,
Ivan

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Sep 17, 2008 12:02 pm

Hi Ivan,

Which problems are you running into with the revXMLRPC commands?

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Ivan Wong
Posts: 4
Joined: Tue Sep 16, 2008 5:18 pm

Post by Ivan Wong » Wed Sep 17, 2008 6:34 pm

Hi Jan,

I managed to get revXMLRPC working separately. I also got revlibcurl working (but not for XML-RPC calls).

I am interested in using revlibcurl for making non-blocking calls to an xmlrpc blog server, as I found when posting a large quantity of requests via revXMLRPC it suddenly slows down after several requests.

I actually have 2 questions here:

1) How to set the equivalent of revXMLRPC_CreateRequest, revXMLRPC_SetMethod, revXMLRPC_AddParam & revXMLRPC_Execute for CURL

2) How to use revlibcurl for non-blocking calls (I could not find any examples in Mark's documentation)


Thanks,
Ivan

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

nice

Post by reelstuff » Fri Sep 19, 2008 12:01 am

Thanks, for the Curl lib, very cool,

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Fri Sep 19, 2008 7:02 am

Hi Ivan,

The 'revXMLRPC' library was built on top of libURL and also offers direct socket communication (so that you can take care of the connection and leave it open long-term, which is something you can't do in libURL).

Anyway, as the library was written in Revolution, you should be able to make a copy, take it apart and replace the single call to the 'post' command with a call to the equivalent Curl lib command. Okay, you may have to replace a few more things in the same handler to set and read HTTP-headers, but it's not rocket science.

To see the Revolution script that offers the revXMLRPC calls, open the Message Box, go to the Back Scripts section, tick the checkbox do show Revolution UI back scripts and doubleclick the line 'revXMLRPC' - then select all, copy and paste into the script of a new stack. Finally replace 'revXMLRPC_' with 'curlXMLRPC_' and go to work :-)

Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

IvanWong
Posts: 2
Joined: Fri May 23, 2008 6:51 pm

Post by IvanWong » Wed Sep 24, 2008 9:26 am

Hi Jan,

Thanks for the reply. I'll give it a shot.


Cheers,
Ivan

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Fri Sep 26, 2008 12:42 am

Sorry, wasn't paying attention for the last few days.

I've never played with the xml-rpc stuff, so I'll have a look, and see what I can find.

Best,

Mark

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Fri Sep 26, 2008 2:05 am

Ivan, for a non-blocking POST:

Code: Select all

put curl.new() into tCurl
curl.setUrl tCurl, "http://someserver.com/somepath"
curl.setPostData tCurl, tPostData
curl.execute tCurl
-- at this point, curl just gets on with it, and your script continues...

repeat until curl.done(tCurl)
  wait 20 ticks with messages --always 'with messages' or everything stops!
  put curl.prog(tCurl) & "%" -- put 'percent complete' into the message box
end repeat

put curl.response(tCurl) -- show the server response
curl.cleanup tCurl -- free up the resources used by this curl instance.
You might also checking to see if <curl.error(tCurl)> returns empty, before cleanup.

Whilst all this is happening, the user of your app can continue working, including starting other curls.

Handling many concurrent instances can get a bit tricky, but I'm doing it in more than one app quite successfully.

However, Jan is right about the built-in XML-RPC library. It uses libUrl (not surprisingly). A brief look at the XML-RPC script tells me that you could certainly make it use curl, but it's not just simply a case of replacing the call to libUrl's post handler.

IvanWong
Posts: 2
Joined: Fri May 23, 2008 6:51 pm

Post by IvanWong » Thu Oct 09, 2008 6:45 pm

Hi Mark,

Thanks for the code and advice.


Ivan
Mark Smith wrote:Ivan, for a non-blocking POST:

Code: Select all

put curl.new() into tCurl
curl.setUrl tCurl, "http://someserver.com/somepath"
curl.setPostData tCurl, tPostData
curl.execute tCurl
-- at this point, curl just gets on with it, and your script continues...

repeat until curl.done(tCurl)
  wait 20 ticks with messages --always 'with messages' or everything stops!
  put curl.prog(tCurl) & "%" -- put 'percent complete' into the message box
end repeat

put curl.response(tCurl) -- show the server response
curl.cleanup tCurl -- free up the resources used by this curl instance.
You might also checking to see if <curl.error(tCurl)> returns empty, before cleanup.

Whilst all this is happening, the user of your app can continue working, including starting other curls.

Handling many concurrent instances can get a bit tricky, but I'm doing it in more than one app quite successfully.

However, Jan is right about the built-in XML-RPC library. It uses libUrl (not surprisingly). A brief look at the XML-RPC script tells me that you could certainly make it use curl, but it's not just simply a case of replacing the call to libUrl's post handler.

Post Reply