Class UrlUtils

java.lang.Object
com.biglybt.core.util.UrlUtils

public class UrlUtils extends Object
  • Field Details

    • patMagnetSHA1HashFinder

      private static Pattern patMagnetSHA1HashFinder
    • patMagnetMultiHashFinder

      private static Pattern patMagnetMultiHashFinder
    • prefixes

      private static final String[] prefixes
    • MAGNETURL_STARTS_AT

      private static final int MAGNETURL_STARTS_AT
      See Also:
    • XMLescapes

      private static final Object[] XMLescapes
    • last_headers

      private static String last_headers
    • default_headers

      private static final String default_headers
      See Also:
  • Constructor Details

    • UrlUtils

      public UrlUtils()
  • Method Details

    • decodeArgs

      public static Map<String,String> decodeArgs(String args)
    • getMagnetURI

      public static String getMagnetURI(byte[] hash)
    • getURLForm

      public static String getURLForm(InetSocketAddress address)
    • getURLForm

      public static String getURLForm(InetAddress address, int port)
    • getURLForm

      public static String getURLForm(String address, int port)
    • extractURLHost

      public static String extractURLHost(String str)
    • getMagnetURI

      public static String getMagnetURI(byte[] hash, String name, String[] networks)
    • getMagnetURI

      public static String getMagnetURI(byte[] hash, byte[] hash_v2, String name, String[] networks)
    • encodeName

      private static String encodeName(String name)
    • encodeNetworks

      private static String encodeNetworks(String[] networks)
    • extractNetworks

      public static Set<String> extractNetworks(String[] magnet_uri)
    • getMagnetURI

      public static String getMagnetURI(Download download)
    • getMagnetURI

      public static String getMagnetURI(Download download, int max_name_len)
    • getMagnetURI

      public static String getMagnetURI(DownloadManager dm)
    • truncateForURI

      public static String truncateForURI(String str, int max_utf8_bytes)
    • getMagnetURI

      public static String getMagnetURI(DownloadManager dm, int max_name_len)
    • getMagnetURI

      public static String getMagnetURI(TOTorrent to_torrent)
    • getMagnetURI

      public static String getMagnetURI(Torrent torrent)
    • getMagnetURI

      public static String getMagnetURI(String name, Torrent torrent)
    • getMagnetURI

      public static String getMagnetURI(String name, Torrent torrent, String[] networks)
    • addSource

      public static String addSource(Download download, String magnet, InetSocketAddress address)
    • normaliseMagnetURI

      public static String normaliseMagnetURI(String base_hash)
      returns magnet uri if input is base 32 or base 16 encoded sha1 or sha256 hash, null otherwise
      Parameters:
      base_hash -
      Returns:
    • getTruncatedHashFromMagnetURI

      public static byte[] getTruncatedHashFromMagnetURI(String magnetURI)
      decodes a sha1 or sha256 multihash from an actual magnet URI and truncates to 20 bytes
      Parameters:
      hash_str -
      Returns:
    • decodeTruncatedHashFromMagnetURI

      public static byte[] decodeTruncatedHashFromMagnetURI(String hash_str)
      decodes a sha1 or sha256 multihash as found in a magnet URI and truncates to 20 bytes
      Parameters:
      hash_str -
      Returns:
    • decodeTruncatedMultiHash

      private static byte[] decodeTruncatedMultiHash(String hash_str)
    • decodeTruncatedHash

      public static byte[] decodeTruncatedHash(String hash_str)
      Decodes a hex or base32 encoded sha1, sha256 or multihash
      Parameters:
      hash_str -
      Returns:
    • decodeSHA1Hash

      public static byte[] decodeSHA1Hash(String str)
    • decodeSHA256Hash

      private static byte[] decodeSHA256Hash(String str)
    • decodeMultiHash

      private static byte[] decodeMultiHash(String str)
    • getRawURL

      public static URL getRawURL(String url)
    • getFriendlyName

      public static String getFriendlyName(URL url, String url_str)
    • isURL

      public static boolean isURL(String sURL)
      test string for possibility that it's an URL. Considers 40 byte hex strings as URLs
      Parameters:
      sURL -
      Returns:
    • isURL

      public static boolean isURL(String sURL, boolean bGuess)
    • parseTextForURL

      public static String parseTextForURL(String text, boolean accept_magnets)
    • getURL

      public static String getURL(String text)
    • isInternalProtocol

      public static boolean isInternalProtocol(String url)
    • parseTextForURL

      public static String parseTextForURL(String text, boolean accept_magnets, boolean guess)
    • parseTextForMagnets

      public static String parseTextForMagnets(String text)
    • parseTextForMagnets

      public static String parseTextForMagnets(String text, boolean check_raw_embeded_hashes)
    • parseHTMLforURL

      private static String parseHTMLforURL(String text)
    • encode

      public static String encode(String s)
      Like URLEncoder.encode, except translates spaces into %20 instead of +
      Parameters:
      s -
      Returns:
    • decode

      public static String decode(String s)
    • decodeIfNeeded

      public static String decodeIfNeeded(String s)
      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

      public static String escapeXML(String s)
    • unescapeXML

      public static String unescapeXML(String s)
    • convertIPV6Host

      public static String convertIPV6Host(String host)
    • expandIPV6Host

      public static String expandIPV6Host(String host)
    • resolveIPv6Host

      public static String resolveIPv6Host(String url) throws Exception
      Throws:
      Exception
    • resolveIPv4Host

      public static String resolveIPv4Host(String url)
    • 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

      public static void setBrowserHeaders(ResourceDownloader rd, String referer)
    • setBrowserHeaders

      public static void setBrowserHeaders(ResourceDownloader rd, String encoded_headers, String referer)
    • setBrowserHeaders

      public static void setBrowserHeaders(ResourceUploader ru, String encoded_headers, String referer)
    • setBrowserHeaders

      public static void setBrowserHeaders(URLConnection connection, String referer)
    • setBrowserHeaders

      public static void setBrowserHeaders(URLConnection connection, String encoded_headers, String referer)
    • getBrowserHeaders

      public static Map getBrowserHeaders(String referer)
    • getBrowserHeadersToUse

      private static String getBrowserHeadersToUse(String encoded_headers)
    • queryHasParameter

      public static boolean queryHasParameter(String query_string, String param_name, boolean case_sensitive)
    • containsPasskey

      public static boolean containsPasskey(URL url)
    • setPort

      public static URL setPort(URL u, int port)
    • setHost

      public static URL setHost(URL u, String host)
    • setProtocol

      public static URL setProtocol(URL u, String protocol)
    • getBaseURL

      public static URL getBaseURL(URL u)
    • getCanonicalString

      public static String getCanonicalString(String str)
    • getCanonicalString

      public static String getCanonicalString(URL url)
    • getIPV4Fallback

      public static URL getIPV4Fallback(URL url)
      Returns an explicit IPv4 url if the supplied one has both IPv6 and IPv4 addresses
      Parameters:
      url -
      Returns:
    • getContentLength

      public static long getContentLength(URLConnection con)
    • SSLSocketSNIHack

      public static boolean SSLSocketSNIHack(String host_name, SSLSocket socket)
    • DHHackIt

      public static SSLSocketFactory DHHackIt(SSLSocketFactory factory)
    • HTTPSURLConnectionSNIHack

      public static void HTTPSURLConnectionSNIHack(String host_name, HttpsURLConnection con)
    • DHHackIt

      public static void DHHackIt(HttpsURLConnection ssl_con)
    • 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

      public static List<InetSocketAddress> getURLAddresses(URL url)