LibreOffice Module ucb (master)  1
neon/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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_DAVTYPES_HXX
30 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_DAVTYPES_HXX
31 
32 #include <config_lgpl.h>
33 #include <memory>
34 #include <list>
35 #include <map>
36 #include <osl/mutex.hxx>
37 #include <rtl/uri.hxx>
38 #include <rtl/ustring.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 
41 namespace webdav_ucp
42 {
43 /* Excerpt from RFC 4918
44  <https://tools.ietf.org/html/rfc4918#section-18>
45 
46  18.1 Class 1
47 
48  A class 1 compliant resource MUST meet all "MUST" requirements in all
49  sections of this document.
50 
51  Class 1 compliant resources MUST return, at minimum, the value "1" in
52  the DAV header on all responses to the OPTIONS method.
53 
54  18.2 Class 2
55 
56  A class 2 compliant resource MUST meet all class 1 requirements and
57  support the LOCK method, the DAV:supportedlock property, the DAV:
58  lockdiscovery property, the Time-Out response header and the Lock-
59  Token request header. A class 2 compliant resource SHOULD also
60  support the Timeout request header and the 'owner' XML element.
61 
62  Class 2 compliant resources MUST return, at minimum, the values "1"
63  and "2" in the DAV header on all responses to the OPTIONS method.
64 
65  18.3. Class 3
66 
67  A resource can explicitly advertise its support for the revisions to
68  [RFC2518] made in this document. Class 1 MUST be supported as well.
69  Class 2 MAY be supported. Advertising class 3 support in addition to
70  class 1 and 2 means that the server supports all the requirements in
71  this specification. Advertising class 3 and class 1 support, but not
72  class 2, means that the server supports all the requirements in this
73  specification except possibly those that involve locking support.
74 
75 */
76 
77  class DAVOptions final
78  {
79  private:
80  bool m_isClass1;
81  bool m_isClass2;
82  bool m_isClass3;
86  bool m_isLocked;
89 
91  sal_uInt32 m_nStaleTime;
93  OUString m_sURL;
94  OUString m_sRedirectedURL;
95 
100 
101  public:
102  DAVOptions();
103 
104  DAVOptions( const DAVOptions & rOther );
105 
106  ~DAVOptions();
107 
108  bool isClass1() const { return m_isClass1; };
109  void setClass1( bool Class1 = true ) { m_isClass1 = Class1; };
110 
111  bool isClass2() const { return m_isClass2; };
112  void setClass2( bool Class2 = true ) { m_isClass2 = Class2; };
113 
114  bool isClass3() const { return m_isClass3; };
115  void setClass3( bool Class3 = true ) { m_isClass3 = Class3; };
116 
117  bool isHeadAllowed() const { return m_isHeadAllowed; };
118  void setHeadAllowed( bool HeadAllowed = true ) { m_isHeadAllowed = HeadAllowed; };
119 
120  sal_uInt32 getStaleTime() const { return m_nStaleTime ; };
121  void setStaleTime( const sal_uInt32 nStaleTime ) { m_nStaleTime = nStaleTime; };
122 
123  sal_uInt32 getRequestedTimeLife() const { return m_nRequestedTimeLife; };
124  void setRequestedTimeLife( const sal_uInt32 nRequestedTimeLife ) { m_nRequestedTimeLife = nRequestedTimeLife; };
125 
126  const OUString & getURL() const { return m_sURL; };
127  void setURL( const OUString & sURL ) { m_sURL = sURL; };
128 
129  const OUString & getRedirectedURL() const { return m_sRedirectedURL; };
130  void setRedirectedURL( const OUString & sRedirectedURL ) { m_sRedirectedURL = sRedirectedURL; };
131 
132  void setAllowedMethods( const OUString & aAllowedMethods ) { m_aAllowedMethods = aAllowedMethods; } ;
133  const OUString & getAllowedMethods() const { return m_aAllowedMethods; } ;
134  bool isLockAllowed() const { return ( m_aAllowedMethods.indexOf( "LOCK" ) != -1 ); };
135 
136  void setLocked( bool locked = true ) { m_isLocked = locked; } ;
137  bool isLocked() const { return m_isLocked; };
138 
139  sal_uInt16 getHttpResponseStatusCode() const { return m_nHttpResponseStatusCode; };
140  void setHttpResponseStatusCode( const sal_uInt16 nHttpResponseStatusCode ) { m_nHttpResponseStatusCode = nHttpResponseStatusCode; };
141 
142  const OUString & getHttpResponseStatusText() const { return m_sHttpResponseStatusText; };
143  void setHttpResponseStatusText( const OUString & rHttpResponseStatusText ) { m_sHttpResponseStatusText = rHttpResponseStatusText; };
144 
145  void init() {
146  m_isClass1 = false;
147  m_isClass2 = false;
148  m_isClass3 = false;
149  m_isHeadAllowed = true;
150  m_isLocked = false;
151  m_aAllowedMethods.clear();
152  m_nStaleTime = 0;
153  m_nRequestedTimeLife = 0;
154  m_sURL.clear();
155  m_sRedirectedURL.clear();
156  m_nHttpResponseStatusCode = 0;
157  m_sHttpResponseStatusText.clear();
158  };
159 
160  DAVOptions & operator=( const DAVOptions& rOpts );
161  bool operator==( const DAVOptions& rOpts ) const;
162 
163  };
164 
165  // TODO: the OUString key element in std::map needs to be changed with a URI representation
166  // along with a specific compare (std::less) implementation, as suggested in
167  // <https://tools.ietf.org/html/rfc3986#section-6>, to find by URI and not by string comparison
168  typedef std::map< OUString, DAVOptions,
169  std::less< OUString > > DAVOptionsMap;
170 
172  {
173  DAVOptionsMap m_aTheCache;
174  osl::Mutex m_aMutex;
175  public:
176  explicit DAVOptionsCache();
178 
179  bool getDAVOptions( const OUString & rURL, DAVOptions & rDAVOptions );
180  void removeDAVOptions( const OUString & rURL );
181  void addDAVOptions( DAVOptions & rDAVOptions, const sal_uInt32 nLifeTime );
182 
183  void setHeadAllowed( const OUString & rURL, bool HeadAllowed = true );
184 
185  private:
186 
188  static void normalizeURLLastChar( OUString& aUrl ) {
189  if ( aUrl.getLength() > 1 &&
190  ( ( aUrl.lastIndexOf( '/' ) + 1 ) == aUrl.getLength() ) )
191  aUrl = aUrl.copy(0, aUrl.getLength() - 1 );
192  };
193  };
194 
195  enum Depth { DAVZERO = 0, DAVONE = 1, DAVINFINITY = -1 };
196 
198 
200  {
202  OUString const name;
203  css::uno::Any const value;
204 
206  const OUString & n,
207  const css::uno::Any & v )
208  : operation( o ), name( n ), value( v ) {}
209  };
210 } // namespace webdav_ucp
211 
212 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_DAVTYPES_HXX
213 
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & getAllowedMethods() const
sal_uInt32 m_nRequestedTimeLife
void setURL(const OUString &sURL)
void setStaleTime(const sal_uInt32 nStaleTime)
void removeDAVOptions(const OUString &rURL)
Definition: DAVTypes.cxx:130
bool isLockAllowed() const
void addDAVOptions(DAVOptions &rDAVOptions, const sal_uInt32 nLifeTime)
Definition: DAVTypes.cxx:143
sal_uInt32 getRequestedTimeLife() const
void setHeadAllowed(const OUString &rURL, bool HeadAllowed=true)
Definition: DAVTypes.cxx:171
sal_uInt32 m_nStaleTime
target time when this capability becomes stale
void setClass2(bool Class2=true)
void setHttpResponseStatusCode(const sal_uInt16 nHttpResponseStatusCode)
void setRequestedTimeLife(const sal_uInt32 nRequestedTimeLife)
void setClass1(bool Class1=true)
void setHeadAllowed(bool HeadAllowed=true)
OUString m_sHttpResponseStatusText
The cached string with the server returned HTTP response status code string, corresponds to m_nHttpRe...
static void normalizeURLLastChar(OUString &aUrl)
remove the last '/' in aUrl, if it exists
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 ...
bool getDAVOptions(const OUString &rURL, DAVOptions &rDAVOptions)
Definition: DAVTypes.cxx:103
const OUString & getHttpResponseStatusText() const
bool m_isHeadAllowed
for server that do not implement it
void setRedirectedURL(const OUString &sRedirectedURL)
std::map< OUString, DAVOptions, std::less< OUString > > DAVOptionsMap
ProppatchValue(const ProppatchOperation o, const OUString &n, const css::uno::Any &v)
const OUString & getRedirectedURL() const
void setAllowedMethods(const OUString &aAllowedMethods)
sal_uInt16 getHttpResponseStatusCode() const
css::uno::Any const value
ProppatchOperation const operation
DAVOptions & operator=(const DAVOptions &rOpts)
Definition: DAVTypes.cxx:58
void setHttpResponseStatusText(const OUString &rHttpResponseStatusText)
void setLocked(bool locked=true)
const OUString & getURL() const
OUString m_aAllowedMethods
contains the methods allowed on this resource
bool m_isLocked
Internally used to maintain the locked state of the resource, only if it's a Class 2 resource...
sal_uInt32 getStaleTime() const
bool isHeadAllowed() const
bool operator==(const DAVOptions &rOpts) const
Definition: DAVTypes.cxx:75
void setClass3(bool Class3=true)