]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix openstack list buckets with plain formatting
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 16 Mar 2011 23:14:43 +0000 (16:14 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 16 Mar 2011 23:14:43 +0000 (16:14 -0700)
src/rgw/rgw_formats.cc
src/rgw/rgw_formats.h

index d50a9a776d44444811a3ce45203136d790bf4fdd..df71bce52aa43edf098d7ee17c9a1796897196c2 100644 (file)
@@ -2,17 +2,30 @@
 #include "rgw_formats.h"
 
 /* Plain */
+void RGWFormatter_Plain::formatter_init()
+{
+  stack.clear();
+}
 
 void RGWFormatter_Plain::open_obj_section(const char *name)
 {
+  struct plain_stack_entry new_entry;
+  new_entry.is_array = false;
+  new_entry.size = 0;
+  stack.push_back(new_entry);
 }
 
 void RGWFormatter_Plain::open_array_section(const char *name)
 {
+  struct plain_stack_entry new_entry;
+  new_entry.is_array = true;
+  new_entry.size = 0;
+  stack.push_back(new_entry);
 }
 
 void RGWFormatter_Plain::close_section(const char *name)
 {
+  stack.pop_back();
 }
 
 void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...)
@@ -21,12 +34,19 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...)
   char buf[LARGE_SIZE];
   va_list ap;
 
+  struct plain_stack_entry& entry = stack.back();
+  bool should_print = (stack.size() == 1);
+  entry.size++;
+
+  if (!should_print)
+    return;
+
   va_start(ap, fmt);
   int n = vsnprintf(buf, LARGE_SIZE, fmt, ap);
   va_end(ap);
   if (n >= LARGE_SIZE)
     return;
-  CGI_PRINTF(s, "%s\n", buf);
+  CGI_PRINTF(s, "%s\n", (int)entry.is_array, entry.size, buf);
 }
 
 void RGWFormatter_Plain::dump_value_str(const char *name, const char *fmt, ...)
@@ -34,6 +54,13 @@ void RGWFormatter_Plain::dump_value_str(const char *name, const char *fmt, ...)
   char buf[LARGE_SIZE];
   va_list ap;
 
+  struct plain_stack_entry& entry = stack.back();
+  bool should_print = (!entry.is_array || entry.size == 0);
+  entry.size++;
+
+  if (!should_print)
+    return;
+
   va_start(ap, fmt);
   int n = vsnprintf(buf, LARGE_SIZE, fmt, ap);
   va_end(ap);
index 0a12679a2df1f9b96e286a646f23b32f2974bce5..2e662af5aaef38e674cc360549f064a2169b8064 100644 (file)
@@ -1,9 +1,15 @@
 #ifndef CEPH_RGW_FORMATS_H
 #define CEPH_RGW_FORMATS_H
 
+struct plain_stack_entry {
+  int size;
+  bool is_array;
+};
+
 class RGWFormatter_Plain : public RGWFormatter {
+  std::list<struct plain_stack_entry> stack;
 protected:
-  void formatter_init() {}
+  void formatter_init();
 
 public:
   RGWFormatter_Plain() : RGWFormatter() {}