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