aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2005-09-10 17:01:30 +0000
committerAlexey Shchepin <alexey@process-one.net>2005-09-10 17:01:30 +0000
commitd63018071798767a790bceca75a2223af2317a68 (patch)
tree011a742e45a03643e4e6f5d3a55e29e83cee9509 /src
parent* src/mod_disco.erl: Disco publishing support (thanks to Magnus (diff)
* src/ejd2odbc.erl: Updated
SVN Revision: 410
Diffstat (limited to 'src')
-rw-r--r--src/ejd2odbc.erl61
1 files changed, 37 insertions, 24 deletions
diff --git a/src/ejd2odbc.erl b/src/ejd2odbc.erl
index aef05fb4c..959bad2c2 100644
--- a/src/ejd2odbc.erl
+++ b/src/ejd2odbc.erl
@@ -11,10 +11,10 @@
-vsn('$Revision$ ').
%% External exports
--export([export_passwd/1,
- export_roster/1,
- export_offline/1,
- export_last/1]).
+-export([export_passwd/2,
+ export_roster/2,
+ export_offline/2,
+ export_last/2]).
-include("ejabberd.hrl").
-include("jlib.hrl").
@@ -29,9 +29,9 @@
%%% API
%%%----------------------------------------------------------------------
-export_passwd(Server) ->
+export_passwd(Server, Output) ->
export_common(
- Server, passwd,
+ Server, passwd, Output,
fun(Host, {passwd, {LUser, LServer}, Password} = R)
when LServer == Host ->
Username = ejabberd_odbc:escape(LUser),
@@ -43,9 +43,9 @@ export_passwd(Server) ->
[]
end).
-export_roster(Server) ->
+export_roster(Server, Output) ->
export_common(
- Server, roster,
+ Server, roster, Output,
fun(Host, #roster{usj = {LUser, LServer, LJID}} = R)
when LServer == Host ->
Username = ejabberd_odbc:escape(LUser),
@@ -71,9 +71,9 @@ export_roster(Server) ->
[]
end).
-export_offline(Server) ->
+export_offline(Server, Output) ->
export_common(
- Server, offline_msg,
+ Server, offline_msg, Output,
fun(Host, #offline_msg{us = {LUser, LServer},
timestamp = TimeStamp,
from = From,
@@ -102,9 +102,9 @@ export_offline(Server) ->
[]
end).
-export_last(Server) ->
+export_last(Server, Output) ->
export_common(
- Server, last_activity,
+ Server, last_activity, Output,
fun(Host, #last_activity{us = {LUser, LServer},
timestamp = TimeStamp,
status = Status})
@@ -123,10 +123,17 @@ export_last(Server) ->
%%% Internal functions
%%%----------------------------------------------------------------------
-export_common(Server, Table, ConvertFun) ->
+export_common(Server, Table, Output, ConvertFun) ->
+ IO = case Output of
+ odbc ->
+ odbc;
+ _ ->
+ {ok, IODevice} = file:open(Output, [write, raw]),
+ IODevice
+ end,
mnesia:transaction(
fun() ->
- mnesia:read_lock_table(passwd),
+ mnesia:read_lock_table(Table),
LServer = jlib:nameprep(Server),
{_N, SQLs} =
mnesia:foldl(
@@ -139,22 +146,28 @@ export_common(Server, Table, ConvertFun) ->
N < ?MAX_RECORDS_PER_TRANSACTION - 1 ->
{N + 1, [SQL | SQLs]};
true ->
- catch ejabberd_odbc:sql_query(
- LServer,
- ["begin;",
- lists:reverse([SQL | SQLs]),
- "commit"]),
+ output(LServer, IO,
+ ["begin;",
+ lists:reverse([SQL | SQLs]),
+ "commit"]),
{0, []}
end
end
end, {0, []}, Table),
- catch ejabberd_odbc:sql_query(
- LServer,
- ["begin;",
- lists:reverse(SQLs),
- "commit"])
+ output(LServer, IO,
+ ["begin;",
+ lists:reverse(SQLs),
+ "commit"])
end).
+output(LServer, IO, SQL) ->
+ case IO of
+ odbc ->
+ catch ejabberd_odbc:sql_query(LServer, SQL);
+ _ ->
+ file:write(IO, [SQL, $\n])
+ end.
+
record_to_string(#roster{usj = {User, Server, JID},
name = Name,
subscription = Subscription,