mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Update more SQL queries
This commit is contained in:
parent
6d7ce0237a
commit
d8fbe8a289
@ -25,7 +25,7 @@
|
|||||||
-define(SQL_UPSERT(Host, Table, Fields),
|
-define(SQL_UPSERT(Host, Table, Fields),
|
||||||
ejabberd_odbc:sql_query(Host, ?SQL_UPSERT_MARK(Table, Fields))).
|
ejabberd_odbc:sql_query(Host, ?SQL_UPSERT_MARK(Table, Fields))).
|
||||||
-define(SQL_UPSERT_T(Table, Fields),
|
-define(SQL_UPSERT_T(Table, Fields),
|
||||||
ejabberd_odbc:sql_query_t(Host, ?SQL_UPSERT_MARK(Table, Fields))).
|
ejabberd_odbc:sql_query_t(?SQL_UPSERT_MARK(Table, Fields))).
|
||||||
|
|
||||||
-record(sql_query, {hash, format_query, format_res, args, loc}).
|
-record(sql_query, {hash, format_query, format_res, args, loc}).
|
||||||
|
|
||||||
|
@ -153,26 +153,24 @@ set_password(User, Server, Password) ->
|
|||||||
(LUser == <<>>) or (LServer == <<>>) ->
|
(LUser == <<>>) or (LServer == <<>>) ->
|
||||||
{error, invalid_jid};
|
{error, invalid_jid};
|
||||||
true ->
|
true ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
|
||||||
case is_scrammed() of
|
case is_scrammed() of
|
||||||
true ->
|
true ->
|
||||||
Scram = password_to_scram(Password),
|
Scram = password_to_scram(Password),
|
||||||
case catch odbc_queries:set_password_scram_t(
|
case catch odbc_queries:set_password_scram_t(
|
||||||
LServer,
|
LServer,
|
||||||
Username,
|
LUser,
|
||||||
ejabberd_odbc:escape(Scram#scram.storedkey),
|
Scram#scram.storedkey,
|
||||||
ejabberd_odbc:escape(Scram#scram.serverkey),
|
Scram#scram.serverkey,
|
||||||
ejabberd_odbc:escape(Scram#scram.salt),
|
Scram#scram.salt,
|
||||||
integer_to_binary(Scram#scram.iterationcount)
|
Scram#scram.iterationcount
|
||||||
)
|
)
|
||||||
of
|
of
|
||||||
{atomic, ok} -> ok;
|
{atomic, ok} -> ok;
|
||||||
Other -> {error, Other}
|
Other -> {error, Other}
|
||||||
end;
|
end;
|
||||||
false ->
|
false ->
|
||||||
Pass = ejabberd_odbc:escape(Password),
|
|
||||||
case catch odbc_queries:set_password_t(LServer,
|
case catch odbc_queries:set_password_t(LServer,
|
||||||
Username, Pass)
|
LUser, Password)
|
||||||
of
|
of
|
||||||
{atomic, ok} -> ok;
|
{atomic, ok} -> ok;
|
||||||
Other -> {error, Other}
|
Other -> {error, Other}
|
||||||
|
@ -616,9 +616,9 @@ pgsql_prepare(SQLQuery, State) ->
|
|||||||
|
|
||||||
pgsql_execute_escape() ->
|
pgsql_execute_escape() ->
|
||||||
#sql_escape{string = fun(X) -> X end,
|
#sql_escape{string = fun(X) -> X end,
|
||||||
integer = fun(X) -> integer_to_binary(X) end,
|
integer = fun(X) -> [integer_to_binary(X)] end,
|
||||||
boolean = fun(true) -> <<"1">>;
|
boolean = fun(true) -> "1";
|
||||||
(false) -> <<"0">>
|
(false) -> "0"
|
||||||
end
|
end
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
@ -223,23 +223,18 @@ process_blocklist_block(LUser, LServer, Filter, odbc) ->
|
|||||||
Default = case
|
Default = case
|
||||||
mod_privacy:sql_get_default_privacy_list_t(LUser)
|
mod_privacy:sql_get_default_privacy_list_t(LUser)
|
||||||
of
|
of
|
||||||
{selected, [<<"name">>], []} ->
|
{selected, []} ->
|
||||||
Name = <<"Blocked contacts">>,
|
Name = <<"Blocked contacts">>,
|
||||||
mod_privacy:sql_add_privacy_list(LUser, Name),
|
mod_privacy:sql_add_privacy_list(LUser, Name),
|
||||||
mod_privacy:sql_set_default_privacy_list(LUser,
|
mod_privacy:sql_set_default_privacy_list(LUser,
|
||||||
Name),
|
Name),
|
||||||
Name;
|
Name;
|
||||||
{selected, [<<"name">>], [[Name]]} -> Name
|
{selected, [{Name}]} -> Name
|
||||||
end,
|
end,
|
||||||
{selected, [<<"id">>], [[ID]]} =
|
{selected, [{ID}]} =
|
||||||
mod_privacy:sql_get_privacy_list_id_t(LUser, Default),
|
mod_privacy:sql_get_privacy_list_id_t(LUser, Default),
|
||||||
case mod_privacy:sql_get_privacy_list_data_by_id_t(ID)
|
case mod_privacy:sql_get_privacy_list_data_by_id_t(ID) of
|
||||||
of
|
{selected, RItems = [_ | _]} ->
|
||||||
{selected,
|
|
||||||
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
|
|
||||||
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
|
|
||||||
<<"match_presence_in">>, <<"match_presence_out">>],
|
|
||||||
RItems = [_ | _]} ->
|
|
||||||
List = lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
|
List = lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
|
||||||
_ -> List = []
|
_ -> List = []
|
||||||
end,
|
end,
|
||||||
@ -345,17 +340,12 @@ unblock_by_filter(LUser, LServer, Filter, odbc) ->
|
|||||||
F = fun () ->
|
F = fun () ->
|
||||||
case mod_privacy:sql_get_default_privacy_list_t(LUser)
|
case mod_privacy:sql_get_default_privacy_list_t(LUser)
|
||||||
of
|
of
|
||||||
{selected, [<<"name">>], []} -> ok;
|
{selected, []} -> ok;
|
||||||
{selected, [<<"name">>], [[Default]]} ->
|
{selected, [{Default}]} ->
|
||||||
{selected, [<<"id">>], [[ID]]} =
|
{selected, [{ID}]} =
|
||||||
mod_privacy:sql_get_privacy_list_id_t(LUser, Default),
|
mod_privacy:sql_get_privacy_list_id_t(LUser, Default),
|
||||||
case mod_privacy:sql_get_privacy_list_data_by_id_t(ID)
|
case mod_privacy:sql_get_privacy_list_data_by_id_t(ID) of
|
||||||
of
|
{selected, RItems = [_ | _]} ->
|
||||||
{selected,
|
|
||||||
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
|
|
||||||
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
|
|
||||||
<<"match_presence_in">>, <<"match_presence_out">>],
|
|
||||||
RItems = [_ | _]} ->
|
|
||||||
List = lists:flatmap(fun mod_privacy:raw_to_item/1,
|
List = lists:flatmap(fun mod_privacy:raw_to_item/1,
|
||||||
RItems),
|
RItems),
|
||||||
NewList = Filter(List),
|
NewList = Filter(List),
|
||||||
@ -435,16 +425,12 @@ process_blocklist_get(LUser, LServer, odbc) ->
|
|||||||
case catch
|
case catch
|
||||||
mod_privacy:sql_get_default_privacy_list(LUser, LServer)
|
mod_privacy:sql_get_default_privacy_list(LUser, LServer)
|
||||||
of
|
of
|
||||||
{selected, [<<"name">>], []} -> [];
|
{selected, []} -> [];
|
||||||
{selected, [<<"name">>], [[Default]]} ->
|
{selected, [{Default}]} ->
|
||||||
case catch mod_privacy:sql_get_privacy_list_data(LUser,
|
case catch mod_privacy:sql_get_privacy_list_data(LUser,
|
||||||
LServer, Default)
|
LServer, Default)
|
||||||
of
|
of
|
||||||
{selected,
|
{selected, RItems} ->
|
||||||
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
|
|
||||||
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
|
|
||||||
<<"match_presence_in">>, <<"match_presence_out">>],
|
|
||||||
RItems} ->
|
|
||||||
lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
|
lists:flatmap(fun mod_privacy:raw_to_item/1, RItems);
|
||||||
{'EXIT', _} -> error
|
{'EXIT', _} -> error
|
||||||
end;
|
end;
|
||||||
|
@ -181,16 +181,14 @@ process_lists_get(LUser, LServer, _Active, riak) ->
|
|||||||
error
|
error
|
||||||
end;
|
end;
|
||||||
process_lists_get(LUser, LServer, _Active, odbc) ->
|
process_lists_get(LUser, LServer, _Active, odbc) ->
|
||||||
Default = case catch sql_get_default_privacy_list(LUser,
|
Default = case catch sql_get_default_privacy_list(LUser, LServer) of
|
||||||
LServer)
|
{selected, []} -> none;
|
||||||
of
|
{selected, [{DefName}]} -> DefName;
|
||||||
{selected, [<<"name">>], []} -> none;
|
|
||||||
{selected, [<<"name">>], [[DefName]]} -> DefName;
|
|
||||||
_ -> none
|
_ -> none
|
||||||
end,
|
end,
|
||||||
case catch sql_get_privacy_list_names(LUser, LServer) of
|
case catch sql_get_privacy_list_names(LUser, LServer) of
|
||||||
{selected, [<<"name">>], Names} ->
|
{selected, Names} ->
|
||||||
LItems = lists:map(fun ([N]) ->
|
LItems = lists:map(fun ({N}) ->
|
||||||
#xmlel{name = <<"list">>,
|
#xmlel{name = <<"list">>,
|
||||||
attrs = [{<<"name">>, N}],
|
attrs = [{<<"name">>, N}],
|
||||||
children = []}
|
children = []}
|
||||||
@ -242,17 +240,11 @@ process_list_get(LUser, LServer, Name, riak) ->
|
|||||||
error
|
error
|
||||||
end;
|
end;
|
||||||
process_list_get(LUser, LServer, Name, odbc) ->
|
process_list_get(LUser, LServer, Name, odbc) ->
|
||||||
case catch sql_get_privacy_list_id(LUser, LServer, Name)
|
case catch sql_get_privacy_list_id(LUser, LServer, Name) of
|
||||||
of
|
{selected, []} -> not_found;
|
||||||
{selected, [<<"id">>], []} -> not_found;
|
{selected, [{ID}]} ->
|
||||||
{selected, [<<"id">>], [[ID]]} ->
|
case catch sql_get_privacy_list_data_by_id(ID, LServer) of
|
||||||
case catch sql_get_privacy_list_data_by_id(ID, LServer)
|
{selected, RItems} ->
|
||||||
of
|
|
||||||
{selected,
|
|
||||||
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
|
|
||||||
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
|
|
||||||
<<"match_presence_in">>, <<"match_presence_out">>],
|
|
||||||
RItems} ->
|
|
||||||
lists:flatmap(fun raw_to_item/1, RItems);
|
lists:flatmap(fun raw_to_item/1, RItems);
|
||||||
_ -> error
|
_ -> error
|
||||||
end;
|
end;
|
||||||
@ -405,9 +397,9 @@ process_default_set(LUser, LServer, {value, Name},
|
|||||||
odbc) ->
|
odbc) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
case sql_get_privacy_list_names_t(LUser) of
|
case sql_get_privacy_list_names_t(LUser) of
|
||||||
{selected, [<<"name">>], []} -> not_found;
|
{selected, []} -> not_found;
|
||||||
{selected, [<<"name">>], Names} ->
|
{selected, Names} ->
|
||||||
case lists:member([Name], Names) of
|
case lists:member({Name}, Names) of
|
||||||
true -> sql_set_default_privacy_list(LUser, Name), ok;
|
true -> sql_set_default_privacy_list(LUser, Name), ok;
|
||||||
false -> not_found
|
false -> not_found
|
||||||
end
|
end
|
||||||
@ -473,17 +465,11 @@ process_active_set(LUser, LServer, Name, riak) ->
|
|||||||
error
|
error
|
||||||
end;
|
end;
|
||||||
process_active_set(LUser, LServer, Name, odbc) ->
|
process_active_set(LUser, LServer, Name, odbc) ->
|
||||||
case catch sql_get_privacy_list_id(LUser, LServer, Name)
|
case catch sql_get_privacy_list_id(LUser, LServer, Name) of
|
||||||
of
|
{selected, []} -> error;
|
||||||
{selected, [<<"id">>], []} -> error;
|
{selected, [{ID}]} ->
|
||||||
{selected, [<<"id">>], [[ID]]} ->
|
case catch sql_get_privacy_list_data_by_id(ID, LServer) of
|
||||||
case catch sql_get_privacy_list_data_by_id(ID, LServer)
|
{selected, RItems} ->
|
||||||
of
|
|
||||||
{selected,
|
|
||||||
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
|
|
||||||
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
|
|
||||||
<<"match_presence_in">>, <<"match_presence_out">>],
|
|
||||||
RItems} ->
|
|
||||||
lists:flatmap(fun raw_to_item/1, RItems);
|
lists:flatmap(fun raw_to_item/1, RItems);
|
||||||
_ -> error
|
_ -> error
|
||||||
end;
|
end;
|
||||||
@ -520,9 +506,9 @@ remove_privacy_list(LUser, LServer, Name, riak) ->
|
|||||||
remove_privacy_list(LUser, LServer, Name, odbc) ->
|
remove_privacy_list(LUser, LServer, Name, odbc) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
case sql_get_default_privacy_list_t(LUser) of
|
case sql_get_default_privacy_list_t(LUser) of
|
||||||
{selected, [<<"name">>], []} ->
|
{selected, []} ->
|
||||||
sql_remove_privacy_list(LUser, Name), ok;
|
sql_remove_privacy_list(LUser, Name), ok;
|
||||||
{selected, [<<"name">>], [[Default]]} ->
|
{selected, [{Default}]} ->
|
||||||
if Name == Default -> conflict;
|
if Name == Default -> conflict;
|
||||||
true -> sql_remove_privacy_list(LUser, Name), ok
|
true -> sql_remove_privacy_list(LUser, Name), ok
|
||||||
end
|
end
|
||||||
@ -590,12 +576,12 @@ set_privacy_list(LUser, LServer, Name, List, odbc) ->
|
|||||||
RItems = lists:map(fun item_to_raw/1, List),
|
RItems = lists:map(fun item_to_raw/1, List),
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
ID = case sql_get_privacy_list_id_t(LUser, Name) of
|
ID = case sql_get_privacy_list_id_t(LUser, Name) of
|
||||||
{selected, [<<"id">>], []} ->
|
{selected, []} ->
|
||||||
sql_add_privacy_list(LUser, Name),
|
sql_add_privacy_list(LUser, Name),
|
||||||
{selected, [<<"id">>], [[I]]} =
|
{selected, [{I}]} =
|
||||||
sql_get_privacy_list_id_t(LUser, Name),
|
sql_get_privacy_list_id_t(LUser, Name),
|
||||||
I;
|
I;
|
||||||
{selected, [<<"id">>], [[I]]} -> I
|
{selected, [{I}]} -> I
|
||||||
end,
|
end,
|
||||||
sql_set_privacy_list(ID, RItems),
|
sql_set_privacy_list(ID, RItems),
|
||||||
ok
|
ok
|
||||||
@ -785,16 +771,11 @@ get_user_list(_, LUser, LServer, riak) ->
|
|||||||
get_user_list(_, LUser, LServer, odbc) ->
|
get_user_list(_, LUser, LServer, odbc) ->
|
||||||
case catch sql_get_default_privacy_list(LUser, LServer)
|
case catch sql_get_default_privacy_list(LUser, LServer)
|
||||||
of
|
of
|
||||||
{selected, [<<"name">>], []} -> {none, []};
|
{selected, []} -> {none, []};
|
||||||
{selected, [<<"name">>], [[Default]]} ->
|
{selected, [{Default}]} ->
|
||||||
case catch sql_get_privacy_list_data(LUser, LServer,
|
case catch sql_get_privacy_list_data(LUser, LServer,
|
||||||
Default)
|
Default) of
|
||||||
of
|
{selected, RItems} ->
|
||||||
{selected,
|
|
||||||
[<<"t">>, <<"value">>, <<"action">>, <<"ord">>,
|
|
||||||
<<"match_all">>, <<"match_iq">>, <<"match_message">>,
|
|
||||||
<<"match_presence_in">>, <<"match_presence_out">>],
|
|
||||||
RItems} ->
|
|
||||||
{Default, lists:flatmap(fun raw_to_item/1, RItems)};
|
{Default, lists:flatmap(fun raw_to_item/1, RItems)};
|
||||||
_ -> {none, []}
|
_ -> {none, []}
|
||||||
end;
|
end;
|
||||||
@ -822,26 +803,21 @@ get_user_lists(LUser, LServer, riak) ->
|
|||||||
end;
|
end;
|
||||||
get_user_lists(LUser, LServer, odbc) ->
|
get_user_lists(LUser, LServer, odbc) ->
|
||||||
Default = case catch sql_get_default_privacy_list(LUser, LServer) of
|
Default = case catch sql_get_default_privacy_list(LUser, LServer) of
|
||||||
{selected, [<<"name">>], []} ->
|
{selected, []} ->
|
||||||
none;
|
none;
|
||||||
{selected, [<<"name">>], [[DefName]]} ->
|
{selected, [{DefName}]} ->
|
||||||
DefName;
|
DefName;
|
||||||
_ ->
|
_ ->
|
||||||
none
|
none
|
||||||
end,
|
end,
|
||||||
case catch sql_get_privacy_list_names(LUser, LServer) of
|
case catch sql_get_privacy_list_names(LUser, LServer) of
|
||||||
{selected, [<<"name">>], Names} ->
|
{selected, Names} ->
|
||||||
Lists =
|
Lists =
|
||||||
lists:flatmap(
|
lists:flatmap(
|
||||||
fun([Name]) ->
|
fun({Name}) ->
|
||||||
case catch sql_get_privacy_list_data(
|
case catch sql_get_privacy_list_data(
|
||||||
LUser, LServer, Name) of
|
LUser, LServer, Name) of
|
||||||
{selected,
|
{selected, RItems} ->
|
||||||
[<<"t">>, <<"value">>, <<"action">>,
|
|
||||||
<<"ord">>, <<"match_all">>, <<"match_iq">>,
|
|
||||||
<<"match_message">>, <<"match_presence_in">>,
|
|
||||||
<<"match_presence_out">>],
|
|
||||||
RItems} ->
|
|
||||||
[{Name, lists:flatmap(fun raw_to_item/1, RItems)}];
|
[{Name, lists:flatmap(fun raw_to_item/1, RItems)}];
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
@ -994,9 +970,9 @@ updated_list(_, #userlist{name = OldName} = Old,
|
|||||||
true -> Old
|
true -> Old
|
||||||
end.
|
end.
|
||||||
|
|
||||||
raw_to_item([SType, SValue, SAction, SOrder, SMatchAll,
|
raw_to_item({SType, SValue, SAction, Order, MatchAll,
|
||||||
SMatchIQ, SMatchMessage, SMatchPresenceIn,
|
MatchIQ, MatchMessage, MatchPresenceIn,
|
||||||
SMatchPresenceOut] = Row) ->
|
MatchPresenceOut} = Row) ->
|
||||||
try
|
try
|
||||||
{Type, Value} = case SType of
|
{Type, Value} = case SType of
|
||||||
<<"n">> -> {none, none};
|
<<"n">> -> {none, none};
|
||||||
@ -1018,12 +994,6 @@ raw_to_item([SType, SValue, SAction, SOrder, SMatchAll,
|
|||||||
<<"a">> -> allow;
|
<<"a">> -> allow;
|
||||||
<<"d">> -> deny
|
<<"d">> -> deny
|
||||||
end,
|
end,
|
||||||
Order = jlib:binary_to_integer(SOrder),
|
|
||||||
MatchAll = ejabberd_odbc:to_bool(SMatchAll),
|
|
||||||
MatchIQ = ejabberd_odbc:to_bool(SMatchIQ),
|
|
||||||
MatchMessage = ejabberd_odbc:to_bool(SMatchMessage),
|
|
||||||
MatchPresenceIn = ejabberd_odbc:to_bool(SMatchPresenceIn),
|
|
||||||
MatchPresenceOut = ejabberd_odbc:to_bool(SMatchPresenceOut),
|
|
||||||
[#listitem{type = Type, value = Value, action = Action,
|
[#listitem{type = Type, value = Value, action = Action,
|
||||||
order = Order, match_all = MatchAll, match_iq = MatchIQ,
|
order = Order, match_all = MatchAll, match_iq = MatchIQ,
|
||||||
match_message = MatchMessage,
|
match_message = MatchMessage,
|
||||||
@ -1057,58 +1027,29 @@ item_to_raw(#listitem{type = Type, value = Value,
|
|||||||
allow -> <<"a">>;
|
allow -> <<"a">>;
|
||||||
deny -> <<"d">>
|
deny -> <<"d">>
|
||||||
end,
|
end,
|
||||||
SOrder = iolist_to_binary(integer_to_list(Order)),
|
{SType, SValue, SAction, Order, MatchAll, MatchIQ,
|
||||||
SMatchAll = if MatchAll -> <<"1">>;
|
MatchMessage, MatchPresenceIn, MatchPresenceOut}.
|
||||||
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,
|
|
||||||
[SType, SValue, SAction, SOrder, SMatchAll, SMatchIQ,
|
|
||||||
SMatchMessage, SMatchPresenceIn, SMatchPresenceOut].
|
|
||||||
|
|
||||||
sql_get_default_privacy_list(LUser, LServer) ->
|
sql_get_default_privacy_list(LUser, LServer) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:get_default_privacy_list(LServer, LUser).
|
||||||
odbc_queries:get_default_privacy_list(LServer,
|
|
||||||
Username).
|
|
||||||
|
|
||||||
sql_get_default_privacy_list_t(LUser) ->
|
sql_get_default_privacy_list_t(LUser) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:get_default_privacy_list_t(LUser).
|
||||||
odbc_queries:get_default_privacy_list_t(Username).
|
|
||||||
|
|
||||||
sql_get_privacy_list_names(LUser, LServer) ->
|
sql_get_privacy_list_names(LUser, LServer) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:get_privacy_list_names(LServer, LUser).
|
||||||
odbc_queries:get_privacy_list_names(LServer, Username).
|
|
||||||
|
|
||||||
sql_get_privacy_list_names_t(LUser) ->
|
sql_get_privacy_list_names_t(LUser) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:get_privacy_list_names_t(LUser).
|
||||||
odbc_queries:get_privacy_list_names_t(Username).
|
|
||||||
|
|
||||||
sql_get_privacy_list_id(LUser, LServer, Name) ->
|
sql_get_privacy_list_id(LUser, LServer, Name) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:get_privacy_list_id(LServer, LUser, Name).
|
||||||
SName = ejabberd_odbc:escape(Name),
|
|
||||||
odbc_queries:get_privacy_list_id(LServer, Username,
|
|
||||||
SName).
|
|
||||||
|
|
||||||
sql_get_privacy_list_id_t(LUser, Name) ->
|
sql_get_privacy_list_id_t(LUser, Name) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:get_privacy_list_id_t(LUser, Name).
|
||||||
SName = ejabberd_odbc:escape(Name),
|
|
||||||
odbc_queries:get_privacy_list_id_t(Username, SName).
|
|
||||||
|
|
||||||
sql_get_privacy_list_data(LUser, LServer, Name) ->
|
sql_get_privacy_list_data(LUser, LServer, Name) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:get_privacy_list_data(LServer, LUser, Name).
|
||||||
SName = ejabberd_odbc:escape(Name),
|
|
||||||
odbc_queries:get_privacy_list_data(LServer, Username,
|
|
||||||
SName).
|
|
||||||
|
|
||||||
sql_get_privacy_list_data_t(LUser, Name) ->
|
sql_get_privacy_list_data_t(LUser, Name) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
@ -1122,33 +1063,22 @@ sql_get_privacy_list_data_by_id_t(ID) ->
|
|||||||
odbc_queries:get_privacy_list_data_by_id_t(ID).
|
odbc_queries:get_privacy_list_data_by_id_t(ID).
|
||||||
|
|
||||||
sql_set_default_privacy_list(LUser, Name) ->
|
sql_set_default_privacy_list(LUser, Name) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:set_default_privacy_list(LUser, Name).
|
||||||
SName = ejabberd_odbc:escape(Name),
|
|
||||||
odbc_queries:set_default_privacy_list(Username, SName).
|
|
||||||
|
|
||||||
sql_unset_default_privacy_list(LUser, LServer) ->
|
sql_unset_default_privacy_list(LUser, LServer) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:unset_default_privacy_list(LServer, LUser).
|
||||||
odbc_queries:unset_default_privacy_list(LServer,
|
|
||||||
Username).
|
|
||||||
|
|
||||||
sql_remove_privacy_list(LUser, Name) ->
|
sql_remove_privacy_list(LUser, Name) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:remove_privacy_list(LUser, Name).
|
||||||
SName = ejabberd_odbc:escape(Name),
|
|
||||||
odbc_queries:remove_privacy_list(Username, SName).
|
|
||||||
|
|
||||||
sql_add_privacy_list(LUser, Name) ->
|
sql_add_privacy_list(LUser, Name) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:add_privacy_list(LUser, Name).
|
||||||
SName = ejabberd_odbc:escape(Name),
|
|
||||||
odbc_queries:add_privacy_list(Username, SName).
|
|
||||||
|
|
||||||
sql_set_privacy_list(ID, RItems) ->
|
sql_set_privacy_list(ID, RItems) ->
|
||||||
odbc_queries:set_privacy_list(ID, RItems).
|
odbc_queries:set_privacy_list(ID, RItems).
|
||||||
|
|
||||||
sql_del_privacy_lists(LUser, LServer) ->
|
sql_del_privacy_lists(LUser, LServer) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:del_privacy_lists(LServer, LUser).
|
||||||
Server = ejabberd_odbc:escape(LServer),
|
|
||||||
odbc_queries:del_privacy_lists(LServer, Server,
|
|
||||||
Username).
|
|
||||||
|
|
||||||
update_table() ->
|
update_table() ->
|
||||||
Fields = record_info(fields, privacy),
|
Fields = record_info(fields, privacy),
|
||||||
|
@ -152,11 +152,8 @@ set_data(LUser, LServer, {XmlNS, Xmlel}, mnesia) ->
|
|||||||
{LUser, LServer, XmlNS},
|
{LUser, LServer, XmlNS},
|
||||||
xml = Xmlel});
|
xml = Xmlel});
|
||||||
set_data(LUser, LServer, {XMLNS, El}, odbc) ->
|
set_data(LUser, LServer, {XMLNS, El}, odbc) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
SData = fxml:element_to_binary(El),
|
||||||
LXMLNS = ejabberd_odbc:escape(XMLNS),
|
odbc_queries:set_private_data(LServer, LUser, XMLNS, SData);
|
||||||
SData = ejabberd_odbc:escape(fxml:element_to_binary(El)),
|
|
||||||
odbc_queries:set_private_data(LServer, Username, LXMLNS,
|
|
||||||
SData);
|
|
||||||
set_data(LUser, LServer, {XMLNS, El}, riak) ->
|
set_data(LUser, LServer, {XMLNS, El}, riak) ->
|
||||||
ejabberd_riak:put(#private_storage{usns = {LUser, LServer, XMLNS},
|
ejabberd_riak:put(#private_storage{usns = {LUser, LServer, XMLNS},
|
||||||
xml = El},
|
xml = El},
|
||||||
@ -184,12 +181,10 @@ get_data(LUser, LServer, mnesia,
|
|||||||
end;
|
end;
|
||||||
get_data(LUser, LServer, odbc, [{XMLNS, El} | Els],
|
get_data(LUser, LServer, odbc, [{XMLNS, El} | Els],
|
||||||
Res) ->
|
Res) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
|
||||||
LXMLNS = ejabberd_odbc:escape(XMLNS),
|
|
||||||
case catch odbc_queries:get_private_data(LServer,
|
case catch odbc_queries:get_private_data(LServer,
|
||||||
Username, LXMLNS)
|
LUser, XMLNS)
|
||||||
of
|
of
|
||||||
{selected, [<<"data">>], [[SData]]} ->
|
{selected, [{SData}]} ->
|
||||||
case fxml_stream:parse_element(SData) of
|
case fxml_stream:parse_element(SData) of
|
||||||
Data when is_record(Data, xmlel) ->
|
Data when is_record(Data, xmlel) ->
|
||||||
get_data(LUser, LServer, odbc, Els, [Data | Res])
|
get_data(LUser, LServer, odbc, Els, [Data | Res])
|
||||||
@ -217,11 +212,10 @@ get_all_data(LUser, LServer, mnesia) ->
|
|||||||
xml = '$1'},
|
xml = '$1'},
|
||||||
[], ['$1']}]));
|
[], ['$1']}]));
|
||||||
get_all_data(LUser, LServer, odbc) ->
|
get_all_data(LUser, LServer, odbc) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
case catch odbc_queries:get_private_data(LServer, LUser) of
|
||||||
case catch odbc_queries:get_private_data(LServer, Username) of
|
{selected, Res} ->
|
||||||
{selected, [<<"namespace">>, <<"data">>], Res} ->
|
|
||||||
lists:flatmap(
|
lists:flatmap(
|
||||||
fun([_, SData]) ->
|
fun({_, SData}) ->
|
||||||
case fxml_stream:parse_element(SData) of
|
case fxml_stream:parse_element(SData) of
|
||||||
#xmlel{} = El ->
|
#xmlel{} = El ->
|
||||||
[El];
|
[El];
|
||||||
@ -269,9 +263,7 @@ remove_user(LUser, LServer, mnesia) ->
|
|||||||
end,
|
end,
|
||||||
mnesia:transaction(F);
|
mnesia:transaction(F);
|
||||||
remove_user(LUser, LServer, odbc) ->
|
remove_user(LUser, LServer, odbc) ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
odbc_queries:del_user_private_storage(LServer, LUser);
|
||||||
odbc_queries:del_user_private_storage(LServer,
|
|
||||||
Username);
|
|
||||||
remove_user(LUser, LServer, riak) ->
|
remove_user(LUser, LServer, riak) ->
|
||||||
{atomic, ejabberd_riak:delete_by_index(private_storage,
|
{atomic, ejabberd_riak:delete_by_index(private_storage,
|
||||||
<<"us">>, {LUser, LServer})}.
|
<<"us">>, {LUser, LServer})}.
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
set_default_privacy_list/2,
|
set_default_privacy_list/2,
|
||||||
unset_default_privacy_list/2, remove_privacy_list/2,
|
unset_default_privacy_list/2, remove_privacy_list/2,
|
||||||
add_privacy_list/2, set_privacy_list/2,
|
add_privacy_list/2, set_privacy_list/2,
|
||||||
del_privacy_lists/3, set_vcard/26, get_vcard/2,
|
del_privacy_lists/2, set_vcard/26, get_vcard/2,
|
||||||
escape/1, count_records_where/3, get_roster_version/2,
|
escape/1, count_records_where/3, get_roster_version/2,
|
||||||
set_roster_version/2, opt_type/1]).
|
set_roster_version/2, opt_type/1]).
|
||||||
|
|
||||||
@ -151,32 +151,28 @@ get_password_scram(LServer, LUser) ->
|
|||||||
" from users"
|
" from users"
|
||||||
" where username=%(LUser)s")).
|
" where username=%(LUser)s")).
|
||||||
|
|
||||||
set_password_t(LServer, Username, Pass) ->
|
set_password_t(LServer, LUser, Password) ->
|
||||||
ejabberd_odbc:sql_transaction(LServer,
|
ejabberd_odbc:sql_transaction(
|
||||||
|
LServer,
|
||||||
fun () ->
|
fun () ->
|
||||||
update_t(<<"users">>,
|
?SQL_UPSERT_T(
|
||||||
[<<"username">>,
|
"users",
|
||||||
<<"password">>],
|
["!username=%(LUser)s",
|
||||||
[Username, Pass],
|
"password=%(Password)s"])
|
||||||
[<<"username='">>, Username,
|
|
||||||
<<"'">>])
|
|
||||||
end).
|
end).
|
||||||
|
|
||||||
set_password_scram_t(LServer, Username,
|
set_password_scram_t(LServer, LUser,
|
||||||
StoredKey, ServerKey, Salt, IterationCount) ->
|
StoredKey, ServerKey, Salt, IterationCount) ->
|
||||||
ejabberd_odbc:sql_transaction(LServer,
|
ejabberd_odbc:sql_transaction(
|
||||||
|
LServer,
|
||||||
fun () ->
|
fun () ->
|
||||||
update_t(<<"users">>,
|
?SQL_UPSERT_T(
|
||||||
[<<"username">>,
|
"users",
|
||||||
<<"password">>,
|
["!username=%(LUser)s",
|
||||||
<<"serverkey">>,
|
"password=%(StoredKey)s",
|
||||||
<<"salt">>,
|
"serverkey=%(ServerKey)s",
|
||||||
<<"iterationcount">>],
|
"salt=%(Salt)s",
|
||||||
[Username, StoredKey,
|
"iterationcount=%(IterationCount)d"])
|
||||||
ServerKey, Salt,
|
|
||||||
IterationCount],
|
|
||||||
[<<"username='">>, Username,
|
|
||||||
<<"'">>])
|
|
||||||
end).
|
end).
|
||||||
|
|
||||||
add_user(LServer, Username, Pass) ->
|
add_user(LServer, Username, Pass) ->
|
||||||
@ -428,12 +424,12 @@ get_subscription(LServer, LUser, SJID) ->
|
|||||||
?SQL("select @(subscription)s from rosterusers "
|
?SQL("select @(subscription)s from rosterusers "
|
||||||
"where username=%(LUser)s and jid=%(SJID)s")).
|
"where username=%(LUser)s and jid=%(SJID)s")).
|
||||||
|
|
||||||
set_private_data(_LServer, Username, LXMLNS, SData) ->
|
set_private_data(_LServer, LUser, XMLNS, SData) ->
|
||||||
update_t(<<"private_storage">>,
|
?SQL_UPSERT_T(
|
||||||
[<<"username">>, <<"namespace">>, <<"data">>],
|
"private_storage",
|
||||||
[Username, LXMLNS, SData],
|
["!username=%(LUser)s",
|
||||||
[<<"username='">>, Username, <<"' and namespace='">>,
|
"!namespace=%(XMLNS)s",
|
||||||
LXMLNS, <<"'">>]).
|
"data=%(SData)s"]).
|
||||||
|
|
||||||
set_private_data_sql(Username, LXMLNS, SData) ->
|
set_private_data_sql(Username, LXMLNS, SData) ->
|
||||||
[[<<"delete from private_storage where username='">>,
|
[[<<"delete from private_storage where username='">>,
|
||||||
@ -443,22 +439,23 @@ set_private_data_sql(Username, LXMLNS, SData) ->
|
|||||||
Username, <<"', '">>, LXMLNS, <<"', '">>, SData,
|
Username, <<"', '">>, LXMLNS, <<"', '">>, SData,
|
||||||
<<"');">>]].
|
<<"');">>]].
|
||||||
|
|
||||||
get_private_data(LServer, Username, LXMLNS) ->
|
get_private_data(LServer, LUser, XMLNS) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"select data from private_storage where "
|
LServer,
|
||||||
"username='">>,
|
?SQL("select @(data)s from private_storage"
|
||||||
Username, <<"' and namespace='">>, LXMLNS,
|
" where username=%(LUser)s and namespace=%(XMLNS)s")).
|
||||||
<<"';">>]).
|
|
||||||
|
|
||||||
get_private_data(LServer, Username) ->
|
get_private_data(LServer, LUser) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"select namespace, data from private_storage "
|
LServer,
|
||||||
"where username='">>, Username, <<"';">>]).
|
?SQL("select @(namespace)s, @(data)s from private_storage"
|
||||||
|
" where username=%(LUser)s")).
|
||||||
|
|
||||||
del_user_private_storage(LServer, Username) ->
|
del_user_private_storage(LServer, LUser) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"delete from private_storage where username='">>,
|
LServer,
|
||||||
Username, <<"';">>]).
|
?SQL("delete from private_storage"
|
||||||
|
" where username=%(LUser)s")).
|
||||||
|
|
||||||
set_vcard(LServer, LUsername, SBDay, SCTRY, SEMail, SFN,
|
set_vcard(LServer, LUsername, SBDay, SCTRY, SEMail, SFN,
|
||||||
SFamily, SGiven, SLBDay, SLCTRY, SLEMail, SLFN,
|
SFamily, SGiven, SLBDay, SLCTRY, SLEMail, SLFN,
|
||||||
@ -508,122 +505,128 @@ get_vcard(LServer, Username) ->
|
|||||||
[<<"select vcard from vcard where username='">>,
|
[<<"select vcard from vcard where username='">>,
|
||||||
Username, <<"';">>]).
|
Username, <<"';">>]).
|
||||||
|
|
||||||
get_default_privacy_list(LServer, Username) ->
|
get_default_privacy_list(LServer, LUser) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"select name from privacy_default_list "
|
LServer,
|
||||||
"where username='">>,
|
?SQL("select @(name)s from privacy_default_list "
|
||||||
Username, <<"';">>]).
|
"where username=%(LUser)s")).
|
||||||
|
|
||||||
get_default_privacy_list_t(Username) ->
|
get_default_privacy_list_t(LUser) ->
|
||||||
ejabberd_odbc:sql_query_t([<<"select name from privacy_default_list "
|
ejabberd_odbc:sql_query_t(
|
||||||
"where username='">>,
|
?SQL("select @(name)s from privacy_default_list "
|
||||||
Username, <<"';">>]).
|
"where username=%(LUser)s")).
|
||||||
|
|
||||||
get_privacy_list_names(LServer, Username) ->
|
get_privacy_list_names(LServer, LUser) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"select name from privacy_list where "
|
LServer,
|
||||||
"username='">>,
|
?SQL("select @(name)s from privacy_list"
|
||||||
Username, <<"';">>]).
|
" where username=%(LUser)s")).
|
||||||
|
|
||||||
get_privacy_list_names_t(Username) ->
|
get_privacy_list_names_t(LUser) ->
|
||||||
ejabberd_odbc:sql_query_t([<<"select name from privacy_list where "
|
ejabberd_odbc:sql_query_t(
|
||||||
"username='">>,
|
?SQL("select @(name)s from privacy_list"
|
||||||
Username, <<"';">>]).
|
" where username=%(LUser)s")).
|
||||||
|
|
||||||
get_privacy_list_id(LServer, Username, SName) ->
|
get_privacy_list_id(LServer, LUser, Name) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"select id from privacy_list where username='">>,
|
LServer,
|
||||||
Username, <<"' and name='">>, SName, <<"';">>]).
|
?SQL("select @(id)d from privacy_list"
|
||||||
|
" where username=%(LUser)s and name=%(Name)s")).
|
||||||
|
|
||||||
get_privacy_list_id_t(Username, SName) ->
|
get_privacy_list_id_t(LUser, Name) ->
|
||||||
ejabberd_odbc:sql_query_t([<<"select id from privacy_list where username='">>,
|
ejabberd_odbc:sql_query_t(
|
||||||
Username, <<"' and name='">>, SName, <<"';">>]).
|
?SQL("select @(id)d from privacy_list"
|
||||||
|
" where username=%(LUser)s and name=%(Name)s")).
|
||||||
|
|
||||||
get_privacy_list_data(LServer, Username, SName) ->
|
get_privacy_list_data(LServer, LUser, Name) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"select t, value, action, ord, match_all, "
|
LServer,
|
||||||
"match_iq, match_message, match_presence_in, "
|
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
|
||||||
"match_presence_out from privacy_list_data "
|
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
|
||||||
"where id = (select id from privacy_list "
|
"@(match_presence_out)b from privacy_list_data "
|
||||||
"where username='">>,
|
"where id ="
|
||||||
Username, <<"' and name='">>, SName,
|
" (select id from privacy_list"
|
||||||
<<"') order by ord;">>]).
|
" where username=%(LUser)s and name=%(Name)s) "
|
||||||
|
"order by ord")).
|
||||||
|
|
||||||
get_privacy_list_data_t(Username, SName) ->
|
%% Not used?
|
||||||
ejabberd_odbc:sql_query_t([<<"select t, value, action, ord, match_all, "
|
get_privacy_list_data_t(LUser, Name) ->
|
||||||
"match_iq, match_message, match_presence_in, "
|
ejabberd_odbc:sql_query_t(
|
||||||
"match_presence_out from privacy_list_data "
|
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
|
||||||
"where id = (select id from privacy_list "
|
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
|
||||||
"where username='">>,
|
"@(match_presence_out)b from privacy_list_data "
|
||||||
Username, <<"' and name='">>, SName,
|
"where id ="
|
||||||
<<"') order by ord;">>]).
|
" (select id from privacy_list"
|
||||||
|
" where username=%(LUser)s and name=%(Name)s) "
|
||||||
|
"order by ord")).
|
||||||
|
|
||||||
get_privacy_list_data_by_id(LServer, ID) ->
|
get_privacy_list_data_by_id(LServer, ID) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"select t, value, action, ord, match_all, "
|
LServer,
|
||||||
"match_iq, match_message, match_presence_in, "
|
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
|
||||||
"match_presence_out from privacy_list_data "
|
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
|
||||||
"where id='">>,
|
"@(match_presence_out)b from privacy_list_data "
|
||||||
ID, <<"' order by ord;">>]).
|
"where id=%(ID)d order by ord")).
|
||||||
|
|
||||||
get_privacy_list_data_by_id_t(ID) ->
|
get_privacy_list_data_by_id_t(ID) ->
|
||||||
ejabberd_odbc:sql_query_t([<<"select t, value, action, ord, match_all, "
|
ejabberd_odbc:sql_query_t(
|
||||||
"match_iq, match_message, match_presence_in, "
|
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
|
||||||
"match_presence_out from privacy_list_data "
|
"@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
|
||||||
"where id='">>,
|
"@(match_presence_out)b from privacy_list_data "
|
||||||
ID, <<"' order by ord;">>]).
|
"where id=%(ID)d order by ord")).
|
||||||
|
|
||||||
set_default_privacy_list(Username, SName) ->
|
set_default_privacy_list(LUser, Name) ->
|
||||||
update_t(<<"privacy_default_list">>,
|
?SQL_UPSERT_T(
|
||||||
[<<"username">>, <<"name">>], [Username, SName],
|
"privacy_default_list",
|
||||||
[<<"username='">>, Username, <<"'">>]).
|
["!username=%(LUser)s",
|
||||||
|
"name=%(Name)s"]).
|
||||||
|
|
||||||
unset_default_privacy_list(LServer, Username) ->
|
unset_default_privacy_list(LServer, LUser) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(
|
||||||
[<<"delete from privacy_default_list "
|
LServer,
|
||||||
" where username='">>,
|
?SQL("delete from privacy_default_list"
|
||||||
Username, <<"';">>]).
|
" where username=%(LUser)s")).
|
||||||
|
|
||||||
remove_privacy_list(Username, SName) ->
|
remove_privacy_list(LUser, Name) ->
|
||||||
ejabberd_odbc:sql_query_t([<<"delete from privacy_list where username='">>,
|
ejabberd_odbc:sql_query_t(
|
||||||
Username, <<"' and name='">>, SName, <<"';">>]).
|
?SQL("delete from privacy_list where"
|
||||||
|
" username=%(LUser)s and name=%(Name)s")).
|
||||||
|
|
||||||
add_privacy_list(Username, SName) ->
|
add_privacy_list(LUser, Name) ->
|
||||||
ejabberd_odbc:sql_query_t([<<"insert into privacy_list(username, name) "
|
ejabberd_odbc:sql_query_t(
|
||||||
"values ('">>,
|
?SQL("insert into privacy_list(username, name) "
|
||||||
Username, <<"', '">>, SName, <<"');">>]).
|
"values (%(LUser)s, %(Name)s)")).
|
||||||
|
|
||||||
set_privacy_list(ID, RItems) ->
|
set_privacy_list(ID, RItems) ->
|
||||||
ejabberd_odbc:sql_query_t([<<"delete from privacy_list_data where "
|
ejabberd_odbc:sql_query_t(
|
||||||
"id='">>,
|
?SQL("delete from privacy_list_data where id=%(ID)d")),
|
||||||
ID, <<"';">>]),
|
lists:foreach(
|
||||||
lists:foreach(fun (Items) ->
|
fun({SType, SValue, SAction, Order, MatchAll, MatchIQ,
|
||||||
ejabberd_odbc:sql_query_t([<<"insert into privacy_list_data(id, t, "
|
MatchMessage, MatchPresenceIn, MatchPresenceOut}) ->
|
||||||
|
ejabberd_odbc:sql_query_t(
|
||||||
|
?SQL("insert into privacy_list_data(id, t, "
|
||||||
"value, action, ord, match_all, match_iq, "
|
"value, action, ord, match_all, match_iq, "
|
||||||
"match_message, match_presence_in, match_prese"
|
"match_message, match_presence_in, match_presence_out) "
|
||||||
"nce_out ) values ('">>,
|
"values (%(ID)d, %(SType)s, %(SValue)s, %(SAction)s,"
|
||||||
ID, <<"', '">>,
|
" %(Order)d, %(MatchAll)b, %(MatchIQ)b,"
|
||||||
join(Items, <<"', '">>),
|
" %(MatchMessage)b, %(MatchPresenceIn)b,"
|
||||||
<<"');">>])
|
" %(MatchPresenceOut)b)"))
|
||||||
end,
|
end,
|
||||||
RItems).
|
RItems).
|
||||||
|
|
||||||
del_privacy_lists(LServer, Server, Username) ->
|
del_privacy_lists(LServer, LUser) ->
|
||||||
%% Characters to escape
|
ejabberd_odbc:sql_query(
|
||||||
%% Count number of records in a table given a where clause
|
LServer,
|
||||||
ejabberd_odbc:sql_query(LServer,
|
?SQL("delete from privacy_list where username=%(LUser)s")),
|
||||||
[<<"delete from privacy_list where username='">>,
|
%US = <<LUser/binary, "@", LServer/binary>>,
|
||||||
Username, <<"';">>]),
|
%ejabberd_odbc:sql_query(
|
||||||
ejabberd_odbc:sql_query(LServer,
|
% LServer,
|
||||||
[<<"delete from privacy_list_data where "
|
% ?SQL("delete from privacy_list_data where value=%(US)s")),
|
||||||
"value='">>,
|
ejabberd_odbc:sql_query(
|
||||||
<<Username/binary, "@", Server/binary>>,
|
LServer,
|
||||||
<<"';">>]),
|
?SQL("delete from privacy_default_list where username=%(LUser)s")).
|
||||||
ejabberd_odbc:sql_query(LServer,
|
|
||||||
[<<"delete from privacy_default_list where "
|
|
||||||
"username='">>,
|
|
||||||
Username, <<"';">>]).
|
|
||||||
|
|
||||||
|
%% Characters to escape
|
||||||
escape($\000) -> <<"\\0">>;
|
escape($\000) -> <<"\\0">>;
|
||||||
escape($\n) -> <<"\\n">>;
|
escape($\n) -> <<"\\n">>;
|
||||||
escape($\t) -> <<"\\t">>;
|
escape($\t) -> <<"\\t">>;
|
||||||
@ -634,6 +637,7 @@ escape($") -> <<"\\\"">>;
|
|||||||
escape($\\) -> <<"\\\\">>;
|
escape($\\) -> <<"\\\\">>;
|
||||||
escape(C) -> <<C>>.
|
escape(C) -> <<C>>.
|
||||||
|
|
||||||
|
%% Count number of records in a table given a where clause
|
||||||
count_records_where(LServer, Table, WhereClause) ->
|
count_records_where(LServer, Table, WhereClause) ->
|
||||||
ejabberd_odbc:sql_query(LServer,
|
ejabberd_odbc:sql_query(LServer,
|
||||||
[<<"select count(*) from ">>, Table, <<" ">>,
|
[<<"select count(*) from ">>, Table, <<" ">>,
|
||||||
|
Loading…
Reference in New Issue
Block a user