зеркало из https://github.com/mozilla/pjs.git
more work to get respecting the newsrc set working. move the set into the db. this isn't done yet, but it's shaping up.
This commit is contained in:
Родитель
cf4141e1cc
Коммит
ea0eec35aa
|
@ -22,6 +22,10 @@
|
|||
#include "nsMsgKeySet.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#ifdef DEBUG_seth
|
||||
#define DEBUG_MSGKEYSET 1
|
||||
#endif
|
||||
|
||||
/* A compressed encoding for sets of article. This is usually for lines from
|
||||
the newsrc, which have article lists like
|
||||
|
||||
|
@ -207,6 +211,10 @@ nsMsgKeySet::Create(/*MSG_NewsHost* host*/)
|
|||
nsMsgKeySet*
|
||||
nsMsgKeySet::Create(const char* value /* , MSG_NewsHost* host */)
|
||||
{
|
||||
#ifdef DEBUG_MSGKEYSET
|
||||
printf("create from %s\n",value);
|
||||
#endif
|
||||
|
||||
nsMsgKeySet* set = new nsMsgKeySet(value /* , host */);
|
||||
if (set && set->m_data == NULL) {
|
||||
delete set;
|
||||
|
@ -636,6 +644,10 @@ nsMsgKeySet::Add(PRInt32 number)
|
|||
PRInt32 *tail;
|
||||
PRInt32 *end;
|
||||
|
||||
#ifdef DEBUG_MSGKEYSET
|
||||
printf("add %d\n",number);
|
||||
#endif
|
||||
|
||||
size = m_length;
|
||||
head = m_data;
|
||||
tail = head;
|
||||
|
@ -728,6 +740,9 @@ nsMsgKeySet::Remove(PRInt32 number)
|
|||
PRInt32 *head;
|
||||
PRInt32 *tail;
|
||||
PRInt32 *end;
|
||||
#ifdef DEBUG_MSGKEYSET
|
||||
printf("remove %d\n",number);
|
||||
#endif
|
||||
|
||||
size = m_length;
|
||||
head = m_data;
|
||||
|
|
|
@ -160,6 +160,7 @@ public:
|
|||
NS_IMETHOD GetThreadContainingMsgHdr(nsIMsgDBHdr *msgHdr, nsIMsgThread **result) = 0;
|
||||
|
||||
NS_IMETHOD GetMsgKeySet(nsMsgKeySet **pSet) = 0;
|
||||
NS_IMETHOD SetMsgKeySet(char * setStr) = 0;
|
||||
|
||||
NS_IMETHOD GetHighWaterArticleNum(nsMsgKey *key) =0;
|
||||
NS_IMETHOD GetLowWaterArticleNum(nsMsgKey *key) =0;
|
||||
|
|
|
@ -179,8 +179,9 @@ public:
|
|||
NS_IMETHOD GetThreadForMsgKey(nsMsgKey msgKey, nsIMsgThread **result);
|
||||
NS_IMETHOD GetThreadContainingMsgHdr(nsIMsgDBHdr *msgHdr, nsIMsgThread **result) ;
|
||||
|
||||
NS_IMETHOD GetMsgKeySet(nsMsgKeySet **pSet) ;
|
||||
|
||||
NS_IMETHOD GetMsgKeySet(nsMsgKeySet **pSet);
|
||||
NS_IMETHOD SetMsgKeySet(char * setStr);
|
||||
|
||||
NS_IMETHOD GetHighWaterArticleNum(nsMsgKey *key);
|
||||
NS_IMETHOD GetLowWaterArticleNum(nsMsgKey *key);
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -44,9 +44,7 @@ public:
|
|||
// methods to get and set docsets for ids.
|
||||
NS_IMETHOD MarkHdrRead(nsIMsgDBHdr *msgHdr, PRBool bRead,
|
||||
nsIDBChangeListener *instigator = NULL);
|
||||
#if 0
|
||||
NS_IMETHOD IsRead(nsMsgKey key, PRBool *pRead);
|
||||
#endif
|
||||
|
||||
virtual PRBool IsArticleOffline(nsMsgKey key);
|
||||
NS_IMETHOD MarkAllRead(nsMsgKeyArray *thoseMarked = NULL);
|
||||
|
|
|
@ -1088,6 +1088,7 @@ nsresult nsMsgDatabase::HasAttachments(nsMsgKey key, PRBool *pHasThem)
|
|||
NS_IMETHODIMP nsMsgDatabase::MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, PRBool bRead,
|
||||
nsIDBChangeListener *instigator)
|
||||
{
|
||||
nsresult rv;
|
||||
nsMsgKey key;
|
||||
PRUint32 oldFlags;
|
||||
(void)msgHdr->GetMessageKey(&key);
|
||||
|
@ -1106,7 +1107,9 @@ NS_IMETHODIMP nsMsgDatabase::MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, PRBool bRead,
|
|||
}
|
||||
|
||||
PRUint32 flags;
|
||||
(void)msgHdr->GetFlags(&flags);
|
||||
rv = msgHdr->GetFlags(&flags);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NotifyKeyChangeAll(key, oldFlags, flags, instigator);
|
||||
}
|
||||
|
||||
|
@ -1390,26 +1393,49 @@ NS_IMETHODIMP nsMsgDatabase::MarkLater(nsMsgKey key, time_t *until)
|
|||
|
||||
NS_IMETHODIMP nsMsgDatabase::GetMsgKeySet(nsMsgKeySet **pSet)
|
||||
{
|
||||
// if it doesn't exist, try to create it
|
||||
if (!m_newSet) {
|
||||
m_newSet = nsMsgKeySet::Create();
|
||||
if (m_newSet == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (!pSet) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ASSERTION(m_newSet,"set doesn't exist yet!");
|
||||
if (!m_newSet) return NS_ERROR_FAILURE;
|
||||
|
||||
*pSet = m_newSet;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDatabase::SetMsgKeySet(char * setStr)
|
||||
{
|
||||
NS_ASSERTION(!m_newSet, "set already exists!");
|
||||
if (m_newSet) {
|
||||
delete m_newSet;
|
||||
m_newSet = nsnull;
|
||||
}
|
||||
|
||||
m_newSet = nsMsgKeySet::Create(setStr /* , this */);
|
||||
if (!m_newSet) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
#ifdef DEBUG_seth
|
||||
char *str = nsnull;
|
||||
str = m_newSet->Output();
|
||||
if (str) {
|
||||
printf("in str = %s\nout str = %s\n", setStr,str);
|
||||
delete [] str;
|
||||
str = nsnull;
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDatabase::AddToNewList(nsMsgKey key)
|
||||
{
|
||||
if (!m_newSet)
|
||||
m_newSet = nsMsgKeySet::Create();
|
||||
nsresult rv;
|
||||
|
||||
if (m_newSet)
|
||||
m_newSet->Add(key);
|
||||
return (m_newSet) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ASSERTION(m_newSet,"set doesn't exist yet!");
|
||||
if (!m_newSet) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = m_newSet->Add(key);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1440,6 +1466,9 @@ NS_IMETHODIMP nsMsgDatabase::ClearNewList(PRBool notify /* = FALSE */)
|
|||
delete m_newSet;
|
||||
m_newSet = NULL;
|
||||
}
|
||||
else {
|
||||
NS_ASSERTION(0, "no set!\n");
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -1452,7 +1481,7 @@ NS_IMETHODIMP nsMsgDatabase::GetFirstNew(nsMsgKey *result)
|
|||
{
|
||||
// even though getLength is supposedly for debugging only, it's the only
|
||||
// way I can tell if the set is empty (as opposed to having a member 0.
|
||||
if (HasNew() == NS_OK)
|
||||
if (NS_SUCCEEDED(HasNew()))
|
||||
*result = m_newSet->GetFirstMember();
|
||||
else
|
||||
*result = nsMsgKey_None;
|
||||
|
|
|
@ -107,6 +107,15 @@ NS_IMETHODIMP nsNewsDatabase::Open(nsIFileSpec *aNewsgroupName, PRBool create, n
|
|||
|
||||
nsresult nsNewsDatabase::Close(PRBool forceCommit)
|
||||
{
|
||||
#ifdef DEBUG_seth
|
||||
if (m_newSet) {
|
||||
char *str = nsnull;
|
||||
str = m_newSet->Output();
|
||||
printf("setStr is %s\n", str);
|
||||
delete [] str;
|
||||
str = nsnull;
|
||||
}
|
||||
#endif
|
||||
return nsMsgDatabase::Close(forceCommit);
|
||||
}
|
||||
|
||||
|
@ -134,19 +143,19 @@ NS_IMETHODIMP nsNewsDatabase::MarkHdrRead(nsIMsgDBHdr *msgHdr, PRBool bRead,
|
|||
nsMsgKey messageKey;
|
||||
rv = msgHdr->GetMessageKey(&messageKey);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
return rv;
|
||||
}
|
||||
#if 0
|
||||
#if 1
|
||||
if (!bRead)
|
||||
rv = AddToNewList(messageKey);
|
||||
rv = AddToNewList(messageKey);
|
||||
else
|
||||
rv = m_newSet->Remove(messageKey);
|
||||
rv = m_newSet->Remove(messageKey);
|
||||
#endif
|
||||
// give parent class chance to update data structures
|
||||
rv = nsMsgDatabase::MarkHdrRead(msgHdr, bRead, instigator);
|
||||
|
||||
// sspitzer:
|
||||
// yes, it is expensive to commit every time here.
|
||||
// yes, it is expensive to commit every time here.
|
||||
//
|
||||
// if we crash (the horror!) before we commit, the user will
|
||||
// lose all there mark as read changes.
|
||||
|
@ -154,23 +163,25 @@ NS_IMETHODIMP nsNewsDatabase::MarkHdrRead(nsIMsgDBHdr *msgHdr, PRBool bRead,
|
|||
// since committing every time is expensive if we mark a
|
||||
// whole bunch of headers as read, we should commit after we are
|
||||
// done marking.
|
||||
Commit(kSessionCommit);
|
||||
Commit(kSessionCommit);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP nsNewsDatabase::IsRead(nsMsgKey key, PRBool *pRead)
|
||||
{
|
||||
NS_ASSERTION(pRead != NULL, "null out param in IsRead");
|
||||
if (pRead == NULL)
|
||||
NS_ASSERTION(pRead, "null out param in IsRead");
|
||||
if (!pRead)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ASSERTION(m_newSet, "set is null!");
|
||||
if (!m_newSet) return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool isRead = m_newSet->IsMember(key);
|
||||
*pRead = isRead;
|
||||
return 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
PRBool nsNewsDatabase::IsArticleOffline(nsMsgKey key)
|
||||
{
|
||||
|
|
|
@ -394,7 +394,7 @@ nsNNTPNewsgroupList::GetRangeOfArtsToDownload(
|
|||
}
|
||||
}
|
||||
#ifdef DEBUG_NEWS
|
||||
printf("GetRangeOfArtsToDownload(first possible = %ld, last possible = %ld, first = %ld, last = %ld maxextra = %ld\n",first_possible, last_possible, *first, *last, maxextra);
|
||||
printf("GetRangeOfArtsToDownload(first possible = %d, last possible = %d, first = %d, last = %d maxextra = %d\n",first_possible, last_possible, *first, *last, maxextra);
|
||||
#endif
|
||||
m_firstMsgToDownload = *first;
|
||||
m_lastMsgToDownload = *last;
|
||||
|
@ -565,7 +565,7 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number)
|
|||
|
||||
GET_TOKEN ();
|
||||
#ifdef DEBUG_NEWS /* message number */
|
||||
printf("message number = %d\n", atol(line));
|
||||
printf("message number = %ld\n", atol(line));
|
||||
#endif
|
||||
*message_number = atol(line);
|
||||
|
||||
|
@ -624,7 +624,7 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number)
|
|||
// no reason to store milliseconds, since they aren't specified
|
||||
if (PR_SUCCESS == status) {
|
||||
#ifdef DEBUG_NEWS
|
||||
printf("date = %s, %d\n", line, resDate);
|
||||
printf("date = %s, %ld\n", line, resDate);
|
||||
#endif
|
||||
newMsgHdr->SetDate(resDate); /* date */
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
|||
|
||||
nsMsgNewsFolder::nsMsgNewsFolder(void) : nsMsgLineBuffer(nsnull, PR_FALSE),
|
||||
mPath(nsnull), mExpungedBytes(0), mGettingNews(PR_FALSE),
|
||||
mInitialized(PR_FALSE), mOptionLines(nsnull), mHostname(nsnull), mSet(nsnull)
|
||||
mInitialized(PR_FALSE), mOptionLines(nsnull), mHostname(nsnull)
|
||||
{
|
||||
// NS_INIT_REFCNT(); done by superclass
|
||||
}
|
||||
|
@ -85,11 +85,6 @@ nsMsgNewsFolder::~nsMsgNewsFolder(void)
|
|||
mHostname = nsnull;
|
||||
}
|
||||
|
||||
if (mSet) {
|
||||
delete mSet;
|
||||
mSet = nsnull;
|
||||
}
|
||||
|
||||
PR_FREEIF(mOptionLines);
|
||||
mOptionLines = nsnull;
|
||||
}
|
||||
|
@ -522,8 +517,10 @@ nsresult nsMsgNewsFolder::GetDatabase()
|
|||
#endif
|
||||
}
|
||||
|
||||
if(mDatabase) {
|
||||
mDatabase->AddListener(this);
|
||||
if (mDatabase) {
|
||||
rv = mDatabase->AddListener(this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
UpdateSummaryTotals();
|
||||
}
|
||||
}
|
||||
|
@ -1400,12 +1397,19 @@ nsresult nsMsgNewsFolder::ForgetLine()
|
|||
// caller needs to use delete [] to free
|
||||
NS_IMETHODIMP nsMsgNewsFolder::GetMsgKeySetStr(char * *aMsgKeySetStr)
|
||||
{
|
||||
if (!aMsgKeySetStr) return NS_ERROR_NULL_POINTER;
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(mSet, "mSet is null");
|
||||
if (!mSet) return NS_ERROR_FAILURE;
|
||||
if (!aMsgKeySetStr) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aMsgKeySetStr = mSet->Output();
|
||||
NS_ASSERTION(mDatabase, "no database!");
|
||||
if (!mDatabase) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsMsgKeySet * set = nsnull;
|
||||
|
||||
rv = mDatabase->GetMsgKeySet(&set);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aMsgKeySetStr = set->Output();
|
||||
|
||||
if (!*aMsgKeySetStr) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -1414,25 +1418,16 @@ NS_IMETHODIMP nsMsgNewsFolder::GetMsgKeySetStr(char * *aMsgKeySetStr)
|
|||
|
||||
NS_IMETHODIMP nsMsgNewsFolder::SetMsgKeySetStr(char * aMsgKeySetStr)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (!aMsgKeySetStr) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ASSERTION(!mSet, "mSet is not null");
|
||||
if (mSet) {
|
||||
delete mSet;
|
||||
mSet = nsnull;
|
||||
}
|
||||
rv = GetDatabase();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mSet = nsMsgKeySet::Create(aMsgKeySetStr /* , this */);
|
||||
if (!mSet) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
#ifdef DEBUG_NEWS
|
||||
char *setStr = nsnull;
|
||||
setStr = mSet->Output();
|
||||
if (setStr) {
|
||||
printf("here's the setStr = %s\n", setStr);
|
||||
delete [] setStr;
|
||||
}
|
||||
#endif
|
||||
NS_ASSERTION(mDatabase, "no database!");
|
||||
if (!mDatabase) return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
rv = mDatabase->SetMsgKeySet(aMsgKeySetStr);
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -132,9 +132,6 @@ protected:
|
|||
nsISupportsArray *mMessages;
|
||||
char *mOptionLines;
|
||||
char *mHostname;
|
||||
|
||||
private:
|
||||
nsMsgKeySet *mSet;
|
||||
};
|
||||
|
||||
#endif // nsMsgNewsFolder_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче