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

Fulfill all requirements of XEP-0398 v0.2.0

These include:
- Avoid rewriting vcardupdate tags with empty <photo/> element
- Advertise "urn:xmpp:pep-vcard-conversion:0" feature
This commit is contained in:
Evgeniy Khramtsov 2018-03-16 12:10:57 +03:00
parent e15595df64
commit ddc29d42de
3 changed files with 37 additions and 10 deletions

View File

@ -25,7 +25,7 @@
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.20"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.20"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}}, {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "dbf173f"}}}, {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "dbf173f"}}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "2bb82b29"}}}, {xmpp, ".*", {git, "https://github.com/processone/xmpp", {tag, "0a1c76e"}}},
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.12"}}}, {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.12"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}}, {jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}}, {p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},

View File

@ -26,7 +26,8 @@
%% gen_mod API %% gen_mod API
-export([start/2, stop/1, reload/3, depends/2, mod_opt_type/1, mod_options/1]). -export([start/2, stop/1, reload/3, depends/2, mod_opt_type/1, mod_options/1]).
%% Hooks %% Hooks
-export([pubsub_publish_item/6, vcard_iq_convert/1, vcard_iq_publish/1]). -export([pubsub_publish_item/6, vcard_iq_convert/1, vcard_iq_publish/1,
get_sm_features/5]).
-include("xmpp.hrl"). -include("xmpp.hrl").
-include("logger.hrl"). -include("logger.hrl").
@ -43,13 +44,17 @@ start(Host, _Opts) ->
ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE,
vcard_iq_convert, 30), vcard_iq_convert, 30),
ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE,
vcard_iq_publish, 100). vcard_iq_publish, 100),
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
get_sm_features, 50).
stop(Host) -> stop(Host) ->
ejabberd_hooks:delete(pubsub_publish_item, Host, ?MODULE, ejabberd_hooks:delete(pubsub_publish_item, Host, ?MODULE,
pubsub_publish_item, 50), pubsub_publish_item, 50),
ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_convert, 30), ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_convert, 30),
ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_publish, 100). ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_publish, 100),
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE,
get_sm_features, 50).
reload(_Host, _NewOpts, _OldOpts) -> reload(_Host, _NewOpts, _OldOpts) ->
ok. ok.
@ -144,6 +149,20 @@ vcard_iq_publish(#iq{sub_els = [#vcard_temp{
vcard_iq_publish(Acc) -> vcard_iq_publish(Acc) ->
Acc. Acc.
-spec get_sm_features({error, stanza_error()} | empty | {result, [binary()]},
jid(), jid(), binary(), binary()) ->
{error, stanza_error()} | empty | {result, [binary()]}.
get_sm_features({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
Acc;
get_sm_features(Acc, _From, _To, <<"">>, _Lang) ->
{result, [?NS_DISCO_INFO, ?NS_PEP_VCARD_CONVERSION_0 |
case Acc of
{result, Features} -> Features;
empty -> []
end]};
get_sm_features(Acc, _From, _To, _Node, _Lang) ->
Acc.
%%%=================================================================== %%%===================================================================
%%% Internal functions %%% Internal functions
%%%=================================================================== %%%===================================================================

View File

@ -24,9 +24,10 @@
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
-module(mod_vcard_xupdate). -module(mod_vcard_xupdate).
-behaviour(gen_mod). -behaviour(gen_mod).
-protocol({xep, 398, '0.2.0'}).
%% gen_mod callbacks %% gen_mod callbacks
-export([start/2, stop/1, reload/3]). -export([start/2, stop/1, reload/3]).
@ -75,11 +76,18 @@ depends(_Host, _Opts) ->
-> {presence(), ejabberd_c2s:state()}. -> {presence(), ejabberd_c2s:state()}.
update_presence({#presence{type = available} = Pres, update_presence({#presence{type = available} = Pres,
#{jid := #jid{luser = LUser, lserver = LServer}} = State}) -> #{jid := #jid{luser = LUser, lserver = LServer}} = State}) ->
Pres1 = case get_xupdate(LUser, LServer) of case xmpp:get_subtag(Pres, #vcard_xupdate{}) of
undefined -> xmpp:remove_subtag(Pres, #vcard_xupdate{}); #vcard_xupdate{hash = <<>>} ->
XUpdate -> xmpp:set_subtag(Pres, XUpdate) %% XEP-0398 forbids overwriting vcard:x:update
end, %% tags with empty <photo/> element
{Pres1, State}; {Pres, State};
_ ->
Pres1 = case get_xupdate(LUser, LServer) of
undefined -> xmpp:remove_subtag(Pres, #vcard_xupdate{});
XUpdate -> xmpp:set_subtag(Pres, XUpdate)
end,
{Pres1, State}
end;
update_presence(Acc) -> update_presence(Acc) ->
Acc. Acc.