]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_xml_enc.cc
import ceph 14.2.5
[ceph.git] / ceph / src / rgw / rgw_xml_enc.cc
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 #include "rgw_common.h"
18 #include "rgw_xml.h"
19
20 #include "common/Formatter.h"
21
22 #define dout_subsys ceph_subsys_rgw
23
24 void 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
43 void RGWBWRedirectInfo::decode_xml(XMLObj *obj) {
44 RGWXMLDecoder::decode_xml("Protocol", redirect.protocol, obj);
45 RGWXMLDecoder::decode_xml("HostName", redirect.hostname, obj);
46 int code = 0;
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);
51 }
52
53 void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const
54 {
55 if (!key_prefix_equals.empty()) {
56 encode_xml("KeyPrefixEquals", key_prefix_equals, f);
57 }
58 if (http_error_code_returned_equals > 0) {
59 encode_xml("HttpErrorCodeReturnedEquals", (int)http_error_code_returned_equals, f);
60 }
61 }
62
63 void RGWBWRoutingRuleCondition::decode_xml(XMLObj *obj) {
64 RGWXMLDecoder::decode_xml("KeyPrefixEquals", key_prefix_equals, obj);
65 int code = 0;
66 RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code, obj);
67 http_error_code_returned_equals = code;
68 }
69
70 void RGWBWRoutingRule::dump_xml(Formatter *f) const
71 {
72 encode_xml("Condition", condition, f);
73 encode_xml("Redirect", redirect_info, f);
74 }
75
76 void RGWBWRoutingRule::decode_xml(XMLObj *obj) {
77 RGWXMLDecoder::decode_xml("Condition", condition, obj);
78 RGWXMLDecoder::decode_xml("Redirect", redirect_info, obj);
79 }
80
81 static void encode_xml(const char *name, const std::list<RGWBWRoutingRule>& l, ceph::Formatter *f)
82 {
83 do_encode_xml("RoutingRules", l, "RoutingRule", f);
84 }
85
86 void RGWBucketWebsiteConf::dump_xml(Formatter *f) const
87 {
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);
93 }
94 f->close_section();
95 }
96 if (!index_doc_suffix.empty()) {
97 f->open_object_section("IndexDocument");
98 encode_xml("Suffix", index_doc_suffix, f);
99 f->close_section();
100 }
101 if (!error_doc.empty()) {
102 f->open_object_section("ErrorDocument");
103 encode_xml("Key", error_doc, f);
104 f->close_section();
105 }
106 if (!routing_rules.rules.empty()) {
107 encode_xml("RoutingRules", routing_rules.rules, f);
108 }
109 }
110
111 void decode_xml_obj(list<RGWBWRoutingRule>& l, XMLObj *obj)
112 {
113 do_decode_xml_obj(l, "RoutingRule", obj);
114 }
115
116 void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) {
117 XMLObj *o = obj->find_first("RedirectAllRequestsTo");
118 if (o) {
119 is_redirect_all = true;
120 RGWXMLDecoder::decode_xml("HostName", redirect_all.hostname, o, true);
121 RGWXMLDecoder::decode_xml("Protocol", redirect_all.protocol, o);
122 } else {
123 o = obj->find_first("IndexDocument");
124 if (o) {
125 is_set_index_doc = true;
126 RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o);
127 }
128 o = obj->find_first("ErrorDocument");
129 if (o) {
130 RGWXMLDecoder::decode_xml("Key", error_doc, o);
131 }
132 RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj);
133 }
134 }
135