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 <rtl/ustring.hxx>
33 
34 namespace webdav_ucp
35 {
36 
37 
38 // HTTP/WebDAV status codes
39 
40 
41 const sal_uInt16 SC_NONE                             = 0;
42 
43 // 1xx (Informational - no errors)
44 const sal_uInt16 SC_CONTINUE                         = 100;
45 const sal_uInt16 SC_SWITCHING_PROTOCOLS              = 101;
46 // DAV extensions
47 const sal_uInt16 SC_PROCESSING                       = 102;
48 
49 //2xx (Successful - no errors)
50 const sal_uInt16 SC_OK                               = 200;
51 const sal_uInt16 SC_CREATED                          = 201;
52 const sal_uInt16 SC_ACCEPTED                         = 202;
53 const sal_uInt16 SC_NON_AUTHORITATIVE_INFORMATION    = 203;
54 const sal_uInt16 SC_NO_CONTENT                       = 204;
55 const sal_uInt16 SC_RESET_CONTENT                    = 205;
56 const sal_uInt16 SC_PARTIAL_CONTENT                  = 206;
57 // DAV extensions
58 const sal_uInt16 SC_MULTISTATUS                      = 207;
59 
60 //3xx (Redirection)
61 const sal_uInt16 SC_MULTIPLE_CHOICES                 = 300;
62 const sal_uInt16 SC_MOVED_PERMANENTLY                = 301;
63 const sal_uInt16 SC_MOVED_TEMPORARILY                = 302;
64 const sal_uInt16 SC_SEE_OTHER                        = 303;
65 const sal_uInt16 SC_NOT_MODIFIED                     = 304;
66 const sal_uInt16 SC_USE_PROXY                        = 305;
67 const sal_uInt16 SC_TEMPORARY_REDIRECT               = 307;
68 
69 //4xx (Client error)
70 const sal_uInt16 SC_BAD_REQUEST                      = 400;
71 const sal_uInt16 SC_UNAUTHORIZED                     = 401;
72 const sal_uInt16 SC_PAYMENT_REQUIRED                 = 402;
73 const sal_uInt16 SC_FORBIDDEN                        = 403;
74 const sal_uInt16 SC_NOT_FOUND                        = 404;
75 const sal_uInt16 SC_METHOD_NOT_ALLOWED               = 405;
76 const sal_uInt16 SC_NOT_ACCEPTABLE                   = 406;
77 const sal_uInt16 SC_PROXY_AUTHENTICATION_REQUIRED    = 407;
78 const sal_uInt16 SC_REQUEST_TIMEOUT                  = 408;
79 const sal_uInt16 SC_CONFLICT                         = 409;
80 const sal_uInt16 SC_GONE                             = 410;
81 const sal_uInt16 SC_LENGTH_REQUIRED                  = 411;
82 const sal_uInt16 SC_PRECONDITION_FAILED              = 412;
83 const sal_uInt16 SC_REQUEST_ENTITY_TOO_LARGE         = 413;
84 const sal_uInt16 SC_REQUEST_URI_TOO_LONG             = 414;
85 const sal_uInt16 SC_UNSUPPORTED_MEDIA_TYPE           = 415;
86 const sal_uInt16 SC_REQUESTED_RANGE_NOT_SATISFIABLE  = 416;
87 const sal_uInt16 SC_EXPECTATION_FAILED               = 417;
88 // DAV extensions
89 const sal_uInt16 SC_UNPROCESSABLE_ENTITY             = 422;
90 const sal_uInt16 SC_LOCKED                           = 423;
91 const sal_uInt16 SC_FAILED_DEPENDENCY                = 424;
92 
93 //5xx (Server error, general <https://tools.ietf.org/html/rfc7231#section-6.6>)
94 const sal_uInt16 SC_INTERNAL_SERVER_ERROR            = 500;
95 const sal_uInt16 SC_NOT_IMPLEMENTED                  = 501;
96 const sal_uInt16 SC_BAD_GATEWAY                      = 502;
97 const sal_uInt16 SC_SERVICE_UNAVAILABLE              = 503;
98 const sal_uInt16 SC_GATEWAY_TIMEOUT                  = 504;
99 const sal_uInt16 SC_HTTP_VERSION_NOT_SUPPORTED       = 505;
100 // DAV extensions (<https://tools.ietf.org/html/rfc4918#section-11>)
101 const sal_uInt16 SC_INSUFFICIENT_STORAGE             = 507;
102 
103 // unofficial status codes only used internally by LO
104 // used to cache the connection time out event
105 const sal_uInt16 USC_CONNECTION_TIMED_OUT            = 908;
106     // name resolution failed
107 const sal_uInt16 USC_LOOKUP_FAILED                   = 909;
108 const sal_uInt16 USC_AUTH_FAILED                     = 910;
109 const sal_uInt16 USC_AUTHPROXY_FAILED                = 911;
110 
111 
112 
113 class DAVException : public std::exception
114 {
115     public:
116         enum ExceptionCode {
117             DAV_HTTP_ERROR = 0, // Generic error,
118                                 // mData = server error message,
119                                 // mStatusCode = HTTP status code
120             DAV_HTTP_LOOKUP,    // Name lookup failed,
121                                 // mData = server[:port]
122             DAV_HTTP_AUTH,      // User authentication failed on server,
123                                 // mData = server[:port]
124             DAV_HTTP_AUTHPROXY, // User authentication failed on proxy,
125                                 // mData = proxy server[:port]
126             DAV_HTTP_CONNECT,   // Could not connect to server,
127                                 // mData = server[:port]
128             DAV_HTTP_TIMEOUT,   // Connection timed out
129                                 // mData = server[:port]
130             DAV_HTTP_FAILED,    // The precondition failed
131                                 // mData = server[:port]
132             DAV_HTTP_RETRY,     // Retry request
133                                 // mData = server[:port]
134             DAV_HTTP_REDIRECT,  // Request was redirected,
135                                 // mData = new URL
136             DAV_SESSION_CREATE, // session creation error,
137                                 // mData = server[:port]
138             DAV_INVALID_ARG,    // invalid argument
139 
140             DAV_LOCK_EXPIRED,   // DAV lock expired
141 
142             DAV_NOT_LOCKED,     // not locked
143 
144             DAV_LOCKED_SELF,    // locked by this OOo session
145 
146             DAV_LOCKED          // locked by third party
147         };
148 
149     private:
150         ExceptionCode   mExceptionCode;
151         OUString   mData;
152         sal_uInt16      mStatusCode;
153 
154     public:
DAVException(ExceptionCode inExceptionCode)155          explicit DAVException( ExceptionCode inExceptionCode ) :
156             mExceptionCode( inExceptionCode ), mStatusCode( SC_NONE ) {};
DAVException(ExceptionCode inExceptionCode,const OUString & rData)157          DAVException( ExceptionCode inExceptionCode,
158                        const OUString & rData ) :
159             mExceptionCode( inExceptionCode ), mData( rData ),
160             mStatusCode( SC_NONE ) {};
DAVException(ExceptionCode inExceptionCode,const OUString & rData,sal_uInt16 nStatusCode)161          DAVException( ExceptionCode inExceptionCode,
162                        const OUString & rData,
163                        sal_uInt16 nStatusCode ) :
164             mExceptionCode( inExceptionCode ), mData( rData ),
165             mStatusCode( nStatusCode ) {};
166 
getError() const167     const ExceptionCode & getError() const { return mExceptionCode; }
getData() const168     const OUString & getData() const  { return mData; }
getStatus() const169     sal_uInt16 getStatus() const { return mStatusCode; }
170 };
171 
172 } // namespace webdav_ucp
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
175