Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / webdav-curl / DAVTypes.hxx
blobe0f2e856030a6eb280de66a8f607c0d099f14414
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #pragma once
23 #include <memory>
24 #include <map>
25 #include <mutex>
26 #include <rtl/ustring.hxx>
27 #include <com/sun/star/uno/Any.hxx>
29 namespace http_dav_ucp
31 /* Excerpt from RFC 4918
32 <https://tools.ietf.org/html/rfc4918#section-18>
34 18.1 Class 1
36 A class 1 compliant resource MUST meet all "MUST" requirements in all
37 sections of this document.
39 Class 1 compliant resources MUST return, at minimum, the value "1" in
40 the DAV header on all responses to the OPTIONS method.
42 18.2 Class 2
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.
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.
53 18.3. Class 3
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.
65 class DAVOptions
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;
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;
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;
89 public:
90 DAVOptions();
92 DAVOptions( const DAVOptions & rOther );
94 ~DAVOptions();
96 bool isClass1() const { return m_isClass1; };
97 void setClass1( bool Class1 = true ) { m_isClass1 = Class1; };
99 bool isClass2() const { return m_isClass2; };
100 void setClass2( bool Class2 = true ) { m_isClass2 = Class2; };
102 bool isClass3() const { return m_isClass3; };
103 void setClass3( bool Class3 = true ) { m_isClass3 = Class3; };
105 bool isHeadAllowed() const { return m_isHeadAllowed; };
106 void setHeadAllowed( bool HeadAllowed = true ) { m_isHeadAllowed = HeadAllowed; };
108 sal_uInt32 getStaleTime() const { return m_nStaleTime ; };
109 void setStaleTime( const sal_uInt32 nStaleTime ) { m_nStaleTime = nStaleTime; };
111 sal_uInt32 getRequestedTimeLife() const { return m_nRequestedTimeLife; };
112 void setRequestedTimeLife( const sal_uInt32 nRequestedTimeLife ) { m_nRequestedTimeLife = nRequestedTimeLife; };
114 const OUString & getURL() const { return m_sURL; };
115 void setURL( const OUString & sURL ) { m_sURL = sURL; };
117 const OUString & getRedirectedURL() const { return m_sRedirectedURL; };
118 void setRedirectedURL( const OUString & sRedirectedURL ) { m_sRedirectedURL = sRedirectedURL; };
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 ); };
124 void setLocked( bool locked = true ) { m_isLocked = locked; } ;
125 bool isLocked() const { return m_isLocked; };
127 sal_uInt16 getHttpResponseStatusCode() const { return m_nHttpResponseStatusCode; };
128 void setHttpResponseStatusCode( const sal_uInt16 nHttpResponseStatusCode ) { m_nHttpResponseStatusCode = nHttpResponseStatusCode; };
130 const OUString & getHttpResponseStatusText() const { return m_sHttpResponseStatusText; };
131 void setHttpResponseStatusText( const OUString & rHttpResponseStatusText ) { m_sHttpResponseStatusText = rHttpResponseStatusText; };
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();
148 DAVOptions & operator=( const DAVOptions& rOpts );
149 bool operator==( const DAVOptions& rOpts ) const;
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;
159 class DAVOptionsCache
161 DAVOptionsMap m_aTheCache;
162 std::mutex m_aMutex;
163 public:
164 explicit DAVOptionsCache();
165 ~DAVOptionsCache();
167 bool getDAVOptions( const OUString & rURL, DAVOptions & rDAVOptions );
168 void removeDAVOptions( const OUString & rURL );
169 void addDAVOptions( DAVOptions & rDAVOptions, const sal_uInt32 nLifeTime );
171 void setHeadAllowed( const OUString & rURL, bool HeadAllowed = true );
173 private:
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 );
183 enum Depth { DAVZERO = 0, DAVONE = 1, DAVINFINITY = -1 };
185 enum ProppatchOperation { PROPSET = 0, PROPREMOVE = 1 };
187 struct ProppatchValue
189 ProppatchOperation const operation;
190 OUString const name;
191 css::uno::Any const value;
193 ProppatchValue( const ProppatchOperation o,
194 OUString n,
195 css::uno::Any v )
196 : operation( o ), name( std::move(n) ), value( std::move(v) ) {}
198 } // namespace http_dav_ucp
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */