]> granicus.if.org Git - ejabberd/commitdiff
Fulfill all requirements of XEP-0398 v0.2.0
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 16 Mar 2018 09:10:57 +0000 (12:10 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 16 Mar 2018 09:10:57 +0000 (12:10 +0300)
These include:
- Avoid rewriting vcard:x:update tags with empty <photo/> element
- Advertise "urn:xmpp:pep-vcard-conversion:0" feature

rebar.config
src/mod_avatar.erl
src/mod_vcard_xupdate.erl

index 098b19cffd031e10d558ef78d92ada978a5efea3..143de57748d1bf78ef03f1a2e9e1205dbc6434d5 100644 (file)
@@ -25,7 +25,7 @@
         {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.20"}}},
         {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}},
         {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"}}},
         {jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
         {p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},
index 640f5f6b4e1183873f4060975085fe2c42b1c1d5..45999e8854cb03e008c729d1eb1b524f160b8346 100644 (file)
@@ -26,7 +26,8 @@
 %% gen_mod API
 -export([start/2, stop/1, reload/3, depends/2, mod_opt_type/1, mod_options/1]).
 %% 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("logger.hrl").
@@ -43,13 +44,17 @@ start(Host, _Opts) ->
     ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE,
                       vcard_iq_convert, 30),
     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) ->
     ejabberd_hooks:delete(pubsub_publish_item, Host, ?MODULE,
                          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_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) ->
     ok.
@@ -144,6 +149,20 @@ vcard_iq_publish(#iq{sub_els = [#vcard_temp{
 vcard_iq_publish(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
 %%%===================================================================
index 597ff41a84c5ecda8395fa42768be4ef3e9ac019..867e5ae253bd74b234d16ffc34218fe5afdd51ae 100644 (file)
 %%%----------------------------------------------------------------------
 
 -module(mod_vcard_xupdate).
-
 -behaviour(gen_mod).
 
+-protocol({xep, 398, '0.2.0'}).
+
 %% gen_mod callbacks
 -export([start/2, stop/1, reload/3]).
 
@@ -75,11 +76,18 @@ depends(_Host, _Opts) ->
       -> {presence(), ejabberd_c2s:state()}.
 update_presence({#presence{type = available} = Pres,
                 #{jid := #jid{luser = LUser, lserver = LServer}} = State}) ->
-    Pres1 = case get_xupdate(LUser, LServer) of
-               undefined -> xmpp:remove_subtag(Pres, #vcard_xupdate{});
-               XUpdate -> xmpp:set_subtag(Pres, XUpdate)
-           end,
-    {Pres1, State};
+    case xmpp:get_subtag(Pres, #vcard_xupdate{}) of
+       #vcard_xupdate{hash = <<>>} ->
+           %% XEP-0398 forbids overwriting vcard:x:update
+           %% tags with empty <photo/> element
+           {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) ->
     Acc.