]>
Commit | Line | Data |
---|---|---|
7c673cae | 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 | |
12 | * License version 2.1, as published by the Free Software | |
13 | * Foundation. See file COPYING. | |
14 | * | |
15 | */ | |
11fdf7f2 | 16 | |
7c673cae FG |
17 | #ifndef RGW_WEBSITE_H |
18 | #define RGW_WEBSITE_H | |
19 | ||
c07f9fc5 FG |
20 | #include <list> |
21 | #include <string> | |
22 | ||
11fdf7f2 TL |
23 | #include "common/ceph_json.h" |
24 | ||
7c673cae FG |
25 | #include "rgw_xml.h" |
26 | ||
27 | struct RGWRedirectInfo | |
28 | { | |
c07f9fc5 FG |
29 | std::string protocol; |
30 | std::string hostname; | |
31 | uint16_t http_redirect_code = 0; | |
7c673cae FG |
32 | |
33 | void encode(bufferlist& bl) const { | |
34 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
35 | encode(protocol, bl); |
36 | encode(hostname, bl); | |
37 | encode(http_redirect_code, bl); | |
7c673cae FG |
38 | ENCODE_FINISH(bl); |
39 | } | |
11fdf7f2 | 40 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 41 | DECODE_START(1, bl); |
11fdf7f2 TL |
42 | decode(protocol, bl); |
43 | decode(hostname, bl); | |
44 | decode(http_redirect_code, bl); | |
7c673cae FG |
45 | DECODE_FINISH(bl); |
46 | } | |
47 | ||
48 | void dump(Formatter *f) const; | |
49 | void decode_json(JSONObj *obj); | |
50 | }; | |
51 | WRITE_CLASS_ENCODER(RGWRedirectInfo) | |
52 | ||
53 | ||
54 | struct RGWBWRedirectInfo | |
55 | { | |
56 | RGWRedirectInfo redirect; | |
c07f9fc5 FG |
57 | std::string replace_key_prefix_with; |
58 | std::string replace_key_with; | |
7c673cae FG |
59 | |
60 | void encode(bufferlist& bl) const { | |
61 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
62 | encode(redirect, bl); |
63 | encode(replace_key_prefix_with, bl); | |
64 | encode(replace_key_with, bl); | |
7c673cae FG |
65 | ENCODE_FINISH(bl); |
66 | } | |
11fdf7f2 | 67 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 68 | DECODE_START(1, bl); |
11fdf7f2 TL |
69 | decode(redirect, bl); |
70 | decode(replace_key_prefix_with, bl); | |
71 | decode(replace_key_with, bl); | |
7c673cae FG |
72 | DECODE_FINISH(bl); |
73 | } | |
74 | ||
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); | |
79 | }; | |
80 | WRITE_CLASS_ENCODER(RGWBWRedirectInfo) | |
81 | ||
82 | struct RGWBWRoutingRuleCondition | |
83 | { | |
c07f9fc5 | 84 | std::string key_prefix_equals; |
11fdf7f2 | 85 | uint16_t http_error_code_returned_equals = 0; |
7c673cae FG |
86 | |
87 | void encode(bufferlist& bl) const { | |
88 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
89 | encode(key_prefix_equals, bl); |
90 | encode(http_error_code_returned_equals, bl); | |
7c673cae FG |
91 | ENCODE_FINISH(bl); |
92 | } | |
11fdf7f2 | 93 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 94 | DECODE_START(1, bl); |
11fdf7f2 TL |
95 | decode(key_prefix_equals, bl); |
96 | decode(http_error_code_returned_equals, bl); | |
7c673cae FG |
97 | DECODE_FINISH(bl); |
98 | } | |
99 | ||
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); | |
104 | ||
c07f9fc5 | 105 | bool check_key_condition(const std::string& key); |
7c673cae FG |
106 | bool check_error_code_condition(const int error_code) { |
107 | return (uint16_t)error_code == http_error_code_returned_equals; | |
108 | } | |
109 | }; | |
110 | WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition) | |
111 | ||
112 | struct RGWBWRoutingRule | |
113 | { | |
114 | RGWBWRoutingRuleCondition condition; | |
115 | RGWBWRedirectInfo redirect_info; | |
116 | ||
117 | void encode(bufferlist& bl) const { | |
118 | ENCODE_START(1, 1, bl); | |
11fdf7f2 TL |
119 | encode(condition, bl); |
120 | encode(redirect_info, bl); | |
7c673cae FG |
121 | ENCODE_FINISH(bl); |
122 | } | |
11fdf7f2 | 123 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 124 | DECODE_START(1, bl); |
11fdf7f2 TL |
125 | decode(condition, bl); |
126 | decode(redirect_info, bl); | |
7c673cae FG |
127 | DECODE_FINISH(bl); |
128 | } | |
129 | ||
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); | |
134 | ||
c07f9fc5 | 135 | bool check_key_condition(const std::string& key) { |
7c673cae FG |
136 | return condition.check_key_condition(key); |
137 | } | |
138 | bool check_error_code_condition(int error_code) { | |
139 | return condition.check_error_code_condition(error_code); | |
140 | } | |
141 | ||
c07f9fc5 FG |
142 | void apply_rule(const std::string& default_protocol, |
143 | const std::string& default_hostname, | |
144 | const std::string& key, | |
145 | std::string *redirect, | |
146 | int *redirect_code); | |
7c673cae FG |
147 | }; |
148 | WRITE_CLASS_ENCODER(RGWBWRoutingRule) | |
149 | ||
150 | struct RGWBWRoutingRules | |
151 | { | |
c07f9fc5 | 152 | std::list<RGWBWRoutingRule> rules; |
7c673cae FG |
153 | |
154 | void encode(bufferlist& bl) const { | |
155 | ENCODE_START(1, 1, bl); | |
11fdf7f2 | 156 | encode(rules, bl); |
7c673cae FG |
157 | ENCODE_FINISH(bl); |
158 | } | |
11fdf7f2 | 159 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 160 | DECODE_START(1, bl); |
11fdf7f2 | 161 | decode(rules, bl); |
7c673cae FG |
162 | DECODE_FINISH(bl); |
163 | } | |
164 | ||
165 | void dump(Formatter *f) const; | |
166 | void dump_xml(Formatter *f) const; | |
167 | void decode_json(JSONObj *obj); | |
168 | ||
c07f9fc5 | 169 | bool check_key_condition(const std::string& key, RGWBWRoutingRule **rule); |
7c673cae | 170 | bool check_error_code_condition(int error_code, RGWBWRoutingRule **rule); |
c07f9fc5 FG |
171 | bool check_key_and_error_code_condition(const std::string& key, |
172 | const int error_code, | |
173 | RGWBWRoutingRule **rule); | |
7c673cae FG |
174 | }; |
175 | WRITE_CLASS_ENCODER(RGWBWRoutingRules) | |
176 | ||
177 | struct RGWBucketWebsiteConf | |
178 | { | |
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; | |
eafe8130 TL |
185 | bool is_redirect_all; |
186 | bool is_set_index_doc; | |
7c673cae FG |
187 | RGWBWRoutingRules routing_rules; |
188 | ||
189 | RGWBucketWebsiteConf() | |
190 | : listing_enabled(false) { | |
eafe8130 TL |
191 | is_redirect_all = false; |
192 | is_set_index_doc = false; | |
7c673cae FG |
193 | } |
194 | ||
195 | void encode(bufferlist& bl) const { | |
196 | ENCODE_START(2, 1, bl); | |
11fdf7f2 TL |
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); | |
7c673cae FG |
204 | ENCODE_FINISH(bl); |
205 | } | |
11fdf7f2 | 206 | void decode(bufferlist::const_iterator& bl) { |
7c673cae | 207 | DECODE_START(2, bl); |
11fdf7f2 TL |
208 | decode(index_doc_suffix, bl); |
209 | decode(error_doc, bl); | |
210 | decode(routing_rules, bl); | |
211 | decode(redirect_all, bl); | |
7c673cae | 212 | if (struct_v >= 2) { |
11fdf7f2 TL |
213 | decode(subdir_marker, bl); |
214 | decode(listing_css_doc, bl); | |
215 | decode(listing_enabled, bl); | |
7c673cae FG |
216 | } |
217 | DECODE_FINISH(bl); | |
218 | } | |
219 | ||
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; | |
224 | ||
225 | bool should_redirect(const std::string& key, | |
226 | const int http_error_code, | |
227 | RGWBWRoutingRule *redirect); | |
228 | ||
eafe8130 | 229 | bool get_effective_key(const std::string& key, |
224ce89b | 230 | std::string *effective_key, bool is_file) const; |
7c673cae FG |
231 | |
232 | const std::string& get_index_doc() const { | |
233 | return index_doc_suffix; | |
234 | } | |
235 | ||
236 | bool is_empty() const { | |
237 | return index_doc_suffix.empty() && | |
238 | error_doc.empty() && | |
239 | subdir_marker.empty() && | |
240 | listing_css_doc.empty() && | |
241 | ! listing_enabled; | |
242 | } | |
243 | }; | |
244 | WRITE_CLASS_ENCODER(RGWBucketWebsiteConf) | |
245 | ||
246 | #endif |