]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_xml_enc.cc
import ceph 15.2.10
[ceph.git] / ceph / src / rgw / rgw_xml_enc.cc
CommitLineData
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#include "rgw_common.h"
18#include "rgw_xml.h"
19
20#include "common/Formatter.h"
21
22#define dout_subsys ceph_subsys_rgw
23
24void RGWBWRedirectInfo::dump_xml(Formatter *f) const
25{
26 if (!redirect.protocol.empty()) {
27 encode_xml("Protocol", redirect.protocol, f);
28 }
29 if (!redirect.hostname.empty()) {
30 encode_xml("HostName", redirect.hostname, f);
31 }
32 if (redirect.http_redirect_code > 0) {
33 encode_xml("HttpRedirectCode", (int)redirect.http_redirect_code, f);
34 }
35 if (!replace_key_prefix_with.empty()) {
36 encode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, f);
37 }
38 if (!replace_key_with.empty()) {
39 encode_xml("ReplaceKeyWith", replace_key_with, f);
40 }
41}
42
9f95a23c
TL
43#define WEBSITE_HTTP_REDIRECT_CODE_MIN 300
44#define WEBSITE_HTTP_REDIRECT_CODE_MAX 400
7c673cae
FG
45void RGWBWRedirectInfo::decode_xml(XMLObj *obj) {
46 RGWXMLDecoder::decode_xml("Protocol", redirect.protocol, obj);
47 RGWXMLDecoder::decode_xml("HostName", redirect.hostname, obj);
48 int code = 0;
9f95a23c
TL
49 bool has_http_redirect_code = RGWXMLDecoder::decode_xml("HttpRedirectCode", code, obj);
50 if (has_http_redirect_code &&
51 !(code > WEBSITE_HTTP_REDIRECT_CODE_MIN &&
52 code < WEBSITE_HTTP_REDIRECT_CODE_MAX)) {
53 throw RGWXMLDecoder::err("The provided HTTP redirect code is not valid. Valid codes are 3XX except 300.");
54 }
7c673cae 55 redirect.http_redirect_code = code;
9f95a23c
TL
56 bool has_replace_key_prefix_with = RGWXMLDecoder::decode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, obj);
57 bool has_replace_key_with = RGWXMLDecoder::decode_xml("ReplaceKeyWith", replace_key_with, obj);
58 if (has_replace_key_prefix_with && has_replace_key_with) {
59 throw RGWXMLDecoder::err("You can only define ReplaceKeyPrefix or ReplaceKey but not both.");
60 }
7c673cae
FG
61}
62
63void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const
64{
65 if (!key_prefix_equals.empty()) {
66 encode_xml("KeyPrefixEquals", key_prefix_equals, f);
67 }
68 if (http_error_code_returned_equals > 0) {
69 encode_xml("HttpErrorCodeReturnedEquals", (int)http_error_code_returned_equals, f);
70 }
71}
72
9f95a23c
TL
73#define WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MIN 400
74#define WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MAX 600
7c673cae
FG
75void RGWBWRoutingRuleCondition::decode_xml(XMLObj *obj) {
76 RGWXMLDecoder::decode_xml("KeyPrefixEquals", key_prefix_equals, obj);
77 int code = 0;
9f95a23c
TL
78 bool has_http_error_code_returned_equals = RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code, obj);
79 if (has_http_error_code_returned_equals &&
80 !(code >= WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MIN &&
81 code < WEBSITE_HTTP_ERROR_CODE_RETURNED_EQUALS_MAX)) {
82 throw RGWXMLDecoder::err("The provided HTTP redirect code is not valid. Valid codes are 4XX or 5XX.");
83 }
7c673cae
FG
84 http_error_code_returned_equals = code;
85}
86
87void RGWBWRoutingRule::dump_xml(Formatter *f) const
88{
89 encode_xml("Condition", condition, f);
90 encode_xml("Redirect", redirect_info, f);
91}
92
93void RGWBWRoutingRule::decode_xml(XMLObj *obj) {
94 RGWXMLDecoder::decode_xml("Condition", condition, obj);
95 RGWXMLDecoder::decode_xml("Redirect", redirect_info, obj);
96}
97
98static void encode_xml(const char *name, const std::list<RGWBWRoutingRule>& l, ceph::Formatter *f)
99{
100 do_encode_xml("RoutingRules", l, "RoutingRule", f);
101}
102
103void RGWBucketWebsiteConf::dump_xml(Formatter *f) const
104{
105 if (!redirect_all.hostname.empty()) {
106 f->open_object_section("RedirectAllRequestsTo");
107 encode_xml("HostName", redirect_all.hostname, f);
108 if (!redirect_all.protocol.empty()) {
109 encode_xml("Protocol", redirect_all.protocol, f);
110 }
111 f->close_section();
112 }
113 if (!index_doc_suffix.empty()) {
114 f->open_object_section("IndexDocument");
115 encode_xml("Suffix", index_doc_suffix, f);
116 f->close_section();
117 }
118 if (!error_doc.empty()) {
119 f->open_object_section("ErrorDocument");
120 encode_xml("Key", error_doc, f);
121 f->close_section();
122 }
123 if (!routing_rules.rules.empty()) {
124 encode_xml("RoutingRules", routing_rules.rules, f);
125 }
126}
127
128void decode_xml_obj(list<RGWBWRoutingRule>& l, XMLObj *obj)
129{
130 do_decode_xml_obj(l, "RoutingRule", obj);
131}
132
133void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) {
134 XMLObj *o = obj->find_first("RedirectAllRequestsTo");
135 if (o) {
eafe8130 136 is_redirect_all = true;
7c673cae
FG
137 RGWXMLDecoder::decode_xml("HostName", redirect_all.hostname, o, true);
138 RGWXMLDecoder::decode_xml("Protocol", redirect_all.protocol, o);
139 } else {
140 o = obj->find_first("IndexDocument");
141 if (o) {
eafe8130 142 is_set_index_doc = true;
7c673cae
FG
143 RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o);
144 }
145 o = obj->find_first("ErrorDocument");
146 if (o) {
147 RGWXMLDecoder::decode_xml("Key", error_doc, o);
148 }
149 RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj);
150 }
151}
152