25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

* 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
This commit is contained in:
Alexey Shchepin 2003-05-18 16:41:15 +00:00
parent ee15945cd7
commit d719a93fa1
6 changed files with 144 additions and 50 deletions

View File

@ -1,3 +1,9 @@
2003-05-18 Alexey Shchepin <alexey@sevcom.net>
* 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 <alexey@sevcom.net>
* src/ejabberd_s2s.erl: Added error catching for do_route/3

4
TODO
View File

@ -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

View File

@ -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));
_ ->
Err = jlib:make_error_reply(
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
ejabberd_router:route(To, From, Err)
"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;
_ ->
Err = jlib:make_error_reply(Packet, ?ERR_JID_NOT_FOUND),
ejabberd_router:route(To, From, Err)
case xml:get_attr_s("type", Attrs) of
"error" ->
ok;
"result" ->
ok;
_ ->
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;

View File

@ -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}.

View File

@ -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}

View File

@ -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),
% "</", Name, ">"];
% 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, "")).
%