diff --git a/mix.exs b/mix.exs index ba1a690b7..26e40b1db 100644 --- a/mix.exs +++ b/mix.exs @@ -46,7 +46,7 @@ defmodule Ejabberd.MixProject do def application do [mod: {:ejabberd_app, []}, applications: [:idna, :inets, :kernel, :sasl, :ssl, :stdlib, :mix, - :fast_tls, :fast_xml, :fast_yaml, :jiffy, :jose, + :fast_tls, :fast_xml, :fast_yaml, :jose, :p1_utils, :stringprep, :syntax_tools, :yconf] ++ cond_apps(), included_applications: [:mnesia, :os_mon, @@ -114,6 +114,7 @@ defmodule Ejabberd.MixProject do 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"27", [{:d, :OTP_BELOW_27}]) ++ 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}] @@ -139,7 +140,6 @@ defmodule Ejabberd.MixProject do {:fast_xml, ">= 1.1.51"}, {:fast_yaml, "~> 1.0"}, {:idna, "~> 6.0"}, - {:jiffy, "~> 1.1.1"}, {:mqtree, "~> 1.0"}, {:p1_acme, git: "https://github.com/processone/p1_acme", branch: "master"}, {:p1_oauth2, "~> 0.6"}, @@ -173,6 +173,7 @@ defmodule Ejabberd.MixProject do {config(:zlib), {:ezlib, "~> 1.0"}}, {if_version_above(~c"23", true), {:jose, "~> 1.11.10"}}, {if_version_below(~c"24", true), {:jose, "1.11.1"}}, + {if_version_below(~c"27", true), {:jiffy, "~> 1.1.1"}}, {if_version_below(~c"22", true), {:lager, "~> 3.9.1"}}, {config(:lua), {:luerl, "~> 1.2.0"}}, {config(:mysql), {:p1_mysql, ">= 1.0.23" }}, @@ -185,6 +186,7 @@ defmodule Ejabberd.MixProject do defp cond_apps do for {:true, app} <- [{config(:stun), :stun}, {Map.has_key?(System.get_env(), "RELIVE"), :exsync}, + {if_version_below(~c"27", true), :jiffy}, {config(:tools), :observer}], do: app end diff --git a/rebar.config b/rebar.config index 09da3c176..b1b017843 100644 --- a/rebar.config +++ b/rebar.config @@ -40,9 +40,8 @@ {fast_xml, "~> 1.1.51", {git, "https://github.com/processone/fast_xml", {tag, "1.1.51"}}}, {fast_yaml, "~> 1.0.36", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.36"}}}, {idna, "~> 6.0", {git, "https://github.com/benoitc/erlang-idna", {tag, "6.0.0"}}}, - {if_version_above, "19", - {jiffy, "~> 1.1.1", {git, "https://github.com/davisp/jiffy", {tag, "1.1.1"}}}, - {jiffy, "1.1.0", {git, "https://github.com/davisp/jiffy", {tag, "1.1.0"}}} % for R19 and below + {if_version_below, "27", + {jiffy, "~> 1.1.1", {git, "https://github.com/davisp/jiffy", {tag, "1.1.1"}}} }, {if_version_above, "23", {jose, "~> 1.11.10", {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.11.10"}}}, @@ -131,6 +130,7 @@ {if_version_below, "24", {d, 'SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL'}}, {if_version_below, "24", {d, 'OTP_BELOW_24'}}, {if_version_below, "25", {d, 'OTP_BELOW_25'}}, + {if_version_below, "27", {d, 'OTP_BELOW_27'}}, {if_var_false, debug, no_debug_info}, {if_var_true, debug, debug_info}, {if_var_true, elixir, {d, 'ELIXIR_ENABLED'}}, @@ -206,10 +206,11 @@ {if_version_above, "25", {plt_extra_apps, [asn1, odbc, public_key, stdlib, syntax_tools, - idna, jiffy, jose, + idna, jose, cache_tab, eimp, fast_tls, fast_xml, fast_yaml, mqtree, p1_acme, p1_oauth2, p1_utils, pkix, stringprep, xmpp, yconf, + {if_version_below, "27", jiffy}, {if_var_true, pam, epam}, {if_var_true, redis, eredis}, {if_var_true, sip, esip}, diff --git a/src/ejabberd_ctl.erl b/src/ejabberd_ctl.erl index 3a6f984c5..d42ac2393 100644 --- a/src/ejabberd_ctl.erl +++ b/src/ejabberd_ctl.erl @@ -374,7 +374,7 @@ format_arg(Arg, {tuple, Elements}) -> list_to_tuple(format_args(Args, Elements)); format_arg(Arg, Format) -> S = unicode:characters_to_binary(Arg, utf8), - JSON = jiffy:decode(S, [return_maps]), + JSON = misc:json_decode(S), mod_http_api:format_arg(JSON, Format). format_arg2(Arg, Parse)-> diff --git a/src/ejabberd_oauth.erl b/src/ejabberd_oauth.erl index 9fd6aee3c..96c664acf 100644 --- a/src/ejabberd_oauth.erl +++ b/src/ejabberd_oauth.erl @@ -755,7 +755,7 @@ json_response(Code, Body) -> {Code, [{<<"Content-Type">>, <<"application/json;charset=UTF-8">>}, {<<"Cache-Control">>, <<"no-store">>}, {<<"Pragma">>, <<"no-cache">>}], - jiffy:encode(Body)}. + misc:json_encode(Body)}. %% OAauth error are defined in: %% https://tools.ietf.org/html/draft-ietf-oauth-v2-25#section-5.2 diff --git a/src/ext_mod.erl b/src/ext_mod.erl index 6b8344026..3c3182415 100644 --- a/src/ext_mod.erl +++ b/src/ext_mod.erl @@ -884,7 +884,7 @@ get_commit_details2(Path) -> end. parse_details(Body) -> - Contents = jiffy:decode(Body, [return_maps]), + Contents = misc:json_decode(Body), {ok, Commit} = maps:find(<<"commit">>, Contents), {ok, Sha} = maps:find(<<"sha">>, Commit), diff --git a/src/misc.erl b/src/misc.erl index 26c3c4c2d..a1cd340a2 100644 --- a/src/misc.erl +++ b/src/misc.erl @@ -42,6 +42,7 @@ is_mucsub_message/1, best_match/2, pmap/2, peach/2, format_exception/4, get_my_ipv4_address/0, get_my_ipv6_address/0, parse_ip_mask/1, crypto_hmac/3, crypto_hmac/4, uri_parse/1, uri_parse/2, uri_quote/1, + json_encode/1, json_decode/1, match_ip_mask/3, format_hosts_list/1, format_cycle/1, delete_dir/1, semver_to_xxyy/1, logical_processors/0, get_mucsub_event_type/1]). @@ -58,6 +59,13 @@ -type re_mp() :: {re_pattern, _, _, _, _}. -export_type([re_mp/0]). +-ifdef(OTP_BELOW_27). +-type json_value() :: jiffy:json_value(). +-else. +-type json_value() :: json:encode_value(). +-endif. +-export_type([json_value/0]). + -type distance_cache() :: #{{string(), string()} => non_neg_integer()}. -spec uri_parse(binary()|string()) -> {ok, string(), string(), string(), number(), string(), string()} | {error, term()}. @@ -122,6 +130,18 @@ crypto_hmac(Type, Key, Data) -> crypto:mac(hmac, Type, Key, Data). crypto_hmac(Type, Key, Data, MacL) -> crypto:macN(hmac, Type, Key, Data, MacL). -endif. +-ifdef(OTP_BELOW_27). +json_encode(Term) -> + jiffy:encode(Term). +json_decode(Bin) -> + jiffy:decode(Bin, [return_maps]). +-else. +json_encode(Term) -> + iolist_to_binary(json:encode(Term)). +json_decode(Bin) -> + json:decode(Bin). +-endif. + %%%=================================================================== %%% API %%%=================================================================== diff --git a/src/mod_bosh.erl b/src/mod_bosh.erl index 1a6cfbdf6..9b6e0eeaf 100644 --- a/src/mod_bosh.erl +++ b/src/mod_bosh.erl @@ -154,14 +154,22 @@ get_type(Hdrs) -> depends(_Host, _Opts) -> []. -mod_opt_type(json) -> +-ifdef(OTP_BELOW_27). +mod_opt_type_json() -> econf:and_then( econf:bool(), fun(false) -> false; (true) -> ejabberd:start_app(jiffy), true - end); + end). +-else. +mod_opt_type_json() -> + econf:bool(). +-endif. + +mod_opt_type(json) -> + mod_opt_type_json(); mod_opt_type(max_concat) -> econf:pos_int(unlimited); mod_opt_type(max_inactivity) -> diff --git a/src/mod_conversejs.erl b/src/mod_conversejs.erl index de1564cbb..9017720a4 100644 --- a/src/mod_conversejs.erl +++ b/src/mod_conversejs.erl @@ -90,7 +90,7 @@ process([], #request{method = 'GET', host = Host, raw_path = RawPath}) -> <<"">>, <<"
">>, <<"">>, <<"">>, <<"