Adding files to the repository. NOT PART OF THE BUILD!

This commit is contained in:
rhp%netscape.com 1999-12-21 17:55:56 +00:00
parent 3f7e67c780
commit 1e36d1d252
10 changed files with 1006 additions and 0 deletions

View File

@ -0,0 +1,48 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = signed
LIBRARY_NAME = signed
IS_COMPONENT = 1
CPPSRCS = \
mimexpcom.cpp \
nsSignedStub.cpp \
nsMimeContentTypeHandler.cpp \
nsSignedStubFactory.cpp \
$(NULL)
EXTRA_DSO_LDOPTS = \
-L$(DIST)/bin \
-L$(DIST)/lib \
-lxpcom \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,103 @@
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH=..\..\..\..
#//------------------------------------------------------------------------
#//
# New build system where zip dll is build indepenant of java stubs.
#//
#//------------------------------------------------------------------------
MODULE = signed
REQUIRES=
#EXPORTS =
# Exported headers here!!!
# $(NULL)
DEFINES= -DEBUG_rhp -D_IMPL_NS_HTML
#//------------------------------------------------------------------------
#//
#// Define the files necessary to build the target (ie. OBJS)
#//
#//------------------------------------------------------------------------
OBJS= \
.\$(OBJDIR)\nsSignedStub.obj \
.\$(OBJDIR)\mimexpcom.obj \
.\$(OBJDIR)\nsMimeContentTypeHandler.obj \
.\$(OBJDIR)\nsSignedStubFactory.obj \
$(NULL)
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DLLNAME=$(MODULE)
MAPFILE=$(MODULE).map
DEFFILE=$(MODULE).def
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
#
DLL=.\$(OBJDIR)\$(DLLNAME).dll
#//------------------------------------------------------------------------
#//
#// Define any local options for the make tools
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
#//
#//------------------------------------------------------------------------
LCFLAGS=-DNETSCAPE
MSGLIBS= \
$(NULL)
# These are the libraries we need to link with to create the dll
LLIBS= \
$(LLIBS) \
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(NULL)
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
clobber::
rm -f $(DIST)\bin\$(DLLNAME).dll

View File

@ -0,0 +1,142 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsIComponentManager.h"
#include "nsMimeObjectClassAccess.h"
#include "nsCOMPtr.h"
#include "nsMsgMimeCID.h"
static NS_DEFINE_CID(kMimeObjectClassAccessCID, NS_MIME_OBJECT_CLASS_ACCESS_CID);
/*
* These calls are necessary to expose the object class heirarchy
* to externally developed content type handlers.
*/
extern "C" void *
COM_GetmimeInlineTextClass(void)
{
nsCOMPtr<nsIMimeObjectClassAccess> objAccess;
void *ptr = NULL;
nsresult res = nsComponentManager::CreateInstance(kMimeObjectClassAccessCID,
NULL, nsIMimeObjectClassAccess::GetIID(),
(void **) getter_AddRefs(objAccess));
if (NS_SUCCEEDED(res) && objAccess)
objAccess->GetmimeInlineTextClass(&ptr);
return ptr;
}
extern "C" void *
COM_GetmimeLeafClass(void)
{
nsCOMPtr<nsIMimeObjectClassAccess> objAccess;
void *ptr = NULL;
nsresult res = nsComponentManager::CreateInstance(kMimeObjectClassAccessCID,
NULL, nsIMimeObjectClassAccess::GetIID(),
(void **) getter_AddRefs(objAccess));
if (NS_SUCCEEDED(res) && objAccess)
objAccess->GetmimeLeafClass(&ptr);
return ptr;
}
extern "C" void *
COM_GetmimeObjectClass(void)
{
nsCOMPtr<nsIMimeObjectClassAccess> objAccess;
void *ptr = NULL;
nsresult res = nsComponentManager::CreateInstance(kMimeObjectClassAccessCID,
NULL, nsIMimeObjectClassAccess::GetIID(),
(void **) getter_AddRefs(objAccess));
if (NS_SUCCEEDED(res) && objAccess)
objAccess->GetmimeObjectClass(&ptr);
return ptr;
}
extern "C" void *
COM_GetmimeContainerClass(void)
{
nsCOMPtr<nsIMimeObjectClassAccess> objAccess;
void *ptr = NULL;
nsresult res = nsComponentManager::CreateInstance(kMimeObjectClassAccessCID,
NULL, nsIMimeObjectClassAccess::GetIID(),
(void **) getter_AddRefs(objAccess));
if (NS_SUCCEEDED(res) && objAccess)
objAccess->GetmimeContainerClass(&ptr);
return ptr;
}
extern "C" void *
COM_GetmimeMultipartClass(void)
{
nsCOMPtr<nsIMimeObjectClassAccess> objAccess;
void *ptr = NULL;
nsresult res = nsComponentManager::CreateInstance(kMimeObjectClassAccessCID,
NULL, nsIMimeObjectClassAccess::GetIID(),
(void **) getter_AddRefs(objAccess));
if (NS_SUCCEEDED(res) && objAccess)
objAccess->GetmimeMultipartClass(&ptr);
return ptr;
}
extern "C" void *
COM_GetmimeMultipartSignedClass(void)
{
nsCOMPtr<nsIMimeObjectClassAccess> objAccess;
void *ptr = NULL;
nsresult res = nsComponentManager::CreateInstance(kMimeObjectClassAccessCID,
NULL, nsIMimeObjectClassAccess::GetIID(),
(void **) getter_AddRefs(objAccess));
if (NS_SUCCEEDED(res) && objAccess)
objAccess->GetmimeMultipartSignedClass(&ptr);
return ptr;
}
extern "C" int
COM_MimeObject_write(void *mimeObject, char *data, PRInt32 length,
PRBool user_visible_p)
{
nsCOMPtr<nsIMimeObjectClassAccess> objAccess;
PRInt32 rc=-1;
nsresult res = nsComponentManager::CreateInstance(kMimeObjectClassAccessCID,
NULL, nsIMimeObjectClassAccess::GetIID(),
(void **) getter_AddRefs(objAccess));
if (NS_SUCCEEDED(res) && objAccess)
{
if (NS_SUCCEEDED(objAccess->MimeObjectWrite(mimeObject, data, length, user_visible_p)))
rc = length;
else
rc = -1;
}
return rc;
}

View File

@ -0,0 +1,111 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* This is the definitions for the Content Type Handler plugins to
* access internals of libmime via XP-COM calls
*/
#ifndef _MIMEXPCOM_H_
#define _MIMEXPCOM_H_
/*
This header exposes functions that are necessary to access the
object heirarchy for the mime chart. The class hierarchy is:
MimeObject (abstract)
|
|--- MimeContainer (abstract)
| |
| |--- MimeMultipart (abstract)
| | |
| | |--- MimeMultipartMixed
| | |
| | |--- MimeMultipartDigest
| | |
| | |--- MimeMultipartParallel
| | |
| | |--- MimeMultipartAlternative
| | |
| | |--- MimeMultipartRelated
| | |
| | |--- MimeMultipartAppleDouble
| | |
| | |--- MimeSunAttachment
| | |
| | |--- MimeMultipartSigned (abstract)
| | |
| | |--- MimeMultipartSigned
| |
| |--- MimeXlateed (abstract)
| | |
| | |--- MimeXlateed
| |
| |--- MimeMessage
| |
| |--- MimeUntypedText
|
|--- MimeLeaf (abstract)
| |
| |--- MimeInlineText (abstract)
| | |
| | |--- MimeInlineTextPlain
| | |
| | |--- MimeInlineTextHTML
| | |
| | |--- MimeInlineTextRichtext
| | | |
| | | |--- MimeInlineTextEnriched
| | |
| | |--- MimeInlineTextVCard
| | |
| | |--- MimeInlineTextCalendar
| |
| |--- MimeInlineImage
| |
| |--- MimeExternalObject
|
|--- MimeExternalBody
*/
/*
* These functions are exposed by libmime to be used by content type
* handler plugins for processing stream data.
*/
/*
* This is the write call for outputting processed stream data.
*/
extern "C" int COM_MimeObject_write(void *mimeObject, char *data,
PRInt32 length,
PRBool user_visible_p);
/*
* The following group of calls expose the pointers for the object
* system within libmime.
*/
extern "C" void *COM_GetmimeInlineTextClass(void);
extern "C" void *COM_GetmimeLeafClass(void);
extern "C" void *COM_GetmimeObjectClass(void);
extern "C" void *COM_GetmimeContainerClass(void);
extern "C" void *COM_GetmimeMultipartClass(void);
extern "C" void *COM_GetmimeMultipartSignedClass(void);
#endif /* _MIMEXPCOM_H_ */

View File

@ -0,0 +1,95 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "stdio.h"
#include "nscore.h"
#include "plstr.h"
#include "prtypes.h"
//#include "mimecth.h"
#include "nsMimeContentTypeHandler.h"
/*
* This function will be used by the factory to generate an
* mime object class object....
*/
nsresult NS_NewMimeContentTypeHandler(nsIMimeContentTypeHandler ** aInstancePtrResult)
{
/* note this new macro for assertions...they can take
a string describing the assertion */
NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr");
if (nsnull != aInstancePtrResult)
{
nsMimeContentTypeHandler *obj = new nsMimeContentTypeHandler();
if (obj)
return obj->QueryInterface(nsIMimeContentTypeHandler::GetIID(), (void**) aInstancePtrResult);
else
return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the object */
}
else
return NS_ERROR_NULL_POINTER; /* aInstancePtrResult was NULL....*/
}
/*
* The following macros actually implement addref, release and
* query interface for our component.
*/
NS_IMPL_ADDREF(nsMimeContentTypeHandler)
NS_IMPL_RELEASE(nsMimeContentTypeHandler)
NS_IMPL_QUERY_INTERFACE(nsMimeContentTypeHandler, nsIMimeContentTypeHandler::GetIID()); /* we need to pass in the interface ID of this interface */
/*
* nsIMimeEmitter definitions....
*/
nsMimeContentTypeHandler::nsMimeContentTypeHandler()
{
/* the following macro is used to initialize the ref counting data */
NS_INIT_REFCNT();
}
nsMimeContentTypeHandler::~nsMimeContentTypeHandler(void)
{
}
extern "C" char *MIME_GetContentType(void);
extern "C" MimeObjectClass *MIME_CreateContentTypeHandlerClass(const char *content_type,
contentTypeHandlerInitStruct *initStruct);
// Get the content type if necessary
nsresult
nsMimeContentTypeHandler::GetContentType(char **contentType)
{
*contentType = MIME_GetContentType();
return NS_OK;
}
// Set the output stream for processed data.
nsresult
nsMimeContentTypeHandler::CreateContentTypeHandlerClass(const char *content_type,
contentTypeHandlerInitStruct *initStruct,
MimeObjectClass **objClass)
{
*objClass = MIME_CreateContentTypeHandlerClass(content_type, initStruct);
if (!*objClass)
return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the object */
else
return NS_OK;
}

View File

@ -0,0 +1,60 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* This interface is implemented by content type handlers that will be
* called upon by libmime to process various attachments types. The primary
* purpose of these handlers will be to represent the attached data in a
* viewable HTML format that is useful for the user
*
* Note: These will all register by their content type prefixed by the
* following: mimecth:text/vcard
*
* libmime will then use nsComponentManager::ProgIDToCLSID() to
* locate the appropriate Content Type handler
*/
#ifndef nsMimeContentTypeHandler_h_
#define nsMimeContentTypeHandler_h_
#include "prtypes.h"
#include "nsIMimeContentTypeHandler.h"
class nsMimeContentTypeHandler : public nsIMimeContentTypeHandler {
public:
nsMimeContentTypeHandler ();
virtual ~nsMimeContentTypeHandler (void);
/* this macro defines QueryInterface, AddRef and Release for this class */
NS_DECL_ISUPPORTS
NS_IMETHOD GetContentType(char **contentType);
NS_IMETHOD CreateContentTypeHandlerClass(const char *content_type,
contentTypeHandlerInitStruct *initStruct,
MimeObjectClass **objClass);
};
/* this function will be used by the factory to generate an class access object....*/
extern nsresult NS_NewMimeContentTypeHandler(nsIMimeContentTypeHandler **aInstancePtrResult);
#endif /* nsMimeContentTypeHandler_h_ */

View File

@ -0,0 +1,151 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsSIGNEDStub.h"
#include "prmem.h"
#include "plstr.h"
#include "mimexpcom.h"
#include "mimecth.h"
#include "mimeobj.h"
#include "nsCRT.h"
static int MimeInlineTextSIGNEDStub_parse_line (char *, PRInt32, MimeObject *);
static int MimeInlineTextSIGNEDStub_parse_eof (MimeObject *, PRBool);
static int MimeInlineTextSIGNEDStub_parse_begin (MimeObject *obj);
/* This is the object definition. Note: we will set the superclass
to NULL and manually set this on the class creation */
MimeDefClass(MimeInlineTextSIGNEDStub, MimeInlineTextSIGNEDStubClass, mimeInlineTextSIGNEDStubClass, NULL);
extern "C" char *
MIME_GetContentType(void)
{
return SIGNED_CONTENT_TYPE;
}
extern "C" MimeObjectClass *
MIME_CreateContentTypeHandlerClass(const char *content_type,
contentTypeHandlerInitStruct *initStruct)
{
MimeObjectClass *clazz = (MimeObjectClass *)&mimeInlineTextSIGNEDStubClass;
/*
* Must set the superclass by hand.
*/
if (!COM_GetmimeInlineTextClass())
return NULL;
clazz->superclass = (MimeObjectClass *)COM_GetmimeInlineTextClass();
initStruct->force_inline_display = PR_TRUE;
return clazz;
}
static int
MimeInlineTextSIGNEDStubClassInitialize(MimeInlineTextSIGNEDStubClass *clazz)
{
MimeObjectClass *oclass = (MimeObjectClass *) clazz;
PR_ASSERT(!oclass->class_initialized);
oclass->parse_begin = MimeInlineTextSIGNEDStub_parse_begin;
oclass->parse_line = MimeInlineTextSIGNEDStub_parse_line;
oclass->parse_eof = MimeInlineTextSIGNEDStub_parse_eof;
return 0;
}
int
GenerateMessage(char** html)
{
*html = nsCRT::strdup("\
<text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#FF0000\" vlink=\"#800080\" alink=\"#0000FF\">\
<center><table BORDER=1 ><tr>\
<td><CENTER>This messages is possibly <B>SIGNED</B>. Mozilla Mail does not support signed mail.</CENTER></td>\
</tr>\
</table></center>");
return 0;
}
static int
MimeInlineTextSIGNEDStub_parse_begin(MimeObject *obj)
{
MimeInlineTextSIGNEDStubClass *clazz;
int status = ((MimeObjectClass*)COM_GetmimeLeafClass())->parse_begin(obj);
if (status < 0)
return status;
if (!obj->output_p)
return 0;
if (!obj->options || !obj->options->write_html_p)
return 0;
/* This is a fine place to write out any HTML before the real meat begins. */
// Initialize the clazz variable...
clazz = ((MimeInlineTextSIGNEDStubClass *) obj->clazz);
return 0;
}
static int
MimeInlineTextSIGNEDStub_parse_line(char *line, PRInt32 length, MimeObject *obj)
{
/*
* This routine gets fed each line of data, one at a time. We just buffer
* it all up, to be dealt with all at once at the end.
*/
if (!obj->output_p)
return 0;
if (!obj->options || !obj->options->output_fn)
return 0;
if (!obj->options->write_html_p)
{
return COM_MimeObject_write(obj, line, length, TRUE);
}
return 0;
}
static int
MimeInlineTextSIGNEDStub_parse_eof (MimeObject *obj, PRBool abort_p)
{
int status = 0;
char* html = NULL;
if (obj->closed_p) return 0;
/* Run parent method first, to flush out any buffered data. */
status = ((MimeObjectClass*)COM_GetmimeInlineTextClass())->parse_eof(obj, abort_p);
if (status < 0)
return status;
status = GenerateMessage(&html);
if (status < 0)
return status;
status = COM_MimeObject_write(obj, html, PL_strlen(html), TRUE);
PR_FREEIF(html);
if (status < 0)
return status;
return 0;
}

View File

@ -0,0 +1,54 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef _MIMESIGNED_H_
#define _MIMESIGNED_H_
#include "mimetext.h"
/*
* These functions are the public interface for this content type
* handler and will be called in by the mime component.
*/
#define SIGNED_CONTENT_TYPE "application/x-pkcs7-signature"
/* The MimeInlineTextSIGNEDStub class implements the "application/x-pkcs7-mime"2
MIME content types.
*/
typedef struct MimeInlineTextSIGNEDStubClass MimeInlineTextSIGNEDStubClass;
typedef struct MimeInlineTextSIGNEDStub MimeInlineTextSIGNEDStub;
struct MimeInlineTextSIGNEDStubClass {
MimeInlineTextClass text;
char* buffer;
PRInt32 bufferlen;
PRInt32 buffermax;
};
extern MimeInlineTextSIGNEDStubClass mimeInlineTextSIGNEDStubClass;
struct MimeInlineTextSIGNEDStub {
MimeInlineText text;
};
#endif /* _MIMESIGNED_H_ */

View File

@ -0,0 +1,220 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsIFactory.h"
#include "nsISupports.h"
#include "msgCore.h"
#include "nsCOMPtr.h"
#include "pratom.h"
#include "nsSignedStub.h"
/* Include all of the interfaces our factory can generate components for */
#include "nsIMimeContentTypeHandler.h"
#include "nsMimeContentTypeHandler.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kMimeContentTypeHandlerCID, NS_SIGNED_CONTENT_TYPE_HANDLER_CID);
////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
static PRInt32 g_InstanceCount = 0;
static PRInt32 g_LockCount = 0;
class nsSignedStubFactory : public nsIFactory
{
public:
// nsISupports methods
NS_DECL_ISUPPORTS
nsSignedStubFactory(const nsCID &aClass,
const char* aClassName,
const char* aProgID,
nsISupports*);
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~nsSignedStubFactory();
nsCID mClassID;
char* mClassName;
char* mProgID;
nsIServiceManager* mServiceManager;
};
nsSignedStubFactory::nsSignedStubFactory(const nsCID &aClass,
const char* aClassName,
const char* aProgID,
nsISupports *compMgrSupports)
: mClassID(aClass),
mClassName(nsCRT::strdup(aClassName)),
mProgID(nsCRT::strdup(aProgID))
{
NS_INIT_REFCNT();
// store a copy of the
compMgrSupports->QueryInterface(nsIServiceManager::GetIID(),
(void **)&mServiceManager);
}
nsSignedStubFactory::~nsSignedStubFactory()
{
NS_IF_RELEASE(mServiceManager);
PL_strfree(mClassName);
PL_strfree(mProgID);
}
nsresult
nsSignedStubFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (aResult == NULL)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = NULL;
// we support two interfaces....nsISupports and nsFactory.....
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aResult = (void *)(nsISupports*)this;
else if (aIID.Equals(nsIFactory::GetIID()))
*aResult = (void *)(nsIFactory*)this;
if (*aResult == NULL)
return NS_NOINTERFACE;
AddRef(); // Increase reference count for caller
return NS_OK;
}
NS_IMPL_ADDREF(nsSignedStubFactory)
NS_IMPL_RELEASE(nsSignedStubFactory)
nsresult
nsSignedStubFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult res = NS_OK;
if (aResult == NULL)
return NS_ERROR_NULL_POINTER;
*aResult = NULL;
nsCOMPtr <nsIMimeContentTypeHandler> inst;
// ClassID check happens here
// Whenever you add a new class that supports an interface, plug it in here!!!
// do they want a mime emitter interface ?
if (mClassID.Equals(kMimeContentTypeHandlerCID))
{
res = NS_NewMimeContentTypeHandler(getter_AddRefs(inst));
if (NS_FAILED(res)) // was there a problem creating the object ?
return res;
}
// End of checking the interface ID code....
if (inst)
{
// so we now have the class that supports the desired interface...we need to turn around and
// query for our desired interface.....
res = inst->QueryInterface(aIID, aResult);
}
else
res = NS_ERROR_OUT_OF_MEMORY;
return res;
}
nsresult
nsSignedStubFactory::LockFactory(PRBool aLock)
{
if (aLock)
PR_AtomicIncrement(&g_LockCount);
else
PR_AtomicDecrement(&g_LockCount);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// return the proper factory to the caller.
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if (nsnull == aFactory)
return NS_ERROR_NULL_POINTER;
*aFactory = new nsSignedStubFactory(aClass, aClassName, aProgID, aServMgr);
if (aFactory)
return (*aFactory)->QueryInterface(nsIFactory::GetIID(),
(void**)aFactory);
else
return NS_ERROR_OUT_OF_MEMORY;
}
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr)
{
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
}
////////////////////////////////////////////////////////////////////////////////
extern "C" NS_EXPORT nsresult
NSRegisterSelf(nsISupports* aServMgr, const char* path)
{
nsresult rv = NS_OK;
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
char *cType = {"mimecth:"SIGNED_CONTENT_TYPE};
rv = compMgr->RegisterComponent(kMimeContentTypeHandlerCID,
"MIME SignedStubed Mail Handler",
cType,
path, PR_TRUE, PR_TRUE);
return rv;
}
extern "C" NS_EXPORT nsresult
NSUnregisterSelf(nsISupports* aServMgr, const char* path)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kMimeContentTypeHandlerCID, path);
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,22 @@
; The contents of this file are subject to the Netscape Public
; License Version 1.1 (the "License"); you may not use this file
; except in compliance with the License. You may obtain a copy of
; the License at http://www.mozilla.org/NPL/
;
; Software distributed under the License is distributed on an "AS
; IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
; implied. See the License for the specific language governing
; rights and limitations under the License.
;
; The Original Code is mozilla.org code.
;
; The Initial Developer of the Original Code is Netscape
; Communications Corporation. Portions created by Netscape are
; Copyright (C) 1998 Netscape Communications Corporation. All
; Rights Reserved.
;
; Contributor(s):
LIBRARY signed.dll
EXPORTS