PermitPlane Docs
All docs pages

Add licensing to a C or C++ app

At the end, your C or C++ app activates a licence key and unlocks its features offline.

From your product page in PermitPlane (app.permitplane.com/ops/vendor/), click Download permitplane.json and Create test key.

1. Install

Download permitplane-c-0.1.0-x86_64-pc-windows-msvc.zip for Windows x86_64. Compare its sha256 with the one in manifest.json. Unpack it, add include/ to your include path and link lib/permitplane:

PowerShell
$zip = ".\permitplane-c-0.1.0-x86_64-pc-windows-msvc.zip"
Get-FileHash -Algorithm SHA256 $zip
Expand-Archive $zip -DestinationPath C:\libs
Rename-Item "C:\libs\$((Get-Item $zip).BaseName)" permitplane

2. Activate a licence key

Open the client with the built-in storage, key, clock and HTTPS, then activate:

C
#include <stdio.h>
#include "permitplane.h"

int main(void) {
  pp_client *client = NULL;
  /* Reads the config and the saved state. */
  pp_status st =
      pp_client_open_default("permitplane.json", NULL, &client);
  if (st != PP_OK) return 1;

  // paste your test key here; in your real app, ask the user for it
  st = pp_client_activate_with_key(
      client, "PP-7KQ4M-X9T2H-B6WRN-3FJ8D", "Office PC");
  if (st != PP_OK)
    fprintf(stderr, "activate: %s\n", pp_status_code(st));

  /* ... unlock features here (step 3) ... */
  pp_client_free(client);
  return 0;
}

3. Unlock features in your app

Turn parts of your app on or off based on what the customer's licence includes. The check reads the signed grant and works offline up to your policy's offline days.

C
bool can_export = false;
pp_client_has_feature(client, "export", &can_export);
if (can_export) {
  enable_export();
} else {
  show_upgrade_offer();
}
C
pp_limit seats;
pp_client_feature_value(client, "seats", &seats);
/* seats.unlimited, or seats.value */

char status[512];
size_t len = 0;
pp_client_status(client, status, sizeof status, &len);
/* {"status":"paid","message":"...","activation_id":"...",...} */

4. Keep it current

  • Call pp_client_refresh on start and every hour.
  • Call pp_client_persist now and then and before exit.
  • Call pp_client_deactivate to release the device.

Errors

Every function returns a pp_status. pp_status_code gives its short name. pp_client_last_error gives the service's code as JSON.

ErrorWhat to do
Status not_a_license_keyThe key is mistyped. Ask the user to check it.
Service code invalid_license_keyThe key is unknown or revoked. Ask for the key from the purchase email.
Service code device_limitEvery device slot is taken. Deactivate another device first.
Service code license_expired, license_suspended or license_revokedShow a renew or contact link.
Status transportThe network failed. Retry later. Unlocked features keep working.
C
char err[512];
size_t n = 0;
if (st != PP_OK) pp_client_last_error(client, err, sizeof err, &n);

Going further

Reference

Package contents

  • include/permitplane.h and the header-only C++17 wrapper include/permitplane.hpp.
  • The DLL, import library and static library in lib/.
  • examples/verify_grant.c and a README with exact compiler lines.
  • The licence and the third-party notices.
  • Downloads need no sign-in. On Linux or macOS, check a file with sha256sum <file>.

Built-in host

pp_client_open_default(config_path, dir, &client) gives the client:

  • The saved state and a P-256 installation key, in files protected with DPAPI.
  • The folder %LOCALAPPDATA%\PermitPlane, or dir when it is not NULL. Files are named per product.
  • A monotonic clock that includes sleep, plus the boot id.
  • WinHTTP with the system proxy and certificate store. It sends HTTPS only, follows no redirects and accepts at most 1 MiB.

For a folder every user of the machine shares, call pp_client_new_default(config_json, PP_SCOPE_MACHINE, NULL, &client). It uses %ProgramData%\PermitPlane, open only to SYSTEM, Administrators and the creating user.

In an installer, create a folder per product first and pass it as dir:

PowerShell
$dir = "$env:ProgramData\PermitPlane\Acme\Widget"
New-Item -ItemType Directory -Force $dir | Out-Null
icacls $dir /inheritance:r `
  /grant:r "*S-1-5-18:(OI)(CI)F" "*S-1-5-32-544:(OI)(CI)F"
  • A folder or file that is a link, or that other accounts can open, fails with host.

Use your own storage or HTTP

Fill one pp_host and pass it to pp_client_new. Your functions take the arguments shown in permitplane.h.

C
pp_host host = {
    .struct_size = sizeof(pp_host),
    /* handed back to every callback; must outlive the client */
    .user_data = &my_app,
    /* load saved licence state from disk */
    .state_load = my_state_load,
    /* save licence state in protected storage */
    .state_save = my_state_save,
    /* delete the saved state */
    .state_clear = my_state_clear,
    /* create or load this device's P-256 key */
    .key_init = my_key_init,
    /* sign requests with this device's private key */
    .key_sign = my_key_sign,
    /* monotonic time, so clock changes can't extend a licence */
    .clock_observe = my_clock,
    /* send one HTTPS request; never follow redirects */
    .http_send = my_http,
};
pp_client *client = NULL;
pp_status st = pp_client_new(config_json, &host, &client);
  • The state holds a bearer installation token and the signed grant.
  • key_init returns the public key as 64 bytes: x then y.
  • key_sign writes 64 bytes: r then s.
  • Set confident = 0 in the clock sample if your clock skips suspend time or has no boot id.
  • Headers are plain Name: value\r\n blocks in both directions.
  • Return the server's nonce response header unchanged in the response.
  • The library adds the request proof, the nonce retry and the idempotency key.
  • It calls only the PermitPlane licensing endpoints on your origin.

Buffers and memory

  • Text outputs use your buffer.
  • To size one, call with buf = NULL, cap = 0, then call again.
  • The only memory you free is the client, with pp_client_free.

Status values

pp_client_status returns one of free, trial, paid, online_required, expired, recovery_required or seat_unavailable.

  • After a refresh, a suspended, expired or revoked licence shows in the status.
  • A revoked or released activation also clears the saved state.
  • pp_client_last_error returns {"code":...,"http_status":...,"message":...,"retry_after":...}.

Threading

  • You can share one client between threads.
  • The library serialises calls, so a feature check can wait for another thread's request.
  • A host callback must not call into the same client. That call fails with busy.

C++

C++
#include <iostream>
#include "permitplane.hpp"

auto client =
    permitplane::Client::open_default("permitplane.json");
try {
  client.activate_with_key("PP-7KQ4M-X9T2H-B6WRN-3FJ8D",
                           "Office PC");
} catch (const permitplane::Error& e) {
  std::cerr << e.code() << " " << e.detail() << "\n";
}
bool can_export = client.has_feature("export");
  • Methods: refresh(), persist(), deactivate(), feature_value(), status_json() and last_error_json().
  • Error::code() is the status name. Error::detail() holds the service's JSON.
  • For your own storage, implement permitplane::Host (see permitplane.hpp) and pass it to permitplane::Client(config_json, host).
  • The C boundary catches exceptions from your host methods. They surface as host errors.
  • The host object must outlive the client.

Floating seats

A floating licence holds a seat as a lease. The library has no timers, so you renew the lease yourself.

C
/* 0 = online lease; 1 to 504 = offline borrow, in hours */
if (pp_client_checkout_seat(client, 0) == PP_OK) {
  /* status JSON: "lease":{"kind":"online","ttl_seconds":598,...},"heartbeat_in_seconds":299 */
  /* From your timer, heartbeat_in_seconds after reading the status: */
  pp_client_renew_seat(client);
}
/* Give the seat back early. A borrow cannot be returned. */
pp_client_release_seat(client);
  • No free seat: checkout_seat fails with api and the service code seats_exhausted.
  • Try again after retry_after seconds from pp_client_last_error.
  • seats_exhausted and lease_required set the status to seat_unavailable.
  • The next successful checkout sets it back to paid.
  • lease_borrowed and not_floating change nothing.
  • C++: checkout_seat(), renew_seat() and release_seat().

Offline activation

C
char req[PP_OFFLINE_REQUEST_MAX_LEN];
size_t req_len = 0;
pp_client_create_offline_request(client, PP_OFFLINE_ACTIVATE,
                                 "Lab PC", req, sizeof req, &req_len);
/* Carry req to the vendor console. Bring the response back. */
pp_status ok = pp_client_import_offline_response(client, response);
C++
std::string file = client.create_offline_request(
    permitplane::Client::OfflineKind::Activate, "Lab PC");
client.import_offline_response(response_text);
  • The client accepts only the response to its pending request.
  • The response must match this installation key.
  • Rejections: request (another request), installation (another machine), import_expired (too late).
  • A rejected file stores nothing.
  • PP_OFFLINE_DEACTIVATE ends local rights at once. Its file frees the seat when the vendor processes it.

Build

CMake
add_executable(app main.c)
target_include_directories(app PRIVATE
  C:/libs/permitplane/include)
target_link_libraries(app PRIVATE
  C:/libs/permitplane/lib/permitplane.lib)  # .a file on Linux
if(WIN32)
  target_link_libraries(app PRIVATE bcrypt advapi32 kernel32 ntdll
                        userenv ws2_32 dbghelp crypt32 winhttp)
else()
  target_link_libraries(app PRIVATE pthread dl m)
endif()
  • On Windows, build with the dynamic runtime (/MD).
  • The static library needs crypt32 and winhttp for the built-in host.
  • For the shared library, link permitplane.dll.lib and ship permitplane.dll.
  • The archive README has the exact cl and cc lines.

Good to know

  • The library never stores the licence key.
  • You can safely retry an activation with the same key and device name after a lost response.
  • pp_client_persist saves the clock high-water mark.
  • pp_client_deactivate also clears the local state.