diff --git a/mailnews/mime/src/makefile.win b/mailnews/mime/src/makefile.win index 5aa070fb407..6e2c9aea5c6 100644 --- a/mailnews/mime/src/makefile.win +++ b/mailnews/mime/src/makefile.win @@ -55,7 +55,8 @@ EXPORTS = nsRFC822toHTMLStreamConverter.h \ $(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... # .\$(OBJDIR)\plugin_inst.obj \ + .\$(OBJDIR)\rebuffer.obj \ # MIME parsing code .\$(OBJDIR)\mimecont.obj \ .\$(OBJDIR)\mimeebod.obj \ @@ -101,7 +103,8 @@ OBJS= \ .\$(OBJDIR)\mimetpla.obj \ .\$(OBJDIR)\mimetric.obj \ .\$(OBJDIR)\mimeunty.obj \ - .\$(OBJDIR)\mimemoz.obj \ +# .\$(OBJDIR)\mimemoz.obj \ + .\$(OBJDIR)\mimemoz2.obj \ .\$(OBJDIR)\mimecth.obj \ .\$(OBJDIR)\mimebuf.obj \ .\$(OBJDIR)\mimecom.obj \ diff --git a/mailnews/mime/src/nsMimeFactory.cpp b/mailnews/mime/src/nsMimeFactory.cpp index 20651c4ec16..e96ee83a838 100644 --- a/mailnews/mime/src/nsMimeFactory.cpp +++ b/mailnews/mime/src/nsMimeFactory.cpp @@ -210,14 +210,6 @@ extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr) 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) { nsresult rv; @@ -234,19 +226,27 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char * #ifdef NS_DEBUG printf("*** Mime being registered\n"); #endif + + // Content type handler object class access interface rv = compMgr->RegisterComponent(kCMimeMimeObjectClassAccessCID, NULL, NULL, path, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) goto done; - rv = compMgr->RegisterComponent(kCMimeRFC822HTMLConverterCID, NULL, NULL, path, - PR_TRUE, PR_TRUE); - if (NS_FAILED(rv)) goto done; + + // I18N Header Conversion routines rv = compMgr->RegisterComponent(kCMimeHeaderConverterCID, NULL, NULL, path, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) goto done; + + // The new interface for stream conversion rv = compMgr->RegisterComponent(kINetPluginMIMECID, NULL, PROGRAM_ID, path, PR_TRUE, PR_TRUE); 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: (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); return rv; @@ -270,12 +270,13 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char #endif rv = compMgr->UnregisterComponent(kCMimeMimeObjectClassAccessCID, path); if (NS_FAILED(rv)) goto done; - rv = compMgr->UnregisterComponent(kCMimeRFC822HTMLConverterCID, path); if (NS_FAILED(rv)) goto done; rv = compMgr->UnregisterComponent(kCMimeHeaderConverterCID, path); if (NS_FAILED(rv)) goto done; rv = compMgr->UnregisterComponent(kINetPluginMIMECID, path); if (NS_FAILED(rv)) goto done; + // The original interface (NOT FUNCTIONAL) for stream conversion + rv = compMgr->UnregisterComponent(kCMimeRFC822HTMLConverterCID, path); done: (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); diff --git a/mailnews/mime/src/plugin_inst.cpp b/mailnews/mime/src/plugin_inst.cpp index 882863fe398..6747a28c596 100644 --- a/mailnews/mime/src/plugin_inst.cpp +++ b/mailnews/mime/src/plugin_inst.cpp @@ -17,7 +17,9 @@ */ #include #include +#include "mimemoz2.h" #include "plugin_inst.h" +#include "rebuffer.h" static NS_DEFINE_IID(kINetPluginInstanceIID, NS_INETPLUGININSTANCE_IID); static NS_DEFINE_IID(kINetOStreamIID, NS_INETOSTREAM_IID); @@ -82,8 +84,9 @@ NS_IMPL_RELEASE(MimePluginInstance); MimePluginInstance::MimePluginInstance(void) { NS_INIT_REFCNT(); - OutStream = NULL; - first_write = PR_FALSE; + mOutStream = NULL; + mBridgeStream = NULL; + mRebuffer = NULL; } MimePluginInstance::~MimePluginInstance(void) @@ -91,20 +94,34 @@ MimePluginInstance::~MimePluginInstance(void) } NS_METHOD -MimePluginInstance::Initialize(nsINetOStream* stream, const char * aStreamName) +MimePluginInstance::Initialize(nsINetOStream* stream, const char *stream_name) { - OutStream = stream; - return NS_OK; + mOutStream = stream; + 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 MimePluginInstance::GetMIMEOutput(const char* *result) { - *result = "text/html"; - return NS_OK; + *result = "text/html"; + return NS_OK; } - NS_METHOD MimePluginInstance::Start(void) { @@ -117,74 +134,165 @@ MimePluginInstance::Stop(void) return NS_OK; } -NS_METHOD -MimePluginInstance::Destroy(void) +nsresult MimePluginInstance::Close(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) { - nsINetOStream *stream = OutStream; - if (stream) - { - if (first_write) - { - unsigned int written; - stream->Write("", 6, &written); - } - return stream->Complete(); - } - return NS_OK; + nsINetOStream *stream = mOutStream; + + if (!stream) + return NS_ERROR_FAILURE; + + // + // Now complete the stream! + // + mime_display_stream_complete(mBridgeStream); + + // 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) { - nsINetOStream *stream = OutStream; + nsINetOStream *stream = mOutStream; - if (stream) - { - return stream->Abort(status); - } - return NS_OK; + if (!stream) + return NS_ERROR_FAILURE; + + mime_display_stream_abort (mBridgeStream, status); + + // Make sure to do necessary cleanup! + InternalCleanup(); + + return stream->Abort(status); } nsresult MimePluginInstance::WriteReady(PRUint32 *aReadyCount) { - nsINetOStream *stream = OutStream; + nsINetOStream *stream = mOutStream; - if (stream) - { - return stream->WriteReady(aReadyCount); - } - return NS_OK; + if (!stream) + return NS_ERROR_FAILURE; + + return stream->WriteReady(aReadyCount); } -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 (!first_write) - { - unsigned int written; - stream->Write("
", 5, &written);
-			first_write = PR_TRUE;
-		}
-		return stream->Write(aBuf, aCount, aWriteCount);
-	}
-	return NS_OK;
+  if (!stream)
+    return NS_ERROR_FAILURE;
+
+  // SHERRY mTotalWritten = 0;
+  mTotalRead += aCount;
+  rc = mime_display_stream_write(mBridgeStream, aBuf, aCount);
+  // *aWriteCount = mTotalWritten;
+  if (mRebuffer->GetSize() > 0)
+    *aWriteCount = 0;
+  else
+    *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)
-	{
-		return stream->Close();
-	}
-	return NS_OK;
+  if (!obj)
+    return NS_ERROR_FAILURE;
+  newStream = (nsINetOStream *)(obj->mOutStream);
+
+  //
+  // 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;
+  }
 }
diff --git a/mailnews/mime/src/plugin_inst.h b/mailnews/mime/src/plugin_inst.h
index abff2f14d8f..cb6a9f8cb12 100644
--- a/mailnews/mime/src/plugin_inst.h
+++ b/mailnews/mime/src/plugin_inst.h
@@ -18,6 +18,7 @@
 #ifndef plugin_inst_h_
 #define plugin_inst_h_
 
+#include "rebuffer.h"
 #include "nsINetOStream.h"
 #include "nsINetPluginInstance.h"
 
@@ -39,7 +40,7 @@ public:
     NS_DECL_ISUPPORTS
 
     // 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    Start(void);
     NS_IMETHOD    Stop(void);
@@ -60,9 +61,14 @@ public:
 
     ////////////////////////////////////////////////////////////////////////////
     // MimePluginInstance specific methods:
-protected:
-    nsINetOStream *OutStream;
-    PRBool         first_write;
+    ////////////////////////////////////////////////////////////////////////////
+    NS_IMETHOD    InternalCleanup(void);
+
+    nsINetOStream *mOutStream;
+    void          *mBridgeStream;
+    PRUint32      mTotalWritten;
+    PRUint32      mTotalRead;
+    MimeRebuffer  *mRebuffer;
 };
 
 /* this function will be used by the factory to generate an class access object....*/