23
edits
| Line 68: | Line 68: | ||
== Interface == | == Interface == | ||
The service provides a | The service provides a single scriptable function: | ||
<pre> | <pre> | ||
/** | |||
* getEffectiveTLDLength | |||
* | |||
* Finds the length of the effective TLD of a hostname. An effective TLD | |||
* is the highest-level domain under which individual domains may be | |||
* registered, and may therefore contain one or more dots. For example, | |||
* the effective TLD for "www.bbc.co.uk" is "co.uk", because the .uk TLD | |||
PRInt32 | * does not allow the registration of domains at the second level ("bbc.uk" | ||
* is forbidden). Similarly, the effective TLD of "developer.mozilla.com" | |||
* is "com". | |||
* | |||
* The hostname will be normalized using nsIDNService::Normalize, which | |||
* follows RFC 3454. getEffectiveTLDLength() will fail, generating an | |||
* error, if the hostname contains characters that are invalid in URIs. | |||
* | |||
* @param aHostname The hostname to be analyzed, in UTF-8 | |||
* | |||
* @returns the number of bytes that the longest identified effective TLD | |||
* (TLD or TLD-like higher-level subdomain) occupies, not including | |||
* the leading dot: | |||
* bugzilla.mozilla.org -> org -> 3 | |||
* theregister.co.uk -> co.uk -> 5 | |||
* mysite.us -> us -> 2 | |||
*/ | |||
PRInt32 getEffectiveTLDLength(in AUTF8String aHostname); | |||
</pre> | </pre> | ||
To call the service, use the getService function: | To call the service, use the getService function: | ||
| Line 93: | Line 107: | ||
.getService(Components.interfaces.nsIEffectiveTLDService); | .getService(Components.interfaces.nsIEffectiveTLDService); | ||
var hostLength = tld. | var hostLength = tld.getEffectiveTLDLength(hostname); | ||
</pre> | </pre> | ||
--[[User:PamG|PamG]] | --[[User:PamG|PamG]] 11:52, 7 June 2006 (PDT) | ||
edits