Changes for autoregistration as well as the new stream converter

interface.
This commit is contained in:
rhp%netscape.com 1999-03-09 22:37:03 +00:00
Родитель 55a36c9c4b
Коммит 89dc724e32
4 изменённых файлов: 190 добавлений и 72 удалений

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

@ -55,7 +55,8 @@ EXPORTS = nsRFC822toHTMLStreamConverter.h \
$(NULL) $(NULL)
DEFINES= -DEBUG_rhp -DHAVE_MIME_DATA_SLOT -D_IMPL_NS_HTML #DEFINES= -DEBUG_rhp -DHAVE_MIME_DATA_SLOT -D_IMPL_NS_HTML
DEFINES= -DEBUG_rhp -D_IMPL_NS_HTML
#//------------------------------------------------------------------------ #//------------------------------------------------------------------------
#// #//
@ -74,6 +75,7 @@ OBJS= \
# Code for stream converter interface to netlib... # Code for stream converter interface to netlib...
# #
.\$(OBJDIR)\plugin_inst.obj \ .\$(OBJDIR)\plugin_inst.obj \
.\$(OBJDIR)\rebuffer.obj \
# MIME parsing code # MIME parsing code
.\$(OBJDIR)\mimecont.obj \ .\$(OBJDIR)\mimecont.obj \
.\$(OBJDIR)\mimeebod.obj \ .\$(OBJDIR)\mimeebod.obj \
@ -101,7 +103,8 @@ OBJS= \
.\$(OBJDIR)\mimetpla.obj \ .\$(OBJDIR)\mimetpla.obj \
.\$(OBJDIR)\mimetric.obj \ .\$(OBJDIR)\mimetric.obj \
.\$(OBJDIR)\mimeunty.obj \ .\$(OBJDIR)\mimeunty.obj \
.\$(OBJDIR)\mimemoz.obj \ # .\$(OBJDIR)\mimemoz.obj \
.\$(OBJDIR)\mimemoz2.obj \
.\$(OBJDIR)\mimecth.obj \ .\$(OBJDIR)\mimecth.obj \
.\$(OBJDIR)\mimebuf.obj \ .\$(OBJDIR)\mimebuf.obj \
.\$(OBJDIR)\mimecom.obj \ .\$(OBJDIR)\mimecom.obj \

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

@ -210,14 +210,6 @@ extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr)
return PRBool(g_InstanceCount == 0 && g_LockCount == 0); return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
} }
//
// rhp - when the new interface is in place...this GOES AWAY!
// External includes necessary for test application
//
#include "net.h"
extern NET_StreamClass *MIME_MessageConverter(int format_out, void *closure,
URL_Struct *url, MWContext *context);
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *path) extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *path)
{ {
nsresult rv; nsresult rv;
@ -234,19 +226,27 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *
#ifdef NS_DEBUG #ifdef NS_DEBUG
printf("*** Mime being registered\n"); printf("*** Mime being registered\n");
#endif #endif
// Content type handler object class access interface
rv = compMgr->RegisterComponent(kCMimeMimeObjectClassAccessCID, NULL, NULL, path, rv = compMgr->RegisterComponent(kCMimeMimeObjectClassAccessCID, NULL, NULL, path,
PR_TRUE, PR_TRUE); PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kCMimeRFC822HTMLConverterCID, NULL, NULL, path,
PR_TRUE, PR_TRUE); // I18N Header Conversion routines
if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kCMimeHeaderConverterCID, NULL, NULL, path, rv = compMgr->RegisterComponent(kCMimeHeaderConverterCID, NULL, NULL, path,
PR_TRUE, PR_TRUE); PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
// The new interface for stream conversion
rv = compMgr->RegisterComponent(kINetPluginMIMECID, NULL, PROGRAM_ID, path, rv = compMgr->RegisterComponent(kINetPluginMIMECID, NULL, PROGRAM_ID, path,
PR_TRUE, PR_TRUE); PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
// The original interface (NOT FUNCTIONAL) for stream conversion
rv = compMgr->RegisterComponent(kCMimeRFC822HTMLConverterCID, NULL, NULL, path,
PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
done: done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr); (void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv; return rv;
@ -270,12 +270,13 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char
#endif #endif
rv = compMgr->UnregisterComponent(kCMimeMimeObjectClassAccessCID, path); rv = compMgr->UnregisterComponent(kCMimeMimeObjectClassAccessCID, path);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kCMimeRFC822HTMLConverterCID, path);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kCMimeHeaderConverterCID, path); rv = compMgr->UnregisterComponent(kCMimeHeaderConverterCID, path);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kINetPluginMIMECID, path); rv = compMgr->UnregisterComponent(kINetPluginMIMECID, path);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
// The original interface (NOT FUNCTIONAL) for stream conversion
rv = compMgr->UnregisterComponent(kCMimeRFC822HTMLConverterCID, path);
done: done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr); (void)servMgr->ReleaseService(kComponentManagerCID, compMgr);

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

@ -17,7 +17,9 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "mimemoz2.h"
#include "plugin_inst.h" #include "plugin_inst.h"
#include "rebuffer.h"
static NS_DEFINE_IID(kINetPluginInstanceIID, NS_INETPLUGININSTANCE_IID); static NS_DEFINE_IID(kINetPluginInstanceIID, NS_INETPLUGININSTANCE_IID);
static NS_DEFINE_IID(kINetOStreamIID, NS_INETOSTREAM_IID); static NS_DEFINE_IID(kINetOStreamIID, NS_INETOSTREAM_IID);
@ -82,8 +84,9 @@ NS_IMPL_RELEASE(MimePluginInstance);
MimePluginInstance::MimePluginInstance(void) MimePluginInstance::MimePluginInstance(void)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
OutStream = NULL; mOutStream = NULL;
first_write = PR_FALSE; mBridgeStream = NULL;
mRebuffer = NULL;
} }
MimePluginInstance::~MimePluginInstance(void) MimePluginInstance::~MimePluginInstance(void)
@ -91,20 +94,34 @@ MimePluginInstance::~MimePluginInstance(void)
} }
NS_METHOD NS_METHOD
MimePluginInstance::Initialize(nsINetOStream* stream, const char * aStreamName) MimePluginInstance::Initialize(nsINetOStream* stream, const char *stream_name)
{ {
OutStream = stream; mOutStream = stream;
return NS_OK; mTotalWritten = 0;
mTotalRead = 0;
mBridgeStream = mime_bridge_create_stream(this, stream_name, FO_NGLAYOUT);
if (!mBridgeStream)
return NS_ERROR_OUT_OF_MEMORY;
// Create rebuffering object
mRebuffer = new MimeRebuffer();
return NS_OK;
}
NS_METHOD
MimePluginInstance::Destroy(void)
{
return NS_OK;
} }
NS_METHOD NS_METHOD
MimePluginInstance::GetMIMEOutput(const char* *result) MimePluginInstance::GetMIMEOutput(const char* *result)
{ {
*result = "text/html"; *result = "text/html";
return NS_OK; return NS_OK;
} }
NS_METHOD NS_METHOD
MimePluginInstance::Start(void) MimePluginInstance::Start(void)
{ {
@ -117,74 +134,165 @@ MimePluginInstance::Stop(void)
return NS_OK; return NS_OK;
} }
NS_METHOD nsresult MimePluginInstance::Close(void)
MimePluginInstance::Destroy(void)
{ {
return NS_OK; nsINetOStream *stream = mOutStream;
nsresult rc;
if (!stream)
return NS_ERROR_FAILURE;
rc = stream->Close();
return rc;
} }
extern "C" int
sconverter_write_data(void *streamObj, const char *buf, PRUint32 size);
nsresult MimePluginInstance::Complete(void) nsresult MimePluginInstance::Complete(void)
{ {
nsINetOStream *stream = OutStream;
if (stream) nsINetOStream *stream = mOutStream;
{
if (first_write) if (!stream)
{ return NS_ERROR_FAILURE;
unsigned int written;
stream->Write("</pre>", 6, &written); //
} // Now complete the stream!
return stream->Complete(); //
} mime_display_stream_complete(mBridgeStream);
return NS_OK;
// Make sure to do necessary cleanup!
InternalCleanup();
return stream->Complete();
}
nsresult MimePluginInstance::InternalCleanup(void)
{
// If we are here and still have data to write, we should try
// to flush it...if we try and fail, we should probably return
// an error!
if (mRebuffer->GetSize() > 0)
sconverter_write_data(this, "", 0);
printf("TOTAL READ = %d\n", mTotalRead);
printf("TOTAL WRITTEN = %d\n", mTotalWritten);
printf("LEFTOVERS = %d\n", mRebuffer->GetSize());
//
// Now do necessary cleanup!
//
mime_bridge_destroy_stream(mBridgeStream);
if (mRebuffer)
delete mRebuffer;
Close();
return NS_OK;
} }
nsresult MimePluginInstance::Abort(PRInt32 status) nsresult MimePluginInstance::Abort(PRInt32 status)
{ {
nsINetOStream *stream = OutStream; nsINetOStream *stream = mOutStream;
if (stream) if (!stream)
{ return NS_ERROR_FAILURE;
return stream->Abort(status);
} mime_display_stream_abort (mBridgeStream, status);
return NS_OK;
// Make sure to do necessary cleanup!
InternalCleanup();
return stream->Abort(status);
} }
nsresult MimePluginInstance::WriteReady(PRUint32 *aReadyCount) nsresult MimePluginInstance::WriteReady(PRUint32 *aReadyCount)
{ {
nsINetOStream *stream = OutStream; nsINetOStream *stream = mOutStream;
if (stream) if (!stream)
{ return NS_ERROR_FAILURE;
return stream->WriteReady(aReadyCount);
} return stream->WriteReady(aReadyCount);
return NS_OK;
} }
nsresult MimePluginInstance::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) nsresult MimePluginInstance::Write(const char* aBuf, PRUint32 aCount,
PRUint32 *aWriteCount)
{ {
nsINetOStream *stream = OutStream; nsresult rc;
nsINetOStream *stream = mOutStream;
if (stream) if (!stream)
{ return NS_ERROR_FAILURE;
if (!first_write)
{ // SHERRY mTotalWritten = 0;
unsigned int written; mTotalRead += aCount;
stream->Write("<pre>", 5, &written); rc = mime_display_stream_write(mBridgeStream, aBuf, aCount);
first_write = PR_TRUE; // *aWriteCount = mTotalWritten;
} if (mRebuffer->GetSize() > 0)
return stream->Write(aBuf, aCount, aWriteCount); *aWriteCount = 0;
} else
return NS_OK; *aWriteCount = aCount;
return rc;
} }
nsresult MimePluginInstance::Close(void) ////////////////////////////////////////////////////////////////////////////////
// These are routines necessary for the C based routines in libmime
// to access the new world streams.
////////////////////////////////////////////////////////////////////////////////
extern "C" int
sconverter_write_data(void *streamObj, const char *buf, PRUint32 size)
{ {
nsINetOStream *stream = OutStream; unsigned int written = 0;
MimePluginInstance *obj = (MimePluginInstance *)streamObj;
nsINetOStream *newStream;
PRUint32 rc, aReadyCount = 0;
if (stream) if (!obj)
{ return NS_ERROR_FAILURE;
return stream->Close(); newStream = (nsINetOStream *)(obj->mOutStream);
}
return NS_OK; //
// Make sure that the buffer we are "pushing" into has enough room
// for the write operation. If not, we have to buffer, return, and get
// it on the next time through
//
rc = newStream->WriteReady(&aReadyCount);
// First, handle any old buffer data...
if (obj->mRebuffer->GetSize() > 0)
{
if (aReadyCount >= obj->mRebuffer->GetSize())
{
rc += newStream->Write(obj->mRebuffer->GetBuffer(),
obj->mRebuffer->GetSize(), &written);
obj->mTotalWritten += written;
obj->mRebuffer->ReduceBuffer(written);
}
else
{
rc += newStream->Write(obj->mRebuffer->GetBuffer(),
aReadyCount, &written);
obj->mTotalWritten += written;
obj->mRebuffer->ReduceBuffer(written);
obj->mRebuffer->IncreaseBuffer(buf, size);
return rc;
}
}
// Now, deal with the new data the best way possible...
rc = newStream->WriteReady(&aReadyCount);
if (aReadyCount >= size)
{
rc += newStream->Write(buf, size, &written);
obj->mTotalWritten += written;
return rc;
}
else
{
rc += newStream->Write(buf, aReadyCount, &written);
obj->mTotalWritten += written;
obj->mRebuffer->IncreaseBuffer(buf+written, (size-written));
return rc;
}
} }

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

@ -18,6 +18,7 @@
#ifndef plugin_inst_h_ #ifndef plugin_inst_h_
#define plugin_inst_h_ #define plugin_inst_h_
#include "rebuffer.h"
#include "nsINetOStream.h" #include "nsINetOStream.h"
#include "nsINetPluginInstance.h" #include "nsINetPluginInstance.h"
@ -39,7 +40,7 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// from nsINetPluginInstance // from nsINetPluginInstance
NS_IMETHOD Initialize(nsINetOStream* out_stream, const char * streamName); NS_IMETHOD Initialize(nsINetOStream* out_stream, const char *stream_name);
NS_IMETHOD GetMIMEOutput(const char* *result); NS_IMETHOD GetMIMEOutput(const char* *result);
NS_IMETHOD Start(void); NS_IMETHOD Start(void);
NS_IMETHOD Stop(void); NS_IMETHOD Stop(void);
@ -60,9 +61,14 @@ public:
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// MimePluginInstance specific methods: // MimePluginInstance specific methods:
protected: ////////////////////////////////////////////////////////////////////////////
nsINetOStream *OutStream; NS_IMETHOD InternalCleanup(void);
PRBool first_write;
nsINetOStream *mOutStream;
void *mBridgeStream;
PRUint32 mTotalWritten;
PRUint32 mTotalRead;
MimeRebuffer *mRebuffer;
}; };
/* this function will be used by the factory to generate an class access object....*/ /* this function will be used by the factory to generate an class access object....*/