mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Convert to exmpp.
PR: EJABP-1 SVN Revision: 1610
This commit is contained in:
parent
ca7a0813b4
commit
78466384c4
@ -3,6 +3,9 @@
|
||||
* src/ejabberd_local.erl: Fix a bug where an error stanza was not
|
||||
created correctly, leading to ejabberd_c2s crash.
|
||||
|
||||
* src/mod_stats.erl, src/mod_service_log.erl, src/mod_time.erl:
|
||||
Convert to exmpp.
|
||||
|
||||
2008-10-06 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||
|
||||
* src/ejabberd_sm.erl (process_iq/3): Fix a bug where we were matching
|
||||
|
@ -34,8 +34,9 @@
|
||||
log_user_send/3,
|
||||
log_user_receive/4]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
start(Host, _Opts) ->
|
||||
ejabberd_hooks:add(user_send_packet, Host,
|
||||
@ -52,26 +53,21 @@ stop(Host) ->
|
||||
ok.
|
||||
|
||||
log_user_send(From, To, Packet) ->
|
||||
log_packet(From, To, Packet, From#jid.lserver).
|
||||
log_packet(From, To, Packet, From#jid.ldomain).
|
||||
|
||||
log_user_receive(_JID, From, To, Packet) ->
|
||||
log_packet(From, To, Packet, To#jid.lserver).
|
||||
log_packet(From, To, Packet, To#jid.ldomain).
|
||||
|
||||
|
||||
log_packet(From, To, {xmlelement, Name, Attrs, Els}, Host) ->
|
||||
log_packet(From, To, Packet, Host) ->
|
||||
Loggers = gen_mod:get_module_opt(Host, ?MODULE, loggers, []),
|
||||
ServerJID = #jid{user = "", server = Host, resource = "",
|
||||
luser = "", lserver = Host, lresource = ""},
|
||||
NewAttrs = jlib:replace_from_to_attrs(jlib:jid_to_string(From),
|
||||
jlib:jid_to_string(To),
|
||||
Attrs),
|
||||
FixedPacket = {xmlelement, Name, NewAttrs, Els},
|
||||
ServerJID = #jid{domain = Host, ldomain = Host},
|
||||
FixedPacket = exmpp_stanza:set_jids(Packet, From, To),
|
||||
lists:foreach(
|
||||
fun(Logger) ->
|
||||
ejabberd_router:route(
|
||||
ServerJID,
|
||||
#jid{user = "", server = Logger, resource = "",
|
||||
luser = "", lserver = Logger, lresource = ""},
|
||||
{xmlelement, "route", [], [FixedPacket]})
|
||||
#jid{domain = Logger, ldomain = Logger},
|
||||
#xmlel{name = 'route', children = [FixedPacket]})
|
||||
end, Loggers).
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
stop/1,
|
||||
process_local_iq/3]).
|
||||
|
||||
-include("jlib.hrl").
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
start(Host, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||
@ -44,33 +44,26 @@ stop(Host) ->
|
||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_STATS).
|
||||
|
||||
|
||||
process_local_iq(_From, To, #iq{id = _ID, type = Type,
|
||||
xmlns = XMLNS, sub_el = SubEl} = IQ) ->
|
||||
%%Lang = xml:get_tag_attr_s("xml:lang", SubEl),
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
get ->
|
||||
{xmlelement, _, _Attrs, Els} = SubEl,
|
||||
Node = string:tokens(xml:get_tag_attr_s("node", SubEl), "/"),
|
||||
Names = get_names(Els, []),
|
||||
process_local_iq(_From, To, #iq{type = get,
|
||||
ns = XMLNS, payload = SubEl} = IQ_Rec) ->
|
||||
Node = string:tokens(exmpp_xml:get_attribute(SubEl, 'node', ""), "/"),
|
||||
Names = get_names(exmpp_xml:get_child_elements(SubEl), []),
|
||||
|
||||
case get_local_stats(To#jid.server, Node, Names) of
|
||||
case get_local_stats(To#jid.domain, Node, Names) of
|
||||
{result, Res} ->
|
||||
IQ#iq{type = result,
|
||||
sub_el = [{xmlelement, "query",
|
||||
[{"xmlns", XMLNS}],
|
||||
Res}]};
|
||||
Result = #xmlel{ns = XMLNS, name = 'query', children = Res},
|
||||
exmpp_iq:result(IQ_Rec, Result);
|
||||
{error, Error} ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, Error]}
|
||||
end
|
||||
end.
|
||||
exmpp_iq:error(IQ_Rec, Error)
|
||||
end;
|
||||
process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||
|
||||
|
||||
get_names([], Res) ->
|
||||
Res;
|
||||
get_names([{xmlelement, "stat", Attrs, _} | Els], Res) ->
|
||||
Name = xml:get_attr_s("name", Attrs),
|
||||
get_names([#xmlel{name = 'stat', attrs = Attrs} | Els], Res) ->
|
||||
Name = exmpp_xml:get_attribute_from_list(Attrs, 'name', ""),
|
||||
case Name of
|
||||
"" ->
|
||||
get_names(Els, Res);
|
||||
@ -81,7 +74,7 @@ get_names([_ | Els], Res) ->
|
||||
get_names(Els, Res).
|
||||
|
||||
|
||||
-define(STAT(Name), {xmlelement, "stat", [{"name", Name}], []}).
|
||||
-define(STAT(Name), #xmlel{ns = ?NS_STATS, name = 'stat', attrs = [#xmlattr{name = 'name', value = Name}]}).
|
||||
|
||||
get_local_stats(_Server, [], []) ->
|
||||
{result,
|
||||
@ -110,30 +103,30 @@ get_local_stats(_Server, ["running nodes", _], []) ->
|
||||
get_local_stats(_Server, ["running nodes", ENode], Names) ->
|
||||
case search_running_node(ENode) of
|
||||
false ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND};
|
||||
{error, 'item-not-found'};
|
||||
Node ->
|
||||
{result,
|
||||
lists:map(fun(Name) -> get_node_stat(Node, Name) end, Names)}
|
||||
end;
|
||||
|
||||
get_local_stats(_Server, _, _) ->
|
||||
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}.
|
||||
{error, 'feature-not-implemented'}.
|
||||
|
||||
|
||||
|
||||
-define(STATVAL(Val, Unit),
|
||||
{xmlelement, "stat",
|
||||
[{"name", Name},
|
||||
{"units", Unit},
|
||||
{"value", Val}
|
||||
], []}).
|
||||
#xmlel{ns = ?NS_STATS, name = 'stat', attrs =
|
||||
[#xmlattr{name = 'name', value = Name},
|
||||
#xmlattr{name = 'units', value = Unit},
|
||||
#xmlattr{name = 'value', value = Val}
|
||||
]}).
|
||||
|
||||
-define(STATERR(Code, Desc),
|
||||
{xmlelement, "stat",
|
||||
[{"name", Name}],
|
||||
[{xmlelement, "error",
|
||||
[{"code", Code}],
|
||||
[{xmlcdata, Desc}]}]}).
|
||||
#xmlel{ns = ?NS_STATS, name = 'stat', attrs=
|
||||
[#xmlattr{name = 'name', value = Name}], children =
|
||||
[#xmlel{ns = ?NS_STATS, name = 'error', attrs =
|
||||
[#xmlattr{name = 'code', value = Code}], children =
|
||||
[#xmlcdata{cdata = list_to_binary(Desc)}]}]}).
|
||||
|
||||
|
||||
get_local_stat(Server, [], Name) when Name == "users/online" ->
|
||||
|
@ -33,8 +33,9 @@
|
||||
stop/1,
|
||||
process_local_iq/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
|
||||
start(Host, Opts) ->
|
||||
@ -45,17 +46,15 @@ start(Host, Opts) ->
|
||||
stop(Host) ->
|
||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_TIME).
|
||||
|
||||
process_local_iq(_From, _To, #iq{type = Type, sub_el = SubEl} = IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
get ->
|
||||
process_local_iq(_From, _To, #iq{type = get} = IQ_Rec) ->
|
||||
UTC = jlib:timestamp_to_iso(calendar:universal_time()),
|
||||
IQ#iq{type = result,
|
||||
sub_el = [{xmlelement, "query",
|
||||
[{"xmlns", ?NS_TIME}],
|
||||
[{xmlelement, "utc", [],
|
||||
[{xmlcdata, UTC}]}]}]}
|
||||
end.
|
||||
Result = #xmlel{ns = ?NS_TIME, name = 'query', children = [
|
||||
#xmlel{ns = ?NS_TIME, name = 'utc', children = [
|
||||
#xmlcdata{cdata = list_to_binary(UTC)}
|
||||
]}
|
||||
]},
|
||||
exmpp_iq:result(IQ_Rec, Result);
|
||||
process_local_iq(_From, _To, #iq{type = set} = IQ_Rec) ->
|
||||
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user