add support for posting messages

Not complete - the nsINNTPNewsgroupPost is not completely finished (it doesn't assemble the message)
This commit is contained in:
alecf%netscape.com 1999-02-05 07:50:40 +00:00
Родитель 44bb50c9f2
Коммит 20e362a95c
11 изменённых файлов: 80 добавлений и 45 удалений

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

@ -31,6 +31,7 @@ EXPORTS= \
nsINNTPArticleList.h \
nsINNTPCategoryContainer.h \
nsINntpUrl.h \
nsINNTPNewsgroupPost.h \
$(NULL)
include $(topsrcdir)/config/config.mk

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

@ -27,6 +27,7 @@ EXPORTS = \
nsIMsgOfflineNewsState.h \
nsINNTPArticleList.h \
nsINntpUrl.h \
nsINNTPNewsgroupPost.h \
$(NULL)
MODULE=mailnews

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

@ -98,8 +98,8 @@ class nsINNTPNewsgroupPost : public nsISupports {
NS_IMETHOD SetOrganization(char * aOrganization) = 0;
/* <IDL> */
NS_IMETHOD GetMessage(char * *aMessage) = 0;
NS_IMETHOD SetMessage(char * aMessage) = 0;
NS_IMETHOD GetBody(char * *aBody) = 0;
NS_IMETHOD SetBody(char * aBody) = 0;
/* <IDL> */
NS_IMETHOD MakeControlCancel(const char *messageID) = 0;

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

@ -58,7 +58,7 @@ interface nsINNTPNewsgroupPost : nsISupports {
attribute string organization;
/* the message itself */
attribute string message;
attribute string body;
/* control messages */
void MakeControlCancel(in string messageID);

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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
@ -29,6 +29,7 @@
#include "nsINNTPArticleList.h"
#include "nsINNTPHost.h"
#include "nsINNTPNewsgroup.h"
#include "nsINNTPNewsgroupPost.h"
#include "nsIMsgOfflineNewsState.h"
/* BDD12930-A682-11d2-804C-006008128C4E */
@ -67,6 +68,10 @@ public:
NS_IMETHOD SetErrorMessage (char * errorMessage) = 0;
// caller must free using PR_FREE
NS_IMETHOD GetErrorMessage (char ** errorMessage) const = 0;
NS_IMETHOD SetMessageToPost (nsINNTPNewsgroupPost *post) = 0;
NS_IMETHOD GetMessageToPost (nsINNTPNewsgroupPost **post) = 0;
};
#endif /* nsIHttpURL_h___ */
#endif /* nsIHttpURL_h___ */

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

@ -31,6 +31,7 @@ EXPORTS = \
nsNNTPArticleSet.h \
nsNNTPNewsgroupList.h \
nsNNTPNewsgroup.h \
nsNNTPNewsgroupPost.h \
nntpCore.h \
$(NULL)
@ -38,6 +39,7 @@ CPPSRCS = \
nsNNTPArticleList.cpp \
nsNNTPArticleSet.cpp \
nsNNTPNewsgroupList.cpp \
nsNNTPNewsgroupPost.cpp \
nsNNTPProtocol.cpp \
nsNntpUrl.cpp \
nsNNTPHost.cpp \

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

@ -32,6 +32,7 @@ CPPSRCS= nsNNTPProtocol.cpp \
nsNNTPArticleSet.cpp \
nsNNTPArticleList.cpp \
nsNNTPNewsgroupList.cpp \
nsNNTPNewsgroupPost.cpp \
nsNNTPHost.cpp \
$(NULL)
@ -40,6 +41,7 @@ CPP_OBJS= .\$(OBJDIR)\nsNNTPProtocol.obj \
.\$(OBJDIR)\nsNNTPArticleSet.obj \
.\$(OBJDIR)\nsNNTPArticleList.obj \
.\$(OBJDIR)\nsNNTPNewsgroupList.obj \
.\$(OBJDIR)\nsNNTPNewsgroupPost.obj \
.\$(OBJDIR)\nsNNTPHost.obj \
$(NULL)
@ -50,6 +52,7 @@ EXPORTS= nsNNTPProtocol.h \
nsNNTPNewsgroupList.h \
nsNNTPNewsgroup.h \
nntpCore.h \
nsNNTPNewsgroupPost.h \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\mailnews -I$(PUBLIC)\raptor -I$(PUBLIC)\netlib -I$(PUBLIC)\security -I$(PUBLIC)\rdf

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

@ -55,7 +55,6 @@
/* temporary hacks to test if this compiles */
typedef void MSG_GroupName;
class nsNNTPHost;
#ifdef XP_UNIX
static const char LINEBREAK_START = '\012';

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

@ -34,7 +34,11 @@
#include "prerror.h"
#include "nsEscape.h"
#include HG09893
#include "xp_str.h"
#include "fe_proto.h"
#include "prprf.h"
#include "merrors.h"
/* #include HG09893 */
/* include event sink interfaces for news */
@ -370,7 +374,6 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL)
{
PRInt32 status = 0;
PRBool bVal = FALSE;
PRBool default_host = FALSE;
char * hostAndPort = 0;
int32 port = 0;
char *group = 0;
@ -378,6 +381,7 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL)
char *commandSpecificData = 0;
PRBool cancel = FALSE;
char* colon;
nsINNTPNewsgroupPost *message=NULL;
nsresult rv = NS_OK;
@ -405,7 +409,7 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL)
m_runningURL->GetNewsgroup(&m_newsgroup);
m_runningURL->GetOfflineNewsState(&m_offlineNewsState);
}
else
else /* let rv fall through */
NS_ASSERTION(0, "Invalid url type passed into NNTP Protocol Handler");
}
else
@ -457,8 +461,16 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL)
status = -1;
goto FAIL;
}
else if (ce->URL_s->method == URL_POST_METHOD)
else
#endif
/* We are posting a user-written message
if and only if this message has a message to post
Cancel messages are created later with a ?cancel URL
*/
rv = m_runningURL->GetMessageToPost(&message);
if (NS_SUCCEEDED(rv) && message)
{
#ifdef UNREADY_CODE
/* news://HOST done with a POST instead of a GET;
this means a new message is being posted.
Don't allow this unless it's an internal URL.
@ -468,12 +480,12 @@ PRInt32 nsNNTPProtocol::LoadURL(nsIURL * aURL)
status = -1;
goto FAIL;
}
#endif
PR_ASSERT (!group && !message_id && !commandSpecificData);
m_typeWanted = NEWS_POST;
StrAllocCopy(cd->path, "");
StrAllocCopy(m_path, "");
}
else
#endif
if (messageID)
{
/* news:MESSAGE_ID
@ -1087,8 +1099,12 @@ PRInt32 nsNNTPProtocol::SendData(const char * dataBuffer)
NS_PRECONDITION(m_outputStream && m_outputConsumer, "no registered consumer for our output");
if (dataBuffer && m_outputStream)
{
nsresult rv = m_outputStream->Write(dataBuffer, 0 /* offset */, PL_strlen(dataBuffer), &writeCount);
if (NS_SUCCEEDED(rv) && writeCount == PL_strlen(dataBuffer))
nsresult rv;
int len = PL_strlen(dataBuffer);
rv = m_outputStream->Write(dataBuffer, 0 /* offset */,
len, &writeCount);
if (NS_SUCCEEDED(rv) && (writeCount == (PRUint32)len))
{
// notify the consumer that data has arrived
// HACK ALERT: this should really be m_runningURL once we have NNTP url support...
@ -1628,15 +1644,6 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
}
}
/* mscott: we'll extract the post_data from the news URL when we have it */
#ifdef HAVE_NEWS_URL
if(m_typeWanted == NEWS_POST && !ce->URL_s->post_data)
{
PR_ASSERT(0);
return(-1);
}
else
#endif
if(m_typeWanted == NEWS_POST)
{ /* posting to the news group */
StrAllocCopy(command, "POST");
@ -3056,6 +3063,21 @@ PRInt32 nsNNTPProtocol::PostData()
/* returns 0 on done and negative on error
* positive if it needs to continue.
*/
nsresult rv;
nsINNTPNewsgroupPost *message;
rv = m_runningURL->GetMessageToPost(&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);
}
#ifdef UNREADY_CODE
status = NET_WritePostData(ce->window_id, ce->URL_s,
ce->socket,
@ -3341,7 +3363,7 @@ PRInt32 nsNNTPProtocol::Cancel()
{
int status = 0;
char *id, *subject, *newsgroups, *distribution, *other_random_headers, *body;
char *from, *old_from, *news_url;
char *from, *old_from;
int L;
#ifdef USE_LIBMSG
MSG_CompositionFields *fields = NULL;

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

@ -48,11 +48,11 @@ nsNntpUrl::nsNntpUrl(nsISupports* aContainer, nsIURLGroup* aGroup)
m_offlineNews = nsnull;
m_newsgroupList = nsnull;
m_errorMessage = nsnull;
m_newsgroupPost = nsnull;
// nsINetLibUrl specific state
m_URL_s = nsnull;
m_messageToPost = nsnull;
// nsIURL specific state
m_protocol = nsnull;
m_host = nsnull;
@ -75,7 +75,7 @@ nsNntpUrl::~nsNntpUrl()
NS_IF_RELEASE(m_newsgroup);
NS_IF_RELEASE(m_offlineNews);
NS_IF_RELEASE(m_newsgroupList);
PR_FREEIF(m_messageToPost);
PR_FREEIF(m_newsgroupPost);
PR_FREEIF(m_errorMessage);
PR_FREEIF(m_spec);
@ -102,17 +102,17 @@ nsresult nsNntpUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
static NS_DEFINE_IID(kINetlibURLIID, NS_INETLIBURL_IID);
if (aIID.Equals(kINntpURLIID) || aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsINntpUrl*)this);
AddRef();
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIURLIID)) {
*aInstancePtr = (void*) ((nsIURL*)this);
AddRef();
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kINetlibURLIID)) {
*aInstancePtr = (void*) ((nsINetlibURL*)this);
AddRef();
NS_ADDREF_THIS();
return NS_OK;
}
@ -410,7 +410,7 @@ nsresult nsNntpUrl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
// protocol spec. A protocol spec is an alphanumeric string of 1 or
// more characters that is terminated with a colon.
PRBool isAbsolute = PR_FALSE;
char* cp;
char* cp=NULL;
char* ap = cSpec;
char ch;
while (0 != (ch = *ap)) {
@ -871,7 +871,7 @@ nsresult nsNntpUrl::SetPostHeader(const char* name, const char* value)
nsresult nsNntpUrl::SetPostData(nsIInputStream* input)
{
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsNntpUrl::GetURLGroup(nsIURLGroup* *result) const
@ -900,21 +900,22 @@ nsresult nsNntpUrl::ToString(PRUnichar* *aString) const
return NS_OK;
}
nsresult nsNntpUrl::SetMessageToPost(char *aString)
nsresult nsNntpUrl::SetMessageToPost(nsINNTPNewsgroupPost *post)
{
NS_LOCK_INSTANCE();
PR_FREEIF(m_messageToPost);
m_messageToPost = PL_strdup(aString);
NS_IF_RELEASE(m_newsgroupPost);
m_newsgroupPost=post;
if (m_newsgroupPost) NS_ADDREF(m_newsgroupPost);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsNntpUrl::GetMessageToPost(char **aString)
nsresult nsNntpUrl::GetMessageToPost(nsINNTPNewsgroupPost **aPost)
{
NS_LOCK_INSTANCE();
char *result;
if (!aString) return NS_ERROR_NULL_POINTER;
*aString = PL_strdup(m_messageToPost);
if (!aPost) return NS_ERROR_NULL_POINTER;
*aPost = m_newsgroupPost;
if (*aPost) NS_ADDREF(*aPost);
NS_UNLOCK_INSTANCE();
return NS_OK;
}

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

@ -21,6 +21,7 @@
#include "nsINntpUrl.h"
#include "nsINetlibURL.h" /* this should be temporary until Network N2 project lands */
#include "nsINNTPNewsgroupPost.h"
class nsNntpUrl : public nsINntpUrl, public nsINetlibURL
{
@ -81,8 +82,8 @@ public:
// caller must free using PR_FREE
NS_IMETHOD GetErrorMessage (char ** errorMessage) const;
NS_IMETHOD SetMessageToPost(char *messageToPost);
NS_IMETHOD GetMessageToPost(char **messageToPost);
NS_IMETHOD SetMessageToPost(nsINNTPNewsgroupPost *post);
NS_IMETHOD GetMessageToPost(nsINNTPNewsgroupPost **post);
// nsNntpUrl
nsNntpUrl(nsISupports* aContainer, nsIURLGroup* aGroup);
@ -105,9 +106,9 @@ protected:
char *m_ref;
char *m_search;
char *m_errorMessage;
char *m_messageToPost; // temp char buffer of message to post
// (eventually probably a message
// instance of some kind)
nsINNTPNewsgroupPost *m_newsgroupPost;
PRInt32 m_port;
nsISupports* m_container;