| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <memory> |
| 24 |
#include <map> |
| 25 |
#include <mutex> |
| 26 |
#include <rtl/ustring.hxx> |
| 27 |
#include <com/sun/star/uno/Any.hxx> |
| 28 |
|
| 29 |
namespace http_dav_ucp |
| 30 |
{ |
| 31 |
/* Excerpt from RFC 4918 |
| 32 |
<https://tools.ietf.org/html/rfc4918#section-18> |
| 33 |
|
| 34 |
18.1 Class 1 |
| 35 |
|
| 36 |
A class 1 compliant resource MUST meet all "MUST" requirements in all |
| 37 |
sections of this document. |
| 38 |
|
| 39 |
Class 1 compliant resources MUST return, at minimum, the value "1" in |
| 40 |
the DAV header on all responses to the OPTIONS method. |
| 41 |
|
| 42 |
18.2 Class 2 |
| 43 |
|
| 44 |
A class 2 compliant resource MUST meet all class 1 requirements and |
| 45 |
support the LOCK method, the DAV:supportedlock property, the DAV: |
| 46 |
lockdiscovery property, the Time-Out response header and the Lock- |
| 47 |
Token request header. A class 2 compliant resource SHOULD also |
| 48 |
support the Timeout request header and the 'owner' XML element. |
| 49 |
|
| 50 |
Class 2 compliant resources MUST return, at minimum, the values "1" |
| 51 |
and "2" in the DAV header on all responses to the OPTIONS method. |
| 52 |
|
| 53 |
18.3. Class 3 |
| 54 |
|
| 55 |
A resource can explicitly advertise its support for the revisions to |
| 56 |
[RFC2518] made in this document. Class 1 MUST be supported as well. |
| 57 |
Class 2 MAY be supported. Advertising class 3 support in addition to |
| 58 |
class 1 and 2 means that the server supports all the requirements in |
| 59 |
this specification. Advertising class 3 and class 1 support, but not |
| 60 |
class 2, means that the server supports all the requirements in this |
| 61 |
specification except possibly those that involve locking support. |
| 62 |
|
| 63 |
*/ |
| 64 |
|
| 65 |
class DAVOptions |
| 66 |
{ |
| 67 |
private: |
| 68 |
bool m_isClass1; |
| 69 |
bool m_isClass2; |
| 70 |
bool m_isClass3; |
| 71 |
/// for server that do not implement it |
| 72 |
bool m_isHeadAllowed; |
| 73 |
/// Internally used to maintain the locked state of the resource, only if it's a Class 2 resource |
| 74 |
bool m_isLocked; |
| 75 |
/// contains the methods allowed on this resource |
| 76 |
OUString m_aAllowedMethods; |
| 77 |
|
| 78 |
/// target time when this capability becomes stale |
| 79 |
sal_uInt32 m_nStaleTime; |
| 80 |
sal_uInt32 m_nRequestedTimeLife; |
| 81 |
OUString m_sURL; |
| 82 |
OUString m_sRedirectedURL; |
| 83 |
|
| 84 |
/// The cached HTT response status code. It's 0 if the code was dealt with and there is no need to cache it |
| 85 |
sal_uInt16 m_nHttpResponseStatusCode; |
| 86 |
/// The cached string with the server returned HTTP response status code string, corresponds to m_nHttpResponseStatusCode. |
| 87 |
OUString m_sHttpResponseStatusText; |
| 88 |
|
| 89 |
public: |
| 90 |
DAVOptions(); |
| 91 |
|
| 92 |
DAVOptions( const DAVOptions & rOther ); |
| 93 |
|
| 94 |
~DAVOptions(); |
| 95 |
|
| 96 |
bool isClass1() const { return m_isClass1; }; |
| 97 |
void setClass1( bool Class1 = true ) { m_isClass1 = Class1; }; |
| 98 |
|
| 99 |
bool isClass2() const { return m_isClass2; }; |
| 100 |
void setClass2( bool Class2 = true ) { m_isClass2 = Class2; }; |
| 101 |
|
| 102 |
bool isClass3() const { return m_isClass3; }; |
| 103 |
void setClass3( bool Class3 = true ) { m_isClass3 = Class3; }; |
| 104 |
|
| 105 |
bool isHeadAllowed() const { return m_isHeadAllowed; }; |
| 106 |
void setHeadAllowed( bool HeadAllowed = true ) { m_isHeadAllowed = HeadAllowed; }; |
| 107 |
|
| 108 |
sal_uInt32 getStaleTime() const { return m_nStaleTime ; }; |
| 109 |
void setStaleTime( const sal_uInt32 nStaleTime ) { m_nStaleTime = nStaleTime; }; |
| 110 |
|
| 111 |
sal_uInt32 getRequestedTimeLife() const { return m_nRequestedTimeLife; }; |
| 112 |
void setRequestedTimeLife( const sal_uInt32 nRequestedTimeLife ) { m_nRequestedTimeLife = nRequestedTimeLife; }; |
| 113 |
|
| 114 |
const OUString & getURL() const { return m_sURL; }; |
| 115 |
void setURL( const OUString & sURL ) { m_sURL = sURL; }; |
| 116 |
|
| 117 |
const OUString & getRedirectedURL() const { return m_sRedirectedURL; }; |
| 118 |
void setRedirectedURL( const OUString & sRedirectedURL ) { m_sRedirectedURL = sRedirectedURL; }; |
| 119 |
|
| 120 |
void setAllowedMethods( const OUString & aAllowedMethods ) { m_aAllowedMethods = aAllowedMethods; } ; |
| 121 |
const OUString & getAllowedMethods() const { return m_aAllowedMethods; } ; |
| 122 |
bool isLockAllowed() const { return ( m_aAllowedMethods.indexOf( "LOCK" ) != -1 ); }; |
| 123 |
|
| 124 |
void setLocked( bool locked = true ) { m_isLocked = locked; } ; |
| 125 |
bool isLocked() const { return m_isLocked; }; |
| 126 |
|
| 127 |
sal_uInt16 getHttpResponseStatusCode() const { return m_nHttpResponseStatusCode; }; |
| 128 |
void setHttpResponseStatusCode( const sal_uInt16 nHttpResponseStatusCode ) { m_nHttpResponseStatusCode = nHttpResponseStatusCode; }; |
| 129 |
|
| 130 |
const OUString & getHttpResponseStatusText() const { return m_sHttpResponseStatusText; }; |
| 131 |
void setHttpResponseStatusText( const OUString & rHttpResponseStatusText ) { m_sHttpResponseStatusText = rHttpResponseStatusText; }; |
| 132 |
|
| 133 |
void init() { |
| 134 |
m_isClass1 = false; |
| 135 |
m_isClass2 = false; |
| 136 |
m_isClass3 = false; |
| 137 |
m_isHeadAllowed = true; |
| 138 |
m_isLocked = false; |
| 139 |
m_aAllowedMethods.clear(); |
| 140 |
m_nStaleTime = 0; |
| 141 |
m_nRequestedTimeLife = 0; |
| 142 |
m_sURL.clear(); |
| 143 |
m_sRedirectedURL.clear(); |
| 144 |
m_nHttpResponseStatusCode = 0; |
| 145 |
m_sHttpResponseStatusText.clear(); |
| 146 |
}; |
| 147 |
|
| 148 |
DAVOptions & operator=( const DAVOptions& rOpts ); |
| 149 |
bool operator==( const DAVOptions& rOpts ) const; |
| 150 |
|
| 151 |
}; |
| 152 |
|
| 153 |
// TODO: the OUString key element in std::map needs to be changed with a URI representation |
| 154 |
// along with a specific compare (std::less) implementation, as suggested in |
| 155 |
// <https://tools.ietf.org/html/rfc3986#section-6>, to find by URI and not by string comparison |
| 156 |
typedef std::map< OUString, DAVOptions, |
| 157 |
std::less< OUString > > DAVOptionsMap; |
| 158 |
|
| 159 |
class DAVOptionsCache |
| 160 |
{ |
| 161 |
DAVOptionsMap m_aTheCache; |
| 162 |
std::mutex m_aMutex; |
| 163 |
public: |
| 164 |
explicit DAVOptionsCache(); |
| 165 |
~DAVOptionsCache(); |
| 166 |
|
| 167 |
bool getDAVOptions( const OUString & rURL, DAVOptions & rDAVOptions ); |
| 168 |
void removeDAVOptions( const OUString & rURL ); |
| 169 |
void addDAVOptions( DAVOptions & rDAVOptions, const sal_uInt32 nLifeTime ); |
| 170 |
|
| 171 |
void setHeadAllowed( const OUString & rURL, bool HeadAllowed = true ); |
| 172 |
|
| 173 |
private: |
| 174 |
|
| 175 |
/// remove the last '/' in aUrl, if it exists |
| 176 |
static void normalizeURLLastChar( OUString& aUrl ) { |
| 177 |
if ( aUrl.getLength() > 1 && |
| 178 |
( ( aUrl.lastIndexOf( '/' ) + 1 ) == aUrl.getLength() ) ) |
| 179 |
aUrl = aUrl.copy(0, aUrl.getLength() - 1 ); |
| 180 |
}; |
| 181 |
}; |
| 182 |
|
| 183 |
enum Depth { DAVZERO = 0, DAVONE = 1, DAVINFINITY = -1 }; |
| 184 |
|
| 185 |
enum ProppatchOperation { PROPSET = 0, PROPREMOVE = 1 }; |
| 186 |
|
| 187 |
struct ProppatchValue |
| 188 |
{ |
| 189 |
ProppatchOperation const operation; |
| 190 |
OUString const name; |
| 191 |
css::uno::Any const value; |
| 192 |
|
| 193 |
ProppatchValue( const ProppatchOperation o, |
| 194 |
OUString n, |
| 195 |
css::uno::Any v ) |
| 196 |
: operation( o ), name( std::move(n) ), value( std::move(v) ) {} |
| 197 |
}; |
| 198 |
} // namespace http_dav_ucp |
| 199 |
|
| 200 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |