mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Fix Dialyzer reports
This commit is contained in:
parent
6e65f0694e
commit
dffb9cdaf9
@ -448,9 +448,7 @@ remove_user(User, Server, Password) ->
|
||||
{atomic, ok} ->
|
||||
ok;
|
||||
{atomic, Res} ->
|
||||
Res;
|
||||
_ ->
|
||||
bad_request
|
||||
Res
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
|
@ -194,9 +194,19 @@ normalize_hosts([Host|Hosts], PrepHosts) ->
|
||||
exit("invalid hostname")
|
||||
end.
|
||||
|
||||
ensure_localhost_is_first(["localhost" | _] = Hosts) ->
|
||||
Hosts;
|
||||
%% @spec (Hosts::[string()]) -> ["localhost" | string()]
|
||||
ensure_localhost_is_first(Hosts) ->
|
||||
case lists:all(fun is_list/1, Hosts) of
|
||||
true ->
|
||||
ensure_localhost_is_first1(Hosts);
|
||||
false ->
|
||||
?ERROR_MSG("This list of hosts is bad formed:~n~p", [Hosts]),
|
||||
ensure_localhost_is_first1([])
|
||||
end.
|
||||
|
||||
ensure_localhost_is_first1(["localhost" | _] = Hosts) ->
|
||||
Hosts;
|
||||
ensure_localhost_is_first1(Hosts) ->
|
||||
case lists:member("localhost", Hosts) of
|
||||
true ->
|
||||
["localhost" | lists:delete("localhost", Hosts)];
|
||||
|
@ -84,13 +84,14 @@ register(Host, Config) when is_list(Host), is_list(Config) ->
|
||||
true = exmpp_stringprep:is_node(Host),
|
||||
ID = get_clusterid(),
|
||||
H = #hosts{host = Host, clusterid = ID, config = Config},
|
||||
ok = gen_storage:dirty_write(Host, H),
|
||||
HostB = list_to_binary(Host),
|
||||
ok = gen_storage:dirty_write(HostB, H),
|
||||
reload(),
|
||||
ok.
|
||||
|
||||
%% Updates host configuration
|
||||
update_host_conf(Host, Config) when is_list(Host), is_list(Config) ->
|
||||
true = jlib:is_nodename(Host),
|
||||
true = exmpp_stringprep:is_node(Host),
|
||||
case registered(Host) of
|
||||
false -> {error, host_process_not_registered};
|
||||
true ->
|
||||
@ -103,8 +104,9 @@ update_host_conf(Host, Config) when is_list(Host), is_list(Config) ->
|
||||
remove(Host) when is_list(Host) ->
|
||||
true = exmpp_stringprep:is_node(Host),
|
||||
ID = get_clusterid(),
|
||||
HostB = list_to_binary(Host),
|
||||
gen_storage:dirty_delete_where(
|
||||
Host, hosts,
|
||||
HostB, hosts,
|
||||
[{'andalso',
|
||||
{'==', clusterid, ID},
|
||||
{'==', host, Host}}]),
|
||||
@ -207,7 +209,7 @@ handle_info(timeout, State = #state{state=wait_odbc,backend=Backend,odbc_wait_ti
|
||||
{config, text}]}]),
|
||||
|
||||
%% Now let's add the default vhost: "localhost"
|
||||
gen_storage:dirty_write(Host, #hosts{host = Host,
|
||||
gen_storage:dirty_write(HostB, #hosts{host = Host,
|
||||
clusterid = 1,
|
||||
config = ""}),
|
||||
|
||||
@ -371,19 +373,10 @@ stop_host(Host) ->
|
||||
get_hosts(ejabberd) -> ?MYHOSTS;
|
||||
get_hosts(odbc) ->
|
||||
ClusterID = get_clusterid(),
|
||||
case gen_storage:dirty_select(?MYNAME, hosts, [{'=', clusterid, ClusterID}]) of
|
||||
Hosts when is_list(Hosts) ->
|
||||
lists:map(fun (#hosts{host = Host}) ->
|
||||
case exmpp_stringprep:nameprep(Host) of
|
||||
error ->
|
||||
erlang:error({bad_vhost_name, Host});
|
||||
Name ->
|
||||
Name
|
||||
end
|
||||
end, Hosts);
|
||||
E ->
|
||||
erlang:error({get_hosts_error, E})
|
||||
end.
|
||||
Hosts = gen_storage:dirty_select(?MYNAME, hosts, [{'=', clusterid, ClusterID}]),
|
||||
lists:map(fun (#hosts{host = Host}) ->
|
||||
exmpp_stringprep:nameprep(Host)
|
||||
end, Hosts).
|
||||
|
||||
%% Retreive the text format config for host Host from ODBC and covert
|
||||
%% it into a {host, Host, Config} tuple.
|
||||
|
@ -205,24 +205,20 @@ delete_balanced_route(LDomain, Pid) ->
|
||||
|
||||
|
||||
force_unregister_route(Domain) ->
|
||||
case jlib:nameprep(Domain) of
|
||||
error ->
|
||||
erlang:error({invalid_domain, Domain});
|
||||
LDomain ->
|
||||
F = fun() ->
|
||||
case mnesia:match_object(
|
||||
#route{domain = LDomain,
|
||||
_ = '_'}) of
|
||||
Rs when is_list(Rs) ->
|
||||
lists:foreach(fun(R) ->
|
||||
mnesia:delete_object(R)
|
||||
end, Rs);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F)
|
||||
end.
|
||||
LDomain = exmpp_stringprep:nameprep(Domain),
|
||||
F = fun() ->
|
||||
case mnesia:match_object(
|
||||
#route{domain = LDomain,
|
||||
_ = '_'}) of
|
||||
Rs when is_list(Rs) ->
|
||||
lists:foreach(fun(R) ->
|
||||
mnesia:delete_object(R)
|
||||
end, Rs);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F).
|
||||
|
||||
unregister_routes(Domains) ->
|
||||
lists:foreach(fun(Domain) ->
|
||||
|
@ -61,10 +61,9 @@ behaviour_info(_) ->
|
||||
-spec all_table_hosts(atom()) ->
|
||||
[storage_host()].
|
||||
all_table_hosts(Tab) ->
|
||||
mnesia:dirty_select(table, [{#table{host_name = '$1',
|
||||
_ = '_'},
|
||||
[{'=:=', {element, 2, '$1'}, {const, Tab}}],
|
||||
[{element, 1, '$1'}]}]).
|
||||
mnesia:dirty_select(table, [{{table, {'$1', '$2'}, '_', '_'},
|
||||
[{'=:=', '$2', {const, Tab}}],
|
||||
['$1']}]).
|
||||
|
||||
-spec table_info(storage_host, storage_table, atom()) ->
|
||||
any().
|
||||
@ -110,7 +109,7 @@ table_info(Host, Tab, InfoKey) ->
|
||||
%% columndef() defaults to text for all unspecified attributes
|
||||
|
||||
-spec create_table(atom(), storage_host(), storage_table(), #table{}) ->
|
||||
{atomic, ok}.
|
||||
tuple().
|
||||
|
||||
create_table(mnesia, Host, Tab, Def) ->
|
||||
MDef = filter_mnesia_tabdef(Def),
|
||||
@ -123,7 +122,7 @@ create_table(odbc, Host, Tab, Def) ->
|
||||
define_table(gen_storage_odbc, Host, Tab, ODef),
|
||||
gen_storage_odbc:create_table(ODef).
|
||||
|
||||
-spec define_table(atom(), storage_host(), storage_table(), #table{}) ->
|
||||
-spec define_table(atom(), storage_host(), storage_table(), #mnesia_def{} | tuple()) ->
|
||||
ok.
|
||||
define_table(Backend, Host, Name, Def) ->
|
||||
mnesia:create_table(table, [{attributes, record_info(fields, table)}]),
|
||||
@ -131,8 +130,10 @@ define_table(Backend, Host, Name, Def) ->
|
||||
backend = Backend,
|
||||
def = Def}).
|
||||
|
||||
%% @spec (#table{}) -> [{atom(), any()}]
|
||||
|
||||
-spec filter_mnesia_tabdef(#table{}) ->
|
||||
[{atom(), any()}].
|
||||
[any()].
|
||||
|
||||
filter_mnesia_tabdef(TabDef) ->
|
||||
lists:filter(fun filter_mnesia_tabdef_/1, TabDef).
|
||||
@ -531,7 +532,7 @@ write_lock_table(Host, Tab) ->
|
||||
|
||||
|
||||
-spec transaction(storage_host(), storage_table(), fun()) ->
|
||||
{atomic, any()}.
|
||||
{atomic, any()} | {aborted, string()}.
|
||||
%% Warning: all tabs touched by the transaction must use the same
|
||||
%% storage backend!
|
||||
transaction(Host, Tab, Fun) ->
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
%% @spec (Host, Table, Migrations) -> any()
|
||||
%% @spec (Host::storage_host(), Table::atom(), Migrations) -> any()
|
||||
%% Migrations = [{OldTable, OldAttributes, MigrateFun}]
|
||||
migrate_mnesia(Host, Table, Migrations) ->
|
||||
SameTableName = [Migration
|
||||
@ -33,14 +33,15 @@ migrate_mnesia(Host, Table, Migrations) ->
|
||||
end, DifferentTableName).
|
||||
|
||||
migrate_mnesia1(Host, Table, {OldTable, OldAttributes, MigrateFun}) ->
|
||||
HostB = list_to_binary(Host),
|
||||
case (catch mnesia:table_info(OldTable, attributes)) of
|
||||
OldAttributes ->
|
||||
if
|
||||
Table =:= OldTable ->
|
||||
%% TODO: move into transaction
|
||||
TmpTable = list_to_atom(atom_to_list(Table) ++ "_tmp"),
|
||||
NewRecordName = gen_storage:table_info(Host, Table, record_name),
|
||||
NewAttributes = gen_storage:table_info(Host, Table, attributes),
|
||||
NewRecordName = gen_storage:table_info(HostB, Table, record_name),
|
||||
NewAttributes = gen_storage:table_info(HostB, Table, attributes),
|
||||
?INFO_MSG("Migrating mnesia table ~p via ~p~nfrom ~p~nto ~p",
|
||||
[Table, TmpTable, OldAttributes, NewAttributes]),
|
||||
|
||||
@ -67,15 +68,15 @@ migrate_mnesia1(Host, Table, {OldTable, OldAttributes, MigrateFun}) ->
|
||||
end,
|
||||
{atomic, ok} = mnesia:transaction(F1),
|
||||
mnesia:delete_table(OldTable),
|
||||
TableInfo = gen_storage:table_info(Host, Table, all),
|
||||
TableInfo = gen_storage:table_info(HostB, Table, all),
|
||||
{value, {_, Backend}} = lists:keysearch(backend, 1, TableInfo),
|
||||
gen_storage:create_table(Backend, Host, Table, TableInfo),
|
||||
gen_storage:create_table(Backend, HostB, Table, TableInfo),
|
||||
F2 = fun() ->
|
||||
mnesia:write_lock_table(Table),
|
||||
mnesia:foldl(
|
||||
fun(NewRecord, _) ->
|
||||
?DEBUG("~p-~p: ~p~n",[OldTable, Table, NewRecord]),
|
||||
gen_storage:write(Host, Table, NewRecord, write)
|
||||
gen_storage:write(HostB, Table, NewRecord, write)
|
||||
end, ok, TmpTable)
|
||||
end,
|
||||
{atomic, ok} = mnesia:transaction(F2),
|
||||
@ -93,7 +94,7 @@ migrate_mnesia1(Host, Table, {OldTable, OldAttributes, MigrateFun}) ->
|
||||
?DEBUG("~p-~p: ~p -> ~p~n",[OldTable, Table, OldRecord, NewRecord]),
|
||||
if
|
||||
is_tuple(NewRecord) ->
|
||||
gen_storage:write(Host, Table, NewRecord, write);
|
||||
gen_storage:write(HostB, Table, NewRecord, write);
|
||||
true ->
|
||||
ignored
|
||||
end
|
||||
@ -142,6 +143,7 @@ migrate_odbc1(Host, Tables, {OldTablesColumns, MigrateFun}) ->
|
||||
migrate_odbc2(Host, Tables, OldTable, OldTables, OldColumns, OldColumnsAll, OldTablesA, ColumnsT, MigrateFun)
|
||||
when ColumnsT == OldColumnsAll ->
|
||||
?INFO_MSG("Migrating ODBC table ~p to gen_storage tables ~p", [OldTable, Tables]),
|
||||
HostB = list_to_binary(Host),
|
||||
|
||||
%% rename old tables to *_old
|
||||
lists:foreach(fun(OldTable1) ->
|
||||
@ -149,13 +151,12 @@ migrate_odbc2(Host, Tables, OldTable, OldTables, OldColumns, OldColumnsAll, OldT
|
||||
ejabberd_odbc:sql_query_t("alter table " ++ OldTable1 ++
|
||||
" rename to " ++ OldTable1 ++ "_old")
|
||||
end, OldTables),
|
||||
HostB = list_to_binary(Host),
|
||||
%% recreate new tables
|
||||
lists:foreach(fun(NewTable) ->
|
||||
case lists:member(NewTable, OldTablesA) of
|
||||
true ->
|
||||
TableInfo =
|
||||
gen_storage:table_info(Host, NewTable, all),
|
||||
gen_storage:table_info(HostB, NewTable, all),
|
||||
{value, {_, Backend}} =
|
||||
lists:keysearch(backend, 1, TableInfo),
|
||||
gen_storage:create_table(Backend, HostB,
|
||||
|
@ -325,11 +325,7 @@ find_x_expire(TimeStamp, [#xmlel{ns = ?NS_MESSAGE_EXPIRE} = El | _Els]) ->
|
||||
{'EXIT', _} ->
|
||||
0;
|
||||
Int when Int > 0 ->
|
||||
{MegaSecs, Secs, MicroSecs} = TimeStamp,
|
||||
S = MegaSecs * 1000000 + Secs + Int,
|
||||
MegaSecs1 = S div 1000000,
|
||||
Secs1 = S rem 1000000,
|
||||
{MegaSecs1, Secs1, MicroSecs};
|
||||
TimeStamp + Int;
|
||||
_ ->
|
||||
0
|
||||
end;
|
||||
@ -450,11 +446,12 @@ remove_old_messages(Days) ->
|
||||
Timestamp = make_timestamp() - 60 * 60 * 24 * Days,
|
||||
lists:foreach(
|
||||
fun(Host) ->
|
||||
HostB = list_to_binary(Host),
|
||||
F = fun() ->
|
||||
gen_storage:delete_where(Host, offline_msg,
|
||||
gen_storage:delete_where(HostB, offline_msg,
|
||||
[{'<', timestamp, Timestamp}])
|
||||
end,
|
||||
{atomic, _} = gen_storage:transaction(Host, offline_msg, F)
|
||||
{atomic, _} = gen_storage:transaction(HostB, offline_msg, F)
|
||||
end, gen_storage:all_table_hosts(offline_msg)).
|
||||
|
||||
remove_user(User, Server) when is_binary(User), is_binary(Server) ->
|
||||
@ -494,8 +491,8 @@ update_table(Host, mnesia) ->
|
||||
Expire1 = case Expire of
|
||||
never ->
|
||||
0;
|
||||
{MegaSecs, Secs, _MicroSecs} ->
|
||||
MegaSecs * 1000000 + Secs
|
||||
Ts ->
|
||||
Ts
|
||||
end,
|
||||
PacketXmlel = exmpp_xml:xmlelement_to_xmlel(
|
||||
Packet, [?DEFAULT_NS], ?PREFIXED_NS),
|
||||
@ -680,8 +677,10 @@ user_queue_parse_query(US, Query) ->
|
||||
us_to_list({User, Server}) ->
|
||||
exmpp_jid:to_list(User, Server).
|
||||
|
||||
%% @spec (User::string(), Host::string()) -> integer()
|
||||
get_queue_length(User, Host) ->
|
||||
gen_storage:dirty_count_records(Host, offline_msg, [{'=', user_host, {User, Host}}]).
|
||||
HostB = list_to_binary(Host),
|
||||
gen_storage:dirty_count_records(HostB, offline_msg, [{'=', user_host, {User, Host}}]).
|
||||
|
||||
get_messages_subset(User, Host, MsgsAll) ->
|
||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access_max_user_messages,
|
||||
|
@ -804,6 +804,7 @@ updated_list(_,
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
update_tables(Host, mnesia) ->
|
||||
HostB = list_to_binary(Host),
|
||||
gen_storage_migration:migrate_mnesia(
|
||||
Host, privacy_default_list,
|
||||
[{privacy, [us, default, lists],
|
||||
@ -821,7 +822,7 @@ update_tables(Host, mnesia) ->
|
||||
match_presence_in = MatchPresenceIn,
|
||||
match_presence_out = MatchPresenceOut}) ->
|
||||
ValueBin = convert_value_to_binary(Value),
|
||||
gen_storage:write(Host,
|
||||
gen_storage:write(HostB,
|
||||
#privacy_list_data{user_host = US,
|
||||
name = Name,
|
||||
type = Type,
|
||||
@ -834,7 +835,7 @@ update_tables(Host, mnesia) ->
|
||||
match_presence_in = MatchPresenceIn,
|
||||
match_presence_out = MatchPresenceOut})
|
||||
end, List),
|
||||
gen_storage:write(Host,
|
||||
gen_storage:write(HostB,
|
||||
#privacy_list{user_host = US,
|
||||
name = Name})
|
||||
end, Lists),
|
||||
|
@ -389,7 +389,7 @@ storageroster_to_roster(#rosteritem{user_host_jid = {U, S, JID} = USJ,
|
||||
(_, R) ->
|
||||
R
|
||||
end, [], Rostergroups),
|
||||
#roster{usj = {US, JID},
|
||||
#roster{usj = {U, S, JID},
|
||||
us = US,
|
||||
jid = JID,
|
||||
name = convert_to_string(Name),
|
||||
@ -695,12 +695,8 @@ get_subscription_lists(_, User, Server)
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case gen_storage:dirty_select(LServer, rosteritem, [{'=', user_host_jid, {LUser, LServer, '_'}}]) of
|
||||
Items when is_list(Items) ->
|
||||
fill_subscription_lists(Items, [], []);
|
||||
_ ->
|
||||
{[], []}
|
||||
end
|
||||
Items = gen_storage:dirty_select(LServer, rosteritem, [{'=', user_host_jid, {LUser, LServer, '_'}}]),
|
||||
fill_subscription_lists(Items, [], [])
|
||||
catch
|
||||
_ ->
|
||||
{[], []}
|
||||
@ -1142,8 +1138,7 @@ get_in_pending_subscriptions(Ls, User, Server)
|
||||
JID = exmpp_jid:make(User, Server),
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case gen_storage:dirty_select(LServer, rosteritem, [{'=', user_host_jid, {LUser, LServer, '_'}}]) of
|
||||
Result when is_list(Result) ->
|
||||
Result = gen_storage:dirty_select(LServer, rosteritem, [{'=', user_host_jid, {LUser, LServer, '_'}}]),
|
||||
Ls ++ lists:map(
|
||||
fun(#rosteritem{user_host_jid = {_, _, RJID},
|
||||
askmessage = Message}) ->
|
||||
@ -1169,10 +1164,7 @@ get_in_pending_subscriptions(Ls, User, Server)
|
||||
_ -> false
|
||||
end
|
||||
end,
|
||||
Result));
|
||||
_ ->
|
||||
Ls
|
||||
end.
|
||||
Result)).
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@ -1235,6 +1227,7 @@ get_jid_info(_, User, Server, JID)
|
||||
%% Only supports migration from ejabberd 1.1.2 or higher.
|
||||
|
||||
update_table(Host, mnesia) ->
|
||||
HostB = list_to_binary(Host),
|
||||
gen_storage_migration:migrate_mnesia(
|
||||
Host, rosteritem,
|
||||
[{roster, [usj, us, jid, name, subscription, ask, groups, askmessage, xs],
|
||||
@ -1250,7 +1243,7 @@ update_table(Host, mnesia) ->
|
||||
lists:foreach(
|
||||
fun(Group) ->
|
||||
Group2 = list_to_binary(Group),
|
||||
gen_storage:write(Host,
|
||||
gen_storage:write(HostB,
|
||||
#rostergroup{user_host_jid = USJ1,
|
||||
grp = Group2})
|
||||
end, Groups),
|
||||
|
@ -106,18 +106,18 @@ start(Host, Opts) ->
|
||||
{attributes, record_info(fields, vcard_search)},
|
||||
{types, [{user_host, {text, text}}]}]),
|
||||
update_tables(Host, Backend),
|
||||
gen_storage:add_table_index(Host, vcard_search, lusername),
|
||||
gen_storage:add_table_index(Host, vcard_search, lfn),
|
||||
gen_storage:add_table_index(Host, vcard_search, lfamily),
|
||||
gen_storage:add_table_index(Host, vcard_search, lgiven),
|
||||
gen_storage:add_table_index(Host, vcard_search, lmiddle),
|
||||
gen_storage:add_table_index(Host, vcard_search, lnickname),
|
||||
gen_storage:add_table_index(Host, vcard_search, lbday),
|
||||
gen_storage:add_table_index(Host, vcard_search, lctry),
|
||||
gen_storage:add_table_index(Host, vcard_search, llocality),
|
||||
gen_storage:add_table_index(Host, vcard_search, lemail),
|
||||
gen_storage:add_table_index(Host, vcard_search, lorgname),
|
||||
gen_storage:add_table_index(Host, vcard_search, lorgunit),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lusername),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lfn),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lfamily),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lgiven),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lmiddle),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lnickname),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lbday),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lctry),
|
||||
gen_storage:add_table_index(HostB, vcard_search, llocality),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lemail),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lorgname),
|
||||
gen_storage:add_table_index(HostB, vcard_search, lorgunit),
|
||||
|
||||
ejabberd_hooks:add(remove_user, HostB,
|
||||
?MODULE, remove_user, 50),
|
||||
|
@ -47,7 +47,7 @@ start() ->
|
||||
end,
|
||||
case Res of
|
||||
ok ->
|
||||
Port = open_port({spawn, ?DRIVER}, [binary]),
|
||||
Port = open_port({spawn, atom_to_list(?DRIVER)}, [binary]),
|
||||
register(?DRIVER, Port);
|
||||
{error, Reason} ->
|
||||
?CRITICAL_MSG("unable to load driver '~s': ~s",
|
||||
|
Loading…
Reference in New Issue
Block a user