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

Move some namespaces definitions into header file

This commit is contained in:
Evgeniy Khramtsov 2014-07-20 22:20:44 +04:00
parent c068712373
commit 014d61955c
2 changed files with 19 additions and 20 deletions

View File

@ -144,5 +144,8 @@
-define(NS_MEDIA, <<"urn:xmpp:media-element">>).
-define(NS_BOB, <<"urn:xmpp:bob">>).
-define(NS_PING, <<"urn:xmpp:ping">>).
-define(NS_CARBONS_2, <<"urn:xmpp:carbons:2">>).
-define(NS_CARBONS_1, <<"urn:xmpp:carbons:1">>).
-define(NS_FORWARD, <<"urn:xmpp:forward:0">>).
-define(NS_STREAM_MGMT_2, <<"urn:xmpp:sm:2">>).
-define(NS_STREAM_MGMT_3, <<"urn:xmpp:sm:3">>).

View File

@ -41,10 +41,6 @@
remove_connection/4,
is_carbon_copy/1]).
-define(NS_CC_2, <<"urn:xmpp:carbons:2">>).
-define(NS_CC_1, <<"urn:xmpp:carbons:1">>).
-define(NS_FORWARD, <<"urn:xmpp:forward:0">>).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("jlib.hrl").
@ -64,8 +60,8 @@ is_carbon_copy(Packet, Direction) ->
case xml:get_subtag(Packet, Direction) of
#xmlel{name = Direction, attrs = Attrs} ->
case xml:get_attr_s(<<"xmlns">>, Attrs) of
?NS_CC_2 -> true;
?NS_CC_1 -> true;
?NS_CARBONS_2 -> true;
?NS_CARBONS_1 -> true;
_ -> false
end;
_ -> false
@ -73,8 +69,8 @@ is_carbon_copy(Packet, Direction) ->
start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts,fun gen_iq_handler:check_type/1, one_queue),
mod_disco:register_feature(Host, ?NS_CC_1),
mod_disco:register_feature(Host, ?NS_CC_2),
mod_disco:register_feature(Host, ?NS_CARBONS_1),
mod_disco:register_feature(Host, ?NS_CARBONS_2),
Fields = record_info(fields, ?TABLE),
try mnesia:table_info(?TABLE, attributes) of
Fields -> ok;
@ -90,23 +86,23 @@ start(Host, Opts) ->
%% why priority 89: to define clearly that we must run BEFORE mod_logdb hook (90)
ejabberd_hooks:add(user_send_packet,Host, ?MODULE, user_send_packet, 89),
ejabberd_hooks:add(user_receive_packet,Host, ?MODULE, user_receive_packet, 89),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CC_2, ?MODULE, iq_handler2, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CC_1, ?MODULE, iq_handler1, IQDisc).
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2, ?MODULE, iq_handler2, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_1, ?MODULE, iq_handler1, IQDisc).
stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_CC_1),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_CC_2),
mod_disco:unregister_feature(Host, ?NS_CC_2),
mod_disco:unregister_feature(Host, ?NS_CC_1),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_1),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_CARBONS_2),
mod_disco:unregister_feature(Host, ?NS_CARBONS_2),
mod_disco:unregister_feature(Host, ?NS_CARBONS_1),
%% why priority 89: to define clearly that we must run BEFORE mod_logdb hook (90)
ejabberd_hooks:delete(user_send_packet,Host, ?MODULE, user_send_packet, 89),
ejabberd_hooks:delete(user_receive_packet,Host, ?MODULE, user_receive_packet, 89),
ejabberd_hooks:delete(unset_presence_hook,Host, ?MODULE, remove_connection, 10).
iq_handler2(From, To, IQ) ->
iq_handler(From, To, IQ, ?NS_CC_2).
iq_handler(From, To, IQ, ?NS_CARBONS_2).
iq_handler1(From, To, IQ) ->
iq_handler(From, To, IQ, ?NS_CC_1).
iq_handler(From, To, IQ, ?NS_CARBONS_1).
iq_handler(From, _To, #iq{type=set, sub_el = #xmlel{name = Operation, children = []}} = IQ, CC)->
?DEBUG("carbons IQ received: ~p", [IQ]),
@ -208,7 +204,7 @@ send_copies(JID, To, Packet, Direction)->
end, TargetJIDs),
ok.
build_forward_packet(JID, Packet, Sender, Dest, Direction, ?NS_CC_2) ->
build_forward_packet(JID, Packet, Sender, Dest, Direction, ?NS_CARBONS_2) ->
#xmlel{name = <<"message">>,
attrs = [{<<"xmlns">>, <<"jabber:client">>},
{<<"type">>, <<"chat">>},
@ -216,7 +212,7 @@ build_forward_packet(JID, Packet, Sender, Dest, Direction, ?NS_CC_2) ->
{<<"to">>, jlib:jid_to_string(Dest)}],
children = [
#xmlel{name = list_to_binary(atom_to_list(Direction)),
attrs = [{<<"xmlns">>, ?NS_CC_2}],
attrs = [{<<"xmlns">>, ?NS_CARBONS_2}],
children = [
#xmlel{name = <<"forwarded">>,
attrs = [{<<"xmlns">>, ?NS_FORWARD}],
@ -224,7 +220,7 @@ build_forward_packet(JID, Packet, Sender, Dest, Direction, ?NS_CC_2) ->
complete_packet(JID, Packet, Direction)]}
]}
]};
build_forward_packet(JID, Packet, Sender, Dest, Direction, ?NS_CC_1) ->
build_forward_packet(JID, Packet, Sender, Dest, Direction, ?NS_CARBONS_1) ->
#xmlel{name = <<"message">>,
attrs = [{<<"xmlns">>, <<"jabber:client">>},
{<<"type">>, <<"chat">>},
@ -232,7 +228,7 @@ build_forward_packet(JID, Packet, Sender, Dest, Direction, ?NS_CC_1) ->
{<<"to">>, jlib:jid_to_string(Dest)}],
children = [
#xmlel{name = list_to_binary(atom_to_list(Direction)),
attrs = [{<<"xmlns">>, ?NS_CC_1}]},
attrs = [{<<"xmlns">>, ?NS_CARBONS_1}]},
#xmlel{name = <<"forwarded">>,
attrs = [{<<"xmlns">>, ?NS_FORWARD}],
children = [complete_packet(JID, Packet, Direction)]}