diff options
author | Alexey Shchepin <alexey@process-one.net> | 2003-03-26 20:51:18 +0000 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2003-03-26 20:51:18 +0000 |
commit | 8efae60c04f68b9abcd33c56af2c2ae07559ab7f (patch) | |
tree | 9fc8cae8ba43c0e842f4c31f9a7108a820aa7113 /src/mod_muc | |
parent | * src/mod_muc/: Support for more configuration options and (diff) |
* src/mod_muc/: Support for discovering service and more
configuration options
SVN Revision: 92
Diffstat (limited to 'src/mod_muc')
-rw-r--r-- | src/mod_muc/mod_muc.erl | 55 | ||||
-rw-r--r-- | src/mod_muc/mod_muc_room.erl | 114 |
2 files changed, 111 insertions, 58 deletions
diff --git a/src/mod_muc/mod_muc.erl b/src/mod_muc/mod_muc.erl index b94a948d..b943e739 100644 --- a/src/mod_muc/mod_muc.erl +++ b/src/mod_muc/mod_muc.erl @@ -18,7 +18,8 @@ room_destroyed/1, store_room/2, restore_room/1, - forget_room/1]). + forget_room/1, + process_iq_disco_items/5]). -include("ejabberd.hrl"). -include("jlib.hrl"). @@ -76,10 +77,14 @@ do_route(Host, From, To, Packet) -> Res = {iq, ID, result, XMLNS, [{xmlelement, "query", [{"xmlns", XMLNS}], - iq_disco()}]}, + 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]); _ -> Err = jlib:make_error_reply( Packet, ?ERR_SERVICE_UNAVAILABLE), @@ -130,15 +135,6 @@ stop() -> ok. -iq_disco() -> - [{xmlelement, "identity", - [{"category", "conference"}, - {"type", "text"}, - {"name", "ejabberd/mod_muc"}], []}, - {xmlelement, "feature", - [{"var", ?NS_MUC}], []}]. - - store_room(Name, Opts) -> F = fun() -> mnesia:write(#muc_room{name = Name, @@ -180,3 +176,40 @@ load_permanent_rooms(Host) -> end, Rs) 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)). + + + + diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index e01dab87..7f0026ad 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -35,17 +35,17 @@ -record(lqueue, {queue, len, max}). --record(config, {allow_change_subj = true, % TODO +-record(config, {allow_change_subj = true, allow_query_users = true, allow_private_messages = true, public = true, % TODO - persistent = false, % TODO + persistent = false, moderated = false, % TODO - members_by_default = true, % TODO + members_by_default = true, members_only = false, % TODO allow_user_invites = false, % TODO password_protected = false, % TODO - anonymous = true, % TODO + anonymous = true, logging = false % TODO }). @@ -426,6 +426,14 @@ handle_event(Event, StateName, StateData) -> %% {stop, Reason, 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) -> Reply = ok, {reply, Reply, StateName, StateData}. @@ -656,15 +664,17 @@ send_new_presence(NJID, StateData) -> SRole = role_to_list(Role), lists:foreach( fun({LJID, Info}) -> - ItemAttrs = case Info#user.role of - moderator -> - [{"jid", jlib:jid_to_string(RealJID)}, - {"affiliation", SAffiliation}, - {"role", SRole}]; - _ -> - [{"affiliation", SAffiliation}, - {"role", SRole}] - end, + ItemAttrs = + case (Info#user.role == moderator) orelse + ((StateData#state.config)#config.anonymous == false) of + true -> + [{"jid", jlib:jid_to_string(RealJID)}, + {"affiliation", SAffiliation}, + {"role", SRole}]; + _ -> + [{"affiliation", SAffiliation}, + {"role", SRole}] + end, Packet = append_subtags( Presence, [{xmlelement, "x", [{"xmlns", ?NS_MUC_USER}], @@ -692,19 +702,20 @@ send_existing_presences(ToJID, StateData) -> ok; _ -> FromAffiliation = get_affiliation(LJID, StateData), - ItemAttrs = case Role of - moderator -> - [{"jid", - jlib:jid_to_string(FromJID)}, - {"affiliation", - affiliation_to_list( - FromAffiliation)}, - {"role", role_to_list(FromRole)}]; - _ -> - [{"affiliation", affiliation_to_list( - FromAffiliation)}, - {"role", role_to_list(FromRole)}] - end, + ItemAttrs = + case (Role == moderator) orelse + ((StateData#state.config)#config.anonymous == + false) of + true -> + [{"jid", jlib:jid_to_string(FromJID)}, + {"affiliation", + affiliation_to_list(FromAffiliation)}, + {"role", role_to_list(FromRole)}]; + _ -> + [{"affiliation", + affiliation_to_list(FromAffiliation)}, + {"role", role_to_list(FromRole)}] + end, Packet = append_subtags( Presence, [{xmlelement, "x", [{"xmlns", ?NS_MUC_USER}], @@ -746,26 +757,30 @@ send_nick_changing(JID, OldNick, StateData) -> SRole = role_to_list(Role), lists:foreach( fun({LJID, Info}) -> - ItemAttrs1 = case Info#user.role of - moderator -> - [{"jid", jlib:jid_to_string(RealJID)}, - {"affiliation", SAffiliation}, - {"role", SRole}, - {"nick", Nick}]; - _ -> - [{"affiliation", SAffiliation}, - {"role", SRole}, - {"nick", Nick}] - end, - ItemAttrs2 = case Info#user.role of - moderator -> - [{"jid", jlib:jid_to_string(RealJID)}, - {"affiliation", SAffiliation}, - {"role", SRole}]; - _ -> - [{"affiliation", SAffiliation}, - {"role", SRole}] - end, + ItemAttrs1 = + case (Info#user.role == moderator) orelse + ((StateData#state.config)#config.anonymous == false) of + true -> + [{"jid", jlib:jid_to_string(RealJID)}, + {"affiliation", SAffiliation}, + {"role", SRole}, + {"nick", Nick}]; + _ -> + [{"affiliation", SAffiliation}, + {"role", SRole}, + {"nick", Nick}] + end, + ItemAttrs2 = + case (Info#user.role == moderator) orelse + ((StateData#state.config)#config.anonymous == false) of + true -> + [{"jid", jlib:jid_to_string(RealJID)}, + {"affiliation", SAffiliation}, + {"role", SRole}]; + _ -> + [{"affiliation", SAffiliation}, + {"role", SRole}] + end, Packet1 = {xmlelement, "presence", [{"type", "unavailable"}], [{xmlelement, "x", [{"xmlns", ?NS_MUC_USER}], @@ -871,7 +886,12 @@ send_join_messages_end(JID, StateData) -> Packet). 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 |