25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-10-15 15:19:20 +02:00

* src/jlib.hrl: Added declaration of "iq" record

* (all): Updated to use "iq" record

SVN Revision: 186
This commit is contained in:
Alexey Shchepin 2003-12-17 20:13:21 +00:00
parent 4768cd2f26
commit b3b09bcfd8
24 changed files with 605 additions and 578 deletions

View File

@ -1,3 +1,8 @@
2003-12-17 Alexey Shchepin <alexey@sevcom.net>
* src/jlib.hrl: Added declaration of "iq" record
* (all): Updated to use "iq" record
2003-12-14 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_local.erl: Replaced register_local_route to

View File

@ -1,7 +1,7 @@
%%%----------------------------------------------------------------------
%%% File : ejabberd_c2s.erl
%%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose :
%%% Purpose : Serve C2S connection
%%% Created : 16 Nov 2002 by Alexey Shchepin <alexey@sevcom.net>
%%% Id : $Id$
%%%----------------------------------------------------------------------
@ -124,7 +124,7 @@ init([{SockMod, Socket}, Opts]) ->
%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
case xml:get_attr_s("xmlns:stream", Attrs) of
?NS_STREAM ->
case xml:get_attr_s("version", Attrs) of
@ -195,12 +195,12 @@ wait_for_stream(closed, StateData) ->
wait_for_auth({xmlstreamelement, El}, StateData) ->
case is_auth_packet(El) of
{auth, ID, get, {"", _, _, _}} ->
{auth, _ID, get, {"", _, _, _}} ->
Err = jlib:make_error_reply(El, ?ERR_BAD_REQUEST),
send_element(StateData, Err),
{next_state, wait_for_auth, StateData};
{auth, ID, get, {U, _, _, _}} ->
{xmlelement, Name, Attrs, Els} = jlib:make_result_iq_reply(El),
{auth, _ID, get, {U, _, _, _}} ->
{xmlelement, Name, Attrs, _Els} = jlib:make_result_iq_reply(El),
Res = case ejabberd_auth:plain_password_required() of
false ->
{xmlelement, Name, Attrs,
@ -219,11 +219,11 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
end,
send_element(StateData, Res),
{next_state, wait_for_auth, StateData};
{auth, ID, set, {U, P, D, ""}} ->
{auth, _ID, set, {U, P, D, ""}} ->
Err = jlib:make_error_reply(El, ?ERR_AUTH_NO_RESOURCE_PROVIDED),
send_element(StateData, Err),
{next_state, wait_for_auth, StateData};
{auth, ID, set, {U, P, D, R}} ->
{auth, _ID, set, {U, P, D, R}} ->
io:format("AUTH: ~p~n", [{U, P, D, R}]),
JID = jlib:make_jid(U, StateData#state.server, R),
case (JID /= error) andalso
@ -286,10 +286,9 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
end;
_ ->
case jlib:iq_query_info(El) of
{iq, ID, Type, ?NS_REGISTER, SubEl} ->
#iq{xmlns = ?NS_REGISTER} = IQ ->
ResIQ = mod_register:process_iq(
{"", "", ""}, {"", ?MYNAME, ""},
{iq, ID, Type, ?NS_REGISTER, SubEl}),
{"", "", ""}, {"", ?MYNAME, ""}, IQ),
Res1 = jlib:replace_from_to({"", ?MYNAME, ""},
{"", "", ""},
jlib:iq_to_xml(ResIQ)),
@ -301,7 +300,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
end
end;
wait_for_auth({xmlstreamend, Name}, StateData) ->
wait_for_auth({xmlstreamend, _Name}, StateData) ->
send_text(StateData, ?STREAM_TRAILER),
{stop, normal, StateData};
@ -351,10 +350,9 @@ wait_for_sasl_auth({xmlstreamelement, El}, StateData) ->
end;
_ ->
case jlib:iq_query_info(El) of
{iq, ID, Type, ?NS_REGISTER, SubEl} ->
#iq{xmlns = ?NS_REGISTER} = IQ ->
ResIQ = mod_register:process_iq(
{"", "", ""}, {"", ?MYNAME, ""},
{iq, ID, Type, ?NS_REGISTER, SubEl}),
{"", "", ""}, {"", ?MYNAME, ""}, IQ),
Res1 = jlib:replace_from_to({"", ?MYNAME, ""},
{"", "", ""},
jlib:iq_to_xml(ResIQ)),
@ -366,7 +364,7 @@ wait_for_sasl_auth({xmlstreamelement, El}, StateData) ->
end
end;
wait_for_sasl_auth({xmlstreamend, Name}, StateData) ->
wait_for_sasl_auth({xmlstreamend, _Name}, StateData) ->
send_text(StateData, ?STREAM_TRAILER),
{stop, normal, StateData};
@ -414,10 +412,9 @@ wait_for_sasl_response({xmlstreamelement, El}, StateData) ->
end;
_ ->
case jlib:iq_query_info(El) of
{iq, ID, Type, ?NS_REGISTER, SubEl} ->
#iq{xmlns = ?NS_REGISTER} = IQ ->
ResIQ = mod_register:process_iq(
{"", "", ""}, {"", ?MYNAME, ""},
{iq, ID, Type, ?NS_REGISTER, SubEl}),
{"", "", ""}, {"", ?MYNAME, ""}, IQ),
Res1 = jlib:replace_from_to({"", ?MYNAME, ""},
{"", "", ""},
jlib:iq_to_xml(ResIQ)),
@ -429,7 +426,7 @@ wait_for_sasl_response({xmlstreamelement, El}, StateData) ->
end
end;
wait_for_sasl_response({xmlstreamend, Name}, StateData) ->
wait_for_sasl_response({xmlstreamend, _Name}, StateData) ->
send_text(StateData, ?STREAM_TRAILER),
{stop, normal, StateData};
@ -444,7 +441,7 @@ wait_for_sasl_response(closed, StateData) ->
wait_for_bind({xmlstreamelement, El}, StateData) ->
case jlib:iq_query_info(El) of
{iq, ID, set, ?NS_BIND, SubEl} ->
#iq{type = set, xmlns = ?NS_BIND, sub_el = SubEl} = IQ ->
U = StateData#state.user,
R1 = xml:get_path_s(SubEl, [{elem, "resource"}, cdata]),
R = case jlib:resourceprep(R1) of
@ -461,11 +458,12 @@ wait_for_bind({xmlstreamelement, El}, StateData) ->
{next_state, wait_for_bind, StateData};
_ ->
JID = jlib:make_jid(U, StateData#state.server, R),
Res = {iq, ID, result, ?NS_BIND,
[{xmlelement, "bind",
[{"xmlns", ?NS_BIND}],
[{xmlelement, "jid", [],
[{xmlcdata, jlib:jid_to_string(JID)}]}]}]},
Res = IQ#iq{type = result,
sub_el = [{xmlelement, "bind",
[{"xmlns", ?NS_BIND}],
[{xmlelement, "jid", [],
[{xmlcdata,
jlib:jid_to_string(JID)}]}]}]},
send_element(StateData, jlib:iq_to_xml(Res)),
{next_state, wait_for_session,
StateData#state{resource = R, jid = JID}}
@ -474,7 +472,7 @@ wait_for_bind({xmlstreamelement, El}, StateData) ->
{next_state, wait_for_bind, StateData}
end;
wait_for_bind({xmlstreamend, Name}, StateData) ->
wait_for_bind({xmlstreamend, _Name}, StateData) ->
send_text(StateData, ?STREAM_TRAILER),
{stop, normal, StateData};
@ -489,7 +487,7 @@ wait_for_bind(closed, StateData) ->
wait_for_session({xmlstreamelement, El}, StateData) ->
case jlib:iq_query_info(El) of
{iq, ID, set, ?NS_SESSION, SubEl} ->
#iq{type = set, xmlns = ?NS_SESSION} ->
U = StateData#state.user,
R = StateData#state.resource,
io:format("SASLAUTH: ~p~n", [{U, R}]),
@ -521,22 +519,11 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
send_element(StateData, Err),
{next_state, wait_for_session, StateData}
end;
% TODO: is this needed?
{iq, ID, Type, ?NS_REGISTER, SubEl} ->
ResIQ = mod_register:process_iq(
{"", "", ""}, {"", ?MYNAME, ""},
{iq, ID, Type, ?NS_REGISTER, SubEl}),
Res1 = jlib:replace_from_to({"", ?MYNAME, ""},
{"", "", ""},
jlib:iq_to_xml(ResIQ)),
Res = jlib:remove_attr("to", Res1),
send_element(StateData, Res),
{next_state, wait_for_session, StateData};
_ ->
{next_state, wait_for_session, StateData}
end;
wait_for_session({xmlstreamend, Name}, StateData) ->
wait_for_session({xmlstreamend, _Name}, StateData) ->
send_text(StateData, ?STREAM_TRAILER),
{stop, normal, StateData};
@ -551,7 +538,7 @@ wait_for_session(closed, StateData) ->
session_established({xmlstreamelement, El}, StateData) ->
{xmlelement, Name, Attrs, Els} = El,
{xmlelement, Name, Attrs, _Els} = El,
User = StateData#state.user,
Server = StateData#state.server,
%FromJID = {User,
@ -594,13 +581,14 @@ session_established({xmlstreamelement, El}, StateData) ->
none ->
ejabberd_router:route(FromJID, ToJID, El),
StateData;
PrivList ->
_PrivList ->
case jlib:iq_query_info(El) of
{iq, ID, Type, ?NS_PRIVACY = XMLNS, SubEl} = IQ ->
#iq{xmlns = ?NS_PRIVACY} = IQ ->
process_privacy_iq(
FromJID, ToJID, IQ, StateData);
_ ->
ejabberd_router:route(FromJID, ToJID, El),
ejabberd_router:route(
FromJID, ToJID, El),
StateData
end
end;
@ -613,7 +601,7 @@ session_established({xmlstreamelement, El}, StateData) ->
end,
{next_state, session_established, NewState};
session_established({xmlstreamend, Name}, StateData) ->
session_established({xmlstreamend, _Name}, StateData) ->
send_text(StateData, ?STREAM_TRAILER),
{stop, normal, StateData};
@ -645,7 +633,7 @@ session_established(closed, StateData) ->
%% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
handle_event(Event, StateName, StateData) ->
handle_event(_Event, StateName, StateData) ->
{next_state, StateName, StateData}.
%%----------------------------------------------------------------------
@ -657,11 +645,11 @@ handle_event(Event, StateName, StateData) ->
%% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData}
%%----------------------------------------------------------------------
handle_sync_event(Event, From, StateName, StateData) ->
handle_sync_event(_Event, _From, StateName, StateData) ->
Reply = ok,
{reply, Reply, StateName, StateData}.
code_change(OldVsn, StateName, StateData, Extra) ->
code_change(_OldVsn, StateName, StateData, _Extra) ->
{ok, StateName, StateData}.
%%----------------------------------------------------------------------
@ -673,7 +661,7 @@ code_change(OldVsn, StateName, StateData, Extra) ->
handle_info({send_text, Text}, StateName, StateData) ->
send_text(StateData, Text),
{next_state, StateName, StateData};
handle_info(replaced, StateName, StateData) ->
handle_info(replaced, _StateName, StateData) ->
% TODO
%send_text(StateData#state.sender, Text),
{stop, normal, StateData#state{authentificated = replaced}};
@ -721,37 +709,37 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
end;
"broadcast" ->
?DEBUG("broadcast~n~p~n", [Els]),
NewSt = case Els of
[{item, IJID, ISubscription}] ->
{false, Attrs,
roster_change(IJID, ISubscription,
StateData)};
[{exit, Reason}] ->
{exit, Attrs, Reason};
[{privacy_list, PrivList}] ->
{false, Attrs,
case catch mod_privacy:updated_list(
StateData#state.privacy_list,
PrivList) of
{'EXIT', _} ->
{false, Attrs, StateData};
NewPL ->
StateData#state{privacy_list = NewPL}
end};
_ ->
{false, Attrs, StateData}
end;
case Els of
[{item, IJID, ISubscription}] ->
{false, Attrs,
roster_change(IJID, ISubscription,
StateData)};
[{exit, Reason}] ->
{exit, Attrs, Reason};
[{privacy_list, PrivList}] ->
{false, Attrs,
case catch mod_privacy:updated_list(
StateData#state.privacy_list,
PrivList) of
{'EXIT', _} ->
{false, Attrs, StateData};
NewPL ->
StateData#state{privacy_list = NewPL}
end};
_ ->
{false, Attrs, StateData}
end;
"iq" ->
IQ = jlib:iq_query_info(Packet),
case IQ of
{iq, ID, Type, ?NS_VCARD, SubEl} ->
#iq{xmlns = ?NS_VCARD} ->
ResIQ = mod_vcard:process_sm_iq(From, To, IQ),
ejabberd_router:route(To,
From,
jlib:iq_to_xml(ResIQ)),
{false, Attrs, StateData};
%-ifdef(PRIVACY_SUPPORT).
{iq, _ID, Type, _XMLNS, _SubEl} ->
#iq{} ->
case catch mod_privacy:check_packet(
StateData#state.user,
StateData#state.privacy_list,
@ -808,7 +796,7 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
%% Purpose: Shutdown the fsm
%% Returns: any
%%----------------------------------------------------------------------
terminate(Reason, StateName, StateData) ->
terminate(_Reason, StateName, StateData) ->
case StateName of
session_established ->
case StateData#state.authentificated of
@ -870,7 +858,7 @@ new_id() ->
is_auth_packet(El) ->
case jlib:iq_query_info(El) of
{iq, ID, Type, ?NS_AUTH, SubEl} ->
#iq{id = ID, type = Type, xmlns = ?NS_AUTH, sub_el = SubEl} ->
{xmlelement, _, _, Els} = SubEl,
{auth, ID, Type,
get_auth_tags(Els, "", "", "", "")};
@ -879,7 +867,7 @@ is_auth_packet(El) ->
end.
get_auth_tags([{xmlelement, Name, Attrs, Els}| L], U, P, D, R) ->
get_auth_tags([{xmlelement, Name, _Attrs, Els}| L], U, P, D, R) ->
CData = xml:get_cdata(Els),
case Name of
"username" ->
@ -947,7 +935,7 @@ process_presence_probe(From, To, StateData) ->
end.
presence_update(From, Packet, StateData) ->
{xmlelement, Name, Attrs, Els} = Packet,
{xmlelement, _Name, Attrs, _Els} = Packet,
case xml:get_attr_s("type", Attrs) of
"unavailable" ->
ejabberd_sm:unset_presence(StateData#state.user,
@ -1019,7 +1007,7 @@ presence_update(From, Packet, StateData) ->
end.
presence_track(From, To, Packet, StateData) ->
{xmlelement, Name, Attrs, Els} = Packet,
{xmlelement, _Name, Attrs, _Els} = Packet,
LTo = jlib:jid_tolower(To),
User = StateData#state.user,
case xml:get_attr_s("type", Attrs) of
@ -1245,7 +1233,9 @@ update_priority(El, StateData) ->
process_privacy_iq(From, To, {iq, ID, Type, XMLNS, SubEl} = IQ, StateData) ->
process_privacy_iq(From, To,
#iq{type = Type, sub_el = SubEl} = IQ,
StateData) ->
{Res, NewStateData} =
case Type of
get ->
@ -1272,10 +1262,9 @@ process_privacy_iq(From, To, {iq, ID, Type, XMLNS, SubEl} = IQ, StateData) ->
IQRes =
case Res of
{result, Result} ->
{iq, ID, result, XMLNS, Result};
IQ#iq{type = result, sub_el = Result};
{error, Error} ->
{iq, ID, error, XMLNS,
[SubEl, Error]}
IQ#iq{type = error, sub_el = [SubEl, Error]}
end,
ejabberd_router:route(
To, From, jlib:iq_to_xml(IQRes)),

View File

@ -106,31 +106,24 @@ do_route(State, From, To, Packet) ->
process_iq(State, From, To, Packet) ->
IQ = jlib:iq_query_info(Packet),
case IQ of
{iq, _ID, Type, XMLNS, _SubEl} ->
case jlib:is_iq_request_type(Type) of
true ->
case ets:lookup(State#state.iqtable, XMLNS) of
[{_, Module, Function}] ->
ResIQ = apply(Module, Function, [From, To, IQ]),
if
ResIQ /= ignore ->
ejabberd_router ! {route,
To,
From,
jlib:iq_to_xml(ResIQ)};
true ->
ok
end;
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Module, Function, Opts,
From, To, IQ);
[] ->
Err = jlib:make_error_reply(
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
ejabberd_router:route(To, From, Err)
#iq{xmlns = XMLNS} ->
case ets:lookup(State#state.iqtable, XMLNS) of
[{_, Module, Function}] ->
ResIQ = Module:Function(From, To, IQ),
if
ResIQ /= ignore ->
ejabberd_router:route(
To, From, jlib:iq_to_xml(ResIQ));
true ->
ok
end;
_ ->
ok
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Module, Function, Opts,
From, To, IQ);
[] ->
Err = jlib:make_error_reply(
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
ejabberd_router:route(To, From, Err)
end;
reply ->
ok;

View File

@ -341,7 +341,7 @@ dirty_get_my_sessions_list() ->
process_iq(From, To, Packet) ->
IQ = jlib:iq_query_info(Packet),
case IQ of
{iq, _ID, _Type, XMLNS, _SubEl} ->
#iq{xmlns = XMLNS} ->
case ets:lookup(sm_iqtable, XMLNS) of
[{_, Module, Function}] ->
ResIQ = Module:Function(From, To, IQ),
@ -366,7 +366,7 @@ process_iq(From, To, Packet) ->
ok;
_ ->
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
ejabberd_router ! {route, To, From, Err},
ejabberd_router:route(To, From, Err),
ok
end.

View File

@ -82,7 +82,7 @@ init([File, User, Pid]) ->
%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
wait_for_xdb({xmlstreamstart, Name, Attrs}, StateData) ->
wait_for_xdb({xmlstreamstart, Name, _Attrs}, StateData) ->
case Name of
"xdb" ->
{next_state, xdb_data, StateData};
@ -95,7 +95,7 @@ wait_for_xdb(closed, StateData) ->
xdb_data({xmlstreamelement, El}, StateData) ->
{xmlelement, Name, Attrs, Els} = El,
{xmlelement, _Name, Attrs, _Els} = El,
Server = StateData#state.server,
From = jlib:make_jid(StateData#state.user, Server, ""),
NewState =
@ -107,13 +107,14 @@ xdb_data({xmlstreamelement, El}, StateData) ->
?NS_ROSTER ->
%mod_roster:process_iq(From,
% {"", ?MYNAME, ""},
% {iq, "", set, ?NS_ROSTER, El}),
% #iq{type = set, xmlns = ?NS_ROSTER, sub_el = El}),
mod_roster:set_items(StateData#state.user, El),
StateData;
?NS_VCARD ->
Res = mod_vcard:process_sm_iq(From,
jlib:make_jid("", ?MYNAME, ""),
{iq, "", set, ?NS_VCARD, El}),
mod_vcard:process_sm_iq(
From,
jlib:make_jid("", ?MYNAME, ""),
#iq{type = set, xmlns = ?NS_VCARD, sub_el = El}),
StateData;
"jabber:x:offline" ->
process_offline(From, El),
@ -121,7 +122,7 @@ xdb_data({xmlstreamelement, El}, StateData) ->
%?NS_REGISTER ->
% mod_register:process_iq(
% {"", "", ""}, {"", ?MYNAME, ""},
% {iq, "", set, ?NS_REGISTER, El}),
% #iq{type =set, xmlns = ?NS_REGISTER, xub_el = El}),
% User = xml:get_path_s(El, [{elem, "username"}, cdata]),
% io:format("user ~s~n", [User]),
% StateData;
@ -131,11 +132,11 @@ xdb_data({xmlstreamelement, El}, StateData) ->
mod_private:process_local_iq(
From,
jlib:make_jid("", ?MYNAME, ""),
{iq, "", set, ?NS_PRIVATE,
{xmlelement, "query", [],
[jlib:remove_attr(
"j_private_flag",
jlib:remove_attr("xdbns", El))]}}),
#iq{type = set, xmlns = ?NS_PRIVATE,
sub_el = {xmlelement, "query", [],
[jlib:remove_attr(
"j_private_flag",
jlib:remove_attr("xdbns", El))]}}),
StateData;
_ ->
io:format("jd2ejd: Unknown namespace \"~s\"~n",
@ -145,7 +146,7 @@ xdb_data({xmlstreamelement, El}, StateData) ->
end,
{next_state, xdb_data, NewState};
xdb_data({xmlstreamend, Name}, StateData) ->
xdb_data({xmlstreamend, _Name}, StateData) ->
{stop, normal, StateData};
xdb_data(closed, StateData) ->
@ -172,7 +173,7 @@ xdb_data(closed, StateData) ->
%% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
handle_event(Event, StateName, StateData) ->
handle_event(_Event, StateName, StateData) ->
{next_state, StateName, StateData}.
%%----------------------------------------------------------------------
@ -184,11 +185,11 @@ handle_event(Event, StateName, StateData) ->
%% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData}
%%----------------------------------------------------------------------
handle_sync_event(Event, From, StateName, StateData) ->
handle_sync_event(_Event, _From, StateName, StateData) ->
Reply = ok,
{reply, Reply, StateName, StateData}.
code_change(OldVsn, StateName, StateData, Extra) ->
code_change(_OldVsn, StateName, StateData, _Extra) ->
{ok, StateName, StateData}.
%%----------------------------------------------------------------------
@ -205,7 +206,7 @@ handle_info(_, StateName, StateData) ->
%% Purpose: Shutdown the fsm
%% Returns: any
%%----------------------------------------------------------------------
terminate(Reason, StateName, StateData) ->
terminate(Reason, _StateName, StateData) ->
exit(StateData#state.xml_stream_pid, closed),
StateData#state.pid ! {jd2ejd, Reason},
% Profiling

View File

@ -343,7 +343,8 @@ iq_query_info({xmlelement, Name, Attrs, Els}) when Name == "iq" ->
XMLNS = xml:get_attr_s("xmlns", Attrs2),
if
XMLNS /= "" ->
{iq, ID, Type1, XMLNS, {xmlelement, Name2, Attrs2, Els2}};
#iq{id = ID, type = Type1, xmlns = XMLNS,
sub_el = {xmlelement, Name2, Attrs2, Els2}};
true ->
invalid
end;
@ -367,7 +368,7 @@ iq_type_to_string(error) -> "error";
iq_type_to_string(_) -> invalid.
iq_to_xml({iq, ID, Type, _, SubEl}) ->
iq_to_xml(#iq{id = ID, type = Type, sub_el = SubEl}) ->
if
ID /= "" ->
{xmlelement, "iq",

View File

@ -143,3 +143,8 @@
-record(jid, {user, server, resource,
luser, lserver, lresource}).
-record(iq, {id = "",
type,
xmlns = "",
sub_el}).

View File

@ -34,24 +34,26 @@ stop() ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, ?NS_IQDATA).
process_local_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
process_local_iq(From, _To, #iq{id = ID, type = Type,
xmlns = XMLNS, sub_el = SubEl} = IQ) ->
case acl:match_rule(configure, From) of
deny ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
allow ->
Lang = xml:get_tag_attr_s("xml:lang", SubEl),
case Type of
set ->
case xml:get_tag_attr_s("type", SubEl) of
"cancel" ->
{iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}], []}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS}], []}]};
"submit" ->
XData = jlib:parse_xdata_submit(SubEl),
case XData of
invalid ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_BAD_REQUEST]};
IQ#iq{type = error,
sub_el = [SubEl, ?ERR_BAD_REQUEST]};
_ ->
Node =
string:tokens(
@ -59,32 +61,34 @@ process_local_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
"/"),
case set_form(Node, Lang, XData) of
{result, Res} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS}],
Res
}]};
IQ#iq{type = result,
sub_el =
[{xmlelement, "query",
[{"xmlns", XMLNS}],
Res
}]};
{error, Error} ->
{iq, ID, error, XMLNS,
[SubEl, Error]}
IQ#iq{type = error,
sub_el = [SubEl, Error]}
end
end;
_ ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_NOT_ALLOWED]}
IQ#iq{type = error,
sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
end;
get ->
Node =
string:tokens(xml:get_tag_attr_s("node", SubEl), "/"),
case get_form(Node, Lang) of
{result, Res} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}],
Res
}]};
IQ#iq{type = result,
sub_el =
[{xmlelement, "query", [{"xmlns", XMLNS}],
Res
}]};
{error, Error} ->
{iq, ID, error, XMLNS,
[SubEl, Error]}
IQ#iq{type = error,
sub_el = [SubEl, Error]}
end
end
end.
@ -129,7 +133,7 @@ get_form(["running nodes", ENode, "DB"], Lang) ->
{error, ?ERR_ITEM_NOT_FOUND};
Node ->
case rpc:call(Node, mnesia, system_info, [tables]) of
{badrpc, Reason} ->
{badrpc, _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR};
Tables ->
STables = lists:sort(Tables),
@ -163,7 +167,7 @@ get_form(["running nodes", ENode, "modules", "stop"], Lang) ->
{error, ?ERR_ITEM_NOT_FOUND};
Node ->
case rpc:call(Node, gen_mod, loaded_modules, []) of
{badrpc, Reason} ->
{badrpc, _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR};
Modules ->
SModules = lists:sort(Modules),
@ -698,10 +702,11 @@ search_running_node(SNode, [Node | Nodes]) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process_sm_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
process_sm_iq(From, To,
#iq{type = Type, xmlns = XMLNS, sub_el = SubEl} = IQ) ->
case acl:match_rule(configure, From) of
deny ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
allow ->
#jid{user = User} = To,
Lang = xml:get_tag_attr_s("xml:lang", SubEl),
@ -709,14 +714,15 @@ process_sm_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
set ->
case xml:get_tag_attr_s("type", SubEl) of
"cancel" ->
{iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}], []}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS}], []}]};
"submit" ->
XData = jlib:parse_xdata_submit(SubEl),
case XData of
invalid ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_BAD_REQUEST]};
IQ#iq{type = error,
sub_el = [SubEl, ?ERR_BAD_REQUEST]};
_ ->
Node =
string:tokens(
@ -725,32 +731,33 @@ process_sm_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
case set_sm_form(
User, Node, Lang, XData) of
{result, Res} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS}],
Res
}]};
IQ#iq{type = result,
sub_el =
[{xmlelement, "query",
[{"xmlns", XMLNS}],
Res
}]};
{error, Error} ->
{iq, ID, error, XMLNS,
[SubEl, Error]}
IQ#iq{type = error,
sub_el = [SubEl, Error]}
end
end;
_ ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_NOT_ALLOWED]}
IQ#iq{type = error,
sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
end;
get ->
Node =
string:tokens(xml:get_tag_attr_s("node", SubEl), "/"),
case get_sm_form(User, Node, Lang) of
{result, Res} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}],
Res
}]};
IQ#iq{type = result,
sub_el =
[{xmlelement, "query", [{"xmlns", XMLNS}],
Res
}]};
{error, Error} ->
{iq, ID, error, XMLNS,
[SubEl, Error]}
IQ#iq{type = error, sub_el = [SubEl, Error]}
end
end
end.

View File

@ -32,16 +32,16 @@ stop() ->
gen_iq_handler:remove_iq_handler(ejabberd_sm, ?NS_IQDATA).
process_local_iq(From, _To, {iq, ID, Type, XMLNS, SubEl}) ->
process_local_iq(From, _To, #iq{type = Type, sub_el = SubEl} = IQ) ->
case acl:match_rule(configure, From) of
deny ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
allow ->
%Lang = xml:get_tag_attr_s("xml:lang", SubEl),
case Type of
set ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]};
IQ#iq{type = error,
sub_el = [SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]};
%case xml:get_tag_attr_s("type", SubEl) of
% "cancel" ->
% {iq, ID, result, XMLNS,
@ -76,9 +76,9 @@ process_local_iq(From, _To, {iq, ID, Type, XMLNS, SubEl}) ->
get ->
case process_get(SubEl) of
{result, Res} ->
{iq, ID, result, XMLNS, [Res]};
IQ#iq{type = result, sub_el = [Res]};
{error, Error} ->
{iq, ID, error, XMLNS, [SubEl, Error]}
IQ#iq{type = error, sub_el = [SubEl, Error]}
end
end
end.

View File

@ -27,9 +27,10 @@
-include("jlib.hrl").
-define(EMPTY_INFO_RESULT,
{iq, ID, result, XMLNS, [{xmlelement, "query",
[{"xmlns", ?NS_DISCO_INFO},
{"node", SNode}], []}]}).
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", ?NS_DISCO_INFO},
{"node", SNode}], []}]}).
start(Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
@ -72,44 +73,45 @@ unregister_extra_domain(Domain) ->
catch ets:new(disco_extra_domains, [named_table, ordered_set, public]),
ets:delete(disco_extra_domains, Domain).
process_local_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
process_local_iq_items(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
Lang = xml:get_tag_attr_s("xml:lang", SubEl),
case Type of
set ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
get ->
SNode = xml:get_tag_attr_s("node", SubEl),
Node = string:tokens(SNode, "/"),
case acl:match_rule(configure, From) of
deny when Node /= [] ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
deny ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", ?NS_DISCO_ITEMS}],
get_services_only()
}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", ?NS_DISCO_ITEMS}],
get_services_only()
}]};
_ ->
case get_local_items(Node, jlib:jid_to_string(To), Lang) of
{result, Res} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", ?NS_DISCO_ITEMS},
{"node", SNode}],
Res
}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", ?NS_DISCO_ITEMS},
{"node", SNode}],
Res
}]};
{error, Error} ->
{iq, ID, error, XMLNS, [SubEl, Error]}
IQ#iq{type = error, sub_el = [SubEl, Error]}
end
end
end.
process_local_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
process_local_iq_info(From, _To, #iq{type = Type, xmlns = XMLNS,
sub_el = SubEl} = IQ) ->
case Type of
set ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
get ->
SNode = xml:get_tag_attr_s("node", SubEl),
Node = string:tokens(SNode, "/"),
@ -117,17 +119,18 @@ process_local_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
{_, []} ->
Features = lists:map(fun feature_to_xml/1,
ets:tab2list(disco_features)),
{iq, ID, result, XMLNS, [{xmlelement,
"query",
[{"xmlns", ?NS_DISCO_INFO}],
[{xmlelement, "identity",
[{"category", "service"},
{"type", "im"},
{"name", "ejabberd"}], []}] ++
Features
}]};
IQ#iq{type = result,
sub_el = [{xmlelement,
"query",
[{"xmlns", ?NS_DISCO_INFO}],
[{xmlelement, "identity",
[{"category", "service"},
{"type", "im"},
{"name", "ejabberd"}], []}] ++
Features
}]};
{deny, _} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
{allow, ["config"]} -> ?EMPTY_INFO_RESULT;
{allow, ["online users"]} -> ?EMPTY_INFO_RESULT;
{allow, ["all users"]} -> ?EMPTY_INFO_RESULT;
@ -136,56 +139,57 @@ process_local_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
{allow, ["running nodes"]} -> ?EMPTY_INFO_RESULT;
{allow, ["stopped nodes"]} -> ?EMPTY_INFO_RESULT;
{allow, ["running nodes", ENode]} ->
{iq, ID, result, XMLNS, [{xmlelement,
"query",
[{"xmlns", XMLNS},
{"node", SNode}],
[{xmlelement, "identity",
[{"category", "ejabberd"},
{"type", "node"},
{"name", ENode}], []},
feature_to_xml({?NS_STATS})
]
}]};
IQ#iq{type = result,
sub_el = [{xmlelement,
"query",
[{"xmlns", XMLNS},
{"node", SNode}],
[{xmlelement, "identity",
[{"category", "ejabberd"},
{"type", "node"},
{"name", ENode}], []},
feature_to_xml({?NS_STATS})
]
}]};
{allow, ["running nodes", ENode, "DB"]} ->
{iq, ID, result, XMLNS, [{xmlelement,
"query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
IQ#iq{type = result,
sub_el = [{xmlelement,
"query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
{allow, ["running nodes", ENode, "modules"]} ->
?EMPTY_INFO_RESULT;
{allow, ["running nodes", ENode, "modules", _]} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
{allow, ["running nodes", ENode, "backup"]} ->
?EMPTY_INFO_RESULT;
{allow, ["running nodes", ENode, "backup", _]} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
{allow, ["running nodes", ENode, "import"]} ->
?EMPTY_INFO_RESULT;
{allow, ["running nodes", ENode, "import", _]} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
{allow, ["config", _]} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]};
_ ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_ITEM_NOT_FOUND]}
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
end
end.
@ -452,42 +456,42 @@ get_stopped_nodes(Lang) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process_sm_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
process_sm_iq_items(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
#jid{user = User} = To,
case {acl:match_rule(configure, From), Type} of
{deny, _} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
{allow, set} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
{allow, get} ->
case xml:get_tag_attr_s("node", SubEl) of
"" ->
{iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", ?NS_DISCO_ITEMS}],
get_user_resources(User)
}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", ?NS_DISCO_ITEMS}],
get_user_resources(User)
}]};
_ ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_ITEM_NOT_FOUND]}
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
end
end.
process_sm_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
process_sm_iq_info(From, To, #iq{type = Type, xmlns = XMLNS,
sub_el = SubEl} = IQ) ->
case {acl:match_rule(configure, From), Type} of
{deny, _} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
{allow, set} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
{allow, get} ->
case xml:get_tag_attr_s("node", SubEl) of
"" ->
{iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}],
[feature_to_xml({?NS_IQDATA})]}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query", [{"xmlns", XMLNS}],
[feature_to_xml({?NS_IQDATA})]}]};
_ ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]}
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
end
end.

View File

@ -63,20 +63,24 @@ do_route(Host, From, To, Packet) ->
case Resource of
"" ->
case jlib:iq_query_info(Packet) of
{iq, ID, get, ?NS_DISCO_INFO = XMLNS, SubEl} ->
Res = {iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS}],
iq_disco()}]},
#iq{type = get, xmlns = ?NS_DISCO_INFO = XMLNS,
sub_el = SubEl} = IQ ->
Res = IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS}],
iq_disco()}]},
ejabberd_router:route(To,
From,
jlib:iq_to_xml(Res));
{iq, ID, Type, ?NS_IQDATA = XMLNS, SubEl} ->
iq_data(From, To, ID, XMLNS, Type, SubEl);
_ ->
#iq{type = Type, xmlns = ?NS_IQDATA,
sub_el = SubEl} = IQ ->
iq_data(From, To, IQ);
#iq{} = IQ ->
Err = jlib:make_error_reply(
Packet, ?ERR_SERVICE_UNAVAILABLE),
ejabberd_router:route(To, From, Err)
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
ejabberd_router:route(To, From, Err);
_ ->
ok
end;
_ ->
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
@ -155,8 +159,8 @@ iq_disco() ->
iq_data(From, To, ID, XMLNS, Type, SubEl) ->
case catch process_iq_data(From, To, ID, XMLNS, Type, SubEl) of
iq_data(From, To, #iq{type = Type} = IQ) ->
case catch process_iq_data(From, To, IQ) of
{'EXIT', Reason} ->
?ERROR_MSG("~p", [Reason]);
ResIQ ->
@ -170,20 +174,22 @@ iq_data(From, To, ID, XMLNS, Type, SubEl) ->
end.
process_iq_data(From, To, ID, XMLNS, Type, SubEl) ->
process_iq_data(From, To,
#iq{type = Type, xmlns = XMLNS, sub_el = SubEl} = IQ) ->
Lang = xml:get_tag_attr_s("xml:lang", SubEl),
case Type of
set ->
case xml:get_tag_attr_s("type", SubEl) of
"cancel" ->
{iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}], []}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS}], []}]};
"submit" ->
XData = jlib:parse_xdata_submit(SubEl),
case XData of
invalid ->
{iq, ID, error, XMLNS,
[SubEl, ?ERR_BAD_REQUEST]};
IQ#iq{type = error,
sub_el = [SubEl, ?ERR_BAD_REQUEST]};
_ ->
Node =
string:tokens(
@ -191,32 +197,32 @@ process_iq_data(From, To, ID, XMLNS, Type, SubEl) ->
"/"),
case set_form(From, Node, Lang, XData) of
{result, Res} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", XMLNS}],
Res
}]};
IQ#iq{type = result,
sub_el = [{xmlelement, "query",
[{"xmlns", XMLNS}],
Res
}]};
{error, Error} ->
{iq, ID, error, XMLNS,
[SubEl, Error]}
IQ#iq{type = error,
sub_el = [SubEl, Error]}
end
end;
_ ->