/
ts_config_shell.erl
72 lines (62 loc) · 2.73 KB
/
ts_config_shell.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%%%
%%% Copyright 2010 © INRIA
%%%
%%% Author : Nicolas Niclausse <nniclaus@sophia.inria.fr>
%%% Created: 18 août 2010 by Nicolas Niclausse <nniclaus@sophia.inria.fr>
%%%
%%% This program is free software; you can redistribute it and/or modify
%%% it under the terms of the GNU General Public License as published by
%%% the Free Software Foundation; either version 2 of the License, or
%%% (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%%% GNU General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
%%%
%%% In addition, as a special exception, you have the permission to
%%% link the code of this program with any library released under
%%% the EPL license and distribute linked combinations including
%%% the two.
-module(ts_config_shell).
-vc('$Id$ ').
-author('nicolas.niclausse@sophia.inria.fr').
-export([parse_config/2]).
-include("ts_profile.hrl").
-include("ts_http.hrl").
-include("ts_config.hrl").
-include("xmerl.hrl").
-include("ts_shell.hrl").
%% @spec parse_config(#xmlElement{}, Config::term()) -> NewConfig::term()
%% @doc Parses a tsung.xml configuration file xml element for this
%% protocol and updates the Config term.
%% @end
parse_config(Element = #xmlElement{name=dyn_variable}, Conf = #config{}) ->
ts_config:parse(Element,Conf);
parse_config(Element = #xmlElement{name=shell},
Config=#config{curid = Id, session_tab = Tab,
sessions = [CurS | _], dynvar=DynVar,
subst = SubstFlag, match=MatchRegExp}) ->
Cmd = ts_config:getAttr(string,Element#xmlElement.attributes, cmd),
Args = ts_config:getAttr(string,Element#xmlElement.attributes, args, ""),
Request = #shell{command=Cmd,args=Args},
Msg= #ts_request{ack = parse,
endpage = true,
dynvar_specs = DynVar,
subst = SubstFlag,
match = MatchRegExp,
param = Request},
ts_config:mark_prev_req(Id-1, Tab, CurS),
ets:insert(Tab,{{CurS#session.id, Id},Msg}),
lists:foldl( fun(A,B)->ts_config:parse(A,B) end, Config#config{dynvar=[]},
Element#xmlElement.content);
%% Parsing other elements
parse_config(Element = #xmlElement{}, Conf = #config{}) ->
ts_config:parse(Element,Conf);
%% Parsing non #xmlElement elements
parse_config(_, Conf = #config{}) ->
Conf.