25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-09-29 14:37:44 +02:00

Merge branch '2.1.x' into 2.2.x

This commit is contained in:
Christophe Romain 2010-08-05 10:20:47 +02:00
commit 7be707f7bc
18 changed files with 656 additions and 412 deletions

View File

@ -2,7 +2,7 @@
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>Ejabberd 2.1.x Developers Guide
<TITLE>Ejabberd 2.1.5 Developers Guide
</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
@ -49,7 +49,7 @@ TD P{margin:0px;}
<!--HEVEA command line is: /usr/bin/hevea -fix -pedantic dev.tex -->
<!--CUT DEF section 1 --><P><A NAME="titlepage"></A>
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 2.1.x Developers Guide</H1><H3 CLASS="titlerest">Alexey Shchepin<BR>
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 2.1.5 Developers Guide</H1><H3 CLASS="titlerest">Alexey Shchepin<BR>
<A HREF="mailto:alexey@sevcom.net"><TT>mailto:alexey@sevcom.net</TT></A><BR>
<A HREF="xmpp:aleksey@jabber.ru"><TT>xmpp:aleksey@jabber.ru</TT></A></H3></TD></TR>
</TABLE><DIV CLASS="center">

View File

@ -2,7 +2,7 @@
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>Ejabberd 2.1.x Feature Sheet
<TITLE>Ejabberd 2.1.5 Feature Sheet
</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
@ -50,7 +50,7 @@ SPAN{width:20%; float:right; text-align:left; margin-left:auto;}
<!--HEVEA command line is: /usr/bin/hevea -fix -pedantic features.tex -->
<!--CUT DEF section 1 --><P><A NAME="titlepage"></A>
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 2.1.x Feature Sheet</H1><H3 CLASS="titlerest">Sander Devrieze<BR>
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 2.1.5 Feature Sheet</H1><H3 CLASS="titlerest">Sander Devrieze<BR>
<A HREF="mailto:s.devrieze@pandora.be"><TT>mailto:s.devrieze@pandora.be</TT></A><BR>
<A HREF="xmpp:sander@devrieze.dyndns.org"><TT>xmpp:sander@devrieze.dyndns.org</TT></A></H3></TD></TR>
</TABLE><DIV CLASS="center">

View File

@ -6,7 +6,7 @@
ejabberd 2.1.x
ejabberd 2.1.5
Installation and Operation Guide
@ -76,7 +76,7 @@ BLOCKQUOTE.figure DIV.center DIV.center HR{display:none;}
<HR SIZE=2><BR>
<BR>
<TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP> <FONT SIZE=6><B>ejabberd 2.1.x </B></FONT></TD></TR>
<TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP> <FONT SIZE=6><B>ejabberd 2.1.5 </B></FONT></TD></TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
<TR><TD ALIGN=right NOWRAP> <FONT SIZE=6>Installation and Operation Guide</FONT></TD></TR>
</TABLE><BR>
@ -1060,7 +1060,9 @@ There are also <A HREF="http://www.ejabberd.im/extauth">several example authenti
</P><DL CLASS="description"><DT CLASS="dt-description">
<B><TT>{extauth_program, PathToScript}</TT></B></DT><DD CLASS="dd-description">
Indicate in this option the full path to the external authentication script.
The script must be executable by ejabberd.</DD><DT CLASS="dt-description"><B><TT>{extauth_cache, false|CacheTimeInteger}</TT></B></DT><DD CLASS="dd-description">
The script must be executable by ejabberd.</DD><DT CLASS="dt-description"><B><TT>{extauth_instances, Integer}</TT></B></DT><DD CLASS="dd-description">
Indicate how many instances of the script to run simultaneously to serve authentication in the virtual host.
The default value is the minimum number: 1.</DD><DT CLASS="dt-description"><B><TT>{extauth_cache, false|CacheTimeInteger}</TT></B></DT><DD CLASS="dd-description">
The value <TT>false</TT> disables the caching feature, this is the default.
The integer <TT>0</TT> (zero) enables caching for statistics, but doesn&#X2019;t use that cached information to authenticate users.
If another integer value is set, caching is enabled both for statistics and for authentication:
@ -1069,10 +1071,12 @@ the authentication information since the user last disconnected,
to verify again the user authentication without querying again the extauth script.
Note: caching should not be enabled in a host if internal auth is also enabled.
If caching is enabled, <TT>mod_last</TT> or <TT>mod_last_odbc</TT> must be enabled also in that vhost.
</DD></DL><P>This example sets external authentication, the extauth script, and enables caching for 10 minutes:
</DD></DL><P>This example sets external authentication, the extauth script, enables caching for 10 minutes,
and starts three instances of the script for each virtual host defined in ejabberd:
</P><PRE CLASS="verbatim">{auth_method, [external]}.
{extauth_program, "/etc/ejabberd/JabberAuth.class.php"}.
{extauth_cache, 600}.
{extauth_instances, 3}.
</PRE><P> <A NAME="saslanonymous"></A> </P><!--TOC subsubsection SASL Anonymous and Anonymous Login-->
<H4 CLASS="subsubsection"><!--SEC ANCHOR --><A HREF="#saslanonymous">SASL Anonymous and Anonymous Login</A></H4><!--SEC END --><P> <A NAME="saslanonymous"></A>
</P><P>The value <TT>anonymous</TT> will enable the internal authentication method.</P><P>The anonymous authentication method can be configured with the following

View File

@ -1239,6 +1239,10 @@ These are the specific options:
Indicate in this option the full path to the external authentication script.
The script must be executable by ejabberd.
\titem{\{extauth\_instances, Integer\}}
Indicate how many instances of the script to run simultaneously to serve authentication in the virtual host.
The default value is the minimum number: 1.
\titem{\{extauth\_cache, false|CacheTimeInteger\}}
The value \term{false} disables the caching feature, this is the default.
The integer \term{0} (zero) enables caching for statistics, but doesn't use that cached information to authenticate users.
@ -1250,11 +1254,13 @@ These are the specific options:
If caching is enabled, \term{mod\_last} or \term{mod\_last\_odbc} must be enabled also in that vhost.
\end{description}
This example sets external authentication, the extauth script, and enables caching for 10 minutes:
This example sets external authentication, the extauth script, enables caching for 10 minutes,
and starts three instances of the script for each virtual host defined in ejabberd:
\begin{verbatim}
{auth_method, [external]}.
{extauth_program, "/etc/ejabberd/JabberAuth.class.php"}.
{extauth_cache, 600}.
{extauth_instances, 3}.
\end{verbatim}
\makesubsubsection{saslanonymous}{SASL Anonymous and Anonymous Login}

View File

@ -0,0 +1,70 @@
Release Notes
ejabberd 2.1.5
ejabberd 2.1.5 is the fifth release in ejabberd 2.1.x branch,
and includes several minor bugfixes and a few improvements.
Read more details about the changes in:
http://redir.process-one.net/ejabberd-2.1.4
Download the source code and installers from:
http://www.process-one.net/en/ejabberd/
This is the full list of changes:
* Authentication
- Extauth: Support parallel script running (EJAB-1280)
- mod_register: Return Registered element when account exists
* ejabberdctl
- Fix print of command result that contains ~
- Fix problem when FIREWALL_WINDOW options for erl kernel were used
- Fix typo in update_list command (EJAB-1237)
- Some systems delete the lock dir; in such case don't use flock at all
- The command Update now returns meaningful message and exit-status (EJAB-1237)
* HTTP-Bind (BOSH)
- Don't say v1.2 in the Bind HTTP page
- New optional BOSH connection attribute process-delay (EJAB-1257)
* MUC
- Document the mod_muc option captcha_protected
- Now admins are able to see private rooms in disco (EJAB-1269)
- Show some more room options in the log file
* ODBC
- Correct handling of SQL boolean types (EJAB-1275)
- Discard too old queued requests (the caller has already got a timeout)
- Fixes wrong SQL escaping when --enable-full-xml is set
- Use ets insead of asking supervisor in ejabberd_odbc_sup:get_pids/1
* Pubsub, PEP and Caps
- Enforce disco features results (EJAB-1033, EJAB-1228, EJAB-1238)
- Support all the hash functions required by Caps XEP-0115
* Requirements
- Fixed support for Erlang R12; which doesn't support: true andalso ok
- Support OTP R14A by using public_key library instead of old ssl (EJAB-953)
- Requirement of OpenSSL increased from 0.9.6 to 0.9.8
- OpenSSL is now required, not optional
* Other
- Don't ask for client certificate when using tls (EJAB-1267)
- Fix typo in --enable-transient_supervisors
- Fix privacy check when serving local Last (EJAB-1271)
- Inform client that SSL session caching is disabled
- New configure option: --enable-nif
- Use driver allocator in C files for reflecting memory in erlang:memory(system)
- Debug: New p1_prof compiled with: make debugtools=true
- Debug: Added functions to collect stats about queues, memory, reductions etc
- HTTP: Log error if request has ambiguous Host header (EJAB-1261)
- Logs: When logging s2s out connection attempt or success, log if TLS is used
- Shared Rosters: When account is deleted, delete also member of stored rosters
Bug reports
You can officially report bugs on ProcessOne support site:
http://support.process-one.net/

View File

@ -1,2 +1,2 @@
% ejabberd version (automatically generated).
\newcommand{\version}{2.1.x}
\newcommand{\version}{2.1.5}

18
src/configure vendored
View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.65 for ejabberd 2.1.x.
# Generated by GNU Autoconf 2.65 for ejabberd 2.1.5.
#
# Report bugs to <ejabberd@process-one.net>.
#
@ -552,8 +552,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='ejabberd'
PACKAGE_TARNAME='ejabberd'
PACKAGE_VERSION='2.1.x'
PACKAGE_STRING='ejabberd 2.1.x'
PACKAGE_VERSION='2.1.5'
PACKAGE_STRING='ejabberd 2.1.5'
PACKAGE_BUGREPORT='ejabberd@process-one.net'
PACKAGE_URL=''
@ -1278,7 +1278,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures ejabberd 2.1.x to adapt to many kinds of systems.
\`configure' configures ejabberd 2.1.5 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1344,7 +1344,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of ejabberd 2.1.x:";;
short | recursive ) echo "Configuration of ejabberd 2.1.5:";;
esac
cat <<\_ACEOF
@ -1469,7 +1469,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
ejabberd configure 2.1.x
ejabberd configure 2.1.5
generated by GNU Autoconf 2.65
Copyright (C) 2009 Free Software Foundation, Inc.
@ -1815,7 +1815,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by ejabberd $as_me 2.1.x, which was
It was created by ejabberd $as_me 2.1.5, which was
generated by GNU Autoconf 2.65. Invocation command line was
$ $0 $@
@ -5654,7 +5654,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by ejabberd $as_me 2.1.x, which was
This file was extended by ejabberd $as_me 2.1.5, which was
generated by GNU Autoconf 2.65. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -5707,7 +5707,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
ejabberd config.status 2.1.x
ejabberd config.status 2.1.5
configured by $0, generated by GNU Autoconf 2.65,
with options \\"\$ac_cs_config\\"

View File

@ -2,7 +2,7 @@
{application, ejabberd,
[{description, "ejabberd"},
{vsn, "2.1.x"},
{vsn, "2.1.5"},
{modules, [acl,
adhoc,
configure,

View File

@ -106,7 +106,7 @@ commands() ->
desc = "Update the given module, or use the keyword: all",
module = ?MODULE, function = update,
args = [{module, string}],
result = {res, rescode}},
result = {res, restuple}},
#ejabberd_commands{name = register, tags = [accounts],
desc = "Register a user",
@ -305,7 +305,10 @@ update(ModStr) ->
update_module(ModuleNameString) ->
ModuleName = list_to_atom(ModuleNameString),
ejabberd_update:update([ModuleName]).
case ejabberd_update:update([ModuleName]) of
{ok, Res} -> {ok, io_lib:format("Updated: ~p", [Res])};
{error, Reason} -> {error, Reason}
end.
%%%
%%% Account management

View File

@ -57,6 +57,8 @@ start(normal, _Args) ->
ejabberd_config:start(),
ejabberd_check:config(),
connect_nodes(),
%% Loading ASN.1 driver explicitly to avoid races in LDAP
catch asn1rt:load_driver(),
Sup = ejabberd_sup:start_link(),
ejabberd_rdbms:start(),
ejabberd_auth:start(),

View File

@ -290,7 +290,7 @@ get_last_info(User, Server) ->
case get_mod_last_enabled(Server) of
mod_last -> mod_last:get_last_info(User, Server);
mod_last_odbc -> mod_last_odbc:get_last_info(User, Server);
mod_mod_last -> mod_last_required
no_mod_last -> mod_last_required
end.
%% @spec (Server) -> mod_last | mod_last_odbc | no_mod_last

View File

@ -198,7 +198,8 @@ init([From, Server, Type]) ->
open_socket(init, StateData) ->
log_s2s_out(StateData#state.new,
StateData#state.myname,
StateData#state.server),
StateData#state.server,
StateData#state.tls),
?DEBUG("open_socket: ~p", [{StateData#state.myname,
StateData#state.server,
StateData#state.new,
@ -346,8 +347,8 @@ wait_for_validation({xmlstreamelement, El}, StateData) ->
case Type of
"valid" ->
send_queue(StateData, StateData#state.queue),
?INFO_MSG("Connection established: ~s -> ~s",
[StateData#state.myname, StateData#state.server]),
?INFO_MSG("Connection established: ~s -> ~s with TLS=~p",
[StateData#state.myname, StateData#state.server, StateData#state.tls_enabled]),
ejabberd_hooks:run(s2s_connect_hook,
[StateData#state.myname,
StateData#state.server]),
@ -1160,10 +1161,10 @@ outgoing_s2s_timeout() ->
%% Human readable S2S logging: Log only new outgoing connections as INFO
%% Do not log dialback
log_s2s_out(false, _, _) -> ok;
log_s2s_out(false, _, _, _) -> ok;
%% Log new outgoing connections:
log_s2s_out(_, Myname, Server) ->
?INFO_MSG("Trying to open s2s connection: ~s -> ~s",[Myname, Server]).
log_s2s_out(_, Myname, Server, Tls) ->
?INFO_MSG("Trying to open s2s connection: ~s -> ~s with TLS=~p", [Myname, Server, Tls]).
%% Calculate timeout depending on which state we are in:
%% Can return integer > 0 | infinity

View File

@ -43,16 +43,29 @@
-define(CALL_TIMEOUT, 10000). % Timeout is in milliseconds: 10 seconds == 10000
start(Host, ExtPrg) ->
spawn(?MODULE, init, [Host, ExtPrg]).
lists:foreach(
fun(This) ->
spawn(?MODULE, init, [get_process_name(Host, This), ExtPrg])
end,
lists:seq(0, get_instances(Host)-1)
).
init(Host, ExtPrg) ->
register(gen_mod:get_module_proc(Host, eauth), self()),
init(ProcessName, ExtPrg) ->
register(ProcessName, self()),
process_flag(trap_exit,true),
Port = open_port({spawn, ExtPrg}, [{packet,2}]),
loop(Port, ?INIT_TIMEOUT).
stop(Host) ->
gen_mod:get_module_proc(Host, eauth) ! stop.
lists:foreach(
fun(This) ->
get_process_name(Host, This) ! stop
end,
lists:seq(0, get_instances(Host)-1)
).
get_process_name(Host, Integer) ->
gen_mod:get_module_proc(lists:append([Host, integer_to_list(Integer)]), eauth).
check_password(User, Server, Password) ->
call_port(Server, ["auth", User, Server, Password]).
@ -77,12 +90,24 @@ remove_user(User, Server, Password) ->
call_port(Server, Msg) ->
LServer = jlib:nameprep(Server),
gen_mod:get_module_proc(LServer, eauth) ! {call, self(), Msg},
ProcessName = get_process_name(LServer, random_instance(get_instances(LServer))),
ProcessName ! {call, self(), Msg},
receive
{eauth,Result} ->
Result
end.
random_instance(MaxNum) ->
{A1,A2,A3} = now(),
random:seed(A1, A2, A3),
random:uniform(MaxNum) - 1.
get_instances(Server) ->
case ejabberd_config:get_local_option({extauth_instances, Server}) of
Num when is_integer(Num) -> Num;
_ -> 1
end.
loop(Port, Timeout) ->
receive
{call, Caller, Msg} ->

View File

@ -73,8 +73,7 @@
disco_sm_items/5
]).
%% exported iq handlers
-export([iq_local/3,
iq_sm/3
-export([iq_sm/3
]).
%% exports for console debug manual use
@ -198,24 +197,22 @@ init([ServerHost, Opts]) ->
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc),
case lists:member(?PEPNODE, Plugins) of
true ->
ejabberd_hooks:add(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB, ?MODULE, iq_local, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_local, IQDisc);
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc);
false ->
ok
end,
@ -584,15 +581,12 @@ send_loop(State) ->
%% disco hooks handling functions
%%
identity(Host) ->
Identity = case lists:member(?PEPNODE, plugins(Host)) of
true -> [{"category", "pubsub"}, {"type", "pep"}];
false -> [{"category", "pubsub"}, {"type", "service"}]
end,
{xmlelement, "identity", Identity, []}.
disco_local_identity(Acc, _From, To, [], _Lang) ->
Acc ++ [identity(To#jid.lserver)];
case lists:member(?PEPNODE, plugins(To#jid.lserver)) of
true ->
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []} | Acc];
false -> Acc
end;
disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
Acc.
@ -613,76 +607,116 @@ disco_local_items(Acc, _From, _To, [], _Lang) ->
disco_local_items(Acc, _From, _To, _Node, _Lang) ->
Acc.
disco_sm_identity(Acc, _From, To, [], _Lang) ->
Acc ++ [identity(To#jid.lserver)];
disco_sm_identity(Acc, From, To, Node, Lang) when is_list(Node) ->
disco_sm_identity(Acc, From, To, list_to_binary(Node), Lang);
disco_sm_identity(empty, From, To, Node, Lang) ->
disco_sm_identity([], From, To, Node, Lang);
disco_sm_identity(Acc, From, To, Node, _Lang) ->
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
Acc ++ case node_disco_identity(LOwner, From, Node) of
{result, I} -> I;
_ -> []
end.
disco_identity(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From) ++ Acc.
disco_sm_features(Acc, _From, _To, [], _Lang) ->
Acc;
disco_sm_features(Acc, From, To, Node, _Lang) ->
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
Features = node_disco_features(LOwner, From, Node),
case {Acc, Features} of
{{result, AccFeatures}, {result, AddFeatures}} ->
{result, AccFeatures++AddFeatures};
{_, {result, AddFeatures}} ->
{result, AddFeatures};
{_, _} ->
Acc
disco_identity(_Host, <<>>, _From) ->
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
disco_identity(Host, Node, From) ->
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
{xmlelement, "identity",
[{"category", "pubsub"},
{"type", "leaf"}
| case get_option(Options, title) of
false -> [];
[Title] -> [{"name", Title}]
end],
[]}]};
_ -> {result, []}
end
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> Result;
_ -> []
end.
disco_sm_items(Acc, From, To, [], _Lang) ->
Host = To#jid.lserver,
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
[] ->
Acc;
Nodes ->
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
Items = case Acc of
{result, I} -> I;
_ -> []
end,
NodeItems = lists:map(
fun(#pubsub_node{nodeid = {_, Node}}) ->
{xmlelement, "item",
[{"jid", SBJID}|nodeAttr(Node)],
[]}
end, Nodes),
{result, NodeItems ++ Items}
disco_sm_features(Acc, From, To, Node, Lang) when is_list(Node) ->
disco_sm_features(Acc, From, To, list_to_binary(Node), Lang);
disco_sm_features(empty, From, To, Node, Lang) ->
disco_sm_features({result, []}, From, To, Node, Lang);
disco_sm_features({result, OtherFeatures} = _Acc, From, To, Node, _Lang) ->
{result,
OtherFeatures ++
disco_features(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From)};
disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
Acc.
disco_features(_Host, <<>>, _From) ->
[?NS_PUBSUB
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
disco_features(Host, Node, From) ->
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
{result, [?NS_PUBSUB
| [?NS_PUBSUB ++ "#" ++ Feature || Feature <- features("pep")]]};
_ -> {result, []}
end
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> Result;
_ -> []
end.
disco_sm_items(Acc, From, To, Node, Lang) when is_list(Node) ->
disco_sm_items(Acc, From, To, list_to_binary(Node), Lang);
disco_sm_items(empty, From, To, Node, Lang) ->
disco_sm_items({result, []}, From, To, Node, Lang);
disco_sm_items({result, OtherItems}, From, To, Node, _Lang) ->
{result,
lists:usort(OtherItems ++
disco_items(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From))};
disco_sm_items(Acc, _From, _To, _Node, _Lang) ->
Acc.
disco_items(Host, <<>>, From) ->
Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx, owners = Owners}, Acc) ->
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
[{xmlelement, "item",
[{"node", binary_to_list(NodeID)},
{"jid", case Host of
{_,_,_} -> jlib:jid_to_string(Host);
_Host -> Host
end}
| case get_option(Options, title) of
false -> [];
[Title] -> [{"name", Title}]
end],
[]}
| Acc];
_ -> Acc
end
end,
case transaction(Host, Action, sync_dirty) of
{result, Items} -> Items;
_ -> []
end;
disco_sm_items(Acc, From, To, SNode, _Lang) ->
Host = To#jid.lserver,
Node = string_to_node(SNode),
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
% TODO call get_items/6 instead for access control (EJAB-1033)
case node_call(Type, get_items, [NodeId, From]) of
{result, []} ->
none;
{result, AllItems} ->
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
Items = case Acc of
{result, I} -> I;
_ -> []
end,
NodeItems = lists:map(
fun(#pubsub_item{itemid = {Id, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, Id]),
{xmlelement, "item", [{"jid", SBJID}, {"name", Name}], []}
end, AllItems),
{result, NodeItems ++ Items};
_ ->
none
end
end,
disco_items(Host, Node, From) ->
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, Items} ->
{result, [{xmlelement, "item",
[{"jid", case Host of
{_,_,_} -> jlib:jid_to_string(Host);
_Host -> Host
end},
{"name", ItemID}], []}
|| #pubsub_item{itemid = {ItemID,_}} <- Items]};
_ -> {result, []}
end
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Items}} -> {result, Items};
_ -> Acc
{result, {_, Result}} -> Result;
_ -> []
end.
%% -------
@ -858,25 +892,23 @@ terminate(_Reason, #state{host = Host,
case lists:member(?PEPNODE, Plugins) of
true ->
ejabberd_hooks:delete(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER);
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER);
false ->
ok
end,
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER),
mod_disco:unregister_feature(ServerHost, ?NS_PUBSUB),
gen_mod:get_module_proc(ServerHost, ?LOOPNAME) ! stop,
terminate_plugins(Host, ServerHost, Plugins, TreePlugin).
@ -1017,10 +1049,10 @@ command_disco_info(_Host, <<?NS_PUBSUB_GET_PENDING>>, _From) ->
node_disco_info(Host, Node, From) ->
node_disco_info(Host, Node, From, true, true).
node_disco_identity(Host, Node, From) ->
node_disco_info(Host, Node, From, true, false).
node_disco_features(Host, Node, From) ->
node_disco_info(Host, Node, From, false, true).
%node_disco_identity(Host, Node, From) ->
% node_disco_info(Host, Node, From, true, false).
%node_disco_features(Host, Node, From) ->
% node_disco_info(Host, Node, From, false, true).
node_disco_info(Host, Node, From, Identity, Features) ->
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
@ -1120,17 +1152,15 @@ iq_disco_items(Host, Item, From) ->
{result, []};
[SNode] ->
Node = string_to_node(SNode),
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
% TODO call get_items/6 instead for access control (EJAB-1033)
NodeItems = case node_call(Type, get_items, [NodeId, From]) of
{result, I} -> I;
_ -> []
end,
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
NodeItems = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, R} -> R;
_ -> []
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
Attrs =
case get_option(Options, title) of
case get_option(SubOptions, title) of
false ->
[{"jid", Host} |nodeAttr(SubNode)];
Title ->
@ -1151,24 +1181,6 @@ iq_disco_items(Host, Item, From) ->
end
end.
iq_local(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
ServerHost = To#jid.lserver,
%% Accept IQs to server only from our own users.
if
From#jid.lserver /= ServerHost ->
IQ#iq{type = error, sub_el = [?ERR_FORBIDDEN, SubEl]};
true ->
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(From)),
Res = case XMLNS of
?NS_PUBSUB -> iq_pubsub(LOwner, ServerHost, From, Type, SubEl, Lang);
?NS_PUBSUB_OWNER -> iq_pubsub_owner(LOwner, ServerHost, From, Type, SubEl, Lang)
end,
case Res of
{result, IQRes} -> IQ#iq{type = result, sub_el = IQRes};
{error, Error} -> IQ#iq{type = error, sub_el = [Error, SubEl]}
end
end.
iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
ServerHost = To#jid.lserver,
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
@ -1868,7 +1880,7 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
error -> {"", "", ""};
J -> jlib:jid_tolower(J)
end,
Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) ->
Action = fun(#pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId}) ->
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
@ -1877,21 +1889,7 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
AccessModel = get_option(Options, access_model),
SendLast = get_option(Options, send_last_published_item),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
{PresenceSubscription, RosterGroup} =
case Host of
{OUser, OServer, _} ->
get_roster_info(OUser, OServer,
Subscriber, AllowedGroups);
_ ->
case Subscriber of
{"", "", ""} ->
{false, false};
_ ->
{OU, OS, _} = Owner,
get_roster_info(OU, OS,
Subscriber, AllowedGroups)
end
end,
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
if
not SubscribeFeature ->
%% Node does not support subscriptions
@ -2234,20 +2232,13 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) ->
{error, Error} ->
{error, Error};
_ ->
Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId, owners = Owners}) ->
Features = features(Type),
RetreiveFeature = lists:member("retrieve-items", Features),
PersistentFeature = lists:member("persistent-items", Features),
AccessModel = get_option(Options, access_model),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
{PresenceSubscription, RosterGroup} =
case Host of
{OUser, OServer, _} ->
get_roster_info(OUser, OServer,
jlib:jid_tolower(From), AllowedGroups);
_ ->
{true, true}
end,
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
if
not RetreiveFeature ->
%% Item Retrieval Not Supported
@ -2297,6 +2288,12 @@ get_item(Host, Node, ItemId) ->
{result, {_, Items}} -> Items;
Error -> Error
end.
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
AccessModel = get_option(Options, access_model),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined]).
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
%% Host = pubsubHost()
@ -2774,8 +2771,24 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
end
end.
get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups) ->
if (AccessModel == presence) or (AccessModel == roster) ->
case Host of
{User, Server, _} ->
get_roster_info(User, Server, From, AllowedGroups);
_ ->
[{OUser, OServer, _}|_] = Owners,
get_roster_info(OUser, OServer, From, AllowedGroups)
end;
true ->
{true, true}
end.
%% @spec (OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, SubscriberResource}, AllowedGroups)
%% -> {PresenceSubscription, RosterGroup}
get_roster_info(_, _, {"", "", _}, _) ->
{false, false};
get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) ->
{Subscription, Groups} =
ejabberd_hooks:run_fold(
@ -2787,7 +2800,9 @@ get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, A
RosterGroup = lists:any(fun(Group) ->
lists:member(Group, AllowedGroups)
end, Groups),
{PresenceSubscription, RosterGroup}.
{PresenceSubscription, RosterGroup};
get_roster_info(OwnerUser, OwnerServer, JID, AllowedGroups) ->
get_roster_info(OwnerUser, OwnerServer, jlib:jid_tolower(JID), AllowedGroups).
%% @spec (AffiliationStr) -> Affiliation
%% AffiliationStr = string()
@ -3742,6 +3757,10 @@ transaction(Host, Node, Action, Trans) ->
Error
end
end, Trans).
transaction(Host, Action, Trans) ->
transaction(fun() ->
{result, lists:foldl(Action, [], tree_call(Host, get_nodes, [Host]))}
end, Trans).
transaction(Fun, Trans) ->
case catch mnesia:Trans(Fun) of

View File

@ -73,8 +73,7 @@
disco_sm_items/5
]).
%% exported iq handlers
-export([iq_local/3,
iq_sm/3
-export([iq_sm/3
]).
%% exports for console debug manual use
@ -198,24 +197,22 @@ init([ServerHost, Opts]) ->
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc),
case lists:member(?PEPNODE, Plugins) of
true ->
ejabberd_hooks:add(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB, ?MODULE, iq_local, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_local, IQDisc);
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc);
false ->
ok
end,
@ -387,15 +384,12 @@ send_loop(State) ->
%% disco hooks handling functions
%%
identity(Host) ->
Identity = case lists:member(?PEPNODE, plugins(Host)) of
true -> [{"category", "pubsub"}, {"type", "pep"}];
false -> [{"category", "pubsub"}, {"type", "service"}]
end,
{xmlelement, "identity", Identity, []}.
disco_local_identity(Acc, _From, To, [], _Lang) ->
Acc ++ [identity(To#jid.lserver)];
case lists:member(?PEPNODE, plugins(To#jid.lserver)) of
true ->
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []} | Acc];
false -> Acc
end;
disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
Acc.
@ -416,76 +410,120 @@ disco_local_items(Acc, _From, _To, [], _Lang) ->
disco_local_items(Acc, _From, _To, _Node, _Lang) ->
Acc.
disco_sm_identity(Acc, _From, To, [], _Lang) ->
Acc ++ [identity(To#jid.lserver)];
disco_sm_identity(Acc, From, To, Node, Lang) when is_list(Node) ->
disco_sm_identity(Acc, From, To, list_to_binary(Node), Lang);
disco_sm_identity(empty, From, To, Node, Lang) ->
disco_sm_identity([], From, To, Node, Lang);
disco_sm_identity(Acc, From, To, Node, _Lang) ->
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
Acc ++ case node_disco_identity(LOwner, From, Node) of
{result, I} -> I;
_ -> []
end.
disco_identity(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From) ++ Acc.
disco_sm_features(Acc, _From, _To, [], _Lang) ->
Acc;
disco_sm_features(Acc, From, To, Node, _Lang) ->
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
Features = node_disco_features(LOwner, From, Node),
case {Acc, Features} of
{{result, AccFeatures}, {result, AddFeatures}} ->
{result, AccFeatures++AddFeatures};
{_, {result, AddFeatures}} ->
{result, AddFeatures};
{_, _} ->
Acc
disco_identity(_Host, <<>>, _From) ->
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
disco_identity(Host, Node, From) ->
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
{xmlelement, "identity",
[{"category", "pubsub"},
{"type", "leaf"}
| case get_option(Options, title) of
false -> [];
[Title] -> [{"name", Title}]
end],
[]}]};
_ -> {result, []}
end
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> Result;
_ -> []
end.
disco_sm_items(Acc, From, To, [], _Lang) ->
Host = To#jid.lserver,
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
[] ->
Acc;
Nodes ->
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
Items = case Acc of
{result, I} -> I;
_ -> []
end,
NodeItems = lists:map(
fun(#pubsub_node{nodeid = {_, Node}}) ->
{xmlelement, "item",
[{"jid", SBJID}|nodeAttr(Node)],
[]}
end, Nodes),
{result, NodeItems ++ Items}
disco_sm_features(Acc, From, To, Node, Lang) when is_list(Node) ->
disco_sm_features(Acc, From, To, list_to_binary(Node), Lang);
disco_sm_features(empty, From, To, Node, Lang) ->
disco_sm_features({result, []}, From, To, Node, Lang);
disco_sm_features({result, OtherFeatures} = _Acc, From, To, Node, _Lang) ->
{result,
OtherFeatures ++
disco_features(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From)};
disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
Acc.
disco_features(_Host, <<>>, _From) ->
[?NS_PUBSUB
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
disco_features(Host, Node, From) ->
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
{result, [?NS_PUBSUB
| [?NS_PUBSUB ++ "#" ++ Feature || Feature <- features("pep")]]};
_ -> {result, []}
end
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> Result;
_ -> []
end.
disco_sm_items(Acc, From, To, Node, Lang) when is_list(Node) ->
disco_sm_items(Acc, From, To, list_to_binary(Node), Lang);
disco_sm_items(empty, From, To, Node, Lang) ->
disco_sm_items({result, []}, From, To, Node, Lang);
disco_sm_items({result, OtherItems}, From, To, Node, _Lang) ->
{result,
lists:usort(OtherItems ++
disco_items(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From))};
disco_sm_items(Acc, _From, _To, _Node, _Lang) ->
Acc.
disco_items(Host, <<>>, From) ->
Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx}, Acc) ->
Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
[{xmlelement, "item",
[{"node", binary_to_list(NodeID)},
{"jid", case Host of
{_,_,_} -> jlib:jid_to_string(Host);
_Host -> Host
end}
| case get_option(Options, title) of
false -> [];
[Title] -> [{"name", Title}]
end],
[]}
| Acc];
_ -> Acc
end
end,
case transaction_on_nodes(Host, Action, sync_dirty) of
{result, Items} -> Items;
_ -> []
end;
disco_sm_items(Acc, From, To, SNode, _Lang) ->
Host = To#jid.lserver,
Node = string_to_node(SNode),
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
% TODO call get_items/6 instead for access control (EJAB-1033)
case node_call(Type, get_items, [NodeId, From]) of
{result, []} ->
none;
{result, AllItems} ->
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
Items = case Acc of
{result, I} -> I;
_ -> []
end,
NodeItems = lists:map(
fun(#pubsub_item{itemid = {Id, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, Id]),
{xmlelement, "item", [{"jid", SBJID}, {"name", Name}], []}
end, AllItems),
{result, NodeItems ++ Items};
_ ->
none
end
end,
disco_items(Host, Node, From) ->
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, Items} ->
{result, [{xmlelement, "item",
[{"jid", case Host of
{_,_,_} -> jlib:jid_to_string(Host);
_Host -> Host
end},
{"name", ItemID}], []}
|| #pubsub_item{itemid = {ItemID,_}} <- Items]};
_ -> {result, []}
end
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Items}} -> {result, Items};
_ -> Acc
{result, {_, Result}} -> Result;
_ -> []
end.
%% -------
@ -661,25 +699,23 @@ terminate(_Reason, #state{host = Host,
case lists:member(?PEPNODE, Plugins) of
true ->
ejabberd_hooks:delete(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER);
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER);
false ->
ok
end,
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER),
mod_disco:unregister_feature(ServerHost, ?NS_PUBSUB),
gen_mod:get_module_proc(ServerHost, ?LOOPNAME) ! stop,
terminate_plugins(Host, ServerHost, Plugins, TreePlugin).
@ -821,10 +857,10 @@ command_disco_info(_Host, <<?NS_PUBSUB_GET_PENDING>>, _From) ->
node_disco_info(Host, Node, From) ->
node_disco_info(Host, Node, From, true, true).
node_disco_identity(Host, Node, From) ->
node_disco_info(Host, Node, From, true, false).
node_disco_features(Host, Node, From) ->
node_disco_info(Host, Node, From, false, true).
%node_disco_identity(Host, Node, From) ->
% node_disco_info(Host, Node, From, true, false).
%node_disco_features(Host, Node, From) ->
% node_disco_info(Host, Node, From, false, true).
node_disco_info(Host, Node, From, Identity, Features) ->
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
@ -926,17 +962,16 @@ iq_disco_items(Host, Item, From, RSM) ->
{result, []};
[SNode] ->
Node = string_to_node(SNode),
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
%% TODO call get_items/6 instead for access control (EJAB-1033)
{NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
{result, I} -> I;
_ -> {[], none}
end,
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
Owners = node_owners_call(Type, Idx),
{NodeItems, RsmOut} = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners, RSM) of
{result, R} -> R;
_ -> {[], none}
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
Attrs =
case get_option(Options, title) of
case get_option(SubOptions, title) of
false ->
[{"jid", Host} |nodeAttr(SubNode)];
Title ->
@ -957,24 +992,6 @@ iq_disco_items(Host, Item, From, RSM) ->
end
end.
iq_local(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
ServerHost = To#jid.lserver,
%% Accept IQs to server only from our own users.
if
From#jid.lserver /= ServerHost ->
IQ#iq{type = error, sub_el = [?ERR_FORBIDDEN, SubEl]};
true ->
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(From)),
Res = case XMLNS of
?NS_PUBSUB -> iq_pubsub(LOwner, ServerHost, From, Type, SubEl, Lang);
?NS_PUBSUB_OWNER -> iq_pubsub_owner(LOwner, ServerHost, From, Type, SubEl, Lang)
end,
case Res of
{result, IQRes} -> IQ#iq{type = result, sub_el = IQRes};
{error, Error} -> IQ#iq{type = error, sub_el = [Error, SubEl]}
end
end.
iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
ServerHost = To#jid.lserver,
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
@ -1687,25 +1704,8 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
AccessModel = get_option(Options, access_model),
SendLast = get_option(Options, send_last_published_item),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
{PresenceSubscription, RosterGroup} =
case Host of
{OUser, OServer, _} ->
get_roster_info(OUser, OServer,
Subscriber, AllowedGroups);
_ ->
case Subscriber of
{"", "", ""} ->
{false, false};
_ ->
case node_owners_call(Type, NodeId) of
[{OU, OS, _}|_] ->
get_roster_info(OU, OS,
Subscriber, AllowedGroups);
_ ->
{false, false}
end
end
end,
Owners = node_owners_call(Type, NodeId),
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
if
not SubscribeFeature ->
%% Node does not support subscriptions
@ -2054,14 +2054,8 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs, RSM) ->
PersistentFeature = lists:member("persistent-items", Features),
AccessModel = get_option(Options, access_model),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
{PresenceSubscription, RosterGroup} =
case Host of
{OUser, OServer, _} ->
get_roster_info(OUser, OServer,
jlib:jid_tolower(From), AllowedGroups);
_ ->
{true, true}
end,
Owners = node_owners_call(Type, NodeId),
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
if
not RetreiveFeature ->
%% Item Retrieval Not Supported
@ -2112,6 +2106,17 @@ get_item(Host, Node, ItemId) ->
{result, {_, Items}} -> Items;
Error -> Error
end.
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
case get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, none) of
{result, {I, _}} -> {result, I};
Error -> Error
end.
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, RSM) ->
AccessModel = get_option(Options, access_model),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined, RSM]).
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
%% Host = pubsubHost()
@ -2584,8 +2589,24 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
end
end.
get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups) ->
if (AccessModel == presence) or (AccessModel == roster) ->
case Host of
{User, Server, _} ->
get_roster_info(User, Server, From, AllowedGroups);
_ ->
[{OUser, OServer, _}|_] = Owners,
get_roster_info(OUser, OServer, From, AllowedGroups)
end;
true ->
{true, true}
end.
%% @spec (OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, SubscriberResource}, AllowedGroups)
%% -> {PresenceSubscription, RosterGroup}
get_roster_info(_, _, {"", "", _}, _) ->
{false, false};
get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) ->
{Subscription, Groups} =
ejabberd_hooks:run_fold(
@ -2597,7 +2618,9 @@ get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, A
RosterGroup = lists:any(fun(Group) ->
lists:member(Group, AllowedGroups)
end, Groups),
{PresenceSubscription, RosterGroup}.
{PresenceSubscription, RosterGroup};
get_roster_info(OwnerUser, OwnerServer, JID, AllowedGroups) ->
get_roster_info(OwnerUser, OwnerServer, jlib:jid_tolower(JID), AllowedGroups).
%% @spec (AffiliationStr) -> Affiliation
%% AffiliationStr = string()
@ -3582,6 +3605,10 @@ transaction(Host, Node, Action, Trans) ->
Error
end
end, Trans).
transaction_on_nodes(Host, Action, Trans) ->
transaction(Host, fun() ->
{result, lists:foldl(Action, [], tree_call(Host, get_nodes, [Host]))}
end, Trans).
transaction(Host, Fun, Trans) ->
transaction_retry(Host, Fun, Trans, 2).

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-06-02 15:03:48.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-06-02 16:45:38.000000000 +0200
--- mod_pubsub.erl 2010-08-02 16:07:28.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-08-02 17:04:37.000000000 +0200
@@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18.
@ -22,7 +22,7 @@
%% exports for hooks
-export([presence_probe/3,
@@ -104,7 +104,7 @@
@@ -103,7 +103,7 @@
string_to_affiliation/1,
extended_error/2,
extended_error/3,
@ -31,7 +31,7 @@
]).
%% API and gen_server callbacks
@@ -123,7 +123,7 @@
@@ -122,7 +122,7 @@
-export([send_loop/1
]).
@ -40,7 +40,7 @@
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
-define(PLUGIN_PREFIX, "node_").
-define(TREE_PREFIX, "nodetree_").
@@ -220,8 +220,6 @@
@@ -217,8 +217,6 @@
ok
end,
ejabberd_router:register_route(Host),
@ -49,7 +49,7 @@
init_nodes(Host, ServerHost, NodeTree, Plugins),
State = #state{host = Host,
server_host = ServerHost,
@@ -280,207 +278,14 @@
@@ -277,207 +275,14 @@
init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
%% TODO, this call should be done plugin side
@ -260,7 +260,7 @@
send_loop(State) ->
receive
{presence, JID, Pid} ->
@@ -491,17 +296,15 @@
@@ -488,17 +293,15 @@
%% for each node From is subscribed to
%% and if the node is so configured, send the last published item to From
lists:foreach(fun(PType) ->
@ -284,7 +284,54 @@
true ->
% resource not concerned about that subscription
ok
@@ -747,10 +550,10 @@
@@ -617,7 +420,8 @@
disco_identity(_Host, <<>>, _From) ->
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
disco_identity(Host, Node, From) ->
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
+ Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
@@ -652,7 +456,8 @@
[?NS_PUBSUB
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
disco_features(Host, Node, From) ->
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
+ Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
{result, [?NS_PUBSUB
@@ -677,7 +482,8 @@
Acc.
disco_items(Host, <<>>, From) ->
- Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx, owners = Owners}, Acc) ->
+ Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx}, Acc) ->
+ Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, _} ->
[{xmlelement, "item",
@@ -695,13 +501,14 @@
_ -> Acc
end
end,
- case transaction(Host, Action, sync_dirty) of
+ case transaction_on_nodes(Host, Action, sync_dirty) of
{result, Items} -> Items;
_ -> []
end;
disco_items(Host, Node, From) ->
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
+ Owners = node_owners_call(Type, Idx),
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
{result, Items} ->
{result, [{xmlelement, "item",
@@ -781,10 +588,10 @@
lists:foreach(fun(PType) ->
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
lists:foreach(fun
@ -297,7 +344,7 @@
true ->
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
false ->
@@ -920,7 +723,8 @@
@@ -952,7 +759,8 @@
sub_el = SubEl} = IQ ->
{xmlelement, _, QAttrs, _} = SubEl,
Node = xml:get_attr_s("node", QAttrs),
@ -307,7 +354,7 @@
{result, IQRes} ->
jlib:iq_to_xml(
IQ#iq{type = result,
@@ -1033,7 +837,7 @@
@@ -1065,7 +873,7 @@
[] ->
["leaf"]; %% No sub-nodes: it's a leaf node
_ ->
@ -316,7 +363,7 @@
{result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"];
_ -> []
@@ -1049,8 +853,9 @@
@@ -1081,8 +889,9 @@
[];
true ->
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
@ -328,7 +375,7 @@
end, features(Type))]
end,
%% TODO: add meta-data info (spec section 5.4)
@@ -1079,8 +884,9 @@
@@ -1111,8 +920,9 @@
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
{xmlelement, "feature", [{"var", ?NS_COMMANDS}], []},
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
@ -340,7 +387,7 @@
end, features(Host, Node))};
<<?NS_COMMANDS>> ->
command_disco_info(Host, Node, From);
@@ -1090,7 +896,7 @@
@@ -1122,7 +932,7 @@
node_disco_info(Host, Node, From)
end.
@ -349,7 +396,7 @@
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) ->
{result, lists:map(
@@ -1107,14 +913,14 @@
@@ -1139,23 +949,24 @@
Other ->
Other
end;
@ -367,21 +414,20 @@
case string:tokens(Item, "!") of
[_SNode, _ItemID] ->
{result, []};
@@ -1122,10 +928,10 @@
[SNode] ->
Node = string_to_node(SNode),
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
- % TODO call get_items/6 instead for access control (EJAB-1033)
- NodeItems = case node_call(Type, get_items, [NodeId, From]) of
+ %% TODO call get_items/6 instead for access control (EJAB-1033)
+ {NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
{result, I} -> I;
- _ -> []
+ _ -> {[], none}
end,
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
- NodeItems = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
+ Owners = node_owners_call(Type, Idx),
+ {NodeItems, RsmOut} = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners, RSM) of
{result, R} -> R;
- _ -> []
+ _ -> {[], none}
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
@@ -1143,7 +949,7 @@
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
@@ -1173,7 +984,7 @@
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
{xmlelement, "item", [{"jid", Host}, {"name", Name}], []}
end, NodeItems),
@ -390,7 +436,7 @@
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> {result, Result};
@@ -1272,7 +1078,8 @@
@@ -1284,7 +1095,8 @@
(_, Acc) ->
Acc
end, [], xml:remove_cdata(Els)),
@ -400,7 +446,7 @@
{get, "subscriptions"} ->
get_subscriptions(Host, Node, From, Plugins);
{get, "affiliations"} ->
@@ -1295,7 +1102,9 @@
@@ -1307,7 +1119,9 @@
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
{xmlelement, _, _, SubEls} = SubEl,
@ -411,7 +457,7 @@
case Action of
[{xmlelement, Name, Attrs, Els}] ->
Node = string_to_node(xml:get_attr_s("node", Attrs)),
@@ -1425,7 +1234,8 @@
@@ -1437,7 +1251,8 @@
_ -> []
end
end,
@ -421,7 +467,7 @@
sync_dirty) of
{result, Res} -> Res;
Err -> Err
@@ -1464,7 +1274,7 @@
@@ -1476,7 +1291,7 @@
%%% authorization handling
@ -430,7 +476,7 @@
Lang = "en", %% TODO fix
Stanza = {xmlelement, "message",
[],
@@ -1493,7 +1303,7 @@
@@ -1505,7 +1320,7 @@
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
lists:foreach(fun(Owner) ->
ejabberd_router:route(service_jid(Host), jlib:make_jid(Owner), Stanza)
@ -439,7 +485,7 @@
find_authorization_response(Packet) ->
{xmlelement, _Name, _Attrs, Els} = Packet,
@@ -1557,8 +1367,8 @@
@@ -1569,8 +1384,8 @@
"true" -> true;
_ -> false
end,
@ -450,7 +496,7 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if
not IsApprover ->
@@ -1757,7 +1567,7 @@
@@ -1769,7 +1584,7 @@
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
[{xmlelement, "create", nodeAttr(Node),
[]}]}],
@ -459,7 +505,7 @@
{result, {NodeId, SubsByDepth, {Result, broadcast}}} ->
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth),
case Result of
@@ -1860,7 +1670,7 @@
@@ -1872,7 +1687,7 @@
%%<li>The node does not exist.</li>
%%</ul>
subscribe_node(Host, Node, From, JID, Configuration) ->
@ -468,33 +514,24 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -1868,7 +1678,7 @@
@@ -1880,7 +1695,7 @@
error -> {"", "", ""};
J -> jlib:jid_tolower(J)
end,
- Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) ->
- Action = fun(#pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId}) ->
+ Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
@@ -1887,9 +1697,13 @@
{"", "", ""} ->
{false, false};
_ ->
- {OU, OS, _} = Owner,
- get_roster_info(OU, OS,
- Subscriber, AllowedGroups)
+ case node_owners_call(Type, NodeId) of
+ [{OU, OS, _}|_] ->
+ get_roster_info(OU, OS,
+ Subscriber, AllowedGroups);
+ _ ->
+ {false, false}
+ end
end
end,
@@ -1889,6 +1704,7 @@
AccessModel = get_option(Options, access_model),
SendLast = get_option(Options, send_last_published_item),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
+ Owners = node_owners_call(Type, NodeId),
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
if
@@ -2220,7 +2034,7 @@
not SubscribeFeature ->
@@ -2218,7 +2034,7 @@
%% <p>The permission are not checked in this function.</p>
%% @todo We probably need to check that the user doing the query has the right
%% to read the items.
@ -503,7 +540,22 @@
MaxItems =
if
SMaxItems == "" -> get_max_items_node(Host);
@@ -2259,11 +2073,11 @@
@@ -2232,12 +2048,13 @@
{error, Error} ->
{error, Error};
_ ->
- Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId, owners = Owners}) ->
+ Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
Features = features(Type),
RetreiveFeature = lists:member("retrieve-items", Features),
PersistentFeature = lists:member("persistent-items", Features),
AccessModel = get_option(Options, access_model),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
+ Owners = node_owners_call(Type, NodeId),
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
if
not RetreiveFeature ->
@@ -2250,11 +2067,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
@ -517,7 +569,7 @@
SendItems = case ItemIDs of
[] ->
Items;
@@ -2276,7 +2090,8 @@
@@ -2267,7 +2084,8 @@
%% number of items sent to MaxItems:
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
[{xmlelement, "items", nodeAttr(Node),
@ -527,7 +579,24 @@
Error ->
Error
end
@@ -2308,16 +2123,27 @@
@@ -2289,10 +2107,15 @@
Error -> Error
end.
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
+ case get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, none) of
+ {result, {I, _}} -> {result, I};
+ Error -> Error
+ end.
+get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, RSM) ->
AccessModel = get_option(Options, access_model),
AllowedGroups = get_option(Options, roster_groups_allowed, []),
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
- node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined]).
+ node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined, RSM]).
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
@@ -2305,16 +2128,27 @@
%% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) ->
@ -561,7 +630,7 @@
send_items(Host, Node, NodeId, Type, LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
@@ -2443,7 +2269,8 @@
@@ -2440,7 +2274,8 @@
error ->
{error, ?ERR_BAD_REQUEST};
_ ->
@ -571,7 +640,7 @@
case lists:member(Owner, Owners) of
true ->
OwnerJID = jlib:make_jid(Owner),
@@ -2453,24 +2280,7 @@
@@ -2450,24 +2285,7 @@
end,
lists:foreach(
fun({JID, Affiliation}) ->
@ -597,7 +666,7 @@
end, FilteredEntities),
{result, []};
_ ->
@@ -2523,11 +2333,11 @@
@@ -2520,11 +2338,11 @@
end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -611,7 +680,7 @@
OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)},
{"subid", SubID}|nodeAttr(Node)],
[XdataEl]},
@@ -2553,7 +2363,7 @@
@@ -2550,7 +2368,7 @@
end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -620,7 +689,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -2582,7 +2392,7 @@
@@ -2579,7 +2397,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error(?ERR_BAD_REQUEST, "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) ->
@ -629,7 +698,7 @@
{error, notfound} ->
{error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
{result, _} ->
@@ -2750,8 +2560,8 @@
@@ -2747,8 +2565,8 @@
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza)
end,
@ -640,7 +709,7 @@
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3088,7 +2898,7 @@
@@ -3103,7 +2921,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
@ -649,7 +718,7 @@
{result, CollSubs} -> CollSubs;
_ -> []
end.
@@ -3102,9 +2912,9 @@
@@ -3117,9 +2935,9 @@
get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -661,7 +730,7 @@
_ -> Acc
end;
(_, Acc) ->
@@ -3308,6 +3118,30 @@
@@ -3323,6 +3141,30 @@
Result
end.
@ -692,7 +761,7 @@
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
@@ -3704,7 +3538,13 @@
@@ -3719,7 +3561,13 @@
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
@ -707,7 +776,7 @@
%% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) ->
@@ -3724,13 +3564,13 @@
@@ -3739,13 +3587,13 @@
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -723,9 +792,16 @@
case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) ->
case Action(N) of
@@ -3743,8 +3583,14 @@
@@ -3757,13 +3605,19 @@
Error
end
end, Trans).
-transaction(Host, Action, Trans) ->
- transaction(fun() ->
+transaction_on_nodes(Host, Action, Trans) ->
+ transaction(Host, fun() ->
{result, lists:foldl(Action, [], tree_call(Host, get_nodes, [Host]))}
end, Trans).
-transaction(Fun, Trans) ->
- case catch mnesia:Trans(Fun) of
@ -740,7 +816,7 @@
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
@@ -3752,6 +3598,15 @@
@@ -3771,6 +3625,15 @@
{aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, ?ERR_INTERNAL_SERVER_ERROR};
@ -756,7 +832,7 @@
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, ?ERR_INTERNAL_SERVER_ERROR};
@@ -3760,6 +3615,17 @@
@@ -3779,6 +3642,17 @@
{error, ?ERR_INTERNAL_SERVER_ERROR}
end.

View File

@ -187,6 +187,18 @@ process_iq(From, To,
sub_el = [SubEl, ?ERR_BAD_REQUEST]}
end;
get ->
{UsernameSubels, QuerySubels} =
case From of
#jid{user = User, lserver = Server} ->
case ejabberd_auth:is_user_exists(User,Server) of
true ->
{[{xmlcdata, User}], [{xmlelement, "registered", [], []}]};
false ->
{[{xmlcdata, User}], []}
end;
_ ->
{[], []}
end,
IQ#iq{type = result,
sub_el = [{xmlelement,
"query",
@ -197,8 +209,9 @@ process_iq(From, To,
Lang,
"Choose a username and password "
"to register with this server")}]},
{xmlelement, "username", [], []},
{xmlelement, "password", [], []}]}]}
{xmlelement, "username", [], UsernameSubels},
{xmlelement, "password", [], []}
| QuerySubels]}]}
end.
%% @doc Try to change password and return IQ response

View File

@ -33,8 +33,6 @@
-module(mod_http_bind).
-author('steve@zeank.in-berlin.de').
-define(MOD_HTTP_BIND_VERSION, "1.2").
%%-define(ejabberd_debug, true).
-behaviour(gen_mod).
@ -80,7 +78,7 @@ process(_Path, _Request) ->
[{xmlcdata, "400 Bad Request"}]}}.
get_human_html_xmlel() ->
Heading = "ejabberd " ++ atom_to_list(?MODULE) ++ " v" ++ ?MOD_HTTP_BIND_VERSION,
Heading = "ejabberd " ++ atom_to_list(?MODULE),
{xmlelement, "html", [{"xmlns", "http://www.w3.org/1999/xhtml"}],
[{xmlelement, "head", [],
[{xmlelement, "title", [], [{xmlcdata, Heading}]}]},