Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsIDNService Class Reference

#include <nsIDNService.h>

Inheritance diagram for nsIDNService:
Inheritance graph
[legend]
Collaboration diagram for nsIDNService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIIDNSERVICE
NS_DECL_NSIOBSERVER 
nsIDNService ()
virtual ~nsIDNService ()
nsresult Init ()
ACString convertUTF8toACE (in AUTF8String input)
 Prepares the input hostname according to IDNA ToASCII operation, the input hostname is assumed to be UTF8-encoded.
AUTF8String convertACEtoUTF8 (in ACString input)
 This is the ToUnicode operation as specified in the IDNA proposal, with an additional step to encode the result in UTF-8.
boolean isACE (in ACString input)
 Checks if the input string is ACE encoded or not.
AUTF8String normalize (in AUTF8String input)
 Performs the unicode normalization needed for hostnames in IDN, for callers that want early normalization.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Private Member Functions

void normalizeFullStops (nsAString &s)
nsresult stringPrepAndACE (const nsAString &in, nsACString &out)
nsresult encodeToACE (const nsAString &in, nsACString &out)
nsresult stringPrep (const nsAString &in, nsAString &out)
nsresult decodeACE (const nsACString &in, nsACString &out)
void prefsChanged (nsIPrefBranch *prefBranch, const PRUnichar *pref)

Private Attributes

PRBool mMultilingualTestBed
idn_nameprep_t mNamePrepHandle
nsCOMPtr< nsIUnicodeNormalizermNormalizer
char mACEPrefix [kACEPrefixLen+1]
nsXPIDLString mIDNBlacklist

Detailed Description

Definition at line 58 of file nsIDNService.h.


Constructor & Destructor Documentation

Definition at line 127 of file nsIDNService.cpp.

{
  nsresult rv;

  // initialize to the official prefix (RFC 3490 "5. ACE prefix")
  const char kIDNSPrefix[] = "xn--";
  strcpy(mACEPrefix, kIDNSPrefix);

  mMultilingualTestBed = PR_FALSE;

  if (idn_success != idn_nameprep_create(NULL, &mNamePrepHandle))
    mNamePrepHandle = nsnull;

  mNormalizer = do_GetService(NS_UNICODE_NORMALIZER_CONTRACTID, &rv);
  if (NS_FAILED(rv))
    mNormalizer = nsnull;
  /* member initializers and constructor code */
}

Here is the call graph for this function:

Definition at line 146 of file nsIDNService.cpp.

Here is the call graph for this function:


Member Function Documentation

AUTF8String nsIIDNService::convertACEtoUTF8 ( in ACString  input) [inherited]

This is the ToUnicode operation as specified in the IDNA proposal, with an additional step to encode the result in UTF-8.

It takes an ACE-encoded hostname and performs ToUnicode to it, then encodes the resulting string into UTF8.

ACString nsIIDNService::convertUTF8toACE ( in AUTF8String  input) [inherited]

Prepares the input hostname according to IDNA ToASCII operation, the input hostname is assumed to be UTF8-encoded.

The current input is string, but this may change pending Bug 84186.

nsresult nsIDNService::decodeACE ( const nsACString &  in,
nsACString &  out 
) [private]

Definition at line 531 of file nsIDNService.cpp.

{
  PRBool isAce;
  IsACE(in, &isAce);
  if (!isAce) {
    out.Assign(in);
    return NS_OK;
  }

  // RFC 3490 - 4.2 ToUnicode
  // The ToUnicode output never contains more code points than its input.
  punycode_uint output_length = in.Length() - kACEPrefixLen + 1;
  punycode_uint *output = new punycode_uint[output_length];
  NS_ENSURE_TRUE(output, NS_ERROR_OUT_OF_MEMORY);

  enum punycode_status status = punycode_decode(in.Length() - kACEPrefixLen,
                                                PromiseFlatCString(in).get() + kACEPrefixLen,
                                                &output_length,
                                                output,
                                                nsnull);
  if (status != punycode_success) {
    delete [] output;
    return NS_ERROR_FAILURE;
  }

  // UCS4 -> UTF8
  output[output_length] = 0;
  nsAutoString utf16;
  ucs4toUtf16(output, utf16);
  delete [] output;
  if (!isOnlySafeChars(utf16, mIDNBlacklist))
    return NS_ERROR_FAILURE;
  CopyUTF16toUTF8(utf16, out);

  // Validation: encode back to ACE and compare the strings
  nsCAutoString ace;
  nsresult rv = ConvertUTF8toACE(out, ace);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!ace.Equals(in, nsCaseInsensitiveCStringComparator()))
    return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsIDNService::encodeToACE ( const nsAString &  in,
nsACString &  out 
) [private]

Definition at line 461 of file nsIDNService.cpp.

{
  // RACE encode is supported for existing testing environment
  if (!strcmp("bq--", mACEPrefix))
    return encodeToRACE(mACEPrefix, in, out);
  
  // use punycoce
  return punycode(mACEPrefix, in, out);
}

Here is the call graph for this function:

Here is the caller graph for this function:

boolean nsIIDNService::isACE ( in ACString  input) [inherited]

Checks if the input string is ACE encoded or not.

AUTF8String nsIIDNService::normalize ( in AUTF8String  input) [inherited]

Performs the unicode normalization needed for hostnames in IDN, for callers that want early normalization.

void nsIDNService::normalizeFullStops ( nsAString &  s) [private]

Definition at line 509 of file nsIDNService.cpp.

{
  nsAString::const_iterator start, end;
  s.BeginReading(start); 
  s.EndReading(end); 
  PRInt32 index = 0;

  while (start != end) {
    switch (*start) {
      case 0x3002:
      case 0xFF0E:
      case 0xFF61:
        s.Replace(index, 1, NS_LITERAL_STRING("."));
        break;
      default:
        break;
    }
    start++;
    index++;
  }
}
void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.
void nsIDNService::prefsChanged ( nsIPrefBranch prefBranch,
const PRUnichar pref 
) [private]

Definition at line 102 of file nsIDNService.cpp.

{
  if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNTESTBED).Equals(pref)) {
    PRBool val;
    if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_IDNTESTBED, &val)))
      mMultilingualTestBed = val;
  }
  if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNPREFIX).Equals(pref)) {
    nsXPIDLCString prefix;
    nsresult rv = prefBranch->GetCharPref(NS_NET_PREF_IDNPREFIX, getter_Copies(prefix));
    if (NS_SUCCEEDED(rv) && prefix.Length() <= kACEPrefixLen)
      PL_strncpyz(nsIDNService::mACEPrefix, prefix.get(), kACEPrefixLen + 1);
  }
  if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNBLACKLIST).Equals(pref)) {
    nsCOMPtr<nsISupportsString> blacklist;
    nsresult rv = prefBranch->GetComplexValue(NS_NET_PREF_IDNBLACKLIST,
                                              NS_GET_IID(nsISupportsString),
                                              getter_AddRefs(blacklist));
    if (NS_SUCCEEDED(rv))
      blacklist->ToString(getter_Copies(mIDNBlacklist));
    else
      mIDNBlacklist.Truncate();
  }
}

Here is the call graph for this function:

nsresult nsIDNService::stringPrep ( const nsAString &  in,
nsAString &  out 
) [private]

Definition at line 413 of file nsIDNService.cpp.

{
  if (!mNamePrepHandle || !mNormalizer)
    return NS_ERROR_FAILURE;

  nsresult rv = NS_OK;
  PRUint32 ucs4Buf[kMaxDNSNodeLen + 1];
  PRUint32 ucs4Len;
  utf16ToUcs4(in, ucs4Buf, kMaxDNSNodeLen, &ucs4Len);

  // map
  idn_result_t idn_err;

  PRUint32 namePrepBuf[kMaxDNSNodeLen * 3];   // map up to three characters
  idn_err = idn_nameprep_map(mNamePrepHandle, (const PRUint32 *) ucs4Buf,
                                   (PRUint32 *) namePrepBuf, kMaxDNSNodeLen * 3);
  NS_ENSURE_TRUE(idn_err == idn_success, NS_ERROR_FAILURE);

  nsAutoString namePrepStr;
  ucs4toUtf16(namePrepBuf, namePrepStr);
  if (namePrepStr.Length() >= kMaxDNSNodeLen)
    return NS_ERROR_FAILURE;

  // normalize
  nsAutoString normlizedStr;
  rv = mNormalizer->NormalizeUnicodeNFKC(namePrepStr, normlizedStr);
  if (normlizedStr.Length() >= kMaxDNSNodeLen)
    return NS_ERROR_FAILURE;

  // prohibit
  const PRUint32 *found = nsnull;
  idn_err = idn_nameprep_isprohibited(mNamePrepHandle, 
                                      (const PRUint32 *) ucs4Buf, &found);
  if (idn_err != idn_success || found)
    return NS_ERROR_FAILURE;

  // check bidi
  idn_err = idn_nameprep_isvalidbidi(mNamePrepHandle, 
                                     (const PRUint32 *) ucs4Buf, &found);
  if (idn_err != idn_success || found)
    return NS_ERROR_FAILURE;

  // set the result string
  out.Assign(normlizedStr);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsIDNService::stringPrepAndACE ( const nsAString &  in,
nsACString &  out 
) [private]

Definition at line 471 of file nsIDNService.cpp.

{
  nsresult rv = NS_OK;

  out.Truncate();

  if (in.Length() > kMaxDNSNodeLen) {
    NS_ERROR("IDN node too large");
    return NS_ERROR_FAILURE;
  }

  if (IsASCII(in))
    CopyUCS2toASCII(in, out);
  else {
    nsAutoString strPrep;
    rv = stringPrep(in, strPrep);
    if (NS_SUCCEEDED(rv)) {
      if (IsASCII(strPrep))
        CopyUCS2toASCII(strPrep, out);
      else
        rv = encodeToACE(strPrep, out);
    }
  }

  if (out.Length() > kMaxDNSNodeLen) {
    NS_ERROR("IDN node too large");
    return NS_ERROR_FAILURE;
  }

  return rv;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 83 of file nsIDNService.h.

Definition at line 84 of file nsIDNService.h.

Definition at line 80 of file nsIDNService.h.

Definition at line 81 of file nsIDNService.h.

Definition at line 82 of file nsIDNService.h.


The documentation for this class was generated from the following files: