dejagnu
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

telnet.exp patch


From: Ben Elliston
Subject: telnet.exp patch
Date: 08 Feb 2004 02:21:20 +1100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

I would like to submit this patch for review.  Much of it is simple
comment and code cleanups, but I am particularly keen to know:

  * if there are any objections to me removing the code that prefers
    /usr/kerberos/bin/telnet over the telnet in the user's PATH?  I
    think that such behaviour is really unexpected.

  * I have removed telnet_transmit, as it simply wraps the proc
    `standard_transmit'.  My understanding is that call_remote will
    use standard_transmit if the communication layer does not provide
    a transmit method.  Right?

Thanks, Ben

Index: telnet.exp
===================================================================
RCS file: /cvsroot/dejagnu/dejagnu/lib/telnet.exp,v
retrieving revision 1.7
diff -u -p -r1.7 telnet.exp
--- telnet.exp  23 Aug 2003 05:55:08 -0000      1.7
+++ telnet.exp  7 Feb 2004 15:16:01 -0000
@@ -17,83 +17,68 @@
 # along with DejaGnu; if not, write to the Free Software Foundation,
 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+# Connect to HOST using Telnet.  The optional argument may be the
+# keyword "raw" which indicates that the remote server is a raw TCP
+# connection and not serving the Telnet protocol.
 #
-# Connect using telnet. This takes two arguments. The first one is the
-# hostname, and the second is the optional port number. This sets
-# the fileid field in the config array, and returns -1 for error, or the
-# spawn id.
+# Returns the spawn_id (and sets the fileid field in the config
+# array), or returns -1 in the case of error.
 #
 proc telnet_open { hostname args } {
-    global verbose
-    global connectmode
-    global spawn_id
-    global timeout
-    global board_info
-
-    set raw 0
-
-    if { [llength $args] > 0 } {
-       if { [lindex $args 0] == "raw" } {
-           set raw 1
-       }
-    }
+    set raw [expr [llength $args] > 0 && \
+                [string match [lindex $args 0] "raw"]]
 
-    set port 23
     if [board_info $hostname exists name] {
        set connhost [board_info $hostname name]
     } else {
        set connhost $hostname
     }
 
-    if [board_info $connhost exists hostname] {
-       set hostname [board_info $connhost hostname]
+    # Use the existing connection, if present.
+    if [board_info $connhost exists fileid] {
+       return [board_info $connhost fileid]
     }
 
-    if [file exists /usr/kerberos/bin/telnet] {
-       set telnet /usr/kerberos/bin/telnet
-    } else {
-       set telnet telnet
+    if [board_info $connhost exists hostname] {
+       set hostname [board_info $connhost hostname]
     }
 
-    # Instead of unsetting it, let's return it. One connection at a
-    # time, please.
-    if [board_info $connhost exists fileid] {
-       return [board_info $connhost fileid]
-    }
-    # get the hostname and port number from the config array
+    # Get the host name and port number from the config array.
+    set port 23
     if [board_info $connhost exists netport] {
        set type $hostname
-       set hosttmp [split [board_info $connhost netport] ":"]
-       set hostname [lindex $hosttmp 0]
-       if { [llength $hosttmp] > 1 } {
-           set port [lindex $hosttmp 1]
+       set addrpair [split [board_info $connhost netport] ":"]
+       set hostname [lindex $addrpair 0]
+       if { [llength $addrpair] > 1 } {
+           set port [lindex $addrpair 1]
        }
-       unset hosttmp
+       unset addrpair
     } else {
        set type target
     }
     if [board_info $connhost exists shell_prompt] {
         set shell_prompt [board_info $connhost shell_prompt]
-    }
-    if ![info exists shell_prompt] {   # if no prompt, then set it to 
something generic
+    } else {
        set shell_prompt ".*> "
     }
 
     set tries 0
     set result -1
     set need_respawn 1
-    verbose "Starting a telnet connection to $hostname:$port $shell_prompt" 2
+
+    verbose "telnet: starting a telnet connection to $hostname:$port" 2
+
     while { $result < 0 && $tries <= 3 } {
        if { $need_respawn } {
            set need_respawn 0
-           spawn $telnet $hostname $port
+           spawn telnet $hostname $port
        }
        expect {
            "Trying " {
                exp_continue
            }
            -re "$shell_prompt.*$" {
-               verbose "Got prompt\n"
+               verbose "telnet: got prompt\n"
                set result 0
            }
            -re "nt Name:|ogin:" {
@@ -187,27 +172,29 @@ proc telnet_open { hostname args } {
        }
        incr tries
     }
-    # we look for this here again cause it means something went wrong, and
-    # it doesn't always show up in the expect in buffer till the server times 
out.
+
+    # We look for this here again cause it means something went wrong,
+    # and it doesn't always show up in the expect in buffer until the
+    # server times out.
     if [info exists expect_out(buffer)] {
        if [regexp "assword:|ogin:" $expect_out(buffer)] {
-           perror "telnet: need to supply a login and password."
+           perror "telnet: need to supply a login and password"
        }
     }
+
     if { $result < 0 } {
        catch close
        catch wait
        set spawn_id -1
     }
     if { $spawn_id >= 0 } {
-       verbose "setting board_info($connhost,fileid) to $spawn_id" 3
+       verbose "telnet: setting board_info($connhost,fileid) to $spawn_id" 3
        set board_info($connhost,fileid) $spawn_id
     }
     return $spawn_id
 }
 
-#
-# Put the telnet connection into binary mode.
+# Put the Telnet connection into binary mode.
 #
 proc telnet_binary { hostname } {
     if [board_info $hostname exists fileid] {
@@ -232,12 +219,8 @@ proc telnet_binary { hostname } {
            }
            -re "Already operating in binary.*\[\r\n\].*$" { }
            timeout {
-               warning "Never got binary response from telnet."
+               warning "telnet: never got response to binary command"
            }
        }
     }
-}
-
-proc telnet_transmit { dest file args } {
-    return [standard_transmit $dest $file]
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]