return get(s, exists);
}
+
+int XMLArgs::get_bool(const string& name, bool *val, bool *exists)
+{
+ map<string, string>::iterator iter;
+ iter = val_map.find(name);
+ bool e = (iter != val_map.end());
+ if (exists)
+ *exists = e;
+
+ if (e) {
+ const char *s = iter->second.c_str();
+
+ if (strcasecmp(s, "false") == 0) {
+ *val = false;
+ } else if (strcasecmp(s, "true") == 0) {
+ *val = true;
+ } else {
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+int XMLArgs::get_bool(const char *name, bool *val, bool *exists)
+{
+ string s(name);
+ return get_bool(s, val, exists);
+}
+
bool verify_bucket_permission(struct req_state *s, int perm)
{
if (!s->bucket_acl)
/** Get the value for a specific argument parameter */
string& get(const string& name, bool *exists = NULL);
string& get(const char *name, bool *exists = NULL);
+ int get_bool(const string& name, bool *val, bool *exists);
+ int get_bool(const char *name, bool *val, bool *exists);
+
/** see if a parameter is contained in this XMLArgs */
bool exists(const char *name) {
map<string, string>::iterator iter = val_map.find(name);
void RGWListBuckets::execute()
{
- ret = get_params();
- if (ret < 0)
- return;
-
bool done;
-
bool started = false;
uint64_t total_count = 0;
size_t max_buckets = s->cct->_conf->rgw_list_buckets_max_chunk;
+ ret = get_params();
+ if (ret < 0)
+ goto send_end;
+
do {
RGWUserBuckets buckets;
uint64_t read_count = min(limit - total_count, max_buckets);
ret = rgw_read_user_buckets(store, s->user.user_id, buckets,
- marker, read_count, !!(s->prot_flags & RGW_REST_SWIFT));
+ marker, read_count, should_get_stats());
if (!started) {
send_response_begin();
}
} while (!done);
+send_end:
+ if (!started) {
+ send_response_begin();
+ }
send_response_end();
}
virtual void send_response_end() = 0;
virtual void send_response() {}
+ virtual bool should_get_stats() { return false; }
+
virtual const char *name() { return "list_buckets"; }
};
void RGWListBuckets_ObjStore_S3::send_response_data(RGWUserBuckets& buckets)
{
+ if (!sent_data)
+ return;
+
map<string, RGWBucketEnt>& m = buckets.get_buckets();
map<string, RGWBucketEnt>::iterator iter;
if (sent_data) {
s->formatter->close_section();
list_all_buckets_end(s);
+ rgw_flush_formatter_and_reset(s, s->formatter);
}
- rgw_flush_formatter_and_reset(s, s->formatter);
}
int RGWListBucket_ObjStore_S3::get_params()
if (limit == 0)
limit = limit_max;
+ need_stats = (s->format != RGW_FORMAT_PLAIN);
+
+ if (need_stats) {
+ bool stats, exists;
+ int r = s->args.get_bool("stats", &stats, &exists);
+
+ if (r < 0)
+ return r;
+
+ if (exists) {
+ need_stats = stats;
+ }
+ }
+
return 0;
}
map<string, RGWBucketEnt>& m = buckets.get_buckets();
map<string, RGWBucketEnt>::iterator iter;
+ if (!sent_data)
+ return;
+
for (iter = m.begin(); iter != m.end(); ++iter) {
RGWBucketEnt obj = iter->second;
s->formatter->open_object_section("container");
s->formatter->dump_string("name", obj.bucket.name);
- s->formatter->dump_int("count", obj.count);
- s->formatter->dump_int("bytes", obj.size);
+ if (need_stats) {
+ s->formatter->dump_int("count", obj.count);
+ s->formatter->dump_int("bytes", obj.size);
+ }
s->formatter->close_section();
rgw_flush_formatter(s, s->formatter);
}
{
if (sent_data) {
s->formatter->close_section();
+ rgw_flush_formatter_and_reset(s, s->formatter);
}
-
- rgw_flush_formatter_and_reset(s, s->formatter);
}
int RGWListBucket_ObjStore_SWIFT::get_params()
};
class RGWListBuckets_ObjStore_SWIFT : public RGWListBuckets_ObjStore {
+ bool need_stats;
public:
- RGWListBuckets_ObjStore_SWIFT() {}
+ RGWListBuckets_ObjStore_SWIFT() : need_stats(true) {}
~RGWListBuckets_ObjStore_SWIFT() {}
int get_params();
void send_response_begin();
void send_response_data(RGWUserBuckets& buckets);
void send_response_end();
+
+ bool should_get_stats() { return need_stats; }
};
class RGWListBucket_ObjStore_SWIFT : public RGWListBucket_ObjStore {