| 328 | } |
| 329 | |
| 330 | private synchronized SetResponse |
| 331 | lookup(Name name, int type) { |
| 332 | int labels; |
| 333 | int olabels; |
| 334 | int tlabels; |
| 335 | RRset rrset; |
| 336 | Name tname; |
| 337 | Object types; |
| 338 | SetResponse sr; |
| 339 | |
| 340 | if (!name.subdomain(origin)) |
| 341 | return SetResponse.ofType(SetResponse.NXDOMAIN); |
| 342 | |
| 343 | labels = name.labels(); |
| 344 | olabels = origin.labels(); |
| 345 | |
| 346 | for (tlabels = olabels; tlabels <= labels; tlabels++) { |
| 347 | boolean isOrigin = (tlabels == olabels); |
| 348 | boolean isExact = (tlabels == labels); |
| 349 | |
| 350 | if (isOrigin) |
| 351 | tname = origin; |
| 352 | else if (isExact) |
| 353 | tname = name; |
| 354 | else |
| 355 | tname = new Name(name, labels - tlabels); |
| 356 | |
| 357 | types = exactName(tname); |
| 358 | if (types == null) |
| 359 | continue; |
| 360 | |
| 361 | /* If this is a delegation, return that. */ |
| 362 | if (!isOrigin) { |
| 363 | RRset ns = oneRRset(types, Type.NS); |
| 364 | if (ns != null) |
| 365 | return new SetResponse(SetResponse.DELEGATION, |
| 366 | ns); |
| 367 | } |
| 368 | |
| 369 | /* If this is an ANY lookup, return everything. */ |
| 370 | if (isExact && type == Type.ANY) { |
| 371 | sr = new SetResponse(SetResponse.SUCCESSFUL); |
| 372 | RRset [] sets = allRRsets(types); |
| 373 | for (int i = 0; i < sets.length; i++) |
| 374 | sr.addRRset(sets[i]); |
| 375 | return sr; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * If this is the name, look for the actual type or a CNAME. |
| 380 | * Otherwise, look for a DNAME. |
| 381 | */ |
| 382 | if (isExact) { |
| 383 | rrset = oneRRset(types, type); |
| 384 | if (rrset != null) { |
| 385 | sr = new SetResponse(SetResponse.SUCCESSFUL); |
| 386 | sr.addRRset(rrset); |
| 387 | return sr; |