UpdateRuleGroup 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 *Key;
const wchar_t *Value;
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"Description",L"string");
CkJsonObjectW_UpdateInt(json,L"DryRun",123);
CkJsonObjectW_UpdateString(json,L"EncryptionConfiguration.KeyId",L"string");
CkJsonObjectW_UpdateString(json,L"EncryptionConfiguration.Type",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.RulesSourceList.GeneratedRulesType",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.RulesSourceList.Targets[0]",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.RulesSourceList.TargetTypes[0]",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.RulesString",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].Action",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].Header.Destination",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].Header.DestinationPort",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].Header.Direction",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].Header.Protocol",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].Header.Source",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].Header.SourcePort",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].RuleOptions[0].Keyword",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatefulRules[0].RuleOptions[0].Settings[0]",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[0].ActionDefinition.PublishMetricAction.Dimensions[0].Value",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[0].ActionName",L"string");
CkJsonObjectW_UpdateInt(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].Priority",123);
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.Actions[0]",L"string");
CkJsonObjectW_UpdateInt(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.DestinationPorts[0].FromPort",123);
CkJsonObjectW_UpdateInt(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.DestinationPorts[0].ToPort",123);
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.Destinations[0].AddressDefinition",L"string");
ERROR: Undefined variable(number)
ERROR: Undefined variable(number)
ERROR: Undefined variable(number)
CkJsonObjectW_UpdateInt(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.Protocols[0]",number);ERROR: Undefined variable(number)
ERROR: Undefined variable(number)
ERROR: Undefined variable(number)
ERROR: Undefined variable(number)
ERROR: Undefined variable(number)
CkJsonObjectW_UpdateInt(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.SourcePorts[0].FromPort",123);
CkJsonObjectW_UpdateInt(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.SourcePorts[0].ToPort",123);
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.Sources[0].AddressDefinition",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.TCPFlags[0].Flags[0]",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.TCPFlags[0].Masks[0]",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RuleVariables.IPSets.string.Definition[0]",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.RuleVariables.PortSets.string.Definition[0]",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroup.StatefulRuleOptions.RuleOrder",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroupArn",L"string");
CkJsonObjectW_UpdateString(json,L"RuleGroupName",L"string");
CkJsonObjectW_UpdateString(json,L"Rules",L"string");
CkJsonObjectW_UpdateString(json,L"SourceMetadata.SourceArn",L"string");
CkJsonObjectW_UpdateString(json,L"SourceMetadata.SourceUpdateToken",L"string");
CkJsonObjectW_UpdateString(json,L"Type",L"string");
CkJsonObjectW_UpdateString(json,L"UpdateToken",L"string");
// The JSON request body created by the above code:
// {
// "Description": "string",
// "DryRun": boolean,
// "EncryptionConfiguration": {
// "KeyId": "string",
// "Type": "string"
// },
// "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"
// }
// },
// "RuleGroupArn": "string",
// "RuleGroupName": "string",
// "Rules": "string",
// "SourceMetadata": {
// "SourceArn": "string",
// "SourceUpdateToken": "string"
// },
// "Type": "string",
// "UpdateToken": "string"
// }
CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.0");
CkRestW_AddHeader(rest,L"X-Amz-Target",L"NetworkFirewall_20201112.UpdateRuleGroup");
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.
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"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:
// {
// "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);
}