Skip to content

Commit 9c041f2

Browse files
authored
Merge pull request #4314 from garlick/s3_cleanup
content-s3: cosmetic cleanup
2 parents d9c64e7 + 4200df5 commit 9c041f2

File tree

2 files changed

+55
-41
lines changed

2 files changed

+55
-41
lines changed

src/modules/content-s3/s3.c

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ struct cb_data {
4848
S3Status status;
4949
};
5050

51-
static S3Status response_props_cb (const S3ResponseProperties *properties, void *data)
51+
static S3Status response_props_cb (const S3ResponseProperties *properties,
52+
void *data)
5253
{
5354
return S3StatusOK;
5455
}
5556

56-
static void response_complete_cb (S3Status status, const S3ErrorDetails *error, void *data)
57+
static void response_complete_cb (S3Status status,
58+
const S3ErrorDetails *error,
59+
void *data)
5760
{
5861
struct cb_data *ctx = data;
5962
ctx->status = status;
@@ -65,7 +68,8 @@ static void response_complete_cb (S3Status status, const S3ErrorDetails *error,
6568
static int put_object_cb (int buff_size, char *buff, void *data)
6669
{
6770
struct cb_data *ctx = data;
68-
int size = (buff_size < ctx->size - ctx->count ? buff_size : ctx->size - ctx->count);
71+
int size = (buff_size < ctx->size - ctx->count ? buff_size
72+
: ctx->size - ctx->count);
6973

7074
memcpy (buff, ctx->data + ctx->count, size);
7175
ctx->count += size;
@@ -145,17 +149,20 @@ int s3_bucket_create (struct s3_config *cfg, const char **errstr)
145149
S3_create_bucket (protocol,
146150
cfg->access_key,
147151
cfg->secret_key,
148-
NULL, // hostName (NULL to use the same hostName passed to S3_initialize())
152+
NULL, // hostName (NULL=use hostName passed
153+
// to S3_initialize())
149154
cfg->bucket,
150155
S3CannedAclPrivate,
151156
NULL, // locationContstraint
152-
NULL, // requestContext (NULL for synchronous operation)
157+
NULL, // requestContext (NULL for synchronous
158+
// operation)
153159
&resp_hndl,
154160
&ctx);
155161
retries--;
156162
} while (S3_status_is_retryable (ctx.status) && retries > 0);
157163

158-
if (ctx.status != S3StatusOK && ctx.status != S3StatusErrorBucketAlreadyOwnedByYou) {
164+
if (ctx.status != S3StatusOK
165+
&& ctx.status != S3StatusErrorBucketAlreadyOwnedByYou) {
159166
errno = EREMOTEIO;
160167
if (errstr)
161168
*errstr = S3_get_status_name (status);
@@ -166,7 +173,11 @@ int s3_bucket_create (struct s3_config *cfg, const char **errstr)
166173
return 0;
167174
}
168175

169-
int s3_put (struct s3_config *cfg, const char *key, const void *data, size_t size, const char **errstr)
176+
int s3_put (struct s3_config *cfg,
177+
const char *key,
178+
const void *data,
179+
size_t size,
180+
const char **errstr)
170181
{
171182
int retries = cfg->retries;
172183
S3Status status = S3StatusOK;
@@ -190,7 +201,10 @@ int s3_put (struct s3_config *cfg, const char *key, const void *data, size_t siz
190201
.putObjectDataCallback = &put_object_cb
191202
};
192203

193-
if (strlen (key) == 0 || strchr (key, '/') || !strcmp (key, "..") || !strcmp (key, ".")) {
204+
if (strlen (key) == 0
205+
|| strchr (key, '/')
206+
|| !strcmp (key, "..")
207+
|| !strcmp (key, ".")) {
194208
errno = EINVAL;
195209
if (errstr)
196210
*errstr = "invalid key";
@@ -227,7 +241,11 @@ int s3_put (struct s3_config *cfg, const char *key, const void *data, size_t siz
227241
return 0;
228242
}
229243

230-
int s3_get (struct s3_config *cfg, const char *key, void **datap, size_t *sizep, const char **errstr)
244+
int s3_get (struct s3_config *cfg,
245+
const char *key,
246+
void **datap,
247+
size_t *sizep,
248+
const char **errstr)
231249
{
232250
int retries = cfg->retries;
233251
size_t size = 0;
@@ -260,7 +278,10 @@ int s3_get (struct s3_config *cfg, const char *key, void **datap, size_t *sizep,
260278
.status = status
261279
};
262280

263-
if (strlen (key) == 0 || strchr (key, '/') || !strcmp (key, "..") || !strcmp (key, ".")) {
281+
if (strlen (key) == 0
282+
|| strchr (key, '/')
283+
|| !strcmp (key, "..")
284+
|| !strcmp (key, ".")) {
264285
errno = EINVAL;
265286
if (errstr)
266287
*errstr = "invalid key";
@@ -273,14 +294,15 @@ int s3_get (struct s3_config *cfg, const char *key, void **datap, size_t *sizep,
273294
key,
274295
NULL, // getConditions (NULL for none)
275296
0, // startByte
276-
0, // byteCount (0 indicates the entire object should be read)
297+
0, // byteCount (0 indicates the entire object
298+
// should be read)
277299
NULL, // requestContext (NULL for synchronous operation)
278300
&get_obj_hndl, &ctx);
279301
retries--;
280302
} while (S3_status_is_retryable (ctx.status) && retries > 0);
281303

282304
if (ctx.status != S3StatusOK) {
283-
free(ctx.data);
305+
free (ctx.data);
284306
if (ctx.status == S3StatusErrorNoSuchKey)
285307
errno = ENOENT;
286308
else

src/modules/content-s3/s3.h

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,38 @@ struct s3_config {
2323
char *hostname; // hostname string
2424
};
2525

26+
/* All int-returning functions below return 0 on success. On failure,
27+
* they return -1 with errno set. In addition, if 'errstr' is non-NULL
28+
* on failure, it is assigned an S3 status string.
29+
*/
30+
2631
/* Initialize the s3 connection.
27-
* On success, an s3 connection to the endpoint is created
28-
* and S3StatusOK (0) is returned. On failure, a status
29-
* > 0 will be returned.
3032
*/
31-
int s3_init(struct s3_config *cfg, const char **errstr);
33+
int s3_init (struct s3_config *cfg, const char **errstr);
3234

3335
/* Close down the s3 connection.
3436
*/
35-
void s3_cleanup(void);
37+
void s3_cleanup (void);
3638

37-
/* Create a bucket on the s3 connection.
38-
* On success, a bucket will be created and 0 will be returned.
39-
* On failure, a -1 will be reuturned and a bucket
40-
* will not be created.
39+
/* Create a bucket to be used for subsequent put/get operations.
4140
*/
42-
int s3_bucket_create(struct s3_config *cfg, const char **errstr);
41+
int s3_bucket_create (struct s3_config *cfg, const char **errstr);
4342

44-
/* Put an object to the s3 bucket.
45-
* On success, the data will be put into the bucket
46-
* and 0 will be returned. On failure, the data will not put
47-
* to the bucket and -1 will be returned.
43+
/* Write 'data' of length 'size' to object named 'key'.
4844
*/
49-
int s3_put(struct s3_config *cfg,
50-
const char *key,
51-
const void *data,
52-
size_t size,
53-
const char **errstr);
45+
int s3_put (struct s3_config *cfg,
46+
const char *key,
47+
const void *data,
48+
size_t size,
49+
const char **errstr);
5450

55-
/* Get an object's data from the s3 bucket.
56-
* On success, the object with key 'key' will be retrieved
57-
* from the bucket and the data written to 'datap'
58-
* and 0 will be returned. On failure, the data will not
59-
* be retrieved from the bucket and -1 will be returned.
51+
/* Read 'datap', 'sizep' from object named 'key'.
6052
*/
61-
int s3_get(struct s3_config *cfg,
62-
const char *key,
63-
void **datap,
64-
size_t *sizep,
65-
const char **errstr);
53+
int s3_get (struct s3_config *cfg,
54+
const char *key,
55+
void **datap,
56+
size_t *sizep,
57+
const char **errstr);
6658

6759
#endif
6860

0 commit comments

Comments
 (0)