ListBucket lists all keys in given bucket with given prefix. Return NULL when there is failure due to network instability or service unstable, so that caller could retry. Caller should delete returned object.
| 291 | // |
| 292 | // Caller should delete returned object. |
| 293 | ListBucketResult S3InterfaceService::listBucket(S3Url &s3Url) { |
| 294 | ListBucketResult result; |
| 295 | |
| 296 | string marker = ""; |
| 297 | string encodedPrefix = s3Url.getPrefix(); |
| 298 | FindAndReplace(encodedPrefix, "/", "%2F"); |
| 299 | do { |
| 300 | // To get next set(up to 1000) keys in one iteration. |
| 301 | // S3 requires query parameters specified alphabetically. |
| 302 | |
| 303 | // marker and prefix are used as the values of query parameters here |
| 304 | // so URI encode their whole string, "/" also. |
| 305 | |
| 306 | // transfer /bucket/prefix to /bucket/?prefix=prefix because we need to "GET" a real thing |
| 307 | stringstream querySs; |
| 308 | if (!marker.empty()) { |
| 309 | querySs << "marker=" << UriEncode(marker); |
| 310 | } |
| 311 | |
| 312 | if (!encodedPrefix.empty()) { |
| 313 | querySs << (marker.empty() ? "prefix=" : "&prefix=") << encodedPrefix; |
| 314 | } |
| 315 | |
| 316 | s3Url.setPrefix(""); |
| 317 | string queryStr = querySs.str(); |
| 318 | |
| 319 | Response resp = getBucketResponse(s3Url, queryStr); |
| 320 | |
| 321 | if (resp.getStatus() == RESPONSE_OK) { |
| 322 | xmlParserCtxtPtr xmlContext = getXMLContext(resp); |
| 323 | XMLContextHolder holder(xmlContext); |
| 324 | if (parseBucketXML(&result, xmlContext, marker)) { |
| 325 | continue; |
| 326 | } |
| 327 | } else if (resp.getStatus() == RESPONSE_ERROR) { |
| 328 | S3MessageParser s3msg(resp); |
| 329 | S3_DIE(S3LogicError, s3msg.getCode(), s3msg.getMessage()); |
| 330 | } else { |
| 331 | S3_DIE(S3RuntimeError, "unexpected response status"); |
| 332 | } |
| 333 | |
| 334 | return result; |
| 335 | } while (!marker.empty()); |
| 336 | |
| 337 | return result; |
| 338 | } |
| 339 | |
| 340 | uint64_t S3InterfaceService::fetchData(uint64_t offset, S3VectorUInt8 &data, uint64_t len, |
| 341 | const S3Url &s3Url) { |