void dump(req_state* s)
{
- if (s->format != RGW_FORMAT_HTML)
+ if (s->format != RGWFormat::HTML)
s->formatter->open_object_section("Error");
if (!s->err.err_code.empty())
s->formatter->dump_string("Code", s->err.err_code);
if (!s->trans_id.empty()) // TODO: connect to expose_bucket or another toggle
s->formatter->dump_string("RequestId", s->trans_id);
s->formatter->dump_string("HostId", s->host_id);
- if (s->format != RGW_FORMAT_HTML)
+ if (s->format != RGWFormat::HTML)
s->formatter->close_section();
}
#define RGW_ATTR_TRACE RGW_ATTR_PREFIX "trace"
-#define RGW_FORMAT_PLAIN 0
-#define RGW_FORMAT_XML 1
-#define RGW_FORMAT_JSON 2
-#define RGW_FORMAT_HTML 3
+enum class RGWFormat : int8_t {
+ BAD_FORMAT = -1,
+ PLAIN = 0,
+ XML,
+ JSON,
+ HTML,
+};
+
+static inline const char* to_mime_type(const RGWFormat f)
+{
+ switch (f) {
+ case RGWFormat::XML:
+ return "application/xml";
+ break;
+ case RGWFormat::JSON:
+ return "application/json";
+ break;
+ case RGWFormat::HTML:
+ return "text/html";
+ break;
+ case RGWFormat::PLAIN:
+ return "text/plain";
+ break;
+ default:
+ return "invalid format";
+ }
+}
#define RGW_CAP_READ 0x1
#define RGW_CAP_WRITE 0x2
std::string ratelimit_bucket_marker;
std::string ratelimit_user_name;
bool content_started{false};
- int format{0};
+ RGWFormat format{RGWFormat::PLAIN};
ceph::Formatter *formatter{nullptr};
std::string decoded_uri;
std::string relative_uri;
if (force_content_type ||
(!content_type && s->formatter->get_len() != 0) || s->is_err()){
switch (s->format) {
- case RGW_FORMAT_XML:
+ case RGWFormat::XML:
ctype = "application/xml";
break;
- case RGW_FORMAT_JSON:
+ case RGWFormat::JSON:
ctype = "application/json";
break;
- case RGW_FORMAT_HTML:
+ case RGWFormat::HTML:
ctype = "text/html";
break;
default:
string error_content("");
if (!s->formatter) {
s->formatter = new JSONFormatter;
- s->format = RGW_FORMAT_JSON;
+ s->format = RGWFormat::JSON;
}
// op->error_handler is responsible for calling it's handler error_handler
} /* put_op */
int RGWHandler_REST::allocate_formatter(req_state *s,
- int default_type,
+ RGWFormat default_type,
bool configurable)
{
- s->format = -1; // set to invalid value to allocation happens anyway
+ s->format = RGWFormat::BAD_FORMAT; // set to invalid value to allocation happens anyway
auto type = default_type;
if (configurable) {
string format_str = s->info.args.get("format");
if (format_str.compare("xml") == 0) {
- type = RGW_FORMAT_XML;
+ type = RGWFormat::XML;
} else if (format_str.compare("json") == 0) {
- type = RGW_FORMAT_JSON;
+ type = RGWFormat::JSON;
} else if (format_str.compare("html") == 0) {
- type = RGW_FORMAT_HTML;
+ type = RGWFormat::HTML;
} else {
const char *accept = s->info.env->get("HTTP_ACCEPT");
if (accept) {
}
format_buf[i] = 0;
if ((strcmp(format_buf, "text/xml") == 0) || (strcmp(format_buf, "application/xml") == 0)) {
- type = RGW_FORMAT_XML;
+ type = RGWFormat::XML;
} else if (strcmp(format_buf, "application/json") == 0) {
- type = RGW_FORMAT_JSON;
+ type = RGWFormat::JSON;
} else if (strcmp(format_buf, "text/html") == 0) {
- type = RGW_FORMAT_HTML;
+ type = RGWFormat::HTML;
}
}
}
return RGWHandler_REST::reallocate_formatter(s, type);
}
-int RGWHandler_REST::reallocate_formatter(req_state *s, int type)
+int RGWHandler_REST::reallocate_formatter(req_state *s, const RGWFormat type)
{
if (s->format == type) {
// do nothing, just reset
const bool swift_bulkupload = s->prot_flags & RGW_REST_SWIFT &&
s->info.args.exists("extract-archive");
switch (s->format) {
- case RGW_FORMAT_PLAIN:
+ case RGWFormat::PLAIN:
{
const bool use_kv_syntax = s->info.args.exists("bulk-delete") ||
multipart_delete || swift_bulkupload;
s->formatter = new RGWFormatter_Plain(use_kv_syntax);
break;
}
- case RGW_FORMAT_XML:
+ case RGWFormat::XML:
{
const bool lowercase_underscore = s->info.args.exists("bulk-delete") ||
multipart_delete || swift_bulkupload;
s->formatter = new XMLFormatter(false, lowercase_underscore);
break;
}
- case RGW_FORMAT_JSON:
+ case RGWFormat::JSON:
s->formatter = new JSONFormatter(false);
break;
- case RGW_FORMAT_HTML:
+ case RGWFormat::HTML:
s->formatter = new HTMLFormatter(s->prot_flags & RGW_REST_WEBSITE);
break;
default:
virtual RGWOp *op_options() { return NULL; }
public:
- static int allocate_formatter(req_state *s, int default_formatter,
+ static int allocate_formatter(req_state *s, RGWFormat default_formatter,
bool configurable);
static constexpr int MAX_BUCKET_NAME_LEN = 255;
static int validate_bucket_name(const std::string& bucket);
static int validate_object_name(const std::string& object);
- static int reallocate_formatter(req_state *s, int type);
+ static int reallocate_formatter(req_state *s, RGWFormat type);
int init_permissions(RGWOp* op, optional_yield y) override;
int read_permissions(RGWOp* op, optional_yield y) override;
{
s->dialect = "iam";
- if (int ret = RGWHandler_REST_IAM::init_from_header(s, RGW_FORMAT_XML, true); ret < 0) {
+ if (int ret = RGWHandler_REST_IAM::init_from_header(s, RGWFormat::XML, true); ret < 0) {
ldpp_dout(s, 10) << "init_from_header returned err=" << ret << dendl;
return ret;
}
}
int RGWHandler_REST_IAM::init_from_header(req_state* s,
- int default_formatter,
+ RGWFormat default_formatter,
bool configurable_format)
{
string req;
void rgw_iam_parse_input();
public:
- static int init_from_header(req_state *s, int default_formatter, bool configurable_format);
+ static int init_from_header(req_state *s, RGWFormat default_formatter, bool configurable_format);
RGWHandler_REST_IAM(const rgw::auth::StrategyRegistry& auth_registry,
bufferlist& bl_post_body)
int RGWHandler_REST_S3::init_from_header(rgw::sal::Store* store,
req_state* s,
- int default_formatter,
+ RGWFormat default_formatter,
bool configurable_format)
{
string req;
int RGWHandler_Auth_S3::init(rgw::sal::Store* store, req_state *state,
rgw::io::BasicClient *cio)
{
- int ret = RGWHandler_REST_S3::init_from_header(store, state, RGW_FORMAT_JSON, true);
+ int ret = RGWHandler_REST_S3::init_from_header(store, state, RGWFormat::JSON, true);
if (ret < 0)
return ret;
bool is_s3website = enable_s3website && (s->prot_flags & RGW_REST_WEBSITE);
int ret =
RGWHandler_REST_S3::init_from_header(store, s,
- is_s3website ? RGW_FORMAT_HTML :
- RGW_FORMAT_XML, true);
+ is_s3website ? RGWFormat::HTML :
+ RGWFormat::XML, true);
if (ret < 0)
return NULL;
protected:
const rgw::auth::StrategyRegistry& auth_registry;
public:
- static int init_from_header(rgw::sal::Store* store, req_state *s, int default_formatter, bool configurable_format);
+ static int init_from_header(rgw::sal::Store* store, req_state *s, RGWFormat default_formatter,
+ bool configurable_format);
explicit RGWHandler_REST_S3(const rgw::auth::StrategyRegistry& auth_registry)
: RGWHandler_REST(),
{
s->dialect = "sts";
- if (int ret = RGWHandler_REST_STS::init_from_header(s, RGW_FORMAT_XML, true); ret < 0) {
+ if (int ret = RGWHandler_REST_STS::init_from_header(s, RGWFormat::XML, true); ret < 0) {
ldpp_dout(s, 10) << "init_from_header returned err=" << ret << dendl;
return ret;
}
}
int RGWHandler_REST_STS::init_from_header(req_state* s,
- int default_formatter,
+ RGWFormat default_formatter,
bool configurable_format)
{
string req;
void rgw_sts_parse_input();
public:
- static int init_from_header(req_state *s, int default_formatter, bool configurable_format);
+ static int init_from_header(req_state *s, RGWFormat default_formatter, bool configurable_format);
RGWHandler_REST_STS(const rgw::auth::StrategyRegistry& auth_registry, const std::string& post_body="")
: RGWHandler_REST(),
{
if (op_ret) {
set_req_state_err(s, op_ret);
- } else if (!has_buckets && s->format == RGW_FORMAT_PLAIN) {
+ } else if (!has_buckets && s->format == RGWFormat::PLAIN) {
op_ret = STATUS_NO_CONTENT;
set_req_state_err(s, op_ret);
}
/* swift is a bit inconsistent here */
switch (s->format) {
- case RGW_FORMAT_XML:
+ case RGWFormat::XML:
s->formatter->dump_string("name", name);
break;
default:
return -ENOENT;
}
- int ret = allocate_formatter(s, RGW_FORMAT_PLAIN, true);
+ int ret = allocate_formatter(s, RGWFormat::PLAIN, true);
if (ret < 0)
return ret;
rgw::io::BasicClient* const cio) override {
state->dialect = "swift";
state->formatter = new JSONFormatter;
- state->format = RGW_FORMAT_JSON;
+ state->format = RGWFormat::JSON;
return RGWHandler::init(store, state, cio);
}
rgw::io::BasicClient* const cio) override {
state->dialect = "swift";
state->formatter = new JSONFormatter;
- state->format = RGW_FORMAT_JSON;
+ state->format = RGWFormat::JSON;
return RGWHandler::init(store, state, cio);
}
rgw::io::BasicClient* const cio) override {
state->dialect = "swift";
state->formatter = new JSONFormatter;
- state->format = RGW_FORMAT_JSON;
+ state->format = RGWFormat::JSON;
return RGWHandler::init(store, state, cio);
}
{
state->dialect = "swift-auth";
state->formatter = new JSONFormatter;
- state->format = RGW_FORMAT_JSON;
+ state->format = RGWFormat::JSON;
return RGWHandler::init(store, state, cio);
}
if (is_truncated) {
s->formatter->dump_string("NextMarker", next_marker);
}
- if (s->format == RGW_FORMAT_JSON) {
+ if (s->format == RGWFormat::JSON) {
s->formatter->open_array_section("Objects");
}
for (auto& i : response.hits.hits) {
rgw_flush_formatter(s, s->formatter);
s->formatter->close_section();
};
- if (s->format == RGW_FORMAT_JSON) {
+ if (s->format == RGWFormat::JSON) {
s->formatter->close_section();
}
s->formatter->close_section();
{
int ret =
RGWHandler_REST_S3::init_from_header(store, s,
- RGW_FORMAT_XML, true);
+ RGWFormat::XML, true);
if (ret < 0) {
return nullptr;
}
const rgw::auth::StrategyRegistry& auth_registry,
const std::string& frontend_prefix)
{
- if (RGWHandler_REST_S3::init_from_header(store, s, RGW_FORMAT_JSON, true) < 0) {
+ if (RGWHandler_REST_S3::init_from_header(store, s, RGWFormat::JSON, true) < 0) {
return nullptr;
}
} else if (s->init_state.url_bucket == "notifications") {
handler = new RGWHandler_REST_PSNotifs(auth_registry);
} else if (s->info.args.exists("notification")) {
- const int ret = RGWHandler_REST::allocate_formatter(s, RGW_FORMAT_XML, true);
+ const int ret = RGWHandler_REST::allocate_formatter(s, RGWFormat::XML, true);
if (ret == 0) {
handler = new RGWHandler_REST_PSNotifs_S3(auth_registry);
}