516 static class Authority {
517 HostPortrange p;
518
519 Authority(String scheme, String authority) {
520 int at = authority.indexOf('@');
521 if (at == -1) {
522 p = new HostPortrange(scheme, authority);
523 } else {
524 p = new HostPortrange(scheme, authority.substring(at+1));
525 }
526 }
527
528 boolean implies(Authority other) {
529 return impliesHostrange(other) && impliesPortrange(other);
530 }
531
532 private boolean impliesHostrange(Authority that) {
533 String thishost = this.p.hostname();
534 String thathost = that.p.hostname();
535
536 if (p.wildcard() && thishost.equals("")) {
537 // this "*" implies all others
538 return true;
539 }
540 if (that.p.wildcard() && thathost.equals("")) {
541 // that "*" can only be implied by this "*"
542 return false;
543 }
544 if (thishost.equals(thathost)) {
545 // covers all cases of literal IP addresses and fixed
546 // domain names.
547 return true;
548 }
549 if (this.p.wildcard()) {
550 // this "*.foo.com" implies "bub.bar.foo.com"
551 return thathost.endsWith(thishost);
552 }
553 return false;
554 }
555
556 private boolean impliesPortrange(Authority that) {
557 int[] thisrange = this.p.portrange();
558 int[] thatrange = that.p.portrange();
559 if (thisrange[0] == -1) {
560 /* port not specified non http/s URL */
|
516 static class Authority {
517 HostPortrange p;
518
519 Authority(String scheme, String authority) {
520 int at = authority.indexOf('@');
521 if (at == -1) {
522 p = new HostPortrange(scheme, authority);
523 } else {
524 p = new HostPortrange(scheme, authority.substring(at+1));
525 }
526 }
527
528 boolean implies(Authority other) {
529 return impliesHostrange(other) && impliesPortrange(other);
530 }
531
532 private boolean impliesHostrange(Authority that) {
533 String thishost = this.p.hostname();
534 String thathost = that.p.hostname();
535
536 if (p.wildcard() && thishost.isEmpty()) {
537 // this "*" implies all others
538 return true;
539 }
540 if (that.p.wildcard() && thathost.isEmpty()) {
541 // that "*" can only be implied by this "*"
542 return false;
543 }
544 if (thishost.equals(thathost)) {
545 // covers all cases of literal IP addresses and fixed
546 // domain names.
547 return true;
548 }
549 if (this.p.wildcard()) {
550 // this "*.foo.com" implies "bub.bar.foo.com"
551 return thathost.endsWith(thishost);
552 }
553 return false;
554 }
555
556 private boolean impliesPortrange(Authority that) {
557 int[] thisrange = this.p.portrange();
558 int[] thatrange = that.p.portrange();
559 if (thisrange[0] == -1) {
560 /* port not specified non http/s URL */
|