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