aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2008-02-06 20:30:58 +0000
committerBadlop <badlop@process-one.net>2008-02-06 20:30:58 +0000
commit0beb1c8116a6f396a63d797a3da80c7f9a6920d6 (patch)
tree00ad8a96b4852ddf92620a590f46d8cba46b8707 /src
parent* src/mod_pubsub/node_buddy.erl: Fixed typo (diff)
* src/mod_muc/mod_muc_room.erl: Support for decline of invitation
to MUC room (EJAB-515) SVN Revision: 1175
Diffstat (limited to 'src')
-rw-r--r--src/mod_muc/mod_muc_room.erl53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl
index 90c70780a..4837afc11 100644
--- a/src/mod_muc/mod_muc_room.erl
+++ b/src/mod_muc/mod_muc_room.erl
@@ -368,10 +368,7 @@ normal_state({route, From, "",
"error" ->
ok;
_ ->
- ErrText = "Only occupants are allowed to send messages to the conference",
- Err = jlib:make_error_reply(
- Packet, ?ERRT_NOT_ACCEPTABLE(Lang, ErrText)),
- ejabberd_router:route(StateData#state.jid, From, Err)
+ handle_roommessage_from_nonparticipant(Packet, Lang, StateData, From)
end,
{next_state, normal_state, StateData}
end;
@@ -3101,6 +3098,54 @@ check_invitation(From, Els, Lang, StateData) ->
JID
end.
+%% Handle a message sent to the room by a non-participant.
+%% If it is a decline, send to the inviter.
+%% Otherwise, an error message is sent to the sender.
+handle_roommessage_from_nonparticipant(Packet, Lang, StateData, From) ->
+ case catch check_decline_invitation(Packet) of
+ {true, Decline_data} ->
+ send_decline_invitation(Decline_data, StateData#state.jid);
+ _ ->
+ send_error_only_occupants(Packet, Lang, StateData#state.jid, From)
+ end.
+
+%% Check in the packet is a decline.
+%% If so, also returns the splitted packet.
+%% This function must be catched,
+%% because it crashes when the packet is not a decline message.
+check_decline_invitation(Packet) ->
+ {xmlelement, "message", PAttrs, _} = Packet,
+ XEl = xml:get_subtag(Packet, "x"),
+ ?NS_MUC_USER = xml:get_tag_attr_s("xmlns", XEl),
+ DEl = xml:get_subtag(XEl, "decline"),
+ {value, FromString} = xml:get_attr("from", PAttrs),
+ ToString = xml:get_tag_attr_s("to", DEl),
+ ToJID = jlib:string_to_jid(ToString),
+ {true, {Packet, XEl, DEl, FromString, ToJID}}.
+
+%% Send the decline to the inviter user.
+%% The original stanza must be slightly modified.
+send_decline_invitation({Packet, XEl, DEl, FromString, ToJID}, RoomJID) ->
+ {xmlelement, "decline", DAttrs, DEls} = DEl,
+ DAttrs2 = lists:keydelete("to", 1, DAttrs),
+ DAttrs3 = [{"from", FromString} | DAttrs2],
+ DEl2 = {xmlelement, "decline", DAttrs3, DEls},
+ XEl2 = replace_subelement(XEl, DEl2),
+ Packet2 = replace_subelement(Packet, XEl2),
+ ejabberd_router:route(RoomJID, ToJID, Packet2).
+
+%% Given an element and a new subelement,
+%% replace the instance of the subelement in element with the new subelement.
+replace_subelement({xmlelement, Name, Attrs, SubEls}, NewSubEl) ->
+ {_, NameNewSubEl, _, _} = NewSubEl,
+ SubEls2 = lists:keyreplace(NameNewSubEl, 2, SubEls, NewSubEl),
+ {xmlelement, Name, Attrs, SubEls2}.
+
+send_error_only_occupants(Packet, Lang, RoomJID, From) ->
+ ErrText = "Only occupants are allowed to send messages to the conference",
+ Err = jlib:make_error_reply(Packet, ?ERRT_NOT_ACCEPTABLE(Lang, ErrText)),
+ ejabberd_router:route(RoomJID, From, Err).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Logging