.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Net::SNPP::Server 3pm" .TH Net::SNPP::Server 3pm "2016-08-19" "perl v5.22.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Net::SNPP::Server \- SNPP server library .SH "DESCRIPTION" .IX Header "DESCRIPTION" An object interface for creating \s-1SNPP\s0 servers. Almost everything you need to create your very own \s-1SNPP\s0 server is here in this module. There is a \fIcallback()\fR method that can replace default function with your own. them. Any \s-1SNPP\s0 command can be overridden or new/custom ones can be created using \fIcustom_command()\fR. To disable commands you just don't want to deal with, use \fIdisable_command()\fR. .SH "SYNOPSIS" .IX Header "SYNOPSIS" There may be a synopsis here someday ... .SH "METHODS" .IX Header "METHODS" .IP "\fInew()\fR" 4 .IX Item "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. .Sp .Vb 9 \& 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) \& ); .Ve .IP "\fIclient()\fR" 4 .IX Item "client()" Calls \fIaccept()\fR 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 \f(CW$client\fR = \f(CW$server\fR\->\fIclient()\fR; .IP "\fIip()\fR" 4 .IX Item "ip()" Return the \s-1IP\s0 address associated with a client handle. printf \*(L"connection from \f(CW%s\fR\*(R", \f(CW$client\fR\->\fIip()\fR; .IP "\fIsocket()\fR" 4 .IX Item "socket()" Returns the raw socket handle. This mainly exists for use with \fIselect()\fR or IO::Select. my \f(CW$select\fR = IO::Select\->\fInew()\fR; \f(CW$select\fR\->add( \f(CW$server\fR\->\fIsocket()\fR ); .IP "\fIconnected()\fR" 4 .IX Item "connected()" For use with a client handle. True if server socket is still alive. .IP "\fIshutdown()\fR" 4 .IX Item "shutdown()" Shuts down the server socket. \f(CW$server\fR\->\fIshutdown\fR\|(2); .IP "\fIcallback()\fR" 4 .IX Item "callback()" Insert a callback into Server.pm. \f(CW$server\fR\->callback( 'process_page', \e&my_function ); \f(CW$server\fR\->callback( 'validate_pager_id', \e&my_function ); \f(CW$server\fR\->callback( 'validate_pager_pin', \e&my_function ); \f(CW$server\fR\->callback( 'write_log', \e&my_function ); \f(CW$server\fR\->callback( 'create_id_and_pin', \e&my_function ); .RS 4 .ie n .IP "process_page( $PAGER_ID, \e%PAGE, \e@RESULTS )" 2 .el .IP "process_page( \f(CW$PAGER_ID\fR, \e%PAGE, \e@RESULTS )" 2 .IX Item "process_page( $PAGER_ID, %PAGE, @RESULTS )" \&\f(CW$PAGER_ID\fR = [ 0 => retval of validate_pager_id 1 => retval of validate_pager_pin ] \&\f(CW$PAGE\fR = { mess => $, responses => [], } .IP "validate_pager_id( \s-1PAGER_ID \s0)" 2 .IX Item "validate_pager_id( PAGER_ID )" The return value of this callback will be saved as the pager id that is passed to the process_page callback as the first list element of the first argument. .IP "validate_pager_pin( \s-1VALIDATED_PAGER_ID, PIN \s0)" 2 .IX Item "validate_pager_pin( VALIDATED_PAGER_ID, PIN )" The value returned by this callback will be saved as the second list element in the first argument to process_page. The \s-1PAGER_ID\s0 input to this callback is the output from the validate_pager_id callback. .Sp \&\s-1NOTE:\s0 If you really care about the \s-1PIN,\s0 you must use this callback. The default callback will return 1 if the pin is not set. .IP "write_log" 2 .IX Item "write_log" First argument is a Unix syslog level, such as \*(L"warning\*(R" or \*(L"info.\*(R" The rest of the arguments are the message. Return value is ignored. .IP "create_id_and_pin" 2 .IX Item "create_id_and_pin" Create an \s-1ID\s0 and \s-1PIN\s0 for a 2way message. .RE .RS 4 .RE .IP "\fIcustom_command()\fR" 4 .IX Item "custom_command()" Create a custom command or override a default command in \fIhandle_client()\fR. The command name must be 4 letters or numbers. The second argument is a coderef that should return a text command, i.e. \*(L"250 \s-1OK\*(R"\s0 and some \*(L"defined\*(R" value to continue the client loop. +++If no value is set, the client will be disconnected after executing your command.+++ If you need \s-1MSTA\s0 or \s-1KTAG,\s0 this is the hook you need to implement them. .Sp The subroutine will be passed the command arguments, split on whitespace. .Sp .Vb 6 \& sub my_MSTA_sub { \& my( $id, $password ) = @_; \& # ... \& return "250 OK", 1; \& } \& $server\->custom_command( "MSTA", \e&my_MSTA_sub ); .Ve .IP "\fIdisable_command()\fR" 4 .IX Item "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. \f(CW$server\fR\->disable_command( \*(L"2WAY\*(R", \*(L"550 2WAY not supported here\*(R" ); .Sp The second argument is an optional custom error message. The default is: \*(L"500 Command Not Implemented, Try Again\*(R" .IP "\fIhandle_client()\fR" 4 .IX Item "handle_client()" Takes the result of \f(CW$server\fR\->\fIclient()\fR 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 \fInew()\fR, \s-1SIGARLM\s0 will be used to set a timeout. If you use this, make sure to take signals into account when writing your code. \fIfork()\fR'ing before calling handle_client is a good way to avoid interrupting code that shouldn't be interrupted. .IP "\fIforked_server()\fR" 4 .IX Item "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) = \f(CW$server\fR\->\fIforked_server()\fR; my \f(CW$line\fR = \f(CW$pipe\fR\->\fIgetline()\fR; chomp( \f(CW$line\fR ); my( \f(CW$pgr\fR, \f(CW$pgr\fR, \f(CW%pagedata\fR ) = split( /;/, \f(CW$line\fR ); .SH "AUTHOR" .IX Header "AUTHOR" Al Tobey .PP Some ideas from Sendpage::SNPPServer Kees Cook http://outflux.net/ .SH "TODO" .IX Header "TODO" Add more hooks for callbacks .PP Implement the following level 2 and level 3 commands .PP .Vb 7 \& 4.5.1 LOGIn [password] \& 4.5.3 LEVEl \& 4.5.5 COVErage \& 4.5.7 CALLerid \& 4.6.3 EXPTag \& 4.6.5 ACKRead <0|1> \& 4.6.6 RTYPe .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Net::Cmd Socket