From cdac156f2e7474f92da584725fe76b65ba12c80e Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 30 Jun 2009 16:54:46 +0000 Subject: [PATCH] Add announcement of offline feature to service discovery (EJAB-234) SVN Revision: 2346 --- src/mod_offline.erl | 23 +++++++++++++++++++++++ src/mod_offline_odbc.erl | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/mod_offline.erl b/src/mod_offline.erl index c2f3da232..8085d348a 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -35,6 +35,7 @@ store_packet/3, resend_offline_messages/2, pop_offline_messages/3, + get_sm_features/5, remove_expired_messages/0, remove_old_messages/1, remove_user/2, @@ -76,6 +77,10 @@ start(Host, Opts) -> ?MODULE, remove_user, 50), ejabberd_hooks:add(anonymous_purge_hook, HostB, ?MODULE, remove_user, 50), + ejabberd_hooks:add(disco_sm_features, HostB, + ?MODULE, get_sm_features, 50), + ejabberd_hooks:add(disco_local_features, HostB, + ?MODULE, get_sm_features, 50), ejabberd_hooks:add(webadmin_page_host, HostB, ?MODULE, webadmin_page, 50), ejabberd_hooks:add(webadmin_user, HostB, @@ -152,6 +157,8 @@ stop(Host) -> ?MODULE, remove_user, 50), ejabberd_hooks:delete(anonymous_purge_hook, HostB, ?MODULE, remove_user, 50), + ejabberd_hooks:delete(disco_sm_features, HostB, ?MODULE, get_sm_features, 50), + ejabberd_hooks:delete(disco_local_features, HostB, ?MODULE, get_sm_features, 50), ejabberd_hooks:delete(webadmin_page_host, HostB, ?MODULE, webadmin_page, 50), ejabberd_hooks:delete(webadmin_user, HostB, @@ -162,6 +169,21 @@ stop(Host) -> exit(whereis(Proc), stop), {wait, Proc}. +get_sm_features(Acc, _From, _To, "", _Lang) -> + Feats = case Acc of + {result, I} -> I; + _ -> [] + end, + {result, Feats ++ [?NS_FEATURE_MSGOFFLINE]}; + +get_sm_features(_Acc, _From, _To, ?NS_FEATURE_MSGOFFLINE, _Lang) -> + %% override all lesser features... + {result, []}; + +get_sm_features(Acc, _From, _To, _Node, _Lang) -> + Acc. + + store_packet(From, To, Packet) -> Type = exmpp_stanza:get_type(Packet), if @@ -321,6 +343,7 @@ pop_offline_messages(Ls, User, Server) Ls end. + remove_expired_messages() -> TimeStamp = now(), F = fun() -> diff --git a/src/mod_offline_odbc.erl b/src/mod_offline_odbc.erl index 254d75bc2..92de5548a 100644 --- a/src/mod_offline_odbc.erl +++ b/src/mod_offline_odbc.erl @@ -36,6 +36,7 @@ stop/1, store_packet/3, pop_offline_messages/3, + get_sm_features/5, remove_user/2, webadmin_page/3, webadmin_user/4, @@ -70,6 +71,10 @@ start(Host, Opts) -> ?MODULE, remove_user, 50), ejabberd_hooks:add(anonymous_purge_hook, HostB, ?MODULE, remove_user, 50), + ejabberd_hooks:add(disco_sm_features, HostB, + ?MODULE, get_sm_features, 50), + ejabberd_hooks:add(disco_local_features, HostB, + ?MODULE, get_sm_features, 50), ejabberd_hooks:add(webadmin_page_host, HostB, ?MODULE, webadmin_page, 50), ejabberd_hooks:add(webadmin_user, HostB, @@ -159,6 +164,8 @@ stop(Host) -> ?MODULE, remove_user, 50), ejabberd_hooks:delete(anonymous_purge_hook, HostB, ?MODULE, remove_user, 50), + ejabberd_hooks:delete(disco_sm_features, HostB, ?MODULE, get_sm_features, 50), + ejabberd_hooks:delete(disco_local_features, HostB, ?MODULE, get_sm_features, 50), ejabberd_hooks:delete(webadmin_page_host, HostB, ?MODULE, webadmin_page, 50), ejabberd_hooks:delete(webadmin_user, HostB, @@ -169,6 +176,21 @@ stop(Host) -> exit(whereis(Proc), stop), ok. +get_sm_features(Acc, _From, _To, "", _Lang) -> + Feats = case Acc of + {result, I} -> I; + _ -> [] + end, + {result, Feats ++ [?NS_FEATURE_MSGOFFLINE]}; + +get_sm_features(_Acc, _From, _To, ?NS_FEATURE_MSGOFFLINE, _Lang) -> + %% override all lesser features... + {result, []}; + +get_sm_features(Acc, _From, _To, _Node, _Lang) -> + Acc. + + store_packet(From, To, Packet) -> Type = exmpp_stanza:get_type(Packet), if