changes to get nntpTest (and eventually news) working

This commit is contained in:
sspitzer%netscape.com 1999-05-04 02:35:32 +00:00
Родитель e11943a38d
Коммит d16e31e6e7
14 изменённых файлов: 1424 добавлений и 358 удалений

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

@ -31,6 +31,8 @@ CPPSRCS= nsNNTPProtocol.cpp \
nsNNTPArticleList.cpp \
nsNNTPNewsgroupList.cpp \
nsNNTPNewsgroupPost.cpp \
nsNNTPNewsgroup.cpp \
nsNNTPCategoryContainer.cpp \
nsNNTPHost.cpp \
nsNntpService.cpp \
nsNewsFolder.cpp \
@ -46,6 +48,8 @@ CPP_OBJS= .\$(OBJDIR)\nsNNTPProtocol.obj \
.\$(OBJDIR)\nsNNTPNewsgroupList.obj \
.\$(OBJDIR)\nsNNTPNewsgroupPost.obj \
.\$(OBJDIR)\nsNNTPHost.obj \
.\$(OBJDIR)\nsNNTPNewsgroup.obj \
.\$(OBJDIR)\nsNNTPCategoryContainer.obj \
.\$(OBJDIR)\nsNntpService.obj \
.\$(OBJDIR)\nsNewsFolder.obj \
.\$(OBJDIR)\nsNntpIncomingServer.obj \

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

@ -118,7 +118,7 @@ nsNNTPArticleList::~nsNNTPArticleList()
nsresult
nsNNTPArticleList::AddArticleKey(PRInt32 key)
{
#ifdef DEBUG_mscott
#if defined(DEBUG_mscott) || defined(DEBUG_sspitzer)
char * groupname = nsnull;
if (m_newsgroup)
m_newsgroup->GetName(&groupname);

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

@ -0,0 +1,101 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* This is a stub event sink for a NNTP Newsgroup introduced by mscott to test
the NNTP protocol */
#include "nsISupports.h" /* interface nsISupports */
#include "nsINNTPCategoryContainer.h"
#include "nsINNTPNewsgroup.h" /* interface nsINNTPNewsgroup */
#include "nscore.h"
#include "plstr.h"
#include "prmem.h"
#include <stdio.h>
class nsNNTPCategoryContainerStub : public nsISupports {
public:
nsNNTPCategoryContainerStub();
virtual ~nsNNTPCategoryContainerStub();
NS_DECL_ISUPPORTS
NS_IMETHOD GetRootCategory(nsINNTPNewsgroup * *aRootCategory);
NS_IMETHOD SetRootCategory(nsINNTPNewsgroup * aRootCategory);
protected:
nsINNTPNewsgroup * m_newsgroup;
};
NS_IMPL_ISUPPORTS(nsNNTPCategoryContainerStub, nsINNTPCategoryContainer::GetIID());
nsNNTPCategoryContainerStub::nsNNTPCategoryContainerStub()
{
NS_INIT_REFCNT();
m_newsgroup = nsnull;
}
nsNNTPCategoryContainerStub::~nsNNTPCategoryContainerStub()
{
printf("Destroying category container. \n");
NS_IF_RELEASE(m_newsgroup);
}
nsresult nsNNTPCategoryContainerStub::GetRootCategory(nsINNTPNewsgroup * *aRootCategory)
{
if (aRootCategory)
{
*aRootCategory = m_newsgroup;
NS_IF_ADDREF(m_newsgroup);
}
return NS_OK;
}
nsresult nsNNTPCategoryContainerStub::SetRootCategory(nsINNTPNewsgroup * aRootCategory)
{
if (aRootCategory)
{
char * name = nsnull;
aRootCategory->GetName(&name);
printf("Setting root category for container to %s", name ? name : "unspecified");
m_newsgroup = aRootCategory;
NS_IF_ADDREF(m_newsgroup);
}
return NS_OK;
}
extern "C" {
nsresult NS_NewCategoryContainerFromNewsgroup(nsINNTPCategoryContainer ** aInstancePtr, nsINNTPNewsgroup* group)
{
nsresult rv = NS_OK;
nsNNTPCategoryContainerStub * stub = nsnull;
if (aInstancePtr)
{
stub = new nsNNTPCategoryContainerStub();
stub->SetRootCategory(group);
rv = stub->QueryInterface(nsINNTPCategoryContainer::GetIID(), (void **) aInstancePtr);
}
return rv;
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -21,9 +21,15 @@
#include "nsINNTPHost.h"
/* some platforms (like Windows and Mac) use a map file, because of
* file name length limitations. */
#ifndef XP_UNIX
#define USE_NEWSRC_MAP_FILE
#endif
NS_BEGIN_EXTERN_C
nsresult NS_NewNNTPHost(nsINNTPHost **aInstancePtrResult, const char * name, PRUint32 port);
nsresult NS_NewNNTPHost(nsINNTPHost **aInstancePtrResult, const char *name, PRUint32 port);
NS_END_EXTERN_C

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

@ -0,0 +1,341 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nscore.h"
#include "plstr.h"
#include "prmem.h"
#include <stdio.h>
#include "nsISupports.h" /* interface nsISupports */
#include "nsINNTPNewsgroup.h"
#include "nsNNTPArticleSet.h"
class nsNNTPNewsgroup : public nsINNTPNewsgroup
{
public:
nsNNTPNewsgroup();
virtual ~nsNNTPNewsgroup();
NS_DECL_ISUPPORTS
NS_IMETHOD GetName(char * *aName);
NS_IMETHOD SetName(char * aName);
NS_IMETHOD GetPrettyName(char * *aPrettyName);
NS_IMETHOD SetPrettyName(char * aPrettyName);
NS_IMETHOD GetPassword(char * *aPassword);
NS_IMETHOD SetPassword(char * aPassword);
NS_IMETHOD GetUsername(char * *aUsername);
NS_IMETHOD SetUsername(char * aUsername);
NS_IMETHOD GetNeedsExtraInfo(PRBool *aNeedsExtraInfo);
NS_IMETHOD SetNeedsExtraInfo(PRBool aNeedsExtraInfo);
NS_IMETHOD IsOfflineArticle(PRInt32 num, PRBool *_retval);
NS_IMETHOD GetCategory(PRBool *aCategory);
NS_IMETHOD SetCategory(PRBool aCategory);
NS_IMETHOD GetSubscribed(PRBool *aSubscribed);
NS_IMETHOD SetSubscribed(PRBool aSubscribed);
NS_IMETHOD GetWantNewTotals(PRBool *aWantNewTotals);
NS_IMETHOD SetWantNewTotals(PRBool aWantNewTotals);
NS_IMETHOD GetNewsgroupList(nsINNTPNewsgroupList * *aNewsgroupList);
NS_IMETHOD SetNewsgroupList(nsINNTPNewsgroupList * aNewsgroupList);
NS_IMETHOD UpdateSummaryFromNNTPInfo(PRInt32 oldest, PRInt32 youngest, PRInt32 total_messages);
protected:
char * m_groupName;
char * m_prettyName;
char * m_password;
char * m_userName;
PRBool m_isSubscribed;
PRBool m_wantsNewTotals;
PRBool m_needsExtraInfo;
PRBool m_category;
nsINNTPNewsgroupList * m_newsgroupList;
};
nsNNTPNewsgroup::nsNNTPNewsgroup()
{
NS_INIT_REFCNT();
m_groupName = nsnull;
m_prettyName = nsnull;
m_password = nsnull;
m_userName = nsnull;
m_newsgroupList = nsnull;
m_needsExtraInfo = PR_FALSE;
m_category = PR_FALSE;
}
nsNNTPNewsgroup::~nsNNTPNewsgroup()
{
printf("destroying newsgroup: %s", m_groupName ? m_groupName : "");
NS_IF_RELEASE(m_newsgroupList);
PR_FREEIF(m_groupName);
PR_FREEIF(m_password);
PR_FREEIF(m_userName);
PR_FREEIF(m_prettyName);
}
NS_IMPL_ISUPPORTS(nsNNTPNewsgroup, nsINNTPNewsgroup::GetIID());
nsresult nsNNTPNewsgroup::GetName(char ** aName)
{
if (aName)
{
*aName = PL_strdup(m_groupName);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetName(char *aName)
{
if (aName)
{
printf("Setting newsgroup name to %s. \n", aName);
m_groupName = PL_strdup(aName);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetPrettyName(char ** aName)
{
if (aName)
{
*aName = PL_strdup(m_prettyName);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetPrettyName(char *aName)
{
if (aName)
{
printf("Setting pretty newsgroup name to %s. \n", aName);
m_prettyName = PL_strdup(aName);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetPassword(char ** aName)
{
if (aName)
{
*aName = PL_strdup(m_password);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetPassword(char *aName)
{
if (aName)
{
printf("Setting password for newsgroup %s to %s. \n", m_groupName, aName);
m_password = PL_strdup(aName);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetUsername(char ** aUsername)
{
if (aUsername)
{
*aUsername = PL_strdup(m_userName);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetUsername(char *aUsername)
{
if (aUsername)
{
printf("Setting username for newsgroup %s to %s. \n", m_groupName, aUsername);
m_userName = PL_strdup(aUsername);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetNeedsExtraInfo(PRBool *aNeedsExtraInfo)
{
if (aNeedsExtraInfo)
{
*aNeedsExtraInfo = m_needsExtraInfo;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetNeedsExtraInfo(PRBool aNeedsExtraInfo)
{
if (aNeedsExtraInfo)
{
printf("Setting needs extra info for newsgroup %s to %s. \n", m_groupName, aNeedsExtraInfo ? "TRUE" : "FALSE" );
m_needsExtraInfo = aNeedsExtraInfo;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::IsOfflineArticle(PRInt32 num, PRBool *_retval)
{
printf("Testing for offline article %d in %s. \n", num, m_groupName);
if (_retval)
*_retval = PR_FALSE;
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetCategory(PRBool *aCategory)
{
if (aCategory)
{
*aCategory = m_category;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetCategory(PRBool aCategory)
{
if (aCategory)
{
printf("Setting is category for newsgroup %s to %s. \n", m_groupName, aCategory ? "TRUE" : "FALSE" );
m_category = aCategory;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetSubscribed(PRBool *aSubscribed)
{
if (aSubscribed)
{
*aSubscribed = m_isSubscribed;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetSubscribed(PRBool aSubscribed)
{
if (aSubscribed)
{
m_isSubscribed = aSubscribed;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetWantNewTotals(PRBool *aWantNewTotals)
{
if (aWantNewTotals)
{
*aWantNewTotals = m_wantsNewTotals;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetWantNewTotals(PRBool aWantNewTotals)
{
if (aWantNewTotals)
{
printf("Setting wants new totals for newsgroup %s to %s. \n", m_groupName, aWantNewTotals ? "TRUE" : "FALSE" );
m_wantsNewTotals = aWantNewTotals;
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::GetNewsgroupList(nsINNTPNewsgroupList * *aNewsgroupList)
{
if (aNewsgroupList)
{
*aNewsgroupList = m_newsgroupList;
NS_IF_ADDREF(m_newsgroupList);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::SetNewsgroupList(nsINNTPNewsgroupList * aNewsgroupList)
{
if (aNewsgroupList)
{
printf("Setting newsgroup list for newsgroup %s. \n", m_groupName);
m_newsgroupList = aNewsgroupList;
NS_IF_ADDREF(m_newsgroupList);
}
return NS_OK;
}
nsresult nsNNTPNewsgroup::UpdateSummaryFromNNTPInfo(PRInt32 oldest, PRInt32 youngest, PRInt32 total_messages)
{
printf("Updating summary with oldest= %d, youngest= %d, and total messages = %d. \n", oldest, youngest, total_messages);
return NS_OK;
}
extern "C" {
nsresult NS_NewNewsgroup(nsINNTPNewsgroup **info,
char *line,
nsNNTPArticleSet *set,
PRBool subscribed,
nsINNTPHost *host,
int depth)
{
nsresult rv = NS_OK;
nsNNTPNewsgroup * group = new nsNNTPNewsgroup();
if (group)
{
group->SetSubscribed(subscribed);
rv = group->QueryInterface(nsINNTPNewsgroup::GetIID(), (void **) info);
}
#ifdef DEBUG_sspitzer
printf("NS_NewNewsgroup(%s)\n",line?line:"(null)");
#endif
if (line) {
group->SetName(line);
}
return rv;
}
}

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

@ -33,5 +33,6 @@ NS_NewNewsgroup(nsINNTPNewsgroup **info,
int depth);
NS_END_EXTERN_C
#endif

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

@ -43,9 +43,16 @@ class MessageDBView;
#include "nsNNTPNewsgroupList.h"
#include "nsINNTPArticleList.h"
#include "nsNNTPArticleSet.h"
#include "nsINNTPNewsgroup.h"
#include "nsNNTPNewsgroup.h"
#include "nsINNTPHost.h"
#include "nsNNTPHost.h"
#include "msgCore.h"
#include "plstr.h"
@ -66,6 +73,7 @@ class MessageDBView;
#include "msgpane.h"
#endif
#if 0
extern "C"
{
extern int MK_OUT_OF_MEMORY;
@ -73,6 +81,7 @@ extern "C"
extern int MK_HDR_DOWNLOAD_COUNT;
extern int MK_NO_NEW_DISC_MSGS;
}
#endif
extern PRInt32 net_NewsChunkSize;
@ -86,7 +95,7 @@ class nsNNTPNewsgroupList : public nsINNTPNewsgroupList
#endif
{
public:
nsNNTPNewsgroupList(nsINNTPHost *, nsINNTPNewsgroup*);
nsNNTPNewsgroupList(nsINNTPHost *host, nsINNTPNewsgroup *newsgroup, const char *name, const char*url);
nsNNTPNewsgroupList();
virtual ~nsNNTPNewsgroupList();
NS_DECL_ISUPPORTS
@ -102,16 +111,16 @@ public:
// XOVER parser to populate this class
NS_IMETHOD InitXOVER(PRInt32 first_msg, PRInt32 last_msg);
NS_IMETHOD ProcessXOVER(const char *line, PRUint32 * status);
NS_IMETHOD ProcessXOVERLINE(const char *line, PRUint32 * status);
NS_IMETHOD ResetXOVER();
NS_IMETHOD ProcessNonXOVER(const char *line);
NS_IMETHOD FinishXOVER(int status, int *newstatus);
NS_IMETHOD FinishXOVERLINE(int status, int *newstatus);
NS_IMETHOD ClearXOVERState();
NS_IMETHOD GetGroupName(char **retval);
private:
NS_METHOD Init(nsINNTPHost *, nsINNTPNewsgroup*) { return NS_OK;}
NS_METHOD InitNewsgroupList(const char *url, const char *groupName);
void Init(nsINNTPHost *host, nsINNTPNewsgroup *newsgroup, const char *name, const char *url);
NS_METHOD CleanUp();
@ -128,7 +137,6 @@ private:
#endif
PRBool m_finishingXover;
nsINNTPHost* GetHost() {return m_host;}
const char * GetGroupName() {return m_groupName;}
const char * GetURL() {return m_url;}
#ifdef HAVE_CHANGELISTENER
@ -154,6 +162,7 @@ protected:
PRInt32 m_maxArticles;
char *m_groupName;
nsINNTPHost *m_host;
nsINNTPNewsgroup *m_newsgroup;
char *m_url; // url we're retrieving
#ifdef HAVE_MASTER
MSG_Master *m_master;
@ -173,10 +182,12 @@ protected:
nsNNTPNewsgroupList::nsNNTPNewsgroupList(nsINNTPHost* host,
nsINNTPNewsgroup *newsgroup)
nsINNTPNewsgroup *newsgroup,
const char *name,
const char *url)
{
NS_INIT_REFCNT();
Init(host, newsgroup);
Init(host, newsgroup, name, url);
}
@ -186,11 +197,9 @@ nsNNTPNewsgroupList::~nsNNTPNewsgroupList()
NS_IMPL_ISUPPORTS(nsNNTPNewsgroupList, nsINNTPNewsgroupList::GetIID());
nsresult
nsNNTPNewsgroupList::InitNewsgroupList(const char *url, const char *groupName)
#ifdef HAVE_PANES
, MSG_Pane *pane);
#endif
void
nsNNTPNewsgroupList::Init(nsINNTPHost *host, nsINNTPNewsgroup *newsgroup, const char *name, const char *url)
{
#ifdef HAVE_NEWSDB
m_newsDB = NULL;
@ -198,7 +207,7 @@ nsNNTPNewsgroupList::InitNewsgroupList(const char *url, const char *groupName)
#ifdef HAVE_DBVIEW
m_msgDBView = NULL;
#endif
m_groupName = PL_strdup(groupName);
m_groupName = PL_strdup(name);
m_host = NULL;
m_url = PL_strdup(url);
m_lastProcessedNumber = 0;
@ -214,24 +223,16 @@ nsNNTPNewsgroupList::InitNewsgroupList(const char *url, const char *groupName)
m_startedUpdate = PR_FALSE;
memset(&m_knownArts, 0, sizeof(m_knownArts));
m_knownArts.group_name = m_groupName;
#ifdef HAVE_URLPARSER
char* host_and_port = NET_ParseURL(url, GET_HOST_PART);
#ifdef HAVE_MASTER
m_host = m_master->FindHost(host_and_port,
(url[0] == 's' || url[0] == 'S'),
-1);
#endif
PR_FREEIF(host_and_port);
#endif
m_host = host;
m_newsgroup = newsgroup;
m_knownArts.host = m_host;
m_knownArts.set = nsNNTPArticleSet::Create();
m_getOldMessages = PR_FALSE;
m_promptedAlready = PR_FALSE;
m_downloadAll = PR_FALSE;
m_maxArticles = 0;
m_firstMsgToDownload = 0;
m_lastMsgToDownload = 0;
return NS_MSG_SUCCESS;
}
nsresult
@ -248,7 +249,10 @@ nsNNTPNewsgroupList::CleanUp() {
if (m_newsDB)
m_newsDB->Close();
#endif
delete m_knownArts.set;
if (m_knownArts.set) {
delete m_knownArts.set;
m_knownArts.set = nsnull;
}
return NS_OK;
}
@ -322,10 +326,16 @@ nsNNTPNewsgroupList::GetRangeOfArtsToDownload(
newsGroupInfo->GetKnownArtsSet(knownArtsString);
if (last_possible < newsGroupInfo->GetHighWater())
newsGroupInfo->SetHighWater(last_possible, TRUE);
if (m_knownArts.set) {
delete m_knownArts.set;
}
m_knownArts.set = nsNNTPArticleSet::Create(knownArtsString);
}
else
{
{
if (m_knownArts.set) {
delete m_knownArts.set;
}
m_knownArts.set = nsNNTPArticleSet::Create();
m_knownArts.set->AddRange(m_newsDB->GetLowWaterArticleNum(), m_newsDB->GetHighwaterArticleNum());
}
@ -476,11 +486,13 @@ nsNNTPNewsgroupList::AddToKnownArticles(PRInt32 first, PRInt32 last)
m_knownArts.host = host;
PR_FREEIF(m_knownArts.group_name);
m_knownArts.group_name = PL_strdup(group_name);
delete m_knownArts.set;
if (m_knownArts.set) {
delete m_knownArts.set;
}
m_knownArts.set = nsNNTPArticleSet::Create();
if (!m_knownArts.group_name || !m_knownArts.set) {
return MK_OUT_OF_MEMORY;
return NS_ERROR_OUT_OF_MEMORY;
}
}
@ -536,7 +548,7 @@ nsNNTPNewsgroupList::InitXOVER(PRInt32 first_msg, PRInt32 last_msg)
#define NEWS_ART_DISPLAY_FREQ 10
nsresult
nsNNTPNewsgroupList::ProcessXOVER(const char *line, PRUint32 *status)
nsNNTPNewsgroupList::ProcessXOVERLINE(const char *line, PRUint32 *status)
{
const char *next;
PRUint32 message_number=0;
@ -545,7 +557,7 @@ nsNNTPNewsgroupList::ProcessXOVER(const char *line, PRUint32 *status)
PR_ASSERT (line);
if (!line)
return NS_MSG_FAILURE;
return NS_ERROR_NULL_POINTER;
#ifdef HAVE_DBVIEW
if (m_msgDBView != NULL)
@ -671,7 +683,7 @@ nsNNTPNewsgroupList::ProcessNonXOVER (const char * /*line*/)
nsresult
nsNNTPNewsgroupList::FinishXOVER (int status, int *newstatus)
nsNNTPNewsgroupList::FinishXOVERLINE(int status, int *newstatus)
{
struct MSG_NewsKnown* k;
@ -702,6 +714,11 @@ nsNNTPNewsgroupList::FinishXOVER (int status, int *newstatus)
k = &m_knownArts;
if (k == nsnull) {
return NS_ERROR_NULL_POINTER;
}
if (k->set)
{
PRInt32 n = k->set->FirstNonMember();
@ -785,3 +802,25 @@ nsNNTPNewsgroupList::ClearXOVERState()
return NS_OK;
}
nsresult
nsNNTPNewsgroupList::GetGroupName(char **retval)
{
*retval = m_groupName;
return NS_OK;
}
extern "C" nsresult NS_NewNewsgroupList(nsINNTPNewsgroupList **aInstancePtrResult,
nsINNTPHost *newsHost,
nsINNTPNewsgroup *newsgroup,
const char *name,
const char *url)
{
nsNNTPNewsgroupList *list = nsnull;
list = new nsNNTPNewsgroupList(newsHost, newsgroup, name, url);
if (list == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = list->QueryInterface(nsINNTPNewsgroupList::GetIID(), (void **) aInstancePtrResult);
return rv;
}

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

@ -57,6 +57,8 @@ typedef struct MSG_NewsKnown {
extern "C" nsresult
NS_NewNewsgroupList(nsINNTPNewsgroupList **aInstancePtrResult,
nsINNTPHost *newsHost,
nsINNTPNewsgroup *newsgroup);
nsINNTPNewsgroup *newsgroup,
const char *name,
const char *url);
#endif

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

@ -143,6 +143,8 @@ NS_IMPL_ISUPPORTS(nsNNTPNewsgroupPost, nsINNTPNewsgroupPost::GetIID());
nsNNTPNewsgroupPost::nsNNTPNewsgroupPost()
{
NS_INIT_REFCNT();
int i;
for (i=0; i <= HEADER_LAST; i++)
m_header[i]=nsnull;

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

@ -532,7 +532,20 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL, nsISupports * aConsumer)
{
rv = NS_NewNNTPHost(&m_newsHost, hostAndPort, port ? port : NEWS_PORT);
// save it on our url for future use....
if (NS_FAILED(rv) || (m_newsHost == nsnull)) {
status = -1;
goto FAIL;
}
m_runningURL->SetNntpHost(m_newsHost);
// read in the newsrc file now, to build up the host correctly.
rv = m_newsHost->LoadNewsrc("news://news.mozilla.org");
if (NS_FAILED(rv)) {
status = -1;
goto FAIL;
}
}
PR_ASSERT(NS_SUCCEEDED(rv));
@ -1580,6 +1593,10 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
nsresult rv;
nsINNTPNewsgroup *newsgroup;
if (m_newsHost == nsnull) {
printf("m_newsHost is null, panic!\n");
return -1;
}
rv = m_newsHost->GetNewsgroupAndNumberOfID(m_path,
&newsgroup,
&number);
@ -1618,7 +1635,11 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
{
PRTime last_update;
nsresult rv;
if (m_newsHost == nsnull) {
printf("m_newsHost is null, panic!\n");
return -1;
}
rv = m_newsHost->GetLastUpdatedTime(&last_update);
char small_buf[64];
PRExplodedTime expandedTime;
@ -1634,7 +1655,7 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
last_update -= NEWGROUPS_TIME_OFFSET;
{
int64 secToUSec, timeInSec, timeInUSec;
PRInt64 secToUSec, timeInSec, timeInUSec;
LL_I2L(timeInSec, last_update);
LL_I2L(secToUSec, PR_USEC_PER_SEC);
LL_MUL(timeInUSec, timeInSec, secToUSec);
@ -1651,7 +1672,12 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
ClearFlag(NNTP_USE_FANCY_NEWSGROUP);
PRTime last_update;
nsresult rv = m_newsHost->GetLastUpdatedTime(&last_update);
if (m_newsHost == nsnull) {
printf("m_newsHost is null, panic!\n");
return -1;
}
nsresult rv = m_newsHost->GetLastUpdatedTime(&last_update);
if (NS_SUCCEEDED(rv) && last_update!=0)
{
@ -1695,9 +1721,14 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
nsresult rv=NS_ERROR_NULL_POINTER;
NET_SACopy(&command, "GROUP ");
if (m_newsgroup)
rv = m_newsgroup->GetName(&group_name);
if (m_newsgroup == nsnull) {
printf("m_newsgroup is null, panic!\n");
return -1;
}
rv = m_newsgroup->GetName(&group_name);
slash = PL_strchr(group_name, '/');
m_firstArticle = 0;
m_lastArticle = 0;
if (slash)
@ -1713,6 +1744,10 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
{
nsresult rv;
PRBool searchable=PR_FALSE;
if (m_newsHost == nsnull) {
printf("m_newsHost is null, panic!\n");
return -1;
}
rv = m_newsHost->QueryExtension("SEARCH", &searchable);
if (NS_SUCCEEDED(rv) && searchable)
{
@ -1737,6 +1772,10 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
/* for XPAT, we have to GROUP into the group before searching */
NET_SACopy(&command, "GROUP ");
if (m_newsgroup == nsnull) {
printf("m_newsgroup is null, panic!\n");
return -1;
}
rv = m_newsgroup->GetName(&group_name);
NET_SACat (&command, group_name);
m_nextState = NNTP_RESPONSE;
@ -2695,7 +2734,7 @@ PRInt32 nsNNTPProtocol::BeginReadXover()
/* We now know there is a summary line there; make sure it has the
right numbers in it. */
char *group_name;
char *group_name = nsnull;
m_newsgroup->GetName(&group_name);
m_newsHost->DisplaySubscribedGroup(group_name,
@ -2703,6 +2742,7 @@ PRInt32 nsNNTPProtocol::BeginReadXover()
m_lastPossibleArticle,
count, PR_TRUE);
PR_Free(group_name);
group_name = nsnull;
if (status < 0) return status;
m_numArticlesLoaded = 0;
@ -2725,19 +2765,23 @@ PRInt32 nsNNTPProtocol::FigureNextChunk()
if (m_firstArticle > 0)
{
nsresult rv;
nsresult rv = NS_OK;
char *groupName;
nsINNTPNewsgroupList *newsgroupList;
rv = m_newsgroup->GetName(&groupName);
rv = m_newsgroup->GetName(&groupName);
/* XXX - parse state stored in MSG_Pane cd->pane */
if (NS_SUCCEEDED(rv))
rv = m_newsHost->GetNewsgroupList(groupName, &newsgroupList);
rv = m_newsHost->GetNewsgroupList(groupName, &m_newsgroupList);
if (NS_SUCCEEDED(rv))
rv = newsgroupList->AddToKnownArticles(m_firstArticle,
#ifdef DEBUG_sspitzer
printf("add to known articles: %d - %d\n", m_firstArticle, m_lastArticle);
#endif
if (NS_SUCCEEDED(rv) && m_newsgroupList != nsnull) {
rv = m_newsgroupList->AddToKnownArticles(m_firstArticle,
m_lastArticle);
}
if (NS_FAILED(rv))
{
return status;
@ -2753,27 +2797,28 @@ PRInt32 nsNNTPProtocol::FigureNextChunk()
}
char *groupName;
nsINNTPNewsgroupList *newsgroupList;
char *groupName = nsnull;
rv = m_newsgroup->GetName(&groupName);
if (NS_SUCCEEDED(rv))
rv = m_newsHost->GetNewsgroupList(groupName, &newsgroupList);
if (m_newsgroupList == nsnull) {
rv = m_newsgroup->GetName(&groupName);
if (NS_SUCCEEDED(rv))
rv = m_newsHost->GetNewsgroupList(groupName, &m_newsgroupList);
}
if (NS_SUCCEEDED(rv))
rv =
newsgroupList->GetRangeOfArtsToDownload(m_firstPossibleArticle,
if (NS_SUCCEEDED(rv) && m_newsgroupList != nsnull) {
rv = m_newsgroupList->GetRangeOfArtsToDownload(m_firstPossibleArticle,
m_lastPossibleArticle,
m_numArticlesWanted -
m_numArticlesLoaded,
&(m_firstArticle),
&(m_lastArticle),
&status);
if (NS_FAILED(rv))
{
return status;
}
if (NS_FAILED(rv)) {
return status;
}
if (m_firstArticle <= 0 || m_firstArticle > m_lastArticle)
{
@ -2788,9 +2833,9 @@ PRInt32 nsNNTPProtocol::FigureNextChunk()
m_articleNumber = m_firstArticle;
/* was MSG_InitXOVER() */
rv = m_newsgroup->GetNewsgroupList(&m_newsgroupList);
if (NS_SUCCEEDED(rv))
if (m_newsgroupList != nsnull) {
rv = m_newsgroupList->InitXOVER(m_firstArticle, m_lastArticle);
}
/* convert nsresult->status */
status = !NS_SUCCEEDED(rv);
@ -2818,7 +2863,9 @@ PRInt32 nsNNTPProtocol::XoverSend()
m_firstArticle,
m_lastArticle);
/* printf("XOVER %ld-%ld\n", m_firstArticle, m_lastArticle); */
#ifdef DEBUG_sspitzer
printf("XOVER %ld-%ld\n", m_firstArticle, m_lastArticle);
#endif
NNTP_LOG_WRITE(outputBuffer);
@ -2874,7 +2921,7 @@ PRInt32 nsNNTPProtocol::ReadXoverResponse()
PRInt32 nsNNTPProtocol::ReadXover(nsIInputStream * inputStream, PRUint32 length)
{
char *line;
char *line;
nsresult rv;
PRUint32 status = 1;
@ -2924,7 +2971,7 @@ PRInt32 nsNNTPProtocol::ReadXover(nsIInputStream * inputStream, PRUint32 length)
#endif
}
rv = m_newsgroupList->ProcessXOVER(line, &status);
rv = m_newsgroupList->ProcessXOVERLINE(line, &status);
PR_ASSERT(NS_SUCCEEDED(rv));
m_numArticlesLoaded++;
@ -2941,8 +2988,13 @@ PRInt32 nsNNTPProtocol::ProcessXover()
{
nsresult rv;
PRInt32 status = 0;
/* xover_parse_state stored in MSG_Pane cd->pane */
rv = m_newsgroupList->FinishXOVER(0,&status);
if (m_newsgroupList == nsnull) {
return NS_ERROR_NULL_POINTER;
}
rv = m_newsgroupList->FinishXOVERLINE(0,&status);
if (NS_SUCCEEDED(rv) && status < 0) return status;
@ -4512,7 +4564,7 @@ PRInt32 nsNNTPProtocol::CloseConnection()
int status;
nsresult rv;
/* XXX - how/when to Release() this? */
rv = m_newsgroupList->FinishXOVER(status,&status);
rv = m_newsgroupList->FinishXOVERLINE(status,&status);
PR_ASSERT(NS_SUCCEEDED(rv));
if (NS_SUCCEEDED(rv))
NS_RELEASE(m_newsgroupList);
@ -4527,7 +4579,7 @@ PRInt32 nsNNTPProtocol::CloseConnection()
}
#ifdef UNREADY_CODE
if (cd->control_con)
cd->control_con->last_used_time = XP_TIME();
cd->control_con->last_used_time = PR_Now();
#endif
PR_FREEIF(m_path);

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

@ -23,17 +23,28 @@
#include <windows.h> // for InterlockedIncrement
#endif
#include "nsNntpService.h"
#include "nsINetService.h"
#include "nsINntpUrl.h"
#include "nsNNTPProtocol.h"
#include "nsNNTPNewsgroupPost.h"
#include "nsINetService.h"
#include "nsIMsgMailSession.h"
#include "nsIMsgIdentity.h"
#include "nsString2.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(kNntpUrlCID, NS_NNTPURL_CID);
static NS_DEFINE_CID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
nsNntpService::nsNntpService()
{
@ -51,16 +62,17 @@ nsresult nsNntpService::QueryInterface(const nsIID &aIID, void** aInstancePtr)
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsINntpService::GetIID()) || aIID.Equals(kISupportsIID))
if (aIID.Equals(nsINntpService::GetIID())
|| aIID.Equals(kISupportsIID))
{
*aInstancePtr = (void*) ((nsINntpService*)this);
AddRef();
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIMsgMessageService::GetIID()))
{
*aInstancePtr = (void*) ((nsIMsgMessageService*)this);
AddRef();
NS_ADDREF_THIS();
return NS_OK;
}
@ -82,16 +94,16 @@ nsresult nsNntpService::QueryInterface(const nsIID &aIID, void** aInstancePtr)
nsresult nsNntpService::DisplayMessage(const char* aMessageURI, nsISupports * aDisplayConsumer,
nsIUrlListener * aUrlListener, nsIURL ** aURL)
{
// this function is just a shell right now....eventually we'll implement displaymessage such
// that we break down the URI and extract the news host and article number. We'll then
// build up a url that represents that action, create a connection to run the url
// and load the url into the connection.
// HACK ALERT: For now, the only news url we run is a display message url. So just forward
// this URI to RunNewUrl
return RunNewsUrl(aMessageURI, aDisplayConsumer, aUrlListener, aURL);
// this function is just a shell right now....eventually we'll implement displaymessage such
// that we break down the URI and extract the news host and article number. We'll then
// build up a url that represents that action, create a connection to run the url
// and load the url into the connection.
// HACK ALERT: For now, the only news url we run is a display message url. So just forward
// this URI to RunNewUrl
nsString uri = aMessageURI;
return RunNewsUrl(uri, aDisplayConsumer, aUrlListener, aURL);
}
nsresult nsNntpService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListener * aMailboxCopyHandler, PRBool moveMessage,
@ -104,9 +116,53 @@ nsresult nsNntpService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListen
////////////////////////////////////////////////////////////////////////////////////////
// nsINntpService support
////////////////////////////////////////////////////////////////////////////////////////
nsresult nsNntpService::PostMessage(nsFilePath &pathToFile, const char *subject, const char *newsgroup, nsIUrlListener * aUrlListener, nsIURL ** aURL)
{
nsresult rv = NS_OK;
NS_IMETHODIMP nsNntpService::RunNewsUrl(const nsString& urlString, nsISupports * aConsumer,
nsIUrlListener *aUrlListener, nsIURL ** aUrl)
#ifdef DEBUG_sspitzer
printf("nsNntpService::PostMessage(%s,%s,%s,??,??)\n",(const char *)pathToFile,subject,newsgroup);
#endif
NS_LOCK_INSTANCE();
// get the current identity from the news session....
NS_WITH_SERVICE(nsIMsgMailSession,newsSession,kCMsgMailSessionCID,&rv);
if (NS_SUCCEEDED(rv) && newsSession)
{
nsIMsgIdentity * identity = nsnull;
rv = newsSession->GetCurrentIdentity(&identity);
if (NS_SUCCEEDED(rv) && identity)
{
char * fullname = nsnull;
char * email = nsnull;
char * organization = nsnull;
identity->GetFullName(&fullname);
identity->GetEmail(&email);
identity->GetOrganization(&organization);
#ifdef DEBUG_sspitzer
printf("post message as: %s,%s,%s\n",fullname,email,organization);
#endif
// todo: are we leaking fullname, email and organization?
// release the identity
NS_IF_RELEASE(identity);
} // if we have an identity
else
NS_ASSERTION(0, "no current identity found for this user....");
} // if we had a news session
NS_UNLOCK_INSTANCE();
return rv;
}
nsresult nsNntpService::RunNewsUrl(const nsString& urlString, nsISupports * aConsumer,
nsIUrlListener *aUrlListener, nsIURL ** aURL)
{
// for now, assume the url is a news url and load it....
nsINntpUrl *nntpUrl = nsnull;
@ -147,10 +203,12 @@ NS_IMETHODIMP nsNntpService::RunNewsUrl(const nsString& urlString, nsISupports *
nntpProtocol = new nsNNTPProtocol(nntpUrl, transport);
if (nntpProtocol)
nntpProtocol->LoadURL(nntpUrl, aConsumer);
//delete nntpProtocol;
}
if (aUrl)
*aUrl = nntpUrl; // transfer ref count
if (aURL)
*aURL = nntpUrl; // transfer ref count
else
NS_RELEASE(nntpUrl);
} // if nntpUrl

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

@ -39,6 +39,8 @@ public:
NS_IMETHOD RunNewsUrl (const nsString& urlString, nsISupports * aConsumer,
nsIUrlListener * aUrlListener, nsIURL ** aURL);
NS_IMETHOD PostMessage (nsFilePath &pathToFile, const char *subject, const char *newsgroup, nsIUrlListener * aUrlListener, nsIURL ** aURL);
////////////////////////////////////////////////////////////////////////////////////////
// we suppport the nsIMsgMessageService Interface
////////////////////////////////////////////////////////////////////////////////////////

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

@ -849,6 +849,11 @@ nsresult nsNntpUrl::GetSpec(const char* *result) const
nsresult nsNntpUrl::SetSpec(const char *aNewSpec)
{
#ifdef DEBUG_sspitzer
if (aNewSpec) {
printf("nsNntpUrl::SetSpec(%s)\n", aNewSpec);
}
#endif
// XXX is this right, or should we call ParseURL?
nsresult rv = NS_OK;
// NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");