зеркало из https://github.com/mozilla/pjs.git
convert auth news to use single sign on. convert the nsINntpService interface
to have proper interCaps. remove dead code, clean up other code. r=alecf
This commit is contained in:
Родитель
40b08d3c88
Коммит
e2cbafada0
|
@ -23,10 +23,16 @@
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
#include "nsIMsgFolder.idl"
|
#include "nsIMsgFolder.idl"
|
||||||
|
|
||||||
|
interface nsIMsgWindow;
|
||||||
|
|
||||||
[scriptable, uuid(3716abe4-f6d4-11d2-86d5-004005263078)]
|
[scriptable, uuid(3716abe4-f6d4-11d2-86d5-004005263078)]
|
||||||
interface nsIMsgNewsFolder : nsISupports {
|
interface nsIMsgNewsFolder : nsISupports {
|
||||||
attribute string unreadSetStr;
|
attribute string unreadSetStr;
|
||||||
attribute string groupUsername;
|
attribute string groupUsername;
|
||||||
attribute string groupPassword;
|
attribute string groupPassword;
|
||||||
|
|
||||||
|
string getGroupPasswordWithUI(in wstring aPromptString, in wstring aPromptTitle, in nsIMsgWindow aMsgWindow);
|
||||||
|
string getGroupUsernameWithUI(in wstring aPromptString, in wstring aPromptTitle, in nsIMsgWindow aMsgWindow);
|
||||||
|
|
||||||
nsIMsgFolder addNewsgroup(in string newsgroupName, in string setStr);
|
nsIMsgFolder addNewsgroup(in string newsgroupName, in string setStr);
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,12 +33,12 @@ interface nsIMsgWindow;
|
||||||
[scriptable, uuid(4C9F90E0-E19B-11d2-806E-006008128C4E)]
|
[scriptable, uuid(4C9F90E0-E19B-11d2-806E-006008128C4E)]
|
||||||
interface nsINntpService : nsISupports {
|
interface nsINntpService : nsISupports {
|
||||||
|
|
||||||
string ConvertNewsgroupsString(in string newsgroupsStr);
|
string convertNewsgroupsString(in string newsgroupsStr);
|
||||||
|
|
||||||
nsIURI PostMessage (in nsIFileSpec fileToPost, in string newsgroupNames, in nsIUrlListener aUrlListener);
|
nsIURI postMessage (in nsIFileSpec fileToPost, in string newsgroupNames, in nsIUrlListener aUrlListener);
|
||||||
|
|
||||||
nsIURI GetNewNews (in nsINntpIncomingServer nntpServer, in string uri, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow);
|
nsIURI getNewNews (in nsINntpIncomingServer nntpServer, in string uri, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow);
|
||||||
|
|
||||||
nsIURI CancelMessages (in string hostname, in string newsgroupname, in nsISupportsArray messages, in nsISupports aConsumer, in nsIUrlListener aUrlListener);
|
nsIURI cancelMessages (in string hostname, in string newsgroupname, in nsISupportsArray messages, in nsISupports aConsumer, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/NPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
function doit() {
|
|
||||||
dump("start of doit()\n");
|
|
||||||
|
|
||||||
var str = document.getElementById('newsgroups').value;
|
|
||||||
var news = Components.classes['component://netscape/messenger/nntpservice'];
|
|
||||||
|
|
||||||
if (news) {
|
|
||||||
news = news.getService();
|
|
||||||
}
|
|
||||||
if (news) {
|
|
||||||
news = news.QueryInterface(Components.interfaces.nsINntpService);
|
|
||||||
}
|
|
||||||
if (news) {
|
|
||||||
try {
|
|
||||||
document.getElementById('result').value = news.ConvertNewsgroupsString(str);
|
|
||||||
}
|
|
||||||
catch (ex) {
|
|
||||||
dump(ex + "\n");
|
|
||||||
document.getElementById('result').value = "Error check console";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -82,6 +82,15 @@
|
||||||
#include "nsIRDFResource.h"
|
#include "nsIRDFResource.h"
|
||||||
#include "nsRDFCID.h"
|
#include "nsRDFCID.h"
|
||||||
|
|
||||||
|
#include "nsIMsgWindow.h"
|
||||||
|
#include "nsIWebShell.h"
|
||||||
|
#include "nsIWebShellWindow.h"
|
||||||
|
#include "nsINetPrompt.h"
|
||||||
|
|
||||||
|
#ifdef DEBUG_sspitzer
|
||||||
|
#define DEBUG_NEWS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_NEWS_CHUNK_SIZE -1
|
#define DEFAULT_NEWS_CHUNK_SIZE -1
|
||||||
|
|
||||||
// ***jt -- the following were pirated from xpcom/io/nsByteBufferInputStream
|
// ***jt -- the following were pirated from xpcom/io/nsByteBufferInputStream
|
||||||
|
@ -123,8 +132,7 @@ protected:
|
||||||
PRUint32 mLength;
|
PRUint32 mLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*#define CACHE_NEWSGRP_PASSWORD*/
|
// todo: get rid of this
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
char * NET_SACopy (char **destination, const char *source);
|
char * NET_SACopy (char **destination, const char *source);
|
||||||
|
@ -294,7 +302,6 @@ char *stateLabels[] = {
|
||||||
(the object that is going to manage the NNTP connections. it would keep track of the connection list.)
|
(the object that is going to manage the NNTP connections. it would keep track of the connection list.)
|
||||||
*/
|
*/
|
||||||
/* PRIVATE XP_List * nntp_connection_list=0; */
|
/* PRIVATE XP_List * nntp_connection_list=0; */
|
||||||
static PRBool net_news_last_username_probably_valid=PR_FALSE;
|
|
||||||
PRInt32 net_NewsChunkSize=DEFAULT_NEWS_CHUNK_SIZE;
|
PRInt32 net_NewsChunkSize=DEFAULT_NEWS_CHUNK_SIZE;
|
||||||
/* PRIVATE PRInt32 net_news_timeout = 170; */
|
/* PRIVATE PRInt32 net_news_timeout = 170; */
|
||||||
/* seconds that an idle NNTP conn can live */
|
/* seconds that an idle NNTP conn can live */
|
||||||
|
@ -433,7 +440,7 @@ nsDummyBufferStream::QueryInterface(REFNSIID aIID, void** result)
|
||||||
return NS_ERROR_NO_INTERFACE;
|
return NS_ERROR_NO_INTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsNNTPProtocol::nsNNTPProtocol(nsIURI * aURL)
|
nsNNTPProtocol::nsNNTPProtocol(nsIURI * aURL, nsIMsgWindow *aMsgWindow)
|
||||||
: nsMsgProtocol(aURL, nsnull)
|
: nsMsgProtocol(aURL, nsnull)
|
||||||
{
|
{
|
||||||
m_messageID = nsnull;
|
m_messageID = nsnull;
|
||||||
|
@ -441,6 +448,10 @@ nsNNTPProtocol::nsNNTPProtocol(nsIURI * aURL)
|
||||||
m_cancelNewsgroups = nsnull;
|
m_cancelNewsgroups = nsnull;
|
||||||
m_cancelDistribution = nsnull;
|
m_cancelDistribution = nsnull;
|
||||||
m_cancelID = nsnull;
|
m_cancelID = nsnull;
|
||||||
|
|
||||||
|
if (aMsgWindow) {
|
||||||
|
m_msgWindow = aMsgWindow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsNNTPProtocol::~nsNNTPProtocol()
|
nsNNTPProtocol::~nsNNTPProtocol()
|
||||||
|
@ -545,8 +556,37 @@ nsresult nsNNTPProtocol::Initialize(void)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsNNTPProtocol::InitializeNewsFolderFromUri(const char *uri)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
NS_ENSURE_ARG_POINTER(uri);
|
||||||
|
|
||||||
|
#ifdef DEBUG_NEWS
|
||||||
|
printf("InitializeNewsFolderFromUri(%s)\n",uri);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
|
||||||
|
if (NS_FAILED(rv)) return(rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIRDFResource> resource;
|
||||||
|
rv = rdf->GetResource(uri, getter_AddRefs(resource));
|
||||||
|
if (NS_FAILED(rv)) return(rv);
|
||||||
|
|
||||||
|
m_newsFolder = do_QueryInterface(resource, &rv);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
if (!m_newsFolder) return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
|
nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
|
||||||
{
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aURL);
|
||||||
|
|
||||||
PRBool bVal = PR_FALSE;
|
PRBool bVal = PR_FALSE;
|
||||||
nsXPIDLCString group;
|
nsXPIDLCString group;
|
||||||
char *commandSpecificData = nsnull;
|
char *commandSpecificData = nsnull;
|
||||||
|
@ -555,32 +595,25 @@ nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
m_articleNumber = -1;
|
m_articleNumber = -1;
|
||||||
if (aURL)
|
rv = aURL->GetHost(getter_Copies(m_hostName));
|
||||||
{
|
if (NS_FAILED(rv)) return rv;
|
||||||
rv = aURL->GetHost(getter_Copies(m_hostName));
|
rv = aURL->GetPreHost(getter_Copies(m_userName));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
rv = aURL->GetPreHost(getter_Copies(m_userName));
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
m_runningURL = do_QueryInterface(aURL, &rv);
|
m_runningURL = do_QueryInterface(aURL, &rv);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
m_runningURL->GetNewsAction(&m_newsAction);
|
m_runningURL->GetNewsAction(&m_newsAction);
|
||||||
|
|
||||||
// okay, now fill in our event sinks...Note that each getter ref counts before
|
// okay, now fill in our event sinks...Note that each getter ref counts before
|
||||||
// it returns the interface to us...we'll release when we are done
|
// it returns the interface to us...we'll release when we are done
|
||||||
m_runningURL->GetNewsgroupList(getter_AddRefs(m_newsgroupList));
|
m_runningURL->GetNewsgroupList(getter_AddRefs(m_newsgroupList));
|
||||||
m_runningURL->GetNntpArticleList(getter_AddRefs(m_articleList));
|
m_runningURL->GetNntpArticleList(getter_AddRefs(m_articleList));
|
||||||
m_runningURL->GetNntpHost(getter_AddRefs(m_newsHost));
|
m_runningURL->GetNntpHost(getter_AddRefs(m_newsHost));
|
||||||
m_runningURL->GetNewsgroup(getter_AddRefs(m_newsgroup));
|
m_runningURL->GetNewsgroup(getter_AddRefs(m_newsgroup));
|
||||||
m_runningURL->GetOfflineNewsState(getter_AddRefs(m_offlineNewsState));
|
m_runningURL->GetOfflineNewsState(getter_AddRefs(m_offlineNewsState));
|
||||||
}
|
|
||||||
else
|
|
||||||
rv = NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
{
|
if (NS_FAILED(rv)) goto FAIL;
|
||||||
goto FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
PR_FREEIF(m_messageID);
|
PR_FREEIF(m_messageID);
|
||||||
m_messageID = nsnull;
|
m_messageID = nsnull;
|
||||||
|
@ -711,15 +744,14 @@ nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
|
||||||
news:/GROUP
|
news:/GROUP
|
||||||
news://HOST/GROUP
|
news://HOST/GROUP
|
||||||
*/
|
*/
|
||||||
#ifdef UNREADY_CODE
|
|
||||||
if (ce->window_id->type != MWContextNews && ce->window_id->type != MWContextNewsMsg
|
nsXPIDLCString newsgroupURI;
|
||||||
&& ce->window_id->type != MWContextMailMsg
|
rv = aURL->GetSpec(getter_Copies(newsgroupURI));
|
||||||
&& ce->window_id->type != MWContextMail && ce->window_id->type != MWContextMailNewsProgress)
|
if (NS_FAILED(rv)) return(rv);
|
||||||
{
|
|
||||||
*status = -1;
|
rv = InitializeNewsFolderFromUri((const char *)newsgroupURI);
|
||||||
goto FAIL;
|
if (NS_FAILED(rv)) return(rv);
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (PL_strchr (group, '*'))
|
if (PL_strchr (group, '*'))
|
||||||
m_typeWanted = LIST_WANTED;
|
m_typeWanted = LIST_WANTED;
|
||||||
else
|
else
|
||||||
|
@ -1111,46 +1143,6 @@ PRInt32 nsNNTPProtocol::NewsResponse(nsIInputStream * inputStream, PRUint32 leng
|
||||||
|
|
||||||
/* authentication required can come at any time
|
/* authentication required can come at any time
|
||||||
*/
|
*/
|
||||||
#ifdef CACHE_NEWSGRP_PASSWORD
|
|
||||||
/*
|
|
||||||
* This is an effort of trying to cache the username/password
|
|
||||||
* per newsgroup. It is extremely hard to make it work along with
|
|
||||||
* nntp voluntary password checking mechanism. We are backing this
|
|
||||||
* feature out. Instead of touching various of backend msg files
|
|
||||||
* at this late Dogbert 4.0 beta4 game, the infrastructure will
|
|
||||||
* remain in the msg library. We only modify codes within this file.
|
|
||||||
* Maybe one day we will try to do it again. Zzzzz -- jht
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(MK_NNTP_RESPONSE_AUTHINFO_REQUIRE == m_responseCode ||
|
|
||||||
MK_NTTP_RESPONSE_AUTHINFO_SIMPLE_REQUIRE == m_responseCode ||
|
|
||||||
MK_NNTP_RESPONSE_PERMISSION_DENIED == m_responseCode)
|
|
||||||
{
|
|
||||||
m_nextState = NNTP_BEGIN_AUTHORIZE;
|
|
||||||
if (MK_NNTP_RESPONSE_PERMISSION_DENIED == m_responseCode)
|
|
||||||
{
|
|
||||||
if (MK_NNTP_RESPONSE_TYPE_OK == MK_NNTP_RESPONSE_TYPE(m_previousResponseCode)
|
|
||||||
{
|
|
||||||
if (net_news_last_username_probably_valid)
|
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_newsgroup->SetUsername(NULL);
|
|
||||||
m_newsgroup->SetPassword(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
if (NNTP_PASSWORD_RESPONSE == m_nextStateAfterResponse)
|
|
||||||
{
|
|
||||||
m_newsgroup->SetUsername(NULL);
|
|
||||||
m_newsgroup->SetPassword(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (MK_NNTP_RESPONSE_AUTHINFO_REQUIRE == m_responseCode ||
|
if (MK_NNTP_RESPONSE_AUTHINFO_REQUIRE == m_responseCode ||
|
||||||
MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_REQUIRE == m_responseCode)
|
MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_REQUIRE == m_responseCode)
|
||||||
{
|
{
|
||||||
|
@ -1158,17 +1150,12 @@ PRInt32 nsNNTPProtocol::NewsResponse(nsIInputStream * inputStream, PRUint32 leng
|
||||||
}
|
}
|
||||||
else if (MK_NNTP_RESPONSE_PERMISSION_DENIED == m_responseCode)
|
else if (MK_NNTP_RESPONSE_PERMISSION_DENIED == m_responseCode)
|
||||||
{
|
{
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
#ifdef UNREADY_CODE
|
|
||||||
return net_display_html_error_state(ce);
|
|
||||||
#else
|
|
||||||
PR_FREEIF(line);
|
PR_FREEIF(line);
|
||||||
return (0);
|
return (0);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
else {
|
||||||
else
|
|
||||||
m_nextState = m_nextStateAfterResponse;
|
m_nextState = m_nextStateAfterResponse;
|
||||||
|
}
|
||||||
|
|
||||||
PR_FREEIF(line);
|
PR_FREEIF(line);
|
||||||
return(0); /* everything ok */
|
return(0); /* everything ok */
|
||||||
|
@ -1511,8 +1498,7 @@ PRInt32 nsNNTPProtocol::SendListSubscriptionsResponse(nsIInputStream * inputStre
|
||||||
if ('.' != line[0])
|
if ('.' != line[0])
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
char *urlScheme = "news:";
|
char *url = PR_smprintf ("%s//%s/%s", NEWS_SCHEME, m_hostName, line);
|
||||||
char *url = PR_smprintf ("%s//%s/%s", urlScheme, m_hostName, line);
|
|
||||||
if (url)
|
if (url)
|
||||||
MSG_AddSubscribedNewsgroup (cd->pane, url);
|
MSG_AddSubscribedNewsgroup (cd->pane, url);
|
||||||
#endif
|
#endif
|
||||||
|
@ -2303,163 +2289,65 @@ void nsNNTPProtocol::ParseHeaderForCancel(char *buf)
|
||||||
PRInt32 nsNNTPProtocol::BeginAuthorization()
|
PRInt32 nsNNTPProtocol::BeginAuthorization()
|
||||||
{
|
{
|
||||||
char * command = 0;
|
char * command = 0;
|
||||||
nsXPIDLString username;
|
nsXPIDLCString username;
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
PRInt32 status = 0;
|
PRInt32 status = 0;
|
||||||
nsCOMPtr <nsIMsgNewsFolder> newsFolder;
|
|
||||||
nsXPIDLCString cachedUsername;
|
nsXPIDLCString cachedUsername;
|
||||||
#if 0
|
|
||||||
char * cp;
|
|
||||||
#endif /* 0 */
|
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
|
if (!m_newsFolder) {
|
||||||
if (NS_FAILED(rv)) return(MK_NNTP_AUTH_FAILED);
|
if (!m_runningURL) return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
nsCAutoString newsgroupURI;
|
nsCAutoString folderURI = "news://";
|
||||||
if (m_newsgroup && m_hostName) {
|
folderURI += (const char *)m_hostName;
|
||||||
nsXPIDLCString groupName;
|
folderURI += "/";
|
||||||
rv = m_newsgroup->GetName(getter_Copies(groupName));
|
|
||||||
if (NS_SUCCEEDED(rv) && groupName) {
|
|
||||||
newsgroupURI = kNewsRootURI;
|
|
||||||
newsgroupURI += "/";
|
|
||||||
if (m_userName) {
|
|
||||||
newsgroupURI += m_userName;
|
|
||||||
newsgroupURI += "@";
|
|
||||||
}
|
|
||||||
newsgroupURI += m_hostName;
|
|
||||||
newsgroupURI += "/";
|
|
||||||
newsgroupURI += groupName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CACHE_NEWSGRP_PASSWORD
|
nsXPIDLCString newsgroupName;
|
||||||
/* reuse cached username from newsgroup folder info*/
|
rv = m_runningURL->GetNewsgroupName(getter_Copies(newsgroupName));
|
||||||
if (cd->pane &&
|
if (NS_SUCCEEDED(rv) && ((const char *)newsgroupName)) {
|
||||||
(!net_news_last_username_probably_valid ||
|
folderURI += (const char *)newsgroupName;
|
||||||
(last_username_hostname &&
|
rv = InitializeNewsFolderFromUri((const char *)folderURI);
|
||||||
PL_strcasecmp(last_username_hostname, m_hostName))))
|
}
|
||||||
{
|
|
||||||
m_newsgroup->GetUsername(&username);
|
|
||||||
if (username && last_username &&
|
|
||||||
!PL_strcmp (username, last_username) &&
|
|
||||||
(m_previousResponseCode == MK_NNTP_RESPONSE_AUTHINFO_OK ||
|
|
||||||
m_previousResponseCode == MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_OK ||
|
|
||||||
m_previousResponseCode == MK_NNTP_RESPONSE_GROUP_SELECTED)) {
|
|
||||||
PR_FREEIF (username);
|
|
||||||
m_newsgroup->SetUsername(NULL);
|
|
||||||
m_newsgroup->SetPassword(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Following a snews://username:password@newhost.domain.com/newsgroup.topic
|
|
||||||
* backend calls MSG_Master::FindNewsHost() to locate the folderInfo and setting
|
|
||||||
* the username/password to the newsgroup folderInfo
|
|
||||||
*/
|
|
||||||
m_newsgroup->GetUsername(&username);
|
|
||||||
if (username && *username) {
|
|
||||||
NET_SACopy(&last_username, username);
|
|
||||||
NET_SACopy(&last_username_hostname, m_hostName);
|
|
||||||
/* use it for only once */
|
|
||||||
m_newsgroup->SetUsername(NULL);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* empty username; free and clear it so it will work with
|
|
||||||
* our logic
|
|
||||||
*/
|
|
||||||
PR_FREEIF(username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the URL/m_hostName contains @ this must be triggered
|
if (m_newsFolder) {
|
||||||
* from the bookmark. Use the embed username if we could.
|
rv = m_newsFolder->GetGroupUsername(getter_Copies(cachedUsername));
|
||||||
*/
|
}
|
||||||
if ((cp = PL_strchr(m_hostName, '@')) != NULL)
|
|
||||||
{
|
|
||||||
/* in this case the username and possibly
|
|
||||||
* the password are in the URL
|
|
||||||
*/
|
|
||||||
char * colon;
|
|
||||||
*cp = '\0';
|
|
||||||
|
|
||||||
colon = PL_strchr(m_hostName, ':');
|
|
||||||
if(colon)
|
|
||||||
*colon = '\0';
|
|
||||||
|
|
||||||
NET_SACopy(&username, m_hostName);
|
|
||||||
NET_SACopy(&last_username, m_hostName);
|
|
||||||
NET_SACopy(&last_username_hostname, cp+1);
|
|
||||||
|
|
||||||
*cp = '@';
|
|
||||||
|
|
||||||
if(colon)
|
|
||||||
*colon = ':';
|
|
||||||
}
|
|
||||||
/* reuse global saved username if we think it is
|
|
||||||
* valid
|
|
||||||
*/
|
|
||||||
if (!username && net_news_last_username_probably_valid)
|
|
||||||
{
|
|
||||||
if( last_username_hostname &&
|
|
||||||
!PL_strcasecmp(last_username_hostname, m_hostName) )
|
|
||||||
NET_SACopy(&username, last_username);
|
|
||||||
else
|
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
}
|
|
||||||
#endif /* 0 */
|
|
||||||
|
|
||||||
if ((const char *)newsgroupURI) {
|
|
||||||
nsCOMPtr<nsIRDFResource> resource;
|
|
||||||
rv = rdf->GetResource((const char *)newsgroupURI, getter_AddRefs(resource));
|
|
||||||
if (NS_FAILED(rv)) return(MK_NNTP_AUTH_FAILED);
|
|
||||||
|
|
||||||
newsFolder = do_QueryInterface(resource, &rv);
|
|
||||||
if (NS_FAILED(rv) || !newsFolder) return(MK_NNTP_AUTH_FAILED);
|
|
||||||
|
|
||||||
rv = newsFolder->GetGroupUsername(getter_Copies(cachedUsername));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_FAILED(rv) || !cachedUsername) {
|
if (NS_FAILED(rv) || !cachedUsername) {
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("ask for the news username\n");
|
printf("ask for the news username\n");
|
||||||
#endif /* DEBUG_NEWS */
|
#endif /* DEBUG_NEWS */
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIPrompt, dialog, kCNetSupportDialogCID, &rv);
|
|
||||||
if (NS_FAILED(rv) || !dialog) {
|
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
|
||||||
}
|
|
||||||
nsXPIDLString usernamePromptText;
|
nsXPIDLString usernamePromptText;
|
||||||
GetNewsStringByName("enterUsername", getter_Copies(usernamePromptText));
|
GetNewsStringByName("enterUsername", getter_Copies(usernamePromptText));
|
||||||
PRBool okButtonClicked = PR_FALSE;
|
if (m_newsFolder) {
|
||||||
rv = dialog->Prompt(usernamePromptText, nsnull /* default text */, getter_Copies(username), &okButtonClicked);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && !okButtonClicked) {
|
if (!m_msgWindow) {
|
||||||
|
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
|
||||||
|
if (mailnewsurl) {
|
||||||
|
rv = mailnewsurl->GetMsgWindow(getter_AddRefs(m_msgWindow));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rv = m_newsFolder->GetGroupUsernameWithUI(usernamePromptText, nsnull, m_msgWindow, getter_Copies(username));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("we don't know the folder\n");
|
||||||
|
printf("this can happen if someone gives us just an article url\n");
|
||||||
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
|
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
|
||||||
if (mailnewsurl)
|
if (mailnewsurl)
|
||||||
mailnewsurl->SetErrorMessage(NET_ExplainErrorDetails(MK_NNTP_AUTH_FAILED, "Aborted by user"));
|
mailnewsurl->SetErrorMessage(NET_ExplainErrorDetails(MK_NNTP_AUTH_FAILED, "Aborted by user"));
|
||||||
#if 0
|
|
||||||
/* reset net_news_last_username_probably_valid to false */
|
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
#endif /* 0 */
|
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_FAILED(rv) || !username) {
|
|
||||||
#if 0
|
|
||||||
/* reset net_news_last_username_probably_valid to false */
|
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
#endif /* 0 */
|
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
}
|
}
|
||||||
} // !username
|
} // !username
|
||||||
|
|
||||||
#ifdef CACHE_NEWSGRP_PASSWORD
|
if (NS_FAILED(rv) || (!username && !cachedUsername)) {
|
||||||
if (NS_SUCCEEDED(m_newsgroup->GetUsername(&username)) {
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
munged_username = XP_STRDUP (username);
|
|
||||||
m_newsgroup->SetUsername(munged_username);
|
|
||||||
PR_FreeIF(munged_username);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
NET_SACopy(&command, "AUTHINFO user ");
|
NET_SACopy(&command, "AUTHINFO user ");
|
||||||
if (cachedUsername) {
|
if (cachedUsername) {
|
||||||
|
@ -2469,14 +2357,10 @@ PRInt32 nsNNTPProtocol::BeginAuthorization()
|
||||||
NET_SACat(&command, (const char *)cachedUsername);
|
NET_SACat(&command, (const char *)cachedUsername);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nsCAutoString usernameCString(username);
|
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("use %s as the username\n",(const char *)usernameCString);
|
printf("use %s as the username\n",(const char *)username);
|
||||||
#endif /* DEBUG_NEWS */
|
#endif /* DEBUG_NEWS */
|
||||||
if (newsFolder) {
|
NET_SACat(&command, (const char *)username);
|
||||||
rv = newsFolder->SetGroupUsername((const char *)usernameCString);
|
|
||||||
}
|
|
||||||
NET_SACat(&command, (const char *)usernameCString);
|
|
||||||
}
|
}
|
||||||
NET_SACat(&command, CRLF);
|
NET_SACat(&command, CRLF);
|
||||||
|
|
||||||
|
@ -2497,39 +2381,8 @@ PRInt32 nsNNTPProtocol::BeginAuthorization()
|
||||||
PRInt32 nsNNTPProtocol::AuthorizationResponse()
|
PRInt32 nsNNTPProtocol::AuthorizationResponse()
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
nsCOMPtr <nsIMsgNewsFolder> newsFolder;
|
|
||||||
PRInt32 status = 0;
|
PRInt32 status = 0;
|
||||||
nsXPIDLCString cachedPassword;
|
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
|
|
||||||
if (NS_FAILED(rv)) return(MK_NNTP_AUTH_FAILED);
|
|
||||||
|
|
||||||
nsCAutoString newsgroupURI;
|
|
||||||
if (m_newsgroup && m_hostName) {
|
|
||||||
nsXPIDLCString groupName;
|
|
||||||
rv = m_newsgroup->GetName(getter_Copies(groupName));
|
|
||||||
if (NS_SUCCEEDED(rv) && groupName) {
|
|
||||||
newsgroupURI = kNewsRootURI;
|
|
||||||
newsgroupURI += "/";
|
|
||||||
if (m_userName) {
|
|
||||||
newsgroupURI += m_userName;
|
|
||||||
newsgroupURI += "@";
|
|
||||||
}
|
|
||||||
newsgroupURI += m_hostName;
|
|
||||||
newsgroupURI += "/";
|
|
||||||
newsgroupURI += groupName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((const char *)newsgroupURI) {
|
|
||||||
nsCOMPtr<nsIRDFResource> resource;
|
|
||||||
rv = rdf->GetResource((const char *)newsgroupURI, getter_AddRefs(resource));
|
|
||||||
if (NS_FAILED(rv)) return(MK_NNTP_AUTH_FAILED);
|
|
||||||
|
|
||||||
newsFolder = do_QueryInterface(resource, &rv);
|
|
||||||
if (NS_FAILED(rv) || !newsFolder) return(MK_NNTP_AUTH_FAILED);
|
|
||||||
rv = newsFolder->GetGroupPassword(getter_Copies(cachedPassword));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MK_NNTP_RESPONSE_AUTHINFO_OK == m_responseCode ||
|
if (MK_NNTP_RESPONSE_AUTHINFO_OK == m_responseCode ||
|
||||||
MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_OK == m_responseCode)
|
MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_OK == m_responseCode)
|
||||||
|
@ -2552,7 +2405,6 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse()
|
||||||
/* Normal authentication */
|
/* Normal authentication */
|
||||||
m_nextState = SEND_FIRST_NNTP_COMMAND;
|
m_nextState = SEND_FIRST_NNTP_COMMAND;
|
||||||
|
|
||||||
net_news_last_username_probably_valid = PR_TRUE;
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
else if (MK_NNTP_RESPONSE_AUTHINFO_CONT == m_responseCode)
|
else if (MK_NNTP_RESPONSE_AUTHINFO_CONT == m_responseCode)
|
||||||
|
@ -2560,100 +2412,63 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse()
|
||||||
/* password required
|
/* password required
|
||||||
*/
|
*/
|
||||||
char * command = 0;
|
char * command = 0;
|
||||||
nsXPIDLString password;
|
nsXPIDLCString password;
|
||||||
#if 0
|
nsXPIDLCString cachedPassword;
|
||||||
char * cp;
|
|
||||||
|
|
||||||
if (net_news_last_username_probably_valid
|
if (!m_newsFolder) {
|
||||||
&& last_password
|
if (!m_runningURL) return NS_ERROR_FAILURE;
|
||||||
&& last_password_hostname
|
|
||||||
&& !PL_strcasecmp(last_password_hostname, m_hostName))
|
|
||||||
{
|
|
||||||
#ifdef CACHE_NEWSGRP_PASSWORD
|
|
||||||
if (cd->pane)
|
|
||||||
m_newsgroup->GetPassword(&password);
|
|
||||||
password = XP_STRDUP(password);
|
|
||||||
#else
|
|
||||||
NET_SACopy(&password, last_password);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if ((cp = PL_strchr(m_hostName, '@')) != NULL)
|
|
||||||
{
|
|
||||||
/* in this case the username and possibly
|
|
||||||
* the password are in the URL
|
|
||||||
*/
|
|
||||||
char * colon;
|
|
||||||
*cp = '\0';
|
|
||||||
|
|
||||||
colon = PL_strchr(m_hostName, ':');
|
nsCAutoString folderURI = "news://";
|
||||||
if(colon)
|
folderURI += (const char *)m_hostName;
|
||||||
{
|
folderURI += "/";
|
||||||
*colon = '\0';
|
|
||||||
|
|
||||||
NET_SACopy(&password, colon+1);
|
nsXPIDLCString newsgroupName;
|
||||||
NET_SACopy(&last_password, colon+1);
|
rv = m_runningURL->GetNewsgroupName(getter_Copies(newsgroupName));
|
||||||
NET_SACopy(&last_password_hostname, cp+1);
|
if (NS_SUCCEEDED(rv) && ((const char *)newsgroupName)) {
|
||||||
|
folderURI += (const char *)newsgroupName;
|
||||||
|
rv = InitializeNewsFolderFromUri((const char *)folderURI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*colon = ':';
|
if (m_newsFolder) {
|
||||||
}
|
rv = m_newsFolder->GetGroupPassword(getter_Copies(cachedPassword));
|
||||||
|
}
|
||||||
*cp = '@';
|
if (NS_FAILED(rv) || !cachedPassword) {
|
||||||
|
|
||||||
}
|
|
||||||
#endif /* 0 */
|
|
||||||
|
|
||||||
if (!cachedPassword)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("ask for the news password\n");
|
printf("ask for the news password\n");
|
||||||
#endif /* DEBUG_NEWS */
|
#endif /* DEBUG_NEWS */
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIPrompt, dialog, kCNetSupportDialogCID, &rv);
|
|
||||||
if (NS_FAILED(rv) || !dialog) {
|
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsXPIDLString passwordPromptText;
|
nsXPIDLString passwordPromptText;
|
||||||
GetNewsStringByName("enterPassword", getter_Copies(passwordPromptText));
|
GetNewsStringByName("enterPassword", getter_Copies(passwordPromptText));
|
||||||
nsXPIDLString passwordPromptTitleText;
|
nsXPIDLString passwordPromptTitleText;
|
||||||
GetNewsStringByName("enterPasswordTitle", getter_Copies(passwordPromptTitleText));
|
GetNewsStringByName("enterPasswordTitle", getter_Copies(passwordPromptTitleText));
|
||||||
PRBool okButtonClicked = PR_FALSE;
|
|
||||||
|
|
||||||
rv = dialog->PromptPassword(passwordPromptText, passwordPromptTitleText, getter_Copies(password), &okButtonClicked);
|
if (m_newsFolder) {
|
||||||
|
if (!m_msgWindow) {
|
||||||
|
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
|
||||||
|
if (mailnewsurl) {
|
||||||
|
rv = mailnewsurl->GetMsgWindow(getter_AddRefs(m_msgWindow));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rv = m_newsFolder->GetGroupPasswordWithUI(passwordPromptText, passwordPromptTitleText, m_msgWindow, getter_Copies(password));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("we don't know the folder\n");
|
||||||
|
printf("this can happen if someone gives us just an article url\n");
|
||||||
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && !okButtonClicked) {
|
if (NS_FAILED(rv)) {
|
||||||
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
|
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
|
||||||
if (mailnewsurl)
|
if (mailnewsurl)
|
||||||
mailnewsurl->SetErrorMessage(NET_ExplainErrorDetails(MK_NNTP_AUTH_FAILED, "Aborted by user"));
|
mailnewsurl->SetErrorMessage(NET_ExplainErrorDetails(MK_NNTP_AUTH_FAILED, "Aborted by user"));
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
#endif /* 0 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NS_FAILED(rv) || (!password && !cachedPassword)) {
|
if(NS_FAILED(rv) || (!password && !cachedPassword)) {
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NET_SACopy(&last_password, password);
|
|
||||||
NET_SACopy(&last_password_hostname, m_hostName);
|
|
||||||
}
|
|
||||||
#endif /* 0 */
|
|
||||||
|
|
||||||
#ifdef CACHE_NEWSGRP_PASSWORD
|
|
||||||
char *garbage_password;
|
|
||||||
nsresult rv;
|
|
||||||
rv = m_newsgroup->GetPassword(&garbage_password);
|
|
||||||
if (!NS_SUCCEEDED(rv)) {
|
|
||||||
PR_Free(garbage_password);
|
|
||||||
munged_password = XP_STRDUP(password);
|
|
||||||
m_newsgroup->SetPassword(munged_password);
|
|
||||||
PR_FREEIF(munged_password);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NET_SACopy(&command, "AUTHINFO pass ");
|
NET_SACopy(&command, "AUTHINFO pass ");
|
||||||
if (cachedPassword) {
|
if (cachedPassword) {
|
||||||
|
@ -2663,14 +2478,10 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse()
|
||||||
NET_SACat(&command, (const char *)cachedPassword);
|
NET_SACat(&command, (const char *)cachedPassword);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nsCAutoString passwordCString(password);
|
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("use %s as the password\n",(const char *)passwordCString);
|
printf("use %s as the password\n",(const char *)password);
|
||||||
#endif /* DEBUG_NEWS */
|
#endif /* DEBUG_NEWS */
|
||||||
if (newsFolder) {
|
NET_SACat(&command, (const char *)password);
|
||||||
rv = newsFolder->SetGroupPassword((const char *)passwordCString);
|
|
||||||
}
|
|
||||||
NET_SACat(&command, (const char *)passwordCString);
|
|
||||||
}
|
}
|
||||||
NET_SACat(&command, CRLF);
|
NET_SACat(&command, CRLF);
|
||||||
|
|
||||||
|
@ -2694,12 +2505,6 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse()
|
||||||
MK_NNTP_AUTH_FAILED,
|
MK_NNTP_AUTH_FAILED,
|
||||||
m_responseText ? m_responseText : ""));
|
m_responseText ? m_responseText : ""));
|
||||||
|
|
||||||
#ifdef CACHE_NEWSGRP_PASSWORD
|
|
||||||
if (cd->pane)
|
|
||||||
m_newsgroup->SetUsername(NULL);
|
|
||||||
#endif
|
|
||||||
net_news_last_username_probably_valid = PR_FALSE;
|
|
||||||
|
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2733,8 +2538,6 @@ PRInt32 nsNNTPProtocol::PasswordResponse()
|
||||||
/* Normal authentication */
|
/* Normal authentication */
|
||||||
m_nextState = SEND_FIRST_NNTP_COMMAND;
|
m_nextState = SEND_FIRST_NNTP_COMMAND;
|
||||||
|
|
||||||
net_news_last_username_probably_valid = PR_TRUE;
|
|
||||||
|
|
||||||
// if we are posting, m_newsgroup will be null
|
// if we are posting, m_newsgroup will be null
|
||||||
if (!m_newsgroupList && m_newsgroup) {
|
if (!m_newsgroupList && m_newsgroup) {
|
||||||
nsXPIDLCString groupName;
|
nsXPIDLCString groupName;
|
||||||
|
@ -2756,10 +2559,6 @@ PRInt32 nsNNTPProtocol::PasswordResponse()
|
||||||
MK_NNTP_AUTH_FAILED,
|
MK_NNTP_AUTH_FAILED,
|
||||||
m_responseText ? m_responseText : ""));
|
m_responseText ? m_responseText : ""));
|
||||||
|
|
||||||
#ifdef CACHE_NEWSGRP_PASSWORD
|
|
||||||
if (cd->pane)
|
|
||||||
m_newsgroup->SetPassword(NULL);
|
|
||||||
#endif
|
|
||||||
return(MK_NNTP_AUTH_FAILED);
|
return(MK_NNTP_AUTH_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
#include "nsINNTPHost.h"
|
#include "nsINNTPHost.h"
|
||||||
#include "nsINNTPNewsgroup.h"
|
#include "nsINNTPNewsgroup.h"
|
||||||
#include "nsIMsgOfflineNewsState.h"
|
#include "nsIMsgOfflineNewsState.h"
|
||||||
|
#include "nsIMsgNewsFolder.h"
|
||||||
|
#include "nsIMsgWindow.h"
|
||||||
|
|
||||||
#include "nsMsgLineBuffer.h"
|
#include "nsMsgLineBuffer.h"
|
||||||
#include "nsSpecialSystemDirectory.h"
|
#include "nsSpecialSystemDirectory.h"
|
||||||
|
@ -146,7 +148,7 @@ class nsNNTPProtocol : public nsMsgProtocol
|
||||||
public:
|
public:
|
||||||
// Creating a protocol instance requires the URL
|
// Creating a protocol instance requires the URL
|
||||||
// need to call Initialize after we do a new of nsNNTPProtocol
|
// need to call Initialize after we do a new of nsNNTPProtocol
|
||||||
nsNNTPProtocol(nsIURI * aURL);
|
nsNNTPProtocol(nsIURI * aURL, nsIMsgWindow *aMsgWindow);
|
||||||
virtual ~nsNNTPProtocol();
|
virtual ~nsNNTPProtocol();
|
||||||
|
|
||||||
// initialization function given a news url
|
// initialization function given a news url
|
||||||
|
@ -185,6 +187,9 @@ private:
|
||||||
nsCOMPtr <nsINNTPNewsgroup> m_newsgroup;
|
nsCOMPtr <nsINNTPNewsgroup> m_newsgroup;
|
||||||
nsCOMPtr <nsIMsgOfflineNewsState> m_offlineNewsState;
|
nsCOMPtr <nsIMsgOfflineNewsState> m_offlineNewsState;
|
||||||
|
|
||||||
|
nsCOMPtr <nsIMsgNewsFolder> m_newsFolder;
|
||||||
|
nsCOMPtr <nsIMsgWindow> m_msgWindow;
|
||||||
|
|
||||||
nsCOMPtr<nsIWebShell> m_displayConsumer;
|
nsCOMPtr<nsIWebShell> m_displayConsumer;
|
||||||
nsCOMPtr<nsIBufferInputStream> mDisplayInputStream;
|
nsCOMPtr<nsIBufferInputStream> mDisplayInputStream;
|
||||||
nsCOMPtr<nsIBufferOutputStream> mDisplayOutputStream;
|
nsCOMPtr<nsIBufferOutputStream> mDisplayOutputStream;
|
||||||
|
@ -374,6 +379,7 @@ private:
|
||||||
|
|
||||||
void SetProgressBarPercent(int percent);
|
void SetProgressBarPercent(int percent);
|
||||||
void SetProgressStatus(char * message);
|
void SetProgressStatus(char * message);
|
||||||
|
nsresult InitializeNewsFolderFromUri(const char *uri);
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_BEGIN_EXTERN_C
|
NS_BEGIN_EXTERN_C
|
||||||
|
|
|
@ -54,6 +54,13 @@
|
||||||
#include "nsMsgBaseCID.h"
|
#include "nsMsgBaseCID.h"
|
||||||
#include "nsFileStream.h"
|
#include "nsFileStream.h"
|
||||||
|
|
||||||
|
#include "nsIMsgWindow.h"
|
||||||
|
#include "nsIWebShell.h"
|
||||||
|
#include "nsIWebShellWindow.h"
|
||||||
|
#include "nsINetPrompt.h"
|
||||||
|
|
||||||
|
#include "nsXPIDLString.h"
|
||||||
|
|
||||||
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
|
// 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 doesn't allow you to call ::nsISupports::GetIID() inside of a class
|
||||||
// that multiply inherits from nsISupports
|
// that multiply inherits from nsISupports
|
||||||
|
@ -70,6 +77,9 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||||
#define NEWSGROUP_PASSWORD_PREF_PREFIX "newsgroup.password."
|
#define NEWSGROUP_PASSWORD_PREF_PREFIX "newsgroup.password."
|
||||||
#define NEWSRC_FILE_BUFFER_SIZE 1024
|
#define NEWSRC_FILE_BUFFER_SIZE 1024
|
||||||
|
|
||||||
|
#define NEWS_SCHEME "news:"
|
||||||
|
#define SNEWS_SCHEME "snews:"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,10 +133,6 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
char *hostname;
|
|
||||||
rv = GetHostname(&hostname);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
PRBool isNewsServer = PR_FALSE;
|
PRBool isNewsServer = PR_FALSE;
|
||||||
rv = GetIsServer(&isNewsServer);
|
rv = GetIsServer(&isNewsServer);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
@ -158,8 +164,6 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
|
||||||
rv = NS_OK;
|
rv = NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
PR_FREEIF(hostname);
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,12 +171,11 @@ NS_IMETHODIMP
|
||||||
nsMsgNewsFolder::AddNewsgroup(const char *name, const char *setStr, nsIMsgFolder **child)
|
nsMsgNewsFolder::AddNewsgroup(const char *name, const char *setStr, nsIMsgFolder **child)
|
||||||
{
|
{
|
||||||
if (!child) return NS_ERROR_NULL_POINTER;
|
if (!child) return NS_ERROR_NULL_POINTER;
|
||||||
|
if (!setStr) return NS_ERROR_NULL_POINTER;
|
||||||
if (!setStr) return NS_ERROR_NULL_POINTER;
|
if (!name) return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
nsCString nameStr(name);
|
printf("AddNewsgroup(%s,??,%s)\n",name,setStr);
|
||||||
printf("AddNewsgroup(%s,??,%s)\n",nameStr.GetBuffer(),setStr);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
@ -443,8 +446,6 @@ nsMsgNewsFolder::GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleEnumerator* *res
|
||||||
|
|
||||||
NS_IMETHODIMP nsMsgNewsFolder::GetFolderURL(char **url)
|
NS_IMETHODIMP nsMsgNewsFolder::GetFolderURL(char **url)
|
||||||
{
|
{
|
||||||
const char *urlScheme = "news:";
|
|
||||||
|
|
||||||
if(!url)
|
if(!url)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
@ -457,10 +458,10 @@ NS_IMETHODIMP nsMsgNewsFolder::GetFolderURL(char **url)
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
#if defined(XP_MAC)
|
#if defined(XP_MAC)
|
||||||
nsCAutoString tmpPath((nsFilePath)path); //ducarroz: please don't cast a nsFilePath to char* on Mac
|
nsCAutoString tmpPath((nsFilePath)path); //ducarroz: please don't cast a nsFilePath to char* on Mac
|
||||||
*url = PR_smprintf("%s%s", urlScheme, tmpPath.GetBuffer());
|
*url = PR_smprintf("%s%s", NEWS_SCHEME, tmpPath.GetBuffer());
|
||||||
#else
|
#else
|
||||||
const char *pathName = path;
|
const char *pathName = path;
|
||||||
*url = PR_smprintf("%s%s", urlScheme, pathName);
|
*url = PR_smprintf("%s%s", NEWS_SCHEME, pathName);
|
||||||
#endif
|
#endif
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
|
@ -774,7 +775,7 @@ NS_IMETHODIMP nsMsgNewsFolder::GetSizeOnDisk(PRUint32 *size)
|
||||||
|
|
||||||
/* this is news, so remember that DeleteMessage is really CANCEL */
|
/* this is news, so remember that DeleteMessage is really CANCEL */
|
||||||
NS_IMETHODIMP nsMsgNewsFolder::DeleteMessages(nsISupportsArray *messages,
|
NS_IMETHODIMP nsMsgNewsFolder::DeleteMessages(nsISupportsArray *messages,
|
||||||
nsIMsgWindow *msgWindow, PRBool deleteStorage)
|
nsIMsgWindow *aMsgWindow, PRBool deleteStorage)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
@ -786,21 +787,18 @@ NS_IMETHODIMP nsMsgNewsFolder::DeleteMessages(nsISupportsArray *messages,
|
||||||
NS_WITH_SERVICE(nsINntpService, nntpService, kNntpServiceCID, &rv);
|
NS_WITH_SERVICE(nsINntpService, nntpService, kNntpServiceCID, &rv);
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && nntpService) {
|
if (NS_SUCCEEDED(rv) && nntpService) {
|
||||||
char *hostname = nsnull;
|
nsXPIDLCString hostname;
|
||||||
rv = GetHostname(&hostname);
|
rv = GetHostname(getter_Copies(hostname));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
PRUnichar *newsgroupname = nsnull;
|
nsXPIDLString newsgroupname;
|
||||||
rv = GetName(&newsgroupname);
|
rv = GetName(getter_Copies(newsgroupname));
|
||||||
nsCString asciiName(newsgroupname);
|
nsCAutoString asciiName(newsgroupname);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
PR_FREEIF(hostname);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = nntpService->CancelMessages(hostname, asciiName.GetBuffer(), messages, nsnull /* consumer */, nsnull, nsnull);
|
rv = nntpService->CancelMessages((const char *)hostname, (const char *)asciiName, messages, nsnull /* consumer */, nsnull, aMsgWindow, nsnull);
|
||||||
|
|
||||||
PR_FREEIF(hostname);
|
|
||||||
PR_FREEIF(newsgroupname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -1154,57 +1152,44 @@ NS_IMETHODIMP nsMsgNewsFolder::SetUnreadSetStr(const char * aUnreadSetStr)
|
||||||
|
|
||||||
NS_IMETHODIMP nsMsgNewsFolder::GetGroupUsername(char **aGroupUsername)
|
NS_IMETHODIMP nsMsgNewsFolder::GetGroupUsername(char **aGroupUsername)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
NS_ENSURE_ARG_POINTER(aGroupUsername);
|
||||||
|
nsresult rv;
|
||||||
if (!aGroupUsername) return NS_ERROR_NULL_POINTER;
|
#ifdef DEBUG_sspitzer
|
||||||
|
printf("get the group username for %s\n",mURI);
|
||||||
if (!mGroupUsername) {
|
#endif
|
||||||
nsCAutoString prefName = NEWSGROUP_USERNAME_PREF_PREFIX;
|
if (mGroupUsername) {
|
||||||
prefName += mURI;
|
|
||||||
rv = GetRememberedPref((const char *)prefName, &mGroupUsername);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && mGroupUsername) {
|
|
||||||
*aGroupUsername = PL_strdup(mGroupUsername);
|
*aGroupUsername = PL_strdup(mGroupUsername);
|
||||||
if (!*aGroupUsername) return NS_ERROR_FAILURE;
|
|
||||||
rv = NS_OK;
|
rv = NS_OK;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsMsgNewsFolder::SetGroupUsername(const char *aGroupUsername)
|
NS_IMETHODIMP nsMsgNewsFolder::SetGroupUsername(const char *aGroupUsername)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
NS_ENSURE_ARG_POINTER(aGroupUsername);
|
||||||
|
|
||||||
if (!aGroupUsername) return NS_ERROR_INVALID_ARG;
|
|
||||||
PR_FREEIF(mGroupUsername);
|
PR_FREEIF(mGroupUsername);
|
||||||
|
|
||||||
mGroupUsername = PL_strdup(aGroupUsername);
|
mGroupUsername = PL_strdup(aGroupUsername);
|
||||||
if (!mGroupUsername) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsCAutoString prefName = NEWSGROUP_USERNAME_PREF_PREFIX;
|
return NS_OK;
|
||||||
prefName += mURI;
|
|
||||||
|
|
||||||
rv = SetRememberedPref((const char *)prefName, mGroupUsername);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsMsgNewsFolder::GetGroupPassword(char **aGroupPassword)
|
NS_IMETHODIMP nsMsgNewsFolder::GetGroupPassword(char **aGroupPassword)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
NS_ENSURE_ARG_POINTER(aGroupPassword);
|
||||||
if (!aGroupPassword) return NS_ERROR_NULL_POINTER;
|
nsresult rv;
|
||||||
|
|
||||||
if (!mGroupPassword) {
|
if (mGroupPassword) {
|
||||||
nsCAutoString prefName = NEWSGROUP_PASSWORD_PREF_PREFIX;
|
|
||||||
prefName += mURI;
|
|
||||||
rv = GetRememberedPref((const char *)prefName, &mGroupPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && mGroupPassword) {
|
|
||||||
*aGroupPassword = PL_strdup(mGroupPassword);
|
*aGroupPassword = PL_strdup(mGroupPassword);
|
||||||
if (!*aGroupPassword) return NS_ERROR_FAILURE;
|
rv = NS_OK;
|
||||||
rv = NS_OK;
|
}
|
||||||
|
else {
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -1212,76 +1197,157 @@ NS_IMETHODIMP nsMsgNewsFolder::GetGroupPassword(char **aGroupPassword)
|
||||||
|
|
||||||
NS_IMETHODIMP nsMsgNewsFolder::SetGroupPassword(const char *aGroupPassword)
|
NS_IMETHODIMP nsMsgNewsFolder::SetGroupPassword(const char *aGroupPassword)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
NS_ENSURE_ARG_POINTER(aGroupPassword);
|
||||||
|
|
||||||
if (!aGroupPassword) return NS_ERROR_INVALID_ARG;
|
PR_FREEIF(mGroupPassword);
|
||||||
PR_FREEIF(mGroupPassword);
|
|
||||||
|
|
||||||
mGroupPassword = PL_strdup(aGroupPassword);
|
mGroupPassword = PL_strdup(aGroupPassword);
|
||||||
if (!mGroupPassword) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsCAutoString prefName = NEWSGROUP_PASSWORD_PREF_PREFIX;
|
return NS_OK;
|
||||||
prefName += mURI;
|
|
||||||
|
|
||||||
rv = SetRememberedPref((const char *)prefName, mGroupPassword);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsMsgNewsFolder::GetRememberedPref(const char *prefName, char **prefValue)
|
NS_IMETHODIMP
|
||||||
|
nsMsgNewsFolder::GetGroupPasswordWithUI(const PRUnichar * aPromptMessage, const
|
||||||
|
PRUnichar *aPromptTitle,
|
||||||
|
nsIMsgWindow* aMsgWindow,
|
||||||
|
char **aGroupPassword)
|
||||||
{
|
{
|
||||||
PRBool rememberPassword;
|
nsresult rv = NS_OK;
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
nsCOMPtr <nsIMsgIncomingServer> server;
|
#ifdef DEBUG_sspitzer
|
||||||
rv = GetServer(getter_AddRefs(server));
|
printf("with ui, get the group username for %s\n",mURI);
|
||||||
if (NS_FAILED(rv)) return rv;
|
#endif
|
||||||
|
|
||||||
rv = server->GetRememberPassword(&rememberPassword);
|
NS_ENSURE_ARG_POINTER(aMsgWindow);
|
||||||
if (NS_FAILED(rv)) return rv;
|
NS_ENSURE_ARG_POINTER(aGroupPassword);
|
||||||
|
|
||||||
if (!rememberPassword) {
|
if (!mGroupPassword) {
|
||||||
// we weren't supposed to have remembered anything
|
// prompt the user for the password
|
||||||
*prefValue = nsnull;
|
nsCOMPtr<nsIWebShell> webShell;
|
||||||
return NS_OK;
|
rv = aMsgWindow->GetRootWebShell(getter_AddRefs(webShell));
|
||||||
}
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
// get top level window
|
||||||
|
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
|
||||||
|
rv = webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
nsCOMPtr<nsINetPrompt> dialog( do_QueryInterface( topLevelWindow, &rv ) );
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
{
|
||||||
|
nsXPIDLString uniGroupPassword;
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
PRBool okayValue = PR_TRUE;
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
rv = prefs->CopyCharPref(prefName, prefValue);
|
nsCAutoString signonURI(mURI);
|
||||||
#ifdef DEBUG_NEWS
|
#if SINGLE_SIGNON_USING_FULL_URLS
|
||||||
if (NS_SUCCEEDED(rv)) {
|
signonURI += "#password";
|
||||||
printf("getting %s as %s\n",prefName, prefValue);
|
#else
|
||||||
}
|
signonURI = NEWS_SCHEME;
|
||||||
#endif /* DEBUG_NEWS */
|
signonURI += "//";
|
||||||
|
nsXPIDLCString hostname;
|
||||||
|
rv = GetHostname(getter_Copies(hostname));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
signonURI += (const char *)hostname;
|
||||||
|
signonURI += "-";
|
||||||
|
|
||||||
|
nsXPIDLString newsgroupname;
|
||||||
|
rv = GetName(getter_Copies(newsgroupname));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
nsCAutoString asciiName(newsgroupname);
|
||||||
|
|
||||||
|
signonURI += (const char *)asciiName;
|
||||||
|
signonURI += "-password";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rv = dialog->PromptPassword((const char *)signonURI, aPromptTitle, aPromptMessage, getter_Copies(uniGroupPassword), &okayValue);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
if (!okayValue) // if the user pressed cancel, just return NULL;
|
||||||
|
{
|
||||||
|
*aGroupPassword = nsnull;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we got a password back...so remember it
|
||||||
|
nsCString aCStr(uniGroupPassword);
|
||||||
|
rv = SetGroupPassword((const char *) aCStr);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
} // if we got a prompt dialog
|
||||||
|
} // if the password is empty
|
||||||
|
|
||||||
|
rv = GetGroupPassword(aGroupPassword);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsMsgNewsFolder::SetRememberedPref(const char *prefName, const char *prefValue)
|
NS_IMETHODIMP
|
||||||
|
nsMsgNewsFolder::GetGroupUsernameWithUI(const PRUnichar * aPromptMessage, const
|
||||||
|
PRUnichar *aPromptTitle,
|
||||||
|
nsIMsgWindow* aMsgWindow,
|
||||||
|
char **aGroupUsername)
|
||||||
{
|
{
|
||||||
PRBool rememberPassword;
|
nsresult rv = NS_OK;
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
nsCOMPtr <nsIMsgIncomingServer> server;
|
NS_ENSURE_ARG_POINTER(aMsgWindow);
|
||||||
rv = GetServer(getter_AddRefs(server));
|
NS_ENSURE_ARG_POINTER(aGroupUsername);
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
rv = server->GetRememberPassword(&rememberPassword);
|
if (!mGroupUsername) {
|
||||||
if (NS_FAILED(rv)) return rv;
|
// prompt the user for the password
|
||||||
|
nsCOMPtr<nsIWebShell> webShell;
|
||||||
|
rv = aMsgWindow->GetRootWebShell(getter_AddRefs(webShell));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
// get top level window
|
||||||
|
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
|
||||||
|
rv = webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
nsCOMPtr<nsINetPrompt> dialog( do_QueryInterface( topLevelWindow, &rv ) );
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
{
|
||||||
|
nsXPIDLString uniGroupUsername;
|
||||||
|
|
||||||
if (!rememberPassword) {
|
PRBool okayValue = PR_TRUE;
|
||||||
// we aren't supposed to remember this
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
nsCAutoString signonURI(mURI);
|
||||||
if (NS_FAILED(rv)) return rv;
|
#if SINGLE_SIGNON_USING_FULL_URLS
|
||||||
|
signonURI += "#username";
|
||||||
|
#else
|
||||||
|
signonURI = NEWS_SCHEME;
|
||||||
|
signonURI += "//";
|
||||||
|
nsXPIDLCString hostname;
|
||||||
|
rv = GetHostname(getter_Copies(hostname));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
rv = prefs->SetCharPref(prefName, prefValue);
|
signonURI += (const char *)hostname;
|
||||||
#ifdef DEBUG_NEWS
|
signonURI += "-";
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
printf("setting %s as %s\n",prefName, prefValue);
|
nsXPIDLString newsgroupname;
|
||||||
}
|
rv = GetName(getter_Copies(newsgroupname));
|
||||||
#endif /* DEBUG_NEWS */
|
if (NS_FAILED(rv)) return rv;
|
||||||
return rv;
|
|
||||||
|
nsCAutoString asciiName(newsgroupname);
|
||||||
|
|
||||||
|
signonURI += (const char *)asciiName;
|
||||||
|
signonURI += "-username";
|
||||||
|
#endif
|
||||||
|
rv = dialog->Prompt((const char *)signonURI, aPromptTitle, aPromptMessage, getter_Copies(uniGroupUsername), &okayValue);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
if (!okayValue) // if the user pressed cancel, just return NULL;
|
||||||
|
{
|
||||||
|
*aGroupUsername= nsnull;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we got a username back, remember it
|
||||||
|
nsCString aCStr(uniGroupUsername);
|
||||||
|
rv = SetGroupUsername((const char *) aCStr);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
} // if we got a prompt dialog
|
||||||
|
} // if the password is empty
|
||||||
|
|
||||||
|
rv = GetGroupUsername(aGroupUsername);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,10 +124,6 @@ protected:
|
||||||
// used for auth news
|
// used for auth news
|
||||||
char *mGroupUsername;
|
char *mGroupUsername;
|
||||||
char *mGroupPassword;
|
char *mGroupPassword;
|
||||||
|
|
||||||
private:
|
|
||||||
nsresult SetRememberedPref(const char *prefName, const char *prefValue);
|
|
||||||
nsresult GetRememberedPref(const char *prefName, char **prefValue);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsMsgNewsFolder_h__
|
#endif // nsMsgNewsFolder_h__
|
||||||
|
|
|
@ -129,7 +129,7 @@ nsNntpService::SaveMessageToDisk(const char *aMessageURI,
|
||||||
msgUrl->SetCanonicalLineEnding(canonicalLineEnding);
|
msgUrl->SetCanonicalLineEnding(canonicalLineEnding);
|
||||||
}
|
}
|
||||||
|
|
||||||
RunNewsUrl(myuri, nsnull);
|
RunNewsUrl(myuri, nsnull, nsnull);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aURL)
|
if (aURL)
|
||||||
|
@ -181,7 +181,7 @@ nsresult nsNntpService::DisplayMessage(const char* aMessageURI, nsISupports * aD
|
||||||
if (NS_SUCCEEDED(rv) && webshell)
|
if (NS_SUCCEEDED(rv) && webshell)
|
||||||
rv = webshell->LoadURI(myuri, "view", nsnull, PR_TRUE);
|
rv = webshell->LoadURI(myuri, "view", nsnull, PR_TRUE);
|
||||||
else
|
else
|
||||||
rv = RunNewsUrl(myuri, aDisplayConsumer);
|
rv = RunNewsUrl(myuri, aMsgWindow, aDisplayConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aURL)
|
if (aURL)
|
||||||
|
@ -429,9 +429,10 @@ nsresult nsNntpService::FindHostFromGroup(nsCString &host, nsCString &groupName)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNames)
|
nsNntpService::SetUpNntpUrlForPosting(nsINntpUrl *nntpUrl, const char *newsgroupsNames)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
nsCAutoString host;
|
||||||
|
|
||||||
if (!newsgroupsNames) return NS_ERROR_NULL_POINTER;
|
if (!newsgroupsNames) return NS_ERROR_NULL_POINTER;
|
||||||
if (PL_strlen(newsgroupsNames) == 0) return NS_ERROR_FAILURE;
|
if (PL_strlen(newsgroupsNames) == 0) return NS_ERROR_FAILURE;
|
||||||
|
@ -459,6 +460,8 @@ nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNa
|
||||||
char *token = nsnull;
|
char *token = nsnull;
|
||||||
char *rest = list;
|
char *rest = list;
|
||||||
nsCAutoString str;
|
nsCAutoString str;
|
||||||
|
PRUint32 numGroups = 0; // the number of newsgroup we are attempt to post to
|
||||||
|
nsCAutoString currentGroup;
|
||||||
|
|
||||||
token = nsCRT::strtok(rest, ",", &rest);
|
token = nsCRT::strtok(rest, ",", &rest);
|
||||||
while (token && *token) {
|
while (token && *token) {
|
||||||
|
@ -498,6 +501,7 @@ nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNa
|
||||||
if (slashpos > 0 ) {
|
if (slashpos > 0 ) {
|
||||||
// theRest is "host/group"
|
// theRest is "host/group"
|
||||||
theRest.Left(currentHost, slashpos);
|
theRest.Left(currentHost, slashpos);
|
||||||
|
theRest.Right(currentGroup, slashpos);
|
||||||
#ifdef DEBUG_NEWS
|
#ifdef DEBUG_NEWS
|
||||||
printf("currentHost == %s\n", currentHost.GetBuffer());
|
printf("currentHost == %s\n", currentHost.GetBuffer());
|
||||||
#endif
|
#endif
|
||||||
|
@ -505,12 +509,14 @@ nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNa
|
||||||
else {
|
else {
|
||||||
// theRest is "group"
|
// theRest is "group"
|
||||||
rv = FindHostFromGroup(currentHost, str);
|
rv = FindHostFromGroup(currentHost, str);
|
||||||
|
currentGroup = str;
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
PR_FREEIF(list);
|
PR_FREEIF(list);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numGroups++;
|
||||||
if (host.IsEmpty()) {
|
if (host.IsEmpty()) {
|
||||||
host = currentHost;
|
host = currentHost;
|
||||||
|
|
||||||
|
@ -519,7 +525,7 @@ nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNa
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (host != currentHost) {
|
if (host != currentHost) {
|
||||||
printf("no cross posting to multiple hosts!\n");
|
printf("todo, implement an alert: no cross posting to multiple hosts!\n");
|
||||||
PR_FREEIF(list);
|
PR_FREEIF(list);
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -537,10 +543,32 @@ nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNa
|
||||||
}
|
}
|
||||||
PR_FREEIF(list);
|
PR_FREEIF(list);
|
||||||
|
|
||||||
if (!host.IsEmpty())
|
if (host.IsEmpty())
|
||||||
return NS_OK;
|
|
||||||
else
|
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
nsCAutoString urlStr = kNewsRootURI;
|
||||||
|
urlStr += "/";
|
||||||
|
urlStr += (const char *)host;
|
||||||
|
|
||||||
|
// if the user tried to post to one newsgroup, set that information in the
|
||||||
|
// nntp url. this can save them an authentication, if they've already logged in
|
||||||
|
// and we have that information in the single signon database
|
||||||
|
if ((numGroups == 1) && ((const char *)currentGroup)) {
|
||||||
|
rv = nntpUrl->SetNewsgroupName((const char *)currentGroup);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl);
|
||||||
|
|
||||||
|
if (mailnewsurl) {
|
||||||
|
mailnewsurl->SetSpec((const char *)urlStr);
|
||||||
|
mailnewsurl->SetPort(NEWS_PORT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// nsINntpService support
|
// nsINntpService support
|
||||||
|
@ -712,24 +740,11 @@ nsresult nsNntpService::PostMessage(nsIFileSpec *fileToPost, const char *newsgro
|
||||||
|
|
||||||
nntpUrl->SetNewsAction(nsINntpUrl::ActionPostArticle);
|
nntpUrl->SetNewsAction(nsINntpUrl::ActionPostArticle);
|
||||||
|
|
||||||
nsCAutoString host;
|
rv = SetUpNntpUrlForPosting(nntpUrl, newsgroupsNames);
|
||||||
rv = DetermineHostForPosting(host, newsgroupsNames);
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
if (NS_FAILED(rv) || (host.IsEmpty())) return rv;
|
|
||||||
|
|
||||||
printf("post to this host: %s\n",host.GetBuffer());
|
|
||||||
|
|
||||||
char *urlstr = PR_smprintf("%s/%s",kNewsRootURI,host.GetBuffer());
|
|
||||||
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl);
|
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl);
|
||||||
if (mailnewsurl) {
|
if (!mailnewsurl) return NS_ERROR_FAILURE;
|
||||||
mailnewsurl->SetSpec(urlstr);
|
|
||||||
mailnewsurl->SetPort(NEWS_PORT);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PR_FREEIF(urlstr);
|
|
||||||
|
|
||||||
if (aUrlListener) // register listener if there is one...
|
if (aUrlListener) // register listener if there is one...
|
||||||
mailnewsurl->RegisterListener(aUrlListener);
|
mailnewsurl->RegisterListener(aUrlListener);
|
||||||
|
@ -737,7 +752,7 @@ nsresult nsNntpService::PostMessage(nsIFileSpec *fileToPost, const char *newsgro
|
||||||
// almost there...now create a nntp protocol instance to run the url in...
|
// almost there...now create a nntp protocol instance to run the url in...
|
||||||
nsNNTPProtocol *nntpProtocol = nsnull;
|
nsNNTPProtocol *nntpProtocol = nsnull;
|
||||||
|
|
||||||
nntpProtocol = new nsNNTPProtocol(mailnewsurl);
|
nntpProtocol = new nsNNTPProtocol(mailnewsurl, nsnull);
|
||||||
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;;
|
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;;
|
||||||
|
|
||||||
rv = nntpProtocol->Initialize();
|
rv = nntpProtocol->Initialize();
|
||||||
|
@ -807,15 +822,17 @@ nsresult nsNntpService::ConstructNntpUrl(const char * urlString, const char * ne
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsNntpService::RunNewsUrl(nsIURI * aUri, nsISupports * aConsumer)
|
nsNntpService::RunNewsUrl(nsIURI * aUri, nsIMsgWindow *aMsgWindow, nsISupports * aConsumer)
|
||||||
{
|
{
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
// almost there...now create a nntp protocol instance to run the url in...
|
// almost there...now create a nntp protocol instance to run the url in...
|
||||||
nsNNTPProtocol *nntpProtocol = nsnull;
|
nsNNTPProtocol *nntpProtocol = nsnull;
|
||||||
|
|
||||||
nntpProtocol = new nsNNTPProtocol(aUri);
|
nntpProtocol = new nsNNTPProtocol(aUri, aMsgWindow);
|
||||||
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;
|
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
nsresult rv = nntpProtocol->Initialize();
|
rv = nntpProtocol->Initialize();
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
rv = nntpProtocol->LoadUrl(aUri, aConsumer);
|
rv = nntpProtocol->LoadUrl(aUri, aConsumer);
|
||||||
|
@ -891,7 +908,7 @@ NS_IMETHODIMP nsNntpService::GetNewNews(nsINntpIncomingServer *nntpServer, const
|
||||||
mailNewsUrl->SetMsgWindow(aMsgWindow);
|
mailNewsUrl->SetMsgWindow(aMsgWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = RunNewsUrl(aUrl, nsnull);
|
rv = RunNewsUrl(aUrl, aMsgWindow, nsnull);
|
||||||
|
|
||||||
if (_retval)
|
if (_retval)
|
||||||
{
|
{
|
||||||
|
@ -907,7 +924,7 @@ NS_IMETHODIMP nsNntpService::GetNewNews(nsINntpIncomingServer *nntpServer, const
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsNntpService::CancelMessages(const char *hostname, const char *newsgroupname, nsISupportsArray *messages, nsISupports * aConsumer, nsIUrlListener * aUrlListener, nsIURI ** aURL)
|
NS_IMETHODIMP nsNntpService::CancelMessages(const char *hostname, const char *newsgroupname, nsISupportsArray *messages, nsISupports * aConsumer, nsIUrlListener * aUrlListener, nsIMsgWindow *aMsgWindow, nsIURI ** aURL)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
PRUint32 count = 0;
|
PRUint32 count = 0;
|
||||||
|
@ -975,7 +992,7 @@ NS_IMETHODIMP nsNntpService::CancelMessages(const char *hostname, const char *ne
|
||||||
nsCOMPtr<nsINntpUrl> nntpUrl = do_QueryInterface(url);
|
nsCOMPtr<nsINntpUrl> nntpUrl = do_QueryInterface(url);
|
||||||
if (nntpUrl)
|
if (nntpUrl)
|
||||||
nntpUrl->SetNewsAction(nsINntpUrl::ActionCancelArticle);
|
nntpUrl->SetNewsAction(nsINntpUrl::ActionCancelArticle);
|
||||||
rv = RunNewsUrl(url, aConsumer);
|
rv = RunNewsUrl(url, aMsgWindow, aConsumer);
|
||||||
|
|
||||||
if (aURL)
|
if (aURL)
|
||||||
{
|
{
|
||||||
|
@ -1034,7 +1051,7 @@ NS_IMETHODIMP nsNntpService::NewChannel(const char *verb,
|
||||||
nsIChannel **_retval)
|
nsIChannel **_retval)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
nsNNTPProtocol *nntpProtocol = new nsNNTPProtocol(aURI);
|
nsNNTPProtocol *nntpProtocol = new nsNNTPProtocol(aURI, nsnull);
|
||||||
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;
|
if (!nntpProtocol) return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
rv = nntpProtocol->Initialize();
|
rv = nntpProtocol->Initialize();
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include "nsIFileSpec.h"
|
#include "nsIFileSpec.h"
|
||||||
#include "MailNewsTypes.h"
|
#include "MailNewsTypes.h"
|
||||||
#include "nsIMsgProtocolInfo.h"
|
#include "nsIMsgProtocolInfo.h"
|
||||||
|
#include "nsIMsgWindow.h"
|
||||||
|
#include "nsINntpUrl.h"
|
||||||
|
|
||||||
class nsIURI;
|
class nsIURI;
|
||||||
class nsIUrlListener;
|
class nsIUrlListener;
|
||||||
|
@ -56,14 +58,14 @@ protected:
|
||||||
nsCString &newsgroupName,
|
nsCString &newsgroupName,
|
||||||
nsMsgKey *aKey);
|
nsMsgKey *aKey);
|
||||||
|
|
||||||
nsresult DetermineHostForPosting(nsCString &host, const char *newsgroupNames);
|
nsresult SetUpNntpUrlForPosting(nsINntpUrl * nntpUrl, const char *newsgroupNames);
|
||||||
nsresult FindHostFromGroup(nsCString &host, nsCString &groupName);
|
nsresult FindHostFromGroup(nsCString &host, nsCString &groupName);
|
||||||
void FindServerWithNewsgroup(nsCString &host, nsCString &groupName);
|
void FindServerWithNewsgroup(nsCString &host, nsCString &groupName);
|
||||||
|
|
||||||
// a convience routine used to put together news urls.
|
// a convience routine used to put together news urls.
|
||||||
nsresult ConstructNntpUrl(const char * urlString, const char * newsgroupName, nsMsgKey key, nsIUrlListener *aUrlListener, nsIURI ** aUrl);
|
nsresult ConstructNntpUrl(const char * urlString, const char * newsgroupName, nsMsgKey key, nsIUrlListener *aUrlListener, nsIURI ** aUrl);
|
||||||
// a convience routine to run news urls
|
// a convience routine to run news urls
|
||||||
nsresult RunNewsUrl (nsIURI * aUrl, nsISupports * aConsumer);
|
nsresult RunNewsUrl (nsIURI * aUrl, nsIMsgWindow *aMsgWindow, nsISupports * aConsumer);
|
||||||
static PRBool findNewsServerWithGroup(nsISupports *aElement, void *data);
|
static PRBool findNewsServerWithGroup(nsISupports *aElement, void *data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче