]> granicus.if.org Git - ejabberd/commitdiff
* src/ejd2odbc.erl: Updated
authorAlexey Shchepin <alexey@process-one.net>
Sat, 10 Sep 2005 17:01:30 +0000 (17:01 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Sat, 10 Sep 2005 17:01:30 +0000 (17:01 +0000)
SVN Revision: 410

ChangeLog
src/ejd2odbc.erl

index 519b97212d73a1b1dd366846bfa89069ba6c2717..de69f055ff9f382feedbdc45f305b2f9691fdabb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-09-10  Alexey Shchepin  <alexey@sevcom.net>
+
+       * src/ejd2odbc.erl: Updated
+
 2005-09-04  Alexey Shchepin  <alexey@sevcom.net>
 
        * src/mod_disco.erl: Disco publishing support (thanks to Magnus
index aef05fb4cbe1cbc21fab8725756a08679f01e931..959bad2c212949d694e1d63722cd577421b3c1b0 100644 (file)
 -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,