mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
* src/ejd2odbc.erl: Updated
SVN Revision: 410
This commit is contained in:
parent
a83c99805a
commit
d630180717
@ -1,3 +1,7 @@
|
|||||||
|
2005-09-10 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
|
* src/ejd2odbc.erl: Updated
|
||||||
|
|
||||||
2005-09-04 Alexey Shchepin <alexey@sevcom.net>
|
2005-09-04 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
* src/mod_disco.erl: Disco publishing support (thanks to Magnus
|
* src/mod_disco.erl: Disco publishing support (thanks to Magnus
|
||||||
|
@ -11,10 +11,10 @@
|
|||||||
-vsn('$Revision$ ').
|
-vsn('$Revision$ ').
|
||||||
|
|
||||||
%% External exports
|
%% External exports
|
||||||
-export([export_passwd/1,
|
-export([export_passwd/2,
|
||||||
export_roster/1,
|
export_roster/2,
|
||||||
export_offline/1,
|
export_offline/2,
|
||||||
export_last/1]).
|
export_last/2]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
-include("jlib.hrl").
|
||||||
@ -29,9 +29,9 @@
|
|||||||
%%% API
|
%%% API
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
export_passwd(Server) ->
|
export_passwd(Server, Output) ->
|
||||||
export_common(
|
export_common(
|
||||||
Server, passwd,
|
Server, passwd, Output,
|
||||||
fun(Host, {passwd, {LUser, LServer}, Password} = R)
|
fun(Host, {passwd, {LUser, LServer}, Password} = R)
|
||||||
when LServer == Host ->
|
when LServer == Host ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
@ -43,9 +43,9 @@ export_passwd(Server) ->
|
|||||||
[]
|
[]
|
||||||
end).
|
end).
|
||||||
|
|
||||||
export_roster(Server) ->
|
export_roster(Server, Output) ->
|
||||||
export_common(
|
export_common(
|
||||||
Server, roster,
|
Server, roster, Output,
|
||||||
fun(Host, #roster{usj = {LUser, LServer, LJID}} = R)
|
fun(Host, #roster{usj = {LUser, LServer, LJID}} = R)
|
||||||
when LServer == Host ->
|
when LServer == Host ->
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
@ -71,9 +71,9 @@ export_roster(Server) ->
|
|||||||
[]
|
[]
|
||||||
end).
|
end).
|
||||||
|
|
||||||
export_offline(Server) ->
|
export_offline(Server, Output) ->
|
||||||
export_common(
|
export_common(
|
||||||
Server, offline_msg,
|
Server, offline_msg, Output,
|
||||||
fun(Host, #offline_msg{us = {LUser, LServer},
|
fun(Host, #offline_msg{us = {LUser, LServer},
|
||||||
timestamp = TimeStamp,
|
timestamp = TimeStamp,
|
||||||
from = From,
|
from = From,
|
||||||
@ -102,9 +102,9 @@ export_offline(Server) ->
|
|||||||
[]
|
[]
|
||||||
end).
|
end).
|
||||||
|
|
||||||
export_last(Server) ->
|
export_last(Server, Output) ->
|
||||||
export_common(
|
export_common(
|
||||||
Server, last_activity,
|
Server, last_activity, Output,
|
||||||
fun(Host, #last_activity{us = {LUser, LServer},
|
fun(Host, #last_activity{us = {LUser, LServer},
|
||||||
timestamp = TimeStamp,
|
timestamp = TimeStamp,
|
||||||
status = Status})
|
status = Status})
|
||||||
@ -123,10 +123,17 @@ export_last(Server) ->
|
|||||||
%%% Internal functions
|
%%% 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(
|
mnesia:transaction(
|
||||||
fun() ->
|
fun() ->
|
||||||
mnesia:read_lock_table(passwd),
|
mnesia:read_lock_table(Table),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
{_N, SQLs} =
|
{_N, SQLs} =
|
||||||
mnesia:foldl(
|
mnesia:foldl(
|
||||||
@ -139,8 +146,7 @@ export_common(Server, Table, ConvertFun) ->
|
|||||||
N < ?MAX_RECORDS_PER_TRANSACTION - 1 ->
|
N < ?MAX_RECORDS_PER_TRANSACTION - 1 ->
|
||||||
{N + 1, [SQL | SQLs]};
|
{N + 1, [SQL | SQLs]};
|
||||||
true ->
|
true ->
|
||||||
catch ejabberd_odbc:sql_query(
|
output(LServer, IO,
|
||||||
LServer,
|
|
||||||
["begin;",
|
["begin;",
|
||||||
lists:reverse([SQL | SQLs]),
|
lists:reverse([SQL | SQLs]),
|
||||||
"commit"]),
|
"commit"]),
|
||||||
@ -148,13 +154,20 @@ export_common(Server, Table, ConvertFun) ->
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, {0, []}, Table),
|
end, {0, []}, Table),
|
||||||
catch ejabberd_odbc:sql_query(
|
output(LServer, IO,
|
||||||
LServer,
|
|
||||||
["begin;",
|
["begin;",
|
||||||
lists:reverse(SQLs),
|
lists:reverse(SQLs),
|
||||||
"commit"])
|
"commit"])
|
||||||
end).
|
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},
|
record_to_string(#roster{usj = {User, Server, JID},
|
||||||
name = Name,
|
name = Name,
|
||||||
subscription = Subscription,
|
subscription = Subscription,
|
||||||
|
Loading…
Reference in New Issue
Block a user