]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: cors, style fixes, other fixes
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 27 Mar 2013 19:57:06 +0000 (12:57 -0700)
committerSage Weil <sage@inktank.com>
Mon, 1 Apr 2013 04:51:59 +0000 (21:51 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
13 files changed:
src/rgw/rgw_common.cc
src/rgw/rgw_cors.cc
src/rgw/rgw_cors.h
src/rgw/rgw_cors_s3.cc
src/rgw/rgw_cors_s3.h
src/rgw/rgw_cors_swift.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_resolve.cc
src/rgw/rgw_rest.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_xml.cc

index ad9cb1ad91702aa4d212e19a8a84a3f7f1f16bf6..b1127bb50dab86bbb1ba74d8bc318466e57ae4f8 100644 (file)
@@ -93,8 +93,8 @@ is_err() const
 
 
 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;
index 85aa48f998a32e19af7a4218ff10ba34e40466f1..578fe1975b665d6bd7ee649121f942006bd8a52c 100644 (file)
 #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);
@@ -49,33 +49,33 @@ void RGWCORSRule::erase_origin_if_present(string& origin, bool *rule_empty){
   }
 }
 
-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;
@@ -84,60 +84,60 @@ static bool is_string_in_set(set<string>& s, string h){
   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();
   }
index 372229a79da7a1e5036e2882331e4ea1ff5884f5..f28892aab5d04a0981519d7fe9e606852f250241 100644 (file)
@@ -51,7 +51,7 @@ public:
        allowed_methods(f),
        allowed_hdrs(h),
        allowed_origins(o),
-       exposable_hdrs(e){}
+       exposable_hdrs(e) {}
   virtual ~RGWCORSRule() {}
 
   std::string& get_id() { return id; }
@@ -92,8 +92,8 @@ class RGWCORSConfiguration
   protected:
     std::list<RGWCORSRule> rules;
   public:
-    RGWCORSConfiguration(){}
-    ~RGWCORSConfiguration(){}
+    RGWCORSConfiguration() {}
+    ~RGWCORSConfiguration() {}
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);
@@ -106,26 +106,26 @@ class RGWCORSConfiguration
     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;
 }
index d3d6134bb30fa52b1a2f49198a1728cc5b081266..4dc12bf838bf75a86158510678b290a6388b1770 100644 (file)
 
 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;
     }
@@ -105,42 +105,42 @@ bool RGWCORSRule_S3::xml_end(const char *el){
   }
   /*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);
     }
@@ -148,25 +148,25 @@ bool RGWCORSRule_S3::xml_end(const char *el){
   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;
@@ -174,56 +174,56 @@ bool RGWCORSConfiguration_S3::xml_end(const char *el){
 
 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;
index 32e5dcdd8d04e6a81bf350e0023a6e3c25d21771..0db03c3ea1420cd65b941e01fcde5b7b291b99dc 100644 (file)
@@ -30,8 +30,8 @@ using namespace std;
 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);
@@ -40,8 +40,8 @@ class RGWCORSRule_S3 : public RGWCORSRule, public XMLObj
 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);
index 5d1a203a9ce6103345c217dc3daaedcbe7ebec10..dcce4830d02dc008675d9eb7a4b5fd6bf520e1f6 100644 (file)
@@ -29,40 +29,40 @@ using namespace std;
 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)
index bff0e3573cbb57913456e5133aefef2841ba737d..66945bfe19bdedfe50fd80e3c448aa566ef6c400 100644 (file)
@@ -1559,7 +1559,7 @@ void RGWPutMetadata::execute()
     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;
   }
@@ -1855,7 +1855,7 @@ int RGWGetCORS::verify_permission()
 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;
@@ -1929,7 +1929,7 @@ void RGWDeleteCORS::execute()
   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;
@@ -1956,15 +1956,15 @@ void RGWDeleteCORS::execute()
   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));
       }
     }
@@ -1973,24 +1973,24 @@ void RGWOptionsCORS::get_response_params(string& hdrs, string& exp_hdrs, unsigne
   *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;
@@ -2000,13 +2000,13 @@ int RGWOptionsCORS::validate_cors_request(){
 
 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;
@@ -2014,7 +2014,7 @@ void RGWOptionsCORS::execute()
     return;
   }
   origin = s->env->get("HTTP_ORIGIN");
-  if(!origin){
+  if (!origin) {
     dout(0) << 
     "Preflight request without mandatory Origin header"
     << dendl;
@@ -2023,7 +2023,7 @@ void RGWOptionsCORS::execute()
   }
   req_hdrs = s->env->get("HTTP_ACCESS_CONTROL_ALLOW_HEADERS");
   ret = validate_cors_request();
-  if(!rule){
+  if (!rule) {
     origin = req_meth = NULL;
     return;
   }
@@ -2512,7 +2512,7 @@ int RGWHandler::do_read_permissions(RGWOp *op, bool only_bucket)
 
 int RGWHandler::read_cors_config(void)
 {
-  int ret;
+  int ret = 0;
   bufferlist bl;
  
   dout(10) << "Going to read cors from attrs" << dendl;
@@ -2535,11 +2535,10 @@ int RGWHandler::read_cors_config(void)
         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;
index 7272090a96d37b2e8fa4e83484f350ad0be27561..adf863a441e6ab01791a7249e5ee0e30393a68fd 100644 (file)
@@ -563,10 +563,10 @@ protected:
 
 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);
index 80d94f7153da2c0e623fc00ce9ad2b1ab81aaa1d..adbff3f4318ec4fb9f469b99a8b969cdf2aef2ce 100644 (file)
@@ -94,7 +94,7 @@ int RGWDNSResolver::resolve_cname(const string& hostname, string& cname, bool *f
   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;
@@ -120,7 +120,7 @@ int RGWDNSResolver::resolve_cname(const string& hostname, string& cname, bool *f
 
   /* 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;
   }
@@ -138,7 +138,7 @@ int RGWDNSResolver::resolve_cname(const string& hostname, string& cname, bool *f
   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;
   }
index a02ab83c1c92dc03f02981b726efeaee2e6b4264..a3d3a59840d48620b6710994c18969581225ace0 100644 (file)
@@ -345,17 +345,17 @@ void dump_owner(struct req_state *s, string& id, string& name, const char *secti
 }
 
 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);
     }
   }
index 0a3198829457bc8d5c09d33668410b174c33542b..49494a7cdffb7175b998caf6a7d1788bc9ad7168 100644 (file)
@@ -1230,8 +1230,8 @@ void RGWPutACLs_ObjStore_S3::send_response()
 
 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);
@@ -1239,7 +1239,9 @@ void RGWGetCORS_ObjStore_S3::send_response()
   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()
@@ -1270,11 +1272,11 @@ void RGWOptionsCORS_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);
@@ -1541,7 +1543,7 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_get()
     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;
@@ -1565,7 +1567,7 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_put()
     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;
@@ -1573,7 +1575,7 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_put()
 
 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;
index 4ce95125dd79803ad1fce21dd5f4d52917eedc8c..576eb99cec69756f0e84ee4d330e713493d34c2c 100644 (file)
@@ -371,10 +371,10 @@ int RGWPutMetadata_ObjStore_SWIFT::get_params()
     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;
@@ -540,11 +540,11 @@ void RGWOptionsCORS_ObjStore_SWIFT::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);
index 41e1f8ca63e1ccd604bbe770a908b272c0f5baa7..9595a02cec27abf8ea6a9fd6f32c501a71ac111b 100644 (file)
@@ -108,7 +108,7 @@ find(string name)
   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();