Net-SSLeay-1.36 > Net::SSLeay::Handle
Net-SSLeay-1.36
Other versions:
Net-SSLeay-1.20

名前

Net::SSLeay::Handle - Perl module that lets SSL (HTTPS) sockets be handled as standard file handles.

Net::SSLeay::Handle - SSL (HTTPS) ソケットを標準のファイルハンドルとして扱わせる Perl モジュール

概要

  use Net::SSLeay::Handle qw/shutdown/;
  my ($host, $port) = ("localhost", 443);

  tie(*SSL, "Net::SSLeay::Handle", $host, $port);

  print SSL "GET / HTTP/1.0\r\n";
  shutdown(\*SSL, 1);
  print while (<SSL>);
  close SSL;                                                       
  

説明

Net::SSLeay::Handle allows you to request and receive HTTPS web pages using "old-fashion" file handles as in:

Net::SSLeay::Handle は HTTPS web ページを「昔ながらの」ファイルハンドルを 使って以下のように、リクエストしたり、受け取ることを可能にします:

    print SSL "GET / HTTP/1.0\r\n";

and

そして

    print while (<SSL>);

If you export the shutdown routine, then the only extra code that you need to add to your program is the tie function as in:

shutdown ルーチンをエクスポートすると、あなたのプログラムに追加する 必要がある特別なコードは、以下のような tie 関数だけになります:

    my $socket;
    if ($scheme eq "https") {
        tie(*S2, "Net::SSLeay::Handle", $host, $port);
        $socket = \*S2;
    else {
        $socket = Net::SSLeay::Handle->make_socket($host, $port);
    }
    print $socket $request_headers;
    ... 

関数

shutdown
  shutdown(\*SOCKET, $mode)

Calls to the main shutdown() don't work with tied sockets created with this module. This shutdown should be able to distinquish between tied and untied sockets and do the right thing.

メインの shutdown() は、このモジュールで作成した tie された ソケットに対しては正しく動作しません。 この shutdown は tie されたソケットとそれ以外を区別し、 正しいことをします。

debug
  my $debug = Net::SSLeay::Handle->debug()
  Net::SSLeay::Handle->debug(1)

Get/set debuging mode. Always returns the debug value before the function call. if an additional argument is given the debug option will be set to this value.

デバッグモードを取得/設定する。 常に、関数呼び出しの前のデバッグモードを返します。 追加の引数が与えられると、デバッグオプションはこの値に設定されます。

make_socket
  my $sock = Net::SSLeay::Handle->make_socket($host, $port);

Creates a socket that is connected to $post using $port. It uses $Net::SSLeay::proxyhost and proxyport if set and authentificates itself against this proxy depending on $Net::SSLeay::proxyauth. It also turns autoflush on for the created socket.

$port を使って $host に接続されたソケットを作ります。 設定されていれば、$Net::SSLeay::proxyhost と proxyport を使い、 $Net::SSLeay::proxyauth に依存してこのプロキシに対して認証します。 また、作られたソケットの自動フラッシュを有効にします。

既存のソケットを利用する

One of the motivations for writing this module was to avoid duplicating socket creation code (which is mostly error handling). The calls to tie() above where it is passed a $host and $port is provided for convenience testing. If you already have a socket connected to the right host and port, S1, then you can do something like:

このモジュールを作った動機の一つは、ソケットを作るコードが重複する ことを避けることでした(そのほとんどはエラーの取り扱いになります)。 上記の $host と $port が渡されるところで tie() を呼び出すことは、 便宜上、テストのために提供されています。 正しいホストとポートに接続されたソケット S1 を既に持っているのであれば、 以下のようにすることができます:

    my $socket \*S1;
    if ($scheme eq "https") {
        tie(*S2, "Net::SSLeay::Handle", $socket);
        $socket = \*S2;
    }
    my $last_sel = select($socket); $| = 1; select($last_sel);
    print $socket $request_headers;
    ... 

Note: As far as I know you must be careful with the globs in the tie() function. The first parameter must be a glob (*SOMETHING) and the last parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler that was assigned to a reference to a glob (as in the example above)

注意: 私が知る限り、tie() 関数ではグロブの取り扱いには注意しなければ なりません。 最初のパラメータはグロブ (*SOMETHING) でなければなりません。 そして最後のパラメータはグロブへのリファレンス (\*SOMETHING_ELSE) あるいは (上記の例のように)グロブへのリファレンスが代入されたスカラーでなければ なりません。

Also, the two globs must be different. When I tried to use the same glob, I got a core dump.

また、二つのグロブは違うものでなければなりません。 私が同じグロブを使おうとしたときには、コアダンプになりました。

EXPORT

None by default.

デフォルトでは何もありません。

You can export the shutdown() function.

shutodown() 関数をエクスポートすることができます。

It is suggested that you do export shutdown() or use the fully qualified Net::SSLeay::Handle::shutdown() function to shutdown SSL sockets. It should be smart enough to distinguish between SSL and non-SSL sockets and do the right thing.

SSL ソケットをシャットダウンするためには、shutdown() をエスクポートするか、 完全に修飾された Net::SSLeay::Handle::shutdown() 関数を使うことを提案します。 SSL と非 SSL ソケットを区別し、正しいことを行うのに十分スマートです。

  use Net::SSLeay::Handle qw/shutdown/;
  my ($host, $port) = ("localhost", 443);

  tie(*SSL, "Net::SSLeay::Handle", $host, $port);

  print SSL "GET / HTTP/1.0\r\n";
  shutdown(\*SSL, 1);
  print while (<SSL>);
  close SSL; 

TODO

Better error handling. Callback routine?

よりよいエラーの取り扱い。 コールバックルーチン?

CAVEATS

Tying to a file handle is a little tricky (for me at least).

ファイルハンドルに tie しようとすることは少しトリッキーです (少なくとも私にとっては)。

The first parameter to tie() must be a glob (*SOMETHING) and the last parameter must be a reference to a glob (\*SOMETHING_ELSE) or a scaler that was assigned to a reference to a glob ($s = \*SOMETHING_ELSE). Also, the two globs must be different. When I tried to use the same glob, I got a core dump.

tie() への最初のパラメータはグロブ (*SOMETHING) で 、最後のパラメータは グロブへのリファレンス (\*SOMETHING_ELSE) か、グロブへのリファレンスが 代入されたスカラ ($s = \*SOMETHING_ELSE) でなければなりません。 また二つのグロブは違うものでなければなりません。 私が同じグロブを使おうとしたときには、コアダンプになりました。

I was able to associate attributes to globs created by this module (like *SSL above) by making a hash of hashes keyed by the file head1.

ファイル head1 によりキーが付けられたハッシュのハッシュを作ることにより、 (上記の *SSL のように) このモジュールにより作成されたグロブに属性を 関連付けることができました。

Support for old perls may not be 100%. If in trouble try 5.6.0 or newer.

古い perl のサポートは 100% ではないかもしれません。 障害時には 5.6.0 以上をお試しください。

CHANGES

Please see Net-SSLeay-Handle-0.50/Changes file.

Net-SSLeay-Handle-0.50/Changes ファイルをご覧ください。

KNOWN BUGS

If you let this module construct sockets for you with Perl versions below v.5.6 then there is a slight memory leak. Other upgrade your Perl, or create the sockets yourself. The leak was created to let these older versions of Perl access more than one Handle at a time.

Perl バージョン v5.6 以前で、このモジュールにあなた用のソケットを作るよう 命令すると、少しメモリリークを起こします。 Perl をアップグレードするか、あなた自身でソケットを作成してください。 そのリークは、これらの古いバージョンの Perl に同時に複数の ハンドルにアクセスさせるために作られます。

作者

Jim Bowlin jbowlin@linklint.org

SEE ALSO

Net::SSLeay, perl(1), http://openssl.org/