Any libcurl expertise here on compsci.ca?
Author |
Message |
btiffin
![](http://compsci.ca/v3/uploads/user_avatars/189169540547b535e50e4a7.jpg)
|
Posted: Tue Jul 01, 2008 3:25 pm Post subject: Any libcurl expertise here on compsci.ca? |
|
|
I've tasked myself with producing libcurl bindings for OpenCOBOL 1.1 and I'd appreciate any hints on issues I may bump into, or general what's what stories.
The first cut went well (once Roger fixed the CALL BY VALUE handle) issue yesterday, but I'm not too sure how far I'm going to take the support so any tales you may have would help.
Thanks and cheers
edit; spelling |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
btiffin
![](http://compsci.ca/v3/uploads/user_avatars/189169540547b535e50e4a7.jpg)
|
Posted: Tue Jul 01, 2008 10:23 pm Post subject: Re: Any libcurl expertise here on compsci.ca? |
|
|
Here's a sample;
COBOL: |
>>SOURCE FORMAT IS FIXED
*> **************************************************************
*>
*> Copyright (C) 2008 The OpenCOBOL Project
*>
*> This program is free software; you can redistribute it and/or
*> modify it under the terms of the GNU General Public License as
*> published by the Free Software Foundation; either version 2,
*> or (at your option) any later version.
*>
*> This program is distributed in the hope that it will be
*> useful, but WITHOUT ANY WARRANTY; without even the implied
*> warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
*> PURPOSE. See the GNU General Public License for more details.
*>
*> You should have received a copy of the
*> GNU General Public License along with this software;
*> see the file COPYING. If not, write to
*> the Free Software Foundation, 51 Franklin Street, Fifth Floor
*> Boston, MA 02110-1301 USA
*> **************************************************************
identification division.
program-id. showcurl.
author. Brian Tiffin.
data division.
working-storage section.
01 handle usage is pointer.
01 result pic s9(8) comp-5.
01 url.
02 filler pic x(20) value 'http://opencobol.org'.
02 filler pic x(1) value X"00".
01 user-url pic x(80).
01 ind pic 99.
01 str-ptr usage is pointer.
01 display-url pic x(80).
linkage section.
01 current-url pic x(80).
procedure division.
* 3 is CURL_GLOBAL_ALL
call "curl_global_init" using by value 3
returning result.
call "curl_easy_init" returning handle.
display "handle: " handle.
* Get a url from the user or command line
accept user-url from command-line.
if user-url equal spaces then
display "url: " with no advancing
accept user-url
if user-url equal spaces then
move url to user-url
end-if
end-if.
* take first piece as the actual url
string user-url delimited by space into display-url.
move display-url to user-url.
* get the real length
perform varying ind from length user-url by -1
until user-url(ind:1) not equal space
end-perform.
* Add a C null byte
if ind equal length user-url then
subtract 1 from length user-url giving ind.
move X"00" to user-url(ind + 1:1).
* tell cURL the url
* 10002 is CURLOPT_URL
call "curl_easy_setopt" using by value handle
by value 10002
by reference user-url
returning result.
display "set url: " result.
* Prove the curl handle is getting information
* 1048577 is CURLINFO_EFFECTIVE_URL
call "curl_easy_getinfo" using by value handle
by value 1048577
by reference str-ptr
returning result.
set address of current-url to str-ptr.
* skip the null terminator for display
string current-url delimited by low-value
into display-url.
display "get url: " result ", " display-url.
* default operations is read the url and send to stdout
call "curl_easy_perform" using by value handle
returning result.
display "perform: " result.
* Clean up
call "curl_easy_cleanup" using by value handle.
exit program.
stop run.
|
Compile command and sample runs being
code: |
$ cobc -x -lcurl showcurl.cob
$ ./showcurl wanip.org
handle: 0x08059630
set url: +00000000
get url: +00000000, wanip.org
<font size="6">99.241.xxx.xxx</font>
perform: +00000000
$ ./showcurl
handle: 0x08059630
url: wanip.org
set url: +00000000
get url: +00000000, wanip.org
<font size="6">99.241.xxx.xxx</font>
perform: +00000000
$ ./showcurl wanip.org and then other command line stuff
handle: 0x08059630
set url: +00000000
get url: +00000000, wanip.org
<font size="6">99.241.xxx.xxx</font>
perform: +00000000
$ ./showcurl
handle: 0x08059630
url: somekindajunkurl
set url: +00000000
get url: +00000000, somekindajunkurl
perform: +00000006
|
If you haven't COBOLed yet ... well, OpenCOBOL is wicked awesome.
Cheers |
|
|
|
|
![](images/spacer.gif) |
|
|