Bug 71247, provide scriptable UTF8 encoders in nsILDAPService. r=dmose,

sr=mscott, a=asa@mozilla.org, patch=leif@netscape.com.
This commit is contained in:
leif%netscape.com 2001-06-20 03:35:55 +00:00
Родитель 9d35ed31a4
Коммит 6140b5aece
4 изменённых файлов: 86 добавлений и 3 удалений

Просмотреть файл

@ -208,4 +208,30 @@ interface nsILDAPService : nsISupports {
AString createFilter(in unsigned long aMaxSize, in AString aPattern,
in AString aPrefix, in AString aSuffix,
in AString aAttr, in AString aValue);
/**
* Convert a Unicode string (AString) to a single byte string, using
* UTF8 encoding. This is used to pass UTF8 encoded strings into the
* nsILDAPURL interface for instance. Note that this method will go
* away (hopefully) once we have a real solution (see bug 84186).
*
* @param aString Unicode string to be converted
* @return UTF8 encoded string, single byte
*
* @exception NS_ERROR_NULL_POINTER NULL pointer
* @exception NS_ERROR_OUT_OF_MEMORY ran out of memory
*/
string UCS2toUTF8(in AString aString);
/**
* Convert a UTF8 string (|string|) to a Unicode (|AString|) string.
* Note that this method will go away (hopefully) once we have a
* real solution (see bug 84186).
*
* @param string UTF8 string to be converted
* @return Unicode string
*
* @exception NS_ERROR_OUT_OF_MEMORY ran out of memory
*/
AString UTF8toUCS2(in string aString);
};

Просмотреть файл

@ -35,11 +35,27 @@
#include "nsIURI.idl"
/**
* Strings in methods inherited from nsIURI, which are using XPIDL
* |string| types, are expected to be UTF8 encoded. All such strings
* in this interface, except attribute types (e.g. "cn"), should in fact
* be UTF8. It's important to remember that attributes can not be UTF8,
* they can only be of a limited subset of ASCII (see RFC 2251).
*
* Currently we deal with this encoding using two little helper methods
* in the nsILDAPService interface, |UTF8toUCS2()| and |UCS2toUTF8|,
* which are both scriptable. This will hopefully go away once a real
* solution is implemented, see bug 84186 for more details.
*
* FYI, ASCII is a subset of UTF8.
*/
[scriptable, uuid(7310562d-1567-43c7-a123-633c1ba3663e)]
interface nsILDAPURL : nsIURI {
/**
* The distinguished name of the URL (ie the base DN for the search)
* The distinguished name of the URL (ie the base DN for the search).
* This string is expected to be a valid UTF8 string.
*
* for the getter:
*

Просмотреть файл

@ -788,9 +788,9 @@ nsLDAPChannel::OnLDAPBind(nsILDAPMessage *aMessage)
//
PR_LOG(gLDAPLogModule, PR_LOG_DEBUG,
("bind completed; starting search\n"));
rv = mCurrentOperation->SearchExt(NS_ConvertASCIItoUCS2(baseDn).get(),
rv = mCurrentOperation->SearchExt(NS_ConvertUTF8toUCS2(baseDn).get(),
scope,
NS_ConvertASCIItoUCS2(filter).get(),
NS_ConvertUTF8toUCS2(filter).get(),
0, 0,
0, LDAP_NO_LIMIT);
NS_ENSURE_SUCCESS(rv,rv);

Просмотреть файл

@ -1004,3 +1004,44 @@ nsLDAPService::NextToken(nsReadingIterator<PRUnichar> & aIter,
return token.ToNewCString();
}
// Note that these 2 functions might go away in the future, see bug 84186.
//
// string UCS2ToUTF8 (in AString aString);
NS_IMETHODIMP
nsLDAPService::UCS2toUTF8(const nsAReadableString &aString,
char **_retval)
{
char *str;
if (!_retval) {
NS_ERROR("nsLDAPService::UCS2toUTF8: null pointer ");
return NS_ERROR_NULL_POINTER;
}
str = NS_ConvertUCS2toUTF8(aString).ToNewCString();
if (!str) {
NS_ERROR("nsLDAPService::UCS2toUTF8: out of memory ");
return NS_ERROR_OUT_OF_MEMORY;
}
*_retval = str;
return NS_OK;
}
// AString UTF8ToUCS2 (in string aString);
NS_IMETHODIMP
nsLDAPService::UTF8toUCS2(const char *aString,
nsAWritableString &_retval)
{
PRUnichar *str;
str = NS_ConvertUTF8toUCS2(aString).ToNewUnicode();
if (!str) {
NS_ERROR("nsLDAPService::UTF8toUCS2: out of memory ");
return NS_ERROR_OUT_OF_MEMORY;
}
_retval = str;
return NS_OK;
}