зеркало из https://github.com/mozilla/pjs.git
fix for bug #5668. now multiple news hosts really works.
This commit is contained in:
Родитель
5e0d3d710b
Коммит
ec6e26b471
|
@ -43,7 +43,7 @@ nsresult nsNewsDatabase::Open(nsFileSpec &newsgroupName, PRBool create, nsIMsgDa
|
|||
nsNewsSummarySpec summarySpec(newsgroupName);
|
||||
nsresult err = NS_OK;
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("nsNewsDatabase::Open(%s, %s, %p, %s) -> %s\n",
|
||||
(const char*)newsgroupName, create ? "TRUE":"FALSE",
|
||||
pMessageDB, upgrading ? "TRUE":"FALSE", (const char*)newsgroupName);
|
||||
|
@ -54,7 +54,7 @@ nsresult nsNewsDatabase::Open(nsFileSpec &newsgroupName, PRBool create, nsIMsgDa
|
|||
newsDB = new nsNewsDatabase();
|
||||
|
||||
if (!newsDB) {
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("NS_ERROR_OUT_OF_MEMORY\n");
|
||||
#endif
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -65,12 +65,12 @@ nsresult nsNewsDatabase::Open(nsFileSpec &newsgroupName, PRBool create, nsIMsgDa
|
|||
|
||||
err = newsDB->OpenMDB((const char *) summarySpec, create);
|
||||
if (NS_SUCCEEDED(err)) {
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("newsDB->OpenMDB succeeded!\n");
|
||||
#endif
|
||||
*pMessageDB = newsDB;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_sspitzer
|
||||
else {
|
||||
printf("newsDB->OpenMDB failed!\n");
|
||||
*pMessageDB = nsnull;
|
||||
|
@ -249,7 +249,7 @@ nsresult
|
|||
nsNewsDatabase::CreateMsgHdr(nsIMdbRow* hdrRow, nsMsgKey key, nsIMsgDBHdr* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("nsNewsDatabase::CreateMsgHdr()\n");
|
||||
#endif
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ nsGetMailboxRoot(const char *hostname, nsFileSpec &result)
|
|||
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(serverSupports);
|
||||
|
||||
// this had better be a nsIMsgIncomingServer, otherwise
|
||||
// FindServersByHostname is broken or we got some wierd object back
|
||||
// FindServersByHostname is broken or we got some weird object back
|
||||
PR_ASSERT(server);
|
||||
|
||||
// now ask the server what it's root is
|
||||
|
@ -89,8 +89,6 @@ nsLocalURI2Path(const char* rootURI, const char* uriStr,
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
|
||||
nsAutoString sep;
|
||||
sep += PR_GetDirectorySeparator();
|
||||
|
||||
|
@ -103,8 +101,8 @@ nsLocalURI2Path(const char* rootURI, const char* uriStr,
|
|||
return NS_ERROR_FAILURE;
|
||||
|
||||
// verify that rootURI starts with "mailbox:/" or "mailbox_message:/"
|
||||
if ((strcmp(rootURI, kMailboxRootURI) != 0) &&
|
||||
(strcmp(rootURI, kMailboxMessageRootURI) != 0)) {
|
||||
if ((PL_strcmp(rootURI, kMailboxRootURI) != 0) &&
|
||||
(PL_strcmp(rootURI, kMailboxMessageRootURI) != 0)) {
|
||||
pathResult = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -139,9 +137,11 @@ nsLocalURI2Path(const char* rootURI, const char* uriStr,
|
|||
// at all?
|
||||
char *hostchar = hostname.ToNewCString();
|
||||
rv = nsGetMailboxRoot(hostchar, pathResult);
|
||||
#ifdef DEBUG_alecf
|
||||
printf("nsGetMailboxRoot(%s) = %s\n\tfolder = %s\n",
|
||||
hostchar, (const char*)pathResult,
|
||||
folder.ToNewCString());
|
||||
#endif
|
||||
delete[] hostchar;
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -195,8 +195,9 @@ nsLocalURI2Path(const char* rootURI, const char* uriStr,
|
|||
pathResult +=path;
|
||||
#endif
|
||||
|
||||
if (folder != "")
|
||||
pathResult += folder;
|
||||
if (folder != "") {
|
||||
pathResult += folder;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,8 +85,10 @@ nsMailboxUrl::~nsMailboxUrl()
|
|||
NS_IF_RELEASE(m_container);
|
||||
PR_FREEIF(m_errorMessage);
|
||||
|
||||
if (m_filePath)
|
||||
if (m_filePath) {
|
||||
delete m_filePath;
|
||||
m_filePath = nsnull;
|
||||
}
|
||||
|
||||
PR_FREEIF(m_messageID);
|
||||
PR_FREEIF(m_spec);
|
||||
|
@ -643,16 +645,21 @@ nsresult nsMailboxUrl::GetFile(const char* *result) const
|
|||
|
||||
nsresult nsMailboxUrl::SetFile(const char *aNewFile)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
|
||||
NS_LOCK_INSTANCE();
|
||||
m_file = nsCRT::strdup(aNewFile);
|
||||
ReconstructSpec();
|
||||
if (m_filePath)
|
||||
if (m_filePath) {
|
||||
delete m_filePath;
|
||||
m_filePath = nsnull;
|
||||
}
|
||||
m_filePath = new nsFileSpec(m_file);
|
||||
|
||||
if (m_filePath == nsnull) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_UNLOCK_INSTANCE();
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMailboxUrl::GetSpec(const char* *result) const
|
||||
|
|
|
@ -154,7 +154,9 @@ nsMsgNewsFolder::isNewsHost()
|
|||
// if we get here, mURI looks like this: news://x
|
||||
// where x is non-empty, and may contain "/"
|
||||
char *rightAfterTheRoot = mURI+rootURIlen+1;
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("search for a slash in %s\n",rightAfterTheRoot);
|
||||
#endif
|
||||
if (PL_strstr(rightAfterTheRoot,"/") == nsnull) {
|
||||
// there is no slashes after news://,
|
||||
// so mURI is of the form news://x
|
||||
|
@ -185,7 +187,7 @@ nsMsgNewsFolder::MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, ns
|
|||
char is_newsgroup[512];
|
||||
PRBool rv;
|
||||
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("MapHostToNewsrcFile(%s,%s,%s,??)\n",newshostname,(const char *)fatFile, newshostname);
|
||||
#endif
|
||||
lookingFor = PR_smprintf("newsrc-%s",newshostname);
|
||||
|
@ -204,7 +206,7 @@ nsMsgNewsFolder::MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, ns
|
|||
|
||||
/* we expect the first line to be NEWSRC_MAP_FILE_COOKIE */
|
||||
rv = inputStream.readline(buffer, sizeof(buffer));
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("buffer = %s\n", buffer);
|
||||
#endif
|
||||
if ((!rv) || (PL_strncmp(buffer, NEWSRC_MAP_FILE_COOKIE, PL_strlen(NEWSRC_MAP_FILE_COOKIE)))) {
|
||||
|
@ -226,7 +228,7 @@ nsMsgNewsFolder::MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, ns
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("buffer = %s\n", buffer);
|
||||
#endif
|
||||
|
||||
|
@ -255,19 +257,21 @@ nsMsgNewsFolder::MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, ns
|
|||
}
|
||||
|
||||
if(!PL_strncmp(is_newsgroup, "TRUE", 4)) {
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("is_newsgroups_file = TRUE\n");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("is_newsgroups_file = FALSE\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("psuedo_name=%s,filename=%s\n", psuedo_name, filename);
|
||||
#endif
|
||||
if (!PL_strncmp(psuedo_name,lookingFor,PL_strlen(lookingFor))) {
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("found a match for %s\n",lookingFor);
|
||||
#endif
|
||||
newsrcFile = filename;
|
||||
|
@ -342,7 +346,7 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
|
|||
rv = GetNewsrcFile(newshostname, path, newsrcFile);
|
||||
if (rv == NS_OK) {
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("newsrc file = %s\n", (const char *)newsrcFile);
|
||||
printf("uri = %s newsrc file = %s\n", mURI, (const char *)newsrcFile);
|
||||
#endif
|
||||
rv = LoadNewsrcFileAndCreateNewsgroups(newsrcFile);
|
||||
}
|
||||
|
@ -351,7 +355,7 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
|
|||
newshostname = nsnull;
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("%s is not a host, so it has no newsgroups.\n", mURI);
|
||||
#endif
|
||||
rv = NS_OK;
|
||||
|
@ -517,7 +521,7 @@ nsresult nsMsgNewsFolder::GetDatabase()
|
|||
if (NS_SUCCEEDED(rv) && newsDBFactory)
|
||||
{
|
||||
folderOpen = newsDBFactory->Open(path, PR_TRUE, (nsIMsgDatabase **) &mNewsDatabase, PR_FALSE);
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
if (NS_SUCCEEDED(folderOpen)) {
|
||||
printf ("newsDBFactory->Open() succeeded\n");
|
||||
}
|
||||
|
@ -1072,10 +1076,7 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr,
|
|||
rv = msgDBHdr->GetMessageKey(&key);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = GetPath(path);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = nsBuildNewsMessageURI(path, key, &msgURI);
|
||||
rv = nsBuildNewsMessageURI(mURI, key, &msgURI);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
|
@ -1266,7 +1267,9 @@ msg_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
|||
void *closure),
|
||||
void *closure)
|
||||
{
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("msg_LineBuffer()\n");
|
||||
#endif
|
||||
|
||||
int status = 0;
|
||||
if (*buffer_fpP > 0 && *bufferP && (*bufferP)[*buffer_fpP - 1] == CR &&
|
||||
|
@ -1377,7 +1380,7 @@ nsMsgNewsFolder::LoadNewsrcFileAndCreateNewsgroups(nsFileSpec &newsrcFile)
|
|||
break;
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_sspitzer
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("%d: %s\n", numread, buffer);
|
||||
#endif
|
||||
msg_LineBuffer(buffer, numread,
|
||||
|
@ -1407,14 +1410,18 @@ nsMsgNewsFolder::LoadNewsrcFileAndCreateNewsgroups(nsFileSpec &newsrcFile)
|
|||
PRInt32
|
||||
nsMsgNewsFolder::ProcessLine_s(char* line, PRUint32 line_size, void* closure)
|
||||
{
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("nsMsgNewsFolder::ProcessLine_s()\n");
|
||||
return ((nsMsgNewsFolder*) closure)->ProcessLine(line, line_size);
|
||||
#endif
|
||||
return ((nsMsgNewsFolder*) closure)->ProcessLine(line, line_size);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsMsgNewsFolder::ProcessLine(char* line, PRUint32 line_size)
|
||||
{
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("nsMsgNewsFolder::ProcessLine()\n");
|
||||
#endif
|
||||
|
||||
/* guard against blank line lossage */
|
||||
if (line[0] == '#' || line[0] == CR || line[0] == LF) return 0;
|
||||
|
@ -1458,7 +1465,9 @@ nsMsgNewsFolder::ProcessLine(char* line, PRUint32 line_size)
|
|||
}
|
||||
|
||||
if (subscribed) {
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("subscribed: %s\n", line);
|
||||
#endif
|
||||
|
||||
// were subscribed, so add it
|
||||
nsIMsgFolder *child = nsnull;
|
||||
|
@ -1468,7 +1477,9 @@ nsMsgNewsFolder::ProcessLine(char* line, PRUint32 line_size)
|
|||
child = nsnull;
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("NOT subscribed: %s\n", line);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_PORT
|
||||
|
|
|
@ -29,38 +29,50 @@
|
|||
|
||||
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
|
||||
|
||||
|
||||
//Utilities
|
||||
static char *gNewsRoot = nsnull;
|
||||
|
||||
nsresult
|
||||
nsGetNewsRoot(nsFileSpec &result)
|
||||
nsGetNewsRoot(const char *hostname, nsFileSpec &result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (gNewsRoot == nsnull) {
|
||||
NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);
|
||||
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager;
|
||||
rv = session->GetAccountManager(getter_AddRefs(accountManager));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsISupportsArray> servers;
|
||||
rv = accountManager->FindServersByHostname("news.mozilla.org",
|
||||
nsINntpIncomingServer::GetIID(),
|
||||
getter_AddRefs(servers));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && servers->Count() > 0) {
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
server = do_QueryInterface(servers->ElementAt(0));
|
||||
|
||||
if (server)
|
||||
rv = server->GetLocalPath(&gNewsRoot);
|
||||
}
|
||||
}
|
||||
} /* if (gNewsRoot == nsnull) .. */
|
||||
// retrieve the AccountManager
|
||||
NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager;
|
||||
rv = session->GetAccountManager(getter_AddRefs(accountManager));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
result = gNewsRoot;
|
||||
// find all news hosts matching the given hostname
|
||||
nsCOMPtr<nsISupportsArray> hosts;
|
||||
rv = accountManager->FindServersByHostname(hostname,
|
||||
nsINntpIncomingServer::GetIID(),
|
||||
getter_AddRefs(hosts));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// use enumeration function to find the first nntp server
|
||||
nsISupports *serverSupports = hosts->ElementAt(0);
|
||||
|
||||
#ifdef DEBUG_sspitzer_
|
||||
if (hosts->Count() <= 0)
|
||||
fprintf(stderr, "Augh, no nntp server named %s?\n", hostname);
|
||||
if (!serverSupports)
|
||||
fprintf(stderr, "Huh, serverSupports returned nsnull\n");
|
||||
#endif
|
||||
|
||||
// if there are no nntp servers, how did we get here?
|
||||
if (! serverSupports) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(serverSupports);
|
||||
|
||||
// this had better be a nsIMsgIncomingServer, otherwise
|
||||
// FindServersByHostname is broken or we got some weird object back
|
||||
PR_ASSERT(server);
|
||||
|
||||
// now ask the server what it's root is
|
||||
char *localPath;
|
||||
rv = server->GetLocalPath(&localPath);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
result = localPath;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -75,131 +87,74 @@ nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult)
|
|||
if (uri.Find(rootURI) != 0) // if doesn't start with rootURI
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if ((PL_strcmp(rootURI, kNewsRootURI) == 0) ||
|
||||
(PL_strcmp(rootURI, kNewsMessageRootURI) == 0)) {
|
||||
rv = nsGetNewsRoot(pathResult);
|
||||
// verify that rootURI starts with "news:/" or "news_message:/"
|
||||
if ((PL_strcmp(rootURI, kNewsRootURI) != 0) &&
|
||||
(PL_strcmp(rootURI, kNewsMessageRootURI) != 0)) {
|
||||
pathResult = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
// the server name is the first component of the path, so extract it out
|
||||
PRInt32 hostStart;
|
||||
|
||||
hostStart = uri.Find('/');
|
||||
if (hostStart <= 0) return NS_ERROR_FAILURE;
|
||||
|
||||
// skip past all //
|
||||
while (uri[hostStart]=='/') hostStart++;
|
||||
|
||||
// cut news://hostname/newsgroup -> hostname/newsgroup
|
||||
nsAutoString hostname;
|
||||
uri.Right(hostname, uri.Length() - hostStart);
|
||||
|
||||
PRInt32 hostEnd = hostname.Find('/');
|
||||
|
||||
// newsgroup comes after the hostname, after the '/'
|
||||
nsAutoString newsgroup = "";
|
||||
|
||||
if (hostEnd != -1) {
|
||||
hostname.Right(newsgroup, hostname.Length() - hostEnd - 1);
|
||||
}
|
||||
|
||||
// cut off first '/' and everything following it
|
||||
// hostname/newsgroup -> hostname
|
||||
if (hostEnd >0) {
|
||||
hostname.Truncate(hostEnd);
|
||||
}
|
||||
|
||||
char *hostchar = hostname.ToNewCString();
|
||||
rv = nsGetNewsRoot(hostchar, pathResult);
|
||||
delete[] hostchar;
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
pathResult = nsnull;
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("nsGetNewsRoot failed!\n");
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsAutoString path="";
|
||||
uri.Cut(0, nsCRT::strlen(rootURI));
|
||||
|
||||
PRInt32 uriLen = uri.Length();
|
||||
PRInt32 pos;
|
||||
while(uriLen > 0) {
|
||||
nsAutoString folderName;
|
||||
nsAutoString alteredHost = "host-";
|
||||
alteredHost += hostname;
|
||||
|
||||
PRInt32 leadingPos;
|
||||
// if it's the first character then remove it.
|
||||
while ((leadingPos = uri.Find('/')) == 0) {
|
||||
uri.Cut(0, 1);
|
||||
uriLen--;
|
||||
}
|
||||
// can't do pathResult += "host-"; pathresult += hostname;
|
||||
// because += on a nsFileSpec inserts a separator
|
||||
// so we'd end up with host-/hostname and not host-hostname
|
||||
pathResult += alteredHost;
|
||||
|
||||
if (uriLen == 0)
|
||||
break;
|
||||
|
||||
pos = uri.Find('/');
|
||||
if (pos < 0)
|
||||
pos = uriLen;
|
||||
|
||||
|
||||
PRInt32 leftRes = uri.Left(folderName, pos);
|
||||
|
||||
NS_ASSERTION(leftRes == pos,
|
||||
"something wrong with nsString");
|
||||
//We only want to add this after the first time around.
|
||||
if(path.Length() > 0) {
|
||||
//We only want to add this after the first time around.
|
||||
path += sep;
|
||||
}
|
||||
else {
|
||||
// we only want to add this the first time around
|
||||
path += "host-";
|
||||
}
|
||||
|
||||
path += folderName;
|
||||
uri.Cut(0, pos);
|
||||
uriLen -= pos;
|
||||
if (newsgroup != "") {
|
||||
pathResult += newsgroup;
|
||||
}
|
||||
|
||||
if(path.Length() > 0)
|
||||
pathResult +=path;
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("nsGetNewsRoot(%s) = %s\n\tnewsgroup = %s\n",
|
||||
hostname.ToNewCString(), (const char*)pathResult,
|
||||
newsgroup.ToNewCString());
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPath2NewsURI(const char* rootURI, const nsFileSpec& spec, char **uri)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
||||
nsAutoString sep;
|
||||
/* sspitzer: is this ok for mail and news? */
|
||||
rv = nsGetMailFolderSeparator(sep);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRUint32 sepLen = sep.Length();
|
||||
|
||||
nsFileSpec root;
|
||||
rv = nsGetNewsRoot(root);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
const char *path = spec;
|
||||
nsAutoString pathStr(path);
|
||||
path = root;
|
||||
nsAutoString rootStr(path);
|
||||
|
||||
PRInt32 pos = pathStr.Find(rootStr);
|
||||
if (pos != 0) // if doesn't start with root path
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsAutoString uriStr(rootURI);
|
||||
|
||||
PRUint32 rootStrLen = rootStr.Length();
|
||||
pathStr.Cut(0, rootStrLen);
|
||||
PRInt32 pathStrLen = pathStr.Length();
|
||||
|
||||
char dirSep = PR_GetDirectorySeparator();
|
||||
|
||||
while (pathStrLen > 0) {
|
||||
nsAutoString folderName;
|
||||
|
||||
PRInt32 leadingPos;
|
||||
// if it's the first character then remove it.
|
||||
while ((leadingPos = pathStr.Find(dirSep)) == 0) {
|
||||
pathStr.Cut(0, 1);
|
||||
pathStrLen--;
|
||||
}
|
||||
if (pathStrLen == 0)
|
||||
break;
|
||||
|
||||
pos = pathStr.Find(sep);
|
||||
if (pos < 0)
|
||||
pos = pathStrLen;
|
||||
|
||||
PRInt32 leftRes = pathStr.Left(folderName, pos);
|
||||
NS_ASSERTION(leftRes == pos,
|
||||
"something wrong with nsString");
|
||||
|
||||
pathStr.Cut(0, pos + sepLen);
|
||||
pathStrLen -= pos + sepLen;
|
||||
|
||||
uriStr += '/';
|
||||
uriStr += folderName;
|
||||
}
|
||||
*uri = uriStr.ToNewCString();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNewsURI2Name(const char* rootURI, char* uriStr, nsString& name)
|
||||
{
|
||||
|
@ -213,7 +168,8 @@ nsNewsURI2Name(const char* rootURI, char* uriStr, nsString& name)
|
|||
}
|
||||
|
||||
/* parses NewsMessageURI */
|
||||
nsresult nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key)
|
||||
nsresult
|
||||
nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key)
|
||||
{
|
||||
if(!key)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
@ -236,21 +192,21 @@ nsresult nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *k
|
|||
|
||||
}
|
||||
|
||||
nsresult nsBuildNewsMessageURI(const nsFileSpec& path, PRUint32 key, char** uri)
|
||||
nsresult nsBuildNewsMessageURI(const char *baseURI, PRUint32 key, char** uri)
|
||||
{
|
||||
|
||||
if(!uri)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
// need to convert news://hostname/.. to news_message://hostname/..
|
||||
|
||||
char *folderURI;
|
||||
|
||||
nsPath2NewsURI(kNewsMessageRootURI, path, &folderURI);
|
||||
|
||||
*uri = PR_smprintf("%s#%d", folderURI, key);
|
||||
|
||||
delete[] folderURI;
|
||||
nsAutoString tailURI(baseURI);
|
||||
|
||||
// chop off news:/
|
||||
if (tailURI.Find(kNewsRootURI) == 0)
|
||||
tailURI.Cut(0, PL_strlen(kNewsRootURI));
|
||||
|
||||
const char *tail = tailURI.ToNewCString();
|
||||
|
||||
*uri = PR_smprintf("%s%s#%d", kNewsMessageRootURI, tail, key);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,14 +26,11 @@ static const char kNewsRootURI[] = "news:/";
|
|||
static const char kNewsMessageRootURI[] = "news_message:/";
|
||||
|
||||
extern nsresult
|
||||
nsGetNewsRoot(nsFileSpec &result);
|
||||
nsGetNewsRoot(const char* hostname, nsFileSpec &result);
|
||||
|
||||
extern nsresult
|
||||
nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult);
|
||||
|
||||
extern nsresult
|
||||
nsPath2NewsURI(const char* rootURI, const nsFileSpec& path, char* *uri);
|
||||
|
||||
extern nsresult
|
||||
nsNewsURI2Name(const char* rootURI, char* uriStr, nsString& name);
|
||||
|
||||
|
@ -41,7 +38,7 @@ extern nsresult
|
|||
nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key);
|
||||
|
||||
extern nsresult
|
||||
nsBuildNewsMessageURI(const nsFileSpec& path, PRUint32 key, char **uri);
|
||||
nsBuildNewsMessageURI(const char *baseURI, PRUint32 key, char** uri);
|
||||
|
||||
|
||||
#endif //NS_NEWSUTILS_H
|
||||
|
|
|
@ -86,6 +86,11 @@ nsNntpUrl::~nsNntpUrl()
|
|||
PR_FREEIF(m_newsgroupPost);
|
||||
PR_FREEIF(m_errorMessage);
|
||||
|
||||
if (m_filePath) {
|
||||
delete m_filePath;
|
||||
m_filePath = nsnull;
|
||||
}
|
||||
|
||||
PR_FREEIF(m_spec);
|
||||
PR_FREEIF(m_protocol);
|
||||
PR_FREEIF(m_host);
|
||||
|
@ -339,23 +344,42 @@ nsresult nsNntpUrl::GetErrorMessage (char ** errorMessage) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNntpUrl::GetFilePath(const nsFileSpec ** aFilePath)
|
||||
{
|
||||
if (aFilePath)
|
||||
*aFilePath = m_filePath;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult nsNntpUrl::SetFilePath(const nsFileSpec& aFilePath)
|
||||
{
|
||||
NS_LOCK_INSTANCE();
|
||||
if (m_filePath)
|
||||
delete m_filePath;
|
||||
m_filePath = new nsFileSpec(aFilePath);
|
||||
|
||||
NS_UNLOCK_INSTANCE();
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
// from nsIMsgUriUrl
|
||||
NS_IMETHODIMP nsNntpUrl::GetURI(char ** aURI)
|
||||
{
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("nsNntpUrl::GetURI()\n");
|
||||
#endif
|
||||
{
|
||||
if (aURI)
|
||||
{
|
||||
const nsFileSpec * filePath = nsnull;
|
||||
#if 0
|
||||
GetFilePath(&filePath);
|
||||
#endif
|
||||
if (filePath)
|
||||
{
|
||||
char * uri = nsnull;
|
||||
nsFileSpec folder = *filePath;
|
||||
nsBuildNewsMessageURI(folder, nsnull, &uri);
|
||||
nsBuildNewsMessageURI(m_spec, 0 /* don't have keys yet */, &uri);
|
||||
#ifdef DEBUG_alecf
|
||||
fprintf(stderr, "nsBuildNewsMessageURI(%s, %d -> %s) in nsNntpUrl::GetURI", m_spec, m_messageKey, uri);
|
||||
#endif
|
||||
*aURI = uri;
|
||||
}
|
||||
else
|
||||
|
@ -365,6 +389,7 @@ NS_IMETHODIMP nsNntpUrl::GetURI(char ** aURI)
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// End nsINntpUrl specific support
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -79,6 +79,8 @@ public:
|
|||
|
||||
NS_IMETHOD SetMessageToPost(nsINNTPNewsgroupPost *post);
|
||||
NS_IMETHOD GetMessageToPost(nsINNTPNewsgroupPost **post);
|
||||
|
||||
NS_IMETHOD GetFilePath(const nsFileSpec ** aFilePath);
|
||||
|
||||
// from nsIMsgMailNewsUrl:
|
||||
NS_IMETHOD SetUrlState(PRBool aRunningUrl, nsresult aExitCode);
|
||||
|
@ -118,6 +120,8 @@ protected:
|
|||
PRBool m_runningUrl;
|
||||
|
||||
nsINNTPNewsgroupPost *m_newsgroupPost;
|
||||
|
||||
nsFileSpec *m_filePath;
|
||||
|
||||
// manager of all of current url listeners....
|
||||
nsIUrlListenerManager * m_urlListeners;
|
||||
|
|
Загрузка…
Ссылка в новой задаче