webdav: Parse response of LOCK request.

Change-Id: Ib17de602e2c51eb29b0495ce7411836ceeccf9d4
This commit is contained in:
Matúš Kukan
2014-03-20 20:59:46 +01:00
parent 6e0cc0cd40
commit c1496e6761
3 changed files with 87 additions and 48 deletions

View File

@@ -20,7 +20,7 @@
#include "SerfLockReqProcImpl.hxx"
#include "DAVException.hxx"
//#include "webdavresponseparser.hxx"
#include "webdavresponseparser.hxx"
#include <rtl/strbuf.hxx>
namespace http_dav_ucp
@@ -131,33 +131,23 @@ void SerfLockReqProcImpl::processChunkOfResponseData( const char* data,
}
}
void SerfLockReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ )
void SerfLockReqProcImpl::handleEndOfResponseData( serf_bucket_t * )
{
//const std::vector< DAVResourceInfo > rResInfo( parseWebDAVPropNameResponse( m_xInputStream.get() ) );
const std::vector< css::ucb::Lock > aLocks( parseWebDAVLockResponse( m_xInputStream.get() ) );
/*
if ( theRetVal == NE_OK )
if (!aLocks.empty())
{
m_aSerfLockStore.addLock( theLock,
this,
lastChanceToSendRefreshRequest(
startCall, theLock->timeout ) );
uno::Sequence< OUString > aTokens( 1 );
aTokens[ 0 ] = OUString::createFromAscii( theLock->token );
m_xLock.LockTokens = aTokens;
SAL_INFO("ucb.ucp.webdav", "SerfSession::LOCK: created lock for "
<< makeAbsoluteURL( inPath ) << ". token: " << theLock->token );
for (size_t i = 0; i < aLocks.size(); ++i)
{
// m_pSerfLockStore->addLock( aLocks[i], m_pSerfSession, m_aStartCall );
SAL_INFO("ucb.ucp.webdav", "SerfSession::LOCK: created lock for "
<< getPathStr() << ". token: " << aLocks[i].LockTokens[0]);
}
}
else
{
ne_lock_destroy( theLock );
SAL_INFO("ucb.ucp.webdav", "SerfSession::LOCK: obtaining lock for "
<< makeAbsoluteURL( inPath ) << " failed!");
SAL_INFO("ucb.ucp.webdav", "SerfSession::LOCK: obtaining lock failed!");
}
*/
}
} // namespace http_dav_ucp

View File

@@ -27,6 +27,7 @@
#include <com/sun/star/ucb/LockEntry.hpp>
#include <com/sun/star/ucb/LockScope.hpp>
#include <com/sun/star/ucb/LockType.hpp>
#include <com/sun/star/ucb/Lock.hpp>
#include <map>
#include <boost/unordered_map.hpp>
@@ -69,6 +70,7 @@ namespace
enum WebDAVName
{
WebDAVName_unknown = 0,
WebDAVName_activelock,
WebDAVName_multistatus,
WebDAVName_response,
WebDAVName_href,
@@ -80,8 +82,11 @@ namespace
WebDAVName_supportedlock,
WebDAVName_lockentry,
WebDAVName_lockscope,
WebDAVName_locktoken,
WebDAVName_exclusive,
WebDAVName_locktype,
WebDAVName_owner,
WebDAVName_timeout,
WebDAVName_write,
WebDAVName_shared,
WebDAVName_status,
@@ -100,6 +105,7 @@ namespace
if(aWebDAVNameMapperList.empty())
{
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("activelock"), WebDAVName_activelock));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("multistatus"), WebDAVName_multistatus));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("response"), WebDAVName_response));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("href"), WebDAVName_href));
@@ -111,8 +117,11 @@ namespace
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("supportedlock"), WebDAVName_supportedlock));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("lockentry"), WebDAVName_lockentry));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("lockscope"), WebDAVName_lockscope));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("locktoken"), WebDAVName_locktoken));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("exclusive"), WebDAVName_exclusive));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("locktype"), WebDAVName_locktype));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("owner"), WebDAVName_owner));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("timeout"), WebDAVName_timeout));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("write"), WebDAVName_write));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("shared"), WebDAVName_shared));
aWebDAVNameMapperList.insert(WebDAVNameValueType(OUString("status"), WebDAVName_status));
@@ -277,12 +286,14 @@ namespace
enum WebDAVResponseParserMode
{
WebDAVResponseParserMode_PropFind = 0,
WebDAVResponseParserMode_PropName
WebDAVResponseParserMode_PropName,
WebDAVResponseParserMode_Lock
};
class WebDAVResponseParser : public cppu::WeakImplHelper1< com::sun::star::xml::sax::XDocumentHandler >
{
private:
std::vector< ucb::Lock > maResult_Lock;
std::vector< http_dav_ucp::DAVResource > maResult_PropFind;
std::vector< http_dav_ucp::DAVResourceInfo > maResult_PropName;
@@ -296,6 +307,7 @@ namespace
uno::Sequence< ucb::LockEntry > maLockEntries;
ucb::LockScope maLockScope;
ucb::LockType maLockType;
ucb::Lock maLock;
WebDAVResponseParserMode meWebDAVResponseParserMode;
// bitfield
@@ -356,6 +368,7 @@ namespace
virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) throw (xml::sax::SAXException, uno::RuntimeException);
virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, uno::RuntimeException);
const std::vector< ucb::Lock >& getResult_Lock() const { return maResult_Lock; }
const std::vector< http_dav_ucp::DAVResource >& getResult_PropFind() const { return maResult_PropFind; }
const std::vector< http_dav_ucp::DAVResourceInfo >& getResult_PropName() const { return maResult_PropName; }
};
@@ -480,6 +493,11 @@ namespace
mbLockTypeSet = false;
break;
}
case WebDAVName_activelock:
{
maLock = ucb::Lock();
break;
}
}
break;
}
@@ -641,6 +659,30 @@ namespace
}
break;
}
case WebDAVName_owner:
{
maLock.Owner <<= mpContext->getWhiteSpace();
break;
}
case WebDAVName_timeout:
{
const OUString sTimeout(mpContext->getWhiteSpace());
if (sTimeout == "Infinite")
maLock.Timeout = -1;
else if (sTimeout.startsWith("Second-"))
maLock.Timeout = sTimeout.copy(7).toInt64();
break;
}
case WebDAVName_locktoken:
{
const OUString sLockToken(maHref);
SAL_WARN_IF(!sLockToken.startsWith("opaquelocktoken:"), "ucb.ucp.webdav",
"Parser error: wrong 'locktoken' value.");
const sal_Int32 nLength(maLock.LockTokens.getLength());
maLock.LockTokens.realloc(nLength+1);
maLock.LockTokens[nLength] = sLockToken;
break;
}
case WebDAVName_exclusive:
{
// exclusive lockscope end
@@ -671,6 +713,12 @@ namespace
}
break;
}
case WebDAVName_activelock:
{
maLock.Type = maLockType;
maLock.Scope = maLockScope;
maResult_Lock.push_back(maLock);
}
case WebDAVName_propstat:
{
// propstat end, check status
@@ -789,10 +837,10 @@ namespace
namespace
{
void parseWebDAVPropNameResponse(
template<typename T>
void parseWebDAVResponse(
const uno::Reference< io::XInputStream >& xInputStream,
std::vector< http_dav_ucp::DAVResource >& rPropFind,
std::vector< http_dav_ucp::DAVResourceInfo >& rPropName,
std::vector< T >& rResult,
WebDAVResponseParserMode eWebDAVResponseParserMode)
{
if(xInputStream.is())
@@ -818,16 +866,17 @@ namespace
// get result
switch(eWebDAVResponseParserMode)
{
// *(std::vector<T>*) & is a horrible hack but hopefully works,
// I was not able to come up with something sane :-/
case WebDAVResponseParserMode_PropFind:
{
rPropFind = pWebDAVResponseParser->getResult_PropFind();
rResult = *(std::vector<T>*) &pWebDAVResponseParser->getResult_PropFind();
break;
}
case WebDAVResponseParserMode_PropName:
{
rPropName = pWebDAVResponseParser->getResult_PropName();
rResult = *(std::vector<T>*) &pWebDAVResponseParser->getResult_PropName();
break;
case WebDAVResponseParserMode_Lock:
rResult = *(std::vector<T>*) &pWebDAVResponseParser->getResult_Lock();
break;
}
}
}
catch(uno::Exception&)
@@ -843,22 +892,25 @@ namespace
namespace http_dav_ucp
{
std::vector< ucb::Lock > parseWebDAVLockResponse(const uno::Reference< io::XInputStream >& xInputStream)
{
std::vector< ucb::Lock > aResult;
parseWebDAVResponse< ucb::Lock >(xInputStream, aResult, WebDAVResponseParserMode_Lock);
return aResult;
}
std::vector< DAVResource > parseWebDAVPropFindResponse(const uno::Reference< io::XInputStream >& xInputStream)
{
std::vector< DAVResource > aRetval;
std::vector< DAVResourceInfo > aFoo;
parseWebDAVPropNameResponse(xInputStream, aRetval, aFoo, WebDAVResponseParserMode_PropFind);
return aRetval;
std::vector< DAVResource > aResult;
parseWebDAVResponse< DAVResource >(xInputStream, aResult, WebDAVResponseParserMode_PropFind);
return aResult;
}
std::vector< DAVResourceInfo > parseWebDAVPropNameResponse(const uno::Reference< io::XInputStream >& xInputStream)
{
std::vector< DAVResource > aFoo;
std::vector< DAVResourceInfo > aRetval;
parseWebDAVPropNameResponse(xInputStream, aFoo, aRetval, WebDAVResponseParserMode_PropName);
return aRetval;
std::vector< DAVResourceInfo > aResult;
parseWebDAVResponse< DAVResourceInfo >(xInputStream, aResult, WebDAVResponseParserMode_PropName);
return aResult;
}
} // namespace http_dav_ucp

View File

@@ -22,22 +22,19 @@
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/ucb/Lock.hpp>
#include "DAVResource.hxx"
#include <vector>
namespace http_dav_ucp
{
std::vector< DAVResource > parseWebDAVPropFindResponse(const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& xInputStream);
std::vector< DAVResourceInfo > parseWebDAVPropNameResponse(const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& xInputStream);
std::vector< css::ucb::Lock > parseWebDAVLockResponse(const css::uno::Reference< css::io::XInputStream >& xInputStream);
std::vector< DAVResource > parseWebDAVPropFindResponse(const css::uno::Reference< css::io::XInputStream >& xInputStream);
std::vector< DAVResourceInfo > parseWebDAVPropNameResponse(const css::uno::Reference< css::io::XInputStream >& xInputStream);
} // namespace http_dav_ucp
#endif // _WEBDAVRESPONSEPARSER_HXX_
// eof
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */