Skip to content

Commit

Permalink
add resource attribute for XMPP (TSUN-174).
Browse files Browse the repository at this point in the history
  • Loading branch information
nniclausse committed Jan 9, 2012
1 parent 4d370ef commit a0905a1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
7 changes: 5 additions & 2 deletions doc/user_manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<!--CUT DEF section 1 --><H1 ALIGN=center>Tsung User’s manual</H1><DIV CLASS="center">

<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1><TR><TD ALIGN=left NOWRAP bgcolor="#F2F2F2"> Version:</TD><TD ALIGN=left NOWRAP>1.4.2</TD></TR>
<TR><TD ALIGN=left NOWRAP bgcolor="#F2F2F2"> Date :</TD><TD ALIGN=left NOWRAP>January 4, 2012</TD></TR>
<TR><TD ALIGN=left NOWRAP bgcolor="#F2F2F2"> Date :</TD><TD ALIGN=left NOWRAP>January 9, 2012</TD></TR>
</TABLE>
</DIV><!--TOC section Contents-->
<H2 CLASS="section"><!--SEC ANCHOR -->Contents</H2><!--SEC END --><UL CLASS="toc"><LI CLASS="li-toc">
Expand Down Expand Up @@ -1994,7 +1994,10 @@ <H5 CLASS="paragraph"><!--SEC ANCHOR -->raw XML</H5><!--SEC END --><P>
</TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE><P>Beware: you must encode XML characters like <FONT COLOR=purple>&lt;</FONT>
,<FONT COLOR=purple>&gt;</FONT>, <FONT COLOR=purple>&amp;</FONT>, etc.</P><!--TOC subsubsection PostgreSQL-->
,<FONT COLOR=purple>&gt;</FONT>, <FONT COLOR=purple>&amp;</FONT>, etc.</P><!--TOC paragraph resource-->
<H5 CLASS="paragraph"><!--SEC ANCHOR -->resource</H5><!--SEC END --><P>By default, the XMPP resource is set to <FONT COLOR=purple>tsung</FONT>. Since
version 1.4.3, you can override this (in all <TT>auth_*</TT> and
<TT>register</TT> requests) using the <TT>resource</TT> attribute.</P><!--TOC subsubsection PostgreSQL-->
<H4 CLASS="subsubsection"><!--SEC ANCHOR --><A NAME="htoc59">6.6.4</A>  PostgreSQL</H4><!--SEC END --><P>For PostgreSQL, 4 types of requests are available:
</P><OL CLASS="enumerate" type=1><LI CLASS="li-enumerate">
connect (to a given database with a given username
Expand Down
6 changes: 6 additions & 0 deletions doc/user_manual.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,12 @@ \subsubsection{Jabber/XMPP}
Beware: you must encode XML characters like \userinput{<}
,\userinput{>}, \userinput{\&}, etc.
\paragraph{resource}
By default, the XMPP resource is set to \userinput{tsung}. Since
version 1.4.3, you can override this (in all \varname{auth\_*} and
\varname{register} requests) using the \varname{resource} attribute.
\subsubsection{PostgreSQL}
For PostgreSQL, 4 types of requests are available:
Expand Down
1 change: 1 addition & 0 deletions include/ts_jabber.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
pubsub_service, %%ej: pubsub.localhost
group, %% roster group
node, %% pubsub node
resource,
node_type
}).

Expand Down
38 changes: 20 additions & 18 deletions src/tsung/ts_jabber_common.erl
Original file line number Diff line number Diff line change
Expand Up @@ -296,62 +296,62 @@ auth_get(Username, _Passwd, Type) ->
%%----------------------------------------------------------------------
%% Func: auth_set_plain/1
%%----------------------------------------------------------------------
auth_set_plain(#jabber{username=Name,passwd=Passwd})->
auth_set_plain(Name, Passwd, "auth").
auth_set_plain(#jabber{username=Name,passwd=Passwd,resource=Resource})->
auth_set_plain(Name, Passwd, "auth", Resource).


%%----------------------------------------------------------------------
%% Func: auth_set_plain/3
%%----------------------------------------------------------------------
auth_set_plain(Username, Passwd, Type) ->
auth_set_plain(Username, Passwd, Type, Resource) ->
list_to_binary([
"<iq id='", ts_msg_server:get_id(list),
"' type='set' >",
"<query xmlns='jabber:iq:", Type, "'>",
"<username>", Username, "</username>",
"<resource>tsung</resource>",
"<resource>", Resource,"</resource>",
"<password>", Passwd, "</password></query></iq>"]).


%%----------------------------------------------------------------------
%% Func: auth_set_digest/2
%%----------------------------------------------------------------------
auth_set_digest(#jabber{username=Name,passwd=Passwd}, Sid)->
auth_set_digest(Name, Passwd, "auth", Sid).
auth_set_digest(#jabber{username=Name,passwd=Passwd, resource=Resource}, Sid)->
auth_set_digest(Name, Passwd, "auth", Sid, Resource).


%%----------------------------------------------------------------------
%% Func: auth_set_digest/4
%%----------------------------------------------------------------------
auth_set_digest(Username, Passwd, Type, Sid) ->
auth_set_digest(Username, Passwd, Type, Sid, Resource) ->
{Digest} = ts_digest:digest(Sid, Passwd),
list_to_binary([
"<iq id='", ts_msg_server:get_id(list),
"' type='set' >",
"<query xmlns='jabber:iq:", Type, "'>",
"<username>", Username, "</username>",
"<resource>tsung</resource>",
"<resource>",Resource,"</resource>",
"<digest>", Digest, "</digest></query></iq>"]).


%%----------------------------------------------------------------------
%% Func: auth_set_sip/3
%%----------------------------------------------------------------------
auth_set_sip(#jabber{username=Name,passwd=Passwd,domain=Domain}, Nonce, Realm)->
auth_set_sip(Name, Passwd, Domain, "auth", Nonce, Realm).
auth_set_sip(#jabber{username=Name,passwd=Passwd,domain=Domain,resource=Resource}, Nonce, Realm)->
auth_set_sip(Name, Passwd, Domain, "auth", Nonce, Realm,Resource).

%%----------------------------------------------------------------------
%% Func: auth_set_sip/6
%%----------------------------------------------------------------------
auth_set_sip(Username, Passwd, Domain, Type, Nonce, Realm) ->
auth_set_sip(Username, Passwd, Domain, Type, Nonce, Realm,Resource) ->
Jid = Username ++ "@" ++ Realm,
{SipDigest,Integrity} = ts_digest:sip_digest(Nonce, Jid, Realm, Passwd),
list_to_binary([
"<iq id='", ts_msg_server:get_id(list),
"' type='set' >",
"<query xmlns='jabber:iq:", Type, "'>",
"<username>", Jid, "</username>",
"<resource>tsung</resource>",
"<resource>",Resource,"</resource>",
"<x xmlns='xmpp:assert' version='1.0'>",
"<ContextInfo><ServiceValue><Realm>", Domain,
"</Realm></ServiceValue></ContextInfo>",
Expand Down Expand Up @@ -387,16 +387,18 @@ auth_sasl(Username, Passwd, Mechanism) ->
%%----------------------------------------------------------------------
%% Func: auth_sasl_bind/1
%%----------------------------------------------------------------------
auth_sasl_bind(#jabber{username=Name,passwd=Passwd,domain=Domain})->
auth_sasl_bind(Name, Passwd, Domain).
auth_sasl_bind(#jabber{username=Name,passwd=Passwd,domain=Domain, resource=Resource})->
auth_sasl_bind(Name, Passwd, Domain, Resource).


%%----------------------------------------------------------------------
%% Func: auth_sasl_bind/3
%%----------------------------------------------------------------------
auth_sasl_bind(_Username, _Passwd, _Domain) ->
auth_sasl_bind(_Username, _Passwd, _Domain, Resource) ->
list_to_binary(["<iq type='set' id='",ts_msg_server:get_id(list),
"' ><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>tsung</resource></bind></iq>"]).
"' ><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>",
"<resource>",Resource,"</resource>",
"</bind></iq>"]).


%%----------------------------------------------------------------------
Expand All @@ -417,8 +419,8 @@ auth_sasl_session(_Username, _Passwd, _Domain) ->
%% Func: registration/1
%% Purpose: register message
%%----------------------------------------------------------------------
registration(#jabber{username=Name,passwd=Passwd})->
auth_set_plain(Name, Passwd, "register").
registration(#jabber{username=Name,passwd=Passwd,resource=Resource})->
auth_set_plain(Name, Passwd, "register",Resource).

%%----------------------------------------------------------------------
%% Func: message/3
Expand Down
2 changes: 2 additions & 0 deletions src/tsung_controller/ts_config_jabber.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ parse_config(Element = #xmlElement{name=jabber},
Data= ts_config:getAttr(string,Element#xmlElement.attributes, data,undefined),
Show= ts_config:getAttr(string,Element#xmlElement.attributes, show, "chat"),
Status= ts_config:getAttr(string,Element#xmlElement.attributes, status, "Available"),
Resource= ts_config:getAttr(string,Element#xmlElement.attributes, resource, "tsung"),
Type= list_to_atom(TypeStr),
Room = ts_config:getAttr(string,Element#xmlElement.attributes, room, undefined),
Nick = ts_config:getAttr(string,Element#xmlElement.attributes, nick, undefined),
Expand Down Expand Up @@ -128,6 +129,7 @@ parse_config(Element = #xmlElement{name=jabber},
size = Size,
show = Show,
status = Status,
resource = Resource,
room = Room,
nick = Nick,
group = Group,
Expand Down
3 changes: 2 additions & 1 deletion tsung-1.0.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ repeat | if | change_type | foreach | set_option)*>
room CDATA #IMPLIED
group CDATA #IMPLIED
node CDATA #IMPLIED
regexp CDATA #IMPLIED
regexp CDATA #IMPLIED
resource CDATA "tsung"
node_type CDATA #IMPLIED >

<!ELEMENT xmpp_authenticate EMPTY >
Expand Down

0 comments on commit a0905a1

Please sign in to comment.