nsINNTPProtocol.h is going away, since it is not being used.

the only thing that uses nsNNTPProtocol is nsNntpService.
remove it from the news factory.

changes to get mark message read on display working.
This commit is contained in:
sspitzer%netscape.com 1999-06-10 05:39:09 +00:00
Родитель 497dafb30f
Коммит d5d2171a10
16 изменённых файлов: 291 добавлений и 241 удалений

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

@ -34,7 +34,6 @@
#include "nsNntpService.h"
#include "nsNntpIncomingServer.h"
#include "nsNewsMessage.h"
#include "nsNNTPProtocol.h"
#include "nsNNTPNewsgroup.h"
#include "nsNNTPNewsgroupPost.h"
#include "nsNNTPNewsgroupList.h"
@ -47,7 +46,6 @@ static NS_DEFINE_CID(kNntpServiceCID, NS_NNTPSERVICE_CID);
static NS_DEFINE_CID(kNewsFolderResourceCID, NS_NEWSFOLDERRESOURCE_CID);
static NS_DEFINE_CID(kNntpIncomingServerCID, NS_NNTPINCOMINGSERVER_CID);
static NS_DEFINE_CID(kNewsMessageResourceCID, NS_NEWSMESSAGERESOURCE_CID);
static NS_DEFINE_CID(kNNTPProtocolCID, NS_NNTPPROTOCOL_CID);
static NS_DEFINE_CID(kNNTPNewsgroupCID, NS_NNTPNEWSGROUP_CID);
static NS_DEFINE_CID(kNNTPNewsgroupPostCID, NS_NNTPNEWSGROUPPOST_CID);
static NS_DEFINE_CID(kNNTPNewsgroupListCID, NS_NNTPNEWSGROUPLIST_CID);
@ -158,17 +156,6 @@ nsresult nsMsgNewsFactory::CreateInstance(nsISupports * /* aOuter */,
if (NS_FAILED(rv) && service)
delete service;
}
else if (mClassID.Equals(kNNTPProtocolCID))
{
nsNNTPProtocol *protocol = new nsNNTPProtocol();
if (protocol)
rv = protocol->QueryInterface(aIID, aResult);
else
rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv) && protocol)
delete protocol;
}
else if (mClassID.Equals(kNNTPNewsgroupPostCID))
{
nsNNTPNewsgroupPost *newsgroupPost = new nsNNTPNewsgroupPost();
@ -304,6 +291,9 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
@ -348,12 +338,6 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kNNTPProtocolCID,
"NNTP Protocol",
"component://netscape/messeneger/nntpprotocol",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kNNTPNewsgroupCID,
"NNTP Newsgroup",
"component://netscape/messeneger/nntpnewsgroup",
@ -413,9 +397,6 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* path)
rv = compMgr->UnregisterComponent(kNewsMessageResourceCID, path);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kNNTPProtocolCID, path);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kNNTPNewsgroupCID, path);
if (NS_FAILED(rv)) return rv;

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

@ -17,5 +17,4 @@
#
nsINNTPNewsgroupPost.h
nsINNTPProtocol.h
nsINntpUrl.h

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

@ -38,7 +38,6 @@ XPIDLSRCS= \
EXPORTS= \
nsINNTPNewsgroupPost.h \
nsINNTPProtocol.h \
nsINntpUrl.h \
$(NULL)

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

@ -35,7 +35,6 @@ XPIDLSRCS= \
EXPORTS= \
nsINNTPNewsgroupPost.h \
nsINNTPProtocol.h \
nsINntpUrl.h \
$(NULL)

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

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

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

@ -32,12 +32,15 @@ interface nsISupportsArray;
#include "nsString.h"
%}
/* sspitzer: TODO use MailNewsTypes.idl or MailNewsTypes.h */
typedef unsigned long nsMsgKey;
[scriptable, uuid(4C9F90E0-E19B-11d2-806E-006008128C4E)]
interface nsINntpService : nsISupports {
nsIURL PostMessage (in nsFilePath pathToFile, in string subject, in string newsgroup, in nsIUrlListener aUrlListener);
nsIURL RunNewsUrl (in nsString urlString, in nsISupports aConsumer, in nsIUrlListener aUrlListener);
nsIURL RunNewsUrl (in nsString urlString, in nsString newsgroupNane, in nsMsgKey aKey, in nsISupports aConsumer, in nsIUrlListener aUrlListener);
nsIURL GetNewNews (in nsINntpIncomingServer nntpServer, in string uri, in nsIUrlListener aUrlListener);

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

@ -34,8 +34,9 @@
#include "nsINNTPNewsgroupPost.h"
#include "nsIMsgOfflineNewsState.h"
/* BDD12930-A682-11d2-804C-006008128C4E */
class nsIMsgDBHdr;
/* BDD12930-A682-11d2-804C-006008128C4E */
#define NS_INNTPURL_IID \
{ 0xbdd12930, 0xa682, 0x11d2, \
{ 0x80, 0x4c, 0x0, 0x60, 0x8, 0x12, 0x8c, 0x4e } }
@ -74,6 +75,12 @@ public:
NS_IMETHOD SetMessageToPost (nsINNTPNewsgroupPost *post) = 0;
NS_IMETHOD GetMessageToPost (nsINNTPNewsgroupPost **post) = 0;
// return a message db header for that message.
NS_IMETHOD GetMessageHeader(nsIMsgDBHdr ** aMsgHdr) = 0;
NS_IMETHOD SetMessageKey(nsMsgKey aKey) = 0;
NS_IMETHOD SetNewsgroupName(char *aNewsgroupName) = 0;
};
#endif /* nsIHttpURL_h___ */

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

@ -69,6 +69,10 @@
#define DEFAULT_NEWS_CHUNK_SIZE -1
#ifdef DEBUG_sspitzer_
#define DEBUG_NEWS 1
#endif
/* #define UNREADY_CODE */ /* mscott: generic flag for hiding access to url struct and active entry which are now gone */
/*#define CACHE_NEWSGRP_PASSWORD*/
@ -1961,6 +1965,7 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt
m_nextState = NEWS_START_CANCEL;
else
m_nextState = NEWS_DONE;
// and close the article file if it was open....
if (m_tempArticleStream)
m_tempArticleStream->Close();
@ -1980,6 +1985,16 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt
PR_FREEIF(article_path_url);
}
// now mark the message as read
nsCOMPtr<nsIMsgDBHdr> msgHdr;
nsresult rv = NS_OK;
rv = m_runningURL->GetMessageHeader(getter_AddRefs(msgHdr));
if (NS_SUCCEEDED(rv)) {
msgHdr->MarkRead(PR_TRUE);
}
ClearFlag(NNTP_PAUSE_FOR_READ);
}
else
@ -4172,7 +4187,7 @@ nsresult nsNNTPProtocol::ProcessProtocolState(nsIURL * url, nsIInputStream * inp
{
#if DEBUG_NEWS
printf("Next state: %s",stateLabels[m_nextState]);
printf("Next state: %s\n",stateLabels[m_nextState]);
#endif
// examine our current state and call an appropriate handler for that state.....
switch(m_nextState)

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

@ -158,7 +158,7 @@ public:
NS_IMETHOD Initialize(nsIURL * aURL);
// aConsumer is typically a display stream you may want the results to be displayed into...
virtual nsresult LoadUrl(nsIURL * aURL, nsISupports * aConsumer = nsnull);
NS_IMETHOD LoadUrl(nsIURL * aURL, nsISupports * aConsumer = nsnull);
// stop binding is a "notification" informing us that the stream associated with aURL is going away.
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);

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

@ -222,7 +222,7 @@ nsNewsURI2Name(const char* rootURI, const char* uriStr, nsString& name)
/* parses NewsMessageURI */
nsresult
nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key)
nsParseNewsMessageURI(const char* uri, nsString& messageUriWithoutKey, PRUint32 *key)
{
if(!key)
return NS_ERROR_NULL_POINTER;
@ -231,8 +231,7 @@ nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key)
PRInt32 keySeparator = uriStr.Find('#');
if(keySeparator != -1)
{
nsAutoString folderPath;
uriStr.Left(folderURI, keySeparator);
uriStr.Left(messageUriWithoutKey, keySeparator);
nsAutoString keyStr;
uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1));

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

@ -63,7 +63,7 @@ extern nsresult
nsNewsURI2Name(const char* rootURI, const char* uriStr, nsString& name);
extern nsresult
nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key);
nsParseNewsMessageURI(const char* uri, nsString& messageUriWithoutKey, PRUint32 *key);
extern nsresult
nsBuildNewsMessageURI(const char *baseURI, PRUint32 key, char** uri);

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

@ -34,7 +34,6 @@
#include "nsINetService.h"
#include "nsIMsgMailSession.h"
#include "nsIMsgIdentity.h"
#include "nsString.h"
@ -54,6 +53,10 @@
#include "nsINetSupportDialogService.h"
#ifdef DEBUG_sspitzer_
#define DEBUG_NEWS 1
#endif
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
// that multiply inherits from nsISupports
@ -66,7 +69,7 @@ static NS_DEFINE_CID(kCNewsDB, NS_NEWSDB_CID);
static NS_DEFINE_CID(kNNTPNewsgroupCID, NS_NNTPNEWSGROUP_CID);
static NS_DEFINE_CID(kNNTPNewsgroupPostCID, NS_NNTPNEWSGROUPPOST_CID);
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
nsNntpService::nsNntpService()
{
NS_INIT_REFCNT();
@ -135,13 +138,12 @@ nsresult nsNntpService::DisplayMessage(const char* aMessageURI, nsISupports * aD
printf("nsNntpService::DisplayMessage(%s,...)\n",aMessageURI);
#endif
nsString uri = aMessageURI;
if (PL_strncmp(aMessageURI, kNewsRootURI, kNewsRootURILen) == 0) {
uri = aMessageURI;
}
else if (PL_strncmp(aMessageURI, kNewsMessageRootURI, kNewsMessageRootURILen) == 0) {
rv = ConvertNewsMessageURI2NewsURI(aMessageURI, uri);
nsString2 uri(aMessageURI, eOneByte);
nsString2 newsgroupName("", eOneByte);
nsMsgKey key = nsMsgKey_None;
if (PL_strncmp(aMessageURI, kNewsMessageRootURI, kNewsMessageRootURILen) == 0) {
rv = ConvertNewsMessageURI2NewsURI(aMessageURI, uri, newsgroupName, &key);
}
else {
return NS_ERROR_UNEXPECTED;
@ -150,40 +152,51 @@ nsresult nsNntpService::DisplayMessage(const char* aMessageURI, nsISupports * aD
if (NS_FAILED(rv)) {
return rv;
}
else {
return RunNewsUrl(uri, aDisplayConsumer, aUrlListener, aURL);
}
return RunNewsUrl(uri, newsgroupName, key, aDisplayConsumer, aUrlListener, aURL);
}
nsresult nsNntpService::ConvertNewsMessageURI2NewsURI(const char *messageURI, nsString &newsURI)
nsresult nsNntpService::ConvertNewsMessageURI2NewsURI(const char *messageURI, nsString &newsURI, nsString &newsgroupName, nsMsgKey *key)
{
nsAutoString hostname (eOneByte);
nsAutoString folder (eOneByte);
nsString2 hostname("", eOneByte);
nsString2 messageUriWithoutKey("", eOneByte);
nsresult rv = NS_OK;
PRUint32 key;
// messageURI is of the form: news_message://news.mcom.com/mcom.linux#1
rv = nsParseNewsMessageURI(messageURI, folder, &key);
// messageURI is of the form: "news_message://news.mcom.com/mcom.linux#1"
// if successful, we should get
// messageUriWithoutKey = "news_message://news.mcom.com/mcom.linux"
// key = 1
rv = nsParseNewsMessageURI(messageURI, messageUriWithoutKey, key);
if (NS_FAILED(rv)) {
return rv;
}
// cut news_message://hostname/group -> hostname/group
folder.Right(hostname, folder.Length() - kNewsMessageRootURILen - 1);
// turn news_message://news.mcom.com/mcom.linux -> news.mcom.com/mcom.linux
// stick "news.mcom.com/mcom.linux" in hostname.
messageUriWithoutKey.Right(hostname, messageUriWithoutKey.Length() - kNewsMessageRootURILen - 1);
// cut hostname/group -> hostname
// take news.mcom.com/mcom.linux (in hostname) and put
// "mcom.linux" into newsgroupName and truncate to leave
// "news.mcom.com" in hostname
PRInt32 hostEnd = hostname.Find('/');
if (hostEnd >0) {
if (hostEnd > 0) {
hostname.Right(newsgroupName, hostname.Length() - hostEnd - 1);
hostname.Truncate(hostEnd);
}
else {
// error!
// we didn't find a "/" in something we thought looked like this:
// news.mcom.com/mcom.linux
return NS_ERROR_FAILURE;
}
#ifdef DEBUG_NEWS
printf("ConvertNewsMessageURI2NewsURI(%s,??) -> %s %u\n", messageURI, folder.GetBuffer(), key);
printf("ConvertNewsMessageURI2NewsURI(%s,??) -> %s %u\n", messageURI, newsgroupName.GetBuffer(), *key);
#endif
nsNativeFileSpec pathResult;
rv = nsNewsURI2Path(kNewsMessageRootURI, folder.GetBuffer(), pathResult);
rv = nsNewsURI2Path(kNewsMessageRootURI, messageUriWithoutKey.GetBuffer(), pathResult);
if (NS_FAILED(rv)) {
return rv;
}
@ -204,7 +217,7 @@ nsresult nsNntpService::ConvertNewsMessageURI2NewsURI(const char *messageURI, ns
nsCOMPtr<nsIMsgDBHdr> msgHdr;
rv = newsDB->GetMsgHdrForKey((nsMsgKey) key, getter_AddRefs(msgHdr));
rv = newsDB->GetMsgHdrForKey((nsMsgKey) *key, getter_AddRefs(msgHdr));
if (NS_FAILED(rv) || (!msgHdr)) {
return rv;
}
@ -253,172 +266,122 @@ nsresult nsNntpService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListen
nsresult nsNntpService::PostMessage(nsFilePath &pathToFile, const char *subject, const char *newsgroupName, nsIUrlListener * aUrlListener, nsIURL **_retval)
{
#ifdef DEBUG_NEWS
printf("nsNntpService::PostMessage(%s,%s,%s,??,??)\n",(const char *)pathToFile,subject,newsgroupName);
printf("nsNntpService::PostMessage(%s,%s,%s,??,??)\n",(const char *)pathToFile,subject,newsgroupName);
#endif
NS_LOCK_INSTANCE();
// for now, assume the url is a news url and load it....
nsINntpUrl *nntpUrl = nsnull;
nsNNTPProtocol *nntpProtocol = nsnull;
nsresult rv = NS_OK;
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), (void **) &nntpUrl);
if (NS_SUCCEEDED(rv) && nntpUrl) {
printf("hardcoding the server name. right now, we can only post to news.mozilla.org\n");
char *urlstr = PR_smprintf("news://%s/%s","news.mozilla.org",newsgroupName);
nntpUrl->SetSpec(urlstr);
PR_FREEIF(urlstr);
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
if (NS_SUCCEEDED(rv) && newsgroup) {
newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
newsgroup->SetName((char *)newsgroupName);
}
else {
return rv;
}
nntpUrl->SetNewsgroup(newsgroup);
const char * hostname = nsnull;
PRUint32 port = NEWS_PORT;
if (aUrlListener) // register listener if there is one...
nntpUrl->RegisterListener(aUrlListener);
// okay now create a transport to run the url in...
NS_LOCK_INSTANCE();
nsCOMPtr <nsINntpUrl> nntpUrl;
nsresult rv = NS_OK;
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), getter_AddRefs(nntpUrl));
if (NS_FAILED(rv) || !nntpUrl) return rv;
printf("hardcoding the server name. right now, we can only post to news.mozilla.org\n");
char *urlstr = PR_smprintf("news://%s/%s","news.mozilla.org",newsgroupName);
nntpUrl->SetSpec(urlstr);
PR_FREEIF(urlstr);
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
if (NS_FAILED(rv) || !newsgroup) return rv;
newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
newsgroup->SetName((char *)newsgroupName);
nntpUrl->SetNewsgroup(newsgroup);
if (aUrlListener) // register listener if there is one...
nntpUrl->RegisterListener(aUrlListener);
// almost there...now create a nntp protocol instance to run the url in...
nsNNTPProtocol *nntpProtocol = nsnull;
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;;
rv = nntpProtocol->Initialize(nntpUrl);
if (NS_FAILED(rv)) return rv;
// get the current identity from the news session....
NS_WITH_SERVICE(nsIMsgMailSession,newsSession,kCMsgMailSessionCID,&rv);
if (NS_FAILED(rv) || !newsSession) return rv;
#ifdef DEBUG_NEWS
printf("nsNntpService::RunNewsUrl(): hostname = %s port = %d\n", hostname, port);
printf("post message as: %s,%s,%s\n",fullname,from,org);
#endif
// almost there...now create a nntp protocol instance to run the url in...
nntpProtocol = new nsNNTPProtocol();
if (nntpProtocol) {
rv = nntpProtocol->Initialize(nntpUrl);
if (NS_FAILED(rv)) return rv;
// get the current identity from the news session....
NS_WITH_SERVICE(nsIMsgMailSession,newsSession,kCMsgMailSessionCID,&rv);
if (NS_SUCCEEDED(rv) && newsSession) {
nsCOMPtr<nsIMsgIdentity> identity;
rv = newsSession->GetCurrentIdentity(getter_AddRefs(identity));
if (NS_SUCCEEDED(rv) && identity) {
char * fullname = nsnull;
char * from = nsnull;
char * org = nsnull;
identity->GetFullName(&fullname);
identity->GetEmail(&from);
identity->GetOrganization(&org);
nsCOMPtr <nsINNTPNewsgroupPost> post;
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupPostCID, nsnull, nsINNTPNewsgroupPost::GetIID(), getter_AddRefs(post));
if (NS_FAILED(rv) || !post) return rv;
post->AddNewsgroup(newsgroupName);
#ifdef DEBUG_NEWS
printf("post message as: %s,%s,%s\n",fullname,from,org);
printf("set file to post to %s\n",(const char *)pathToFile);
#endif
nsCOMPtr <nsINNTPNewsgroupPost> post;
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupPostCID, nsnull, nsINNTPNewsgroupPost::GetIID(), getter_AddRefs(post));
if (NS_SUCCEEDED(rv)) {
post->AddNewsgroup(newsgroupName);
post->SetSubject((char *)subject);
post->SetFrom((char *)from);
post->SetOrganization((char *)org);
#ifdef DEBUG_NEWS
printf("set file to post to %s\n",(const char *)pathToFile);
#endif
rv = post->SetPostMessageFile(pathToFile);
if (NS_FAILED(rv)) {
return rv;
}
rv = nntpUrl->SetMessageToPost(post);
if (NS_FAILED(rv)) {
return rv;
}
}
PR_FREEIF(fullname);
PR_FREEIF(from);
PR_FREEIF(org);
}
else {
NS_ASSERTION(0, "no current identity found for this user....");
}
}
if (NS_SUCCEEDED(rv))
rv = nntpProtocol->LoadUrl(nntpUrl, /* aConsumer */ nsnull);
rv = post->SetPostMessageFile(pathToFile);
if (NS_FAILED(rv)) return rv;
rv = nntpUrl->SetMessageToPost(post);
if (NS_FAILED(rv)) return rv;
rv = nntpProtocol->LoadUrl(nntpUrl, /* aConsumer */ nsnull);
if (_retval)
*_retval = nntpUrl; // transfer ref count
else
NS_RELEASE(nntpUrl);
}
}
NS_UNLOCK_INSTANCE();
if (_retval)
*_retval = nntpUrl; // transfer ref count
NS_UNLOCK_INSTANCE();
return rv;
return rv;
}
nsresult
nsNntpService::RunNewsUrl(nsString& urlString, nsISupports * aConsumer, nsIUrlListener *aUrlListener, nsIURL **_retval)
nsNntpService::RunNewsUrl(nsString& urlString, nsString &newsgroupName, nsMsgKey key, nsISupports * aConsumer, nsIUrlListener *aUrlListener, nsIURL **_retval)
{
#ifdef DEBUG_NEWS
printf("nsNntpService::RunNewsUrl(%s,...)\n", (const char *)nsAutoCString(urlString));
printf("nsNntpService::RunNewsUrl(%s,...)\n", (const char *)nsAutoCString(urlString));
#endif
// for now, assume the url is a news url and load it....
nsINntpUrl *nntpUrl = nsnull;
nsNNTPProtocol *nntpProtocol = nsnull;
nsresult rv = NS_OK;
nsCOMPtr <nsINntpUrl> nntpUrl;
nsresult rv = NS_OK;
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), (void **) &nntpUrl);
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), getter_AddRefs(nntpUrl));
if (NS_FAILED(rv) || !nntpUrl) return rv;
nntpUrl->SetSpec(nsAutoCString(urlString));
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
if (NS_FAILED(rv) || !newsgroup) return rv;
rv = newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
nsString2 newsgroupNameStr(newsgroupName,eOneByte);
newsgroup->SetName((char *)(newsgroupNameStr.GetBuffer()));
nntpUrl->SetNewsgroup(newsgroup);
if (NS_SUCCEEDED(rv) && nntpUrl) {
nntpUrl->SetSpec(nsAutoCString(urlString));
// if we are running a news url to display a message, these
// will be used later, to mark the message as read after we finish loading
nntpUrl->SetMessageKey(key);
nntpUrl->SetNewsgroupName((char *)(newsgroupNameStr.GetBuffer()));
if (aUrlListener) // register listener if there is one...
nntpUrl->RegisterListener(aUrlListener);
nsAutoString newsgroupName;
nsNewsURI2Name(kNewsRootURI, nsAutoCString(urlString), newsgroupName);
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
if (NS_SUCCEEDED(rv)) {
rv = newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
newsgroup->SetName((char *)((const char *)nsAutoCString(newsgroupName)));
}
else
return rv;
nntpUrl->SetNewsgroup(newsgroup);
// almost there...now create a nntp protocol instance to run the url in...
nsNNTPProtocol *nntpProtocol = nsnull;
nntpProtocol = new nsNNTPProtocol();
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;
rv = nntpProtocol->Initialize(nntpUrl);
if (NS_FAILED(rv)) return rv;
rv = nntpProtocol->LoadUrl(nntpUrl, aConsumer);
if (NS_FAILED(rv)) return rv;
if (_retval)
*_retval = nntpUrl; // transfer ref count
if (aUrlListener) // register listener if there is one...
nntpUrl->RegisterListener(aUrlListener);
// okay now create a transport to run the url in...
#ifdef DEBUG_NEWS
printf("nsNntpService::RunNewsUrl(): hostname = %s port = %d\n", hostname, port);
#endif
// almost there...now create a nntp protocol instance to run the url in...
nntpProtocol = new nsNNTPProtocol();
if (nntpProtocol) {
rv = nntpProtocol->Initialize(nntpUrl);
if (NS_FAILED(rv)) return rv;
rv = nntpProtocol->LoadUrl(nntpUrl, aConsumer);
if (NS_FAILED(rv)) return rv;
}
if (_retval)
*_retval = nntpUrl; // transfer ref count
else
NS_RELEASE(nntpUrl);
}
return rv;
return rv;
}
NS_IMETHODIMP nsNntpService::GetNewNews(nsINntpIncomingServer *nntpServer, const char *uri, nsIUrlListener * aUrlListener, nsIURL **_retval)
@ -452,7 +415,7 @@ NS_IMETHODIMP nsNntpService::GetNewNews(nsINntpIncomingServer *nntpServer, const
}
#endif
#ifdef DEBUG_sspitzer
#ifdef DEBUG_NEWS
if (nntpHostName) {
printf("get news from news://%s\n", nntpHostName);
}
@ -461,9 +424,21 @@ NS_IMETHODIMP nsNntpService::GetNewNews(nsINntpIncomingServer *nntpServer, const
}
#endif
nsString uriStr(uri);
rv = RunNewsUrl(uriStr, nsnull, aUrlListener, _retval);
nsString2 uriStr(uri, eOneByte);
nsString2 newsgroupName("", eOneByte);
NS_ASSERTION((uriStr.Find(kNewsRootURI) == 0), "uriStr didn't start with news:/");
if (uriStr.Find(kNewsRootURI) == 0) {
// uriStr look like this: "news://news.mcom.com/mcom.linux"
//
uriStr.Right(newsgroupName, uriStr.Length() - kNewsRootURILen /* for news:/ */ - 1 /* for the slash */ - PL_strlen(nntpHostName) /* for the hostname */ -1 /* for the next slash */);
rv = RunNewsUrl(uriStr, newsgroupName, nsMsgKey_None, nsnull, aUrlListener, _retval);
}
else {
rv = NS_ERROR_FAILURE;
}
NS_UNLOCK_INSTANCE();
return rv;
}
@ -474,32 +449,31 @@ NS_IMETHODIMP nsNntpService::CancelMessages(nsISupportsArray *messages, nsIUrlLi
PRUint32 count = 0;
NS_WITH_SERVICE(nsINetSupportDialogService,dialog,kNetSupportDialogCID,&rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
if (!messages) {
nsAutoString alertText("No articles are selected.");
if (dialog)
nsAutoString alertText("No articles are selected.");
if (dialog)
rv = dialog->Alert(alertText);
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NULL_POINTER;
}
rv = messages->Count(&count);
if (NS_FAILED(rv)) {
#ifdef DEBUG_sspitzer
#ifdef DEBUG_NEWS
printf("Count failed\n");
#endif
return rv;
}
if (count != 1) {
nsAutoString alertText("You can only cancel one article at a time.");
if (dialog)
rv = dialog->Alert(alertText);
return NS_ERROR_FAILURE;
}
// we've got an article. check that the we are the poster.
// nsAutoString alertText("This message does not appear to be from you. You may only cancel your own posts, not those made by others.");
@ -508,7 +482,7 @@ NS_IMETHODIMP nsNntpService::CancelMessages(nsISupportsArray *messages, nsIUrlLi
nsAutoString confirmText("Are you sure you want to cancel this message?");
rv = dialog->Confirm(confirmText, &result);
#ifdef DEBUG_sspitzer
#ifdef DEBUG_NEWS
printf("OK or CANCEL? %d\n",result);
#endif
@ -526,14 +500,15 @@ NS_IMETHODIMP nsNntpService::CancelMessages(nsISupportsArray *messages, nsIUrlLi
nsMsgKey key;
rv = message->GetMessageKey(&key);
if (NS_SUCCEEDED(rv)) {
if (messageIds.Length() > 0)
if (messageIds.Length() > 0) {
messageIds.Append(',');
}
messageIds.Append((PRInt32)key);
}
}
}
#ifdef DEBUG_sspitzer
#ifdef DEBUG_NEWS
printf("attempt to cancel the following IDs: %s\n", messageIds.GetBuffer());
#endif

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

@ -23,6 +23,7 @@
#include "nsIMsgMessageService.h"
#include "nsINntpIncomingServer.h"
#include "nsIFileSpec.h"
#include "MailNewsTypes.h"
class nsIURL;
class nsIUrlListener;
@ -35,7 +36,7 @@ public:
////////////////////////////////////////////////////////////////////////////////////////
NS_IMETHOD PostMessage(nsFilePath &pathToFile, const char *subject, const char *newsgroup, nsIUrlListener * aUrlListener, nsIURL **_retval);
NS_IMETHOD RunNewsUrl (nsString& urlString, nsISupports * aConsumer, nsIUrlListener * aUrlListener, nsIURL **_retval);
NS_IMETHOD RunNewsUrl (nsString& urlString, nsString& newsgroupName, nsMsgKey aKey, nsISupports * aConsumer, nsIUrlListener * aUrlListener, nsIURL **_retval);
NS_IMETHOD GetNewNews(nsINntpIncomingServer *nntpServer, const char *uri, nsIUrlListener * aUrlListener, nsIURL **_retval);
@ -56,8 +57,11 @@ public:
// nsNntpService
nsNntpService();
virtual ~nsNntpService();
nsresult ConvertNewsMessageURI2NewsURI(const char *messageURI, nsString &newsURI);
nsresult ConvertNewsMessageURI2NewsURI(const char *messageURI,
nsString &newsURI,
nsString &newsgroupName,
nsMsgKey *aKey);
NS_DECL_ISUPPORTS
};

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

@ -36,12 +36,17 @@
#include "nntpCore.h"
#include "nsCOMPtr.h"
#include "nsIMsgDatabase.h"
#include "nsMsgDBCID.h"
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
// that multiply inherits from nsISupports
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kUrlListenerManagerCID, NS_URLLISTENERMANAGER_CID);
static NS_DEFINE_CID(kCNewsDB, NS_NEWSDB_CID);
nsNntpUrl::nsNntpUrl(nsISupports* aContainer, nsIURLGroup* aGroup)
{
NS_INIT_REFCNT();
@ -54,6 +59,8 @@ nsNntpUrl::nsNntpUrl(nsISupports* aContainer, nsIURLGroup* aGroup)
m_newsgroupList = nsnull;
m_errorMessage = nsnull;
m_newsgroupPost = nsnull;
m_newsgroupName = nsnull;
m_messageKey = nsMsgKey_None;
// nsINetLibUrl specific state
m_URL_s = nsnull;
@ -87,7 +94,8 @@ nsNntpUrl::~nsNntpUrl()
NS_IF_RELEASE(m_newsgroupList);
PR_FREEIF(m_newsgroupPost);
PR_FREEIF(m_errorMessage);
PR_FREEIF(m_newsgroupName);
if (m_filePath) {
delete m_filePath;
m_filePath = nsnull;
@ -952,14 +960,6 @@ nsresult nsNntpUrl::GetContentLength(PRInt32 *len)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// End of nsIURL support
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// The following set of functions should become obsolete once we take them out of
// nsIURL.....
////////////////////////////////////////////////////////////////////////////////////
nsresult nsNntpUrl::GetLoadAttribs(nsILoadAttribs* *result) const
{
NS_LOCK_INSTANCE();
@ -1034,6 +1034,68 @@ nsresult nsNntpUrl::GetMessageToPost(nsINNTPNewsgroupPost **aPost)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// End of functions which should be made obsolete after modifying nsIURL
////////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsNntpUrl::GetMessageHeader(nsIMsgDBHdr ** aMsgHdr)
{
nsresult rv = NS_OK;
nsNativeFileSpec pathResult;
if (!aMsgHdr) return NS_ERROR_NULL_POINTER;
if (!m_newsgroupName) return NS_ERROR_FAILURE;
if (!m_host) return NS_ERROR_FAILURE;
nsString2 newsgroupURI(kNewsMessageRootURI, eOneByte);
newsgroupURI.Append("/");
newsgroupURI.Append(m_host);
newsgroupURI.Append("/");
newsgroupURI.Append(m_newsgroupName);
rv = nsNewsURI2Path(kNewsMessageRootURI, newsgroupURI.GetBuffer(), pathResult);
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIMsgDatabase> newsDBFactory;
nsCOMPtr<nsIMsgDatabase> newsDB;
rv = nsComponentManager::CreateInstance(kCNewsDB, nsnull, nsIMsgDatabase::GetIID(), getter_AddRefs(newsDBFactory));
if (NS_FAILED(rv) || (!newsDBFactory)) {
return rv;
}
rv = newsDBFactory->Open(pathResult, PR_TRUE, getter_AddRefs(newsDB), PR_FALSE);
if (NS_FAILED(rv) || (!newsDB)) {
return rv;
}
rv = newsDB->GetMsgHdrForKey(m_messageKey, aMsgHdr);
if (NS_FAILED(rv) || (!aMsgHdr)) {
return rv;
}
return NS_OK;
}
NS_IMETHODIMP nsNntpUrl::SetNewsgroupName(char * aNewsgroupName)
{
if (!aNewsgroupName) return NS_ERROR_NULL_POINTER;
PR_FREEIF(m_newsgroupName);
m_newsgroupName = nsnull;
m_newsgroupName = PL_strdup(aNewsgroupName);
if (!m_newsgroupName) {
return NS_ERROR_OUT_OF_MEMORY;
}
else {
return NS_OK;
}
}
NS_IMETHODIMP nsNntpUrl::SetMessageKey(nsMsgKey aKey)
{
m_messageKey = aKey;
return NS_OK;
}

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

@ -81,7 +81,12 @@ public:
NS_IMETHOD GetMessageToPost(nsINNTPNewsgroupPost **post);
NS_IMETHOD GetFilePath(const nsFileSpec ** aFilePath);
NS_IMETHOD GetMessageHeader(nsIMsgDBHdr ** aMsgHdr);
NS_IMETHOD SetMessageKey(nsMsgKey aKey);
NS_IMETHOD SetNewsgroupName(char *aNewsgroupName);
// from nsIMsgMailNewsUrl:
NS_IMETHOD SetUrlState(PRBool aRunningUrl, nsresult aExitCode);
NS_IMETHOD GetUrlState(PRBool * aRunningUrl);
@ -135,7 +140,9 @@ protected:
nsINNTPNewsgroup * m_newsgroup;
nsIMsgOfflineNewsState * m_offlineNews;
nsINNTPNewsgroupList * m_newsgroupList;
nsMsgKey m_messageKey;
char * m_newsgroupName;
void ReconstructSpec(void);
};