use PR_smprintf, not sprintf().

for news, we aren't going to have .sdb for directories.
put the summary files in <newsdir>/host-<hostname>
This commit is contained in:
sspitzer%netscape.com 1999-04-28 05:00:02 +00:00
Родитель 59f677783b
Коммит 463c8d96c9
3 изменённых файлов: 59 добавлений и 45 удалений

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

@ -176,9 +176,9 @@ nsMsgNewsFolder::isNewsHost()
#define NEWSRC_MAP_FILE_COOKIE "netscape-newsrc-map-file" #define NEWSRC_MAP_FILE_COOKIE "netscape-newsrc-map-file"
nsresult nsresult
nsMsgNewsFolder::MapHostToNewsrcFile(nsFileSpec &fatFile, char *newshostname, nsFileSpec &newsrcFile) nsMsgNewsFolder::MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, nsFileSpec &newsrcFile)
{ {
char lookingFor[512]; char *lookingFor = nsnull;
char buffer[512]; char buffer[512];
char psuedo_name[512]; char psuedo_name[512];
char filename[512]; char filename[512];
@ -186,15 +186,19 @@ nsMsgNewsFolder::MapHostToNewsrcFile(nsFileSpec &fatFile, char *newshostname, ns
PRBool rv; PRBool rv;
#ifdef DEBUG_sspitzer #ifdef DEBUG_sspitzer
printf("MapHostToNewsrcFile(%s,%s,??)\n",(const char *)fatFile, newshostname); printf("MapHostToNewsrcFile(%s,%s,%s,??)\n",newshostname,(const char *)fatFile, newshostname);
#endif #endif
sprintf(lookingFor,"newsrc-%s",newshostname); lookingFor = PR_smprintf("newsrc-%s",newshostname);
if (lookingFor == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsInputFileStream inputStream(fatFile); nsInputFileStream inputStream(fatFile);
if (inputStream.eof()) { if (inputStream.eof()) {
newsrcFile = ""; newsrcFile = "";
inputStream.close(); inputStream.close();
PR_FREEIF(lookingFor);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -206,6 +210,7 @@ nsMsgNewsFolder::MapHostToNewsrcFile(nsFileSpec &fatFile, char *newshostname, ns
if ((!rv) || (PL_strncmp(buffer, NEWSRC_MAP_FILE_COOKIE, PL_strlen(NEWSRC_MAP_FILE_COOKIE)))) { if ((!rv) || (PL_strncmp(buffer, NEWSRC_MAP_FILE_COOKIE, PL_strlen(NEWSRC_MAP_FILE_COOKIE)))) {
newsrcFile = ""; newsrcFile = "";
inputStream.close(); inputStream.close();
PR_FREEIF(lookingFor);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -217,6 +222,7 @@ nsMsgNewsFolder::MapHostToNewsrcFile(nsFileSpec &fatFile, char *newshostname, ns
if (!rv) { if (!rv) {
newsrcFile = ""; newsrcFile = "";
inputStream.close(); inputStream.close();
PR_FREEIF(lookingFor);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -266,6 +272,7 @@ nsMsgNewsFolder::MapHostToNewsrcFile(nsFileSpec &fatFile, char *newshostname, ns
#endif #endif
newsrcFile = filename; newsrcFile = filename;
inputStream.close(); inputStream.close();
PR_FREEIF(lookingFor);
return NS_OK; return NS_OK;
} }
} }
@ -273,15 +280,19 @@ nsMsgNewsFolder::MapHostToNewsrcFile(nsFileSpec &fatFile, char *newshostname, ns
// failed to find a match in the map file // failed to find a match in the map file
newsrcFile = ""; newsrcFile = "";
inputStream.close(); inputStream.close();
PR_FREEIF(lookingFor);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
#endif /* USE_NEWSRC_MAP_FILE */ #endif /* USE_NEWSRC_MAP_FILE */
nsresult nsresult
nsMsgNewsFolder::GetNewsrcFile(nsFileSpec &path, nsFileSpec &newsrcFile) nsMsgNewsFolder::GetNewsrcFile(char *newshostname, nsFileSpec &path, nsFileSpec &newsrcFile)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
char *newshostname = path.GetLeafName();
if (newshostname == nsnull) {
return NS_ERROR_NULL_POINTER;
}
#ifdef USE_NEWSRC_MAP_FILE #ifdef USE_NEWSRC_MAP_FILE
// the fat file lives in the same directory as // the fat file lives in the same directory as
@ -289,24 +300,21 @@ nsMsgNewsFolder::GetNewsrcFile(nsFileSpec &path, nsFileSpec &newsrcFile)
nsFileSpec fatFile(path); nsFileSpec fatFile(path);
fatFile.SetLeafName("fat"); fatFile.SetLeafName("fat");
rv = MapHostToNewsrcFile(fatFile, newshostname, newsrcFile); rv = MapHostToNewsrcFile(newshostname, fatFile, newsrcFile);
#else #else
char str[1024]; char *str = nsnull;
if ((newshostname == nsnull) || (PL_strlen(newshostname) == 0)) { str = PR_smprintf(".newsrc-%s", newshostname);
newsrcFile = ""; if (str == nsnull) {
rv = NS_ERROR_NULL_POINTER; return NS_ERROR_OUT_OF_MEMORY;
} }
else {
sprintf(str, ".newsrc-%s", newshostname);
newsrcFile = path; newsrcFile = path;
newsrcFile.SetLeafName(str); newsrcFile.SetLeafName(str);
PR_FREEIF(str);
str = nsnull;
rv = NS_OK; rv = NS_OK;
}
#endif /* USE_NEWSRC_MAP_FILE */ #endif /* USE_NEWSRC_MAP_FILE */
if (newshostname) {
delete [] newshostname;
}
return rv; return rv;
} }
@ -316,18 +324,31 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (isNewsHost()) { if (isNewsHost()) {
char *newshostname = nsnull;
// since we know it is a host, mURI is of the form
// news://foobar
// all we want is foobar
// so skip over news:// (a.k.a. kNewsRootURI)
newshostname = PR_smprintf("%s", mURI + PL_strlen(kNewsRootURI) + 1);
if (newshostname == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
#ifdef DEBUG_sspitzer #ifdef DEBUG_sspitzer
printf("CreateSubFolders: %s = %s\n", mURI, (const char *)path); printf("CreateSubFolders: %s = %s\n", mURI, (const char *)path);
#endif #endif
nsFileSpec newsrcFile(""); nsFileSpec newsrcFile("");
rv = GetNewsrcFile(path, newsrcFile); rv = GetNewsrcFile(newshostname, path, newsrcFile);
if (rv == NS_OK) { if (rv == NS_OK) {
#ifdef DEBUG_sspitzer #ifdef DEBUG_sspitzer
printf("newsrc file = %s\n", (const char *)newsrcFile); printf("newsrc file = %s\n", (const char *)newsrcFile);
#endif #endif
rv = LoadNewsrcFileAndCreateNewsgroups(newsrcFile); rv = LoadNewsrcFileAndCreateNewsgroups(newsrcFile);
} }
PR_FREEIF(newshostname);
newshostname = nsnull;
} }
else { else {
#ifdef DEBUG_sspitzer #ifdef DEBUG_sspitzer

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

@ -129,9 +129,9 @@ protected:
PRInt32 ProcessLine(char *line, PRUint32 line_size); PRInt32 ProcessLine(char *line, PRUint32 line_size);
PRInt32 RememberLine(char *line); PRInt32 RememberLine(char *line);
static PRInt32 ProcessLine_s(char *line, PRUint32 line_size, void *closure); static PRInt32 ProcessLine_s(char *line, PRUint32 line_size, void *closure);
nsresult GetNewsrcFile(nsFileSpec &path, nsFileSpec &newsrcFile); nsresult GetNewsrcFile(char *newshostname, nsFileSpec &path, nsFileSpec &newsrcFile);
#ifdef USE_NEWSRC_MAP_FILE #ifdef USE_NEWSRC_MAP_FILE
nsresult MapHostToNewsrcFile(nsFileSpec &fatFile, char *newshostname, nsFileSpec &newsrcFile); nsresult MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, nsFileSpec &newsrcFile);
#endif #endif
protected: protected:

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

@ -59,21 +59,14 @@ nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult)
{ {
nsresult rv; nsresult rv;
nsAutoString sep = PR_GetDirectorySeparator();
nsAutoString sep;
sep += PR_GetDirectorySeparator();
nsAutoString sbdSep;
/* sspitzer: is this ok for mail and news? */
rv = nsGetMailFolderSeparator(sbdSep);
if (NS_FAILED(rv)) return rv;
nsAutoString uri = uriStr; nsAutoString uri = uriStr;
if (uri.Find(rootURI) != 0) // if doesn't start with rootURI if (uri.Find(rootURI) != 0) // if doesn't start with rootURI
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
if ((strcmp(rootURI, kNewsRootURI) == 0) || if ((PL_strcmp(rootURI, kNewsRootURI) == 0) ||
(strcmp(rootURI, kNewsMessageRootURI) == 0)) { (PL_strcmp(rootURI, kNewsMessageRootURI) == 0)) {
rv = nsGetNewsRoot(pathResult); rv = nsGetNewsRoot(pathResult);
} }
else { else {
@ -113,14 +106,14 @@ nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult)
NS_ASSERTION(leftRes == pos, NS_ASSERTION(leftRes == pos,
"something wrong with nsString"); "something wrong with nsString");
//We only want to add this after the first time around. //We only want to add this after the first time around.
if(path.Length() > 0) if(path.Length() > 0) {
{ //We only want to add this after the first time around.
path += sep; path += sep;
path += PR_GetDirectorySeparator();
} }
// the first time around the separator is special because else {
// the root mail folder doesn't end with .sbd // we only want to add this the first time around
sep = sbdSep; path += "host-";
}
path += folderName; path += folderName;
uri.Cut(0, pos); uri.Cut(0, pos);