Bug 234392 - nsIRDFResource needs scriptable access to IDN resources. r=pike sr=darin

This commit is contained in:
bsmedberg%covad.net 2004-03-09 14:42:24 +00:00
Родитель c1509e7360
Коммит 46cb970ead
6 изменённых файлов: 89 добавлений и 89 удалений

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

@ -327,16 +327,15 @@ NS_IMETHODIMP nsAbMDBDirectory::AddDirectory(const char *uriName, nsIAbDirectory
NS_IMETHODIMP nsAbMDBDirectory::GetDirUri(char **uri)
{
if (uri)
{
if (mURI)
*uri = nsCRT::strdup(mURI);
else
*uri = nsCRT::strdup("");
return NS_OK;
}
else
return NS_RDF_NO_VALUE;
NS_ASSERTION(uri, "Null out param");
NS_ASSERTION(!mURI.IsEmpty(), "Not initialized?");
*uri = ToNewCString(mURI);
if (!*uri)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
@ -381,15 +380,16 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsIEnumerator* *result)
return array->Enumerate(result);
}
if (mURI && mIsMailingList == -1)
NS_ASSERTION(!mURI.IsEmpty(), "Not Initialized?");
if (mIsMailingList == -1)
{
/* directory URIs are of the form
* moz-abmdbdirectory://foo
* mailing list URIs are of the form
* moz-abmdbdirectory://foo/bar
*/
NS_ENSURE_TRUE(strlen(mURI) > kMDBDirectoryRootLen, NS_ERROR_UNEXPECTED);
if (strchr(mURI + kMDBDirectoryRootLen, '/'))
NS_ENSURE_TRUE(mURI.Length() > kMDBDirectoryRootLen, NS_ERROR_UNEXPECTED);
if (strchr(mURI.get() + kMDBDirectoryRootLen, '/'))
mIsMailingList = 1;
else
mIsMailingList = 0;
@ -493,7 +493,7 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCards(nsISupportsArray *cards)
//to do, get mailing list dir side uri and notify rdf to remove it
PRUint32 rowID;
dbcard->GetDbRowID(&rowID);
char *listUri = PR_smprintf("%s/MailList%ld", mURI, rowID);
char *listUri = PR_smprintf("%s/MailList%ld", mURI.get(), rowID);
if (listUri)
{
nsresult rv = NS_OK;
@ -656,7 +656,7 @@ nsresult nsAbMDBDirectory::InternalAddMailList(nsIAbDirectory *list, PRUint32 *k
dblist->GetDbRowID(&dbRowID);
nsCAutoString listUri;
listUri = nsDependentCString(mURI) + NS_LITERAL_CSTRING("/MailList");
listUri = mURI + NS_LITERAL_CSTRING("/MailList");
listUri.AppendInt(dbRowID);
nsCOMPtr<nsIAbDirectory> newList;
@ -734,15 +734,16 @@ NS_IMETHODIMP nsAbMDBDirectory::DropCard(nsIAbCard* aCard, PRBool needToCopyCard
if (!isNormal)
return NS_OK;
if (mURI && mIsMailingList == -1)
NS_ASSERTION(!mURI.IsEmpty(), "Not initialized?");
if (mIsMailingList == -1)
{
/* directory URIs are of the form
* moz-abmdbdirectory://foo
* mailing list URIs are of the form
* moz-abmdbdirectory://foo/bar
*/
NS_ENSURE_TRUE(strlen(mURI) > kMDBDirectoryRootLen, NS_ERROR_UNEXPECTED);
if (strchr(mURI + kMDBDirectoryRootLen, '/'))
NS_ENSURE_TRUE(mURI.Length() > kMDBDirectoryRootLen, NS_ERROR_UNEXPECTED);
if (strchr(mURI.get() + kMDBDirectoryRootLen, '/'))
mIsMailingList = 1;
else
mIsMailingList = 0;
@ -981,13 +982,15 @@ nsresult nsAbMDBDirectory::OnSearchFoundCard (nsIAbCard* card)
nsresult nsAbMDBDirectory::GetAbDatabase()
{
if (!mDatabase && mURI) {
NS_ASSERTION(!mURI.IsEmpty(), "Not initialized?");
if (!mDatabase) {
nsresult rv;
nsCOMPtr<nsIAddressBook> addressBook = do_GetService(NS_ADDRESSBOOK_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = addressBook->GetAbDatabaseFromURI(mURI, getter_AddRefs(mDatabase));
rv = addressBook->GetAbDatabaseFromURI(mURI.get(), getter_AddRefs(mDatabase));
NS_ENSURE_SUCCESS(rv,rv);
rv = mDatabase->AddListener(this);

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

@ -285,7 +285,7 @@ NS_IMETHODIMP nsImapMailFolder::Enumerate(nsIEnumerator* *result)
nsresult nsImapMailFolder::AddDirectorySeparator(nsFileSpec &path)
{
nsresult rv = NS_OK;
if (nsCRT::strcmp(mURI, kImapRootURI) == 0)
if (mURI.Equals(kImapRootURI))
{
// don't concat the full separator with .sbd
}
@ -331,28 +331,22 @@ NS_IMETHODIMP nsImapMailFolder::AddSubfolderWithPath(nsAutoString *name, nsIFile
if(NS_FAILED(rv))
return rv;
PRInt32 flags = 0;
nsAutoString uri;
uri.AppendWithConversion(mURI);
uri.Append(PRUnichar('/'));
PRInt32 flags = 0;
uri.Append(*name);
char* uriStr = ToNewCString(uri);
if (uriStr == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsCAutoString uri = mURI + NS_LITERAL_CSTRING("/");
AppendUTF16toUTF8(*name, uri);
//will make sure mSubFolders does not have duplicates because of bogus msf files.
nsCOMPtr <nsIMsgFolder> msgFolder;
rv = GetChildWithURI(uriStr, PR_FALSE/*deep*/, PR_FALSE /*case Insensitive*/, getter_AddRefs(msgFolder));
rv = GetChildWithURI(uri.get(), PR_FALSE/*deep*/, PR_FALSE /*case Insensitive*/, getter_AddRefs(msgFolder));
if (NS_SUCCEEDED(rv) && msgFolder)
{
nsMemory::Free(uriStr);
return NS_MSG_FOLDER_EXISTS;
}
nsCOMPtr<nsIRDFResource> res;
rv = rdf->GetUnicodeResource(uri, getter_AddRefs(res));
rv = rdf->GetResource(uri, getter_AddRefs(res));
if (NS_FAILED(rv))
return rv;
@ -366,7 +360,6 @@ NS_IMETHODIMP nsImapMailFolder::AddSubfolderWithPath(nsAutoString *name, nsIFile
folder->GetFlags((PRUint32 *)&flags);
folder->SetParent(this);
nsMemory::Free(uriStr);
flags |= MSG_FOLDER_FLAG_MAIL;
@ -5687,7 +5680,7 @@ NS_IMETHODIMP nsImapMailFolder::GetPath(nsIFileSpec ** aPathName)
if (! m_pathName)
return NS_ERROR_OUT_OF_MEMORY;
rv = nsImapURI2Path(kImapRootURI, mURI, *m_pathName);
rv = nsImapURI2Path(kImapRootURI, mURI.get(), *m_pathName);
// printf("constructing path %s\n", (const char *) *m_pathName);
if (NS_FAILED(rv)) return rv;
}
@ -6834,18 +6827,17 @@ NS_IMETHODIMP nsImapMailFolder::GetFolderURL(char **aFolderURL)
nsXPIDLCString rootURI;
rootFolder->GetURI(getter_Copies(rootURI));
nsCAutoString namePart(mURI + rootURI.Length());
char *escapedName = nsEscape(namePart.get(), url_Path);
NS_ASSERTION(mURI.Length() > rootURI.Length(), "Should match with a folder name!");
nsAdoptingCString escapedName(nsEscape(mURI.get() + rootURI.Length(),
url_Path));
if (escapedName.IsEmpty()) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aFolderURL = ToNewCString(rootURI + escapedName);
if (!*aFolderURL)
return NS_ERROR_OUT_OF_MEMORY;
char *folderURL = (char *) PR_Malloc(rootURI.Length() + strlen(escapedName) + 1);
if (!folderURL)
return NS_ERROR_OUT_OF_MEMORY;
strcpy(folderURL, rootURI.get());
strcpy(folderURL + rootURI.Length(), escapedName);
PR_Free(escapedName);
// imap uri's aren't escaped, so we need to escape the folder name
// part of the uri and return that.
*aFolderURL = folderURL;
return NS_OK;
}

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

@ -302,26 +302,25 @@ nsresult
nsMsgNewsFolder::AddDirectorySeparator(nsFileSpec &path)
{
nsresult rv = NS_OK;
if (PL_strcmp(mURI, kNewsRootURI) == 0)
if (mURI.Equals(kNewsRootURI))
{
// don't concat the full separator with .sbd
}
else
{
nsAutoString sep;
#if 0
rv = nsGetNewsFolderSeparator(sep);
#else
rv = NS_OK;
#endif
if (NS_FAILED(rv)) return rv;
// see if there's a dir with the same name ending with .sbd
// unfortunately we can't just say:
// path += sep;
// here because of the way nsFileSpec concatenates
nsAutoString str; str.AssignWithConversion(nsFilePath(path));
nsAutoString str;
str.AssignWithConversion(nsFilePath(path));
#if 0
nsAutoString sep;
rv = nsGetNewsFolderSeparator(sep);
if (NS_FAILED(rv)) return rv;
str += sep;
#endif
path = nsFilePath(str);
}
@ -1005,7 +1004,8 @@ nsresult nsMsgNewsFolder::GetNewsMessages(nsIMsgWindow *aMsgWindow, PRBool aGetO
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsIURI> resultUri;
rv = nntpService->GetNewNews(nntpServer, mURI, aGetOld, this, aMsgWindow, getter_AddRefs(resultUri));
rv = nntpService->GetNewNews(nntpServer, mURI.get(), aGetOld, this,
aMsgWindow, getter_AddRefs(resultUri));
if (aUrlListener && NS_SUCCEEDED(rv) && resultUri)
{
nsCOMPtr<nsIMsgMailNewsUrl> msgUrl (do_QueryInterface(resultUri));
@ -1311,7 +1311,7 @@ NS_IMETHODIMP nsMsgNewsFolder::ForgetGroupUsername()
if (NS_FAILED(rv)) return rv;
nsXPIDLCString signonURL;
rv = CreateNewsgroupUsernameUrlForSignon(mURI, getter_Copies(signonURL));
rv = CreateNewsgroupUsernameUrlForSignon(mURI.get(), getter_Copies(signonURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> uri;
@ -1335,7 +1335,7 @@ NS_IMETHODIMP nsMsgNewsFolder::ForgetGroupPassword()
if (NS_FAILED(rv)) return rv;
nsXPIDLCString signonURL;
rv = CreateNewsgroupPasswordUrlForSignon(mURI, getter_Copies(signonURL));
rv = CreateNewsgroupPasswordUrlForSignon(mURI.get(), getter_Copies(signonURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> uri;
@ -1398,7 +1398,7 @@ nsMsgNewsFolder::GetGroupPasswordWithUI(const PRUnichar * aPromptMessage, const
PRBool okayValue = PR_TRUE;
nsXPIDLCString signonURL;
rv = CreateNewsgroupPasswordUrlForSignon(mURI, getter_Copies(signonURL));
rv = CreateNewsgroupPasswordUrlForSignon(mURI.get(), getter_Copies(signonURL));
if (NS_FAILED(rv)) return rv;
rv = dialog->PromptPassword(aPromptTitle, aPromptMessage, NS_ConvertASCIItoUCS2(NS_STATIC_CAST(const char*, signonURL)).get(), nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY,
@ -1468,7 +1468,7 @@ nsMsgNewsFolder::GetGroupUsernameWithUI(const PRUnichar * aPromptMessage, const
PRBool okayValue = PR_TRUE;
nsXPIDLCString signonURL;
rv = CreateNewsgroupUsernameUrlForSignon(mURI, getter_Copies(signonURL));
rv = CreateNewsgroupUsernameUrlForSignon(mURI.get(), getter_Copies(signonURL));
if (NS_FAILED(rv)) return rv;
rv = dialog->Prompt(aPromptTitle, aPromptMessage, NS_ConvertASCIItoUCS2(signonURL).get(),

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

@ -43,16 +43,24 @@
* An nsIRDFResource is an object that has unique identity in the
* RDF data model. The object's identity is determined by its URI.
*/
[scriptable, uuid(E0C493D1-9542-11d2-8EB8-00805F29F370)]
[scriptable, uuid(fb9686a7-719a-49dc-9107-10dea5739341)]
interface nsIRDFResource : nsIRDFNode {
/**
* The single-byte string value of the resource
* The single-byte string value of the resource.
* @note THIS IS OBSOLETE. C++ should use GetValueConst and script
* should use .valueUTF8
*/
readonly attribute string Value;
/**
* The UTF-8 URI of the resource.
*/
readonly attribute AUTF8String ValueUTF8;
/**
* An unscriptable version used to avoid a string copy. Meant
* for use as a performance optimization.
* for use as a performance optimization. The string is encoded
* in UTF-8.
*/
[noscript] void GetValueConst([shared] out string aConstValue);

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

@ -61,6 +61,7 @@ public:
// nsIRDFResource methods:
NS_IMETHOD Init(const char* aURI);
NS_IMETHOD GetValue(char* *aURI);
NS_IMETHOD GetValueUTF8(nsACString& aResult);
NS_IMETHOD GetValueConst(const char** aURI);
NS_IMETHOD EqualsString(const char* aURI, PRBool* aResult);
NS_IMETHOD GetDelegate(const char* aKey, REFNSIID aIID, void** aResult);
@ -75,7 +76,7 @@ protected:
static nsrefcnt gRDFServiceRefCnt;
protected:
char* mURI;
nsCString mURI;
struct DelegateEntry {
nsCString mKey;

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

@ -53,7 +53,7 @@ nsrefcnt nsRDFResource::gRDFServiceRefCnt = 0;
////////////////////////////////////////////////////////////////////////////////
nsRDFResource::nsRDFResource(void)
: mURI(nsnull), mDelegates(nsnull)
: mDelegates(nsnull)
{
}
@ -66,20 +66,11 @@ nsRDFResource::~nsRDFResource(void)
delete doomed;
}
if (!mURI)
if (!gRDFService)
return;
if (!gRDFService) {
nsMemory::Free(mURI);
return;
}
gRDFService->UnregisterResource(this);
// N.B. that we need to free the URI *after* we un-cache the resource,
// due to the way that the resource manager is implemented.
nsMemory::Free(mURI);
if (--gRDFServiceRefCnt == 0) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
@ -125,8 +116,7 @@ nsRDFResource::Init(const char* aURI)
if (! aURI)
return NS_ERROR_NULL_POINTER;
if (! (mURI = (char *)nsMemory::Clone(aURI, strlen(aURI) + 1)))
return NS_ERROR_OUT_OF_MEMORY;
mURI = aURI;
if (gRDFServiceRefCnt++ == 0) {
nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
@ -140,19 +130,27 @@ nsRDFResource::Init(const char* aURI)
NS_IMETHODIMP
nsRDFResource::GetValue(char* *aURI)
{
if (!aURI)
return NS_ERROR_NULL_POINTER;
NS_ASSERTION(aURI, "Null out param.");
if ((*aURI = nsCRT::strdup(mURI)) == nsnull)
*aURI = ToNewCString(mURI);
if (!*aURI)
return NS_ERROR_OUT_OF_MEMORY;
else
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
nsRDFResource::GetValueUTF8(nsACString& aResult)
{
aResult = mURI;
return NS_OK;
}
NS_IMETHODIMP
nsRDFResource::GetValueConst(const char** aURI)
{
*aURI = mURI;
*aURI = mURI.get();
return NS_OK;
}
@ -163,11 +161,9 @@ nsRDFResource::EqualsString(const char* aURI, PRBool* aResult)
if (! aURI)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (!aResult)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResult, "null ptr");
*aResult = (nsCRT::strcmp(aURI, mURI) == 0);
*aResult = mURI.Equals(aURI);
return NS_OK;
}
@ -196,8 +192,8 @@ nsRDFResource::GetDelegate(const char* aKey, REFNSIID aIID, void** aResult)
contractID.Append(aKey);
contractID.Append("&scheme=");
for (const char* p = mURI; *p && *p != ':'; ++p)
contractID.Append(*p);
PRInt32 i = mURI.FindChar(':');
contractID += StringHead(mURI, i);
nsCOMPtr<nsIRDFDelegateFactory> delegateFactory =
do_CreateInstance(contractID.get(), &rv);