summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/acl.c15
-rw-r--r--src/bucket.c22
-rw-r--r--src/general.c14
-rw-r--r--src/object.c15
-rw-r--r--src/request.c23
-rw-r--r--src/s3.c24
-rw-r--r--src/service.c5
-rw-r--r--src/service_access_logging.c17
8 files changed, 86 insertions, 49 deletions
diff --git a/src/acl.c b/src/acl.c
index 2a8272b..25e4058 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -122,7 +122,8 @@ void S3_get_acl(const S3BucketContext *bucketContext, const char *key,
RequestParams params =
{
HttpRequestTypeGET, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
@@ -195,16 +196,13 @@ static S3Status generateAclXmlDocument(const char *ownerId,
const char *grantee;
switch (grant->granteeType) {
case S3GranteeTypeAllAwsUsers:
- grantee = "http://acs.amazonaws.com/groups/global/"
- "AuthenticatedUsers";
+ grantee = ACS_GROUP_AWS_USERS;
break;
case S3GranteeTypeAllUsers:
- grantee = "http://acs.amazonaws.com/groups/global/"
- "AllUsers";
+ grantee = ACS_GROUP_ALL_USERS;
break;
default:
- grantee = "http://acs.amazonaws.com/groups/s3/"
- "LogDelivery";
+ grantee = ACS_GROUP_LOG_DELIVERY;
break;
}
append("Group\"><URI>%s</URI>", grantee);
@@ -322,7 +320,8 @@ void S3_set_acl(const S3BucketContext *bucketContext, const char *key,
RequestParams params =
{
HttpRequestTypePUT, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
diff --git a/src/bucket.c b/src/bucket.c
index 9bac3ca..f4f1987 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -107,7 +107,8 @@ static void testBucketCompleteCallback(S3Status requestStatus,
void S3_test_bucket(S3Protocol protocol, S3UriStyle uriStyle,
const char *accessKeyId, const char *secretAccessKey,
- const char *bucketName, int locationConstraintReturnSize,
+ const char *hostName, const char *bucketName,
+ int locationConstraintReturnSize,
char *locationConstraintReturn,
S3RequestContext *requestContext,
const S3ResponseHandler *handler, void *callbackData)
@@ -134,7 +135,8 @@ void S3_test_bucket(S3Protocol protocol, S3UriStyle uriStyle,
RequestParams params =
{
HttpRequestTypeGET, // httpRequestType
- { bucketName, // bucketName
+ { hostName, // hostName
+ bucketName, // bucketName
protocol, // protocol
uriStyle, // uriStyle
accessKeyId, // accessKeyId
@@ -223,8 +225,9 @@ static void createBucketCompleteCallback(S3Status requestStatus,
void S3_create_bucket(S3Protocol protocol, const char *accessKeyId,
- const char *secretAccessKey, const char *bucketName,
- S3CannedAcl cannedAcl, const char *locationConstraint,
+ const char *secretAccessKey, const char *hostName,
+ const char *bucketName, S3CannedAcl cannedAcl,
+ const char *locationConstraint,
S3RequestContext *requestContext,
const S3ResponseHandler *handler, void *callbackData)
{
@@ -270,7 +273,8 @@ void S3_create_bucket(S3Protocol protocol, const char *accessKeyId,
RequestParams params =
{
HttpRequestTypePUT, // httpRequestType
- { bucketName, // bucketName
+ { hostName, // hostName
+ bucketName, // bucketName
protocol, // protocol
S3UriStylePath, // uriStyle
accessKeyId, // accessKeyId
@@ -332,7 +336,7 @@ static void deleteBucketCompleteCallback(S3Status requestStatus,
void S3_delete_bucket(S3Protocol protocol, S3UriStyle uriStyle,
const char *accessKeyId, const char *secretAccessKey,
- const char *bucketName,
+ const char *hostName, const char *bucketName,
S3RequestContext *requestContext,
const S3ResponseHandler *handler, void *callbackData)
{
@@ -352,7 +356,8 @@ void S3_delete_bucket(S3Protocol protocol, S3UriStyle uriStyle,
RequestParams params =
{
HttpRequestTypeDELETE, // httpRequestType
- { bucketName, // bucketName
+ { hostName, // hostName
+ bucketName, // bucketName
protocol, // protocol
uriStyle, // uriStyle
accessKeyId, // accessKeyId
@@ -710,7 +715,8 @@ void S3_list_bucket(const S3BucketContext *bucketContext, const char *prefix,
RequestParams params =
{
HttpRequestTypeGET, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
diff --git a/src/general.c b/src/general.c
index 861c289..fb30c37 100644
--- a/src/general.c
+++ b/src/general.c
@@ -32,13 +32,14 @@
static int initializeCountG = 0;
-S3Status S3_initialize(const char *userAgentInfo, int flags)
+S3Status S3_initialize(const char *userAgentInfo, int flags,
+ const char *defaultS3HostName)
{
if (initializeCountG++) {
return S3StatusOK;
}
- return request_api_initialize(userAgentInfo, flags);
+ return request_api_initialize(userAgentInfo, flags, defaultS3HostName);
}
@@ -372,18 +373,15 @@ static S3Status convertAclXmlCallback(const char *elementPath,
}
else if (caData->groupUri[0]) {
if (!strcmp(caData->groupUri,
- "http://acs.amazonaws.com/groups/global/"
- "AuthenticatedUsers")) {
+ ACS_GROUP_AWS_USERS)) {
grant->granteeType = S3GranteeTypeAllAwsUsers;
}
else if (!strcmp(caData->groupUri,
- "http://acs.amazonaws.com/groups/global/"
- "AllUsers")) {
+ ACS_GROUP_ALL_USERS)) {
grant->granteeType = S3GranteeTypeAllUsers;
}
else if (!strcmp(caData->groupUri,
- "http://acs.amazonaws.com/groups/s3/"
- "LogDelivery")) {
+ ACS_GROUP_LOG_DELIVERY)) {
grant->granteeType = S3GranteeTypeLogDelivery;
}
else {
diff --git a/src/object.c b/src/object.c
index 9f1d33b..d7c7f80 100644
--- a/src/object.c
+++ b/src/object.c
@@ -42,7 +42,8 @@ void S3_put_object(const S3BucketContext *bucketContext, const char *key,
RequestParams params =
{
HttpRequestTypePUT, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
@@ -199,7 +200,8 @@ void S3_copy_object(const S3BucketContext *bucketContext, const char *key,
RequestParams params =
{
HttpRequestTypeCOPY, // httpRequestType
- { destinationBucket ? destinationBucket :
+ { bucketContext->hostName, // hostName
+ destinationBucket ? destinationBucket :
bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
@@ -239,7 +241,8 @@ void S3_get_object(const S3BucketContext *bucketContext, const char *key,
RequestParams params =
{
HttpRequestTypeGET, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
@@ -276,7 +279,8 @@ void S3_head_object(const S3BucketContext *bucketContext, const char *key,
RequestParams params =
{
HttpRequestTypeHEAD, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
@@ -313,7 +317,8 @@ void S3_delete_object(const S3BucketContext *bucketContext, const char *key,
RequestParams params =
{
HttpRequestTypeDELETE, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
diff --git a/src/request.c b/src/request.c
index 646c26c..b267a5e 100644
--- a/src/request.c
+++ b/src/request.c
@@ -46,6 +46,8 @@ static Request *requestStackG[REQUEST_STACK_SIZE];
static int requestStackCountG;
+char defaultHostNameG[S3_MAX_HOSTNAME_SIZE];
+
typedef struct RequestComputedValues
{
@@ -755,17 +757,20 @@ static S3Status compose_uri(char *buffer, int bufferSize,
uri_append("http%s://",
(bucketContext->protocol == S3ProtocolHTTP) ? "" : "s");
+ const char *hostName =
+ bucketContext->hostName ? bucketContext->hostName : defaultHostNameG;
+
if (bucketContext->bucketName &&
bucketContext->bucketName[0]) {
if (bucketContext->uriStyle == S3UriStyleVirtualHost) {
- uri_append("%s.s3.amazonaws.com", bucketContext->bucketName);
+ uri_append("%s.%s", bucketContext->bucketName, hostName);
}
else {
- uri_append("s3.amazonaws.com/%s", bucketContext->bucketName);
+ uri_append("%s/%s", hostName, bucketContext->bucketName);
}
}
else {
- uri_append("%s", "s3.amazonaws.com");
+ uri_append("%s", hostName);
}
uri_append("%s", "/");
@@ -1058,7 +1063,8 @@ static void request_release(Request *request)
}
-S3Status request_api_initialize(const char *userAgentInfo, int flags)
+S3Status request_api_initialize(const char *userAgentInfo, int flags,
+ const char *defaultHostName)
{
if (curl_global_init(CURL_GLOBAL_ALL &
~((flags & S3_INIT_WINSOCK) ? 0 : CURL_GLOBAL_WIN32))
@@ -1066,6 +1072,15 @@ S3Status request_api_initialize(const char *userAgentInfo, int flags)
return S3StatusInternalError;
}
+ if (!defaultHostName) {
+ defaultHostName = S3_DEFAULT_HOSTNAME;
+ }
+
+ if (snprintf(defaultHostNameG, S3_MAX_HOSTNAME_SIZE,
+ "%s", defaultHostName) >= S3_MAX_HOSTNAME_SIZE) {
+ return S3StatusUriTooLong;
+ }
+
pthread_mutex_init(&requestStackMutexG, 0);
requestStackCountG = 0;
diff --git a/src/s3.c b/src/s3.c
index 0eda6de..65acc52 100644
--- a/src/s3.c
+++ b/src/s3.c
@@ -144,7 +144,9 @@ static char putenvBufG[256];
static void S3_init()
{
S3Status status;
- if ((status = S3_initialize("s3", S3_INIT_ALL))
+ const char *hostname = getenv("S3_HOSTNAME");
+
+ if ((status = S3_initialize("s3", S3_INIT_ALL, hostname))
!= S3StatusOK) {
fprintf(stderr, "Failed to initialize libs3: %s\n",
S3_get_status_name(status));
@@ -184,6 +186,7 @@ static void usageExit(FILE *out)
"\n"
" S3_ACCESS_KEY_ID : S3 access key ID (required)\n"
" S3_SECRET_ACCESS_KEY : S3 secret access key (required)\n"
+" S3_HOSTNAME : specify alternative S3 host (optional)\n"
"\n"
" Commands (with <required parameters> and [optional parameters]) :\n"
"\n"
@@ -862,7 +865,7 @@ static void list_service(int allDetails)
};
do {
- S3_list_service(protocolG, accessKeyIdG, secretAccessKeyG, 0,
+ S3_list_service(protocolG, accessKeyIdG, secretAccessKeyG, 0, 0,
&listServiceHandler, &data);
} while (S3_status_is_retryable(statusG) && should_retry());
@@ -906,7 +909,7 @@ static void test_bucket(int argc, char **argv, int optindex)
char locationConstraint[64];
do {
S3_test_bucket(protocolG, uriStyleG, accessKeyIdG, secretAccessKeyG,
- bucketName, sizeof(locationConstraint),
+ 0, bucketName, sizeof(locationConstraint),
locationConstraint, 0, &responseHandler, 0);
} while (S3_status_is_retryable(statusG) && should_retry());
@@ -1005,7 +1008,7 @@ static void create_bucket(int argc, char **argv, int optindex)
do {
S3_create_bucket(protocolG, accessKeyIdG, secretAccessKeyG,
- bucketName, cannedAcl, locationConstraint, 0,
+ 0, bucketName, cannedAcl, locationConstraint, 0,
&responseHandler, 0);
} while (S3_status_is_retryable(statusG) && should_retry());
@@ -1045,7 +1048,7 @@ static void delete_bucket(int argc, char **argv, int optindex)
do {
S3_delete_bucket(protocolG, uriStyleG, accessKeyIdG, secretAccessKeyG,
- bucketName, 0, &responseHandler, 0);
+ 0, bucketName, 0, &responseHandler, 0);
} while (S3_status_is_retryable(statusG) && should_retry());
if (statusG != S3StatusOK) {
@@ -1196,6 +1199,7 @@ static void list_bucket(const char *bucketName, const char *prefix,
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -1315,6 +1319,7 @@ static void delete_object(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -1575,6 +1580,7 @@ static void put_object(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -1761,6 +1767,7 @@ static void copy_object(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
sourceBucketName,
protocolG,
uriStyleG,
@@ -1940,6 +1947,7 @@ static void get_object(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -2013,6 +2021,7 @@ static void head_object(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -2091,6 +2100,7 @@ static void generate_query_string(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -2192,6 +2202,7 @@ void get_acl(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -2354,6 +2365,7 @@ void set_acl(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -2445,6 +2457,7 @@ void get_logging(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
@@ -2610,6 +2623,7 @@ void set_logging(int argc, char **argv, int optindex)
S3BucketContext bucketContext =
{
+ 0,
bucketName,
protocolG,
uriStyleG,
diff --git a/src/service.c b/src/service.c
index 68b3ff8..2d1e038 100644
--- a/src/service.c
+++ b/src/service.c
@@ -131,7 +131,7 @@ static void completeCallback(S3Status requestStatus,
void S3_list_service(S3Protocol protocol, const char *accessKeyId,
- const char *secretAccessKey,
+ const char *secretAccessKey, const char *hostName,
S3RequestContext *requestContext,
const S3ListServiceHandler *handler, void *callbackData)
{
@@ -161,7 +161,8 @@ void S3_list_service(S3Protocol protocol, const char *accessKeyId,
RequestParams params =
{
HttpRequestTypeGET, // httpRequestType
- { 0, // bucketName
+ { hostName, // hostName
+ 0, // bucketName
protocol, // protocol
S3UriStylePath, // uriStyle
accessKeyId, // accessKeyId
diff --git a/src/service_access_logging.c b/src/service_access_logging.c
index cbed2c1..22c6e40 100644
--- a/src/service_access_logging.c
+++ b/src/service_access_logging.c
@@ -147,13 +147,11 @@ static S3Status convertBlsXmlCallback(const char *elementPath,
}
else if (caData->groupUri[0]) {
if (!strcmp(caData->groupUri,
- "http://acs.amazonaws.com/groups/global/"
- "AuthenticatedUsers")) {
+ ACS_GROUP_AWS_USERS)) {
grant->granteeType = S3GranteeTypeAllAwsUsers;
}
else if (!strcmp(caData->groupUri,
- "http://acs.amazonaws.com/groups/global/"
- "AllUsers")) {
+ ACS_GROUP_ALL_USERS)) {
grant->granteeType = S3GranteeTypeAllUsers;
}
else {
@@ -325,7 +323,8 @@ void S3_get_server_access_logging(const S3BucketContext *bucketContext,
RequestParams params =
{
HttpRequestTypeGET, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId
@@ -405,10 +404,9 @@ static S3Status generateSalXmlDocument(const char *targetBucket,
grant->grantee.canonicalUser.displayName);
break;
default: // case S3GranteeTypeAllAwsUsers/S3GranteeTypeAllUsers:
- append("Group\"><URI>http://acs.amazonaws.com/groups/"
- "global/%s</URI>",
+ append("Group\"><URI>%s</URI>",
(grant->granteeType == S3GranteeTypeAllAwsUsers) ?
- "AuthenticatedUsers" : "AllUsers");
+ ACS_GROUP_AWS_USERS : ACS_GROUP_ALL_USERS);
break;
}
append("</Grantee><Permission>%s</Permission></Grant>",
@@ -529,7 +527,8 @@ void S3_set_server_access_logging(const S3BucketContext *bucketContext,
RequestParams params =
{
HttpRequestTypePUT, // httpRequestType
- { bucketContext->bucketName, // bucketName
+ { bucketContext->hostName, // hostName
+ bucketContext->bucketName, // bucketName
bucketContext->protocol, // protocol
bucketContext->uriStyle, // uriStyle
bucketContext->accessKeyId, // accessKeyId