зеркало из https://github.com/mozilla/pjs.git
more work on the hostinfo.dat support. now, we can at least read the hostinfo.dat in
if we have on (say, from migration.) if hostinfo.dat is there, we'll use it to populate the subscribe dialog, instead of going to the server. (woo-hoo!) this is for bug #10854, still tons to do.
This commit is contained in:
Родитель
6e54e5dd6b
Коммит
bb477bd5f6
|
@ -40,6 +40,7 @@
|
|||
|
||||
#define NEW_NEWS_DIR_NAME "News"
|
||||
#define PREF_MAIL_NEWSRC_ROOT "mail.newsrc_root"
|
||||
#define HOSTINFO_FILE_NAME "hostinfo.dat"
|
||||
|
||||
// this platform specific junk is so the newsrc filenames we create
|
||||
// will resemble the migrated newsrc filenames.
|
||||
|
@ -51,6 +52,11 @@
|
|||
#define NEWSRC_FILE_SUFFIX ".rc"
|
||||
#endif /* XP_UNIX || XP_BEOS */
|
||||
|
||||
// ###tw This really ought to be the most
|
||||
// efficient file reading size for the current
|
||||
// operating system.
|
||||
#define HOSTINFO_FILE_BUFFER_SIZE 1024
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
|
||||
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
|
@ -67,7 +73,7 @@ NS_INTERFACE_MAP_BEGIN(nsNntpIncomingServer)
|
|||
NS_INTERFACE_MAP_ENTRY(nsISubscribableServer)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsMsgIncomingServer)
|
||||
|
||||
nsNntpIncomingServer::nsNntpIncomingServer()
|
||||
nsNntpIncomingServer::nsNntpIncomingServer() : nsMsgLineBuffer(nsnull, PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
|
@ -675,6 +681,46 @@ nsNntpIncomingServer::WriteHostInfoFile()
|
|||
nsresult
|
||||
nsNntpIncomingServer::LoadHostInfoFile()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = GetLocalPath(getter_AddRefs(mHostInfoFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!mHostInfoFile) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = mHostInfoFile->AppendRelativeUnixPath(HOSTINFO_FILE_NAME);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool exists;
|
||||
rv = mHostInfoFile->Exists(&exists);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// it is ok if the hostinfo.dat file does not exist.
|
||||
if (!exists) return NS_OK;
|
||||
|
||||
nsInputFileStream hostinfoStream(mHostInfoFile);
|
||||
|
||||
PRInt32 numread = 0;
|
||||
|
||||
if (NS_FAILED(mHostInfoInputStream.GrowBuffer(HOSTINFO_FILE_BUFFER_SIZE))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mHasSeenBeginGroups = PR_FALSE;
|
||||
|
||||
while (1) {
|
||||
numread = hostinfoStream.read(mHostInfoInputStream.GetBuffer(), HOSTINFO_FILE_BUFFER_SIZE);
|
||||
if (numread == 0) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
rv = BufferInput(mHostInfoInputStream.GetBuffer(), numread);
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hostinfoStream.close();
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("LoadHostInfoFile()\n");
|
||||
#endif
|
||||
|
@ -682,6 +728,18 @@ nsNntpIncomingServer::LoadHostInfoFile()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
addGroup(nsCString &aElement, void *aData)
|
||||
{
|
||||
nsresult rv;
|
||||
nsNntpIncomingServer *server;
|
||||
server = (nsNntpIncomingServer *)aData;
|
||||
|
||||
rv = server->AddNewsgroupToSubscribeDS((const char *)aElement);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"AddNewsgroupToSubscribeDS failed");
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNntpIncomingServer::PopulateSubscribeDatasourceFromHostInfo(nsIMsgWindow *aMsgWindow)
|
||||
{
|
||||
|
@ -689,14 +747,8 @@ nsNntpIncomingServer::PopulateSubscribeDatasourceFromHostInfo(nsIMsgWindow *aMsg
|
|||
#ifdef DEBUG_sspitzer
|
||||
printf("PopulateSubscribeDatasourceFromHostInfo()\n");
|
||||
#endif
|
||||
rv = AddNewsgroupToSubscribeDS("a.b.d");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AddNewsgroupToSubscribeDS("a.b.e");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AddNewsgroupToSubscribeDS("a.b.f");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AddNewsgroupToSubscribeDS("a.c");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mGroupsOnServer.EnumerateForwards((nsCStringArrayEnumFunc)addGroup, (void *)this);
|
||||
|
||||
rv = StopPopulatingSubscribeDS();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -716,15 +768,11 @@ nsNntpIncomingServer::PopulateSubscribeDatasource(nsIMsgWindow *aMsgWindow)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
if (!nntpService) return NS_ERROR_FAILURE;
|
||||
|
||||
#ifdef DEBUG_sspitzer_
|
||||
if (!mHostInfoLoaded) {
|
||||
// will set mHostInfoLoaded, if we were able to load the hostinfo.dat file
|
||||
rv = LoadHostInfoFile();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
#else
|
||||
mHostInfoLoaded = PR_FALSE;
|
||||
#endif
|
||||
|
||||
if (mHostInfoLoaded) {
|
||||
rv = PopulateSubscribeDatasourceFromHostInfo(aMsgWindow);
|
||||
|
@ -905,3 +953,33 @@ nsNntpIncomingServer::Unsubscribe(const char *aName)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsNntpIncomingServer::HandleLine(char* line, PRUint32 line_size)
|
||||
{
|
||||
NS_ASSERTION(line, "line is null");
|
||||
if (!line) return 0;
|
||||
|
||||
line[line_size] = 0;
|
||||
#ifdef DEBUG_sspitzer_
|
||||
printf("%s",line);
|
||||
#endif
|
||||
|
||||
if (mHasSeenBeginGroups) {
|
||||
char *commaPos = PL_strchr(line,',');
|
||||
if (commaPos) *commaPos = 0;
|
||||
#ifdef DEBUG_sspitzer
|
||||
printf("%s\n",line);
|
||||
#endif
|
||||
nsCString str(line);
|
||||
mGroupsOnServer.AppendCString(str);
|
||||
}
|
||||
else {
|
||||
if (nsCRT::strncmp(line,"begingroups", 11) == 0) {
|
||||
mGroupsOnServer.Clear();
|
||||
mHasSeenBeginGroups = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsIMsgWindow.h"
|
||||
#include "nsISubscribableServer.h"
|
||||
#include "nsMsgLineBuffer.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class nsINntpUrl;
|
||||
class nsIMsgMailNewsUrl;
|
||||
|
@ -44,7 +46,8 @@ class nsIMsgMailNewsUrl;
|
|||
class nsNntpIncomingServer : public nsMsgIncomingServer,
|
||||
public nsINntpIncomingServer,
|
||||
public nsIUrlListener,
|
||||
public nsISubscribableServer
|
||||
public nsISubscribableServer,
|
||||
public nsMsgLineBuffer
|
||||
|
||||
{
|
||||
public:
|
||||
|
@ -60,14 +63,21 @@ public:
|
|||
NS_IMETHOD CloseCachedConnections();
|
||||
NS_IMETHOD PerformBiff();
|
||||
NS_IMETHOD PerformExpand(nsIMsgWindow *aMsgWindow);
|
||||
|
||||
// for nsMsgLineBuffer
|
||||
virtual PRInt32 HandleLine(char *line, PRUint32 line_size);
|
||||
|
||||
protected:
|
||||
nsresult CreateProtocolInstance(nsINNTPProtocol ** aNntpConnection, nsIURI *url,
|
||||
nsresult CreateProtocolInstance(nsINNTPProtocol ** aNntpConnection, nsIURI *url,
|
||||
nsIMsgWindow *window);
|
||||
PRBool ConnectionTimeOut(nsINNTPProtocol* aNntpConnection);
|
||||
nsCOMPtr<nsISupportsArray> m_connectionCache;
|
||||
NS_IMETHOD GetServerRequiresPasswordForBiff(PRBool *_retval);
|
||||
nsByteArray mHostInfoInputStream;
|
||||
|
||||
private:
|
||||
nsCStringArray mGroupsOnServer;
|
||||
PRBool mHasSeenBeginGroups;
|
||||
nsresult WriteHostInfoFile();
|
||||
nsresult LoadHostInfoFile();
|
||||
nsresult PopulateSubscribeDatasourceFromHostInfo(nsIMsgWindow *aMsgWindow);
|
||||
|
@ -77,6 +87,7 @@ private:
|
|||
PRBool mHostInfoLoaded;
|
||||
PRBool mHostInfoHasChanged;
|
||||
nsCOMPtr <nsISubscribableServer> mInner;
|
||||
nsCOMPtr <nsIFileSpec> mHostInfoFile;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче