![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Invalidating Dependent Variables When Inputs ChangeSee more CURL ExamplesThis example demonstrates how After a multi-step execution plan runs successfully, variables such as However, if an input variable is cleared using For example, if Note: This example requires Chilkat v11.5.0 or greater. For more information, see https://www.chilkatsoft.com/curl_dependency_engine.asp
#include <C_CkHttpCurlW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { BOOL success; HCkHttpCurlW httpCurl; const wchar_t *targetCurl; const wchar_t *fnName; HCkJsonObjectW jsonOAuth2; HCkJsonObjectW planJson; success = FALSE; httpCurl = CkHttpCurlW_Create(); // The target curl command we ultimately want to execute. // It requires drive_id. targetCurl = L"curl -X GET https://graph.microsoft.com/v1.0/drives/{{drive_id}}/root/children"; // Define a helper function that produces drive_id. // This requires site_id. fnName = L"getDrives"; CkHttpCurlW_AddFunction(httpCurl,fnName,L"curl -X GET https://graph.microsoft.com/v1.0/sites/{{site_id}}/drives"); CkHttpCurlW_AddOutput(httpCurl,fnName,L"value[0].id",L"drive_id"); // Define another helper function that produces site_id. // This requires site_name. fnName = L"getSite"; CkHttpCurlW_AddFunction(httpCurl,fnName,L"curl -X GET https://graph.microsoft.com/v1.0/sites/root:/sites/{{site_name}}"); CkHttpCurlW_AddOutput(httpCurl,fnName,L"id",L"site_id"); // site_name is the starting known value. CkHttpCurlW_SetVar(httpCurl,L"site_name",L"test"); // Configure OAuth2 authentication. jsonOAuth2 = CkJsonObjectW_Create(); CkJsonObjectW_putEnableSecrets(jsonOAuth2,TRUE); CkJsonObjectW_UpdateString(jsonOAuth2,L"oauth2.client_id",L"!!sharepoint|oauth2|client_id"); CkJsonObjectW_UpdateString(jsonOAuth2,L"oauth2.client_secret",L"!!sharepoint|oauth2|client_secret"); CkJsonObjectW_UpdateString(jsonOAuth2,L"oauth2.scope",L"https://graph.microsoft.com/.default"); CkJsonObjectW_UpdateString(jsonOAuth2,L"oauth2.token_endpoint",L"!!sharepoint|oauth2|token_endpoint"); CkHttpCurlW_SetAuth(httpCurl,jsonOAuth2); // ----------------------------------------------------------------------------- // First execution plan: // site_id and drive_id are not known yet, so the full dependency chain is needed. // ----------------------------------------------------------------------------- planJson = CkJsonObjectW_Create(); CkJsonObjectW_putEmitCompact(planJson,FALSE); wprintf(L"Execution plan before first call:\n"); success = CkHttpCurlW_ExaminePlan(httpCurl,targetCurl,planJson); wprintf(L"%s\n",CkJsonObjectW_emit(planJson)); // Expected: // // { // "plan": [{ // "function": "getSite", // "inputs": ["site_name"], // "outputs": ["site_id"] // },{ // "function": "getDrives", // "inputs": ["site_id"], // "outputs": ["drive_id"] // },{ // "function": "targetCurl", // "inputs": ["drive_id"], // "outputs": [] // }] // } success = CkHttpCurlW_DoYourThing(httpCurl,targetCurl); if (success == FALSE) { wprintf(L"%s\n",CkHttpCurlW_lastErrorText(httpCurl)); CkHttpCurlW_Dispose(httpCurl); CkJsonObjectW_Dispose(jsonOAuth2); CkJsonObjectW_Dispose(planJson); return; } wprintf(L"After first call:\n"); wprintf(L"site_id = %s\n",CkHttpCurlW_getVar(httpCurl,L"site_id")); wprintf(L"drive_id = %s\n",CkHttpCurlW_getVar(httpCurl,L"drive_id")); // ----------------------------------------------------------------------------- // Second execution plan: // site_id and drive_id are now known, so only the target curl command is needed. // ----------------------------------------------------------------------------- wprintf(L"Execution plan after first call:\n"); success = CkHttpCurlW_ExaminePlan(httpCurl,targetCurl,planJson); wprintf(L"%s\n",CkJsonObjectW_emit(planJson)); // Expected: // // { // "plan": [{ // "function": "targetCurl", // "inputs": ["drive_id"], // "outputs": [] // }] // } // ----------------------------------------------------------------------------- // Change the original input. // Because site_id was produced from site_name, changing site_name invalidates site_id. // Because drive_id depends on site_id, drive_id is also invalidated. // ----------------------------------------------------------------------------- // Note: Make sure this site exists on in your SharePoint... CkHttpCurlW_SetVar(httpCurl,L"site_name",L"anotherSite"); wprintf(L"After changing site_name:\n"); wprintf(L"site_id defined? %d\n",CkHttpCurlW_VarDefined(httpCurl,L"site_id")); wprintf(L"drive_id defined? %d\n",CkHttpCurlW_VarDefined(httpCurl,L"drive_id")); // ----------------------------------------------------------------------------- // The execution plan is automatically rebuilt. // Since site_id and drive_id were invalidated, the full dependency chain is needed again. // ----------------------------------------------------------------------------- wprintf(L"Execution plan after changing site_name:\n"); success = CkHttpCurlW_ExaminePlan(httpCurl,targetCurl,planJson); wprintf(L"%s\n",CkJsonObjectW_emit(planJson)); // Expected: // // { // "plan": [{ // "function": "getSite", // "inputs": ["site_name"], // "outputs": ["site_id"] // },{ // "function": "getDrives", // "inputs": ["site_id"], // "outputs": ["drive_id"] // },{ // "function": "targetCurl", // "inputs": ["drive_id"], // "outputs": [] // }] // } success = CkHttpCurlW_DoYourThing(httpCurl,targetCurl); if (success == FALSE) { wprintf(L"%s\n",CkHttpCurlW_lastErrorText(httpCurl)); CkHttpCurlW_Dispose(httpCurl); CkJsonObjectW_Dispose(jsonOAuth2); CkJsonObjectW_Dispose(planJson); return; } wprintf(L"After running again with the new site_name:\n"); wprintf(L"site_id = %s\n",CkHttpCurlW_getVar(httpCurl,L"site_id")); wprintf(L"drive_id = %s\n",CkHttpCurlW_getVar(httpCurl,L"drive_id")); // ----------------------------------------------------------------------------- // Clearing a variable also invalidates values that depend on it. // Here, clearing site_id also invalidates drive_id. // ----------------------------------------------------------------------------- CkHttpCurlW_ClearVar(httpCurl,L"site_id"); wprintf(L"After clearing site_id:\n"); wprintf(L"site_id defined? %d\n",CkHttpCurlW_VarDefined(httpCurl,L"site_id")); wprintf(L"drive_id defined? %d\n",CkHttpCurlW_VarDefined(httpCurl,L"drive_id")); wprintf(L"Execution plan after clearing site_id:\n"); success = CkHttpCurlW_ExaminePlan(httpCurl,targetCurl,planJson); wprintf(L"%s\n",CkJsonObjectW_emit(planJson)); // Expected: // // { // "plan": [{ // "function": "getSite", // "inputs": ["site_name"], // "outputs": ["site_id"] // },{ // "function": "getDrives", // "inputs": ["site_id"], // "outputs": ["drive_id"] // },{ // "function": "targetCurl", // "inputs": ["drive_id"], // "outputs": [] // }] // } CkHttpCurlW_Dispose(httpCurl); CkJsonObjectW_Dispose(jsonOAuth2); CkJsonObjectW_Dispose(planJson); } |
||||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.