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_AUTH,      // User authentication failed on server,
110                                 // mData = server[:port]
111             DAV_HTTP_AUTHPROXY, // User authentication failed on proxy,
112                                 // mData = proxy server[:port]
113             DAV_HTTP_CONNECT,   // Could not connect to server,
114                                 // mData = server[:port]
115             DAV_HTTP_TIMEOUT,   // Connection timed out
116                                 // mData = server[:port]
117             DAV_HTTP_FAILED,    // The precondition failed
118                                 // mData = server[:port]
119             DAV_HTTP_RETRY,     // Retry request
120                                 // mData = server[:port]
121             DAV_HTTP_REDIRECT,  // Request was redirected,
122                                 // mData = new URL
123             DAV_SESSION_CREATE, // session creation error,
124                                 // mData = server[:port]
125             DAV_INVALID_ARG,    // invalid argument
126 
127             DAV_LOCK_EXPIRED,   // DAV lock expired
128 
129             DAV_NOT_LOCKED,     // not locked
130 
131             DAV_LOCKED_SELF,    // locked by this OOo session
132 
133             DAV_LOCKED          // locked by third party
134         };
135 
136     private:
137         ExceptionCode   mExceptionCode;
138         rtl::OUString   mData;
139         sal_uInt16      mStatusCode;
140 
141     public:
142          DAVException( ExceptionCode inExceptionCode )
143              : mExceptionCode( inExceptionCode )
144              , mData()
145              , mStatusCode( SC_NONE )
146          {};
147          DAVException( ExceptionCode inExceptionCode,
148                        const rtl::OUString & rData )
149              : mExceptionCode( inExceptionCode )
150              , mData( rData )
151              , mStatusCode( SC_NONE )
152          {};
153          DAVException( ExceptionCode inExceptionCode,
154                        const rtl::OUString & rData,
155                        sal_uInt16 nStatusCode )
156             : mExceptionCode( inExceptionCode )
157             , mData( rData )
158             , mStatusCode( nStatusCode )
159          {};
160         ~DAVException( ) {};
161 
162     const ExceptionCode & getError() const { return mExceptionCode; }
163     const rtl::OUString & getData() const  { return mData; }
164     sal_uInt16 getStatus() const { return mStatusCode; }
165 };
166 
167 } // namespace http_dav_ucp
168 
169 #endif // _DAVEXCEPTION_HXX_
170