25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-30 16:36:29 +01:00

* src/mod_muc/: Support for discovering service and more

configuration options

SVN Revision: 92
This commit is contained in:
Alexey Shchepin 2003-03-26 20:51:18 +00:00
parent 6d89957e06
commit 8efae60c04
3 changed files with 116 additions and 58 deletions

View File

@ -1,3 +1,8 @@
2003-03-26 Alexey Shchepin <alexey@sevcom.net>
* src/mod_muc/: Support for discovering service and more
configuration options
2003-03-25 Alexey Shchepin <alexey@sevcom.net> 2003-03-25 Alexey Shchepin <alexey@sevcom.net>
* src/mod_muc/: Support for more configuration options and * src/mod_muc/: Support for more configuration options and

View File

@ -18,7 +18,8 @@
room_destroyed/1, room_destroyed/1,
store_room/2, store_room/2,
restore_room/1, restore_room/1,
forget_room/1]). forget_room/1,
process_iq_disco_items/5]).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
@ -76,10 +77,14 @@ do_route(Host, From, To, Packet) ->
Res = {iq, ID, result, XMLNS, Res = {iq, ID, result, XMLNS,
[{xmlelement, "query", [{xmlelement, "query",
[{"xmlns", XMLNS}], [{"xmlns", XMLNS}],
iq_disco()}]}, iq_disco_info()}]},
ejabberd_router:route(To, ejabberd_router:route(To,
From, From,
jlib:iq_to_xml(Res)); jlib:iq_to_xml(Res));
{iq, ID, get, ?NS_DISCO_ITEMS = XMLNS, SubEl} ->
spawn(?MODULE,
process_iq_disco_items,
[Host, From, To, ID, SubEl]);
_ -> _ ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, ?ERR_SERVICE_UNAVAILABLE), Packet, ?ERR_SERVICE_UNAVAILABLE),
@ -130,15 +135,6 @@ stop() ->
ok. ok.
iq_disco() ->
[{xmlelement, "identity",
[{"category", "conference"},
{"type", "text"},
{"name", "ejabberd/mod_muc"}], []},
{xmlelement, "feature",
[{"var", ?NS_MUC}], []}].
store_room(Name, Opts) -> store_room(Name, Opts) ->
F = fun() -> F = fun() ->
mnesia:write(#muc_room{name = Name, mnesia:write(#muc_room{name = Name,
@ -180,3 +176,40 @@ load_permanent_rooms(Host) ->
end, Rs) end, Rs)
end. end.
iq_disco_info() ->
[{xmlelement, "identity",
[{"category", "conference"},
{"type", "text"},
{"name", "ejabberd/mod_muc"}], []},
{xmlelement, "feature",
[{"var", ?NS_MUC}], []}].
process_iq_disco_items(Host, From, To, ID, SubEl) ->
Res = {iq, ID, result, ?NS_DISCO_ITEMS,
[{xmlelement, "query",
[{"xmlns", ?NS_DISCO_ITEMS}],
iq_disco_items(Host, From)}]},
ejabberd_router:route(To,
From,
jlib:iq_to_xml(Res)).
% TODO: ask more info from room processes
iq_disco_items(Host, From) ->
lists:zf(fun(#muc_online_room{name = Name, pid = Pid}) ->
case catch gen_fsm:sync_send_all_state_event(
Pid, get_disco_item, 100) of
{'EXIT', _} ->
false;
{item, Desc} ->
{true,
{xmlelement, "item",
[{"jid", jlib:jid_to_string({Name, Host, ""})},
{"name", Desc}], []}}
end
end, ets:tab2list(muc_online_room)).

View File

@ -35,17 +35,17 @@
-record(lqueue, {queue, len, max}). -record(lqueue, {queue, len, max}).
-record(config, {allow_change_subj = true, % TODO -record(config, {allow_change_subj = true,
allow_query_users = true, allow_query_users = true,
allow_private_messages = true, allow_private_messages = true,
public = true, % TODO public = true, % TODO
persistent = false, % TODO persistent = false,
moderated = false, % TODO moderated = false, % TODO
members_by_default = true, % TODO members_by_default = true,
members_only = false, % TODO members_only = false, % TODO
allow_user_invites = false, % TODO allow_user_invites = false, % TODO
password_protected = false, % TODO password_protected = false, % TODO
anonymous = true, % TODO anonymous = true,
logging = false % TODO logging = false % TODO
}). }).
@ -426,6 +426,14 @@ handle_event(Event, StateName, StateData) ->
%% {stop, Reason, NewStateData} | %% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData} %% {stop, Reason, Reply, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_sync_event(get_disco_item, From, StateName, StateData) ->
Reply = case (StateData#state.config)#config.public of
true ->
{item, StateData#state.room};
_ ->
false
end,
{reply, Reply, StateName, StateData};
handle_sync_event(Event, From, StateName, StateData) -> handle_sync_event(Event, From, StateName, StateData) ->
Reply = ok, Reply = ok,
{reply, Reply, StateName, StateData}. {reply, Reply, StateName, StateData}.
@ -656,8 +664,10 @@ send_new_presence(NJID, StateData) ->
SRole = role_to_list(Role), SRole = role_to_list(Role),
lists:foreach( lists:foreach(
fun({LJID, Info}) -> fun({LJID, Info}) ->
ItemAttrs = case Info#user.role of ItemAttrs =
moderator -> case (Info#user.role == moderator) orelse
((StateData#state.config)#config.anonymous == false) of
true ->
[{"jid", jlib:jid_to_string(RealJID)}, [{"jid", jlib:jid_to_string(RealJID)},
{"affiliation", SAffiliation}, {"affiliation", SAffiliation},
{"role", SRole}]; {"role", SRole}];
@ -692,17 +702,18 @@ send_existing_presences(ToJID, StateData) ->
ok; ok;
_ -> _ ->
FromAffiliation = get_affiliation(LJID, StateData), FromAffiliation = get_affiliation(LJID, StateData),
ItemAttrs = case Role of ItemAttrs =
moderator -> case (Role == moderator) orelse
[{"jid", ((StateData#state.config)#config.anonymous ==
jlib:jid_to_string(FromJID)}, false) of
true ->
[{"jid", jlib:jid_to_string(FromJID)},
{"affiliation", {"affiliation",
affiliation_to_list( affiliation_to_list(FromAffiliation)},
FromAffiliation)},
{"role", role_to_list(FromRole)}]; {"role", role_to_list(FromRole)}];
_ -> _ ->
[{"affiliation", affiliation_to_list( [{"affiliation",
FromAffiliation)}, affiliation_to_list(FromAffiliation)},
{"role", role_to_list(FromRole)}] {"role", role_to_list(FromRole)}]
end, end,
Packet = append_subtags( Packet = append_subtags(
@ -746,8 +757,10 @@ send_nick_changing(JID, OldNick, StateData) ->
SRole = role_to_list(Role), SRole = role_to_list(Role),
lists:foreach( lists:foreach(
fun({LJID, Info}) -> fun({LJID, Info}) ->
ItemAttrs1 = case Info#user.role of ItemAttrs1 =
moderator -> case (Info#user.role == moderator) orelse
((StateData#state.config)#config.anonymous == false) of
true ->
[{"jid", jlib:jid_to_string(RealJID)}, [{"jid", jlib:jid_to_string(RealJID)},
{"affiliation", SAffiliation}, {"affiliation", SAffiliation},
{"role", SRole}, {"role", SRole},
@ -757,8 +770,10 @@ send_nick_changing(JID, OldNick, StateData) ->
{"role", SRole}, {"role", SRole},
{"nick", Nick}] {"nick", Nick}]
end, end,
ItemAttrs2 = case Info#user.role of ItemAttrs2 =
moderator -> case (Info#user.role == moderator) orelse
((StateData#state.config)#config.anonymous == false) of
true ->
[{"jid", jlib:jid_to_string(RealJID)}, [{"jid", jlib:jid_to_string(RealJID)},
{"affiliation", SAffiliation}, {"affiliation", SAffiliation},
{"role", SRole}]; {"role", SRole}];
@ -871,7 +886,12 @@ send_join_messages_end(JID, StateData) ->
Packet). Packet).
can_change_subject(Role, StateData) -> can_change_subject(Role, StateData) ->
(Role == moderator) orelse (Role == participant). case (StateData#state.config)#config.allow_change_subj of
true ->
(Role == moderator) orelse (Role == participant);
_ ->
Role == moderator
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Admin stuff % Admin stuff