~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%%<copyright>
2
 
%% <year>2003-2007</year>
 
2
%% <year>2003-2008</year>
3
3
%% <holder>Ericsson AB, All Rights Reserved</holder>
4
4
%%</copyright>
5
5
%%<legalnotice>
24
24
%%% perform string matching on the result.
25
25
%%% (See the <code>unix_telnet</code> manual page for information 
26
26
%%% about how ct_telnet may be used specifically with unix hosts.)</p>
27
 
%%% <p>The rx driver used by ct_telnet for handling regular expressions is
28
 
%%% currently only ported to Unix and Linux and will not work on Windows!</p>
29
27
%%% <p>The following default values are defined in ct_telnet:</p>
30
28
%%% <pre>
31
29
%%% Connection timeout = 10 sec (time to wait for connection)
56
54
 
57
55
%%% @type prompt_regexp() = string(). A regular expression which
58
56
%%% matches all possible prompts for a specific type of target. The
59
 
%%% regexp must not have any groups i.e. when matching, rx:match shall
 
57
%%% regexp must not have any groups i.e. when matching, re:run/3 shall
60
58
%%% return a list with one single element.
61
59
%%%
62
60
%%% @see unix_telnet
368
366
             Settings ->
369
367
                 set_telnet_defaults(Settings,#state{})                             
370
368
         end,
371
 
    case TargetMod:connect(Ip,Port,S0#state.conn_to,Extra) of
 
369
    case catch TargetMod:connect(Ip,Port,S0#state.conn_to,Extra) of
372
370
        {ok,TelnPid} ->
373
371
            log(heading(init,{Name,Type}), 
374
372
                "Opened telnet connection\n"
386
384
                                 target_mod=TargetMod,
387
385
                                 extra=Extra,
388
386
                                 prx=TargetMod:get_prompt_regexp()}};
 
387
        {'EXIT',Reason} ->
 
388
            {error,Reason};
389
389
        Error ->
390
390
            Error
391
391
    end.
1008
1008
  when PromptType=/=FoundPrompt ->
1009
1009
    match_line(Line,Patterns,FoundPrompt,EO,RetTag);
1010
1010
match_line(Line,[{Tag,Pattern}|Patterns],FoundPrompt,EO,RetTag) ->
1011
 
    case rx:match(Line,Pattern) of
 
1011
    case re:run(Line,Pattern,[{capture,all,list}]) of
1012
1012
        nomatch ->
1013
1013
            match_line(Line,Patterns,FoundPrompt,EO,RetTag);
1014
 
        Match ->
 
1014
        {match,Match} ->
1015
1015
            try_cont_log("<b>MATCH:</b> ~s", [Line]),
1016
1016
            {RetTag,{Tag,Match}}
1017
1017
    end;
1018
1018
match_line(Line,[Pattern|Patterns],FoundPrompt,EO,RetTag) ->
1019
 
    case rx:match(Line,Pattern) of
 
1019
    case re:run(Line,Pattern,[{capture,all,list}]) of
1020
1020
        nomatch ->
1021
1021
            match_line(Line,Patterns,FoundPrompt,EO,RetTag);
1022
 
        Match ->
 
1022
        {match,Match} ->
1023
1023
            try_cont_log("<b>MATCH:</b> ~s", [Line]),
1024
1024
            {RetTag,Match}
1025
1025
    end;
1120
1120
match_prompt(Str,Prx) ->
1121
1121
    match_prompt(Str,Prx,[]).
1122
1122
match_prompt(Str,Prx,Acc) ->
1123
 
    case rx:match_pos(Str,Prx) of
 
1123
    case re:run(Str,Prx) of
1124
1124
        nomatch ->
1125
1125
            noprompt;
1126
 
        [{Start,End}] ->
1127
 
            case split_prompt_string(Str,Start,End,1,[],[]) of
 
1126
        {match,[{Start,Len}]} ->
 
1127
            case split_prompt_string(Str,Start+1,Start+Len,1,[],[]) of
1128
1128
                {noprompt,Done,Rest} ->
1129
1129
                    match_prompt(Rest,Prx,Done);
1130
1130
                {prompt,UptoPrompt,Prompt,Rest} ->