Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2015 Yehuda Sadeh <yehuda@redhat.com>
7  * Copyright (C) 2015 Robin H. Johnson <robin.johnson@dreamhost.com>
8  *
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.
13  * 
14  */
15 #include "rgw_common.h"
16 #include "rgw_xml.h"
17
18 #include "common/Formatter.h"
19
20 #define dout_subsys ceph_subsys_rgw
21
22 void RGWBWRedirectInfo::dump_xml(Formatter *f) const
23 {
24   if (!redirect.protocol.empty()) {
25     encode_xml("Protocol", redirect.protocol, f);
26   }
27   if (!redirect.hostname.empty()) {
28     encode_xml("HostName", redirect.hostname, f);
29   }
30   if (redirect.http_redirect_code > 0) {
31     encode_xml("HttpRedirectCode", (int)redirect.http_redirect_code, f);
32   }
33   if (!replace_key_prefix_with.empty()) {
34     encode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, f);
35   }
36   if (!replace_key_with.empty()) {
37     encode_xml("ReplaceKeyWith", replace_key_with, f);
38   }
39 }
40
41 void RGWBWRedirectInfo::decode_xml(XMLObj *obj) {
42   RGWXMLDecoder::decode_xml("Protocol", redirect.protocol, obj);
43   RGWXMLDecoder::decode_xml("HostName", redirect.hostname, obj);
44   int code = 0;
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);
49 }
50
51 void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const
52 {
53   if (!key_prefix_equals.empty()) {
54     encode_xml("KeyPrefixEquals", key_prefix_equals, f);
55   }
56   if (http_error_code_returned_equals > 0) {
57     encode_xml("HttpErrorCodeReturnedEquals", (int)http_error_code_returned_equals, f);
58   }
59 }
60
61 void RGWBWRoutingRuleCondition::decode_xml(XMLObj *obj) {
62   RGWXMLDecoder::decode_xml("KeyPrefixEquals", key_prefix_equals, obj);
63   int code = 0;
64   RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code, obj);
65   http_error_code_returned_equals = code;
66 }
67
68 void RGWBWRoutingRule::dump_xml(Formatter *f) const
69 {
70   encode_xml("Condition", condition, f);
71   encode_xml("Redirect", redirect_info, f);
72 }
73
74 void RGWBWRoutingRule::decode_xml(XMLObj *obj) {
75   RGWXMLDecoder::decode_xml("Condition", condition, obj);
76   RGWXMLDecoder::decode_xml("Redirect", redirect_info, obj);
77 }
78
79 static void encode_xml(const char *name, const std::list<RGWBWRoutingRule>& l, ceph::Formatter *f)
80 {
81   do_encode_xml("RoutingRules", l, "RoutingRule", f);
82 }
83
84 void RGWBucketWebsiteConf::dump_xml(Formatter *f) const
85 {
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);
91     }
92     f->close_section();
93   }
94   if (!index_doc_suffix.empty()) {
95     f->open_object_section("IndexDocument");
96     encode_xml("Suffix", index_doc_suffix, f);
97     f->close_section();
98   }
99   if (!error_doc.empty()) {
100     f->open_object_section("ErrorDocument");
101     encode_xml("Key", error_doc, f);
102     f->close_section();
103   }
104   if (!routing_rules.rules.empty()) {
105     encode_xml("RoutingRules", routing_rules.rules, f);
106   }
107 }
108
109 void decode_xml_obj(list<RGWBWRoutingRule>& l, XMLObj *obj)
110 {
111   do_decode_xml_obj(l, "RoutingRule", obj);
112 }
113
114 void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) {
115   XMLObj *o = obj->find_first("RedirectAllRequestsTo");
116   if (o) {
117     RGWXMLDecoder::decode_xml("HostName", redirect_all.hostname, o, true);
118     RGWXMLDecoder::decode_xml("Protocol", redirect_all.protocol, o);
119   } else {
120     o = obj->find_first("IndexDocument");
121     if (o) {
122       RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o);
123     }
124     o = obj->find_first("ErrorDocument");
125     if (o) {
126       RGWXMLDecoder::decode_xml("Key", error_doc, o);
127     }
128     RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj);
129   }
130 }
131