]>
Commit | Line | Data |
---|---|---|
1e59de90 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
7c673cae FG |
4 | /* |
5 | * Ceph - scalable distributed file system | |
6 | * | |
7 | * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com> | |
8 | * Copyright (C) 2015 Robin H. Johnson <robin.johnson@dreamhost.com> | |
9 | * | |
10 | * This is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU Lesser General Public | |
1e59de90 | 12 | * License version 2.1, as published by the Free Software |
7c673cae | 13 | * Foundation. See file COPYING. |
1e59de90 | 14 | * |
7c673cae | 15 | */ |
11fdf7f2 | 16 | |
1e59de90 | 17 | #pragma once |
7c673cae | 18 | |
c07f9fc5 FG |
19 | #include <list> |
20 | #include <string> | |
21 | ||
11fdf7f2 TL |
22 | #include "common/ceph_json.h" |
23 | ||
7c673cae FG |
24 | #include "rgw_xml.h" |
25 | ||
26 | struct RGWRedirectInfo | |
27 | { | |
c07f9fc5 FG |
28 | std::string protocol; |
29 | std::string hostname; | |
30 | uint16_t http_redirect_code = 0; | |
7c673cae FG |
31 | |
32 | void encode(bufferlist& bl) const { | |
33 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
34 | encode(protocol, bl); |
35 | encode(hostname, bl); | |
36 | encode(http_redirect_code, bl); | |
7c673cae FG |
37 | ENCODE_FINISH(bl); |
38 | } | |
11fdf7f2 | 39 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 40 | DECODE_START(1, bl); |
11fdf7f2 TL |
41 | decode(protocol, bl); |
42 | decode(hostname, bl); | |
43 | decode(http_redirect_code, bl); | |
7c673cae FG |
44 | DECODE_FINISH(bl); |
45 | } | |
46 | ||
47 | void dump(Formatter *f) const; | |
48 | void decode_json(JSONObj *obj); | |
49 | }; | |
50 | WRITE_CLASS_ENCODER(RGWRedirectInfo) | |
51 | ||
52 | ||
53 | struct RGWBWRedirectInfo | |
54 | { | |
55 | RGWRedirectInfo redirect; | |
c07f9fc5 FG |
56 | std::string replace_key_prefix_with; |
57 | std::string replace_key_with; | |
7c673cae FG |
58 | |
59 | void encode(bufferlist& bl) const { | |
60 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
61 | encode(redirect, bl); |
62 | encode(replace_key_prefix_with, bl); | |
63 | encode(replace_key_with, bl); | |
7c673cae FG |
64 | ENCODE_FINISH(bl); |
65 | } | |
11fdf7f2 | 66 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 67 | DECODE_START(1, bl); |
11fdf7f2 TL |
68 | decode(redirect, bl); |
69 | decode(replace_key_prefix_with, bl); | |
70 | decode(replace_key_with, bl); | |
7c673cae FG |
71 | DECODE_FINISH(bl); |
72 | } | |
73 | ||
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); | |
78 | }; | |
79 | WRITE_CLASS_ENCODER(RGWBWRedirectInfo) | |
80 | ||
81 | struct RGWBWRoutingRuleCondition | |
82 | { | |
c07f9fc5 | 83 | std::string key_prefix_equals; |
11fdf7f2 | 84 | uint16_t http_error_code_returned_equals = 0; |
7c673cae FG |
85 | |
86 | void encode(bufferlist& bl) const { | |
87 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
88 | encode(key_prefix_equals, bl); |
89 | encode(http_error_code_returned_equals, bl); | |
7c673cae FG |
90 | ENCODE_FINISH(bl); |
91 | } | |
11fdf7f2 | 92 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 93 | DECODE_START(1, bl); |
11fdf7f2 TL |
94 | decode(key_prefix_equals, bl); |
95 | decode(http_error_code_returned_equals, bl); | |
7c673cae FG |
96 | DECODE_FINISH(bl); |
97 | } | |
98 | ||
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); | |
103 | ||
c07f9fc5 | 104 | bool check_key_condition(const std::string& key); |
7c673cae FG |
105 | bool check_error_code_condition(const int error_code) { |
106 | return (uint16_t)error_code == http_error_code_returned_equals; | |
107 | } | |
108 | }; | |
109 | WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition) | |
110 | ||
111 | struct RGWBWRoutingRule | |
112 | { | |
113 | RGWBWRoutingRuleCondition condition; | |
114 | RGWBWRedirectInfo redirect_info; | |
115 | ||
116 | void encode(bufferlist& bl) const { | |
117 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
118 | encode(condition, bl); |
119 | encode(redirect_info, bl); | |
7c673cae FG |
120 | ENCODE_FINISH(bl); |
121 | } | |
11fdf7f2 | 122 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 123 | DECODE_START(1, bl); |
11fdf7f2 TL |
124 | decode(condition, bl); |
125 | decode(redirect_info, bl); | |
7c673cae FG |
126 | DECODE_FINISH(bl); |
127 | } | |
128 | ||
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); | |
133 | ||
c07f9fc5 | 134 | bool check_key_condition(const std::string& key) { |
7c673cae FG |
135 | return condition.check_key_condition(key); |
136 | } | |
137 | bool check_error_code_condition(int error_code) { | |
138 | return condition.check_error_code_condition(error_code); | |
139 | } | |
140 | ||
c07f9fc5 FG |
141 | void apply_rule(const std::string& default_protocol, |
142 | const std::string& default_hostname, | |
143 | const std::string& key, | |
144 | std::string *redirect, | |
145 | int *redirect_code); | |
7c673cae FG |
146 | }; |
147 | WRITE_CLASS_ENCODER(RGWBWRoutingRule) | |
148 | ||
149 | struct RGWBWRoutingRules | |
150 | { | |
c07f9fc5 | 151 | std::list<RGWBWRoutingRule> rules; |
7c673cae FG |
152 | |
153 | void encode(bufferlist& bl) const { | |
154 | ENCODE_START(1, 1, bl); | |
11fdf7f2 | 155 | encode(rules, bl); |
7c673cae FG |
156 | ENCODE_FINISH(bl); |
157 | } | |
11fdf7f2 | 158 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 159 | DECODE_START(1, bl); |
11fdf7f2 | 160 | decode(rules, bl); |
7c673cae FG |
161 | DECODE_FINISH(bl); |
162 | } | |
163 | ||
164 | void dump(Formatter *f) const; | |
165 | void dump_xml(Formatter *f) const; | |
166 | void decode_json(JSONObj *obj); | |
167 | ||
c07f9fc5 | 168 | bool check_key_condition(const std::string& key, RGWBWRoutingRule **rule); |
7c673cae | 169 | bool check_error_code_condition(int error_code, RGWBWRoutingRule **rule); |
c07f9fc5 FG |
170 | bool check_key_and_error_code_condition(const std::string& key, |
171 | const int error_code, | |
172 | RGWBWRoutingRule **rule); | |
7c673cae FG |
173 | }; |
174 | WRITE_CLASS_ENCODER(RGWBWRoutingRules) | |
175 | ||
176 | struct RGWBucketWebsiteConf | |
177 | { | |
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; | |
eafe8130 TL |
184 | bool is_redirect_all; |
185 | bool is_set_index_doc; | |
7c673cae FG |
186 | RGWBWRoutingRules routing_rules; |
187 | ||
188 | RGWBucketWebsiteConf() | |
189 | : listing_enabled(false) { | |
eafe8130 TL |
190 | is_redirect_all = false; |
191 | is_set_index_doc = false; | |
7c673cae FG |
192 | } |
193 | ||
194 | void encode(bufferlist& bl) const { | |
195 | ENCODE_START(2, 1, bl); | |
11fdf7f2 TL |
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); | |
7c673cae FG |
203 | ENCODE_FINISH(bl); |
204 | } | |
11fdf7f2 | 205 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 206 | DECODE_START(2, bl); |
11fdf7f2 TL |
207 | decode(index_doc_suffix, bl); |
208 | decode(error_doc, bl); | |
209 | decode(routing_rules, bl); | |
210 | decode(redirect_all, bl); | |
7c673cae | 211 | if (struct_v >= 2) { |
11fdf7f2 TL |
212 | decode(subdir_marker, bl); |
213 | decode(listing_css_doc, bl); | |
214 | decode(listing_enabled, bl); | |
7c673cae FG |
215 | } |
216 | DECODE_FINISH(bl); | |
217 | } | |
218 | ||
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; | |
223 | ||
224 | bool should_redirect(const std::string& key, | |
225 | const int http_error_code, | |
226 | RGWBWRoutingRule *redirect); | |
227 | ||
eafe8130 | 228 | bool get_effective_key(const std::string& key, |
224ce89b | 229 | std::string *effective_key, bool is_file) const; |
7c673cae FG |
230 | |
231 | const std::string& get_index_doc() const { | |
232 | return index_doc_suffix; | |
233 | } | |
234 | ||
235 | bool is_empty() const { | |
236 | return index_doc_suffix.empty() && | |
237 | error_doc.empty() && | |
238 | subdir_marker.empty() && | |
239 | listing_css_doc.empty() && | |
240 | ! listing_enabled; | |
241 | } | |
242 | }; | |
243 | WRITE_CLASS_ENCODER(RGWBucketWebsiteConf) |