Ensure that the domain and subdomain are valid

@throw {Error} when domain or subdomain are not valid
@return {bool} True if domain and subdomain are valid and compatible
164979
function validateDomainType() {
			if (!parent._domainType.hasOwnProperty(options.domain) || options.domain === "min" || options.domain.substring(0, 2) === "x_") {
				throw new Error("The domain '" + options.domain + "' is not valid");
			}

			if (!parent._domainType.hasOwnProperty(options.subDomain) || options.subDomain === "year") {
				throw new Error("The subDomain '" + options.subDomain + "' is not valid");
			}

			if (parent._domainType[options.domain].level <= parent._domainType[options.subDomain].level) {
				throw new Error("'" + options.subDomain + "' is not a valid subDomain to '" + options.domain +  "'");
			}

			return true;
		}
65774
function isBranchAssociatedDomains(domain, linkDomains) {
    return !(
      domain.indexOf("bnc.lt") > 0 ||
      domain.indexOf("app.link") > 0 ||
      linkDomains.indexOf(domain) >= 0
    );
  }
688114
public boolean isValid() {
        // to be valid a scope must have a type set other than undefined and its name will be set
        return (type != null && !type.equals(ScopeType.UNDEFINED) && (name != null && !("").equals(name)));
    }
244981
public boolean contains(final InternetDomainName domain) {
        ImmutableList<String> otherDomainParts = domain.parts();

        if (parts.size() > otherDomainParts.size()) {
            return false;
        }

        otherDomainParts = otherDomainParts.reverse()
                .subList(0, parts.size());

        return parts.reverse()
                .equals(otherDomainParts);
    }
562937
public static function isValidDomain($domain)
    {
        $valid = mb_strlen($domain, 'UTF-8') <= self::PHP_IDN_HANDLEABLE_LENGTH;

        if ($valid) {
            $result = idn_to_ascii(
                $domain,
                IDNA_USE_STD3_RULES | IDNA_NONTRANSITIONAL_TO_ASCII,
                INTL_IDNA_VARIANT_UTS46
            );

            if (!is_string($result)) {
                $valid = false;
            }
        }
        
        if ($valid) {
            $domainNameLength = strlen($result);
            if ($domainNameLength < 1 || $domainNameLength > 253) {
                $valid = false;
            }
        }
        
        if ($valid) {
            foreach (explode('.', $result) as $label) {
                $labelLength = strlen($label);
                if ($labelLength < 1 || $labelLength > 63) {
                    $valid = false;
                    break;
                }
            }
        }
        
        if ($valid) {
            $result = idn_to_utf8($result, IDNA_USE_STD3_RULES, INTL_IDNA_VARIANT_UTS46, $idna_info);
            if ($idna_info['errors'] !== 0) {
                $valid = false;
            }
        }
        
        return $valid;
    }
1211425
protected function checkDomain()
    {
        if ($this->domain === null) {
            return true;
        }

        if (self::$cachehost !== null) {
            $host = self::$cachehost;
        } else {
            $fhost = Request::header('Host');
            $host = strstr($fhost, ':', true);
            $host = $host ? $host : $fhost;

            self::$cachehost = $host;
        }

        if ($host === $this->domain) {
            return true;
        } elseif ($host) {
            $re = Regex::parse($this->domain);

            if ($re === false || preg_match('#^' . $re . '$#', $host, $matches) === 0) {
                return false;
            }

            array_shift($matches);

            $this->arguments = array_merge($this->arguments, $matches);

            return true;
        }

        return false;
    }
1086372
function Subdomain(sub, r, logging){
	if (!(this instanceof Subdomain)){
		var instance = new Subdomain(sub, r, logging);
		return instance;
	}

    if(!sub || !r || typeof sub !== 'string' || (typeof r !== "object" && typeof r !== "function")){
        throw new Error('Missing or wrong params! Expected first param a STRING (is '+(typeof sub)+') and second a GENERATOR-Object or a function (is '+(typeof r)+')');
    }
    if (typeof logging === 'undefined') {
        logging = true;
    }
    /**
    * steps to test:
    * 1) sub === this.hostname
    * 2) this.subdomain[0] === sub
    * 3) typeof this.subdomain[1] === 'string' // or wildcard => sub sub domain ?
    */
    return function *(next){ 
        // for the case someone enters a complete domain name
        // e.g. 'sub.example.com'
        // instead of 'sub' or '*'

        
        if(sub === this.hostname){
            if (logging) {
                console.log('direct match');
            }
           
            if(typeof r.routes === "function") {
                yield r.routes();
            } else 
            { 
                yield r;
            }; 
            
        }

       //console.log('subdomains: ',this.subdomains);
        var subdomain = this.subdomains[0] || '';
       // console.log('subdomain: ',subdomain);
       // console.log('sub: ',sub);
        //console.log(typeof this.subdomains[1]);
        if (subdomain === sub && sub[0] !== '*' && !this.subdomains[1]) {
            if (logging) {
                console.log('match by '+subdomain);
            }
            if(typeof r.routes === "function") {
                yield r.routes();
            } else 
            { 
                yield r;
            };        
        } else if(typeof this.subdomains[1] === 'string' 
            || sub[0] === "*"){
        //    console.log('subdomains[1]',this.subdomains[1]);
            // converting array back to subdomain
            var subdomainsstring = "";
            var length = this.subdomains.length;
            for(var i=length; i > 0; i-- ){
                if(subdomainsstring === ""){
                    subdomainsstring += this.subdomains[i-1];
                }else {
                    subdomainsstring += "."+this.subdomains[i-1];
                }
               // console.log('subdomainsstring:',subdomainsstring);
            }
            // wildcard subdomain at most left in "sub" string
            var splittedSub = sub.split(".");
           // console.log('splittedSub: ',splittedSub);
           if(splittedSub[0] === "*"){
                var subdomains = this.subdomains;
                var hostname = this.hostname.split(".");
                var hostnamelength = hostname.length;
                // reverse lookup arrays against each other 
                for(var s=hostnamelength; s > 0; s--){
                    var hostnamepop = hostname.pop();
                    if(subdomains.length > 0){
                        var shift = subdomains.shift();                        
                    }
                    var pop = splittedSub.pop();
                //    console.log('hostname pop: ',hostnamepop);
                //    console.log('subdomain shift: ',shift);
                //    console.log('split pop: ',pop);
                    if(shift === pop || hostnamepop === pop){
                        continue;
                    } else {
                        if(pop === "*"){
                            if (logging) {
                                console.log('match by * in '+sub);
                            }
                            if(typeof r.routes === "function") {
                                yield r.routes();
                            } else 
                            { 
                                yield r;
                            };
                           break;            
                        } else {
                            yield next;
                            break;
                        }
                    }
                }
            }

            // NOTE: app.subdomainOffset is the base!
            if(subdomainsstring === sub){
                if (logging) {
                    console.log('match by subdomainstring '+subdomainsstring);
                }
                if(typeof r.routes === "function") {
                    yield r.routes();
                } else 
                { 
                    yield r;
                };
            } else {
                yield next;
            }
        }
        else{
            yield next;
        }
    };


}
914071
function setDomains(newDomains) {
    if (!isObject(newDomains)) {
        throw new InvalidException('newDomains should be an object', newDomains);
    }
    domainsMap = domainsMap.merge(newDomains);
}
133202
def valid?
      return false if @id.nil?
      return false if @name.nil?
      return false if @name !~ Regexp.new(/^(?!(.*[\\\"\\*\\\\\\>\\<\\?\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$))/)
      return false if @node_type.nil?
      return false if @is_folder.nil?
      return false if @is_file.nil?
      return false if @modified_at.nil?
      return false if @modified_by_user.nil?
      return false if @created_at.nil?
      return false if @created_by_user.nil?
      return true
    end
89743
private boolean validate(final String realName, final String name, final String host, final Problems problems, final String compName) {
		return false;
	}
70934
function isResponseValid(response) {
  return !/^\s*\{\s*"advertisementAvailable"\s*:\s*false/i.test(response.content) &&
    response.content.indexOf('<VAST version="2.0"></VAST>') === -1 && (typeof response.cpm !== 'undefined') &&
    response.status === 1;
}
1251702
function isSameOrigin(a, b) {
  var urlA = parseURL(a);
  var urlB = parseURL(b);
  if (!urlA || !urlB) {
    return false;
  }
  if (urlA.origin === urlB.origin) {
    return true;
  }
  if (
    urlA.protocol === urlB.protocol &&
    urlA.hostname === urlB.hostname &&
    urlA.port === urlB.port
  ) {
    return true;
  }
  return false;
}
435522
def valid?
      return false if @id.nil?
      return false if @name.nil?
      authenticator_validator = EnumAttributeValidator.new('String', ["local", "ldap"])
      return false unless authenticator_validator.valid?(@authenticator)
      return true
    end
85374
def check_subdomain_transition(cls, existing_subrec, new_subrec):
        
        if existing_subrec.get_fqn() != new_subrec.get_fqn():
            return False

        if existing_subrec.n + 1 != new_subrec.n:
            return False

        if not new_subrec.verify_signature(existing_subrec.address):
            log.debug("Invalid signature from {}".format(existing_subrec.address))
            return False

        if virtualchain.address_reencode(existing_subrec.address) != virtualchain.address_reencode(new_subrec.address):
            if new_subrec.independent:
                log.debug("Transfer is independent of domain: {}".format(new_subrec))
                return False

        return True
594013
def domain_name=(domain_name)
      if domain_name.nil?
        fail ArgumentError, "domain_name cannot be nil"
      end

      if domain_name.to_s.length > 255
        fail ArgumentError, "invalid value for 'domain_name', the character length must be smaller than or equal to 255."
      end

      if domain_name.to_s.length < 1
        fail ArgumentError, "invalid value for 'domain_name', the character length must be great than or equal to 1."
      end

      @domain_name = domain_name
    end
712278
function(start) {
		"use strict";

		var parent = this;
		return this.triggerEvent("afterLoadPreviousDomain", function() {
			var subDomain = parent.getSubDomain(start);
			return [subDomain.shift(), subDomain.pop()];
		});
	}
1222731
function() {
        let docDomain = this.getDocDomain();
        if ( docDomain === '' ) { docDomain = this.docHostname; }
        if ( this.domain !== undefined && this.domain !== '' ) {
            return this.domain !== docDomain;
        }
        const hostname = this.getHostname();
        if ( hostname.endsWith(docDomain) === false ) { return true; }
        const i = hostname.length - docDomain.length;
        if ( i === 0 ) { return false; }
        return hostname.charCodeAt(i - 1) !== 0x2E /* '.' */;
    }