} else {
# Close off the slave side of pty/tty pair
close($slave);
# Record the pty side for later i/o
$self->{INPUT} = $pty;
$self->{OUTPUT} = $pty;
}
# Record the pid of the process we just made
$self->{PID} = $pid;
# If something bad happens kill this process off...
$SIG{INT} = $SIG{__DIE__} = $SIG{HUP} = $SIG{TERM} =
sub { kill 9, $pid; exit };
1;
}
sub incoming
{
my($self) = @_;
$self->{JUNOS_Device}->report_error("Unhandled incoming data");
return;
}
#
# Implemented by subclass if necessary (xnm_auth stuff for instance)
#
sub authenticate {
1;
}
1;
__END__
=head1 NAME
JUNOS::Access - Implement the Access Method superclass. All Access Method
classes must subclass from JUNOS::Access.
=head1 SYNOPSIS
This example is extracted from Device.pm. It creates an Access object
based on the access method type specified in $self (a reference to
a hash table containing information such as login, password, access
method type and destination hostname). Then it starts a session with
the JUNOScript server at the destination host by calling the connect
method in the access object. After the session is established, it
goes on to perform the initial handshake with the JUNOScript server.
my $conn = new JUNOS::Access($self);
# Need better error handling here....
ref($conn) || die "Could not open connection";
# Record the connection; connect it, mark it
$self->{JUNOS_Conn} = $conn;
$conn->connect() || die "Could not connect";
$self->{JUNOS_Connected} = 1;
# Kick off the XML parser
$self->parse_start();
trace("Trace", "starting connect::\n");
# We need to receive the server side of the initial handshake first
# (at least the <?xml?> part), so that we can avoid sending our
# handshake to the ssh processes initial prompts (password/etc).
# So we wait til we see the start of the real XML data flow....
until ($self->{JUNOS_Active}) {
my $in = $conn->recv();
my $waiting = 'waiting for xml';
if( $conn->{seen_xml} ) { $waiting = 'found xml'; }
trace("IO", "during connect - ($waiting) input:\n\t$in\n" );
if ($conn->{seen_xml}) {
# After we've seen xml, parse anything
} elsif ($in =~ /<\s*\?/) {
$in =~ s/^[\d\D]*(<\s*\?)/$1/;
$conn->{seen_xml} = 1;
} else {
if (not $conn->incoming($in) or $conn->eof) {
$self->disconnect;
return undef;
}
next;
}
if ($conn->eof) {
$self->parse_done($in);
last;
} else {
$self->parse_more($in);
}
}
=4= |