зеркало из https://github.com/mozilla/pjs.git
Updates to include the fact that Initialialzing the protocol instance no longer requires the
transport object to be created. It does it for you. These changes are related to my nsMsgProtocol changes.
This commit is contained in:
Родитель
882a2de9af
Коммит
d0d08e4abb
|
@ -260,121 +260,100 @@ nsresult nsNntpService::PostMessage(nsFilePath &pathToFile, const char *subject,
|
||||||
|
|
||||||
// for now, assume the url is a news url and load it....
|
// for now, assume the url is a news url and load it....
|
||||||
nsINntpUrl *nntpUrl = nsnull;
|
nsINntpUrl *nntpUrl = nsnull;
|
||||||
nsCOMPtr<nsINetService> pNetService;
|
|
||||||
nsCOMPtr<nsITransport> transport;
|
|
||||||
nsNNTPProtocol *nntpProtocol = nsnull;
|
nsNNTPProtocol *nntpProtocol = nsnull;
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
// make sure we have a netlib service around...
|
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), (void **) &nntpUrl);
|
||||||
rv = NS_NewINetService(getter_AddRefs(pNetService), nsnull);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && pNetService) {
|
|
||||||
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), (void **)
|
|
||||||
&nntpUrl);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && nntpUrl) {
|
if (NS_SUCCEEDED(rv) && nntpUrl) {
|
||||||
printf("hardcoding the server name. right now, we can only post to news.mozilla.org\n");
|
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);
|
char *urlstr = PR_smprintf("news://%s/%s","news.mozilla.org",newsgroupName);
|
||||||
nntpUrl->SetSpec(urlstr);
|
nntpUrl->SetSpec(urlstr);
|
||||||
PR_FREEIF(urlstr);
|
PR_FREEIF(urlstr);
|
||||||
|
|
||||||
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
|
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
|
||||||
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
|
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && newsgroup) {
|
if (NS_SUCCEEDED(rv) && newsgroup) {
|
||||||
newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
|
newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
|
||||||
newsgroup->SetName((char *)newsgroupName);
|
newsgroup->SetName((char *)newsgroupName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
nntpUrl->SetNewsgroup(newsgroup);
|
nntpUrl->SetNewsgroup(newsgroup);
|
||||||
|
|
||||||
const char * hostname = nsnull;
|
const char * hostname = nsnull;
|
||||||
PRUint32 port = NEWS_PORT;
|
PRUint32 port = NEWS_PORT;
|
||||||
|
|
||||||
if (aUrlListener) // register listener if there is one...
|
if (aUrlListener) // register listener if there is one...
|
||||||
nntpUrl->RegisterListener(aUrlListener);
|
nntpUrl->RegisterListener(aUrlListener);
|
||||||
|
|
||||||
rv = nntpUrl->GetHostPort(&port);
|
|
||||||
if (NS_FAILED(rv)) {
|
// okay now create a transport to run the url in...
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
rv = nntpUrl->GetHost(&hostname);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
// okay now create a transport to run the url in...
|
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("nsNntpService::RunNewsUrl(): hostname = %s port = %d\n", hostname, port);
|
printf("nsNntpService::RunNewsUrl(): hostname = %s port = %d\n", hostname, port);
|
||||||
#endif
|
#endif
|
||||||
pNetService->CreateSocketTransport(getter_AddRefs(transport), port, hostname);
|
// almost there...now create a nntp protocol instance to run the url in...
|
||||||
if (NS_SUCCEEDED(rv) && transport)
|
nntpProtocol = new nsNNTPProtocol();
|
||||||
{
|
if (nntpProtocol) {
|
||||||
// almost there...now create a nntp protocol instance to run the url in...
|
rv = nntpProtocol->Initialize(nntpUrl);
|
||||||
nntpProtocol = new nsNNTPProtocol();
|
if (NS_FAILED(rv)) return rv;
|
||||||
if (nntpProtocol) {
|
// get the current identity from the news session....
|
||||||
rv = nntpProtocol->Initialize(nntpUrl, transport);
|
NS_WITH_SERVICE(nsIMsgMailSession,newsSession,kCMsgMailSessionCID,&rv);
|
||||||
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) {
|
if (NS_SUCCEEDED(rv) && newsSession) {
|
||||||
nsCOMPtr<nsIMsgIdentity> identity;
|
nsCOMPtr<nsIMsgIdentity> identity;
|
||||||
rv = newsSession->GetCurrentIdentity(getter_AddRefs(identity));
|
rv = newsSession->GetCurrentIdentity(getter_AddRefs(identity));
|
||||||
if (NS_SUCCEEDED(rv) && identity) {
|
if (NS_SUCCEEDED(rv) && identity) {
|
||||||
char * fullname = nsnull;
|
char * fullname = nsnull;
|
||||||
char * from = nsnull;
|
char * from = nsnull;
|
||||||
char * org = nsnull;
|
char * org = nsnull;
|
||||||
|
|
||||||
identity->GetFullName(&fullname);
|
identity->GetFullName(&fullname);
|
||||||
identity->GetEmail(&from);
|
identity->GetEmail(&from);
|
||||||
identity->GetOrganization(&org);
|
identity->GetOrganization(&org);
|
||||||
|
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("post message as: %s,%s,%s\n",fullname,from,org);
|
printf("post message as: %s,%s,%s\n",fullname,from,org);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsCOMPtr <nsINNTPNewsgroupPost> post;
|
nsCOMPtr <nsINNTPNewsgroupPost> post;
|
||||||
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupPostCID, nsnull, nsINNTPNewsgroupPost::GetIID(), getter_AddRefs(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)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
PRInt32 status = 0;
|
post->AddNewsgroup(newsgroupName);
|
||||||
rv = nntpProtocol->LoadURL(nntpUrl, /* aConsumer */ nsnull, &status);
|
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....");
|
||||||
}
|
}
|
||||||
//delete nntpProtocol?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
PRInt32 status = 0;
|
||||||
|
rv = nntpProtocol->LoadUrl(nntpUrl, /* aConsumer */ nsnull, &status);
|
||||||
|
}
|
||||||
|
|
||||||
if (_retval)
|
if (_retval)
|
||||||
*_retval = nntpUrl; // transfer ref count
|
*_retval = nntpUrl; // transfer ref count
|
||||||
else
|
else
|
||||||
|
@ -395,72 +374,53 @@ nsNntpService::RunNewsUrl(nsString& urlString, nsISupports * aConsumer, nsIUrlLi
|
||||||
#endif
|
#endif
|
||||||
// for now, assume the url is a news url and load it....
|
// for now, assume the url is a news url and load it....
|
||||||
nsINntpUrl *nntpUrl = nsnull;
|
nsINntpUrl *nntpUrl = nsnull;
|
||||||
nsCOMPtr<nsINetService> pNetService;
|
|
||||||
nsCOMPtr<nsITransport> transport;
|
|
||||||
nsNNTPProtocol *nntpProtocol = nsnull;
|
nsNNTPProtocol *nntpProtocol = nsnull;
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
// make sure we have a netlib service around...
|
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), (void **) &nntpUrl);
|
||||||
rv = NS_NewINetService(getter_AddRefs(pNetService), nsnull);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && pNetService)
|
if (NS_SUCCEEDED(rv) && nntpUrl) {
|
||||||
{
|
nntpUrl->SetSpec(nsAutoCString(urlString));
|
||||||
rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), (void **) &nntpUrl);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && nntpUrl) {
|
nsAutoString newsgroupName;
|
||||||
nntpUrl->SetSpec(nsAutoCString(urlString));
|
nsNewsURI2Name(kNewsRootURI, nsAutoCString(urlString), newsgroupName);
|
||||||
|
|
||||||
nsAutoString newsgroupName;
|
|
||||||
nsNewsURI2Name(kNewsRootURI, nsAutoCString(urlString), newsgroupName);
|
|
||||||
|
|
||||||
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
|
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
|
||||||
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
|
rv = nsComponentManager::CreateInstance(kNNTPNewsgroupCID, nsnull, nsINNTPNewsgroup::GetIID(), getter_AddRefs(newsgroup));
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
rv = newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
|
rv = newsgroup->Initialize(nsnull /* line */, nsnull /* set */, PR_FALSE /* subscribed */);
|
||||||
newsgroup->SetName((char *)((const char *)nsAutoCString(newsgroupName)));
|
newsgroup->SetName((char *)((const char *)nsAutoCString(newsgroupName)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nntpUrl->SetNewsgroup(newsgroup);
|
nntpUrl->SetNewsgroup(newsgroup);
|
||||||
|
|
||||||
const char * hostname = nsnull;
|
if (aUrlListener) // register listener if there is one...
|
||||||
PRUint32 port = NEWS_PORT;
|
nntpUrl->RegisterListener(aUrlListener);
|
||||||
|
|
||||||
if (aUrlListener) // register listener if there is one...
|
|
||||||
nntpUrl->RegisterListener(aUrlListener);
|
|
||||||
|
|
||||||
nntpUrl->GetHostPort(&port);
|
// okay now create a transport to run the url in...
|
||||||
nntpUrl->GetHost(&hostname);
|
|
||||||
// okay now create a transport to run the url in...
|
|
||||||
|
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("nsNntpService::RunNewsUrl(): hostname = %s port = %d\n", hostname, port);
|
printf("nsNntpService::RunNewsUrl(): hostname = %s port = %d\n", hostname, port);
|
||||||
#endif
|
#endif
|
||||||
pNetService->CreateSocketTransport(getter_AddRefs(transport), port, hostname);
|
// almost there...now create a nntp protocol instance to run the url in...
|
||||||
//PR_FREEIF(hostname);
|
nntpProtocol = new nsNNTPProtocol();
|
||||||
if (NS_SUCCEEDED(rv) && transport) {
|
if (nntpProtocol) {
|
||||||
// almost there...now create a nntp protocol instance to run the url in...
|
PRInt32 status = 0;
|
||||||
nntpProtocol = new nsNNTPProtocol();
|
rv = nntpProtocol->Initialize(nntpUrl);
|
||||||
if (nntpProtocol) {
|
if (NS_FAILED(rv)) return rv;
|
||||||
PRInt32 status = 0;
|
rv = nntpProtocol->LoadUrl(nntpUrl, aConsumer, &status);
|
||||||
rv = nntpProtocol->Initialize(nntpUrl, transport);
|
if (NS_FAILED(rv)) return rv;
|
||||||
if (NS_FAILED(rv)) return rv;
|
}
|
||||||
rv = nntpProtocol->LoadURL(nntpUrl, aConsumer, &status);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
//delete nntpProtocol;
|
if (_retval)
|
||||||
}
|
*_retval = nntpUrl; // transfer ref count
|
||||||
|
else
|
||||||
if (_retval)
|
NS_RELEASE(nntpUrl);
|
||||||
*_retval = nntpUrl; // transfer ref count
|
}
|
||||||
else
|
|
||||||
NS_RELEASE(nntpUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче