Package com.biglybt.core.util
Class UrlUtils
java.lang.Object
com.biglybt.core.util.UrlUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
addSource
(Download download, String magnet, InetSocketAddress address) static Socket
connectSocketAndWrite
(boolean is_ssl, String target_host, int target_port, byte[] bytes, int connect_timeout, int read_timeout) static Socket
connectSocketAndWrite
(boolean is_ssl, String target_host, int target_port, byte[] bytes, int connect_timeout, int read_timeout, boolean unconnected_socket_hack) static Socket
connectSocketAndWrite
(boolean is_ssl, String target_host_name, InetAddress bind_ip, InetAddress target_host, int target_port, byte[] bytes, int connect_timeout, int read_timeout, boolean unconnected_socket_hack) static void
connectWithTimeout
(URLConnection connection, long connect_timeout) static void
connectWithTimeouts
(URLConnection connection, long connect_timeout, long read_timeout) static boolean
containsPasskey
(URL url) static String
convertIPV6Host
(String host) static String
decodeArgs
(String args) static String
Unfortunately we have code that mindlessly decoded URLs (FileDownloadWindow) which borked (in the case I discovered) magnet uris with encoded parameters (e.g.private static byte[]
decodeMultiHash
(String str) static byte[]
decodeSHA1Hash
(String str) private static byte[]
decodeSHA256Hash
(String str) static byte[]
decodeTruncatedHash
(String hash_str) Decodes a hex or base32 encoded sha1, sha256 or multihashstatic byte[]
decodeTruncatedHashFromMagnetURI
(String hash_str) decodes a sha1 or sha256 multihash as found in a magnet URI and truncates to 20 bytesprivate static byte[]
decodeTruncatedMultiHash
(String hash_str) static void
DHHackIt
(HttpsURLConnection ssl_con) static SSLSocketFactory
DHHackIt
(SSLSocketFactory factory) static String
Like URLEncoder.encode, except translates spaces into %20 instead of +private static String
encodeName
(String name) private static String
encodeNetworks
(String[] networks) static String
static String
expandIPV6Host
(String host) extractNetworks
(String[] magnet_uri) static String
extractURLHost
(String str) static URL
getBaseURL
(URL u) static Map
getBrowserHeaders
(String referer) private static String
getBrowserHeadersToUse
(String encoded_headers) static String
getCanonicalString
(String str) static String
getCanonicalString
(URL url) static long
static String
getFriendlyName
(URL url, String url_str) static URL
getIPV4Fallback
(URL url) Returns an explicit IPv4 url if the supplied one has both IPv6 and IPv4 addressesstatic String
getMagnetURI
(byte[] hash) static String
getMagnetURI
(byte[] hash, byte[] hash_v2, String name, String[] networks) static String
getMagnetURI
(byte[] hash, String name, String[] networks) static String
static String
getMagnetURI
(DownloadManager dm, int max_name_len) static String
getMagnetURI
(TOTorrent to_torrent) static String
getMagnetURI
(Download download) static String
getMagnetURI
(Download download, int max_name_len) static String
getMagnetURI
(Torrent torrent) static String
getMagnetURI
(String name, Torrent torrent) static String
getMagnetURI
(String name, Torrent torrent, String[] networks) static URL
static byte[]
getTruncatedHashFromMagnetURI
(String magnetURI) decodes a sha1 or sha256 multihash from an actual magnet URI and truncates to 20 bytesstatic String
static List
<InetSocketAddress> getURLAddresses
(URL url) static String
getURLForm
(String address, int port) static String
getURLForm
(InetAddress address, int port) static String
getURLForm
(InetSocketAddress address) static void
HTTPSURLConnectionSNIHack
(String host_name, HttpsURLConnection con) static boolean
isInternalProtocol
(String url) static boolean
test string for possibility that it's an URL.static boolean
static String
normaliseMagnetURI
(String base_hash) returns magnet uri if input is base 32 or base 16 encoded sha1 or sha256 hash, null otherwiseprivate static String
parseHTMLforURL
(String text) static String
parseTextForMagnets
(String text) static String
parseTextForMagnets
(String text, boolean check_raw_embeded_hashes) static String
parseTextForURL
(String text, boolean accept_magnets) static String
parseTextForURL
(String text, boolean accept_magnets, boolean guess) static boolean
queryHasParameter
(String query_string, String param_name, boolean case_sensitive) static String
resolveIPv4Host
(String url) static String
resolveIPv6Host
(String url) static void
setBrowserHeaders
(ResourceDownloader rd, String referer) static void
setBrowserHeaders
(ResourceDownloader rd, String encoded_headers, String referer) static void
setBrowserHeaders
(ResourceUploader ru, String encoded_headers, String referer) static void
setBrowserHeaders
(URLConnection connection, String referer) static void
setBrowserHeaders
(URLConnection connection, String encoded_headers, String referer) static URL
static URL
static URL
setProtocol
(URL u, String protocol) static boolean
SSLSocketSNIHack
(String host_name, SSLSocket socket) static String
truncateForURI
(String str, int max_utf8_bytes) static String
-
Field Details
-
patMagnetSHA1HashFinder
-
patMagnetMultiHashFinder
-
prefixes
-
MAGNETURL_STARTS_AT
private static final int MAGNETURL_STARTS_AT- See Also:
-
XMLescapes
-
last_headers
-
default_headers
- See Also:
-
-
Constructor Details
-
UrlUtils
public UrlUtils()
-
-
Method Details
-
decodeArgs
-
getMagnetURI
-
getURLForm
-
getURLForm
-
getURLForm
-
extractURLHost
-
getMagnetURI
-
getMagnetURI
-
encodeName
-
encodeNetworks
-
extractNetworks
-
getMagnetURI
-
getMagnetURI
-
getMagnetURI
-
truncateForURI
-
getMagnetURI
-
getMagnetURI
-
getMagnetURI
-
getMagnetURI
-
getMagnetURI
-
addSource
-
normaliseMagnetURI
returns magnet uri if input is base 32 or base 16 encoded sha1 or sha256 hash, null otherwise- Parameters:
base_hash
-- Returns:
-
getTruncatedHashFromMagnetURI
decodes a sha1 or sha256 multihash from an actual magnet URI and truncates to 20 bytes- Parameters:
hash_str
-- Returns:
-
decodeTruncatedHashFromMagnetURI
decodes a sha1 or sha256 multihash as found in a magnet URI and truncates to 20 bytes- Parameters:
hash_str
-- Returns:
-
decodeTruncatedMultiHash
-
decodeTruncatedHash
Decodes a hex or base32 encoded sha1, sha256 or multihash- Parameters:
hash_str
-- Returns:
-
decodeSHA1Hash
-
decodeSHA256Hash
-
decodeMultiHash
-
getRawURL
-
getFriendlyName
-
isURL
test string for possibility that it's an URL. Considers 40 byte hex strings as URLs- Parameters:
sURL
-- Returns:
-
isURL
-
parseTextForURL
-
getURL
-
isInternalProtocol
-
parseTextForURL
-
parseTextForMagnets
-
parseTextForMagnets
-
parseHTMLforURL
-
encode
Like URLEncoder.encode, except translates spaces into %20 instead of +- Parameters:
s
-- Returns:
-
decode
-
decodeIfNeeded
Unfortunately we have code that mindlessly decoded URLs (FileDownloadWindow) which borked (in the case I discovered) magnet uris with encoded parameters (e.g. the invalid input: '&tr'= parameter) - doing so screws stuff up later if, for example, the parameter included an encoded 'invalid input: '&''- Parameters:
s
-- Returns:
-
escapeXML
-
unescapeXML
-
convertIPV6Host
-
expandIPV6Host
-
resolveIPv6Host
- Throws:
Exception
-
resolveIPv4Host
-
connectWithTimeout
public static void connectWithTimeout(URLConnection connection, long connect_timeout) throws IOException - Throws:
IOException
-
connectWithTimeouts
public static void connectWithTimeouts(URLConnection connection, long connect_timeout, long read_timeout) throws IOException - Throws:
IOException
-
setBrowserHeaders
-
setBrowserHeaders
-
setBrowserHeaders
-
setBrowserHeaders
-
setBrowserHeaders
public static void setBrowserHeaders(URLConnection connection, String encoded_headers, String referer) -
getBrowserHeaders
-
getBrowserHeadersToUse
-
queryHasParameter
-
containsPasskey
-
setPort
-
setHost
-
setProtocol
-
getBaseURL
-
getCanonicalString
-
getCanonicalString
-
getIPV4Fallback
Returns an explicit IPv4 url if the supplied one has both IPv6 and IPv4 addresses- Parameters:
url
-- Returns:
-
getContentLength
-
SSLSocketSNIHack
-
DHHackIt
-
HTTPSURLConnectionSNIHack
-
DHHackIt
-
connectSocketAndWrite
public static Socket connectSocketAndWrite(boolean is_ssl, String target_host, int target_port, byte[] bytes, int connect_timeout, int read_timeout) throws Throwable - Throws:
Throwable
-
connectSocketAndWrite
public static Socket connectSocketAndWrite(boolean is_ssl, String target_host, int target_port, byte[] bytes, int connect_timeout, int read_timeout, boolean unconnected_socket_hack) throws Throwable - Throws:
Throwable
-
connectSocketAndWrite
public static Socket connectSocketAndWrite(boolean is_ssl, String target_host_name, InetAddress bind_ip, InetAddress target_host, int target_port, byte[] bytes, int connect_timeout, int read_timeout, boolean unconnected_socket_hack) throws Throwable - Throws:
Throwable
-
getURLAddresses
-