Finds all matching sets or something that causes the lookup to stop.
(Name name, int type, int minCred)
| 401 | * Finds all matching sets or something that causes the lookup to stop. |
| 402 | */ |
| 403 | protected synchronized SetResponse |
| 404 | lookup(Name name, int type, int minCred) { |
| 405 | int labels; |
| 406 | int tlabels; |
| 407 | Element element; |
| 408 | Name tname; |
| 409 | Object types; |
| 410 | SetResponse sr; |
| 411 | |
| 412 | labels = name.labels(); |
| 413 | |
| 414 | for (tlabels = labels; tlabels >= 1; tlabels--) { |
| 415 | boolean isRoot = (tlabels == 1); |
| 416 | boolean isExact = (tlabels == labels); |
| 417 | |
| 418 | if (isRoot) |
| 419 | tname = Name.root; |
| 420 | else if (isExact) |
| 421 | tname = name; |
| 422 | else |
| 423 | tname = new Name(name, labels - tlabels); |
| 424 | |
| 425 | types = data.get(tname); |
| 426 | if (types == null) |
| 427 | continue; |
| 428 | |
| 429 | /* |
| 430 | * If this is the name, look for the actual type or a CNAME |
| 431 | * (unless it's an ANY query, where we return everything). |
| 432 | * Otherwise, look for a DNAME. |
| 433 | */ |
| 434 | if (isExact && type == Type.ANY) { |
| 435 | sr = new SetResponse(SetResponse.SUCCESSFUL); |
| 436 | Element [] elements = allElements(types); |
| 437 | int added = 0; |
| 438 | for (int i = 0; i < elements.length; i++) { |
| 439 | element = elements[i]; |
| 440 | if (element.expired()) { |
| 441 | removeElement(tname, element.getType()); |
| 442 | continue; |
| 443 | } |
| 444 | if (!(element instanceof CacheRRset)) |
| 445 | continue; |
| 446 | if (element.compareCredibility(minCred) < 0) |
| 447 | continue; |
| 448 | sr.addRRset((CacheRRset)element); |
| 449 | added++; |
| 450 | } |
| 451 | /* There were positive entries */ |
| 452 | if (added > 0) |
| 453 | return sr; |
| 454 | } else if (isExact) { |
| 455 | element = oneElement(tname, types, type, minCred); |
| 456 | if (element != null && |
| 457 | element instanceof CacheRRset) |
| 458 | { |
| 459 | sr = new SetResponse(SetResponse.SUCCESSFUL); |
| 460 | sr.addRRset((CacheRRset) element); |
no test coverage detected