From e2d009106ca9cf053939c04f07b3b6d0f33d0575 Mon Sep 17 00:00:00 2001 From: "jshin%mailaps.org" Date: Fri, 3 Jun 2005 02:21:47 +0000 Subject: [PATCH] bug 236425: fix IDN support on 64bit platforms (r=darin, sr=bz, a=chofmann) --- netwerk/dns/src/nameprep.c | 52 ++++++++++++++--------------- netwerk/dns/src/nameprep_template.c | 10 +++--- netwerk/dns/src/nsIDNKitInterface.h | 24 +++++++------ netwerk/dns/src/nsIDNService.cpp | 10 +++--- netwerk/dns/src/race.c | 14 ++++---- 5 files changed, 57 insertions(+), 53 deletions(-) diff --git a/netwerk/dns/src/nameprep.c b/netwerk/dns/src/nameprep.c index 3ab8c327c08..c4274f7ec53 100644 --- a/netwerk/dns/src/nameprep.c +++ b/netwerk/dns/src/nameprep.c @@ -64,9 +64,9 @@ #include "nameprep_template.c" #undef VERSION -typedef const char *(*nameprep_mapproc)(unsigned long v); -typedef int (*nameprep_checkproc)(unsigned long v); -typedef idn_biditype_t (*nameprep_biditypeproc)(unsigned long v); +typedef const char *(*nameprep_mapproc)(PRUint32 v); +typedef int (*nameprep_checkproc)(PRUint32 v); +typedef idn_biditype_t (*nameprep_biditypeproc)(PRUint32 v); static struct idn_nameprep { char *version; @@ -86,8 +86,8 @@ static struct idn_nameprep { }; static idn_result_t idn_nameprep_check(nameprep_checkproc proc, - const unsigned long *str, - const unsigned long **found); + const PRUint32 *str, + const PRUint32 **found); idn_result_t idn_nameprep_create(const char *version, idn_nameprep_t *handlep) { @@ -125,15 +125,15 @@ idn_nameprep_destroy(idn_nameprep_t handle) { } idn_result_t -idn_nameprep_map(idn_nameprep_t handle, const unsigned long *from, - unsigned long *to, size_t tolen) { +idn_nameprep_map(idn_nameprep_t handle, const PRUint32 *from, + PRUint32 *to, size_t tolen) { assert(handle != NULL && from != NULL && to != NULL); TRACE(("idn_nameprep_map(ctx=%s, from=\"%s\")\n", handle->version, idn__debug_ucs4xstring(from, 50))); while (*from != '\0') { - unsigned long v = *from; + PRUint32 v = *from; const char *mapped; if (v > UCS_MAX) { @@ -189,8 +189,8 @@ idn_nameprep_map(idn_nameprep_t handle, const unsigned long *from, } idn_result_t -idn_nameprep_isprohibited(idn_nameprep_t handle, const unsigned long *str, - const unsigned long **found) { +idn_nameprep_isprohibited(idn_nameprep_t handle, const PRUint32 *str, + const PRUint32 **found) { assert(handle != NULL && str != NULL && found != NULL); TRACE(("idn_nameprep_isprohibited(ctx=%s, str=\"%s\")\n", @@ -200,8 +200,8 @@ idn_nameprep_isprohibited(idn_nameprep_t handle, const unsigned long *str, } idn_result_t -idn_nameprep_isunassigned(idn_nameprep_t handle, const unsigned long *str, - const unsigned long **found) { +idn_nameprep_isunassigned(idn_nameprep_t handle, const PRUint32 *str, + const PRUint32 **found) { assert(handle != NULL && str != NULL && found != NULL); TRACE(("idn_nameprep_isunassigned(handle->version, str=\"%s\")\n", @@ -211,9 +211,9 @@ idn_nameprep_isunassigned(idn_nameprep_t handle, const unsigned long *str, } static idn_result_t -idn_nameprep_check(nameprep_checkproc proc, const unsigned long *str, - const unsigned long **found) { - unsigned long v; +idn_nameprep_check(nameprep_checkproc proc, const PRUint32 *str, + const PRUint32 **found) { + PRUint32 v; while (*str != '\0') { v = *str; @@ -236,9 +236,9 @@ idn_nameprep_check(nameprep_checkproc proc, const unsigned long *str, } idn_result_t -idn_nameprep_isvalidbidi(idn_nameprep_t handle, const unsigned long *str, - const unsigned long **found) { - unsigned long v; +idn_nameprep_isvalidbidi(idn_nameprep_t handle, const PRUint32 *str, + const PRUint32 **found) { + PRUint32 v; idn_biditype_t first_char; idn_biditype_t last_char; int found_r_al; @@ -323,25 +323,25 @@ idn_nameprep_destroyproc(void *handle) { } idn_result_t -idn_nameprep_mapproc(void *handle, const unsigned long *from, - unsigned long *to, size_t tolen) { +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_prohibitproc(void *handle, const unsigned long *str, - const unsigned long **found) { +idn_nameprep_prohibitproc(void *handle, const PRUint32 *str, + const PRUint32 **found) { return idn_nameprep_isprohibited((idn_nameprep_t)handle, str, found); } idn_result_t -idn_nameprep_unassignedproc(void *handle, const unsigned long *str, - const unsigned long **found) { +idn_nameprep_unassignedproc(void *handle, const PRUint32 *str, + const PRUint32 **found) { return idn_nameprep_isunassigned((idn_nameprep_t)handle, str, found); } idn_result_t -idn_nameprep_bidiproc(void *handle, const unsigned long *str, - const unsigned long **found) { +idn_nameprep_bidiproc(void *handle, const PRUint32 *str, + const PRUint32 **found) { return idn_nameprep_isvalidbidi((idn_nameprep_t)handle, str, found); } diff --git a/netwerk/dns/src/nameprep_template.c b/netwerk/dns/src/nameprep_template.c index 3ebbf7e3a06..f5ee38788f9 100644 --- a/netwerk/dns/src/nameprep_template.c +++ b/netwerk/dns/src/nameprep_template.c @@ -48,6 +48,8 @@ #ifndef NAMEPREP_TEMPLATE_INIT #define NAMEPREP_TEMPLATE_INIT +#include "prtypes.h" + /* Symbol composition. */ #define compose_sym2(a, b) compose_sym2X(a, b) #define compose_sym2X(a, b) a ## b @@ -73,7 +75,7 @@ #endif /* NAMEPREP_TEMPLATE_INIT */ static const char * -compose_sym2(nameprep_map_, VERSION) (unsigned long v) { +compose_sym2(nameprep_map_, VERSION) (PRUint32 v) { int idx0 = IDX0(MAP, v); int idx1 = IDX1(MAP, v); int idx2 = IDX2(MAP, v); @@ -92,7 +94,7 @@ compose_sym2(nameprep_map_, VERSION) (unsigned long v) { } static int -compose_sym2(nameprep_prohibited_, VERSION) (unsigned long v) { +compose_sym2(nameprep_prohibited_, VERSION) (PRUint32 v) { int idx0 = IDX0(PROH, v); int idx1 = IDX1(PROH, v); int idx2 = IDX2(PROH, v); @@ -107,7 +109,7 @@ compose_sym2(nameprep_prohibited_, VERSION) (unsigned long v) { } static int -compose_sym2(nameprep_unassigned_, VERSION) (unsigned long v) { +compose_sym2(nameprep_unassigned_, VERSION) (PRUint32 v) { int idx0 = IDX0(UNAS, v); int idx1 = IDX1(UNAS, v); int idx2 = IDX2(UNAS, v); @@ -122,7 +124,7 @@ compose_sym2(nameprep_unassigned_, VERSION) (unsigned long v) { } static idn_biditype_t -compose_sym2(nameprep_biditype_, VERSION) (unsigned long v) { +compose_sym2(nameprep_biditype_, VERSION) (PRUint32 v) { int idx0 = IDX0(BIDI, v); int idx1 = IDX1(BIDI, v); int idx2 = IDX2(BIDI, v); diff --git a/netwerk/dns/src/nsIDNKitInterface.h b/netwerk/dns/src/nsIDNKitInterface.h index a65ca7ef874..2dc5ad1482c 100644 --- a/netwerk/dns/src/nsIDNKitInterface.h +++ b/netwerk/dns/src/nsIDNKitInterface.h @@ -47,6 +47,8 @@ extern "C" { #endif /* __cplusplus */ +#include "prtypes.h" + /* * libidnkit result code. */ @@ -96,12 +98,12 @@ typedef struct idn_nameprep *idn_nameprep_t; /* race.c */ idn_result_t race_decode_decompress(const char *from, - unsigned short *buf, + PRUint16 *buf, size_t buflen); -idn_result_t race_compress_encode(const unsigned short *p, +idn_result_t race_compress_encode(const PRUint16 *p, int compress_mode, char *to, size_t tolen); -int get_compress_mode(unsigned short *p); +int get_compress_mode(PRUint16 *p); /* nameprep.c */ @@ -136,8 +138,8 @@ idn_nameprep_destroy(idn_nameprep_t handle); * idn_buffer_overflow -- result buffer is too small. */ idn_result_t -idn_nameprep_map(idn_nameprep_t handle, const unsigned long *from, - unsigned long *to, size_t tolen); +idn_nameprep_map(idn_nameprep_t handle, const PRUint32 *from, + PRUint32 *to, size_t tolen); /* * Check if an UCS4 string 'str' contains any prohibited characters specified @@ -151,8 +153,8 @@ idn_nameprep_map(idn_nameprep_t handle, const unsigned long *from, * result.) */ idn_result_t -idn_nameprep_isprohibited(idn_nameprep_t handle, const unsigned long *str, - const unsigned long **found); +idn_nameprep_isprohibited(idn_nameprep_t handle, const PRUint32 *str, + const PRUint32 **found); /* * Check if an UCS4 string 'str' contains any unassigned characters specified @@ -166,8 +168,8 @@ idn_nameprep_isprohibited(idn_nameprep_t handle, const unsigned long *str, * result.) */ idn_result_t -idn_nameprep_isunassigned(idn_nameprep_t handle, const unsigned long *str, - const unsigned long **found); +idn_nameprep_isunassigned(idn_nameprep_t handle, const PRUint32 *str, + const PRUint32 **found); /* * Check if an UCS4 string 'str' is valid string specified by ``bidi check'' @@ -180,8 +182,8 @@ idn_nameprep_isunassigned(idn_nameprep_t handle, const unsigned long *str, * Check '*found' to see the result.) */ idn_result_t -idn_nameprep_isvalidbidi(idn_nameprep_t handle, const unsigned long *str, - const unsigned long **found); +idn_nameprep_isvalidbidi(idn_nameprep_t handle, const PRUint32 *str, + const PRUint32 **found); diff --git a/netwerk/dns/src/nsIDNService.cpp b/netwerk/dns/src/nsIDNService.cpp index b83b24bdf27..3970e8f0677 100644 --- a/netwerk/dns/src/nsIDNService.cpp +++ b/netwerk/dns/src/nsIDNService.cpp @@ -397,8 +397,8 @@ nsresult nsIDNService::stringPrep(const nsAString& in, nsAString& out) idn_result_t idn_err; PRUint32 namePrepBuf[kMaxDNSNodeLen * 3]; // map up to three characters - idn_err = idn_nameprep_map(mNamePrepHandle, (const unsigned long*) ucs4Buf, - (unsigned long*) namePrepBuf, kMaxDNSNodeLen * 3); + 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; @@ -413,15 +413,15 @@ nsresult nsIDNService::stringPrep(const nsAString& in, nsAString& out) return NS_ERROR_FAILURE; // prohibit - const unsigned long *found = nsnull; + const PRUint32 *found = nsnull; idn_err = idn_nameprep_isprohibited(mNamePrepHandle, - (const unsigned long*) ucs4Buf, &found); + (const PRUint32 *) ucs4Buf, &found); if (idn_err != idn_success || found) return NS_ERROR_FAILURE; // check bidi idn_err = idn_nameprep_isvalidbidi(mNamePrepHandle, - (const unsigned long*) ucs4Buf, &found); + (const PRUint32 *) ucs4Buf, &found); if (idn_err != idn_success || found) return NS_ERROR_FAILURE; diff --git a/netwerk/dns/src/race.c b/netwerk/dns/src/race.c index d3ab6caf4f8..a7973d7af75 100644 --- a/netwerk/dns/src/race.c +++ b/netwerk/dns/src/race.c @@ -64,9 +64,9 @@ enum { idn_result_t -race_decode_decompress(const char *from, unsigned short *buf, size_t buflen) +race_decode_decompress(const char *from, PRUint16 *buf, size_t buflen) { - unsigned short *p = buf; + PRUint16 *p = buf; unsigned int bitbuf = 0; int bitlen = 0; unsigned int i, j; @@ -108,7 +108,7 @@ race_decode_decompress(const char *from, unsigned short *buf, size_t buflen) buf[j] = (buf[i] << 8) + buf[i + 1]; len = j; } else { - unsigned short c = buf[0] << 8; /* higher octet */ + PRUint16 c = buf[0] << 8; /* higher octet */ for (i = 1, j = 0; i < len; j++) { if (buf[i] == RACE_ESCAPE) { @@ -138,10 +138,10 @@ race_decode_decompress(const char *from, unsigned short *buf, size_t buflen) } idn_result_t -race_compress_encode(const unsigned short *p, int compress_mode, +race_compress_encode(const PRUint16 *p, int compress_mode, char *to, size_t tolen) { - unsigned long bitbuf = *p++; /* bit stream buffer */ + PRUint32 bitbuf = *p++; /* bit stream buffer */ int bitlen = 8; /* # of bits in 'bitbuf' */ while (*p != '\0' || bitlen > 0) { @@ -208,10 +208,10 @@ race_compress_encode(const unsigned short *p, int compress_mode, } int -get_compress_mode(unsigned short *p) { +get_compress_mode(PRUint16 *p) { int zero = 0; unsigned int upper = 0; - unsigned short *modepos = p - 1; + PRUint16 *modepos = p - 1; while (*p != '\0') { unsigned int hi = *p++ & 0xff00;