changes required to do newsposting.

This commit is contained in:
sspitzer%netscape.com 1999-05-18 00:36:49 +00:00
Родитель 4e4b29a2bb
Коммит af49070b99
9 изменённых файлов: 183 добавлений и 75 удалений

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

@ -111,6 +111,10 @@ class nsINNTPNewsgroupPost : public nsISupports {
/* string GetFullMessage (); */
NS_IMETHOD GetFullMessage(char **_retval) = 0;
/* attribute nsFilePath aFileName */
NS_IMETHOD SetPostMessageFile(const nsFilePath& aFileName) = 0;
NS_IMETHOD GetPostMessageFile(const nsFilePath ** aFileName) = 0;
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsINNTPNewsgroupPost *priv);

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

@ -60,6 +60,9 @@ interface nsINNTPNewsgroupPost : nsISupports {
/* the message itself */
attribute string body;
/* the path to the message */
/* attribute nsFilePath postMessageFile; */
/* control messages */
void MakeControlCancel(in string messageID);
/* probably don't need these

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

@ -74,11 +74,6 @@ public:
NS_IMETHOD SetMessageToPost (nsINNTPNewsgroupPost *post) = 0;
NS_IMETHOD GetMessageToPost (nsINNTPNewsgroupPost **post) = 0;
// the message can be stored in a file....allow accessors for getting and setting
// the file name to post...
NS_IMETHOD SetPostMessageFile(const nsFilePath& aFileName) = 0;
NS_IMETHOD GetPostMessageFile(const nsFilePath ** aFileName) = 0;
};
#endif /* nsIHttpURL_h___ */

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

@ -102,11 +102,16 @@ public:
NS_IMETHOD GetFullMessage(char **message);
// the message can be stored in a file....allow accessors for getting and setting
// the file name to post...
NS_IMETHOD SetPostMessageFile(const nsFilePath& aFileName);
NS_IMETHOD GetPostMessageFile(const nsFilePath ** aFileName);
// helper routines
static char *appendAndAlloc(char *string, const char *newSubstring,
PRBool withComma);
private:
nsFilePath m_fileName;
char *m_header[HEADER_LAST+1];
static const char *m_headerName[HEADER_LAST+1];
@ -141,7 +146,8 @@ const char* nsNNTPNewsgroupPost::m_headerName[HEADER_LAST+1]=
NS_IMPL_ISUPPORTS(nsNNTPNewsgroupPost, nsINNTPNewsgroupPost::GetIID());
nsNNTPNewsgroupPost::nsNNTPNewsgroupPost()
nsNNTPNewsgroupPost::nsNNTPNewsgroupPost():
m_fileName("")
{
NS_INIT_REFCNT();
@ -299,6 +305,31 @@ nsNNTPNewsgroupPost::GetMessageID(char **messageID)
}
// the message can be stored in a file....allow accessors for getting and setting
// the file name to post...
nsresult
nsNNTPNewsgroupPost::SetPostMessageFile(const nsFilePath& aFileName)
{
#ifdef DEBUG_sspitzer
printf("SetPostMessageFile(%s)\n",(const char *)aFileName);
#endif
nsresult rv = NS_OK;
if (aFileName)
m_fileName = aFileName;
return rv;
}
nsresult
nsNNTPNewsgroupPost::GetPostMessageFile(const nsFilePath ** aFileName)
{
nsresult rv = NS_OK;
if (aFileName)
*aFileName = &m_fileName;
return rv;
}
NS_BEGIN_EXTERN_C
nsresult NS_NewNewsgroupPost(nsINNTPNewsgroupPost **aPost)

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

@ -24,6 +24,7 @@
#include "nsNNTPProtocol.h"
#include "nsIOutputStream.h"
#include "nsIInputStream.h"
#include "nsFileStream.h"
#include "nsCOMPtr.h"
@ -3089,6 +3090,124 @@ PRInt32 nsNNTPProtocol::ReadNewsgroupBody(nsIInputStream * inputStream, PRUint32
return !NS_SUCCEEDED(rv);
}
// sspitzer: PostMessageInFile is copied from nsSmtpProtocol::SendMessageInFile()
//
// mscott: after dogfood, make a note to move this type of function into a base
// utility class....
#define POST_DATA_BUFFER_SIZE 2048
PRInt32 nsNNTPProtocol::PostMessageInFile(const nsFilePath &filePath)
{
if (filePath && *filePath)
{
#ifdef DEBUG_sspitzer
printf("post this file: %s\n",(const char *)nsFileSpec(filePath));
#endif /* DEBUG_sspitzer */
nsInputFileStream * fileStream = new nsInputFileStream(nsFileSpec(filePath), PR_RDONLY, 00700);
if (fileStream)
{
PRInt32 amtInBuffer = 0;
PRBool lastLineWasComplete = PR_TRUE;
PRBool quoteLines = PR_TRUE; // it is always true but I'd like to generalize this function and then it might not be
char buffer[POST_DATA_BUFFER_SIZE];
if (quoteLines /* || add_crlf_to_line_endings */)
{
char *line;
char * b = buffer;
PRInt32 bsize = POST_DATA_BUFFER_SIZE;
amtInBuffer = 0;
do {
PRInt32 L = 0;
if (fileStream->eof())
{
line = nsnull;
break;
}
if (!fileStream->readline(b, bsize-5)) // if the readline returns false, jump out...
{
line = nsnull;
break;
}
else
line = b;
L = PL_strlen(line);
/* escape periods only if quote_lines_p is set
*/
if (quoteLines && lastLineWasComplete && line[0] == '.')
{
/* This line begins with "." so we need to quote it
by adding another "." to the beginning of the line.
*/
PRInt32 i;
line[L+1] = 0;
for (i = L; i > 0; i--)
line[i] = line[i-1];
L++;
}
/* set default */
lastLineWasComplete = PR_TRUE;
if (L > 1 && line[L-2] == CR && line[L-1] == LF)
{
/* already ok */
}
else if(L > 0 /* && (line[L-1] == LF || line[L-1] == CR) */)
{
/* only add the crlf if required
* we still need to do all the
* if comparisons here to know
* if the line was complete
*/
if(/* add_crlf_to_line_endings */ PR_TRUE)
{
/* Change newline to CRLF. */
// L--;
line[L++] = CR;
line[L++] = LF;
line[L] = 0;
}
}
else
{
line[L++] = CR;
line[L++] = LF;
line[L] = 0;
lastLineWasComplete = PR_FALSE;
}
bsize -= L;
b += L;
amtInBuffer += L;
} while (line && bsize > 100);
}
SendData(buffer);
}
} // if filePath
SetFlag(NNTP_PAUSE_FOR_READ);
// for now, we are always done at this point..we aren't making multiple calls
// to post data...
// always issue a '.' and CRLF when we are done...
PL_strcpy(m_dataBuf, CRLF "." CRLF);
SendData(m_dataBuf);
#ifdef UNREADY_CODE
NET_Progress(CE_WINDOW_ID,
XP_GetString(XP_MESSAGE_SENT_WAITING_MAIL_REPLY));
#endif /* UNREADY_CODE */
m_nextState = NNTP_RESPONSE;
m_nextStateAfterResponse = NNTP_SEND_POST_DATA_RESPONSE;
return(0);
}
PRInt32 nsNNTPProtocol::PostData()
{
@ -3100,27 +3219,14 @@ PRInt32 nsNNTPProtocol::PostData()
#endif
nsresult rv = NS_OK;
const nsFilePath * filePath = nsnull;
rv = m_runningURL->GetPostMessageFile(&filePath);
if (NS_SUCCEEDED(rv) && filePath) {
#ifdef DEBUG_sspitzer
printf("post this file: %s\n",(const char *)filePath);
#endif
}
nsCOMPtr <nsINNTPNewsgroupPost> message;
rv = m_runningURL->GetMessageToPost(getter_AddRefs(message));
if (NS_SUCCEEDED(rv)) {
char *fullMessage;
// XXX maybe we should be breaking this up into chunks?
// or maybe we should be passing the nsIOutputStream to
// the message to tell it to "write itself"
// (but SendData does more than just write to the nsIOutputStream)
message->GetFullMessage(&fullMessage);
SendData(fullMessage);
// now terminate the message
SendData("." CRLF);
const nsFilePath *filePath;
rv = message->GetPostMessageFile(&filePath);
if (NS_SUCCEEDED(rv) && (*filePath != "")) {
PostMessageInFile(*filePath);
}
}
#ifdef UNREADY_CODE
@ -3154,10 +3260,10 @@ PRInt32 nsNNTPProtocol::PostData()
/* this should be handled by NET_ClearCallNetlibAllTheTime */
net_call_all_the_time_count--;
if(net_call_all_the_time_count == 0)
#endif
#endif /* 0 */
NET_ClearCallNetlibAllTheTime(ce->window_id,"mknews");
}
#endif
#endif /* XP_WIN */
NET_SetReadSelect(ce->window_id, ce->socket);
ce->con_sock = 0;
@ -3167,13 +3273,8 @@ PRInt32 nsNNTPProtocol::PostData()
}
return(status);
#else
m_nextState = NNTP_RESPONSE;
m_nextStateAfterResponse = NNTP_SEND_POST_DATA_RESPONSE;
#endif /* UNREADY_CODE */
return 0;
#endif
}

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

@ -283,6 +283,8 @@ private:
// initialization function given a new url and transport layer
void Initialize(nsIURL * aURL, nsITransport * transportLayer);
PRInt32 PostMessageInFile(const nsFilePath &filePath);
////////////////////////////////////////////////////////////////////////////////////////
// Communication methods --> Reading and writing protocol
////////////////////////////////////////////////////////////////////////////////////////

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

@ -283,13 +283,6 @@ nsresult nsNntpService::PostMessage(nsFilePath &pathToFile, const char *subject,
if (NS_FAILED(rv)) {
return rv;
}
#ifdef DEBUG_sspitzer
printf("set file to post to %s\n",(const char *)pathToFile);
#endif
rv = nntpUrl->SetPostMessageFile(pathToFile);
if (NS_FAILED(rv)) {
return rv;
}
// okay now create a transport to run the url in...
#ifdef DEBUG_sspitzer
@ -330,8 +323,18 @@ nsresult nsNntpService::PostMessage(nsFilePath &pathToFile, const char *subject,
post->SetSubject((char *)subject);
post->SetFrom((char *)from);
post->SetOrganization((char *)org);
#ifdef DEBUG_sspitzer
printf("set file to post to %s\n",(const char *)pathToFile);
#endif
rv = post->SetPostMessageFile(pathToFile);
if (NS_FAILED(rv)) {
return rv;
}
nntpUrl->SetMessageToPost(post);
rv = nntpUrl->SetMessageToPost(post);
if (NS_FAILED(rv)) {
return rv;
}
}
PR_FREEIF(fullname);

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

@ -42,8 +42,7 @@
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kUrlListenerManagerCID, NS_URLLISTENERMANAGER_CID);
nsNntpUrl::nsNntpUrl(nsISupports* aContainer, nsIURLGroup* aGroup):
m_fileName("")
nsNntpUrl::nsNntpUrl(nsISupports* aContainer, nsIURLGroup* aGroup)
{
NS_INIT_REFCNT();
@ -347,30 +346,6 @@ nsresult nsNntpUrl::GetErrorMessage (char ** errorMessage) const
return NS_OK;
}
// the message can be stored in a file....allow accessors for getting and setting
// the file name to post...
nsresult nsNntpUrl::SetPostMessageFile(const nsFilePath& aFileName)
{
#ifdef DEBUG_sspitzer
printf("SetPostMessageFile(%s)\n",(const char *)aFileName);
#endif
nsresult rv = NS_OK;
if (aFileName)
m_fileName = aFileName;
return rv;
}
nsresult nsNntpUrl::GetPostMessageFile(const nsFilePath ** aFileName)
{
nsresult rv = NS_OK;
if (aFileName)
*aFileName = &m_fileName;
return rv;
}
nsresult
nsNntpUrl::GetFilePath(const nsFileSpec ** aFilePath)
{

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

@ -80,11 +80,6 @@ public:
NS_IMETHOD SetMessageToPost(nsINNTPNewsgroupPost *post);
NS_IMETHOD GetMessageToPost(nsINNTPNewsgroupPost **post);
// the message can be stored in a file....allow accessors for getting and setting
// the file name to post...
NS_IMETHOD SetPostMessageFile(const nsFilePath& aFileName);
NS_IMETHOD GetPostMessageFile(const nsFilePath ** aFileName);
NS_IMETHOD GetFilePath(const nsFileSpec ** aFilePath);
// from nsIMsgMailNewsUrl:
@ -121,7 +116,6 @@ protected:
char *m_ref;
char *m_search;
char *m_errorMessage;
nsFilePath m_fileName;
PRBool m_runningUrl;