]> granicus.if.org Git - ejabberd/commitdiff
* src/mod_muc/mod_muc_room.erl: Include the error condition in the
authorBadlop <badlop@process-one.net>
Sat, 9 Feb 2008 10:38:47 +0000 (10:38 +0000)
committerBadlop <badlop@process-one.net>
Sat, 9 Feb 2008 10:38:47 +0000 (10:38 +0000)
presence status when kicking a participant due to an error
stanza (EJAB-496)

SVN Revision: 1179

ChangeLog
src/mod_muc/mod_muc_room.erl

index 44efe2be034cc91abe1894a9255d6f1110f5b6b9..acccae26952c0aad2f1b1a7335ac6cb7eda8ba47 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-02-08  Badlop  <badlop@process-one.net>
 
+       * src/mod_muc/mod_muc_room.erl: Include the error condition in the
+       presence status when kicking a participant due to an error
+       stanza (EJAB-496)
+
        * src/ejabberd.cfg.example: Document options to SQL keep alive
        interval and pool size (EJAB-206)
        * doc/guide.tex: Likewise
index 4837afc118073be0e5fa1fc622df2c2327cde1a2..9a36e77a7e2d2bff9c6584b11de9a1d8556d93a6 100644 (file)
@@ -294,18 +294,11 @@ normal_state({route, From, "",
                "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;
@@ -472,17 +465,11 @@ normal_state({route, From, ToNick,
     case decide_fate_message(Type, Packet, From, StateData) of
        {expulse_sender, Reason} ->
            ?DEBUG(Reason, []),
-           Status_text = "This participant sent a bad error message to another participant.",
-           NewState =
-               add_user_presence_un(
-                 From,
-                 {xmlelement, "presence",
-                  [{"type", "unavailable"}],
-                  [{xmlelement, "status", [], [{xmlcdata, Status_text}]}]},
-                 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 to another participant",
+           NewState = expulse_participant(Packet, From, StateData, 
+                                          translate:translate(Lang, ErrorText)),
+           {next_state, normal_state, NewState};
        forget_message ->
            {next_state, normal_state, StateData};
        continue_delivery ->
@@ -899,16 +886,10 @@ process_presence(From, Nick, {xmlelement, "presence", Attrs, _Els} = Packet,
            "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;
@@ -1011,19 +992,14 @@ list_to_affiliation(Affiliation) ->
 %% Returns: continue_delivery | forget_message | {expulse_sender, Reason}
 decide_fate_message("error", Packet, From, StateData) ->
     %% Make a preliminary decision
-    PD = case catch check_error_kick(Packet) of
+    PD = case check_error_kick(Packet) of
             %% If this is an error stanza and its condition matches a criteria
             true ->
                 Reason = io_lib:format("This participant is considered a ghost and is expulsed: ~s",
                                        [jlib:jid_to_string(From)]),
                 {expulse_sender, Reason};
             false ->
-                continue_delivery;
-            {'EXIT', Error} ->
-                Reason = io_lib:format(
-                           "This participant sent a problematic packet and is expulsed: ~s~nPacket: ~p~nError: ~p",
-                           [jlib:jid_to_string(From), Packet, Error]),
-                {expulse_sender, Reason}
+                continue_delivery
         end,
     case PD of
        {expulse_sender, R} ->
@@ -1044,9 +1020,7 @@ decide_fate_message(_, _, _, _) ->
 %% 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;
@@ -1059,6 +1033,32 @@ check_error_kick(Packet) ->
        _ -> 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)),