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 <map>
34 #include <osl/mutex.hxx>
35 #include <rtl/ustring.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 
38 namespace webdav_ucp
39 {
40 /* Excerpt from RFC 4918
41  <https://tools.ietf.org/html/rfc4918#section-18>
42 
43  18.1 Class 1
44 
45  A class 1 compliant resource MUST meet all "MUST" requirements in all
46  sections of this document.
47 
48  Class 1 compliant resources MUST return, at minimum, the value "1" in
49  the DAV header on all responses to the OPTIONS method.
50 
51  18.2 Class 2
52 
53  A class 2 compliant resource MUST meet all class 1 requirements and
54  support the LOCK method, the DAV:supportedlock property, the DAV:
55  lockdiscovery property, the Time-Out response header and the Lock-
56  Token request header. A class 2 compliant resource SHOULD also
57  support the Timeout request header and the 'owner' XML element.
58 
59  Class 2 compliant resources MUST return, at minimum, the values "1"
60  and "2" in the DAV header on all responses to the OPTIONS method.
61 
62  18.3. Class 3
63 
64  A resource can explicitly advertise its support for the revisions to
65  [RFC2518] made in this document. Class 1 MUST be supported as well.
66  Class 2 MAY be supported. Advertising class 3 support in addition to
67  class 1 and 2 means that the server supports all the requirements in
68  this specification. Advertising class 3 and class 1 support, but not
69  class 2, means that the server supports all the requirements in this
70  specification except possibly those that involve locking support.
71 
72 */
73 
74  class DAVOptions final
75  {
76  private:
77  bool m_isClass1;
78  bool m_isClass2;
79  bool m_isClass3;
83  bool m_isLocked;
86 
88  sal_uInt32 m_nStaleTime;
90  OUString m_sURL;
91  OUString m_sRedirectedURL;
92 
97 
98  public:
99  DAVOptions();
100 
101  DAVOptions( const DAVOptions & rOther );
102 
103  ~DAVOptions();
104 
105  bool isClass1() const { return m_isClass1; };
106  void setClass1( bool Class1 = true ) { m_isClass1 = Class1; };
107 
108  bool isClass2() const { return m_isClass2; };
109  void setClass2( bool Class2 = true ) { m_isClass2 = Class2; };
110 
111  bool isClass3() const { return m_isClass3; };
112  void setClass3( bool Class3 = true ) { m_isClass3 = Class3; };
113 
114  bool isHeadAllowed() const { return m_isHeadAllowed; };
115  void setHeadAllowed( bool HeadAllowed = true ) { m_isHeadAllowed = HeadAllowed; };
116 
117  sal_uInt32 getStaleTime() const { return m_nStaleTime ; };
118  void setStaleTime( const sal_uInt32 nStaleTime ) { m_nStaleTime = nStaleTime; };
119 
120  sal_uInt32 getRequestedTimeLife() const { return m_nRequestedTimeLife; };
121  void setRequestedTimeLife( const sal_uInt32 nRequestedTimeLife ) { m_nRequestedTimeLife = nRequestedTimeLife; };
122 
123  const OUString & getURL() const { return m_sURL; };
124  void setURL( const OUString & sURL ) { m_sURL = sURL; };
125 
126  const OUString & getRedirectedURL() const { return m_sRedirectedURL; };
127  void setRedirectedURL( const OUString & sRedirectedURL ) { m_sRedirectedURL = sRedirectedURL; };
128 
129  void setAllowedMethods( const OUString & aAllowedMethods ) { m_aAllowedMethods = aAllowedMethods; } ;
130  const OUString & getAllowedMethods() const { return m_aAllowedMethods; } ;
131  bool isLockAllowed() const { return ( m_aAllowedMethods.indexOf( "LOCK" ) != -1 ); };
132 
133  void setLocked( bool locked = true ) { m_isLocked = locked; } ;
134  bool isLocked() const { return m_isLocked; };
135 
136  sal_uInt16 getHttpResponseStatusCode() const { return m_nHttpResponseStatusCode; };
137  void setHttpResponseStatusCode( const sal_uInt16 nHttpResponseStatusCode ) { m_nHttpResponseStatusCode = nHttpResponseStatusCode; };
138 
139  const OUString & getHttpResponseStatusText() const { return m_sHttpResponseStatusText; };
140  void setHttpResponseStatusText( const OUString & rHttpResponseStatusText ) { m_sHttpResponseStatusText = rHttpResponseStatusText; };
141 
142  void init() {
143  m_isClass1 = false;
144  m_isClass2 = false;
145  m_isClass3 = false;
146  m_isHeadAllowed = true;
147  m_isLocked = false;
148  m_aAllowedMethods.clear();
149  m_nStaleTime = 0;
150  m_nRequestedTimeLife = 0;
151  m_sURL.clear();
152  m_sRedirectedURL.clear();
153  m_nHttpResponseStatusCode = 0;
154  m_sHttpResponseStatusText.clear();
155  };
156 
157  DAVOptions & operator=( const DAVOptions& rOpts );
158  bool operator==( const DAVOptions& rOpts ) const;
159 
160  };
161 
162  // TODO: the OUString key element in std::map needs to be changed with a URI representation
163  // along with a specific compare (std::less) implementation, as suggested in
164  // <https://tools.ietf.org/html/rfc3986#section-6>, to find by URI and not by string comparison
165  typedef std::map< OUString, DAVOptions,
166  std::less< OUString > > DAVOptionsMap;
167 
169  {
170  DAVOptionsMap m_aTheCache;
171  osl::Mutex m_aMutex;
172  public:
173  explicit DAVOptionsCache();
175 
176  bool getDAVOptions( const OUString & rURL, DAVOptions & rDAVOptions );
177  void removeDAVOptions( const OUString & rURL );
178  void addDAVOptions( DAVOptions & rDAVOptions, const sal_uInt32 nLifeTime );
179 
180  void setHeadAllowed( const OUString & rURL, bool HeadAllowed = true );
181 
182  private:
183 
185  static void normalizeURLLastChar( OUString& aUrl ) {
186  if ( aUrl.getLength() > 1 &&
187  ( ( aUrl.lastIndexOf( '/' ) + 1 ) == aUrl.getLength() ) )
188  aUrl = aUrl.copy(0, aUrl.getLength() - 1 );
189  };
190  };
191 
192  enum Depth { DAVZERO = 0, DAVONE = 1, DAVINFINITY = -1 };
193 
195 
197  {
199  OUString const name;
200  css::uno::Any const value;
201 
203  const OUString & n,
204  const css::uno::Any & v )
205  : operation( o ), name( n ), value( v ) {}
206  };
207 } // namespace webdav_ucp
208 
209 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_DAVTYPES_HXX
210 
211 /* 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)