forked from mikulely/s3-cpp-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_service.cpp
90 lines (70 loc) · 2.71 KB
/
list_service.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <getopt.h>
#include <ctype.h>
#include "libs3.h"
static S3Status responsePropertiesCallback(const S3ResponseProperties *properties,
void *callbackData)
{
return S3StatusOK;
}
static void responseCompleteCallback(S3Status status,
const S3ErrorDetails *error,
void *callbackData)
{
}
static S3Status listServiceCallback(const char *ownerId,
const char *ownerDisplayName,
const char *bucketName,
int64_t creationDate, void *callbackData)
{
bool *header_printed = (bool*) callbackData;
if (!*header_printed) {
*header_printed = true;
printf("%-22s", " Bucket");
printf(" %-20s %-12s", " Owner ID", "Display Name");
printf("\n");
printf("----------------------");
printf(" --------------------" " ------------");
printf("\n");
}
printf("%-22s", bucketName);
printf(" %-20s %-12s", ownerId ? ownerId : "", ownerDisplayName ? ownerDisplayName : "");
printf("\n");
return S3StatusOK;
}
int main(int argc, char** args)
{
S3Protocol protocolG = S3ProtocolHTTP;
const char* accessKeyIdG = getenv("S3_ACCESS_KEY_ID");
const char* secretAccessKeyG = getenv("S3_SECRET_ACCESS_KEY");
S3Status status;
const char* hostname = getenv("S3_HOSTNAME");
if ((status = S3_initialize("s3", S3_INIT_ALL, hostname)) != S3StatusOK)
{
fprintf(stdout, "Failed to initialize libs3: %s\n", S3_get_status_name(status));
exit(-1);
}
S3ResponseHandler responseHandler = { &responsePropertiesCallback,
&responseCompleteCallback
};
S3ListServiceHandler listServiceHandler = { responseHandler,
&listServiceCallback
};
//----------------------list all owned bucket-----------------//
bool data = false;
S3_list_service(protocolG, accessKeyIdG, secretAccessKeyG, 0, 0, 0,
&listServiceHandler, &data);
//-----------------------create bucket------------------------//
const char* bucketName = "unitedstack-bucket";
S3_create_bucket(protocolG, accessKeyIdG, secretAccessKeyG, 0,
0, bucketName, S3CannedAclPrivate, 0, 0,
&responseHandler, 0);
S3_deinitialize();
return 0;
}