~ubuntu-branches/ubuntu/trusty/dejagnu/trusty

« back to all changes in this revision

Viewing changes to lib/telnet.exp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2006-12-11 09:06:59 UTC
  • mfrom: (2.1.6 edgy)
  • Revision ID: james.westby@ubuntu.com-20061211090659-w586kgi3giz84053
Tags: 1.4.4.cvs20060709-3
* Acknowledge previous NMUs.
* Fix permissions on /usr/share/dejagnu when building without fakeroot
  (Closes: #392589, #379809).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2
 
# 2001, 2002, 2003 Free Software Foundation, Inc.
 
2
# 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
3
3
#
4
4
# This file is part of DejaGnu.
5
5
#
15
15
#
16
16
# You should have received a copy of the GNU General Public License
17
17
# along with DejaGnu; if not, write to the Free Software Foundation,
18
 
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 
 
20
 
#
21
 
# Connect using telnet. This takes two arguments. The first one is the
22
 
# hostname, and the second is the optional port number. This sets
23
 
# the fileid field in the config array, and returns -1 for error, or the
24
 
# spawn id.
 
18
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 
19
 
 
20
 
 
21
# Connect to HOSTNAME using Telnet.  ARGS is a list of options.
 
22
# Currently the only supported option is "raw".  Sets the fileid field
 
23
# in the config array and returns -1 for error or the spawn id.
25
24
#
26
25
proc telnet_open { hostname args } {
27
26
    global verbose
31
30
    global board_info
32
31
 
33
32
    set raw 0
34
 
 
35
 
    if { [llength $args] > 0 } {
36
 
        if { [lindex $args 0] == "raw" } {
37
 
            set raw 1
 
33
    foreach arg $args {
 
34
        switch $arg {
 
35
            "raw" { set raw 1 }
38
36
        }
39
37
    }
40
38
 
41
39
    set port 23
42
 
    if [board_info $hostname exists name] {
 
40
    if {[board_info $hostname exists name]} {
43
41
        set connhost [board_info $hostname name]
44
42
    } else {
45
43
        set connhost $hostname
46
44
    }
47
45
 
48
 
    if [board_info $connhost exists hostname] {
 
46
    if {[board_info $connhost exists hostname]} {
49
47
        set hostname [board_info $connhost hostname]
50
48
    }
51
49
 
52
 
    if [file exists /usr/kerberos/bin/telnet] {
 
50
    if {[file exists /usr/kerberos/bin/telnet]} {
53
51
        set telnet /usr/kerberos/bin/telnet
54
52
    } else {
55
53
        set telnet telnet
57
55
 
58
56
    # Instead of unsetting it, let's return it. One connection at a
59
57
    # time, please.
60
 
    if [board_info $connhost exists fileid] {
 
58
    if {[board_info $connhost exists fileid]} {
61
59
        return [board_info $connhost fileid]
62
60
    }
63
 
    # get the hostname and port number from the config array
64
 
    if [board_info $connhost exists netport] {
 
61
 
 
62
    # Get the hostname and port number from the config array.
 
63
    if {[board_info $connhost exists netport]} {
65
64
        set type $hostname
66
65
        set hosttmp [split [board_info $connhost netport] ":"]
67
66
        set hostname [lindex $hosttmp 0]
72
71
    } else {
73
72
        set type target
74
73
    }
75
 
    if [board_info $connhost exists shell_prompt] {
 
74
 
 
75
    if {[board_info $connhost exists shell_prompt]} {
76
76
        set shell_prompt [board_info $connhost shell_prompt]
77
77
    }
78
 
    if ![info exists shell_prompt] {    # if no prompt, then set it to something generic
 
78
    if {![info exists shell_prompt]} {
 
79
        # If no prompt, then set it to something generic.
79
80
        set shell_prompt ".*> "
80
81
    }
81
82
 
97
98
                set result 0
98
99
            }
99
100
            -re "nt Name:|ogin:" {
100
 
                if [board_info $connhost exists telnet_username] {
 
101
                if {[board_info $connhost exists telnet_username]} {
101
102
                    exp_send "[board_info $connhost telnet_username]\n"
102
103
                    exp_continue
103
104
                }
104
 
                if [board_info $connhost exists username] {
 
105
                if {[board_info $connhost exists username]} {
105
106
                    exp_send "[board_info $connhost username]\n"
106
107
                    exp_continue
107
108
                }
109
110
                break
110
111
            }
111
112
            "assword:" {
112
 
                if [board_info $connhost exists telnet_password] {
 
113
                if {[board_info $connhost exists telnet_password]} {
113
114
                    exp_send "[board_info $connhost telnet_password]\n"
114
115
                    exp_continue
115
116
                }
116
 
                if [board_info $connhost exists password] {
 
117
                if {[board_info $connhost exists password]} {
117
118
                    exp_send "[board_info $connhost password]\n"
118
119
                    exp_continue
119
120
                }
145
146
                if { $raw || [board_info $connhost exists dont_wait_for_prompt] } {
146
147
                    set result 0
147
148
                } else {
148
 
                    if [board_info $connhost exists send_initial_cr] {
 
149
                    if {[board_info $connhost exists send_initial_cr]} {
149
150
                        exp_send "\n"
150
151
                    }
151
152
                    exp_continue
187
188
        }
188
189
        incr tries
189
190
    }
190
 
    # we look for this here again cause it means something went wrong, and
191
 
    # it doesn't always show up in the expect in buffer till the server times out.
192
 
    if [info exists expect_out(buffer)] {
193
 
        if [regexp "assword:|ogin:" $expect_out(buffer)] {
 
191
 
 
192
    # We look for this here again cause it means something went wrong,
 
193
    # and it doesn't always show up in the expect in buffer till the
 
194
    # server times out.
 
195
    if {[info exists expect_out(buffer)]} {
 
196
        if {[regexp "assword:|ogin:" $expect_out(buffer)]} {
194
197
            perror "telnet: need to supply a login and password."
195
198
        }
196
199
    }
203
206
        verbose "setting board_info($connhost,fileid) to $spawn_id" 3
204
207
        set board_info($connhost,fileid) $spawn_id
205
208
    }
 
209
 
206
210
    return $spawn_id
207
211
}
208
212
 
209
 
#
210
 
# Put the telnet connection into binary mode.
 
213
# Put the Telnet connection to HOSTNAME into binary mode.
211
214
#
212
215
proc telnet_binary { hostname } {
213
 
    if [board_info $hostname exists fileid] {
 
216
    if {[board_info $hostname exists fileid]} {
214
217
        remote_send $hostname ""
215
218
        remote_expect $hostname 5 {
216
219
            -re "telnet> *$" {}
237
240
        }
238
241
    }
239
242
}
240
 
 
241
 
proc telnet_transmit { dest file args } {
242
 
    return [standard_transmit $dest $file]
243
 
}