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.
23 struct RGWRedirectInfo
27 uint16_t http_redirect_code
= 0;
29 void encode(bufferlist
& bl
) const {
30 ENCODE_START(1, 1, bl
);
31 ::encode(protocol
, bl
);
32 ::encode(hostname
, bl
);
33 ::encode(http_redirect_code
, bl
);
36 void decode(bufferlist::iterator
& bl
) {
38 ::decode(protocol
, bl
);
39 ::decode(hostname
, bl
);
40 ::decode(http_redirect_code
, bl
);
44 void dump(Formatter
*f
) const;
45 void decode_json(JSONObj
*obj
);
47 WRITE_CLASS_ENCODER(RGWRedirectInfo
)
50 struct RGWBWRedirectInfo
52 RGWRedirectInfo redirect
;
53 std::string replace_key_prefix_with
;
54 std::string replace_key_with
;
56 void encode(bufferlist
& bl
) const {
57 ENCODE_START(1, 1, bl
);
58 ::encode(redirect
, bl
);
59 ::encode(replace_key_prefix_with
, bl
);
60 ::encode(replace_key_with
, bl
);
63 void decode(bufferlist::iterator
& bl
) {
65 ::decode(redirect
, bl
);
66 ::decode(replace_key_prefix_with
, bl
);
67 ::decode(replace_key_with
, bl
);
71 void dump(Formatter
*f
) const;
72 void dump_xml(Formatter
*f
) const;
73 void decode_json(JSONObj
*obj
);
74 void decode_xml(XMLObj
*obj
);
76 WRITE_CLASS_ENCODER(RGWBWRedirectInfo
)
78 struct RGWBWRoutingRuleCondition
80 std::string key_prefix_equals
;
81 uint16_t http_error_code_returned_equals
;
83 void encode(bufferlist
& bl
) const {
84 ENCODE_START(1, 1, bl
);
85 ::encode(key_prefix_equals
, bl
);
86 ::encode(http_error_code_returned_equals
, bl
);
89 void decode(bufferlist::iterator
& bl
) {
91 ::decode(key_prefix_equals
, bl
);
92 ::decode(http_error_code_returned_equals
, bl
);
96 void dump(Formatter
*f
) const;
97 void dump_xml(Formatter
*f
) const;
98 void decode_json(JSONObj
*obj
);
99 void decode_xml(XMLObj
*obj
);
101 bool check_key_condition(const std::string
& key
);
102 bool check_error_code_condition(const int error_code
) {
103 return (uint16_t)error_code
== http_error_code_returned_equals
;
106 WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition
)
108 struct RGWBWRoutingRule
110 RGWBWRoutingRuleCondition condition
;
111 RGWBWRedirectInfo redirect_info
;
113 void encode(bufferlist
& bl
) const {
114 ENCODE_START(1, 1, bl
);
115 ::encode(condition
, bl
);
116 ::encode(redirect_info
, bl
);
119 void decode(bufferlist::iterator
& bl
) {
121 ::decode(condition
, bl
);
122 ::decode(redirect_info
, bl
);
126 void dump(Formatter
*f
) const;
127 void dump_xml(Formatter
*f
) const;
128 void decode_json(JSONObj
*obj
);
129 void decode_xml(XMLObj
*obj
);
131 bool check_key_condition(const std::string
& key
) {
132 return condition
.check_key_condition(key
);
134 bool check_error_code_condition(int error_code
) {
135 return condition
.check_error_code_condition(error_code
);
138 void apply_rule(const std::string
& default_protocol
,
139 const std::string
& default_hostname
,
140 const std::string
& key
,
141 std::string
*redirect
,
144 WRITE_CLASS_ENCODER(RGWBWRoutingRule
)
146 struct RGWBWRoutingRules
148 std::list
<RGWBWRoutingRule
> rules
;
150 void encode(bufferlist
& bl
) const {
151 ENCODE_START(1, 1, bl
);
155 void decode(bufferlist::iterator
& bl
) {
161 void dump(Formatter
*f
) const;
162 void dump_xml(Formatter
*f
) const;
163 void decode_json(JSONObj
*obj
);
165 bool check_key_condition(const std::string
& key
, RGWBWRoutingRule
**rule
);
166 bool check_error_code_condition(int error_code
, RGWBWRoutingRule
**rule
);
167 bool check_key_and_error_code_condition(const std::string
& key
,
168 const int error_code
,
169 RGWBWRoutingRule
**rule
);
171 WRITE_CLASS_ENCODER(RGWBWRoutingRules
)
173 struct RGWBucketWebsiteConf
175 RGWRedirectInfo redirect_all
;
176 std::string index_doc_suffix
;
177 std::string error_doc
;
178 std::string subdir_marker
;
179 std::string listing_css_doc
;
180 bool listing_enabled
;
181 RGWBWRoutingRules routing_rules
;
183 RGWBucketWebsiteConf()
184 : listing_enabled(false) {
187 void encode(bufferlist
& bl
) const {
188 ENCODE_START(2, 1, bl
);
189 ::encode(index_doc_suffix
, bl
);
190 ::encode(error_doc
, bl
);
191 ::encode(routing_rules
, bl
);
192 ::encode(redirect_all
, bl
);
193 ::encode(subdir_marker
, bl
);
194 ::encode(listing_css_doc
, bl
);
195 ::encode(listing_enabled
, bl
);
198 void decode(bufferlist::iterator
& bl
) {
200 ::decode(index_doc_suffix
, bl
);
201 ::decode(error_doc
, bl
);
202 ::decode(routing_rules
, bl
);
203 ::decode(redirect_all
, bl
);
205 ::decode(subdir_marker
, bl
);
206 ::decode(listing_css_doc
, bl
);
207 ::decode(listing_enabled
, bl
);
212 void dump(Formatter
*f
) const;
213 void decode_json(JSONObj
*obj
);
214 void decode_xml(XMLObj
*obj
);
215 void dump_xml(Formatter
*f
) const;
217 bool should_redirect(const std::string
& key
,
218 const int http_error_code
,
219 RGWBWRoutingRule
*redirect
);
221 void get_effective_key(const std::string
& key
,
222 std::string
*effective_key
, bool is_file
) const;
224 const std::string
& get_index_doc() const {
225 return index_doc_suffix
;
228 bool is_empty() const {
229 return index_doc_suffix
.empty() &&
231 subdir_marker
.empty() &&
232 listing_css_doc
.empty() &&
236 WRITE_CLASS_ENCODER(RGWBucketWebsiteConf
)