1Net::SNPP::Server(3)  User Contributed Perl Documentation Net::SNPP::Server(3)
2
3
4

NAME

6       Net::SNPP::Server
7

DESCRIPTION

9       An object interface for creating SNPP servers.  Almost everything you
10       need to create your very own SNPP server is here in this module.  There
11       is a callback() method that can replace default function with your own.
12       them.  Any SNPP command can be overridden or new/custom ones can be
13       created using custom_command().  To disable commands you just don't
14       want to deal with, use disable_command().
15

SYNOPSIS

17       There may be a synopsis here someday ...
18

METHODS

20       new()
21           Create a Net::SNPP::Server object listening on a port.  By default,
22           it only listens on the localhost (127.0.0.1) - specify MultiHomed
23           to listen on all addresses or LocalAddr to listen on only one.
24
25            my $svr = Net::SNPP::Server->new(
26               Port       => port to listen on
27               BindTo     => interface address to bind to
28               MultiHomed => listen on all interfaces if true (and BindTo is unset)
29               Listen     => how many simultaneous connections to handle (SOMAXCONN)
30               # the following two options are only used by handle_client()
31               MaxErrors  => maximum number of errors before disconnecting client
32               Timeout    => timeout while waiting for data (uses SIGARLM)
33            );
34
35       client()
36           Calls accept() for you and returns a client handle.  This method
37           will block if there is no waiting client.  The handle returned is a
38           subclass of IO::Handle, so all IO::Handle methods should work.
39            my $client = $server->client();
40
41       ip()
42           Return the IP address associated with a client handle.
43            printf "connection from %s", $client->ip();
44
45       socket()
46           Returns the raw socket handle.  This mainly exists for use with
47           select() or IO::Select.
48            my $select = IO::Select->new();
49            $select->add( $server->socket() );
50
51       connected()
52           For use with a client handle.  True if server socket is still
53           alive.
54
55       shutdown()
56           Shuts down the server socket.
57            $server->shutdown(2);
58
59       callback()
60           Insert a callback into Server.pm.
61            $server->callback( 'process_page', \&my_function );
62            $server->callback( 'validate_pager_id', \&my_function );
63            $server->callback( 'validate_pager_pin', \&my_function );
64            $server->callback( 'write_log',    \&my_function );
65            $server->callback( 'create_id_and_pin', \&my_function );
66
67           process_page( $PAGER_ID, \%PAGE, \@RESULTS )
68             $PAGER_ID = [
69                0 => retval of validate_pager_id
70                1 => retval of validate_pager_pin ] $PAGE = {
71                mess => $,
72                responses => [], }
73
74           validate_pager_id( PAGER_ID )
75             The return value of this callback will be saved as the pager id
76             that is passed to the process_page callback as the first list
77             element of the first argument.
78
79           validate_pager_pin( VALIDATED_PAGER_ID, PIN )
80             The value returned by this callback will be saved as the second
81             list element in the first argument to process_page.  The PAGER_ID
82             input to this callback is the output from the validate_pager_id
83             callback.
84
85             NOTE: If you really care about the PIN, you must use this call‐
86             back.  The default callback will return 1 if the pin is not set.
87
88           write_log
89             First argument is a Unix syslog level, such as "warning" or
90             "info."  The rest of the arguments are the message.  Return value
91             is ignored.
92
93           create_id_and_pin
94             Create an ID and PIN for a 2way message.
95
96       custom_command()
97           Create a custom command or override a default command in han‐
98           dle_client().  The command name must be 4 letters or numbers.  The
99           second argument is a coderef that should return a text command,
100           i.e. "250 OK" and some "defined" value to continue the client loop.
101           +++If no value is set, the client will be disconnected after exe‐
102           cuting your command.+++ If you need MSTA or KTAG, this is the hook
103           you need to implement them.
104
105           The subroutine will be passed the command arguments, split on
106           whitespace.
107
108            sub my_MSTA_sub {
109               my( $id, $password ) = @_;
110               # ...
111               return "250 OK", 1;
112            }
113            $server->custom_command( "MSTA", \&my_MSTA_sub );
114
115       disable_command()
116           Specify a command to disable in the server.  This is useful, for
117           instance, if you don't want to support level 3 commands.
118            $server->disable_command( "2WAY", "550 2WAY not supported here" );
119
120           The second argument is an optional custom error message.  The
121           default is:
122            "500 Command Not Implemented, Try Again"
123
124       handle_client()
125           Takes the result of $server->client() and takes care of parsing the
126           user input.   This should be quite close to being rfc1861 compli‐
127           ant.  If you specified Timeout to be something other than 0 in
128           new(), SIGARLM will be used to set a timeout.  If you use this,
129           make sure to take signals into account when writing your code.
130           fork()'ing before calling handle_client is a good way to avoid
131           interrupting code that shouldn't be interrupted.
132
133       forked_server()
134           Creates a server in a forked process.  The return value is an array
135           (or arrayref depending on context) containing a read-only pipe and
136           the pid of the new process.  Pages completed will be written to the
137           pipe as a semicolon delimited array.
138            my($pipe,$pid) = $server->forked_server();
139            my $line = $pipe->getline();
140            chomp( $line );
141            my( $pgr, $pgr, %pagedata ) = split( /;/, $line );
142

AUTHOR

144       Al Tobey <tobeya@tobert.org>
145
146       Some ideas from Sendpage::SNPPServer
147        Kees Cook <cook@cpoint.net> http://outflux.net/
148

TODO

150       Add more hooks for callbacks
151
152       Implement the following level 2 and level 3 commands
153
154        4.5.1 LOGIn <loginid> [password]
155        4.5.3 LEVEl <ServiceLevel>
156        4.5.5 COVErage <AlternateArea>
157        4.5.7 CALLerid <CallerID>
158        4.6.3 EXPTag <hours>
159        4.6.5 ACKRead <0⎪1>
160        4.6.6 RTYPe <Reply_Type_Code>
161

SEE ALSO

163       Net::Cmd Socket
164
165
166
167perl v5.8.8                       2004-04-08              Net::SNPP::Server(3)
Impressum