1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _DAVEXCEPTION_HXX_
29 #define _DAVEXCEPTION_HXX_
30 
31 #include <rtl/ustring.hxx>
32 
33 namespace webdav_ucp
34 {
35 
36 /////////////////////////////////////////////////////////////////////////////
37 // HTTP/WebDAV status codes
38 /////////////////////////////////////////////////////////////////////////////
39 
40 const sal_uInt16 SC_NONE                             = 0;
41 
42 // 1xx (Informational - no errors)
43 const sal_uInt16 SC_CONTINUE                         = 100;
44 const sal_uInt16 SC_SWITCHING_PROTOCOLS              = 101;
45 // DAV extensions
46 const sal_uInt16 SC_PROCESSING                       = 102;
47 
48 //2xx (Successful - no errors)
49 const sal_uInt16 SC_OK                               = 200;
50 const sal_uInt16 SC_CREATED                          = 201;
51 const sal_uInt16 SC_ACCEPTED                         = 202;
52 const sal_uInt16 SC_NON_AUTHORITATIVE_INFORMATION    = 203;
53 const sal_uInt16 SC_NO_CONTENT                       = 204;
54 const sal_uInt16 SC_RESET_CONTENT                    = 205;
55 const sal_uInt16 SC_PARTIAL_CONTENT                  = 206;
56 // DAV extensions
57 const sal_uInt16 SC_MULTISTATUS                      = 207;
58 
59 //3xx (Redirection)
60 const sal_uInt16 SC_MULTIPLE_CHOICES                 = 300;
61 const sal_uInt16 SC_MOVED_PERMANENTLY                = 301;
62 const sal_uInt16 SC_MOVED_TEMPORARILY                = 302;
63 const sal_uInt16 SC_SEE_OTHER                        = 303;
64 const sal_uInt16 SC_NOT_MODIFIED                     = 304;
65 const sal_uInt16 SC_USE_PROXY                        = 305;
66 const sal_uInt16 SC_TEMPORARY_REDIRECT               = 307;
67 
68 //4xx (Client error)
69 const sal_uInt16 SC_BAD_REQUEST                      = 400;
70 const sal_uInt16 SC_UNAUTHORIZED                     = 401;
71 const sal_uInt16 SC_PAYMENT_REQUIRED                 = 402;
72 const sal_uInt16 SC_FORBIDDEN                        = 403;
73 const sal_uInt16 SC_NOT_FOUND                        = 404;
74 const sal_uInt16 SC_METHOD_NOT_ALLOWED               = 405;
75 const sal_uInt16 SC_NOT_ACCEPTABLE                   = 406;
76 const sal_uInt16 SC_PROXY_AUTHENTICATION_REQUIRED    = 407;
77 const sal_uInt16 SC_REQUEST_TIMEOUT                  = 408;
78 const sal_uInt16 SC_CONFLICT                         = 409;
79 const sal_uInt16 SC_GONE                             = 410;
80 const sal_uInt16 SC_LENGTH_REQUIRED                  = 411;
81 const sal_uInt16 SC_PRECONDITION_FAILED              = 412;
82 const sal_uInt16 SC_REQUEST_ENTITY_TOO_LARGE         = 413;
83 const sal_uInt16 SC_REQUEST_URI_TOO_LONG             = 414;
84 const sal_uInt16 SC_UNSUPPORTED_MEDIA_TYPE           = 415;
85 const sal_uInt16 SC_REQUESTED_RANGE_NOT_SATISFIABLE  = 416;
86 const sal_uInt16 SC_EXPECTATION_FAILED               = 417;
87 // DAV extensions
88 const sal_uInt16 SC_UNPROCESSABLE_ENTITY             = 422;
89 const sal_uInt16 SC_LOCKED                           = 423;
90 const sal_uInt16 SC_FAILED_DEPENDENCY                = 424;
91 
92 //5xx (Server error)
93 const sal_uInt16 SC_INTERNAL_SERVER_ERROR            = 500;
94 const sal_uInt16 SC_NOT_IMPLEMENTED                  = 501;
95 const sal_uInt16 SC_BAD_GATEWAY                      = 502;
96 const sal_uInt16 SC_SERVICE_UNAVAILABLE              = 503;
97 const sal_uInt16 SC_GATEWAY_TIMEOUT                  = 504;
98 const sal_uInt16 SC_HTTP_VERSION_NOT_SUPPORTED       = 505;
99 // DAV extensions
100 const sal_uInt16 SC_INSUFFICIENT_STORAGE             = 507;
101 
102 /////////////////////////////////////////////////////////////////////////////
103 
104 class DAVException
105 {
106     public:
107         enum ExceptionCode {
108             DAV_HTTP_ERROR = 0, // Generic error,
109                                 // mData = server error message,
110                                 // mStatusCode = HTTP status code
111             DAV_HTTP_LOOKUP,    // Name lookup failed,
112                                 // mData = server[:port]
113             DAV_HTTP_AUTH,      // User authentication failed on server,
114                                 // mData = server[:port]
115             DAV_HTTP_AUTHPROXY, // User authentication failed on proxy,
116                                 // mData = proxy server[:port]
117             DAV_HTTP_CONNECT,   // Could not connect to server,
118                                 // mData = server[:port]
119             DAV_HTTP_TIMEOUT,   // Connection timed out
120                                 // mData = server[:port]
121             DAV_HTTP_FAILED,    // The precondition failed
122                                 // mData = server[:port]
123             DAV_HTTP_RETRY,     // Retry request
124                                 // mData = server[:port]
125             DAV_HTTP_REDIRECT,  // Request was redirected,
126                                 // mData = new URL
127             DAV_SESSION_CREATE, // session creation error,
128                                 // mData = server[:port]
129             DAV_INVALID_ARG,    // invalid argument
130 
131             DAV_LOCK_EXPIRED,   // DAV lock expired
132 
133             DAV_NOT_LOCKED,     // not locked
134 
135             DAV_LOCKED_SELF,    // locked by this OOo session
136 
137             DAV_LOCKED          // locked by third party
138         };
139 
140     private:
141         ExceptionCode   mExceptionCode;
142         rtl::OUString   mData;
143         sal_uInt16      mStatusCode;
144 
145     public:
146          DAVException( ExceptionCode inExceptionCode ) :
147             mExceptionCode( inExceptionCode ), mStatusCode( SC_NONE ) {};
148          DAVException( ExceptionCode inExceptionCode,
149                        const rtl::OUString & rData ) :
150             mExceptionCode( inExceptionCode ), mData( rData ),
151             mStatusCode( SC_NONE ) {};
152          DAVException( ExceptionCode inExceptionCode,
153                        const rtl::OUString & rData,
154                        sal_uInt16 nStatusCode ) :
155             mExceptionCode( inExceptionCode ), mData( rData ),
156             mStatusCode( nStatusCode ) {};
157         ~DAVException( ) {};
158 
159     const ExceptionCode & getError() const { return mExceptionCode; }
160     const rtl::OUString & getData() const  { return mData; }
161     sal_uInt16 getStatus() const { return mStatusCode; }
162 };
163 
164 } // namespace webdav_ucp
165 
166 #endif // _DAVEXCEPTION_HXX_
167