DescribeRuleGroup unicodeC Example
#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
HCkAuthAwsW authAws;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkStringBuilderW sbResponseBody;
int respStatusCode;
HCkJsonObjectW jResp;
const wchar_t *strVal;
const wchar_t *Action;
const wchar_t *Destination;
const wchar_t *DestinationPort;
const wchar_t *Direction;
const wchar_t *Protocol;
const wchar_t *Source;
const wchar_t *SourcePort;
int j;
int count_j;
const wchar_t *Keyword;
int k;
int count_k;
const wchar_t *ActionName;
const wchar_t *Value;
int Priority;
int FromPort;
int ToPort;
const wchar_t *AddressDefinition;
int intVal;
const wchar_t *Key;
const wchar_t *GeneratedRulesType;
const wchar_t *RulesString;
const wchar_t *RuleOrder;
int Capacity;
int ConsumedCapacity;
const wchar_t *Description;
const wchar_t *KeyId;
const wchar_t *v_Type;
int LastModifiedTime;
int NumberOfAssociations;
const wchar_t *RuleGroupArn;
const wchar_t *RuleGroupId;
const wchar_t *RuleGroupName;
const wchar_t *RuleGroupStatus;
const wchar_t *SnsTopic;
const wchar_t *SourceArn;
const wchar_t *SourceUpdateToken;
const wchar_t *RuleGroupResponseType;
const wchar_t *UpdateToken;
int i;
int count_i;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRestW_Create();
authAws = CkAuthAwsW_Create();
CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY");
CkAuthAwsW_putSecretKey(authAws,L"AWS_SECRET_KEY");
// Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
CkAuthAwsW_putRegion(authAws,L"us-west-2");
CkAuthAwsW_putServiceName(authAws,L"network-firewall");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRestW_SetAuthAws(rest,authAws);
// URL: https://network-firewall.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = CkRestW_Connect(rest,L"network-firewall.us-west-2.amazonaws.com",443,TRUE,TRUE);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
return;
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"RuleGroupArn",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroupName",L"string");
CkJsonObjectW_UpdateString(json,L"Type",L"string");
// The JSON request body created by the above code:
// {
// "RuleGroupArn": "string",
// "RuleGroupName": "string",
// "Type": "string"
// }
CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.0");
CkRestW_AddHeader(rest,L"X-Amz-Target",L"NetworkFirewall_20201112.DescribeRuleGroup");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestSb(rest,L"POST",L"/",sbRequestBody,sbResponseBody);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
wprintf(L"response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
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);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
GeneratedRulesType = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.RulesSourceList.GeneratedRulesType");
RulesString = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.RulesString");
RuleOrder = CkJsonObjectW_stringOf(jResp,L"RuleGroup.StatefulRuleOptions.RuleOrder");
Capacity = CkJsonObjectW_IntOf(jResp,L"RuleGroupResponse.Capacity");
ConsumedCapacity = CkJsonObjectW_IntOf(jResp,L"RuleGroupResponse.ConsumedCapacity");
Description = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.Description");
KeyId = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.EncryptionConfiguration.KeyId");
v_Type = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.EncryptionConfiguration.Type");
LastModifiedTime = CkJsonObjectW_IntOf(jResp,L"RuleGroupResponse.LastModifiedTime");
NumberOfAssociations = CkJsonObjectW_IntOf(jResp,L"RuleGroupResponse.NumberOfAssociations");
RuleGroupArn = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.RuleGroupArn");
RuleGroupId = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.RuleGroupId");
RuleGroupName = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.RuleGroupName");
RuleGroupStatus = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.RuleGroupStatus");
SnsTopic = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.SnsTopic");
SourceArn = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.SourceMetadata.SourceArn");
SourceUpdateToken = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.SourceMetadata.SourceUpdateToken");
RuleGroupResponseType = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.Type");
UpdateToken = CkJsonObjectW_stringOf(jResp,L"UpdateToken");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.RulesSourceList.Targets");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.RulesSourceList.Targets[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.RulesSourceList.TargetTypes");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.RulesSourceList.TargetTypes[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatefulRules");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
Action = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].Action");
Destination = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].Header.Destination");
DestinationPort = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].Header.DestinationPort");
Direction = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].Header.Direction");
Protocol = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].Header.Protocol");
Source = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].Header.Source");
SourcePort = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].Header.SourcePort");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatefulRules[i].RuleOptions");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
Keyword = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Keyword");
k = 0;
count_k = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Settings");
while (k < count_k) {
CkJsonObjectW_putK(jResp,k);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Settings[k]");
k = k + 1;
}
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
ActionName = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionName");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionDefinition.PublishMetricAction.Dimensions");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
Value = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionDefinition.PublishMetricAction.Dimensions[j].Value");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
Priority = CkJsonObjectW_IntOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].Priority");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.Actions");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.Actions[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
FromPort = CkJsonObjectW_IntOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts[j].FromPort");
ToPort = CkJsonObjectW_IntOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts[j].ToPort");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Destinations");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
AddressDefinition = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Destinations[j].AddressDefinition");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Protocols");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
intVal = CkJsonObjectW_IntOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Protocols[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
FromPort = CkJsonObjectW_IntOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts[j].FromPort");
ToPort = CkJsonObjectW_IntOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts[j].ToPort");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Sources");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
AddressDefinition = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Sources[j].AddressDefinition");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
k = 0;
count_k = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Flags");
while (k < count_k) {
CkJsonObjectW_putK(jResp,k);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Flags[k]");
k = k + 1;
}
k = 0;
count_k = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Masks");
while (k < count_k) {
CkJsonObjectW_putK(jResp,k);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Masks[k]");
k = k + 1;
}
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RuleVariables.IPSets.string.Definition");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RuleVariables.IPSets.string.Definition[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroup.RuleVariables.PortSets.string.Definition");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"RuleGroup.RuleVariables.PortSets.string.Definition[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"RuleGroupResponse.Tags");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
Key = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.Tags[i].Key");
Value = CkJsonObjectW_stringOf(jResp,L"RuleGroupResponse.Tags[i].Value");
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "RuleGroup": {
// "RulesSource": {
// "RulesSourceList": {
// "GeneratedRulesType": "string",
// "Targets": [
// "string"
// ],
// "TargetTypes": [
// "string"
// ]
// },
// "RulesString": "string",
// "StatefulRules": [
// {
// "Action": "string",
// "Header": {
// "Destination": "string",
// "DestinationPort": "string",
// "Direction": "string",
// "Protocol": "string",
// "Source": "string",
// "SourcePort": "string"
// },
// "RuleOptions": [
// {
// "Keyword": "string",
// "Settings": [
// "string"
// ]
// }
// ]
// }
// ],
// "StatelessRulesAndCustomActions": {
// "CustomActions": [
// {
// "ActionDefinition": {
// "PublishMetricAction": {
// "Dimensions": [
// {
// "Value": "string"
// }
// ]
// }
// },
// "ActionName": "string"
// }
// ],
// "StatelessRules": [
// {
// "Priority": number,
// "RuleDefinition": {
// "Actions": [
// "string"
// ],
// "MatchAttributes": {
// "DestinationPorts": [
// {
// "FromPort": number,
// "ToPort": number
// }
// ],
// "Destinations": [
// {
// "AddressDefinition": "string"
// }
// ],
// "Protocols": [
// number
// ],
// "SourcePorts": [
// {
// "FromPort": number,
// "ToPort": number
// }
// ],
// "Sources": [
// {
// "AddressDefinition": "string"
// }
// ],
// "TCPFlags": [
// {
// "Flags": [
// "string"
// ],
// "Masks": [
// "string"
// ]
// }
// ]
// }
// }
// }
// ]
// }
// },
// "RuleVariables": {
// "IPSets": {
// "string": {
// "Definition": [
// "string"
// ]
// }
// },
// "PortSets": {
// "string": {
// "Definition": [
// "string"
// ]
// }
// }
// },
// "StatefulRuleOptions": {
// "RuleOrder": "string"
// }
// },
// "RuleGroupResponse": {
// "Capacity": number,
// "ConsumedCapacity": number,
// "Description": "string",
// "EncryptionConfiguration": {
// "KeyId": "string",
// "Type": "string"
// },
// "LastModifiedTime": number,
// "NumberOfAssociations": number,
// "RuleGroupArn": "string",
// "RuleGroupId": "string",
// "RuleGroupName": "string",
// "RuleGroupStatus": "string",
// "SnsTopic": "string",
// "SourceMetadata": {
// "SourceArn": "string",
// "SourceUpdateToken": "string"
// },
// "Tags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "Type": "string"
// },
// "UpdateToken": "string"
// }
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}