25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Make it possible to get/set vCards for MUC rooms

This commit is contained in:
Evgeniy Khramtsov 2014-05-04 23:11:05 +04:00
parent 478b4f19bd
commit fafec77e56
2 changed files with 33 additions and 2 deletions

View File

@ -58,6 +58,7 @@
voice_request_min_interval = 1800 :: non_neg_integer(), voice_request_min_interval = 1800 :: non_neg_integer(),
max_users = ?MAX_USERS_DEFAULT :: non_neg_integer() | none, max_users = ?MAX_USERS_DEFAULT :: non_neg_integer() | none,
logging = false :: boolean(), logging = false :: boolean(),
vcard = <<"">> :: boolean(),
captcha_whitelist = (?SETS):empty() :: gb_set() captcha_whitelist = (?SETS):empty() :: gb_set()
}). }).

View File

@ -418,12 +418,13 @@ normal_state({route, From, <<"">>,
StateData) -> StateData) ->
case jlib:iq_query_info(Packet) of case jlib:iq_query_info(Packet) of
#iq{type = Type, xmlns = XMLNS, lang = Lang, #iq{type = Type, xmlns = XMLNS, lang = Lang,
sub_el = SubEl} = sub_el = #xmlel{name = SubElName} = SubEl} =
IQ IQ
when (XMLNS == (?NS_MUC_ADMIN)) or when (XMLNS == (?NS_MUC_ADMIN)) or
(XMLNS == (?NS_MUC_OWNER)) (XMLNS == (?NS_MUC_OWNER))
or (XMLNS == (?NS_DISCO_INFO)) or (XMLNS == (?NS_DISCO_INFO))
or (XMLNS == (?NS_DISCO_ITEMS)) or (XMLNS == (?NS_DISCO_ITEMS))
or (XMLNS == (?NS_VCARD))
or (XMLNS == (?NS_CAPTCHA)) -> or (XMLNS == (?NS_CAPTCHA)) ->
Res1 = case XMLNS of Res1 = case XMLNS of
?NS_MUC_ADMIN -> ?NS_MUC_ADMIN ->
@ -434,6 +435,8 @@ normal_state({route, From, <<"">>,
process_iq_disco_info(From, Type, Lang, StateData); process_iq_disco_info(From, Type, Lang, StateData);
?NS_DISCO_ITEMS -> ?NS_DISCO_ITEMS ->
process_iq_disco_items(From, Type, Lang, StateData); process_iq_disco_items(From, Type, Lang, StateData);
?NS_VCARD ->
process_iq_vcard(From, Type, Lang, SubEl, StateData);
?NS_CAPTCHA -> ?NS_CAPTCHA ->
process_iq_captcha(From, Type, Lang, SubEl, StateData) process_iq_captcha(From, Type, Lang, SubEl, StateData)
end, end,
@ -441,7 +444,7 @@ normal_state({route, From, <<"">>,
{result, Res, SD} -> {result, Res, SD} ->
{IQ#iq{type = result, {IQ#iq{type = result,
sub_el = sub_el =
[#xmlel{name = <<"query">>, [#xmlel{name = SubElName,
attrs = attrs =
[{<<"xmlns">>, [{<<"xmlns">>,
XMLNS}], XMLNS}],
@ -3894,6 +3897,10 @@ set_opts([{Opt, Val} | Opts], StateData) ->
StateData#state{config = StateData#state{config =
(StateData#state.config)#config{max_users = (StateData#state.config)#config{max_users =
MaxUsers}}; MaxUsers}};
vcard ->
StateData#state{config =
(StateData#state.config)#config{vcard =
Val}};
affiliations -> affiliations ->
StateData#state{affiliations = (?DICT):from_list(Val)}; StateData#state{affiliations = (?DICT):from_list(Val)};
subject -> StateData#state{subject = Val}; subject -> StateData#state{subject = Val};
@ -3926,6 +3933,7 @@ make_opts(StateData) ->
?MAKE_CONFIG_OPT(logging), ?MAKE_CONFIG_OPT(max_users), ?MAKE_CONFIG_OPT(logging), ?MAKE_CONFIG_OPT(max_users),
?MAKE_CONFIG_OPT(allow_voice_requests), ?MAKE_CONFIG_OPT(allow_voice_requests),
?MAKE_CONFIG_OPT(voice_request_min_interval), ?MAKE_CONFIG_OPT(voice_request_min_interval),
?MAKE_CONFIG_OPT(vcard),
{captcha_whitelist, {captcha_whitelist,
(?SETS):to_list((StateData#state.config)#config.captcha_whitelist)}, (?SETS):to_list((StateData#state.config)#config.captcha_whitelist)},
{affiliations, {affiliations,
@ -3991,6 +3999,8 @@ process_iq_disco_info(_From, get, Lang, StateData) ->
{<<"type">>, <<"text">>}, {<<"type">>, <<"text">>},
{<<"name">>, get_title(StateData)}], {<<"name">>, get_title(StateData)}],
children = []}, children = []},
#xmlel{name = <<"feature">>,
attrs = [{<<"var">>, ?NS_VCARD}], children = []},
#xmlel{name = <<"feature">>, #xmlel{name = <<"feature">>,
attrs = [{<<"var">>, ?NS_MUC}], children = []}, attrs = [{<<"var">>, ?NS_MUC}], children = []},
?CONFIG_OPT_TO_FEATURE((Config#config.public), ?CONFIG_OPT_TO_FEATURE((Config#config.public),
@ -4064,6 +4074,26 @@ process_iq_captcha(_From, set, _Lang, SubEl,
_ -> {error, ?ERR_NOT_ACCEPTABLE} _ -> {error, ?ERR_NOT_ACCEPTABLE}
end. end.
process_iq_vcard(_From, get, _Lang, _SubEl, StateData) ->
#state{config = #config{vcard = VCardRaw}} = StateData,
case xml_stream:parse_element(VCardRaw) of
#xmlel{children = VCardEls} ->
{result, VCardEls, StateData};
{error, _} ->
{result, [], StateData}
end;
process_iq_vcard(From, set, Lang, SubEl, StateData) ->
case get_affiliation(From, StateData) of
owner ->
VCardRaw = xml:element_to_binary(SubEl),
Config = StateData#state.config,
NewConfig = Config#config{vcard = VCardRaw},
change_config(NewConfig, StateData);
_ ->
ErrText = <<"Owner privileges required">>,
{error, ?ERRT_FORBIDDEN(Lang, ErrText)}
end.
get_title(StateData) -> get_title(StateData) ->
case (StateData#state.config)#config.title of case (StateData#state.config)#config.title of
<<"">> -> StateData#state.room; <<"">> -> StateData#state.room;