home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _a950e35b5cccaa856181f57ccb9964f9 < prev    next >
Encoding:
Text File  |  2004-06-01  |  82.9 KB  |  3,009 lines

  1. #######################################################################
  2. #
  3. # Win32::Internet - Perl Module for Internet Extensions
  4. # ^^^^^^^^^^^^^^^
  5. # This module creates an object oriented interface to the Win32
  6. # Internet Functions (WININET.DLL).
  7. #
  8. # Version: 0.08  (14 Feb 1997)
  9. # Version: 0.081 (25 Sep 1999)
  10. # Version: 0.082 (04 Sep 2001)
  11. #
  12. #######################################################################
  13.  
  14. # changes:
  15. # - fixed 2 bugs in Option(s) related subs
  16. # - works with build 30x also
  17.  
  18. package Win32::Internet;
  19.  
  20. require Exporter;       # to export the constants to the main:: space
  21. require DynaLoader;     # to dynuhlode the module.
  22.  
  23. # use Win32::WinError;    # for windows constants.
  24.  
  25. @ISA= qw( Exporter DynaLoader );
  26. @EXPORT = qw(
  27.     HTTP_ADDREQ_FLAG_ADD
  28.     HTTP_ADDREQ_FLAG_REPLACE
  29.     HTTP_QUERY_ALLOW
  30.     HTTP_QUERY_CONTENT_DESCRIPTION
  31.     HTTP_QUERY_CONTENT_ID
  32.     HTTP_QUERY_CONTENT_LENGTH
  33.     HTTP_QUERY_CONTENT_TRANSFER_ENCODING
  34.     HTTP_QUERY_CONTENT_TYPE
  35.     HTTP_QUERY_COST
  36.     HTTP_QUERY_CUSTOM
  37.     HTTP_QUERY_DATE
  38.     HTTP_QUERY_DERIVED_FROM
  39.     HTTP_QUERY_EXPIRES
  40.     HTTP_QUERY_FLAG_REQUEST_HEADERS
  41.     HTTP_QUERY_FLAG_SYSTEMTIME
  42.     HTTP_QUERY_LANGUAGE
  43.     HTTP_QUERY_LAST_MODIFIED
  44.     HTTP_QUERY_MESSAGE_ID
  45.     HTTP_QUERY_MIME_VERSION
  46.     HTTP_QUERY_PRAGMA
  47.     HTTP_QUERY_PUBLIC
  48.     HTTP_QUERY_RAW_HEADERS
  49.     HTTP_QUERY_RAW_HEADERS_CRLF
  50.     HTTP_QUERY_REQUEST_METHOD
  51.     HTTP_QUERY_SERVER
  52.     HTTP_QUERY_STATUS_CODE
  53.     HTTP_QUERY_STATUS_TEXT
  54.     HTTP_QUERY_URI
  55.     HTTP_QUERY_USER_AGENT
  56.     HTTP_QUERY_VERSION
  57.     HTTP_QUERY_WWW_LINK
  58.     ICU_BROWSER_MODE
  59.     ICU_DECODE
  60.     ICU_ENCODE_SPACES_ONLY
  61.     ICU_ESCAPE
  62.     ICU_NO_ENCODE
  63.     ICU_NO_META
  64.     ICU_USERNAME
  65.     INTERNET_FLAG_PASSIVE
  66.     INTERNET_FLAG_ASYNC
  67.     INTERNET_HYPERLINK
  68.     INTERNET_FLAG_KEEP_CONNECTION
  69.     INTERNET_FLAG_MAKE_PERSISTENT
  70.     INTERNET_FLAG_NO_AUTH
  71.     INTERNET_FLAG_NO_AUTO_REDIRECT
  72.     INTERNET_FLAG_NO_CACHE_WRITE
  73.     INTERNET_FLAG_NO_COOKIES
  74.     INTERNET_FLAG_READ_PREFETCH
  75.     INTERNET_FLAG_RELOAD
  76.     INTERNET_FLAG_RESYNCHRONIZE
  77.     INTERNET_FLAG_TRANSFER_ASCII
  78.     INTERNET_FLAG_TRANSFER_BINARY
  79.     INTERNET_INVALID_PORT_NUMBER
  80.     INTERNET_INVALID_STATUS_CALLBACK
  81.     INTERNET_OPEN_TYPE_DIRECT
  82.     INTERNET_OPEN_TYPE_PROXY
  83.     INTERNET_OPEN_TYPE_PROXY_PRECONFIG
  84.     INTERNET_OPTION_CONNECT_BACKOFF
  85.     INTERNET_OPTION_CONNECT_RETRIES
  86.     INTERNET_OPTION_CONNECT_TIMEOUT
  87.     INTERNET_OPTION_CONTROL_SEND_TIMEOUT
  88.     INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT
  89.     INTERNET_OPTION_DATA_SEND_TIMEOUT
  90.     INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
  91.     INTERNET_OPTION_HANDLE_SIZE
  92.     INTERNET_OPTION_LISTEN_TIMEOUT
  93.     INTERNET_OPTION_PASSWORD
  94.     INTERNET_OPTION_READ_BUFFER_SIZE
  95.     INTERNET_OPTION_USER_AGENT
  96.     INTERNET_OPTION_USERNAME
  97.     INTERNET_OPTION_VERSION
  98.     INTERNET_OPTION_WRITE_BUFFER_SIZE
  99.     INTERNET_SERVICE_FTP
  100.     INTERNET_SERVICE_GOPHER
  101.     INTERNET_SERVICE_HTTP
  102.     INTERNET_STATUS_CLOSING_CONNECTION
  103.     INTERNET_STATUS_CONNECTED_TO_SERVER    
  104.     INTERNET_STATUS_CONNECTING_TO_SERVER
  105.     INTERNET_STATUS_CONNECTION_CLOSED
  106.     INTERNET_STATUS_HANDLE_CLOSING
  107.     INTERNET_STATUS_HANDLE_CREATED
  108.     INTERNET_STATUS_NAME_RESOLVED
  109.     INTERNET_STATUS_RECEIVING_RESPONSE
  110.     INTERNET_STATUS_REDIRECT    
  111.     INTERNET_STATUS_REQUEST_COMPLETE    
  112.     INTERNET_STATUS_REQUEST_SENT    
  113.     INTERNET_STATUS_RESOLVING_NAME    
  114.     INTERNET_STATUS_RESPONSE_RECEIVED
  115.     INTERNET_STATUS_SENDING_REQUEST    
  116. );
  117.  
  118.  
  119. #######################################################################
  120. # This AUTOLOAD is used to 'autoload' constants from the constant()
  121. # XS function.  If a constant is not found then control is passed
  122. # to the AUTOLOAD in AutoLoader.
  123. #
  124.  
  125. sub AUTOLOAD {
  126.     my($constname);
  127.     ($constname = $AUTOLOAD) =~ s/.*:://;
  128.     #reset $! to zero to reset any current errors.
  129.     local $! = 0;
  130.     my $val = constant($constname, @_ ? $_[0] : 0);
  131.     if ($! != 0) {
  132.  
  133.         # [dada] This results in an ugly Autoloader error
  134.         #if ($! =~ /Invalid/) {
  135.         #  $AutoLoader::AUTOLOAD = $AUTOLOAD;
  136.         #  goto &AutoLoader::AUTOLOAD;
  137.         #} else {
  138.       
  139.         # [dada] ... I prefer this one :)
  140.   
  141.             ($pack,$file,$line) = caller; undef $pack;
  142.             die "Win32::Internet::$constname is not defined, used at $file line $line.";
  143.   
  144.         #}
  145.     }
  146.     eval "sub $AUTOLOAD { $val }";
  147.     goto &$AUTOLOAD;
  148. }
  149.  
  150.  
  151. #######################################################################
  152. # STATIC OBJECT PROPERTIES
  153. #
  154. $VERSION = "0.082";
  155.  
  156. %callback_code = ();
  157. %callback_info = ();
  158.  
  159.  
  160. #######################################################################
  161. # PUBLIC METHODS
  162. #
  163.  
  164. #======== ### CLASS CONSTRUCTOR
  165. sub new {
  166. #========
  167.     my($class, $useragent, $opentype, $proxy, $proxybypass, $flags) = @_;
  168.     my $self = {};  
  169.  
  170.     if(ref($useragent) and ref($useragent) eq "HASH") {
  171.         $opentype       = $useragent->{'opentype'};
  172.         $proxy          = $useragent->{'proxy'};
  173.         $proxybypass    = $useragent->{'proxybypass'};
  174.         $flags          = $useragent->{'flags'};
  175.         my $myuseragent = $useragent->{'useragent'};
  176.         undef $useragent;
  177.         $useragent      = $myuseragent;
  178.     }
  179.  
  180.     $useragent = "Perl-Win32::Internet/".$VERSION       unless defined($useragent);
  181.     $opentype = constant("INTERNET_OPEN_TYPE_DIRECT",0) unless defined($opentype);
  182.     $proxy = ""                                         unless defined($proxy);
  183.     $proxybypass = ""                                   unless defined($proxybypass);
  184.     $flags = 0                                          unless defined($flags);
  185.  
  186.  
  187.     my $handle = InternetOpen($useragent, $opentype, $proxy, $proxybypass, $flags);
  188.     if ($handle) {
  189.         $self->{'connections'} = 0;
  190.         $self->{'pasv'}        = 0;
  191.         $self->{'handle'}      = $handle; 
  192.         $self->{'useragent'}   = $useragent;
  193.         $self->{'proxy'}       = $proxy;
  194.         $self->{'proxybypass'} = $proxybypass;
  195.         $self->{'flags'}       = $flags;
  196.         $self->{'Type'}        = "Internet";
  197.     
  198.         # [dada] I think it's better to call SetStatusCallback explicitly...
  199.         #if($flags & constant("INTERNET_FLAG_ASYNC",0)) {
  200.         #  my $callbackresult=InternetSetStatusCallback($handle);
  201.         #  if($callbackresult==&constant("INTERNET_INVALID_STATUS_CALLBACK",0)) {
  202.         #    $self->{'Error'} = -2;
  203.         #  }
  204.         #}
  205.  
  206.         bless $self;
  207.     } else {
  208.         $self->{'handle'} = undef;
  209.         bless $self;
  210.     }
  211.     $self;
  212. }  
  213.  
  214.  
  215. #============
  216. sub OpenURL {
  217. #============
  218.     my($self,$new,$URL) = @_;
  219.     return undef unless ref($self);
  220.  
  221.     my $newhandle=InternetOpenUrl($self->{'handle'},$URL,"",0,0,0);
  222.     if(!$newhandle) {
  223.         $self->{'Error'} = "Cannot open URL.";
  224.         return undef;
  225.     } else {
  226.         $self->{'connections'}++;
  227.         $_[1] = _new($newhandle);
  228.         $_[1]->{'Type'} = "URL";
  229.         $_[1]->{'URL'}  = $URL;
  230.         return $newhandle;
  231.     }
  232. }
  233.  
  234.  
  235. #================
  236. sub TimeConvert {
  237. #================
  238.     my($self, $sec, $min, $hour, $day, $mon, $year, $wday, $rfc) = @_;
  239.     return undef unless ref($self);
  240.  
  241.     if(!defined($rfc)) {
  242.         return InternetTimeToSystemTime($sec);
  243.     } else {
  244.         return InternetTimeFromSystemTime($sec, $min, $hour, 
  245.                                           $day, $mon, $year, 
  246.                                           $wday, $rfc);
  247.     }
  248. }
  249.  
  250.  
  251. #=======================
  252. sub QueryDataAvailable {
  253. #=======================
  254.     my($self) = @_;
  255.     return undef unless ref($self);
  256.   
  257.     return InternetQueryDataAvailable($self->{'handle'});
  258. }
  259.  
  260.  
  261. #=============
  262. sub ReadFile {
  263. #=============
  264.     my($self, $buffersize) = @_;
  265.     return undef unless ref($self);
  266.  
  267.     my $howmuch = InternetQueryDataAvailable($self->{'handle'});
  268.     $buffersize = $howmuch unless defined($buffersize);
  269.     return InternetReadFile($self->{'handle'}, ($howmuch<$buffersize) ? $howmuch 
  270.                                                                       : $buffersize);
  271. }
  272.  
  273.  
  274. #===================
  275. sub ReadEntireFile {
  276. #===================
  277.     my($handle) = @_;
  278.     my $content    = "";
  279.     my $buffersize = 16000;
  280.     my $howmuch    = 0;
  281.     my $buffer     = "";
  282.  
  283.     $handle = $handle->{'handle'} if defined($handle) and ref($handle);
  284.  
  285.     $howmuch = InternetQueryDataAvailable($handle);
  286.     # print "\nReadEntireFile: $howmuch bytes to read...\n";
  287.   
  288.     while($howmuch>0) {
  289.         $buffer = InternetReadFile($handle, ($howmuch<$buffersize) ? $howmuch 
  290.                                                                    : $buffersize);
  291.         # print "\nReadEntireFile: ", length($buffer), " bytes read...\n";
  292.     
  293.         if(!defined($buffer)) {
  294.             return undef;
  295.         } else {
  296.             $content .= $buffer;
  297.         }
  298.         $howmuch = InternetQueryDataAvailable($handle);
  299.         # print "\nReadEntireFile: still $howmuch bytes to read...\n";
  300.     
  301.     }
  302.     return $content;
  303. }
  304.  
  305.  
  306. #=============
  307. sub FetchURL {
  308. #=============
  309.     # (OpenURL+Read+Close)...
  310.     my($self, $URL) = @_;
  311.     return undef unless ref($self);
  312.  
  313.     my $newhandle = InternetOpenUrl($self->{'handle'}, $URL, "", 0, 0, 0);
  314.     if(!$newhandle) {
  315.         $self->{'Error'} = "Cannot open URL.";
  316.         return undef;
  317.     } else {
  318.         my $content = ReadEntireFile($newhandle);
  319.         InternetCloseHandle($newhandle);
  320.         return $content;
  321.     }
  322. }
  323.  
  324.  
  325. #================
  326. sub Connections {
  327. #================
  328.     my($self) = @_;
  329.     return undef unless ref($self);
  330.  
  331.     return $self->{'connections'} if $self->{'Type'} eq "Internet";
  332.     return undef;
  333. }
  334.  
  335.  
  336. #================
  337. sub GetResponse {
  338. #================
  339.     my($num, $text) = InternetGetLastResponseInfo();
  340.     return $text;
  341. }
  342.  
  343. #===========
  344. sub Option {
  345. #===========
  346.     my($self, $option, $value) = @_;
  347.     return undef unless ref($self);
  348.  
  349.     my $retval = 0;
  350.  
  351.     $option = constant("INTERNET_OPTION_USER_AGENT", 0) unless defined($option);
  352.   
  353.     if(!defined($value)) {
  354.         $retval = InternetQueryOption($self->{'handle'}, $option);
  355.     } else {
  356.         $retval = InternetSetOption($self->{'handle'}, $option, $value);
  357.     }
  358.     return $retval;
  359. }
  360.  
  361.  
  362. #==============
  363. sub UserAgent {
  364. #==============
  365.     my($self, $value) = @_;
  366.     return undef unless ref($self);
  367.  
  368.     return Option($self, constant("INTERNET_OPTION_USER_AGENT", 0), $value);
  369. }
  370.  
  371.  
  372. #=============
  373. sub Username {
  374. #=============
  375.     my($self, $value) = @_;
  376.     return undef unless ref($self);
  377.   
  378.     if($self->{'Type'} ne "HTTP" and $self->{'Type'} ne "FTP") {
  379.         $self->{'Error'} = "Username() only on FTP or HTTP sessions.";
  380.         return undef;
  381.     }
  382.  
  383.     return Option($self, constant("INTERNET_OPTION_USERNAME", 0), $value);
  384. }
  385.  
  386.  
  387. #=============
  388. sub Password {
  389. #=============
  390.     my($self, $value)=@_;
  391.     return undef unless ref($self);
  392.  
  393.     if($self->{'Type'} ne "HTTP" and $self->{'Type'} ne "FTP") {
  394.         $self->{'Error'} = "Password() only on FTP or HTTP sessions.";
  395.         return undef;
  396.     }
  397.  
  398.     return Option($self, constant("INTERNET_OPTION_PASSWORD", 0), $value);
  399. }
  400.  
  401.  
  402. #===================
  403. sub ConnectTimeout {
  404. #===================
  405.     my($self, $value) = @_;
  406.     return undef unless ref($self);
  407.  
  408.     return Option($self, constant("INTERNET_OPTION_CONNECT_TIMEOUT", 0), $value);
  409. }
  410.  
  411.  
  412. #===================
  413. sub ConnectRetries {
  414. #===================
  415.     my($self, $value) = @_;
  416.     return undef unless ref($self);
  417.  
  418.     return Option($self, constant("INTERNET_OPTION_CONNECT_RETRIES", 0), $value);
  419. }
  420.  
  421.  
  422. #===================
  423. sub ConnectBackoff {
  424. #===================
  425.     my($self,$value)=@_;
  426.     return undef unless ref($self);
  427.  
  428.     return Option($self, constant("INTERNET_OPTION_CONNECT_BACKOFF", 0), $value);
  429. }
  430.  
  431.  
  432. #====================
  433. sub DataSendTimeout {
  434. #====================
  435.     my($self,$value) = @_;
  436.     return undef unless ref($self);
  437.  
  438.     return Option($self, constant("INTERNET_OPTION_DATA_SEND_TIMEOUT", 0), $value);
  439. }
  440.  
  441.  
  442. #=======================
  443. sub DataReceiveTimeout {
  444. #=======================
  445.     my($self, $value) = @_;
  446.     return undef unless ref($self);
  447.  
  448.     return Option($self, constant("INTERNET_OPTION_DATA_RECEIVE_TIMEOUT", 0), $value);
  449. }
  450.  
  451.  
  452. #==========================
  453. sub ControlReceiveTimeout {
  454. #==========================
  455.     my($self, $value) = @_;
  456.     return undef unless ref($self);
  457.  
  458.     return Option($self, constant("INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT", 0), $value);
  459. }
  460.  
  461.  
  462. #=======================
  463. sub ControlSendTimeout {
  464. #=======================
  465.     my($self, $value) = @_;
  466.     return undef unless ref($self);
  467.  
  468.     return Option($self, constant("INTERNET_OPTION_CONTROL_SEND_TIMEOUT", 0), $value);
  469. }
  470.  
  471.  
  472. #================
  473. sub QueryOption {
  474. #================
  475.     my($self, $option) = @_;
  476.     return undef unless ref($self);
  477.  
  478.     return InternetQueryOption($self->{'handle'}, $option);
  479. }
  480.  
  481.  
  482. #==============
  483. sub SetOption {
  484. #==============
  485.     my($self, $option, $value) = @_;
  486.     return undef unless ref($self);
  487.  
  488.     return InternetSetOption($self->{'handle'}, $option, $value);
  489. }
  490.  
  491.  
  492. #=============
  493. sub CrackURL {
  494. #=============
  495.     my($self, $URL, $flags) = @_;
  496.     return undef unless ref($self);
  497.  
  498.     $flags = constant("ICU_ESCAPE", 0) unless defined($flags);
  499.   
  500.     my @newurl = InternetCrackUrl($URL, $flags);
  501.   
  502.     if(!defined($newurl[0])) {
  503.         $self->{'Error'} = "Cannot crack URL.";
  504.         return undef;
  505.     } else {
  506.         return @newurl;
  507.     }
  508. }
  509.  
  510.  
  511. #==============
  512. sub CreateURL {
  513. #==============
  514.     my($self, $scheme, $hostname, $port, 
  515.        $username, $password, 
  516.        $path, $extrainfo, $flags) = @_;
  517.     return undef unless ref($self);
  518.  
  519.     if(ref($scheme) and ref($scheme) eq "HASH") {
  520.         $flags       = $hostname;
  521.         $hostname    = $scheme->{'hostname'};
  522.         $port        = $scheme->{'port'};
  523.         $username    = $scheme->{'username'};
  524.         $password    = $scheme->{'password'};
  525.         $path        = $scheme->{'path'};
  526.         $extrainfo   = $scheme->{'extrainfo'};
  527.         my $myscheme = $scheme->{'scheme'};
  528.         undef $scheme;
  529.         $scheme      = $myscheme;
  530.     }
  531.  
  532.     $hostname  = ""                    unless defined($hostname);
  533.     $port      = 0                     unless defined($port);
  534.     $username  = ""                    unless defined($username);
  535.     $password  = ""                    unless defined($password);
  536.     $path      = ""                    unless defined($path);
  537.     $extrainfo = ""                    unless defined($extrainfo);
  538.     $flags = constant("ICU_ESCAPE", 0) unless defined($flags);
  539.   
  540.     my $newurl = InternetCreateUrl($scheme, $hostname, $port,
  541.                                    $username, $password,
  542.                                    $path, $extrainfo, $flags);
  543.     if(!defined($newurl)) {
  544.         $self->{'Error'} = "Cannot create URL.";
  545.         return undef;
  546.     } else {
  547.         return $newurl;
  548.     }
  549. }
  550.  
  551.  
  552. #====================
  553. sub CanonicalizeURL {
  554. #====================
  555.     my($self, $URL, $flags) = @_;
  556.     return undef unless ref($self);
  557.   
  558.     my $newurl = InternetCanonicalizeUrl($URL, $flags);
  559.     if(!defined($newurl)) {
  560.         $self->{'Error'} = "Cannot canonicalize URL.";
  561.         return undef;
  562.     } else {
  563.         return $newurl;
  564.     }
  565. }
  566.  
  567.  
  568. #===============
  569. sub CombineURL {
  570. #===============
  571.     my($self, $baseURL, $relativeURL, $flags) = @_;
  572.     return undef unless ref($self);
  573.   
  574.     my $newurl = InternetCombineUrl($baseURL, $relativeURL, $flags);
  575.     if(!defined($newurl)) {
  576.         $self->{'Error'} = "Cannot combine URL(s).";
  577.         return undef;
  578.     } else {
  579.         return $newurl;
  580.     }
  581. }
  582.  
  583.  
  584. #======================
  585. sub SetStatusCallback {
  586. #======================
  587.     my($self) = @_;
  588.     return undef unless ref($self);
  589.   
  590.     my $callback = InternetSetStatusCallback($self->{'handle'});
  591.     print "callback=$callback, constant=",constant("INTERNET_INVALID_STATUS_CALLBACK", 0), "\n";
  592.     if($callback == constant("INTERNET_INVALID_STATUS_CALLBACK", 0)) {
  593.         return undef;
  594.     } else {
  595.         return $callback;
  596.     }
  597. }
  598.  
  599.  
  600. #======================
  601. sub GetStatusCallback {
  602. #======================
  603.     my($self, $context) = @_;
  604.     $context = $self if not defined $context;
  605.     return($callback_code{$context}, $callback_info{$context});
  606. }
  607.  
  608.  
  609. #==========
  610. sub Error {
  611. #==========
  612.     my($self) = @_;
  613.     return undef unless ref($self);
  614.   
  615.     my $errtext = "";
  616.     my $tmp     = "";
  617.     my $errnum  = Win32::GetLastError();
  618.  
  619.     if($errnum < 12000) {
  620.         $errtext =  Win32::FormatMessage($errnum);
  621.         $errtext =~ s/[\r\n]//g;
  622.     } elsif($errnum == 12003) {
  623.         ($tmp, $errtext) = InternetGetLastResponseInfo();
  624.         chomp $errtext;
  625.         1 while($errtext =~ s/(.*)\n//); # the last line should be significative... 
  626.                                          # otherwise call GetResponse() to get it whole
  627.     } elsif($errnum >= 12000) {
  628.         $errtext = FormatMessage($errnum);
  629.         $errtext =~ s/[\r\n]//g;        
  630.     } else {
  631.         $errtext="Error";
  632.     }
  633.     if($errnum == 0 and defined($self->{'Error'})) { 
  634.         if($self->{'Error'} == -2) {
  635.             $errnum  = -2;
  636.             $errtext = "Asynchronous operations not available.";
  637.         } else {
  638.             $errnum  = -1;
  639.             $errtext = $self->{'Error'};
  640.         }
  641.     }
  642.     return (wantarray)? ($errnum, $errtext) : "\[".$errnum."\] ".$errtext;
  643. }
  644.  
  645.  
  646. #============
  647. sub Version {
  648. #============
  649.     my $dll =  InternetDllVersion();
  650.        $dll =~ s/\0//g;
  651.     return (wantarray)? ($Win32::Internet::VERSION,    $dll) 
  652.                       :  $Win32::Internet::VERSION."/".$dll;
  653. }
  654.  
  655.  
  656. #==========
  657. sub Close {
  658. #==========
  659.     my($self, $handle) = @_;
  660.     if(!defined($handle)) {
  661.         return undef unless ref($self);
  662.         $handle = $self->{'handle'};
  663.     }
  664.     InternetCloseHandle($handle);
  665. }
  666.  
  667.  
  668.  
  669. #######################################################################
  670. # FTP CLASS METHODS
  671. #
  672.  
  673. #======== ### FTP CONSTRUCTOR
  674. sub FTP {
  675. #========
  676.     my($self, $new, $server, $username, $password, $port, $pasv, $context) = @_;    
  677.     return undef unless ref($self);
  678.  
  679.     if(ref($server) and ref($server) eq "HASH") {
  680.         $port        = $server->{'port'};
  681.         $username    = $server->{'username'};
  682.         $password    = $password->{'host'};
  683.         my $myserver = $server->{'server'};
  684.         $pasv        = $server->{'pasv'};
  685.         $context     = $server->{'context'};
  686.         undef $server;
  687.         $server      = $myserver;
  688.     }
  689.  
  690.     $server   = ""          unless defined($server);
  691.     $username = "anonymous" unless defined($username);
  692.     $password = ""          unless defined($password);
  693.     $port     = 21          unless defined($port);
  694.     $context  = 0           unless defined($context);
  695.  
  696.     $pasv = $self->{'pasv'} unless defined $pasv;
  697.     $pasv = $pasv ? constant("INTERNET_FLAG_PASSIVE",0) : 0;
  698.  
  699.     my $newhandle = InternetConnect($self->{'handle'}, $server, $port,
  700.                                     $username, $password,
  701.                                     constant("INTERNET_SERVICE_FTP", 0),
  702.                                     $pasv, $context);
  703.     if($newhandle) {
  704.         $self->{'connections'}++;
  705.         $_[1] = _new($newhandle);
  706.         $_[1]->{'Type'}     = "FTP";
  707.         $_[1]->{'Mode'}     = "bin";
  708.         $_[1]->{'pasv'}     = $pasv;
  709.         $_[1]->{'username'} = $username;
  710.         $_[1]->{'password'} = $password;
  711.         $_[1]->{'server'}   = $server;
  712.         return $newhandle;
  713.     } else {
  714.         return undef;
  715.     }
  716. }
  717.  
  718. #========
  719. sub Pwd {
  720. #========
  721.     my($self) = @_;
  722.     return undef unless ref($self);
  723.  
  724.     if($self->{'Type'} ne "FTP" or !defined($self->{'handle'})) {
  725.         $self->{'Error'} = "Pwd() only on FTP sessions.";
  726.         return undef;
  727.     }
  728.   
  729.     return FtpGetCurrentDirectory($self->{'handle'});
  730. }
  731.  
  732.  
  733. #=======
  734. sub Cd {
  735. #=======
  736.     my($self, $path) = @_;
  737.     return undef unless ref($self);
  738.  
  739.     if($self->{'Type'} ne "FTP" || !defined($self->{'handle'})) {
  740.         $self->{'Error'} = "Cd() only on FTP sessions.";
  741.         return undef;
  742.     }
  743.   
  744.     my $retval = FtpSetCurrentDirectory($self->{'handle'}, $path);
  745.     if(!defined($retval)) {
  746.         return undef;
  747.     } else {
  748.         return $path;
  749.     }
  750. }
  751. #====================
  752. sub Cwd   { Cd(@_); }
  753. sub Chdir { Cd(@_); }
  754. #====================
  755.  
  756.  
  757. #==========
  758. sub Mkdir {
  759. #==========
  760.     my($self, $path) = @_;
  761.     return undef unless ref($self);
  762.  
  763.     if($self->{'Type'} ne "FTP" or !defined($self->{'handle'})) {
  764.         $self->{'Error'} = "Mkdir() only on FTP sessions.";
  765.         return undef;
  766.     }
  767.   
  768.     my $retval = FtpCreateDirectory($self->{'handle'}, $path);
  769.     $self->{'Error'} = "Can't create directory." unless defined($retval);
  770.     return $retval;
  771. }
  772. #====================
  773. sub Md { Mkdir(@_); }
  774. #====================
  775.  
  776.  
  777. #=========
  778. sub Mode {
  779. #=========
  780.     my($self, $value) = @_;
  781.     return undef unless ref($self);
  782.  
  783.     if($self->{'Type'} ne "FTP" or !defined($self->{'handle'})) {
  784.         $self->{'Error'} = "Mode() only on FTP sessions.";
  785.         return undef;
  786.     }
  787.   
  788.     if(!defined($value)) {
  789.         return $self->{'Mode'};
  790.     } else {
  791.         my $modesub = ($value =~ /^a/i) ? "Ascii" : "Binary";
  792.         $self->$modesub($_[0]);
  793.     }
  794.     return $self->{'Mode'};
  795. }
  796.  
  797.  
  798. #==========
  799. sub Rmdir {
  800. #==========
  801.     my($self, $path) = @_;
  802.     return undef unless ref($self);
  803.  
  804.     if($self->{'Type'} ne "FTP" or !defined($self->{'handle'})) {
  805.         $self->{'Error'} = "Rmdir() only on FTP sessions.";
  806.         return undef;
  807.     }
  808.     my $retval = FtpRemoveDirectory($self->{'handle'}, $path);
  809.     $self->{'Error'} = "Can't remove directory." unless defined($retval);
  810.     return $retval;
  811. }
  812. #====================
  813. sub Rd { Rmdir(@_); }
  814. #====================
  815.  
  816.  
  817. #=========
  818. sub Pasv {
  819. #=========
  820.     my($self, $value) = @_;
  821.     return undef unless ref($self);
  822.  
  823.     if(defined($value) and $self->{'Type'} eq "Internet") {
  824.         if($value == 0) {
  825.             $self->{'pasv'} = 0;
  826.         } else {
  827.             $self->{'pasv'} = 1;
  828.         }
  829.     }
  830.     return $self->{'pasv'};
  831. }
  832.  
  833. #=========
  834. sub List {
  835. #=========
  836.     my($self, $pattern, $retmode) = @_;
  837.     return undef unless ref($self);
  838.  
  839.     my $retval = "";
  840.     my $size   = ""; 
  841.     my $attr   = ""; 
  842.     my $ctime  = ""; 
  843.     my $atime  = ""; 
  844.     my $mtime  = "";
  845.     my $csec = 0; my $cmin = 0; my $chou = 0; my $cday = 0; my $cmon = 0; my $cyea = 0;
  846.     my $asec = 0; my $amin = 0; my $ahou = 0; my $aday = 0; my $amon = 0; my $ayea = 0;
  847.     my $msec = 0; my $mmin = 0; my $mhou = 0; my $mday = 0; my $mmon = 0; my $myea = 0;
  848.     my $newhandle = 0;
  849.     my $nextfile  = 1;
  850.     my @results   = ();
  851.     my ($filename, $altname, $file);
  852.   
  853.     if($self->{'Type'} ne "FTP") {
  854.         $self->{'Error'} = "List() only on FTP sessions.";
  855.         return undef;
  856.     }
  857.   
  858.     $pattern = "" unless defined($pattern);
  859.     $retmode = 1  unless defined($retmode);
  860.  
  861.     if($retmode == 2) {
  862.   
  863.         ( $newhandle,$filename, $altname, $size, $attr,         
  864.           $csec, $cmin, $chou, $cday, $cmon, $cyea,
  865.           $asec, $amin, $ahou, $aday, $amon, $ayea,
  866.           $msec, $mmin, $mhou, $mday, $mmon, $myea
  867.         ) = FtpFindFirstFile($self->{'handle'}, $pattern, 0, 0);
  868.     
  869.         if(!$newhandle) {
  870.             $self->{'Error'} = "Can't read FTP directory.";
  871.             return undef;
  872.         } else {
  873.     
  874.             while($nextfile) {
  875.                 $ctime = join(",", ($csec, $cmin, $chou, $cday, $cmon, $cyea));
  876.                 $atime = join(",", ($asec, $amin, $ahou, $aday, $amon, $ayea));
  877.                 $mtime = join(",", ($msec, $mmin, $mhou, $mday, $mmon, $myea));
  878.                 push(@results, $filename, $altname, $size, $attr, $ctime, $atime, $mtime);
  879.         
  880.                 ( $nextfile, $filename, $altname, $size, $attr,
  881.                   $csec, $cmin, $chou, $cday, $cmon, $cyea,
  882.                   $asec, $amin, $ahou, $aday, $amon, $ayea,
  883.                   $msec, $mmin, $mhou, $mday, $mmon, $myea
  884.                 ) = InternetFindNextFile($newhandle);      
  885.         
  886.             }
  887.             InternetCloseHandle($newhandle);
  888.             return @results;
  889.       
  890.         }
  891.     
  892.     } elsif($retmode == 3) {
  893.   
  894.         ( $newhandle,$filename, $altname, $size, $attr,
  895.           $csec, $cmin, $chou, $cday, $cmon, $cyea,
  896.           $asec, $amin, $ahou, $aday, $amon, $ayea,
  897.           $msec, $mmin, $mhou, $mday, $mmon, $myea
  898.         ) = FtpFindFirstFile($self->{'handle'}, $pattern, 0, 0);
  899.     
  900.         if(!$newhandle) {
  901.             $self->{'Error'} = "Can't read FTP directory.";
  902.             return undef;
  903.        
  904.         } else {
  905.      
  906.             while($nextfile) {
  907.                 $ctime = join(",", ($csec, $cmin, $chou, $cday, $cmon, $cyea));
  908.                 $atime = join(",", ($asec, $amin, $ahou, $aday, $amon, $ayea));
  909.                 $mtime = join(",", ($msec, $mmin, $mhou, $mday, $mmon, $myea));
  910.                 $file = { "name"     => $filename,
  911.                           "altname"  => $altname,
  912.                           "size"     => $size,
  913.                           "attr"     => $attr,
  914.                           "ctime"    => $ctime,
  915.                           "atime"    => $atime,
  916.                           "mtime"    => $mtime,
  917.                 };
  918.                 push(@results, $file);
  919.          
  920.                 ( $nextfile, $filename, $altname, $size, $attr,
  921.                   $csec, $cmin, $chou, $cday, $cmon, $cyea,
  922.                   $asec, $amin, $ahou, $aday, $amon, $ayea,
  923.                   $msec, $mmin, $mhou, $mday, $mmon, $myea
  924.                 ) = InternetFindNextFile($newhandle);
  925.          
  926.             }
  927.             InternetCloseHandle($newhandle);
  928.             return @results;
  929.         }
  930.     
  931.     } else {
  932.     
  933.         ($newhandle, $filename) = FtpFindFirstFile($self->{'handle'}, $pattern, 0, 0);
  934.     
  935.         if(!$newhandle) {
  936.             $self->{'Error'} = "Can't read FTP directory.";
  937.             return undef;
  938.       
  939.         } else {
  940.     
  941.             while($nextfile) {
  942.                 push(@results, $filename);
  943.         
  944.                 ($nextfile, $filename) = InternetFindNextFile($newhandle);  
  945.                 # print "List.no more files\n" if !$nextfile;
  946.         
  947.             }
  948.             InternetCloseHandle($newhandle);
  949.             return @results;
  950.         }
  951.     }
  952. }
  953. #====================
  954. sub Ls  { List(@_); }
  955. sub Dir { List(@_); }
  956. #====================
  957.  
  958.  
  959. #=================
  960. sub FileAttrInfo {
  961. #=================
  962.     my($self,$attr) = @_;
  963.     my @attrinfo = ();
  964.     push(@attrinfo, "READONLY")   if $attr & 1;
  965.     push(@attrinfo, "HIDDEN")     if $attr & 2;
  966.     push(@attrinfo, "SYSTEM")     if $attr & 4;
  967.     push(@attrinfo, "DIRECTORY")  if $attr & 16;
  968.     push(@attrinfo, "ARCHIVE")    if $attr & 32;
  969.     push(@attrinfo, "NORMAL")     if $attr & 128;
  970.     push(@attrinfo, "TEMPORARY")  if $attr & 256;
  971.     push(@attrinfo, "COMPRESSED") if $attr & 2048;
  972.     return (wantarray)? @attrinfo : join(" ", @attrinfo);
  973. }
  974.  
  975.  
  976. #===========
  977. sub Binary {
  978. #===========
  979.     my($self) = @_;
  980.     return undef unless ref($self);
  981.  
  982.     if($self->{'Type'} ne "FTP") {
  983.         $self->{'Error'} = "Binary() only on FTP sessions.";
  984.         return undef;
  985.     }
  986.     $self->{'Mode'} = "bin";
  987.     return undef;
  988. }
  989. #======================
  990. sub Bin { Binary(@_); }
  991. #======================
  992.  
  993.  
  994. #==========
  995. sub Ascii {
  996. #==========
  997.     my($self) = @_;
  998.     return undef unless ref($self);
  999.  
  1000.     if($self->{'Type'} ne "FTP") {
  1001.         $self->{'Error'} = "Ascii() only on FTP sessions.";
  1002.         return undef;
  1003.     }
  1004.     $self->{'Mode'} = "asc";
  1005.     return undef;
  1006. }
  1007. #=====================
  1008. sub Asc { Ascii(@_); }
  1009. #=====================
  1010.  
  1011.  
  1012. #========
  1013. sub Get {
  1014. #========
  1015.     my($self, $remote, $local, $overwrite, $flags, $context) = @_;
  1016.     return undef unless ref($self);
  1017.  
  1018.     if($self->{'Type'} ne "FTP") {
  1019.         $self->{'Error'} = "Get() only on FTP sessions.";
  1020.         return undef;
  1021.     }
  1022.     my $mode = ($self->{'Mode'} eq "asc" ? 1 : 2);
  1023.  
  1024.     $remote    = ""      unless defined($remote);
  1025.     $local     = $remote unless defined($local);
  1026.     $overwrite = 0       unless defined($overwrite);
  1027.     $flags     = 0       unless defined($flags);
  1028.     $context   = 0       unless defined($context);
  1029.   
  1030.     my $retval = FtpGetFile($self->{'handle'},
  1031.                             $remote,
  1032.                             $local,
  1033.                             $overwrite,
  1034.                             $flags,
  1035.                             $mode,
  1036.                             $context);
  1037.     $self->{'Error'} = "Can't get file." unless defined($retval);
  1038.     return $retval;
  1039. }
  1040.  
  1041.  
  1042. #===========
  1043. sub Rename {
  1044. #===========
  1045.     my($self, $oldname, $newname) = @_;
  1046.     return undef unless ref($self);
  1047.  
  1048.     if($self->{'Type'} ne "FTP") {
  1049.         $self->{'Error'} = "Rename() only on FTP sessions.";
  1050.         return undef;
  1051.     }
  1052.  
  1053.     my $retval = FtpRenameFile($self->{'handle'}, $oldname, $newname);
  1054.     $self->{'Error'} = "Can't rename file." unless defined($retval);
  1055.     return $retval;
  1056. }
  1057. #======================
  1058. sub Ren { Rename(@_); }
  1059. #======================
  1060.  
  1061.  
  1062. #===========
  1063. sub Delete {
  1064. #===========
  1065.     my($self, $filename) = @_;
  1066.     return undef unless ref($self);
  1067.  
  1068.     if($self->{'Type'} ne "FTP") {
  1069.         $self->{'Error'} = "Delete() only on FTP sessions.";
  1070.         return undef;
  1071.     }
  1072.     my $retval = FtpDeleteFile($self->{'handle'}, $filename);
  1073.     $self->{'Error'} = "Can't delete file." unless defined($retval);
  1074.     return $retval;
  1075. }
  1076. #======================
  1077. sub Del { Delete(@_); }
  1078. #======================
  1079.  
  1080.  
  1081. #========
  1082. sub Put {
  1083. #========
  1084.     my($self, $local, $remote, $context) = @_;
  1085.     return undef unless ref($self);
  1086.  
  1087.     if($self->{'Type'} ne "FTP") {
  1088.         $self->{'Error'} = "Put() only on FTP sessions.";
  1089.         return undef;
  1090.     }
  1091.     my $mode = ($self->{'Mode'} eq "asc" ? 1 : 2);
  1092.  
  1093.     $context = 0 unless defined($context);
  1094.   
  1095.     my $retval = FtpPutFile($self->{'handle'}, $local, $remote, $mode, $context);
  1096.     $self->{'Error'} = "Can't put file." unless defined($retval);
  1097.     return $retval;
  1098. }
  1099.  
  1100.  
  1101. #######################################################################
  1102. # HTTP CLASS METHODS
  1103. #
  1104.  
  1105. #========= ### HTTP CONSTRUCTOR
  1106. sub HTTP {
  1107. #=========
  1108.     my($self, $new, $server, $username, $password, $port, $flags, $context) = @_;    
  1109.     return undef unless ref($self);
  1110.  
  1111.     if(ref($server) and ref($server) eq "HASH") {
  1112.         my $myserver = $server->{'server'};
  1113.         $username    = $server->{'username'};
  1114.         $password    = $password->{'host'};
  1115.         $port        = $server->{'port'};    
  1116.         $flags       = $server->{'flags'};
  1117.         $context     = $server->{'context'};
  1118.         undef $server;
  1119.         $server      = $myserver;
  1120.     }
  1121.  
  1122.     $server   = ""          unless defined($server);
  1123.     $username = "anonymous" unless defined($username);
  1124.     $password = ""          unless defined($password);
  1125.     $port     = 80          unless defined($port);
  1126.     $flags    = 0           unless defined($flags);
  1127.     $context  = 0           unless defined($context);
  1128.   
  1129.     my $newhandle = InternetConnect($self->{'handle'}, $server, $port,
  1130.                                     $username, $password,
  1131.                                     constant("INTERNET_SERVICE_HTTP", 0),
  1132.                                     $flags, $context);
  1133.     if($newhandle) {
  1134.         $self->{'connections'}++;
  1135.         $_[1] = _new($newhandle);
  1136.         $_[1]->{'Type'}     = "HTTP";
  1137.         $_[1]->{'username'} = $username;
  1138.         $_[1]->{'password'} = $password;
  1139.         $_[1]->{'server'}   = $server;
  1140.         $_[1]->{'accept'}   = "text/*\0image/gif\0image/jpeg\0\0";
  1141.         return $newhandle;
  1142.     } else {
  1143.         return undef;
  1144.     }
  1145. }
  1146.  
  1147.  
  1148. #================
  1149. sub OpenRequest {
  1150. #================
  1151.     # alternatively to Request:
  1152.     # it creates a new HTTP_Request object
  1153.     # you can act upon it with AddHeader, SendRequest, ReadFile, QueryInfo, Close, ...
  1154.  
  1155.     my($self, $new, $path, $method, $version, $referer, $accept, $flags, $context) = @_;
  1156.     return undef unless ref($self);
  1157.  
  1158.     if($self->{'Type'} ne "HTTP") {
  1159.         $self->{'Error'} = "OpenRequest() only on HTTP sessions.";
  1160.         return undef;
  1161.     }
  1162.  
  1163.     if(ref($path) and ref($path) eq "HASH") {
  1164.         $method    = $path->{'method'};
  1165.         $version   = $path->{'version'};
  1166.         $referer   = $path->{'referer'};
  1167.         $accept    = $path->{'accept'};
  1168.         $flags     = $path->{'flags'};
  1169.         $context   = $path->{'context'};
  1170.         my $mypath = $path->{'path'};
  1171.         undef $path;
  1172.         $path      = $mypath;
  1173.     }
  1174.  
  1175.     $method  = "GET"             unless defined($method);
  1176.     $path    = "/"               unless defined($path);
  1177.     $version = "HTTP/1.0"        unless defined($version); 
  1178.     $referer = ""                unless defined($referer);
  1179.     $accept  = $self->{'accept'} unless defined($accept);
  1180.     $flags   = 0                 unless defined($flags);
  1181.     $context = 0                 unless defined($context);
  1182.   
  1183.     $path = "/".$path if substr($path,0,1) ne "/";  
  1184.     # accept string list needs to be terminated by double-NULL
  1185.     $accept .= "\0\0" unless $accept =~ /\0\0\z/;
  1186.   
  1187.     my $newhandle = HttpOpenRequest($self->{'handle'},
  1188.                                     $method,
  1189.                                     $path,
  1190.                                     $version,
  1191.                                     $referer,
  1192.                                     $accept,
  1193.                                     $flags,
  1194.                                     $context);
  1195.     if($newhandle) {
  1196.         $_[1] = _new($newhandle);
  1197.         $_[1]->{'Type'}    = "HTTP_Request";
  1198.         $_[1]->{'method'}  = $method;
  1199.         $_[1]->{'request'} = $path;
  1200.         $_[1]->{'accept'}  = $accept;
  1201.         return $newhandle;
  1202.     } else {
  1203.         return undef;
  1204.     }
  1205. }
  1206.  
  1207. #================
  1208. sub SendRequest {
  1209. #================
  1210.     my($self, $postdata) = @_;
  1211.     return undef unless ref($self);
  1212.  
  1213.     if($self->{'Type'} ne "HTTP_Request") {
  1214.         $self->{'Error'} = "SendRequest() only on HTTP requests.";
  1215.         return undef;
  1216.     }
  1217.   
  1218.     $postdata = "" unless defined($postdata);
  1219.  
  1220.     return HttpSendRequest($self->{'handle'}, "", $postdata);
  1221. }
  1222.  
  1223.  
  1224. #==============
  1225. sub AddHeader {
  1226. #==============
  1227.     my($self, $header, $flags) = @_;
  1228.     return undef unless ref($self);
  1229.   
  1230.     if($self->{'Type'} ne "HTTP_Request") {
  1231.         $self->{'Error'} = "AddHeader() only on HTTP requests.";
  1232.         return undef;
  1233.     }
  1234.   
  1235.     $flags = constant("HTTP_ADDREQ_FLAG_ADD", 0) if (!defined($flags) or $flags == 0);
  1236.  
  1237.     return HttpAddRequestHeaders($self->{'handle'}, $header, $flags);
  1238. }
  1239.  
  1240.  
  1241. #==============
  1242. sub QueryInfo {
  1243. #==============
  1244.     my($self, $header, $flags) = @_;
  1245.     return undef unless ref($self);
  1246.  
  1247.     if($self->{'Type'} ne "HTTP_Request") {
  1248.         $self->{'Error'}="QueryInfo() only on HTTP requests.";
  1249.         return undef;
  1250.     }
  1251.   
  1252.     $flags = constant("HTTP_QUERY_CUSTOM", 0) if (!defined($flags) and defined($header));
  1253.     my @queryresult = HttpQueryInfo($self->{'handle'}, $flags, $header);
  1254.     return (wantarray)? @queryresult : join(" ", @queryresult);
  1255. }
  1256.  
  1257.  
  1258. #============
  1259. sub Request {
  1260. #============
  1261.     # HttpOpenRequest+HttpAddHeaders+HttpSendRequest+InternetReadFile+HttpQueryInfo
  1262.     my($self, $path, $method, $version, $referer, $accept, $flags, $postdata) = @_;
  1263.     return undef unless ref($self);
  1264.  
  1265.     if($self->{'Type'} ne "HTTP") {
  1266.         $self->{'Error'} = "Request() only on HTTP sessions.";
  1267.         return undef;
  1268.     }
  1269.  
  1270.     if(ref($path) and ref($path) eq "HASH") {
  1271.         $method    = $path->{'method'};
  1272.         $version   = $path->{'version'};
  1273.         $referer   = $path->{'referer'};
  1274.         $accept    = $path->{'accept'};
  1275.         $flags     = $path->{'flags'};
  1276.         $postdata  = $path->{'postdata'};
  1277.         my $mypath = $path->{'path'};
  1278.         undef $path;
  1279.         $path      = $mypath;
  1280.     }
  1281.  
  1282.     my $content     = "";
  1283.     my $result      = "";
  1284.     my @queryresult = ();
  1285.     my $statuscode  = "";
  1286.     my $headers     = "";
  1287.   
  1288.     $path     = "/"               unless defined($path);
  1289.     $method   = "GET"             unless defined($method);
  1290.     $version  = "HTTP/1.0"        unless defined($version); 
  1291.     $referer  = ""                unless defined($referer);
  1292.     $accept   = $self->{'accept'} unless defined($accept);
  1293.     $flags    = 0                 unless defined($flags);
  1294.     $postdata = ""                unless defined($postdata);
  1295.  
  1296.     $path = "/".$path if substr($path,0,1) ne "/";  
  1297.     # accept string list needs to be terminated by double-NULL
  1298.     $accept .= "\0\0" unless $accept =~ /\0\0\z/;
  1299.  
  1300.     my $newhandle = HttpOpenRequest($self->{'handle'},
  1301.                                     $method,
  1302.                                     $path,
  1303.                                     $version,
  1304.                                     $referer,
  1305.                                     $accept,
  1306.                                     $flags,
  1307.                     0);
  1308.  
  1309.     if($newhandle) {
  1310.  
  1311.         $result = HttpSendRequest($newhandle, "", $postdata);
  1312.  
  1313.         if(defined($result)) {
  1314.             $statuscode = HttpQueryInfo($newhandle,
  1315.                                         constant("HTTP_QUERY_STATUS_CODE", 0), "");
  1316.             $headers = HttpQueryInfo($newhandle,
  1317.                                      constant("HTTP_QUERY_RAW_HEADERS_CRLF", 0), "");
  1318.             $content = ReadEntireFile($newhandle);
  1319.                
  1320.             InternetCloseHandle($newhandle);
  1321.       
  1322.             return($statuscode, $headers, $content);
  1323.         } else {
  1324.             return undef;
  1325.         }
  1326.     } else {
  1327.         return undef;
  1328.     }
  1329. }
  1330.  
  1331.  
  1332. #######################################################################
  1333. # END OF THE PUBLIC METHODS
  1334. #
  1335.  
  1336.  
  1337. #========= ### SUB-CLASSES CONSTRUCTOR
  1338. sub _new {
  1339. #=========
  1340.     my $self = {};
  1341.     if ($_[0]) {
  1342.         $self->{'handle'} = $_[0];
  1343.         bless $self;
  1344.     } else {
  1345.         undef($self);
  1346.     }
  1347.     $self;
  1348. }
  1349.  
  1350.  
  1351. #============ ### CLASS DESTRUCTOR
  1352. sub DESTROY {
  1353. #============
  1354.     my($self) = @_;
  1355.     # print "Closing handle $self->{'handle'}...\n";
  1356.     InternetCloseHandle($self->{'handle'});
  1357.     # [dada] rest in peace
  1358. }
  1359.  
  1360.  
  1361. #=============
  1362. sub callback {
  1363. #=============
  1364.     my($name, $status, $info) = @_;
  1365.     $callback_code{$name} = $status;
  1366.     $callback_info{$name} = $info;
  1367. }
  1368.  
  1369. #######################################################################
  1370. # dynamically load in the Internet.pll module.
  1371. #
  1372.  
  1373. bootstrap Win32::Internet;
  1374.  
  1375. # Preloaded methods go here.
  1376.  
  1377. #Currently Autoloading is not implemented in Perl for win32
  1378. # Autoload methods go after __END__, and are processed by the autosplit program.
  1379.  
  1380. 1;
  1381. __END__
  1382.  
  1383. =head1 NAME
  1384.  
  1385. Win32::Internet - Access to WININET.DLL functions
  1386.  
  1387. =head1 INTRODUCTION
  1388.  
  1389. This extension to Perl implements the Win32 Internet APIs (found in
  1390. F<WININET.DLL>). They give a complete support for HTTP, FTP and GOPHER
  1391. connections.
  1392.  
  1393. See the L<"Version History"> and the L<"Functions Table"> for a list
  1394. of the currently supported features. You should also get a copy of the
  1395. L<"Microsoft Win32 Internet Functions"> documentation.
  1396.  
  1397. =head1 REFERENCE
  1398.  
  1399. To use this module, first add the following line at the beginning of
  1400. your script:
  1401.  
  1402.     use Win32::Internet;
  1403.  
  1404. Then you have to open an Internet connection with this command:
  1405.  
  1406.     $Connection = new Win32::Internet();
  1407.  
  1408. This is required to use any of the function of this module.  It will
  1409. create an Internet object in Perl on which you can act upon with the
  1410. L<"General Internet Functions"> explained later.
  1411.  
  1412. The objects available are:
  1413.  
  1414. =over
  1415.  
  1416. =item *
  1417.  
  1418. Internet connections (the main object, see C<new>)
  1419.  
  1420. =item *
  1421.  
  1422. URLs (see C<OpenURL>)
  1423.  
  1424. =item *
  1425.  
  1426. FTP sessions (see C<FTP>)
  1427.  
  1428. =item *
  1429.  
  1430. HTTP sessions (see C<HTTP>)
  1431.  
  1432. =item *
  1433.  
  1434. HTTP requests (see C<OpenRequest>)
  1435.  
  1436. =back
  1437.  
  1438. As in the good Perl tradition, there are in this extension different
  1439. ways to do the same thing; there are, in fact, different levels of
  1440. implementation of the Win32 Internet Functions.  Some routines use
  1441. several Win32 API functions to perform a complex task in a single
  1442. call; they are simpler to use, but of course less powerful.
  1443.  
  1444. There are then other functions that implement nothing more and nothing
  1445. less than the corresponding API function, so you can use all of their
  1446. power, but with some additional programming steps.
  1447.  
  1448. To make an example, there is a function called C<FetchURL> that you
  1449. can use to fetch the content of any HTTP, FTP or GOPHER URL with this
  1450. simple commands:
  1451.  
  1452.     $INET = new Win32::Internet();
  1453.     $file = $INET->FetchURL("http://www.yahoo.com");
  1454.  
  1455. You can have the same result (and this is actually what is done by
  1456. C<FetchURL>) this way:
  1457.  
  1458.     $INET = new Win32::Internet();
  1459.     $URL = $INET->OpenURL("http://www.yahoo.com");
  1460.     $file = $URL->ReadFile();
  1461.     $URL->Close();
  1462.  
  1463. Or, you can open a complete HTTP session:
  1464.  
  1465.     $INET = new Win32::Internet();
  1466.     $HTTP = $INET->HTTP("www.yahoo.com", "anonymous", "dada@divinf.it");
  1467.     ($statuscode, $headers, $file) = $HTTP->Request("/");
  1468.     $HTTP->Close();
  1469.  
  1470. Finally, you can choose to manage even the HTTP request:
  1471.  
  1472.     $INET = new Win32::Internet();
  1473.     $HTTP = $INET->HTTP("www.yahoo.com", "anonymous", "dada@divinf.it");
  1474.     $HTTP->OpenRequest($REQ, "/");
  1475.     $REQ->AddHeader("If-Modified-Since: Saturday, 16-Nov-96 15:58:50 GMT");
  1476.     $REQ->SendRequest();
  1477.     $statuscode = $REQ->QueryInfo("",HTTP_QUERY_STATUS_CODE);
  1478.     $lastmodified = $REQ->QueryInfo("Last-Modified");
  1479.     $file = $REQ->ReadEntireFile();
  1480.     $REQ->Close();
  1481.     $HTTP->Close();
  1482.  
  1483. To open and control a complete FTP session, type:
  1484.  
  1485.     $Connection->FTP($Session, "ftp://ftp.activeware.com", "anonymous", "dada\@divinf.it");
  1486.  
  1487. This will create an FTP object in Perl to which you can apply the L<"FTP
  1488. functions"> provided by the package:
  1489.  
  1490.     $Session->Cd("/ntperl/perl5.001m/CurrentBuild");
  1491.     $Session->Ascii();
  1492.     $Session->Get("110-i86.zip");
  1493.     $Session->Close();
  1494.  
  1495. For a more complete example, see the TEST.PL file that comes with the
  1496. package.
  1497.  
  1498. =head2 General Internet Functions
  1499.  
  1500. B<General Note>
  1501.  
  1502. All methods assume that you have the line:
  1503.  
  1504.     use Win32::Internet;
  1505.  
  1506. somewhere before the method calls, and that you have an Internet
  1507. object called $INET which was created using this call:
  1508.  
  1509.     $INET = new Win32::Internet();
  1510.  
  1511. See C<new> for more information.
  1512.  
  1513. B<Methods>
  1514.  
  1515. =over
  1516.  
  1517. =item CanonicalizeURL URL, [flags]
  1518.  
  1519. Converts a URL to a canonical format, which includes converting unsafe
  1520. characters to escape sequences.  Returns the canonicalized URL or
  1521. C<undef> on errors.  For the possible values of I<flags>, refer to the
  1522. L<"Microsoft Win32 Internet Functions"> document.  See also
  1523. C<CombineURL> and C<OpenURL>.
  1524.  
  1525. Example:
  1526.  
  1527.     $cURL = $INET->CanonicalizeURL($URL);
  1528.     $URL = $INET->CanonicalizeURL($cURL, ICU_DECODE);
  1529.  
  1530. =item Close
  1531.  
  1532. =item Close object
  1533.  
  1534. Closes an Internet connection.  This can be applied to any
  1535. Win32::Internet object (Internet connections, URLs, FTP sessions,
  1536. etc.).  Note that it is not "strictly" required to close the
  1537. connections you create, since the Win32::Internet objects are
  1538. automatically closed when the program ends (or when you elsehow
  1539. destroy such an object).
  1540.  
  1541. Example:
  1542.  
  1543.     $INET->Close();
  1544.     $FTP->Close();
  1545.     $INET->Close($FTP); # same as above...
  1546.  
  1547. =item CombineURL baseURL, relativeURL, [flags]
  1548.  
  1549. Combines a base and relative URL into a single URL.  Returns the
  1550. (canonicalized) combined URL or C<undef> on errors.  For the possible
  1551. values of I<flags>, refer to the L<"Microsoft Win32 Internet
  1552. Functions"> document.  See also C<CombineURL> and C<OpenURL>.
  1553.  
  1554. Example:
  1555.  
  1556.     $URL = $INET->CombineURL("http://www.divinf.it/dada/perl/internet", "..");
  1557.  
  1558. =item ConnectBackoff [value]
  1559.  
  1560. Reads or sets the delay value, in milliseconds, to wait between
  1561. connection retries.  If no I<value> parameter is specified, the
  1562. current value is returned; otherwise, the delay between retries is set
  1563. to I<value>.  See also C<ConnectTimeout>, C<ConnectRetries>,
  1564. C<QueryOption> and C<SetOption>.
  1565.  
  1566. Example:
  1567.  
  1568.     $HTTP->ConnectBackoff(2000);
  1569.     $backoff = $HTTP->ConnectBackoff();
  1570.  
  1571. =item ConnectRetries [value]
  1572.  
  1573. Reads or sets the number of times a connection is retried before
  1574. considering it failed.  If no I<value> parameter is specified, the
  1575. current value is returned; otherwise, the number of retries is set to
  1576. I<value>.  The default value for C<ConnectRetries> is 5.  See also
  1577. C<ConnectBackoff>, C<ConnectTimeout>, C<QueryOption> and C<SetOption>.
  1578.  
  1579. Example:
  1580.  
  1581.     $HTTP->ConnectRetries(20);
  1582.     $retries = $HTTP->ConnectRetries();
  1583.  
  1584. =item ConnectTimeout [value]
  1585.  
  1586. Reads or sets the timeout value (in milliseconds) before a connection
  1587. is considered failed.  If no I<value> parameter is specified, the
  1588. current value is returned; otherwise, the timeout is set to I<value>.
  1589. The default value for C<ConnectTimeout> is infinite.  See also
  1590. C<ConnectBackoff>, C<ConnectRetries>, C<QueryOption> and C<SetOption>.
  1591.  
  1592. Example:
  1593.  
  1594.     $HTTP->ConnectTimeout(10000);
  1595.     $timeout = $HTTP->ConnectTimeout();
  1596.  
  1597. =item ControlReceiveTimeout [value]
  1598.  
  1599. Reads or sets the timeout value (in milliseconds) to use for non-data
  1600. (control) receive requests before they are canceled.  Currently, this
  1601. value has meaning only for C<FTP> sessions.  If no I<value> parameter
  1602. is specified, the current value is returned; otherwise, the timeout is
  1603. set to I<value>.  The default value for C<ControlReceiveTimeout> is
  1604. infinite.  See also C<ControlSendTimeout>, C<QueryOption> and
  1605. C<SetOption>.
  1606.  
  1607. Example:
  1608.  
  1609.     $HTTP->ControlReceiveTimeout(10000);
  1610.     $timeout = $HTTP->ControlReceiveTimeout();
  1611.  
  1612. =item ControlSendTimeout [value]
  1613.  
  1614. Reads or sets the timeout value (in milliseconds) to use for non-data
  1615. (control) send requests before they are canceled.  Currently, this
  1616. value has meaning only for C<FTP> sessions.  If no I<value> parameter
  1617. is specified, the current value is returned; otherwise, the timeout is
  1618. set to I<value>.  The default value for C<ControlSendTimeout> is
  1619. infinite.  See also C<ControlReceiveTimeout>, C<QueryOption> and
  1620. C<SetOption>.
  1621.  
  1622. Example:
  1623.  
  1624.     $HTTP->ControlSendTimeout(10000);
  1625.     $timeout = $HTTP->ControlSendTimeout();
  1626.  
  1627. =item CrackURL URL, [flags]
  1628.  
  1629. Splits an URL into its component parts and returns them in an array.
  1630. Returns C<undef> on errors, otherwise the array will contain the
  1631. following values: I<scheme, host, port, username, password, path,
  1632. extrainfo>.
  1633.  
  1634. For example, the URL "http://www.divinf.it/index.html#top" can be
  1635. splitted in:
  1636.  
  1637.     http, www.divinf.it, 80, anonymous, dada@divinf.it, /index.html, #top
  1638.  
  1639. If you don't specify a I<flags> parameter, ICU_ESCAPE will be used by
  1640. default; for the possible values of I<flags> refer to the L<"Microsoft
  1641. Win32 Internet Functions"> documentation.  See also C<CreateURL>.
  1642.  
  1643. Example:
  1644.  
  1645.     @parts=$INET->CrackURL("http://www.activeware.com");
  1646.     ($scheme, $host, $port, $user, $pass, $path, $extra) =
  1647.          $INET->CrackURL("http://www.divinf.it:80/perl-win32/index.sht#feedback");
  1648.  
  1649. =item CreateURL scheme, hostname, port, username, password, path, extrainfo, [flags]
  1650.  
  1651. =item CreateURL hashref, [flags]
  1652.  
  1653. Creates a URL from its component parts.  Returns C<undef> on errors,
  1654. otherwise the created URL.
  1655.  
  1656. If you pass I<hashref> (a reference to an hash array), the following
  1657. values are taken from the array:
  1658.  
  1659.     %hash=(
  1660.       "scheme"    => "scheme",
  1661.       "hostname"  => "hostname",
  1662.       "port"      => port,
  1663.       "username"  => "username",
  1664.       "password"  => "password",
  1665.       "path"      => "path",
  1666.       "extrainfo" => "extrainfo",
  1667.     );
  1668.  
  1669. If you don't specify a I<flags> parameter, ICU_ESCAPE will be used by
  1670. default; for the other possible values of I<flags> refer to the
  1671. L<"Microsoft Win32 Internet Functions"> documentation.  See also
  1672. C<CrackURL>.
  1673.  
  1674. Example:
  1675.  
  1676.     $URL=$I->CreateURL("http", "www.divinf.it", 80, "", "", "/perl-win32/index.sht", "#feedback");
  1677.     $URL=$I->CreateURL(\%params);
  1678.  
  1679. =item DataReceiveTimeout [value]
  1680.  
  1681. Reads or sets the timeout value (in milliseconds) to use for data
  1682. receive requests before they are canceled.  If no I<value> parameter
  1683. is specified, the current value is returned; otherwise, the timeout is
  1684. set to I<value>.  The default value for DataReceiveTimeout is
  1685. infinite.  See also C<DataSendTimeout>, C<QueryOption> and
  1686. C<SetOption>.
  1687.  
  1688. Example:
  1689.  
  1690.     $HTTP->DataReceiveTimeout(10000);
  1691.     $timeout = $HTTP->DataReceiveTimeout();
  1692.  
  1693. =item DataSendTimeout [value]
  1694.  
  1695. Reads or sets the timeout value (in milliseconds) to use for data send
  1696. requests before they are canceled.  If no I<value> parameter is
  1697. specified, the current value is returned; otherwise, the timeout is
  1698. set to I<value>.  The default value for DataSendTimeout is infinite.
  1699. See also C<DataReceiveTimeout>, C<QueryOption> and C<SetOption>.
  1700.  
  1701. Example:
  1702.  
  1703.     $HTTP->DataSendTimeout(10000);
  1704.     $timeout = $HTTP->DataSendTimeout();
  1705.  
  1706. =item Error
  1707.  
  1708. Returns the last recorded error in the form of an array or string
  1709. (depending upon the context) containing the error number and an error
  1710. description.  Can be applied on any Win32::Internet object (FTP
  1711. sessions, etc.).  There are 3 types of error you can encounter; they
  1712. are recognizable by the error number returned:
  1713.  
  1714. =over
  1715.  
  1716. =item * -1
  1717.  
  1718. A "trivial" error has occurred in the package.  For example, you tried
  1719. to use a method on the wrong type of object.
  1720.  
  1721. =item * 1 .. 11999
  1722.  
  1723. A generic error has occurred and the Win32::GetLastError error message
  1724. is returned.
  1725.  
  1726. =item * 12000 and higher
  1727.  
  1728. An Internet error has occurred; the extended Win32 Internet API error
  1729. message is returned.
  1730.  
  1731. =back
  1732.  
  1733. See also C<GetResponse>.
  1734.  
  1735. Example:
  1736.  
  1737.     die $INET->Error(), qq(\n);
  1738.     ($ErrNum, $ErrText) = $INET->Error();
  1739.  
  1740. =item FetchURL URL
  1741.  
  1742. Fetch the content of an HTTP, FTP or GOPHER URL.  Returns the content
  1743. of the file read (or C<undef> if there was an error and nothing was
  1744. read).  See also C<OpenURL> and C<ReadFile>.
  1745.  
  1746. Example:
  1747.  
  1748.     $file = $INET->FetchURL("http://www.yahoo.com/");
  1749.     $file = $INET->FetchURL("ftp://www.activeware.com/contrib/internet.zip");
  1750.  
  1751. =item FTP ftpobject, server, username, password, [port, pasv, context]
  1752.  
  1753. =item FTP ftpobject, hashref
  1754.  
  1755. Opens an FTP connection to server logging in with the given
  1756. I<username> and I<password>.
  1757.  
  1758. The parameters and their values are:
  1759.  
  1760. =over
  1761.  
  1762. =item * server
  1763.  
  1764. The server to connect to.  Default: I<none>.
  1765.  
  1766. =item * username
  1767.  
  1768. The username used to login to the server.  Default: anonymous.
  1769.  
  1770. =item * password
  1771.  
  1772. The password used to login to the server.  Default: I<none>.
  1773.  
  1774. =item * port
  1775.  
  1776. The port of the FTP service on the server.  Default: 21.
  1777.  
  1778. =item * pasv
  1779.  
  1780. If it is a value other than 0, use passive transfer mode.  Default is
  1781. taken from the parent Internet connection object; you can set this
  1782. value with the C<Pasv> method.
  1783.  
  1784. =item * context
  1785.  
  1786. A number to identify this operation if it is asynchronous.  See
  1787. C<SetStatusCallback> and C<GetStatusCallback> for more info on
  1788. asynchronous operations.  Default: I<none>.
  1789.  
  1790. =back
  1791.  
  1792. If you pass I<hashref> (a reference to an hash array), the following
  1793. values are taken from the array:
  1794.  
  1795.     %hash=(
  1796.       "server"   => "server",
  1797.       "username" => "username",
  1798.       "password" => "password",
  1799.       "port"     => port,
  1800.       "pasv"     => pasv,
  1801.       "context"  => context,
  1802.     );
  1803.  
  1804. This method returns C<undef> if the connection failed, a number
  1805. otherwise.  You can then call any of the L<"FTP functions"> as methods
  1806. of the newly created I<ftpobject>.
  1807.  
  1808. Example:
  1809.  
  1810.     $result = $INET->FTP($FTP, "ftp.activeware.com", "anonymous", "dada\@divinf.it");
  1811.     # and then for example...
  1812.     $FTP->Cd("/ntperl/perl5.001m/CurrentBuild");
  1813.  
  1814.     $params{"server"} = "ftp.activeware.com";
  1815.     $params{"password"} = "dada\@divinf.it";
  1816.     $params{"pasv"} = 0;
  1817.     $result = $INET->FTP($FTP,\%params);
  1818.  
  1819. =item GetResponse
  1820.  
  1821. Returns the text sent by a remote server in response to the last
  1822. function executed.  It applies on any Win32::Internet object,
  1823. particularly of course on L<FTP sessions|"FTP functions">.  See also
  1824. the C<Error> function.
  1825.  
  1826. Example:
  1827.  
  1828.     print $INET->GetResponse();
  1829.     $INET->FTP($FTP, "ftp.activeware.com", "anonymous", "dada\@divinf.it");
  1830.     print $FTP->GetResponse();
  1831.  
  1832. =item GetStatusCallback context
  1833.  
  1834. Returns information about the progress of the asynchronous operation
  1835. identified by I<context>; those informations consist of two values: a
  1836. status code (one of the INTERNET_STATUS_* L<"Constants">) and an
  1837. additional value depending on the status code; for example, if the
  1838. status code returned is INTERNET_STATUS_HANDLE_CREATED, the second
  1839. value will hold the handle just created.  For more informations on
  1840. those values, please refer to the L<"Microsoft Win32 Internet
  1841. Functions"> documentation.  See also C<SetStatusCallback>.
  1842.  
  1843. Example:
  1844.  
  1845.     ($status, $info) = $INET->GetStatusCallback(1);
  1846.  
  1847. =item HTTP httpobject, server, username, password, [port, flags, context]
  1848.  
  1849. =item HTTP httpobject, hashref
  1850.  
  1851. Opens an HTTP connection to I<server> logging in with the given
  1852. I<username> and I<password>.
  1853.  
  1854. The parameters and their values are:
  1855.  
  1856. =over
  1857.  
  1858. =item * server
  1859.  
  1860. The server to connect to.  Default: I<none>.
  1861.  
  1862. =item * username
  1863.  
  1864. The username used to login to the server.  Default: anonymous.
  1865.  
  1866. =item * password
  1867.  
  1868. The password used to login to the server.  Default: I<none>.
  1869.  
  1870. =item * port
  1871.  
  1872. The port of the HTTP service on the server.  Default: 80.
  1873.  
  1874. =item * flags
  1875.  
  1876. Additional flags affecting the behavior of the function.  Default:
  1877. I<none>.
  1878.  
  1879. =item * context
  1880.  
  1881. A number to identify this operation if it is asynchronous.  See
  1882. C<SetStatusCallback> and C<GetStatusCallback> for more info on
  1883. asynchronous operations.  Default: I<none>.
  1884.  
  1885. =back
  1886.  
  1887. Refer to the L<"Microsoft Win32 Internet Functions"> documentation for
  1888. more details on those parameters.
  1889.  
  1890. If you pass I<hashref> (a reference to an hash array), the following
  1891. values are taken from the array:
  1892.  
  1893.     %hash=(
  1894.       "server"   => "server",
  1895.       "username" => "username",
  1896.       "password" => "password",
  1897.       "port"     => port,
  1898.       "flags"    => flags,
  1899.       "context"  => context,
  1900.     );
  1901.  
  1902. This method returns C<undef> if the connection failed, a number
  1903. otherwise.  You can then call any of the L<"HTTP functions"> as
  1904. methods of the newly created I<httpobject>.
  1905.  
  1906. Example:
  1907.  
  1908.     $result = $INET->HTTP($HTTP,"www.activeware.com","anonymous","dada\@divinf.it");
  1909.     # and then for example...
  1910.     ($statuscode, $headers, $file) = $HTTP->Request("/gifs/camel.gif");
  1911.  
  1912.     $params{"server"} = "www.activeware.com";
  1913.     $params{"password"} = "dada\@divinf.it";
  1914.     $params{"flags"} = INTERNET_FLAG_RELOAD;
  1915.     $result = $INET->HTTP($HTTP,\%params);
  1916.  
  1917. =item new Win32::Internet [useragent, opentype, proxy, proxybypass, flags]
  1918.  
  1919. =item new Win32::Internet [hashref]
  1920.  
  1921. Creates a new Internet object and initializes the use of the Internet
  1922. functions; this is required before any of the functions of this
  1923. package can be used.  Returns C<undef> if the connection fails, a number
  1924. otherwise.  The parameters and their values are:
  1925.  
  1926. =over
  1927.  
  1928. =item * useragent
  1929.  
  1930. The user agent passed to HTTP requests.  See C<OpenRequest>.  Default:
  1931. Perl-Win32::Internet/I<version>.
  1932.  
  1933. =item * opentype
  1934.  
  1935. How to access to the Internet (eg. directly or using a proxy).
  1936. Default: INTERNET_OPEN_TYPE_DIRECT.
  1937.  
  1938. =item * proxy
  1939.  
  1940. Name of the proxy server (or servers) to use.  Default: I<none>.
  1941.  
  1942. =item * proxybypass
  1943.  
  1944. Optional list of host names or IP addresses, or both, that are known
  1945. locally.  Default: I<none>.
  1946.  
  1947. =item * flags
  1948.  
  1949. Additional flags affecting the behavior of the function.  Default:
  1950. I<none>.
  1951.  
  1952. =back
  1953.  
  1954. Refer to the L<"Microsoft Win32 Internet Functions"> documentation for
  1955. more details on those parameters.  If you pass I<hashref> (a reference to
  1956. an hash array), the following values are taken from the array:
  1957.  
  1958.     %hash=(
  1959.       "useragent"   => "useragent",
  1960.       "opentype"    => "opentype",
  1961.       "proxy"       => "proxy",
  1962.       "proxybypass" => "proxybypass",
  1963.       "flags"       => flags,
  1964.     );
  1965.  
  1966. Example:
  1967.  
  1968.     $INET = new Win32::Internet();
  1969.     die qq(Cannot connect to Internet...\n) if ! $INET;
  1970.  
  1971.     $INET = new Win32::Internet("Mozilla/3.0", INTERNET_OPEN_TYPE_PROXY, "www.microsoft.com", "");
  1972.  
  1973.     $params{"flags"} = INTERNET_FLAG_ASYNC;
  1974.     $INET = new Win32::Internet(\%params);
  1975.  
  1976. =item OpenURL urlobject, URL
  1977.  
  1978. Opens a connection to an HTTP, FTP or GOPHER Uniform Resource Location
  1979. (URL).  Returns C<undef> on errors or a number if the connection was
  1980. succesful.  You can then retrieve the URL content by applying the
  1981. methods C<QueryDataAvailable> and C<ReadFile> on the newly created
  1982. I<urlobject>.  See also C<FetchURL>.
  1983.  
  1984. Example:
  1985.  
  1986.     $INET->OpenURL($URL, "http://www.yahoo.com/");
  1987.     $bytes = $URL->QueryDataAvailable();
  1988.     $file = $URL->ReadEntireFile();
  1989.     $URL->Close();
  1990.  
  1991. =item Password [password]
  1992.  
  1993. Reads or sets the password used for an C<FTP> or C<HTTP> connection.
  1994. If no I<password> parameter is specified, the current value is
  1995. returned; otherwise, the password is set to I<password>.  See also
  1996. C<Username>, C<QueryOption> and C<SetOption>.
  1997.  
  1998. Example:
  1999.  
  2000.     $HTTP->Password("splurfgnagbxam");
  2001.     $password = $HTTP->Password();
  2002.  
  2003. =item QueryDataAvailable
  2004.  
  2005. Returns the number of bytes of data that are available to be read
  2006. immediately by a subsequent call to C<ReadFile> (or C<undef> on
  2007. errors).  Can be applied to URL or HTTP request objects.  See
  2008. C<OpenURL> or C<OpenRequest>.
  2009.  
  2010. Example:
  2011.  
  2012.     $INET->OpenURL($URL, "http://www.yahoo.com/");
  2013.     $bytes = $URL->QueryDataAvailable();
  2014.  
  2015. =item QueryOption option
  2016.  
  2017. Queries an Internet option.  For the possible values of I<option>,
  2018. refer to the L<"Microsoft Win32 Internet Functions"> document.  See
  2019. also C<SetOption>.
  2020.  
  2021. Example:
  2022.  
  2023.     $value = $INET->QueryOption(INTERNET_OPTION_CONNECT_TIMEOUT);
  2024.     $value = $HTTP->QueryOption(INTERNET_OPTION_USERNAME);
  2025.  
  2026. =item ReadEntireFile
  2027.  
  2028. Reads all the data available from an opened URL or HTTP request
  2029. object.  Returns what have been read or C<undef> on errors.  See also
  2030. C<OpenURL>, C<OpenRequest> and C<ReadFile>.
  2031.  
  2032. Example:
  2033.  
  2034.     $INET->OpenURL($URL, "http://www.yahoo.com/");
  2035.     $file = $URL->ReadEntireFile();
  2036.  
  2037. =item ReadFile bytes
  2038.  
  2039. Reads I<bytes> bytes of data from an opened URL or HTTP request
  2040. object.  Returns what have been read or C<undef> on errors.  See also
  2041. C<OpenURL>, C<OpenRequest>, C<QueryDataAvailable> and
  2042. C<ReadEntireFile>.
  2043.  
  2044. B<Note:> be careful to keep I<bytes> to an acceptable value (eg.  don't
  2045. tell him to swallow megabytes at once...).  C<ReadEntireFile> in fact
  2046. uses C<QueryDataAvailable> and C<ReadFile> in a loop to read no more
  2047. than 16k at a time.
  2048.  
  2049. Example:
  2050.  
  2051.     $INET->OpenURL($URL, "http://www.yahoo.com/");
  2052.     $chunk = $URL->ReadFile(16000);
  2053.  
  2054. =item SetOption option, value
  2055.  
  2056. Sets an Internet option.  For the possible values of I<option>, refer to
  2057. the L<"Microsoft Win32 Internet Functions"> document.  See also
  2058. C<QueryOption>.
  2059.  
  2060. Example:
  2061.  
  2062.     $INET->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,10000);
  2063.     $HTTP->SetOption(INTERNET_OPTION_USERNAME,"dada");
  2064.  
  2065. =item SetStatusCallback
  2066.  
  2067. Initializes the callback routine used to return data about the
  2068. progress of an asynchronous operation.
  2069.  
  2070. Example:
  2071.  
  2072.     $INET->SetStatusCallback();
  2073.  
  2074. This is one of the step required to perform asynchronous operations;
  2075. the complete procedure is:
  2076.  
  2077.     # use the INTERNET_FLAG_ASYNC when initializing
  2078.     $params{'flags'}=INTERNET_FLAG_ASYNC;
  2079.     $INET = new Win32::Internet(\%params);
  2080.  
  2081.     # initialize the callback routine
  2082.     $INET->SetStatusCallback();
  2083.  
  2084.     # specify the context parameter (the last 1 in this case)
  2085.     $INET->HTTP($HTTP, "www.yahoo.com", "anonymous", "dada\@divinf.it", 80, 0, 1);
  2086.  
  2087. At this point, control returns immediately to Perl and $INET->Error()
  2088. will return 997, which means an asynchronous I/O operation is
  2089. pending.  Now, you can call
  2090.  
  2091.     $HTTP->GetStatusCallback(1);
  2092.  
  2093. in a loop to verify what's happening; see also C<GetStatusCallback>.
  2094.  
  2095. =item TimeConvert time
  2096.  
  2097. =item TimeConvert seconds, minute, hours, day, month, year,
  2098.                   day_of_week, RFC
  2099.  
  2100. The first form takes a HTTP date/time string and returns the date/time
  2101. converted in the following array: I<seconds, minute, hours, day,
  2102. month, year, day_of_week>.
  2103.  
  2104. The second form does the opposite (or at least it should, because
  2105. actually seems to be malfunctioning): it takes the values and returns
  2106. an HTTP date/time string, in the RFC format specified by the I<RFC>
  2107. parameter (OK, I didn't find yet any accepted value in the range
  2108. 0..2000, let me know if you have more luck with it).
  2109.  
  2110. Example:
  2111.  
  2112.     ($sec, $min, $hour, $day, $mday, $year, $wday) =
  2113.        $INET->TimeConvert("Sun, 26 Jan 1997 20:01:52 GMT");
  2114.  
  2115.     # the opposite DOESN'T WORK! which value should $RFC have???
  2116.     $time = $INET->TimeConvert(52, 1, 20, 26, 1, 1997, 0, $RFC);
  2117.  
  2118. =item UserAgent [name]
  2119.  
  2120. Reads or sets the user agent used for HTTP requests.  If no I<name>
  2121. parameter is specified, the current value is returned; otherwise, the
  2122. user agent is set to I<name>.  See also C<QueryOption> and
  2123. C<SetOption>.
  2124.  
  2125. Example:
  2126.  
  2127.     $INET->UserAgent("Mozilla/3.0");
  2128.     $useragent = $INET->UserAgent();
  2129.  
  2130. =item Username [name]
  2131.  
  2132. Reads or sets the username used for an C<FTP> or C<HTTP> connection.
  2133. If no I<name> parameter is specified, the current value is returned;
  2134. otherwise, the username is set to I<name>.  See also C<Password>,
  2135. C<QueryOption> and SetOption.
  2136.  
  2137. Example:
  2138.  
  2139.     $HTTP->Username("dada");
  2140.     $username = $HTTP->Username();
  2141.  
  2142. =item Version
  2143.  
  2144. Returns the version numbers for the Win32::Internet package and the
  2145. WININET.DLL version, as an array or string, depending on the context.
  2146. The string returned will contain "package_version/DLL_version", while
  2147. the array will contain: "package_version", "DLL_version".
  2148.  
  2149. Example:
  2150.  
  2151.     $version = $INET->Version(); # should return "0.06/4.70.1215"
  2152.     @version = $INET->Version(); # should return ("0.06", "4.70.1215")
  2153.  
  2154. =back
  2155.  
  2156.  
  2157. =head2 FTP Functions
  2158.  
  2159. B<General Note>
  2160.  
  2161. All methods assume that you have the following lines:
  2162.  
  2163.     use Win32::Internet;
  2164.     $INET = new Win32::Internet();
  2165.     $INET->FTP($FTP, "hostname", "username", "password");
  2166.  
  2167. somewhere before the method calls; in other words, we assume that you
  2168. have an Internet object called $INET and an open FTP session called
  2169. $FTP.
  2170.  
  2171. See C<new> and C<FTP> for more information.
  2172.  
  2173.  
  2174. B<Methods>
  2175.  
  2176. =over
  2177.  
  2178. =item Ascii
  2179.  
  2180. =item Asc
  2181.  
  2182. Sets the ASCII transfer mode for this FTP session.  It will be applied
  2183. to the subsequent C<Get> functions.  See also the C<Binary> and
  2184. C<Mode> function.
  2185.  
  2186. Example:
  2187.  
  2188.     $FTP->Ascii();
  2189.  
  2190. =item Binary
  2191.  
  2192. =item Bin
  2193.  
  2194. Sets the binary transfer mode for this FTP session.  It will be
  2195. applied to the subsequent C<Get> functions.  See also the C<Ascii> and
  2196. C<Mode> function.
  2197.  
  2198. Example:
  2199.  
  2200.     $FTP->Binary();
  2201.  
  2202. =item Cd path
  2203.  
  2204. =item Cwd path
  2205.  
  2206. =item Chdir path
  2207.  
  2208. Changes the current directory on the FTP remote host.  Returns I<path>
  2209. or C<undef> on error.
  2210.  
  2211. Example:
  2212.  
  2213.     $FTP->Cd("/pub");
  2214.  
  2215. =item Delete file
  2216.  
  2217. =item Del file
  2218.  
  2219. Deletes a file on the FTP remote host.  Returns C<undef> on error.
  2220.  
  2221. Example:
  2222.  
  2223.     $FTP->Delete("110-i86.zip");
  2224.  
  2225. =item Get remote, [local, overwrite, flags, context]
  2226.  
  2227. Gets the I<remote> FTP file and saves it locally in I<local>.  If
  2228. I<local> is not specified, it will be the same name as I<remote>.
  2229. Returns C<undef> on error.  The parameters and their values are:
  2230.  
  2231. =over
  2232.  
  2233. =item * remote
  2234.  
  2235. The name of the remote file on the FTP server.  Default: I<none>.
  2236.  
  2237. =item * local
  2238.  
  2239. The name of the local file to create.  Default: remote.
  2240.  
  2241. =item * overwrite
  2242.  
  2243. If 0, overwrites I<local> if it exists; with any other value, the
  2244. function fails if the I<local> file already exists.  Default: 0.
  2245.  
  2246. =item * flags
  2247.  
  2248. Additional flags affecting the behavior of the function.  Default:
  2249. I<none>.
  2250.  
  2251. =item * context
  2252.  
  2253. A number to identify this operation if it is asynchronous.  See
  2254. C<SetStatusCallback> and C<GetStatusCallback> for more info on
  2255. asynchronous operations.  Default: I<none>.
  2256.  
  2257. =back
  2258.  
  2259. Refer to the L<"Microsoft Win32 Internet Functions"> documentation for
  2260. more details on those parameters.
  2261.  
  2262. Example:
  2263.  
  2264.     $FTP->Get("110-i86.zip");
  2265.     $FTP->Get("/pub/perl/languages/CPAN/00index.html", "CPAN_index.html");
  2266.  
  2267. =item List [pattern, listmode]
  2268.  
  2269. =item Ls [pattern, listmode]
  2270.  
  2271. =item Dir [pattern, listmode]
  2272.  
  2273. Returns a list containing the files found in this directory,
  2274. eventually matching the given I<pattern> (which, if omitted, is
  2275. considered "*.*").  The content of the returned list depends on the
  2276. I<listmode> parameter, which can have the following values:
  2277.  
  2278. =over
  2279.  
  2280. =item * listmode=1 (or omitted)
  2281.  
  2282. the list contains the names of the files found.  Example:
  2283.  
  2284.     @files = $FTP->List();
  2285.     @textfiles = $FTP->List("*.txt");
  2286.     foreach $file (@textfiles) {
  2287.       print "Name: ", $file, "\n";
  2288.     }
  2289.  
  2290. =item * listmode=2
  2291.  
  2292. the list contains 7 values for each file, which respectively are:
  2293.  
  2294. =over
  2295.  
  2296. =item * the file name
  2297.  
  2298. =item * the DOS short file name, aka 8.3
  2299.  
  2300. =item * the size
  2301.  
  2302. =item * the attributes
  2303.  
  2304. =item * the creation time
  2305.  
  2306. =item * the last access time
  2307.  
  2308. =item * the last modified time
  2309.  
  2310. =back
  2311.  
  2312. Example:
  2313.  
  2314.     @files = $FTP->List("*.*", 2);
  2315.     for($i=0; $i<=$#files; $i+=7) {
  2316.       print "Name: ", @files[$i], "\n";
  2317.       print "Size: ", @files[$i+2], "\n";
  2318.       print "Attr: ", @files[$i+3], "\n";
  2319.     }
  2320.  
  2321. =item * listmode=3
  2322.  
  2323. the list contains a reference to an hash array for each found file;
  2324. each hash contains:
  2325.  
  2326. =over
  2327.  
  2328. =item * name => the file name
  2329.  
  2330. =item * altname => the DOS short file name, aka 8.3
  2331.  
  2332. =item * size => the size
  2333.  
  2334. =item * attr => the attributes
  2335.  
  2336. =item * ctime => the creation time
  2337.  
  2338. =item * atime => the last access time
  2339.  
  2340. =item * mtime => the last modified time
  2341.  
  2342. =back
  2343.  
  2344. Example:
  2345.  
  2346.     @files = $FTP->List("*.*", 3);
  2347.     foreach $file (@files) {
  2348.       print $file->{'name'}, " ", $file->{'size'}, " ", $file->{'attr'}, "\n";
  2349.     }
  2350.  
  2351. B<Note:> all times are reported as strings of the following format:
  2352. I<second, hour, minute, day, month, year>.
  2353.  
  2354. Example:
  2355.  
  2356.     $file->{'mtime'} == "0,10,58,9,12,1996" stands for 09 Dec 1996 at 10:58:00
  2357.  
  2358. =back
  2359.  
  2360. =item Mkdir name
  2361.  
  2362. =item Md name
  2363.  
  2364. Creates a directory on the FTP remote host.  Returns C<undef> on error.
  2365.  
  2366. Example:
  2367.  
  2368.     $FTP->Mkdir("NextBuild");
  2369.  
  2370. =item Mode [mode]
  2371.  
  2372. If called with no arguments, returns the current transfer mode for
  2373. this FTP session ("asc" for ASCII or "bin" for binary).  The I<mode>
  2374. argument can be "asc" or "bin", in which case the appropriate transfer
  2375. mode is selected.  See also the Ascii and Binary functions.  Returns
  2376. C<undef> on errors.
  2377.  
  2378. Example:
  2379.  
  2380.     print "Current mode is: ", $FTP->Mode();
  2381.     $FTP->Mode("asc"); # ...  same as $FTP->Ascii();
  2382.  
  2383. =item Pasv [mode]
  2384.  
  2385. If called with no arguments, returns 1 if the current FTP session has
  2386. passive transfer mode enabled, 0 if not.
  2387.  
  2388. You can call it with a I<mode> parameter (0/1) only as a method of a
  2389. Internet object (see C<new>), in which case it will set the default
  2390. value for the next C<FTP> objects you create (read: set it before,
  2391. because you can't change this value once you opened the FTP session).
  2392.  
  2393. Example:
  2394.  
  2395.     print "Pasv is: ", $FTP->Pasv();
  2396.  
  2397.     $INET->Pasv(1);
  2398.     $INET->FTP($FTP,"ftp.activeware.com", "anonymous", "dada\@divinf.it");
  2399.     $FTP->Pasv(0); # this will be ignored...
  2400.  
  2401. =item Put local, [remote, context]
  2402.  
  2403. Upload the I<local> file to the FTP server saving it under the name
  2404. I<remote>, which if if omitted is the same name as I<local>.  Returns
  2405. C<undef> on error.
  2406.  
  2407. I<context> is a number to identify this operation if it is asynchronous.
  2408. See C<SetStatusCallback> and C<GetStatusCallback> for more info on
  2409. asynchronous operations.
  2410.  
  2411. Example:
  2412.  
  2413.     $FTP->Put("internet.zip");
  2414.     $FTP->Put("d:/users/dada/temp.zip", "/temp/dada.zip");
  2415.  
  2416. =item Pwd
  2417.  
  2418. Returns the current directory on the FTP server or C<undef> on errors.
  2419.  
  2420. Example:
  2421.  
  2422.     $path = $FTP->Pwd();
  2423.  
  2424. =item Rename oldfile, newfile
  2425.  
  2426. =item Ren oldfile, newfile
  2427.  
  2428. Renames a file on the FTP remote host.  Returns C<undef> on error.
  2429.  
  2430. Example:
  2431.  
  2432.     $FTP->Rename("110-i86.zip", "68i-011.zip");
  2433.  
  2434. =item Rmdir name
  2435.  
  2436. =item Rd name
  2437.  
  2438. Removes a directory on the FTP remote host.  Returns C<undef> on error.
  2439.  
  2440. Example:
  2441.  
  2442.     $FTP->Rmdir("CurrentBuild");
  2443.  
  2444. =back
  2445.  
  2446. =head2 HTTP Functions
  2447.  
  2448. B<General Note>
  2449.  
  2450. All methods assume that you have the following lines:
  2451.  
  2452.     use Win32::Internet;
  2453.     $INET = new Win32::Internet();
  2454.     $INET->HTTP($HTTP, "hostname", "username", "password");
  2455.  
  2456. somewhere before the method calls; in other words, we assume that you
  2457. have an Internet object called $INET and an open HTTP session called
  2458. $HTTP.
  2459.  
  2460. See C<new> and C<HTTP> for more information.
  2461.  
  2462.  
  2463. B<Methods>
  2464.  
  2465. =over
  2466.  
  2467. =item AddHeader header, [flags]
  2468.  
  2469. Adds HTTP request headers to an HTTP request object created with
  2470. C<OpenRequest>.  For the possible values of I<flags> refer to the
  2471. L<"Microsoft Win32 Internet Functions"> document.
  2472.  
  2473. Example:
  2474.  
  2475.     $HTTP->OpenRequest($REQUEST,"/index.html");
  2476.     $REQUEST->AddHeader("If-Modified-Since:  Sunday, 17-Nov-96 11:40:03 GMT");
  2477.     $REQUEST->AddHeader("Accept: text/html\r\n", HTTP_ADDREQ_FLAG_REPLACE);
  2478.  
  2479. =item OpenRequest requestobject, [path, method, version, referer, accept, flags, context]
  2480.  
  2481. =item OpenRequest requestobject, hashref
  2482.  
  2483. Opens an HTTP request.  Returns C<undef> on errors or a number if the
  2484. connection was succesful.  You can then use one of the C<AddHeader>,
  2485. C<SendRequest>, C<QueryInfo>, C<QueryDataAvailable> and C<ReadFile>
  2486. methods on the newly created I<requestobject>.  The parameters and
  2487. their values are:
  2488.  
  2489. =over
  2490.  
  2491. =item * path
  2492.  
  2493. The object to request.  This is generally a file name, an executable
  2494. module, etc.  Default: /
  2495.  
  2496. =item * method
  2497.  
  2498. The method to use; can actually be GET, POST, HEAD or PUT.  Default:
  2499. GET
  2500.  
  2501. =item * version
  2502.  
  2503. The HTTP version.  Default: HTTP/1.0
  2504.  
  2505. =item * referer
  2506.  
  2507. The URL of the document from which the URL in the request was
  2508. obtained.  Default: I<none>
  2509.  
  2510. =item * accept
  2511.  
  2512. A single string with "\0" (ASCII zero) delimited list of content
  2513. types accepted.  The string must be terminated by "\0\0".
  2514. Default: "text/*\0image/gif\0image/jpeg\0\0"
  2515.  
  2516. =item * flags
  2517.  
  2518. Additional flags affecting the behavior of the function.  Default:
  2519. I<none>
  2520.  
  2521. =item * context
  2522.  
  2523. A number to identify this operation if it is asynchronous.  See
  2524. C<SetStatusCallback> and C<GetStatusCallback> for more info on
  2525. asynchronous operations.  Default: I<none>
  2526.  
  2527. =back
  2528.  
  2529. Refer to the L<"Microsoft Win32 Internet Functions"> documentation for
  2530. more details on those parameters.  If you pass I<hashref> (a reference to
  2531. an hash array), the following values are taken from the array:
  2532.  
  2533.     %hash=(
  2534.       "path"        => "path",
  2535.       "method"      => "method",
  2536.       "version"     => "version",
  2537.       "referer"     => "referer",
  2538.       "accept"      => "accept",
  2539.       "flags"       => flags,
  2540.       "context"     => context,
  2541.     );
  2542.  
  2543. See also C<Request>.
  2544.  
  2545. Example:
  2546.  
  2547.     $HTTP->OpenRequest($REQUEST, "/index.html");
  2548.     $HTTP->OpenRequest($REQUEST, "/index.html", "GET", "HTTP/0.9");
  2549.  
  2550.     $params{"path"} = "/index.html";
  2551.     $params{"flags"} = "
  2552.     $HTTP->OpenRequest($REQUEST, \%params);
  2553.  
  2554. =item QueryInfo header, [flags]
  2555.  
  2556. Queries information about an HTTP request object created with
  2557. C<OpenRequest>.  You can specify an I<header> (for example,
  2558. "Content-type") and/or one or more I<flags>.  If you don't specify
  2559. I<flags>, HTTP_QUERY_CUSTOM will be used by default; this means that
  2560. I<header> should contain a valid HTTP header name.  For the possible
  2561. values of I<flags> refer to the L<"Microsoft Win32 Internet
  2562. Functions"> document.
  2563.  
  2564. Example:
  2565.  
  2566.     $HTTP->OpenRequest($REQUEST,"/index.html");
  2567.     $statuscode = $REQUEST->QueryInfo("", HTTP_QUERY_STATUS_CODE);
  2568.     $headers = $REQUEST->QueryInfo("", HTTP_QUERY_RAW_HEADERS_CRLF); # will get all the headers
  2569.     $length = $REQUEST->QueryInfo("Content-length");
  2570.  
  2571. =item Request [path, method, version, referer, accept, flags]
  2572.  
  2573. =item Request hashref
  2574.  
  2575. Performs an HTTP request and returns an array containing the status
  2576. code, the headers and the content of the file.  It is a one-step
  2577. procedure that makes an C<OpenRequest>, a C<SendRequest>, some
  2578. C<QueryInfo>, C<ReadFile> and finally C<Close>.  For a description of
  2579. the parameters, see C<OpenRequest>.
  2580.  
  2581. Example:
  2582.  
  2583.     ($statuscode, $headers, $file) = $HTTP->Request("/index.html");
  2584.     ($s, $h, $f) = $HTTP->Request("/index.html", "GET", "HTTP/1.0");
  2585.  
  2586. =item SendRequest [postdata]
  2587.  
  2588. Send an HTTP request to the destination server.  I<postdata> are any
  2589. optional data to send immediately after the request header; this is
  2590. generally used for POST or PUT requests.  See also C<OpenRequest>.
  2591.  
  2592. Example:
  2593.  
  2594.     $HTTP->OpenRequest($REQUEST, "/index.html");
  2595.     $REQUEST->SendRequest();
  2596.  
  2597.     # A POST request...
  2598.     $HTTP->OpenRequest($REQUEST, "/cgi-bin/somescript.pl", "POST");
  2599.  
  2600.     #This line is a must -> (thanks Philip :)
  2601.     $REQUEST->AddHeader("Content-Type: application/x-www-form-urlencoded");
  2602.  
  2603.     $REQUEST->SendRequest("key1=value1&key2=value2&key3=value3");
  2604.  
  2605. =back
  2606.  
  2607.  
  2608. =head1 APPENDIX
  2609.  
  2610.  
  2611. =head2 Microsoft Win32 Internet Functions
  2612.  
  2613. Complete documentation for the Microsoft Win32 Internet Functions can
  2614. be found, in both HTML and zipped Word format, at this address:
  2615.  
  2616.     http://www.microsoft.com/intdev/sdk/docs/wininet/
  2617.  
  2618. =head2 Functions Table
  2619.  
  2620. This table reports the correspondence between the functions offered by
  2621. WININET.DLL and their implementation in the Win32::Internet
  2622. extension. Functions showing a "---" are not currently
  2623. implemented. Functions enclosed in parens ( ) aren't implemented
  2624. straightforwardly, but in a higher-level routine, eg. together with
  2625. other functions.
  2626.  
  2627.     WININET.DLL                     Win32::Internet
  2628.  
  2629.     InternetOpen                    new Win32::Internet
  2630.     InternetConnect                 FTP / HTTP
  2631.     InternetCloseHandle             Close
  2632.     InternetQueryOption             QueryOption
  2633.     InternetSetOption               SetOption
  2634.     InternetSetOptionEx             ---
  2635.     InternetSetStatusCallback       SetStatusCallback
  2636.     InternetStatusCallback          GetStatusCallback
  2637.     InternetConfirmZoneCrossing     ---
  2638.     InternetTimeFromSystemTime      TimeConvert
  2639.     InternetTimeToSystemTime        TimeConvert
  2640.     InternetAttemptConnect          ---
  2641.     InternetReadFile                ReadFile
  2642.     InternetSetFilePointer          ---
  2643.     InternetFindNextFile            (List)
  2644.     InternetQueryDataAvailable      QueryDataAvailable
  2645.     InternetGetLastResponseInfo     GetResponse
  2646.     InternetWriteFile               ---
  2647.     InternetCrackUrl                CrackURL
  2648.     InternetCreateUrl               CreateURL
  2649.     InternetCanonicalizeUrl         CanonicalizeURL
  2650.     InternetCombineUrl              CombineURL
  2651.     InternetOpenUrl                 OpenURL
  2652.     FtpFindFirstFile                (List)
  2653.     FtpGetFile                      Get
  2654.     FtpPutFile                      Put
  2655.     FtpDeleteFile                   Delete
  2656.     FtpRenameFile                   Rename
  2657.     FtpOpenFile                     ---
  2658.     FtpCreateDirectory              Mkdir
  2659.     FtpRemoveDirectory              Rmdir
  2660.     FtpSetCurrentDirectory          Cd
  2661.     FtpGetCurrentDirectory          Pwd
  2662.     HttpOpenRequest                 OpenRequest
  2663.     HttpAddRequestHeaders           AddHeader
  2664.     HttpSendRequest                 SendRequest
  2665.     HttpQueryInfo                   QueryInfo
  2666.     InternetErrorDlg                ---
  2667.  
  2668.  
  2669. Actually, I don't plan to add support for Gopher, Cookie and Cache
  2670. functions. I will if there will be consistent requests to do so.
  2671.  
  2672. There are a number of higher-level functions in the Win32::Internet
  2673. that simplify some usual procedures, calling more that one WININET API
  2674. function. This table reports those functions and the relative WININET
  2675. functions they use.
  2676.  
  2677.     Win32::Internet                 WININET.DLL
  2678.  
  2679.     FetchURL                        InternetOpenUrl
  2680.                                     InternetQueryDataAvailable
  2681.                                     InternetReadFile
  2682.                                     InternetCloseHandle
  2683.  
  2684.     ReadEntireFile                  InternetQueryDataAvailable
  2685.                                     InternetReadFile
  2686.  
  2687.     Request                         HttpOpenRequest
  2688.                                     HttpSendRequest
  2689.                                     HttpQueryInfo
  2690.                                     InternetQueryDataAvailable
  2691.                                     InternetReadFile
  2692.                                     InternetCloseHandle
  2693.  
  2694.     List                            FtpFindFirstFile
  2695.                                     InternetFindNextFile
  2696.  
  2697.  
  2698. =head2 Constants
  2699.  
  2700. Those are the constants exported by the package in the main namespace
  2701. (eg. you can use them in your scripts); for their meaning and proper
  2702. use, refer to the Microsoft Win32 Internet Functions document.
  2703.  
  2704.     HTTP_ADDREQ_FLAG_ADD
  2705.     HTTP_ADDREQ_FLAG_REPLACE
  2706.     HTTP_QUERY_ALLOW
  2707.     HTTP_QUERY_CONTENT_DESCRIPTION
  2708.     HTTP_QUERY_CONTENT_ID
  2709.     HTTP_QUERY_CONTENT_LENGTH
  2710.     HTTP_QUERY_CONTENT_TRANSFER_ENCODING
  2711.     HTTP_QUERY_CONTENT_TYPE
  2712.     HTTP_QUERY_COST
  2713.     HTTP_QUERY_CUSTOM
  2714.     HTTP_QUERY_DATE
  2715.     HTTP_QUERY_DERIVED_FROM
  2716.     HTTP_QUERY_EXPIRES
  2717.     HTTP_QUERY_FLAG_REQUEST_HEADERS
  2718.     HTTP_QUERY_FLAG_SYSTEMTIME
  2719.     HTTP_QUERY_LANGUAGE
  2720.     HTTP_QUERY_LAST_MODIFIED
  2721.     HTTP_QUERY_MESSAGE_ID
  2722.     HTTP_QUERY_MIME_VERSION
  2723.     HTTP_QUERY_PRAGMA
  2724.     HTTP_QUERY_PUBLIC
  2725.     HTTP_QUERY_RAW_HEADERS
  2726.     HTTP_QUERY_RAW_HEADERS_CRLF
  2727.     HTTP_QUERY_REQUEST_METHOD
  2728.     HTTP_QUERY_SERVER
  2729.     HTTP_QUERY_STATUS_CODE
  2730.     HTTP_QUERY_STATUS_TEXT
  2731.     HTTP_QUERY_URI
  2732.     HTTP_QUERY_USER_AGENT
  2733.     HTTP_QUERY_VERSION
  2734.     HTTP_QUERY_WWW_LINK
  2735.     ICU_BROWSER_MODE
  2736.     ICU_DECODE
  2737.     ICU_ENCODE_SPACES_ONLY
  2738.     ICU_ESCAPE
  2739.     ICU_NO_ENCODE
  2740.     ICU_NO_META
  2741.     ICU_USERNAME
  2742.     INTERNET_FLAG_PASSIVE
  2743.     INTERNET_FLAG_ASYNC
  2744.     INTERNET_FLAG_HYPERLINK
  2745.     INTERNET_FLAG_KEEP_CONNECTION
  2746.     INTERNET_FLAG_MAKE_PERSISTENT
  2747.     INTERNET_FLAG_NO_AUTH
  2748.     INTERNET_FLAG_NO_AUTO_REDIRECT
  2749.     INTERNET_FLAG_NO_CACHE_WRITE
  2750.     INTERNET_FLAG_NO_COOKIES
  2751.     INTERNET_FLAG_READ_PREFETCH
  2752.     INTERNET_FLAG_RELOAD
  2753.     INTERNET_FLAG_RESYNCHRONIZE
  2754.     INTERNET_FLAG_TRANSFER_ASCII
  2755.     INTERNET_FLAG_TRANSFER_BINARY
  2756.     INTERNET_INVALID_PORT_NUMBER
  2757.     INTERNET_INVALID_STATUS_CALLBACK
  2758.     INTERNET_OPEN_TYPE_DIRECT
  2759.     INTERNET_OPEN_TYPE_PROXY
  2760.     INTERNET_OPEN_TYPE_PROXY_PRECONFIG
  2761.     INTERNET_OPTION_CONNECT_BACKOFF
  2762.     INTERNET_OPTION_CONNECT_RETRIES
  2763.     INTERNET_OPTION_CONNECT_TIMEOUT
  2764.     INTERNET_OPTION_CONTROL_SEND_TIMEOUT
  2765.     INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT
  2766.     INTERNET_OPTION_DATA_SEND_TIMEOUT
  2767.     INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
  2768.     INTERNET_OPTION_HANDLE_TYPE
  2769.     INTERNET_OPTION_LISTEN_TIMEOUT
  2770.     INTERNET_OPTION_PASSWORD
  2771.     INTERNET_OPTION_READ_BUFFER_SIZE
  2772.     INTERNET_OPTION_USER_AGENT
  2773.     INTERNET_OPTION_USERNAME
  2774.     INTERNET_OPTION_VERSION
  2775.     INTERNET_OPTION_WRITE_BUFFER_SIZE
  2776.     INTERNET_SERVICE_FTP
  2777.     INTERNET_SERVICE_GOPHER
  2778.     INTERNET_SERVICE_HTTP
  2779.     INTERNET_STATUS_CLOSING_CONNECTION
  2780.     INTERNET_STATUS_CONNECTED_TO_SERVER
  2781.     INTERNET_STATUS_CONNECTING_TO_SERVER
  2782.     INTERNET_STATUS_CONNECTION_CLOSED
  2783.     INTERNET_STATUS_HANDLE_CLOSING
  2784.     INTERNET_STATUS_HANDLE_CREATED
  2785.     INTERNET_STATUS_NAME_RESOLVED
  2786.     INTERNET_STATUS_RECEIVING_RESPONSE
  2787.     INTERNET_STATUS_REDIRECT
  2788.     INTERNET_STATUS_REQUEST_COMPLETE
  2789.     INTERNET_STATUS_REQUEST_SENT
  2790.     INTERNET_STATUS_RESOLVING_NAME
  2791.     INTERNET_STATUS_RESPONSE_RECEIVED
  2792.     INTERNET_STATUS_SENDING_REQUEST
  2793.  
  2794.  
  2795. =head1 VERSION HISTORY
  2796.  
  2797. =over
  2798.  
  2799. =item * 0.082 (4 Sep 2001)
  2800.  
  2801. =over
  2802.  
  2803. =item *
  2804.  
  2805. Fix passive FTP mode.  INTERNET_FLAG_PASSIVE was misspelled in earlier
  2806. versions (as INTERNET_CONNECT_FLAG_PASSIVE) and wouldn't work.  Found
  2807. by Steve Raynesford <stever@evolvecomm.com>.
  2808.  
  2809. =back
  2810.  
  2811. =item * 0.081 (25 Sep 1999)
  2812.  
  2813. =over
  2814.  
  2815. =item *
  2816.  
  2817. Documentation converted to pod format by Jan Dubois <JanD@ActiveState.com>.
  2818.  
  2819. =item *
  2820.  
  2821. Minor changes from Perl 5.005xx compatibility.
  2822.  
  2823. =back
  2824.  
  2825. =item * 0.08 (14 Feb 1997)
  2826.  
  2827. =over
  2828.  
  2829. =item *
  2830.  
  2831. fixed 2 more bugs in Option(s) related subs (thanks to Brian
  2832. Helterline!).
  2833.  
  2834. =item *
  2835.  
  2836. Error() now gets error messages directly from WININET.DLL.
  2837.  
  2838. =item *
  2839.  
  2840. The PLL file now comes in 2 versions, one for Perl version 5.001
  2841. (build 100) and one for Perl version 5.003 (build 300 and
  2842. higher). Everybody should be happy now :)
  2843.  
  2844. =item *
  2845.  
  2846. added an installation program.
  2847.  
  2848. =back
  2849.  
  2850. =item * 0.07 (10 Feb 1997)
  2851.  
  2852. =over
  2853.  
  2854. =item *
  2855.  
  2856. fixed a bug in Version() introduced with 0.06...
  2857.  
  2858. =item *
  2859.  
  2860. completely reworked PM file, fixed *lots* of minor bugs, and removed
  2861. almost all the warnings with "perl -w".
  2862.  
  2863. =back
  2864.  
  2865. =item * 0.06 (26 Jan 1997)
  2866.  
  2867. =over
  2868.  
  2869. =item *
  2870.  
  2871. fixed another hideous bug in "new" (the 'class' parameter was still
  2872. missing).
  2873.  
  2874. =item *
  2875.  
  2876. added support for asynchronous operations (work still in embryo).
  2877.  
  2878. =item *
  2879.  
  2880. removed the ending \0 (ASCII zero) from the DLL version returned by
  2881. "Version".
  2882.  
  2883. =item *
  2884.  
  2885. added a lot of constants.
  2886.  
  2887. =item *
  2888.  
  2889. added safefree() after every safemalloc() in C... wonder why I didn't
  2890. it before :)
  2891.  
  2892. =item *
  2893.  
  2894. added TimeConvert, which actually works one way only.
  2895.  
  2896. =back
  2897.  
  2898. =item * 0.05f (29 Nov 1996)
  2899.  
  2900. =over
  2901.  
  2902. =item *
  2903.  
  2904. fixed a bug in "new" (parameters passed were simply ignored).
  2905.  
  2906. =item *
  2907.  
  2908. fixed another bug: "Chdir" and "Cwd" were aliases of RMDIR instead of
  2909. CD..
  2910.  
  2911. =back
  2912.  
  2913. =item * 0.05 (29 Nov 1996)
  2914.  
  2915. =over
  2916.  
  2917. =item *
  2918.  
  2919. added "CrackURL" and "CreateURL".
  2920.  
  2921. =item *
  2922.  
  2923. corrected an error in TEST.PL (there was a GetUserAgent instead of
  2924. UserAgent).
  2925.  
  2926. =back
  2927.  
  2928. =item * 0.04 (25 Nov 1996)
  2929.  
  2930. =over
  2931.  
  2932. =item *
  2933.  
  2934. added "Version" to retrieve package and DLL versions.
  2935.  
  2936. =item *
  2937.  
  2938. added proxies and other options to "new".
  2939.  
  2940. =item *
  2941.  
  2942. changed "OpenRequest" and "Request" to read parameters from a hash.
  2943.  
  2944. =item *
  2945.  
  2946. added "SetOption/QueryOption" and a lot of relative functions
  2947. (connect, username, password, useragent, etc.).
  2948.  
  2949. =item *
  2950.  
  2951. added "CanonicalizeURL" and "CombineURL".
  2952.  
  2953. =item *
  2954.  
  2955. "Error" covers a wider spectrum of errors.
  2956.  
  2957. =back
  2958.  
  2959. =item * 0.02 (18 Nov 1996)
  2960.  
  2961. =over
  2962.  
  2963. =item *
  2964.  
  2965. added support for HTTP sessions and requests.
  2966.  
  2967. =back
  2968.  
  2969. =item * 0.01 (11 Nov 1996)
  2970.  
  2971. =over
  2972.  
  2973. =item *
  2974.  
  2975. fetching of HTTP, FTP and GOPHER URLs.
  2976.  
  2977. =item *
  2978.  
  2979. complete set of commands to manage an FTP session.
  2980.  
  2981. =back
  2982.  
  2983. =back
  2984.  
  2985. =head1 AUTHOR
  2986.  
  2987. Version 0.08 (14 Feb 1997) by Aldo Calpini <a.calpini@romagiubileo.it>
  2988.  
  2989.  
  2990. =head1 CREDITS
  2991.  
  2992. Win32::Internet is based on the Win32::Registry code written by Jesse
  2993. Dougherty.
  2994.  
  2995. Additional thanks to: Carl Tichler for his help in the initial
  2996. development; Tore Haraldsen, Brian Helterline for the bugfixes; Dave
  2997. Roth for his great source code examples.
  2998.  
  2999.  
  3000. =head1 DISCLAIMER
  3001.  
  3002. This program is FREE; you can redistribute, modify, disassemble, or
  3003. even reverse engineer this software at your will. Keep in mind,
  3004. however, that NOTHING IS GUARANTEED to work and everything you do is
  3005. AT YOUR OWN RISK - I will not take responsability for any damage, loss
  3006. of money and/or health that may arise from the use of this program!
  3007.  
  3008. This is distributed under the terms of Larry Wall's Artistic License.
  3009.