]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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")); | |
31f18b77 | 18 | LCDeleteMarker_S3 *lc_dm = static_cast<LCDeleteMarker_S3 *>(find_first("ExpiredObjectDeleteMarker")); |
224ce89b | 19 | LCDate_S3 *lc_date = static_cast<LCDate_S3 *>(find_first("Date")); |
7c673cae | 20 | |
224ce89b WB |
21 | if ((!lc_days && !lc_dm && !lc_date) || (lc_days && lc_dm) |
22 | || (lc_days && lc_date) || (lc_dm && lc_date)) { | |
7c673cae | 23 | return false; |
31f18b77 FG |
24 | } |
25 | if (lc_days) { | |
26 | days = lc_days->get_data(); | |
27 | } else if (lc_dm) { | |
28 | dm_expiration = lc_dm->get_data().compare("true") == 0; | |
29 | if (!dm_expiration) { | |
30 | return false; | |
31 | } | |
224ce89b WB |
32 | } else { |
33 | date = lc_date->get_data(); | |
34 | //We need return xml error according to S3 | |
35 | if (boost::none == ceph::from_iso_8601(date)) { | |
36 | return false; | |
37 | } | |
31f18b77 | 38 | } |
7c673cae FG |
39 | return true; |
40 | } | |
41 | ||
42 | bool LCNoncurExpiration_S3::xml_end(const char *el) { | |
43 | LCDays_S3 *lc_noncur_days = static_cast<LCDays_S3 *>(find_first("NoncurrentDays")); | |
44 | if (!lc_noncur_days) { | |
45 | return false; | |
46 | } | |
47 | days = lc_noncur_days->get_data(); | |
48 | return true; | |
49 | } | |
50 | ||
51 | bool LCMPExpiration_S3::xml_end(const char *el) { | |
52 | LCDays_S3 *lc_mp_days = static_cast<LCDays_S3 *>(find_first("DaysAfterInitiation")); | |
53 | if (!lc_mp_days) { | |
54 | return false; | |
55 | } | |
56 | days = lc_mp_days->get_data(); | |
57 | return true; | |
58 | } | |
59 | ||
60 | bool RGWLifecycleConfiguration_S3::xml_end(const char *el) { | |
61 | XMLObjIter iter = find("Rule"); | |
62 | LCRule_S3 *rule = static_cast<LCRule_S3 *>(iter.get_next()); | |
63 | while (rule) { | |
64 | add_rule(rule); | |
65 | rule = static_cast<LCRule_S3 *>(iter.get_next()); | |
66 | } | |
67 | return true; | |
68 | } | |
69 | ||
70 | bool LCRule_S3::xml_end(const char *el) { | |
71 | LCID_S3 *lc_id; | |
72 | LCPrefix_S3 *lc_prefix; | |
73 | LCStatus_S3 *lc_status; | |
74 | LCExpiration_S3 *lc_expiration; | |
75 | LCNoncurExpiration_S3 *lc_noncur_expiration; | |
76 | LCMPExpiration_S3 *lc_mp_expiration; | |
77 | ||
78 | id.clear(); | |
79 | prefix.clear(); | |
80 | status.clear(); | |
31f18b77 | 81 | dm_expiration = false; |
7c673cae FG |
82 | |
83 | lc_id = static_cast<LCID_S3 *>(find_first("ID")); | |
84 | if (!lc_id) | |
85 | return false; | |
86 | id = lc_id->get_data(); | |
87 | ||
88 | lc_prefix = static_cast<LCPrefix_S3 *>(find_first("Prefix")); | |
89 | if (!lc_prefix) | |
90 | return false; | |
91 | prefix = lc_prefix->get_data(); | |
92 | ||
93 | lc_status = static_cast<LCStatus_S3 *>(find_first("Status")); | |
94 | if (!lc_status) | |
95 | return false; | |
96 | status = lc_status->get_data(); | |
97 | if (status.compare("Enabled") != 0 && status.compare("Disabled") != 0) | |
98 | return false; | |
99 | ||
100 | lc_expiration = static_cast<LCExpiration_S3 *>(find_first("Expiration")); | |
101 | lc_noncur_expiration = static_cast<LCNoncurExpiration_S3 *>(find_first("NoncurrentVersionExpiration")); | |
102 | lc_mp_expiration = static_cast<LCMPExpiration_S3 *>(find_first("AbortIncompleteMultipartUpload")); | |
103 | if (!lc_expiration && !lc_noncur_expiration && !lc_mp_expiration) { | |
104 | return false; | |
105 | } else { | |
106 | if (lc_expiration) { | |
224ce89b | 107 | if (lc_expiration->has_days()) { |
31f18b77 | 108 | expiration.set_days(lc_expiration->get_days_str()); |
224ce89b WB |
109 | } else if (lc_expiration->has_date()) { |
110 | expiration.set_date(lc_expiration->get_date()); | |
31f18b77 FG |
111 | } else { |
112 | dm_expiration = lc_expiration->get_dm_expiration(); | |
113 | } | |
7c673cae FG |
114 | } |
115 | if (lc_noncur_expiration) { | |
116 | noncur_expiration = *lc_noncur_expiration; | |
117 | } | |
118 | if (lc_mp_expiration) { | |
119 | mp_expiration = *lc_mp_expiration; | |
120 | } | |
121 | } | |
122 | ||
123 | return true; | |
124 | } | |
125 | ||
126 | void LCRule_S3::to_xml(CephContext *cct, ostream& out) { | |
127 | out << "<Rule>" ; | |
128 | out << "<ID>" << id << "</ID>"; | |
129 | out << "<Prefix>" << prefix << "</Prefix>"; | |
130 | out << "<Status>" << status << "</Status>"; | |
31f18b77 | 131 | if (!expiration.empty() || dm_expiration) { |
224ce89b | 132 | LCExpiration_S3 expir(expiration.get_days_str(), expiration.get_date(), dm_expiration); |
7c673cae FG |
133 | expir.to_xml(out); |
134 | } | |
135 | if (!noncur_expiration.empty()) { | |
136 | LCNoncurExpiration_S3& noncur_expir = static_cast<LCNoncurExpiration_S3&>(noncur_expiration); | |
137 | noncur_expir.to_xml(out); | |
138 | } | |
139 | if (!mp_expiration.empty()) { | |
140 | LCMPExpiration_S3& mp_expir = static_cast<LCMPExpiration_S3&>(mp_expiration); | |
141 | mp_expir.to_xml(out); | |
142 | } | |
143 | out << "</Rule>"; | |
144 | } | |
145 | ||
146 | int RGWLifecycleConfiguration_S3::rebuild(RGWRados *store, RGWLifecycleConfiguration& dest) | |
147 | { | |
148 | int ret = 0; | |
149 | multimap<string, LCRule>::iterator iter; | |
150 | for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) { | |
151 | LCRule& src_rule = iter->second; | |
152 | ret = dest.check_and_add_rule(&src_rule); | |
153 | if (ret < 0) | |
154 | return ret; | |
155 | } | |
224ce89b | 156 | if (!dest.valid()) { |
7c673cae FG |
157 | ret = -ERR_INVALID_REQUEST; |
158 | } | |
159 | return ret; | |
160 | } | |
161 | ||
162 | void RGWLifecycleConfiguration_S3::dump_xml(Formatter *f) const | |
163 | { | |
164 | f->open_object_section_in_ns("LifecycleConfiguration", XMLNS_AWS_S3); | |
165 | ||
166 | for (auto iter = rule_map.begin(); iter != rule_map.end(); ++iter) { | |
167 | const LCRule_S3& rule = static_cast<const LCRule_S3&>(iter->second); | |
168 | rule.dump_xml(f); | |
169 | } | |
170 | ||
171 | f->close_section(); // Lifecycle | |
172 | } | |
173 | ||
174 | XMLObj *RGWLCXMLParser_S3::alloc_obj(const char *el) | |
175 | { | |
176 | XMLObj * obj = NULL; | |
177 | if (strcmp(el, "LifecycleConfiguration") == 0) { | |
178 | obj = new RGWLifecycleConfiguration_S3(cct); | |
179 | } else if (strcmp(el, "Rule") == 0) { | |
180 | obj = new LCRule_S3(); | |
181 | } else if (strcmp(el, "ID") == 0) { | |
182 | obj = new LCID_S3(); | |
183 | } else if (strcmp(el, "Prefix") == 0) { | |
184 | obj = new LCPrefix_S3(); | |
185 | } else if (strcmp(el, "Status") == 0) { | |
186 | obj = new LCStatus_S3(); | |
187 | } else if (strcmp(el, "Expiration") == 0) { | |
188 | obj = new LCExpiration_S3(); | |
189 | } else if (strcmp(el, "Days") == 0) { | |
190 | obj = new LCDays_S3(); | |
224ce89b WB |
191 | } else if (strcmp(el, "Date") == 0) { |
192 | obj = new LCDate_S3(); | |
31f18b77 FG |
193 | } else if (strcmp(el, "ExpiredObjectDeleteMarker") == 0) { |
194 | obj = new LCDeleteMarker_S3(); | |
7c673cae FG |
195 | } else if (strcmp(el, "NoncurrentVersionExpiration") == 0) { |
196 | obj = new LCNoncurExpiration_S3(); | |
197 | } else if (strcmp(el, "NoncurrentDays") == 0) { | |
198 | obj = new LCDays_S3(); | |
199 | } else if (strcmp(el, "AbortIncompleteMultipartUpload") == 0) { | |
200 | obj = new LCMPExpiration_S3(); | |
201 | } else if (strcmp(el, "DaysAfterInitiation") == 0) { | |
202 | obj = new LCDays_S3(); | |
203 | } | |
204 | return obj; | |
205 | } |