🌻 📖 AnyEvent::Ident::Server

NAME

AnyEvent::Ident::Server - Simple asynchronous ident server

VERSION

version 0.08

SYNOPSIS

 use AnyEvent::Ident::Server;
 my $server = AnyEvent::Ident::Server->new;
 
 $server->start(sub {
   my $tx = shift;
   if($tx->req->server_port == 400
   && $tx->req->client_port == 500)
   {
     $tx->reply_with_user('UNIX', 'grimlock');
   }
   else
   {
     $tx->reply_with_error('NO-USER');
   }
 });

DESCRIPTION

Provide a simple asynchronous ident server. This class manages connections and handles client errors for you, but you have to provide an implementation which determines the owner for a connection given a server and client port. This class may also be useful for testing ident clients against (see the test suite in this distribution, it uses this class to test AnyEvent::Ident::Client), or for constructing an ident server which always returns the same user (which may be useful for some applications, such as IRC).

CONSTRUCTOR

 my $server = AnyEvent::Ident::Server->new(%args);

The constructor takes the following optional arguments:

hostname

default 127.0.0.1

The hostname to connect to.

port

default 113

The port to connect to.

on_error

default carp error

A callback subref to be called on error (either connection or transmission error). Passes the error string as the first argument to the callback.

on_bind

A callback subref to be called when the socket has been bound to a port. Useful when using an ephemeral and you do not know the port number in advance.

start

 $server->start( $callback );

Start the Ident server. The given callback will be called on each ident request (there may be multiple ident requests for each connection). The first and only argument passed to the callback is the transaction, an instance of AnyEvent::Ident::Transaction. The most important attribute on the transaction object are res, the response object (itself an instance of AnyEvent::Ident::Transaction with server_port and client_port attributes) and the most important methods on the transaction object are reply_with_user and reply_with_error which reply with a successful and error response respectively.

bindport

 my $port = $server->bindport;

The bind port. If port is set to zero in the constructor or on start, then an ephemeral port will be used, and you can get the port number here.

stop

 $server-E<gt>stop

Stop the server and unbind to the port.

AUTHOR

Graham Ollis <plicease@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.