*/
protected SipURI lookupTelUrlNAPTRRecord(String AUS,
String e164arpa_domain, Set<String> visited, int depth)
throws TelUrlResolverException {
if ((depth > EnumUtil.MAX_DEPTH) || !visited.add(e164arpa_domain)) {
throw new TelUrlResolverException("Loop detected when resolving:" +
AUS);
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"depth:" + depth + " AUS:" + AUS + " domain:" +
e164arpa_domain);
}
try {
Record[] records = doLookup(e164arpa_domain, Type.NAPTR);
Arrays.sort(records, new NaptrComparator());
for (Record record : records) {
NAPTRRecord naptrRecord = (NAPTRRecord) record;
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"number of DNS/NAPTR records:" + records.length);
logger.log(Level.FINE,
"NAPTRRecord.toString():" + record.toString());
}
String flag = naptrRecord.getFlags();
String service = naptrRecord.getService();
Name replacement = naptrRecord.getReplacement();
if (service.equalsIgnoreCase("E2U+sip") ||
service.equalsIgnoreCase("sip+E2U")) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"flag:" + naptrRecord.getFlags() + " flaglength:" +
naptrRecord.getFlags().length());
logger.log(Level.FINE,
"regexp:" + naptrRecord.getRegexp() +
" replacement:" + replacement);
}
if (!EnumUtil.isEmpty(replacement) && (flag.length() == 0)) {
return lookupTelUrlNAPTRRecord(AUS,
replacement.toString(), visited, ++depth);
}
String substitution = EnumUtil.applyRegExp(AUS,
naptrRecord.getRegexp());
if (substitution == null) {
// try next record
continue;
}
if (flag.equals("u")) {
int separator = substitution.indexOf(':');
if (separator == -1) {
throw new TelUrlResolverException(
"The regexp substitution result is not any supported uri:" +
substitution);
}
String schemePart = substitution.substring(0, separator);
String theUriPart = substitution.substring(separator +
1);
if (schemePart.equals(SipFactoryImpl.TEL_URI_PROTOCOL)) {
return lookupTelUrlNAPTRRecord(AUS,
EnumUtil.toDomain(theUriPart, myEnumTopDomain),
visited, ++depth);
} else if (schemePart.equals(
SipFactoryImpl.SIP_URI_PROTOCOL) ||
schemePart.equals(
SipFactoryImpl.SIPS_URI_PROTOCOL)) {
try {
SipURIImpl sipuri = new SipURIImpl(schemePart,
theUriPart, 0);
// check user=phone etc here
String userParam = sipuri.getParameter("user");
if ((userParam != null) &&
userParam.equals("phone")) {
String userTelUrl = sipuri.getUser();
return lookupTelUrlNAPTRRecord(AUS,
EnumUtil.toDomain(userTelUrl,
myEnumTopDomain), visited, ++depth);
}
return sipuri;
} catch (ServletParseException e) {
throw new TelUrlResolverException(e);
}
} else {
throw new TelUrlResolverException(
"The regexp substitution result is not any supported uri:" +
substitution);
}
} else if (flag.length() == 0) {
return lookupTelUrlNAPTRRecord(AUS, substitution,