Skip to content

Commit 3cec5b4

Browse files
committed
mod_unified_push: Fix option push_url when set to a custom URL (#367)
1 parent 30d9d7c commit 3cec5b4

File tree

1 file changed

+15
-60
lines changed

1 file changed

+15
-60
lines changed

mod_unified_push/src/mod_unified_push.erl

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ mod_opt_type(expiration) ->
243243
mod_opt_type(jwk) ->
244244
econf:map(econf:binary(), econf:either(econf:binary(), econf:int()));
245245
mod_opt_type(push_url) ->
246-
econf:either(undefined, econf:binary()).
246+
econf:binary().
247247

248248
-spec mod_options(binary()) -> [{atom(), any()}].
249249
mod_options(_Host) ->
@@ -253,65 +253,20 @@ mod_options(_Host) ->
253253
{push_url, <<"auto">>}
254254
].
255255

256+
-dialyzer({no_missing_calls, get_push_url/1}).
256257
get_push_url(Host) ->
257-
case erlang:function_exported(mod_host_meta, get_url, 4) of
258-
true -> get_push_url_new(Host);
259-
false -> get_push_url_old(Host)
260-
end.
261-
262-
%% ejabberd higher than 25.10
263-
get_push_url_new(Host) ->
264-
misc:expand_keyword(<<"@HOST@">>, guess_url_prefix(any), Host).
265-
266-
%% Based on mod_host_meta's `get_auto_url` and `find_handler_port_path` functions
267-
-spec guess_url_prefix(any | boolean()) -> undefined | binary().
268-
guess_url_prefix(Tls) ->
269-
case
270-
lists:filtermap(
271-
fun
272-
(
273-
{{Port, _, _}, ejabberd_http, #{tls := ThisTls, request_handlers := Handlers}}
274-
) when
275-
(Tls == any) or (Tls == ThisTls)
276-
->
277-
case lists:keyfind(?MODULE, 2, Handlers) of
278-
false -> false;
279-
{Path, ?MODULE} -> {true, {ThisTls, Port, Path}}
280-
end;
281-
(_) ->
282-
false
283-
end,
284-
ets:tab2list(ejabberd_listener)
285-
)
286-
of
287-
[] ->
288-
undefined;
289-
[{ThisTls, Port, Path} | _] ->
290-
Protocol =
291-
case ThisTls of
292-
false -> <<"http">>;
293-
true -> <<"https">>
294-
end,
295-
<<Protocol/binary, "://@HOST@:", (integer_to_binary(Port))/binary, "/",
296-
(str:join(Path, <<"/">>))/binary>>
297-
end.
298-
299-
%% ejabberd 25.10 and lower
300-
get_push_url_old(Host) ->
301-
get_url(?MODULE, any, Host, push_url, ?MODULE).
302-
303-
get_url(M, Tls, Host, Option, Module) ->
304-
case get_url_preliminar(M, Tls, Host, Option, Module) of
305-
undefined -> undefined;
306-
Url -> misc:expand_keyword(<<"@HOST@">>, Url, Host)
307-
end.
308-
309-
-dialyzer({no_missing_calls, get_url_preliminar/5}).
310-
get_url_preliminar(M, Tls, Host, Option, Module) ->
311-
case gen_mod:get_module_opt(Host, M, Option) of
312-
<<"auto">> -> mod_host_meta:get_auto_url(Tls, Module);
313-
U when is_binary(U) -> U;
314-
_ -> mod_host_meta:get_auto_url(Tls, Module)
258+
case gen_mod:get_module_opt(Host, ?MODULE, push_url) of
259+
<<"auto">> ->
260+
AutoUrl = case erlang:function_exported(ejabberd_http, get_auto_url, 2) of
261+
false ->
262+
mod_host_meta:get_auto_url(any, ?MODULE);
263+
true ->
264+
[{_, Http} | _] = ejabberd_http:get_auto_urls(any, ?MODULE),
265+
Http
266+
end,
267+
misc:expand_keyword(<<"@HOST@">>, AutoUrl, Host);
268+
U when is_binary(U) ->
269+
U
315270
end.
316271

317272
-spec mod_doc() -> map().
@@ -338,7 +293,7 @@ mod_doc() ->
338293
)
339294
}},
340295
{push_url,
341-
#{value => "undefined | auto | PushURL",
296+
#{value => "auto | PushURL",
342297
desc =>
343298
?T("Push URL to announce. "
344299
"The keyword '@HOST@' is replaced with the real virtual "

0 commit comments

Comments
 (0)