Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge 2a4d8a6 into b5a67f0
  • Loading branch information
ldachary committed Mar 10, 2015
2 parents b5a67f0 + 2a4d8a6 commit 6234b9c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/rgw/rgw_common.h
Expand Up @@ -849,7 +849,7 @@ struct req_info {

req_info(CephContext *cct, RGWEnv *_env);
void rebuild_from(req_info& src);
void init_meta_info(bool *found_nad_meta);
void init_meta_info(bool *found_bad_meta);
};

/** Store all the state necessary to complete and respond to an HTTP request*/
Expand Down
17 changes: 15 additions & 2 deletions src/rgw/rgw_op.cc
Expand Up @@ -1895,11 +1895,24 @@ void RGWPutMetadata::execute()
orig_attrs = s->bucket_attrs;
}

/* only remove meta attrs */
for (iter = orig_attrs.begin(); iter != orig_attrs.end(); ++iter) {
const string& name = iter->first;
/* check if the attr is user-defined metadata item */
if (name.compare(0, meta_prefix_len, meta_prefix) == 0) {
rmattrs[name] = iter->second;
if (is_object_op) {
/* for the objects all existing meta attrs have to be removed */
rmattrs[name] = iter->second;
} else {
/* for the buckets all existing meta attrs are preserved,
except those that are listed in rmattr_names. */
if (rmattr_names.find(name) != rmattr_names.end()) {
map<string, bufferlist>::iterator aiter = attrs.find(name);
if (aiter != attrs.end()) {
attrs.erase(aiter);
}
rmattrs[name] = iter->second;
}
}
} else if (attrs.find(name) == attrs.end()) {
attrs[name] = iter->second;
}
Expand Down
3 changes: 2 additions & 1 deletion src/rgw/rgw_op.h
Expand Up @@ -14,6 +14,7 @@
#include <limits.h>

#include <string>
#include <set>
#include <map>

#include "rgw_common.h"
Expand Down Expand Up @@ -402,7 +403,7 @@ class RGWPostObj : public RGWOp {
class RGWPutMetadata : public RGWOp {
protected:
int ret;
map<string, bufferlist> attrs;
set<string> rmattr_names;
bool has_policy, has_cors;
RGWAccessControlPolicy policy;
RGWCORSConfiguration cors_config;
Expand Down
50 changes: 36 additions & 14 deletions src/rgw/rgw_rest.cc
Expand Up @@ -76,10 +76,10 @@ string lowercase_underscore_http_attr(const string& orig)
for (size_t i = 0; i < orig.size(); ++i, ++s) {
switch (*s) {
case '-':
buf[i] = '_';
break;
buf[i] = '_';
break;
default:
buf[i] = tolower(*s);
buf[i] = tolower(*s);
}
}
return string(buf);
Expand All @@ -98,10 +98,32 @@ string uppercase_underscore_http_attr(const string& orig)
for (size_t i = 0; i < orig.size(); ++i, ++s) {
switch (*s) {
case '-':
buf[i] = '_';
break;
buf[i] = '_';
break;
default:
buf[i] = toupper(*s);
buf[i] = toupper(*s);
}
}
return string(buf);
}

/*
* make attrs look-like-this
* converts underscores to dashes
*/
string lowercase_dash_http_attr(const string& orig)
{
const char *s = orig.c_str();
char buf[orig.size() + 1];
buf[orig.size()] = '\0';

for (size_t i = 0; i < orig.size(); ++i, ++s) {
switch (*s) {
case '_':
buf[i] = '-';
break;
default:
buf[i] = tolower(*s);
}
}
return string(buf);
Expand All @@ -122,15 +144,15 @@ string camelcase_dash_http_attr(const string& orig)
for (size_t i = 0; i < orig.size(); ++i, ++s) {
switch (*s) {
case '_':
buf[i] = '-';
last_sep = true;
break;
buf[i] = '-';
last_sep = true;
break;
default:
if (last_sep)
buf[i] = toupper(*s);
else
buf[i] = tolower(*s);
last_sep = false;
if (last_sep)
buf[i] = toupper(*s);
else
buf[i] = tolower(*s);
last_sep = false;
}
}
return string(buf);
Expand Down
2 changes: 2 additions & 0 deletions src/rgw/rgw_rest.h
Expand Up @@ -12,6 +12,8 @@ extern std::map<std::string, std::string> rgw_to_http_attrs;

extern void rgw_rest_init(CephContext *cct);

extern string lowercase_dash_http_attr(const string& orig);

extern void rgw_flush_formatter_and_reset(struct req_state *s,
ceph::Formatter *formatter);

Expand Down
23 changes: 23 additions & 0 deletions src/rgw/rgw_rest_swift.cc
Expand Up @@ -424,6 +424,11 @@ void RGWPutObj_ObjStore_SWIFT::send_response()
rgw_flush_formatter_and_reset(s, s->formatter);
}

#define REMOVE_ATTR_PREFIX "HTTP_X_REMOVE_CONTAINER_META_"
#define PUT_ATTR_PREFIX "HTTP_X_CONTAINER_META_"
#define REMOVE_ATTR_PREFIX_LEN sizeof(REMOVE_ATTR_PREFIX) - 1
#define PUT_ATTR_PREFIX_LEN sizeof(PUT_ATTR_PREFIX) - 1

int RGWPutMetadata_ObjStore_SWIFT::get_params()
{
if (s->has_bad_meta)
Expand All @@ -434,6 +439,24 @@ int RGWPutMetadata_ObjStore_SWIFT::get_params()
if (r < 0) {
return r;
}
map<string, string, ltstr_nocase>& m = s->info.env->get_map();
map<string, string, ltstr_nocase>::iterator iter;
for (iter = m.begin(); iter != m.end(); ++iter) {
size_t prefix_len = 0;
const char *p = iter->first.c_str();
if (strncasecmp(p, REMOVE_ATTR_PREFIX, REMOVE_ATTR_PREFIX_LEN) == 0) {
// Explicitly requested removal
prefix_len = REMOVE_ATTR_PREFIX_LEN;
} else if ((strncasecmp(p, PUT_ATTR_PREFIX, PUT_ATTR_PREFIX_LEN) == 0) && iter->second.empty()) {
// Removal requested by putting an empty value
prefix_len = PUT_ATTR_PREFIX_LEN;
}
if (prefix_len > 0) {
string name(RGW_ATTR_META_PREFIX);
name.append(lowercase_dash_http_attr(p + prefix_len));
rmattr_names.insert(name);
}
}
}

return 0;
Expand Down

0 comments on commit 6234b9c

Please sign in to comment.