Skip to content

Commit 39e77ad

Browse files
authored
Merge pull request #1 from badlop/fix-unified
Several fixes for compilation, dialyzer, documentation and "make options"
2 parents 2e0594c + 33ea9e0 commit 39e77ad

File tree

2 files changed

+21
-50
lines changed

2 files changed

+21
-50
lines changed

mod_unified_push/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# mod_unified_push - Conversations-compatible UnifiedPush push server implementation
1+
# mod_unified_push - Conversations-compatible UnifiedPush push server implementation
22

33
- Author: itd (https://codeberg.org/itd)
44
- Copyright (C) 2025 itd
55

66
This module adds Unified Push support compatible with Conversations.
77

8-
To interact with the custom IQ stanzas, this project includes code generated with the xmpp library [0] using the steps outlined in [1].
9-
See `xmpp_spec.patch` for details on the spec update.
10-
11-
[0]: https://github.com/processone/xmpp
12-
[1]: https://github.com/processone/xmpp/issues/9#issue-205855303
8+
ejabberd newer than 25.04 is required,
9+
as it requires an updated version of the
10+
[xmpp erlang library](https://github.com/processone/xmpp)
11+
that includes the improvements from the file `xmpp_spec.patch`.
12+
Or you can
13+
[apply the patch yourself](https://github.com/processone/xmpp/issues/9#issue-205855303)
1314

1415
## Configuration
1516

mod_unified_push/src/mod_unified_push.erl

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,7 @@
5656
%% IQ handler
5757
-export([iq_handler/1]).
5858

59-
%% Exports for XMPP-generated code
60-
-export([
61-
do_decode/4,
62-
tags/0,
63-
do_encode/2,
64-
do_get_name/1,
65-
do_get_ns/1,
66-
pp/2,
67-
records/0,
68-
decode_unified_push_register/3,
69-
decode_unified_push_register_attrs/4,
70-
encode_unified_push_register/2,
71-
decode_unified_push_register_attr_application/2,
72-
decode_unified_push_register_attr_instance/2
73-
]).
59+
-type ttl_timeout() :: undefined | non_neg_integer().
7460

7561
%% API subpaths
7662
-define(ENDPOINT_PUSH, "push").
@@ -84,7 +70,7 @@
8470
-define(UP_INSTANCE, <<"i">>).
8571

8672
%% called by ejabberd_http
87-
-spec process([binary()], http_request()) -> {integer(), [{binary(), binary()}], binary()}.
73+
-spec process([binary()], http_request()) -> {integer(), [{binary(), binary()}], [binary()]}.
8874
process(_LocalPath, #request{method = 'POST', data = <<>>}) ->
8975
?DEBUG("bad POST request for ~p: no data", [_LocalPath]),
9076
{400, [], []};
@@ -99,28 +85,28 @@ process([], #request{method = 'GET'}) ->
9985
[
10086
{<<"Content-Type">>, <<"application/json">>}
10187
],
102-
["{\"unifiedpush\":{\"version\":1}}"]};
88+
[<<"{\"unifiedpush\":{\"version\":1}}">>]};
10389
process([<<?ENDPOINT_MESSAGE>> | _], _Request) ->
10490
%% RFC8030: 6.2.
10591
{410, [], []};
10692
process(_LocalPath, _Request) ->
10793
?DEBUG("bad request for ~p: ~p", [_LocalPath, _Request]),
10894
{400, [], []}.
10995

110-
-spec get_ttl([{atom(), binary()}]) -> integer().
96+
-spec get_ttl([{atom(), binary()}]) -> ttl_timeout().
11197
get_ttl(Headers) ->
11298
try string:to_integer(proplists:get_value(<<"Ttl">>, Headers, "1")) of
113-
{T, <<>>} -> T;
114-
{_, _} -> -1
99+
{T, <<>>} when T >= 0 -> T;
100+
{_, _} -> undefined
115101
catch
116102
_:_ ->
117103
%% assume illegal behavior
118-
-1
104+
undefined
119105
end.
120106

121-
-spec validate_request(binary(), binary(), binary(), binary(), integer()) ->
122-
{integer(), [{binary(), binary()}], binary()}.
123-
validate_request(_Host, _Jwk, _MaybeJwtToken, _Data, Ttl) when Ttl < 0 ->
107+
-spec validate_request(binary(), any(), binary(), binary(), ttl_timeout()) ->
108+
{integer(), [{binary(), binary()}], []}.
109+
validate_request(_Host, _Jwk, _MaybeJwtToken, _Data, undefined) ->
124110
{400, [], []};
125111
validate_request(Host, Jwk, MaybeJwtToken, Data, Ttl) when Data =/= <<"">> ->
126112
?DEBUG("verifying jwt validity", []),
@@ -156,8 +142,8 @@ validate_request(Host, Jwk, MaybeJwtToken, Data, Ttl) when Data =/= <<"">> ->
156142
validate_request(_Host, _Jwk, _MaybeJwtToken, _Data, _Ttl) ->
157143
{400, [], []}.
158144

159-
-spec forward_push_message(binary(), binary(), binary(), integer(), map()) ->
160-
{integer(), [{binary(), binary()}], binary()}.
145+
-spec forward_push_message(binary(), binary(), binary(), ttl_timeout(), map()) ->
146+
{integer(), [{binary(), binary()}], []}.
161147
forward_push_message(Host, Jwt, Data, Ttl, #{
162148
?UP_APPLICATION := Application, ?UP_INSTANCE := Instance, ?UP_OWNER := To
163149
}) ->
@@ -179,6 +165,7 @@ forward_push_message(Host, Jwt, Data, Ttl, #{
179165
?DEBUG("~p: IQ callback: ~p", [?MODULE, _Res]),
180166
ok
181167
end,
168+
undefined,
182169
Ttl
183170
),
184171
UrlPrefix = misc:expand_keyword(<<"@HOST@">>, guess_url_prefix(any), Host),
@@ -250,7 +237,7 @@ get_jwk(Host) ->
250237
-spec mod_opt_type(atom()) -> econf:validator().
251238
mod_opt_type(expiration) ->
252239
%% TODO is there an upper bound for the validity of the JWT token?
253-
econf:int(0, 60 * 60 * 24);
240+
econf:int(0, 86400); %% 60 * 60 * 24
254241
mod_opt_type(jwk) ->
255242
econf:map(econf:binary(), econf:either(econf:binary(), econf:int())).
256243

@@ -334,20 +321,3 @@ mod_doc() ->
334321
" jwk: {\"k\" => \"a4-...\",\"kty\" => \"oct\"}"
335322
]
336323
}.
337-
338-
%% FIXME The following lines add support for the custom IQ stanza.
339-
%% If possible they should be moved to the xmpp package.
340-
%% Created automatically by XML generator (fxml_gen.erl)
341-
%% Source: xmpp_codec.spec
342-
343-
do_decode(
344-
<<"push">>,
345-
<<"http://gultsch.de/xmpp/drafts/unified-push">>,
346-
El,
347-
Opts
348-
) ->
349-
decode_unified_push_push(
350-
<<"http://gultsch.de/xmpp/drafts/unified-push">>,
351-
Opts,
352-
El
353-
);

0 commit comments

Comments
 (0)