private void parse() throws ServletParseException
{
int indexScheme = _uri.indexOf(':');
if (indexScheme < 0)
throw new ServletParseException("Missing SIP scheme. URI=[" + _uri + "]");
_scheme = _uri.substring(0, indexScheme);
if (!_scheme.equals("sip") && !_scheme.equals("sips"))
throw new ServletParseException("Invalid SIP scheme. URI=[" + _uri + "]");
int indexUser = _uri.indexOf('@', indexScheme + 1);
int indexHost;
if (indexUser >= 0)
{
int indexPassword = _uri.indexOf(':', indexScheme + 1);
String sUser;
if (indexPassword >= 0 && indexPassword < indexUser)
{
sUser = _uri.substring(indexScheme + 1, indexPassword);
String sPassword = _uri.substring(indexPassword + 1, indexUser);
if (!SipGrammar.__passwd.containsAll(sPassword))
throw new ServletParseException("Invalid password [" + sPassword
+ "] in URI [" + _uri + "]");
_password = SipGrammar.unescape(sPassword);
}
else
{
sUser = _uri.substring(indexScheme + 1, indexUser);
}
if (!SipGrammar.__user.containsAll(sUser))
throw new ServletParseException("Invalid user [" + sUser + "] in URI [" + _uri + "]");
_user = SipGrammar.unescape(sUser);
indexHost = indexUser + 1;
}
else
{
indexHost = indexScheme + 1;
}
int indexPort = -1;
if (_uri.charAt(indexHost) == '[')
{
int i = _uri.indexOf(']', indexHost);
if (i < 0)
throw new ServletParseException("Invalid IPv6 in " + _uri);
indexPort = _uri.indexOf(':', i);
}
else
{
indexPort = _uri.indexOf(':', indexHost);
}
int indexParams = _uri.indexOf(';', indexHost);
int indexHeaders = _uri.indexOf('?', indexHost);
if ((indexPort > indexParams && indexParams > -1)
|| (indexPort > indexHeaders && indexHeaders > -1))
indexPort = -1;
int endHost = indexPort;
if (endHost < 0)
endHost = indexParams;
if (endHost < 0)
endHost = indexHeaders;
String host;
if (endHost < 0)
host = _uri.substring(indexHost);
else
host = _uri.substring(indexHost, endHost);
host = host.trim();
if (!SipGrammar.__host.containsAll(host))
throw new ServletParseException("Invalid host [" + host + "] in URI [" + _uri + "]");
setHost(host);
if (indexPort < 0)
{
_port = -1;
}
else
{
int endPort = indexParams;
if (endPort < 0)
endPort = indexHeaders;
String sPort;
if (endPort < 0)
sPort = _uri.substring(indexPort + 1);
else
sPort = _uri.substring(indexPort + 1, endPort);
try
{
_port = Integer.parseInt(sPort);
}
catch (NumberFormatException _)
{
throw new ServletParseException("Invalid port number [" + sPort + "] in [" + _uri + "]");
}
}
if (indexParams >= 0)
{
String params;