Beginnings of WebDAV support, starting with (nonconformant but mildly

usable) PROPFIND service.


git-svn-id: svn://10.0.0.236/trunk@163074 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
shaver%mozilla.org
2004-10-01 05:59:55 +00:00
parent 4f9cba3c35
commit a6a2f9cce3
11 changed files with 1230 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
# 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
# Oracle Corporation.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mike Shaver <shaver@off.net> (original author)
#
# 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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = webdav
DIRS = public src
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,53 @@
# 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
# Oracle Corporation.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mike Shaver <shaver@off.net> (original author)
#
# 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.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = webdav
EXPORTS = nsWebDAVServiceCID.h \
$(NULL)
XPIDLSRCS = nsIWebDAVService.idl \
nsIWebDAVResource.idl \
nsIWebDAVListener.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,89 @@
/* -*- Mode: idl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
*
* 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"
#include "nsIWebDAVResource.idl"
interface nsIProperties;
[scriptable,uuid(abfdf17a-d4d1-4e02-9485-75e01da62a22)]
interface nsIWebDAVMetadataListener : nsISupports
{
void onGetPropertyNamesResult(in unsigned long aStatusCode,
in AUTF8String aResource,
in PRUint32 nameCount,
[array, size_is(nameCount)]
in string propertyNames);
void onGetPropertiesResult(in unsigned long aStatusCode,
in AUTF8String aResource,
in nsIProperties aProperties);
void onOptionsResult(in unsigned long aStatusCode,
in nsIWebDAVResource aResource,
in AString aOptions,
in AString aDavCapabilities);
void onMetadataComplete(in unsigned long aStatusCode,
in nsIWebDAVResource aResource,
in string method);
};
[scriptable,uuid(e198a0fd-9e62-4299-84e3-d93c0cd68881)]
interface nsIWebDAVOperationListener : nsISupports
{
void onLockResult(in unsigned long aStatusCode,
in nsIWebDAVResource aResource);
void onUnlockResult(in unsigned long aStatusCode,
in nsIWebDAVResource aResource);
void onMoveResult(in unsigned long aStatusCode,
in nsIWebDAVResource aResource);
void onCopyResult(in unsigned long aStatusCode,
in nsIWebDAVResource aResource);
};
[scriptable,uuid(c368540a-b4c3-45d7-b20f-1474c140c0dd)]
interface nsIWebDAVChildrenListener : nsISupports
{
void hasChild(in unsigned long aStatusCode,
in AUTF8String aParent,
in AUTF8String aChild);
void childListComplete(in AUTF8String aParent);
void childListFailed(in unsigned long aStatusCode,
in AUTF8String aParent);
};

View File

@@ -0,0 +1,64 @@
/* -*- Mode: idl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
*
* 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 nsIInputStream;
interface nsIProperties;
[scriptable,uuid(9ec5321f-e3ea-4812-a4c7-5366a01b609e)]
interface nsIWebDAVResource : nsISupports
{
readonly attribute AUTF8String urlSpec;
};
[scriptable,uuid(20f74394-0e19-4bd9-9435-dd29f1644de9)]
interface nsIWebDAVResourceWithData : nsIWebDAVResource
{
readonly attribute nsIInputStream data;
};
[scriptable,uuid(8956be34-abad-4c1a-88eb-cbc1851547ea)]
interface nsIWebDAVResourceWithProperties : nsIWebDAVResource
{
readonly attribute nsIProperties properties;
};
[scriptable,uuid(82e289d9-ba6f-4eab-b325-a6bdaf58be62)]
interface nsIWebDAVResourceWithTarget : nsIWebDAVResource
{
readonly attribute AUTF8String target;
};

View File

@@ -0,0 +1,100 @@
/* -*- Mode: idl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
*
* 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"
#include "nsIWebDAVListener.idl"
#include "nsIWebDAVResource.idl"
interface nsIStreamListener;
[scriptable,uuid(173ef52e-2a2f-45ca-8f9f-abc7429163c2)]
interface nsIWebDAVService : nsISupports
{
void lockResources(in PRUint32 count,
[array, size_is(count)]
in nsIWebDAVResource resources,
in nsIWebDAVOperationListener listener);
void unlockResources(in PRUint32 count,
[array, size_is(count)]
in nsIWebDAVResource resources,
in nsIWebDAVOperationListener listener);
void getResourcePropertyNames(in nsIWebDAVResource resource,
in boolean withDepth,
in nsIWebDAVMetadataListener listener);
void getResourceProperties(in nsIWebDAVResource resource,
in PRUint32 propCount,
[array, size_is(propCount)]
in string properties, /* XXX wstring? */
in boolean withDepth,
in nsIWebDAVMetadataListener listener);
void getResourceOptions(in nsIWebDAVResource resource,
in nsIWebDAVMetadataListener listener);
void getChildren(in nsIWebDAVResource resource,
in PRUint32 depth, in nsIWebDAVChildrenListener listener);
void get(in nsIWebDAVResource resource,
in nsIStreamListener listener);
void put(in nsIWebDAVResourceWithData resource,
in nsIWebDAVOperationListener listener);
void remove(in nsIWebDAVResource resource,
in nsIWebDAVOperationListener listener);
void moveTo(in nsIWebDAVResourceWithTarget resource,
in nsIWebDAVOperationListener listener);
void copyTo(in nsIWebDAVResourceWithTarget resource,
in nsIWebDAVOperationListener listener,
in boolean recursive);
};
[scriptable,uuid(96c8d65a-fa17-408c-8008-1aa2b95952d4)]
interface nsIWebDAVResourceXXX : nsISupports
{
readonly attribute boolean isCollection;
nsIWebDAVResource makeChildCollection(in string name);
void setProperties([array,size_is(count)] in string propname,
[array,size_is(count)] in string propvalues,
in PRUint32 count);
};

View File

@@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
*
* 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 nsWebDAVServiceCID_h__
#define nsWebDAVServiceCID_h__
#define NS_WEBDAVSERVICE_CONTRACTID \
"@mozilla.org/webdav/service;1"
#define NS_WEBDAVSERVICE_CID \
{ /* 0220d938-9da2-4d0b-a16e-b54a7af793e1 */ \
0x0220d938, \
0x9da2, \
0x4d0b, \
{ 0xa1, 0x6e, 0xb5, 0x4a, 0x7a, 0xf7, 0x93, 0xe1 } \
}
#endif /* nsWebDAVServiceCID_h__ */

View File

@@ -0,0 +1,67 @@
# 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
# Oracle Corporation.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mike Shaver <shaver@off.net> (original author)
#
# 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.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = webdav
LIBRARY_NAME = webdav
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsWebDAVModules
GRE_MODULE = 1
# PACKAGE_FILE = webdav.pkg
# XXX widget is because of a transitive inclusion from nsIDocument.h of
# XXX nsEvent.h -- I mean, really!
REQUIRES = xpcom \
string \
dom \
necko \
content \
widget \
xmlextras \
$(NULL)
CPPSRCS = nsWebDAVService.cpp \
nsPropfindStreamListener.cpp \
nsWebDAVUtils.cpp \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,353 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
* 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 "nsIHttpChannel.h"
#include "nsIIOService.h"
#include "nsNetUtil.h"
#include "nsIDOM3Node.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMParser.h"
#include "nsIDOMRange.h"
#include "nsIDocument.h"
#include "nsIDocumentEncoder.h"
#include "nsIWebDAVResource.h"
#include "nsIWebDAVListener.h"
#include "nsWebDAVInternal.h"
#include "nsISupportsPrimitives.h"
class PropfindStreamListener : public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
PropfindStreamListener(nsIWebDAVResource *resource,
nsIWebDAVMetadataListener *listener) :
mResource(resource), mListener(listener) { }
virtual ~PropfindStreamListener() { }
protected:
static NS_METHOD StreamReaderCallback(nsIInputStream *in, void *closure,
const char *fromRawSegment,
PRUint32 toOffset, PRUint32 count,
PRUint32 *writeCount);
NS_METHOD SignalCompletion(PRUint32 aStatusCode)
{
if (LOG_ENABLED()) {
nsCAutoString spec("");
mResource->GetUrlSpec(spec);
LOG(("PROPFIND completed for %s: %d", spec.get(), aStatusCode));
}
mListener->OnMetadataComplete(aStatusCode, mResource, "PROPFIND");
return NS_OK;
}
NS_METHOD ProcessResponse(nsIDOMElement *responseElt);
NS_METHOD PropertiesFromPropElt(nsIDOMElement *elt,
nsIProperties **retProps);
nsCOMPtr<nsIWebDAVResource> mResource;
nsCOMPtr<nsIWebDAVMetadataListener> mListener;
nsCOMPtr<nsIDOMDocument> mXMLDoc;
nsCString mBody;
};
NS_IMPL_ISUPPORTS1(PropfindStreamListener, nsIStreamListener)
NS_IMETHODIMP
PropfindStreamListener::OnStartRequest(nsIRequest *aRequest,
nsISupports *aContext)
{
mBody.Truncate();
return NS_OK;
}
nsresult
PropfindStreamListener::PropertiesFromPropElt(nsIDOMElement *propElt,
nsIProperties **retProps)
{
nsresult rv = CallCreateInstance(NS_PROPERTIES_CONTRACTID, retProps);
NS_ENSURE_SUCCESS(rv, rv);
nsIProperties *props = *retProps;
nsCOMPtr<nsIDOMNodeList> list;
rv = propElt->GetChildNodes(getter_AddRefs(list));
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 length;
rv = list->GetLength(&length);
NS_ENSURE_SUCCESS(rv, rv);
LOG(("%d properties found", length));
PRUint32 realProps = 0;
for (PRUint32 i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIDOM3Node> node3;
rv = list->Item(i, getter_AddRefs(node));
NS_ENSURE_SUCCESS(rv, rv);
PRUint16 type;
node->GetNodeType(&type);
if (type != nsIDOMNode::ELEMENT_NODE)
continue;
realProps++;
nsCOMPtr<nsIDOMRange> range =
do_CreateInstance("@mozilla.org/content/range;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = range->SelectNodeContents(node);
NS_ENSURE_SUCCESS(rv, rv);
nsString nsStr;
rv = node->GetNamespaceURI(nsStr);
NS_ENSURE_SUCCESS(rv, rv);
nsString propName;
rv = node->GetLocalName(propName);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocumentEncoder> encoder =
do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &rv);
nsCOMPtr<nsIDocument> baseDoc = do_QueryInterface(mXMLDoc, &rv);
NS_ENSURE_SUCCESS(rv, rv);
// This method will fail if no document
rv = encoder->Init(baseDoc, NS_LITERAL_STRING("text/xml"),
nsIDocumentEncoder::OutputEncodeBasicEntities);
NS_ENSURE_SUCCESS(rv, rv);
rv = encoder->SetRange(range);
NS_ENSURE_SUCCESS(rv, rv);
nsString valueStr;
encoder->EncodeToString(valueStr);
nsCOMPtr<nsISupportsString>
suppString(do_CreateInstance("@mozilla.org/supports-string;1",
&rv));
NS_ENSURE_SUCCESS(rv, rv);
suppString->SetData(valueStr);
NS_ConvertUTF16toUTF8 propkey(nsStr + NS_LITERAL_STRING(" ") +
propName);
LOG((" %s = %s", propkey.get(),
NS_ConvertUTF16toUTF8(valueStr).get()));
rv = props->Set(propkey.get(), suppString);
NS_ENSURE_SUCCESS(rv, rv);
}
LOG(("%d real properties added", realProps));
return NS_OK;
}
nsresult
PropfindStreamListener::ProcessResponse(nsIDOMElement *responseElt)
{
nsCOMPtr<nsIDOMElement> hrefElt;
nsString hrefString;
nsresult rv = NS_WD_ElementTextChildValue(responseElt,
NS_LITERAL_STRING("href"),
hrefString);
NS_ENSURE_SUCCESS(rv, rv);
NS_ConvertUTF16toUTF8 hrefUTF8(hrefString);
LOG(("response for %s", hrefUTF8.get()));
nsCOMPtr<nsIDOMNodeList> proplist;
rv = responseElt->GetElementsByTagName(NS_LITERAL_STRING("propstat"),
getter_AddRefs(proplist));
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 length;
rv = proplist->GetLength(&length);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> node;
for (PRUint32 i = 0; i < length; i++) {
rv = proplist->Item(i, getter_AddRefs(node));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> propstatElt = do_QueryInterface(node, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> elt;
rv = NS_WD_GetElementByTagName(propstatElt, NS_LITERAL_STRING("prop"),
getter_AddRefs(elt));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIProperties> props;
rv = PropertiesFromPropElt(elt, getter_AddRefs(props));
NS_ENSURE_SUCCESS(rv, rv);
nsString statusString;
rv = NS_WD_ElementTextChildValue(propstatElt,
NS_LITERAL_STRING("status"),
statusString);
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 res = 0;
NS_ConvertUTF16toUTF8 statusUTF8(statusString);
LOG(("status: %s", statusUTF8.get()));
PRInt32 statusVal = nsCAutoString(Substring(statusUTF8, 8)).ToInteger(&res, 10);
NS_ENSURE_SUCCESS(res, (nsresult)res);
mListener->OnGetPropertiesResult((PRUint32)statusVal, hrefUTF8, props);
}
return NS_OK;
}
NS_IMETHODIMP
PropfindStreamListener::OnStopRequest(nsIRequest *aRequest,
nsISupports *aContext,
nsresult aStatusCode)
{
PRUint32 status, rv;
nsCOMPtr<nsIHttpChannel> channel = do_QueryInterface(aContext);
rv = channel ? channel->GetResponseStatus(&status) : NS_ERROR_UNEXPECTED;
if (NS_FAILED(rv))
return SignalCompletion(rv);
if (status != 207)
return SignalCompletion(status);
// ZZZ Check content-length against mBody.Length()
// Now we parse!
nsCOMPtr<nsIDOMParser>
parser(do_CreateInstance("@mozilla.org/xmlextras/domparser;1", &rv));
NS_ENSURE_SUCCESS(rv, SignalCompletion(rv));
nsCOMPtr<nsIDOMDocument> xmldoc;
rv = parser->ParseFromBuffer(NS_REINTERPRET_CAST(const PRUint8 *,
mBody.get()),
mBody.Length(), "text/xml",
getter_AddRefs(mXMLDoc));
NS_ENSURE_SUCCESS(rv, SignalCompletion(rv));
nsCOMPtr<nsIDOMNodeList> responseList;
rv = mXMLDoc->GetElementsByTagNameNS(NS_LITERAL_STRING("DAV:"),
NS_LITERAL_STRING("response"),
getter_AddRefs(responseList));
NS_ENSURE_SUCCESS(rv, SignalCompletion(rv));
PRUint32 length;
rv = responseList->GetLength(&length);
NS_ENSURE_SUCCESS(rv, SignalCompletion(rv));
LOG(("found %d responses", length));
NS_ENSURE_TRUE(length, SignalCompletion(NS_ERROR_UNEXPECTED));
for (PRUint32 i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> responseNode;
rv = responseList->Item(i, getter_AddRefs(responseNode));
NS_ENSURE_SUCCESS(rv, SignalCompletion(rv));
nsCOMPtr<nsIDOMElement> responseElt =
do_QueryInterface(responseNode, &rv);
NS_ENSURE_SUCCESS(rv, SignalCompletion(rv));
rv = ProcessResponse(responseElt);
NS_ENSURE_SUCCESS(rv, SignalCompletion(rv));
}
SignalCompletion(status);
return NS_OK;
}
NS_METHOD
PropfindStreamListener::StreamReaderCallback(nsIInputStream *aInputStream,
void *aClosure,
const char *aRawSegment,
PRUint32 aToOffset,
PRUint32 aCount,
PRUint32 *aWriteCount)
{
PropfindStreamListener *psl = NS_STATIC_CAST(PropfindStreamListener *,
aClosure);
psl->mBody.Append(aRawSegment, aCount);
*aWriteCount = aCount;
return NS_OK;
}
NS_IMETHODIMP
PropfindStreamListener::OnDataAvailable(nsIRequest *aRequest,
nsISupports *aContext,
nsIInputStream *aInputStream,
PRUint32 aOffset, PRUint32 aCount)
{
PRUint32 result;
nsCOMPtr<nsIHttpChannel> channel = do_QueryInterface(aContext);
if (!channel)
result = NS_ERROR_UNEXPECTED;
PRBool succeeded = PR_FALSE;
channel->GetRequestSucceeded(&succeeded);
if (!succeeded) {
aRequest->Cancel(NS_BINDING_ABORTED);
return NS_BINDING_ABORTED;
}
PRUint32 totalRead;
return aInputStream->ReadSegments(StreamReaderCallback, (void *)this,
aCount, &totalRead);
}
nsIStreamListener *
NS_NewPropfindStreamListener(nsIWebDAVResource *resource,
nsIWebDAVMetadataListener *listener)
{
return new PropfindStreamListener(resource, listener);
}

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
*
* 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 nsWebDAVInternal_h__
#define nsWebDAVInternal_h__
#include "prlog.h"
#include "nsCOMPtr.h"
#include "nsString.h"
class nsIStreamListener;
#include "nsIDOMElement.h"
#include "nsIWebDAVListener.h"
#include "nsIWebDAVResource.h"
#define LOG(args) PR_LOG(gDAVLog, 4, args)
#define LOG_ENABLED() PR_LOG_TEST(gDAVLog, 4)
extern PRLogModuleInfo *gDAVLog;
nsIStreamListener *
NS_NewPropfindStreamListener(nsIWebDAVResource *resource,
nsIWebDAVMetadataListener *listener);
nsresult
NS_WD_GetElementByTagName(nsIDOMElement *parentElt, const nsAString &tagName,
nsIDOMElement **elt);
nsresult
NS_WD_ElementTextChildValue(nsIDOMElement *elt, const nsAString &tagName,
nsAString &value);
#endif /* nsWebDAVInternal_h__ */

View File

@@ -0,0 +1,261 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
*
* 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 ***** */
#if defined(MOZ_LOGGING)
#define FORCE_PR_LOG
#endif
#include "nsWebDAVInternal.h"
#include "nsIWebDAVService.h"
#include "nsWebDAVServiceCID.h"
#include "nsIServiceManagerUtils.h"
#include "nsIHttpChannel.h"
#include "nsIIOService.h"
#include "nsNetUtil.h"
#include "nsIDOMElement.h"
#include "nsIDOMNodeList.h"
#include "nsIDOM3Node.h"
#include "nsIDOMParser.h"
#include "nsIGenericFactory.h"
class nsWebDAVService : public nsIWebDAVService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBDAVSERVICE
nsWebDAVService();
virtual ~nsWebDAVService();
protected:
nsresult EnsureIOService();
nsresult ChannelFromResource(nsIWebDAVResource *resource,
nsIHttpChannel** channel);
nsCOMPtr<nsIIOService> mIOService; // XXX weak?
};
NS_IMPL_ISUPPORTS1_CI(nsWebDAVService, nsIWebDAVService)
#define ENSURE_IO_SERVICE() \
{ \
nsresult rv_ = EnsureIOService(); \
NS_ENSURE_SUCCESS(rv_, rv_); \
}
nsresult
nsWebDAVService::EnsureIOService()
{
if (!mIOService) {
nsresult rv;
mIOService = do_GetIOService(&rv);
if (!mIOService)
return rv;
}
return NS_OK;
}
nsresult
nsWebDAVService::ChannelFromResource(nsIWebDAVResource *resource,
nsIHttpChannel **channel)
{
ENSURE_IO_SERVICE();
nsCAutoString spec;
nsresult rv = resource->GetUrlSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
if (spec.IsEmpty()) {
NS_ASSERTION(0, "non-empty spec!");
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIURI> uri;
rv = mIOService->NewURI(spec, nsnull, nsnull, getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIChannel> baseChannel;
rv = mIOService->NewChannelFromURI(uri, getter_AddRefs(baseChannel));
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(baseChannel, channel);
}
nsWebDAVService::nsWebDAVService()
{
gDAVLog = PR_NewLogModule("webdav");
}
nsWebDAVService::~nsWebDAVService()
{
/* destructor code */
}
NS_IMETHODIMP
nsWebDAVService::LockResources(PRUint32 count, nsIWebDAVResource **resources,
nsIWebDAVOperationListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::UnlockResources(PRUint32 count, nsIWebDAVResource **resources,
nsIWebDAVOperationListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::GetResourcePropertyNames(nsIWebDAVResource *resource,
PRBool withDepth,
nsIWebDAVMetadataListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::GetResourceProperties(nsIWebDAVResource *resource,
PRUint32 propCount,
const char **properties,
PRBool withDepth,
nsIWebDAVMetadataListener *listener)
{
nsresult rv;
NS_ENSURE_ARG(resource);
NS_ENSURE_ARG(listener);
nsCOMPtr<nsIHttpChannel> channel;
rv = ChannelFromResource(resource, getter_AddRefs(channel));
if (NS_FAILED(rv))
return rv;
// XXX I wonder how many compilers this will break...
const nsACString &depthValue = withDepth ? NS_LITERAL_CSTRING("1") :
NS_LITERAL_CSTRING("0");
channel->SetRequestMethod(NS_LITERAL_CSTRING("PROPFIND"));
channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"), depthValue, false);
if (LOG_ENABLED()) {
nsCAutoString spec;
resource->GetUrlSpec(spec);
LOG(("PROPFIND starting for %s", spec.get()));
}
nsCOMPtr<nsIStreamListener> streamListener =
NS_NewPropfindStreamListener(resource, listener);
if (!streamListener)
return NS_ERROR_OUT_OF_MEMORY;
return channel->AsyncOpen(streamListener, channel);
}
NS_IMETHODIMP
nsWebDAVService::GetResourceOptions(nsIWebDAVResource *resource,
nsIWebDAVMetadataListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::GetChildren(nsIWebDAVResource *resource, PRUint32 depth,
nsIWebDAVChildrenListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::Get(nsIWebDAVResource *resource, nsIStreamListener *listener)
{
nsresult rv;
nsCOMPtr<nsIHttpChannel> channel;
rv = ChannelFromResource(resource, getter_AddRefs(channel));
if (NS_FAILED(rv))
return rv;
return channel->AsyncOpen(listener, nsnull);
}
NS_IMETHODIMP
nsWebDAVService::Put(nsIWebDAVResourceWithData *resource,
nsIWebDAVOperationListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::Remove(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::MoveTo(nsIWebDAVResourceWithTarget *resource,
nsIWebDAVOperationListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsWebDAVService::CopyTo(nsIWebDAVResourceWithTarget *resource,
nsIWebDAVOperationListener *listener, PRBool recursive)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebDAVService)
NS_DECL_CLASSINFO(nsWebDAVService)
static const nsModuleComponentInfo components[] =
{
{ "WebDAV Service", NS_WEBDAVSERVICE_CID, NS_WEBDAVSERVICE_CONTRACTID,
nsWebDAVServiceConstructor,
NULL, NULL, NULL,
NS_CI_INTERFACE_GETTER_NAME(nsWebDAVService),
NULL,
&NS_CLASSINFO_NAME(nsWebDAVService)
}
};
NS_IMPL_NSGETMODULE(nsWebDAVService, components)

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:expandtab:ts=4 sw=4:
/*
* 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 Oracle Corporation.
* Portions created by Oracle Corporation are Copyright (C) 2004
* by Oracle Corporation. All Rights Reserved.
*
* Contributor(s):
* Mike Shaver <shaver@off.net> (original author)
*
* 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 "nsWebDAVInternal.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsIDOM3Node.h"
#include "nsIDOMNodeList.h"
#if defined(PR_LOGGING)
PRLogModuleInfo *gDAVLog = nsnull;
#endif
nsresult
NS_WD_GetElementByTagName(nsIDOMElement *parentElt, const nsAString &tagName,
nsIDOMElement **elt)
{
nsresult rv;
nsCOMPtr<nsIDOMNodeList> list;
rv = parentElt->GetElementsByTagName(tagName, getter_AddRefs(list));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> node;
rv = list->Item(0, getter_AddRefs(node));
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(node, elt);
}
nsresult
NS_WD_ElementTextChildValue(nsIDOMElement *elt, const nsAString &tagName,
nsAString &value)
{
nsCOMPtr<nsIDOMElement> childElt;
nsresult rv = NS_WD_GetElementByTagName(elt, tagName,
getter_AddRefs(childElt));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOM3Node> node3 = do_QueryInterface(childElt, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return node3->GetTextContent(value);
}