"error" ->
case is_user_online(From, StateData) of
true ->
- NewState =
- add_user_presence_un(
- From,
- {xmlelement, "presence",
- [{"type", "unavailable"}],
- [{xmlelement, "status", [],
- [{xmlcdata,
- "This participant sent a bad error message to the room."}]}]},
- StateData),
- send_new_presence(From, NewState),
- {next_state, normal_state,
- remove_online_user(From, NewState)};
+ ErrorText = "This participant is kicked from the room because "
+ "he sent an error message",
+ NewState = expulse_participant(Packet, From, StateData,
+ translate:translate(Lang, ErrorText)),
+ {next_state, normal_state, NewState};
_ ->
{next_state, normal_state, StateData}
end;
"error" ->
case is_user_online(From, StateData) of
true ->
- NewState =
- add_user_presence_un(
- From,
- {xmlelement, "presence",
- [{"type", "unavailable"}],
- [{xmlelement, "status", [],
- [{xmlcdata, "This participant sent a bad error presence."}]}]},
- StateData),
- send_new_presence(From, NewState),
- remove_online_user(From, NewState);
+ ErrorText = "This participant is kicked from the room because "
+ "he sent an error presence",
+ expulse_participant(Packet, From, StateData,
+ translate:translate(Lang, ErrorText));
_ ->
StateData
end;
%% that the sender is a dead participant.
%% If so, return true to kick the participant.
check_error_kick(Packet) ->
- {xmlelement, _, _, EEls} = xml:get_subtag(Packet, "error"),
- [{xmlelement, Name, _, _}] = xml:remove_cdata(EEls),
- case Name of
+ case get_error_condition(Packet) of
"gone" -> true;
"internal-server-error" -> true;
"item-not-found" -> true;
_ -> false
end.
+get_error_condition(Packet) ->
+ case catch get_error_condition2(Packet) of
+ {condition, ErrorCondition} ->
+ ErrorCondition;
+ {'EXIT', Error} ->
+ "badformed error stanza"
+ end.
+get_error_condition2(Packet) ->
+ {xmlelement, _, _, EEls} = xml:get_subtag(Packet, "error"),
+ [Condition] = [Name || {xmlelement, Name, [{"xmlns", ?NS_STANZAS}], []} <- EEls],
+ {condition, Condition}.
+
+expulse_participant(Packet, From, StateData, Reason1) ->
+ ErrorCondition = get_error_condition(Packet),
+ Reason2 = io_lib:format(Reason1 ++ ": " ++ "~s", [ErrorCondition]),
+ NewState = add_user_presence_un(
+ From,
+ {xmlelement, "presence",
+ [{"type", "unavailable"}],
+ [{xmlelement, "status", [],
+ [{xmlcdata, Reason2}]
+ }]},
+ StateData),
+ send_new_presence(From, NewState),
+ remove_online_user(From, NewState).
+
set_affiliation(JID, Affiliation, StateData) ->
LJID = jlib:jid_remove_resource(jlib:jid_tolower(JID)),