Browse files

optional attribute to the search operation: result_var (Pablo Polvori…

…n TSUN-56)

SVN Revision: 882
  • Loading branch information...
1 parent 7a1d0a6 commit c0406f19a7bb75d3f6d526b411d3e58dbc621a3e @nniclausse nniclausse committed Aug 29, 2008
Showing with 34 additions and 7 deletions.
  1. +1 −0 include/ts_ldap.hrl
  2. +24 −5 src/tsung/ts_ldap.erl
  3. +6 −0 src/tsung_controller/ts_config_ldap.erl
  4. +3 −2 tsung-1.0.dtd
View
1 include/ts_ldap.hrl
@@ -28,6 +28,7 @@
password,
base,
filter,
+ result_var,
attributes,
scope,
cacertfile,
View
29 src/tsung/ts_ldap.erl
@@ -117,21 +117,24 @@ parse_ldap_response( #'LDAPMessage'{protocolOp = {bindResponse,Result}},State)->
case Result#'BindResponse'.resultCode of
success ->
?Debug("Bind successful~n"),
+ ts_mon:add({ count, ldap_bind_ok}),
{State#state_rcv{ack_done=true},[],false};
_Error ->
ts_mon:add({ count, ldap_bind_error}), %FIXME: retry,fail,etc. should be configurable
?LOG("Bind fail~n",?INFO),
{State#state_rcv{ack_done=true},[],true}
end;
-parse_ldap_response( #'LDAPMessage'{protocolOp = {'searchResDone',R}},State) ->
- ?DebugF("LDAP Search response Done ~p~n",[R]),
+parse_ldap_response( #'LDAPMessage'{protocolOp = {'searchResDone',_R}},State) ->
+ ?DebugF("LDAP Search response Done ~p~n",[_R]),
{State#state_rcv{ack_done=true},[],false}; %%Response done, mark as acknowledged
parse_ldap_response( #'LDAPMessage'{protocolOp = {'searchResEntry',R}},State) ->
+ NewState = acumulate_result(R,State),
+
?DebugF("LDAP search response Entry ~p~n",[R]),
- {State#state_rcv{ack_done=false},[],false};
-parse_ldap_response(#'LDAPMessage'{protocolOp = {'searchResRef',R}},State) ->
- ?DebugF("LDAP search response Ref ~p~n",[R]),
+ {NewState#state_rcv{ack_done=false},[],false};
+parse_ldap_response(#'LDAPMessage'{protocolOp = {'searchResRef',_R}},State) ->
+ ?DebugF("LDAP search response Ref ~p~n",[_R]),
{State#state_rcv{ack_done=false},[],false};
@@ -178,6 +181,22 @@ parse_ldap_response(Resp,State) ->
ts_mon:add({ count, ldap_unexpected_msg_resp}),
{State#state_rcv{ack_done=true},[],false}.
+acumulate_result(R,State = #state_rcv{request =
+ #ts_request{param=#ldap_request{result_var = ResultVar}},
+ dyndata=DynData}) ->
+ case ResultVar of
+ none -> State;
+ {ok,VarName} -> State#state_rcv{dyndata=accumulate_dyndata(R,VarName,DynData)}
+ end.
+
+accumulate_dyndata(R,VarName,DynData = #dyndata{dynvars=DynVars}) when is_list(DynVars)->
+ Prev = proplists:get_value(VarName,DynVars,[]),
+ NewDynVars = lists:keystore(VarName,1,DynVars,{VarName,[R|Prev]}),
+ DynData#dyndata{dynvars=NewDynVars};
+
+accumulate_dyndata(R,VarName,DynData) ->
+ DynData#dyndata{dynvars=[{VarName,[R]}]}.
+
%%----------------------------------------------------------------------
%% Function: add_dynparams/4
View
6 src/tsung_controller/ts_config_ldap.erl
@@ -76,6 +76,11 @@ parse_config(Element = #xmlElement{name=ldap},
Base = ts_config:getAttr(string,Element#xmlElement.attributes,base),
Scope = ts_config:getAttr(atom,Element#xmlElement.attributes,scope),
Filter = ts_config:getAttr(string,Element#xmlElement.attributes,filter),
+ ResultVar = case ts_config:getAttr(string,Element#xmlElement.attributes,result_var,none) of
+ none -> none;
+ VarName -> {ok,list_to_atom(VarName)}
+ end,
+
Attributes=[],
{ParsedFilter,[]} = rfc4515_parser:filter(rfc4515_parser:tokenize(Filter)),
#ts_request{ack = parse,
@@ -84,6 +89,7 @@ parse_config(Element = #xmlElement{name=ldap},
subst = SubstFlag,
match = MatchRegExp,
param = #ldap_request{type=search,
+ result_var = ResultVar,
base=Base,
scope=Scope,
filter=ParsedFilter,
View
5 tsung-1.0.dtd
@@ -181,10 +181,11 @@ repeat)*>
<!ATTLIST ldap
password CDATA #IMPLIED
user CDATA #IMPLIED
- type (bind | unbind | search | start_tls | add | modify ) #REQUIRED
+ type (bind | unbind | search | start_tls | add | modify ) #REQUIRED
+ result_var CDATA #IMPLIED
filter CDATA #IMPLIED
base CDATA #IMPLIED
- scope (singleLevel | baseObject | wholeSubtree) #IMPLIED
+ scope (singleLevel | baseObject | wholeSubtree) #IMPLIED
cacertfile CDATA #IMPLIED
keyfile CDATA #IMPLIED
certfile CDATA #IMPLIED

0 comments on commit c0406f1

Please sign in to comment.