1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RGW_FORMATS_H
5 #define CEPH_RGW_FORMATS_H
7 #include "common/Formatter.h"
14 struct plain_stack_entry
{
19 /* FIXME: this class is mis-named.
20 * FIXME: This was a hack to send certain swift messages.
21 * There is a much better way to do this.
23 class RGWFormatter_Plain
: public Formatter
{
26 explicit RGWFormatter_Plain(bool use_kv
= false);
27 ~RGWFormatter_Plain() override
;
29 void set_status(int status
, const char* status_name
) override
{};
30 void output_header() override
{};
31 void output_footer() override
{};
32 void flush(ostream
& os
) override
;
33 void reset() override
;
35 void open_array_section(const char *name
) override
;
36 void open_array_section_in_ns(const char *name
, const char *ns
) override
;
37 void open_object_section(const char *name
) override
;
38 void open_object_section_in_ns(const char *name
, const char *ns
) override
;
39 void close_section() override
;
40 void dump_unsigned(const char *name
, uint64_t u
) override
;
41 void dump_int(const char *name
, int64_t u
) override
;
42 void dump_float(const char *name
, double d
) override
;
43 void dump_string(const char *name
, const std::string
& s
) override
;
44 std::ostream
& dump_stream(const char *name
) override
;
45 void dump_format_va(const char *name
, const char *ns
, bool quoted
, const char *fmt
, va_list ap
) override
;
46 int get_len() const override
;
47 void write_raw_data(const char *data
) override
;
50 void write_data(const char *fmt
, ...);
51 void dump_value_int(const char *name
, const char *fmt
, ...);
57 std::list
<struct plain_stack_entry
> stack
;
58 size_t min_stack_level
= 0;
60 bool wrote_something
= 0;
64 /* This is a presentation layer. No logic inside, please. */
65 class RGWSwiftWebsiteListingFormatter
{
67 const std::string prefix
;
69 std::string
format_name(const std::string
& item_name
) const;
71 RGWSwiftWebsiteListingFormatter(std::ostream
& ss
,
74 prefix(std::move(prefix
)) {
77 /* The supplied css_path can be empty. In such situation a default,
78 * embedded style sheet will be generated. */
79 void generate_header(const std::string
& dir_path
,
80 const std::string
& css_path
);
81 void generate_footer();
82 void dump_object(const rgw_bucket_dir_entry
& objent
);
83 void dump_subdir(const std::string
& name
);
87 class RGWFormatterFlusher
{
92 virtual void do_flush() = 0;
93 virtual void do_start(int ret
) {}
94 void set_formatter(Formatter
*f
) {
98 explicit RGWFormatterFlusher(Formatter
*f
) : formatter(f
), flushed(false), started(false) {}
99 virtual ~RGWFormatterFlusher() {}
106 virtual void start(int client_ret
) {
108 do_start(client_ret
);
112 Formatter
*get_formatter() { return formatter
; }
113 bool did_flush() { return flushed
; }
114 bool did_start() { return started
; }
117 class RGWStreamFlusher
: public RGWFormatterFlusher
{
120 void do_flush() override
{
121 formatter
->flush(os
);
124 RGWStreamFlusher(Formatter
*f
, ostream
& _os
) : RGWFormatterFlusher(f
), os(_os
) {}