1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
7 * Copyright (C) 2015 Robin H. Johnson <robin.johnson@dreamhost.com>
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
20 struct RGWRedirectInfo
24 uint16_t http_redirect_code
;
26 void encode(bufferlist
& bl
) const {
27 ENCODE_START(1, 1, bl
);
28 ::encode(protocol
, bl
);
29 ::encode(hostname
, bl
);
30 ::encode(http_redirect_code
, bl
);
33 void decode(bufferlist::iterator
& bl
) {
35 ::decode(protocol
, bl
);
36 ::decode(hostname
, bl
);
37 ::decode(http_redirect_code
, bl
);
41 void dump(Formatter
*f
) const;
42 void decode_json(JSONObj
*obj
);
44 WRITE_CLASS_ENCODER(RGWRedirectInfo
)
47 struct RGWBWRedirectInfo
49 RGWRedirectInfo redirect
;
50 string replace_key_prefix_with
;
51 string replace_key_with
;
53 void encode(bufferlist
& bl
) const {
54 ENCODE_START(1, 1, bl
);
55 ::encode(redirect
, bl
);
56 ::encode(replace_key_prefix_with
, bl
);
57 ::encode(replace_key_with
, bl
);
60 void decode(bufferlist::iterator
& bl
) {
62 ::decode(redirect
, bl
);
63 ::decode(replace_key_prefix_with
, bl
);
64 ::decode(replace_key_with
, bl
);
68 void dump(Formatter
*f
) const;
69 void dump_xml(Formatter
*f
) const;
70 void decode_json(JSONObj
*obj
);
71 void decode_xml(XMLObj
*obj
);
73 WRITE_CLASS_ENCODER(RGWBWRedirectInfo
)
75 struct RGWBWRoutingRuleCondition
77 string key_prefix_equals
;
78 uint16_t http_error_code_returned_equals
;
80 void encode(bufferlist
& bl
) const {
81 ENCODE_START(1, 1, bl
);
82 ::encode(key_prefix_equals
, bl
);
83 ::encode(http_error_code_returned_equals
, bl
);
86 void decode(bufferlist::iterator
& bl
) {
88 ::decode(key_prefix_equals
, bl
);
89 ::decode(http_error_code_returned_equals
, bl
);
93 void dump(Formatter
*f
) const;
94 void dump_xml(Formatter
*f
) const;
95 void decode_json(JSONObj
*obj
);
96 void decode_xml(XMLObj
*obj
);
98 bool check_key_condition(const string
& key
);
99 bool check_error_code_condition(const int error_code
) {
100 return (uint16_t)error_code
== http_error_code_returned_equals
;
103 WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition
)
105 struct RGWBWRoutingRule
107 RGWBWRoutingRuleCondition condition
;
108 RGWBWRedirectInfo redirect_info
;
110 void encode(bufferlist
& bl
) const {
111 ENCODE_START(1, 1, bl
);
112 ::encode(condition
, bl
);
113 ::encode(redirect_info
, bl
);
116 void decode(bufferlist::iterator
& bl
) {
118 ::decode(condition
, bl
);
119 ::decode(redirect_info
, bl
);
123 void dump(Formatter
*f
) const;
124 void dump_xml(Formatter
*f
) const;
125 void decode_json(JSONObj
*obj
);
126 void decode_xml(XMLObj
*obj
);
128 bool check_key_condition(const string
& key
) {
129 return condition
.check_key_condition(key
);
131 bool check_error_code_condition(int error_code
) {
132 return condition
.check_error_code_condition(error_code
);
135 void apply_rule(const string
& default_protocol
, const string
& default_hostname
, const string
& key
, string
*redirect
, int *redirect_code
);
137 WRITE_CLASS_ENCODER(RGWBWRoutingRule
)
139 struct RGWBWRoutingRules
141 list
<RGWBWRoutingRule
> rules
;
143 void encode(bufferlist
& bl
) const {
144 ENCODE_START(1, 1, bl
);
148 void decode(bufferlist::iterator
& bl
) {
154 void dump(Formatter
*f
) const;
155 void dump_xml(Formatter
*f
) const;
156 void decode_json(JSONObj
*obj
);
158 bool check_key_condition(const string
& key
, RGWBWRoutingRule
**rule
);
159 bool check_error_code_condition(int error_code
, RGWBWRoutingRule
**rule
);
160 bool check_key_and_error_code_condition(const string
& key
, const int error_code
, RGWBWRoutingRule
**rule
);
162 WRITE_CLASS_ENCODER(RGWBWRoutingRules
)
164 struct RGWBucketWebsiteConf
166 RGWRedirectInfo redirect_all
;
167 std::string index_doc_suffix
;
168 std::string error_doc
;
169 std::string subdir_marker
;
170 std::string listing_css_doc
;
171 bool listing_enabled
;
172 RGWBWRoutingRules routing_rules
;
174 RGWBucketWebsiteConf()
175 : listing_enabled(false) {
178 void encode(bufferlist
& bl
) const {
179 ENCODE_START(2, 1, bl
);
180 ::encode(index_doc_suffix
, bl
);
181 ::encode(error_doc
, bl
);
182 ::encode(routing_rules
, bl
);
183 ::encode(redirect_all
, bl
);
184 ::encode(subdir_marker
, bl
);
185 ::encode(listing_css_doc
, bl
);
186 ::encode(listing_enabled
, bl
);
189 void decode(bufferlist::iterator
& bl
) {
191 ::decode(index_doc_suffix
, bl
);
192 ::decode(error_doc
, bl
);
193 ::decode(routing_rules
, bl
);
194 ::decode(redirect_all
, bl
);
196 ::decode(subdir_marker
, bl
);
197 ::decode(listing_css_doc
, bl
);
198 ::decode(listing_enabled
, bl
);
203 void dump(Formatter
*f
) const;
204 void decode_json(JSONObj
*obj
);
205 void decode_xml(XMLObj
*obj
);
206 void dump_xml(Formatter
*f
) const;
208 bool should_redirect(const std::string
& key
,
209 const int http_error_code
,
210 RGWBWRoutingRule
*redirect
);
212 void get_effective_key(const std::string
& key
,
213 std::string
*effective_key
, bool is_file
) const;
215 const std::string
& get_index_doc() const {
216 return index_doc_suffix
;
219 bool is_empty() const {
220 return index_doc_suffix
.empty() &&
222 subdir_marker
.empty() &&
223 listing_css_doc
.empty() &&
227 WRITE_CLASS_ENCODER(RGWBucketWebsiteConf
)