diff options
author | Alexey Shchepin <alexey@process-one.net> | 2007-05-03 04:07:29 +0000 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2007-05-03 04:07:29 +0000 |
commit | b9e7fa2ef1d498f174f1621384ae6801270e9a6f (patch) | |
tree | 733d385b3279531536fb1bde799c18f83c31967b | |
parent | make install does not overwrites existing ejabberd.cfg anymore, ejabberd.cfg-... (diff) |
* src/mod_muc/mod_muc_room.erl: More accurate invitation errors
(thanks to Magnus Henoch)
SVN Revision: 757
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/mod_muc/mod_muc_room.erl | 129 |
2 files changed, 67 insertions, 67 deletions
@@ -1,3 +1,8 @@ +2007-05-03 Alexey Shchepin <alexey@sevcom.net> + + * src/mod_muc/mod_muc_room.erl: More accurate invitation errors + (thanks to Magnus Henoch) + 2007-04-26 Alexey Shchepin <alexey@sevcom.net> * src/mod_roster_odbc.erl: Don't deliver roster items in "None + diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index 3056c510..2c8c81e0 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -249,11 +249,10 @@ normal_state({route, From, "", From, Err), {next_state, normal_state, StateData}; Type when (Type == "") or (Type == "normal") -> - case check_invitation(From, Els, StateData) of - error -> - ErrText = "It is not allowed to send normal messages to the conference", + case catch check_invitation(From, Els, StateData) of + {error, Error} -> Err = jlib:make_error_reply( - Packet, ?ERRT_NOT_ACCEPTABLE(Lang, ErrText)), + Packet, Error), ejabberd_router:route( StateData#state.jid, From, Err), @@ -2517,69 +2516,65 @@ check_invitation(From, Els, StateData) -> FAffiliation = get_affiliation(From, StateData), CanInvite = (StateData#state.config)#config.allow_user_invites orelse (FAffiliation == admin) orelse (FAffiliation == owner), - case xml:remove_cdata(Els) of - [{xmlelement, "x", _Attrs1, Els1} = XEl] -> - case xml:get_tag_attr_s("xmlns", XEl) of - ?NS_MUC_USER -> - case xml:remove_cdata(Els1) of - [{xmlelement, "invite", Attrs2, _Els2} = InviteEl] -> - case jlib:string_to_jid( - xml:get_attr_s("to", Attrs2)) of - error -> - error; - JID -> - case CanInvite of - true -> - Reason = - xml:get_path_s( - InviteEl, - [{elem, "reason"}, cdata]), - IEl = - [{xmlelement, "invite", - [{"from", - jlib:jid_to_string(From)}], - [{xmlelement, "reason", [], - [{xmlcdata, Reason}]}]}], - PasswdEl = - case (StateData#state.config)#config.password_protected of - true -> - [{xmlelement, "password", [], - [{xmlcdata, (StateData#state.config)#config.password}]}]; - _ -> - [] - end, - Msg = - {xmlelement, "message", - [{"type", "normal"}], - [{xmlelement, "x", - [{"xmlns", ?NS_MUC_USER}], - IEl ++ PasswdEl}, - {xmlelement, "x", - [{"xmlns", - ?NS_XCONFERENCE}, - {"jid", - jlib:jid_to_string( - {StateData#state.room, - StateData#state.host, - ""})}], - [{xmlcdata, Reason}]}]}, - ejabberd_router:route( - StateData#state.jid, - JID, - Msg), - JID; - _ -> - error - end - end; - _ -> - error - end; - _ -> - error - end; - _ -> - error + InviteEl = case xml:remove_cdata(Els) of + [{xmlelement, "x", _Attrs1, Els1} = XEl] -> + case xml:get_tag_attr_s("xmlns", XEl) of + ?NS_MUC_USER -> + ok; + _ -> + throw({error, ?ERR_BAD_REQUEST}) + end, + case xml:remove_cdata(Els1) of + [{xmlelement, "invite", _Attrs2, _Els2} = InviteEl1] -> + InviteEl1; + _ -> + throw({error, ?ERR_BAD_REQUEST}) + end; + _ -> + throw({error, ?ERR_BAD_REQUEST}) + end, + JID = case jlib:string_to_jid( + xml:get_tag_attr_s("to", InviteEl)) of + error -> + throw({error, ?ERR_JID_MALFORMED}); + JID1 -> + JID1 + end, + case CanInvite of + false -> + throw({error, ?ERR_NOT_ALLOWED}); + true -> + Reason = + xml:get_path_s( + InviteEl, + [{elem, "reason"}, cdata]), + IEl = + [{xmlelement, "invite", + [{"from", + jlib:jid_to_string(From)}], + [{xmlelement, "reason", [], + [{xmlcdata, Reason}]}]}], + PasswdEl = + case (StateData#state.config)#config.password_protected of + true -> + [{xmlelement, "password", [], + [{xmlcdata, (StateData#state.config)#config.password}]}]; + _ -> + [] + end, + Msg = + {xmlelement, "message", + [{"type", "normal"}], + [{xmlelement, "x", [{"xmlns", ?NS_MUC_USER}], IEl ++ PasswdEl}, + {xmlelement, "x", + [{"xmlns", ?NS_XCONFERENCE}, + {"jid", jlib:jid_to_string( + {StateData#state.room, + StateData#state.host, + ""})}], + [{xmlcdata, Reason}]}]}, + ejabberd_router:route(StateData#state.jid, JID, Msg), + JID end. |