>>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.
|