2006-11-03 16:42:21 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_privacy_odbc.erl
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2006-11-03 16:42:21 +01:00
|
|
|
%%% Purpose : jabber:iq:privacy support
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Created : 5 Oct 2006 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2010-01-12 17:15:16 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
2007-12-24 13:58:05 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2008-07-11 14:48:27 +02:00
|
|
|
%%%
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2006-11-03 16:42:21 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_privacy_odbc).
|
2007-12-24 13:58:05 +01:00
|
|
|
-author('alexey@process-one.net').
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
|
|
|
-export([start/2, stop/1,
|
|
|
|
process_iq/3,
|
|
|
|
process_iq_set/4,
|
|
|
|
process_iq_get/5,
|
|
|
|
get_user_list/3,
|
|
|
|
check_packet/6,
|
2009-01-19 11:14:04 +01:00
|
|
|
remove_user/2,
|
2006-11-03 16:42:21 +01:00
|
|
|
updated_list/3]).
|
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
-include_lib("exmpp/include/exmpp.hrl").
|
|
|
|
|
2006-11-03 16:42:21 +01:00
|
|
|
-include("ejabberd.hrl").
|
2007-07-26 11:37:16 +02:00
|
|
|
-include("mod_privacy.hrl").
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
start(Host, Opts) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
HostB = list_to_binary(Host),
|
2006-11-03 16:42:21 +01:00
|
|
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:add(privacy_iq_get, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, process_iq_get, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:add(privacy_iq_set, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, process_iq_set, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:add(privacy_get_user_list, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, get_user_list, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:add(privacy_check_packet, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, check_packet, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:add(privacy_updated_list, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, updated_list, 50),
|
2009-01-19 11:14:04 +01:00
|
|
|
ejabberd_hooks:add(remove_user, HostB,
|
|
|
|
?MODULE, remove_user, 50),
|
2009-01-10 17:10:12 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, HostB, ?NS_PRIVACY,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, process_iq, IQDisc).
|
|
|
|
|
|
|
|
stop(Host) ->
|
2009-01-03 16:15:38 +01:00
|
|
|
HostB = list_to_binary(Host),
|
|
|
|
ejabberd_hooks:delete(privacy_iq_get, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, process_iq_get, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:delete(privacy_iq_set, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, process_iq_set, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:delete(privacy_get_user_list, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, get_user_list, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:delete(privacy_check_packet, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, check_packet, 50),
|
2009-01-03 16:15:38 +01:00
|
|
|
ejabberd_hooks:delete(privacy_updated_list, HostB,
|
2006-11-03 16:42:21 +01:00
|
|
|
?MODULE, updated_list, 50),
|
2009-01-19 11:14:04 +01:00
|
|
|
ejabberd_hooks:delete(remove_user, HostB,
|
|
|
|
?MODULE, remove_user, 50),
|
2009-01-10 17:10:12 +01:00
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, HostB, ?NS_PRIVACY).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_iq(_From, _To, IQ_Rec) ->
|
|
|
|
exmpp_iq:error(IQ_Rec, 'not-allowed').
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_iq_get(_, From, _To, #iq{payload = SubEl},
|
2006-11-03 16:42:21 +01:00
|
|
|
#userlist{name = Active}) ->
|
2009-06-01 18:40:51 +02:00
|
|
|
LUser = exmpp_jid:prep_node_as_list(From),
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(From),
|
2008-10-06 17:01:36 +02:00
|
|
|
case exmpp_xml:get_child_elements(SubEl) of
|
2006-11-03 16:42:21 +01:00
|
|
|
[] ->
|
|
|
|
process_lists_get(LUser, LServer, Active);
|
2008-10-06 17:01:36 +02:00
|
|
|
[#xmlel{name = Name} = Child] ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case Name of
|
2008-10-06 17:01:36 +02:00
|
|
|
list ->
|
2009-01-21 14:34:26 +01:00
|
|
|
ListName = exmpp_xml:get_attribute_as_list(Child, name, false),
|
2006-11-03 16:42:21 +01:00
|
|
|
process_list_get(LUser, LServer, ListName);
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'bad-request'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'bad-request'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
process_lists_get(LUser, LServer, Active) ->
|
|
|
|
Default = case catch sql_get_default_privacy_list(LUser, LServer) of
|
|
|
|
{selected, ["name"], []} ->
|
|
|
|
none;
|
|
|
|
{selected, ["name"], [{DefName}]} ->
|
2008-09-16 16:39:57 +02:00
|
|
|
DefName;
|
|
|
|
_ ->
|
|
|
|
none
|
2006-11-03 16:42:21 +01:00
|
|
|
end,
|
|
|
|
case catch sql_get_privacy_list_names(LUser, LServer) of
|
|
|
|
{selected, ["name"], []} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{result, #xmlel{ns = ?NS_PRIVACY, name = 'query'}};
|
2006-11-03 16:42:21 +01:00
|
|
|
{selected, ["name"], Names} ->
|
|
|
|
LItems = lists:map(
|
|
|
|
fun({N}) ->
|
2008-10-06 17:01:36 +02:00
|
|
|
exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = list}, name, N)
|
2006-11-03 16:42:21 +01:00
|
|
|
end, Names),
|
|
|
|
DItems =
|
|
|
|
case Default of
|
|
|
|
none ->
|
|
|
|
LItems;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
[exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = default}, name, Default) | LItems]
|
2006-11-03 16:42:21 +01:00
|
|
|
end,
|
|
|
|
ADItems =
|
|
|
|
case Active of
|
|
|
|
none ->
|
|
|
|
DItems;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
[exmpp_xml:set_attribute(#xmlel{ns = ?NS_PRIVACY, name = active}, name, Active) | DItems]
|
2006-11-03 16:42:21 +01:00
|
|
|
end,
|
2008-10-06 17:01:36 +02:00
|
|
|
{result, #xmlel{ns = ?NS_PRIVACY, name = 'query', children = ADItems}};
|
2008-09-16 16:39:57 +02:00
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'internal-server-error'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end.
|
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_list_get(_LUser, _LServer, false) ->
|
|
|
|
{error, 'bad-request'};
|
|
|
|
|
|
|
|
process_list_get(LUser, LServer, Name) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case catch sql_get_privacy_list_id(LUser, LServer, Name) of
|
|
|
|
{selected, ["id"], []} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'item-not-found'};
|
2006-11-03 16:42:21 +01:00
|
|
|
{selected, ["id"], [{ID}]} ->
|
|
|
|
case catch sql_get_privacy_list_data_by_id(ID, LServer) of
|
|
|
|
{selected, ["t", "value", "action", "ord", "match_all",
|
|
|
|
"match_iq", "match_message",
|
|
|
|
"match_presence_in", "match_presence_out"],
|
|
|
|
RItems} ->
|
|
|
|
Items = lists:map(fun raw_to_item/1, RItems),
|
|
|
|
LItems = lists:map(fun item_to_xml/1, Items),
|
2008-10-06 17:01:36 +02:00
|
|
|
ListEl = exmpp_xml:set_attribute(#xmlel{name = list,
|
|
|
|
ns = ?NS_PRIVACY,
|
|
|
|
children = LItems},
|
|
|
|
name,
|
|
|
|
Name),
|
|
|
|
{result, #xmlel{ns = ?NS_PRIVACY, name = 'query', children = [ListEl]}};
|
|
|
|
_ ->
|
|
|
|
{error, 'internal-server-error'}
|
2008-09-16 16:39:57 +02:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'internal-server-error'}
|
|
|
|
end.
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
item_to_xml(Item) ->
|
2009-01-21 14:34:26 +01:00
|
|
|
Attrs1 = [?XMLATTR('action', action_to_binary(Item#listitem.action)),
|
|
|
|
?XMLATTR('order', order_to_binary(Item#listitem.order))],
|
2006-11-03 16:42:21 +01:00
|
|
|
Attrs2 = case Item#listitem.type of
|
|
|
|
none ->
|
|
|
|
Attrs1;
|
|
|
|
Type ->
|
2009-01-21 14:34:26 +01:00
|
|
|
[?XMLATTR('type', type_to_binary(Item#listitem.type)),
|
|
|
|
?XMLATTR('value', value_to_binary(Type, Item#listitem.value)) |
|
2006-11-03 16:42:21 +01:00
|
|
|
Attrs1]
|
|
|
|
end,
|
|
|
|
SubEls = case Item#listitem.match_all of
|
|
|
|
true ->
|
|
|
|
[];
|
|
|
|
false ->
|
|
|
|
SE1 = case Item#listitem.match_iq of
|
|
|
|
true ->
|
2008-10-06 17:01:36 +02:00
|
|
|
[#xmlel{ns = ?NS_PRIVACY, name = iq}];
|
2006-11-03 16:42:21 +01:00
|
|
|
false ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
SE2 = case Item#listitem.match_message of
|
|
|
|
true ->
|
2008-10-06 17:01:36 +02:00
|
|
|
[#xmlel{ns = ?NS_PRIVACY, name = message} | SE1];
|
2006-11-03 16:42:21 +01:00
|
|
|
false ->
|
|
|
|
SE1
|
|
|
|
end,
|
|
|
|
SE3 = case Item#listitem.match_presence_in of
|
|
|
|
true ->
|
2008-10-06 17:01:36 +02:00
|
|
|
[#xmlel{ns = ?NS_PRIVACY, name = 'presence-in'} | SE2];
|
2006-11-03 16:42:21 +01:00
|
|
|
false ->
|
|
|
|
SE2
|
|
|
|
end,
|
|
|
|
SE4 = case Item#listitem.match_presence_out of
|
|
|
|
true ->
|
2008-10-06 17:01:36 +02:00
|
|
|
[#xmlel{ns = ?NS_PRIVACY, name = 'presence-out'} | SE3];
|
2006-11-03 16:42:21 +01:00
|
|
|
false ->
|
|
|
|
SE3
|
|
|
|
end,
|
|
|
|
SE4
|
|
|
|
end,
|
2008-10-06 17:01:36 +02:00
|
|
|
exmpp_xml:set_attributes(#xmlel{ns = ?NS_PRIVACY, name = item, children = SubEls}, Attrs2).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
|
2009-01-08 15:54:00 +01:00
|
|
|
action_to_binary(Action) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case Action of
|
2009-01-08 15:54:00 +01:00
|
|
|
allow -> <<"allow">>;
|
|
|
|
deny -> <<"deny">>
|
2006-11-03 16:42:21 +01:00
|
|
|
end.
|
|
|
|
|
2009-01-08 15:54:00 +01:00
|
|
|
order_to_binary(Order) ->
|
|
|
|
list_to_binary(integer_to_list(Order)).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
2009-01-08 15:54:00 +01:00
|
|
|
type_to_binary(Type) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case Type of
|
2009-01-08 15:54:00 +01:00
|
|
|
jid -> <<"jid">>;
|
|
|
|
group -> <<"group">>;
|
|
|
|
subscription -> <<"subscription">>
|
2006-11-03 16:42:21 +01:00
|
|
|
end.
|
|
|
|
|
2009-01-08 15:54:00 +01:00
|
|
|
value_to_binary(Type, Val) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case Type of
|
2008-10-06 17:01:36 +02:00
|
|
|
jid ->
|
|
|
|
{N, D, R} = Val,
|
2009-06-01 18:59:08 +02:00
|
|
|
exmpp_jid:to_binary(N, D, R);
|
2006-11-03 16:42:21 +01:00
|
|
|
group -> Val;
|
|
|
|
subscription ->
|
|
|
|
case Val of
|
2009-01-08 15:54:00 +01:00
|
|
|
both -> <<"both">>;
|
|
|
|
to -> <<"to">>;
|
|
|
|
from -> <<"from">>;
|
|
|
|
none -> <<"none">>
|
2006-11-03 16:42:21 +01:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list_to_action(S) ->
|
|
|
|
case S of
|
|
|
|
"allow" -> allow;
|
|
|
|
"deny" -> deny
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_iq_set(_, From, _To, #iq{payload = SubEl}) ->
|
2009-06-01 18:40:51 +02:00
|
|
|
LUser = exmpp_jid:prep_node_as_list(From),
|
2009-06-01 18:38:28 +02:00
|
|
|
LServer = exmpp_jid:prep_domain_as_list(From),
|
2008-10-06 17:01:36 +02:00
|
|
|
case exmpp_xml:get_child_elements(SubEl) of
|
|
|
|
[#xmlel{name = Name} = Child] ->
|
2009-01-21 14:34:26 +01:00
|
|
|
ListName = exmpp_xml:get_attribute_as_list(Child, 'name', false),
|
2006-11-03 16:42:21 +01:00
|
|
|
case Name of
|
2008-10-06 17:01:36 +02:00
|
|
|
list ->
|
2006-11-03 16:42:21 +01:00
|
|
|
process_list_set(LUser, LServer, ListName,
|
2008-10-06 17:01:36 +02:00
|
|
|
exmpp_xml:get_child_elements(Child));
|
|
|
|
active ->
|
2006-11-03 16:42:21 +01:00
|
|
|
process_active_set(LUser, LServer, ListName);
|
2008-10-06 17:01:36 +02:00
|
|
|
default ->
|
2006-11-03 16:42:21 +01:00
|
|
|
process_default_set(LUser, LServer, ListName);
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'bad-request'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'bad-request'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_default_set(LUser, LServer, false) ->
|
|
|
|
case catch sql_unset_default_privacy_list(LUser, LServer) of
|
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
{error, 'internal_server_error'};
|
|
|
|
{error, _Reason} ->
|
|
|
|
{error, 'internal_server_error'};
|
|
|
|
_ ->
|
|
|
|
{result, []}
|
|
|
|
end;
|
|
|
|
|
|
|
|
process_default_set(LUser, LServer, Name) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
F = fun() ->
|
|
|
|
case sql_get_privacy_list_names_t(LUser) of
|
|
|
|
{selected, ["name"], []} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'item-not-found'};
|
2006-11-03 16:42:21 +01:00
|
|
|
{selected, ["name"], Names} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
case lists:member({Name}, Names) of
|
2006-11-03 16:42:21 +01:00
|
|
|
true ->
|
|
|
|
sql_set_default_privacy_list(LUser, Name),
|
|
|
|
{result, []};
|
|
|
|
false ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'item-not-found'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
case odbc_queries:sql_transaction(LServer, F) of
|
|
|
|
{atomic, {error, _} = Error} ->
|
|
|
|
Error;
|
|
|
|
{atomic, {result, _} = Res} ->
|
|
|
|
Res;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'internal-server-error'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_active_set(_LUser, _LServer, false) ->
|
|
|
|
{result, [], #userlist{}};
|
|
|
|
|
|
|
|
process_active_set(LUser, LServer, Name) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case catch sql_get_privacy_list_id(LUser, LServer, Name) of
|
|
|
|
{selected, ["id"], []} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'item-not-found'};
|
2006-11-03 16:42:21 +01:00
|
|
|
{selected, ["id"], [{ID}]} ->
|
|
|
|
case catch sql_get_privacy_list_data_by_id(ID, LServer) of
|
|
|
|
{selected, ["t", "value", "action", "ord", "match_all",
|
|
|
|
"match_iq", "match_message",
|
|
|
|
"match_presence_in", "match_presence_out"],
|
|
|
|
RItems} ->
|
|
|
|
Items = lists:map(fun raw_to_item/1, RItems),
|
2009-03-03 20:26:24 +01:00
|
|
|
NeedDb = is_list_needdb(Items),
|
|
|
|
{result, [], #userlist{name = Name, list = Items, needdb = NeedDb}};
|
2008-09-16 16:39:57 +02:00
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'internal-server-error'}
|
2008-09-16 16:39:57 +02:00
|
|
|
end;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'internal_server_error'}
|
|
|
|
end.
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_list_set(_LUser, _LServer, false, _Els) ->
|
|
|
|
{error, 'bad-request'};
|
2006-11-03 16:42:21 +01:00
|
|
|
|
2008-10-06 17:01:36 +02:00
|
|
|
process_list_set(LUser, LServer, Name, Els) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case parse_items(Els) of
|
|
|
|
false ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'bad-request'};
|
2006-11-03 16:42:21 +01:00
|
|
|
remove ->
|
|
|
|
F =
|
|
|
|
fun() ->
|
|
|
|
case sql_get_default_privacy_list_t(LUser) of
|
|
|
|
{selected, ["name"], []} ->
|
|
|
|
sql_remove_privacy_list(LUser, Name),
|
|
|
|
{result, []};
|
|
|
|
{selected, ["name"], [{Default}]} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
% TODO: check active
|
2006-11-03 16:42:21 +01:00
|
|
|
if
|
|
|
|
Name == Default ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'conflict'};
|
2006-11-03 16:42:21 +01:00
|
|
|
true ->
|
|
|
|
sql_remove_privacy_list(LUser, Name),
|
|
|
|
{result, []}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
case odbc_queries:sql_transaction(LServer, F) of
|
|
|
|
{atomic, {error, _} = Error} ->
|
|
|
|
Error;
|
|
|
|
{atomic, {result, _} = Res} ->
|
|
|
|
ejabberd_router:route(
|
2009-06-01 18:26:00 +02:00
|
|
|
exmpp_jid:make(LUser, LServer),
|
|
|
|
exmpp_jid:make(LUser, LServer),
|
2008-10-06 17:01:36 +02:00
|
|
|
#xmlel{name = 'broadcast',
|
|
|
|
children=[{privacy_list,
|
|
|
|
#userlist{name = Name, list = []},
|
|
|
|
Name}]}),
|
2006-11-03 16:42:21 +01:00
|
|
|
Res;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'internal-server-error'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end;
|
|
|
|
List ->
|
|
|
|
RItems = lists:map(fun item_to_raw/1, List),
|
|
|
|
F =
|
|
|
|
fun() ->
|
|
|
|
ID =
|
|
|
|
case sql_get_privacy_list_id_t(LUser, Name) of
|
|
|
|
{selected, ["id"], []} ->
|
|
|
|
sql_add_privacy_list(LUser, Name),
|
|
|
|
{selected, ["id"], [{I}]} =
|
|
|
|
sql_get_privacy_list_id_t(LUser, Name),
|
|
|
|
I;
|
|
|
|
{selected, ["id"], [{I}]} ->
|
|
|
|
I
|
|
|
|
end,
|
|
|
|
sql_set_privacy_list(ID, RItems),
|
|
|
|
{result, []}
|
|
|
|
end,
|
|
|
|
case odbc_queries:sql_transaction(LServer, F) of
|
|
|
|
{atomic, {error, _} = Error} ->
|
|
|
|
Error;
|
|
|
|
{atomic, {result, _} = Res} ->
|
|
|
|
ejabberd_router:route(
|
2009-06-01 18:26:00 +02:00
|
|
|
exmpp_jid:make(LUser, LServer),
|
|
|
|
exmpp_jid:make(LUser, LServer),
|
2008-10-06 17:01:36 +02:00
|
|
|
#xmlel{name = 'broadcast',
|
|
|
|
children=[{privacy_list,
|
|
|
|
#userlist{name = Name, list = List},
|
|
|
|
Name}]}),
|
2006-11-03 16:42:21 +01:00
|
|
|
Res;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
{error, 'internal_server_error'}
|
2006-11-03 16:42:21 +01:00
|
|
|
end
|
2008-10-06 17:01:36 +02:00
|
|
|
end.
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parse_items([]) ->
|
|
|
|
remove;
|
|
|
|
parse_items(Els) ->
|
|
|
|
parse_items(Els, []).
|
|
|
|
|
|
|
|
parse_items([], Res) ->
|
2009-01-19 16:27:07 +01:00
|
|
|
%% Sort the items by their 'order' attribute
|
2009-03-03 20:26:24 +01:00
|
|
|
lists:keysort(#listitem.order, Res);
|
2008-10-06 17:01:36 +02:00
|
|
|
parse_items([El = #xmlel{name = item} | Els], Res) ->
|
2009-01-21 14:34:26 +01:00
|
|
|
Type = exmpp_xml:get_attribute_as_list(El, type, false),
|
|
|
|
Value = exmpp_xml:get_attribute_as_list(El, value, false),
|
|
|
|
SAction =exmpp_xml:get_attribute_as_list(El, action, false),
|
|
|
|
SOrder = exmpp_xml:get_attribute_as_list(El, order, false),
|
2008-10-06 17:01:36 +02:00
|
|
|
Action = case catch list_to_action(SAction) of
|
2006-11-03 16:42:21 +01:00
|
|
|
{'EXIT', _} -> false;
|
|
|
|
Val -> Val
|
|
|
|
end,
|
2008-10-06 17:01:36 +02:00
|
|
|
Order = case catch list_to_integer(SOrder) of
|
2006-11-03 16:42:21 +01:00
|
|
|
{'EXIT', _} ->
|
|
|
|
false;
|
|
|
|
IntVal ->
|
|
|
|
if
|
|
|
|
IntVal >= 0 ->
|
|
|
|
IntVal;
|
|
|
|
true ->
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
if
|
|
|
|
(Action /= false) and (Order /= false) ->
|
|
|
|
I1 = #listitem{action = Action, order = Order},
|
|
|
|
I2 = case {Type, Value} of
|
2008-10-06 17:01:36 +02:00
|
|
|
{T, V} when is_list(T), is_list(V) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case T of
|
|
|
|
"jid" ->
|
2008-10-06 17:01:36 +02:00
|
|
|
try
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(V),
|
2008-10-06 17:01:36 +02:00
|
|
|
I1#listitem{
|
|
|
|
type = jid,
|
|
|
|
value = jlib:short_prepd_jid(JID)}
|
|
|
|
catch
|
|
|
|
_ ->
|
|
|
|
false
|
2006-11-03 16:42:21 +01:00
|
|
|
end;
|
|
|
|
"group" ->
|
|
|
|
I1#listitem{type = group,
|
|
|
|
value = V};
|
|
|
|
"subscription" ->
|
|
|
|
case V of
|
|
|
|
"none" ->
|
|
|
|
I1#listitem{type = subscription,
|
|
|
|
value = none};
|
|
|
|
"both" ->
|
|
|
|
I1#listitem{type = subscription,
|
|
|
|
value = both};
|
|
|
|
"from" ->
|
|
|
|
I1#listitem{type = subscription,
|
|
|
|
value = from};
|
|
|
|
"to" ->
|
|
|
|
I1#listitem{type = subscription,
|
|
|
|
value = to};
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end;
|
2008-10-06 17:01:36 +02:00
|
|
|
{T, false} when is_list(T) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
false;
|
|
|
|
_ ->
|
|
|
|
I1
|
|
|
|
end,
|
|
|
|
case I2 of
|
|
|
|
false ->
|
|
|
|
false;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
case parse_matches(I2, exmpp_xml:get_child_elements(El)) of
|
2006-11-03 16:42:21 +01:00
|
|
|
false ->
|
|
|
|
false;
|
|
|
|
I3 ->
|
|
|
|
parse_items(Els, [I3 | Res])
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
false
|
|
|
|
end;
|
|
|
|
|
|
|
|
parse_items(_, _Res) ->
|
|
|
|
false.
|
|
|
|
|
|
|
|
|
|
|
|
parse_matches(Item, []) ->
|
|
|
|
Item#listitem{match_all = true};
|
|
|
|
parse_matches(Item, Els) ->
|
|
|
|
parse_matches1(Item, Els).
|
|
|
|
|
|
|
|
parse_matches1(Item, []) ->
|
|
|
|
Item;
|
2008-10-06 17:01:36 +02:00
|
|
|
parse_matches1(Item, [#xmlel{name = message} | Els]) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
parse_matches1(Item#listitem{match_message = true}, Els);
|
2008-10-06 17:01:36 +02:00
|
|
|
parse_matches1(Item, [#xmlel{name = iq} | Els]) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
parse_matches1(Item#listitem{match_iq = true}, Els);
|
2008-10-06 17:01:36 +02:00
|
|
|
parse_matches1(Item, [#xmlel{name = 'presence-in'} | Els]) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
parse_matches1(Item#listitem{match_presence_in = true}, Els);
|
2008-10-06 17:01:36 +02:00
|
|
|
parse_matches1(Item, [#xmlel{name = 'presence-out'} | Els]) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
parse_matches1(Item#listitem{match_presence_out = true}, Els);
|
2008-10-06 17:01:36 +02:00
|
|
|
parse_matches1(_Item, [#xmlel{} | _Els]) ->
|
2006-11-03 16:42:21 +01:00
|
|
|
false.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-03-03 20:26:24 +01:00
|
|
|
is_list_needdb(Items) ->
|
|
|
|
lists:any(
|
|
|
|
fun(X) ->
|
|
|
|
case X#listitem.type of
|
|
|
|
subscription -> true;
|
|
|
|
group -> true;
|
|
|
|
_ -> false
|
|
|
|
end
|
|
|
|
end, Items).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
2009-01-03 16:15:38 +01:00
|
|
|
get_user_list(_, User, Server)
|
|
|
|
when is_binary(User), is_binary(Server) ->
|
2008-10-06 17:01:36 +02:00
|
|
|
try
|
2009-01-03 16:15:38 +01:00
|
|
|
LUser = binary_to_list(User),
|
|
|
|
LServer = binary_to_list(Server),
|
2008-10-06 17:01:36 +02:00
|
|
|
case catch sql_get_default_privacy_list(LUser, LServer) of
|
|
|
|
{selected, ["name"], []} ->
|
|
|
|
#userlist{};
|
|
|
|
{selected, ["name"], [{Default}]} ->
|
|
|
|
case catch sql_get_privacy_list_data(LUser, LServer, Default) of
|
|
|
|
{selected, ["t", "value", "action", "ord", "match_all",
|
|
|
|
"match_iq", "match_message",
|
|
|
|
"match_presence_in", "match_presence_out"],
|
|
|
|
RItems} ->
|
|
|
|
Items = lists:map(fun raw_to_item/1, RItems),
|
2009-03-03 20:26:24 +01:00
|
|
|
NeedDb = is_list_needdb(Items),
|
|
|
|
#userlist{name = Default, list = Items, needdb = NeedDb};
|
2008-10-06 17:01:36 +02:00
|
|
|
_ ->
|
|
|
|
#userlist{}
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
#userlist{}
|
|
|
|
end
|
|
|
|
catch
|
2008-09-16 16:39:57 +02:00
|
|
|
_ ->
|
|
|
|
#userlist{}
|
2006-11-03 16:42:21 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
check_packet(_, User, Server,
|
2009-03-03 20:26:24 +01:00
|
|
|
#userlist{list = List, needdb = NeedDb},
|
2008-10-06 17:01:36 +02:00
|
|
|
{From, To, #xmlel{name = PName}},
|
2009-01-03 16:15:38 +01:00
|
|
|
Dir) when
|
|
|
|
PName =:= message ;
|
2008-10-06 17:01:36 +02:00
|
|
|
PName =:= iq ;
|
|
|
|
PName =:= presence ->
|
2006-11-03 16:42:21 +01:00
|
|
|
case List of
|
|
|
|
[] ->
|
|
|
|
allow;
|
|
|
|
_ ->
|
2008-10-06 17:01:36 +02:00
|
|
|
case {PName, Dir} of
|
2006-11-03 16:42:21 +01:00
|
|
|
{message, in} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
LJID = jlib:short_prepd_jid(From),
|
2006-11-03 16:42:21 +01:00
|
|
|
{Subscription, Groups} =
|
2009-03-03 20:26:24 +01:00
|
|
|
case NeedDb of
|
|
|
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
|
|
|
|
false -> {[], []}
|
|
|
|
end,
|
2006-11-03 16:42:21 +01:00
|
|
|
check_packet_aux(List, message,
|
|
|
|
LJID, Subscription, Groups);
|
|
|
|
{iq, in} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
LJID = jlib:short_prepd_jid(From),
|
2006-11-03 16:42:21 +01:00
|
|
|
{Subscription, Groups} =
|
2009-03-03 20:26:24 +01:00
|
|
|
case NeedDb of
|
|
|
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
|
|
|
|
false -> {[], []}
|
|
|
|
end,
|
2006-11-03 16:42:21 +01:00
|
|
|
check_packet_aux(List, iq,
|
|
|
|
LJID, Subscription, Groups);
|
|
|
|
{presence, in} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
LJID = jlib:short_prepd_jid(From),
|
2006-11-03 16:42:21 +01:00
|
|
|
{Subscription, Groups} =
|
2009-03-03 20:26:24 +01:00
|
|
|
case NeedDb of
|
|
|
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, LJID]);
|
|
|
|
false -> {[], []}
|
|
|
|
end,
|
2006-11-03 16:42:21 +01:00
|
|
|
check_packet_aux(List, presence_in,
|
|
|
|
LJID, Subscription, Groups);
|
|
|
|
{presence, out} ->
|
2008-10-06 17:01:36 +02:00
|
|
|
LJID = jlib:short_prepd_jid(To),
|
2006-11-03 16:42:21 +01:00
|
|
|
{Subscription, Groups} =
|
2009-03-03 20:26:24 +01:00
|
|
|
case NeedDb of
|
|
|
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info, jlib:nameprep(Server), {none, []}, [User, Server, LJID]);
|
|
|
|
false -> {[], []}
|
|
|
|
end,
|
2006-11-03 16:42:21 +01:00
|
|
|
check_packet_aux(List, presence_out,
|
|
|
|
LJID, Subscription, Groups);
|
|
|
|
_ ->
|
|
|
|
allow
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
check_packet_aux([], _PType, _JID, _Subscription, _Groups) ->
|
|
|
|
allow;
|
|
|
|
check_packet_aux([Item | List], PType, JID, Subscription, Groups) ->
|
|
|
|
#listitem{type = Type, value = Value, action = Action} = Item,
|
|
|
|
case is_ptype_match(Item, PType) of
|
|
|
|
true ->
|
|
|
|
case Type of
|
|
|
|
none ->
|
|
|
|
Action;
|
|
|
|
_ ->
|
|
|
|
case is_type_match(Type, Value,
|
|
|
|
JID, Subscription, Groups) of
|
|
|
|
true ->
|
|
|
|
Action;
|
|
|
|
false ->
|
|
|
|
check_packet_aux(List, PType,
|
|
|
|
JID, Subscription, Groups)
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
check_packet_aux(List, PType, JID, Subscription, Groups)
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
is_ptype_match(Item, PType) ->
|
|
|
|
case Item#listitem.match_all of
|
|
|
|
true ->
|
|
|
|
true;
|
|
|
|
false ->
|
|
|
|
case PType of
|
|
|
|
message ->
|
|
|
|
Item#listitem.match_message;
|
|
|
|
iq ->
|
|
|
|
Item#listitem.match_iq;
|
|
|
|
presence_in ->
|
|
|
|
Item#listitem.match_presence_in;
|
|
|
|
presence_out ->
|
|
|
|
Item#listitem.match_presence_out
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
2009-03-07 09:53:34 +01:00
|
|
|
%% TODO: Investigate this: sometimes Value has binaries, other times has strings
|
2006-11-03 16:42:21 +01:00
|
|
|
is_type_match(Type, Value, JID, Subscription, Groups) ->
|
|
|
|
case Type of
|
|
|
|
jid ->
|
2009-03-07 09:53:34 +01:00
|
|
|
{User, Server, Resource} = Value,
|
2009-06-01 18:39:36 +02:00
|
|
|
((User == undefined) orelse (User == []) orelse (User == exmpp_jid:prep_node(JID)))
|
2009-06-01 18:37:15 +02:00
|
|
|
andalso ((Server == undefined) orelse (Server == []) orelse (Server == exmpp_jid:prep_domain(JID)))
|
2009-06-01 18:42:07 +02:00
|
|
|
andalso ((Resource == undefined) orelse (Resource == []) orelse (Resource == exmpp_jid:prep_resource(JID)));
|
2006-11-03 16:42:21 +01:00
|
|
|
subscription ->
|
|
|
|
Value == Subscription;
|
|
|
|
group ->
|
|
|
|
lists:member(Value, Groups)
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
2009-01-19 11:14:04 +01:00
|
|
|
remove_user(User, Server) ->
|
|
|
|
LUser = exmpp_stringprep:nodeprep(User),
|
|
|
|
LServer = exmpp_stringprep:nameprep(Server),
|
2009-02-20 16:30:16 +01:00
|
|
|
sql_del_privacy_lists(binary_to_list(LUser), binary_to_list(LServer)).
|
2009-01-19 11:14:04 +01:00
|
|
|
|
|
|
|
|
2006-11-03 16:42:21 +01:00
|
|
|
updated_list(_,
|
|
|
|
#userlist{name = OldName} = Old,
|
|
|
|
#userlist{name = NewName} = New) ->
|
|
|
|
if
|
|
|
|
OldName == NewName ->
|
|
|
|
New;
|
|
|
|
true ->
|
|
|
|
Old
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
raw_to_item({SType, SValue, SAction, SOrder, SMatchAll, SMatchIQ,
|
|
|
|
SMatchMessage, SMatchPresenceIn, SMatchPresenceOut}) ->
|
|
|
|
{Type, Value} =
|
|
|
|
case SType of
|
|
|
|
"n" ->
|
|
|
|
{none, none};
|
|
|
|
"j" ->
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(SValue),
|
2008-10-06 17:01:36 +02:00
|
|
|
{jid, jlib:short_prepd_jid(JID)};
|
2006-11-03 16:42:21 +01:00
|
|
|
"g" ->
|
|
|
|
{group, SValue};
|
|
|
|
"s" ->
|
|
|
|
case SValue of
|
|
|
|
"none" ->
|
|
|
|
{subscription, none};
|
|
|
|
"both" ->
|
|
|
|
{subscription, both};
|
|
|
|
"from" ->
|
|
|
|
{subscription, from};
|
|
|
|
"to" ->
|
|
|
|
{subscription, to}
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Action =
|
|
|
|
case SAction of
|
|
|
|
"a" -> allow;
|
|
|
|
"d" -> deny
|
|
|
|
end,
|
|
|
|
Order = list_to_integer(SOrder),
|
2008-07-11 14:48:27 +02:00
|
|
|
MatchAll = SMatchAll == "1" orelse SMatchAll == "t",
|
|
|
|
MatchIQ = SMatchIQ == "1" orelse SMatchIQ == "t" ,
|
|
|
|
MatchMessage = SMatchMessage == "1" orelse SMatchMessage == "t",
|
|
|
|
MatchPresenceIn = SMatchPresenceIn == "1" orelse SMatchPresenceIn == "t",
|
|
|
|
MatchPresenceOut = SMatchPresenceOut == "1" orelse SMatchPresenceOut == "t",
|
2006-11-03 16:42:21 +01:00
|
|
|
#listitem{type = Type,
|
|
|
|
value = Value,
|
|
|
|
action = Action,
|
|
|
|
order = Order,
|
|
|
|
match_all = MatchAll,
|
|
|
|
match_iq = MatchIQ,
|
|
|
|
match_message = MatchMessage,
|
|
|
|
match_presence_in = MatchPresenceIn,
|
|
|
|
match_presence_out = MatchPresenceOut
|
|
|
|
}.
|
|
|
|
|
|
|
|
item_to_raw(#listitem{type = Type,
|
|
|
|
value = Value,
|
|
|
|
action = Action,
|
|
|
|
order = Order,
|
|
|
|
match_all = MatchAll,
|
|
|
|
match_iq = MatchIQ,
|
|
|
|
match_message = MatchMessage,
|
|
|
|
match_presence_in = MatchPresenceIn,
|
|
|
|
match_presence_out = MatchPresenceOut
|
|
|
|
}) ->
|
|
|
|
{SType, SValue} =
|
|
|
|
case Type of
|
|
|
|
none ->
|
|
|
|
{"n", ""};
|
|
|
|
jid ->
|
2008-10-10 10:16:29 +02:00
|
|
|
{N0, D0, R0} = Value,
|
2009-06-01 18:52:14 +02:00
|
|
|
{"j", exmpp_jid:to_list(N0, D0, R0)};
|
2006-11-03 16:42:21 +01:00
|
|
|
group ->
|
|
|
|
{"g", Value};
|
|
|
|
subscription ->
|
|
|
|
case Value of
|
|
|
|
none ->
|
|
|
|
{"s", "none"};
|
|
|
|
both ->
|
|
|
|
{"s", "both"};
|
|
|
|
from ->
|
|
|
|
{"s", "from"};
|
|
|
|
to ->
|
|
|
|
{"s", "to"}
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
SAction =
|
|
|
|
case Action of
|
|
|
|
allow -> "a";
|
|
|
|
deny -> "d"
|
|
|
|
end,
|
|
|
|
SOrder = integer_to_list(Order),
|
2008-07-11 14:48:27 +02:00
|
|
|
SMatchAll = if MatchAll -> "1"; true -> "0" end,
|
|
|
|
SMatchIQ = if MatchIQ -> "1"; true -> "0" end,
|
|
|
|
SMatchMessage = if MatchMessage -> "1"; true -> "0" end,
|
|
|
|
SMatchPresenceIn = if MatchPresenceIn -> "1"; true -> "0" end,
|
|
|
|
SMatchPresenceOut = if MatchPresenceOut -> "1"; true -> "0" end,
|
2009-01-19 12:16:44 +01:00
|
|
|
[SType, SValue, SAction, SOrder, SMatchAll, SMatchIQ,
|
|
|
|
SMatchMessage, SMatchPresenceIn, SMatchPresenceOut].
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_default_privacy_list(LUser, LServer) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_default_privacy_list(LServer, Username).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_default_privacy_list_t(LUser) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_default_privacy_list_t(Username).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_privacy_list_names(LUser, LServer) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_privacy_list_names(LServer, Username).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_privacy_list_names_t(LUser) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_privacy_list_names_t(Username).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_privacy_list_id(LUser, LServer, Name) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
SName = ejabberd_odbc:escape(Name),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_privacy_list_id(LServer, Username, SName).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_privacy_list_id_t(LUser, Name) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
SName = ejabberd_odbc:escape(Name),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_privacy_list_id_t(Username, SName).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_privacy_list_data(LUser, LServer, Name) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
SName = ejabberd_odbc:escape(Name),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_privacy_list_data(LServer, Username, SName).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_get_privacy_list_data_by_id(ID, LServer) ->
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:get_privacy_list_data_by_id(LServer, ID).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_set_default_privacy_list(LUser, Name) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
SName = ejabberd_odbc:escape(Name),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:set_default_privacy_list(Username, SName).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_unset_default_privacy_list(LUser, LServer) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:unset_default_privacy_list(LServer, Username).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_remove_privacy_list(LUser, Name) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
SName = ejabberd_odbc:escape(Name),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:remove_privacy_list(Username, SName).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_add_privacy_list(LUser, Name) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
SName = ejabberd_odbc:escape(Name),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:add_privacy_list(Username, SName).
|
2006-11-03 16:42:21 +01:00
|
|
|
|
|
|
|
sql_set_privacy_list(ID, RItems) ->
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:set_privacy_list(ID, RItems).
|
2009-01-19 11:14:04 +01:00
|
|
|
|
|
|
|
sql_del_privacy_lists(LUser, LServer) ->
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
Server = ejabberd_odbc:escape(LServer),
|
2009-01-19 12:16:44 +01:00
|
|
|
odbc_queries:del_privacy_lists(LServer, Server, Username).
|