25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Improve code using new xmpp API

This commit is contained in:
Evgeniy Khramtsov 2017-12-06 17:21:57 +03:00
parent e4a4839880
commit 7a9d2cabc0
4 changed files with 9 additions and 15 deletions

View File

@ -24,8 +24,8 @@
{cache_tab, ".*", {git, "https://github.com/processone/cache_tab", {tag, "1.0.12"}}}, {cache_tab, ".*", {git, "https://github.com/processone/cache_tab", {tag, "1.0.12"}}},
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.17"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.17"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}}, {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.10"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.25"}}}, {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", "724ec0a"}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "a893ee1"}}, {xmpp, ".*", {git, "https://github.com/processone/xmpp", "dbbaed4edfc"}},
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.12"}}}, {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.12"}}},
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}}, {jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}}, {p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.2"}}},

View File

@ -310,11 +310,8 @@ is_item_not_found({error, #stanza_error{reason = 'item-not-found'}}) -> true;
is_item_not_found({error, _}) -> false. is_item_not_found({error, _}) -> false.
-spec is_not_subscribed({error, stanza_error()}) -> boolean(). -spec is_not_subscribed({error, stanza_error()}) -> boolean().
is_not_subscribed({error, #stanza_error{sub_els = Els}}) -> is_not_subscribed({error, StanzaError}) ->
%% TODO: make xmpp:get_els function working for any XMPP element xmpp:has_subtag(StanzaError, #ps_error{type = 'not-subscribed'}).
%% with sub_els field
xmpp:has_subtag(#message{sub_els = Els},
#ps_error{type = 'not-subscribed'}).
depends(_Host, _Opts) -> depends(_Host, _Opts) ->
[{mod_pubsub, hard}]. [{mod_pubsub, hard}].

View File

@ -334,9 +334,8 @@ mk_error(_) ->
-spec format_error(db_result()) -> binary(). -spec format_error(db_result()) -> binary().
format_error(#db_result{type = invalid}) -> format_error(#db_result{type = invalid}) ->
<<"invalid dialback key">>; <<"invalid dialback key">>;
format_error(#db_result{type = error, sub_els = Els}) -> format_error(#db_result{type = error} = Result) ->
%% TODO: improve xmpp.erl case xmpp:get_error(Result) of
case xmpp:get_error(#message{sub_els = Els}) of
#stanza_error{} = Err -> #stanza_error{} = Err ->
format_stanza_error(Err); format_stanza_error(Err);
undefined -> undefined ->

View File

@ -511,7 +511,7 @@ process_features(StreamFeatures,
catch _:undef -> State catch _:undef -> State
end, end,
process_stream_established(State1); process_stream_established(State1);
process_features(#stream_features{sub_els = Els} = StreamFeatures, process_features(StreamFeatures,
#{stream_encrypted := Encrypted, #{stream_encrypted := Encrypted,
mod := Mod, lang := Lang} = State) -> mod := Mod, lang := Lang} = State) ->
State1 = try Mod:handle_unauthenticated_features(StreamFeatures, State) State1 = try Mod:handle_unauthenticated_features(StreamFeatures, State)
@ -522,9 +522,7 @@ process_features(#stream_features{sub_els = Els} = StreamFeatures,
false -> false ->
TLSRequired = is_starttls_required(State1), TLSRequired = is_starttls_required(State1),
TLSAvailable = is_starttls_available(State1), TLSAvailable = is_starttls_available(State1),
%% TODO: improve xmpp.erl case xmpp:get_subtag(StreamFeatures, #starttls{}) of
Msg = #message{sub_els = Els},
case xmpp:get_subtag(Msg, #starttls{}) of
false when TLSRequired and not Encrypted -> false when TLSRequired and not Encrypted ->
Txt = <<"Use of STARTTLS required">>, Txt = <<"Use of STARTTLS required">>,
send_pkt(State1, xmpp:serr_policy_violation(Txt, Lang)); send_pkt(State1, xmpp:serr_policy_violation(Txt, Lang));
@ -545,7 +543,7 @@ process_features(#stream_features{sub_els = Els} = StreamFeatures,
case is_disconnected(State2) of case is_disconnected(State2) of
true -> State2; true -> State2;
false -> false ->
case xmpp:get_subtag(Msg, #sasl_mechanisms{}) of case xmpp:get_subtag(StreamFeatures, #sasl_mechanisms{}) of
#sasl_mechanisms{list = Mechs} -> #sasl_mechanisms{list = Mechs} ->
process_sasl_mechanisms(Mechs, State2); process_sasl_mechanisms(Mechs, State2);
false -> false ->