LibreOffice Module ucb (master) 1
DAVTypes.hxx
Go to the documentation of this file.
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
29namespace 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
66 {
67 private:
77
79 sal_uInt32 m_nStaleTime;
81 OUString m_sURL;
83
88
89 public:
90 DAVOptions();
91
92 DAVOptions( const DAVOptions & rOther );
93
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
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;
142 m_sURL.clear();
143 m_sRedirectedURL.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
160 {
162 std::mutex m_aMutex;
163 public:
164 explicit 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
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
186
188 {
190 OUString const name;
191 css::uno::Any const value;
192
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: */
bool getDAVOptions(const OUString &rURL, DAVOptions &rDAVOptions)
Definition: DAVTypes.cxx:105
void setHeadAllowed(const OUString &rURL, bool HeadAllowed=true)
Definition: DAVTypes.cxx:184
static void normalizeURLLastChar(OUString &aUrl)
remove the last '/' in aUrl, if it exists
Definition: DAVTypes.hxx:176
void removeDAVOptions(const OUString &rURL)
Definition: DAVTypes.cxx:133
void addDAVOptions(DAVOptions &rDAVOptions, const sal_uInt32 nLifeTime)
Definition: DAVTypes.cxx:147
bool isClass1() const
Definition: DAVTypes.hxx:96
bool operator==(const DAVOptions &rOpts) const
Definition: DAVTypes.cxx:77
void setClass3(bool Class3=true)
Definition: DAVTypes.hxx:103
bool m_isHeadAllowed
for server that do not implement it
Definition: DAVTypes.hxx:72
const OUString & getURL() const
Definition: DAVTypes.hxx:114
bool isClass2() const
Definition: DAVTypes.hxx:99
sal_uInt16 m_nHttpResponseStatusCode
The cached HTT response status code. It's 0 if the code was dealt with and there is no need to cache ...
Definition: DAVTypes.hxx:85
sal_uInt32 getRequestedTimeLife() const
Definition: DAVTypes.hxx:111
void setAllowedMethods(const OUString &aAllowedMethods)
Definition: DAVTypes.hxx:120
const OUString & getHttpResponseStatusText() const
Definition: DAVTypes.hxx:130
sal_uInt32 m_nRequestedTimeLife
Definition: DAVTypes.hxx:80
DAVOptions & operator=(const DAVOptions &rOpts)
Definition: DAVTypes.cxx:60
sal_uInt32 m_nStaleTime
target time when this capability becomes stale
Definition: DAVTypes.hxx:79
OUString m_sHttpResponseStatusText
The cached string with the server returned HTTP response status code string, corresponds to m_nHttpRe...
Definition: DAVTypes.hxx:87
void setRequestedTimeLife(const sal_uInt32 nRequestedTimeLife)
Definition: DAVTypes.hxx:112
void setStaleTime(const sal_uInt32 nStaleTime)
Definition: DAVTypes.hxx:109
const OUString & getRedirectedURL() const
Definition: DAVTypes.hxx:117
OUString m_aAllowedMethods
contains the methods allowed on this resource
Definition: DAVTypes.hxx:76
void setClass2(bool Class2=true)
Definition: DAVTypes.hxx:100
void setURL(const OUString &sURL)
Definition: DAVTypes.hxx:115
void setClass1(bool Class1=true)
Definition: DAVTypes.hxx:97
void setHeadAllowed(bool HeadAllowed=true)
Definition: DAVTypes.hxx:106
bool isHeadAllowed() const
Definition: DAVTypes.hxx:105
bool isLockAllowed() const
Definition: DAVTypes.hxx:122
void setLocked(bool locked=true)
Definition: DAVTypes.hxx:124
void setRedirectedURL(const OUString &sRedirectedURL)
Definition: DAVTypes.hxx:118
void setHttpResponseStatusCode(const sal_uInt16 nHttpResponseStatusCode)
Definition: DAVTypes.hxx:128
sal_uInt32 getStaleTime() const
Definition: DAVTypes.hxx:108
sal_uInt16 getHttpResponseStatusCode() const
Definition: DAVTypes.hxx:127
void setHttpResponseStatusText(const OUString &rHttpResponseStatusText)
Definition: DAVTypes.hxx:131
bool m_isLocked
Internally used to maintain the locked state of the resource, only if it's a Class 2 resource.
Definition: DAVTypes.hxx:74
const OUString & getAllowedMethods() const
Definition: DAVTypes.hxx:121
float v
sal_Int64 n
std::map< OUString, DAVOptions, std::less< OUString > > DAVOptionsMap
Definition: DAVTypes.hxx:157
ProppatchValue(const ProppatchOperation o, OUString n, css::uno::Any v)
Definition: DAVTypes.hxx:193
css::uno::Any const value
Definition: DAVTypes.hxx:191
ProppatchOperation const operation
Definition: DAVTypes.hxx:189