Skip to content
Browse files

Added support for jabber unsubscribe operation.

Changed jabber request to include subid (subscription id).
Changed DTD to accomodate the subid attribute.
Enabled variable substitution for unsubscribe requests.
  • Loading branch information...
1 parent 1dbc6b4 commit 6216a3867b00c9fa416275c249887ef813b7b5f4 alex committed with nniclausse
View
3 include/ts_jabber.hrl
@@ -50,7 +50,8 @@
group, %% roster group
node, %% pubsub node
resource,
- node_type
+ node_type,
+ subid
}).
-define(setroster_intensity, 1/(ts_utils:get_val(setroster)*1000)).
View
5 src/tsung/ts_jabber.erl
@@ -267,6 +267,11 @@ subst(Req=#jabber{type = Type}, DynData) when Type == 'muc:chat' ; Type == 'muc:
room = ts_search:subst(Req#jabber.room, DynData)};
subst(Req=#jabber{type = Type}, DynData) when Type == 'pubsub:create' ; Type == 'pubsub:subscribe'; Type == 'pubsub:publish'; Type == 'pubsub:delete' ->
Req#jabber{node = ts_search:subst(Req#jabber.node, DynData)};
+subst(Req=#jabber{type = Type}, DynData) when Type == 'pubsub:unsubscribe' ->
+ NewNode=ts_search:subst(Req#jabber.node,DynData),
+ NewSubId=ts_search:subst(Req#jabber.subid,DynData),
+ put(xmpp_user_id,{NewNode,NewSubId}),% we need to keep the substitution for futures requests
+ Req#jabber{node=NewNode,subid=NewSubId};
subst(Req=#jabber{id=user_defined, username=Name,passwd=Pwd, data=Data}, DynData) ->
NewUser = ts_search:subst(Name,DynData),
View
33 src/tsung/ts_jabber_common.erl
@@ -203,6 +203,20 @@ get_message(#jabber{type = 'pubsub:subscribe', id=Id, username=User,
UserFrom = username(User,Id),
subscribe_pubsub_node(Domain, PubSubComponent, UserFrom, UserTo, Node);
+%% For node unsubscribe, data contain the pubsub nodename (relative to user
+%% hierarchy or absolute)
+get_message(#jabber{type = 'pubsub:unsubscribe', id=Id, username=User, user_server=UserServer,
+ dest=random, node=Node, domain=Domain, pubsub_service=PubSubComponent, subid=SubId}) ->
+ Dest = ts_user_server:get_id(UserServer),
+ UserFrom = username(User,Id),
+ UserTo = username(User,id_to_string(Dest)),
+ unsubscribe_pubsub_node(Domain, PubSubComponent, UserFrom, UserTo, Node, SubId);
+
+get_message(#jabber{type = 'pubsub:unsubscribe', id=Id, username=User,
+ dest=UserTo, node=Node, domain=Domain, pubsub_service=PubSubComponent, subid=SubId}) ->
+ UserFrom = username(User,Id),
+ unsubscribe_pubsub_node(Domain, PubSubComponent, UserFrom, UserTo, Node, SubId);
+
%% For node publication, data contain the pubsub nodename (relative to user
%% hierarchy or absolute)
get_message(#jabber{type = 'pubsub:publish', size=Size, id=Id,
@@ -584,6 +598,25 @@ subscribe_pubsub_node(Domain, PubSubComponent, UserFrom, UserTo, Node) ->
"</pubsub></iq>"]).
%%%----------------------------------------------------------------------
+%%% Func: unsubscribe_pubsub_node/4
+%%% Unsubscribe from a pubsub node: Generate XML packet
+%%% If node name is undefined (data attribute), we unsubscribe from target user
+%%% root node
+%%% Nodenames are relative to the User pubsub hierarchy (ejabberd); they are
+%%% absolute with leading slash.
+%%%----------------------------------------------------------------------
+unsubscribe_pubsub_node(Domain, PubSubComponent, UserFrom, UserTo, Node, SubId) ->
+ list_to_binary(["<iq to='", PubSubComponent, "' type='set' id='", ts_msg_server:get_id(list),"'>"
+ "<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
+ "<unsubscribe",
+ pubsub_node_attr(Node, Domain, UserTo),
+ " jid='", UserFrom, "@", Domain, "'"
+ " subid='", SubId, "'"
+ "/>"
+ "</pubsub>"
+ "</iq>"]).
+
+%%%----------------------------------------------------------------------
%%% Func: publish_pubsub_node/4
%%% Publish an item to a pubsub node
%%% Nodenames are relative to the User pubsub hierarchy (ejabberd); they are
View
5 src/tsung_controller/ts_config_jabber.erl
@@ -91,6 +91,8 @@ parse_config(Element = #xmlElement{name=jabber},
%% Otherwise: (any other string)
%% The specified string
+ SubId = ts_config:getAttr(string, Element#xmlElement.attributes, 'subid', undefined),
+
Domain =ts_config:get_default(Tab, jabber_domain_name, jabber_domain),
MUC_service = ts_config:get_default(Tab, muc_service, muc_service),
PubSub_service =ts_config:get_default(Tab, pubsub_service, pubsub_service),
@@ -136,7 +138,8 @@ parse_config(Element = #xmlElement{name=jabber},
muc_service = MUC_service,
pubsub_service = PubSub_service,
node = Node,
- node_type = NodeType
+ node_type = NodeType,
+ subid = SubId
}
},
ts_config:mark_prev_req(Id-1, Tab, CurS),
View
3 tsung-1.0.dtd
@@ -223,7 +223,8 @@ repeat | if | change_type | foreach | set_option)*>
node CDATA #IMPLIED
regexp CDATA #IMPLIED
resource CDATA "tsung"
- node_type CDATA #IMPLIED >
+ node_type CDATA #IMPLIED
+ subid CDATA #IMPLIED >
<!ELEMENT xmpp_authenticate EMPTY >
<!ATTLIST xmpp_authenticate

0 comments on commit 6216a38

Please sign in to comment.
Something went wrong with that request. Please try again.