25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +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(),
max_users = ?MAX_USERS_DEFAULT :: non_neg_integer() | none,
logging = false :: boolean(),
vcard = <<"">> :: boolean(),
captcha_whitelist = (?SETS):empty() :: gb_set()
}).

View File

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