1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
8 * Copyright (C) 2015 Robin H. Johnson <robin.johnson@dreamhost.com>
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
23 #include "common/ceph_json.h"
27 struct RGWRedirectInfo
31 uint16_t http_redirect_code
= 0;
33 void encode(bufferlist
& bl
) const {
34 ENCODE_START(1, 1, bl
);
37 encode(http_redirect_code
, bl
);
40 void decode(bufferlist::const_iterator
& bl
) {
44 decode(http_redirect_code
, bl
);
48 void dump(Formatter
*f
) const;
49 void decode_json(JSONObj
*obj
);
51 WRITE_CLASS_ENCODER(RGWRedirectInfo
)
54 struct RGWBWRedirectInfo
56 RGWRedirectInfo redirect
;
57 std::string replace_key_prefix_with
;
58 std::string replace_key_with
;
60 void encode(bufferlist
& bl
) const {
61 ENCODE_START(1, 1, bl
);
63 encode(replace_key_prefix_with
, bl
);
64 encode(replace_key_with
, bl
);
67 void decode(bufferlist::const_iterator
& bl
) {
70 decode(replace_key_prefix_with
, bl
);
71 decode(replace_key_with
, bl
);
75 void dump(Formatter
*f
) const;
76 void dump_xml(Formatter
*f
) const;
77 void decode_json(JSONObj
*obj
);
78 void decode_xml(XMLObj
*obj
);
80 WRITE_CLASS_ENCODER(RGWBWRedirectInfo
)
82 struct RGWBWRoutingRuleCondition
84 std::string key_prefix_equals
;
85 uint16_t http_error_code_returned_equals
= 0;
87 void encode(bufferlist
& bl
) const {
88 ENCODE_START(1, 1, bl
);
89 encode(key_prefix_equals
, bl
);
90 encode(http_error_code_returned_equals
, bl
);
93 void decode(bufferlist::const_iterator
& bl
) {
95 decode(key_prefix_equals
, bl
);
96 decode(http_error_code_returned_equals
, bl
);
100 void dump(Formatter
*f
) const;
101 void dump_xml(Formatter
*f
) const;
102 void decode_json(JSONObj
*obj
);
103 void decode_xml(XMLObj
*obj
);
105 bool check_key_condition(const std::string
& key
);
106 bool check_error_code_condition(const int error_code
) {
107 return (uint16_t)error_code
== http_error_code_returned_equals
;
110 WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition
)
112 struct RGWBWRoutingRule
114 RGWBWRoutingRuleCondition condition
;
115 RGWBWRedirectInfo redirect_info
;
117 void encode(bufferlist
& bl
) const {
118 ENCODE_START(1, 1, bl
);
119 encode(condition
, bl
);
120 encode(redirect_info
, bl
);
123 void decode(bufferlist::const_iterator
& bl
) {
125 decode(condition
, bl
);
126 decode(redirect_info
, bl
);
130 void dump(Formatter
*f
) const;
131 void dump_xml(Formatter
*f
) const;
132 void decode_json(JSONObj
*obj
);
133 void decode_xml(XMLObj
*obj
);
135 bool check_key_condition(const std::string
& key
) {
136 return condition
.check_key_condition(key
);
138 bool check_error_code_condition(int error_code
) {
139 return condition
.check_error_code_condition(error_code
);
142 void apply_rule(const std::string
& default_protocol
,
143 const std::string
& default_hostname
,
144 const std::string
& key
,
145 std::string
*redirect
,
148 WRITE_CLASS_ENCODER(RGWBWRoutingRule
)
150 struct RGWBWRoutingRules
152 std::list
<RGWBWRoutingRule
> rules
;
154 void encode(bufferlist
& bl
) const {
155 ENCODE_START(1, 1, bl
);
159 void decode(bufferlist::const_iterator
& bl
) {
165 void dump(Formatter
*f
) const;
166 void dump_xml(Formatter
*f
) const;
167 void decode_json(JSONObj
*obj
);
169 bool check_key_condition(const std::string
& key
, RGWBWRoutingRule
**rule
);
170 bool check_error_code_condition(int error_code
, RGWBWRoutingRule
**rule
);
171 bool check_key_and_error_code_condition(const std::string
& key
,
172 const int error_code
,
173 RGWBWRoutingRule
**rule
);
175 WRITE_CLASS_ENCODER(RGWBWRoutingRules
)
177 struct RGWBucketWebsiteConf
179 RGWRedirectInfo redirect_all
;
180 std::string index_doc_suffix
;
181 std::string error_doc
;
182 std::string subdir_marker
;
183 std::string listing_css_doc
;
184 bool listing_enabled
;
185 bool is_redirect_all
;
186 bool is_set_index_doc
;
187 RGWBWRoutingRules routing_rules
;
189 RGWBucketWebsiteConf()
190 : listing_enabled(false) {
191 is_redirect_all
= false;
192 is_set_index_doc
= false;
195 void encode(bufferlist
& bl
) const {
196 ENCODE_START(2, 1, bl
);
197 encode(index_doc_suffix
, bl
);
198 encode(error_doc
, bl
);
199 encode(routing_rules
, bl
);
200 encode(redirect_all
, bl
);
201 encode(subdir_marker
, bl
);
202 encode(listing_css_doc
, bl
);
203 encode(listing_enabled
, bl
);
206 void decode(bufferlist::const_iterator
& bl
) {
208 decode(index_doc_suffix
, bl
);
209 decode(error_doc
, bl
);
210 decode(routing_rules
, bl
);
211 decode(redirect_all
, bl
);
213 decode(subdir_marker
, bl
);
214 decode(listing_css_doc
, bl
);
215 decode(listing_enabled
, bl
);
220 void dump(Formatter
*f
) const;
221 void decode_json(JSONObj
*obj
);
222 void decode_xml(XMLObj
*obj
);
223 void dump_xml(Formatter
*f
) const;
225 bool should_redirect(const std::string
& key
,
226 const int http_error_code
,
227 RGWBWRoutingRule
*redirect
);
229 bool get_effective_key(const std::string
& key
,
230 std::string
*effective_key
, bool is_file
) const;
232 const std::string
& get_index_doc() const {
233 return index_doc_suffix
;
236 bool is_empty() const {
237 return index_doc_suffix
.empty() &&
239 subdir_marker
.empty() &&
240 listing_css_doc
.empty() &&
244 WRITE_CLASS_ENCODER(RGWBucketWebsiteConf
)