// RFC 3454 // // 1) Map -- For each character in the input, check if it has a mapping // and, if so, replace it with its mapping. This is described in section 3. // // 2) Normalize -- Possibly normalize the result of step 1 using Unicode // normalization. This is described in section 4. // // 3) Prohibit -- Check for any characters that are not allowed in the // output. If any are found, return an error. This is described in section // 5. // // 4) Check bidi -- Possibly check for right-to-left characters, and if any // are found, make sure that the whole string satisfies the requirements // for bidirectional strings. If the string does not satisfy the requirements // for bidirectional strings, return an error. This is described in section 6. // // 5) Check unassigned code points -- If allowUnassigned is false, check for // any unassigned Unicode points and if any are found return an error. // This is described in section 7. // nsresult nsIDNService::stringPrep(const nsAString& in, nsAString& out, bool allowUnassigned) { if (!mNamePrepHandle || !mNormalizer) return NS_ERROR_FAILURE; nsresult rv = NS_OK; uint32_t ucs4Buf[kMaxDNSNodeLen + 1]; uint32_t ucs4Len; utf16ToUcs4(in, ucs4Buf, kMaxDNSNodeLen, &ucs4Len); // map idn_result_t idn_err; uint32_t namePrepBuf[kMaxDNSNodeLen * 3]; // map up to three characters idn_err = idn_nameprep_map(mNamePrepHandle, (const uint32_t *) ucs4Buf, (uint32_t *) 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 uint32_t *found = nullptr; idn_err = idn_nameprep_isprohibited(mNamePrepHandle, (const uint32_t *) ucs4Buf, &found); if (idn_err != idn_success || found) return NS_ERROR_FAILURE; // check bidi idn_err = idn_nameprep_isvalidbidi(mNamePrepHandle, (const uint32_t *) ucs4Buf, &found); if (idn_err != idn_success || found) return NS_ERROR_FAILURE; if (!allowUnassigned) { // check unassigned code points idn_err = idn_nameprep_isunassigned(mNamePrepHandle, (const uint32_t *) ucs4Buf, &found); if (idn_err != idn_success || found) return NS_ERROR_FAILURE; } // set the result string out.Assign(normlizedStr); return rv; }
idn_result_t idn_nameprep_mapproc(void *handle, const PRUint32 *from, PRUint32 *to, size_t tolen) { return idn_nameprep_map((idn_nameprep_t)handle, from, to, tolen); }
idn_result_t idn_nameprep_mapproc(void *handle, const unsigned long *from, unsigned long *to, size_t tolen) { return idn_nameprep_map((idn_nameprep_t)handle, from, to, tolen); }