Gecko:Effective TLD Service: Difference between revisions

Line 68: Line 68:
== Interface ==
== Interface ==


The service provides a number of functions:
The service provides a single scriptable function:


<pre>
<pre>
     PRInt32    getEffectiveTLDLengthForHost(in AUTF8String aHostname);
     /**
    AUTF8String getEffectiveTLDForHost(in AUTF8String aHostname);
    * getEffectiveTLDLength
    PRInt32    getPrivateDomainLengthForHost(in AUTF8String aHostname);
    *
    AUTF8String getPrivateDomainForHost(in AUTF8String aHostname);
    * Finds the length of the effective TLD of a hostname.  An effective TLD
 
    * is the highest-level domain under which individual domains may be
    PRInt32    getEffectiveTLDLengthForURI(in nsIURI aURI);
    * registered, and may therefore contain one or more dots.  For example,
    AUTF8String getEffectiveTLDForURI(in nsIURI aURI);
    * the effective TLD for "www.bbc.co.uk" is "co.uk", because the .uk TLD
     PRInt32     getPrivateDomainLengthForURI(in nsIURI aURI);
    * does not allow the registration of domains at the second level ("bbc.uk"
    AUTF8String getPrivateDomainForURI(in nsIURI aURI);
    * 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>
These functions operate on either a string hostname or on an nsURI object; they extract either the effective TLD or the first level of the private domain (that is, the effective TLD plus one additional subdomain level); and they return either the length of the result in bytes or the string result itself.


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.getEffectiveTLDLengthForHost(hostname);
var hostLength = tld.getEffectiveTLDLength(hostname);
</pre>
</pre>


--[[User:PamG|PamG]] 17:25, 2 June 2006 (PDT)
--[[User:PamG|PamG]] 11:52, 7 June 2006 (PDT)
23

edits