]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_website.h
bf92011ba6f5626f13ce2e5f49fd01a40d29e91e
[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 ft=cpp
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 #pragma once
18
19 #include <list>
20 #include <string>
21
22 #include "common/ceph_json.h"
23
24 #include "rgw_xml.h"
25
26 struct RGWRedirectInfo
27 {
28 std::string protocol;
29 std::string hostname;
30 uint16_t http_redirect_code = 0;
31
32 void encode(bufferlist& bl) const {
33 ENCODE_START(1, 1, bl);
34 encode(protocol, bl);
35 encode(hostname, bl);
36 encode(http_redirect_code, bl);
37 ENCODE_FINISH(bl);
38 }
39 void decode(bufferlist::const_iterator& bl) {
40 DECODE_START(1, bl);
41 decode(protocol, bl);
42 decode(hostname, bl);
43 decode(http_redirect_code, bl);
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;
56 std::string replace_key_prefix_with;
57 std::string replace_key_with;
58
59 void encode(bufferlist& bl) const {
60 ENCODE_START(1, 1, bl);
61 encode(redirect, bl);
62 encode(replace_key_prefix_with, bl);
63 encode(replace_key_with, bl);
64 ENCODE_FINISH(bl);
65 }
66 void decode(bufferlist::const_iterator& bl) {
67 DECODE_START(1, bl);
68 decode(redirect, bl);
69 decode(replace_key_prefix_with, bl);
70 decode(replace_key_with, bl);
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 {
83 std::string key_prefix_equals;
84 uint16_t http_error_code_returned_equals = 0;
85
86 void encode(bufferlist& bl) const {
87 ENCODE_START(1, 1, bl);
88 encode(key_prefix_equals, bl);
89 encode(http_error_code_returned_equals, bl);
90 ENCODE_FINISH(bl);
91 }
92 void decode(bufferlist::const_iterator& bl) {
93 DECODE_START(1, bl);
94 decode(key_prefix_equals, bl);
95 decode(http_error_code_returned_equals, bl);
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
104 bool check_key_condition(const std::string& key);
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);
118 encode(condition, bl);
119 encode(redirect_info, bl);
120 ENCODE_FINISH(bl);
121 }
122 void decode(bufferlist::const_iterator& bl) {
123 DECODE_START(1, bl);
124 decode(condition, bl);
125 decode(redirect_info, bl);
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
134 bool check_key_condition(const std::string& key) {
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
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);
146 };
147 WRITE_CLASS_ENCODER(RGWBWRoutingRule)
148
149 struct RGWBWRoutingRules
150 {
151 std::list<RGWBWRoutingRule> rules;
152
153 void encode(bufferlist& bl) const {
154 ENCODE_START(1, 1, bl);
155 encode(rules, bl);
156 ENCODE_FINISH(bl);
157 }
158 void decode(bufferlist::const_iterator& bl) {
159 DECODE_START(1, bl);
160 decode(rules, bl);
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
168 bool check_key_condition(const std::string& key, RGWBWRoutingRule **rule);
169 bool check_error_code_condition(int error_code, RGWBWRoutingRule **rule);
170 bool check_key_and_error_code_condition(const std::string& key,
171 const int error_code,
172 RGWBWRoutingRule **rule);
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;
184 bool is_redirect_all;
185 bool is_set_index_doc;
186 RGWBWRoutingRules routing_rules;
187
188 RGWBucketWebsiteConf()
189 : listing_enabled(false) {
190 is_redirect_all = false;
191 is_set_index_doc = false;
192 }
193
194 void encode(bufferlist& bl) const {
195 ENCODE_START(2, 1, bl);
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);
203 ENCODE_FINISH(bl);
204 }
205 void decode(bufferlist::const_iterator& bl) {
206 DECODE_START(2, bl);
207 decode(index_doc_suffix, bl);
208 decode(error_doc, bl);
209 decode(routing_rules, bl);
210 decode(redirect_all, bl);
211 if (struct_v >= 2) {
212 decode(subdir_marker, bl);
213 decode(listing_css_doc, bl);
214 decode(listing_enabled, bl);
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
228 bool get_effective_key(const std::string& key,
229 std::string *effective_key, bool is_file) const;
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)