Compare commits

...

2 Commits

Author SHA1 Message Date
Paweł Chmielowski c5437235f3 Make mod_vcard_xupdate send hash after avatar get set for first time
We need to remove info about empty photo in session stored presence after
avatar get set, otherwise as we don't modify presences like that in
mod_vcard_xupdate, we will send presence with updated hash.

This fixes issue #4182
2024-03-20 10:57:12 +01:00
Paweł Chmielowski 537aac24f7 Improve detection of types in odbc
This should fix issue with dialyzer on erlang 26.2.3+
2024-03-18 14:54:32 +01:00
7 changed files with 67 additions and 9 deletions

17
mix.exs
View File

@ -80,6 +80,20 @@ defmodule Ejabberd.MixProject do
end
end
defp if_type_exported(module, typeDef, okResult) do
try do
{:ok, concrete} = :dialyzer_utils.get_core_from_beam(:code.which(module))
{:ok, types} = :dialyzer_utils.get_record_and_type_info(concrete)
if Maps.has_key(types, typeDef) do
okResult
else
[]
end
rescue
_ -> []
end
end
defp erlc_options do
# Use our own includes + includes from all dependencies
includes = ["include", deps_include()]
@ -97,7 +111,8 @@ defmodule Ejabberd.MixProject do
if_version_below(~c"24", [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++
if_version_below(~c"24", [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}]) ++
if_version_below(~c"24", [{:d, :OTP_BELOW_24}]) ++
if_version_below(~c"25", [{:d, :OTP_BELOW_25}])
if_version_below(~c"25", [{:d, :OTP_BELOW_25}]) ++
if_type_exported(:odbc, {:opaque, :connection_reference, 0}, [{:d, :ODBC_HAS_TYPES}])
defines = for {:d, value} <- result, do: {:d, value}
result ++ [{:d, :ALL_DEFS, defines}]
end

View File

@ -152,6 +152,7 @@
{if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATEWAY_WORKAROUND'}},
{if_var_true, sip, {d, 'SIP'}},
{if_var_true, stun, {d, 'STUN'}},
{if_type_exported, {odbc, {opaque, connection_reference, 0}}, {d, 'ODBC_HAS_TYPES'}},
{src_dirs, [src,
{if_rebar3, sql},
{if_var_true, tools, tools}]}]}.

View File

@ -151,6 +151,30 @@ ProcessVars = fun F([], Acc) ->
false ->
F(Tail, Acc)
end;
F([{Type, {Mod, TypeDef}, Value} | Tail], Acc) when
Type == if_type_exported orelse
Type == if_type_not_exported ->
try
{ok, Concrete} = dialyzer_utils:get_core_from_beam(code:which(Mod)),
{ok, Types} = dialyzer_utils:get_record_and_type_info(Concrete),
maps:get(TypeDef, Types, undefined)
of
undefined when Type == if_type_not_exported ->
F(Tail, ProcessSingleVar(F, Value, Acc));
undefined ->
F(Tail, Acc);
_ when Type == if_type_exported ->
F(Tail, ProcessSingleVar(F, Value, Acc));
_ ->
F(Tail, Acc)
catch _:_ ->
if
Type == if_type_not_exported ->
F(Tail, ProcessSingleVar(F, Value, Acc));
true ->
F(Tail, Acc)
end
end;
F([Other1 | Tail1], Acc) ->
F(Tail1, [F(Other1, []) | Acc]);
F(Val, Acc) when is_tuple(Val) ->

View File

@ -52,7 +52,8 @@
-export([get_presence/1, set_presence/2, resend_presence/1, resend_presence/2,
open_session/1, call/3, cast/2, send/2, close/1, close/2, stop_async/1,
reply/2, copy_state/2, set_timeout/2, route/2, format_reason/2,
host_up/1, host_down/1, send_ws_ping/1, bounce_message_queue/2]).
host_up/1, host_down/1, send_ws_ping/1, bounce_message_queue/2,
reset_vcard_xupdate_resend_presence/1]).
-include_lib("xmpp/include/xmpp.hrl").
-include("logger.hrl").
@ -108,6 +109,10 @@ resend_presence(Pid) ->
resend_presence(Pid, To) ->
route(Pid, {resend_presence, To}).
-spec reset_vcard_xupdate_resend_presence(pid()) -> boolean().
reset_vcard_xupdate_resend_presence(Pid) ->
route(Pid, reset_vcard_xupdate_resend_presence).
-spec close(pid()) -> ok;
(state()) -> state().
close(Ref) ->
@ -246,6 +251,13 @@ process_info(#{lserver := LServer} = State, {route, Packet}) ->
true ->
State1
end;
process_info(State, reset_vcard_xupdate_resend_presence) ->
case maps:get(pres_last, State, error) of
error -> State;
Pres ->
Pres2 = xmpp:remove_subtag(Pres, #vcard_xupdate{}),
process_self_presence(State#{pres_last => Pres2}, Pres2)
end;
process_info(#{jid := JID} = State, {resend_presence, To}) ->
case maps:get(pres_last, State, error) of
error -> State;

View File

@ -56,6 +56,7 @@
get_vh_session_number/1,
get_vh_by_backend/1,
force_update_presence/1,
reset_vcard_xupdate_resend_presence/1,
connected_users/0,
connected_users_number/0,
user_resources/2,
@ -926,6 +927,15 @@ force_update_presence({LUser, LServer}) ->
end,
Ss).
-spec reset_vcard_xupdate_resend_presence({binary(), binary()}) -> ok.
reset_vcard_xupdate_resend_presence({LUser, LServer}) ->
Mod = get_sm_backend(LServer),
Ss = get_sessions(Mod, LUser, LServer),
lists:foreach(
fun(#session{sid = {_, Pid}}) ->
ejabberd_c2s:reset_vcard_xupdate_resend_presence(Pid)
end, Ss).
-spec get_sm_backend(binary()) -> module().
get_sm_backend(Host) ->

View File

@ -67,12 +67,8 @@
-export([connecting/2, connecting/3,
session_established/2, session_established/3]).
-ifdef(OTP_RELEASE).
-if(?OTP_RELEASE >= 27).
-type(odbc_connection_reference() :: odbc:connection_reference()).
-else.
-type(odbc_connection_reference() :: pid()).
-endif.
-ifdef(ODBC_HAS_TYPES).
-type(odbc_connection_reference() :: odbc:connection_reference()).
-else.
-type(odbc_connection_reference() :: pid()).
-endif.

View File

@ -97,7 +97,7 @@ user_send_packet(Acc) ->
-spec vcard_set(iq()) -> iq().
vcard_set(#iq{from = #jid{luser = LUser, lserver = LServer}} = IQ) ->
ets_cache:delete(?VCARD_XUPDATE_CACHE, {LUser, LServer}, ejabberd_cluster:get_nodes()),
ejabberd_sm:force_update_presence({LUser, LServer}),
ejabberd_sm:reset_vcard_xupdate_resend_presence({LUser, LServer}),
IQ;
vcard_set(Acc) ->
Acc.