New files for XP-COM stream converter interface.

This commit is contained in:
rhp%netscape.com 1999-03-03 05:36:20 +00:00
Родитель 2fa3681daa
Коммит 93041ebaa1
2 изменённых файлов: 263 добавлений и 0 удалений

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

@ -0,0 +1,191 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <stdio.h>
#include <string.h>
#include "plugin_inst.h"
////////////////////////////////////////////////////////////////////////////////
// SimplePluginInstance Methods
////////////////////////////////////////////////////////////////////////////////
nsresult
NS_NewSimplePluginInstance(SimplePluginInstance **aInstancePtrResult)
{
/* note this new macro for assertions...they can take
a string describing the assertion */
nsresult res = NS_OK;
NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr");
if (nsnull != aInstancePtrResult)
{
SimplePluginInstance* inst = new SimplePluginInstance();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
res = inst->QueryInterface(nsINetPluginInstance::IID(), (void **)aInstancePtrResult);
if (res != NS_OK)
{
*aInstancePtrResult = NULL;
delete inst;
}
return res;
}
else
return NS_ERROR_NULL_POINTER; /* aInstancePtrResult was NULL....*/
}
SimplePluginInstance::SimplePluginInstance(void)
{
OutStream = NULL;
first_write = PR_FALSE;
NS_INIT_REFCNT();
}
SimplePluginInstance::~SimplePluginInstance(void)
{
}
static NS_DEFINE_IID(kINetPluginInstanceIID, NS_INETPLUGININSTANCE_IID);
static NS_DEFINE_IID(kINetOStreamIID, NS_INETOSTREAM_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_METHOD
SimplePluginInstance::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if (aIID.Equals(kINetPluginInstanceIID))
*aInstancePtr = (void*) this;
else if (aIID.Equals(kISupportsIID))
*aInstancePtr = (void*) ((nsISupports*)(nsINetPluginInstance *)this);
else if (aIID.Equals(kINetOStreamIID))
*aInstancePtr = (void *)((nsINetOStream *)this);
if (*aInstancePtr == NULL)
return NS_NOINTERFACE;
AddRef(); // Increase reference count for caller
return NS_OK;
}
NS_IMPL_ADDREF(SimplePluginInstance);
NS_IMPL_RELEASE(SimplePluginInstance);
NS_METHOD
SimplePluginInstance::Initialize(nsINetOStream* stream)
{
OutStream = stream;
return NS_OK;
}
NS_METHOD
SimplePluginInstance::GetMIMEOutput(const char* *result)
{
*result = "text/html";
return NS_OK;
}
NS_METHOD
SimplePluginInstance::Start(void)
{
return NS_OK;
}
NS_METHOD
SimplePluginInstance::Stop(void)
{
return NS_OK;
}
NS_METHOD
SimplePluginInstance::Destroy(void)
{
return NS_OK;
}
nsresult SimplePluginInstance :: Complete(void)
{
nsINetOStream *stream = OutStream;
if (stream)
{
if (first_write)
{
unsigned int written;
stream->Write("</pre>", 0, 6, &written);
}
return stream->Complete();
}
return NS_OK;
}
nsresult SimplePluginInstance :: Abort(PRInt32 status)
{
nsINetOStream *stream = OutStream;
if (stream)
{
return stream->Abort(status);
}
return NS_OK;
}
nsresult SimplePluginInstance :: WriteReady(PRUint32 *aReadyCount)
{
nsINetOStream *stream = OutStream;
if (stream)
{
return stream->WriteReady(aReadyCount);
}
return NS_OK;
}
nsresult SimplePluginInstance :: Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount)
{
nsINetOStream *stream = OutStream;
if (stream)
{
if (!first_write)
{
unsigned int written;
stream->Write("<pre>", 0, 5, &written);
first_write = PR_TRUE;
}
return stream->Write(aBuf, aOffset, aCount, aWriteCount);
}
return NS_OK;
}
nsresult SimplePluginInstance::Close(void)
{
nsINetOStream *stream = OutStream;
if (stream)
{
return stream->Close();
}
return NS_OK;
}

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

@ -0,0 +1,72 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef plugin_inst_h_
#define plugin_inst_h_
#include "nsINetOStream.h"
#include "nsINetPluginInstance.h"
// The ProgID for message/rfc822 messages
#define PROGRAM_ID MESSAGE_RFC822
// {B21EDB21-D10C-11d2-B373-525400E2D63A}
#define NS_INET_PLUGIN_MIME_CID \
{ 0xb21edb21, 0xd10c, 0x11d2, \
{ 0xb3, 0x73, 0x52, 0x54, 0x0, 0xe2, 0xd6, 0x3a } };
class SimplePluginInstance : public nsINetPluginInstance, public nsINetOStream {
public:
//static const nsIID& IID() { static nsIID iid = NS_INETPLUGININSTANCE_IID; return iid; }
SimplePluginInstance(void);
virtual ~SimplePluginInstance(void);
NS_DECL_ISUPPORTS
// from nsINetPluginInstance
NS_IMETHOD Initialize(nsINetOStream* out_stream);
NS_IMETHOD GetMIMEOutput(const char* *result);
NS_IMETHOD Start(void);
NS_IMETHOD Stop(void);
NS_IMETHOD Destroy(void);
//nsINetOStream interface
NS_IMETHOD Complete(void);
NS_IMETHOD Abort(PRInt32 status);
NS_IMETHOD WriteReady(PRUint32 *aReadyCount);
// nsIOutputStream interface
NS_IMETHOD Write(const char *aBuf,
PRUint32 aOffset,
PRUint32 aLen,
PRUint32 *aWriteLength);
// nsIBaseStream interface
NS_IMETHOD Close(void);
////////////////////////////////////////////////////////////////////////////
// SimplePluginInstance specific methods:
protected:
nsINetOStream *OutStream;
PRBool first_write;
};
/* this function will be used by the factory to generate an class access object....*/
extern nsresult NS_NewSimplePluginInstance(SimplePluginInstance **aInstancePtrResult);
#endif /* plugin_inst_h_ */