Compare commits

..

16 Commits

Author SHA1 Message Date
waterson%netscape.com
53290be7ef Added stuff to handle SetAttribute(), not quite in the right way, but better than we were doing before.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20904 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 07:55:48 +00:00
hyatt%netscape.com
cc41f20577 Implementing nsIDOMXULElement and moving broadcaster stuff over to nsRDFResourceElement
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20879 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:56:10 +00:00
hyatt%netscape.com
365c530406 Implementing nsIDOMXULElement and moving broadcaster stuff over to nsRDFResourceElement
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20878 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:53:05 +00:00
waterson%netscape.com
a13f4f72a8 Renamed XULNode to XULElement, derived from Element.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20877 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:50:18 +00:00
waterson%netscape.com
2e383bd6ff Rename XULNode to XULElement.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20876 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:45:46 +00:00
waterson%netscape.com
fb1d31b51e Renamed XULNode to XULElement, and derived XULElement from Element.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20875 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:44:24 +00:00
waterson%netscape.com
581a4ad6b7 Changed to use rdf_PossiblyMakeAbsolute.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20874 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:28:25 +00:00
waterson%netscape.com
01896afc44 Removed FullyQualifyURI() method.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20873 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:27:59 +00:00
waterson%netscape.com
6bd6d90055 Added rdf_PossiblyMakeAbsolute.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20872 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:27:38 +00:00
waterson%netscape.com
3323e496e5 Changed content sink to use rdf_PossiblyMakeAbsolute and nsRDFParserUtils.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20871 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:27:24 +00:00
waterson%netscape.com
ad0ae0f68c Added XULDocument, hooked up a bunch more DOM interfaces.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20869 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:26:21 +00:00
waterson%netscape.com
b7b5a905ae Initial revision.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20868 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:25:36 +00:00
waterson%netscape.com
7af2b0504c Added XULDocument, derived XULNode from Node.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20867 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:25:17 +00:00
waterson%netscape.com
5cd36671dc Derived from Node.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20866 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:24:51 +00:00
waterson%netscape.com
a42a84d979 Added XULDocument.idl
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20865 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-17 03:24:43 +00:00
(no author)
50e3bb2d04 This commit was manufactured by cvs2svn to create branch
'RDFDOM_19990216_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990216_BRANCH@20822 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 19:56:20 +00:00
218 changed files with 60631 additions and 5119 deletions

View File

@@ -0,0 +1,305 @@
/* -*- 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 "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 Communicator client 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.
*/
/*
Helper class to implement the nsIDOMNodeList interface.
XXX It's probably wrong in some sense, as it uses the "naked"
content interface to look for kids. (I assume in general this is
bad because there may be pseudo-elements created for presentation
that aren't visible to the DOM.)
*/
#include "nsDOMCID.h"
#include "nsIDOMNode.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsRDFDOMNodeList.h"
////////////////////////////////////////////////////////////////////////
// GUID definitions
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID);
static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID);
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
////////////////////////////////////////////////////////////////////////
//
class RDFHTMLCollectionImpl : public nsIDOMHTMLCollection
{
private:
nsRDFDOMNodeList* mOuter;
public:
RDFHTMLCollectionImpl(nsRDFDOMNodeList* aOuter);
virtual ~RDFHTMLCollectionImpl();
// nsISupports interface
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aResult);
// nsIDOMHTMLCollection interface
NS_DECL_IDOMHTMLCOLLECTION
};
RDFHTMLCollectionImpl::RDFHTMLCollectionImpl(nsRDFDOMNodeList* aOuter)
: mOuter(aOuter)
{
}
RDFHTMLCollectionImpl::~RDFHTMLCollectionImpl(void)
{
}
NS_IMETHODIMP_(nsrefcnt)
RDFHTMLCollectionImpl::AddRef(void)
{
return mOuter->AddRef();
}
NS_IMETHODIMP_(nsrefcnt)
RDFHTMLCollectionImpl::Release(void)
{
return mOuter->Release();
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMHTMLCollection::IID())) {
*aResult = NS_STATIC_CAST(nsIDOMHTMLCollection*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
return mOuter->QueryInterface(aIID, aResult);
}
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::GetLength(PRUint32* aLength)
{
return mOuter->GetLength(aLength);
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
return mOuter->Item(aIndex, aReturn);
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::NamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// ctors & dtors
nsRDFDOMNodeList::nsRDFDOMNodeList(void)
: mInner(nsnull),
mElements(nsnull),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
nsRDFDOMNodeList::~nsRDFDOMNodeList(void)
{
NS_IF_RELEASE(mElements);
delete mInner;
}
nsresult
nsRDFDOMNodeList::Create(nsRDFDOMNodeList** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRDFDOMNodeList* list = new nsRDFDOMNodeList();
if (! list)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
if (NS_FAILED(rv = list->Init())) {
delete list;
return rv;
}
NS_ADDREF(list);
*aResult = list;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(nsRDFDOMNodeList);
NS_IMPL_RELEASE(nsRDFDOMNodeList);
nsresult
nsRDFDOMNodeList::QueryInterface(REFNSIID aIID, void** aResult)
{
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMNodeList::IID()) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIDOMNodeList*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(nsIDOMHTMLCollection::IID())) {
// Aggregate this interface
if (! mInner) {
if (! (mInner = new RDFHTMLCollectionImpl(this)))
return NS_ERROR_OUT_OF_MEMORY;
}
return mInner->QueryInterface(aIID, aResult);
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeList interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetLength(PRUint32* aLength)
{
NS_ASSERTION(aLength != nsnull, "null ptr");
if (! aLength)
return NS_ERROR_NULL_POINTER;
*aLength = mElements->Count();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
NS_PRECONDITION(aReturn != nsnull, "null ptr");
if (! aReturn)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aIndex < (PRUint32) mElements->Count(), "invalid arg");
if (aIndex >= (PRUint32) mElements->Count())
return NS_ERROR_INVALID_ARG;
// Cast is okay because we're in a closed system.
*aReturn = (nsIDOMNode*) mElements->ElementAt(aIndex);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIScriptObjectOwner interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult rv = NS_OK;
nsIScriptGlobalObject* global = aContext->GetGlobalObject();
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID,
kIDOMScriptObjectFactoryIID,
(nsISupports **)&factory))) {
rv = factory->NewScriptHTMLCollection(aContext,
(nsISupports*)(nsIDOMNodeList*)this,
global,
(void**)&mScriptObject);
nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory);
}
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return rv;
}
NS_IMETHODIMP
nsRDFDOMNodeList::SetScriptObject(void* aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Implementation methods
nsresult
nsRDFDOMNodeList::Init(void)
{
nsresult rv;
if (NS_FAILED(rv = NS_NewISupportsArray(&mElements))) {
NS_ERROR("unable to create elements array");
return rv;
}
return NS_OK;
}
nsresult
nsRDFDOMNodeList::AppendNode(nsIDOMNode* aNode)
{
NS_PRECONDITION(aNode != nsnull, "null ptr");
if (! aNode)
return NS_ERROR_NULL_POINTER;
return mElements->AppendElement(aNode);
}

View File

@@ -0,0 +1,58 @@
/* -*- 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 "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 Communicator client 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.
*/
#ifndef nsRDFDOMNodeList_h__
#define nsRDFDOMNodeList_h__
#include "nsIDOMNodeList.h"
#include "nsIScriptObjectOwner.h"
class nsIDOMNode;
class nsISupportsArray;
class nsRDFDOMNodeList : public nsIDOMNodeList,
public nsIScriptObjectOwner
{
private:
nsISupports* mInner;
nsISupportsArray* mElements;
void* mScriptObject;
nsRDFDOMNodeList(void);
nsresult Init(void);
public:
static nsresult Create(nsRDFDOMNodeList** aResult);
virtual ~nsRDFDOMNodeList(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMNodeList interface
NS_DECL_IDOMNODELIST
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
// Implementation methods
nsresult AppendNode(nsIDOMNode* aNode);
};
#endif // nsRDFDOMNodeList_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
interface XULDocument : Document {
/* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
Node getElementByID(in DOMString id);
};

View File

@@ -0,0 +1,9 @@
interface XULElement : Element {
/* IID: { 0x574ed81, 0xc088, 0x11d2, \
{ 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } */
void addBroadcastListener(in DOMString attr, in Node node);
void removeBroadcastListener(in DOMString attr, in Node node);
void doCommand();
};

View File

@@ -0,0 +1,55 @@
/* -*- 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.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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMXULDocument_h__
#define nsIDOMXULDocument_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMDocument.h"
class nsIDOMNode;
#define NS_IDOMXULDOCUMENT_IID \
{ 0x17ddd8c0, 0xc5f8, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIDOMXULDocument : public nsIDOMDocument {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; }
NS_IMETHOD GetElementByID(const nsString& aId, nsIDOMNode** aReturn)=0;
};
#define NS_DECL_IDOMXULDOCUMENT \
NS_IMETHOD GetElementByID(const nsString& aId, nsIDOMNode** aReturn); \
#define NS_FORWARD_IDOMXULDOCUMENT(_to) \
NS_IMETHOD GetElementByID(const nsString& aId, nsIDOMNode** aReturn) { return _to##GetElementByID(aId, aReturn); } \
extern "C" NS_DOM nsresult NS_InitXULDocumentClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptXULDocument(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMXULDocument_h__

View File

@@ -0,0 +1,63 @@
/* -*- 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.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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMXULElement_h__
#define nsIDOMXULElement_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMElement.h"
class nsIDOMNode;
#define NS_IDOMXULELEMENT_IID \
{ 0x574ed81, 0xc088, 0x11d2, \
{ 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } }
class nsIDOMXULElement : public nsIDOMElement {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMXULELEMENT_IID; return iid; }
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode)=0;
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode)=0;
NS_IMETHOD DoCommand()=0;
};
#define NS_DECL_IDOMXULELEMENT \
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode); \
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode); \
NS_IMETHOD DoCommand(); \
#define NS_FORWARD_IDOMXULELEMENT(_to) \
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode) { return _to##AddBroadcastListener(aAttr, aNode); } \
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode) { return _to##RemoveBroadcastListener(aAttr, aNode); } \
NS_IMETHOD DoCommand() { return _to##DoCommand(); } \
extern "C" NS_DOM nsresult NS_InitXULElementClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptXULElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMXULElement_h__

View File

@@ -0,0 +1,312 @@
/* -*- 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.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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMNode.h"
#include "nsIDOMXULDocument.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIXULDocumentIID, NS_IDOMXULDOCUMENT_IID);
NS_DEF_PTR(nsIDOMNode);
NS_DEF_PTR(nsIDOMXULDocument);
/***********************************************************************/
//
// XULDocument Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULDocument *a = (nsIDOMXULDocument*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// XULDocument Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULDocument *a = (nsIDOMXULDocument*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// XULDocument finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeXULDocument(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// XULDocument enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateXULDocument(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// XULDocument resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveXULDocument(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method GetElementByID
//
PR_STATIC_CALLBACK(JSBool)
XULDocumentGetElementByID(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->GetElementByID(b0, &nativeRet)) {
return JS_FALSE;
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);
}
else {
JS_ReportError(cx, "Function getElementByID requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for XULDocument
//
JSClass XULDocumentClass = {
"XULDocument",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetXULDocumentProperty,
SetXULDocumentProperty,
EnumerateXULDocument,
ResolveXULDocument,
JS_ConvertStub,
FinalizeXULDocument
};
//
// XULDocument class properties
//
static JSPropertySpec XULDocumentProperties[] =
{
{0}
};
//
// XULDocument class methods
//
static JSFunctionSpec XULDocumentMethods[] =
{
{"getElementByID", XULDocumentGetElementByID, 1},
{0}
};
//
// XULDocument constructor
//
PR_STATIC_CALLBACK(JSBool)
XULDocument(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// XULDocument class initialization
//
nsresult NS_InitXULDocumentClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULDocument", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitDocumentClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&XULDocumentClass, // JSClass
XULDocument, // JSNative ctor
0, // ctor args
XULDocumentProperties, // proto props
XULDocumentMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new XULDocument JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptXULDocument(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULDocument");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMXULDocument *aXULDocument;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitXULDocumentClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIXULDocumentIID, (void **)&aXULDocument);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &XULDocumentClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULDocument);
}
else {
NS_RELEASE(aXULDocument);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -0,0 +1,400 @@
/* -*- 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.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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMXULElement.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIXULElementIID, NS_IDOMXULELEMENT_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
NS_DEF_PTR(nsIDOMXULElement);
NS_DEF_PTR(nsIDOMNode);
/***********************************************************************/
//
// XULElement Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULElement *a = (nsIDOMXULElement*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// XULElement Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULElement *a = (nsIDOMXULElement*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// XULElement finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeXULElement(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// XULElement enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateXULElement(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// XULElement resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveXULElement(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method AddBroadcastListener
//
PR_STATIC_CALLBACK(JSBool)
XULElementAddBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsIDOMNodePtr b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->AddBroadcastListener(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function addBroadcastListener requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method RemoveBroadcastListener
//
PR_STATIC_CALLBACK(JSBool)
XULElementRemoveBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsIDOMNodePtr b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->RemoveBroadcastListener(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function removeBroadcastListener requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method DoCommand
//
PR_STATIC_CALLBACK(JSBool)
XULElementDoCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->DoCommand()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function doCommand requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for XULElement
//
JSClass XULElementClass = {
"XULElement",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetXULElementProperty,
SetXULElementProperty,
EnumerateXULElement,
ResolveXULElement,
JS_ConvertStub,
FinalizeXULElement
};
//
// XULElement class properties
//
static JSPropertySpec XULElementProperties[] =
{
{0}
};
//
// XULElement class methods
//
static JSFunctionSpec XULElementMethods[] =
{
{"addBroadcastListener", XULElementAddBroadcastListener, 2},
{"removeBroadcastListener", XULElementRemoveBroadcastListener, 2},
{"doCommand", XULElementDoCommand, 0},
{0}
};
//
// XULElement constructor
//
PR_STATIC_CALLBACK(JSBool)
XULElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// XULElement class initialization
//
nsresult NS_InitXULElementClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULElement", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitElementClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&XULElementClass, // JSClass
XULElement, // JSNative ctor
0, // ctor args
XULElementProperties, // proto props
XULElementMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new XULElement JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptXULElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULElement");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMXULElement *aXULElement;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitXULElementClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIXULElementIID, (void **)&aXULElement);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &XULElementClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULElement);
}
else {
NS_RELEASE(aXULElement);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -1,70 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIDOMWindow;
/**
* This interface provides support for registering Mozilla as the default
* Mail Client. This interface can also be used to get/set the user preference
* for the default Mail Client.
*
*/
[scriptable, uuid(c5be14ba-4e0a-4eec-a1b8-04363761d63c)]
interface nsIMapiRegistry: nsISupports {
/** This is set to TRUE if Mozilla is the default Application
*/
attribute boolean isDefaultMailClient;
/** This is set TRUE only once per session.
*/
readonly attribute boolean showDialog;
/** This will bring the dialog asking the user if he/she wants to set
* Mozilla as default Mail Client.
* Call this only if Mozilla is not the default Mail client
*/
void showMailIntegrationDialog(in nsIDOMWindow parentWindow);
};
%{C++
#define NS_IMAPIREGISTRY_CONTRACTID "@mozilla.org/mapiregistry;1"
#define NS_IMAPIREGISTRY_CLASSNAME "Mozilla MAPI Registry"
%}

View File

@@ -1,27 +0,0 @@
#!nmake
#
# 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): Srilatha Moturi <srilatha@netscape.com>
# Krishna Mohan Khandrika <kkhandrika@netscape.com>
DEPTH=..\..
DIRS=mapihook resources mapiDll
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,54 +0,0 @@
; ***** BEGIN LICENSE BLOCK *****
; Version: MPL 1.1/GPL 2.0/LGPL 2.1
;
; The contents of this file are subject to the Mozilla 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/MPL/
;
; 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.
;
; The Initial Developer of the Original Code is
; Netscape Communications Corp.
; Portions created by the Initial Developer are Copyright (C) 2001
; the Initial Developer. All Rights Reserved.
;
; Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
;
; Alternatively, the contents of this file may be used under the terms of
; either the GNU General Public License Version 2 or later (the "GPL"), or
; the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
; in which case the provisions of the GPL or the LGPL are applicable instead
; of those above. If you wish to allow use of your version of this file only
; under the terms of either the GPL or the LGPL, and not to allow others to
; use your version of this file under the terms of the MPL, indicate your
; decision by deleting the provisions above and replace them with the notice
; and other provisions required by the GPL or the LGPL. If you do not delete
; the provisions above, a recipient may use your version of this file under
; the terms of any one of the MPL, the GPL or the LGPL.
;
; ***** END LICENSE BLOCK *****
LIBRARY mozMapi32.dll
DESCRIPTION 'Mozilla Simple MAPI Support'
EXPORTS
MAPILogon
MAPILogoff
MAPISendMail
MAPISendDocuments
MAPIFindNext
MAPIReadMail
MAPISaveMail
MAPIDeleteMail
MAPIAddress
MAPIDetails
MAPIResolveName
MAPIFreeBuffer
GetMapiDllVersion

View File

@@ -1,346 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <windows.h>
#include <tchar.h>
#include <mapidefs.h>
#include <mapi.h>
#include "msgMapi.h"
#include "msgMapiMain.h"
#define MAX_RECIPS 100
#define MAX_FILES 100
const CLSID CLSID_CMapiImp = {0x29f458be, 0x8866, 0x11d5,
{0xa3, 0xdd, 0x0, 0xb0, 0xd0, 0xf3, 0xba, 0xa7}};
const IID IID_nsIMapi = {0x6EDCD38E,0x8861,0x11d5,
{0xA3,0xDD,0x00,0xB0,0xD0,0xF3,0xBA,0xA7}};
DWORD tId = 0;
BOOL WINAPI DllMain(HINSTANCE aInstance, DWORD aReason, LPVOID aReserved)
{
switch (aReason)
{
case DLL_PROCESS_ATTACH : tId = TlsAlloc();
if (tId == 0xFFFFFFFF)
return FALSE;
break;
case DLL_PROCESS_DETACH : TlsFree(tId);
break;
}
return TRUE;
}
BOOL InitMozillaReference(nsIMapi **aRetValue)
{
// Check wehther this thread has a valid Interface
// by looking into thread-specific-data variable
*aRetValue = (nsIMapi *)TlsGetValue(tId);
// Check whether the pointer actually resolves to
// a valid method call; otherwise mozilla is not running
if ((*aRetValue) && (*aRetValue)->IsValid() == S_OK)
return TRUE;
HRESULT hRes = ::CoInitialize(nsnull) ;
hRes = ::CoCreateInstance(CLSID_CMapiImp, NULL, CLSCTX_LOCAL_SERVER,
IID_nsIMapi, (LPVOID *)aRetValue);
if (hRes == S_OK && (*aRetValue)->Initialize() == S_OK)
if (TlsSetValue(tId, (LPVOID)(*aRetValue)))
return TRUE;
// Either CoCreate or TlsSetValue failed; so return FALSE
if ((*aRetValue))
(*aRetValue)->Release();
::CoUninitialize();
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////////////
// The MAPILogon function begins a Simple MAPI session, loading the default message ////
// store and address book providers ////
////////////////////////////////////////////////////////////////////////////////////////
ULONG FAR PASCAL MAPILogon(ULONG aUIParam, LPTSTR aProfileName,
LPTSTR aPassword, FLAGS aFlags,
ULONG aReserved, LPLHANDLE aSession)
{
HRESULT hr = 0;
ULONG nSessionId = 0;
nsIMapi *pNsMapi = NULL;
if (!InitMozillaReference(&pNsMapi))
return MAPI_E_FAILURE;
if (!(aFlags & MAPI_UNICODE))
{
// Need to convert the parameters to Unicode.
char *pUserName = (char *) aProfileName;
char *pPassWord = (char *) aPassword;
TCHAR ProfileName[MAX_NAME_LEN] = {0};
TCHAR PassWord[MAX_PW_LEN] = {0};
if (pUserName != NULL)
{
if (!MultiByteToWideChar(CP_ACP, 0, pUserName, -1, ProfileName,
MAX_NAME_LEN))
return MAPI_E_FAILURE;
}
if (pPassWord != NULL)
{
if (!MultiByteToWideChar(CP_ACP, 0, pPassWord, -1, PassWord,
MAX_NAME_LEN))
return MAPI_E_FAILURE;
}
hr = pNsMapi->Login(aUIParam, ProfileName, PassWord, aFlags,
&nSessionId);
}
else
hr = pNsMapi->Login(aUIParam, aProfileName, aPassword,
aFlags, &nSessionId);
if (hr == S_OK)
(*aSession) = (LHANDLE) nSessionId;
else
return nSessionId;
return SUCCESS_SUCCESS;
}
ULONG FAR PASCAL MAPILogoff (LHANDLE aSession, ULONG aUIParam,
FLAGS aFlags, ULONG aReserved)
{
nsIMapi *pNsMapi = (nsIMapi *)TlsGetValue(tId);
if (pNsMapi != NULL)
{
if (pNsMapi->Logoff((ULONG) aSession) == S_OK)
pNsMapi->Release();
pNsMapi = NULL;
}
TlsSetValue(tId, NULL);
::CoUninitialize();
return SUCCESS_SUCCESS;
}
ULONG FAR PASCAL MAPISendMail (LHANDLE lhSession, ULONG ulUIParam, lpnsMapiMessage lpMessage,
FLAGS flFlags, ULONG ulReserved )
{
HRESULT hr = 0;
BOOL bTempSession = FALSE ;
nsIMapi *pNsMapi = NULL;
if (!InitMozillaReference(&pNsMapi))
return MAPI_E_FAILURE;
if (lpMessage->nRecipCount > MAX_RECIPS)
return MAPI_E_TOO_MANY_RECIPIENTS ;
if (lpMessage->nFileCount > MAX_FILES)
return MAPI_E_TOO_MANY_FILES ;
if ( (!(flFlags & MAPI_DIALOG)) && (lpMessage->lpRecips == NULL) )
return MAPI_E_UNKNOWN_RECIPIENT ;
if (!lhSession || pNsMapi->IsValidSession(lhSession) != S_OK)
{
FLAGS LoginFlag ;
if ( (flFlags & MAPI_LOGON_UI) && (flFlags & MAPI_NEW_SESSION) )
LoginFlag = MAPI_LOGON_UI | MAPI_NEW_SESSION ;
else if (flFlags & MAPI_LOGON_UI)
LoginFlag = MAPI_LOGON_UI ;
hr = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, LoginFlag, 0, &lhSession) ;
if (hr != SUCCESS_SUCCESS)
return MAPI_E_LOGIN_FAILURE ;
bTempSession = TRUE ;
}
// we need to deal with null data passed in by MAPI clients, specially when MAPI_DIALOG is set.
// The MS COM type lib code generated by MIDL for the MS COM interfaces checks for these parameters
// to be non null, although null is a valid value for them here.
nsMapiRecipDesc * lpRecips ;
nsMapiFileDesc * lpFiles ;
nsMapiMessage Message ;
memset (&Message, 0, sizeof (nsMapiMessage) ) ;
nsMapiRecipDesc Recipient ;
memset (&Recipient, 0, sizeof (nsMapiRecipDesc) );
nsMapiFileDesc Files ;
memset (&Files, 0, sizeof (nsMapiFileDesc) ) ;
if(!lpMessage)
{
lpMessage = &Message ;
}
if(!lpMessage->lpRecips)
{
lpRecips = &Recipient ;
}
else
lpRecips = lpMessage->lpRecips ;
if(!lpMessage->lpFiles)
{
lpFiles = &Files ;
}
else
lpFiles = lpMessage->lpFiles ;
HANDLE hEvent = CreateEvent (NULL, FALSE, FALSE, (LPCTSTR) MAPI_SENDCOMPLETE_EVENT) ;
hr = pNsMapi->SendMail (lhSession, lpMessage,
(short) lpMessage->nRecipCount, lpRecips,
(short) lpMessage->nFileCount, lpFiles,
flFlags, ulReserved);
// we are seeing a problem when using Word, although we return success from the MAPI support
// MS COM interface in mozilla, we are getting this error here. This is a temporary hack !!
if (hr == 0x800703e6)
hr = SUCCESS_SUCCESS;
if (hr == SUCCESS_SUCCESS)
WaitForSingleObject (hEvent, INFINITE) ;
CloseHandle (hEvent) ;
if (bTempSession)
MAPILogoff (lhSession, ulUIParam, 0,0) ;
return hr ;
}
ULONG FAR PASCAL MAPISendDocuments(ULONG ulUIParam, LPTSTR lpszDelimChar, LPTSTR lpszFilePaths,
LPTSTR lpszFileNames, ULONG ulReserved)
{
LHANDLE lhSession ;
nsIMapi *pNsMapi = NULL;
if (!InitMozillaReference(&pNsMapi))
return MAPI_E_FAILURE;
unsigned long result = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, MAPI_LOGON_UI, 0, &lhSession) ;
if (result != SUCCESS_SUCCESS)
return MAPI_E_LOGIN_FAILURE ;
HRESULT hr;
HANDLE hEvent = CreateEvent (NULL, FALSE, FALSE, (LPCTSTR) MAPI_SENDCOMPLETE_EVENT) ;
hr = pNsMapi->SendDocuments(lhSession, (LPTSTR) lpszDelimChar, (LPTSTR) lpszFilePaths,
(LPTSTR) lpszFileNames, ulReserved) ;
if (hr == SUCCESS_SUCCESS)
WaitForSingleObject (hEvent, INFINITE) ;
CloseHandle (hEvent) ;
MAPILogoff (lhSession, ulUIParam, 0,0) ;
return hr ;
}
ULONG FAR PASCAL MAPIFindNext(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageType,
LPTSTR lpszSeedMessageID, FLAGS flFlags, ULONG ulReserved,
LPTSTR lpszMessageID)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIReadMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
FLAGS flFlags, ULONG ulReserved, lpMapiMessage FAR *lppMessage)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPISaveMail(LHANDLE lhSession, ULONG ulUIParam, lpMapiMessage lpMessage,
FLAGS flFlags, ULONG ulReserved, LPTSTR lpszMessageID)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIDeleteMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
FLAGS flFlags, ULONG ulReserved)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIAddress(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszCaption,
ULONG nEditFields, LPTSTR lpszLabels, ULONG nRecips,
lpMapiRecipDesc lpRecips, FLAGS flFlags,
ULONG ulReserved, LPULONG lpnNewRecips,
lpMapiRecipDesc FAR *lppNewRecips)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIDetails(LHANDLE lhSession, ULONG ulUIParam, lpMapiRecipDesc lpRecip,
FLAGS flFlags, ULONG ulReserved)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIResolveName(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszName,
FLAGS flFlags, ULONG ulReserved, lpMapiRecipDesc FAR *lppRecip)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIFreeBuffer(LPVOID pv)
{
return MAPI_E_FAILURE;
}
ULONG FAR PASCAL GetMapiDllVersion()
{
return 94;
}

View File

@@ -1,62 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corp.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH=..\..\..
MODULE = mozMapi32
EXPORT_LIBRARY = $(MODULE)
LIBRARY_NAME = $(MODULE)
DEFFILE = Mapi32.def
REQUIRES = MapiProxy \
msgMapi \
xpcom \
string \
$(NULL)
include <$(DEPTH)\config\config.mak>
###############################################################
LCFLAGS=-DUNICODE -D_UNICODE
OBJS= .\$(OBJDIR)\MapiDll.obj \
$(NULL)
WIN_LIBS= ole32.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,47 +0,0 @@
; ***** BEGIN LICENSE BLOCK *****
; Version: MPL 1.1/GPL 2.0/LGPL 2.1
;
; The contents of this file are subject to the Mozilla 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/MPL/
;
; 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.
;
; The Initial Developer of the Original Code is
; Netscape Communications Corp.
; Portions created by the Initial Developer are Copyright (C) 2001
; the Initial Developer. All Rights Reserved.
;
; Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
;
; Alternatively, the contents of this file may be used under the terms of
; either the GNU General Public License Version 2 or later (the "GPL"), or
; the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
; in which case the provisions of the GPL or the LGPL are applicable instead
; of those above. If you wish to allow use of your version of this file only
; under the terms of either the GPL or the LGPL, and not to allow others to
; use your version of this file under the terms of the MPL, indicate your
; decision by deleting the provisions above and replace them with the notice
; and other provisions required by the GPL or the LGPL. If you do not delete
; the provisions above, a recipient may use your version of this file under
; the terms of any one of the MPL, the GPL or the LGPL.
;
; ***** END LICENSE BLOCK *****
LIBRARY MapiProxy.dll
DESCRIPTION 'Proxy/Stub DLL'
EXPORTS
DllGetClassObject @1 PRIVATE
DllCanUnloadNow @2 PRIVATE
GetProxyDllInfo @3 PRIVATE
DllRegisterServer @4 PRIVATE
DllUnregisterServer @5 PRIVATE

View File

@@ -1,68 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corp.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH=..\..\..\..
MODULE = MapiProxy
EXPORT_LIBRARY = $(MODULE)
LIBRARY_NAME = $(MODULE)
DEFFILE = MapiProxy.def
include <$(DEPTH)\config\config.mak>
##################################################################
LCFLAGS=-DREGISTER_PROXY_DLL -DUNICODE -D_UNICODE
OBJS= .\$(OBJDIR)\dlldata.obj \
.\$(OBJDIR)\msgMapi_p.obj \
.\$(OBJDIR)\msgMapi_i.obj \
$(NULL)
WIN_LIBS= rpcrt4.lib
EXPORTS= msgMapi.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>
msgMapi.h msgMapi_p.c msgMapi_i.c dlldata.c : msgMapi.idl
midl $(UNICODE_FLAGS) msgMapi.idl
clobber::
rm -f dlldata.c msgMapi_i.c msgMapi_p.c msgMapi.h

View File

@@ -1,114 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// This idl will be compiled by MIDL. MS-COM is used
// as brdige between MAPI clients and the Mozilla.
import "unknwn.idl";
typedef wchar_t LOGIN_PW_TYPE[256];
typedef struct
{
unsigned long ulReserved;
unsigned long flFlags; /* Flags */
unsigned long nPosition_NotUsed; /* character in text to be replaced by attachment */
LPTSTR lpszPathName; /* Full path name including file name */
LPTSTR lpszFileName; /* Real (original) file name */
unsigned char * lpFileType_NotUsed ;
} nsMapiFileDesc, * lpnsMapiFileDesc;
typedef struct
{
unsigned long ulReserved;
unsigned long ulRecipClass; /* MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG */
LPTSTR lpszName; /* Recipient name to display */
LPTSTR lpszAddress; /* Recipient email address */
unsigned long ulEIDSize_NotUsed;
unsigned char * lpEntryID_NotUsed ;
} nsMapiRecipDesc, * lpnsMapiRecipDesc;
typedef struct
{
unsigned long ulReserved;
LPTSTR lpszSubject; /* Message Subject */
LPTSTR lpszNoteText; /* Message Text */
LPTSTR lpszMessageType_NotUsed;
LPTSTR lpszDateReceived_notUsed; /* in YYYY/MM/DD HH:MM format */
LPTSTR lpszConversationID_NotUsed; /* conversation thread ID */
unsigned long flFlags; /* unread,return receipt */
lpnsMapiRecipDesc lpOriginator; /* Originator descriptor */
unsigned long nRecipCount; /* Number of recipients */
lpnsMapiRecipDesc lpRecips; /* Recipient descriptors */
unsigned long nFileCount; /* # of file attachments */
lpnsMapiFileDesc lpFiles; /* Attachment descriptors */
} nsMapiMessage, * lpnsMapiMessage;
[
object,
uuid(6EDCD38E-8861-11d5-A3DD-00B0D0F3BAA7),
helpstring("nsIMapi Inteface"),
pointer_default(unique)
]
interface nsIMapi : IUnknown
{
HRESULT Login(unsigned long aUIArg, LOGIN_PW_TYPE aLogin,
LOGIN_PW_TYPE aPassWord, unsigned long aFlags,
[out] unsigned long *aSessionId);
HRESULT Initialize();
HRESULT IsValid();
HRESULT IsValidSession([in] unsigned long aSession);
HRESULT SendMail([in] unsigned long aSession, [in] lpnsMapiMessage aMessage,
[in] short aRecipCount, [in, size_is(aRecipCount)] lpnsMapiRecipDesc aRecips,
[in] short aFileCount, [in, size_is(aFileCount)] lpnsMapiFileDesc aFiles,
[in] unsigned long aFlags, [in] unsigned long aReserved) ;
HRESULT SendDocuments( [in] unsigned long aSession,
[in] LPTSTR aDelimChar, [in] LPTSTR aFilePaths,
[in] LPTSTR aFileNames, [in] ULONG aFlags ) ;
HRESULT Logoff (unsigned long aSession);
HRESULT CleanUp();
};

View File

@@ -1,41 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corp.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Srilatha Moturi (srilatha@netscape.com)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH=..\..\..
DIRS= build public src
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,49 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Srilatha Moturi <srilatha@netscape.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH=..\..\..\..
MODULE=msgMapi
XPIDL_MODULE=mapihook
XPIDLSRCS = \
.\nsIMapiRegistry.idl \
.\nsIMapiSupport.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,70 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIDOMWindow;
/**
* This interface provides support for registering Mozilla as the default
* Mail Client. This interface can also be used to get/set the user preference
* for the default Mail Client.
*
*/
[scriptable, uuid(c5be14ba-4e0a-4eec-a1b8-04363761d63c)]
interface nsIMapiRegistry: nsISupports {
/** This is set to TRUE if Mozilla is the default Application
*/
attribute boolean isDefaultMailClient;
/** This is set TRUE only once per session.
*/
readonly attribute boolean showDialog;
/** This will bring the dialog asking the user if he/she wants to set
* Mozilla as default Mail Client.
* Call this only if Mozilla is not the default Mail client
*/
void showMailIntegrationDialog(in nsIDOMWindow parentWindow);
};
%{C++
#define NS_IMAPIREGISTRY_CONTRACTID "@mozilla.org/mapiregistry;1"
#define NS_IMAPIREGISTRY_CLASSNAME "Mozilla MAPI Registry"
%}

View File

@@ -1,64 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/**
* This interface provides support for registering Mozilla as a COM component
* for extending the use of Mail/News through Simple MAPI.
*
*/
[noscript, uuid(8967fed2-c8bb-11d5-a3e9-00b0d0f3baa7)]
interface nsIMapiSupport : nsISupports {
/** Initiates MAPI support
*/
void initializeMAPISupport();
/** Shuts down the MAPI support
*/
void shutdownMAPISupport();
};
%{C++
#define NS_IMAPISUPPORT_CONTRACTID "@mozilla.org/mapisupport;1"
#define NS_IMAPISUPPORT_CLASSNAME "Mozilla MAPI Support"
%}

View File

@@ -1,323 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika <kkhandrika@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#undef _UNICODE
#undef UNICODE
#include <objbase.h>
#include "nsString.h"
#include "Registry.h"
#define MAPI_PROXY_DLL_NAME "MapiProxy.dll"
#define MAPI_STARTUP_ARG " /MAPIStartUp"
#define MAX_SIZE 2048
// Size of a CLSID as a string
const int CLSID_STRING_SIZE = 39;
// Proxy/Stub Dll Routines
typedef HRESULT (__stdcall ProxyServer)();
// Convert a CLSID to a char string.
BOOL CLSIDtochar(const CLSID& clsid, char* szCLSID,
int length)
{
LPOLESTR wszCLSID = NULL;
// Get CLSID
HRESULT hr = StringFromCLSID(clsid, &wszCLSID);
if (FAILED(hr))
return FALSE;
// Covert from wide characters to non-wide.
wcstombs(szCLSID, wszCLSID, length);
// Free memory.
CoTaskMemFree(wszCLSID);
return TRUE;
}
// Create a key and set its value.
BOOL setKeyAndValue(nsCAutoString keyName, const char* subKey,
const char* theValue)
{
HKEY hKey;
BOOL retValue = TRUE;
nsCAutoString theKey(keyName);
if (subKey != NULL)
{
theKey += "\\";
theKey += subKey;
}
// Create and open key and subkey.
long lResult = RegCreateKeyEx(HKEY_CLASSES_ROOT, theKey.get(),
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &hKey, NULL);
if (lResult != ERROR_SUCCESS)
return FALSE ;
// Set the Value.
if (theValue != NULL)
{
lResult = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE *)theValue,
strlen(theValue)+1);
if (lResult != ERROR_SUCCESS)
retValue = FALSE;
}
RegCloseKey(hKey);
return TRUE;
}
// Delete a key and all of its descendents.
LONG recursiveDeleteKey(HKEY hKeyParent, // Parent of key to delete
const char* lpszKeyChild) // Key to delete
{
// Open the child.
HKEY hKeyChild ;
LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyChild, 0,
KEY_ALL_ACCESS, &hKeyChild) ;
if (lRes != ERROR_SUCCESS)
{
return lRes ;
}
// Enumerate all of the decendents of this child.
FILETIME time ;
char szBuffer[MAX_SIZE] ;
DWORD dwSize = MAX_SIZE ;
while (RegEnumKeyEx(hKeyChild, 0, szBuffer, &dwSize, NULL,
NULL, NULL, &time) == S_OK)
{
// Delete the decendents of this child.
lRes = recursiveDeleteKey(hKeyChild, szBuffer) ;
if (lRes != ERROR_SUCCESS)
{
// Cleanup before exiting.
RegCloseKey(hKeyChild) ;
return lRes;
}
dwSize = MAX_SIZE;
}
// Close the child.
RegCloseKey(hKeyChild) ;
// Delete this child.
return RegDeleteKey(hKeyParent, lpszKeyChild) ;
}
void RegisterProxy()
{
HINSTANCE h = NULL;
ProxyServer *RegisterFunc = NULL;
char szModule[MAX_SIZE];
char *pTemp = NULL;
HMODULE hModule = GetModuleHandle(NULL);
DWORD dwResult = ::GetModuleFileName(hModule, szModule,
sizeof(szModule)/sizeof(char));
if (dwResult == 0)
return;
pTemp = strrchr(szModule, '\\');
if (pTemp == NULL)
return;
*pTemp = '\0';
nsCAutoString proxyPath(szModule);
proxyPath += "\\";
proxyPath += MAPI_PROXY_DLL_NAME;
h = LoadLibrary(proxyPath.get());
if (h == NULL)
return;
RegisterFunc = (ProxyServer *) GetProcAddress(h, "DllRegisterServer");
if (RegisterFunc)
RegisterFunc();
FreeLibrary(h);
}
void UnRegisterProxy()
{
HINSTANCE h = NULL;
ProxyServer *UnRegisterFunc = NULL;
char szModule[MAX_SIZE];
char *pTemp = NULL;
HMODULE hModule = GetModuleHandle(NULL);
DWORD dwResult = ::GetModuleFileName(hModule, szModule,
sizeof(szModule)/sizeof(char));
if (dwResult == 0)
return;
pTemp = strrchr(szModule, '\\');
if (pTemp == NULL)
return;
*pTemp = '\0';
nsCAutoString proxyPath(szModule);
proxyPath += "\\";
proxyPath += MAPI_PROXY_DLL_NAME;
h = LoadLibrary(proxyPath.get());
if (h == NULL)
return;
UnRegisterFunc = (ProxyServer *) GetProcAddress(h, "DllUnregisterServer");
if (UnRegisterFunc)
UnRegisterFunc();
FreeLibrary(h);
}
// Register the component in the registry.
HRESULT RegisterServer(const CLSID& clsid, // Class ID
const char* szFriendlyName, // Friendly Name
const char* szVerIndProgID, // Programmatic
const char* szProgID) // IDs
{
HMODULE hModule = GetModuleHandle(NULL);
char szModuleName[MAX_SIZE];
char szCLSID[CLSID_STRING_SIZE];
nsCAutoString independentProgId(szVerIndProgID);
nsCAutoString progId(szProgID);
DWORD dwResult = ::GetModuleFileName(hModule, szModuleName,
sizeof(szModuleName)/sizeof(char));
if (dwResult == 0)
return S_FALSE;
nsCAutoString moduleName(szModuleName);
nsCAutoString registryKey("CLSID\\");
moduleName += MAPI_STARTUP_ARG;
// Convert the CLSID into a char.
if (!CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)))
return S_FALSE;
registryKey += szCLSID;
// Add the CLSID to the registry.
if (!setKeyAndValue(registryKey, NULL, szFriendlyName))
return S_FALSE;
if (!setKeyAndValue(registryKey, "LocalServer32", moduleName.get()))
return S_FALSE;
// Add the ProgID subkey under the CLSID key.
if (!setKeyAndValue(registryKey, "ProgID", szProgID))
return S_FALSE;
// Add the version-independent ProgID subkey under CLSID key.
if (!setKeyAndValue(registryKey, "VersionIndependentProgID", szVerIndProgID))
return S_FALSE;
// Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT.
if (!setKeyAndValue(independentProgId, NULL, szFriendlyName))
return S_FALSE;
if (!setKeyAndValue(independentProgId, "CLSID", szCLSID))
return S_FALSE;
if (!setKeyAndValue(independentProgId, "CurVer", szProgID))
return S_FALSE;
// Add the versioned ProgID subkey under HKEY_CLASSES_ROOT.
if (!setKeyAndValue(progId, NULL, szFriendlyName))
return S_FALSE;
if (!setKeyAndValue(progId, "CLSID", szCLSID))
return S_FALSE;
RegisterProxy();
return S_OK;
}
LONG UnregisterServer(const CLSID& clsid, // Class ID
const char* szVerIndProgID, // Programmatic
const char* szProgID) // IDs
{
LONG lResult = S_OK;
// Convert the CLSID into a char.
char szCLSID[CLSID_STRING_SIZE];
if (!CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)))
return S_FALSE;
UnRegisterProxy();
nsCAutoString registryKey("CLSID\\");
registryKey += szCLSID;
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, registryKey.get());
if (lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND)
return lResult;
registryKey += "\\LocalServer32";
// Delete only the path for this server.
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, registryKey.get());
if (lResult != ERROR_SUCCESS && lResult != ERROR_FILE_NOT_FOUND)
return lResult;
// Delete the version-independent ProgID Key.
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szVerIndProgID);
if (lResult != ERROR_SUCCESS && lResult != ERROR_FILE_NOT_FOUND)
return lResult;
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szProgID);
return lResult;
}

View File

@@ -1,56 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Krishna Mohan Khandrika <kkhandrika@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _REGISTRY_H_
#define _REGISTRY_H_
#include <objbase.h>
// This function will register a component in the Registry.
HRESULT RegisterServer(const CLSID& clsid,
const char* szFriendlyName,
const char* szVerIndProgID,
const char* szProgID) ;
// This function will unregister a component.
HRESULT UnregisterServer(const CLSID& clsid,
const char* szVerIndProgID,
const char* szProgID) ;
#endif

View File

@@ -1,107 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Srilatha Moturi <srilatha@netscape.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH=..\..\..\..
MODULE = msgMapi
MAKE_OBJ_TYPE = DLL
LIBRARY_NAME=$(MODULE)
MODULE_NAME = $(MODULE)
REQUIRES = xpcom \
string \
MapiProxy \
appshell \
windowwatcher \
dom \
profile \
msgbase \
pref \
msgbaseutil \
msgcompo \
mailnews \
necko \
intl \
editor \
msgdb \
uriloader \
appstartup \
$(NULL)
include <$(DEPTH)\config\config.mak>
############################################################################
LCFLAGS=-DUNICODE -D_UNICODE
OBJS= \
..\build\$(OBJDIR)\msgMapi_i.obj \
.\$(OBJDIR)\msgMapiFactory.obj \
.\$(OBJDIR)\msgMapiHook.obj \
.\$(OBJDIR)\msgMapiImp.obj \
.\$(OBJDIR)\msgMapiMain.obj \
.\$(OBJDIR)\msgMapiSupport.obj \
.\$(OBJDIR)\nsMapiRegistry.obj \
.\$(OBJDIR)\nsMapiRegistryUtils.obj \
.\$(OBJDIR)\Registry.obj \
$(NULL)
LLIBS= \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\msgbsutl.lib \
$(LIBNSPR) \
$(NULL)
WIN_LIBS= \
ole32.lib \
$(NULL)
EXPORTS= \
msgMapiFactory.h \
msgMapiHook.h \
msgMapiImp.h \
msgMapiMain.h \
msgMapiSupport.h \
nsMapiRegistry.h \
nsMapiRegistryUtils.h \
Registry.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,118 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#undef UNICODE
#undef _UNICODE
#include "msgMapiFactory.h"
#include "msgMapiImp.h"
#include "msgMapi.h"
CMapiFactory ::CMapiFactory()
: m_cRef(1)
{
}
CMapiFactory::~CMapiFactory()
{
}
STDMETHODIMP CMapiFactory::QueryInterface(const IID& aIid, void** aPpv)
{
if ((aIid == IID_IUnknown) || (aIid == IID_IClassFactory))
{
*aPpv = static_cast<IClassFactory*>(this);
}
else
{
*aPpv = nsnull;
return E_NOINTERFACE;
}
reinterpret_cast<IUnknown*>(*aPpv)->AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG) CMapiFactory::AddRef()
{
return (PR_AtomicIncrement(&m_cRef));
}
STDMETHODIMP_(ULONG) CMapiFactory::Release()
{
PRInt32 temp;
temp = PR_AtomicDecrement(&m_cRef);
if (m_cRef == 0)
{
delete this;
return 0;
}
return temp;
}
STDMETHODIMP CMapiFactory::CreateInstance(IUnknown* aUnknownOuter,
const IID& aIid,
void** aPpv)
{
// Cannot aggregate.
if (aUnknownOuter != nsnull)
{
return CLASS_E_NOAGGREGATION ;
}
// Create component.
CMapiImp* pImp = new CMapiImp();
if (pImp == nsnull)
{
return E_OUTOFMEMORY ;
}
// Get the requested interface.
HRESULT hr = pImp->QueryInterface(aIid, aPpv);
// Release the IUnknown pointer.
// (If QueryInterface failed, component will delete itself.)
pImp->Release();
return hr;
}
STDMETHODIMP CMapiFactory::LockServer(PRBool aLock)
{
return S_OK ;
}

View File

@@ -1,69 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef MSG_MAPI_FACTORY_H
#define MSG_MAPI_FACTORY_H
#include <windows.h>
#include <objbase.h>
#include "nspr.h"
class CMapiFactory : public IClassFactory
{
public :
// IUnknown
STDMETHODIMP QueryInterface (REFIID aIid, void** aPpv);
STDMETHODIMP_(ULONG) AddRef(void);
STDMETHODIMP_(ULONG) Release(void);
// IClassFactory
STDMETHODIMP CreateInstance (LPUNKNOWN aUnkOuter, REFIID aIid, void **aPpv);
STDMETHODIMP LockServer (BOOL aLock);
CMapiFactory ();
~CMapiFactory ();
private :
PRInt32 m_cRef;
};
#endif // MSG_MAPI_FACTORY_H

View File

@@ -1,777 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
* Contributor(s): Srilatha Moturi (srilatha@netscape.com)
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#define MAPI_STARTUP_ARG "/MAPIStartUp"
#define MAPI_STARTUP_ARG "/MAPIStartUp"
#include <mapidefs.h>
#include <mapi.h>
#include <tchar.h>
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsISupports.h"
#include "nsIPromptService.h"
#include "nsAppShellCIDs.h"
#include "nsIDOMWindowInternal.h"
#include "nsIAppShellService.h"
#include "nsINativeAppSupport.h"
#include "nsICmdLineService.h"
#include "nsIProfileInternal.h"
#include "nsIMsgAccountManager.h"
#include "nsIDOMWindowInternal.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsMsgBaseCID.h"
#include "nsIStringBundle.h"
#include "nsIPref.h"
#include "nsString.h"
#include "nsIMsgAttachment.h"
#include "nsIMsgCompFields.h"
#include "nsIMsgComposeParams.h"
#include "nsIMsgCompose.h"
#include "nsMsgCompCID.h"
#include "nsIMsgSend.h"
#include "nsIProxyObjectManager.h"
#include "nsIMsgComposeService.h"
#include "nsProxiedService.h"
#include "nsSpecialSystemDirectory.h"
#include "nsMsgI18N.h"
#include "msgMapi.h"
#include "msgMapiHook.h"
#include "msgMapiSupport.h"
#include "msgMapiMain.h"
#include "nsNetUtil.h"
static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID);
class nsMAPISendListener : public nsIMsgSendListener
{
public:
virtual ~nsMAPISendListener() { }
// nsISupports interface
NS_DECL_ISUPPORTS
/* void OnStartSending (in string aMsgID, in PRUint32 aMsgSize); */
NS_IMETHOD OnStartSending(const char *aMsgID, PRUint32 aMsgSize) { return NS_OK; }
/* void OnProgress (in string aMsgID, in PRUint32 aProgress, in PRUint32 aProgressMax); */
NS_IMETHOD OnProgress(const char *aMsgID, PRUint32 aProgress, PRUint32 aProgressMax) { return NS_OK;}
/* void OnStatus (in string aMsgID, in wstring aMsg); */
NS_IMETHOD OnStatus(const char *aMsgID, const PRUnichar *aMsg) { return NS_OK;}
/* void OnStopSending (in string aMsgID, in nsresult aStatus, in wstring aMsg, in nsIFileSpec returnFileSpec); */
NS_IMETHOD OnStopSending(const char *aMsgID, nsresult aStatus, const PRUnichar *aMsg,
nsIFileSpec *returnFileSpec) {
m_done = PR_TRUE;
HANDLE hEvent = CreateEvent (NULL, FALSE, FALSE, (LPCTSTR) MAPI_SENDCOMPLETE_EVENT) ;
SetEvent (hEvent) ;
CloseHandle (hEvent) ;
return NS_OK ;
}
/* void OnSendNotPerformed */
NS_IMETHOD OnSendNotPerformed(const char *aMsgID, nsresult aStatus)
{
return OnStopSending(aMsgID, aStatus, nsnull, nsnull) ;
}
/* void OnGetDraftFolderURI (); */
NS_IMETHOD OnGetDraftFolderURI(const char *aFolderURI) {return NS_OK;}
static nsresult CreateMAPISendListener( nsIMsgSendListener **ppListener);
PRBool IsDone() { return m_done ; }
protected :
nsMAPISendListener() {
NS_INIT_REFCNT();
m_done = PR_FALSE;
}
PRBool m_done;
};
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMAPISendListener, nsIMsgSendListener)
nsresult nsMAPISendListener::CreateMAPISendListener( nsIMsgSendListener **ppListener)
{
NS_ENSURE_ARG_POINTER(ppListener) ;
*ppListener = new nsMAPISendListener();
if (! *ppListener)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*ppListener);
return NS_OK;
}
PRBool nsMapiHook::isMapiService = PR_FALSE;
PRBool nsMapiHook::Initialize()
{
nsresult rv;
nsCOMPtr<nsINativeAppSupport> native;
nsCOMPtr<nsICmdLineService> cmdLineArgs(do_GetService(kCmdLineServiceCID, &rv));
if (NS_FAILED(rv)) return PR_FALSE;
nsCOMPtr<nsIAppShellService> appShell (do_GetService( "@mozilla.org/appshell/appShellService;1", &rv));
if (NS_FAILED(rv)) return PR_FALSE;
rv = appShell->GetNativeAppSupport( getter_AddRefs( native ));
if (NS_FAILED(rv)) return PR_FALSE;
rv = native->EnsureProfile(cmdLineArgs);
if (NS_FAILED(rv)) return PR_FALSE;
return PR_TRUE;
}
void nsMapiHook::CleanUp()
{
// This routine will be fully implemented in future
// to cleanup mapi related stuff inside mozilla code.
}
PRBool nsMapiHook::DisplayLoginDialog(PRBool aLogin, PRUnichar **aUsername, \
PRUnichar **aPassword)
{
nsresult rv;
PRBool btnResult = PR_FALSE;
nsCOMPtr<nsIAppShellService> appShell(do_GetService( "@mozilla.org/appshell/appShellService;1", &rv));
if (NS_FAILED(rv) || !appShell) return PR_FALSE;
nsCOMPtr<nsIPromptService> dlgService(do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv));
if (NS_SUCCEEDED(rv) && dlgService)
{
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
if (NS_FAILED(rv) || !bundleService) return PR_FALSE;
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(MAPI_PROPERTIES_CHROME, getter_AddRefs(bundle));
if (NS_FAILED(rv) || !bundle) return PR_FALSE;
nsCOMPtr<nsIStringBundle> brandBundle;
rv = bundleService->CreateBundle(
"chrome://global/locale/brand.properties",
getter_AddRefs(brandBundle));
if (NS_FAILED(rv)) return PR_FALSE;
nsXPIDLString brandName;
rv = brandBundle->GetStringFromName(
NS_LITERAL_STRING("brandShortName").get(),
getter_Copies(brandName));
if (NS_FAILED(rv)) return PR_FALSE;
nsXPIDLString loginTitle;
const PRUnichar *brandStrings[] = { brandName.get() };
NS_NAMED_LITERAL_STRING(loginTitlePropertyTag, "loginTitle");
const PRUnichar *dTitlePropertyTag = loginTitlePropertyTag.get();
rv = bundle->FormatStringFromName(dTitlePropertyTag, brandStrings, 1,
getter_Copies(loginTitle));
if (NS_FAILED(rv)) return PR_FALSE;
if (aLogin)
{
nsXPIDLString loginText;
rv = bundle->GetStringFromName(NS_LITERAL_STRING("loginTextwithName").get(),
getter_Copies(loginText));
if (NS_FAILED(rv) || !loginText) return PR_FALSE;
rv = dlgService->PromptUsernameAndPassword(nsnull, loginTitle,
loginText, aUsername, aPassword,
nsnull, PR_FALSE, &btnResult);
}
else
{
//nsString loginString;
nsXPIDLString loginText;
const PRUnichar *userNameStrings[] = { *aUsername };
NS_NAMED_LITERAL_STRING(loginTextPropertyTag, "loginText");
const PRUnichar *dpropertyTag = loginTextPropertyTag.get();
rv = bundle->FormatStringFromName(dpropertyTag, userNameStrings, 1,
getter_Copies(loginText));
if (NS_FAILED(rv)) return PR_FALSE;
rv = dlgService->PromptPassword(nsnull, loginTitle, loginText,
aPassword, nsnull, PR_FALSE, &btnResult);
}
}
return btnResult;
}
PRBool nsMapiHook::VerifyUserName(const PRUnichar *aUsername, char **aIdKey)
{
nsresult rv;
if (aUsername == nsnull)
return PR_FALSE;
nsCOMPtr<nsIMsgAccountManager> accountManager(do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv)) return PR_FALSE;
nsCOMPtr<nsISupportsArray> identities;
rv = accountManager->GetAllIdentities(getter_AddRefs(identities));
if (NS_FAILED(rv)) return PR_FALSE;
PRUint32 numIndentities;
identities->Count(&numIndentities);
for (PRUint32 i = 0; i < numIndentities; i++)
{
// convert supports->Identity
nsCOMPtr<nsISupports> thisSupports;
rv = identities->GetElementAt(i, getter_AddRefs(thisSupports));
if (NS_FAILED(rv)) continue;
nsCOMPtr<nsIMsgIdentity> thisIdentity(do_QueryInterface(thisSupports, &rv));
if (NS_SUCCEEDED(rv) && thisIdentity)
{
nsXPIDLCString email;
rv = thisIdentity->GetEmail(getter_Copies(email));
if (NS_FAILED(rv)) continue;
// get the username from the email and compare with the username
nsCAutoString aEmail(email.get());
PRInt32 index = aEmail.FindChar('@');
if (index != -1)
aEmail.Truncate(index);
if (nsDependentString(aUsername) == NS_ConvertASCIItoUCS2(aEmail)) // == overloaded
return NS_SUCCEEDED(thisIdentity->GetKey(aIdKey));
}
}
return PR_FALSE;
}
PRBool
nsMapiHook::IsBlindSendAllowed()
{
PRBool enabled = PR_FALSE;
PRBool warn = PR_TRUE;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
if (prefs) {
prefs->GetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND,&warn);
prefs->GetBoolPref(PREF_MAPI_BLIND_SEND_ENABLED,&enabled);
}
if (!enabled)
return PR_FALSE;
if (!warn)
return PR_TRUE; // Everything is okay.
nsresult rv;
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
if (NS_FAILED(rv) || !bundleService) return PR_FALSE;
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(MAPI_PROPERTIES_CHROME, getter_AddRefs(bundle));
if (NS_FAILED(rv) || !bundle) return PR_FALSE;
nsXPIDLString warningMsg;
rv = bundle->GetStringFromName(NS_LITERAL_STRING("mapiBlindSendWarning").get(),
getter_Copies(warningMsg));
if (NS_FAILED(rv)) return PR_FALSE;
nsXPIDLString dontShowAgainMessage;
rv = bundle->GetStringFromName(NS_LITERAL_STRING("mapiBlindSendDontShowAgain").get(),
getter_Copies(dontShowAgainMessage));
if (NS_FAILED(rv)) return PR_FALSE;
nsCOMPtr<nsIPromptService> dlgService(do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv));
if (NS_FAILED(rv) || !dlgService) return PR_FALSE;
PRBool continueToWarn = PR_TRUE;
PRBool okayToContinue = PR_FALSE;
dlgService->ConfirmCheck(nsnull, nsnull, warningMsg, dontShowAgainMessage, &continueToWarn, &okayToContinue);
if (!continueToWarn && okayToContinue && prefs)
prefs->SetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND,PR_FALSE);
return okayToContinue;
}
// this is used for Send without UI
nsresult nsMapiHook::BlindSendMail (unsigned long aSession, nsIMsgCompFields * aCompFields)
{
nsresult rv = NS_OK ;
if (!IsBlindSendAllowed())
return NS_ERROR_FAILURE;
/** create nsIMsgComposeParams obj and other fields to populate it **/
// get parent window
nsCOMPtr<nsIAppShellService> appService = do_GetService( "@mozilla.org/appshell/appShellService;1", &rv);
if (NS_FAILED(rv)|| (!appService) ) return rv ;
nsCOMPtr<nsIDOMWindowInternal> hiddenWindow;
rv = appService->GetHiddenDOMWindow(getter_AddRefs(hiddenWindow));
if ( NS_FAILED(rv) ) return rv ;
// smtp password and Logged in used IdKey from MapiConfig (session obj)
nsMAPIConfiguration * pMapiConfig = nsMAPIConfiguration::GetMAPIConfiguration() ;
if (!pMapiConfig) return NS_ERROR_FAILURE ; // get the singelton obj
PRUnichar * password = pMapiConfig->GetPassword(aSession) ;
// password
nsCAutoString smtpPassword ;
smtpPassword.AssignWithConversion (password) ;
// Id key
char * MsgIdKey = pMapiConfig->GetIdKey(aSession) ;
// get the MsgIdentity for the above key using AccountManager
nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService (NS_MSGACCOUNTMANAGER_CONTRACTID) ;
if (NS_FAILED(rv) || (!accountManager) ) return rv ;
nsCOMPtr <nsIMsgIdentity> pMsgId ;
rv = accountManager->GetIdentity (MsgIdKey, getter_AddRefs(pMsgId)) ;
if (NS_FAILED(rv) ) return rv ;
// create a send listener to get back the send status
nsCOMPtr <nsIMsgSendListener> sendListener ;
rv = nsMAPISendListener::CreateMAPISendListener(getter_AddRefs(sendListener)) ;
if (NS_FAILED(rv) || (!sendListener) ) return rv;
// create the compose params object
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
if (NS_FAILED(rv) || (!pMsgComposeParams) ) return rv ;
// populate the compose params
pMsgComposeParams->SetType(nsIMsgCompType::New);
pMsgComposeParams->SetFormat(nsIMsgCompFormat::Default);
pMsgComposeParams->SetIdentity(pMsgId);
pMsgComposeParams->SetComposeFields(aCompFields);
pMsgComposeParams->SetSendListener(sendListener) ;
pMsgComposeParams->SetSmtpPassword(smtpPassword.get());
// create the nsIMsgCompose object to send the object
nsCOMPtr<nsIMsgCompose> pMsgCompose (do_CreateInstance(NS_MSGCOMPOSE_CONTRACTID, &rv));
if (NS_FAILED(rv) || (!pMsgCompose) ) return rv ;
/** initialize nsIMsgCompose, Send the message, wait for send completion response **/
rv = pMsgCompose->Initialize(hiddenWindow, pMsgComposeParams) ;
if (NS_FAILED(rv)) return rv ;
pMsgCompose->SendMsg(nsIMsgSend::nsMsgDeliverNow, pMsgId, nsnull) ;
if (NS_FAILED(rv)) return rv ;
// assign to interface pointer from nsCOMPtr to facilitate typecast below
nsIMsgSendListener * pSendListener = sendListener ;
// we need to wait here to make sure that we return only after send is completed
// so we will have a event loop here which will process the events till the Send IsDone.
nsCOMPtr<nsIEventQueueService> pEventQService = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
nsCOMPtr<nsIEventQueue> eventQueue;
pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(eventQueue));
while ( !((nsMAPISendListener *) pSendListener)->IsDone() )
eventQueue->ProcessPendingEvents();
return rv ;
}
// this is used to populate comp fields with Unicode data
nsresult nsMapiHook::PopulateCompFields(lpnsMapiMessage aMessage,
nsIMsgCompFields * aCompFields)
{
nsresult rv = NS_OK ;
if (aMessage->lpOriginator)
{
PRUnichar * From = aMessage->lpOriginator->lpszAddress ;
aCompFields->SetFrom (From) ;
}
nsAutoString To ;
nsAutoString Cc ;
nsAutoString Bcc ;
nsAutoString Comma ;
Comma.AssignWithConversion(",");
if (aMessage->lpRecips)
{
for (int i=0 ; i < (int) aMessage->nRecipCount ; i++)
{
if (aMessage->lpRecips[i].lpszAddress)
{
switch (aMessage->lpRecips[i].ulRecipClass)
{
case MAPI_TO :
if (To.Length() > 0)
To += Comma ;
To += (PRUnichar *) aMessage->lpRecips[i].lpszAddress ;
break ;
case MAPI_CC :
if (Cc.Length() > 0)
Cc += Comma ;
Cc += (PRUnichar *) aMessage->lpRecips[i].lpszAddress ;
break ;
case MAPI_BCC :
if (Bcc.Length() > 0)
Bcc += Comma ;
Bcc += (PRUnichar *) aMessage->lpRecips[i].lpszAddress ;
break ;
}
}
}
}
// set To, Cc, Bcc
aCompFields->SetTo (To.get()) ;
aCompFields->SetCc (Cc.get()) ;
aCompFields->SetBcc (Bcc.get()) ;
// set subject
if (aMessage->lpszSubject)
{
PRUnichar * Subject = aMessage->lpszSubject ;
aCompFields->SetSubject(Subject) ;
}
// handle attachments as File URL
rv = HandleAttachments (aCompFields, aMessage->nFileCount, aMessage->lpFiles, PR_TRUE) ;
if (NS_FAILED(rv)) return rv ;
// set body
if (aMessage->lpszNoteText)
{
PRUnichar * Body = aMessage->lpszNoteText ;
rv = aCompFields->SetBody(Body) ;
}
#ifdef RAJIV_DEBUG
// testing what all was set in CompFields
printf ("To : %S \n", To.get()) ;
printf ("CC : %S \n", Cc.get() ) ;
printf ("BCC : %S \n", Bcc.get() ) ;
#endif
return rv ;
}
nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 aFileCount,
lpnsMapiFileDesc aFiles, BOOL aIsUnicode)
{
nsresult rv = NS_OK ;
nsCAutoString Attachments ;
nsCAutoString TempFiles ;
nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
if (NS_FAILED(rv) || (!pFile) ) return rv ;
for (int i=0 ; i < aFileCount ; i++)
{
if (aFiles[i].lpszPathName)
{
// check if attachment exists
if (aIsUnicode)
pFile->InitWithUnicodePath (aFiles[i].lpszPathName) ;
else
pFile->InitWithPath ((char *) aFiles[i].lpszPathName) ;
PRBool bExist ;
rv = pFile->Exists(&bExist) ;
if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;
// create Msg attachment object
nsCOMPtr<nsIMsgAttachment> attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv);
if (NS_FAILED(rv) || (!attachment) ) return rv ;
// set url
nsXPIDLCString pURL ;
NS_GetURLSpecFromFile(pFile, getter_Copies(pURL));
attachment->SetUrl(pURL) ;
if (aFiles[i].lpszFileName)
{
if (! aIsUnicode)
{
nsAutoString realFileName ;
realFileName.AssignWithConversion ((char *) aFiles[i].lpszFileName) ;
attachment->SetName(realFileName.get()) ;
// attachment->SetName( (nsDependentString(aFiles[i].lpszFileName)).get() );
}
else
attachment->SetName(aFiles[i].lpszFileName) ;
}
attachment->SetTemporary(PR_FALSE) ;
rv = aCompFields->AddAttachment (attachment);
}
}
return rv ;
}
// this is used to convert non Unicode data and then populate comp fields
nsresult nsMapiHook::PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage,
nsIMsgCompFields * aCompFields)
{
nsresult rv = NS_OK ;
if (aMessage->lpOriginator)
{
nsAutoString From ;
From.AssignWithConversion((char *) aMessage->lpOriginator->lpszAddress);
aCompFields->SetFrom (From.get()) ;
}
nsAutoString To ;
nsAutoString Cc ;
nsAutoString Bcc ;
nsAutoString Comma ;
Comma.AssignWithConversion(",");
if (aMessage->lpRecips)
{
for (int i=0 ; i < (int) aMessage->nRecipCount ; i++)
{
if (aMessage->lpRecips[i].lpszAddress)
{
switch (aMessage->lpRecips[i].ulRecipClass)
{
case MAPI_TO :
if (To.Length() > 0)
To += Comma ;
To.AppendWithConversion ((char *) aMessage->lpRecips[i].lpszAddress);
break ;
case MAPI_CC :
if (Cc.Length() > 0)
Cc += Comma ;
Cc.AppendWithConversion ((char *) aMessage->lpRecips[i].lpszAddress);
break ;
case MAPI_BCC :
if (Bcc.Length() > 0)
Bcc += Comma ;
Bcc.AppendWithConversion ((char *) aMessage->lpRecips[i].lpszAddress) ;
break ;
}
}
}
}
// set To, Cc, Bcc
aCompFields->SetTo (To.get()) ;
aCompFields->SetCc (Cc.get()) ;
aCompFields->SetBcc (Bcc.get()) ;
nsCAutoString platformCharSet;
// set subject
if (aMessage->lpszSubject)
{
nsAutoString Subject ;
if (platformCharSet.IsEmpty())
platformCharSet.Assign(nsMsgI18NFileSystemCharset());
rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszSubject, Subject);
if (NS_FAILED(rv)) return rv ;
aCompFields->SetSubject(Subject.get()) ;
}
// handle attachments as File URL
rv = HandleAttachments (aCompFields, aMessage->nFileCount, aMessage->lpFiles, PR_FALSE) ;
if (NS_FAILED(rv)) return rv ;
// set body
if (aMessage->lpszNoteText)
{
nsAutoString Body ;
if (platformCharSet.IsEmpty())
platformCharSet.Assign(nsMsgI18NFileSystemCharset());
rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszNoteText, Body);
if (NS_FAILED(rv)) return rv ;
rv = aCompFields->SetBody(Body.get()) ;
}
#ifdef RAJIV_DEBUG
// testing what all was set in CompFields
printf ("To : %S \n", To.get()) ;
printf ("CC : %S \n", Cc.get() ) ;
printf ("BCC : %S \n", Bcc.get() ) ;
#endif
return rv ;
}
// this is used to populate the docs as attachments in the Comp fields for Send Documents
nsresult nsMapiHook::PopulateCompFieldsForSendDocs(nsIMsgCompFields * aCompFields, ULONG aFlags,
PRUnichar * aDelimChar, PRUnichar * aFilePaths)
{
nsAutoString strDelimChars ;
nsString strFilePaths;
nsresult rv = NS_OK ;
if (aFlags & MAPI_UNICODE)
{
if (aDelimChar)
strDelimChars.Assign (aDelimChar) ;
if (aFilePaths)
strFilePaths.Assign (aFilePaths) ;
}
else
{
if (aDelimChar)
strDelimChars.AssignWithConversion ((char*) aDelimChar) ;
if (aFilePaths)
strFilePaths.AssignWithConversion ((char *) aFilePaths) ;
}
// check for comma in filename
if (strDelimChars.Find (",") == kNotFound) // if comma is not in the delimiter specified by user
{
if (strFilePaths.Find(",") != kNotFound) // if comma found in filenames return error
return NS_ERROR_FILE_INVALID_PATH ;
}
nsCString Attachments ;
// only 1 file is to be sent, no delim specified
if ((!strDelimChars.Length()) && (strFilePaths.Length()>0))
{
nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
if (NS_FAILED(rv) || (!pFile) ) return rv ;
pFile->InitWithUnicodePath (strFilePaths.get()) ;
PRBool bExist ;
rv = pFile->Exists(&bExist) ;
if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;
nsXPIDLCString pURL ;
NS_GetURLSpecFromFile(pFile, getter_Copies(pURL));
if (pURL)
Attachments.Assign(pURL) ;
// set attachments for comp field and return
rv = aCompFields->SetAttachments (Attachments.get());
return rv ;
}
// multiple files to be sent, delim specified
nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
if (NS_FAILED(rv) || (!pFile) ) return rv ;
PRInt32 offset = 0 ;
PRInt32 FilePathsLen = strFilePaths.Length() ;
if (FilePathsLen)
{
PRUnichar * newFilePaths = (PRUnichar *) strFilePaths.get() ;
while (offset != kNotFound)
{
nsString RemainingPaths ;
RemainingPaths.Assign(newFilePaths) ;
offset = RemainingPaths.Find (strDelimChars) ;
if (offset != kNotFound)
{
RemainingPaths.SetLength (offset) ;
if ((offset + strDelimChars.Length()) < FilePathsLen)
newFilePaths += offset + strDelimChars.Length() ;
}
pFile->InitWithUnicodePath (RemainingPaths.get()) ;
#ifdef RAJIV_DEBUG
printf ("File : %S \n", RemainingPaths.get()) ;
#endif
PRBool bExist ;
rv = pFile->Exists(&bExist) ;
if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;
nsXPIDLCString pURL ;
NS_GetURLSpecFromFile(pFile, getter_Copies(pURL));
if (pURL)
{
if (Attachments.Length() > 0)
Attachments.Append(",") ;
Attachments.Append(pURL) ;
}
}
rv = aCompFields->SetAttachments (Attachments.get());
}
return rv ;
}
// this used for Send with UI
nsresult nsMapiHook::ShowComposerWindow (unsigned long aSession, nsIMsgCompFields * aCompFields)
{
nsresult rv = NS_OK ;
// create a send listener to get back the send status
nsCOMPtr <nsIMsgSendListener> sendListener ;
rv = nsMAPISendListener::CreateMAPISendListener(getter_AddRefs(sendListener)) ;
if (NS_FAILED(rv) || (!sendListener) ) return rv ;
// create the compose params object
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
if (NS_FAILED(rv) || (!pMsgComposeParams) ) return rv ;
// populate the compose params
pMsgComposeParams->SetType(nsIMsgCompType::New);
pMsgComposeParams->SetFormat(nsIMsgCompFormat::Default);
pMsgComposeParams->SetComposeFields(aCompFields);
pMsgComposeParams->SetSendListener(sendListener) ;
/** get the nsIMsgComposeService object to open the compose window **/
nsCOMPtr <nsIMsgComposeService> compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ;
if (NS_FAILED(rv)|| (!compService) ) return rv ;
rv = compService->OpenComposeWindowWithParams(nsnull, pMsgComposeParams) ;
if (NS_FAILED(rv)) return rv ;
return rv ;
}

View File

@@ -1,66 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef MSG_MAPI_HOOK_H_
#define MSG_MAPI_HOOK_H_
#include "prtypes.h"
class nsMapiHook
{
public :
static PRBool Initialize();
static PRBool DisplayLoginDialog(PRBool aLogin, PRUnichar **aUsername,
PRUnichar **aPassword);
static PRBool VerifyUserName(const PRUnichar *aUsername, char **aIdKey);
static PRBool IsBlindSendAllowed () ;
static nsresult BlindSendMail (unsigned long aSession, nsIMsgCompFields * aCompFields) ;
static nsresult ShowComposerWindow (unsigned long aSession, nsIMsgCompFields * aCompFields) ;
static nsresult PopulateCompFields(lpnsMapiMessage aMessage, nsIMsgCompFields * aCompFields) ;
static nsresult PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage,
nsIMsgCompFields * aCompFields) ;
static nsresult PopulateCompFieldsForSendDocs(nsIMsgCompFields * aCompFields,
ULONG aFlags, LPTSTR aDelimChar, LPTSTR aFilePaths) ;
static nsresult HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 aFileCount,
lpnsMapiFileDesc aFiles, BOOL aIsUnicode) ;
static void CleanUp();
static PRBool isMapiService;
};
#endif // MSG_MAPI_HOOK_H_

View File

@@ -1,266 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <mapidefs.h>
#include <mapi.h>
#include "msgMapi.h"
#include "msgMapiImp.h"
#include "msgMapiFactory.h"
#include "msgMapiMain.h"
#include "nsMsgCompFields.h"
#include "msgMapiHook.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsMsgCompCID.h"
CMapiImp::CMapiImp()
: m_cRef(1)
{
m_Lock = PR_NewLock();
}
CMapiImp::~CMapiImp()
{
if (m_Lock)
PR_DestroyLock(m_Lock);
}
STDMETHODIMP CMapiImp::QueryInterface(const IID& aIid, void** aPpv)
{
if (aIid == IID_IUnknown)
{
*aPpv = static_cast<nsIMapi*>(this);
}
else if (aIid == IID_nsIMapi)
{
*aPpv = static_cast<nsIMapi*>(this);
}
else
{
*aPpv = nsnull;
return E_NOINTERFACE;
}
reinterpret_cast<IUnknown*>(*aPpv)->AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG) CMapiImp::AddRef()
{
return PR_AtomicIncrement(&m_cRef);
}
STDMETHODIMP_(ULONG) CMapiImp::Release()
{
PRInt32 temp;
temp = PR_AtomicDecrement(&m_cRef);
if (m_cRef == 0)
{
delete this;
return 0;
}
return temp;
}
STDMETHODIMP CMapiImp::IsValid()
{
return S_OK;
}
STDMETHODIMP CMapiImp::IsValidSession(unsigned long aSession)
{
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
if (pConfig && pConfig->IsSessionValid(aSession))
return S_OK;
return E_FAIL;
}
STDMETHODIMP CMapiImp::Initialize()
{
HRESULT hr = E_FAIL;
if (!m_Lock)
return E_FAIL;
PR_Lock(m_Lock);
// Initialize MAPI Configuration
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
if (pConfig != nsnull)
if (nsMapiHook::Initialize())
hr = S_OK;
PR_Unlock(m_Lock);
return hr;
}
STDMETHODIMP CMapiImp::Login(unsigned long aUIArg, LOGIN_PW_TYPE aLogin, LOGIN_PW_TYPE aPassWord,
unsigned long aFlags, unsigned long *aSessionId)
{
HRESULT hr = E_FAIL;
PRBool bNewSession = PR_FALSE;
char *id_key = nsnull;
if (aFlags & MAPI_NEW_SESSION)
bNewSession = PR_TRUE;
// Check For Profile Name
if (aLogin != nsnull && aLogin[0] != '\0')
{
if (nsMapiHook::VerifyUserName(aLogin, &id_key) == PR_FALSE)
{
*aSessionId = MAPI_E_LOGIN_FAILURE;
return hr;
}
}
// finally register(create) the session.
PRUint32 nSession_Id;
PRInt16 nResult = 0;
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
if (pConfig != nsnull)
nResult = pConfig->RegisterSession(aUIArg, aLogin, aPassWord,
(aFlags & MAPI_FORCE_DOWNLOAD), bNewSession,
&nSession_Id, id_key);
switch (nResult)
{
case -1 :
{
*aSessionId = MAPI_E_TOO_MANY_SESSIONS;
return hr;
}
case 0 :
{
*aSessionId = MAPI_E_INSUFFICIENT_MEMORY;
return hr;
}
default :
{
*aSessionId = nSession_Id;
break;
}
}
return S_OK;
}
STDMETHODIMP CMapiImp::SendMail( unsigned long aSession, lpnsMapiMessage aMessage,
short aRecipCount, lpnsMapiRecipDesc aRecips , short aFileCount, lpnsMapiFileDesc aFiles ,
unsigned long aFlags, unsigned long aReserved)
{
nsresult rv = NS_OK ;
// Assign the pointers in the aMessage struct to the array of Recips and Files
// recieved here from MS COM. These are used in BlindSendMail and ShowCompWin fns
aMessage->lpRecips = aRecips ;
aMessage->lpFiles = aFiles ;
/** create nsIMsgCompFields obj and populate it **/
nsCOMPtr<nsIMsgCompFields> pCompFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv) ;
if (NS_FAILED(rv) || (!pCompFields) ) return MAPI_E_INSUFFICIENT_MEMORY ;
if (aFlags & MAPI_UNICODE)
rv = nsMapiHook::PopulateCompFields(aMessage, pCompFields) ;
else
rv = nsMapiHook::PopulateCompFieldsWithConversion(aMessage, pCompFields) ;
if (NS_SUCCEEDED (rv))
{
// see flag to see if UI needs to be brought up
if (!(aFlags & MAPI_DIALOG))
{
rv = nsMapiHook::BlindSendMail(aSession, pCompFields);
}
else
{
rv = nsMapiHook::ShowComposerWindow(aSession, pCompFields);
}
}
return nsMAPIConfiguration::GetMAPIErrorFromNSError (rv) ;
}
STDMETHODIMP CMapiImp::SendDocuments( unsigned long aSession, LPTSTR aDelimChar,
LPTSTR aFilePaths, LPTSTR aFileNames, ULONG aFlags)
{
nsresult rv = NS_OK ;
/** create nsIMsgCompFields obj and populate it **/
nsCOMPtr<nsIMsgCompFields> pCompFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv) ;
if (NS_FAILED(rv) || (!pCompFields) ) return MAPI_E_INSUFFICIENT_MEMORY ;
if (aFilePaths)
{
rv = nsMapiHook::PopulateCompFieldsForSendDocs(pCompFields, aFlags, aDelimChar, aFilePaths) ;
}
if (NS_SUCCEEDED (rv))
rv = nsMapiHook::ShowComposerWindow(aSession, pCompFields);
return nsMAPIConfiguration::GetMAPIErrorFromNSError (rv) ;
}
STDMETHODIMP CMapiImp::Logoff (unsigned long aSession)
{
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
if (pConfig->UnRegisterSession((PRUint32)aSession))
return S_OK;
return E_FAIL;
}
STDMETHODIMP CMapiImp::CleanUp()
{
nsMapiHook::CleanUp();
return S_OK;
}

View File

@@ -1,92 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef MSG_MAPI_IMP_H
#define MSG_MAPI_IMP_H
#include <windows.h>
#include <mapi.h>
#include "msgMapi.h"
#include "nsXPIDLString.h"
#include "nspr.h"
const CLSID CLSID_CMapiImp = {0x29f458be, 0x8866, 0x11d5, {0xa3, 0xdd, 0x0, 0xb0, 0xd0, 0xf3, 0xba, 0xa7}};
// this class implements the MS COM interface nsIMapi that provides the methods
// called by mapi32.dll to perform the mail operations as specified by MAPI.
// These class methods in turn use the Mozilla Mail XPCOM interfaces to do so.
class CMapiImp : public nsIMapi
{
public :
// IUnknown
STDMETHODIMP QueryInterface(const IID& aIid, void** aPpv);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
// Interface INsMapi
STDMETHODIMP Login(unsigned long aUIArg, LOGIN_PW_TYPE aLogin,
LOGIN_PW_TYPE aPassWord, unsigned long aFlags,
unsigned long *aSessionId);
STDMETHODIMP SendMail( unsigned long aSession, lpnsMapiMessage aMessage,
short aRecipCount, lpnsMapiRecipDesc aRecips ,
short aFileCount, lpnsMapiFileDesc aFiles ,
unsigned long aFlags, unsigned long aReserved) ;
STDMETHODIMP SendDocuments( unsigned long aSession, LPTSTR aDelimChar,
LPTSTR aFilePaths, LPTSTR aFileNames, ULONG aFlags);
STDMETHODIMP Initialize();
STDMETHODIMP IsValid();
STDMETHODIMP IsValidSession(unsigned long aSession);
STDMETHODIMP Logoff (unsigned long aSession);
STDMETHODIMP CleanUp();
CMapiImp();
~CMapiImp();
private :
PRLock *m_Lock;
PRInt32 m_cRef;
};
#endif // MSG_MAPI_IMP_H

View File

@@ -1,376 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <mapidefs.h>
#include <mapi.h>
#include "msgCore.h"
#include "nsMsgComposeStringBundle.h"
#include "msgMapiMain.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
// move to xpcom bug 81956.
class nsPRUintKey : public nsHashKey {
protected:
PRUint32 mKey;
public:
nsPRUintKey(PRUint32 key) : mKey(key) {}
PRUint32 HashCode(void) const {
return mKey;
}
PRBool Equals(const nsHashKey *aKey) const {
return mKey == ((const nsPRUintKey *) aKey)->mKey;
}
nsHashKey *Clone() const {
return new nsPRUintKey(mKey);
}
PRUint32 GetValue() { return mKey; }
};
//
nsMAPIConfiguration *nsMAPIConfiguration::m_pSelfRef = nsnull;
PRUint32 nsMAPIConfiguration::session_generator = 0;
PRUint32 nsMAPIConfiguration::sessionCount = 0;
nsMAPIConfiguration *nsMAPIConfiguration::GetMAPIConfiguration()
{
if (m_pSelfRef == nsnull)
m_pSelfRef = new nsMAPIConfiguration();
return m_pSelfRef;
}
nsMAPIConfiguration::nsMAPIConfiguration()
: m_nMaxSessions(MAX_SESSIONS)
{
m_Lock = PR_NewLock();
}
static PRBool
FreeSessionMapEntries(nsHashKey *aKey, void *aData, void* aClosure)
{
nsMAPISession *pTemp = (nsMAPISession*) aData;
if (pTemp)
{
delete pTemp;
pTemp = nsnull;
}
return PR_TRUE;
}
static PRBool
FreeProfileMapEntries(nsHashKey *aKey, void *aData, void* aClosure)
{
return PR_TRUE;
}
nsMAPIConfiguration::~nsMAPIConfiguration()
{
if (m_Lock)
PR_DestroyLock(m_Lock);
m_SessionMap.Reset(FreeSessionMapEntries);
m_ProfileMap.Reset(FreeProfileMapEntries);
}
void nsMAPIConfiguration::OpenConfiguration()
{
// No. of max. sessions is set to MAX_SESSIONS. In future
// if it is decided to have configuration (registry)
// parameter, this function can be used to set the
// max sessions;
return;
}
PRInt16 nsMAPIConfiguration::RegisterSession(PRUint32 aHwnd,
const PRUnichar *aUserName, const PRUnichar *aPassword,
PRBool aForceDownLoad, PRBool aNewSession,
PRUint32 *aSession, char *aIdKey)
{
PRInt16 nResult = 0;
PRUint32 n_SessionId = 0;
PR_Lock(m_Lock);
// Check whether max sessions is exceeded
if (sessionCount >= m_nMaxSessions)
{
PR_Unlock(m_Lock);
return -1;
}
if (aUserName != nsnull && aUserName[0] != '\0')
{
nsStringKey usernameKey(aUserName);
n_SessionId = (PRUint32) m_ProfileMap.Get(&usernameKey);
}
// try to share a session; if not create a session
if (n_SessionId > 0)
{
nsPRUintKey sessionKey(n_SessionId);
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
if (pTemp != nsnull)
{
pTemp->IncrementSession();
*aSession = n_SessionId;
nResult = 1;
}
}
else if (aNewSession || n_SessionId == 0) // checking for n_SessionId is a concession
{
// create a new session ; if new session is specified OR there is no session
nsMAPISession *pTemp = nsnull;
pTemp = new nsMAPISession(aHwnd, aUserName,
aPassword, aForceDownLoad, aIdKey);
if (pTemp != nsnull)
{
session_generator++;
// I don't think there will be (2 power 32) sessions alive
// in a cycle. This is an assumption
if (session_generator == 0)
session_generator++;
nsPRUintKey sessionKey(session_generator);
m_SessionMap.Put(&sessionKey, pTemp);
if (aUserName != nsnull && aUserName[0] != '\0')
{
nsStringKey usernameKey(aUserName);
m_ProfileMap.Put(&usernameKey, (void*)session_generator);
}
*aSession = session_generator;
sessionCount++;
nResult = 1;
}
}
PR_Unlock(m_Lock);
return nResult;
}
PRBool nsMAPIConfiguration::UnRegisterSession(PRUint32 aSessionID)
{
PRBool bResult = PR_FALSE;
PR_Lock(m_Lock);
if (aSessionID != 0)
{
nsPRUintKey sessionKey(aSessionID);
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
if (pTemp != nsnull)
{
if (pTemp->DecrementSession() == 0)
{
if (pTemp->m_pProfileName.get() != nsnull)
{
nsStringKey stringKey(pTemp->m_pProfileName.get());
m_ProfileMap.Remove(&stringKey);
}
m_SessionMap.Remove(&sessionKey);
sessionCount--;
bResult = PR_TRUE;
}
}
}
PR_Unlock(m_Lock);
return bResult;
}
PRBool nsMAPIConfiguration::IsSessionValid(PRUint32 aSessionID)
{
if (aSessionID == 0)
return PR_FALSE;
PRBool retValue = PR_FALSE;
nsPRUintKey sessionKey(aSessionID);
PR_Lock(m_Lock);
retValue = m_SessionMap.Exists(&sessionKey);
PR_Unlock(m_Lock);
return retValue;
}
PRUnichar *nsMAPIConfiguration::GetPassword(PRUint32 aSessionID)
{
PRUnichar *pResult = nsnull;
PR_Lock(m_Lock);
if (aSessionID != 0)
{
nsPRUintKey sessionKey(aSessionID);
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
if (pTemp)
{
pResult = pTemp->GetPassword();
}
}
PR_Unlock(m_Lock);
return pResult;
}
char *nsMAPIConfiguration::GetIdKey(PRUint32 aSessionID)
{
char *pResult = nsnull;
PR_Lock(m_Lock);
if (aSessionID != 0)
{
nsPRUintKey sessionKey(aSessionID);
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
if (pTemp)
{
pResult = pTemp->GetIdKey();
}
}
PR_Unlock(m_Lock);
return pResult;
}
// util func
HRESULT nsMAPIConfiguration::GetMAPIErrorFromNSError (nsresult res)
{
HRESULT hr = SUCCESS_SUCCESS ;
if (NS_SUCCEEDED (hr)) return hr ;
// if failure return the related MAPI failure code
switch (res)
{
case NS_MSG_NO_RECIPIENTS :
hr = MAPI_E_BAD_RECIPTYPE ;
break ;
case NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS :
hr = MAPI_E_INVALID_RECIPS ;
break ;
case NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER :
hr = MAPI_E_LOGIN_FAILURE ;
break ;
case NS_MSG_UNABLE_TO_OPEN_FILE :
case NS_MSG_UNABLE_TO_OPEN_TMP_FILE :
case NS_MSG_COULDNT_OPEN_FCC_FOLDER :
case NS_ERROR_FILE_INVALID_PATH :
hr = MAPI_E_ATTACHMENT_OPEN_FAILURE ;
break ;
case NS_ERROR_FILE_TARGET_DOES_NOT_EXIST :
hr = MAPI_E_ATTACHMENT_NOT_FOUND ;
break ;
case NS_MSG_CANCELLING :
hr = MAPI_E_USER_ABORT ;
break ;
case NS_MSG_ERROR_WRITING_FILE :
case NS_MSG_UNABLE_TO_SAVE_TEMPLATE :
case NS_MSG_UNABLE_TO_SAVE_DRAFT :
hr = MAPI_E_ATTACHMENT_WRITE_FAILURE ;
break ;
default :
hr = MAPI_E_FAILURE ;
break ;
}
return hr ;
}
nsMAPISession::nsMAPISession(PRUint32 aHwnd, const PRUnichar *aUserName,\
const PRUnichar *aPassword, \
PRBool aForceDownLoad, char *aKey)
: m_bIsForcedDownLoad(aForceDownLoad),
m_hAppHandle(aHwnd),
m_nShared(1),
m_pIdKey(aKey)
{
m_pProfileName.Assign(aUserName);
m_pPassword.Assign(aPassword);
}
nsMAPISession::~nsMAPISession()
{
if (m_pIdKey != nsnull)
{
delete [] m_pIdKey;
m_pIdKey = nsnull;
}
}
PRUint32 nsMAPISession::IncrementSession()
{
return ++m_nShared;
}
PRUint32 nsMAPISession::DecrementSession()
{
return --m_nShared;
}
PRUint32 nsMAPISession::GetSessionCount()
{
return m_nShared;
}
PRUnichar *nsMAPISession::GetPassword()
{
return (PRUnichar *)m_pPassword.get();
}
char *nsMAPISession::GetIdKey()
{
return m_pIdKey;
}

View File

@@ -1,112 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef MSG_MAPI_MAIN_H_
#define NSG_MAPI_MAIN_H_
#define MAX_NAME_LEN 256
#define MAX_PW_LEN 256
#define MAX_SESSIONS 50
#define MAPI_SENDCOMPLETE_EVENT "SendCompletionEvent"
#define MAPI_PROPERTIES_CHROME "chrome://messenger-mapi/locale/mapi.properties"
#define PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND "mapi.blind-send.warn"
#define PREF_MAPI_BLIND_SEND_ENABLED "mapi.blind-send.enabled"
#include "nsXPIDLString.h"
#include "nspr.h"
#include "nsString.h"
#include "nsHashtable.h"
class nsMAPIConfiguration
{
private :
static PRUint32 session_generator;
static PRUint32 sessionCount;
static nsMAPIConfiguration *m_pSelfRef;
PRLock *m_Lock;
PRUint32 m_nMaxSessions;
nsHashtable m_ProfileMap;
nsHashtable m_SessionMap;
nsMAPIConfiguration();
public :
static nsMAPIConfiguration *GetMAPIConfiguration();
void OpenConfiguration();
PRInt16 RegisterSession(PRUint32 aHwnd, const PRUnichar *aUserName, \
const PRUnichar *aPassword, PRBool aForceDownLoad, \
PRBool aNewSession, PRUint32 *aSession, char *aIdKey);
PRBool IsSessionValid(PRUint32 aSessionID);
PRBool UnRegisterSession(PRUint32 aSessionID);
PRUnichar *GetPassword(PRUint32 aSessionID);
char *GetIdKey(PRUint32 aSessionID);
~nsMAPIConfiguration();
// a util func
static HRESULT GetMAPIErrorFromNSError (nsresult res) ;
};
class nsMAPISession
{
friend class nsMAPIConfiguration;
private :
PRBool m_bIsForcedDownLoad;
PRBool m_bApp_or_Service;
PRUint32 m_hAppHandle;
PRUint32 m_nShared;
char *m_pIdKey;
nsString m_pProfileName;
nsString m_pPassword;
public :
nsMAPISession(PRUint32 aHwnd, const PRUnichar *aUserName, \
const PRUnichar *aPassword, \
PRBool aForceDownLoad, char *aKey);
PRUint32 IncrementSession();
PRUint32 DecrementSession();
PRUint32 GetSessionCount();
PRUnichar *nsMAPISession::GetPassword();
char *nsMAPISession::GetIdKey();
~nsMAPISession();
};
#endif // MSG_MAPI_MAIN_H_

View File

@@ -1,209 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "objbase.h"
#include "nsISupports.h"
#include "nsIGenericFactory.h"
#include "nsIObserverService.h"
#include "nsIAppStartupNotifier.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsICategoryManager.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranchInternal.h"
#include "msgMapiSupport.h"
#include "nsMapiRegistryUtils.h"
#include "nsMapiRegistry.h"
#include "msgMapiImp.h"
/** Implementation of the nsIMapiSupport interface.
* Use standard implementation of nsISupports stuff.
*/
NS_IMPL_THREADSAFE_ISUPPORTS2(nsMapiSupport, nsIMapiSupport, nsIObserver);
static NS_METHOD nsMapiRegistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath, const char *registryLocation, const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> categoryManager(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
rv = categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY, "Mapi Support",
"service," NS_IMAPISUPPORT_CONTRACTID, PR_TRUE, PR_TRUE, nsnull);
return rv ;
}
NS_IMETHODIMP
nsMapiSupport::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
nsresult rv = NS_OK ;
if (!nsCRT::strcmp(aTopic, "profile-after-change"))
return InitializeMAPISupport();
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
return ShutdownMAPISupport();
if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID))
{
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject, &rv);
if (NS_FAILED(rv)) return rv;
// which preference changed?
if (!nsCRT::strcmp(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, NS_ConvertUCS2toUTF8(aData).get()))
{
PRBool bIsDefault = PR_FALSE ;
rv = prefs->GetBoolPref(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, &bIsDefault);
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsIMapiRegistry> mapiRegistry = do_CreateInstance(NS_IMAPIREGISTRY_CONTRACTID, &rv) ;
if (NS_FAILED(rv)) return rv;
return mapiRegistry->SetIsDefaultMailClient(bIsDefault) ;
}
return rv ;
}
nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1", &rv));
if (NS_FAILED(rv)) return rv;
rv = observerService->AddObserver(this,"profile-after-change", PR_FALSE);
if (NS_FAILED(rv)) return rv;
rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIPrefBranchInternal> prefInternal = do_QueryInterface(prefs, &rv);
if (NS_FAILED(rv)) return rv;
rv = prefInternal->AddObserver(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, this, PR_FALSE);
if (NS_FAILED(rv)) return rv;
return rv;
}
nsMapiSupport::nsMapiSupport()
: m_dwRegister(0),
m_nsMapiFactory(nsnull)
{
NS_INIT_ISUPPORTS();
}
nsMapiSupport::~nsMapiSupport()
{
}
NS_IMETHODIMP
nsMapiSupport::InitializeMAPISupport()
{
::CoInitialize(nsnull) ;
if (m_nsMapiFactory == nsnull) // No Registering if already done. Sanity Check!!
{
m_nsMapiFactory = new CMapiFactory();
if (m_nsMapiFactory != nsnull)
{
HRESULT hr = ::CoRegisterClassObject(CLSID_CMapiImp, \
m_nsMapiFactory, \
CLSCTX_LOCAL_SERVER, \
REGCLS_MULTIPLEUSE, \
&m_dwRegister);
if (FAILED(hr))
{
m_nsMapiFactory->Release() ;
m_nsMapiFactory = nsnull;
return NS_ERROR_FAILURE;
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsMapiSupport::ShutdownMAPISupport()
{
if (m_dwRegister != 0)
::CoRevokeClassObject(m_dwRegister);
if (m_nsMapiFactory != nsnull)
{
m_nsMapiFactory->Release();
m_nsMapiFactory = nsnull;
}
::CoUninitialize();
return NS_OK ;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMapiRegistry);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMapiSupport);
// The list of components we register
static nsModuleComponentInfo components[] =
{
{
NS_IMAPIREGISTRY_CLASSNAME,
NS_IMAPIREGISTRY_CID,
NS_IMAPIREGISTRY_CONTRACTID,
nsMapiRegistryConstructor
},
{
NS_IMAPISUPPORT_CLASSNAME,
NS_IMAPISUPPORT_CID,
NS_IMAPISUPPORT_CONTRACTID,
nsMapiSupportConstructor,
nsMapiRegistrationProc,
nsnull
}
};
NS_IMPL_NSGETMODULE(msgMapiModule, components);

View File

@@ -1,66 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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
*
* The Initial Developer of the Original Code is
# Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef MSG_MAPI_SUPPORT_H_
#define MSG_MAPI_SUPPORT_H_
#include "nsIObserver.h"
#include "nsIMapiSupport.h"
#include "msgMapiFactory.h"
#define NS_IMAPISUPPORT_CID \
{0x8967fed2, 0xc8bb, 0x11d5, \
{ 0xa3, 0xe9, 0x00, 0xb0, 0xd0, 0xf3, 0xba, 0xa7 }}
class nsMapiSupport : public nsIMapiSupport,
public nsIObserver
{
public :
nsMapiSupport();
~nsMapiSupport();
// Declare all interface methods we must implement.
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIMAPISUPPORT
private :
DWORD m_dwRegister;
CMapiFactory *m_nsMapiFactory;
};
#endif // MSG_MAPI_SUPPORT_H_

View File

@@ -1,167 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIServiceManager.h"
#include "nsXPIDLString.h"
#include "nsIPromptService.h"
#include "nsIProxyObjectManager.h"
#include "nsProxiedService.h"
#include "nsMapiRegistryUtils.h"
#include "nsMapiRegistry.h"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
/** Implementation of the nsIMapiRegistry interface.
* Use standard implementation of nsISupports stuff.
*/
NS_IMPL_ISUPPORTS1(nsMapiRegistry, nsIMapiRegistry);
nsMapiRegistry::nsMapiRegistry() {
NS_INIT_ISUPPORTS();
m_ShowDialog = ! m_registryUtils.verifyRestrictedAccess();
m_DefaultMailClient = m_registryUtils.IsDefaultMailClient();
}
nsMapiRegistry::~nsMapiRegistry() {
}
NS_IMETHODIMP
nsMapiRegistry::GetIsDefaultMailClient(PRBool * retval) {
// we need to get the value from registry everytime
// because the registry settings can be changed from
// other mail applications.
*retval = m_registryUtils.IsDefaultMailClient();
return NS_OK;
}
NS_IMETHODIMP
nsMapiRegistry::GetShowDialog(PRBool * retval) {
*retval = m_ShowDialog;
return NS_OK;
}
NS_IMETHODIMP
nsMapiRegistry::SetIsDefaultMailClient(PRBool aIsDefaultMailClient)
{
nsresult rv = NS_OK ;
if (aIsDefaultMailClient)
{
rv = m_registryUtils.setDefaultMailClient();
if (NS_SUCCEEDED(rv))
m_DefaultMailClient = PR_TRUE;
else
m_registryUtils.ShowMapiErrorDialog();
}
else
{
rv = m_registryUtils.unsetDefaultMailClient();
if (NS_SUCCEEDED(rv))
m_DefaultMailClient = PR_FALSE;
else
m_registryUtils.ShowMapiErrorDialog();
}
return rv ;
}
/** This will bring up the dialog box only once per session and
* only if the current app is not default Mail Client.
* This also checks the registry if the registry key
* showMapiDialog is set
*/
NS_IMETHODIMP
nsMapiRegistry::ShowMailIntegrationDialog(nsIDOMWindow *aParentWindow) {
nsresult rv;
if (!m_ShowDialog || !m_registryUtils.getShowDialog()) return NS_OK;
nsCOMPtr<nsIPromptService> promptService(do_GetService(
"@mozilla.org/embedcomp/prompt-service;1", &rv));
if (NS_SUCCEEDED(rv) && promptService)
{
nsCOMPtr<nsIStringBundle> bundle;
rv = m_registryUtils.MakeMapiStringBundle (getter_AddRefs (bundle)) ;
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsXPIDLString dialogTitle;
const PRUnichar *brandStrings[] = { m_registryUtils.brandName() };
NS_NAMED_LITERAL_STRING(dialogTitlePropertyTag, "dialogTitle");
rv = bundle->FormatStringFromName(dialogTitlePropertyTag.get(),
brandStrings, 1,
getter_Copies(dialogTitle));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsXPIDLString dialogText;
NS_NAMED_LITERAL_STRING(dialogTextPropertyTag, "dialogText");
rv = bundle->FormatStringFromName(dialogTextPropertyTag.get(),
brandStrings, 1,
getter_Copies(dialogText));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsXPIDLString checkboxText;
rv = bundle->GetStringFromName(
NS_LITERAL_STRING("checkboxText").get(),
getter_Copies(checkboxText));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
PRBool checkValue = PR_FALSE;
PRInt32 buttonPressed = 0;
rv = promptService->ConfirmEx(aParentWindow,
dialogTitle,
dialogText.get(),
(nsIPromptService::BUTTON_TITLE_YES *
nsIPromptService::BUTTON_POS_0) +
(nsIPromptService::BUTTON_TITLE_NO *
nsIPromptService::BUTTON_POS_1),
nsnull,
nsnull,
nsnull,
checkboxText,
&checkValue,
&buttonPressed);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = m_registryUtils.SetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
"showMapiDialog", (checkValue) ? "0" : "1");
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
m_ShowDialog = PR_FALSE;
if (!buttonPressed)
rv = SetIsDefaultMailClient(PR_TRUE) ; // SetDefaultMailClient();
}
return rv;
}

View File

@@ -1,76 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsmapiregistry_h____
#define nsmapiregistry_h____
#include "nsIMapiRegistry.h"
#ifndef MAX_BUF
#define MAX_BUF 4096
#endif
/* c5be14ba-4e0a-4eec-a1b8-04363761d63c */
#define NS_IMAPIREGISTRY_CID \
{ 0xc5be14ba, 0x4e0a, 0x4eec, {0xa1, 0xb8, 0x04, 0x36, 0x37, 0x61, 0xd6, 0x3c} }
#define NS_IMAPIREGISTRY_CONTRACTID "@mozilla.org/mapiregistry;1"
#define NS_IMAPIREGISTRY_CLASSNAME "Mozilla MAPI Registry"
#define MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT "mailnews.default_mail_client"
class nsMapiRegistry : public nsIMapiRegistry {
public:
// ctor/dtor
nsMapiRegistry();
virtual ~nsMapiRegistry();
// Declare all interface methods we must implement.
NS_DECL_ISUPPORTS
NS_DECL_NSIMAPIREGISTRY
protected:
PRBool m_DefaultMailClient;
PRBool m_ShowDialog;
nsMapiRegistryUtils m_registryUtils ;
private:
// Special member to handle initialization.
PRBool mHaveBeenSet;
}; // nsMapiRegistry
#endif // nsmapiregistry_h____

View File

@@ -1,743 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#undef UNICODE
#undef _UNICODE
#include "nsIServiceManager.h"
#include "msgMapiImp.h"
#include "msgMapiMain.h"
#include "nsMapiRegistryUtils.h"
#include "nsString.h"
#include "nsIStringBundle.h"
#include "nsIPromptService.h"
#include "nsXPIDLString.h"
#include "nsSpecialSystemDirectory.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIPref.h"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define EXE_EXTENSION ".exe"
#define USERAGENT_VERSION_PREF "general.useragent.misc"
#define USERAGENT_VERSION_NS_PREF "general.useragent.vendorSub"
#define USERAGENT_PREF_PREFIX "rv:"
nsMapiRegistryUtils::nsMapiRegistryUtils()
{
m_mapiStringBundle = nsnull ;
}
const char * nsMapiRegistryUtils::thisApplication()
{
if (m_thisApp.IsEmpty()) {
char buffer[MAX_PATH] = {0};
DWORD len = ::GetModuleFileName(NULL, buffer, MAX_PATH);
if (!len) return nsnull ;
char shortPathBuf[MAX_PATH] = {0};
len = ::GetShortPathName(buffer, shortPathBuf, MAX_PATH);
if (!len) return nsnull ;
m_thisApp = buffer;
m_thisApp.ToUpperCase();
}
return m_thisApp.get() ;
}
const PRUnichar * nsMapiRegistryUtils::brandName()
{
nsresult rv;
if (m_brand.IsEmpty()) {
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(
kStringBundleServiceCID, &rv));
if (NS_SUCCEEDED(rv) && bundleService) {
nsCOMPtr<nsIStringBundle> brandBundle;
rv = bundleService->CreateBundle(
"chrome://global/locale/brand.properties",
getter_AddRefs(brandBundle));
if (NS_SUCCEEDED(rv)) {
nsXPIDLString brandName;
rv = brandBundle->GetStringFromName(
NS_LITERAL_STRING("brandShortName").get(),
getter_Copies(brandName));
if (NS_SUCCEEDED(rv)) {
m_brand = brandName ;
}
}
}
}
return m_brand.get() ;
}
const PRUnichar * nsMapiRegistryUtils::versionNo()
{
if (!m_versionNo.IsEmpty())
return m_versionNo.get() ;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
if (prefs) {
nsXPIDLCString versionStr ;
nsresult rv = prefs->GetCharPref(USERAGENT_VERSION_NS_PREF, getter_Copies(versionStr));
if (NS_SUCCEEDED(rv) && versionStr)
m_versionNo.AssignWithConversion (versionStr.get()) ;
else {
rv = prefs->GetCharPref(USERAGENT_VERSION_PREF, getter_Copies(versionStr));
if (NS_SUCCEEDED(rv) && versionStr) {
m_versionNo.AssignWithConversion (versionStr.get()) ;
m_versionNo.StripChars (USERAGENT_PREF_PREFIX) ;
}
}
}
return m_versionNo.get() ;
}
PRBool nsMapiRegistryUtils::verifyRestrictedAccess() {
char subKey[] = "Software\\Mozilla - Test Key";
PRBool result = PR_FALSE;
DWORD dwDisp = 0;
HKEY key;
// Try to create/open a subkey under HKLM.
DWORD rc = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,
subKey,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&key,
&dwDisp);
if (rc == ERROR_SUCCESS) {
// Key was opened; first close it.
::RegCloseKey(key);
// Delete it if we just created it.
switch(dwDisp) {
case REG_CREATED_NEW_KEY:
::RegDeleteKey(HKEY_LOCAL_MACHINE, subKey);
break;
case REG_OPENED_EXISTING_KEY:
break;
}
} else {
// Can't create/open it; we don't have access.
result = PR_TRUE;
}
return result;
}
nsresult nsMapiRegistryUtils::SetRegistryKey(HKEY baseKey, const char * keyName,
const char * valueName, char * value)
{
nsresult result = NS_ERROR_FAILURE;
HKEY key;
LONG rc = ::RegCreateKey(baseKey, keyName, &key);
if (rc == ERROR_SUCCESS) {
rc = ::RegSetValueEx(key, valueName, NULL, REG_SZ,
(LPBYTE)(const char*)value, strlen(value));
if (rc == ERROR_SUCCESS) {
result = NS_OK;
}
::RegCloseKey(key);
}
return result;
}
nsresult nsMapiRegistryUtils::DeleteRegistryValue(HKEY baseKey, const char * keyName,
const char * valueName)
{
nsresult result = NS_ERROR_FAILURE;
HKEY key;
LONG rc = ::RegOpenKey(baseKey, keyName, &key);
if (rc == ERROR_SUCCESS) {
rc = ::RegDeleteValue(key, valueName);
if (rc == ERROR_SUCCESS)
result = NS_OK;
::RegCloseKey(key);
}
return result;
}
void nsMapiRegistryUtils::GetRegistryKey(HKEY baseKey, const char * keyName,
const char * valueName, nsCAutoString & value)
{
HKEY key;
LONG rc = ::RegOpenKey(baseKey, keyName, &key);
if (rc == ERROR_SUCCESS) {
char buffer[MAX_PATH] = {0};
DWORD len = sizeof buffer;
rc = ::RegQueryValueEx(key, valueName, NULL, NULL,
(LPBYTE)buffer, &len);
if (rc == ERROR_SUCCESS) {
if (len)
value = buffer;
}
::RegCloseKey(key);
}
}
PRBool nsMapiRegistryUtils::IsDefaultMailClient()
{
if (!isSmartDll() && !isMozDll())
return PR_FALSE;
nsCAutoString name;
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Clients\\Mail", "", name);
if (!name.IsEmpty()) {
nsCAutoString keyName("Software\\Clients\\Mail\\");
keyName += name.get();
keyName += "\\protocols\\mailto\\shell\\open\\command";
nsCAutoString result;
GetRegistryKey(HKEY_LOCAL_MACHINE, keyName.get(), "", result);
if (!result.IsEmpty()) {
nsCAutoString strExtension;
strExtension.Assign(EXE_EXTENSION);
result.ToUpperCase();
strExtension.ToUpperCase();
PRInt32 index = result.RFind(strExtension.get());
if (index != kNotFound) {
result.Truncate(index + strExtension.Length());
}
nsCAutoString thisApp (thisApplication()) ;
return (result == thisApp);
}
}
return PR_FALSE;
}
nsresult nsMapiRegistryUtils::saveDefaultMailClient()
{
nsresult rv;
nsCAutoString name ;
GetRegistryKey(HKEY_LOCAL_MACHINE,"Software\\Clients\\Mail", "", name);
if (!name.IsEmpty()) {
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail",
(char *)name.get());
if (NS_SUCCEEDED(rv)) {
nsCAutoString keyName("Software\\Clients\\Mail\\");
keyName += name.get();
keyName += "\\protocols\\mailto\\shell\\open\\command";
nsCAutoString appPath ;
GetRegistryKey(HKEY_LOCAL_MACHINE, keyName.get(), "", appPath);
if (!appPath.IsEmpty()) {
nsCAutoString stringName("HKEY_LOCAL_MACHINE\\");
stringName += keyName.get();
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
stringName.get(), (char *)appPath.get());
}
}
}
else
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail",
"");
return rv;
}
nsresult nsMapiRegistryUtils::saveUserDefaultMailClient()
{
nsresult rv;
nsCAutoString name ;
GetRegistryKey(HKEY_CURRENT_USER,"Software\\Clients\\Mail", "", name);
if (!name.IsEmpty()) {
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"HKEY_CURRENT_USER\\Software\\Clients\\Mail",
(char *)name.get());
}
else {
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"HKEY_CURRENT_USER\\Software\\Clients\\Mail",
"");
}
return rv;
}
/**
* Check whether it is a smart dll or not. Smart dll is the one installed by
* IE5 or Outlook Express which forwards the MAPI calls to the dll based on the
* registry key setttings.
* Returns TRUE if is a smart dll.
*/
typedef HRESULT (FAR PASCAL GetOutlookVersionFunc)();
PRBool nsMapiRegistryUtils::isSmartDll()
{
char buffer[MAX_PATH] = {0};
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
return PR_FALSE;
PL_strcatn(buffer, sizeof(buffer), "\\Mapi32.dll");
HINSTANCE hInst;
GetOutlookVersionFunc *doesExist = nsnull;
hInst = LoadLibrary(buffer);
if (hInst == nsnull)
return PR_FALSE;
doesExist = (GetOutlookVersionFunc *) GetProcAddress (hInst, "GetOutlookVersion");
FreeLibrary(hInst);
return (doesExist != nsnull);
}
typedef HRESULT (FAR PASCAL GetMapiDllVersion)();
/**
* Checks whether mapi32.dll is installed by this app.
* Returns TRUE if it is.
*/
PRBool nsMapiRegistryUtils::isMozDll()
{
char buffer[MAX_PATH] = {0};
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
return PR_FALSE;
PL_strcatn(buffer, sizeof(buffer), "\\Mapi32.dll");
HINSTANCE hInst;
GetMapiDllVersion *doesExist = nsnull;
hInst = LoadLibrary(buffer);
if (hInst == nsnull)
return PR_FALSE;
doesExist = (GetMapiDllVersion *) GetProcAddress (hInst, "GetMapiDllVersion");
FreeLibrary(hInst);
return (doesExist != nsnull);
}
/** Renames Mapi32.dl in system directory to Mapi32_moz_bak.dll
* copies the mozMapi32.dll from bin directory to the system directory
*/
nsresult nsMapiRegistryUtils::CopyMozMapiToWinSysDir()
{
nsresult rv;
char buffer[MAX_PATH] = {0};
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
return NS_ERROR_FAILURE;
nsCAutoString filePath(buffer);
filePath.Append("\\Mapi32_moz_bak.dll");
nsCOMPtr<nsILocalFile> pCurrentMapiFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv) || !pCurrentMapiFile) return rv;
pCurrentMapiFile->InitWithPath(filePath.get());
nsCOMPtr<nsIFile> pMozMapiFile;
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (!directoryService) return NS_ERROR_FAILURE;
rv = directoryService->Get(NS_OS_CURRENT_PROCESS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(pMozMapiFile));
if (NS_FAILED(rv)) return rv;
pMozMapiFile->Append("mozMapi32.dll");
PRBool bExist;
rv = pMozMapiFile->Exists(&bExist);
if (NS_FAILED(rv) || !bExist) return rv;
rv = pCurrentMapiFile->Exists(&bExist);
if (NS_SUCCEEDED(rv) && bExist)
{
rv = pCurrentMapiFile->Remove(PR_FALSE);
}
if (NS_FAILED(rv)) return rv;
filePath.Assign(buffer);
filePath.Append("\\Mapi32.dll");
pCurrentMapiFile->InitWithPath(filePath.get());
rv = pCurrentMapiFile->Exists(&bExist);
if (NS_SUCCEEDED(rv) && bExist)
{
rv = pCurrentMapiFile->MoveTo(nsnull, "Mapi32_moz_bak.dll");
if (NS_FAILED(rv)) return rv;
nsCAutoString fullFilePath(buffer);
fullFilePath.Append("\\Mapi32_moz_bak.dll");
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"Mapi_backup_dll",
(char *)fullFilePath.get());
if (NS_FAILED(rv)) {
RestoreBackedUpMapiDll();
return rv;
}
}
NS_NAMED_LITERAL_STRING(fileName, "Mapi32.dll");
filePath.Assign(buffer);
pCurrentMapiFile->InitWithPath(filePath.get());
rv = pMozMapiFile->CopyToUnicode(pCurrentMapiFile, fileName.get());
if (NS_FAILED(rv))
RestoreBackedUpMapiDll();
return rv;
}
/** deletes the Mapi32.dll in system directory and renames Mapi32_moz_bak.dll
* to Mapi32.dll
*/
nsresult nsMapiRegistryUtils::RestoreBackedUpMapiDll()
{
nsresult rv;
char buffer[MAX_PATH] = {0};
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
return NS_ERROR_FAILURE;
nsCAutoString filePath(buffer);
nsCAutoString previousFileName(buffer);
filePath.Append("\\Mapi32.dll");
previousFileName.Append("\\Mapi32_moz_bak.dll");
nsCOMPtr <nsILocalFile> pCurrentMapiFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv) || !pCurrentMapiFile) return NS_ERROR_FAILURE;
pCurrentMapiFile->InitWithPath(filePath.get());
nsCOMPtr<nsILocalFile> pPreviousMapiFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv) || !pPreviousMapiFile) return NS_ERROR_FAILURE;
pPreviousMapiFile->InitWithPath(previousFileName.get());
PRBool bExist;
rv = pCurrentMapiFile->Exists(&bExist);
if (NS_SUCCEEDED(rv) && bExist) {
rv = pCurrentMapiFile->Remove(PR_FALSE);
if (NS_FAILED(rv)) return rv;
}
rv = pPreviousMapiFile->Exists(&bExist);
if (NS_SUCCEEDED(rv) && bExist)
rv = pPreviousMapiFile->MoveTo(nsnull, "Mapi32.dll");
if (NS_SUCCEEDED(rv))
DeleteRegistryValue(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"Mapi_backup_dll");
return rv;
}
/** Sets Mozilla as default Mail Client
*/
nsresult nsMapiRegistryUtils::setDefaultMailClient()
{
nsresult rv;
nsresult mailKeySet=NS_ERROR_FAILURE;
if (verifyRestrictedAccess()) return NS_ERROR_FAILURE;
if (!isSmartDll()) {
if (NS_FAILED(CopyMozMapiToWinSysDir())) return NS_ERROR_FAILURE;
}
rv = saveDefaultMailClient();
if (NS_FAILED(saveUserDefaultMailClient()) ||
NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCAutoString keyName("Software\\Clients\\Mail\\");
nsCAutoString appName (NS_ConvertUCS2toUTF8(brandName()).get());
if (!appName.IsEmpty()) {
keyName.Append(appName.get());
nsCOMPtr<nsIStringBundle> bundle;
rv = MakeMapiStringBundle (getter_AddRefs (bundle)) ;
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsXPIDLString defaultMailTitle;
const PRUnichar *keyValuePrefixStr[] = { brandName(), versionNo() };
NS_NAMED_LITERAL_STRING(defaultMailTitleTag, "defaultMailDisplayTitle");
rv = bundle->FormatStringFromName(defaultMailTitleTag.get(),
keyValuePrefixStr, 2,
getter_Copies(defaultMailTitle));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
keyName.get(),
"", NS_CONST_CAST(char *, NS_ConvertUCS2toUTF8(defaultMailTitle).get()) ) ;
}
else
rv = NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
nsCAutoString thisApp (thisApplication()) ;
if (NS_FAILED(rv)) return rv ;
nsCAutoString dllPath (thisApp) ;
PRInt32 index = dllPath.RFind("\\");
if (index != kNotFound)
dllPath.Truncate(index + 1);
dllPath += "mozMapi32.dll";
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
keyName.get(), "DLLPath",
(char *)dllPath.get());
if (NS_SUCCEEDED(rv)) {
keyName.Append("\\protocols\\mailto");
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
keyName.get(),
"", "URL:MailTo Protocol");
if (NS_SUCCEEDED(rv)) {
nsCAutoString appPath (thisApp);
appPath += " \"%1\"";
keyName.Append("\\shell\\open\\command");
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
keyName.get(),
"", (char *)appPath.get());
if (NS_SUCCEEDED(rv)) {
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Clients\\Mail",
"", (char *)appName.get());
}
if (NS_SUCCEEDED(rv)) {
nsCAutoString mailAppPath(thisApp);
mailAppPath += " -mail";
nsCAutoString appKeyName ("Software\\Clients\\Mail\\");
appKeyName.Append(appName.get());
appKeyName.Append("\\shell\\open\\command");
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
appKeyName.get(),
"", (char *)mailAppPath.get());
}
if (NS_SUCCEEDED(rv)) {
nsCAutoString iconPath(thisApp);
iconPath += ",0";
nsCAutoString iconKeyName ("Software\\Clients\\Mail\\");
iconKeyName.Append(appName.get());
iconKeyName.Append("\\DefaultIcon");
mailKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
iconKeyName.get(),
"", (char *)iconPath.get());
}
}
}
}
if (NS_SUCCEEDED(mailKeySet)) {
nsresult desktopKeySet = SetRegistryKey(HKEY_CURRENT_USER,
"Software\\Clients\\Mail",
"", (char *)appName.get());
if (NS_SUCCEEDED(desktopKeySet)) {
desktopKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"defaultMailHasBeenSet", "1");
}
::SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
(LPARAM)"Software\\Clients\\Mail");
RegisterServer(CLSID_CMapiImp, "Mozilla MAPI", "mozMapi", "mozMapi.1");
return desktopKeySet;
}
return mailKeySet;
}
/** Removes Mozilla as the default Mail client and restores the previous setting
*/
nsresult nsMapiRegistryUtils::unsetDefaultMailClient() {
nsresult result = NS_OK;
nsresult mailKeySet = NS_ERROR_FAILURE;
if (verifyRestrictedAccess()) return NS_ERROR_FAILURE;
if (!isSmartDll()) {
if (NS_FAILED(RestoreBackedUpMapiDll())) return NS_ERROR_FAILURE;
}
nsCAutoString name ;
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
"HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail", name);
nsCAutoString appName (NS_ConvertUCS2toUTF8(brandName()).get());
if (!name.IsEmpty() && !appName.IsEmpty() && name.Equals(appName)) {
nsCAutoString keyName("HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail\\");
keyName.Append(appName.get());
keyName.Append("\\protocols\\mailto\\shell\\open\\command");
nsCAutoString appPath ;
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
keyName.get(), appPath);
if (!appPath.IsEmpty()) {
keyName.Assign("Software\\Clients\\Mail\\");
keyName.Append(appName.get());
keyName.Append("\\protocols\\mailto\\shell\\open\\command");
result = SetRegistryKey(HKEY_LOCAL_MACHINE,
keyName.get(),
"", (char *)appPath.get());
if (NS_SUCCEEDED(result)) {
PRInt32 index = appPath.RFind("\\");
if (index != kNotFound)
appPath.Truncate(index + 1);
appPath += "mozMapi32.dll";
keyName.Assign("Software\\Clients\\Mail\\");
keyName.Append(appName.get());
result = SetRegistryKey(HKEY_LOCAL_MACHINE,
keyName.get(),
"DLLPath", (char *) appPath.get());
}
}
}
if (!name.IsEmpty()) {
if (NS_SUCCEEDED(result)) {
mailKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Clients\\Mail",
"", (char *)name.get());
}
}
else
mailKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Clients\\Mail",
"", "");
if (NS_SUCCEEDED(mailKeySet)) {
nsCAutoString userAppName ;
GetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"HKEY_CURRENT_USER\\Software\\Clients\\Mail", userAppName);
nsresult desktopKeySet = NS_OK;
if (!userAppName.IsEmpty()) {
desktopKeySet = SetRegistryKey(HKEY_CURRENT_USER,
"Software\\Clients\\Mail",
"", (char *)userAppName.get());
}
else {
DeleteRegistryValue(HKEY_CURRENT_USER, "Software\\Clients\\Mail", "");
}
if (NS_SUCCEEDED(desktopKeySet)) {
desktopKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"defaultMailHasBeenSet", "0");
}
::SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
(LPARAM)"Software\\Clients\\Mail");
UnregisterServer(CLSID_CMapiImp, "mozMapi", "mozMapi.1");
return desktopKeySet;
}
return mailKeySet;
}
/** Returns FALSE if showMapiDialog is set to 0.
* Returns TRUE otherwise
* Also returns TRUE if the Mozilla has been set as the default mail client
* and some other application has changed that setting.
* This function gets called only if the current app is not the default mail
* client
*/
PRBool nsMapiRegistryUtils::getShowDialog() {
PRBool rv = PR_FALSE;
nsCAutoString showDialog ;
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
"showMapiDialog", showDialog);
// if the user has not selected the checkbox, show dialog
if (showDialog.IsEmpty() || showDialog.Equals("1"))
rv = PR_TRUE;
if (!rv) {
// even if the user has selected the checkbox
// show it if some other application has changed the
// default setting.
nsCAutoString setMailDefault ;
GetRegistryKey(HKEY_LOCAL_MACHINE,"Software\\Mozilla\\Desktop",
"defaultMailHasBeenSet", setMailDefault);
if (setMailDefault.Equals("1")) {
// need to reset the defaultMailHasBeenSet to "0"
// so that after the dialog is displayed once,
// we do not keep displaying this dialog after the user has
// selected the checkbox
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
"Software\\Mozilla\\Desktop",
"defaultMailHasBeenSet", "0");
rv = PR_TRUE;
}
}
return rv;
}
nsresult nsMapiRegistryUtils::MakeMapiStringBundle(nsIStringBundle ** aMapiStringBundle)
{
nsresult rv = NS_OK ;
if (m_mapiStringBundle)
{
*aMapiStringBundle = m_mapiStringBundle ;
NS_ADDREF(*aMapiStringBundle);
return rv ;
}
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(
kStringBundleServiceCID, &rv));
if (NS_FAILED(rv) || !bundleService) return NS_ERROR_FAILURE;
rv = bundleService->CreateBundle(
MAPI_PROPERTIES_CHROME,
getter_AddRefs(m_mapiStringBundle));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
NS_ADDREF(*aMapiStringBundle = m_mapiStringBundle) ;
return rv ;
}
nsresult nsMapiRegistryUtils::ShowMapiErrorDialog()
{
nsresult rv;
nsCOMPtr<nsIPromptService> promptService(do_GetService(
"@mozilla.org/embedcomp/prompt-service;1", &rv));
if (NS_SUCCEEDED(rv) && promptService)
{
nsCOMPtr<nsIStringBundle> bundle;
rv = MakeMapiStringBundle (getter_AddRefs (bundle)) ;
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsXPIDLString dialogTitle;
const PRUnichar *brandStrings[] = { brandName() };
NS_NAMED_LITERAL_STRING(dialogTitlePropertyTag, "errorMessageTitle");
rv = bundle->FormatStringFromName(dialogTitlePropertyTag.get(),
brandStrings, 1,
getter_Copies(dialogTitle));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsXPIDLString dialogText;
NS_NAMED_LITERAL_STRING(dialogTextPropertyTag, "errorMessage");
rv = bundle->FormatStringFromName(dialogTextPropertyTag.get(),
brandStrings, 1,
getter_Copies(dialogText));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = promptService->Alert(nsnull, dialogTitle,
dialogText);
}
return rv;
}

View File

@@ -1,112 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsmapiregistryutils_h____
#define nsmapiregistryutils_h____
#include <windows.h>
#include <string.h>
#include <winreg.h>
#include "Registry.h"
#include "nsString.h"
#include "nsIStringBundle.h"
class nsMapiRegistryUtils
{
private :
nsCAutoString m_thisApp ;
nsAutoString m_brand ;
nsAutoString m_versionNo ;
nsCOMPtr<nsIStringBundle> m_mapiStringBundle ;
public :
nsMapiRegistryUtils() ;
// returns TRUE if the Mapi32.dll is smart dll.
PRBool isSmartDll();
// returns TRUE if the Mapi32.dll is a Mozilla dll.
PRBool isMozDll();
// Returns the (fully-qualified) name of this executable.
const char * thisApplication() ;
// This returns the brand name for this application
const PRUnichar * brandName() ;
// This returns the version no for this application
const PRUnichar * versionNo() ;
// verifyRestrictedAccess - Returns PR_TRUE if this user only has restricted access
// to the registry keys we need to modify.
PRBool verifyRestrictedAccess() ;
// set the Windows registry key
nsresult SetRegistryKey(HKEY baseKey, const char * keyName,
const char * valueName, char * value);
// delete a registry key
nsresult DeleteRegistryValue(HKEY baseKey, const char * keyName,
const char * valueName);
// get a Windows registry key
void GetRegistryKey(HKEY baseKey, const char * keyName,
const char * valueName, nsCAutoString & value) ;
// Returns TRUE if the current application is default mail client.
PRBool IsDefaultMailClient();
// Sets Mozilla as default Mail Client
nsresult setDefaultMailClient() ;
// Removes Mozilla as the default Mail client and restores the previous setting
nsresult unsetDefaultMailClient() ;
// Saves the current setting of the default Mail Client in
// HKEY_LOCAL_MACHINE\\Software\\Mozilla\\Desktop
nsresult saveDefaultMailClient();
// Saves the current user setting of the default Mail Client in
// HKEY_LOCAL_MACHINE\\Software\\Mozilla\\Desktop
nsresult saveUserDefaultMailClient();
nsresult CopyMozMapiToWinSysDir();
nsresult RestoreBackedUpMapiDll();
// Returns FALSE if showMapiDialog is set to 0.
PRBool getShowDialog() ;
// create a string bundle for MAPI messages
nsresult MakeMapiStringBundle(nsIStringBundle ** aMapiStringBundle) ;
// display an error dialog for MAPI messages
nsresult ShowMapiErrorDialog() ;
} ;
#endif

View File

@@ -1,30 +0,0 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<!-- list all the packages being supplied by this jar -->
<RDF:Seq about="urn:mozilla:package:root">
<RDF:li resource="urn:mozilla:package:messenger-mapi"/>
</RDF:Seq>
<!-- package information -->
<RDF:Description about="urn:mozilla:package:messenger-mapi"
chrome:displayName="Messenger"
chrome:author="mozilla.org"
chrome:name="messenger-mapi"
chrome:localeVersion="0.9.7"
chrome:skinVersion="0.9.4">
</RDF:Description>
<!-- overlay information -->
<RDF:Seq about="urn:mozilla:overlays">
<RDF:li resource="chrome://messenger/content/pref-mailnews.xul"/>
</RDF:Seq>
<!-- mapi items for Mail And Newsgroups preferences pane -->
<RDF:Seq about="chrome://messenger/content/pref-mailnews.xul">
<RDF:li>chrome://messenger-mapi/content/pref-mailnewsOverlay.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>

View File

@@ -1,3 +0,0 @@
messenger.jar:
content/messenger-mapi/pref-mailnewsOverlay.xul
content/messenger-mapi/contents.rdf

View File

@@ -1,29 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Srilatha Moturi <srilatha@netscape.com>
#
DEPTH=..\..\..\..
include <$(DEPTH)\config\rules.mak>
chrome::
$(REGCHROME) content messenger-mapi messenger.jar

View File

@@ -1,14 +0,0 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:chrome="http://www.mozilla.org/rdf/chrome#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!-- mapi items for mailnews preferences -->
<RDF:Seq about="urn:mozilla:overlays">
<RDF:li resource="chrome://messenger/content/pref-mailnews.xul"/>
</RDF:Seq>
<RDF:Seq about="chrome://messenger/content/pref-mailnews.xul">
<RDF:li>chrome://messenger/content/pref-mailnewsOverlay.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>

View File

@@ -1,104 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*/
function mailnewsOverlayStartup() {
mailnewsOverlayInit();
parent.hPrefWindow.registerOKCallbackFunc(onOK);
if (!("mapiPref" in parent)) {
parent.mapiPref = new Object;
parent.mapiPref.isDefaultMailClient =
document.getElementById("mailnewsEnableMapi").checked;
}
else {
// when we switch between different panes
// set the checkbox based on the saved state
var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
if (parent.mapiPref.isDefaultMailClient)
mailnewsEnableMapi.setAttribute("checked", "true");
else
mailnewsEnableMapi.setAttribute("checked", "false");
}
}
function mailnewsOverlayInit() {
try {
var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].
getService( Components.interfaces.nsIMapiRegistry );
}
catch(ex){
mapiRegistry = null;
}
const prefbase = "system.windows.lock_ui.";
var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
if (mapiRegistry) {
// initialise preference component.
// While the data is coming from the system registry, we use a set
// of parallel preferences to indicate if the ui should be locked.
try {
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService()
.QueryInterface(Components.interfaces.nsIPrefService);
var prefBranch = prefService.getBranch(prefbase);
if (prefBranch && prefBranch.prefIsLocked("default_mail_client")) {
if (prefBranch.getBoolPref("default_mail_client"))
mapiRegistry.setDefaultMailClient();
else
mapiRegistry.unsetDefaultMailClient();
mailnewsEnableMapi.setAttribute("disabled", "true");
}
}
catch(ex) {}
if (mapiRegistry.isDefaultMailClient)
mailnewsEnableMapi.setAttribute("checked", "true");
else
mailnewsEnableMapi.setAttribute("checked", "false");
}
else
mailnewsEnableMapi.setAttribute("disabled", "true");
}
function onEnableMapi() {
// save the state of the checkbox
if ("mapiPref" in parent)
parent.mapiPref.isDefaultMailClient =
document.getElementById("mailnewsEnableMapi").checked;
}
function onOK()
{
try {
var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].
getService( Components.interfaces.nsIMapiRegistry );
}
catch(ex){
mapiRegistry = null;
}
if (mapiRegistry &&
("mapiPref" in parent) &&
(mapiRegistry.isDefaultMailClient != parent.mapiPref.isDefaultMailClient)) {
if (parent.mapiPref.isDefaultMailClient)
mapiRegistry.setDefaultMailClient();
else
mapiRegistry.unsetDefaultMailClient();
}
}

View File

@@ -1,44 +0,0 @@
<?xml version="1.0"?>
<!--
The contents of this file are subject to the Mozilla 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/MPL/
oftware 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) 2001 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
Srilatha Moturi <srilatha@netscape.com>
-->
<!DOCTYPE window [
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
%brandDTD;
<!ENTITY % prefMailnewsOverlayDTD SYSTEM "chrome://messenger-mapi/locale/pref-mailnewsOverlay.dtd" >
%prefMailnewsOverlayDTD;
]>
<overlay id="prefMailnewsOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript">
<![CDATA[
_elementIDs.push("mailnewsEnableMapi");
]]>
</script>
<script type="application/x-javascript" src="chrome://messenger-mapi/content/pref-mailnewsOverlay.js"/>
<hbox autostretch="never" id="mapi">
<checkbox id="mailnewsEnableMapi" label="&enableMapi.label;"
accesskey="&enableMapi.accesskey;"
preftype="bool" prefstring="mailnews.default_mail_client" prefattribute="checked"/>
</hbox>
</overlay>

View File

@@ -1,23 +0,0 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<!-- list all the skins being supplied by this package -->
<RDF:Seq about="urn:mozilla:locale:root">
<RDF:li resource="urn:mozilla:locale:en-US"/>
</RDF:Seq>
<!-- locale information -->
<RDF:Description about="urn:mozilla:locale:en-US">
<chrome:packages>
<RDF:Seq about="urn:mozilla:locale:en-US:packages">
<RDF:li resource="urn:mozilla:locale:en-US:messenger-mapi"/>
</RDF:Seq>
</chrome:packages>
</RDF:Description>
<!-- Version Information. State that we work only with major version of this
package. -->
<RDF:Description about="urn:mozilla:locale:en-US:messenger-mapi"
chrome:localeVersion="0.9.7"/>
</RDF:RDF>

View File

@@ -1,4 +0,0 @@
en-US.jar:
locale/en-US/messenger-mapi/pref-mailnewsOverlay.dtd
locale/en-US/messenger-mapi/mapi.properties
locale/en-US/messenger-mapi/contents.rdf

View File

@@ -1,40 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Srilatha Moturi <srilatha@netscape.com>
#
DEPTH=..\..\..\..\..
CHROME_DIR=locales\en-US
CHROME_L10N_DIR=messenger\locale
CHROME_L10N = \
.\pref-mailnewsOverlay.dtd \
.\mapi.properties \
.\contents.rdf \
$(NULL)
include <$(DEPTH)\config\rules.mak>
chrome::
$(REGCHROME) locale en-US/messenger-mapi en-US.jar

View File

@@ -1,23 +0,0 @@
# Mail Integration Dialog
dialogTitle=%S Mail
dialogText=Do you want to use %S as the default mail application?
checkboxText=Do not display this dialog again
# MAPI Messages
loginText=Please enter your password for %S:
loginTextwithName=Please enter your username and password
loginTitle=%S Mail
PasswordTitle=%S Mail
# MAPI Error Messages
errorMessage=%S Mail could not be set as the default mail application because a registry key could not be updated. Verify with your system administrator that you have write access to your system registry, and then try again.
errorMessageTitle=%S Mail
# MAPI Security Messages
mapiBlindSendWarning=Another application is attempting to send mail using your user profile. Are you sure you want to send mail?
mapiBlindSendDontShowAgain=Warn me whenever other applications try to send mail from me
#Default Mail Display String
# localization note, $1%S is the app name, $2%S is the version
defaultMailDisplayTitle=%S %S Mail

View File

@@ -1,3 +0,0 @@
<!ENTITY enableMapiTitle.label "When sending mail from other applications">
<!ENTITY enableMapi.label "Use &vendorShortName; Mail as the default mail application.">
<!ENTITY enableMapi.accesskey "u">

View File

@@ -1,28 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Srilatha Moturi <srilatha@netscape.com>
#
DEPTH=..\..\..\..
DIRS=en-US
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,27 +0,0 @@
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Srilatha Moturi <srilatha@netscape.com>
#
DEPTH=..\..\..
DIRS=content locale
include <$(DEPTH)\config\rules.mak>

33
mozilla/rdf/Makefile.in Normal file
View File

@@ -0,0 +1,33 @@
#!gmake
#
# 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.
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = base content datasource build
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,29 @@
#!gmake
#
# 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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,27 @@
#!gmake
#
# 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.
DEPTH=..\..
MODULE = rdf
DIRS=\
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,11 @@
rdf.h
nsIRDFCompositeDataSource.h
nsIRDFContentSink.h
nsIRDFCursor.h
nsIRDFDataSource.h
nsIRDFNode.h
nsIRDFObserver.h
nsIRDFResourceFactory.h
nsIRDFService.h
nsIRDFXMLDataSource.h
nsIRDFXMLSource.h

View File

@@ -0,0 +1,46 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
EXPORTS = \
rdf.h \
nsIRDFCompositeDataSource.h \
nsIRDFContentSink.h \
nsIRDFCursor.h \
nsIRDFDataSource.h \
nsIRDFNode.h \
nsIRDFObserver.h \
nsIRDFResourceFactory.h \
nsIRDFService.h \
nsIRDFXMLDataSource.h \
nsIRDFXMLSource.h \
nsRDFResource.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,40 @@
#!gmake
#
# 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.
MODULE=rdf
DEPTH=..\..\..
EXPORTS=\
rdf.h \
nsIRDFCompositeDataSource.h \
nsIRDFContentSink.h \
nsIRDFCursor.h \
nsIRDFDataSource.h \
nsIRDFNode.h \
nsIRDFObserver.h \
nsIRDFResourceFactory.h \
nsIRDFService.h \
nsIRDFXMLDataSource.h \
nsIRDFXMLSource.h \
nsRDFResource.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,60 @@
/* -*- 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
* 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.
*/
/*
RDF composite data source interface. A composite data source
aggregates individual RDF data sources.
*/
#ifndef nsIRDFCompositeDataSource_h__
#define nsIRDFCompositeDataSource_h__
#include "nsISupports.h"
#include "nsIRDFDataSource.h"
class nsIRDFDataSource;
// 96343820-307c-11d2-bc15-00805f912fe7
#define NS_IRDFCOMPOSITEDATASOURCE_IID \
{ 0x96343820, 0x307c, 0x11d2, { 0xb, 0x15, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
/**
* An <tt>nsIRDFCompositeDataSource</tt> composes individual data sources, providing
* the illusion of a single, coherent RDF graph.
*/
class nsIRDFCompositeDataSource : public nsIRDFDataSource {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCOMPOSITEDATASOURCE_IID; return iid; }
/**
* Add a datasource the the database.
*/
NS_IMETHOD AddDataSource(nsIRDFDataSource* source) = 0;
/**
* Remove a datasource from the database
*/
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source) = 0;
};
extern nsresult
NS_NewRDFCompositeDataSource(nsIRDFCompositeDataSource** result);
#endif /* nsIRDFCompositeDataSource_h__ */

View File

@@ -0,0 +1,72 @@
/* -*- 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 "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 Communicator client 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.
*/
/*
An RDF-specific content sink. The content sink is targeted by the
parser for building the RDF content model.
*/
#ifndef nsIRDFContentSink_h___
#define nsIRDFContentSink_h___
#include "nsIXMLContentSink.h"
class nsIDocument;
class nsIRDFXMLDataSource;
class nsINameSpaceManager;
class nsIURL;
// {751843E2-8309-11d2-8EAC-00805F29F370}
#define NS_IRDFCONTENTSINK_IID \
{ 0x751843e2, 0x8309, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* This interface represents a content sink for RDF files.
*/
class nsIRDFContentSink : public nsIXMLContentSink {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCONTENTSINK_IID; return iid; }
/**
* Initialize the content sink.
*/
NS_IMETHOD Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager) = 0;
/**
* Set the content sink's RDF Data source
*/
NS_IMETHOD SetDataSource(nsIRDFXMLDataSource* aDataSource) = 0;
/**
* Retrieve the content sink's RDF data source.
*/
NS_IMETHOD GetDataSource(nsIRDFXMLDataSource*& rDataSource) = 0;
};
/**
* This constructs a content sink that can be used without a
* document, say, to create a stand-alone in-memory graph.
*/
nsresult
NS_NewRDFContentSink(nsIRDFContentSink** aResult);
#endif // nsIRDFContentSink_h___

View File

@@ -0,0 +1,174 @@
/* -*- 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
* 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.
*/
/*
Interfaces for RDF cursors, including nsIRDFCursor,
nsIRDFAssertionCursor, nsIRDFArcsInCursor, nsIRDFArcsOutCursor,
nad nsIRDFResourceCursor.
*/
#ifndef nsIRDFCursor_h__
#define nsIRDFCursor_h__
#include "nsISupports.h"
#include "prtypes.h"
#include "rdf.h" // for error codes
class nsIRDFDataSource;
class nsIRDFNode;
class nsIRDFResource;
// 1c2abdb0-4cef-11d2-bc16-00805f912fe7
#define NS_IRDFCURSOR_IID \
{ 0x1c2abdb0, 0x4cef, 0x11d2, { 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
/**
* An abstract base interface that is the basis for all RDF cursors.
*/
class nsIRDFCursor : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCURSOR_IID; return iid; }
/**
* Advance the cursor to the next element.
* @return NS_ERROR_RDF_CURSOR_EMPTY if the cursor has reached the end
* and there are no more elements to enumerate; otherwise, NS_OK
* unless a catastrophic error occurs.
*/
NS_IMETHOD Advance(void) = 0;
/* Retrieve the data source from which the current item was obtained.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) = 0;
/**
* Irrespective of the query, a cursor is an interator over a set.
* This allows you to obtain the current value.
*/
NS_IMETHOD GetValue(nsIRDFNode** aValue) = 0;
};
// {1ED57100-9904-11d2-8EBA-00805F29F370}
#define NS_IRDFASSERTIONCURSOR_IID \
{ 0x1ed57100, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A cursor that enumerates assertions
* @seealso nsIRDFDataSource::GetTargetS(), nsIRDFDataSource::GetSources()
*/
class nsIRDFAssertionCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFASSERTIONCURSOR_IID; return iid; }
/**
* Retrieve the assertion's subject resource.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetSubject(nsIRDFResource** aSubject) = 0;
/**
* Retrieve the assertion's predicate resource.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
/**
* Retrieve the assertion's object node.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetObject(nsIRDFNode** aObject) = 0;
/**
* Retrieve the assertion's truth value.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) = 0;
};
// {1ED57101-9904-11d2-8EBA-00805F29F370}
#define NS_IRDFARCSOUTCURSOR_IID \
{ 0x1ed57101, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A cursor that enumerates the outbound arcs from a resource node.
* @seealso nsIRDFDataSource::ArcsOut()
*/
class nsIRDFArcsOutCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFARCSOUTCURSOR_IID; return iid; }
/**
* Retrieve the "subject" node from which the arcs originate.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetSubject(nsIRDFResource** aSubject) = 0;
/**
* Retrieve the predicate label of the arc.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
};
// {1ED57102-9904-11d2-8EBA-00805F29F370}
#define NS_IRDFARCSINCURSOR_IID \
{ 0x1ed57102, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A cursor that enumerates the inbound arcs to a node.
* @seealso nsIRDFDataSource::ArcsIn()
*/
class nsIRDFArcsInCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFARCSINCURSOR_IID; return iid; }
/**
* Retrieve the "object" node in which the arc terminates.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetObject(nsIRDFNode** aObject) = 0;
/**
* Retrieve the predicate label of the arc
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
};
// {C2850C10-B0CF-11d2-A684-00104BDE6048}
#define NS_IRDFRESOURCECURSOR_IID \
{ 0xc2850c10, 0xb0cf, 0x11d2, { 0xa6, 0x84, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
/**
* A cursor that enumerates all of the resources in a data source.
*/
class nsIRDFResourceCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFRESOURCECURSOR_IID; return iid; }
NS_IMETHOD GetResource(nsIRDFResource** aResource) = 0;
};
#endif /* nsIRDFCursor_h__ */

View File

@@ -0,0 +1,210 @@
/* -*- 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
* 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.
*/
/*
The RDF data source interface. An RDF data source presents a
graph-like interface to a back-end service.
*/
#ifndef nsIRDFDataSource_h__
#define nsIRDFDataSource_h__
#include "nsISupports.h"
// {0F78DA58-8321-11d2-8EAC-00805F29F370}
#define NS_IRDFDATASOURCE_IID \
{ 0xf78da58, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFAssertionCursor;
class nsIRDFArcsInCursor;
class nsIRDFArcsOutCursor;
class nsIRDFDataBase;
class nsIRDFNode;
class nsIRDFObserver;
class nsIRDFResource;
class nsIRDFResourceCursor;
/**
* An RDF data source.
*/
class nsIRDFDataSource : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFDATASOURCE_IID; return iid; }
// XXX I didn't make some of these methods "const" because it's
// probably pretty likely that many data sources will just make
// stuff up at runtime to answer queries.
/**
* Specify the URI for the data source: this is the prefix
* that will be used to register the data source in the
* data source registry.
*/
NS_IMETHOD Init(const char* uri) = 0;
/**
* Retrieve the URI of the data source.
*/
NS_IMETHOD GetURI(const char* *uri) const = 0;
/**
* Find an RDF resource that points to a given node over the
* specified arc & truth value
*
* @return NS_ERROR_FAILURE if there is no source that leads
* to the target with the specified property.
*/
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source /* out */) = 0;
/**
* Find all RDF resources that point to a given node over the
* specified arc & truth value
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsIRDFCursor points
* to a valid (but possibly empty) cursor.
*/
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** sources /* out */) = 0;
/**
* Find a child of that is related to the source by the given arc
* arc and truth value
*
* @return NS_ERROR_FAILURE if there is no target accessable from the
* source via the specified property.
*/
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target /* out */) = 0;
/**
* Find all children of that are related to the source by the given arc
* arc and truth value.
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsIRDFCursor points
* to a valid (but possibly empty) cursor.
*/
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets /* out */) = 0;
/**
* Add an assertion to the graph.
*/
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv) = 0;
/**
* Remove an assertion from the graph.
*/
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) = 0;
/**
* Query whether an assertion exists in this graph.
*
* @return NS_OK unless a catastrophic error occurs.
*/
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion /* out */) = 0;
/**
* Add an observer to this data source.
*/
NS_IMETHOD AddObserver(nsIRDFObserver* n) = 0;
/**
* Remove an observer from this data source
*/
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) = 0;
// XXX individual resource observers?
/**
* Get a cursor to iterate over all the arcs that point into a node.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsIRDFCursor object.
*/
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels /* out */) = 0;
/**
* Get a cursor to iterate over all the arcs that originate in
* a resource.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsIRDFCursor object.
*/
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels /* out */) = 0;
/**
* Retrieve all of the resources that the data source currently
* refers to.
*/
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) = 0;
/**
* Request that a data source write it's contents out to
* permanent storage if applicable.
*/
NS_IMETHOD Flush(void) = 0;
/**
* Determine whether the specified command is enabled for the
* resource.
*
* XXX We will probably need to make this interface much more intricate
* to handle arbitrary arguments and selection sets.
*/
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult) = 0;
/**
* Perform the specified command on the resource.
*
* XXX We will probably need to make this interface much more intricate
* to handle arbitrary arguments and selection sets.
*/
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget) = 0;
};
#endif /* nsIRDFDataSource_h__ */

View File

@@ -0,0 +1,116 @@
/* -*- 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
* 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.
*/
/*
RDF node interfaces, including nsIRDFNode, nsIRDFResource, and
nsIRDFLiteral. Nodes are the elements that appear in RDF graphs.
*/
#ifndef nsIRDFNode_h__
#define nsIRDFNode_h__
#include "nscore.h"
#include "nsISupports.h"
// {0F78DA50-8321-11d2-8EAC-00805F29F370}
#define NS_IRDFNODE_IID \
{ 0xf78da50, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
*
* Nodes are created using an instance of nsIRDFService, which
* should be obtained from the service manager:
*
* nsIRDFService* service;
* if (NS_SUCCEEDED(nsServiceManager::GetService(kCRDFServiceCID,
* kIRDFServiceIID,
* (nsISupports**) &service))) {
* nsIRDFNode* node;
* if (NS_SUCCEEDED(service->GetResource("http://foo.bar/", node))) {
* // do something useful here...
* NS_IF_RELEASE(node);
* }
* nsServiceManager::ReleaseService(kCRDFServiceCID, mgr);
* }
*
*/
class nsIRDFNode : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFNODE_IID; return iid; }
/**
* Determine if two nodes are identical
*/
NS_IMETHOD EqualsNode(nsIRDFNode* that, PRBool* result) const = 0;
};
/**
* A resource node, which has unique object identity.
*/
// {E0C493D1-9542-11d2-8EB8-00805F29F370}
#define NS_IRDFRESOURCE_IID \
{ 0xe0c493d1, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFResource : public nsIRDFNode {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFRESOURCE_IID; return iid; }
/**
* Get the 8-bit string value of the node.
*/
NS_IMETHOD GetValue(const char* *uri) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const = 0;
};
// {E0C493D2-9542-11d2-8EB8-00805F29F370}
#define NS_IRDFLITERAL_IID \
{ 0xe0c493d2, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFLiteral : public nsIRDFNode {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFLITERAL_IID; return iid; }
/**
* Get the Unicode string value of the node.
*/
NS_IMETHOD GetValue(const PRUnichar* *value) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const = 0;
};
#endif // nsIRDFNode_h__

View File

@@ -0,0 +1,64 @@
/* -*- 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
* 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.
*/
/*
The RDF data source observer interface. Data source observers are
notified when the contents of the graph change.
*/
#ifndef nsIRDFObserver_h__
#define nsIRDFObserver_h__
#include "nsISupports.h"
class nsIRDFDataSource;
class nsIRDFResource;
class nsIRDFNode;
/**
* An observer on an nsIRDFDataSource.
*/
// 3cc75360-484a-11d2-bc16-00805f912fe7
#define NS_IRDFOBSERVER_IID \
{ 0x3cc75360, 0x484a, 0x11d2, { 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
class nsIRDFObserver : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFOBSERVER_IID; return iid; }
/**
* Called whenever a new assertion is made in the data source.
*/
NS_IMETHOD OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object) = 0;
/**
* Called whenever an assertion is removed from the data source.
*/
NS_IMETHOD OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object) = 0;
};
#endif /* nsIRDFObserver_h__ */

View File

@@ -0,0 +1,74 @@
/* -*- 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
* 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.
*/
/*
The RDF resource factory interface. A resource factory produces
nsIRDFResource objects for a specified URI prefix.
*/
#ifndef nsIRDFResourceFactory_h__
#define nsIRDFResourceFactory_h__
#include "nsISupports.h"
class nsIRDFResource;
// {8CE57A20-A02C-11d2-8EBF-00805F29F370}
#define NS_IRDFRESOURCEFACTORY_IID \
{ 0x8ce57a20, 0xa02c, 0x11d2, { 0x8e, 0xbf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A resource factory can be registered with <tt>nsIRDFService</tt> to produce
* resources with a certain <i>URI prefix</i>. The resource factory will be called
* upon to create a new resource, which the resource manager will cache.
*
* @see nsIRDFService::RegisterResourceFactory
* @see nsIRDFService::UnRegisterResourceFactory
*/
class nsIRDFResourceFactory : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFRESOURCEFACTORY_IID; return iid; }
/**
* This method is called by the RDF service to create a new
* resource.
*
* NOTE. After constructing a new resource via a call to
* nsIRDFResourceFactory::CreateResource(), the implementation of
* the RDF service calls nsIRDFResource::GetValue() on the
* resulting resource. The resulting <tt>const char*</tt> is used
* as a key for the resource cache. (The assumption is that the
* custom resource implementation needs to store this information,
* anyway.)
*
* This has important implications for a custom resource's
* destructor; namely, that you must call
* nsIRDFService::UnCacheResource() <b>before</b> releasing the
* storage for the resource's URI. See
* nsIRDFService::UnCacheResource() for more information.
*/
NS_IMETHOD CreateResource(const char* aURI, nsIRDFResource** aResult) = 0;
};
#endif // nsIRDFResourceFactory_h__

View File

@@ -0,0 +1,176 @@
/* -*- 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
* 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.
*/
/*
The RDF service interface. This is a singleton object, and should be
obtained from the <tt>nsServiceManager</tt>.
XXX I'm not particularly happy with the current APIs for named data
sources. The idea is that you want "rdf:bookmarks" to always map to
the "bookmarks" data store. The thing that bothers me now is that
the implementation has to pre-load all of the data sources: that
means you need to parse the bookmarks file, read the history, etc.,
rather than doing this on-demand. With a little thought, it may be
able to enormously improve these APIs so that pre-loading data
sources is unnecessary.
*/
#ifndef nsIRDFService_h__
#define nsIRDFService_h__
#include "nscore.h"
#include "nsISupports.h"
class nsIRDFDataBase;
class nsIRDFDataSource;
class nsIRDFLiteral;
class nsIRDFResource;
class nsIRDFResourceFactory;
typedef nsresult (*NSDataSourceConstructorCallback)(nsIRDFDataSource** aResult);
// {BFD05261-834C-11d2-8EAC-00805F29F370}
#define NS_IRDFSERVICE_IID \
{ 0xbfd05261, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFService : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFSERVICE_IID; return iid; }
// Resource management routines
/**
* Construct an RDF resource from a single-byte URI. <tt>nsIRDFSerivce</tt>
* caches resources that are in-use, so multiple calls to <tt>GetResource()</tt>
* for the same <tt>uri</tt> will return identical pointers.
*/
NS_IMETHOD GetResource(const char* uri, nsIRDFResource** resource) = 0;
/**
* Construct an RDF resource from a Unicode URI. This is provided
* as a convenience method, allowing automatic, in-line C++
* conversion from <tt>nsString</tt> objects. The <tt>uri</tt> will
* be converted to a single-byte representation internally.
*/
NS_IMETHOD GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource) = 0;
/**
* Construct an RDF literal from a Unicode string.
*/
NS_IMETHOD GetLiteral(const PRUnichar* value, nsIRDFLiteral** literal) = 0;
/**
* Called to notify the resource manager that a resource is no
* longer in use. This method should only be called from the
* destructor of a "custom" resource implementation to notify the
* RDF service that the last reference to the resource has been
* released, so the resource is no longer valid.
*
* NOTE. As mentioned in nsIRDFResourceFactory::CreateResource(),
* the RDF service will use the result of
* nsIRDFResource::GetValue() as a key into its cache. For this
* reason, you must always un-cache the resource <b>before</b>
* releasing the storage for the <tt>const char*</tt> URI.
*/
NS_IMETHOD UnCacheResource(nsIRDFResource* resource) = 0;
/**
* Registers the specified resource factory as the producer for resources that
* have the specified <i>URI prefix</i>.
*/
NS_IMETHOD RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory) = 0;
/**
* Unregsters the specified resource factory from producing resources that have
* the specified <i>URI prefix</i>.
*/
NS_IMETHOD UnRegisterResourceFactory(const char* aURIPrefix) = 0;
// Data source management routines
/**
* Register a <i>named data source</i>. The RDF service will call
* <tt>nsIRDFDataSource::GetURI()</tt> to determine the URI under which to
* register the data source.
*
* Note that the data source will <i>not</i> be refcounted by the
* RDF service! The assumption is that an RDF data source registers
* with the service once it is initialized (via <tt>nsIRDFDataSource::Init()</tt>),
* and unregisters when the last reference to the data source is
* released.
*/
NS_IMETHOD RegisterDataSource(nsIRDFDataSource* dataSource) = 0;
/**
* Unregister a <i>named data source</i>. The RDF service will call
* <tt>nsIRDFDataSource::GetURI()</tt> to determine the URI under which the
* data source was registered.
*/
NS_IMETHOD UnregisterDataSource(nsIRDFDataSource* dataSource) = 0;
/**
* Register a constructor function that will create a named data source.
* The RDF service will call this function to attempt to create a
* named data source.
*/
NS_IMETHOD RegisterDataSourceConstructor(const char* aURI, NSDataSourceConstructorCallback aFn) = 0;
/**
* Unregister the constructor function for a named data source.
*/
NS_IMETHOD UnregisterDataSourceConstructor(const char* aURI) = 0;
/**
* Get the <i>named data source</i> corresponding to the URI. If a data
* source has been registered via <tt>RegisterDataSource()</tt>, that
* data source will be returned.
*
* If no data source is currently
* registered for the specified URI, and a data source <i>constructor</i>
* function has been registered via <tt>RegisterDatasourceConstructor()</tt>,
* the RDF service will call the constructor to attempt to construct a
* new data source. If construction is successful, the data source will
* be initialized via <tt>nsIRDFDataSource::Init()</tt>.
*/
NS_IMETHOD GetDataSource(const char* uri, nsIRDFDataSource** dataSource) = 0;
/**
* Create a database that contains the specified named data
* sources. This is a convenience method whose functionality is
* equivalent to (1) constructing a new nsIRDFDataBase object from
* the repository, and (2) iteratively adding the named data sources
* to it, in order.
*/
NS_IMETHOD CreateDatabase(const char** uris, nsIRDFDataBase** dataBase) = 0;
/**
* Get the database aggregating all the stuff that Navigator sees as a default,
* including a "local" store.
*/
NS_IMETHOD CreateBrowserDatabase(nsIRDFDataBase** dataBase) = 0;
};
extern nsresult
NS_NewRDFService(nsIRDFService** result);
#endif // nsIRDFService_h__

View File

@@ -0,0 +1,60 @@
/* -*- 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
* 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 nsIRDFTree_h__
#define nsIRDFTree_h__
#include "nscore.h"
#include "nsISupports.h"
#include "prtypes.h"
#include "rdf.h" // for error codes
/*
An interface for presenting a tree view of an rdf datasource (or
database).
Any datasource can also support nsIRDFTree. The interface is purely
syntactic sugar for traversing simple tree where the child relation
corresponds to the property type nc:child (nc = http://home.netscape.com/NC-rdf#).
Each leaf is assumed to have a certain predefined set of properties
such as creationDate, size, lastModificationDate, lastVisitDate, etc.
This interface is substantially less general than nsIRDFDataSource,
but is adequate for bookmarks, the file system, history and a few
other very commonly used data sources.
*/
// {7D7EEBD1-AA41-11d2-80B7-006097B76B8E}
#define NS_IRDFTREE_IID \
{ 0x7d7eebd1, 0xaa41, 0x11d2, { 0x80, 0xb7, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } };
class nsIRDFTree : public nsISupports {
public:
NS_IMETHOD ListChildren (nsIRDFResource* folder, nsVoidArray** result);
// XXX should define something called nsResourceArray and use that
NS_IMETHOD IsFolder (nsIRDFResource* node, PRBool* result);
NS_IMETHOD GetProperty (nsIRDFResource* node, nsIRDFResource* property,
nsIRDFNode** result);
}
#endif

View File

@@ -0,0 +1,200 @@
/* -*- 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
* 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.
*/
/*
This interface encapsulates information about an RDF/XML file,
including the root resource, CSS style sheets, and named data
sources.
This file also includes an observer interface for nsIRDFXMLDataSource
objects.
*/
#ifndef nsIRDFXMLDataSource_h__
#define nsIRDFXMLDataSource_h__
#include "nsIRDFDataSource.h"
class nsIAtom;
class nsIOutputStream;
class nsIURL;
class nsString;
// {EB1A5D30-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENTOBSERVER_IID \
{ 0xeb1a5d30, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDataSource;
class nsIRDFXMLDataSourceObserver : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFXMLDOCUMENTOBSERVER_IID; return iid; }
/**
* Called when the RDF/XML document begins to load.
*/
NS_IMETHOD OnBeginLoad(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called when the RDF/XML document load is interrupted for some reason.
*/
NS_IMETHOD OnInterrupt(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called when an interrupted RDF/XML document load is resumed.
*/
NS_IMETHOD OnResume(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called whtn the RDF/XML document load is complete.
*/
NS_IMETHOD OnEndLoad(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called when the root resource of the RDF/XML document is found
*/
NS_IMETHOD OnRootResourceFound(nsIRDFXMLDataSource* aStream, nsIRDFResource* aResource) = 0;
/**
* Called when a CSS style sheet is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnCSSStyleSheetAdded(nsIRDFXMLDataSource* aStream, nsIURL* aCSSStyleSheetURL) = 0;
/**
* Called when a named data source is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnNamedDataSourceAdded(nsIRDFXMLDataSource* aStream, const char* aNamedDataSourceURI) = 0;
};
// {EB1A5D31-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDATASOURCE_IID \
{ 0xeb1a5d31, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDataSource : public nsIRDFDataSource
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFXMLDATASOURCE_IID; return iid; }
/**
* Sets the RDF/XML stream to load either synchronously or
* asynchronously when nsIRDFDataSource::Init() is called.
* By default, the stream will load <em>asynchronously</em>.
*/
NS_IMETHOD SetSynchronous(PRBool aIsSynchronous) = 0;
/**
* Sets the RDF/XML stream's read-only status. By default,
* the stream will be read/write if the URL on which
* nsIRDFDataSource::Init() is called is writable.
*/
NS_IMETHOD SetReadOnly(PRBool aIsReadOnly) = 0;
/**
* Notify the document that the load is beginning.
*/
NS_IMETHOD BeginLoad(void) = 0;
/**
* Notify the document that the load is being interrupted.
*/
NS_IMETHOD Interrupt(void) = 0;
/**
* Notify the document that an interrupted load is being resumed.
*/
NS_IMETHOD Resume(void) = 0;
/**
* Notify the document that the load is ending.
*/
NS_IMETHOD EndLoad(void) = 0;
/**
* Set the root resource for the document.
*/
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
/**
* Retrieve the root resource for the document.
*/
NS_IMETHOD GetRootResource(nsIRDFResource** aResource) = 0;
/**
* Add a CSS style sheet to the document.
* @param aStyleSheetURL An nsIURL object that is the URL of the style
* sheet to add to the document.
*/
NS_IMETHOD AddCSSStyleSheetURL(nsIURL* aStyleSheetURL) = 0;
/**
* Get the set of style sheets that have been included in the
* document.
* @param aStyleSheetURLs (out) A pointer to an array of pointers to nsIURL objects.
* @param aCount (out) The number of nsIURL objects returned.
*/
NS_IMETHOD GetCSSStyleSheetURLs(nsIURL*** aStyleSheetURLs, PRInt32* aCount) = 0;
/**
* Add a named data source to the document.
* @param aNamedDataSoruceURI A URI identifying the data source.
*/
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI) = 0;
/**
* Get the set of named data sources that have been included in
* the document
* @param aNamedDataSourceURIs (out) A pointer to an array of C-style character
* strings.
* @param aCount (out) The number of named data sources in the array.
*/
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount) = 0;
/**
* Add a new namespace declaration to the RDF/XML document.
*/
NS_IMETHOD AddNameSpace(nsIAtom* aPrefix, const nsString& aURI) = 0;
/**
* Add an observer to the document. The observer will be notified of
* RDF/XML events via the nsIRDFXMLDataSourceObserver interface. Note that
* the observer is <em>not</em> reference counted.
*/
NS_IMETHOD AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver) = 0;
/**
* Remove an observer from the document.
*/
NS_IMETHOD RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver) = 0;
};
// Two different kinds of XML data sources exist for RDF: serialized RDF and XUL.
// These are the methods that make these data sources.
extern nsresult
NS_NewRDFXMLDataSource(nsIRDFXMLDataSource** result);
extern nsresult
NS_NewXULDataSource(nsIRDFXMLDataSource** result);
#endif // nsIRDFXMLDataSource_h__

View File

@@ -0,0 +1,165 @@
/* -*- 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
* 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.
*/
/*
This interface encapsulates information about an RDF/XML file,
including the root resource, CSS style sheets, and named data
sources.
This file also includes an observer interface for nsIRDFXMLDocument
objects.
*/
#ifndef nsIRDFXMLDocument_h__
#define nsIRDFXMLDocument_h__
#include "nsISupports.h"
class nsIOutputStream;
class nsIURL;
// {EB1A5D30-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENTOBSERVER_IID \
{ 0xeb1a5d30, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDocumentObserver : public nsISupports
{
public:
/**
* Called when the RDF/XML document begins to load.
*/
NS_IMETHOD OnBeginLoad(void) = 0;
/**
* Called when the RDF/XML document load is interrupted for some reason.
*/
NS_IMETHOD OnInterrupt(void) = 0;
/**
* Called when an interrupted RDF/XML document load is resumed.
*/
NS_IMETHOD OnResume(void) = 0;
/**
* Called whtn the RDF/XML document load is complete.
*/
NS_IMETHOD OnEndLoad(void) = 0;
/**
* Called when the root resource of the RDF/XML document is found
*/
NS_IMETHOD OnRootResourceFound(nsIRDFResource* aResource) = 0;
/**
* Called when a CSS style sheet is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnCSSStyleSheetAdded(nsIURL* aCSSStyleSheetURL) = 0;
/**
* Called when a named data source is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnNamedDataSourceAdded(const char* aNamedDataSourceURI) = 0;
};
// {EB1A5D31-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENT_IID \
{ 0xeb1a5d31, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDocument : public nsISupports
{
public:
/**
* Notify the document that the load is beginning.
*/
NS_IMETHOD BeginLoad(void) = 0;
/**
* Notify the document that the load is being interrupted.
*/
NS_IMETHOD Interrupt(void) = 0;
/**
* Notify the document that an interrupted load is being resumed.
*/
NS_IMETHOD Resume(void) = 0;
/**
* Notify the document that the load is ending.
*/
NS_IMETHOD EndLoad(void) = 0;
/**
* Set the root resource for the document.
*/
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
/**
* Retrieve the root resource for the document.
*/
NS_IMETHOD GetRootResource(nsIRDFResource** aResource) = 0;
/**
* Add a CSS style sheet to the document.
* @param aStyleSheetURL An nsIURL object that is the URL of the style
* sheet to add to the document.
*/
NS_IMETHOD AddCSSStyleSheetURL(nsIURL* aStyleSheetURL) = 0;
/**
* Get the set of style sheets that have been included in the
* document.
* @param aStyleSheetURLs (out) A pointer to an array of pointers to nsIURL objects.
* @param aCount (out) The number of nsIURL objects returned.
*/
NS_IMETHOD GetCSSStyleSheetURLs(nsIURL*** aStyleSheetURLs, PRInt32* aCount) = 0;
/**
* Add a named data source to the document.
* @param aNamedDataSoruceURI A URI identifying the data source.
*/
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI) = 0;
/**
* Get the set of named data sources that have been included in
* the document
* @param aNamedDataSourceURIs (out) A pointer to an array of C-style character
* strings.
* @param aCount (out) The number of named data sources in the array.
*/
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount) = 0;
/**
* Add an observer to the document. The observer will be notified of
* RDF/XML events via the nsIRDFXMLDocumentObserver interface. Note that
* the observer is <em>not</em> reference counted.
*/
NS_IMETHOD AddDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
/**
* Remove an observer from the document.
*/
NS_IMETHOD RemoveDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
};
#endif // nsIRDFXMLDocument_h__

View File

@@ -0,0 +1,44 @@
/* -*- 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
* 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.
*/
/*
The RDF/XML source interface. An RDF/XML source is capable of
producing serialized RDF/XML to an output stream.
*/
#ifndef nsIRDFXMLSource_h__
#define nsIRDFXMLSource_h__
class nsIOutputStream;
// {4DA56F10-99FE-11d2-8EBB-00805F29F370}
#define NS_IRDFXMLSOURCE_IID \
{ 0x4da56f10, 0x99fe, 0x11d2, { 0x8e, 0xbb, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLSource : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFXMLSOURCE_IID; return iid; }
NS_IMETHOD Serialize(nsIOutputStream* aStream) = 0;
};
#endif // nsIRDFXMLSource_h__

View File

@@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 2; 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
* 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 nsRDFResource_h__
#define nsRDFResource_h__
#include "nsIRDFNode.h"
/**
* This simple base class implements nsIRDFResource, and can be used as a
* superclass for more sophisticated resource implementations.
*/
class nsRDFResource : public nsIRDFResource {
public:
NS_DECL_ISUPPORTS
// nsIRDFNode methods:
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
// nsIRDFResource methods:
NS_IMETHOD GetValue(const char* *uri) const;
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
// nsRDFResource methods:
nsRDFResource(const char* uri);
virtual ~nsRDFResource(void);
protected:
const char* mURI;
};
#endif // nsRDFResource_h__

View File

@@ -0,0 +1,71 @@
/* -*- 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.
*/
/*
A catch-all header file for miscellaneous RDF stuff. Currently
contains error codes and vocabulary macros.
*/
#ifndef rdf_h___
#define rdf_h___
#include "nsError.h"
/*
* The following macros are to aid in vocabulary definition.
* They creates const char*'s for "kURI[prefix]_[name]" and
* "kTag[prefix]_[name]", with appropriate complete namespace
* qualification on the URI, e.g.,
*
* #define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
* DEFINE_RDF_ELEMENT(RDF_NAMESPACE_URI, RDF, ID);
*
* will define:
*
* kURIRDF_ID to be "http://www.w3.org/TR/WD-rdf-syntax#ID", and
* kTagRDF_ID to be "ID"
*/
#define DEFINE_RDF_VOCAB(namespace, prefix, name) \
static const char* kURI##prefix##_##name = ##namespace #name ;\
static const char* kTag##prefix##_##name = kURI##prefix##_##name## + sizeof(##namespace) - 1
/**
* Core RDF vocabularies that we use to infer semantic actions
*/
#define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
/**
* @name Standard RDF error codes
*/
/*@{*/
/* Returned from nsIRDFCursor::Advance() if the cursor has no more
elements to enuemrate */
#define NS_ERROR_RDF_CURSOR_EMPTY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF, 1)
#define NS_ERROR_RDF_NO_VALUE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF, 2)
/*@}*/
#endif /* rdf_h___ */

View File

@@ -0,0 +1,57 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rdfbase_s
CPPSRCS = \
nsCompositeDataSource.cpp \
nsContainerCursor.cpp \
nsDefaultResourceFactory.cpp \
nsEmptyCursor.cpp \
nsInMemoryDataSource.cpp \
nsRDFContentSink.cpp \
nsRDFParserUtils.cpp \
nsRDFService.cpp \
nsRDFXMLDataSource.cpp \
rdfutil.cpp \
nsRDFResource.cpp \
$(NULL)
EXPORTS = \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = rdfbase
REQUIRES = netlib rdf raptor xpcom
MKSHLIB :=
# we don't want the shared lib
NO_SHARED_LIB=1
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,48 @@
#!gmake
#
# 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.
DEPTH=..\..\..
MODULE=rdf
LIBRARY_NAME=rdfbase_s
CPP_OBJS=\
.\$(OBJDIR)\nsCompositeDataSource.obj \
.\$(OBJDIR)\nsContainerCursor.obj \
.\$(OBJDIR)\nsDefaultResourceFactory.obj \
.\$(OBJDIR)\nsEmptyCursor.obj \
.\$(OBJDIR)\nsInMemoryDataSource.obj \
.\$(OBJDIR)\nsRDFContentSink.obj \
.\$(OBJDIR)\nsRDFParserUtils.obj \
.\$(OBJDIR)\nsRDFService.obj \
.\$(OBJDIR)\nsRDFXMLDataSource.obj \
.\$(OBJDIR)\rdfutil.obj \
.\$(OBJDIR)\nsRDFResource.obj \
$(NULL)
LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\netlib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,887 @@
/* -*- 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
* 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.
*/
/*
A simple composite data source implementation. A composit data
source is just a strategy for combining individual data sources into
a collective graph.
1) A composite data source holds a sequence of data sources. The set
of data sources can be specified during creation of the
database. Data sources can also be added/deleted from a database
later.
2) The aggregation mechanism is based on simple super-positioning of
the graphs from the datasources. If there is a conflict (i.e.,
data source A has a true arc from foo to bar while data source B
has a false arc from foo to bar), the data source that it earlier
in the sequence wins.
The implementation below doesn't really do this and needs to be
fixed.
*/
#include "nsIRDFCursor.h"
#include "nsIRDFNode.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFObserver.h"
#include "nsRepository.h"
#include "nsVoidArray.h"
#include "prlog.h"
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
// CompositeDataSourceImpl
class CompositeDataSourceImpl : public nsIRDFCompositeDataSource,
public nsIRDFObserver
{
protected:
nsVoidArray* mObservers;
virtual ~CompositeDataSourceImpl(void);
public:
CompositeDataSourceImpl(void);
CompositeDataSourceImpl(char** dataSources);
nsVoidArray mDataSources;
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFDataSource interface
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(const char* *uri) const;
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source);
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** sources);
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target);
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets);
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv);
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels);
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels);
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
NS_IMETHOD Flush();
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult);
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget);
// nsIRDFCompositeDataSource interface
NS_IMETHOD AddDataSource(nsIRDFDataSource* source);
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source);
// nsIRDFObserver interface
NS_IMETHOD OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
NS_IMETHOD OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
// Implementation methods
PRBool HasAssertionN(int n, nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv);
};
class DBArcsInOutCursor : public nsIRDFArcsOutCursor,
public nsIRDFArcsInCursor
{
CompositeDataSourceImpl* mCompositeDataSourceImpl;
nsIRDFResource* mSource;
nsIRDFNode* mTarget;
PRInt32 mCount;
nsIRDFArcsOutCursor* mOutCursor;
nsIRDFArcsInCursor* mInCursor;
nsVoidArray mResults;
public:
DBArcsInOutCursor(CompositeDataSourceImpl* db, nsIRDFNode* node, PRBool arcsOutp);
virtual ~DBArcsInOutCursor();
NS_DECL_ISUPPORTS
NS_IMETHOD Advance();
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return (mInCursor ? mInCursor->GetDataSource(aDataSource) :
mOutCursor->GetDataSource(aDataSource));
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return mOutCursor->GetSubject(aResource);
}
NS_IMETHOD GetObject(nsIRDFNode** aNode) {
return mInCursor->GetObject(aNode);
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return (mInCursor ? mInCursor->GetPredicate(aPredicate) :
mOutCursor->GetPredicate(aPredicate));
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return (mInCursor ? mInCursor->GetValue(aValue) :
mOutCursor->GetValue(aValue));
}
};
DBArcsInOutCursor::DBArcsInOutCursor(CompositeDataSourceImpl* db,
nsIRDFNode* node,
PRBool arcsOutp)
: mCompositeDataSourceImpl(db),
mTarget(0),
mSource(0),
mCount(0),
mInCursor(0),
mOutCursor(0)
{
NS_INIT_REFCNT();
NS_ADDREF(mCompositeDataSourceImpl);
if (arcsOutp) {
mSource = (nsIRDFResource*) node;
} else {
mTarget = node;
}
NS_IF_ADDREF(node);
// XXX there better be at least _one_ datasource in this here
// CompositeDataSourceImpl, else this'll be a real short ride...
PR_ASSERT(db->mDataSources.Count() > 0);
nsIRDFDataSource* ds = (nsIRDFDataSource*) db->mDataSources[mCount++];
if (mTarget) {
ds->ArcLabelsIn(mTarget, &mInCursor);
} else {
ds->ArcLabelsOut(mSource, &mOutCursor);
}
}
DBArcsInOutCursor::~DBArcsInOutCursor(void)
{
for (PRInt32 i = mResults.Count() - 1; i >= 0; --i) {
nsIRDFNode* node = (nsIRDFNode*) mResults[i];
NS_RELEASE(node);
}
NS_IF_RELEASE(mSource);
NS_IF_RELEASE(mTarget);
NS_IF_RELEASE(mInCursor);
NS_IF_RELEASE(mOutCursor);
NS_RELEASE(mCompositeDataSourceImpl);
}
NS_IMPL_ADDREF(DBArcsInOutCursor);
NS_IMPL_RELEASE(DBArcsInOutCursor);
NS_IMETHODIMP_(nsresult)
DBArcsInOutCursor::QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFArcsOutCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFArcsOutCursor*, this);
NS_ADDREF(this);
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
DBArcsInOutCursor::Advance(void)
{
nsIRDFDataSource* ds;
while (mInCursor || mOutCursor) {
nsresult result = (mInCursor ? mInCursor->Advance() : mOutCursor->Advance());
while (NS_SUCCEEDED(result)) {
nsIRDFNode* obj ;
GetValue(&obj);
if (mResults.IndexOf(obj) < 0) {
mResults.AppendElement(obj);
return NS_OK;
}
result = (mInCursor ? mInCursor->Advance() : mOutCursor->Advance());
}
if (result != NS_ERROR_RDF_CURSOR_EMPTY)
return result;
NS_IF_RELEASE(mInCursor);
NS_IF_RELEASE(mOutCursor);
if (mCount >= mCompositeDataSourceImpl->mDataSources.Count())
break;
ds = (nsIRDFDataSource*) mCompositeDataSourceImpl->mDataSources[mCount];
++mCount;
if (mTarget) {
ds->ArcLabelsIn(mTarget, &mInCursor);
} else {
ds->ArcLabelsOut(mSource, &mOutCursor);
}
}
return NS_ERROR_RDF_CURSOR_EMPTY;
}
////////////////////////////////////////////////////////////////////////
// DBAssertionCursor
//
// An assertion cursor implementation for the db.
//
class DBGetSTCursor : public nsIRDFAssertionCursor
{
private:
CompositeDataSourceImpl* mCompositeDataSourceImpl;
nsIRDFResource* mSource;
nsIRDFResource* mLabel;
nsIRDFNode* mTarget;
PRInt32 mCount;
PRBool mTruthValue;
nsIRDFAssertionCursor* mCurrentCursor;
public:
DBGetSTCursor(CompositeDataSourceImpl* db, nsIRDFNode* u,
nsIRDFResource* property, PRBool inversep, PRBool tv);
virtual ~DBGetSTCursor();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFAssertionCursor interface
NS_IMETHOD Advance();
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return mCurrentCursor->GetDataSource(aDataSource);
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return mCurrentCursor->GetSubject(aResource);
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return mCurrentCursor->GetPredicate(aPredicate);
}
NS_IMETHOD GetObject(nsIRDFNode** aObject) {
return mCurrentCursor->GetObject(aObject);
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return mCurrentCursor->GetTruthValue(aTruthValue);
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return mCurrentCursor->GetValue(aValue);
}
};
//NS_IMPL_ISUPPORTS(DBGetSTCursor, kIRDFAssertionCursorIID);
DBGetSTCursor::DBGetSTCursor(CompositeDataSourceImpl* db,
nsIRDFNode* u,
nsIRDFResource* property,
PRBool inversep,
PRBool tv)
: mCompositeDataSourceImpl(db),
mSource(nsnull),
mLabel(property),
mTarget(nsnull),
mCount(0),
mTruthValue(tv),
mCurrentCursor(nsnull)
{
NS_INIT_REFCNT();
NS_ADDREF(mCompositeDataSourceImpl);
if (!inversep) {
mSource = (nsIRDFResource*) u;
} else {
mTarget = u;
}
NS_IF_ADDREF(mSource);
NS_IF_ADDREF(mTarget);
NS_IF_ADDREF(mLabel);
// XXX assume that at least one data source exists in the CompositeDataSourceImpl.
nsIRDFDataSource* ds = (nsIRDFDataSource*) db->mDataSources[mCount++];
if (mSource)
ds->GetTargets(mSource, mLabel, mTruthValue, &mCurrentCursor);
else
ds->GetSources(mLabel, mTarget, mTruthValue, &mCurrentCursor);
}
DBGetSTCursor::~DBGetSTCursor(void)
{
NS_IF_RELEASE(mCurrentCursor);
NS_IF_RELEASE(mLabel);
NS_IF_RELEASE(mSource);
NS_IF_RELEASE(mTarget);
NS_RELEASE(mCompositeDataSourceImpl);
}
NS_IMPL_ADDREF(DBGetSTCursor);
NS_IMPL_RELEASE(DBGetSTCursor);
NS_IMETHODIMP_(nsresult)
DBGetSTCursor::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFAssertionCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
NS_ADDREF(this);
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
DBGetSTCursor::Advance(void)
{
nsIRDFDataSource* ds;
while (mCurrentCursor) {
nsresult result = mCurrentCursor->Advance();
while (NS_ERROR_RDF_CURSOR_EMPTY != result) {
nsIRDFResource* src;
nsIRDFNode* trg;
mCurrentCursor->GetSubject(&src);
mCurrentCursor->GetObject(&trg);
if (!mCompositeDataSourceImpl->HasAssertionN(mCount-1, src, mLabel, trg, !mTruthValue)) {
return NS_OK;
} else {
result = mCurrentCursor->Advance();
}
}
if (mCount >= mCompositeDataSourceImpl->mDataSources.Count())
break;
ds = (nsIRDFDataSource*) mCompositeDataSourceImpl->mDataSources[mCount];
++mCount;
NS_RELEASE(mCurrentCursor);
if (mSource)
ds->GetTargets(mSource, mLabel, mTruthValue, &mCurrentCursor);
else
ds->GetSources(mLabel, mTarget, mTruthValue, &mCurrentCursor);
}
return NS_ERROR_RDF_CURSOR_EMPTY;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFCompositeDataSource(nsIRDFCompositeDataSource** result)
{
CompositeDataSourceImpl* db = new CompositeDataSourceImpl();
if (! db)
return NS_ERROR_OUT_OF_MEMORY;
*result = db;
NS_ADDREF(*result);
return NS_OK;
}
CompositeDataSourceImpl::CompositeDataSourceImpl(void)
: mObservers(nsnull)
{
NS_INIT_REFCNT();
}
CompositeDataSourceImpl::~CompositeDataSourceImpl(void)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
ds->RemoveObserver(this);
NS_IF_RELEASE(ds);
}
delete mObservers;
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(CompositeDataSourceImpl);
NS_IMPL_RELEASE(CompositeDataSourceImpl);
NS_IMETHODIMP
CompositeDataSourceImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFCompositeDataSourceIID) ||
iid.Equals(kIRDFDataSourceIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFCompositeDataSource*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (iid.Equals(kIRDFObserverIID)) {
*result = NS_STATIC_CAST(nsIRDFObserver*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
*result = nsnull;
return NS_NOINTERFACE;
}
}
////////////////////////////////////////////////////////////////////////
// nsIRDFDataSource interface
NS_IMETHODIMP
CompositeDataSourceImpl::Init(const char* uri)
{
PR_ASSERT(0);
return NS_ERROR_UNEXPECTED; // XXX CompositeDataSourceImpl doesn't have a URI?
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetURI(const char* *uri) const
{
PR_ASSERT(0);
return NS_ERROR_UNEXPECTED; // XXX CompositeDataSourceImpl doesn't have a URI?
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(ds->GetSource(property, target, tv, source)))
continue;
// okay, found it. make sure we don't have the opposite
// asserted in a more local data source
if (!HasAssertionN(count-1, *source, property, target, !tv))
return NS_OK;
NS_RELEASE(*source);
return NS_ERROR_RDF_NO_VALUE;
}
return NS_ERROR_RDF_NO_VALUE;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = new DBGetSTCursor(this, target, property, 1, tv);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*result);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(ds->GetTarget(source, property, tv, target)))
continue;
// okay, found it. make sure we don't have the opposite
// asserted in the "local" data source
if (!HasAssertionN(count-1, source, property, *target, !tv))
return NS_OK;
NS_RELEASE(*target);
return NS_ERROR_RDF_NO_VALUE;
}
return NS_ERROR_RDF_NO_VALUE;
}
PRBool
CompositeDataSourceImpl::HasAssertionN(int n,
nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv)
{
int m = 0;
PRBool result = 0;
while (m < n) {
nsIRDFDataSource* ds = (nsIRDFDataSource*) mDataSources[m];
ds->HasAssertion(source, property, target, tv, &result);
if (result) return 1;
m++;
}
return 0;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets)
{
if (! targets)
return NS_ERROR_NULL_POINTER;
nsIRDFAssertionCursor* result;
result = new DBGetSTCursor(this, source, property, 0, tv);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*targets = result;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv)
{
// Need to add back the stuff for unblocking ...
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_SUCCEEDED(ds->Assert(source, property, target, tv)))
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target)
{
nsresult rv;
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(rv = ds->Unassert(source, property, target)))
break;
}
if (NS_FAILED(rv)) {
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
rv = ds0->Assert(source, property, target, PR_FALSE);
}
return rv;
}
NS_IMETHODIMP
CompositeDataSourceImpl::HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion)
{
nsresult rv;
// Otherwise, look through all the data sources to see if anyone
// has the positive...
PRInt32 count = mDataSources.Count();
PRBool hasNegation = 0;
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(rv = ds->HasAssertion(source, property, target, tv, hasAssertion)))
return rv;
if (*hasAssertion)
return NS_OK;
if (NS_FAILED(rv = ds->HasAssertion(source, property, target, !tv, &hasNegation)))
return rv;
if (hasNegation) {
*hasAssertion = 0;
return NS_OK;
}
}
// If we get here, nobody had the assertion at all
*hasAssertion = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::AddObserver(nsIRDFObserver* obs)
{
if (!mObservers) {
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
// XXX ensure uniqueness?
mObservers->AppendElement(obs);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::RemoveObserver(nsIRDFObserver* obs)
{
if (!mObservers)
return NS_OK;
mObservers->RemoveElement(obs);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels)
{
if (! labels)
return NS_ERROR_NULL_POINTER;
nsIRDFArcsInCursor* result = new DBArcsInOutCursor(this, node, 0);
if (! result)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(result);
*labels = result;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels)
{
if (! labels)
return NS_ERROR_NULL_POINTER;
nsIRDFArcsOutCursor* result = new DBArcsInOutCursor(this, source, 1);
if (! result)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(result);
*labels = result;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetAllResources(nsIRDFResourceCursor** aCursor)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Flush()
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
ds->Flush();
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CompositeDataSourceImpl::DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFCompositeDataSource methods
// XXX rvg We should make this take an additional argument specifying where
// in the sequence of data sources (of the db), the new data source should
// fit in. Right now, the new datasource gets stuck at the end.
// need to add the observers of the CompositeDataSourceImpl to the new data source.
NS_IMETHODIMP
CompositeDataSourceImpl::AddDataSource(nsIRDFDataSource* source)
{
NS_ASSERTION(source != nsnull, "null ptr");
if (! source)
return NS_ERROR_NULL_POINTER;
mDataSources.InsertElementAt(source, 0);
source->AddObserver(this);
NS_ADDREF(source);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::RemoveDataSource(nsIRDFDataSource* source)
{
NS_ASSERTION(source != nsnull, "null ptr");
if (! source)
return NS_ERROR_NULL_POINTER;
if (mDataSources.IndexOf(source) >= 0) {
mDataSources.RemoveElement(source);
source->RemoveObserver(this);
NS_RELEASE(source);
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object)
{
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnAssert(subject, predicate, object);
// XXX ignore return value?
}
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object)
{
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnUnassert(subject, predicate, object);
// XXX ignore return value?
}
}
return NS_OK;
}

View File

@@ -0,0 +1,339 @@
/* -*- 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
* 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.
*/
/*
A simple cursor that enumerates the elements of an RDF container
(RDF:Bag, RDF:Seq, or RDF:Alt).
Caveats
-------
1. This uses an implementation-specific detail to determine the
index of the last element in the container; specifically, the RDF
utilities maintain a counter attribute on the container that
holds the numeric value of the next value that is to be
assigned. So, this cursor will bust if you use it with a bag that
hasn't been created using the RDF utility routines.
2. This is sort of a continuation of (1), but -- it's not smart
enough to notice duplicates.
TODO. This is way too brain dead to handle aggregated RDF
databases. It needs to be upgraded in a big way.
*/
#include "nscore.h"
#include "nsIRDFCursor.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "prlog.h"
#include "rdf.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
////////////////////////////////////////////////////////////////////////
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, nextVal); // ad hoc way to make containers fast
////////////////////////////////////////////////////////////////////////
class ContainerCursorImpl : public nsIRDFAssertionCursor {
private:
// pseudo-constants
static nsrefcnt gRefCnt;
static nsIRDFResource* kRDF_nextVal;
nsIRDFDataSource* mDataSource;
nsIRDFResource* mContainer;
nsIRDFNode* mCurrent;
nsIRDFResource* mOrdinalProperty;
PRInt32 mNextIndex;
public:
ContainerCursorImpl(nsIRDFDataSource* ds, nsIRDFResource* container);
virtual ~ContainerCursorImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD Advance(void);
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
NS_IMETHOD GetSubject(nsIRDFResource** aResource);
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
NS_IMETHOD GetObject(nsIRDFNode** aObject);
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
NS_IMETHOD GetValue(nsIRDFNode** aValue);
};
nsrefcnt ContainerCursorImpl::gRefCnt;
nsIRDFResource* ContainerCursorImpl::kRDF_nextVal;
ContainerCursorImpl::ContainerCursorImpl(nsIRDFDataSource* ds,
nsIRDFResource* container)
: mDataSource(ds),
mContainer(container),
mCurrent(nsnull),
mOrdinalProperty(nsnull),
mNextIndex(1)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(mDataSource);
NS_IF_ADDREF(mContainer);
if (gRefCnt++ == 0) {
nsresult rv;
nsIRDFService* service;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &service);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to acquire resource manager");
if (! service)
return;
NS_VERIFY(NS_SUCCEEDED(rv = service->GetResource(kURIRDF_nextVal, &kRDF_nextVal)),
"unable to get resource");
}
}
ContainerCursorImpl::~ContainerCursorImpl(void)
{
NS_IF_RELEASE(mCurrent);
NS_IF_RELEASE(mOrdinalProperty);
NS_IF_RELEASE(mContainer);
NS_IF_RELEASE(mDataSource);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kRDF_nextVal);
}
}
NS_IMPL_ADDREF(ContainerCursorImpl);
NS_IMPL_RELEASE(ContainerCursorImpl);
NS_IMETHODIMP_(nsresult)
ContainerCursorImpl::QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFAssertionCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
ContainerCursorImpl::Advance(void)
{
nsresult rv;
// release the last value that we were holding
NS_IF_RELEASE(mCurrent);
nsIRDFNode* nextNode = nsnull;
nsIRDFLiteral* nextVal = nsnull;
const PRUnichar* p;
nsAutoString s;
PRInt32 last;
PRInt32 err;
// Figure out the upper bound so we'll know when we're done.
// XXX we could cache all this crap when the cursor gets created.
if (NS_FAILED(rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, &nextNode)))
goto done;
if (NS_FAILED(rv = nextNode->QueryInterface(kIRDFLiteralIID, (void**) &nextVal)))
goto done;
if (NS_FAILED(rv = nextVal->GetValue(&p)))
goto done;
s = p;
last = s.ToInteger(&err);
if (NS_FAILED(err))
goto done;
// initialize rv to the case where mNextIndex has advanced past the
// last element
rv = NS_ERROR_RDF_CURSOR_EMPTY;
while (mNextIndex < last) {
NS_IF_RELEASE(mOrdinalProperty);
if (NS_FAILED(rv = rdf_IndexToOrdinalResource(mNextIndex, &mOrdinalProperty)))
break;
rv = mDataSource->GetTarget(mContainer, mOrdinalProperty, PR_TRUE, &mCurrent);
++mNextIndex;
if (NS_SUCCEEDED(rv)) {
// Don't bother releasing mCurrent; we'll let the AddRef
// serve as the implicit addref that GetNext() should
// perform.
break;
}
}
done:
NS_IF_RELEASE(nextNode);
NS_IF_RELEASE(nextVal);
return rv;
}
NS_IMETHODIMP
ContainerCursorImpl::GetDataSource(nsIRDFDataSource** aDataSource)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(mDataSource);
*aDataSource = mDataSource;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetSubject(nsIRDFResource** aSubject)
{
NS_PRECONDITION(aSubject != nsnull, "null ptr");
if (! aSubject)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(mContainer);
*aSubject = mContainer;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetPredicate(nsIRDFResource** aPredicate)
{
NS_PRECONDITION(aPredicate != nsnull, "null ptr");
if (! aPredicate)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mOrdinalProperty, "unexpected");
if (! mOrdinalProperty)
return NS_ERROR_UNEXPECTED;
NS_ADDREF(mOrdinalProperty);
*aPredicate = mOrdinalProperty;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetObject(nsIRDFNode** aObject)
{
NS_PRECONDITION(aObject != nsnull, "null ptr");
if (! aObject)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mCurrent, "unexpected");
if (! mCurrent)
return NS_ERROR_UNEXPECTED;
NS_ADDREF(mCurrent);
*aObject = mCurrent;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetValue(nsIRDFNode** aObject)
{
NS_PRECONDITION(aObject != nsnull, "null ptr");
if (! aObject)
return NS_ERROR_NULL_POINTER;
if (! mCurrent)
return NS_ERROR_UNEXPECTED;
NS_ADDREF(mCurrent);
*aObject = mCurrent;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetTruthValue(PRBool* aTruthValue)
{
NS_PRECONDITION(aTruthValue != nsnull, "null ptr");
if (! aTruthValue)
return NS_ERROR_NULL_POINTER;
*aTruthValue = PR_TRUE;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewContainerCursor(nsIRDFDataSource* ds,
nsIRDFResource* container,
nsIRDFAssertionCursor** cursor)
{
NS_PRECONDITION(ds != nsnull, "null ptr");
NS_PRECONDITION(container != nsnull, "null ptr");
NS_PRECONDITION(cursor != nsnull, "null ptr");
if (!ds || !container || !cursor)
return NS_ERROR_NULL_POINTER;
NS_ASSERTION(rdf_IsContainer(ds, container), "not a container");
if (! rdf_IsContainer(ds, container))
return NS_ERROR_ILLEGAL_VALUE;
ContainerCursorImpl* result = new ContainerCursorImpl(ds, container);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
*cursor = result;
NS_ADDREF(result);
return NS_OK;
}

View File

@@ -0,0 +1,229 @@
/* -*- 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
* 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.
*/
/*
The default resource factory implementation. This resource factory
produces nsIRDFResource objects for any URI prefix that is not
covered by some other factory.
*/
#include "nsIRDFNode.h"
#include "nsIRDFResourceFactory.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "plstr.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kIRDFResourceFactoryIID, NS_IRDFRESOURCEFACTORY_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
////////////////////////////////////////////////////////////////////////
class DefaultResourceImpl : public nsIRDFResource
{
public:
DefaultResourceImpl(const char* uri);
virtual ~DefaultResourceImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFNode
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
// nsIRDFResource
NS_IMETHOD GetValue(const char* *uri) const;
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
// Implementation methods
const char* GetURI(void) const {
return mURI;
}
private:
char* mURI;
};
DefaultResourceImpl::DefaultResourceImpl(const char* uri)
{
NS_INIT_REFCNT();
mURI = PL_strdup(uri);
}
DefaultResourceImpl::~DefaultResourceImpl(void)
{
nsresult rv;
nsIRDFService* mgr;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &mgr);
PR_ASSERT(NS_SUCCEEDED(rv));
if (NS_SUCCEEDED(rv)) {
mgr->UnCacheResource(this);
nsServiceManager::ReleaseService(kRDFServiceCID, mgr);
}
// N.B. that we need to free the URI *after* we un-cache the resource,
// due to the way that the resource manager is implemented.
PL_strfree(mURI);
}
NS_IMPL_ADDREF(DefaultResourceImpl);
NS_IMPL_RELEASE(DefaultResourceImpl);
nsresult
DefaultResourceImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFResourceIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFResource*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
DefaultResourceImpl::EqualsNode(nsIRDFNode* node, PRBool* result) const
{
nsresult rv;
nsIRDFResource* resource;
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
rv = EqualsResource(resource, result);
NS_RELEASE(resource);
}
else {
*result = PR_FALSE;
rv = NS_OK;
}
return rv;
}
NS_IMETHODIMP
DefaultResourceImpl::GetValue(const char* *uri) const
{
if (!uri)
return NS_ERROR_NULL_POINTER;
*uri = mURI;
return NS_OK;
}
NS_IMETHODIMP
DefaultResourceImpl::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
{
if (!resource || !result)
return NS_ERROR_NULL_POINTER;
*result = (resource == this);
return NS_OK;
}
NS_IMETHODIMP
DefaultResourceImpl::EqualsString(const char* uri, PRBool* result) const
{
if (!uri || !result)
return NS_ERROR_NULL_POINTER;
*result = (PL_strcmp(uri, mURI) == 0);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
class DefaultResourceFactoryImpl : public nsIRDFResourceFactory
{
public:
DefaultResourceFactoryImpl(void);
virtual ~DefaultResourceFactoryImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD CreateResource(const char* aURI, nsIRDFResource** aResult);
};
DefaultResourceFactoryImpl::DefaultResourceFactoryImpl(void)
{
NS_INIT_REFCNT();
}
DefaultResourceFactoryImpl::~DefaultResourceFactoryImpl(void)
{
}
NS_IMPL_ISUPPORTS(DefaultResourceFactoryImpl, kIRDFResourceFactoryIID);
NS_IMETHODIMP
DefaultResourceFactoryImpl::CreateResource(const char* aURI, nsIRDFResource** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
DefaultResourceImpl* resource = new DefaultResourceImpl(aURI);
if (! resource)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(resource);
*aResult = resource;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFDefaultResourceFactory(nsIRDFResourceFactory** result)
{
NS_PRECONDITION(result != nsnull, "null ptr");
if (! result)
return NS_ERROR_NULL_POINTER;
DefaultResourceFactoryImpl* factory = new DefaultResourceFactoryImpl();
if (! factory)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*result = factory;
return NS_OK;
}

View File

@@ -0,0 +1,240 @@
/* -*- 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
* 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.
*/
/*
A set of "empty cursors" (nsIRDFAssertionCursor,
nsIRDFArcsOutCursor, nsIRDFArcsInCursor) that can be used to ensure
that the data source methods which return a cursor always return
*something*.
*/
#include "nscore.h"
#include "nsIRDFCursor.h"
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
class EmptyAssertionCursorImpl : public nsIRDFAssertionCursor
{
public:
EmptyAssertionCursorImpl(void) {};
virtual ~EmptyAssertionCursorImpl(void) {};
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void) {
return 2;
}
NS_IMETHOD_(nsrefcnt) Release(void) {
return 1;
}
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFAssertionCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
// nsIRDFCursor
NS_IMETHOD Advance(void) {
return NS_ERROR_RDF_CURSOR_EMPTY;
}
// nsIRDFAssertionCursor
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetObject(nsIRDFNode** aObject) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return NS_ERROR_UNEXPECTED;
}
};
nsresult
NS_NewEmptyRDFAssertionCursor(nsIRDFAssertionCursor** result)
{
static EmptyAssertionCursorImpl gEmptyAssertionCursor;
*result = &gEmptyAssertionCursor;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
class EmptyArcsOutCursorImpl : public nsIRDFArcsOutCursor
{
public:
EmptyArcsOutCursorImpl(void) {};
virtual ~EmptyArcsOutCursorImpl(void) {};
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void) {
return 2;
}
NS_IMETHOD_(nsrefcnt) Release(void) {
return 1;
}
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFArcsOutCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFArcsOutCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
// nsIRDFCursor
NS_IMETHOD Advance(void) {
return NS_ERROR_RDF_CURSOR_EMPTY;
}
// nsIRDFArcsOutCursor
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return NS_ERROR_UNEXPECTED;
}
};
nsresult
NS_NewEmptyRDFArcsOutCursor(nsIRDFArcsOutCursor** result)
{
static EmptyArcsOutCursorImpl gEmptyArcsOutCursor;
*result = &gEmptyArcsOutCursor;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
class EmptyArcsInCursorImpl : public nsIRDFArcsInCursor
{
public:
EmptyArcsInCursorImpl(void) {};
virtual ~EmptyArcsInCursorImpl(void) {};
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void) {
return 2;
}
NS_IMETHOD_(nsrefcnt) Release(void) {
return 1;
}
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFArcsInCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFArcsInCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
// nsIRDFCursor
NS_IMETHOD Advance(void) {
return NS_ERROR_RDF_CURSOR_EMPTY;
}
// nsIRDFArcsInCursor
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetObject(nsIRDFNode** aNode) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return NS_ERROR_UNEXPECTED;
}
};
nsresult
NS_NewEmptyRDFArcsInCursor(nsIRDFArcsInCursor** result)
{
static EmptyArcsInCursorImpl gEmptyArcsInCursor;
*result = &gEmptyArcsInCursor;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
/* -*- 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
* 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.
*/
/*
This header file just contains prototypes for the factory methods
for "builtin" data sources that are included in rdf.dll.
Each of these data sources is exposed to the external world via its
CID in ../include/nsRDFCID.h.
*/
#ifndef nsBaseDataSources_h__
#define nsBaseDataSources_h__
#include "nsError.h"
class nsIRDFDataSource;
// in nsInMemoryDataSource.cpp
nsresult NS_NewRDFInMemoryDataSource(nsIRDFDataSource** result);
#endif // nsBaseDataSources_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,137 @@
/* -*- 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 "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 Communicator client 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.
*/
/*
*/
#ifndef nsRDFContentSink_h__
#define nsRDFContentSink_h__
#include "nsIRDFContentSink.h"
class nsIURL;
class nsVoidArray;
class nsIRDFResource;
class nsIRDFDataSource;
class nsIRDFService;
class nsINameSpaceManager;
typedef enum {
eRDFContentSinkState_InProlog,
eRDFContentSinkState_InDocumentElement,
eRDFContentSinkState_InDescriptionElement,
eRDFContentSinkState_InContainerElement,
eRDFContentSinkState_InPropertyElement,
eRDFContentSinkState_InMemberElement,
eRDFContentSinkState_InEpilog
} RDFContentSinkState;
class RDFContentSinkImpl : public nsIRDFContentSink
{
public:
RDFContentSinkImpl();
virtual ~RDFContentSinkImpl();
// nsISupports
NS_DECL_ISUPPORTS
// nsIContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
NS_IMETHOD SetParser(nsIParser* aParser);
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
NS_IMETHOD AddComment(const nsIParserNode& aNode);
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
NS_IMETHOD NotifyError(nsresult aErrorResult);
// nsIXMLContentSink
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
// nsIRDFContentSink
NS_IMETHOD SetDataSource(nsIRDFDataSource* ds);
NS_IMETHOD GetDataSource(nsIRDFDataSource*& ds);
NS_IMETHOD Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager);
protected:
// Text management
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
PRBool* aDidFlush=nsnull);
PRUnichar* mText;
PRInt32 mTextLength;
PRInt32 mTextSize;
PRBool mConstrainSize;
// namespace management
void PushNameSpacesFrom(const nsIParserNode& aNode);
nsIAtom* CutNameSpacePrefix(nsString& aString);
PRInt32 GetNameSpaceID(nsIAtom* aPrefix);
void GetNameSpaceURI(PRInt32 aID, nsString& aURI);
void PopNameSpaces();
nsINameSpaceManager* mNameSpaceManager;
nsVoidArray* mNameSpaceStack;
PRInt32 mRDFNameSpaceID;
void SplitQualifiedName(const nsString& aQualifiedName,
PRInt32& rNameSpaceID,
nsString& rProperty);
// RDF-specific parsing
nsresult GetIdAboutAttribute(const nsIParserNode& aNode, nsString& rResource);
nsresult GetResourceAttribute(const nsIParserNode& aNode, nsString& rResource);
nsresult AddProperties(const nsIParserNode& aNode, nsIRDFResource* aSubject);
virtual nsresult OpenRDF(const nsIParserNode& aNode);
virtual nsresult OpenObject(const nsIParserNode& aNode);
virtual nsresult OpenProperty(const nsIParserNode& aNode);
virtual nsresult OpenMember(const nsIParserNode& aNode);
virtual nsresult OpenValue(const nsIParserNode& aNode);
// Miscellaneous RDF junk
nsIRDFService* mRDFService;
nsIRDFDataSource* mDataSource;
RDFContentSinkState mState;
// content stack management
PRInt32 PushContext(nsIRDFResource *aContext, RDFContentSinkState aState);
nsresult PopContext(nsIRDFResource*& rContext, RDFContentSinkState& rState);
nsIRDFResource* GetContextElement(PRInt32 ancestor = 0);
nsVoidArray* mContextStack;
nsIURL* mDocumentURL;
PRUint32 mGenSym; // for generating anonymous resources
};
#endif // nsRDFContentSink_h__

View File

@@ -0,0 +1,245 @@
/* -*- 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 "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 Communicator client 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.
*/
/*
Some useful parsing routines.
This isn't the best place for them: I wish that they'd go into some
shared area (like mozilla/base).
*/
#include <stdlib.h> // XXX for atoi(), maybe this should go into nsCRT?
#include "nsCRT.h"
#include "nsIURL.h"
#include "nsString.h"
#include "nsRDFParserUtils.h"
// XXX This totally sucks. I wish that mozilla/base had this code.
PRUnichar
nsRDFParserUtils::EntityToUnicode(const char* buf)
{
if ((buf[0] == 'g' || buf[0] == 'G') &&
(buf[1] == 't' || buf[1] == 'T'))
return PRUnichar('>');
if ((buf[0] == 'l' || buf[0] == 'L') &&
(buf[1] == 't' || buf[1] == 'T'))
return PRUnichar('<');
if ((buf[0] == 'a' || buf[0] == 'A') &&
(buf[1] == 'm' || buf[1] == 'M') &&
(buf[2] == 'p' || buf[2] == 'P'))
return PRUnichar('&');
NS_NOTYETIMPLEMENTED("this is a named entity that I can't handle...");
return PRUnichar('?');
}
// XXX Code copied from nsHTMLContentSink. It should be shared.
void
nsRDFParserUtils::StripAndConvert(nsString& aResult)
{
// Strip quotes if present
PRUnichar first = aResult.First();
if ((first == '"') || (first == '\'')) {
if (aResult.Last() == first) {
aResult.Cut(0, 1);
PRInt32 pos = aResult.Length() - 1;
if (pos >= 0) {
aResult.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
// Reduce any entities
// XXX Note: as coded today, this will only convert well formed
// entities. This may not be compatible enough.
// XXX there is a table in navigator that translates some numeric entities
// should we be doing that? If so then it needs to live in two places (bad)
// so we should add a translate numeric entity method from the parser...
char cbuf[100];
PRInt32 index = 0;
while (index < aResult.Length()) {
// If we have the start of an entity (and it's not at the end of
// our string) then translate the entity into it's unicode value.
if ((aResult.CharAt(index++) == '&') && (index < aResult.Length())) {
PRInt32 start = index - 1;
PRUnichar e = aResult.CharAt(index);
if (e == '#') {
// Convert a numeric character reference
index++;
char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1;
PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length();
while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index);
if (e == ';') {
index++;
ok = PR_TRUE;
break;
}
if ((e >= '0') && (e <= '9')) {
*cp++ = char(e);
index++;
continue;
}
break;
}
if (!ok || (cp == cbuf)) {
continue;
}
*cp = '\0';
if (cp - cbuf > 5) {
continue;
}
PRInt32 ch = PRInt32( ::atoi(cbuf) );
if (ch > 65535) {
continue;
}
// Remove entity from string and replace it with the integer
// value.
aResult.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start);
index = start + 1;
}
else if (((e >= 'A') && (e <= 'Z')) ||
((e >= 'a') && (e <= 'z'))) {
// Convert a named entity
index++;
char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1;
*cp++ = char(e);
PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length();
while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index);
if (e == ';') {
index++;
ok = PR_TRUE;
break;
}
if (((e >= '0') && (e <= '9')) ||
((e >= 'A') && (e <= 'Z')) ||
((e >= 'a') && (e <= 'z'))) {
*cp++ = char(e);
index++;
continue;
}
break;
}
if (!ok || (cp == cbuf)) {
continue;
}
*cp = '\0';
PRInt32 ch;
// XXX Um, here's where we should be converting a
// named entity. I removed this to avoid a link-time
// dependency on core raptor.
ch = EntityToUnicode(cbuf);
if (ch < 0) {
continue;
}
// Remove entity from string and replace it with the integer
// value.
aResult.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start);
index = start + 1;
}
else if (e == '{') {
// Convert a script entity
// XXX write me!
NS_NOTYETIMPLEMENTED("convert a script entity");
}
}
}
}
nsresult
nsRDFParserUtils::GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue)
{
static const char kQuote = '\"';
static const char kApostrophe = '\'';
PRInt32 offset;
PRInt32 endOffset = -1;
nsresult result = NS_OK;
offset = aSource.Find(aAttribute);
if (-1 != offset) {
offset = aSource.Find('=', offset);
PRUnichar next = aSource.CharAt(++offset);
if (kQuote == next) {
endOffset = aSource.Find(kQuote, ++offset);
}
else if (kApostrophe == next) {
endOffset = aSource.Find(kApostrophe, ++offset);
}
if (-1 != endOffset) {
aSource.Mid(aValue, offset, endOffset-offset);
}
else {
// Mismatched quotes - return an error
result = NS_ERROR_FAILURE;
}
}
else {
aValue.Truncate();
}
return result;
}
PRBool
nsRDFParserUtils::IsJavaScriptLanguage(const nsString& aName)
{
if (aName.EqualsIgnoreCase("JavaScript") ||
aName.EqualsIgnoreCase("LiveScript") ||
aName.EqualsIgnoreCase("Mocha")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.1")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.2")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.3")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.4")) {
return PR_TRUE;
}
else {
return PR_FALSE;
}
}

View File

@@ -0,0 +1,55 @@
/* -*- 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 "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 Communicator client 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.
*/
/*
Some useful parsing routines.
*/
#ifndef nsRDFParserUtils_h__
#define nsRDFParserUtils_h__
#include "nscore.h"
class nsIURL;
class nsString;
class nsRDFParserUtils {
public:
static PRUnichar
EntityToUnicode(const char* buf);
static void
StripAndConvert(nsString& aResult);
static nsresult
GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue);
static PRBool
IsJavaScriptLanguage(const nsString& aName);
};
#endif // nsRDFPasrserUtils_h__

View File

@@ -0,0 +1,117 @@
/* -*- Mode: C++; tab-width: 2; 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
* 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 "nsRDFResource.h"
#include "nsCRT.h"
////////////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
nsRDFResource::nsRDFResource(const char* uri)
: mURI(uri)
{
}
nsRDFResource::~nsRDFResource(void)
{
}
NS_IMPL_ADDREF(nsRDFResource)
NS_IMPL_RELEASE(nsRDFResource)
NS_IMETHODIMP
nsRDFResource::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFResourceIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFResource*, this);
}
if (*result != nsnull) {
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRDFNode methods:
NS_METHOD
nsRDFResource::EqualsNode(nsIRDFNode* node, PRBool* result) const
{
nsresult rv;
nsIRDFResource* resource;
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
rv = EqualsResource(resource, result);
NS_RELEASE(resource);
}
else {
*result = PR_FALSE;
rv = NS_OK;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRDFResource methods:
NS_METHOD
nsRDFResource::GetValue(const char* *uri) const
{
if (!uri)
return NS_ERROR_NULL_POINTER;
*uri = mURI;
return NS_OK;
}
NS_METHOD
nsRDFResource::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
{
if (!resource || !result)
return NS_ERROR_NULL_POINTER;
const char *uri;
if (NS_SUCCEEDED(resource->GetValue(&uri))) {
return EqualsString(uri, result) ? NS_OK : NS_ERROR_FAILURE;
}
return NS_ERROR_FAILURE;
}
NS_METHOD
nsRDFResource::EqualsString(const char* uri, PRBool* result) const
{
if (!uri || !result)
return NS_ERROR_NULL_POINTER;
*result = nsCRT::strcmp(uri, mURI) == 0;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,759 @@
/* -*- 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
* 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.
*/
/*
This file provides the implementation for the RDF service manager.
TO DO
-----
1) Figure out a better way to do "pluggable resources." Currently,
we have two _major_ hacks:
RegisterBuiltInNamedDataSources()
RegisterBuiltInResourceFactories()
These introduce dependencies on the datasource directory. You'd
like to have this stuff discovered dynamically at startup or
something. Maybe from the registry.
2) Implement the CreateDataBase() methods.
*/
#include "nsIAtom.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIRDFResourceFactory.h"
#include "nsString.h"
#include "plhash.h"
#include "plstr.h"
#include "prlog.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
// PrefixMap
//
// A simple map from a string prefix to a value. It maintains an
// ordered list of prefixes that map to a <tt>void*</tt>. The list
// is sorted in ASCII order such that if one prefix <b>p</b> is
// itself a prefix of another prefix <b>q</b>, the longest prefix
// (<b>q</b>) will appear first in the list. The idea is that you
// want to find the "best" match first. (Will this actually be
// useful? Probabably not...)
//
class PrefixMap
{
private:
struct PrefixMapEntry
{
const char* mPrefix;
PRInt32 mPrefixLen;
const void* mValue;
PrefixMapEntry* mNext;
};
PrefixMapEntry* mHead;
public:
PrefixMap();
~PrefixMap();
PRBool Add(const char* aPrefix, const void* aValue);
const void* Remove(const char* aPrefix);
/**
* Find the most specific value matching the specified string.
*/
const void* Find(const char* aString);
};
PrefixMap::PrefixMap()
: mHead(nsnull)
{
}
PrefixMap::~PrefixMap()
{
while (mHead) {
PrefixMapEntry* doomed = mHead;
mHead = mHead->mNext;
PL_strfree(NS_CONST_CAST(char*, doomed->mPrefix));
delete doomed;
}
}
PRBool
PrefixMap::Add(const char* aPrefix, const void* aValue)
{
PRInt32 newPrefixLen = PL_strlen(aPrefix);
PrefixMapEntry* entry = mHead;
PrefixMapEntry* last = nsnull;
while (entry != nsnull) {
// check to see if the new prefix is longer than the current
// entry. If so, we'll want to insert the new prefix *before*
// this one.
if (newPrefixLen > entry->mPrefixLen)
break;
// check for exact equality: if so, the prefix is already
// registered, so fail (?)
if (PL_strcmp(entry->mPrefix, aPrefix) == 0)
return PR_FALSE;
// otherwise, the new prefix is the same length or shorter
// than the current entry: continue on to the next one.
last = entry;
entry = entry->mNext;
}
PrefixMapEntry* newEntry = new PrefixMapEntry;
if (! newEntry)
return PR_FALSE;
newEntry->mPrefix = PL_strdup(aPrefix);
newEntry->mPrefixLen = newPrefixLen;
newEntry->mValue = aValue;
if (last) {
// we found an entry that we need to insert the current
// entry *before*
newEntry->mNext = last->mNext;
last->mNext = newEntry;
}
else {
// Otherwise, insert at the start
newEntry->mNext = mHead;
mHead = newEntry;
}
return PR_TRUE;
}
const void*
PrefixMap::Remove(const char* aPrefix)
{
PrefixMapEntry* entry = mHead;
PrefixMapEntry* last = nsnull;
PRInt32 doomedPrefixLen = PL_strlen(aPrefix);
while (entry != nsnull) {
if ((doomedPrefixLen == entry->mPrefixLen) &&
(PL_strcmp(entry->mPrefix, aPrefix) == 0)) {
if (last) {
last->mNext = entry->mNext;
}
else {
mHead = entry->mNext;
}
const void* value = entry->mValue;
PL_strfree(NS_CONST_CAST(char*, entry->mPrefix));
delete entry;
return value;
}
last = entry;
entry = entry->mNext;
}
return nsnull;
}
const void*
PrefixMap::Find(const char* aString)
{
for (PrefixMapEntry* entry = mHead; entry != nsnull; entry = entry->mNext) {
PRInt32 cmp = PL_strncmp(entry->mPrefix, aString, entry->mPrefixLen);
if (cmp == 0)
return entry->mValue;
}
return nsnull;
}
////////////////////////////////////////////////////////////////////////
// LiteralImpl
//
// Currently, all literals are implemented exactly the same way;
// i.e., there is are no resource factories to allow you to generate
// customer resources. I doubt that makes sense, anyway.
//
// What _may_ make sense is to atomize literals (well, at least
// short ones), to reduce in memory overhead at the expense of some
// processing time.
//
class LiteralImpl : public nsIRDFLiteral {
public:
LiteralImpl(const PRUnichar* s);
virtual ~LiteralImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFNode
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
// nsIRDFLiteral
NS_IMETHOD GetValue(const PRUnichar* *value) const;
NS_IMETHOD EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const;
private:
nsAutoString mValue;
};
LiteralImpl::LiteralImpl(const PRUnichar* s)
: mValue(s)
{
NS_INIT_REFCNT();
}
LiteralImpl::~LiteralImpl(void)
{
}
NS_IMPL_ADDREF(LiteralImpl);
NS_IMPL_RELEASE(LiteralImpl);
nsresult
LiteralImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFLiteralIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFLiteral*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
LiteralImpl::EqualsNode(nsIRDFNode* node, PRBool* result) const
{
nsresult rv;
nsIRDFLiteral* literal;
if (NS_SUCCEEDED(node->QueryInterface(kIRDFLiteralIID, (void**) &literal))) {
rv = EqualsLiteral(literal, result);
NS_RELEASE(literal);
}
else {
*result = PR_FALSE;
rv = NS_OK;
}
return rv;
}
NS_IMETHODIMP
LiteralImpl::GetValue(const PRUnichar* *value) const
{
NS_ASSERTION(value, "null ptr");
if (! value)
return NS_ERROR_NULL_POINTER;
*value = mValue.GetUnicode();
return NS_OK;
}
NS_IMETHODIMP
LiteralImpl::EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const
{
NS_ASSERTION(literal && result, "null ptr");
if (!literal || !result)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const PRUnichar* p;
if (NS_FAILED(rv = literal->GetValue(&p)))
return rv;
nsAutoString s(p);
*result = s.Equals(mValue);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// ServiceImpl
//
// This is the RDF service.
//
class ServiceImpl : public nsIRDFService
{
protected:
PrefixMap mResourceFactories;
PLHashTable* mNamedDataSources;
PLHashTable* mDataSourceConstructors;
PLHashTable* mResources;
ServiceImpl(void);
virtual ~ServiceImpl(void);
static nsIRDFService* gRDFService; // The one-and-only RDF service
static void RegisterBuiltInResourceFactories();
static void RegisterBuiltInNamedDataSources();
public:
static nsresult GetRDFService(nsIRDFService** result);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFService
NS_IMETHOD GetResource(const char* uri, nsIRDFResource** resource);
NS_IMETHOD GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource);
NS_IMETHOD GetLiteral(const PRUnichar* value, nsIRDFLiteral** literal);
NS_IMETHOD UnCacheResource(nsIRDFResource* resource);
NS_IMETHOD RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory);
NS_IMETHOD UnRegisterResourceFactory(const char* aURIPrefix);
NS_IMETHOD RegisterDataSource(nsIRDFDataSource* dataSource);
NS_IMETHOD UnregisterDataSource(nsIRDFDataSource* dataSource);
NS_IMETHOD RegisterDataSourceConstructor(const char* uri, NSDataSourceConstructorCallback fn);
NS_IMETHOD UnregisterDataSourceConstructor(const char* uri);
NS_IMETHOD GetDataSource(const char* uri, nsIRDFDataSource** dataSource);
NS_IMETHOD CreateDatabase(const char** uris, nsIRDFDataBase** dataBase);
NS_IMETHOD CreateBrowserDatabase(nsIRDFDataBase** dataBase);
};
nsIRDFService* ServiceImpl::gRDFService = nsnull;
////////////////////////////////////////////////////////////////////////
ServiceImpl::ServiceImpl(void)
: mResources(nsnull), mNamedDataSources(nsnull)
{
NS_INIT_REFCNT();
mResources = PL_NewHashTable(1023, // nbuckets
PL_HashString, // hash fn
PL_CompareStrings, // key compare fn
PL_CompareValues, // value compare fn
nsnull, nsnull); // alloc ops & priv
mNamedDataSources = PL_NewHashTable(23,
PL_HashString,
PL_CompareStrings,
PL_CompareValues,
nsnull, nsnull);
mDataSourceConstructors = PL_NewHashTable(23,
PL_HashString,
PL_CompareStrings,
PL_CompareValues,
nsnull, nsnull);
}
ServiceImpl::~ServiceImpl(void)
{
if (mDataSourceConstructors) {
PL_HashTableDestroy(mDataSourceConstructors);
mDataSourceConstructors = nsnull;
}
if (mNamedDataSources) {
PL_HashTableDestroy(mNamedDataSources);
mNamedDataSources = nsnull;
}
if (mResources) {
PL_HashTableDestroy(mResources);
mResources = nsnull;
}
gRDFService = nsnull;
}
nsresult
ServiceImpl::GetRDFService(nsIRDFService** mgr)
{
if (! gRDFService) {
gRDFService = new ServiceImpl();
if (! gRDFService)
return NS_ERROR_OUT_OF_MEMORY;
RegisterBuiltInResourceFactories();
RegisterBuiltInNamedDataSources();
}
NS_ADDREF(gRDFService);
*mgr = gRDFService;
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
ServiceImpl::AddRef(void)
{
return 2;
}
NS_IMETHODIMP_(nsrefcnt)
ServiceImpl::Release(void)
{
return 1;
}
NS_IMPL_QUERY_INTERFACE(ServiceImpl, kIRDFServiceIID);
NS_IMETHODIMP
ServiceImpl::GetResource(const char* uri, nsIRDFResource** resource)
{
nsIRDFResource* result =
NS_STATIC_CAST(nsIRDFResource*, PL_HashTableLookup(mResources, uri));
if (! result) {
nsIRDFResourceFactory* factory =
NS_STATIC_CAST(nsIRDFResourceFactory*,
NS_CONST_CAST(void*, mResourceFactories.Find(uri)));
PR_ASSERT(factory != nsnull);
if (! factory)
return NS_ERROR_FAILURE; // XXX
nsresult rv;
if (NS_FAILED(rv = factory->CreateResource(uri, &result)))
return rv;
const char* uri;
result->GetValue(&uri);
// This is a little trick to make storage more efficient. For
// the "key" in the table, we'll use the string value that's
// stored as a member variable of the nsIRDFResource object.
PL_HashTableAdd(mResources, uri, result);
// *We* don't AddRef() the resource: that way, the resource
// can be garbage collected when the last refcount goes
// away. The single addref that the CreateResource() call made
// will be owned by the callee.
}
else {
// Addref for the callee.
NS_ADDREF(result);
}
*resource = result;
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource)
{
nsString s(uri);
char* cstr = s.ToNewCString();
nsresult rv = GetResource(cstr, resource);
delete[] cstr;
return rv;
}
NS_IMETHODIMP
ServiceImpl::GetLiteral(const PRUnichar* uri, nsIRDFLiteral** literal)
{
LiteralImpl* result = new LiteralImpl(uri);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
*literal = result;
NS_ADDREF(result);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::UnCacheResource(nsIRDFResource* resource)
{
nsresult rv;
const char* uri;
if (NS_FAILED(rv = resource->GetValue(&uri)))
return rv;
PL_HashTableRemove(mResources, uri);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory)
{
if (! mResourceFactories.Add(aURIPrefix, aFactory))
return NS_ERROR_ILLEGAL_VALUE;
NS_ADDREF(aFactory); // XXX should we addref?
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::UnRegisterResourceFactory(const char* aURIPrefix)
{
nsIRDFResourceFactory* factory =
NS_STATIC_CAST(nsIRDFResourceFactory*,
NS_CONST_CAST(void*, mResourceFactories.Remove(aURIPrefix)));
if (! factory)
return NS_ERROR_ILLEGAL_VALUE;
NS_RELEASE(factory); // XXX should we addref?
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::RegisterDataSource(nsIRDFDataSource* aDataSource)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const char* uri;
if (NS_FAILED(rv = aDataSource->GetURI(&uri)))
return rv;
// XXX check for dups, etc.
PL_HashTableAdd(mNamedDataSources, uri, aDataSource);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const char* uri;
if (NS_FAILED(rv = aDataSource->GetURI(&uri)))
return rv;
nsIRDFDataSource* ds =
NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri));
if (! ds)
return NS_ERROR_ILLEGAL_VALUE;
PL_HashTableRemove(mNamedDataSources, uri);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::RegisterDataSourceConstructor(const char* uri, NSDataSourceConstructorCallback fn)
{
// XXX check for dups, etc.
PL_HashTableAdd(mDataSourceConstructors, uri, fn);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::UnregisterDataSourceConstructor(const char* uri)
{
PL_HashTableRemove(mDataSourceConstructors, uri);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::GetDataSource(const char* uri, nsIRDFDataSource** aDataSource)
{
nsIRDFDataSource* ds =
NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri));
if (ds) {
NS_ADDREF(ds);
*aDataSource = ds;
return NS_OK;
}
// Otherwise, see if we have a lazy constructor
NSDataSourceConstructorCallback constructor =
(NSDataSourceConstructorCallback)
PL_HashTableLookup(mDataSourceConstructors, uri);
if (constructor) {
// Yep, so try to construct it on the fly...
nsresult rv;
if (NS_FAILED(rv = constructor(&ds))) {
#ifdef DEBUG
printf("error constructing built-in datasource %s\n", uri);
#endif
return rv;
}
// If it wants to register itself, it should do so in the Init() method.
if (NS_FAILED(rv = ds->Init(uri))) {
#ifdef DEBUG
printf("error initializing named datasource %s\n", uri);
#endif
NS_RELEASE(ds);
return rv;
}
// constructor did an implicit addref
*aDataSource = ds;
return NS_OK;
}
// XXX at this point, we might want to try to construct a
// stream URI and load it that way...
return NS_ERROR_ILLEGAL_VALUE;
}
NS_IMETHODIMP
ServiceImpl::CreateDatabase(const char** uri, nsIRDFDataBase** dataBase)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ServiceImpl::CreateBrowserDatabase(nsIRDFDataBase** dataBase)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
//
// This is Big Hack #1. Depedencies on all builtin resource
// factories are *here*, in the ResourceFactoryTable.
//
struct ResourceFactoryTable {
const char* mPrefix;
nsresult (*mFactoryConstructor)(nsIRDFResourceFactory** result);
};
void
ServiceImpl::RegisterBuiltInResourceFactories(void)
{
extern nsresult NS_NewRDFDefaultResourceFactory(nsIRDFResourceFactory** result);
extern nsresult NS_NewRDFMailResourceFactory(nsIRDFResourceFactory** result);
extern nsresult NS_NewRDFMailAccountResourceFactory(nsIRDFResourceFactory** result);
extern nsresult NS_NewRDFFileResourceFactory(nsIRDFResourceFactory** result);
static ResourceFactoryTable gTable[] = {
"", NS_NewRDFDefaultResourceFactory,
"mailaccount:", NS_NewRDFMailAccountResourceFactory,
"mailbox:", NS_NewRDFMailResourceFactory,
#if 0
"file:", NS_NewRDFFileResourceFactory,
#endif
nsnull, nsnull
};
nsresult rv;
for (ResourceFactoryTable* entry = gTable; entry->mPrefix != nsnull; ++entry) {
nsIRDFResourceFactory* factory;
if (NS_FAILED(rv = (entry->mFactoryConstructor)(&factory)))
continue;
rv = gRDFService->RegisterResourceFactory(entry->mPrefix, factory);
PR_ASSERT(NS_SUCCEEDED(rv));
NS_RELEASE(factory);
}
}
////////////////////////////////////////////////////////////////////////
//
// This is Big Hack #2. Dependencies on all builtin datasources are
// *here*, in the DataSourceTable.
//
// FWIW, I don't particularly like this interface *anyway*, because
// it requires each built-in data source to be constructed "up
// front". Not only does it cause the service manager to be
// re-entered (which may be a problem), but it's wasteful: I think
// these data sources should be created on demand, and released when
// you're done with them.
//
struct DataSourceTable {
const char* mURI;
nsresult (*mDataSourceConstructor)(nsIRDFDataSource** result);
};
void
ServiceImpl::RegisterBuiltInNamedDataSources(void)
{
extern nsresult NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result);
extern nsresult NS_NewRDFHistoryDataSource(nsIRDFDataSource** result);
extern nsresult NS_NewRDFLocalFileSystemDataSource(nsIRDFDataSource** result);
extern nsresult NS_NewRDFMailDataSource(nsIRDFDataSource** result);
static DataSourceTable gTable[] = {
"rdf:bookmarks", NS_NewRDFBookmarkDataSource,
"rdf:mail", NS_NewRDFMailDataSource,
#if 0
"rdf:history", NS_NewRDFHistoryDataSource,
"rdf:lfs", NS_NewRDFLocalFileSystemDataSource,
#endif
nsnull, nsnull
};
nsresult rv;
for (DataSourceTable* entry = gTable; entry->mURI != nsnull; ++entry) {
if (NS_FAILED(rv = gRDFService->RegisterDataSourceConstructor(entry->mURI, entry->mDataSourceConstructor))) {
#ifdef DEBUG
printf("error registering built-in datasource constructor for %s\n", entry->mURI);
#endif
continue;
}
}
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFService(nsIRDFService** mgr)
{
return ServiceImpl::GetRDFService(mgr);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,240 @@
/* -*- 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 "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 Communicator client 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.
*/
/*
A bunch of useful RDF utility routines. Many of these will
eventually be exported outside of RDF.DLL via the nsIRDFService
interface.
*/
#ifndef rdfutil_h__
#define rdfutil_h__
#include "prtypes.h"
class nsIRDFCursor;
class nsIRDFDataBase;
class nsIRDFDataSource;
class nsIRDFNode;
class nsString;
/**
* Returns PR_TRUE if the URI is an RDF ordinal property; e.g., rdf:_1,
* rdf:_2, etc.
*/
PR_EXTERN(PRBool)
rdf_IsOrdinalProperty(const nsIRDFResource* property);
/**
* Converts an ordinal property to an index
*/
PR_EXTERN(nsresult)
rdf_OrdinalResourceToIndex(nsIRDFResource* aOrdinal, PRInt32* aIndex);
/**
* Converts an index to an ordinal property
*/
PR_EXTERN(nsresult)
rdf_IndexToOrdinalResource(PRInt32 aIndex, nsIRDFResource** aOrdinal);
/**
* Returns PR_TRUE if the resource is a container resource; e.g., an
* rdf:Bag.
*/
PR_EXTERN(PRBool)
rdf_IsContainer(nsIRDFDataSource* db,
nsIRDFResource* resource);
PR_EXTERN(PRBool)
rdf_IsBag(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource);
PR_EXTERN(PRBool)
rdf_IsSeq(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource);
PR_EXTERN(PRBool)
rdf_IsAlt(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource);
/**
* Various utilities routines for making assertions in a data source
*/
// 0. node, node, node
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
// 1. string, string, string
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
const nsString& subjectURI,
const nsString& predicateURI,
const nsString& objectURI);
// 2. node, node, string
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
nsIRDFResource* predicate,
const nsString& objectURI);
// 3. node, string, string
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
const nsString& predicateURI,
const nsString& objectURI);
// 4. node, string, node
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
const nsString& predicateURI,
nsIRDFNode* object);
// 5. string, string, node
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
const nsString& subjectURI,
const nsString& predicateURI,
nsIRDFNode* object);
/**
* Construct a new, "anonymous" node; that is, a node with an internal
* resource URI.
*/
PR_EXTERN(nsresult)
rdf_CreateAnonymousResource(const nsString& aContextURI, nsIRDFResource** result);
/**
* Determine if a resource is an "anonymous" resource that we've constructed
* ourselves.
*/
PR_EXTERN(PRBool)
rdf_IsAnonymousResource(const nsString& aContextURI, nsIRDFResource* aResource);
/**
* Try to convert the absolute URL into a relative URL.
*/
PR_EXTERN(nsresult)
rdf_PossiblyMakeRelative(const nsString& aContextURI, nsString& aURI);
/**
* Try to convert the possibly-relative URL into an absolute URL.
*/
PR_EXTERN(nsresult)
rdf_PossiblyMakeAbsolute(const nsString& aContextURI, nsString& aURI);
/**
* Create a bag resource.
*/
PR_EXTERN(nsresult)
rdf_MakeBag(nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Create a sequence resource.
*/
PR_EXTERN(nsresult)
rdf_MakeSeq(nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Create an alternation resource.
*/
PR_EXTERN(nsresult)
rdf_MakeAlt(nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Add an element to the end of container.
*/
PR_EXTERN(nsresult)
rdf_ContainerAppendElement(nsIRDFDataSource* ds,
nsIRDFResource* container,
nsIRDFNode* element);
/**
* Remove an element from a container
*/
PR_EXTERN(nsresult)
rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsIRDFNode* aElement);
/**
* Insert an element into a container at the specified index.
*/
PR_EXTERN(nsresult)
rdf_ContainerInsertElementAt(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsIRDFNode* aElement,
PRInt32 aIndex);
/**
* Determine the index of an element in a container.
*/
PR_EXTERN(nsresult)
rdf_ContainerIndexOf(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsIRDFNode* aElement,
PRInt32* aIndex);
/**
* Create a cursor on a container that enumerates its contents in
* order
*/
PR_EXTERN(nsresult)
NS_NewContainerCursor(nsIRDFDataSource* ds,
nsIRDFResource* container,
nsIRDFAssertionCursor** cursor);
/**
* Create an empty nsIRDFCursor. This will *never* fail, and will *always*
* return the same object.
*/
PR_EXTERN(nsresult)
NS_NewEmptyRDFAssertionCursor(nsIRDFAssertionCursor** result);
PR_EXTERN(nsresult)
NS_NewEmptyRDFArcsInCursor(nsIRDFArcsInCursor** result);
PR_EXTERN(nsresult)
NS_NewEmptyRDFArcsOutCursor(nsIRDFArcsOutCursor** result);
// XXX need to move nsEmptyCursor stuff here.
#endif // rdfutil_h__

View File

@@ -0,0 +1 @@
nsRDFCID.h

View File

@@ -0,0 +1,69 @@
#!gmake
#
# 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.
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rdf
CPPSRCS = \
nsRDFFactory.cpp \
$(NULL)
EXPORTS = \
nsRDFCID.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = rdf
REQUIRES = dom js netlib rdf raptor xpcom
# XXX Note dependencies on implementation headers for factory functions
INCLUDES += -I$(srcdir)/../base/src \
-I$(srcdir)/../content/src \
-I$(srcdir)/../datasource/src \
$(NULL)
EXTRA_DSO_LDOPTS = \
-L$(DIST)/bin \
-L$(DIST)/lib \
-lrdfbase_s \
-lrdfcontent_s \
-lrdfdatasource_s \
$(NULL)
include $(topsrcdir)/config/rules.mk
install:: $(TARGETS)
$(INSTALL) $(srcdir)/../resources/Mail/joe@meer.net/inbox $(DIST)/bin/res/rdf/Mail/joe@meer.net
$(INSTALL) $(srcdir)/../resources/sidebar.xul $(DIST)/bin/res/rdf
$(INSTALL) $(srcdir)/../resources/sidebar.css $(DIST)/bin/res/rdf
$(INSTALL) $(srcdir)/../resources/bookmarks.html $(DIST)/bin/res/rdf
$(INSTALL) $(srcdir)/../resources/Mail/joe@meer.net/work $(DIST)/bin/res/rdf/Mail/joe@meer.net
$(INSTALL) $(srcdir)/../resources/Mail/joe@meer.net/other $(DIST)/bin/res/rdf/Mail/joe@meer.net
$(INSTALL) $(srcdir)/../resources/Mail/jane@aol.com/inbox $(DIST)/bin/res/rdf/Mail/jane@aol.com
$(INSTALL) $(srcdir)/../resources/Mail/jane@aol.com/hiking $(DIST)/bin/res/rdf/Mail/jane@aol.com
$(INSTALL) $(srcdir)/../resources/Mail/jane@aol.com/trash $(DIST)/bin/res/rdf/Mail/jane@aol.com

View File

@@ -0,0 +1,83 @@
#!gmake
#
# 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.
DEPTH=..\..
MODULE=rdf
MAKE_OBJ_TYPE=DLL
DLLNAME=rdf
DLL=.\$(OBJDIR)\$(DLLNAME).dll
EXPORTS=\
nsRDFCID.h \
$(NULL)
CPP_OBJS=\
.\$(OBJDIR)\nsRDFFactory.obj \
$(NULL)
# XXX linking in raptor is a heinous crime that will go away once we
# have a more DOM-based mechanism for constructing elements and
# hooking in to their changes.
LLIBS=\
$(DIST)\lib\rdfbase_s.lib \
$(DIST)\lib\rdfcontent_s.lib \
$(DIST)\lib\rdfdatasource_s.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\raptorgfxwin.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\raptorhtml.lib \
$(DIST)\lib\jsdom.lib \
$(DIST)\lib\js3250.lib \
$(LIBNSPR)
MISCDEP=$(LLIBS)
# XXX Note dependencies on implementation dirs for factory methods.
LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(DEPTH)\rdf\base\src \
-I$(DEPTH)\rdf\content\src \
-I$(DEPTH)\rdf\datasource\src \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
$(MAKE_INSTALL) ..\resources\Mail\joe@meer.net\inbox $(DIST)\bin\res\rdf\Mail\joe@meer.net
$(MAKE_INSTALL) ..\resources\sidebar.xul $(DIST)\bin\res\rdf
$(MAKE_INSTALL) ..\resources\sidebar.css $(DIST)\bin\res\rdf
$(MAKE_INSTALL) ..\resources\bookmarks.html $(DIST)\bin\res\rdf
$(MAKE_INSTALL) ..\resources\Mail\joe@meer.net\work $(DIST)\bin\res\rdf\Mail\joe@meer.net
$(MAKE_INSTALL) ..\resources\Mail\joe@meer.net\other $(DIST)\bin\res\rdf\Mail\joe@meer.net
$(MAKE_INSTALL) ..\resources\Mail\jane@aol.com\inbox $(DIST)\bin\res\rdf\Mail\jane@aol.com
$(MAKE_INSTALL) ..\resources\Mail\jane@aol.com\hiking $(DIST)\bin\res\rdf\Mail\jane@aol.com
$(MAKE_INSTALL) ..\resources\Mail\jane@aol.com\trash $(DIST)\bin\res\rdf\Mail\jane@aol.com

View File

@@ -0,0 +1,81 @@
/* -*- 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
* 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.
*/
/*
XPCOM Class IDs for RDF objects that can be constructed via the RDF
factory.
*/
#ifndef nsRDFCID_h__
#define nsRDFCID_h__
// {0F78DA56-8321-11d2-8EAC-00805F29F370}
#define NS_RDFNODE_CID \
{ 0xf78da56, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {BFD05264-834C-11d2-8EAC-00805F29F370}
#define NS_RDFSERVICE_CID \
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {BFD0526D-834C-11d2-8EAC-00805F29F370}
#define NS_RDFINMEMORYDATASOURCE_CID \
{ 0xbfd0526d, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {E638D760-8687-11d2-B530-000000000000}
#define NS_RDFBOOKMARKDATASOURCE_CID \
{ 0xe638d760, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {E638D761-8687-11d2-B530-000000000000}
#define NS_RDFCOMPOSITEDATASOURCE_CID \
{ 0xe638d761, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {954F0813-81DC-11d2-B52A-000000000000}
#define NS_RDFHTMLBUILDER_CID \
{ 0x954f0813, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {3D262D00-8B5A-11d2-8EB0-00805F29F370}
#define NS_RDFTREEBUILDER_CID \
{ 0x3d262d00, 0x8b5a, 0x11d2, { 0x8e, 0xb0, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {7BAF62E0-8E61-11d2-8EB1-00805F29F370}
#define NS_RDFXMLDATASOURCE_CID \
{ 0x7baf62e0, 0x8e61, 0x11d2, { 0x8e, 0xb1, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {6791B601-B9FE-11d2-BF86-00105A1B0627}
#define NS_XULDATASOURCE_CID \
{ 0x6791b601, 0xb9fe, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {0958B101-9ADA-11d2-8EBC-00805F29F370}
#define NS_RDFCONTENTSINK_CID \
{ 0x958b101, 0x9ada, 0x11d2, { 0x8e, 0xbc, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {E45313F0-B59C-11d2-A68C-00104BDE6048}
#define NS_RDFXULBUILDER_CID \
{ 0xe45313f0, 0xb59c, 0x11d2, { 0xa6, 0x8c, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
// {CE058B21-BA9C-11d2-BF86-00105A1B0627}
#define NS_XULCONTENTSINK_CID \
{ 0xce058b21, 0xba9c, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {541AFCB2-A9A3-11d2-8EC5-00805F29F370}
#define NS_XULDOCUMENT_CID \
{ 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
#endif // nsRDFCID_h__

View File

@@ -0,0 +1,263 @@
/* -*- 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
* 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.
*/
/*
The RDF factory implementation.
*/
#include "nsIFactory.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFContentSink.h"
#include "nsIRDFDocument.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIXULContentSink.h"
#include "nsISupports.h"
#include "nsRDFBaseDataSources.h"
#include "nsRDFBuiltInDataSources.h"
#include "nsRDFCID.h"
#include "nsRepository.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
class RDFFactoryImpl : public nsIFactory
{
public:
RDFFactoryImpl(const nsCID &aClass);
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~RDFFactoryImpl();
private:
nsCID mClassID;
};
////////////////////////////////////////////////////////////////////////
RDFFactoryImpl::RDFFactoryImpl(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
RDFFactoryImpl::~RDFFactoryImpl()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMETHODIMP
RDFFactoryImpl::QueryInterface(const nsIID &aIID,
void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(RDFFactoryImpl);
NS_IMPL_RELEASE(RDFFactoryImpl);
NS_IMETHODIMP
RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
*aResult = nsnull;
nsresult rv;
PRBool wasRefCounted = PR_TRUE;
nsISupports *inst = nsnull;
if (mClassID.Equals(kRDFServiceCID)) {
if (NS_FAILED(rv = NS_NewRDFService((nsIRDFService**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFInMemoryDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFInMemoryDataSource((nsIRDFDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFXMLDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFXMLDataSource((nsIRDFXMLDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFBookmarkDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFBookmarkDataSource((nsIRDFDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFCompositeDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFCompositeDataSource((nsIRDFCompositeDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kXULDocumentCID)) {
if (NS_FAILED(rv = NS_NewXULDocument((nsIRDFDocument**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFHTMLBuilderCID)) {
if (NS_FAILED(rv = NS_NewRDFHTMLBuilder((nsIRDFContentModelBuilder**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFTreeBuilderCID)) {
if (NS_FAILED(rv = NS_NewRDFTreeBuilder((nsIRDFContentModelBuilder**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFXULBuilderCID)) {
if (NS_FAILED(rv = NS_NewRDFXULBuilder((nsIRDFContentModelBuilder**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFContentSinkCID)) {
if (NS_FAILED(rv = NS_NewRDFContentSink((nsIRDFContentSink**) &inst)))
return rv;
}
else if (mClassID.Equals(kXULDataSourceCID)) {
if (NS_FAILED(rv = NS_NewXULDataSource((nsIRDFXMLDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kXULContentSinkCID)) {
if (NS_FAILED(rv = NS_NewXULContentSink((nsIXULContentSink**) &inst)))
return rv;
}
else {
return NS_ERROR_NO_INTERFACE;
}
if (! inst)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
// We didn't get the right interface, so clean up
delete inst;
if (wasRefCounted)
NS_IF_RELEASE(inst);
return rv;
}
nsresult RDFFactoryImpl::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// return the proper factory to the caller
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(const nsCID &aClass, nsISupports* aServiceManager, nsIFactory **aFactory)
{
if (! aFactory)
return NS_ERROR_NULL_POINTER;
RDFFactoryImpl* factory = new RDFFactoryImpl(aClass);
if (factory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(const char* aPath)
{
nsRepository::RegisterFactory(kRDFBookmarkDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFCompositeDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFContentSinkCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFHTMLBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFInMemoryDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFServiceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFTreeBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFXMLDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFXULBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULContentSinkCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULDocumentCID, aPath, PR_TRUE, PR_TRUE);
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(const char* aPath)
{
nsRepository::UnregisterFactory(kRDFBookmarkDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFCompositeDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFContentSinkCID, aPath);
nsRepository::UnregisterFactory(kRDFHTMLBuilderCID, aPath);
nsRepository::UnregisterFactory(kRDFInMemoryDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFServiceCID, aPath);
nsRepository::UnregisterFactory(kRDFTreeBuilderCID, aPath);
nsRepository::UnregisterFactory(kRDFXMLDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFXULBuilderCID, aPath);
nsRepository::UnregisterFactory(kXULContentSinkCID, aPath);
nsRepository::UnregisterFactory(kXULDataSourceCID, aPath);
nsRepository::UnregisterFactory(kXULDocumentCID, aPath);
return NS_OK;
}

View File

@@ -0,0 +1,29 @@
#!gmake
#
# 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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,27 @@
#!gmake
#
# 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.
DEPTH=..\..
MODULE = rdf
DIRS=\
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,6 @@
nsIDOMNodeObserver.h
nsIDOMXULDocument.h
nsIDOMXULElement.h
nsIRDFContent.h
nsIRDFContentModelBuilder.h
nsIRDFDocument.h

View File

@@ -0,0 +1,40 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
EXPORTS = \
nsIDOMNodeObserver.h \
nsIDOMXULDocument.h \
nsIDOMXULElement.h \
nsIRDFContent.h \
nsIRDFContentModelBuilder.h \
nsIRDFDocument.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,10 @@
interface NodeObserver {
/* IID: { 0x3e969070, 0xc301, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
void onSetNodeValue(in Node node, in DOMString value);
void onInsertBefore(in Node parent, in Node newChild, in Node refChild);
void onReplaceChild(in Node parent, in Node newChild, in Node oldChild);
void onRemoveChild(in Node parent, in Node oldChild);
void onAppendChild(in Node parent, in Node newChild);
};

View File

@@ -0,0 +1,7 @@
interface XULDocument : Document {
/* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
Node getElementByID(in DOMString id);
};

View File

@@ -0,0 +1,9 @@
interface XULElement : Element {
/* IID: { 0x574ed81, 0xc088, 0x11d2, \
{ 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } */
void addBroadcastListener(in DOMString attr, in Node node);
void removeBroadcastListener(in DOMString attr, in Node node);
void doCommand();
};

Some files were not shown because too many files have changed in this diff Show More