From d719a93fa1258f68ee97ccb6c72c98171e5a800a Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Sun, 18 May 2003 16:41:15 +0000 Subject: [PATCH] * src/mod_muc/mod_muc.erl: Now body of message from admin to MUC service is broadcasted to all conferences * src/mod_muc/mod_muc_room.erl: Likewise SVN Revision: 110 --- ChangeLog | 6 ++ TODO | 4 - src/mod_muc/mod_muc.erl | 137 +++++++++++++++++++++++------------ src/mod_muc/mod_muc_room.erl | 19 +++++ src/mod_register.erl | 1 + src/xml.erl | 25 +++++++ 6 files changed, 143 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index 736d11366..705bdec34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-05-18 Alexey Shchepin + + * src/mod_muc/mod_muc.erl: Now body of message from admin to MUC + service is broadcasted to all conferences + * src/mod_muc/mod_muc_room.erl: Likewise + 2003-05-15 Alexey Shchepin * src/ejabberd_s2s.erl: Added error catching for do_route/3 diff --git a/TODO b/TODO index 0b7984866..e5b2266d0 100644 --- a/TODO +++ b/TODO @@ -20,7 +20,3 @@ add traffic shapers to c2s connection before authentification add traffic shapers to s2s connections more traffic shapers SNMP - -mod_muc: - - * broadcast messages from admin diff --git a/src/mod_muc/mod_muc.erl b/src/mod_muc/mod_muc.erl index dfb64f524..d3ec27397 100644 --- a/src/mod_muc/mod_muc.erl +++ b/src/mod_muc/mod_muc.erl @@ -75,68 +75,107 @@ loop(Host) -> do_route(Host, From, To, Packet) -> {Room, _, Nick} = To, + {xmlelement, Name, Attrs, Els} = Packet, case Room of "" -> case Nick of "" -> - case jlib:iq_query_info(Packet) of - {iq, ID, get, ?NS_DISCO_INFO = XMLNS, SubEl} -> - Res = {iq, ID, result, XMLNS, - [{xmlelement, "query", - [{"xmlns", XMLNS}], - iq_disco_info()}]}, - ejabberd_router:route(To, - From, - jlib:iq_to_xml(Res)); - {iq, ID, get, ?NS_DISCO_ITEMS = XMLNS, SubEl} -> - spawn(?MODULE, - process_iq_disco_items, - [Host, From, To, ID, SubEl]); - {iq, ID, get, ?NS_REGISTER = XMLNS, SubEl} -> - Lang = xml:get_tag_attr_s("xml:lang", SubEl), - Res = {iq, ID, result, XMLNS, - [{xmlelement, "query", - [{"xmlns", XMLNS}], - iq_get_register_info(From, Lang)}]}, - ejabberd_router:route(To, - From, - jlib:iq_to_xml(Res)); - {iq, ID, set, ?NS_REGISTER = XMLNS, SubEl} -> - case process_iq_register_set(From, SubEl) of - {result, IQRes} -> + case Name of + "iq" -> + case jlib:iq_query_info(Packet) of + {iq, ID, get, ?NS_DISCO_INFO = XMLNS, SubEl} -> Res = {iq, ID, result, XMLNS, [{xmlelement, "query", [{"xmlns", XMLNS}], - IQRes}]}, - ejabberd_router:route( - To, From, jlib:iq_to_xml(Res)); - {error, Error} -> + iq_disco_info()}]}, + ejabberd_router:route(To, + From, + jlib:iq_to_xml(Res)); + {iq, ID, get, ?NS_DISCO_ITEMS = XMLNS, SubEl} -> + spawn(?MODULE, + process_iq_disco_items, + [Host, From, To, ID, SubEl]); + {iq, ID, get, ?NS_REGISTER = XMLNS, SubEl} -> + Lang = xml:get_tag_attr_s( + "xml:lang", SubEl), + Res = {iq, ID, result, XMLNS, + [{xmlelement, "query", + [{"xmlns", XMLNS}], + iq_get_register_info( + From, Lang)}]}, + ejabberd_router:route(To, + From, + jlib:iq_to_xml(Res)); + {iq, ID, set, ?NS_REGISTER = XMLNS, SubEl} -> + case process_iq_register_set(From, SubEl) of + {result, IQRes} -> + Res = {iq, ID, result, XMLNS, + [{xmlelement, "query", + [{"xmlns", XMLNS}], + IQRes}]}, + ejabberd_router:route( + To, From, jlib:iq_to_xml(Res)); + {error, Error} -> + Err = jlib:make_error_reply( + Packet, Error), + ejabberd_router:route( + To, From, Err) + end; + {iq, ID, get, ?NS_VCARD = XMLNS, SubEl} -> + Lang = xml:get_tag_attr_s( + "xml:lang", SubEl), + Res = {iq, ID, result, XMLNS, + [{xmlelement, "query", + [{"xmlns", XMLNS}], + iq_get_vcard(Lang)}]}, + ejabberd_router:route(To, + From, + jlib:iq_to_xml(Res)); + reply -> + ok; + _ -> Err = jlib:make_error_reply( - Packet, Error), + Packet, + ?ERR_FEATURE_NOT_IMPLEMENTED), ejabberd_router:route(To, From, Err) end; - {iq, ID, get, ?NS_VCARD = XMLNS, SubEl} -> - Lang = xml:get_tag_attr_s("xml:lang", SubEl), - Res = {iq, ID, result, XMLNS, - [{xmlelement, "query", - [{"xmlns", XMLNS}], - iq_get_vcard(Lang)}]}, - ejabberd_router:route(To, - From, - jlib:iq_to_xml(Res)); + "message" -> + case xml:get_attr_s("type", Attrs) of + "error" -> + ok; + _ -> + case acl:match_rule(muc_admin, From) of + allow -> + Msg = xml:get_path_s( + Packet, + [{elem, "body"}, cdata]), + broadcast_service_message(Msg); + _ -> + Err = jlib:make_error_reply( + Packet, + ?ERR_NOT_ALLOWED), + ejabberd_router:route( + To, From, Err) + end + end; + "presence" -> + ok + end; + _ -> + case xml:get_attr_s("type", Attrs) of + "error" -> + ok; + "result" -> + ok; _ -> Err = jlib:make_error_reply( - Packet, ?ERR_FEATURE_NOT_IMPLEMENTED), + Packet, ?ERR_JID_NOT_FOUND), ejabberd_router:route(To, From, Err) - end; - _ -> - Err = jlib:make_error_reply(Packet, ?ERR_JID_NOT_FOUND), - ejabberd_router:route(To, From, Err) + end end; _ -> case ets:lookup(muc_online_room, Room) of [] -> - {xmlelement, Name, Attrs, Els} = Packet, Type = xml:get_attr_s("type", Attrs), case {Name, Type} of {"presence", ""} -> @@ -358,6 +397,14 @@ iq_get_vcard(Lang) -> "Copyright (c) 2003 Alexey Shchepin"}]}]. +broadcast_service_message(Msg) -> + lists:foreach( + fun(#muc_online_room{name = Name, pid = Pid}) -> + gen_fsm:send_all_state_event( + Pid, {service_message, Msg}) + end, ets:tab2list(muc_online_room)). + + can_use_nick(JID, "") -> false; diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index 47e55576f..92d111b85 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -521,6 +521,25 @@ normal_state(Event, StateData) -> %% {next_state, NextStateName, NextStateData, Timeout} | %% {stop, Reason, NewStateData} %%---------------------------------------------------------------------- +handle_event({service_message, Msg}, StateName, StateData) -> + MessagePkt = {xmlelement, "message", + [{"type", "groupchat"}], + [{xmlelement, "body", [], [{xmlcdata, Msg}]}]}, + lists:foreach( + fun({LJID, Info}) -> + ejabberd_router:route( + {StateData#state.room, + StateData#state.host, + ""}, + Info#user.jid, + MessagePkt) + end, + ?DICT:to_list(StateData#state.users)), + NSD = add_message_to_history("", + MessagePkt, + StateData), + {next_state, normal_state, NSD}; + handle_event(Event, StateName, StateData) -> {next_state, StateName, StateData}. diff --git a/src/mod_register.erl b/src/mod_register.erl index 08643ba8b..2b6b03fbd 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -109,6 +109,7 @@ try_register(User, Password) -> {atomic, ok} -> ok; {atomic, exists} -> + % TODO: replace to "username unavailable" {error, ?ERR_BAD_REQUEST}; {error, Reason} -> {error, ?ERR_INTERNAL_SERVER_ERROR} diff --git a/src/xml.erl b/src/xml.erl index 76da8a709..88b00e7b1 100644 --- a/src/xml.erl +++ b/src/xml.erl @@ -40,6 +40,31 @@ attrs_to_string(Attrs) -> attr_to_string({Name, Value}) -> " " ++ crypt(Name) ++ "='" ++ crypt(Value) ++ "'". + +%element_to_string2(El) -> +% lists:flatten(element_to_string21(El)). +% +%element_to_string21(El) -> +% case El of +% {xmlelement, Name, Attrs, Els} -> +% if length(Els) > 0 -> +% [[$< | Name], attrs_to_list(Attrs), ">", +% lists:map(fun(E) -> element_to_string21(E) end, Els), +% ""]; +% true -> +% ["<", Name, attrs_to_list(Attrs), "/>"] +% end; +% {xmlcdata, CData} -> crypt(CData) +% end. +% +%attrs_to_list(Attrs) -> +% lists:map(fun(A) -> attr_to_list(A) end, Attrs). +% +%attr_to_list({Name, Value}) -> +% [" ", crypt(Name), "='", crypt(Value), "'"]. + + + %crypt(S) -> % lists:reverse(crypt(S, "")). % -- 2.40.0