#define RGW_MAX_PENDING_CHUNKS 16
#define RGW_MAX_PUT_SIZE (5ULL*1024*1024*1024)
+#define RGW_FORMAT_PLAIN 0
#define RGW_FORMAT_XML 1
#define RGW_FORMAT_JSON 2
return 0;
}
+int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_type, bool configurable)
+{
+ s->format = default_type;
+ if (configurable) {
+ string format_str = s->args.get("format");
+ if (format_str.compare("xml") == 0) {
+ s->format = RGW_FORMAT_XML;
+ } else if (format_str.compare("json") == 0) {
+ s->format = RGW_FORMAT_JSON;
+ }
+ }
+
+ switch (s->format) {
+ case RGW_FORMAT_PLAIN:
+ s->formatter = new RGWFormatter_Plain;
+ break;
+ case RGW_FORMAT_XML:
+ s->formatter = new XMLFormatter(false);
+ break;
+ case RGW_FORMAT_JSON:
+ s->formatter = new JSONFormatter(false);
+ break;
+ default:
+ return -EINVAL;
+
+ };
+ s->formatter->reset();
+
+ return 0;
+}
+
// This function enforces Amazon's spec for bucket names.
// (The requirements, not the recommendations.)
int RGWHandler_ObjStore::validate_bucket_name(const string& bucket)
virtual int validate_bucket_name(const string& bucket);
virtual int validate_object_name(const string& object);
+
+ static int allocate_formatter(struct req_state *s, int default_formatter, bool configurable);
public:
RGWHandler_ObjStore() {}
virtual ~RGWHandler_ObjStore() {}
return new RGWInitMultipart_ObjStore_S3;
}
-int RGWHandler_ObjStore_S3::init_from_header(struct req_state *s)
+int RGWHandler_ObjStore_S3::init_from_header(struct req_state *s, int default_formatter, bool configurable_format)
{
string req;
string first;
- /* this is the default, might change in a few lines */
- s->format = RGW_FORMAT_XML;
- s->formatter = new XMLFormatter(false);
- s->formatter->reset();
-
int pos;
if (g_conf->rgw_dns_name.length() && s->host) {
string h(s->host);
s->args.set(p);
s->args.parse();
+ /* must be called after the args parsing */
+ int ret = allocate_formatter(s, default_formatter, configurable_format);
+ if (ret < 0)
+ return ret;
+
if (*req_name != '/')
return 0;
int RGWHandler_Auth_S3::init(struct req_state *state, RGWClientIO *cio)
{
- int ret = RGWHandler_ObjStore_S3::init_from_header(state);
+ int ret = RGWHandler_ObjStore_S3::init_from_header(state, RGW_FORMAT_JSON, true);
if (ret < 0)
return ret;
RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s)
{
- int ret = RGWHandler_ObjStore_S3::init_from_header(s);
+ int ret = RGWHandler_ObjStore_S3::init_from_header(s, RGW_FORMAT_XML, false);
if (ret < 0)
return NULL;
class RGWHandler_ObjStore_S3 : public RGWHandler_ObjStore {
friend class RGWRESTMgr_S3;
public:
- static int init_from_header(struct req_state *s);
+ static int init_from_header(struct req_state *s, int default_formatter, bool configurable_format);
RGWHandler_ObjStore_S3() : RGWHandler_ObjStore() {}
virtual ~RGWHandler_ObjStore_S3() {}
return -ENOENT;
}
- s->formatter = new RGWFormatter_Plain;
- string format_str = s->args.get("format");
- if (format_str.compare("xml") == 0) {
- s->format = RGW_FORMAT_XML;
- delete s->formatter;
- s->formatter = new XMLFormatter(false);
- } else if (format_str.compare("json") == 0) {
- s->format = RGW_FORMAT_JSON;
- delete s->formatter;
- s->formatter = new JSONFormatter(false);
- }
- s->formatter->reset();
+ int ret = allocate_formatter(s, RGW_FORMAT_PLAIN, true);
+ if (ret < 0)
+ return ret;
string ver;
int RGWHandler_SWIFT_Auth::init(struct req_state *state, RGWClientIO *cio)
{
state->dialect = "swift-auth";
+ state->formatter = new JSONFormatter;
+ state->format = RGW_FORMAT_JSON;
return RGWHandler::init(state, cio);
}