mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-08 21:43:07 +02:00
use dsn-less config for mssql (#3131)
This commit is contained in:
parent
d9131c854d
commit
1f7ca91670
|
@ -51,10 +51,8 @@
|
||||||
sqlite_file/1,
|
sqlite_file/1,
|
||||||
encode_term/1,
|
encode_term/1,
|
||||||
decode_term/1,
|
decode_term/1,
|
||||||
odbc_config/0,
|
|
||||||
freetds_config/0,
|
|
||||||
odbcinst_config/0,
|
odbcinst_config/0,
|
||||||
init_mssql/1,
|
init_mssql/0,
|
||||||
keep_alive/2,
|
keep_alive/2,
|
||||||
to_list/2,
|
to_list/2,
|
||||||
to_array/2]).
|
to_array/2]).
|
||||||
|
@ -1109,8 +1107,9 @@ db_opts(Host) ->
|
||||||
SSLOpts = get_ssl_opts(Transport, Host),
|
SSLOpts = get_ssl_opts(Transport, Host),
|
||||||
case Type of
|
case Type of
|
||||||
mssql ->
|
mssql ->
|
||||||
[mssql, <<"DSN=", Host/binary, ";UID=", User/binary,
|
[mssql, <<"DRIVER=FreeTDS;SERVER=", Server/binary, ";UID=", User/binary,
|
||||||
";PWD=", Pass/binary>>, Timeout];
|
";DATABASE=", DB/binary ,";PWD=", Pass/binary,
|
||||||
|
";PORT=", (integer_to_binary(Port))/binary ,";CLIENT_CHARSET=UTF-8;">>, Timeout];
|
||||||
_ ->
|
_ ->
|
||||||
[Type, Server, Port, DB, User, Pass, Timeout, Transport, SSLOpts]
|
[Type, Server, Port, DB, User, Pass, Timeout, Transport, SSLOpts]
|
||||||
end
|
end
|
||||||
|
@ -1152,44 +1151,15 @@ get_ssl_opts(ssl, Host) ->
|
||||||
get_ssl_opts(tcp, _) ->
|
get_ssl_opts(tcp, _) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_mssql(Host) ->
|
init_mssql() ->
|
||||||
Server = ejabberd_option:sql_server(Host),
|
ODBCINST = io_lib:fwrite("[FreeTDS]~n"
|
||||||
Port = ejabberd_option:sql_port(Host),
|
"Driver = libtdsodbc.so~n", []),
|
||||||
DB = case ejabberd_option:sql_database(Host) of
|
|
||||||
undefined -> <<"ejabberd">>;
|
|
||||||
D -> D
|
|
||||||
end,
|
|
||||||
FreeTDS = io_lib:fwrite("[~ts]~n"
|
|
||||||
"\thost = ~ts~n"
|
|
||||||
"\tport = ~p~n"
|
|
||||||
"\tclient charset = UTF-8~n"
|
|
||||||
"\ttds version = 7.1~n",
|
|
||||||
[Host, Server, Port]),
|
|
||||||
ODBCINST = io_lib:fwrite("[freetds]~n"
|
|
||||||
"Description = MSSQL connection~n"
|
|
||||||
"Driver = libtdsodbc.so~n"
|
|
||||||
"Setup = libtdsS.so~n"
|
|
||||||
"UsageCount = 1~n"
|
|
||||||
"FileUsage = 1~n", []),
|
|
||||||
ODBCINI = io_lib:fwrite("[~ts]~n"
|
|
||||||
"Description = MS SQL~n"
|
|
||||||
"Driver = freetds~n"
|
|
||||||
"Servername = ~ts~n"
|
|
||||||
"Database = ~ts~n"
|
|
||||||
"Port = ~p~n",
|
|
||||||
[Host, Host, DB, Port]),
|
|
||||||
?DEBUG("~ts:~n~ts", [freetds_config(), FreeTDS]),
|
|
||||||
?DEBUG("~ts:~n~ts", [odbcinst_config(), ODBCINST]),
|
?DEBUG("~ts:~n~ts", [odbcinst_config(), ODBCINST]),
|
||||||
?DEBUG("~ts:~n~ts", [odbc_config(), ODBCINI]),
|
case filelib:ensure_dir(odbcinst_config()) of
|
||||||
case filelib:ensure_dir(freetds_config()) of
|
|
||||||
ok ->
|
ok ->
|
||||||
try
|
try
|
||||||
ok = write_file_if_new(freetds_config(), FreeTDS),
|
|
||||||
ok = write_file_if_new(odbcinst_config(), ODBCINST),
|
ok = write_file_if_new(odbcinst_config(), ODBCINST),
|
||||||
ok = write_file_if_new(odbc_config(), ODBCINI),
|
|
||||||
os:putenv("ODBCSYSINI", tmp_dir()),
|
os:putenv("ODBCSYSINI", tmp_dir()),
|
||||||
os:putenv("FREETDS", freetds_config()),
|
|
||||||
os:putenv("FREETDSCONF", freetds_config()),
|
|
||||||
ok
|
ok
|
||||||
catch error:{badmatch, {error, Reason} = Err} ->
|
catch error:{badmatch, {error, Reason} = Err} ->
|
||||||
?ERROR_MSG("Failed to create temporary files in ~ts: ~ts",
|
?ERROR_MSG("Failed to create temporary files in ~ts: ~ts",
|
||||||
|
@ -1214,12 +1184,6 @@ tmp_dir() ->
|
||||||
_ -> filename:join(["/tmp", "ejabberd"])
|
_ -> filename:join(["/tmp", "ejabberd"])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
odbc_config() ->
|
|
||||||
filename:join(tmp_dir(), "odbc.ini").
|
|
||||||
|
|
||||||
freetds_config() ->
|
|
||||||
filename:join(tmp_dir(), "freetds.conf").
|
|
||||||
|
|
||||||
odbcinst_config() ->
|
odbcinst_config() ->
|
||||||
filename:join(tmp_dir(), "odbcinst.ini").
|
filename:join(tmp_dir(), "odbcinst.ini").
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,6 @@ stop() ->
|
||||||
ejabberd_hooks:delete(config_reloaded, ?MODULE, config_reloaded, 20).
|
ejabberd_hooks:delete(config_reloaded, ?MODULE, config_reloaded, 20).
|
||||||
|
|
||||||
init([]) ->
|
init([]) ->
|
||||||
file:delete(ejabberd_sql:freetds_config()),
|
|
||||||
file:delete(ejabberd_sql:odbc_config()),
|
|
||||||
file:delete(ejabberd_sql:odbcinst_config()),
|
file:delete(ejabberd_sql:odbcinst_config()),
|
||||||
ejabberd_hooks:add(host_up, ?MODULE, start, 20),
|
ejabberd_hooks:add(host_up, ?MODULE, start, 20),
|
||||||
ejabberd_hooks:add(host_down, ?MODULE, stop, 90),
|
ejabberd_hooks:add(host_down, ?MODULE, stop, 90),
|
||||||
|
@ -98,7 +96,7 @@ init([Host]) ->
|
||||||
sqlite ->
|
sqlite ->
|
||||||
check_sqlite_db(Host);
|
check_sqlite_db(Host);
|
||||||
mssql ->
|
mssql ->
|
||||||
ejabberd_sql:init_mssql(Host);
|
ejabberd_sql:init_mssql();
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user