New upstream version 1.6.1
Philipp Huebner
1 year, 3 months ago
0 | # Version 1.6.1 | |
1 | ||
2 | * Apply change introduced in XEP-0060 Version 1.23.0 | |
3 | * Use net:getaddrinfo for hostname resolution | |
4 | ||
0 | 5 | # Version 1.6.0 |
1 | 6 | |
2 | 7 | * Updating fast_tls to version 1.1.16. |
5 | 5 | %%% Created : 10 Jul 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%---------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
5 | 5 | %%% Created : 10 Dec 2015 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
2 | 2 | %%% Author : Evgeniy Khramtsov <ekhramtsov@process-one.net> |
3 | 3 | %%% Purpose : Rebar build script. Compliant with rebar and rebar3. |
4 | 4 | %%% |
5 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
5 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
6 | 6 | %%% |
7 | 7 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | %%% you may not use this file except in compliance with the License. |
20 | 20 | |
21 | 21 | {erl_opts, [debug_info, {src_dirs, ["asn1", "src"]}, |
22 | 22 | nowarn_export_all, |
23 | {platform_define, "^(R|1|20|21|22)", 'USE_OLD_CRYPTO_HMAC'}, | |
23 | {platform_define, "^(R|1|2[012])", 'USE_OLD_CRYPTO_HMAC'}, | |
24 | {platform_define, "^(R|1|2[01])", 'USE_GETHOSTBYNAME'}, | |
25 | {platform_define, "^(R|1|2[0123]|24\.[012])", 'USE_ADDRPORTCONNECT'}, | |
24 | 26 | {i, "include"}]}. |
25 | 27 | |
26 | 28 | {port_env, [{"ERL_LDFLAGS", " -L$ERL_EI_LIBDIR -lei"}, |
3 | 3 | %%% Purpose : Rebar build script. Compliant with rebar and rebar3. |
4 | 4 | %%% Created : 24 Nov 2015 by Mickael Remond <mremond@process-one.net> |
5 | 5 | %%% |
6 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
6 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
7 | 7 | %%% |
8 | 8 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
9 | 9 | %%% you may not use this file except in compliance with the License. |
30 | 30 | label='The name of the node'/> |
31 | 31 | <field var='pubsub#type' |
32 | 32 | type='text-single' |
33 | label='Payload type'/> | |
33 | label='Payload semantic type information'/> | |
34 | 34 | <field var='pubsub#max_items' |
35 | 35 | type='text-single' |
36 | 36 | label='Maximum number of items to persist'/> |
177 | 177 | label='A friendly name for the node'/> |
178 | 178 | <field var='pubsub#type' |
179 | 179 | type='text-single' |
180 | label='The type of node data, usually specified by | |
181 | the namespace of the payload (if any)'/> | |
180 | label='The semantic type information of data in the node, usually specified | |
181 | by the namespace of the payload (if any)'/> | |
182 | 182 | </form_type> |
183 | 183 | |
184 | 184 | <!-- |
5 | 5 | %%% Created : 24 Nov 2015 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
855 | 855 | #xdata_field{var = <<"pubsub#type">>, values = Values, |
856 | 856 | required = IsRequired, type = 'text-single', |
857 | 857 | options = Opts, desc = <<>>, |
858 | label = xmpp_tr:tr(Lang, ?T("Payload type"))}. | |
858 | label = | |
859 | xmpp_tr:tr(Lang, | |
860 | ?T("Payload semantic type information"))}. | |
859 | 861 | |
860 | 862 | -spec encode_max_items(xmpp_util:limit() | undefined, |
861 | 863 | binary(), boolean()) -> xdata_field(). |
2213 | 2213 | options = Opts, desc = <<>>, |
2214 | 2214 | label = |
2215 | 2215 | xmpp_tr:tr(Lang, |
2216 | ?T("The type of node data, usually specified " | |
2217 | "by the namespace of the payload (if " | |
2218 | "any)"))}. | |
2216 | ?T("The semantic type information of data " | |
2217 | "in the node, usually specified by the " | |
2218 | "namespace of the payload (if any)"))}. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% @author Stephen Röttger <stephen.roettger@googlemail.com> |
2 | 2 | %%% |
3 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
3 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
4 | 4 | %%% |
5 | 5 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
6 | 6 | %%% you may not use this file except in compliance with the License. |
4 | 4 | %%% @end |
5 | 5 | %%% |
6 | 6 | %%% |
7 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
7 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
8 | 8 | %%% |
9 | 9 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
10 | 10 | %%% you may not use this file except in compliance with the License. |
5 | 5 | %%% Created : 18 Nov 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
23 | 23 | |
24 | 24 | {application, xmpp, |
25 | 25 | [{description, "Erlang/Elixir XMPP parsing and serialization library"}, |
26 | {vsn, "1.6.0"}, | |
26 | {vsn, "1.6.1"}, | |
27 | 27 | {modules, []}, |
28 | 28 | {registered, []}, |
29 | 29 | {applications, [kernel, stdlib, ezlib, fast_tls, fast_xml, idna, p1_utils, stringprep]}, |
5 | 5 | %%% Created : 9 Dec 2015 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
1 | 1 | %%% @author Evgeny Khramtsov <ekhramtsov@process-one.net> |
2 | 2 | %%% |
3 | 3 | %%% |
4 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
4 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
5 | 5 | %%% |
6 | 6 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | %%% you may not use this file except in compliance with the License. |
5 | 5 | %%% Created : 30 May 2018 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% @author Magnus Henoch <henoch@dtek.chalmers.se> |
2 | 2 | %%% |
3 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
3 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
4 | 4 | %%% |
5 | 5 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
6 | 6 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% @author Stephen Röttger <stephen.roettger@googlemail.com> |
2 | 2 | %%% |
3 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
3 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
4 | 4 | %%% |
5 | 5 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
6 | 6 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
121 | 121 | connect(Addr, Port, Opts, Timeout, self()). |
122 | 122 | |
123 | 123 | connect(Addr, Port, Opts, Timeout, Owner) -> |
124 | case gen_tcp:connect(Addr, Port, Opts, Timeout) of | |
124 | case do_connect(Addr, Port, Opts, Timeout) of | |
125 | 125 | {ok, Socket} -> |
126 | 126 | SocketData = new(gen_tcp, Socket, []), |
127 | 127 | case controlling_process(SocketData, Owner) of |
135 | 135 | {error, _Reason} = Error -> |
136 | 136 | Error |
137 | 137 | end. |
138 | ||
139 | -ifndef(USE_ADDRPORTCONNECT). | |
140 | do_connect(Addr, Port, Opts, Timeout) | |
141 | when is_tuple(Addr) orelse | |
142 | is_list(Addr) orelse | |
143 | is_atom(Addr) orelse | |
144 | (Addr =:= any) orelse | |
145 | (Addr =:= loopback) -> | |
146 | gen_tcp:connect(Addr, Port, Opts, Timeout); | |
147 | do_connect(SockAddr, _Port, Opts, Timeout) -> | |
148 | gen_tcp:connect(SockAddr, Opts, Timeout). | |
149 | -else. | |
150 | do_connect(Addr, Port, Opts, Timeout) | |
151 | when is_tuple(Addr) orelse | |
152 | is_list(Addr) orelse | |
153 | is_atom(Addr) orelse | |
154 | (Addr =:= any) orelse | |
155 | (Addr =:= loopback) -> | |
156 | gen_tcp:connect(Addr, Port, Opts, Timeout); | |
157 | do_connect(SockAddr, _Port, Opts, Timeout) -> | |
158 | #{addr := Addr, port := Port} = SockAddr, | |
159 | gen_tcp:connect(Addr, Port, Opts, Timeout). | |
160 | -endif. | |
138 | 161 | |
139 | 162 | -spec starttls(socket_state(), [proplists:property()]) -> |
140 | 163 | {ok, socket_state()} | |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
84 | 84 | -type next_state() :: noreply() | {stop, term(), state()}. |
85 | 85 | -type host_port() :: {inet:hostname(), inet:port_number(), boolean()} | ip_port(). |
86 | 86 | -type ip_port() :: {inet:ip_address(), inet:port_number(), boolean()}. |
87 | -type addr_info() :: {net:address_info(), boolean()}. | |
87 | 88 | -type h_addr_list() :: [{{integer(), integer(), inet:port_number(), string()}, boolean()}]. |
88 | 89 | -type network_error() :: {error, inet:posix() | atom()}. |
89 | 90 | -type tls_error_reason() :: inet:posix() | atom() | binary(). |
1145 | 1146 | end |
1146 | 1147 | end. |
1147 | 1148 | |
1148 | -spec resolve(string(), state()) -> {ok, [ip_port()]} | network_error(). | |
1149 | -spec resolve(string(), state()) -> {ok, [ip_port()]} | {ok, [addr_info()]} | network_error(). | |
1149 | 1150 | resolve(Host, State) -> |
1150 | 1151 | try callback(resolve, Host, State) of |
1151 | 1152 | [] -> |
1156 | 1157 | do_resolve(Host, State) |
1157 | 1158 | end. |
1158 | 1159 | |
1159 | -spec do_resolve(string(), state()) -> {ok, [ip_port()]} | network_error(). | |
1160 | -spec do_resolve(string(), state()) -> {ok, [ip_port()]} | {ok, [addr_info()]} | network_error(). | |
1160 | 1161 | do_resolve(Host, State) -> |
1161 | 1162 | case srv_lookup(Host, State) of |
1162 | 1163 | {error, _Reason} -> |
1236 | 1237 | {error, nxdomain} |
1237 | 1238 | end. |
1238 | 1239 | |
1240 | ||
1241 | -ifndef(USE_GETHOSTBYNAME). | |
1242 | % New getaddrinfo based lookups (getaddrinfo available in OTP 22, but connect(SockAddr, ...) introduced in OTP 24.3) | |
1243 | -spec a_lookup([host_port()], state()) -> | |
1244 | {ok, [addr_info()]} | network_error(). | |
1245 | a_lookup(HostPorts, State) -> | |
1246 | a_lookup(HostPorts, State, [], {error, nxdomain}). | |
1247 | ||
1248 | -spec a_lookup([{inet:hostname() | inet:ip_address(), inet:port_number(), | |
1249 | boolean()}], | |
1250 | state(), [addr_info()], network_error()) -> {ok, [addr_info()]} | network_error(). | |
1251 | a_lookup([{Addr, Port, TLS}|HostPorts], State, Acc, Err) | |
1252 | when is_tuple(Addr) -> | |
1253 | a_lookup([{inet:ntoa(Addr), Port, TLS}|HostPorts], State, Acc, Err); | |
1254 | a_lookup([{Host, Port, TLS}|HostPorts], State, Acc, Err) -> | |
1255 | Retries = get_dns_retries(State), | |
1256 | case a_lookup(Host, Port, TLS, State, Retries) of | |
1257 | {error, Reason} -> | |
1258 | a_lookup(HostPorts, State, Acc, {error, Reason}); | |
1259 | {ok, AddrPorts} -> | |
1260 | a_lookup(HostPorts, State, Acc ++ AddrPorts, Err) | |
1261 | end; | |
1262 | a_lookup([], _State, [], Err) -> | |
1263 | Err; | |
1264 | a_lookup([], _State, Acc, _) -> | |
1265 | {ok, Acc}. | |
1266 | ||
1267 | -spec a_lookup(inet:hostname(), inet:port_number(), boolean(), | |
1268 | state(), integer()) -> {ok, [addr_info()]} | network_error(). | |
1269 | a_lookup(_Host, _Port, _TLS, _State, Retries) when Retries < 1 -> | |
1270 | {error, timeout}; | |
1271 | a_lookup(Host, Port, TLS, State, Retries) -> | |
1272 | Timeout = get_dns_timeout(State), | |
1273 | Start = current_time(), | |
1274 | case net:getaddrinfo(Host, integer_to_list(Port)) of | |
1275 | {error, nxdomain} = Err -> | |
1276 | %% net:getaddrinfo/2 doesn't return {error, timeout}, | |
1277 | %% so we should check if 'nxdomain' is in fact a result | |
1278 | %% of a timeout. | |
1279 | End = current_time(), | |
1280 | if (End - Start) >= Timeout -> | |
1281 | a_lookup(Host, Port, TLS, State, Retries - 1); | |
1282 | true -> | |
1283 | Err | |
1284 | end; | |
1285 | {error, _} = Err -> | |
1286 | Err; | |
1287 | {ok, AddressInfos} -> | |
1288 | FilteredAddressInfos = [{Addr, TLSVal} || #{protocol := Protocol} = Addr <- AddressInfos, TLSVal <- [TLS], Protocol == tcp], | |
1289 | {ok, FilteredAddressInfos} | |
1290 | end. | |
1291 | ||
1292 | -else. | |
1293 | % Old gethostbyname lookups | |
1239 | 1294 | -spec a_lookup([host_port()], state()) -> |
1240 | 1295 | {ok, [ip_port()]} | network_error(). |
1241 | 1296 | a_lookup(HostPorts, State) -> |
1296 | 1351 | host_entry_to_addr_ports(HostEntry, Port, TLS) |
1297 | 1352 | end. |
1298 | 1353 | |
1354 | -spec host_entry_to_addr_ports(inet:hostent(), inet:port_number(), boolean()) -> | |
1355 | {ok, [ip_port()]} | {error, nxdomain}. | |
1356 | host_entry_to_addr_ports(#hostent{h_addr_list = AddrList}, Port, TLS) -> | |
1357 | AddrPorts = lists:flatmap( | |
1358 | fun(Addr) -> | |
1359 | try get_addr_type(Addr) of | |
1360 | _ -> [{Addr, Port, TLS}] | |
1361 | catch _:_ -> | |
1362 | [] | |
1363 | end | |
1364 | end, AddrList), | |
1365 | case AddrPorts of | |
1366 | [] -> {error, nxdomain}; | |
1367 | _ -> {ok, AddrPorts} | |
1368 | end. | |
1369 | -endif. | |
1370 | ||
1299 | 1371 | -spec h_addr_list_to_host_ports(h_addr_list()) -> {ok, [host_port(),...]} | |
1300 | 1372 | {error, nxdomain}. |
1301 | 1373 | h_addr_list_to_host_ports(AddrList) -> |
1316 | 1388 | _ -> {ok, HostPorts} |
1317 | 1389 | end. |
1318 | 1390 | |
1319 | -spec host_entry_to_addr_ports(inet:hostent(), inet:port_number(), boolean()) -> | |
1320 | {ok, [ip_port()]} | {error, nxdomain}. | |
1321 | host_entry_to_addr_ports(#hostent{h_addr_list = AddrList}, Port, TLS) -> | |
1322 | AddrPorts = lists:flatmap( | |
1323 | fun(Addr) -> | |
1324 | try get_addr_type(Addr) of | |
1325 | _ -> [{Addr, Port, TLS}] | |
1326 | catch _:_ -> | |
1327 | [] | |
1328 | end | |
1329 | end, AddrList), | |
1330 | case AddrPorts of | |
1331 | [] -> {error, nxdomain}; | |
1332 | _ -> {ok, AddrPorts} | |
1333 | end. | |
1334 | ||
1335 | -spec connect([ip_port()], state()) -> {ok, term(), ip_port()} | | |
1391 | -spec connect([ip_port() | addr_info()], state()) -> {ok, term(), ip_port()} | | |
1336 | 1392 | {error, {socket, socket_error_reason()}} | |
1337 | 1393 | {error, {tls, tls_error_reason()}}. |
1338 | 1394 | connect(AddrPorts, State) -> |
1348 | 1404 | {error, {socket, Why}} |
1349 | 1405 | end. |
1350 | 1406 | |
1407 | -ifndef(USE_GETHOSTBYNAME). | |
1408 | -spec connect([addr_info()], state(), network_error()) -> | |
1409 | {ok, term(), ip_port()} | network_error(). | |
1410 | connect([{#{family := Type, addr := SockAddr}, TLS}|AddressInfos], State, _) -> | |
1411 | #{addr := Addr, port := Port} = SockAddr, | |
1412 | Opts = [binary, {packet, 0}, | |
1413 | {send_timeout, ?TCP_SEND_TIMEOUT}, | |
1414 | {send_timeout_close, true}, | |
1415 | {active, false}, Type], | |
1416 | Opts1 = try callback(connect_options, Addr, Opts, State) | |
1417 | catch _:{?MODULE, undef} -> Opts | |
1418 | end, | |
1419 | Timeout = get_connect_timeout(State), | |
1420 | try xmpp_socket:connect(SockAddr, Port, Opts1, Timeout) of | |
1421 | {ok, Socket} -> | |
1422 | {ok, Socket, {Addr, Port, TLS}}; | |
1423 | Err -> | |
1424 | connect(AddressInfos, State, Err) | |
1425 | catch _:badarg -> | |
1426 | connect(AddressInfos, State, {error, einval}) | |
1427 | end; | |
1428 | connect([], _State, Err) -> | |
1429 | Err. | |
1430 | -else. | |
1351 | 1431 | -spec connect([ip_port()], state(), network_error()) -> |
1352 | 1432 | {ok, term(), ip_port()} | network_error(). |
1353 | 1433 | connect([{Addr, Port, TLS}|AddrPorts], State, _) -> |
1374 | 1454 | -spec get_addr_type(inet:ip_address()) -> inet:address_family(). |
1375 | 1455 | get_addr_type({_, _, _, _}) -> inet; |
1376 | 1456 | get_addr_type({_, _, _, _, _, _, _, _}) -> inet6. |
1457 | -endif. | |
1377 | 1458 | |
1378 | 1459 | -spec get_dns_timeout(state()) -> timeout(). |
1379 | 1460 | get_dns_timeout(State) -> |
1395 | 1476 | _:{?MODULE, undef} when NS == ?NS_CLIENT -> 5222 |
1396 | 1477 | end. |
1397 | 1478 | |
1479 | -ifdef(USE_GETHOSTBYNAME). | |
1398 | 1480 | -spec get_address_families(state()) -> [inet:address_family()]. |
1399 | 1481 | get_address_families(State) -> |
1400 | 1482 | try callback(address_families, State) |
1401 | 1483 | catch _:{?MODULE, undef} -> [inet, inet6] |
1402 | 1484 | end. |
1485 | -endif. | |
1403 | 1486 | |
1404 | 1487 | -spec get_connect_timeout(state()) -> timeout(). |
1405 | 1488 | get_connect_timeout(State) -> |
0 | 0 | %%%------------------------------------------------------------------- |
1 | 1 | %%% |
2 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
2 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
3 | 3 | %%% |
4 | 4 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | %%% you may not use this file except in compliance with the License. |
5 | 5 | %%% Created : 3 Mar 2018 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
5 | 5 | %%% Created : 17 Mar 2017 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
5 | 5 | %%% Created : 27 Nov 2017 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |
5 | 5 | %%% Created : 12 Jul 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net> |
6 | 6 | %%% |
7 | 7 | %%% |
8 | %%% Copyright (C) 2002-2022 ProcessOne, SARL. All Rights Reserved. | |
8 | %%% Copyright (C) 2002-2023 ProcessOne, SARL. All Rights Reserved. | |
9 | 9 | %%% |
10 | 10 | %%% Licensed under the Apache License, Version 2.0 (the "License"); |
11 | 11 | %%% you may not use this file except in compliance with the License. |