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