mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Convert to the new #iq record from Exmpp.
SVN Revision: 1524
This commit is contained in:
parent
5e78c53572
commit
d8c3aae412
@ -7,6 +7,11 @@
|
|||||||
Remove the compatibility layer and always call modules with the new
|
Remove the compatibility layer and always call modules with the new
|
||||||
#iq record from Exmpp.
|
#iq record from Exmpp.
|
||||||
|
|
||||||
|
* src/mod_roster.erl, src/mod_vcard.erl, src/adhoc.erl,
|
||||||
|
src/mod_adhoc.erl, src/mod_configure.erl, src/mod_configure2.erl,
|
||||||
|
src/mod_disco.erl, src/mod_last.erl: Convert to the new #iq record
|
||||||
|
from Exmpp.
|
||||||
|
|
||||||
2008-08-06 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-08-06 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
* src/mod_offline.erl, src/mod_offline_odbc.erl, src/mod_echo.erl,
|
* src/mod_offline.erl, src/mod_offline_odbc.erl, src/mod_echo.erl,
|
||||||
|
@ -38,18 +38,16 @@
|
|||||||
|
|
||||||
%% Parse an ad-hoc request. Return either an adhoc_request record or
|
%% Parse an ad-hoc request. Return either an adhoc_request record or
|
||||||
%% an {error, ErrorType} tuple.
|
%% an {error, ErrorType} tuple.
|
||||||
parse_request(IQ) ->
|
parse_request(#iq{type = Type, ns = NS, payload = SubEl, lang = Lang}) ->
|
||||||
try
|
try
|
||||||
SubEl = exmpp_iq:get_request(IQ),
|
case {Type, NS} of
|
||||||
case {exmpp_iq:get_type(IQ), SubEl#xmlel.ns} of
|
|
||||||
{set, ?NS_ADHOC} ->
|
{set, ?NS_ADHOC} ->
|
||||||
?DEBUG("entering parse_request...", []),
|
?DEBUG("entering parse_request...", []),
|
||||||
Lang = exmpp_stanza:get_lang(IQ),
|
|
||||||
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
||||||
SessionID = exmpp_xml:get_attribute(SubEl, 'sessionid', ""),
|
SessionID = exmpp_xml:get_attribute(SubEl, 'sessionid', ""),
|
||||||
Action = exmpp_xml:get_attribute(SubEl, 'action', ""),
|
Action = exmpp_xml:get_attribute(SubEl, 'action', ""),
|
||||||
XData = find_xdata_el(SubEl),
|
XData = find_xdata_el(SubEl),
|
||||||
AllEls = SubEl#xmlel.ns,
|
AllEls = exmpp_xml:get_child_elements(SubEl),
|
||||||
if XData ->
|
if XData ->
|
||||||
Others = lists:delete(XData, AllEls);
|
Others = lists:delete(XData, AllEls);
|
||||||
true ->
|
true ->
|
||||||
|
@ -50,9 +50,9 @@
|
|||||||
start(Host, Opts) ->
|
start(Host, Opts) ->
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
|
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_ADHOC_s,
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_ADHOC,
|
||||||
?MODULE, process_local_iq, IQDisc),
|
?MODULE, process_local_iq, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ADHOC_s,
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ADHOC,
|
||||||
?MODULE, process_sm_iq, IQDisc),
|
?MODULE, process_sm_iq, IQDisc),
|
||||||
|
|
||||||
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
||||||
@ -74,8 +74,8 @@ stop(Host) ->
|
|||||||
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 99),
|
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 99),
|
||||||
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
||||||
|
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ADHOC_s),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ADHOC),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_ADHOC_s).
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_ADHOC).
|
||||||
|
|
||||||
%-------------------------------------------------------------------------
|
%-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -208,19 +208,19 @@ get_sm_features(Acc, _From, _To, _Node, _Lang) ->
|
|||||||
|
|
||||||
%-------------------------------------------------------------------------
|
%-------------------------------------------------------------------------
|
||||||
|
|
||||||
process_local_iq(From, To, IQ) ->
|
process_local_iq(From, To, IQ_Rec) ->
|
||||||
process_adhoc_request(From, To, IQ, adhoc_local_commands).
|
process_adhoc_request(From, To, IQ_Rec, adhoc_local_commands).
|
||||||
|
|
||||||
|
|
||||||
process_sm_iq(From, To, IQ) ->
|
process_sm_iq(From, To, IQ_Rec) ->
|
||||||
process_adhoc_request(From, To, IQ, adhoc_sm_commands).
|
process_adhoc_request(From, To, IQ_Rec, adhoc_sm_commands).
|
||||||
|
|
||||||
|
|
||||||
process_adhoc_request(From, To, IQ, Hook) ->
|
process_adhoc_request(From, To, IQ_Rec, Hook) ->
|
||||||
?DEBUG("About to parse ~p...", [IQ]),
|
?DEBUG("About to parse ~p...", [IQ_Rec]),
|
||||||
case adhoc:parse_request(IQ) of
|
case adhoc:parse_request(IQ_Rec) of
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
exmpp_iq:error(IQ, Error);
|
exmpp_iq:error(IQ_Rec, Error);
|
||||||
#adhoc_request{} = AdhocRequest ->
|
#adhoc_request{} = AdhocRequest ->
|
||||||
Host = To#jid.ldomain,
|
Host = To#jid.ldomain,
|
||||||
% XXX OLD FORMAT: From, To.
|
% XXX OLD FORMAT: From, To.
|
||||||
@ -231,11 +231,11 @@ process_adhoc_request(From, To, IQ, Hook) ->
|
|||||||
ignore ->
|
ignore ->
|
||||||
ignore;
|
ignore;
|
||||||
empty ->
|
empty ->
|
||||||
exmpp_iq:error(IQ, 'item-not-found');
|
exmpp_iq:error(IQ_Rec, 'item-not-found');
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
exmpp_iq:error(IQ, Error);
|
exmpp_iq:error(IQ_Rec, Error);
|
||||||
Command ->
|
Command ->
|
||||||
exmpp_iq:result(IQ, Command)
|
exmpp_iq:result(IQ_Rec, Command)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ stop(Host) ->
|
|||||||
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 50),
|
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 50),
|
||||||
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 50),
|
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 50),
|
||||||
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE, get_local_items, 50),
|
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE, get_local_items, 50),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_ADHOC_s),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_ADHOC),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ADHOC_s).
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ADHOC).
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -47,22 +47,22 @@
|
|||||||
|
|
||||||
start(Host, Opts) ->
|
start(Host, Opts) ->
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_ECONFIGURE_s,
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_ECONFIGURE,
|
||||||
?MODULE, process_local_iq, IQDisc),
|
?MODULE, process_local_iq, IQDisc),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_ECONFIGURE_s).
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_ECONFIGURE).
|
||||||
|
|
||||||
|
|
||||||
process_local_iq(From, To, IQ) ->
|
process_local_iq(From, To, #iq{type = Type, payload = Request} = IQ_Rec) ->
|
||||||
case acl:match_rule(To#jid.ldomain, configure, From) of
|
case acl:match_rule(To#jid.ldomain, configure, From) of
|
||||||
deny ->
|
deny ->
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
exmpp_iq:error(IQ_Rec, 'not-allowed');
|
||||||
allow ->
|
allow ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
case Type of
|
||||||
set ->
|
set ->
|
||||||
exmpp_iq:error(IQ, 'feature-not-implemented');
|
exmpp_iq:error(IQ_Rec, 'feature-not-implemented');
|
||||||
%%case xml:get_tag_attr_s("type", SubEl) of
|
%%case xml:get_tag_attr_s("type", SubEl) of
|
||||||
%% "cancel" ->
|
%% "cancel" ->
|
||||||
%% IQ#iq{type = result,
|
%% IQ#iq{type = result,
|
||||||
@ -96,11 +96,11 @@ process_local_iq(From, To, IQ) ->
|
|||||||
%% sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
|
%% sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
|
||||||
%%end;
|
%%end;
|
||||||
get ->
|
get ->
|
||||||
case process_get(IQ#xmlel.children) of
|
case process_get(Request) of
|
||||||
{result, Res} ->
|
{result, Res} ->
|
||||||
exmpp_iq:result(IQ, Res);
|
exmpp_iq:result(IQ_Rec, Res);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
exmpp_iq:error(IQ, Error)
|
exmpp_iq:error(IQ_Rec, Error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
@ -63,13 +63,13 @@ start(Host, Opts) ->
|
|||||||
ejabberd_local:refresh_iq_handlers(),
|
ejabberd_local:refresh_iq_handlers(),
|
||||||
|
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, atom_to_list(?NS_DISCO_ITEMS),
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS,
|
||||||
?MODULE, process_local_iq_items, IQDisc),
|
?MODULE, process_local_iq_items, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, atom_to_list(?NS_DISCO_INFO),
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO,
|
||||||
?MODULE, process_local_iq_info, IQDisc),
|
?MODULE, process_local_iq_info, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, atom_to_list(?NS_DISCO_ITEMS),
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_DISCO_ITEMS,
|
||||||
?MODULE, process_sm_iq_items, IQDisc),
|
?MODULE, process_sm_iq_items, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, atom_to_list(?NS_DISCO_INFO),
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_DISCO_INFO,
|
||||||
?MODULE, process_sm_iq_info, IQDisc),
|
?MODULE, process_sm_iq_info, IQDisc),
|
||||||
|
|
||||||
catch ets:new(disco_features, [named_table, ordered_set, public]),
|
catch ets:new(disco_features, [named_table, ordered_set, public]),
|
||||||
@ -101,10 +101,10 @@ stop(Host) ->
|
|||||||
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 100),
|
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 100),
|
||||||
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 100),
|
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 100),
|
||||||
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE, get_local_services, 100),
|
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE, get_local_services, 100),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, atom_to_list(?NS_DISCO_ITEMS)),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, atom_to_list(?NS_DISCO_INFO)),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, atom_to_list(?NS_DISCO_ITEMS)),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_DISCO_ITEMS),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, atom_to_list(?NS_DISCO_INFO)),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_DISCO_INFO),
|
||||||
catch ets:match_delete(disco_features, {{'_', Host}}),
|
catch ets:match_delete(disco_features, {{'_', Host}}),
|
||||||
catch ets:match_delete(disco_extra_domains, {{'_', Host}}),
|
catch ets:match_delete(disco_extra_domains, {{'_', Host}}),
|
||||||
ok.
|
ok.
|
||||||
@ -126,75 +126,67 @@ unregister_extra_domain(Host, Domain) ->
|
|||||||
catch ets:new(disco_extra_domains, [named_table, ordered_set, public]),
|
catch ets:new(disco_extra_domains, [named_table, ordered_set, public]),
|
||||||
ets:delete(disco_extra_domains, {Domain, Host}).
|
ets:delete(disco_extra_domains, {Domain, Host}).
|
||||||
|
|
||||||
process_local_iq_items(From, To, IQ) ->
|
process_local_iq_items(From, To, #iq{type = get, payload = SubEl,
|
||||||
case exmpp_iq:get_type(IQ) of
|
lang = Lang} = IQ_Rec) ->
|
||||||
set ->
|
Host = To#jid.ldomain,
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
||||||
get ->
|
|
||||||
SubEl = exmpp_iq:get_request(IQ),
|
|
||||||
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
|
||||||
Host = To#jid.ldomain,
|
|
||||||
Lang = exmpp_stanza:get_lang(IQ),
|
|
||||||
|
|
||||||
% XXX OLD FORMAT: From, To.
|
% XXX OLD FORMAT: From, To.
|
||||||
FromOld = jlib:to_old_jid(From),
|
FromOld = jlib:to_old_jid(From),
|
||||||
ToOld = jlib:to_old_jid(To),
|
ToOld = jlib:to_old_jid(To),
|
||||||
case ejabberd_hooks:run_fold(disco_local_items,
|
case ejabberd_hooks:run_fold(disco_local_items,
|
||||||
Host,
|
Host,
|
||||||
empty,
|
empty,
|
||||||
[FromOld, ToOld, Node, Lang]) of
|
[FromOld, ToOld, Node, Lang]) of
|
||||||
{result, Items} ->
|
{result, Items} ->
|
||||||
% XXX OLD FORMAT: Items might be an #xmlelement.
|
% XXX OLD FORMAT: Items might be an #xmlelement.
|
||||||
ANode = case Node of
|
ANode = case Node of
|
||||||
"" -> [];
|
"" -> [];
|
||||||
_ -> [#xmlattr{name = 'node', value = Node}]
|
_ -> [#xmlattr{name = 'node', value = Node}]
|
||||||
|
end,
|
||||||
|
Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query',
|
||||||
|
attrs = ANode, children = Items},
|
||||||
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
|
{error, Error} ->
|
||||||
|
% XXX OLD FORMAT: Error.
|
||||||
|
exmpp_iq:error(IQ_Rec, Error)
|
||||||
|
end;
|
||||||
|
process_local_iq_items(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
|
|
||||||
|
|
||||||
|
process_local_iq_info(From, To, #iq{type = get, payload = SubEl,
|
||||||
|
lang = Lang} = IQ_Rec) ->
|
||||||
|
Host = To#jid.ldomain,
|
||||||
|
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
||||||
|
% XXX OLD FORMAT: From, To.
|
||||||
|
FromOld = jlib:to_old_jid(From),
|
||||||
|
ToOld = jlib:to_old_jid(To),
|
||||||
|
% XXX OLD FORMAT: Identity might be an #xmlelement.
|
||||||
|
Identity = ejabberd_hooks:run_fold(disco_local_identity,
|
||||||
|
Host,
|
||||||
|
[],
|
||||||
|
[FromOld, ToOld, Node, Lang]),
|
||||||
|
% XXX OLD FORMAT: From, To.
|
||||||
|
case ejabberd_hooks:run_fold(disco_local_features,
|
||||||
|
Host,
|
||||||
|
empty,
|
||||||
|
[FromOld, ToOld, Node, Lang]) of
|
||||||
|
{result, Features} ->
|
||||||
|
ANode = case Node of
|
||||||
|
"" -> [];
|
||||||
|
_ -> [#xmlattr{name = 'node', value = Node}]
|
||||||
end,
|
end,
|
||||||
Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query',
|
Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query',
|
||||||
attrs = ANode, children = Items},
|
attrs = ANode,
|
||||||
exmpp_iq:result(IQ, Result);
|
children = Identity ++ lists:map(fun feature_to_xml/1,
|
||||||
{error, Error} ->
|
Features)},
|
||||||
% XXX OLD FORMAT: Error.
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
exmpp_iq:error(IQ, Error)
|
{error, Error} ->
|
||||||
end
|
exmpp_iq:error(IQ_Rec, Error)
|
||||||
end.
|
end;
|
||||||
|
process_local_iq_info(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
process_local_iq_info(From, To, IQ) ->
|
|
||||||
case exmpp_iq:get_type(IQ) of
|
|
||||||
set ->
|
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
|
||||||
get ->
|
|
||||||
Host = To#jid.ldomain,
|
|
||||||
SubEl = exmpp_iq:get_request(IQ),
|
|
||||||
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
|
||||||
Lang = exmpp_stanza:get_lang(IQ),
|
|
||||||
% XXX OLD FORMAT: From, To.
|
|
||||||
FromOld = jlib:to_old_jid(From),
|
|
||||||
ToOld = jlib:to_old_jid(To),
|
|
||||||
% XXX OLD FORMAT: Identity might be an #xmlelement.
|
|
||||||
Identity = ejabberd_hooks:run_fold(disco_local_identity,
|
|
||||||
Host,
|
|
||||||
[],
|
|
||||||
[FromOld, ToOld, Node, Lang]),
|
|
||||||
% XXX OLD FORMAT: From, To.
|
|
||||||
case ejabberd_hooks:run_fold(disco_local_features,
|
|
||||||
Host,
|
|
||||||
empty,
|
|
||||||
[FromOld, ToOld, Node, Lang]) of
|
|
||||||
{result, Features} ->
|
|
||||||
ANode = case Node of
|
|
||||||
"" -> [];
|
|
||||||
_ -> [#xmlattr{name = 'node', value = Node}]
|
|
||||||
end,
|
|
||||||
Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query',
|
|
||||||
attrs = ANode,
|
|
||||||
children = Identity ++ lists:map(fun feature_to_xml/1,
|
|
||||||
Features)},
|
|
||||||
exmpp_iq:result(IQ, Result);
|
|
||||||
{error, Error} ->
|
|
||||||
exmpp_iq:error(IQ, Error)
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
get_local_identity(Acc, _From, _To, [], _Lang) ->
|
get_local_identity(Acc, _From, _To, [], _Lang) ->
|
||||||
Acc ++ [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [
|
Acc ++ [#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs = [
|
||||||
@ -232,6 +224,10 @@ feature_to_xml({{Feature, _Host}}) ->
|
|||||||
feature_to_xml(Feature) when is_list(Feature) ->
|
feature_to_xml(Feature) when is_list(Feature) ->
|
||||||
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [
|
||||||
#xmlattr{name = 'var', value = Feature}
|
#xmlattr{name = 'var', value = Feature}
|
||||||
|
]};
|
||||||
|
feature_to_xml(Feature) when is_atom(Feature) ->
|
||||||
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [
|
||||||
|
#xmlattr{name = 'var', value = atom_to_list(Feature)}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
domain_to_xml({Domain}) ->
|
domain_to_xml({Domain}) ->
|
||||||
@ -283,50 +279,46 @@ get_vh_services(Host) ->
|
|||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
process_sm_iq_items(From, To, IQ) ->
|
process_sm_iq_items(From, To, #iq{type = get, payload = SubEl,
|
||||||
SubEl = exmpp_iq:get_request(IQ),
|
lang = Lang} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
Host = To#jid.ldomain,
|
||||||
set ->
|
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
||||||
#jid{lnode = LTo, ldomain = ToServer} = To,
|
% XXX OLD FORMAT: From, To.
|
||||||
#jid{lnode = LFrom, ldomain = LServer} = From,
|
FromOld = jlib:to_old_jid(From),
|
||||||
Self = (LTo == LFrom) andalso (ToServer == LServer),
|
ToOld = jlib:to_old_jid(To),
|
||||||
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
case ejabberd_hooks:run_fold(disco_sm_items,
|
||||||
if
|
Host,
|
||||||
Self, Node /= [] ->
|
empty,
|
||||||
%% Here, we treat disco publish attempts to your own JID.
|
[FromOld, ToOld, Node, Lang]) of
|
||||||
Items = SubEl#xmlel.children,
|
{result, Items} ->
|
||||||
case process_disco_publish({LFrom, LServer}, Node, Items) of
|
ANode = case Node of
|
||||||
ok ->
|
"" -> [];
|
||||||
exmpp_iq:result(IQ);
|
_ -> [#xmlattr{name = 'node', value = Node}]
|
||||||
{error, Err} ->
|
end,
|
||||||
exmpp_iq:error(IQ, Err)
|
Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query',
|
||||||
end;
|
attrs = ANode, children = Items},
|
||||||
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
true ->
|
{error, Error} ->
|
||||||
exmpp_iq:error(IQ, 'not-allowed')
|
exmpp_iq:error(IQ_Rec, Error)
|
||||||
|
end;
|
||||||
|
process_sm_iq_items(From, To, #iq{type = set, payload = SubEl} = IQ_Rec) ->
|
||||||
|
#jid{lnode = LTo, ldomain = ToServer} = To,
|
||||||
|
#jid{lnode = LFrom, ldomain = LServer} = From,
|
||||||
|
Self = (LTo == LFrom) andalso (ToServer == LServer),
|
||||||
|
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
||||||
|
if
|
||||||
|
Self, Node /= [] ->
|
||||||
|
%% Here, we treat disco publish attempts to your own JID.
|
||||||
|
Items = SubEl#xmlel.children,
|
||||||
|
case process_disco_publish({LFrom, LServer}, Node, Items) of
|
||||||
|
ok ->
|
||||||
|
exmpp_iq:result(IQ_Rec);
|
||||||
|
{error, Err} ->
|
||||||
|
exmpp_iq:error(IQ_Rec, Err)
|
||||||
end;
|
end;
|
||||||
get ->
|
|
||||||
Host = To#jid.ldomain,
|
true ->
|
||||||
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
exmpp_iq:error(IQ_Rec, 'not-allowed')
|
||||||
Lang = exmpp_stanza:get_lang(IQ),
|
|
||||||
% XXX OLD FORMAT: From, To.
|
|
||||||
FromOld = jlib:to_old_jid(From),
|
|
||||||
ToOld = jlib:to_old_jid(To),
|
|
||||||
case ejabberd_hooks:run_fold(disco_sm_items,
|
|
||||||
Host,
|
|
||||||
empty,
|
|
||||||
[FromOld, ToOld, Node, Lang]) of
|
|
||||||
{result, Items} ->
|
|
||||||
ANode = case Node of
|
|
||||||
"" -> [];
|
|
||||||
_ -> [#xmlattr{name = 'node', value = Node}]
|
|
||||||
end,
|
|
||||||
Result = #xmlel{ns = ?NS_DISCO_ITEMS, name = 'query',
|
|
||||||
attrs = ANode, children = Items},
|
|
||||||
exmpp_iq:result(IQ, Result);
|
|
||||||
{error, Error} ->
|
|
||||||
exmpp_iq:error(IQ, Error)
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_sm_items({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
|
get_sm_items({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
|
||||||
@ -359,41 +351,37 @@ get_sm_items(empty, From, To, _Node, _Lang) ->
|
|||||||
{error, 'not-allowed'}
|
{error, 'not-allowed'}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_sm_iq_info(From, To, IQ) ->
|
process_sm_iq_info(From, To, #iq{type = get, payload = SubEl,
|
||||||
case exmpp_iq:get_type(IQ) of
|
lang = Lang} = IQ_Rec) ->
|
||||||
set ->
|
Host = To#jid.ldomain,
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
||||||
get ->
|
% XXX OLD FORMAT: From, To.
|
||||||
Host = To#jid.ldomain,
|
FromOld = jlib:to_old_jid(From),
|
||||||
SubEl = exmpp_iq:get_request(IQ),
|
ToOld = jlib:to_old_jid(To),
|
||||||
Node = exmpp_xml:get_attribute(SubEl, 'node', ""),
|
% XXX OLD FORMAT: Identity might be an #xmlelement.
|
||||||
Lang = exmpp_stanza:get_lang(IQ),
|
Identity = ejabberd_hooks:run_fold(disco_sm_identity,
|
||||||
% XXX OLD FORMAT: From, To.
|
Host,
|
||||||
FromOld = jlib:to_old_jid(From),
|
[],
|
||||||
ToOld = jlib:to_old_jid(To),
|
[FromOld, ToOld, Node, Lang]),
|
||||||
% XXX OLD FORMAT: Identity might be an #xmlelement.
|
case ejabberd_hooks:run_fold(disco_sm_features,
|
||||||
Identity = ejabberd_hooks:run_fold(disco_sm_identity,
|
Host,
|
||||||
Host,
|
empty,
|
||||||
[],
|
[FromOld, ToOld, Node, Lang]) of
|
||||||
[FromOld, ToOld, Node, Lang]),
|
{result, Features} ->
|
||||||
case ejabberd_hooks:run_fold(disco_sm_features,
|
ANode = case Node of
|
||||||
Host,
|
"" -> [];
|
||||||
empty,
|
_ -> [#xmlattr{name = 'node', value = Node}]
|
||||||
[FromOld, ToOld, Node, Lang]) of
|
end,
|
||||||
{result, Features} ->
|
Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query',
|
||||||
ANode = case Node of
|
attrs = ANode,
|
||||||
"" -> [];
|
children = Identity ++ lists:map(fun feature_to_xml/1,
|
||||||
_ -> [#xmlattr{name = 'node', value = Node}]
|
Features)},
|
||||||
end,
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
Result = #xmlel{ns = ?NS_DISCO_INFO, name = 'query',
|
{error, Error} ->
|
||||||
attrs = ANode,
|
exmpp_iq:error(IQ_Rec, Error)
|
||||||
children = Identity ++ lists:map(fun feature_to_xml/1,
|
end;
|
||||||
Features)},
|
process_sm_iq_info(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
exmpp_iq:result(IQ, Result);
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
{error, Error} ->
|
|
||||||
exmpp_iq:error(IQ, Error)
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
get_sm_identity(Acc, _From, _To, _Node, _Lang) ->
|
get_sm_identity(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
@ -52,9 +52,9 @@ start(Host, Opts) ->
|
|||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
{attributes, record_info(fields, last_activity)}]),
|
{attributes, record_info(fields, last_activity)}]),
|
||||||
update_table(),
|
update_table(),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY_s,
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY,
|
||||||
?MODULE, process_local_iq, IQDisc),
|
?MODULE, process_local_iq, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY_s,
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY,
|
||||||
?MODULE, process_sm_iq, IQDisc),
|
?MODULE, process_sm_iq, IQDisc),
|
||||||
ejabberd_hooks:add(remove_user, Host,
|
ejabberd_hooks:add(remove_user, Host,
|
||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
@ -66,62 +66,56 @@ stop(Host) ->
|
|||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:delete(unset_presence_hook, Host,
|
ejabberd_hooks:delete(unset_presence_hook, Host,
|
||||||
?MODULE, on_presence_update, 50),
|
?MODULE, on_presence_update, 50),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY_s),
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_LAST_ACTIVITY),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY_s).
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_LAST_ACTIVITY).
|
||||||
|
|
||||||
process_local_iq(_From, _To, IQ) ->
|
process_local_iq(_From, _To, #iq{type = get} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
Sec = trunc(element(1, erlang:statistics(wall_clock))/1000),
|
||||||
set ->
|
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', attrs =
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
[#xmlattr{name = 'seconds', value = integer_to_list(Sec)}]},
|
||||||
get ->
|
exmpp_iq:result(IQ_Rec, Response);
|
||||||
Sec = trunc(element(1, erlang:statistics(wall_clock))/1000),
|
process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query', attrs =
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
[#xmlattr{name = 'seconds', value = integer_to_list(Sec)}]},
|
|
||||||
exmpp_iq:result(IQ, Response)
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
process_sm_iq(From, To, IQ) ->
|
process_sm_iq(From, To, #iq{type = get} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
User = To#jid.lnode,
|
||||||
set ->
|
Server = To#jid.ldomain,
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
{Subscription, _Groups} =
|
||||||
get ->
|
ejabberd_hooks:run_fold(
|
||||||
User = To#jid.lnode,
|
roster_get_jid_info, Server,
|
||||||
Server = To#jid.ldomain,
|
{none, []}, [User, Server, From]),
|
||||||
{Subscription, _Groups} =
|
if
|
||||||
ejabberd_hooks:run_fold(
|
(Subscription == both) or (Subscription == from) ->
|
||||||
roster_get_jid_info, Server,
|
UserListRecord = ejabberd_hooks:run_fold(
|
||||||
{none, []}, [User, Server, From]),
|
privacy_get_user_list, Server,
|
||||||
if
|
#userlist{},
|
||||||
(Subscription == both) or (Subscription == from) ->
|
[User, Server]),
|
||||||
UserListRecord = ejabberd_hooks:run_fold(
|
case ejabberd_hooks:run_fold(
|
||||||
privacy_get_user_list, Server,
|
privacy_check_packet, Server,
|
||||||
#userlist{},
|
allow,
|
||||||
[User, Server]),
|
[User, Server, UserListRecord,
|
||||||
case ejabberd_hooks:run_fold(
|
{From, To,
|
||||||
privacy_check_packet, Server,
|
exmpp_presence:available()},
|
||||||
allow,
|
out]) of
|
||||||
[User, Server, UserListRecord,
|
allow ->
|
||||||
{From, To,
|
get_last(IQ_Rec, User, Server);
|
||||||
exmpp_presence:available()},
|
deny ->
|
||||||
out]) of
|
exmpp_iq:error(IQ_Rec, 'not-allowed')
|
||||||
allow ->
|
end;
|
||||||
get_last(IQ, User, Server);
|
true ->
|
||||||
deny ->
|
exmpp_iq:error(IQ_Rec, 'not-allowed')
|
||||||
exmpp_iq:error(IQ, 'not-allowed')
|
end;
|
||||||
end;
|
process_sm_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
true ->
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
exmpp_iq:error(IQ, 'not-allowed')
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% TODO: This function could use get_last_info/2
|
%% TODO: This function could use get_last_info/2
|
||||||
get_last(IQ, LUser, LServer) ->
|
get_last(IQ_Rec, LUser, LServer) ->
|
||||||
case catch mnesia:dirty_read(last_activity, {LUser, LServer}) of
|
case catch mnesia:dirty_read(last_activity, {LUser, LServer}) of
|
||||||
{'EXIT', _Reason} ->
|
{'EXIT', _Reason} ->
|
||||||
exmpp_iq:error(IQ, 'internal-server-error');
|
exmpp_iq:error(IQ_Rec, 'internal-server-error');
|
||||||
[] ->
|
[] ->
|
||||||
exmpp_iq:error(IQ, 'service-unavailable');
|
exmpp_iq:error(IQ_Rec, 'service-unavailable');
|
||||||
[#last_activity{timestamp = TimeStamp, status = Status}] ->
|
[#last_activity{timestamp = TimeStamp, status = Status}] ->
|
||||||
{MegaSecs, Secs, _MicroSecs} = now(),
|
{MegaSecs, Secs, _MicroSecs} = now(),
|
||||||
TimeStamp2 = MegaSecs * 1000000 + Secs,
|
TimeStamp2 = MegaSecs * 1000000 + Secs,
|
||||||
@ -129,7 +123,7 @@ get_last(IQ, LUser, LServer) ->
|
|||||||
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query',
|
Response = #xmlel{ns = ?NS_LAST_ACTIVITY, name = 'query',
|
||||||
attrs = [#xmlattr{name = 'seconds', value = integer_to_list(Sec)}],
|
attrs = [#xmlattr{name = 'seconds', value = integer_to_list(Sec)}],
|
||||||
children = [#xmlcdata{cdata = list_to_binary(Status)}]},
|
children = [#xmlcdata{cdata = list_to_binary(Status)}]},
|
||||||
exmpp_iq:result(IQ, Response)
|
exmpp_iq:result(IQ_Rec, Response)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,8 +78,7 @@ start(Host, Opts) ->
|
|||||||
?MODULE, webadmin_page, 50),
|
?MODULE, webadmin_page, 50),
|
||||||
ejabberd_hooks:add(webadmin_user, Host,
|
ejabberd_hooks:add(webadmin_user, Host,
|
||||||
?MODULE, webadmin_user, 50),
|
?MODULE, webadmin_user, 50),
|
||||||
% XXX OLD FORMAT: NS as string.
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ROSTER,
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, atom_to_list(?NS_ROSTER),
|
|
||||||
?MODULE, process_iq, IQDisc).
|
?MODULE, process_iq, IQDisc).
|
||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
@ -103,41 +102,38 @@ stop(Host) ->
|
|||||||
?MODULE, webadmin_page, 50),
|
?MODULE, webadmin_page, 50),
|
||||||
ejabberd_hooks:delete(webadmin_user, Host,
|
ejabberd_hooks:delete(webadmin_user, Host,
|
||||||
?MODULE, webadmin_user, 50),
|
?MODULE, webadmin_user, 50),
|
||||||
% XXX OLD FORMAT: NS as string.
|
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
|
||||||
atom_to_list(?NS_ROSTER)).
|
?NS_ROSTER).
|
||||||
|
|
||||||
|
|
||||||
process_iq(From, To, IQ) ->
|
process_iq(From, To, IQ_Rec) ->
|
||||||
#jid{ldomain = LServer} = From,
|
#jid{ldomain = LServer} = From,
|
||||||
case lists:member(LServer, ?MYHOSTS) of
|
case lists:member(LServer, ?MYHOSTS) of
|
||||||
true ->
|
true ->
|
||||||
process_local_iq(From, To, IQ);
|
process_local_iq(From, To, IQ_Rec);
|
||||||
_ ->
|
_ ->
|
||||||
exmpp_iq:error(IQ, 'item-not-found')
|
exmpp_iq:error(IQ_Rec, 'item-not-found')
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_local_iq(From, To, IQ) ->
|
process_local_iq(From, To, #iq{type = get} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
process_iq_get(From, To, IQ_Rec);
|
||||||
set ->
|
process_local_iq(From, To, #iq{type = set} = IQ_Rec) ->
|
||||||
process_iq_set(From, To, IQ);
|
process_iq_set(From, To, IQ_Rec).
|
||||||
get ->
|
|
||||||
process_iq_get(From, To, IQ)
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
process_iq_get(From, To, IQ) ->
|
process_iq_get(From, To, IQ_Rec) ->
|
||||||
LUser = From#jid.lnode,
|
LUser = From#jid.lnode,
|
||||||
LServer = From#jid.ldomain,
|
LServer = From#jid.ldomain,
|
||||||
US = {LUser, LServer},
|
US = {LUser, LServer},
|
||||||
case catch ejabberd_hooks:run_fold(roster_get, To#jid.ldomain, [], [US]) of
|
case catch ejabberd_hooks:run_fold(roster_get, To#jid.ldomain, [], [US]) of
|
||||||
Items when is_list(Items) ->
|
Items when is_list(Items) ->
|
||||||
XItems = lists:map(fun item_to_xml/1, Items),
|
XItems = lists:map(fun item_to_xml/1, Items),
|
||||||
exmpp_iq:result(IQ, #xmlel{ns = ?NS_ROSTER, name = 'query',
|
Result = #xmlel{ns = ?NS_ROSTER, name = 'query',
|
||||||
children = XItems});
|
children = XItems},
|
||||||
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
_ ->
|
_ ->
|
||||||
exmpp_iq:error(IQ, 'internal-server-error')
|
exmpp_iq:error(IQ_Rec, 'internal-server-error')
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_user_roster(Acc, US) ->
|
get_user_roster(Acc, US) ->
|
||||||
@ -183,14 +179,14 @@ item_to_xml(Item) ->
|
|||||||
#xmlel{ns = ?NS_ROSTER, name = 'item', attrs = Attrs4, children = SubEls}.
|
#xmlel{ns = ?NS_ROSTER, name = 'item', attrs = Attrs4, children = SubEls}.
|
||||||
|
|
||||||
|
|
||||||
process_iq_set(From, To, IQ) ->
|
process_iq_set(From, To, #iq{payload = Request} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_request(IQ) of
|
case Request of
|
||||||
#xmlel{children = Els} ->
|
#xmlel{children = Els} ->
|
||||||
lists:foreach(fun(El) -> process_item_set(From, To, El) end, Els);
|
lists:foreach(fun(El) -> process_item_set(From, To, El) end, Els);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
exmpp_iq:result(IQ).
|
exmpp_iq:result(IQ_Rec).
|
||||||
|
|
||||||
process_item_set(From, To, #xmlel{} = Item) ->
|
process_item_set(From, To, #xmlel{} = Item) ->
|
||||||
try
|
try
|
||||||
|
@ -84,11 +84,9 @@ start(Host, Opts) ->
|
|||||||
ejabberd_hooks:add(remove_user, Host,
|
ejabberd_hooks:add(remove_user, Host,
|
||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
% XXX OLD FORMAT: NS as string.
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VCARD,
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, atom_to_list(?NS_VCARD),
|
|
||||||
?MODULE, process_local_iq, IQDisc),
|
?MODULE, process_local_iq, IQDisc),
|
||||||
% XXX OLD FORMAT: NS as string.
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_VCARD,
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, atom_to_list(?NS_VCARD),
|
|
||||||
?MODULE, process_sm_iq, IQDisc),
|
?MODULE, process_sm_iq, IQDisc),
|
||||||
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
|
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
|
||||||
MyHost = gen_mod:get_opt_host(Host, Opts, "vjud.@HOST@"),
|
MyHost = gen_mod:get_opt_host(Host, Opts, "vjud.@HOST@"),
|
||||||
@ -126,12 +124,10 @@ loop(Host, ServerHost) ->
|
|||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
ejabberd_hooks:delete(remove_user, Host,
|
ejabberd_hooks:delete(remove_user, Host,
|
||||||
?MODULE, remove_user, 50),
|
?MODULE, remove_user, 50),
|
||||||
% XXX OLD FORMAT: NS as string.
|
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
|
||||||
atom_to_list(?NS_VCARD)),
|
?NS_VCARD),
|
||||||
% XXX OLD FORMAT: NS as string.
|
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
|
||||||
atom_to_list(?NS_VCARD)),
|
?NS_VCARD),
|
||||||
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
|
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
|
||||||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
||||||
Proc ! stop,
|
Proc ! stop,
|
||||||
@ -155,63 +151,53 @@ get_sm_features(Acc, _From, _To, Node, _Lang) ->
|
|||||||
Acc
|
Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_local_iq(_From, _To, IQ) ->
|
process_local_iq(_From, _To, #iq{type = get, lang = Lang} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
Result = #xmlel{ns = ?NS_VCARD, name = 'vCard', children = [
|
||||||
set ->
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'FN'},
|
||||||
exmpp_iq:error(IQ, 'not-allowed');
|
"ejabberd"),
|
||||||
get ->
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'URL'},
|
||||||
Lang = case exmpp_stanza:get_lang(IQ) of
|
?EJABBERD_URI),
|
||||||
undefined -> "";
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'DESC'},
|
||||||
L -> L
|
translate:translate(Lang, "Erlang Jabber Server") ++
|
||||||
end,
|
"\nCopyright (c) 2002-2008 ProcessOne"),
|
||||||
Result = #xmlel{ns = ?NS_VCARD, name = 'vCard', children = [
|
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'BDAY'},
|
||||||
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'FN'},
|
"2002-11-16")
|
||||||
"ejabberd"),
|
]},
|
||||||
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'URL'},
|
exmpp_iq:result(IQ_Rec, Result);
|
||||||
?EJABBERD_URI),
|
process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||||
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'DESC'},
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||||
translate:translate(Lang, "Erlang Jabber Server") ++
|
|
||||||
"\nCopyright (c) 2002-2008 ProcessOne"),
|
|
||||||
exmpp_xml:set_cdata(#xmlel{ns = ?NS_VCARD, name = 'BDAY'},
|
|
||||||
"2002-11-16")
|
|
||||||
]},
|
|
||||||
exmpp_iq:result(IQ, Result)
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
process_sm_iq(From, To, IQ) ->
|
process_sm_iq(_From, To, #iq{type = get} = IQ_Rec) ->
|
||||||
case exmpp_iq:get_type(IQ) of
|
#jid{lnode = LUser, ldomain = LServer} = To,
|
||||||
set ->
|
US = {LUser, LServer},
|
||||||
#jid{node = User, ldomain = LServer} = From,
|
F = fun() ->
|
||||||
case lists:member(LServer, ?MYHOSTS) of
|
mnesia:read({vcard, US})
|
||||||
true ->
|
end,
|
||||||
set_vcard(User, LServer, exmpp_iq:get_request(IQ)),
|
[VCard | _] = case mnesia:transaction(F) of
|
||||||
exmpp_iq:result(IQ);
|
{atomic, Rs} ->
|
||||||
false ->
|
lists:map(fun(R) ->
|
||||||
exmpp_iq:error(IQ, 'not-allowed')
|
case R#vcard.vcard of
|
||||||
end;
|
#xmlel{} = E ->
|
||||||
get ->
|
E;
|
||||||
#jid{lnode = LUser, ldomain = LServer} = To,
|
#xmlelement{} = E ->
|
||||||
US = {LUser, LServer},
|
% XXX OLD FORMAT: Base contains old elements.
|
||||||
F = fun() ->
|
io:format("VCARD: Old element in base: ~p~n", [E]),
|
||||||
mnesia:read({vcard, US})
|
exmpp_xml:xmlelement_to_xmlel(E, [?NS_VCARD], [])
|
||||||
end,
|
end
|
||||||
Els = case mnesia:transaction(F) of
|
end, Rs);
|
||||||
{atomic, Rs} ->
|
{aborted, _Reason} ->
|
||||||
lists:map(fun(R) ->
|
[]
|
||||||
case R#vcard.vcard of
|
end,
|
||||||
#xmlel{} = E ->
|
exmpp_iq:result(IQ_Rec, VCard);
|
||||||
E;
|
process_sm_iq(From, _To, #iq{type = set, payload = Request} = IQ_Rec) ->
|
||||||
#xmlelement{} = E ->
|
#jid{node = User, ldomain = LServer} = From,
|
||||||
% XXX OLD FORMAT: Base contains old elements.
|
case lists:member(LServer, ?MYHOSTS) of
|
||||||
io:format("VCARD: Old element in base: ~p~n", [E]),
|
true ->
|
||||||
exmpp_xml:xmlelement_to_xmlel(E, [?NS_VCARD], [])
|
set_vcard(User, LServer, Request),
|
||||||
end
|
exmpp_iq:result(IQ_Rec);
|
||||||
end, Rs);
|
false ->
|
||||||
{aborted, _Reason} ->
|
exmpp_iq:error(IQ_Rec, 'not-allowed')
|
||||||
[]
|
|
||||||
end,
|
|
||||||
exmpp_iq:result(IQ, Els)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_vcard(User, LServer, VCARD) ->
|
set_vcard(User, LServer, VCARD) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user