зеркало из https://github.com/mozilla/pjs.git
Implement WebDAV REPORT method (bug 275741); not part of default build.
This commit is contained in:
Родитель
f6382aab84
Коммит
2d9f3593da
|
@ -73,6 +73,11 @@ interface nsIWebDAVOperationListener : nsISupports
|
|||
*/
|
||||
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,
|
||||
in nsIWebDAVResource resource,
|
||||
in unsigned long operation,
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
interface nsIStreamListener;
|
||||
interface nsIOutputStream;
|
||||
interface nsIInputStream;
|
||||
interface nsIDOMDocument;
|
||||
|
||||
[scriptable,uuid(173ef52e-2a2f-45ca-8f9f-abc7429163c2)]
|
||||
interface nsIWebDAVService : nsISupports
|
||||
|
@ -163,6 +164,22 @@ interface nsIWebDAVService : nsISupports
|
|||
void makeCollection(in nsIWebDAVResource resource,
|
||||
in nsIWebDAVOperationListener listener,
|
||||
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)]
|
||||
|
|
|
@ -431,6 +431,40 @@ PropfindStreamListener::ProcessResponse(nsIDOMElement *responseElt)
|
|||
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
|
||||
{
|
||||
public:
|
||||
|
@ -490,6 +524,14 @@ NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
|
|||
return new PropfindStreamListener(resource, listener, closure, isPropname);
|
||||
}
|
||||
|
||||
nsIStreamListener *
|
||||
NS_WD_NewReportStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsISupports *closure)
|
||||
{
|
||||
return new ReportStreamListener(resource, listener, closure);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_WD_NewOperationStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
|
|
|
@ -73,6 +73,11 @@ NS_WD_NewPropfindStreamListener(nsIWebDAVResource *resource,
|
|||
nsISupports *closure,
|
||||
PRBool isPropname);
|
||||
|
||||
nsIStreamListener *
|
||||
NS_WD_NewReportStreamListener(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
nsISupports *closure);
|
||||
|
||||
nsresult
|
||||
NS_WD_NewGetOperationRequestObserver(nsIWebDAVResource *resource,
|
||||
nsIWebDAVOperationListener *listener,
|
||||
|
|
|
@ -94,10 +94,10 @@ protected:
|
|||
nsIWebDAVOperationListener *listener,
|
||||
nsISupports *closure, PRBool namesOnly);
|
||||
|
||||
nsresult SendPropfindDocumentToChannel(nsIDocument *doc,
|
||||
nsIHttpChannel *channel,
|
||||
nsIStreamListener *listener,
|
||||
PRBool withDepth);
|
||||
nsresult SendDocumentToChannel(nsIDocument *doc, nsIHttpChannel *channel,
|
||||
const char *const method,
|
||||
nsIStreamListener *listener,
|
||||
PRBool withDepth);
|
||||
nsCOMPtr<nsIIOService> mIOService; // XXX weak?
|
||||
nsAutoString mDAVNSString; // "DAV:"
|
||||
};
|
||||
|
@ -124,10 +124,11 @@ nsWebDAVService::EnsureIOService()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsWebDAVService::SendPropfindDocumentToChannel(nsIDocument *doc,
|
||||
nsIHttpChannel *channel,
|
||||
nsIStreamListener *listener,
|
||||
PRBool withDepth)
|
||||
nsWebDAVService::SendDocumentToChannel(nsIDocument *doc,
|
||||
nsIHttpChannel *channel,
|
||||
const char *const method,
|
||||
nsIStreamListener *listener,
|
||||
PRBool withDepth)
|
||||
{
|
||||
nsCOMPtr<nsIStorageStream> storageStream;
|
||||
// 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_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
channel->SetRequestMethod(NS_LITERAL_CSTRING("PROPFIND"));
|
||||
channel->SetRequestMethod(nsDependentCString(method));
|
||||
|
||||
if (withDepth) {
|
||||
channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"),
|
||||
|
@ -198,7 +199,7 @@ nsWebDAVService::SendPropfindDocumentToChannel(nsIDocument *doc,
|
|||
channel->GetURI(getter_AddRefs(uri));
|
||||
nsCAutoString spec;
|
||||
uri->GetSpec(spec);
|
||||
LOG(("PROPFIND starting for %s", spec.get()));
|
||||
LOG(("%s starting for %s", method, spec.get()));
|
||||
}
|
||||
|
||||
return channel->AsyncOpen(listener, channel);
|
||||
|
@ -427,8 +428,8 @@ nsWebDAVService::PropfindInternal(nsIWebDAVResource *resource,
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsIDocument> requestBaseDoc = do_QueryInterface(requestDoc);
|
||||
return SendPropfindDocumentToChannel(requestBaseDoc, channel,
|
||||
streamListener, withDepth);
|
||||
return SendDocumentToChannel(requestBaseDoc, channel, "PROPFIND",
|
||||
streamListener, withDepth);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -698,6 +699,38 @@ nsWebDAVService::CopyTo(nsIWebDAVResource *resource,
|
|||
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_DECL_CLASSINFO(nsWebDAVService)
|
||||
|
|
|
@ -131,7 +131,7 @@ OperationListener.opToName = { };
|
|||
OperationListener.opNames =
|
||||
["PUT", "GET", "MOVE", "COPY", "REMOVE",
|
||||
"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) {
|
||||
var opName = OperationListener.opNames[i];
|
||||
OperationListener.opToName[CI.nsIWebDAVOperationListener[opName]] = opName;
|
||||
|
@ -169,6 +169,13 @@ OperationListener.prototype =
|
|||
case CI.nsIWebDAVOperationListener.GET_TO_STRING:
|
||||
this.mGetToStringResult = detail.QueryInterface(CI.nsISupportsCString).data;
|
||||
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);
|
||||
runEventPump();
|
||||
}
|
||||
|
||||
function REPORT(url, query, depth)
|
||||
{
|
||||
davSvc.report(new Resource(url), query, depth, new OperationListener(),
|
||||
null);
|
||||
runEventPump();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче