~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/common_test/src/ct_telnet.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%%
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 2003-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 2003-2010. All Rights Reserved.
 
5
%%
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
11
 
%% 
 
11
%%
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
%%
19
19
 
21
21
%%%
22
22
%%% <p>Use this module to set up telnet connections, send commands and
23
23
%%% perform string matching on the result.
24
 
%%% (See the <code>unix_telnet</code> manual page for information 
25
 
%%% about how ct_telnet may be used specifically with unix hosts.)</p>
 
24
%%% See the <c>unix_telnet</c> manual page for information about how to use 
 
25
%%% ct_telnet, and configure connections, specifically for unix hosts.</p>
26
26
%%% <p>The following default values are defined in ct_telnet:</p>
27
27
%%% <pre>
28
28
%%% Connection timeout = 10 sec (time to wait for connection)
29
29
%%% Command timeout = 10 sec (time to wait for a command to return)
30
30
%%% Max no of reconnection attempts = 3
31
31
%%% Reconnection interval = 5 sek (time to wait in between reconnection attempts)
32
 
%%% </pre>
 
32
%%% Keep alive = true (will send NOP to the server every 10 sec if connection is idle)</pre>
33
33
%%% <p>These parameters can be altered by the user with the following
34
34
%%% configuration term:</p>
35
35
%%% <pre>
36
36
%%% {telnet_settings, [{connect_timeout,Millisec},
37
37
%%%                    {command_timeout,Millisec},
38
38
%%%                    {reconnection_attempts,N},
39
 
%%%                    {reconnection_interval,Millisec}]}.
40
 
%%% </pre>
 
39
%%%                    {reconnection_interval,Millisec},
 
40
%%%                    {keep_alive,Bool}]}.</pre>
41
41
%%% <p><code>Millisec = integer(), N = integer()</code></p>
42
42
%%% <p>Enter the <code>telnet_settings</code> term in a configuration 
43
43
%%% file included in the test and ct_telnet will retrieve the information
44
 
%%% automatically.</p>
 
44
%%% automatically. Note that <c>keep_alive</c> may be specified per connection if
 
45
%%% required. See <c>unix_telnet</c> for details.</p></doc>
45
46
 
46
47
%%% @type connection_type() = telnet | ts1 | ts2
47
48
 
88
89
               buffer=[],
89
90
               prompt=false,
90
91
               name,
91
 
               target_mod,extra,
 
92
               target_mod,
 
93
               keep_alive,
 
94
               extra,
92
95
               conn_to=?DEFAULT_TIMEOUT, 
93
96
               com_to=?DEFAULT_TIMEOUT, 
94
97
               reconns=?RECONNS,
150
153
%%% name can only be closed with the handle value.</p>
151
154
%%% 
152
155
%%% <p><code>TargetMod</code> is a module which exports the functions
153
 
%%% <code>connect(Ip,Port,Extra)</code> and <code>get_prompt_regexp()</code>
 
156
%%% <code>connect(Ip,Port,KeepAlive,Extra)</code> and <code>get_prompt_regexp()</code>
154
157
%%% for the given <code>TargetType</code> (e.g. <code>unix_telnet</code>).</p>
155
158
open(KeyOrName,ConnType,TargetMod,Extra) ->
156
159
    case ct:get_config({KeyOrName,ConnType}) of
169
172
                            P -> {IP,P}
170
173
                        end
171
174
                end,
 
175
            KeepAlive =
 
176
                case ct:get_config({KeyOrName,keep_alive}) of
 
177
                    undefined -> 
 
178
                        case ct:get_config({telnet_settings,keep_alive}) of
 
179
                            undefined -> true;
 
180
                            Bool -> Bool
 
181
                        end;
 
182
                    Bool -> Bool
 
183
                end,
172
184
            log(heading(open,{KeyOrName,ConnType}),"Opening connection to: ~p",[Addr1]),
173
185
            ct_gen_conn:start(KeyOrName,full_addr(Addr1,ConnType),
174
 
                              {TargetMod,Extra},?MODULE)
 
186
                              {TargetMod,KeepAlive,Extra},?MODULE)
175
187
    end.
176
188
 
177
189
%%%-----------------------------------------------------------------
373
385
%%%=================================================================
374
386
%%% Callback functions
375
387
%% @hidden
376
 
init(Name,{Ip,Port,Type},{TargetMod,Extra}) ->
 
388
init(Name,{Ip,Port,Type},{TargetMod,KeepAlive,Extra}) ->
377
389
    S0 = case ct:get_config(telnet_settings) of
378
390
             undefined ->
379
391
                 #state{};
380
392
             Settings ->
381
393
                 set_telnet_defaults(Settings,#state{})                             
382
394
         end,
383
 
    case catch TargetMod:connect(Ip,Port,S0#state.conn_to,Extra) of
 
395
    case catch TargetMod:connect(Ip,Port,S0#state.conn_to,KeepAlive,Extra) of
384
396
        {ok,TelnPid} ->
385
397
            log(heading(init,{Name,Type}), 
386
398
                "Opened telnet connection\n"
389
401
                "Command timeout: ~p\n"
390
402
                "Reconnection attempts: ~p\n"
391
403
                "Reconnection interval: ~p\n"
392
 
                "Connection timeout: ~p",
 
404
                "Connection timeout: ~p\n"
 
405
                "Keep alive: ~w",
393
406
                [Ip,Port,S0#state.com_to,S0#state.reconns,
394
 
                 S0#state.reconn_int,S0#state.conn_to]),
 
407
                 S0#state.reconn_int,S0#state.conn_to,KeepAlive]),
395
408
            {ok,TelnPid,S0#state{teln_pid=TelnPid,
396
409
                                 type=type(Type),
397
410
                                 name={Name,Type},
398
411
                                 target_mod=TargetMod,
 
412
                                 keep_alive=KeepAlive,
399
413
                                 extra=Extra,
400
414
                                 prx=TargetMod:get_prompt_regexp()}};
401
415
        {'EXIT',Reason} ->
415
429
    set_telnet_defaults(Ss,S#state{reconns=Rs});
416
430
set_telnet_defaults([{reconnection_interval,RInt}|Ss],S) ->
417
431
    set_telnet_defaults(Ss,S#state{reconn_int=RInt});
 
432
set_telnet_defaults([{keep_alive,_}|Ss],S) ->
 
433
    set_telnet_defaults(Ss,S);
 
434
set_telnet_defaults([Unknown|Ss],S) ->
 
435
    log(heading(set_telnet_defaults,{telnet_settings,Unknown}),
 
436
        "Bad element in telnet_settings: ~p",[Unknown]),
 
437
    set_telnet_defaults(Ss,S);
418
438
set_telnet_defaults([],S) ->
419
439
    S.
420
440
 
527
547
reconnect({Ip,Port,_Type},State) ->
528
548
    reconnect(Ip,Port,State#state.reconns,State).
529
549
reconnect(Ip,Port,N,State=#state{target_mod=TargetMod,
 
550
                                 keep_alive=KeepAlive,
530
551
                                 extra=Extra,
531
552
                                 conn_to=ConnTo,
532
553
                                 reconn_int=ReconnInt}) ->
533
 
    case TargetMod:connect(Ip,Port,ConnTo,Extra) of
 
554
    case TargetMod:connect(Ip,Port,ConnTo,KeepAlive,Extra) of
534
555
        {ok, NewPid} ->
535
556
            {ok, NewPid, State#state{teln_pid=NewPid}};
536
557
        Error when N==0 ->