Call is_prefix instead of compare and substr

This commit is contained in:
Andrew Gaul 2020-09-26 14:09:20 +09:00
parent 757f4caee8
commit 503c86bb8a
4 changed files with 15 additions and 15 deletions

View File

@ -410,7 +410,7 @@ bool StatCache::AddStat(const std::string& key, headers_t& meta, bool forcedir,
ent->meta[iter->first] = value;
}else if(tag == "last-modified"){
ent->meta[iter->first] = value;
}else if(tag.substr(0, 5) == "x-amz"){
}else if(is_prefix(tag.c_str(), "x-amz")){
ent->meta[tag] = value; // key is lower case for "x-amz"
}
}

View File

@ -617,7 +617,7 @@ size_t S3fsCurl::HeaderCallback(void* data, size_t blockSize, size_t numBlocks,
// Force to lower, only "x-amz"
std::string lkey = key;
transform(lkey.begin(), lkey.end(), lkey.begin(), static_cast<int (*)(int)>(std::tolower));
if(lkey.compare(0, 5, "x-amz") == 0){
if(is_prefix(lkey.c_str(), "x-amz")){
key = lkey;
}
std::string value;
@ -2904,7 +2904,7 @@ int S3fsCurl::HeadRequest(const char* tpath, headers_t& meta)
meta[iter->first] = value;
}else if(key == "last-modified"){
meta[iter->first] = value;
}else if(key.substr(0, 5) == "x-amz"){
}else if(is_prefix(key.c_str(), "x-amz")){
meta[key] = value; // key is lower case for "x-amz"
}
}
@ -2938,9 +2938,9 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
std::string key = lower(iter->first);
std::string value = iter->second;
if(key.substr(0, 9) == "x-amz-acl"){
if(is_prefix(key.c_str(), "x-amz-acl")){
// not set value, but after set it.
}else if(key.substr(0, 10) == "x-amz-meta"){
}else if(is_prefix(key.c_str(), "x-amz-meta")){
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
}else if(key == "x-amz-copy-source"){
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
@ -3077,9 +3077,9 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
std::string key = lower(iter->first);
std::string value = iter->second;
if(key.substr(0, 9) == "x-amz-acl"){
if(is_prefix(key.c_str(), "x-amz-acl")){
// not set value, but after set it.
}else if(key.substr(0, 10) == "x-amz-meta"){
}else if(is_prefix(key.c_str(), "x-amz-meta")){
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
}else if(key == "x-amz-server-side-encryption" && value != "aws:kms"){
// skip this header, because this header is specified after logic.
@ -3325,9 +3325,9 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, std::s
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
std::string key = lower(iter->first);
std::string value = iter->second;
if(key.substr(0, 9) == "x-amz-acl"){
if(is_prefix(key.c_str(), "x-amz-acl")){
// not set value, but after set it.
}else if(key.substr(0, 10) == "x-amz-meta"){
}else if(is_prefix(key.c_str(), "x-amz-meta")){
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
}else if(key == "x-amz-server-side-encryption" && value != "aws:kms"){
// Only copy mode.

View File

@ -323,9 +323,9 @@ std::string url_to_host(const std::string &url)
static const std::string https = "https://";
std::string hostname;
if (url.compare(0, http.size(), http) == 0) {
if (is_prefix(url.c_str(), http.c_str())) {
hostname = url.substr(http.size());
} else if (url.compare(0, https.size(), https) == 0) {
} else if (is_prefix(url.c_str(), https.c_str())) {
hostname = url.substr(https.size());
} else {
S3FS_PRN_EXIT("url does not begin with http:// or https://");

View File

@ -4284,13 +4284,13 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
}
if(is_prefix(arg, "ibm_iam_endpoint=")){
std::string endpoint_url;
std::string iam_endpoint = strchr(arg, '=') + sizeof(char);
const char *iam_endpoint = strchr(arg, '=') + sizeof(char);
// Check url for http / https protocol std::string
if((iam_endpoint.compare(0, 8, "https://") != 0) && (iam_endpoint.compare(0, 7, "http://") != 0)) {
if(!is_prefix(iam_endpoint, "https://") && !is_prefix(iam_endpoint, "http://")) {
S3FS_PRN_EXIT("option ibm_iam_endpoint has invalid format, missing http / https protocol");
return -1;
}
endpoint_url = iam_endpoint + "/oidc/token";
endpoint_url = std::string(iam_endpoint) + "/oidc/token";
S3fsCurl::SetIAMCredentialsURL(endpoint_url.c_str());
return 0;
}
@ -4495,7 +4495,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
length = s3host.length();
}
// Check url for http / https protocol std::string
if((s3host.compare(0, 8, "https://") != 0) && (s3host.compare(0, 7, "http://") != 0)) {
if(!is_prefix(s3host.c_str(), "https://") && !is_prefix(s3host.c_str(), "http://")){
S3FS_PRN_EXIT("option url has invalid format, missing http / https protocol");
return -1;
}