I have searched everywhere for this and I could not find a single decent code. How can I access Amazon AWS S3 service using GSOAP?
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
Step 1
Use gSOAP's wsd2lh tool to convert Amazon's S3 WSDL to an interface header file aws-s3.h:
wsdl2h -t typemap.dat -o aws-s3.h http://doc.s3.amazonaws.com/2006-03-01/AmazonS3.wsdl
Use option
-c
to generate C source code instead of the default C++ source code. Thetypemap.dat
file is located in the gsoap directory of the gSOAP distribution.Step 2
Use the soapcpp2 tool on the header file created from the wsdl2h tool.
soapcpp2 -C -j aws-s3.h
This generates client-side code (
-C
option) with C++ service proxies and objects (-j
option) from the aws-s3.h header. Omit-j
for C code.Step 3
Use the auto-generated
AmazonS3SoapBindingProxy
proxy methods to access AWS S3 and create a base64-encoded, HMAC-SHA1 hashed signature for AWS S3. The signature is a string with the base64-encoded version of the HMAC-SHA1 hashed string"AmazonS3" + OPERATION_NAME + Timestamp
:The C code look similar, with the main difference being the use of function calls instead of method invocations, i.e.
soap_call___s3__CreateBucket(&createBucketReq, &createBucketRes)
. All this is explained in the generated aws-s4.h file.Compile the generated files with your source code:
The
SOAP_MAXDIMESIZE=104857600
ensures that DIME attachment sizes can be large enough while preventing denial of service attacks using DIME. The DIME header has the attachment size, so an attacker could set that arbitrary large to deplete memory resources. Other posts failed to mention this.Run
createbucket
, and a new bucket will be created.In the final .cpp file, note that we check the command line arguments (argv) when setting credentialsFile and bucketName. This allows the program to be called with arguments:
For more details on all of this, I suggest to read the excellent CodeProject article on How to use AWS S3 in C++ with gSOAP by Chris Moutsos from which parts of this explanation originates.
The code below is from the OP. Originally, the post contained both the question and the answer and I am turning it into a Q&A format.
The signature has to be of the format
The HMAC, SHA1and B64 utils are available in openssl.
The format for SOAP requests is given by the wsdl.
The REST interface is different.
After
wsdl2h
to generate the header and soapcpp2 to generate the GSOAP client code the following will be the code to access the service:Requirements : OpenSSL, GSOAP.
Build with the compiler preprocessor directive
WITH_OPENSSL
. Link with librarieslibeay32
andssleay32
.