1Net::SNPP::Server(3) User Contributed Perl Documentation Net::SNPP::Server(3)
2
3
4
6 Net::SNPP::Server
7
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
17 There may be a synopsis here someday ...
18
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
86 callback. The default callback will return 1 if the pin is not
87 set.
88
89 write_log
90 First argument is a Unix syslog level, such as "warning" or
91 "info." The rest of the arguments are the message. Return value
92 is ignored.
93
94 create_id_and_pin
95 Create an ID and PIN for a 2way message.
96
97 custom_command()
98 Create a custom command or override a default command in
99 handle_client(). The command name must be 4 letters or numbers.
100 The second argument is a coderef that should return a text command,
101 i.e. "250 OK" and some "defined" value to continue the client loop.
102 +++If no value is set, the client will be disconnected after
103 executing your command.+++ If you need MSTA or KTAG, this is the
104 hook you need to implement them.
105
106 The subroutine will be passed the command arguments, split on
107 whitespace.
108
109 sub my_MSTA_sub {
110 my( $id, $password ) = @_;
111 # ...
112 return "250 OK", 1;
113 }
114 $server->custom_command( "MSTA", \&my_MSTA_sub );
115
116 disable_command()
117 Specify a command to disable in the server. This is useful, for
118 instance, if you don't want to support level 3 commands.
119 $server->disable_command( "2WAY", "550 2WAY not supported here" );
120
121 The second argument is an optional custom error message. The
122 default is:
123 "500 Command Not Implemented, Try Again"
124
125 handle_client()
126 Takes the result of $server->client() and takes care of parsing the
127 user input. This should be quite close to being rfc1861
128 compliant. If you specified Timeout to be something other than 0
129 in new(), SIGARLM will be used to set a timeout. If you use this,
130 make sure to take signals into account when writing your code.
131 fork()'ing before calling handle_client is a good way to avoid
132 interrupting code that shouldn't be interrupted.
133
134 forked_server()
135 Creates a server in a forked process. The return value is an array
136 (or arrayref depending on context) containing a read-only pipe and
137 the pid of the new process. Pages completed will be written to the
138 pipe as a semicolon delimited array.
139 my($pipe,$pid) = $server->forked_server();
140 my $line = $pipe->getline();
141 chomp( $line );
142 my( $pgr, $pgr, %pagedata ) = split( /;/, $line );
143
145 Al Tobey <tobeya@tobert.org>
146
147 Some ideas from Sendpage::SNPPServer
148 Kees Cook <cook@cpoint.net> http://outflux.net/
149
151 Add more hooks for callbacks
152
153 Implement the following level 2 and level 3 commands
154
155 4.5.1 LOGIn <loginid> [password]
156 4.5.3 LEVEl <ServiceLevel>
157 4.5.5 COVErage <AlternateArea>
158 4.5.7 CALLerid <CallerID>
159 4.6.3 EXPTag <hours>
160 4.6.5 ACKRead <0|1>
161 4.6.6 RTYPe <Reply_Type_Code>
162
164 Net::Cmd Socket
165
166
167
168perl v5.34.0 2022-01-21 Net::SNPP::Server(3)