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 enable_line_break() override {};
33 void flush(ostream& os) override;
34 void reset() override;
36 void open_array_section(const char *name) override;
37 void open_array_section_in_ns(const char *name, const char *ns) override;
38 void open_object_section(const char *name) override;
39 void open_object_section_in_ns(const char *name, const char *ns) override;
40 void close_section() override;
41 void dump_unsigned(const char *name, uint64_t u) override;
42 void dump_int(const char *name, int64_t u) override;
43 void dump_float(const char *name, double d) override;
44 void dump_string(const char *name, const std::string& s) override;
45 std::ostream& dump_stream(const char *name) override;
46 void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) override;
47 int get_len() const override;
48 void write_raw_data(const char *data) override;
51 void write_data(const char *fmt, ...);
52 void dump_value_int(const char *name, const char *fmt, ...);
58 std::list<struct plain_stack_entry> stack;
59 size_t min_stack_level = 0;
61 bool wrote_something = 0;
65 /* This is a presentation layer. No logic inside, please. */
66 class RGWSwiftWebsiteListingFormatter {
68 const std::string prefix;
70 std::string format_name(const std::string& item_name) const;
72 RGWSwiftWebsiteListingFormatter(std::ostream& ss,
75 prefix(std::move(prefix)) {
78 /* The supplied css_path can be empty. In such situation a default,
79 * embedded style sheet will be generated. */
80 void generate_header(const std::string& dir_path,
81 const std::string& css_path);
82 void generate_footer();
83 void dump_object(const rgw_bucket_dir_entry& objent);
84 void dump_subdir(const std::string& name);
88 class RGWFormatterFlusher {
93 virtual void do_flush() = 0;
94 virtual void do_start(int ret) {}
95 void set_formatter(Formatter *f) {
99 explicit RGWFormatterFlusher(Formatter *f) : formatter(f), flushed(false), started(false) {}
100 virtual ~RGWFormatterFlusher() {}
107 virtual void start(int client_ret) {
109 do_start(client_ret);
113 Formatter *get_formatter() { return formatter; }
114 bool did_flush() { return flushed; }
115 bool did_start() { return started; }
118 class RGWStreamFlusher : public RGWFormatterFlusher {
121 void do_flush() override {
122 formatter->flush(os);
125 RGWStreamFlusher(Formatter *f, ostream& _os) : RGWFormatterFlusher(f), os(_os) {}