initial commit

This commit is contained in:
NeilClack
2026-08-07 14:51:41 -05:00
commit 9251b3a196
604 changed files with 464448 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
#pragma once
#include "db/database_manager.h"
#include <string>
namespace radiantwave::license {
// NOTE: the system_kv keys where the validated subscription level is persisted
// live in db/db_keys.h (KV_SUBSCRIPTION_LEVEL_*).
enum class Result {
Ok, // license valid; subscription level persisted to the DB
NotConfigured, // email and/or license key missing from the DB
Invalid, // API rejected the pair (bad key, wrong user, inactive, ...)
NetworkError, // the request never completed
};
// How long a previously-validated license stays valid without a successful
// re-validation (7 days). Network failures within this window after the last
// successful check do not invalidate the license; the user has the whole
// window to reconnect so the "last verified" stamp can be refreshed.
constexpr long long GRACE_PERIOD_SECONDS = 7LL * 24 * 60 * 60;
// Validates the stored license key against the stored email address via the
// portal API. On success the subscription level (id/name/description) is
// written to the DB; on failure the stored level is left untouched so a
// previous good value survives a transient outage. Returns NotConfigured
// without touching the network when either value is missing. Never throws.
//
// `outLevelName` / `outErrorMessage` are optional out-params.
Result validateStoredLicense(radiantwave::db::DatabaseManager& db,
const std::string& apiKey = "",
std::string* outLevelName = nullptr,
std::string* outErrorMessage = nullptr);
// Returns the subscription level id currently stored after a successful
// license validation. Returns 0 when no validated license is on record.
int getStoredSubscriptionLevelId(const radiantwave::db::DatabaseManager& db);
// Human-readable name for a subscription level id (Basic / Advanced / Elite).
// Falls back to a generic label for unknown ids.
std::string subscriptionLevelName(int levelId);
// Numeric id for a subscription level name (case-insensitive match against
// Basic / Advanced / Elite). Returns 0 for an unknown or empty name.
int subscriptionLevelIdForName(const std::string& name);
// Records the current time as the "last verified" stamp of the license. Called
// after every successful server validation so the offline grace window starts
// (or is extended) from the most recent confirmation.
void markLicenseVerified(radiantwave::db::DatabaseManager& db);
// True when a prior successful validation happened within
// GRACE_PERIOD_SECONDS of now. Returns false when no stamp is stored or the
// stamp is corrupted or older than the grace window.
bool isLicenseWithinGracePeriod(const radiantwave::db::DatabaseManager& db);
} // namespace radiantwave::license