req_state::req_state(CephContext *_cct, struct RGWEnv *e) : cct(_cct), cio(NULL), op(OP_UNKNOWN),
- has_acl_header(false), os_auth_token(NULL),
- bucket_cors(NULL),
+ bucket_cors(NULL), has_acl_header(false),
+ os_auth_token(NULL),
env(e)
{
enable_ops_log = env->conf->enable_ops_log;
#define dout_subsys ceph_subsys_rgw
using namespace std;
-void RGWCORSRule::dump_origins(){
+void RGWCORSRule::dump_origins() {
unsigned num_origins = allowed_origins.size();
dout(10) << "Allowed origins : " << num_origins << dendl;
for(set<string>::iterator it = allowed_origins.begin();
it != allowed_origins.end();
- it++){
+ it++) {
dout(10) << *it << "," << dendl;
}
}
-void RGWCORSRule::erase_origin_if_present(string& origin, bool *rule_empty){
+void RGWCORSRule::erase_origin_if_present(string& origin, bool *rule_empty) {
set<string>::iterator it = allowed_origins.find(origin);
- if(!rule_empty)
+ if (!rule_empty)
return;
*rule_empty = false;
- if(it != allowed_origins.end()){
+ if (it != allowed_origins.end()) {
dout(10) << "Found origin " << origin << ", set size:" <<
allowed_origins.size() << dendl;
allowed_origins.erase(it);
}
}
-static bool is_string_in_set(set<string>& s, string h){
- if((s.find("*") != s.end()) ||
- (s.find(h) != s.end())){
+static bool is_string_in_set(set<string>& s, string h) {
+ if ((s.find("*") != s.end()) ||
+ (s.find(h) != s.end())) {
return true;
}
/* The header can be Content-*-type, or Content-* */
for(set<string>::iterator it = s.begin();
- it != s.end(); it++){
- unsigned off;
- if((off = (*it).find("*"))!=string::npos){
+ it != s.end(); it++) {
+ size_t off;
+ if ((off = (*it).find("*"))!=string::npos) {
list<string> ssplit;
unsigned flen = 0;
get_str_list((*it), "* \t", ssplit);
- if(off != 0){
+ if (off != 0) {
string sl = ssplit.front();
flen = sl.length();
dout(10) << "Finding " << sl << ", in " << h << ", at offset 0" << dendl;
- if(h.find(sl) != 0)
+ if (h.find(sl) != 0)
continue;
ssplit.pop_front();
}
- if(off != ((*it).length() - 1)){
+ if (off != ((*it).length() - 1)) {
string sl = ssplit.front();
dout(10) << "Finding " << sl << ", in " << h
<< ", at offset not less than " << flen << dendl;
- if(h.compare((h.size() - sl.size()), sl.size(), sl) != 0)
+ if (h.compare((h.size() - sl.size()), sl.size(), sl) != 0)
continue;
}
return true;
return false;
}
-bool RGWCORSRule::is_origin_present(const char *o){
+bool RGWCORSRule::is_origin_present(const char *o) {
string origin = o;
return is_string_in_set(allowed_origins, origin);
}
-bool RGWCORSRule::is_header_allowed(const char *h, size_t len){
+bool RGWCORSRule::is_header_allowed(const char *h, size_t len) {
string hdr(h, len);
return is_string_in_set(allowed_hdrs, hdr);
}
-void RGWCORSRule::format_exp_headers(string& s){
+void RGWCORSRule::format_exp_headers(string& s) {
s = "";
for(list<string>::iterator it = exposable_hdrs.begin();
- it != exposable_hdrs.end(); it++){
- if(s.length() > 0)
+ it != exposable_hdrs.end(); it++) {
+ if (s.length() > 0)
s.append(",");
s.append((*it));
}
}
-RGWCORSRule * RGWCORSConfiguration::host_name_rule(const char *origin){
+RGWCORSRule * RGWCORSConfiguration::host_name_rule(const char *origin) {
for(list<RGWCORSRule>::iterator it_r = rules.begin();
- it_r != rules.end(); it_r++){
+ it_r != rules.end(); it_r++) {
RGWCORSRule& r = (*it_r);
- if(r.is_origin_present(origin))
+ if (r.is_origin_present(origin))
return &r;
}
return NULL;
}
-void RGWCORSConfiguration::erase_host_name_rule(string& origin){
+void RGWCORSConfiguration::erase_host_name_rule(string& origin) {
bool rule_empty;
unsigned loop = 0;
/*Erase the host name from that rule*/
dout(10) << "Num of rules : " << rules.size() << dendl;
for(list<RGWCORSRule>::iterator it_r = rules.begin();
- it_r != rules.end(); it_r++, loop++){
+ it_r != rules.end(); it_r++, loop++) {
RGWCORSRule& r = (*it_r);
r.erase_origin_if_present(origin, &rule_empty);
dout(10) << "Origin:" << origin << ", rule num:"
<< loop << ", emptying now:" << rule_empty << dendl;
- if(rule_empty){
+ if (rule_empty) {
rules.erase(it_r);
break;
}
}
}
-void RGWCORSConfiguration::dump(){
+void RGWCORSConfiguration::dump() {
unsigned loop = 1;
unsigned num_rules = rules.size();
dout(10) << "Number of rules: " << num_rules << dendl;
for(list<RGWCORSRule>::iterator it = rules.begin();
- it!= rules.end(); it++, loop++){
+ it!= rules.end(); it++, loop++) {
dout(10) << " <<<<<<< Rule " << loop << " >>>>>>> " << dendl;
(*it).dump_origins();
}
allowed_methods(f),
allowed_hdrs(h),
allowed_origins(o),
- exposable_hdrs(e){}
+ exposable_hdrs(e) {}
virtual ~RGWCORSRule() {}
std::string& get_id() { return id; }
protected:
std::list<RGWCORSRule> rules;
public:
- RGWCORSConfiguration(){}
- ~RGWCORSConfiguration(){}
+ RGWCORSConfiguration() {}
+ ~RGWCORSConfiguration() {}
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
- std::list<RGWCORSRule>& get_rules(){
+ std::list<RGWCORSRule>& get_rules() {
return rules;
}
- bool is_empty(){
+ bool is_empty() {
return rules.empty();
}
void get_origins_list(const char *origin, std::list<string>& origins);
RGWCORSRule * host_name_rule(const char *origin);
void erase_host_name_rule(std::string& origin);
void dump();
- void stack_rule(RGWCORSRule& r){
+ void stack_rule(RGWCORSRule& r) {
rules.push_front(r);
}
};
WRITE_CLASS_ENCODER(RGWCORSConfiguration)
-static inline int validate_name_string(string& o){
- if(o.length() == 0)
+static inline int validate_name_string(string& o) {
+ if (o.length() == 0)
return -1;
- if(o.find_first_of("*") != o.find_last_of("*"))
+ if (o.find_first_of("*") != o.find_last_of("*"))
return -1;
return 0;
}
using namespace std;
-void RGWCORSRule_S3::to_xml(XMLFormatter& f){
+void RGWCORSRule_S3::to_xml(XMLFormatter& f) {
f.open_object_section("CORSRule");
/*ID if present*/
- if(id.length() > 0){
+ if (id.length() > 0) {
f.dump_string("ID", id);;
}
/*AllowedMethods*/
string m;
- if(allowed_methods & RGW_CORS_GET)
+ if (allowed_methods & RGW_CORS_GET)
f.dump_string("AllowedMethod", "GET");
- if(allowed_methods & RGW_CORS_PUT)
+ if (allowed_methods & RGW_CORS_PUT)
f.dump_string("AllowedMethod", "PUT");
- if(allowed_methods & RGW_CORS_DELETE)
+ if (allowed_methods & RGW_CORS_DELETE)
f.dump_string("AllowedMethod", "DELETE");
- if(allowed_methods & RGW_CORS_HEAD)
+ if (allowed_methods & RGW_CORS_HEAD)
f.dump_string("AllowedMethod", "HEAD");
- if(allowed_methods & RGW_CORS_POST)
+ if (allowed_methods & RGW_CORS_POST)
f.dump_string("AllowedMethod", "POST");
/*AllowedOrigins*/
for(set<string>::iterator it = allowed_origins.begin();
it != allowed_origins.end();
- it++){
+ it++) {
string host = *it;
f.dump_string("AllowedOrigin", host);
}
/*AllowedHeader*/
for(set<string>::iterator it = allowed_hdrs.begin();
- it != allowed_hdrs.end(); it++){
+ it != allowed_hdrs.end(); it++) {
f.dump_string("AllowedHeader", *it);
}
/*MaxAgeSeconds*/
- if(max_age != CORS_MAX_AGE_INVALID){
+ if (max_age != CORS_MAX_AGE_INVALID) {
f.dump_unsigned("MaxAgeSeconds", max_age);
}
/*ExposeHeader*/
for(list<string>::iterator it = exposable_hdrs.begin();
- it != exposable_hdrs.end(); it++){
+ it != exposable_hdrs.end(); it++) {
f.dump_string("ExposeHeader", *it);
}
f.close_section();
}
-bool RGWCORSRule_S3::xml_end(const char *el){
+bool RGWCORSRule_S3::xml_end(const char *el) {
XMLObjIter iter = find("AllowedMethod");
XMLObj *obj;
/*Check all the allowedmethods*/
obj = iter.get_next();
- if(obj){
+ if (obj) {
for( ; obj; obj = iter.get_next()) {
const char *s = obj->get_data().c_str();
dout(10) << "RGWCORSRule::xml_end, el : " << el << ", data : " << s << dendl;
- if(strcasecmp(s, "GET") == 0){
+ if (strcasecmp(s, "GET") == 0) {
allowed_methods |= RGW_CORS_GET;
- }else if(strcasecmp(s, "POST") == 0){
+ } else if (strcasecmp(s, "POST") == 0) {
allowed_methods |= RGW_CORS_POST;
- }else if(strcasecmp(s, "DELETE") == 0){
+ } else if (strcasecmp(s, "DELETE") == 0) {
allowed_methods |= RGW_CORS_DELETE;
- }else if(strcasecmp(s, "HEAD") == 0){
+ } else if (strcasecmp(s, "HEAD") == 0) {
allowed_methods |= RGW_CORS_HEAD;
- }else if(strcasecmp(s, "PUT") == 0){
+ } else if (strcasecmp(s, "PUT") == 0) {
allowed_methods |= RGW_CORS_PUT;
- }else{
+ } else {
return false;
}
}
}
/*Check the id's len, it should be less than 255*/
XMLObj *xml_id = find_first("ID");
- if(xml_id != NULL){
+ if (xml_id != NULL) {
string data = xml_id->get_data();
- if(data.length() > 255){
+ if (data.length() > 255) {
dout(0) << "RGWCORSRule has id of length greater than 255" << dendl;
return false;
}
}
/*Check if there is atleast one AllowedOrigin*/
iter = find("AllowedOrigin");
- if(!(obj = iter.get_next())){
+ if (!(obj = iter.get_next())) {
dout(0) << "RGWCORSRule does not have even one AllowedOrigin" << dendl;
return false;
}
- for( ; obj; obj = iter.get_next()){
+ for( ; obj; obj = iter.get_next()) {
dout(10) << "RGWCORSRule - origin : " << obj->get_data() << dendl;
/*Just take the hostname*/
string host = obj->get_data();
- if(validate_name_string(host) != 0)
+ if (validate_name_string(host) != 0)
return false;
allowed_origins.insert(allowed_origins.end(), host);
}
/*Check of max_age*/
iter = find("MaxAgeSeconds");
- if((obj = iter.get_next())){
+ if ((obj = iter.get_next())) {
char *end = NULL;
- max_age = strtol(obj->get_data().c_str(), &end, 10);
- if (max_age == LONG_MAX)
+ max_age = strtoul(obj->get_data().c_str(), &end, 10);
+ if (max_age == ULONG_MAX)
max_age = CORS_MAX_AGE_INVALID;
dout(10) << "RGWCORSRule : max_age : " << max_age << dendl;
}
/*Check and update ExposeHeader*/
iter = find("ExposeHeader");
- if((obj = iter.get_next())){
- for(; obj; obj = iter.get_next()){
+ if ((obj = iter.get_next())) {
+ for(; obj; obj = iter.get_next()) {
dout(10) << "RGWCORSRule - exp_hdr : " << obj->get_data() << dendl;
exposable_hdrs.push_back(obj->get_data());
}
}
/*Check and update AllowedHeader*/
iter = find("AllowedHeader");
- if((obj = iter.get_next())){
- for(; obj; obj = iter.get_next()){
+ if ((obj = iter.get_next())) {
+ for(; obj; obj = iter.get_next()) {
dout(10) << "RGWCORSRule - allowed_hdr : " << obj->get_data() << dendl;
string s = obj->get_data();
- if(validate_name_string(s) != 0)
+ if (validate_name_string(s) != 0)
return false;
allowed_hdrs.insert(allowed_hdrs.end(), s);
}
return true;
}
-void RGWCORSConfiguration_S3::to_xml(ostream& out){
+void RGWCORSConfiguration_S3::to_xml(ostream& out) {
XMLFormatter f;
f.open_object_section("CORSConfiguration");
for(list<RGWCORSRule>::iterator it = rules.begin();
- it != rules.end(); it++){
+ it != rules.end(); it++) {
(static_cast<RGWCORSRule_S3 &>(*it)).to_xml(f);
}
f.close_section();
f.flush(out);
}
-bool RGWCORSConfiguration_S3::xml_end(const char *el){
+bool RGWCORSConfiguration_S3::xml_end(const char *el) {
XMLObjIter iter = find("CORSRule");
RGWCORSRule_S3 *obj;
- if(!(obj = (RGWCORSRule_S3 *)iter.get_next())){
+ if (!(obj = (RGWCORSRule_S3 *)iter.get_next())) {
dout(0) << "CORSConfiguration should have atleast one CORSRule" << dendl;
return false;
}
- for(; obj; obj = (RGWCORSRule_S3 *)iter.get_next()){
+ for(; obj; obj = (RGWCORSRule_S3 *)iter.get_next()) {
rules.push_back(*obj);
}
return true;
class CORSRuleID_S3 : public XMLObj {
public:
- CORSRuleID_S3(){}
- ~CORSRuleID_S3(){}
+ CORSRuleID_S3() {}
+ ~CORSRuleID_S3() {}
};
class CORSRuleAllowedOrigin_S3 : public XMLObj {
public:
- CORSRuleAllowedOrigin_S3(){}
- ~CORSRuleAllowedOrigin_S3(){}
+ CORSRuleAllowedOrigin_S3() {}
+ ~CORSRuleAllowedOrigin_S3() {}
};
class CORSRuleAllowedMethod_S3 : public XMLObj {
public:
- CORSRuleAllowedMethod_S3(){}
- ~CORSRuleAllowedMethod_S3(){}
+ CORSRuleAllowedMethod_S3() {}
+ ~CORSRuleAllowedMethod_S3() {}
};
class CORSRuleAllowedHeader_S3 : public XMLObj {
public:
- CORSRuleAllowedHeader_S3(){}
- ~CORSRuleAllowedHeader_S3(){}
+ CORSRuleAllowedHeader_S3() {}
+ ~CORSRuleAllowedHeader_S3() {}
};
class CORSRuleMaxAgeSeconds_S3 : public XMLObj {
public:
- CORSRuleMaxAgeSeconds_S3(){}
- ~CORSRuleMaxAgeSeconds_S3(){}
+ CORSRuleMaxAgeSeconds_S3() {}
+ ~CORSRuleMaxAgeSeconds_S3() {}
};
class CORSRuleExposeHeader_S3 : public XMLObj {
public:
- CORSRuleExposeHeader_S3(){}
- ~CORSRuleExposeHeader_S3(){}
+ CORSRuleExposeHeader_S3() {}
+ ~CORSRuleExposeHeader_S3() {}
};
-XMLObj *RGWCORSXMLParser_S3::alloc_obj(const char *el){
- if(strcmp(el, "CORSConfiguration") == 0){
+XMLObj *RGWCORSXMLParser_S3::alloc_obj(const char *el) {
+ if (strcmp(el, "CORSConfiguration") == 0) {
return new RGWCORSConfiguration_S3;
- } else if(strcmp(el, "CORSRule") == 0){
+ } else if (strcmp(el, "CORSRule") == 0) {
return new RGWCORSRule_S3;
- } else if(strcmp(el, "ID") == 0){
+ } else if (strcmp(el, "ID") == 0) {
return new CORSRuleID_S3;
- } else if(strcmp(el, "AllowedOrigin") == 0){
+ } else if (strcmp(el, "AllowedOrigin") == 0) {
return new CORSRuleAllowedOrigin_S3;
- } else if(strcmp(el, "AllowedMethod") == 0){
+ } else if (strcmp(el, "AllowedMethod") == 0) {
return new CORSRuleAllowedMethod_S3;
- } else if(strcmp(el, "AllowedHeader") == 0){
+ } else if (strcmp(el, "AllowedHeader") == 0) {
return new CORSRuleAllowedHeader_S3;
- } else if(strcmp(el, "MaxAgeSeconds") == 0){
+ } else if (strcmp(el, "MaxAgeSeconds") == 0) {
return new CORSRuleMaxAgeSeconds_S3;
- } else if(strcmp(el, "ExposeHeader") == 0){
+ } else if (strcmp(el, "ExposeHeader") == 0) {
return new CORSRuleExposeHeader_S3;
}
return NULL;
class RGWCORSRule_S3 : public RGWCORSRule, public XMLObj
{
public:
- RGWCORSRule_S3(){}
- ~RGWCORSRule_S3(){}
+ RGWCORSRule_S3() {}
+ ~RGWCORSRule_S3() {}
bool xml_end(const char *el);
void to_xml(XMLFormatter& f);
class RGWCORSConfiguration_S3 : public RGWCORSConfiguration, public XMLObj
{
public:
- RGWCORSConfiguration_S3(){}
- ~RGWCORSConfiguration_S3(){}
+ RGWCORSConfiguration_S3() {}
+ ~RGWCORSConfiguration_S3() {}
bool xml_end(const char *el);
void to_xml(ostream& out);
class RGWCORSConfiguration_SWIFT : public RGWCORSConfiguration
{
public:
- RGWCORSConfiguration_SWIFT(){}
- ~RGWCORSConfiguration_SWIFT(){}
+ RGWCORSConfiguration_SWIFT() {}
+ ~RGWCORSConfiguration_SWIFT() {}
int create_update(const char *allow_origins, const char *allow_headers,
- const char *expose_headers, const char *max_age){
+ const char *expose_headers, const char *max_age) {
set<string> o, h, oc;
list<string> e;
- unsigned a = CORS_MAX_AGE_INVALID;
+ long a = CORS_MAX_AGE_INVALID;
uint8_t flags = RGW_CORS_ALL;
string ao = allow_origins;
get_str_set(ao, oc);
- if(oc.empty())
+ if (oc.empty())
return -EINVAL;
- for(set<string>::iterator it = oc.begin(); it != oc.end(); it++){
+ for(set<string>::iterator it = oc.begin(); it != oc.end(); it++) {
string host = *it;
- if(validate_name_string(host) != 0)
+ if (validate_name_string(host) != 0)
return -EINVAL;
o.insert(o.end(), host);
}
- if(allow_headers){
+ if (allow_headers) {
string ah = allow_headers;
get_str_set(ah, h);
for(set<string>::iterator it = h.begin();
- it != h.end(); it++){
+ it != h.end(); it++) {
string s = (*it);
- if(validate_name_string(s) != 0)
+ if (validate_name_string(s) != 0)
return -EINVAL;
}
}
- if(expose_headers){
+ if (expose_headers) {
string eh = expose_headers;
get_str_list(eh, e);
}
- if(max_age){
+ if (max_age) {
char *end = NULL;
a = strtol(max_age, &end, 10);
if (a == LONG_MAX)
policy.encode(bl);
attrs[RGW_ATTR_ACL] = bl;
}
- if(has_cors) {
+ if (has_cors) {
cors_config.encode(cors_bl);
attrs[RGW_ATTR_CORS] = cors_bl;
}
void RGWGetCORS::execute()
{
stringstream ss;
- if(!s->bucket_cors){
+ if (!s->bucket_cors) {
dout(2) << "No CORS configuration set yet for this bucket" << dendl;
ret = -ENOENT;
return;
bufferlist bl;
rgw_obj obj;
string no_obj;
- if(!s->bucket_cors){
+ if (!s->bucket_cors) {
dout(2) << "No CORS configuration set yet for this bucket" << dendl;
ret = -ENOENT;
return;
ret = store->set_attrs(s->obj_ctx, obj, attrs, &rmattrs);
}
-void RGWOptionsCORS::get_response_params(string& hdrs, string& exp_hdrs, unsigned *max_age){
- if(req_hdrs){
+void RGWOptionsCORS::get_response_params(string& hdrs, string& exp_hdrs, unsigned *max_age) {
+ if (req_hdrs) {
list<string> hl;
get_str_list(req_hdrs, hl);
- for(list<string>::iterator it = hl.begin(); it != hl.end(); it++){
- if(!rule->is_header_allowed((*it).c_str(), (*it).length())){
+ for(list<string>::iterator it = hl.begin(); it != hl.end(); it++) {
+ if (!rule->is_header_allowed((*it).c_str(), (*it).length())) {
dout(5) << "Header " << (*it) << " is not registered in this rule" << dendl;
- }else {
- if(hdrs.length() > 0)hdrs.append(",");
+ } else {
+ if (hdrs.length() > 0)hdrs.append(",");
hdrs.append((*it));
}
}
*max_age = rule->get_max_age();
}
-int RGWOptionsCORS::validate_cors_request(){
+int RGWOptionsCORS::validate_cors_request() {
RGWCORSConfiguration *cc = s->bucket_cors;
rule = cc->host_name_rule(origin);
- if(!rule){
+ if (!rule) {
dout(10) << "There is no corsrule present for " << origin << dendl;
return -ENOENT;
}
uint8_t flags = 0;
- if(strcmp(req_meth, "GET") == 0) flags = RGW_CORS_GET;
+ if (strcmp(req_meth, "GET") == 0) flags = RGW_CORS_GET;
else if (strcmp(req_meth, "POST") == 0) flags = RGW_CORS_POST;
else if (strcmp(req_meth, "PUT") == 0) flags = RGW_CORS_PUT;
else if (strcmp(req_meth, "DELETE") == 0) flags = RGW_CORS_DELETE;
else if (strcmp(req_meth, "HEAD") == 0) flags = RGW_CORS_HEAD;
- if ((rule->get_allowed_methods() & flags) == flags){
+ if ((rule->get_allowed_methods() & flags) == flags) {
dout(10) << "Method " << req_meth << " is supported" << dendl;
- }else {
+ } else {
dout(5) << "Method " << req_meth << " is not supported" << dendl;
req_meth = NULL;
return -ENOTSUP;
void RGWOptionsCORS::execute()
{
- if(!s->bucket_cors){
+ if (!s->bucket_cors) {
dout(2) << "No CORS configuration set yet for this bucket" << dendl;
ret = -EACCES;
return;
}
req_meth = s->env->get("HTTP_ACCESS_CONTROL_REQUEST_METHOD");
- if(!req_meth){
+ if (!req_meth) {
dout(0) <<
"Preflight request without mandatory Access-control-request-method header"
<< dendl;
return;
}
origin = s->env->get("HTTP_ORIGIN");
- if(!origin){
+ if (!origin) {
dout(0) <<
"Preflight request without mandatory Origin header"
<< dendl;
}
req_hdrs = s->env->get("HTTP_ACCESS_CONTROL_ALLOW_HEADERS");
ret = validate_cors_request();
- if(!rule){
+ if (!rule) {
origin = req_meth = NULL;
return;
}
int RGWHandler::read_cors_config(void)
{
- int ret;
+ int ret = 0;
bufferlist bl;
dout(10) << "Going to read cors from attrs" << dendl;
s3cors->to_xml(*_dout);
*_dout << dendl;
}
- }else{
+ } else {
/*Not a serious error*/
dout(2) << "Warning: There is no content for CORS xattr,"
" cors may not be set yet" << dendl;
- ret = 0;
}
}
return ret;
public:
RGWOptionsCORS() : ret(0), rule(NULL), origin(NULL),
- req_hdrs(NULL), req_meth(NULL){
+ req_hdrs(NULL), req_meth(NULL) {
}
- int verify_permission(){return 0;}
+ int verify_permission() {return 0;}
int validate_cors_request();
void execute();
void get_response_params(string& allowed_hdrs, string& exp_hdrs, unsigned *max_age);
answend = answer + len;
/* read query */
- if((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
+ if ((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
dout(0) << "ERROR: dn_expand() failed" << dendl;
ret = -EINVAL;
goto done;
/* read answer */
- if((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
+ if ((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
ret = 0;
goto done;
}
pt += INT32SZ; /* ttl */
pt += INT16SZ; /* size */
- if((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
+ if ((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
ret = 0;
goto done;
}
}
void dump_access_control(struct req_state *s, const char *origin, const char *meth,
- const char *hdr, const char *exp_hdr, uint32_t max_age){
- if(origin && (origin[0] != '\0')){
+ const char *hdr, const char *exp_hdr, uint32_t max_age) {
+ if (origin && (origin[0] != '\0')) {
s->cio->print("Access-Control-Allow-Origin: %s\n", origin?origin:"");
- if(meth && (meth[0] != '\0'))
+ if (meth && (meth[0] != '\0'))
s->cio->print("Access-Control-Allow-Methods: %s\n", meth?meth:"");
- if(hdr && (hdr[0] != '\0'))
+ if (hdr && (hdr[0] != '\0'))
s->cio->print("Access-Control-Allow-Headers: %s\n", hdr);
- if(exp_hdr && (exp_hdr[0] != '\0')){
+ if (exp_hdr && (exp_hdr[0] != '\0')) {
s->cio->print("Access-Control-Expose-Headers: %s\n", exp_hdr);
}
- if(max_age != CORS_MAX_AGE_INVALID){
+ if (max_age != CORS_MAX_AGE_INVALID) {
s->cio->print("Access-Control-Max-Age: %d\n", max_age);
}
}
void RGWGetCORS_ObjStore_S3::send_response()
{
- if(ret){
- if(ret == -ENOENT)
+ if (ret) {
+ if (ret == -ENOENT)
set_req_state_err(s, ERR_NOT_FOUND);
else
set_req_state_err(s, ret);
dump_errno(s);
end_header(s, "application/xml");
dump_start(s);
- if(!ret)s->cio->write(cors.c_str(), cors.size());
+ if (!ret) {
+ s->cio->write(cors.c_str(), cors.size());
+ }
}
void RGWPutCORS_ObjStore_S3::send_response()
*ENOENT means, there is no match of the Origin in the list of CORSRule
*ENOTSUPP means, the HTTP_METHOD is not supported
*/
- if(ret == -ENOENT)
+ if (ret == -ENOENT)
ret = -EACCES;
- if(ret != -EACCES){
+ if (ret != -EACCES) {
get_response_params(hdrs, exp_hdrs, &max_age);
- }else{
+ } else {
set_req_state_err(s, ret);
dump_errno(s);
end_header(s);
return new RGWGetBucketLogging_ObjStore_S3;
if (is_acl_op()) {
return new RGWGetACLs_ObjStore_S3;
- } else if (is_cors_op()){
+ } else if (is_cors_op()) {
return new RGWGetCORS_ObjStore_S3;
} else if (s->args.exists("uploads")) {
return new RGWListBucketMultiparts_ObjStore_S3;
return NULL;
if (is_acl_op()) {
return new RGWPutACLs_ObjStore_S3;
- } else if (is_cors_op()){
+ } else if (is_cors_op()) {
return new RGWPutCORS_ObjStore_S3;
}
return new RGWCreateBucket_ObjStore_S3;
RGWOp *RGWHandler_ObjStore_Bucket_S3::op_delete()
{
- if(is_cors_op()) {
+ if (is_cors_op()) {
return new RGWDeleteCORS_ObjStore_S3;
}
return new RGWDeleteBucket_ObjStore_S3;
const char *allow_headers = s->env->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_ALLOW_HEADERS");
const char *expose_headers = s->env->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_EXPOSE_HEADERS");
const char *max_age = s->env->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_MAX_AGE");
- if(allow_origins){
+ if (allow_origins) {
RGWCORSConfiguration_SWIFT *swift_cors = new RGWCORSConfiguration_SWIFT;
int r = swift_cors->create_update(allow_origins, allow_headers, expose_headers, max_age);
- if (r < 0){
+ if (r < 0) {
dout(0) << "Error creating/updating the cors configuration" << dendl;
delete swift_cors;
return r;
*ENOENT means, there is no match of the Origin in the list of CORSRule
*ENOTSUPP means, the HTTP_METHOD is not supported
*/
- if(ret == -ENOENT)
+ if (ret == -ENOENT)
ret = -EACCES;
- if(ret != -EACCES){
+ if (ret != -EACCES) {
get_response_params(hdrs, exp_hdrs, &max_age);
- }else{
+ } else {
set_req_state_err(s, ret);
dump_errno(s);
end_header(s);
map<string, XMLObj *>::iterator first;
map<string, XMLObj *>::iterator last;
first = children.find(name);
- if(first != children.end()){
+ if (first != children.end()) {
last = children.upper_bound(name);
}else
last = children.end();