aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2012-04-02 12:39:23 +1000
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2012-04-02 12:39:23 +1000
commit866085c918f52551b8caf212292a0f653621f6b8 (patch)
tree20990b1007bfb24221276b44bab73450299ed0b4 /src
parentAdd notes about mod_muc_odbc (diff)
Add ODBC exporting function for privacy table
Diffstat (limited to 'src')
-rw-r--r--src/ejd2odbc.erl53
-rw-r--r--src/mod_privacy_odbc.erl1
2 files changed, 54 insertions, 0 deletions
diff --git a/src/ejd2odbc.erl b/src/ejd2odbc.erl
index 5f7b9d4da..a1f3a1eed 100644
--- a/src/ejd2odbc.erl
+++ b/src/ejd2odbc.erl
@@ -35,12 +35,14 @@
export_vcard/2,
export_vcard_search/2,
export_private_storage/2,
+ export_privacy/2,
export_muc_room/2,
export_muc_registered/2]).
-include("ejabberd.hrl").
-include("jlib.hrl").
-include("mod_roster.hrl").
+-include("mod_privacy.hrl").
-record(offline_msg, {us, timestamp, expire, from, to, packet}).
-record(last_activity, {us, timestamp, status}).
@@ -307,6 +309,52 @@ export_muc_registered(Server, Output) ->
end
end).
+export_privacy(Server, Output) ->
+ case ejabberd_odbc:sql_query(
+ jlib:nameprep(Server),
+ ["select id from privacy_list order by id desc limit 1;"]) of
+ {selected, ["id"], [{I}]} ->
+ put(id, list_to_integer(I));
+ _ ->
+ put(id, 0)
+ end,
+ export_common(
+ Server, privacy, Output,
+ fun(Host, #privacy{us = {LUser, LServer},
+ lists = Lists,
+ default = Default}) when LServer == Host ->
+ Username = ejabberd_odbc:escape(LUser),
+ if Default /= none ->
+ SDefault = ejabberd_odbc:escape(Default),
+ ["delete from privacy_default_list where ",
+ "username='", Username, "';",
+ "insert into privacy_default_list(username, name) ",
+ "values ('", Username, "', '", SDefault, "');"];
+ true ->
+ []
+ end ++
+ lists:flatmap(
+ fun({Name, List}) ->
+ SName = ejabberd_odbc:escape(Name),
+ RItems = lists:map(
+ fun mod_privacy_odbc:item_to_raw/1,
+ List),
+ ID = integer_to_list(get_id()),
+ ["delete from privacy_list "
+ "where username='", Username, "' and name='", SName, "';"
+ "insert into privacy_list(username, name, id) "
+ "values ('", Username, "', '", SName, "', '", ID, "');",
+ "delete from privacy_list_data where id='", ID, "';"
+ |[["insert into privacy_list_data("
+ "id, t, value, action, ord, match_all, match_iq, "
+ "match_message, match_presence_in, "
+ "match_presence_out) values ('", ID, "', '",
+ string:join(Items, "', '"), "');"] || Items <- RItems]]
+ end, Lists);
+ (_Host, _R) ->
+ []
+ end).
+
%%%----------------------------------------------------------------------
%%% Internal functions
%%%----------------------------------------------------------------------
@@ -405,3 +453,8 @@ groups_to_string(#roster{usj = {User, _Server, JID},
"'", Username, "',"
"'", SJID, "',"
"'", ejabberd_odbc:escape(Group), "')"] || Group <- Groups].
+
+get_id() ->
+ ID = get(id),
+ put(id, ID+1),
+ ID+1.
diff --git a/src/mod_privacy_odbc.erl b/src/mod_privacy_odbc.erl
index 553264cf3..432617ebe 100644
--- a/src/mod_privacy_odbc.erl
+++ b/src/mod_privacy_odbc.erl
@@ -36,6 +36,7 @@
get_user_list/3,
check_packet/6,
remove_user/2,
+ item_to_raw/1,
updated_list/3]).
-include("ejabberd.hrl").