NAME
Net::SNPP::Server
DESCRIPTION
An object interface for creating SNPP servers. Almost everything you need to create your very own SNPP server is here in this module. There is a callback() method that can replace default function with your own. them. Any SNPP command can be overridden or new/custom ones can be created using custom_command(). To disable commands you just don't want to deal with, use disable_command().
CONSTRUCTOR
- new()
-
Create a Net::SNPP::Server object listening on a port. By default, it only listens on the localhost (127.0.0.1) - specify MultiHomed to listen on all addresses or LocalAddr to listen on only one.
my $svr = Net::SNPP::Server->new( Port => port to listen on BindTo => interface address to bind to MultiHomed => listen on all interfaces if true (and BindTo is unset) Listen => how many simultaneous connections to handle (SOMAXCONN) # the following two options are only used by handle_client() MaxErrors => maximum number of errors before disconnecting client Timeout => timeout while waiting for data (uses SIGARLM) );
METHODS
- client()
-
Calls accept() for you and returns a client handle. This method will block if there is no waiting client. The handle returned is a subclass of IO::Handle, so all IO::Handle methods should work. my $client = $server->client();
- socket()
-
Returns the raw socket handle. This mainly exists for use with select() or IO::Select. my $select = IO::Select->new(); $select->add( $server->socket() );
- connected()
-
For use with a client handle. True if server socket is still alive.
- shutdown()
-
Shuts down the server socket. $server->shutdown(2);
- callback()
-
Insert a callback into Server.pm. $server->callback( 'process_page', \&my_function ); $server->callback( 'validate_pgr', \&my_function ); $server->callback( 'validate_pin', \&my_function ); $server->callback( 'write_log', \&my_function ); $server->callback( 'create_id_and_pin', \&my_function );
- process_page
-
Stuff
- validate_pager_id
-
Stuff
- validate_pager_pin
-
Stuff
- write_log
-
Stuff
- create_id_and_pin
-
Stuff
- custom_command()
-
Create a custom command or override a default command in handle_client(). The command name must be 4 letters or numbers. The second argument is a coderef that should return a text command, i.e. "250 OK." If you need MSTA or KTAG, this is the hook you need to implement them. $server->custom_command( "MSTA", \&my_MSTA_sub );
- disable_command()
-
Specify a command to disable in the server. This is useful, for instance, if you don't want to support level 3 commands. $server->disable_command( "2WAY", "550 2WAY not supported here" );
The second argument is an optional custom error message. The default is: "500 Command Not Implemented, Try Again"
- handle_client()
-
Takes the result of $server->client() and takes care of parsing the user input. This should be quite close to being rfc1861 compliant. If you specified Timeout to be something other than 0 in new(), SIGARLM will be used to set a timeout. If you use this, make sure to take signals into account when writing your code. fork()'ing before calling handle_client is a good way to avoid interrupting code that shouldn't be interrupted.
- forked_server()
-
Creates a server in a forked process. The return value is an array (or arrayref depending on context) containing a read-only pipe and the pid of the new process. Pages completed will be written to the pipe as a semicolon delimited array. my($pipe,$pid) = $server->forked_server(); my $line = $pipe->getline(); chomp( $line ); my( $pgr, $pgr, %pagedata ) = split( /;/, $line );
AUTHOR
Al Tobey <tobeya@tobert.org>
Some ideas from Sendpage::SNPPServer Kees Cook <cook@cpoint.net> http://outflux.net/
TODO
Add more hooks for callbacks
Implement the following level 2 and level 3 commands
4.5.1 LOGIn <loginid> [password]
4.5.3 LEVEl <ServiceLevel>
4.5.5 COVErage <AlternateArea>
4.5.7 CALLerid <CallerID>
4.6.3 EXPTag <hours>
4.6.5 ACKRead <0|1>
4.6.6 RTYPe <Reply_Type_Code>
SEE ALSO
Net::Cmd Socket
3 POD Errors
The following errors were encountered while parsing the POD:
- Around line 47:
You forgot a '=back' before '=head1'
- Around line 130:
'=item' outside of any '=over'
- Around line 650:
You forgot a '=back' before '=head1'