diff --git a/mozilla/extensions/webdav/Makefile.in b/mozilla/extensions/webdav/Makefile.in new file mode 100644 index 00000000000..ef9f9470e30 --- /dev/null +++ b/mozilla/extensions/webdav/Makefile.in @@ -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 (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 + diff --git a/mozilla/extensions/webdav/public/Makefile.in b/mozilla/extensions/webdav/public/Makefile.in new file mode 100644 index 00000000000..89d7217c05a --- /dev/null +++ b/mozilla/extensions/webdav/public/Makefile.in @@ -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 (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 + diff --git a/mozilla/extensions/webdav/public/nsIWebDAVListener.idl b/mozilla/extensions/webdav/public/nsIWebDAVListener.idl new file mode 100644 index 00000000000..2b556a206e3 --- /dev/null +++ b/mozilla/extensions/webdav/public/nsIWebDAVListener.idl @@ -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 (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); +}; diff --git a/mozilla/extensions/webdav/public/nsIWebDAVResource.idl b/mozilla/extensions/webdav/public/nsIWebDAVResource.idl new file mode 100644 index 00000000000..749d7f0c1d0 --- /dev/null +++ b/mozilla/extensions/webdav/public/nsIWebDAVResource.idl @@ -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 (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; +}; diff --git a/mozilla/extensions/webdav/public/nsIWebDAVService.idl b/mozilla/extensions/webdav/public/nsIWebDAVService.idl new file mode 100644 index 00000000000..d74376854df --- /dev/null +++ b/mozilla/extensions/webdav/public/nsIWebDAVService.idl @@ -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 (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); +}; diff --git a/mozilla/extensions/webdav/public/nsWebDAVServiceCID.h b/mozilla/extensions/webdav/public/nsWebDAVServiceCID.h new file mode 100644 index 00000000000..88fa066c928 --- /dev/null +++ b/mozilla/extensions/webdav/public/nsWebDAVServiceCID.h @@ -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 (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__ */ diff --git a/mozilla/extensions/webdav/src/Makefile.in b/mozilla/extensions/webdav/src/Makefile.in new file mode 100644 index 00000000000..f0523262a4b --- /dev/null +++ b/mozilla/extensions/webdav/src/Makefile.in @@ -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 (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 + diff --git a/mozilla/extensions/webdav/src/nsPropfindStreamListener.cpp b/mozilla/extensions/webdav/src/nsPropfindStreamListener.cpp new file mode 100644 index 00000000000..b70d4a255d5 --- /dev/null +++ b/mozilla/extensions/webdav/src/nsPropfindStreamListener.cpp @@ -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 (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 mResource; + nsCOMPtr mListener; + nsCOMPtr 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 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 node; + nsCOMPtr 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 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 encoder = + do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &rv); + + nsCOMPtr 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 + 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 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 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 node; + for (PRUint32 i = 0; i < length; i++) { + rv = proplist->Item(i, getter_AddRefs(node)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr propstatElt = do_QueryInterface(node, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr elt; + rv = NS_WD_GetElementByTagName(propstatElt, NS_LITERAL_STRING("prop"), + getter_AddRefs(elt)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr 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 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 + parser(do_CreateInstance("@mozilla.org/xmlextras/domparser;1", &rv)); + NS_ENSURE_SUCCESS(rv, SignalCompletion(rv)); + + nsCOMPtr 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 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 responseNode; + rv = responseList->Item(i, getter_AddRefs(responseNode)); + NS_ENSURE_SUCCESS(rv, SignalCompletion(rv)); + + nsCOMPtr 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 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); +} diff --git a/mozilla/extensions/webdav/src/nsWebDAVInternal.h b/mozilla/extensions/webdav/src/nsWebDAVInternal.h new file mode 100644 index 00000000000..ee81b5ef44e --- /dev/null +++ b/mozilla/extensions/webdav/src/nsWebDAVInternal.h @@ -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 (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__ */ diff --git a/mozilla/extensions/webdav/src/nsWebDAVService.cpp b/mozilla/extensions/webdav/src/nsWebDAVService.cpp new file mode 100644 index 00000000000..86631e16860 --- /dev/null +++ b/mozilla/extensions/webdav/src/nsWebDAVService.cpp @@ -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 (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 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 uri; + rv = mIOService->NewURI(spec, nsnull, nsnull, getter_AddRefs(uri)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr 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 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 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 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) diff --git a/mozilla/extensions/webdav/src/nsWebDAVUtils.cpp b/mozilla/extensions/webdav/src/nsWebDAVUtils.cpp new file mode 100644 index 00000000000..eb1be6c1afb --- /dev/null +++ b/mozilla/extensions/webdav/src/nsWebDAVUtils.cpp @@ -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 (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 list; + rv = parentElt->GetElementsByTagName(tagName, getter_AddRefs(list)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr 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 childElt; + nsresult rv = NS_WD_GetElementByTagName(elt, tagName, + getter_AddRefs(childElt)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr node3 = do_QueryInterface(childElt, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + return node3->GetTextContent(value); +} +