1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
8 * Copyright (C) 2015 Robin H. Johnson <robin.johnson@dreamhost.com>
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.
17 #include "rgw_common.h"
20 #include "common/Formatter.h"
22 #define dout_subsys ceph_subsys_rgw
24 void RGWBWRedirectInfo::dump_xml(Formatter
*f
) const
26 if (!redirect
.protocol
.empty()) {
27 encode_xml("Protocol", redirect
.protocol
, f
);
29 if (!redirect
.hostname
.empty()) {
30 encode_xml("HostName", redirect
.hostname
, f
);
32 if (redirect
.http_redirect_code
> 0) {
33 encode_xml("HttpRedirectCode", (int)redirect
.http_redirect_code
, f
);
35 if (!replace_key_prefix_with
.empty()) {
36 encode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with
, f
);
38 if (!replace_key_with
.empty()) {
39 encode_xml("ReplaceKeyWith", replace_key_with
, f
);
43 void RGWBWRedirectInfo::decode_xml(XMLObj
*obj
) {
44 RGWXMLDecoder::decode_xml("Protocol", redirect
.protocol
, obj
);
45 RGWXMLDecoder::decode_xml("HostName", redirect
.hostname
, obj
);
47 RGWXMLDecoder::decode_xml("HttpRedirectCode", code
, obj
);
48 redirect
.http_redirect_code
= code
;
49 RGWXMLDecoder::decode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with
, obj
);
50 RGWXMLDecoder::decode_xml("ReplaceKeyWith", replace_key_with
, obj
);
53 void RGWBWRoutingRuleCondition::dump_xml(Formatter
*f
) const
55 if (!key_prefix_equals
.empty()) {
56 encode_xml("KeyPrefixEquals", key_prefix_equals
, f
);
58 if (http_error_code_returned_equals
> 0) {
59 encode_xml("HttpErrorCodeReturnedEquals", (int)http_error_code_returned_equals
, f
);
63 void RGWBWRoutingRuleCondition::decode_xml(XMLObj
*obj
) {
64 RGWXMLDecoder::decode_xml("KeyPrefixEquals", key_prefix_equals
, obj
);
66 RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code
, obj
);
67 http_error_code_returned_equals
= code
;
70 void RGWBWRoutingRule::dump_xml(Formatter
*f
) const
72 encode_xml("Condition", condition
, f
);
73 encode_xml("Redirect", redirect_info
, f
);
76 void RGWBWRoutingRule::decode_xml(XMLObj
*obj
) {
77 RGWXMLDecoder::decode_xml("Condition", condition
, obj
);
78 RGWXMLDecoder::decode_xml("Redirect", redirect_info
, obj
);
81 static void encode_xml(const char *name
, const std::list
<RGWBWRoutingRule
>& l
, ceph::Formatter
*f
)
83 do_encode_xml("RoutingRules", l
, "RoutingRule", f
);
86 void RGWBucketWebsiteConf::dump_xml(Formatter
*f
) const
88 if (!redirect_all
.hostname
.empty()) {
89 f
->open_object_section("RedirectAllRequestsTo");
90 encode_xml("HostName", redirect_all
.hostname
, f
);
91 if (!redirect_all
.protocol
.empty()) {
92 encode_xml("Protocol", redirect_all
.protocol
, f
);
96 if (!index_doc_suffix
.empty()) {
97 f
->open_object_section("IndexDocument");
98 encode_xml("Suffix", index_doc_suffix
, f
);
101 if (!error_doc
.empty()) {
102 f
->open_object_section("ErrorDocument");
103 encode_xml("Key", error_doc
, f
);
106 if (!routing_rules
.rules
.empty()) {
107 encode_xml("RoutingRules", routing_rules
.rules
, f
);
111 void decode_xml_obj(list
<RGWBWRoutingRule
>& l
, XMLObj
*obj
)
113 do_decode_xml_obj(l
, "RoutingRule", obj
);
116 void RGWBucketWebsiteConf::decode_xml(XMLObj
*obj
) {
117 XMLObj
*o
= obj
->find_first("RedirectAllRequestsTo");
119 is_redirect_all
= true;
120 RGWXMLDecoder::decode_xml("HostName", redirect_all
.hostname
, o
, true);
121 RGWXMLDecoder::decode_xml("Protocol", redirect_all
.protocol
, o
);
123 o
= obj
->find_first("IndexDocument");
125 is_set_index_doc
= true;
126 RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix
, o
);
128 o
= obj
->find_first("ErrorDocument");
130 RGWXMLDecoder::decode_xml("Key", error_doc
, o
);
132 RGWXMLDecoder::decode_xml("RoutingRules", routing_rules
.rules
, obj
);