/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: URI.java,v 1.2.4.1 2005/09/15 08:16:00 suresh_emailid Exp $
*/
/**
* A class to represent a Uniform Resource Identifier (URI). This class
* is designed to handle the parsing of URIs and provide access to
* the various components (scheme, host, port, userinfo, path, query
* string and fragment) that may constitute a URI.
* <p>
* Parsing of a URI specification is done according to the URI
* syntax described in RFC 2396
* <http://www.ietf.org/rfc/rfc2396.txt?number=2396>. Every URI consists
* of a scheme, followed by a colon (':'), followed by a scheme-specific
* part. For URIs that follow the "generic URI" syntax, the scheme-
* specific part begins with two slashes ("//") and may be followed
* by an authority segment (comprised of user information, host, and
* port), path segment, query segment and fragment. Note that RFC 2396
* no longer specifies the use of the parameters segment and excludes
* the "user:password" syntax as part of the authority segment. If
* is stored as userinfo.
* <p>
* For URIs that do not follow the "generic URI" syntax (e.g. mailto),
* the entire scheme-specific part is treated as the "path" portion
* of the URI.
* <p>
* Note that, unlike the java.net.URL class, this class does not provide
* any built-in network access functionality nor does it provide any
* scheme-specific functionality (for example, it does not know a
* default port for a specific scheme). Rather, it only knows the
* grammar and basic set of operations that can be applied to a URI.
*
*
*/
{
/**
* MalformedURIExceptions are thrown in the process of building a URI
* or setting fields on a URI when an operation would result in an
* invalid URI specification.
*
*/
{
/**
* Constructs a <code>MalformedURIException</code> with no specified
* detail message.
*/
public MalformedURIException()
{
super();
}
/**
* Constructs a <code>MalformedURIException</code> with the
* specified detail message.
*
* @param p_msg the detail message.
*/
{
super(p_msg);
}
}
/** reserved characters */
/**
* URI punctuation mark characters - these, combined with
* alphanumerics, constitute the "unreserved" characters
*/
/** scheme can be composed of alphanumerics and these characters */
/**
* userinfo can be composed of unreserved, escaped and these
* characters
*/
/** Stores the scheme (usually the protocol) for this URI.
* @serial */
/** If specified, stores the userinfo for this URI; otherwise null.
* @serial */
/** If specified, stores the host for this URI; otherwise null.
* @serial */
/** If specified, stores the port for this URI; otherwise -1.
* @serial */
/** If specified, stores the path for this URI; otherwise null.
* @serial */
/**
* If specified, stores the query string for this URI; otherwise
* null.
* @serial
*/
/** If specified, stores the fragment for this URI; otherwise null.
* @serial */
/** Indicate whether in DEBUG mode */
private static boolean DEBUG = false;
/**
* Construct a new and uninitialized URI.
*/
public URI(){}
/**
* Construct a new URI from another URI. All fields for this URI are
* set equal to the fields of the URI passed in.
*
* @param p_other the URI to copy (cannot be null)
*/
{
}
/**
* Construct a new URI from a URI specification string. If the
* specification follows the "generic URI" syntax, (two slashes
* following the first colon), the specification will be parsed
* accordingly - setting the scheme, userinfo, host,port, path, query
* string and fragment fields as necessary. If the specification does
* not follow the "generic URI" syntax, the specification is parsed
* into a scheme and scheme-specific part (stored as the path) only.
*
* @param p_uriSpec the URI specification string (cannot be null or
* empty)
*
* @throws MalformedURIException if p_uriSpec violates any syntax
* rules
*/
{
}
/**
* Construct a new URI from a base URI and a URI specification string.
* The URI specification string may be a relative URI.
*
* @param p_base the base URI (cannot be null if p_uriSpec is null or
* empty)
* @param p_uriSpec the URI specification string (cannot be null or
* empty if p_base is null)
*
* @throws MalformedURIException if p_uriSpec violates any syntax
* rules
*/
{
}
/**
* Construct a new URI that does not follow the generic URI syntax.
* Only the scheme and scheme-specific part (stored as the path) are
* initialized.
*
* @param p_scheme the URI scheme (cannot be null or empty)
* @param p_schemeSpecificPart the scheme-specific part (cannot be
* null or empty)
*
* @throws MalformedURIException if p_scheme violates any
* syntax rules
*/
throws MalformedURIException
{
{
throw new MalformedURIException(
}
if (p_schemeSpecificPart == null
{
throw new MalformedURIException(
}
}
/**
* Construct a new URI that follows the generic URI syntax from its
* component parts. Each component is validated for syntax and some
* basic semantic checks are performed as well. See the individual
* setter methods for specifics.
*
* @param p_scheme the URI scheme (cannot be null or empty)
* @param p_host the hostname or IPv4 address for the URI
* @param p_path the URI path - if the path contains '?' or '#',
* set from the path; however, if the query and
* fragment are specified both in the path and as
* separate parameters, an exception is thrown
* @param p_queryString the URI query string (cannot be specified
* if path is null)
* @param p_fragment the URI fragment (cannot be specified if path
* is null)
*
* @throws MalformedURIException if any of the parameters violates
* syntax rules or semantic rules
*/
throws MalformedURIException
{
}
/**
* Construct a new URI that follows the generic URI syntax from its
* component parts. Each component is validated for syntax and some
* basic semantic checks are performed as well. See the individual
* setter methods for specifics.
*
* @param p_scheme the URI scheme (cannot be null or empty)
* @param p_userinfo the URI userinfo (cannot be specified if host
* is null)
* @param p_host the hostname or IPv4 address for the URI
* @param p_port the URI port (may be -1 for "unspecified"; cannot
* be specified if host is null)
* @param p_path the URI path - if the path contains '?' or '#',
* set from the path; however, if the query and
* fragment are specified both in the path and as
* separate parameters, an exception is thrown
* @param p_queryString the URI query string (cannot be specified
* if path is null)
* @param p_fragment the URI fragment (cannot be specified if path
* is null)
*
* @throws MalformedURIException if any of the parameters violates
* syntax rules or semantic rules
*/
public URI(String p_scheme, String p_userinfo, String p_host, int p_port, String p_path, String p_queryString, String p_fragment)
throws MalformedURIException
{
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_SCHEME_REQUIRED, null)); //"Scheme is required!");
}
{
if (p_userinfo != null)
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_USERINFO_IF_NO_HOST, null)); //"Userinfo may not be specified if host is not specified!");
}
if (p_port != -1)
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_PORT_IF_NO_HOST, null)); //"Port may not be specified if host is not specified!");
}
}
{
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_QUERY_STRING_IN_PATH, null)); //"Query string cannot be specified in path and query string!");
}
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_FRAGMENT_STRING_IN_PATH, null)); //"Fragment cannot be specified in both the path and fragment!");
}
}
}
/**
* Initialize all fields of this URI from another URI.
*
* @param p_other the URI to copy (cannot be null)
*/
{
}
/**
* Initializes this URI from a base URI and a URI specification string.
* See RFC 2396 Section 4 and Appendix B for specifications on parsing
* the URI and Section 5 for specifications on resolving relative URIs
* and relative paths.
*
* @param p_base the base URI (may be null if p_uriSpec is an absolute
* URI)
* @param p_uriSpec the URI spec string which may be an absolute or
* is not null)
*
* @throws MalformedURIException if p_base is null and p_uriSpec
* is not an absolute URI or if
* p_uriSpec violates syntax rules
*/
throws MalformedURIException
{
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_CANNOT_INIT_URI_EMPTY_PARMS, null)); //"Cannot initialize URI with empty parameters.");
}
// just make a copy of the base if spec is empty
{
return;
}
int index = 0;
// check for scheme
if (colonIndex < 0)
{
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_SCHEME_IN_URI, new Object[]{uriSpec})); //"No scheme found in URI: "+uriSpec);
}
}
else
{
// This is a fix for XALANJ-2059.
{
// a) If <uriSpec> starts with a slash (/), it means <uriSpec> is absolute
// and p_base can be ignored.
// For example,
// uriSpec = file:/myDIR/myXSLFile.xsl
// p_base = file:/myWork/
//
// Here, uriSpec has absolute path after scheme file and :
// Hence p_base can be ignored.
//
// b) Similarily, according to RFC 2396, uri is resolved for <uriSpec> relative to <p_base>
// if scheme in <uriSpec> is same as scheme in <p_base>, else p_base can be ignored.
//
// c) if <p_base> is not hierarchical, it can be ignored.
//
if(uriSpec.startsWith("/") || !m_scheme.equals(p_base.m_scheme) || !p_base.getSchemeSpecificPart().startsWith("/"))
{
}
}
// Fix for XALANJ-2059
}
// two slashes means generic URI syntax, so we get the authority
{
index += 2;
// get authority - everything up to path, query or fragment
char testChar = '\0';
while (index < uriSpecLen)
{
{
break;
}
index++;
}
// if we found authority, parse it out, otherwise we set the
// host to empty string
{
}
else
{
m_host = "";
}
}
// Resolve relative URI to base URI - see RFC 2396 Section 5.2
// In some cases, it might make more sense to throw an exception
// (when scheme is specified is the string spec and the base URI
// is also specified, for example), but we're just following the
// RFC specifications
{
// check to see if this is the current doc - RFC 2396 5.2 #2
// note that this is slightly different from the RFC spec in that
// we don't include the check for query string being null
// - this handles cases where the urispec is just a query
// string or a fragment (e.g. "?y" or "#s") -
// see <http://www.ics.uci.edu/~fielding/url/test1.html> which
// identified this as a bug in the RFC
{
if (m_queryString == null)
{
}
return;
}
// check for scheme - RFC 2396 5.2 #3
// if we found a scheme, it means absolute URI, so we're done
{
}
// check for authority - RFC 2396 5.2 #4
// if we found a host, then we've got a network path, so we're done
{
}
else
{
return;
}
// check for absolute path - RFC 2396 5.2 #5
{
return;
}
// if we get to this point, we need to resolve relative path
// RFC 2396 5.2 #6
// 6a - get all but the last segment of the base URI path
{
if (lastSlash != -1)
{
}
}
// 6b - append the relative URI path
// 6c - remove all "./" where "." is a complete path segment
index = -1;
{
}
// 6d - remove "." if path ends with "." as a complete path segment
{
}
// 6e - remove all "<segment>/../" where "<segment>" is a complete
// path segment not equal to ".."
index = -1;
int segIndex = -1;
{
if (segIndex != -1)
{
{
+ 4));
}
}
}
// 6f - remove ending "<segment>/.." where "<segment>" is a
// complete path segment
{
if (segIndex != -1)
{
}
}
}
}
/**
* Initialize the scheme for this URI from a URI string spec.
*
* @param p_uriSpec the URI specification (cannot be null)
*
* @throws MalformedURIException if URI does not have a conformant
* scheme
*/
{
int index = 0;
char testChar = '\0';
while (index < uriSpecLen)
{
|| testChar == '#')
{
break;
}
index++;
}
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_SCHEME_INURI, null)); //"No scheme found in URI.");
}
else
{
}
}
/**
* Initialize the authority (userinfo, host and port) for this
* URI from a URI string spec.
*
* @param p_uriSpec the URI specification (cannot be null)
*
* @throws MalformedURIException if p_uriSpec violates syntax rules
*/
throws MalformedURIException
{
int index = 0;
int start = 0;
char testChar = '\0';
// userinfo is everything up @
{
{
if (testChar == '@')
{
break;
}
index++;
}
index++;
}
// host is everything up to ':'
{
if (testChar == ':')
{
break;
}
index++;
}
int port = -1;
{
// port
if (testChar == ':')
{
index++;
{
index++;
}
{
{
{
throw new MalformedURIException(
portStr + " is invalid. Port should only contain digits!");
}
}
try
{
}
catch (NumberFormatException nfe)
{
// can't happen
}
}
}
}
}
/**
* Initialize the path for this URI from a URI string spec.
*
* @param p_uriSpec the URI specification (cannot be null)
*
* @throws MalformedURIException if p_uriSpec violates syntax rules
*/
{
{
throw new MalformedURIException(
"Cannot initialize path from null string!");
}
int index = 0;
int start = 0;
char testChar = '\0';
// path - everything up to query string or fragment
{
{
break;
}
// check for valid escape sequence
if (testChar == '%')
{
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE, null)); //"Path contains invalid escape sequence!");
}
}
else if (!isReservedCharacter(testChar)
{
if ('\\' != testChar)
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_PATH_INVALID_CHAR, new Object[]{String.valueOf(testChar)})); //"Path contains invalid character: "
//+ testChar);
}
index++;
}
// query - starts with ? and up to fragment or end
if (testChar == '?')
{
index++;
{
if (testChar == '#')
{
break;
}
if (testChar == '%')
{
{
throw new MalformedURIException(
"Query string contains invalid escape sequence!");
}
}
else if (!isReservedCharacter(testChar)
{
throw new MalformedURIException(
"Query string contains invalid character:" + testChar);
}
index++;
}
}
// fragment - starts with #
if (testChar == '#')
{
index++;
{
if (testChar == '%')
{
{
throw new MalformedURIException(
"Fragment contains invalid escape sequence!");
}
}
else if (!isReservedCharacter(testChar)
{
throw new MalformedURIException(
"Fragment contains invalid character:" + testChar);
}
index++;
}
}
}
/**
* Get the scheme for this URI.
*
* @return the scheme for this URI
*/
{
return m_scheme;
}
/**
* Get the scheme-specific part for this URI (everything following the
* scheme and the first colon). See RFC 2396 Section 5.2 for spec.
*
* @return the scheme-specific part for this URI
*/
{
{
}
if (m_userinfo != null)
{
}
{
}
if (m_port != -1)
{
}
{
}
if (m_queryString != null)
{
}
if (m_fragment != null)
{
}
return schemespec.toString();
}
/**
* Get the userinfo for this URI.
*
* @return the userinfo for this URI (null if not specified).
*/
{
return m_userinfo;
}
/**
* Get the host for this URI.
*
* @return the host for this URI (null if not specified).
*/
{
return m_host;
}
/**
* Get the port for this URI.
*
* @return the port for this URI (-1 if not specified).
*/
public int getPort()
{
return m_port;
}
/**
* Get the path for this URI (optionally with the query string and
* fragment).
*
* @param p_includeQueryString if true (and query string is not null),
* then a "?" followed by the query string
* will be appended
* @param p_includeFragment if true (and fragment is not null),
* then a "#" followed by the fragment
* will be appended
*
* @return the path for this URI possibly including the query string
* and fragment
*/
boolean p_includeFragment)
{
{
}
{
}
return pathString.toString();
}
/**
* Get the path for this URI. Note that the value returned is the path
* only and does not include the query string or fragment.
*
* @return the path for this URI.
*/
{
return m_path;
}
/**
* Get the query string for this URI.
*
* @return the query string for this URI. Null is returned if there
* was no "?" in the URI spec, empty string if there was a
* "?" but no query string following it.
*/
{
return m_queryString;
}
/**
* Get the fragment for this URI.
*
* @return the fragment for this URI. Null is returned if there
* was no "#" in the URI spec, empty string if there was a
* "#" but no fragment following it.
*/
{
return m_fragment;
}
/**
* Set the scheme for this URI. The scheme is converted to lowercase
* before it is set.
*
* @param p_scheme the scheme for this URI (cannot be null)
*
* @throws MalformedURIException if p_scheme is not a conformant
* scheme name
*/
{
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_SCHEME_FROM_NULL_STRING, null)); //"Cannot set scheme from null string!");
}
if (!isConformantSchemeName(p_scheme))
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_SCHEME_NOT_CONFORMANT, null)); //"The scheme is not conformant.");
}
}
/**
* Set the userinfo for this URI. If a non-null value is passed in and
* the host value is null, then an exception is thrown.
*
* @param p_userinfo the userinfo for this URI
*
* @throws MalformedURIException if p_userinfo contains invalid
* characters
*/
{
if (p_userinfo == null)
{
m_userinfo = null;
}
else
{
{
throw new MalformedURIException(
"Userinfo cannot be set when host is null!");
}
// userinfo can contain alphanumerics, mark characters, escaped
// and ';',':','&','=','+','$',','
int index = 0;
char testChar = '\0';
{
if (testChar == '%')
{
{
throw new MalformedURIException(
"Userinfo contains invalid escape sequence!");
}
}
else if (!isUnreservedCharacter(testChar)
{
throw new MalformedURIException(
"Userinfo contains invalid character:" + testChar);
}
index++;
}
}
}
/**
* Set the host for this URI. If null is passed in, the userinfo
* field is also set to null and the port is set to -1.
*
* @param p_host the host for this URI
*
* @throws MalformedURIException if p_host is not a valid IP
* address or DNS hostname.
*/
{
{
m_userinfo = null;
m_port = -1;
}
else if (!isWellFormedAddress(p_host))
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_HOST_ADDRESS_NOT_WELLFORMED, null)); //"Host is not a well formed address!");
}
}
/**
* Set the port for this URI. -1 is used to indicate that the port is
* not specified, otherwise valid port numbers are between 0 and 65535.
* If a valid port number is passed in and the host field is null,
* an exception is thrown.
*
* @param p_port the port number for this URI
*
* @throws MalformedURIException if p_port is not -1 and not a
* valid port number
*/
{
{
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_PORT_WHEN_HOST_NULL, null)); //"Port cannot be set when host is null!");
}
}
else if (p_port != -1)
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_INVALID_PORT, null)); //"Invalid port number!");
}
}
/**
* Set the path for this URI. If the supplied path is null, then the
* query string and fragment are set to null as well. If the supplied
* parsed and set as well. Note that, for URIs following the "generic
* URI" syntax, the path specified should start with a slash.
* For URIs that do not follow the generic URI syntax, this method
* sets the scheme-specific part.
*
* @param p_path the path for this URI (may be null)
*
* @throws MalformedURIException if p_path contains invalid
* characters
*/
{
{
m_fragment = null;
}
else
{
}
}
/**
* Append to the end of the path of this URI. If the current path does
* not end in a slash and the path to be appended does not begin with
* a slash, a slash will be appended to the current path before the
* new segment is added. Also, if the current path ends in a slash
* and the new segment begins with a slash, the extra slash will be
* removed before the new segment is appended.
*
* @param p_addToPath the new segment to be added to the current path
*
* @throws MalformedURIException if p_addToPath contains syntax
* errors
*/
{
{
return;
}
if (!isURIString(p_addToPath))
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_PATH_INVALID_CHAR, new Object[]{p_addToPath})); //"Path contains invalid character!");
}
{
{
}
else
{
}
}
{
{
}
else
{
}
}
else
{
{
}
else
{
}
}
}
/**
* Set the query string for this URI. A non-null value is valid only
* if this is an URI conforming to the generic URI syntax and
* the path value is not null.
*
* @param p_queryString the query string for this URI
*
* @throws MalformedURIException if p_queryString is not null and this
* URI does not conform to the generic
* URI syntax or if the path is null
*/
throws MalformedURIException
{
if (p_queryString == null)
{
}
else if (!isGenericURI())
{
throw new MalformedURIException(
"Query string can only be set for a generic URI!");
}
{
throw new MalformedURIException(
"Query string cannot be set when path is null!");
}
else if (!isURIString(p_queryString))
{
throw new MalformedURIException(
"Query string contains invalid character!");
}
else
{
}
}
/**
* Set the fragment for this URI. A non-null value is valid only
* if this is a URI conforming to the generic URI syntax and
* the path value is not null.
*
* @param p_fragment the fragment for this URI
*
* @throws MalformedURIException if p_fragment is not null and this
* URI does not conform to the generic
* URI syntax or if the path is null
*/
{
if (p_fragment == null)
{
m_fragment = null;
}
else if (!isGenericURI())
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_FRAG_FOR_GENERIC_URI, null)); //"Fragment can only be set for a generic URI!");
}
{
throw new MalformedURIException(
XMLMessages.createXMLMessage(XMLErrorResources.ER_FRAG_WHEN_PATH_NULL, null)); //"Fragment cannot be set when path is null!");
}
else if (!isURIString(p_fragment))
{
throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_FRAG_INVALID_CHAR, null)); //"Fragment contains invalid character!");
}
else
{
}
}
/**
* Determines if the passed-in Object is equivalent to this URI.
*
* @param p_test the Object to test for equality.
*
* @return true if p_test is a URI with all values equal to this
* URI, false otherwise
*/
{
{
if (((m_scheme == null && testURI.m_scheme == null) || (m_scheme != null && testURI.m_scheme != null && m_scheme.equals(
testURI.m_scheme))) && ((m_userinfo == null && testURI.m_userinfo == null) || (m_userinfo != null && testURI.m_userinfo != null && m_userinfo.equals(
testURI.m_userinfo))) && ((m_host == null && testURI.m_host == null) || (m_host != null && testURI.m_host != null && m_host.equals(
testURI.m_host))) && m_port == testURI.m_port && ((m_path == null && testURI.m_path == null) || (m_path != null && testURI.m_path != null && m_path.equals(
testURI.m_path))) && ((m_queryString == null && testURI.m_queryString == null) || (m_queryString != null && testURI.m_queryString != null && m_queryString.equals(
testURI.m_queryString))) && ((m_fragment == null && testURI.m_fragment == null) || (m_fragment != null && testURI.m_fragment != null && m_fragment.equals(
testURI.m_fragment))))
{
return true;
}
}
return false;
}
public int hashCode() {
int hash = 7;
return hash;
}
/**
* Get the URI as a string specification. See RFC 2396 Section 5.2.
*
* @return the URI string specification
*/
{
{
}
return uriSpecString.toString();
}
/**
* Get the indicator as to whether this URI uses the "generic URI"
* syntax.
*
* @return true if this URI uses the "generic URI" syntax, false
* otherwise
*/
public boolean isGenericURI()
{
// presence of the host (whether valid or empty) means
// double-slashes which means generic uri
}
/**
* Determine whether a scheme conforms to the rules for a scheme name.
* A scheme is conformant if it starts with an alphanumeric, and
* contains only alphanumerics, '+','-' and '.'.
*
*
* @param p_scheme The sheme name to check
* @return true if the scheme is conformant, false otherwise
*/
{
{
return false;
}
{
return false;
}
char testChar;
{
{
return false;
}
}
return true;
}
/**
* Determine whether a string is syntactically capable of representing
* a valid IPv4 address or the domain name of a network host. A valid
* IPv4 address consists of four decimal digit groups separated by a
* '.'. A hostname consists of domain labels (each of which must
* begin and end with an alphanumeric but may contain '-') separated
* & by a '.'. See RFC 2396 Section 3.2.2.
*
*
* @param p_address The address string to check
* @return true if the string is a syntactically valid IPv4 address
* or hostname
*/
{
{
return false;
}
{
return false;
}
{
return false;
}
// rightmost domain label starting with digit indicates IP address
// since top level domain label can only start with an alpha
// see RFC 2396 Section 3.2.2
{
}
{
char testChar;
int numDots = 0;
// make sure that 1) we see only digits and dot separators, 2) that
// any dot separator is preceded and followed by a digit and
// 3) that we find 3 dots
for (int i = 0; i < addrLength; i++)
{
if (testChar == '.')
{
{
return false;
}
numDots++;
}
{
return false;
}
}
if (numDots != 3)
{
return false;
}
}
else
{
// domain labels can contain alphanumerics and '-"
// but must start and end with an alphanumeric
char testChar;
for (int i = 0; i < addrLength; i++)
{
if (testChar == '.')
{
{
return false;
}
{
return false;
}
}
{
return false;
}
}
}
return true;
}
/**
* Determine whether a char is a digit.
*
*
* @param p_char the character to check
* @return true if the char is betweeen '0' and '9', false otherwise
*/
{
}
/**
* Determine whether a character is a hexadecimal character.
*
*
* @param p_char the character to check
* @return true if the char is betweeen '0' and '9', 'a' and 'f'
* or 'A' and 'F', false otherwise
*/
{
}
/**
* Determine whether a char is an alphabetic character: a-z or A-Z
*
*
* @param p_char the character to check
* @return true if the char is alphabetic, false otherwise
*/
{
}
/**
* Determine whether a char is an alphanumeric: 0-9, a-z or A-Z
*
*
* @param p_char the character to check
* @return true if the char is alphanumeric, false otherwise
*/
{
}
/**
* Determine whether a character is a reserved character:
* ';', '/', '?', ':', '@', '&', '=', '+', '$' or ','
*
*
* @param p_char the character to check
* @return true if the string contains any reserved characters
*/
{
}
/**
* Determine whether a char is an unreserved character.
*
*
* @param p_char the character to check
* @return true if the char is unreserved, false otherwise
*/
{
}
/**
* Determine whether a given string contains only URI characters (also
* called "uric" in RFC 2396). uric consist of all reserved
* characters, unreserved characters and escaped characters.
*
*
* @param p_uric URI string
* @return true if the string is comprised of uric, false otherwise
*/
{
{
return false;
}
char testChar = '\0';
for (int i = 0; i < end; i++)
{
if (testChar == '%')
{
{
return false;
}
else
{
i += 2;
continue;
}
}
{
continue;
}
else
{
return false;
}
}
return true;
}
}