25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Fix dialyzer errors

This commit is contained in:
Alexey Shchepin 2024-02-16 06:00:57 +03:00
parent 45f24c63cb
commit c10f2a22b6
3 changed files with 22 additions and 35 deletions

View File

@ -362,16 +362,6 @@ process([<<"federation">>, <<"v2">>, <<"send_join">>, RoomID, EventID],
case get_id_domain_exn(Sender) of case get_id_domain_exn(Sender) of
Origin -> Origin ->
case mod_matrix_gw_room:send_join(Host, Origin, RoomID, EventID, JSON) of case mod_matrix_gw_room:send_join(Host, Origin, RoomID, EventID, JSON) of
{error, room_not_found} ->
Res = #{<<"errcode">> => <<"M_NOT_FOUND">>,
<<"error">> => <<"Unknown room">>},
{404, [{<<"Content-Type">>, <<"application/json;charset=UTF-8">>}],
jiffy:encode(Res)};
{error, not_invited} ->
Res = #{<<"errcode">> => <<"M_FORBIDDEN">>,
<<"error">> => <<"You are not invited to this room">>},
{403, [{<<"Content-Type">>, <<"application/json;charset=UTF-8">>}],
jiffy:encode(Res)};
{error, Error} when is_binary(Error) -> {error, Error} when is_binary(Error) ->
Res = #{<<"errcode">> => <<"M_BAD_REQUEST">>, Res = #{<<"errcode">> => <<"M_BAD_REQUEST">>,
<<"error">> => Error}, <<"error">> => Error},
@ -733,13 +723,23 @@ sign_json(Host, JSON) ->
Msg = encode_canonical_json(JSON2), Msg = encode_canonical_json(JSON2),
SignatureName = mod_matrix_gw_opt:matrix_domain(Host), SignatureName = mod_matrix_gw_opt:matrix_domain(Host),
KeyName = mod_matrix_gw_opt:key_name(Host), KeyName = mod_matrix_gw_opt:key_name(Host),
{PubKey, PrivKey} = mod_matrix_gw_opt:key(Host), {_PubKey, PrivKey} = mod_matrix_gw_opt:key(Host),
KeyID = <<"ed25519:", KeyName/binary>>, KeyID = <<"ed25519:", KeyName/binary>>,
Sig = public_key:sign(Msg, ignored, {ed_pri, ed25519, PubKey, PrivKey}), Sig = crypto:sign(eddsa, none, Msg, [PrivKey, ed25519]),
Sig64 = base64_encode(Sig), Sig64 = base64_encode(Sig),
Signatures2 = Signatures#{SignatureName => #{KeyID => Sig64}}, Signatures2 = Signatures#{SignatureName => #{KeyID => Sig64}},
JSON#{<<"signatures">> => Signatures2}. JSON#{<<"signatures">> => Signatures2}.
-spec send_request(
binary(),
get | post | put,
binary(),
[binary()],
[{binary(), binary()}],
none | jiffy:json_object(),
[any()],
[any()]) -> {ok, any()} | {error, any()}.
send_request(Host, Method, MatrixServer, Path, Query, JSON, send_request(Host, Method, MatrixServer, Path, Query, JSON,
HTTPOptions, Options) -> HTTPOptions, Options) ->
URI1 = iolist_to_binary( URI1 = iolist_to_binary(
@ -751,13 +751,13 @@ send_request(Host, Method, MatrixServer, Path, Query, JSON,
URI2 = str:join( URI2 = str:join(
lists:map( lists:map(
fun({K, V}) -> fun({K, V}) ->
[uri_string:quote(K), $=, uri_string:quote(V)] iolist_to_binary(
[uri_string:quote(K), $=,
uri_string:quote(V)])
end, Query), $&), end, Query), $&),
<<URI1/binary, $?, URI2/binary>> <<URI1/binary, $?, URI2/binary>>
end, end,
% TODO
{MHost, MPort} = mod_matrix_gw_s2s:get_matrix_host_port(Host, MatrixServer), {MHost, MPort} = mod_matrix_gw_s2s:get_matrix_host_port(Host, MatrixServer),
%{MHost, MPort} = {MatrixServer, 8008},
URL = <<"https://", MHost/binary, URL = <<"https://", MHost/binary,
":", (integer_to_binary(MPort))/binary, ":", (integer_to_binary(MPort))/binary,
URI/binary>>, URI/binary>>,

View File

@ -72,7 +72,7 @@
-record(data, -record(data,
{host :: binary(), {host :: binary(),
local_user :: jid(), local_user :: jid() | undefined,
remote_user :: binary() | undefined, remote_user :: binary() | undefined,
remote_servers = #{}, remote_servers = #{},
room_id :: binary(), room_id :: binary(),
@ -347,14 +347,7 @@ send_join(Host, Origin, RoomID, EventID, JSON) ->
%% process to initialize. %% process to initialize.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec init(Args :: term()) -> -spec init(Args :: term()) -> gen_statem:init_result(term()).
{gen_statem:callback_mode(),
State :: term(), Data :: term()} |
{gen_statem:callback_mode(),
State :: term(), Data :: term(),
[gen_statem:action()] | gen_statem:action()} |
ignore |
{stop, Reason :: term()}.
init([Host, RoomID]) -> init([Host, RoomID]) ->
mnesia:dirty_write( mnesia:dirty_write(
#matrix_room{room_id = RoomID, #matrix_room{room_id = RoomID,

View File

@ -216,14 +216,7 @@ check_signature(Host, JSON) ->
%% process to initialize. %% process to initialize.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec init(Args :: term()) -> -spec init(Args :: term()) -> gen_statem:init_result(term()).
{gen_statem:callback_mode(),
State :: term(), Data :: term()} |
{gen_statem:callback_mode(),
State :: term(), Data :: term(),
[gen_statem:action()] | gen_statem:action()} |
ignore |
{stop, Reason :: term()}.
init([Host, MatrixServer]) -> init([Host, MatrixServer]) ->
mnesia:dirty_write( mnesia:dirty_write(
#matrix_s2s{to = MatrixServer, #matrix_s2s{to = MatrixServer,
@ -476,8 +469,9 @@ do_get_matrix_host_port(Data) ->
"_matrix._tcp." ++ binary_to_list(MatrixServer), "_matrix._tcp." ++ binary_to_list(MatrixServer),
case inet_res:getbyname(SRVName, srv, 5000) of case inet_res:getbyname(SRVName, srv, 5000) of
{ok, HostEntry} -> {ok, HostEntry} ->
case h_addr_list_to_host_ports( {hostent, _Name, _Aliases, _AddrType, _Len,
HostEntry#hostent.h_addr_list) of HAddrList} = HostEntry,
case h_addr_list_to_host_ports(HAddrList) of
{ok, [{Host, Port} | _]} -> {ok, [{Host, Port} | _]} ->
{list_to_binary(Host), Port}; {list_to_binary(Host), Port};
_ -> _ ->
@ -531,7 +525,7 @@ check_signature(JSON, SignatureName, KeyID, VerifyKey) ->
Signature = mod_matrix_gw:base64_decode(SSignature), Signature = mod_matrix_gw:base64_decode(SSignature),
JSON2 = maps:without([<<"signatures">>, <<"unsigned">>], JSON), JSON2 = maps:without([<<"signatures">>, <<"unsigned">>], JSON),
Msg = mod_matrix_gw:encode_canonical_json(JSON2), Msg = mod_matrix_gw:encode_canonical_json(JSON2),
public_key:verify(Msg, ignored, Signature, {ed_pub, ed25519, VerifyKey}) crypto:verify(eddsa, none, Msg, Signature, [VerifyKey, ed25519])
catch catch
_:_ -> _:_ ->
false false