Sample code for 30+ languages & platforms
Unicode C

Example: Secrets.SecretSpecToJson method

Demonstrates the SecretSpecToJson method. This method converts a secret specification string to the JSON required to create or lookup the secret.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkSecretsW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSecretsW secrets;
    HCkJsonObjectW json;
    const wchar_t *sspec;

    success = FALSE;

    secrets = CkSecretsW_Create();
    json = CkJsonObjectW_Create();
    CkJsonObjectW_putEmitCompact(json,FALSE);

    //  A secret name can include up to 4 components:
    //  [appName] / service / [domain] / username

    //  This example will demonstrate secret specification strings
    //  for each possible combination.

    //  ------------------------------------------------------
    //  1: service + username
    sspec = L"!!imap|john@example.com";

    CkSecretsW_SecretSpecToJson(secrets,sspec,json);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    //  Result:
    //  {
    //    "service": "imap",
    //    "username": "john@example.com"
    //  }

    //  ------------------------------------------------------
    //  2: appName + service + username
    sspec = L"!!myApp|imap|john@example.com";

    CkSecretsW_SecretSpecToJson(secrets,sspec,json);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    //  Result:
    //  {
    //    "appName": "myApp",
    //    "service": "imap",
    //    "username": "john@example.com"
    //  }

    //  ------------------------------------------------------
    //  3: service + domain + username
    sspec = L"!!|imap|imap.example.com|john";

    CkSecretsW_SecretSpecToJson(secrets,sspec,json);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    //  Result:
    //  {
    //    "service": "imap",
    //    "domain": "imap.example.com",
    //    "username": "john"
    //  }

    //  ------------------------------------------------------
    //  4: appName + service + domain + username
    sspec = L"!!myApp|imap|imap.example.com|john";

    CkSecretsW_SecretSpecToJson(secrets,sspec,json);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    //  Result:
    //  {
    //    "appName": "myApp",
    //    "service": "imap",
    //    "domain": "imap.example.com",
    //    "username": "john"
    //  }


    CkSecretsW_Dispose(secrets);
    CkJsonObjectW_Dispose(json);

    }