int RGWPutObj::verify_permission()
{
- if (copy_source) {
+ if (! copy_source.empty()) {
RGWAccessControlPolicy cs_acl(s->cct);
boost::optional<Policy> policy;
store->set_prefetch_data(s->obj_ctx, obj);
/* check source object permissions */
- if (read_obj_policy(store, s, copy_source_bucket_info, cs_attrs, &cs_acl, policy,
- cs_bucket, cs_object) < 0) {
+ if (read_obj_policy(store, s, copy_source_bucket_info, cs_attrs, &cs_acl,
+ policy, cs_bucket, cs_object) < 0) {
return -EACCES;
}
bufferlist data;
if (fst > lst)
break;
- if (!copy_source) {
+ if (copy_source.empty()) {
len = get_data(data);
} else {
uint64_t cur_lst = min(fst + s->cct->_conf->rgw_max_chunk_size - 1, lst);
}
}
-
-bool RGWCopyObj::parse_copy_location(const string& url_src, string& bucket_name, rgw_obj_key& key)
+bool RGWCopyObj::parse_copy_location(const boost::string_view& url_src,
+ string& bucket_name,
+ rgw_obj_key& key)
{
- string name_str;
- string params_str;
+ boost::string_view name_str;
+ boost::string_view params_str;
size_t pos = url_src.find('?');
if (pos == string::npos) {
params_str = url_src.substr(pos + 1);
}
- std::string dec_src = url_decode(name_str);
- const char *src = dec_src.c_str();
-
- if (*src == '/') ++src;
+ boost::string_view dec_src{name_str};
+ if (dec_src[0] == '/')
+ dec_src.remove_prefix(1);
- string str(src);
-
- pos = str.find('/');
+ pos = dec_src.find('/');
if (pos ==string::npos)
return false;
- bucket_name = str.substr(0, pos);
- key.name = str.substr(pos + 1);
+ boost::string_view bn_view{dec_src.substr(0, pos)};
+ bucket_name = std::string{bn_view.data(), bn_view.size()};
+
+ boost::string_view kn_view{dec_src.substr(pos + 1)};
+ key.name = std::string{kn_view.data(), kn_view.size()};
if (key.name.empty()) {
return false;
}
- if (!params_str.empty()) {
+ if (! params_str.empty()) {
RGWHTTPArgs args;
- args.set(params_str);
+ args.set(params_str.to_string());
args.parse();
key.instance = args.get("versionId", NULL);
const char *supplied_etag;
const char *if_match;
const char *if_nomatch;
- const char *copy_source;
+ std::string copy_source;
const char *copy_source_range;
RGWBucketInfo copy_source_bucket_info;
string copy_source_tenant_name;
supplied_etag(NULL),
if_match(NULL),
if_nomatch(NULL),
- copy_source(NULL),
copy_source_range(NULL),
copy_source_range_fst(0),
copy_source_range_lst(0),
copy_if_newer = false;
}
- static bool parse_copy_location(const string& src,
+ static bool parse_copy_location(const boost::string_view& src,
string& bucket_name,
rgw_obj_key& object);
if_match = s->info.env->get("HTTP_IF_MATCH");
if_nomatch = s->info.env->get("HTTP_IF_NONE_MATCH");
- copy_source = s->info.env->get("HTTP_X_AMZ_COPY_SOURCE");
+ copy_source = url_decode(s->info.env->get("HTTP_X_AMZ_COPY_SOURCE", ""));
copy_source_range = s->info.env->get("HTTP_X_AMZ_COPY_SOURCE_RANGE");
/* handle x-amz-copy-source */
-
- if (copy_source) {
- if (*copy_source == '/') ++copy_source;
- copy_source_bucket_name = copy_source;
+ boost::string_view cs_view(copy_source);
+ if (! cs_view.empty()) {
+ if (cs_view[0] == '/')
+ cs_view.remove_prefix(1);
+ copy_source_bucket_name = cs_view.to_string();
pos = copy_source_bucket_name.find("/");
if (pos == std::string::npos) {
ret = -EINVAL;
ldout(s->cct, 5) << "x-amz-copy-source bad format" << dendl;
return ret;
}
- copy_source_object_name = copy_source_bucket_name.substr(pos + 1, copy_source_bucket_name.size());
+ copy_source_object_name =
+ copy_source_bucket_name.substr(pos + 1, copy_source_bucket_name.size());
copy_source_bucket_name = copy_source_bucket_name.substr(0, pos);
#define VERSION_ID_STR "?versionId="
pos = copy_source_object_name.find(VERSION_ID_STR);
if (pos == std::string::npos) {
copy_source_object_name = url_decode(copy_source_object_name);
} else {
- copy_source_version_id = copy_source_object_name.substr(pos + sizeof(VERSION_ID_STR) - 1);
- copy_source_object_name = url_decode(copy_source_object_name.substr(0, pos));
+ copy_source_version_id =
+ copy_source_object_name.substr(pos + sizeof(VERSION_ID_STR) - 1);
+ copy_source_object_name =
+ url_decode(copy_source_object_name.substr(0, pos));
}
pos = copy_source_bucket_name.find(":");
if (pos == std::string::npos) {
s->cct->_conf->rgw_s3_success_create_obj_status);
set_req_state_err(s, op_ret);
}
- if (!copy_source) {
+ if (copy_source.empty()) {
dump_errno(s);
dump_etag(s, etag);
dump_content_length(s, 0);
s->has_acl_header = s->info.env->exists_prefix("HTTP_X_AMZ_GRANT");
const char *copy_source = s->info.env->get("HTTP_X_AMZ_COPY_SOURCE");
-
- if (copy_source && !s->info.env->get("HTTP_X_AMZ_COPY_SOURCE_RANGE")) {
- ret = RGWCopyObj::parse_copy_location(copy_source,
- s->init_state.src_bucket,
- s->src_object);
+ if (copy_source &&
+ (! s->info.env->get("HTTP_X_AMZ_COPY_SOURCE_RANGE"))) {
+ ret = RGWCopyObj::parse_copy_location(url_decode(copy_source),
+ s->init_state.src_bucket,
+ s->src_object);
if (!ret) {
ldout(s->cct, 0) << "failed to parse copy location" << dendl;
return -EINVAL; // XXX why not -ERR_INVALID_BUCKET_NAME or -ERR_BAD_URL?
s->dialect = "swift";
- const char *copy_source = s->info.env->get("HTTP_X_COPY_FROM");
- if (copy_source) {
+ std::string copy_source =
+ url_decode(s->info.env->get("HTTP_X_COPY_FROM", ""));
+ if (! copy_source.empty()) {
bool result = RGWCopyObj::parse_copy_location(copy_source, t->src_bucket,
s->src_object);
if (!result)
}
if (s->op == OP_COPY) {
- const char *req_dest = s->info.env->get("HTTP_DESTINATION");
- if (!req_dest)
+ std::string req_dest =
+ url_decode(s->info.env->get("HTTP_DESTINATION", ""));
+ if (req_dest.empty())
return -ERR_BAD_URL;
- string dest_bucket_name;
+ std::string dest_bucket_name;
rgw_obj_key dest_obj_key;
bool result =
RGWCopyObj::parse_copy_location(req_dest, dest_bucket_name,
if (!result)
return -ERR_BAD_URL;
- string dest_object = dest_obj_key.name;
+ std::string dest_object = dest_obj_key.name;
/* convert COPY operation into PUT */
t->src_bucket = t->url_bucket;