org.gudy.azureus2.core3.util
Class UrlUtils

java.lang.Object
  extended by org.gudy.azureus2.core3.util.UrlUtils

public class UrlUtils
extends Object

Author:
TuxPaper

Constructor Summary
UrlUtils()
           
 
Method Summary
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 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 decode(String s)
           
static Map<String,String> decodeArgs(String args)
           
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.
static byte[] decodeSHA1Hash(String str)
           
static void DHHackIt(HttpsURLConnection ssl_con)
           
static SSLSocketFactory DHHackIt(SSLSocketFactory factory)
           
static String encode(String s)
          Like URLEncoder.encode, except translates spaces into %20 instead of +
static String escapeXML(String s)
           
static String expandIPV6Host(String host)
           
static byte[] extractHash(String magnet_uri)
           
static Set<String> extractNetworks(String[] magnet_uri)
           
static URL getBaseURL(URL u)
           
static Map getBrowserHeaders(String referer)
           
static String getCanonicalString(URL url)
           
static long getContentLength(URLConnection con)
           
static byte[] getHashFromMagnetURI(String magnetURI)
           
static URL getIPV4Fallback(URL url)
          Returns an explicit IPv4 url if the supplied one has both IPv6 and IPv4 addresses
static String getMagnetURI(byte[] hash)
           
static String getMagnetURI(byte[] hash, String name, String[] networks)
           
static String getMagnetURI(Download download)
           
static String getMagnetURI(Download download, int max_name_len)
           
static String getMagnetURI(DownloadManager dm)
           
static String getMagnetURI(DownloadManager dm, int max_name_len)
           
static String getMagnetURI(String name, Torrent torrent)
           
static String getURL(String text)
           
static void HTTPSURLConnectionSNIHack(String host_name, HttpsURLConnection con)
           
static boolean isInternalProtocol(String url)
           
static boolean isURL(String sURL)
          test string for possibility that it's an URL.
static boolean isURL(String sURL, boolean bGuess)
           
static void main(String[] args)
           
static String normaliseMagnetURI(String base_hash)
          returns magnet uri if input is base 32 or base 16 encoded sha1 hash, null otherwise
static String parseTextForMagnets(String text)
           
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 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 setHost(URL u, String host)
           
static URL setPort(URL u, int port)
           
static URL setProtocol(URL u, String protocol)
           
static boolean SSLSocketSNIHack(String host_name, SSLSocket socket)
           
static String unescapeXML(String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlUtils

public UrlUtils()
Method Detail

decodeArgs

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

getMagnetURI

public static String getMagnetURI(byte[] hash)

getMagnetURI

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

extractHash

public static byte[] extractHash(String magnet_uri)

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)

getMagnetURI

public static String getMagnetURI(DownloadManager dm,
                                  int max_name_len)

getMagnetURI

public static String getMagnetURI(String name,
                                  Torrent torrent)

normaliseMagnetURI

public static String normaliseMagnetURI(String base_hash)
returns magnet uri if input is base 32 or base 16 encoded sha1 hash, null otherwise

Parameters:
base_hash -
Returns:

getHashFromMagnetURI

public static byte[] getHashFromMagnetURI(String magnetURI)

decodeSHA1Hash

public static byte[] decodeSHA1Hash(String 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)

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 &tr= parameter) - doing so screws stuff up later if, for example, the parameter included an encoded '&'

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)

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)

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(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 Exception
Throws:
Exception

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 Exception
Throws:
Exception

main

public static void main(String[] args)