Skip to content

Commit

Permalink
rgw: cors, style fixes, other fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Yehuda Sadeh <[email protected]>
  • Loading branch information
yehudasa authored and Sage Weil committed Apr 1, 2013
1 parent f165049 commit e9e86ad
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 160 deletions.
4 changes: 2 additions & 2 deletions src/rgw/rgw_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
56 changes: 28 additions & 28 deletions src/rgw/rgw_cors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,56 @@
#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);
*rule_empty = (allowed_origins.size() == 0);
}
}

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;
Expand All @@ -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();
}
Expand Down
18 changes: 9 additions & 9 deletions src/rgw/rgw_cors.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RGWCORSRule
allowed_methods(f),
allowed_hdrs(h),
allowed_origins(o),
exposable_hdrs(e){}
exposable_hdrs(e) {}
virtual ~RGWCORSRule() {}

std::string& get_id() { return id; }
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit e9e86ad

Please sign in to comment.