.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .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" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Net::SNPP::Server 3pm" .TH Net::SNPP::Server 3pm "2008-02-04" "perl v5.8.8" "User Contributed Perl Documentation" .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 )" $PAGER_ID = [ 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\s0, \s-1PIN\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\s0\*(R" 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