1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DAVEXCEPTION_HXX_
25 #define _DAVEXCEPTION_HXX_
26 
27 #include <rtl/ustring.hxx>
28 
29 namespace http_dav_ucp
30 {
31 
32 /////////////////////////////////////////////////////////////////////////////
33 // HTTP/WebDAV status codes
34 /////////////////////////////////////////////////////////////////////////////
35 
36 const sal_uInt16 SC_NONE                             = 0;
37 
38 // 1xx (Informational - no errors)
39 const sal_uInt16 SC_CONTINUE                         = 100;
40 const sal_uInt16 SC_SWITCHING_PROTOCOLS              = 101;
41 // DAV extensions
42 const sal_uInt16 SC_PROCESSING                       = 102;
43 
44 //2xx (Successful - no errors)
45 const sal_uInt16 SC_OK                               = 200;
46 const sal_uInt16 SC_CREATED                          = 201;
47 const sal_uInt16 SC_ACCEPTED                         = 202;
48 const sal_uInt16 SC_NON_AUTHORITATIVE_INFORMATION    = 203;
49 const sal_uInt16 SC_NO_CONTENT                       = 204;
50 const sal_uInt16 SC_RESET_CONTENT                    = 205;
51 const sal_uInt16 SC_PARTIAL_CONTENT                  = 206;
52 // DAV extensions
53 const sal_uInt16 SC_MULTISTATUS                      = 207;
54 
55 //3xx (Redirection)
56 const sal_uInt16 SC_MULTIPLE_CHOICES                 = 300;
57 const sal_uInt16 SC_MOVED_PERMANENTLY                = 301;
58 const sal_uInt16 SC_MOVED_TEMPORARILY                = 302;
59 const sal_uInt16 SC_SEE_OTHER                        = 303;
60 const sal_uInt16 SC_NOT_MODIFIED                     = 304;
61 const sal_uInt16 SC_USE_PROXY                        = 305;
62 const sal_uInt16 SC_TEMPORARY_REDIRECT               = 307;
63 
64 //4xx (Client error)
65 const sal_uInt16 SC_BAD_REQUEST                      = 400;
66 const sal_uInt16 SC_UNAUTHORIZED                     = 401;
67 const sal_uInt16 SC_PAYMENT_REQUIRED                 = 402;
68 const sal_uInt16 SC_FORBIDDEN                        = 403;
69 const sal_uInt16 SC_NOT_FOUND                        = 404;
70 const sal_uInt16 SC_METHOD_NOT_ALLOWED               = 405;
71 const sal_uInt16 SC_NOT_ACCEPTABLE                   = 406;
72 const sal_uInt16 SC_PROXY_AUTHENTICATION_REQUIRED    = 407;
73 const sal_uInt16 SC_REQUEST_TIMEOUT                  = 408;
74 const sal_uInt16 SC_CONFLICT                         = 409;
75 const sal_uInt16 SC_GONE                             = 410;
76 const sal_uInt16 SC_LENGTH_REQUIRED                  = 411;
77 const sal_uInt16 SC_PRECONDITION_FAILED              = 412;
78 const sal_uInt16 SC_REQUEST_ENTITY_TOO_LARGE         = 413;
79 const sal_uInt16 SC_REQUEST_URI_TOO_LONG             = 414;
80 const sal_uInt16 SC_UNSUPPORTED_MEDIA_TYPE           = 415;
81 const sal_uInt16 SC_REQUESTED_RANGE_NOT_SATISFIABLE  = 416;
82 const sal_uInt16 SC_EXPECTATION_FAILED               = 417;
83 // DAV extensions
84 const sal_uInt16 SC_UNPROCESSABLE_ENTITY             = 422;
85 const sal_uInt16 SC_LOCKED                           = 423;
86 const sal_uInt16 SC_FAILED_DEPENDENCY                = 424;
87 
88 //5xx (Server error)
89 const sal_uInt16 SC_INTERNAL_SERVER_ERROR            = 500;
90 const sal_uInt16 SC_NOT_IMPLEMENTED                  = 501;
91 const sal_uInt16 SC_BAD_GATEWAY                      = 502;
92 const sal_uInt16 SC_SERVICE_UNAVAILABLE              = 503;
93 const sal_uInt16 SC_GATEWAY_TIMEOUT                  = 504;
94 const sal_uInt16 SC_HTTP_VERSION_NOT_SUPPORTED       = 505;
95 // DAV extensions
96 const sal_uInt16 SC_INSUFFICIENT_STORAGE             = 507;
97 
98 /////////////////////////////////////////////////////////////////////////////
99 
100 class DAVException
101 {
102     public:
103         enum ExceptionCode {
104             DAV_HTTP_ERROR = 0, // Generic error,
105                                 // mData = server error message,
106                                 // mStatusCode = HTTP status code
107             DAV_HTTP_LOOKUP,    // Name lookup failed,
108                                 // mData = server[:port]
109             DAV_HTTP_NOAUTH,    // No User authentication data provided - e.g., user aborts corresponding dialog
110                                 // mData = server[:port]
111             DAV_HTTP_AUTH,      // User authentication failed on server,
112                                 // mData = server[:port]
113             DAV_HTTP_AUTHPROXY, // User authentication failed on proxy,
114                                 // mData = proxy server[:port]
115             DAV_HTTP_CONNECT,   // Could not connect to server,
116                                 // mData = server[:port]
117             DAV_HTTP_TIMEOUT,   // Connection timed out
118                                 // mData = server[:port]
119             DAV_HTTP_FAILED,    // The precondition failed
120                                 // mData = server[:port]
121             DAV_HTTP_RETRY,     // Retry request
122                                 // mData = server[:port]
123             DAV_HTTP_REDIRECT,  // Request was redirected,
124                                 // mData = new URL
125             DAV_SESSION_CREATE, // session creation error,
126                                 // mData = server[:port]
127             DAV_INVALID_ARG,    // invalid argument
128 
129             DAV_LOCK_EXPIRED,   // DAV lock expired
130 
131             DAV_NOT_LOCKED,     // not locked
132 
133             DAV_LOCKED_SELF,    // locked by this OOo session
134 
135             DAV_LOCKED          // locked by third party
136         };
137 
138     private:
139         ExceptionCode   mExceptionCode;
140         rtl::OUString   mData;
141     //owner of the lock in case of DAV_LOCKED
142         rtl::OUString   mOwner;
143     //extendend error information, if the server has a specific header
144     //see in SerfRequestProcessor::handleSerfResponse for detail on how this is obtained
145         rtl::OUString   mExtendedError;
146         sal_uInt16      mStatusCode;
147 
148     public:
DAVException(ExceptionCode inExceptionCode)149          DAVException( ExceptionCode inExceptionCode )
150              : mExceptionCode( inExceptionCode )
151              , mData()
152              , mOwner()
153              , mExtendedError()
154              , mStatusCode( SC_NONE )
155          {};
DAVException(ExceptionCode inExceptionCode,const rtl::OUString & rData)156          DAVException( ExceptionCode inExceptionCode,
157                        const rtl::OUString & rData )
158              : mExceptionCode( inExceptionCode )
159              , mData( rData )
160              , mOwner()
161              , mExtendedError()
162              , mStatusCode( SC_NONE )
163          {};
DAVException(ExceptionCode inExceptionCode,const rtl::OUString & rData,sal_uInt16 nStatusCode)164          DAVException( ExceptionCode inExceptionCode,
165                        const rtl::OUString & rData,
166                        sal_uInt16 nStatusCode )
167             : mExceptionCode( inExceptionCode )
168             , mData( rData )
169             , mOwner()
170             , mExtendedError()
171             , mStatusCode( nStatusCode )
172          {};
DAVException(ExceptionCode inExceptionCode,const rtl::OUString & rData,const rtl::OUString & rExtendedError,sal_uInt16 nStatusCode=SC_NONE)173          DAVException( ExceptionCode inExceptionCode,
174                        const rtl::OUString & rData,
175                        const rtl::OUString & rExtendedError,
176                        sal_uInt16 nStatusCode = SC_NONE )
177             : mExceptionCode( inExceptionCode )
178             , mData( rData )
179             , mOwner()
180             , mExtendedError( rExtendedError )
181             , mStatusCode( nStatusCode )
182          {};
~DAVException()183         ~DAVException( ) {};
184 
getError() const185     const ExceptionCode & getError() const { return mExceptionCode; }
getData() const186     const rtl::OUString & getData() const  { return mData; }
getExtendedError() const187     const rtl::OUString & getExtendedError() const { return  mExtendedError; }
getStatus() const188     sal_uInt16 getStatus() const { return mStatusCode; }
getOwner() const189     const rtl::OUString & getOwner() const { return mOwner; }
setOwner(const rtl::OUString & rOwner)190     void setOwner(const rtl::OUString & rOwner) { mOwner = rOwner; }
191 
192 };
193 
194 } // namespace http_dav_ucp
195 
196 #endif // _DAVEXCEPTION_HXX_
197