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.
22 #include "common/ceph_json.h"
26 struct RGWRedirectInfo
30 uint16_t http_redirect_code
= 0;
32 void encode(bufferlist
& bl
) const {
33 ENCODE_START(1, 1, bl
);
36 encode(http_redirect_code
, bl
);
39 void decode(bufferlist::const_iterator
& bl
) {
43 decode(http_redirect_code
, bl
);
47 void dump(Formatter
*f
) const;
48 void decode_json(JSONObj
*obj
);
50 WRITE_CLASS_ENCODER(RGWRedirectInfo
)
53 struct RGWBWRedirectInfo
55 RGWRedirectInfo redirect
;
56 std::string replace_key_prefix_with
;
57 std::string replace_key_with
;
59 void encode(bufferlist
& bl
) const {
60 ENCODE_START(1, 1, bl
);
62 encode(replace_key_prefix_with
, bl
);
63 encode(replace_key_with
, bl
);
66 void decode(bufferlist::const_iterator
& bl
) {
69 decode(replace_key_prefix_with
, bl
);
70 decode(replace_key_with
, bl
);
74 void dump(Formatter
*f
) const;
75 void dump_xml(Formatter
*f
) const;
76 void decode_json(JSONObj
*obj
);
77 void decode_xml(XMLObj
*obj
);
79 WRITE_CLASS_ENCODER(RGWBWRedirectInfo
)
81 struct RGWBWRoutingRuleCondition
83 std::string key_prefix_equals
;
84 uint16_t http_error_code_returned_equals
= 0;
86 void encode(bufferlist
& bl
) const {
87 ENCODE_START(1, 1, bl
);
88 encode(key_prefix_equals
, bl
);
89 encode(http_error_code_returned_equals
, bl
);
92 void decode(bufferlist::const_iterator
& bl
) {
94 decode(key_prefix_equals
, bl
);
95 decode(http_error_code_returned_equals
, bl
);
99 void dump(Formatter
*f
) const;
100 void dump_xml(Formatter
*f
) const;
101 void decode_json(JSONObj
*obj
);
102 void decode_xml(XMLObj
*obj
);
104 bool check_key_condition(const std::string
& key
);
105 bool check_error_code_condition(const int error_code
) {
106 return (uint16_t)error_code
== http_error_code_returned_equals
;
109 WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition
)
111 struct RGWBWRoutingRule
113 RGWBWRoutingRuleCondition condition
;
114 RGWBWRedirectInfo redirect_info
;
116 void encode(bufferlist
& bl
) const {
117 ENCODE_START(1, 1, bl
);
118 encode(condition
, bl
);
119 encode(redirect_info
, bl
);
122 void decode(bufferlist::const_iterator
& bl
) {
124 decode(condition
, bl
);
125 decode(redirect_info
, bl
);
129 void dump(Formatter
*f
) const;
130 void dump_xml(Formatter
*f
) const;
131 void decode_json(JSONObj
*obj
);
132 void decode_xml(XMLObj
*obj
);
134 bool check_key_condition(const std::string
& key
) {
135 return condition
.check_key_condition(key
);
137 bool check_error_code_condition(int error_code
) {
138 return condition
.check_error_code_condition(error_code
);
141 void apply_rule(const std::string
& default_protocol
,
142 const std::string
& default_hostname
,
143 const std::string
& key
,
144 std::string
*redirect
,
147 WRITE_CLASS_ENCODER(RGWBWRoutingRule
)
149 struct RGWBWRoutingRules
151 std::list
<RGWBWRoutingRule
> rules
;
153 void encode(bufferlist
& bl
) const {
154 ENCODE_START(1, 1, bl
);
158 void decode(bufferlist::const_iterator
& bl
) {
164 void dump(Formatter
*f
) const;
165 void dump_xml(Formatter
*f
) const;
166 void decode_json(JSONObj
*obj
);
168 bool check_key_condition(const std::string
& key
, RGWBWRoutingRule
**rule
);
169 bool check_error_code_condition(int error_code
, RGWBWRoutingRule
**rule
);
170 bool check_key_and_error_code_condition(const std::string
& key
,
171 const int error_code
,
172 RGWBWRoutingRule
**rule
);
174 WRITE_CLASS_ENCODER(RGWBWRoutingRules
)
176 struct RGWBucketWebsiteConf
178 RGWRedirectInfo redirect_all
;
179 std::string index_doc_suffix
;
180 std::string error_doc
;
181 std::string subdir_marker
;
182 std::string listing_css_doc
;
183 bool listing_enabled
;
184 bool is_redirect_all
;
185 bool is_set_index_doc
;
186 RGWBWRoutingRules routing_rules
;
188 RGWBucketWebsiteConf()
189 : listing_enabled(false) {
190 is_redirect_all
= false;
191 is_set_index_doc
= false;
194 void encode(bufferlist
& bl
) const {
195 ENCODE_START(2, 1, bl
);
196 encode(index_doc_suffix
, bl
);
197 encode(error_doc
, bl
);
198 encode(routing_rules
, bl
);
199 encode(redirect_all
, bl
);
200 encode(subdir_marker
, bl
);
201 encode(listing_css_doc
, bl
);
202 encode(listing_enabled
, bl
);
205 void decode(bufferlist::const_iterator
& bl
) {
207 decode(index_doc_suffix
, bl
);
208 decode(error_doc
, bl
);
209 decode(routing_rules
, bl
);
210 decode(redirect_all
, bl
);
212 decode(subdir_marker
, bl
);
213 decode(listing_css_doc
, bl
);
214 decode(listing_enabled
, bl
);
219 void dump(Formatter
*f
) const;
220 void decode_json(JSONObj
*obj
);
221 void decode_xml(XMLObj
*obj
);
222 void dump_xml(Formatter
*f
) const;
224 bool should_redirect(const std::string
& key
,
225 const int http_error_code
,
226 RGWBWRoutingRule
*redirect
);
228 bool get_effective_key(const std::string
& key
,
229 std::string
*effective_key
, bool is_file
) const;
231 const std::string
& get_index_doc() const {
232 return index_doc_suffix
;
235 bool is_empty() const {
236 return index_doc_suffix
.empty() &&
238 subdir_marker
.empty() &&
239 listing_css_doc
.empty() &&
243 WRITE_CLASS_ENCODER(RGWBucketWebsiteConf
)