Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Unicode C Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks

Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
Office365
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Unicode C) Amazon Glacier Get Vault Access Policy

Demonstrates how to retrieve the access-policy subresource set on the vault

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    BOOL success;
    HCkAuthAwsW authAws;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW json;
    HCkJsonObjectW jsonPolicy;
    const wchar_t *Version;
    int i;
    int count_i;
    const wchar_t *Sid;
    const wchar_t *Effect;
    const wchar_t *PrincipalAWS;
    const wchar_t *Action;
    const wchar_t *Resource;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    rest = CkRestW_Create();

    // Connect to the Amazon AWS REST server in the desired region.
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"glacier.us-west-2.amazonaws.com",port,bTls,bAutoReconnect);

    // Provide AWS credentials.
    authAws = CkAuthAwsW_Create();
    CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY");
    CkAuthAwsW_putSecretKey(authAws,L"AWS_SECRET_KEY");
    CkAuthAwsW_putServiceName(authAws,L"glacier");
    CkAuthAwsW_putRegion(authAws,L"us-west-2");

    success = CkRestW_SetAuthAws(rest,authAws);

    // --------------------------------------------------------------------------
    // Note: The above REST connection and setup of the AWS credentials
    // can be done once.  After connecting, any number of REST calls can be made.
    // The "auto reconnect" property passed to rest.Connect indicates that if
    // the connection is lost, a REST method call will automatically reconnect
    // if needed.
    // --------------------------------------------------------------------------

    // 
    // For more information, see Glacier Get Vault Access Policy Reference Documentation
    // 
    CkRestW_AddHeader(rest,L"x-amz-glacier-version",L"2012-06-01");

    // Get the access policy for the "chilkat" vault.
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/AWS_ACCOUNT_ID/vaults/chilkat/access-policy",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    // Success is indicated by a 200 response status.
    wprintf(L"response status code = %d\n",respStatusCode);

    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sbResponseBody);
    CkJsonObjectW_putEmitCompact(json,FALSE);

    // Returns JSON such as this:
    // {
    //   "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Define-owner-access-rights\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::9999999999999:root\"},\"Action\":\"glacier:DeleteArchive\",\"Resource\":\"arn:aws:glacier:us-west-2:9999999999999:vaults/chilkat\"}]}"
    // }

    // Unwrap...
    jsonPolicy = CkJsonObjectW_Create();
    CkJsonObjectW_Load(jsonPolicy,CkJsonObjectW_stringOf(json,L"Policy"));
    CkJsonObjectW_putEmitCompact(jsonPolicy,FALSE);

    wprintf(L"%s\n",CkJsonObjectW_emit(jsonPolicy));
    wprintf(L"----\n");

    // The jsonPolicy contains:

    // {
    //   "Version": "2012-10-17",
    //   "Statement": [
    //     {
    //       "Sid": "Define-owner-access-rights",
    //       "Effect": "Allow",
    //       "Principal": {
    //         "AWS": "arn:aws:iam::9999999999999:root"
    //       },
    //       "Action": "glacier:DeleteArchive",
    //       "Resource": "arn:aws:glacier:us-west-2:9999999999999:vaults/chilkat"
    //     }
    //   ]
    // }
    // 

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // To parse the above contents of jsonPolicy...

    Version = CkJsonObjectW_stringOf(jsonPolicy,L"Version");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonPolicy,L"Statement");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonPolicy,i);
        Sid = CkJsonObjectW_stringOf(jsonPolicy,L"Statement[i].Sid");
        Effect = CkJsonObjectW_stringOf(jsonPolicy,L"Statement[i].Effect");
        PrincipalAWS = CkJsonObjectW_stringOf(jsonPolicy,L"Statement[i].Principal.AWS");
        Action = CkJsonObjectW_stringOf(jsonPolicy,L"Statement[i].Action");
        Resource = CkJsonObjectW_stringOf(jsonPolicy,L"Statement[i].Resource");
        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkAuthAwsW_Dispose(authAws);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(json);
    CkJsonObjectW_Dispose(jsonPolicy);

    }

 

© 2000-2020 Chilkat Software, Inc. All Rights Reserved.