All pastes #652314 Raw Edit

Perl Interface to Curl C API

public text v1 · immutable
#652314 ·published 2007-08-10 12:57 UTC
rendered paste body
#*****************************************************************************
#*                                  _   _ ____  _
#*  Project                     ___| | | |  _ \| |
#*                             / __| | | | |_) | |
#*                            | (__| |_| |  _ <| |___
#*                             \___|\___/|_| \_\_____|
#*
#* $Id: perl_interface.pl,v 1.0 2007/08/10 13:45:11 Voldor Exp $
#*****************************************************************************
#!/usr/bin/perl -w
#perl -MInline=Force,NoClean,Info perl_interface.pl // Debugging
#perl perl_interface.pl // Run it
#pp -M FindBin -M Inline -o perl_interface.pl hello // Compile stand-alone exe, remember _Inline dir

use Inline C => Config =>
ENABLE => AUTOWRAP =>   #Use curl functions
AUTO_INCLUDE => '#include "curl/curl.h"' =>   #Curl library
LIBS => "-lcurl";   #Curl flag
use Inline C => <<'END';

char* curl_inline(char* host) {
          CURL *curl;
      CURLcode res;
      curl = curl_easy_init();
      curl_easy_setopt(curl, CURLOPT_URL, host);
      curl_easy_setopt(curl, CURLOPT_HEADER, 1);
      curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
      curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1);
      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
}
END

if (@ARGV < 1) {
                    print("Usage: $0 <url>\n"); 
		    print("Example: ./$0 www.google.com\n");
		    exit(1); 
                    }
		    
my $host = shift; #Take input

curl_inline($host); #Run c code