./ct_report/coverage/mongoose_subdomain_utils.COVER.html

1 -module(mongoose_subdomain_utils).
2
3 %% API
4 -export([make_subdomain_pattern/1,
5 get_fqdn/2,
6 subdomain_type/1,
7 is_subdomain/3]).
8
9 -type subdomain_pattern() :: {fqdn | prefix, binary()}.
10 -export_type([subdomain_pattern/0]).
11
12 %% this function preprocesses configuration subdomain templates like:
13 %% "subdomain.@HOST@"
14 %% it is compatible with mongoose_config_parser_toml:processor() type,
15 %% so it can be used as #option.process value (for more information see
16 %% mongoose_config_spec.hrl)
17 -spec make_subdomain_pattern(SubdomainPatternConfigOpt :: binary() | string()) ->
18 subdomain_pattern().
19 make_subdomain_pattern(ConfigOpt) when is_list(ConfigOpt) ->
20 474 make_subdomain_pattern(list_to_binary(ConfigOpt));
21 make_subdomain_pattern(ConfigOpt) when is_binary(ConfigOpt) ->
22 1419 case re:replace(ConfigOpt, "\\.@HOST@$", ".", [{return, binary}]) of
23 9 ConfigOpt -> {fqdn, ConfigOpt};
24 1410 Prefix -> {prefix, Prefix}
25 end.
26
27 -spec get_fqdn(subdomain_pattern(), Domain :: mongooseim:domain_name()) ->
28 Subdomain :: mongooseim:domain_name().
29
:-(
get_fqdn({fqdn, Subdomain}, _Domain) -> Subdomain;
30 1718 get_fqdn({prefix, Prefix}, Domain) -> <<Prefix/binary, Domain/binary>>.
31
32 -spec subdomain_type(subdomain_pattern()) -> fqdn | subdomain.
33
:-(
subdomain_type({fqdn, _}) -> fqdn;
34 597 subdomain_type({prefix, _}) -> subdomain.
35
36 -spec is_subdomain(subdomain_pattern(),
37 Domain :: mongooseim:domain_name(),
38 Subdomain :: mongooseim:domain_name()) -> boolean().
39 is_subdomain({fqdn, FQDN}, _, Subdomain) ->
40 8 FQDN =:= Subdomain;
41 is_subdomain({prefix, Prefix}, Domain, Subdomain) ->
42 61 Subdomain =:= <<Prefix/binary, Domain/binary>>.
Line Hits Source