зеркало из https://github.com/mozilla/pjs.git
Changed LDAP XPCOM SDK to use "wstring" instead of "string", bug 71247.
r=dmose@netscape.com sr=mscott@netscape.com
This commit is contained in:
Родитель
7f779cec7b
Коммит
6dc106b7ae
|
@ -42,14 +42,14 @@ interface nsILDAPConnection : nsISupports
|
|||
/**
|
||||
* the string version of lderrno
|
||||
*/
|
||||
readonly attribute string errorString;
|
||||
readonly attribute wstring errorString;
|
||||
|
||||
/**
|
||||
* DN to bind as. use the init() method to set this.
|
||||
*
|
||||
* @exception NS_ERROR_OUT_OF_MEMORY
|
||||
*/
|
||||
readonly attribute string bindName;
|
||||
readonly attribute wstring bindName;
|
||||
|
||||
/**
|
||||
* set up the connection.
|
||||
|
@ -65,7 +65,7 @@ interface nsILDAPConnection : nsISupports
|
|||
* @exception NS_ERROR_FAILURE
|
||||
* @exception NS_ERROR_UNEXPECTED internal error
|
||||
*/
|
||||
void init(in string aHost, in short aPort, in string aBindName);
|
||||
void init(in string aHost, in short aPort, in wstring aBindName);
|
||||
|
||||
/**
|
||||
* Get information about the last error that occured on this connection.
|
||||
|
@ -80,7 +80,6 @@ interface nsILDAPConnection : nsISupports
|
|||
*
|
||||
* @return the error code, as defined in nsILDAPErrors.idl
|
||||
*/
|
||||
long getLdErrno(out string matched, out string s);
|
||||
long getLdErrno(out wstring matched, out wstring s);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ interface nsILDAPMessage : nsISupports
|
|||
* @exception NS_ERROR_LDAP_DECODING_ERROR problem during BER-decoding
|
||||
* @exception NS_ERROR_UNEXPECTED bug or memory corruption
|
||||
*/
|
||||
readonly attribute string dn;
|
||||
readonly attribute wstring dn;
|
||||
|
||||
/**
|
||||
* Get all the attributes in this message.
|
||||
|
@ -74,7 +74,7 @@ interface nsILDAPMessage : nsISupports
|
|||
* @exception NS_ERROR_OUT_OF_MEMORY
|
||||
*/
|
||||
void getValues(in string attr, out unsigned long count,
|
||||
[retval, array, size_is(count)] out string values);
|
||||
[retval, array, size_is(count)] out wstring values);
|
||||
|
||||
/**
|
||||
* The operation this message originated from
|
||||
|
|
|
@ -98,7 +98,7 @@ interface nsILDAPOperation : nsISupports
|
|||
* @exception NS_ERROR_OUT_OF_MEMORY ran out of memory
|
||||
* @exception NS_ERROR_UNEXPECTED internal error
|
||||
*/
|
||||
void simpleBind(in string passwd);
|
||||
void simpleBind(in wstring passwd);
|
||||
|
||||
/**
|
||||
* Kicks off an asynchronous search request. The "ext" stands for
|
||||
|
@ -121,8 +121,8 @@ interface nsILDAPOperation : nsISupports
|
|||
*
|
||||
* XXX doesn't currently handle LDAPControl params
|
||||
*/
|
||||
void searchExt(in string aBaseDn, in PRInt32 aScope,
|
||||
in string aFilter, in PRIntervalTime aTimeOut,
|
||||
void searchExt(in wstring aBaseDn, in PRInt32 aScope,
|
||||
in wstring aFilter, in PRIntervalTime aTimeOut,
|
||||
in PRInt32 aSizeLimit);
|
||||
|
||||
/**
|
||||
|
|
|
@ -785,7 +785,10 @@ nsLDAPChannel::OnLDAPBind(nsILDAPMessage *aMessage)
|
|||
//
|
||||
PR_LOG(gLDAPLogModule, PR_LOG_DEBUG,
|
||||
("bind completed; starting search\n"));
|
||||
rv = mCurrentOperation->SearchExt(baseDn, scope, filter, 0, LDAP_NO_LIMIT);
|
||||
rv = mCurrentOperation->SearchExt(NS_ConvertASCIItoUCS2(baseDn).get(),
|
||||
scope,
|
||||
NS_ConvertASCIItoUCS2(filter).get(),
|
||||
0, LDAP_NO_LIMIT);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -860,8 +863,8 @@ nsresult
|
|||
nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString dn;
|
||||
nsCString entry;
|
||||
nsXPIDLString dn;
|
||||
nsString entry;
|
||||
|
||||
PR_LOG(gLDAPLogModule, PR_LOG_DEBUG, ("entry returned!\n"));
|
||||
|
||||
|
@ -872,8 +875,8 @@ nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
entry.SetCapacity(256);
|
||||
entry = NS_LITERAL_CSTRING("dn: ") + nsLiteralCString(dn)
|
||||
+ NS_LITERAL_CSTRING("\n");
|
||||
entry = NS_LITERAL_STRING("dn: ") + nsLiteralString(dn)
|
||||
+ NS_LITERAL_STRING("\n");
|
||||
|
||||
char **attrs;
|
||||
PRUint32 attrCount;
|
||||
|
@ -894,7 +897,7 @@ nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
|||
//
|
||||
for ( PRUint32 i=0 ; i < attrCount ; i++ ) {
|
||||
|
||||
char **vals;
|
||||
PRUnichar **vals;
|
||||
PRUint32 valueCount;
|
||||
|
||||
// get the values of this attribute
|
||||
|
@ -911,10 +914,10 @@ nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
|||
// print all values of this attribute
|
||||
//
|
||||
for ( PRUint32 j=0 ; j < valueCount; j++ ) {
|
||||
entry.Append(attrs[i]);
|
||||
entry.Append(": ");
|
||||
entry.Append(NS_ConvertASCIItoUCS2(attrs[i]).ToNewUnicode());
|
||||
entry.Append(NS_LITERAL_STRING(": "));
|
||||
entry.Append(vals[j]);
|
||||
entry.Append("\n");
|
||||
entry.Append(NS_LITERAL_STRING("\n"));
|
||||
}
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(valueCount, vals);
|
||||
|
||||
|
@ -931,7 +934,7 @@ nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
|||
|
||||
// separate this entry from the next
|
||||
//
|
||||
entry.Append("\n");
|
||||
entry.Append(NS_LITERAL_STRING("\n"));
|
||||
|
||||
// do the write
|
||||
// XXX better err handling
|
||||
|
@ -939,7 +942,8 @@ nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
|||
PRUint32 bytesWritten = 0;
|
||||
PRUint32 entryLength = entry.Length();
|
||||
|
||||
rv = mReadPipeOut->Write(entry, entryLength, &bytesWritten);
|
||||
rv = mReadPipeOut->Write(NS_ConvertUCS2toUTF8(entry).get(),
|
||||
entryLength, &bytesWritten);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// short writes shouldn't happen on blocking pipes!
|
||||
|
|
|
@ -85,7 +85,8 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsLDAPConnection, nsILDAPConnection,
|
|||
nsIRunnable);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, const char *aBindName)
|
||||
nsLDAPConnection::Init(const char *aHost, PRInt16 aPort,
|
||||
const PRUnichar *aBindName)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -109,7 +110,7 @@ nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, const char *aBindName)
|
|||
// need to go through these contortions.
|
||||
//
|
||||
if (aBindName) {
|
||||
mBindName = new nsCString(aBindName);
|
||||
mBindName = new nsString(aBindName);
|
||||
if (!mBindName) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -168,7 +169,7 @@ nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, const char *aBindName)
|
|||
//
|
||||
// readonly attribute string bindName
|
||||
NS_IMETHODIMP
|
||||
nsLDAPConnection::GetBindName(char **_retval)
|
||||
nsLDAPConnection::GetBindName(PRUnichar **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
|
@ -180,7 +181,7 @@ nsLDAPConnection::GetBindName(char **_retval)
|
|||
|
||||
// otherwise, hand out a copy of the bind name
|
||||
//
|
||||
*_retval = mBindName->ToNewCString();
|
||||
*_retval = mBindName->ToNewUnicode();
|
||||
if (!(*_retval)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -193,12 +194,16 @@ nsLDAPConnection::GetBindName(char **_retval)
|
|||
// XXX should copy before returning
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsLDAPConnection::GetLdErrno(char **matched, char **errString,
|
||||
nsLDAPConnection::GetLdErrno(PRUnichar **matched, PRUnichar **errString,
|
||||
PRInt32 *_retval)
|
||||
{
|
||||
char *match, *err;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
*_retval = ldap_get_lderrno(mConnectionHandle, matched, errString);
|
||||
*_retval = ldap_get_lderrno(mConnectionHandle, &match, &err);
|
||||
*matched = NS_ConvertUTF8toUCS2(match).ToNewUnicode();
|
||||
*errString = NS_ConvertUTF8toUCS2(err).ToNewUnicode();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -209,7 +214,7 @@ nsLDAPConnection::GetLdErrno(char **matched, char **errString,
|
|||
// XXX - how does ldap_perror know to look at the global errno?
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsLDAPConnection::GetErrorString(char **_retval)
|
||||
nsLDAPConnection::GetErrorString(PRUnichar **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
|
@ -222,7 +227,7 @@ nsLDAPConnection::GetErrorString(char **_retval)
|
|||
|
||||
// make a copy using the XPCOM shared allocator
|
||||
//
|
||||
*_retval = nsCRT::strdup(rv);
|
||||
*_retval = NS_ConvertUTF8toUCS2(rv).ToNewUnicode();
|
||||
if (!*_retval) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ class nsLDAPConnection : public nsILDAPConnection, nsIRunnable
|
|||
|
||||
|
||||
LDAP *mConnectionHandle; // the LDAP C SDK's connection object
|
||||
nsCString *mBindName; // who to bind as
|
||||
nsString *mBindName; // who to bind as
|
||||
nsCOMPtr<nsIThread> mThread; // thread which marshals results
|
||||
|
||||
nsSupportsHashtable *mPendingOperations; // keep these around for callbacks
|
||||
|
|
|
@ -432,16 +432,16 @@ nsLDAPMessage::IterateAttributes(PRUint32 *aAttrCount, char** *aAttributes,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLDAPMessage::GetDn(char* *aDN)
|
||||
// readonly attribute wstring dn;
|
||||
NS_IMETHODIMP nsLDAPMessage::GetDn(PRUnichar **aDn)
|
||||
{
|
||||
if (!aDN) {
|
||||
if (!aDn) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
char *dn = ldap_get_dn(mConnectionHandle, mMsgHandle);
|
||||
|
||||
if (!dn) {
|
||||
char *rawDn = ldap_get_dn(mConnectionHandle, mMsgHandle);
|
||||
|
||||
if (!rawDn) {
|
||||
PRInt32 lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0);
|
||||
|
||||
switch (lderrno) {
|
||||
|
@ -459,10 +459,11 @@ nsLDAPMessage::GetDn(char* *aDN)
|
|||
|
||||
// get a copy made with the shared allocator, and dispose of the original
|
||||
//
|
||||
*aDN = nsCRT::strdup(dn);
|
||||
ldap_memfree(dn);
|
||||
|
||||
if (!*aDN) {
|
||||
*aDn = NS_ConvertUTF8toUCS2(rawDn).ToNewUnicode();
|
||||
ldap_memfree(rawDn);
|
||||
|
||||
if (!*aDn) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -473,7 +474,7 @@ nsLDAPMessage::GetDn(char* *aDN)
|
|||
//
|
||||
NS_IMETHODIMP
|
||||
nsLDAPMessage::GetValues(const char *aAttr, PRUint32 *aCount,
|
||||
char** *aValues)
|
||||
PRUnichar ***aValues)
|
||||
{
|
||||
char **values;
|
||||
|
||||
|
@ -504,8 +505,8 @@ nsLDAPMessage::GetValues(const char *aAttr, PRUint32 *aCount,
|
|||
|
||||
// create an array of the appropriate size
|
||||
//
|
||||
*aValues = NS_STATIC_CAST(char **,
|
||||
nsMemory::Alloc(numVals * sizeof(char *)));
|
||||
*aValues = NS_STATIC_CAST(PRUnichar **,
|
||||
nsMemory::Alloc(numVals * sizeof(PRUnichar *)));
|
||||
if (!*aValues) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -515,7 +516,7 @@ nsLDAPMessage::GetValues(const char *aAttr, PRUint32 *aCount,
|
|||
//
|
||||
PRUint32 i;
|
||||
for ( i = 0 ; i < numVals ; i++ ) {
|
||||
(*aValues)[i] = nsCRT::strdup(values[i]);
|
||||
(*aValues)[i] = NS_ConvertUTF8toUCS2(values[i]).ToNewUnicode();
|
||||
if ( ! (*aValues)[i] ) {
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, aValues);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
|
@ -114,10 +114,10 @@ nsLDAPOperation::GetMessageListener(nsILDAPMessageListener **aMessageListener)
|
|||
// wrapper for ldap_simple_bind()
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsLDAPOperation::SimpleBind(const char *passwd)
|
||||
nsLDAPOperation::SimpleBind(const PRUnichar *passwd)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString bindName;
|
||||
nsXPIDLString bindName;
|
||||
|
||||
NS_PRECONDITION(mMessageListener != 0, "MessageListener not set");
|
||||
|
||||
|
@ -125,7 +125,9 @@ nsLDAPOperation::SimpleBind(const char *passwd)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mMsgID = ldap_simple_bind(mConnectionHandle, bindName, passwd);
|
||||
mMsgID = ldap_simple_bind(mConnectionHandle,
|
||||
NS_ConvertUCS2toUTF8(bindName).get(),
|
||||
NS_ConvertUCS2toUTF8(passwd).get());
|
||||
|
||||
if (mMsgID == -1) {
|
||||
const int lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0);
|
||||
|
@ -182,9 +184,9 @@ nsLDAPOperation::SimpleBind(const char *passwd)
|
|||
// wrappers for ldap_search_ext
|
||||
//
|
||||
int
|
||||
nsLDAPOperation::SearchExt(const char *base, // base DN to search
|
||||
nsLDAPOperation::SearchExt(const PRUnichar *base, // base DN to search
|
||||
int scope, // SCOPE_{BASE,ONELEVEL,SUBTREE}
|
||||
const char* filter, // search filter
|
||||
const PRUnichar *filter, // search filter
|
||||
char **attrs, // attribute types to be returned
|
||||
int attrsOnly, // attrs only, or values too?
|
||||
LDAPControl **serverctrls,
|
||||
|
@ -197,10 +199,10 @@ nsLDAPOperation::SearchExt(const char *base, // base DN to search
|
|||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
return ldap_search_ext(mConnectionHandle, base, scope,
|
||||
filter, attrs, attrsOnly, serverctrls,
|
||||
clientctrls, timeoutp, sizelimit,
|
||||
&mMsgID);
|
||||
return ldap_search_ext(mConnectionHandle, NS_ConvertUCS2toUTF8(base).get(),
|
||||
scope, NS_ConvertUCS2toUTF8(filter).get(), attrs,
|
||||
attrsOnly, serverctrls, clientctrls, timeoutp,
|
||||
sizelimit, &mMsgID);
|
||||
}
|
||||
|
||||
|
||||
|
@ -220,8 +222,8 @@ nsLDAPOperation::SearchExt(const char *base, // base DN to search
|
|||
* in PRInt32 aSizeLimit);
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsLDAPOperation::SearchExt(const char *aBaseDn, PRInt32 aScope,
|
||||
const char *aFilter, PRIntervalTime aTimeOut,
|
||||
nsLDAPOperation::SearchExt(const PRUnichar *aBaseDn, PRInt32 aScope,
|
||||
const PRUnichar *aFilter, PRIntervalTime aTimeOut,
|
||||
PRInt32 aSizeLimit)
|
||||
{
|
||||
// XXX deal with timeouts
|
||||
|
|
|
@ -64,9 +64,9 @@ class nsLDAPOperation : public nsILDAPOperation
|
|||
*
|
||||
* XXX should move to idl, once LDAPControls have an IDL representation
|
||||
*/
|
||||
int SearchExt(const char *base, // base DN to search
|
||||
int SearchExt(const PRUnichar *base, // base DN to search
|
||||
int scope, // SCOPE_{BASE,ONELEVEL,SUBTREE}
|
||||
const char* filter, // search filter
|
||||
const PRUnichar *filter, // search filter
|
||||
char **attrs, // attribute types to be returned
|
||||
int attrsOnly, // attrs only, or values too?
|
||||
LDAPControl **serverctrls,
|
||||
|
|
|
@ -465,7 +465,7 @@ nsLDAPAutoCompleteSession::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
|||
// nsIAutoCompleteItem::value
|
||||
//
|
||||
PRUint32 numVals;
|
||||
char **values;
|
||||
PRUnichar **values;
|
||||
|
||||
rv = aMessage->GetValues(valueField, &numVals, &values);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -493,7 +493,7 @@ nsLDAPAutoCompleteSession::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
|||
// just use the first value for the email attribute; subsequent values
|
||||
// are ignored
|
||||
//
|
||||
rv = item->SetValue(NS_ConvertUTF8toUCS2(values[0]).GetUnicode());
|
||||
rv = item->SetValue(values[0]);
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(numVals, values);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -716,8 +716,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
|||
// XXXdmose optimization: just request the attributes needed, not all
|
||||
// attributes. requires tweaking SearchExt.
|
||||
//
|
||||
rv = mOperation->SearchExt(dn, scope,
|
||||
searchFilter.get(),
|
||||
rv = mOperation->SearchExt(NS_ConvertUTF8toUCS2(dn).get(), scope,
|
||||
NS_ConvertUTF8toUCS2(searchFilter).get(),
|
||||
0, nsILDAPOperation::NO_LIMIT);
|
||||
if (NS_FAILED(rv)) {
|
||||
switch(rv) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче