1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
7 * Copyright (C) 2015 Robin H. Johnson <robin.johnson@dreamhost.com>
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.
15 #include "rgw_common.h"
18 #include "common/Formatter.h"
20 #define dout_subsys ceph_subsys_rgw
22 void RGWBWRedirectInfo::dump_xml(Formatter *f) const
24 if (!redirect.protocol.empty()) {
25 encode_xml("Protocol", redirect.protocol, f);
27 if (!redirect.hostname.empty()) {
28 encode_xml("HostName", redirect.hostname, f);
30 if (redirect.http_redirect_code > 0) {
31 encode_xml("HttpRedirectCode", (int)redirect.http_redirect_code, f);
33 if (!replace_key_prefix_with.empty()) {
34 encode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, f);
36 if (!replace_key_with.empty()) {
37 encode_xml("ReplaceKeyWith", replace_key_with, f);
41 void RGWBWRedirectInfo::decode_xml(XMLObj *obj) {
42 RGWXMLDecoder::decode_xml("Protocol", redirect.protocol, obj);
43 RGWXMLDecoder::decode_xml("HostName", redirect.hostname, obj);
45 RGWXMLDecoder::decode_xml("HttpRedirectCode", code, obj);
46 redirect.http_redirect_code = code;
47 RGWXMLDecoder::decode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, obj);
48 RGWXMLDecoder::decode_xml("ReplaceKeyWith", replace_key_with, obj);
51 void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const
53 if (!key_prefix_equals.empty()) {
54 encode_xml("KeyPrefixEquals", key_prefix_equals, f);
56 if (http_error_code_returned_equals > 0) {
57 encode_xml("HttpErrorCodeReturnedEquals", (int)http_error_code_returned_equals, f);
61 void RGWBWRoutingRuleCondition::decode_xml(XMLObj *obj) {
62 RGWXMLDecoder::decode_xml("KeyPrefixEquals", key_prefix_equals, obj);
64 RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code, obj);
65 http_error_code_returned_equals = code;
68 void RGWBWRoutingRule::dump_xml(Formatter *f) const
70 encode_xml("Condition", condition, f);
71 encode_xml("Redirect", redirect_info, f);
74 void RGWBWRoutingRule::decode_xml(XMLObj *obj) {
75 RGWXMLDecoder::decode_xml("Condition", condition, obj);
76 RGWXMLDecoder::decode_xml("Redirect", redirect_info, obj);
79 static void encode_xml(const char *name, const std::list<RGWBWRoutingRule>& l, ceph::Formatter *f)
81 do_encode_xml("RoutingRules", l, "RoutingRule", f);
84 void RGWBucketWebsiteConf::dump_xml(Formatter *f) const
86 if (!redirect_all.hostname.empty()) {
87 f->open_object_section("RedirectAllRequestsTo");
88 encode_xml("HostName", redirect_all.hostname, f);
89 if (!redirect_all.protocol.empty()) {
90 encode_xml("Protocol", redirect_all.protocol, f);
94 if (!index_doc_suffix.empty()) {
95 f->open_object_section("IndexDocument");
96 encode_xml("Suffix", index_doc_suffix, f);
99 if (!error_doc.empty()) {
100 f->open_object_section("ErrorDocument");
101 encode_xml("Key", error_doc, f);
104 if (!routing_rules.rules.empty()) {
105 encode_xml("RoutingRules", routing_rules.rules, f);
109 void decode_xml_obj(list<RGWBWRoutingRule>& l, XMLObj *obj)
111 do_decode_xml_obj(l, "RoutingRule", obj);
114 void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) {
115 XMLObj *o = obj->find_first("RedirectAllRequestsTo");
117 RGWXMLDecoder::decode_xml("HostName", redirect_all.hostname, o, true);
118 RGWXMLDecoder::decode_xml("Protocol", redirect_all.protocol, o);
120 o = obj->find_first("IndexDocument");
122 RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o);
124 o = obj->find_first("ErrorDocument");
126 RGWXMLDecoder::decode_xml("Key", error_doc, o);
128 RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj);