int endParamIndex = length;
for (int i = offset; i < length; i++) {
// Control character should not appear in the url.
if (Character.isISOControl(str.charAt(i))) {
throw new ServletParseException(
"The URI contains a control character.");
}
if (str.charAt(i) == ':' && semiIndex == -1 ) {
if (atIndex > 0) {
portIndex = i;
} else {
passwdIndex = i;
}
} else if ((atIndex == -1) && (str.charAt(i) == '@')) {
atIndex = i;
} else if ((semiIndex == -1) && (str.charAt(i) == ';')) {
semiIndex = i;
endHostIndex = i;
} else if ((semiIndex != -1) && (str.charAt(i) == ';') && semiIndex < atIndex ) {
semiIndex = i;
endHostIndex = i;
} else if (str.charAt(i) == '?') {
qIndex = i;
if (semiIndex > 0) {
endParamIndex = i;
} else {
endHostIndex = i;
}
break;
}
}
if ((passwdIndex > 0) && (atIndex < 0)) {
portIndex = passwdIndex;
}
/*
* INFO: The user part and parameter parts of the url, could contains
* escaped characters, so we need to unecape them.
*/
// Check user
try {
if (atIndex > 0) {
if (passwdIndex > 0) {
_user = new Ascii7String(str.substring(offset,
passwdIndex));
_password = new Ascii7String(str.substring(passwdIndex + 1,
atIndex));
} else {
_user = new Ascii7String(str.substring(offset, atIndex));
}
offset = atIndex + 1;
}
// Ex: "sip:+302106699011;tgrp=0;trunk-context=0@164.48.135.94:5060"
if ( endHostIndex < offset ) {
endHostIndex = str.length();
String host = str.substring(offset, endHostIndex);
int innerCheck =host.indexOf(":");
if ( innerCheck != -1 )
portIndex = offset + innerCheck;
}
// Now the hostpart that is mandatory
if (portIndex > 0) { // Host n port
_host = new Ascii7String(str.substring(offset, portIndex));
_port = Integer.parseInt(str.substring(portIndex + 1,
endHostIndex));
} else { // no port only host
_host = new Ascii7String(str.substring(offset,
endHostIndex));
}
} catch (IllegalStateException e) {
throw new ServletParseException("CharacterCodingException");
}
offset = endHostIndex + 1;
// Time for the parameters