]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_website.h
import ceph 14.2.5
[ceph.git] / ceph / src / rgw / rgw_website.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
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 */
16
17 #ifndef RGW_WEBSITE_H
18 #define RGW_WEBSITE_H
19
20 #include <list>
21 #include <string>
22
23 #include "common/ceph_json.h"
24
25 #include "rgw_xml.h"
26
27 struct RGWRedirectInfo
28 {
29 std::string protocol;
30 std::string hostname;
31 uint16_t http_redirect_code = 0;
32
33 void encode(bufferlist& bl) const {
34 ENCODE_START(1, 1, bl);
35 encode(protocol, bl);
36 encode(hostname, bl);
37 encode(http_redirect_code, bl);
38 ENCODE_FINISH(bl);
39 }
40 void decode(bufferlist::const_iterator& bl) {
41 DECODE_START(1, bl);
42 decode(protocol, bl);
43 decode(hostname, bl);
44 decode(http_redirect_code, bl);
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;
57 std::string replace_key_prefix_with;
58 std::string replace_key_with;
59
60 void encode(bufferlist& bl) const {
61 ENCODE_START(1, 1, bl);
62 encode(redirect, bl);
63 encode(replace_key_prefix_with, bl);
64 encode(replace_key_with, bl);
65 ENCODE_FINISH(bl);
66 }
67 void decode(bufferlist::const_iterator& bl) {
68 DECODE_START(1, bl);
69 decode(redirect, bl);
70 decode(replace_key_prefix_with, bl);
71 decode(replace_key_with, bl);
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 {
84 std::string key_prefix_equals;
85 uint16_t http_error_code_returned_equals = 0;
86
87 void encode(bufferlist& bl) const {
88 ENCODE_START(1, 1, bl);
89 encode(key_prefix_equals, bl);
90 encode(http_error_code_returned_equals, bl);
91 ENCODE_FINISH(bl);
92 }
93 void decode(bufferlist::const_iterator& bl) {
94 DECODE_START(1, bl);
95 decode(key_prefix_equals, bl);
96 decode(http_error_code_returned_equals, bl);
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
105 bool check_key_condition(const std::string& key);
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);
119 encode(condition, bl);
120 encode(redirect_info, bl);
121 ENCODE_FINISH(bl);
122 }
123 void decode(bufferlist::const_iterator& bl) {
124 DECODE_START(1, bl);
125 decode(condition, bl);
126 decode(redirect_info, bl);
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
135 bool check_key_condition(const std::string& key) {
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
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);
147 };
148 WRITE_CLASS_ENCODER(RGWBWRoutingRule)
149
150 struct RGWBWRoutingRules
151 {
152 std::list<RGWBWRoutingRule> rules;
153
154 void encode(bufferlist& bl) const {
155 ENCODE_START(1, 1, bl);
156 encode(rules, bl);
157 ENCODE_FINISH(bl);
158 }
159 void decode(bufferlist::const_iterator& bl) {
160 DECODE_START(1, bl);
161 decode(rules, bl);
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
169 bool check_key_condition(const std::string& key, RGWBWRoutingRule **rule);
170 bool check_error_code_condition(int error_code, RGWBWRoutingRule **rule);
171 bool check_key_and_error_code_condition(const std::string& key,
172 const int error_code,
173 RGWBWRoutingRule **rule);
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;
185 bool is_redirect_all;
186 bool is_set_index_doc;
187 RGWBWRoutingRules routing_rules;
188
189 RGWBucketWebsiteConf()
190 : listing_enabled(false) {
191 is_redirect_all = false;
192 is_set_index_doc = false;
193 }
194
195 void encode(bufferlist& bl) const {
196 ENCODE_START(2, 1, bl);
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);
204 ENCODE_FINISH(bl);
205 }
206 void decode(bufferlist::const_iterator& bl) {
207 DECODE_START(2, bl);
208 decode(index_doc_suffix, bl);
209 decode(error_doc, bl);
210 decode(routing_rules, bl);
211 decode(redirect_all, bl);
212 if (struct_v >= 2) {
213 decode(subdir_marker, bl);
214 decode(listing_css_doc, bl);
215 decode(listing_enabled, bl);
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
229 bool get_effective_key(const std::string& key,
230 std::string *effective_key, bool is_file) const;
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