• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

processone / ejabberd / 1258

12 Dec 2025 03:57PM UTC coverage: 33.638% (-0.006%) from 33.644%
1258

push

github

badlop
Container: Apply commit a22c88a

ejabberdctl.template: Show meaningful error when ERL_DIST_PORT is in use

15554 of 46240 relevant lines covered (33.64%)

1078.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.39
/src/mod_jidprep.erl
1
%%%----------------------------------------------------------------------
2
%%% File    : mod_jidprep.erl
3
%%% Author  : Holger Weiss <holger@zedat.fu-berlin.de>
4
%%% Purpose : JID Prep (XEP-0328)
5
%%% Created : 11 Sep 2019 by Holger Weiss <holger@zedat.fu-berlin.de>
6
%%%
7
%%%
8
%%% ejabberd, Copyright (C) 2019-2025 ProcessOne
9
%%%
10
%%% This program is free software; you can redistribute it and/or
11
%%% modify it under the terms of the GNU General Public License as
12
%%% published by the Free Software Foundation; either version 2 of the
13
%%% License, or (at your option) any later version.
14
%%%
15
%%% This program is distributed in the hope that it will be useful,
16
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
%%% General Public License for more details.
19
%%%
20
%%% You should have received a copy of the GNU General Public License along
21
%%% with this program; if not, write to the Free Software Foundation, Inc.,
22
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
%%%
24
%%%----------------------------------------------------------------------
25

26
-module(mod_jidprep).
27
-author('holger@zedat.fu-berlin.de').
28
-protocol({xep, 328, '0.1', '19.09', "complete", ""}).
29

30
-behaviour(gen_mod).
31

32
%% gen_mod callbacks.
33
-export([start/2, stop/1, reload/3, mod_opt_type/1, mod_options/1, depends/2]).
34
-export([mod_doc/0]).
35

36
%% ejabberd_hooks callbacks.
37
-export([disco_local_features/5]).
38

39
%% gen_iq_handler callback.
40
-export([process_iq/1]).
41

42
-include("logger.hrl").
43
-include("translate.hrl").
44
-include_lib("xmpp/include/xmpp.hrl").
45

46
%%--------------------------------------------------------------------
47
%% gen_mod callbacks.
48
%%--------------------------------------------------------------------
49
-spec start(binary(), gen_mod:opts()) -> {ok, [gen_mod:registration()]}.
50
start(_Host, _Opts) ->
51
    {ok, [{iq_handler, ejabberd_local, ?NS_JIDPREP_0, process_iq},
90✔
52
          {hook, disco_local_features, disco_local_features, 50}]}.
53

54
-spec stop(binary()) -> ok.
55
stop(_Host) ->
56
    ok.
90✔
57

58
-spec reload(binary(), gen_mod:opts(), gen_mod:opts()) -> ok.
59
reload(_Host, _NewOpts, _OldOpts) ->
60
    ok.
×
61

62
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].
63
depends(_Host, _Opts) ->
64
    [].
108✔
65

66
-spec mod_opt_type(atom()) -> econf:validator().
67
mod_opt_type(access) ->
68
    econf:acl().
108✔
69

70
-spec mod_options(binary()) -> [{atom(), any()}].
71
mod_options(_Host) ->
72
    [{access, local}].
108✔
73

74
mod_doc() ->
75
    #{desc =>
×
76
          ?T("This module allows XMPP clients to ask the "
77
             "server to normalize a JID as per the rules specified "
78
             "in https://tools.ietf.org/html/rfc6122"
79
             "[RFC 6122: XMPP Address Format]. This might be useful "
80
             "for clients in certain constrained environments, "
81
             "or for testing purposes."),
82
      opts =>
83
          [{access,
84
            #{value => ?T("AccessName"),
85
              desc =>
86
                  ?T("This option defines which access rule will "
87
                     "be used to control who is allowed to use this "
88
                     "service. The default value is 'local'.")}}]}.
89

90
%%--------------------------------------------------------------------
91
%% Service discovery.
92
%%--------------------------------------------------------------------
93
-spec disco_local_features(mod_disco:features_acc(), jid(), jid(), binary(),
94
                           binary()) -> mod_disco:features_acc().
95
disco_local_features(empty, From, To, Node, Lang) ->
96
    disco_local_features({result, []}, From, To, Node, Lang);
×
97
disco_local_features({result, OtherFeatures} = Acc, From,
98
                     #jid{lserver = LServer}, <<"">>, _Lang) ->
99
    Access = mod_jidprep_opt:access(LServer),
9✔
100
    case acl:match_rule(LServer, Access, From) of
9✔
101
        allow ->
102
            {result, [?NS_JIDPREP_0 | OtherFeatures]};
9✔
103
        deny ->
104
            Acc
×
105
    end;
106
disco_local_features(Acc, _From, _To, _Node, _Lang) ->
107
    Acc.
1✔
108

109
%%--------------------------------------------------------------------
110
%% IQ handlers.
111
%%--------------------------------------------------------------------
112
-spec process_iq(iq()) -> iq().
113
process_iq(#iq{type = set, lang = Lang} = IQ) ->
114
    Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
×
115
    xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
×
116
process_iq(#iq{from = From, to = #jid{lserver = LServer}, lang = Lang,
117
               sub_els = [#jidprep{jid = #jid{luser = U,
118
                                              lserver = S,
119
                                              lresource = R} = JID}]} = IQ) ->
120
    Access = mod_jidprep_opt:access(LServer),
1✔
121
    case acl:match_rule(LServer, Access, From) of
1✔
122
        allow ->
123
            case jid:make(U, S, R) of
1✔
124
                #jid{} = Normalized ->
125
                    ?DEBUG("Normalized JID for ~ts: ~ts",
1✔
126
                           [jid:encode(From), jid:encode(JID)]),
1✔
127
                    xmpp:make_iq_result(IQ, #jidprep{jid = Normalized});
1✔
128
                error -> % Cannot happen.
129
                    ?DEBUG("Normalizing JID failed for ~ts: ~ts",
×
130
                           [jid:encode(From), jid:encode(JID)]),
×
131
                    Txt = ?T("JID normalization failed"),
×
132
                    xmpp:make_error(IQ, xmpp:err_jid_malformed(Txt, Lang))
×
133
            end;
134
        deny ->
135
            ?DEBUG("Won't return normalized JID to ~ts: ~ts",
×
136
                   [jid:encode(From), jid:encode(JID)]),
×
137
            Txt = ?T("JID normalization denied by service policy"),
×
138
            xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang))
×
139
    end;
140
process_iq(#iq{lang = Lang} = IQ) ->
141
    Txt = ?T("No module is handling this query"),
×
142
    xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc