|
|
| Line 67: |
Line 67: |
| == Interface == | | == Interface == |
|
| |
|
| The service provides a single scriptable function:
| | See [http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/src/nsEffectiveTLDService.cpp nsEffectiveTLDService.cpp]. |
| | |
| <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
| |
| * 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>
| |
| | |
| To call the service, use the getService function:
| |
| | |
| <pre>
| |
| #include "nsIEffectiveTLDService.h"
| |
| | |
| var tld
| |
| = Components.classes["@mozilla.org/network/effective-tld-service;1"]
| |
| .getService(Components.interfaces.nsIEffectiveTLDService);
| |
| | |
| var hostLength = tld.getEffectiveTLDLength(hostname);
| |
| </pre>
| |
|
| |
|
| == Links == | | == Links == |