mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +01:00
568909d5bb
* src/configure.ac: Likewise * src/mod_muc/mod_muc_room.erl: Weakened presence filtering, added warning in non-anonymous rooms, room destroying updated to latest JEP-0045, added a number of occupants and room name in room's disco#info reply, miscellaneous internal changes (thanks to Sergei Golovan) * src/mod_muc/mod_muc.erl: Better support for nick unregistration (thanks to Sergei Golovan) * src/ejabberd_zlib/ejabberd_zlib.erl: Zlib support (thanks to Sergei Golovan) * src/ejabberd_zlib/ejabberd_zlib_drv.c: Likewise * src/ejabberd_zlib/Makefile.in: Likewise * src/ejabberd_c2s.erl: Stream compression support (JEP-0138) * src/ejabberd_receiver.erl: Likewise * src/mod_disco.erl: Don't split node name before calling hooks (thanks to Sergei Golovan) * src/mod_configure.erl: Support for configuration using ad-hoc commands (thanks to Sergei Golovan) * src/mod_announce.erl: Support for sending announce messages using ad-hoc commands (thanks to Sergei Golovan) * src/mod_adhoc.erl: Ad-hoc support (JEP-0050) (thanks to Magnus Henoch) * src/adhoc.erl: Likewise * src/adhoc.hrl: Likewise * src/jlib.hrl: Updated (thanks to Sergei Golovan) * src/gen_mod.erl: Added function is_loaded/2 (thanks to Sergei Golovan) * src/ejabberd_service.erl: Changed error message on handshake error (thanks to Sergei Golovan) * src/ejabberd.cfg.example: Updated (thanks to Sergei Golovan) SVN Revision: 486
112 lines
3.2 KiB
Erlang
112 lines
3.2 KiB
Erlang
%%%----------------------------------------------------------------------
|
|
%%% File : adhoc.erl
|
|
%%% Author : Magnus Henoch <henoch@dtek.chalmers.se>
|
|
%%% Purpose : Provide helper functions for ad-hoc commands (JEP-0050)
|
|
%%% Created : 31 Oct 2005 by Magnus Henoch <henoch@dtek.chalmers.se>
|
|
%%% Id : $Id$
|
|
%%%----------------------------------------------------------------------
|
|
|
|
-module(adhoc).
|
|
-author('henoch@dtek.chalmers.se').
|
|
-vsn('$Revision$ ').
|
|
|
|
-export([parse_request/1,
|
|
produce_response/2,
|
|
produce_response/1]).
|
|
|
|
-include("ejabberd.hrl").
|
|
-include("jlib.hrl").
|
|
-include("adhoc.hrl").
|
|
|
|
%% Parse an ad-hoc request. Return either an adhoc_request record or
|
|
%% an {error, ErrorType} tuple.
|
|
parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}) ->
|
|
?DEBUG("entering parse_request...", []),
|
|
Node = xml:get_tag_attr_s("node", SubEl),
|
|
SessionID = xml:get_tag_attr_s("sessionid", SubEl),
|
|
Action = xml:get_tag_attr_s("action", SubEl),
|
|
XData = find_xdata_el(SubEl),
|
|
{xmlelement, _, _, AllEls} = SubEl,
|
|
if XData ->
|
|
Others = lists:delete(XData, AllEls);
|
|
true ->
|
|
Others = AllEls
|
|
end,
|
|
|
|
#adhoc_request{lang = Lang,
|
|
node = Node,
|
|
sessionid = SessionID,
|
|
action = Action,
|
|
xdata = XData,
|
|
others = Others};
|
|
parse_request(_) ->
|
|
{error, ?ERR_BAD_REQUEST}.
|
|
|
|
%% Borrowed from mod_vcard.erl
|
|
find_xdata_el({xmlelement, _Name, _Attrs, SubEls}) ->
|
|
find_xdata_el1(SubEls).
|
|
|
|
find_xdata_el1([]) ->
|
|
false;
|
|
find_xdata_el1([{xmlelement, Name, Attrs, SubEls} | Els]) ->
|
|
case xml:get_attr_s("xmlns", Attrs) of
|
|
?NS_XDATA ->
|
|
{xmlelement, Name, Attrs, SubEls};
|
|
_ ->
|
|
find_xdata_el1(Els)
|
|
end;
|
|
find_xdata_el1([_ | Els]) ->
|
|
find_xdata_el1(Els).
|
|
|
|
%% Produce a <command/> node to use as response from an adhoc_response
|
|
%% record, filling in values for language, node and session id from
|
|
%% the request.
|
|
produce_response(#adhoc_request{lang = Lang,
|
|
node = Node,
|
|
sessionid = SessionID},
|
|
Response) ->
|
|
produce_response(Response#adhoc_response{lang = Lang,
|
|
node = Node,
|
|
sessionid = SessionID}).
|
|
|
|
%% Produce a <command/> node to use as response from an adhoc_response
|
|
%% record.
|
|
produce_response(#adhoc_response{lang = _Lang,
|
|
node = Node,
|
|
sessionid = ProvidedSessionID,
|
|
status = Status,
|
|
defaultaction = DefaultAction,
|
|
actions = Actions,
|
|
notes = Notes,
|
|
elements = Elements}) ->
|
|
SessionID = if is_list(ProvidedSessionID), ProvidedSessionID /= "" ->
|
|
ProvidedSessionID;
|
|
true ->
|
|
jlib:now_to_utc_string(now())
|
|
end,
|
|
case Actions of
|
|
[] ->
|
|
ActionsEls = [];
|
|
_ ->
|
|
case DefaultAction of
|
|
"" ->
|
|
ActionsElAttrs = [];
|
|
_ ->
|
|
ActionsElAttrs = [{"execute", DefaultAction}]
|
|
end,
|
|
ActionsEls = [{xmlelement, "actions",
|
|
ActionsElAttrs,
|
|
[{xmlelement, Action, [], []} || Action <- Actions]}]
|
|
end,
|
|
NotesEls = lists:map(fun({Type, Text}) ->
|
|
{xmlelement, "note",
|
|
[{"type", Type}],
|
|
[{xmlcdata, Text}]}
|
|
end, Notes),
|
|
{xmlelement, "command",
|
|
[{"xmlns", ?NS_COMMANDS},
|
|
{"sessionid", SessionID},
|
|
{"node", Node},
|
|
{"status", atom_to_list(Status)}],
|
|
ActionsEls ++ NotesEls ++ Elements}.
|