]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com> | |
7 | * Copyright (C) 2015 Robin H. Johnson <robin.johnson@dreamhost.com> | |
8 | * | |
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. | |
13 | * | |
14 | */ | |
15 | #ifndef RGW_WEBSITE_H | |
16 | #define RGW_WEBSITE_H | |
17 | ||
c07f9fc5 FG |
18 | #include <list> |
19 | #include <string> | |
20 | ||
7c673cae FG |
21 | #include "rgw_xml.h" |
22 | ||
23 | struct RGWRedirectInfo | |
24 | { | |
c07f9fc5 FG |
25 | std::string protocol; |
26 | std::string hostname; | |
27 | uint16_t http_redirect_code = 0; | |
7c673cae FG |
28 | |
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); | |
34 | ENCODE_FINISH(bl); | |
35 | } | |
36 | void decode(bufferlist::iterator& bl) { | |
37 | DECODE_START(1, bl); | |
38 | ::decode(protocol, bl); | |
39 | ::decode(hostname, bl); | |
40 | ::decode(http_redirect_code, bl); | |
41 | DECODE_FINISH(bl); | |
42 | } | |
43 | ||
44 | void dump(Formatter *f) const; | |
45 | void decode_json(JSONObj *obj); | |
46 | }; | |
47 | WRITE_CLASS_ENCODER(RGWRedirectInfo) | |
48 | ||
49 | ||
50 | struct RGWBWRedirectInfo | |
51 | { | |
52 | RGWRedirectInfo redirect; | |
c07f9fc5 FG |
53 | std::string replace_key_prefix_with; |
54 | std::string replace_key_with; | |
7c673cae FG |
55 | |
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); | |
61 | ENCODE_FINISH(bl); | |
62 | } | |
63 | void decode(bufferlist::iterator& bl) { | |
64 | DECODE_START(1, bl); | |
65 | ::decode(redirect, bl); | |
66 | ::decode(replace_key_prefix_with, bl); | |
67 | ::decode(replace_key_with, bl); | |
68 | DECODE_FINISH(bl); | |
69 | } | |
70 | ||
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); | |
75 | }; | |
76 | WRITE_CLASS_ENCODER(RGWBWRedirectInfo) | |
77 | ||
78 | struct RGWBWRoutingRuleCondition | |
79 | { | |
c07f9fc5 | 80 | std::string key_prefix_equals; |
7c673cae FG |
81 | uint16_t http_error_code_returned_equals; |
82 | ||
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); | |
87 | ENCODE_FINISH(bl); | |
88 | } | |
89 | void decode(bufferlist::iterator& bl) { | |
90 | DECODE_START(1, bl); | |
91 | ::decode(key_prefix_equals, bl); | |
92 | ::decode(http_error_code_returned_equals, bl); | |
93 | DECODE_FINISH(bl); | |
94 | } | |
95 | ||
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); | |
100 | ||
c07f9fc5 | 101 | bool check_key_condition(const std::string& key); |
7c673cae FG |
102 | bool check_error_code_condition(const int error_code) { |
103 | return (uint16_t)error_code == http_error_code_returned_equals; | |
104 | } | |
105 | }; | |
106 | WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition) | |
107 | ||
108 | struct RGWBWRoutingRule | |
109 | { | |
110 | RGWBWRoutingRuleCondition condition; | |
111 | RGWBWRedirectInfo redirect_info; | |
112 | ||
113 | void encode(bufferlist& bl) const { | |
114 | ENCODE_START(1, 1, bl); | |
115 | ::encode(condition, bl); | |
116 | ::encode(redirect_info, bl); | |
117 | ENCODE_FINISH(bl); | |
118 | } | |
119 | void decode(bufferlist::iterator& bl) { | |
120 | DECODE_START(1, bl); | |
121 | ::decode(condition, bl); | |
122 | ::decode(redirect_info, bl); | |
123 | DECODE_FINISH(bl); | |
124 | } | |
125 | ||
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); | |
130 | ||
c07f9fc5 | 131 | bool check_key_condition(const std::string& key) { |
7c673cae FG |
132 | return condition.check_key_condition(key); |
133 | } | |
134 | bool check_error_code_condition(int error_code) { | |
135 | return condition.check_error_code_condition(error_code); | |
136 | } | |
137 | ||
c07f9fc5 FG |
138 | void apply_rule(const std::string& default_protocol, |
139 | const std::string& default_hostname, | |
140 | const std::string& key, | |
141 | std::string *redirect, | |
142 | int *redirect_code); | |
7c673cae FG |
143 | }; |
144 | WRITE_CLASS_ENCODER(RGWBWRoutingRule) | |
145 | ||
146 | struct RGWBWRoutingRules | |
147 | { | |
c07f9fc5 | 148 | std::list<RGWBWRoutingRule> rules; |
7c673cae FG |
149 | |
150 | void encode(bufferlist& bl) const { | |
151 | ENCODE_START(1, 1, bl); | |
152 | ::encode(rules, bl); | |
153 | ENCODE_FINISH(bl); | |
154 | } | |
155 | void decode(bufferlist::iterator& bl) { | |
156 | DECODE_START(1, bl); | |
157 | ::decode(rules, bl); | |
158 | DECODE_FINISH(bl); | |
159 | } | |
160 | ||
161 | void dump(Formatter *f) const; | |
162 | void dump_xml(Formatter *f) const; | |
163 | void decode_json(JSONObj *obj); | |
164 | ||
c07f9fc5 | 165 | bool check_key_condition(const std::string& key, RGWBWRoutingRule **rule); |
7c673cae | 166 | bool check_error_code_condition(int error_code, RGWBWRoutingRule **rule); |
c07f9fc5 FG |
167 | bool check_key_and_error_code_condition(const std::string& key, |
168 | const int error_code, | |
169 | RGWBWRoutingRule **rule); | |
7c673cae FG |
170 | }; |
171 | WRITE_CLASS_ENCODER(RGWBWRoutingRules) | |
172 | ||
173 | struct RGWBucketWebsiteConf | |
174 | { | |
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; | |
182 | ||
183 | RGWBucketWebsiteConf() | |
184 | : listing_enabled(false) { | |
185 | } | |
186 | ||
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); | |
196 | ENCODE_FINISH(bl); | |
197 | } | |
198 | void decode(bufferlist::iterator& bl) { | |
199 | DECODE_START(2, bl); | |
200 | ::decode(index_doc_suffix, bl); | |
201 | ::decode(error_doc, bl); | |
202 | ::decode(routing_rules, bl); | |
203 | ::decode(redirect_all, bl); | |
204 | if (struct_v >= 2) { | |
205 | ::decode(subdir_marker, bl); | |
206 | ::decode(listing_css_doc, bl); | |
207 | ::decode(listing_enabled, bl); | |
208 | } | |
209 | DECODE_FINISH(bl); | |
210 | } | |
211 | ||
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; | |
216 | ||
217 | bool should_redirect(const std::string& key, | |
218 | const int http_error_code, | |
219 | RGWBWRoutingRule *redirect); | |
220 | ||
221 | void get_effective_key(const std::string& key, | |
224ce89b | 222 | std::string *effective_key, bool is_file) const; |
7c673cae FG |
223 | |
224 | const std::string& get_index_doc() const { | |
225 | return index_doc_suffix; | |
226 | } | |
227 | ||
228 | bool is_empty() const { | |
229 | return index_doc_suffix.empty() && | |
230 | error_doc.empty() && | |
231 | subdir_marker.empty() && | |
232 | listing_css_doc.empty() && | |
233 | ! listing_enabled; | |
234 | } | |
235 | }; | |
236 | WRITE_CLASS_ENCODER(RGWBucketWebsiteConf) | |
237 | ||
238 | #endif |