PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|JUNOS|Access.pm =

page 4 of 6



    } 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=

1|2|3| < PREV = PAGE 4 = NEXT > |5|6

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00583506 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)