diff --git a/libdispatch/ds3util.c b/libdispatch/ds3util.c index e99e1433f5..ebc3853715 100644 --- a/libdispatch/ds3util.c +++ b/libdispatch/ds3util.c @@ -128,17 +128,24 @@ NC_s3urlrebuild(NCURI* url, NCS3INFO* s3, NCURI** newurlp) /* split the path by "/" */ if((stat = NC_split_delim(url->path,'/',pathsegments))) goto done; - /* Distinguish path-style from virtual-host style from s3: and from other. - Virtual: https://.s3..amazonaws.com/ (1) - or: https://.s3.amazonaws.com/ -- region defaults (to us-east-1) (2) - Path: https://s3..amazonaws.com// (3) - or: https://s3.amazonaws.com// -- region defaults to us-east-1 (4) - S3: s3:/// (5) - Google: https://storage.googleapis.com// (6) - or: gs3:/// (7) - Other: https://// (8) - */ - if(url->host == NULL || strlen(url->host) == 0) + /* Distinguish path-style from virtual-host style from s3: and from other. + Virtual: + (1) https://.s3..amazonaws.com/ + (2) https://.s3.amazonaws.com/ -- region defaults (to us-east-1) + Path: + (3) https://s3..amazonaws.com// + (4) https://s3.amazonaws.com// -- region defaults to us-east-1 + S3: + (5) s3:/// + Google: + (6) https://storage.googleapis.com// + (7) gs3:/// + Other: + (8) https://// + (9) https://.s3..domain.example.com/ + (10)https://s3..example.com// + */ + if(url->host == NULL || strlen(url->host) == 0) {stat = NC_EURL; goto done;} /* Reduce the host to standard form such as s3.amazonaws.com by pulling out the @@ -186,12 +193,21 @@ NC_s3urlrebuild(NCURI* url, NCS3INFO* s3, NCURI** newurlp) /* region is unknown */ /* bucket is unknown at this point */ svc = NCS3GS; - } else { /* Presume Format (8) */ - if((host = strdup(url->host))==NULL) - {stat = NC_ENOMEM; goto done;} - /* region is unknown */ - /* bucket is unknown */ - } + } else { /* Presume Formats (8),(9),(10) */ + if (nclistlength(hostsegments) > 3 && strcasecmp(nclistget(hostsegments, 1), "s3") == 0){ + bucket = nclistremove(hostsegments, 0); + region = nclistremove(hostsegments, 2); + host = strdup(url->host + sizeof(bucket) + 1); + }else{ + if (nclistlength(hostsegments) > 2 && strcasecmp(nclistget(hostsegments, 0), "s3") == 0){ + region = nclistremove(hostsegments, 1); + } + if ((host = strdup(url->host)) == NULL){ + stat = NC_ENOMEM; + goto done; + } + } + } /* region = (1) from url, (2) s3->region, (3) default */ if(region == NULL && s3 != NULL)