]>
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 | ||
18 | #include "rgw_xml.h" | |
19 | ||
20 | struct RGWRedirectInfo | |
21 | { | |
22 | string protocol; | |
23 | string hostname; | |
24 | uint16_t http_redirect_code; | |
25 | ||
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); | |
31 | ENCODE_FINISH(bl); | |
32 | } | |
33 | void decode(bufferlist::iterator& bl) { | |
34 | DECODE_START(1, bl); | |
35 | ::decode(protocol, bl); | |
36 | ::decode(hostname, bl); | |
37 | ::decode(http_redirect_code, bl); | |
38 | DECODE_FINISH(bl); | |
39 | } | |
40 | ||
41 | void dump(Formatter *f) const; | |
42 | void decode_json(JSONObj *obj); | |
43 | }; | |
44 | WRITE_CLASS_ENCODER(RGWRedirectInfo) | |
45 | ||
46 | ||
47 | struct RGWBWRedirectInfo | |
48 | { | |
49 | RGWRedirectInfo redirect; | |
50 | string replace_key_prefix_with; | |
51 | string replace_key_with; | |
52 | ||
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); | |
58 | ENCODE_FINISH(bl); | |
59 | } | |
60 | void decode(bufferlist::iterator& bl) { | |
61 | DECODE_START(1, bl); | |
62 | ::decode(redirect, bl); | |
63 | ::decode(replace_key_prefix_with, bl); | |
64 | ::decode(replace_key_with, bl); | |
65 | DECODE_FINISH(bl); | |
66 | } | |
67 | ||
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); | |
72 | }; | |
73 | WRITE_CLASS_ENCODER(RGWBWRedirectInfo) | |
74 | ||
75 | struct RGWBWRoutingRuleCondition | |
76 | { | |
77 | string key_prefix_equals; | |
78 | uint16_t http_error_code_returned_equals; | |
79 | ||
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); | |
84 | ENCODE_FINISH(bl); | |
85 | } | |
86 | void decode(bufferlist::iterator& bl) { | |
87 | DECODE_START(1, bl); | |
88 | ::decode(key_prefix_equals, bl); | |
89 | ::decode(http_error_code_returned_equals, bl); | |
90 | DECODE_FINISH(bl); | |
91 | } | |
92 | ||
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); | |
97 | ||
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; | |
101 | } | |
102 | }; | |
103 | WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition) | |
104 | ||
105 | struct RGWBWRoutingRule | |
106 | { | |
107 | RGWBWRoutingRuleCondition condition; | |
108 | RGWBWRedirectInfo redirect_info; | |
109 | ||
110 | void encode(bufferlist& bl) const { | |
111 | ENCODE_START(1, 1, bl); | |
112 | ::encode(condition, bl); | |
113 | ::encode(redirect_info, bl); | |
114 | ENCODE_FINISH(bl); | |
115 | } | |
116 | void decode(bufferlist::iterator& bl) { | |
117 | DECODE_START(1, bl); | |
118 | ::decode(condition, bl); | |
119 | ::decode(redirect_info, bl); | |
120 | DECODE_FINISH(bl); | |
121 | } | |
122 | ||
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); | |
127 | ||
128 | bool check_key_condition(const string& key) { | |
129 | return condition.check_key_condition(key); | |
130 | } | |
131 | bool check_error_code_condition(int error_code) { | |
132 | return condition.check_error_code_condition(error_code); | |
133 | } | |
134 | ||
135 | void apply_rule(const string& default_protocol, const string& default_hostname, const string& key, string *redirect, int *redirect_code); | |
136 | }; | |
137 | WRITE_CLASS_ENCODER(RGWBWRoutingRule) | |
138 | ||
139 | struct RGWBWRoutingRules | |
140 | { | |
141 | list<RGWBWRoutingRule> rules; | |
142 | ||
143 | void encode(bufferlist& bl) const { | |
144 | ENCODE_START(1, 1, bl); | |
145 | ::encode(rules, bl); | |
146 | ENCODE_FINISH(bl); | |
147 | } | |
148 | void decode(bufferlist::iterator& bl) { | |
149 | DECODE_START(1, bl); | |
150 | ::decode(rules, bl); | |
151 | DECODE_FINISH(bl); | |
152 | } | |
153 | ||
154 | void dump(Formatter *f) const; | |
155 | void dump_xml(Formatter *f) const; | |
156 | void decode_json(JSONObj *obj); | |
157 | ||
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); | |
161 | }; | |
162 | WRITE_CLASS_ENCODER(RGWBWRoutingRules) | |
163 | ||
164 | struct RGWBucketWebsiteConf | |
165 | { | |
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; | |
173 | ||
174 | RGWBucketWebsiteConf() | |
175 | : listing_enabled(false) { | |
176 | } | |
177 | ||
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); | |
187 | ENCODE_FINISH(bl); | |
188 | } | |
189 | void decode(bufferlist::iterator& bl) { | |
190 | DECODE_START(2, bl); | |
191 | ::decode(index_doc_suffix, bl); | |
192 | ::decode(error_doc, bl); | |
193 | ::decode(routing_rules, bl); | |
194 | ::decode(redirect_all, bl); | |
195 | if (struct_v >= 2) { | |
196 | ::decode(subdir_marker, bl); | |
197 | ::decode(listing_css_doc, bl); | |
198 | ::decode(listing_enabled, bl); | |
199 | } | |
200 | DECODE_FINISH(bl); | |
201 | } | |
202 | ||
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; | |
207 | ||
208 | bool should_redirect(const std::string& key, | |
209 | const int http_error_code, | |
210 | RGWBWRoutingRule *redirect); | |
211 | ||
212 | void get_effective_key(const std::string& key, | |
224ce89b | 213 | std::string *effective_key, bool is_file) const; |
7c673cae FG |
214 | |
215 | const std::string& get_index_doc() const { | |
216 | return index_doc_suffix; | |
217 | } | |
218 | ||
219 | bool is_empty() const { | |
220 | return index_doc_suffix.empty() && | |
221 | error_doc.empty() && | |
222 | subdir_marker.empty() && | |
223 | listing_css_doc.empty() && | |
224 | ! listing_enabled; | |
225 | } | |
226 | }; | |
227 | WRITE_CLASS_ENCODER(RGWBucketWebsiteConf) | |
228 | ||
229 | #endif |