]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
2 | // vim: ts=8 sw=2 smarttab ft=cpp | |
3 | ||
4 | #include <string.h> | |
5 | ||
6 | #include <iostream> | |
7 | #include <map> | |
8 | ||
9 | #include "include/types.h" | |
10 | ||
11 | #include "rgw_xml.h" | |
12 | #include "rgw_multi.h" | |
13 | #include "rgw_op.h" | |
14 | #include "rgw_sal.h" | |
15 | #include "rgw_sal_rados.h" | |
16 | ||
17 | #include "services/svc_sys_obj.h" | |
18 | #include "services/svc_tier_rados.h" | |
19 | ||
20 | #define dout_subsys ceph_subsys_rgw | |
21 | ||
22 | using namespace std; | |
23 | ||
24 | bool RGWMultiPart::xml_end(const char *el) | |
25 | { | |
26 | RGWMultiPartNumber *num_obj = static_cast<RGWMultiPartNumber *>(find_first("PartNumber")); | |
27 | RGWMultiETag *etag_obj = static_cast<RGWMultiETag *>(find_first("ETag")); | |
28 | ||
29 | if (!num_obj || !etag_obj) | |
30 | return false; | |
31 | ||
32 | string s = num_obj->get_data(); | |
33 | if (s.empty()) | |
34 | return false; | |
35 | ||
36 | num = atoi(s.c_str()); | |
37 | ||
38 | s = etag_obj->get_data(); | |
39 | etag = s; | |
40 | ||
41 | return true; | |
42 | } | |
43 | ||
44 | bool RGWMultiCompleteUpload::xml_end(const char *el) { | |
45 | XMLObjIter iter = find("Part"); | |
46 | RGWMultiPart *part = static_cast<RGWMultiPart *>(iter.get_next()); | |
47 | while (part) { | |
48 | int num = part->get_num(); | |
49 | string etag = part->get_etag(); | |
50 | parts[num] = etag; | |
51 | part = static_cast<RGWMultiPart *>(iter.get_next()); | |
52 | } | |
53 | return true; | |
54 | } | |
55 | ||
56 | RGWMultiXMLParser::~RGWMultiXMLParser() {} | |
57 | ||
58 | XMLObj *RGWMultiXMLParser::alloc_obj(const char *el) { | |
59 | XMLObj *obj = NULL; | |
60 | // CompletedMultipartUpload is incorrect but some versions of some libraries use it, see PR #41700 | |
61 | if (strcmp(el, "CompleteMultipartUpload") == 0 || | |
62 | strcmp(el, "CompletedMultipartUpload") == 0 || | |
63 | strcmp(el, "MultipartUpload") == 0) { | |
64 | obj = new RGWMultiCompleteUpload(); | |
65 | } else if (strcmp(el, "Part") == 0) { | |
66 | obj = new RGWMultiPart(); | |
67 | } else if (strcmp(el, "PartNumber") == 0) { | |
68 | obj = new RGWMultiPartNumber(); | |
69 | } else if (strcmp(el, "ETag") == 0) { | |
70 | obj = new RGWMultiETag(); | |
71 | } | |
72 | ||
73 | return obj; | |
74 | } | |
75 | ||
76 | bool is_v2_upload_id(const string& upload_id) | |
77 | { | |
78 | const char *uid = upload_id.c_str(); | |
79 | ||
80 | return (strncmp(uid, MULTIPART_UPLOAD_ID_PREFIX, sizeof(MULTIPART_UPLOAD_ID_PREFIX) - 1) == 0) || | |
81 | (strncmp(uid, MULTIPART_UPLOAD_ID_PREFIX_LEGACY, sizeof(MULTIPART_UPLOAD_ID_PREFIX_LEGACY) - 1) == 0); | |
82 | } | |
83 | ||
84 | void RGWUploadPartInfo::generate_test_instances(list<RGWUploadPartInfo*>& o) | |
85 | { | |
86 | RGWUploadPartInfo *i = new RGWUploadPartInfo; | |
87 | i->num = 1; | |
88 | i->size = 10 * 1024 * 1024; | |
89 | i->etag = "etag"; | |
90 | o.push_back(i); | |
91 | o.push_back(new RGWUploadPartInfo); | |
92 | } | |
93 | ||
94 | void RGWUploadPartInfo::dump(Formatter *f) const | |
95 | { | |
96 | encode_json("num", num, f); | |
97 | encode_json("size", size, f); | |
98 | encode_json("etag", etag, f); | |
99 | utime_t ut(modified); | |
100 | encode_json("modified", ut, f); | |
101 | encode_json("past_prefixes", past_prefixes, f); | |
102 | } | |
103 |