]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_lc_s3.cc
eb58a0c9f4108c5c76e59f76a901d681f0d8b66f
[ceph.git] / ceph / src / rgw / rgw_lc_s3.cc
1 #include <string.h>
2
3 #include <iostream>
4 #include <map>
5
6 #include "include/types.h"
7
8 #include "rgw_user.h"
9 #include "rgw_lc_s3.h"
10
11
12 #define dout_subsys ceph_subsys_rgw
13
14 using namespace std;
15
16 bool LCExpiration_S3::xml_end(const char * el) {
17 LCDays_S3 *lc_days = static_cast<LCDays_S3 *>(find_first("Days"));
18 LCDeleteMarker_S3 *lc_dm = static_cast<LCDeleteMarker_S3 *>(find_first("ExpiredObjectDeleteMarker"));
19
20 if ((!lc_days && !lc_dm) || (lc_days && lc_dm)) {
21 return false;
22 }
23 if (lc_days) {
24 days = lc_days->get_data();
25 } else if (lc_dm) {
26 dm_expiration = lc_dm->get_data().compare("true") == 0;
27 if (!dm_expiration) {
28 return false;
29 }
30 }
31 return true;
32 }
33
34 bool LCNoncurExpiration_S3::xml_end(const char *el) {
35 LCDays_S3 *lc_noncur_days = static_cast<LCDays_S3 *>(find_first("NoncurrentDays"));
36 if (!lc_noncur_days) {
37 return false;
38 }
39 days = lc_noncur_days->get_data();
40 return true;
41 }
42
43 bool LCMPExpiration_S3::xml_end(const char *el) {
44 LCDays_S3 *lc_mp_days = static_cast<LCDays_S3 *>(find_first("DaysAfterInitiation"));
45 if (!lc_mp_days) {
46 return false;
47 }
48 days = lc_mp_days->get_data();
49 return true;
50 }
51
52 bool RGWLifecycleConfiguration_S3::xml_end(const char *el) {
53 XMLObjIter iter = find("Rule");
54 LCRule_S3 *rule = static_cast<LCRule_S3 *>(iter.get_next());
55 while (rule) {
56 add_rule(rule);
57 rule = static_cast<LCRule_S3 *>(iter.get_next());
58 }
59 return true;
60 }
61
62 bool LCRule_S3::xml_end(const char *el) {
63 LCID_S3 *lc_id;
64 LCPrefix_S3 *lc_prefix;
65 LCStatus_S3 *lc_status;
66 LCExpiration_S3 *lc_expiration;
67 LCNoncurExpiration_S3 *lc_noncur_expiration;
68 LCMPExpiration_S3 *lc_mp_expiration;
69
70 id.clear();
71 prefix.clear();
72 status.clear();
73 dm_expiration = false;
74
75 lc_id = static_cast<LCID_S3 *>(find_first("ID"));
76 if (!lc_id)
77 return false;
78 id = lc_id->get_data();
79
80 lc_prefix = static_cast<LCPrefix_S3 *>(find_first("Prefix"));
81 if (!lc_prefix)
82 return false;
83 prefix = lc_prefix->get_data();
84
85 lc_status = static_cast<LCStatus_S3 *>(find_first("Status"));
86 if (!lc_status)
87 return false;
88 status = lc_status->get_data();
89 if (status.compare("Enabled") != 0 && status.compare("Disabled") != 0)
90 return false;
91
92 lc_expiration = static_cast<LCExpiration_S3 *>(find_first("Expiration"));
93 lc_noncur_expiration = static_cast<LCNoncurExpiration_S3 *>(find_first("NoncurrentVersionExpiration"));
94 lc_mp_expiration = static_cast<LCMPExpiration_S3 *>(find_first("AbortIncompleteMultipartUpload"));
95 if (!lc_expiration && !lc_noncur_expiration && !lc_mp_expiration) {
96 return false;
97 } else {
98 if (lc_expiration) {
99 if (!lc_expiration->empty()) {
100 expiration.set_days(lc_expiration->get_days_str());
101 } else {
102 dm_expiration = lc_expiration->get_dm_expiration();
103 }
104 }
105 if (lc_noncur_expiration) {
106 noncur_expiration = *lc_noncur_expiration;
107 }
108 if (lc_mp_expiration) {
109 mp_expiration = *lc_mp_expiration;
110 }
111 }
112
113 return true;
114 }
115
116 void LCRule_S3::to_xml(CephContext *cct, ostream& out) {
117 out << "<Rule>" ;
118 out << "<ID>" << id << "</ID>";
119 out << "<Prefix>" << prefix << "</Prefix>";
120 out << "<Status>" << status << "</Status>";
121 if (!expiration.empty() || dm_expiration) {
122 LCExpiration_S3 expir(expiration.get_days_str(), dm_expiration);
123 expir.to_xml(out);
124 }
125 if (!noncur_expiration.empty()) {
126 LCNoncurExpiration_S3& noncur_expir = static_cast<LCNoncurExpiration_S3&>(noncur_expiration);
127 noncur_expir.to_xml(out);
128 }
129 if (!mp_expiration.empty()) {
130 LCMPExpiration_S3& mp_expir = static_cast<LCMPExpiration_S3&>(mp_expiration);
131 mp_expir.to_xml(out);
132 }
133 out << "</Rule>";
134 }
135
136 int RGWLifecycleConfiguration_S3::rebuild(RGWRados *store, RGWLifecycleConfiguration& dest)
137 {
138 int ret = 0;
139 multimap<string, LCRule>::iterator iter;
140 for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
141 LCRule& src_rule = iter->second;
142 ret = dest.check_and_add_rule(&src_rule);
143 if (ret < 0)
144 return ret;
145 }
146 if (!dest.validate()) {
147 ret = -ERR_INVALID_REQUEST;
148 }
149 return ret;
150 }
151
152 void RGWLifecycleConfiguration_S3::dump_xml(Formatter *f) const
153 {
154 f->open_object_section_in_ns("LifecycleConfiguration", XMLNS_AWS_S3);
155
156 for (auto iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
157 const LCRule_S3& rule = static_cast<const LCRule_S3&>(iter->second);
158 rule.dump_xml(f);
159 }
160
161 f->close_section(); // Lifecycle
162 }
163
164 XMLObj *RGWLCXMLParser_S3::alloc_obj(const char *el)
165 {
166 XMLObj * obj = NULL;
167 if (strcmp(el, "LifecycleConfiguration") == 0) {
168 obj = new RGWLifecycleConfiguration_S3(cct);
169 } else if (strcmp(el, "Rule") == 0) {
170 obj = new LCRule_S3();
171 } else if (strcmp(el, "ID") == 0) {
172 obj = new LCID_S3();
173 } else if (strcmp(el, "Prefix") == 0) {
174 obj = new LCPrefix_S3();
175 } else if (strcmp(el, "Status") == 0) {
176 obj = new LCStatus_S3();
177 } else if (strcmp(el, "Expiration") == 0) {
178 obj = new LCExpiration_S3();
179 } else if (strcmp(el, "Days") == 0) {
180 obj = new LCDays_S3();
181 } else if (strcmp(el, "ExpiredObjectDeleteMarker") == 0) {
182 obj = new LCDeleteMarker_S3();
183 } else if (strcmp(el, "NoncurrentVersionExpiration") == 0) {
184 obj = new LCNoncurExpiration_S3();
185 } else if (strcmp(el, "NoncurrentDays") == 0) {
186 obj = new LCDays_S3();
187 } else if (strcmp(el, "AbortIncompleteMultipartUpload") == 0) {
188 obj = new LCMPExpiration_S3();
189 } else if (strcmp(el, "DaysAfterInitiation") == 0) {
190 obj = new LCDays_S3();
191 }
192 return obj;
193 }