Implement WebDAV REPORT method (bug 275741); not part of default build.

This commit is contained in:
dmose%mozilla.org 2005-01-04 23:03:11 +00:00
Родитель f6382aab84
Коммит 2d9f3593da
6 изменённых файлов: 129 добавлений и 13 удалений

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

@ -73,6 +73,11 @@ interface nsIWebDAVOperationListener : nsISupports
*/ */
const unsigned long GET_TO_STRING = 12; const unsigned long GET_TO_STRING = 12;
/**
* @param detail will be an nsIDOMElement of the <response> element
*/
const unsigned long REPORT = 13;
void onOperationComplete(in unsigned long statusCode, void onOperationComplete(in unsigned long statusCode,
in nsIWebDAVResource resource, in nsIWebDAVResource resource,
in unsigned long operation, in unsigned long operation,

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

@ -45,6 +45,7 @@
interface nsIStreamListener; interface nsIStreamListener;
interface nsIOutputStream; interface nsIOutputStream;
interface nsIInputStream; interface nsIInputStream;
interface nsIDOMDocument;
[scriptable,uuid(173ef52e-2a2f-45ca-8f9f-abc7429163c2)] [scriptable,uuid(173ef52e-2a2f-45ca-8f9f-abc7429163c2)]
interface nsIWebDAVService : nsISupports interface nsIWebDAVService : nsISupports
@ -163,6 +164,22 @@ interface nsIWebDAVService : nsISupports
void makeCollection(in nsIWebDAVResource resource, void makeCollection(in nsIWebDAVResource resource,
in nsIWebDAVOperationListener listener, in nsIWebDAVOperationListener listener,
in nsISupports closure); in nsISupports closure);
/**
* Requests the specified report on the given resource with a Depth: header
* set to zero.
*
* @param resource the resource to perform this query on?
* @param query an XML document of the query
* @param withDepth if true, set the Depth header to 1 instead of 0
* @param listener results will be called back through this interface
* @param closure caller-private data returned via listener
*/
void report(in nsIWebDAVResource resource,
in nsIDOMDocument query,
in boolean withDepth,
in nsIWebDAVOperationListener listener,
in nsISupports closure);
}; };
[scriptable,uuid(96c8d65a-fa17-408c-8008-1aa2b95952d4)] [scriptable,uuid(96c8d65a-fa17-408c-8008-1aa2b95952d4)]

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

@ -431,6 +431,40 @@ PropfindStreamListener::ProcessResponse(nsIDOMElement *responseElt)
return NS_OK; return NS_OK;
} }
class ReportStreamListener : public OperationStreamListener
{
public:
NS_DECL_ISUPPORTS_INHERITED
ReportStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure) :
OperationStreamListener(resource, listener, closure, nsnull,
nsIWebDAVOperationListener::REPORT) { }
virtual ~ReportStreamListener() { }
protected:
virtual nsresult ProcessResponse(nsIDOMElement *responseElt);
};
NS_IMPL_ISUPPORTS_INHERITED0(ReportStreamListener, OperationStreamListener)
nsresult
ReportStreamListener::ProcessResponse(nsIDOMElement *responseElt)
{
nsCAutoString href;
PRUint32 statusCode;
nsresult rv = StatusAndHrefFromResponse(responseElt, href, &statusCode);
NS_ENSURE_SUCCESS(rv, rv);
LOG(("response for %s: %d", href.get(), statusCode));
SignalDetail(statusCode, href, responseElt);
return NS_OK;
}
class GetToStringStreamListener : public OperationStreamListener class GetToStringStreamListener : public OperationStreamListener
{ {
public: public:
@ -490,6 +524,14 @@ NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
return new PropfindStreamListener(resource, listener, closure, isPropname); return new PropfindStreamListener(resource, listener, closure, isPropname);
} }
nsIStreamListener *
NS_WD_NewReportStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
return new ReportStreamListener(resource, listener, closure);
}
nsresult nsresult
NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource, NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener, nsIWebDAVOperationListener *listener,

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

@ -73,6 +73,11 @@ NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
nsISupports *closure, nsISupports *closure,
PRBool isPropname); PRBool isPropname);
nsIStreamListener *
NS_WD_NewReportStreamListener(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener,
nsISupports *closure);
nsresult nsresult
NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource, NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource,
nsIWebDAVOperationListener *listener, nsIWebDAVOperationListener *listener,

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

@ -94,10 +94,10 @@ protected:
nsIWebDAVOperationListener *listener, nsIWebDAVOperationListener *listener,
nsISupports *closure, PRBool namesOnly); nsISupports *closure, PRBool namesOnly);
nsresult SendPropfindDocumentToChannel(nsIDocument *doc, nsresult SendDocumentToChannel(nsIDocument *doc, nsIHttpChannel *channel,
nsIHttpChannel *channel, const char *const method,
nsIStreamListener *listener, nsIStreamListener *listener,
PRBool withDepth); PRBool withDepth);
nsCOMPtr<nsIIOService> mIOService; // XXX weak? nsCOMPtr<nsIIOService> mIOService; // XXX weak?
nsAutoString mDAVNSString; // "DAV:" nsAutoString mDAVNSString; // "DAV:"
}; };
@ -124,10 +124,11 @@ nsWebDAVService::EnsureIOService()
} }
nsresult nsresult
nsWebDAVService::SendPropfindDocumentToChannel(nsIDocument *doc, nsWebDAVService::SendDocumentToChannel(nsIDocument *doc,
nsIHttpChannel *channel, nsIHttpChannel *channel,
nsIStreamListener *listener, const char *const method,
PRBool withDepth) nsIStreamListener *listener,
PRBool withDepth)
{ {
nsCOMPtr<nsIStorageStream> storageStream; nsCOMPtr<nsIStorageStream> storageStream;
// Why do I have to pick values for these? I just want to store some data // Why do I have to pick values for these? I just want to store some data
@ -183,7 +184,7 @@ nsWebDAVService::SendPropfindDocumentToChannel(nsIDocument *doc,
NS_LITERAL_CSTRING("text/xml"), -1); NS_LITERAL_CSTRING("text/xml"), -1);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
channel->SetRequestMethod(NS_LITERAL_CSTRING("PROPFIND")); channel->SetRequestMethod(nsDependentCString(method));
if (withDepth) { if (withDepth) {
channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"), channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"),
@ -198,7 +199,7 @@ nsWebDAVService::SendPropfindDocumentToChannel(nsIDocument *doc,
channel->GetURI(getter_AddRefs(uri)); channel->GetURI(getter_AddRefs(uri));
nsCAutoString spec; nsCAutoString spec;
uri->GetSpec(spec); uri->GetSpec(spec);
LOG(("PROPFIND starting for %s", spec.get())); LOG(("%s starting for %s", method, spec.get()));
} }
return channel->AsyncOpen(listener, channel); return channel->AsyncOpen(listener, channel);
@ -427,8 +428,8 @@ nsWebDAVService::PropfindInternal(nsIWebDAVResource *resource,
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIDocument> requestBaseDoc = do_QueryInterface(requestDoc); nsCOMPtr<nsIDocument> requestBaseDoc = do_QueryInterface(requestDoc);
return SendPropfindDocumentToChannel(requestBaseDoc, channel, return SendDocumentToChannel(requestBaseDoc, channel, "PROPFIND",
streamListener, withDepth); streamListener, withDepth);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -698,6 +699,38 @@ nsWebDAVService::CopyTo(nsIWebDAVResource *resource,
return channel->AsyncOpen(streamListener, channel); return channel->AsyncOpen(streamListener, channel);
} }
NS_IMETHODIMP
nsWebDAVService::Report(nsIWebDAVResource *resource, nsIDOMDocument *query,
PRBool withDepth,
nsIWebDAVOperationListener *listener,
nsISupports *closure)
{
nsresult rv;
NS_ENSURE_ARG(resource);
NS_ENSURE_ARG(query);
NS_ENSURE_ARG(listener);
nsCOMPtr<nsIDocument> queryDoc = do_QueryInterface(query, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIURI> resourceURI;
nsCOMPtr<nsIHttpChannel> channel;
rv = ChannelFromResource(resource, getter_AddRefs(channel),
getter_AddRefs(resourceURI));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIStreamListener> streamListener =
NS_WD_NewReportStreamListener(resource, listener, closure);
if (!streamListener)
return NS_ERROR_OUT_OF_MEMORY;
return SendDocumentToChannel(queryDoc, channel, "REPORT", streamListener,
withDepth);
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebDAVService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebDAVService)
NS_DECL_CLASSINFO(nsWebDAVService) NS_DECL_CLASSINFO(nsWebDAVService)

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

@ -131,7 +131,7 @@ OperationListener.opToName = { };
OperationListener.opNames = OperationListener.opNames =
["PUT", "GET", "MOVE", "COPY", "REMOVE", ["PUT", "GET", "MOVE", "COPY", "REMOVE",
"MAKE_COLLECTION", "LOCK", "UNLOCK", "GET_PROPERTIES", "MAKE_COLLECTION", "LOCK", "UNLOCK", "GET_PROPERTIES",
"GET_PROPERTY_NAMES", "GET_TO_STRING"]; "GET_PROPERTY_NAMES", "GET_TO_STRING", "REPORT"];
for (var i in OperationListener.opNames) { for (var i in OperationListener.opNames) {
var opName = OperationListener.opNames[i]; var opName = OperationListener.opNames[i];
OperationListener.opToName[CI.nsIWebDAVOperationListener[opName]] = opName; OperationListener.opToName[CI.nsIWebDAVOperationListener[opName]] = opName;
@ -169,6 +169,13 @@ OperationListener.prototype =
case CI.nsIWebDAVOperationListener.GET_TO_STRING: case CI.nsIWebDAVOperationListener.GET_TO_STRING:
this.mGetToStringResult = detail.QueryInterface(CI.nsISupportsCString).data; this.mGetToStringResult = detail.QueryInterface(CI.nsISupportsCString).data;
break; break;
case CI.nsIWebDAVOperationListener.REPORT:
var xSerializer = getService('@mozilla.org/xmlextras/domparser;1',
CI.nsIDOMParser);
dump("detail: " + xSerializer.serializeToString(aDetail) + "\n");
break;
} }
} }
} }
@ -283,3 +290,10 @@ function PUT_string(string, url, contentType)
new OperationListener(), null); new OperationListener(), null);
runEventPump(); runEventPump();
} }
function REPORT(url, query, depth)
{
davSvc.report(new Resource(url), query, depth, new OperationListener(),
null);
runEventPump();
}