]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
RGWFormatter: get rid of one flush variant
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 2 Aug 2011 23:04:14 +0000 (16:04 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 2 Aug 2011 23:04:14 +0000 (16:04 -0700)
This flush variant won't exist in common/Formatter.cc.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rest.cc
src/rgw/rgw_rest_os.cc
src/rgw/rgw_rest_s3.cc

index 6ae1411d9438eff3f67267e66daaecc3858b38aa..da4e376dd51bb13a96a21f61b4bc912e5d2829f2 100644 (file)
@@ -9,6 +9,8 @@
 #include "common/Clock.h"
 #include "auth/Crypto.h"
 
+#include <sstream>
+
 using namespace ceph::crypto;
 
 rgw_err::
@@ -71,6 +73,17 @@ req_state::~req_state() {
   free((void *)bucket);
 }
 
+void flush_formatter_to_req_state(struct req_state *s, RGWFormatter *formatter)
+{
+  std::ostringstream oss;
+  formatter->flush(oss);
+  std::string outs(oss.str());
+  if (!outs.empty()) {
+    CGI_PutStr(s, outs.c_str(), outs.size());
+  }
+  s->formatter->reset();
+}
+
 std::ostream& operator<<(std::ostream& oss, const rgw_err &err)
 {
   oss << "rgw_err(http_ret=" << err.http_ret << ", s3='" << err.s3_code << "') ";
@@ -379,16 +392,6 @@ void RGWFormatter::reset()
   max_len = 0;
 }
 
-void RGWFormatter::flush(struct req_state *s)
-{
-  if (!buf)
-    return;
-
-  RGW_LOG(10) << "flush(): buf='" << buf << "'  strlen(buf)=" << strlen(buf) << dendl;
-  CGI_PutStr(s, buf, len - 1);
-  reset();
-}
-
 void RGWFormatter::flush(ostream& os)
 {
   if (!buf)
index a052f070646ee4d6597104152f3abf56932f113b..7406395502a55f1b84c8a8cfae7b07cbc44e2754 100644 (file)
@@ -376,7 +376,6 @@ public:
   }
   void reset();
   void write_data(const char *fmt, ...);
-  virtual void flush(struct req_state *s);
   virtual void flush(ostream& os);
   virtual int get_len() { return (len ? len - 1 : 0); } // don't include null termination in length
   virtual void open_array_section(const char *name) = 0;
@@ -458,6 +457,9 @@ struct req_state {
    ~req_state();
 };
 
+extern void flush_formatter_to_req_state(struct req_state *s,
+                                        RGWFormatter *formatter);
+
 /** Store basic data on an object */
 struct RGWObjEnt {
   std::string name;
index eff172dfd22eec967d2307c9938f99f45ef97abd..4ce12f1d1351aaf27bc0429a4bbc18acead938c3 100644 (file)
@@ -177,7 +177,7 @@ void end_header(struct req_state *s, const char *content_type)
     dump_content_length(s, s->formatter->get_len());
   }
   CGI_PRINTF(s,"Content-type: %s\r\n\r\n", content_type);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
   s->header_ended = true;
 }
 
@@ -186,7 +186,7 @@ void abort_early(struct req_state *s, int err_no)
   set_req_state_err(s, err_no);
   dump_errno(s);
   end_header(s);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 void dump_continue(struct req_state *s)
index 9c4d885da97614d32b7ae95473cf9f3af96e0108..90aa5cccefbbf29119d701312bcb53fa66cb9733 100644 (file)
@@ -2,6 +2,8 @@
 #include "rgw_os.h"
 #include "rgw_rest_os.h"
 
+#include <sstream>
+
 void RGWListBuckets_REST_OS::send_response()
 {
   set_req_state_err(s, ret);
@@ -42,11 +44,16 @@ void RGWListBuckets_REST_OS::send_response()
   }
   s->formatter->close_section("account");
 
-  RGW_LOG(10) << "formatter->get_len=" << s->formatter->get_len() << dendl;
-
-  dump_content_length(s, s->formatter->get_len());
+  ostringstream oss;
+  s->formatter->flush(oss);
+  std::string outs(oss.str());
+  string::size_type outs_size = outs.size();
+  dump_content_length(s, outs_size);
   end_header(s);
-  s->formatter->flush(s);
+  if (!outs.empty()) {
+    CGI_PutStr(s, outs.c_str(), outs_size);
+  }
+  s->formatter->reset();
 }
 
 void RGWListBucket_REST_OS::send_response()
@@ -105,7 +112,7 @@ void RGWListBucket_REST_OS::send_response()
   s->formatter->close_section("container");
 
   end_header(s);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 static void dump_container_metadata(struct req_state *s, RGWBucketEnt& bucket)
@@ -128,7 +135,7 @@ void RGWStatBucket_REST_OS::send_response()
 
   end_header(s);
   dump_start(s);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 void RGWCreateBucket_REST_OS::send_response()
@@ -137,7 +144,7 @@ void RGWCreateBucket_REST_OS::send_response()
     set_req_state_err(s, ret);
   dump_errno(s);
   end_header(s);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 void RGWDeleteBucket_REST_OS::send_response()
@@ -149,7 +156,7 @@ void RGWDeleteBucket_REST_OS::send_response()
   set_req_state_err(s, r);
   dump_errno(s);
   end_header(s);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 void RGWPutObj_REST_OS::send_response()
@@ -160,7 +167,7 @@ void RGWPutObj_REST_OS::send_response()
   set_req_state_err(s, ret);
   dump_errno(s);
   end_header(s);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 void RGWDeleteObj_REST_OS::send_response()
@@ -172,7 +179,7 @@ void RGWDeleteObj_REST_OS::send_response()
   set_req_state_err(s, r);
   dump_errno(s);
   end_header(s);
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 int RGWGetObj_REST_OS::send_response(void *handle)
@@ -226,7 +233,7 @@ send_data:
   if (get_data && !orig_ret) {
     CGI_PutStr(s, data, len);
   }
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 
   return 0;
 }
index 353ea466af039a2bd8c0503485d755b8ffd2c098..608b419760a2c7b57a7b79ba52fd7388367d2dcc 100644 (file)
@@ -109,7 +109,7 @@ void RGWListBuckets_REST_S3::send_response()
   list_all_buckets_end(s);
   dump_content_length(s, s->formatter->get_len());
   end_header(s, "application/xml");
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 void RGWListBucket_REST_S3::send_response()
@@ -159,7 +159,7 @@ void RGWListBucket_REST_S3::send_response()
     }
   }
   s->formatter->close_section("ListBucketResult");
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 void RGWCreateBucket_REST_S3::send_response()
@@ -223,7 +223,7 @@ void RGWCopyObj_REST_S3::send_response()
       }
     }
     s->formatter->close_section("CopyObjectResult");
-    s->formatter->flush(s);
+    flush_formatter_to_req_state(s, s->formatter);
   }
 }
 
@@ -259,7 +259,7 @@ void RGWInitMultipart_REST_S3::send_response()
     s->formatter->dump_format("Key", s->object);
     s->formatter->dump_format("UploadId", upload_id.c_str());
     s->formatter->close_section("InitiateMultipartUploadResult");
-    s->formatter->flush(s);
+    flush_formatter_to_req_state(s, s->formatter);
   }
 }
 
@@ -279,7 +279,7 @@ void RGWCompleteMultipart_REST_S3::send_response()
     s->formatter->dump_format("Key", s->object);
     s->formatter->dump_format("ETag", etag.c_str());
     s->formatter->close_section("CompleteMultipartUploadResult");
-    s->formatter->flush(s);
+    flush_formatter_to_req_state(s, s->formatter);
   }
 }
 
@@ -341,7 +341,7 @@ void RGWListMultipart_REST_S3::send_response()
       s->formatter->close_section("Part");
     }
     s->formatter->close_section("ListMultipartUploadResult");
-    s->formatter->flush(s);
+    flush_formatter_to_req_state(s, s->formatter);
   }
 }
 
@@ -400,7 +400,7 @@ void RGWListBucketMultiparts_REST_S3::send_response()
     }
   }
   s->formatter->close_section("ListMultipartUploadsResult");
-  s->formatter->flush(s);
+  flush_formatter_to_req_state(s, s->formatter);
 }
 
 RGWOp *RGWHandler_REST_S3::get_retrieve_obj_op(bool get_data)