1#if !defined(VRAY_INTERNAL_LICENSING) || defined(VRAY_INTERNAL_GENERATE_IMPORT_CODE)
5#ifndef VRAY_INTERNAL_LICENSING
6#define VRAY_INTERNAL_LICENSING
10#if !defined(VRAY_RUNTIME_LOAD_PRIMARY) && !defined(VRAY_RUNTIME_LOAD_SECONDARY)
11# define VRAYSDK_FUNC(ret, name, ...) extern ret name(__VA_ARGS__)
12# define VRAYSDK_FUNCT VRAYSDK_FUNC
14# ifdef VRAY_RUNTIME_LOAD_SECONDARY
15# define VRAYSDK_FUNC(ret, name, ...) extern ret (*name)(__VA_ARGS__)
16# define VRAYSDK_FUNCT VRAYSDK_FUNC
18# ifndef VRAY_INTERNAL_GENERATE_IMPORT_CODE
19# define VRAYSDK_FUNC(ret, name, ...) ret (*name)(__VA_ARGS__) = nullptr
20# define VRAYSDK_FUNCT VRAYSDK_FUNC
22# define VRAYSDK_FUNC(ret, name, ...) \
23 if (!(Internal::name = (decltype(Internal::name))Internal::GetProcAddress(hLib, #name))) \
24 PROC_IMPORT_FAIL(#name)
25# define VRAYSDK_FUNCT(ret, name, ...) \
26 Internal::name = (decltype(Internal::name))Internal::GetProcAddress(hLib, #name)
31#ifndef VRAY_INTERNAL_GENERATE_IMPORT_CODE
53 const time_t currentTime = std::time(
nullptr);
54 return expiry -
static_cast<long long>(currentTime);
85 const time_t currentTime = std::time(
nullptr);
86 return expiry -
static_cast<long long>(currentTime);
91 AccessToken(
const AccessTokenView& view) :
104 email(view.email ? view.email :
""),
115#if !defined(VRAY_RUNTIME_LOAD_PRIMARY) && !defined(VRAY_RUNTIME_LOAD_SECONDARY)
119typedef void (*UnifiedLoginClient_onLogin)(
const ActiveUserDetailsView* userDetails,
void* userData);
120typedef void (*UnifiedLoginClient_onLogout)(
void* userData);
124VRAYSDK_FUNC(
void*, UnifiedLoginClient_init,
const char* newApplicationId,
unsigned initFlags,
void** errStrHandle);
125VRAYSDK_FUNC(Bool, UnifiedLoginClient_isInitialized);
126VRAYSDK_FUNC(
int, UnifiedLoginClient_startEventServer,
void** errStrHandle);
127VRAYSDK_FUNC(Bool, UnifiedLoginClient_isEventServerStarted);
128VRAYSDK_FUNC(
int, UnifiedLoginClient_getEventServerPort);
129VRAYSDK_FUNC(
void, UnifiedLoginClient_done);
130VRAYSDK_FUNC(
int, UnifiedLoginClient_setOnLogInOut, UnifiedLoginClient_onLogin loginCallback, UnifiedLoginClient_onLogout logoutCallback,
const void* userData);
131VRAYSDK_FUNC(
int, UnifiedLoginClient_getActiveUserDetails, ActiveUserDetailsView* details,
void** errStrHandle);
132VRAYSDK_FUNC(
int, UnifiedLoginClient_loginSync, ActiveUserDetailsView* details,
void** errStrHandle);
133VRAYSDK_FUNC(
int, UnifiedLoginClient_login,
void** errStrHandle);
134VRAYSDK_FUNC(
int, UnifiedLoginClient_logoutSync,
void** errStrHandle);
135VRAYSDK_FUNC(
int, UnifiedLoginClient_logout,
void** errStrHandle);
136VRAYSDK_FUNC(
void, UnifiedLoginClient_setSyncTimeout,
int timeoutMs);
137VRAYSDK_FUNC(
int, UnifiedLoginClient_setCustomPrompt,
const char *loginPrompt,
void** errHandle);
139#if VRAY_AUTH_MORE_STUFF
140VRAYSDK_FUNC(
int, iota_omega);
141VRAYSDK_FUNC(
void, iota_zeta);
142VRAYSDK_FUNC(
void, iota_rho,
unsigned,
unsigned);
143VRAYSDK_FUNC(
void, xi,
void(*)(
const char**,
const char**,
const char**,
const char**));
145VRAYSDK_FUNCT(
void, nu_lambda,
int type,
const char* typeDetails);
146VRAYSDK_FUNCT(
int, nu_rho,
int updateParameters);
147VRAYSDK_FUNCT(
int, nu_alpha);
150#ifndef VRAY_INTERNAL_GENERATE_IMPORT_CODE
152#if !defined(VRAY_RUNTIME_LOAD_PRIMARY) && !defined(VRAY_RUNTIME_LOAD_SECONDARY)
158#ifdef VRAY_RUNTIME_LOAD_PRIMARY
159class ULAClient :
private VRayInit {
169 typedef void (*OnLogout)(
void* userData);
174 flag_noEventServer = 1u << 0,
179#ifdef VRAY_RUNTIME_LOAD_PRIMARY
182# pragma warning(push)
183# pragma warning(disable: 4706)
187 void loadFunctions() {
188# define VRAY_INTERNAL_GENERATE_IMPORT_CODE
191# include "licensing.hpp"
192# undef VRAY_INTERNAL_GENERATE_IMPORT_CODE
200 static void load(VRayInit& vrayinit) {
201 static_cast<ULAClient&
>(vrayinit).loadFunctions();
212 static void*
init(
const char* newApplicationId,
unsigned initFlags, std::string& error) {
214 void* handle = Internal::UnifiedLoginClient_init(newApplicationId, initFlags, &errHandle);
215 error = Internal::getCharStringContent(&errHandle);
216 Internal::releaseCharString(&errHandle);
222 return !!Internal::UnifiedLoginClient_isInitialized();
228 int err = Internal::UnifiedLoginClient_startEventServer(&errHandle);
229 return returnErrorResult(err, &errHandle, error);
234 return !!Internal::UnifiedLoginClient_isEventServerStarted();
239 Internal::UnifiedLoginClient_done();
244 return Internal::UnifiedLoginClient_getEventServerPort();
250 return !Internal::UnifiedLoginClient_setOnLogInOut(loginCallback, logoutCallback, userData);
257 return returnActiveUserDetailsResult(
258 Internal::UnifiedLoginClient_getActiveUserDetails,
266 return returnActiveUserDetailsResult(
267 Internal::UnifiedLoginClient_loginSync,
273 static bool login(std::string& error) {
275 int err = Internal::UnifiedLoginClient_login(&errHandle);
276 return returnErrorResult(err, &errHandle, error);
284 int err = Internal::UnifiedLoginClient_logoutSync(&errHandle);
285 return returnErrorResult(err, &errHandle, error);
293 int err = Internal::UnifiedLoginClient_logout(&errHandle);
294 return returnErrorResult(err, &errHandle, error);
301 Internal::UnifiedLoginClient_setSyncTimeout(timeoutMs);
309 const int err = Internal::UnifiedLoginClient_setCustomPrompt(loginPrompt, &errHandle);
310 return returnErrorResult(err, &errHandle, error);
314 static bool returnActiveUserDetailsResult(
320 int err = activeUserDetailsFunc(&view, &errHandle);
322 userDetails.email = Internal::getCharStringContent(&view.email);
323 Internal::releaseCharString(&view.email);
324 userDetails.
uuid = Internal::getCharStringContent(&view.
uuid);
325 Internal::releaseCharString(&view.
uuid);
327 Internal::releaseCharString(&view.
firstName);
329 Internal::releaseCharString(&view.
lastName);
334 return returnErrorResult(err, &errHandle, error);
337 static bool returnErrorResult(
int err,
void** errStrHandle, std::string& error) {
338 error = Internal::getCharStringContent(errStrHandle);
339 Internal::releaseCharString(errStrHandle);
Definition: licensing.hpp:161
void(* OnLogin)(const ActiveUserDetailsView *activeUserDetails, void *userData)
activeUserDetails will never be nullptr
Definition: licensing.hpp:168
static bool login(std::string &error)
Definition: licensing.hpp:273
static void setSyncTimeout(int timeoutMs)
Definition: licensing.hpp:300
static void * init(const char *newApplicationId, unsigned initFlags, std::string &error)
Definition: licensing.hpp:212
static bool loginSync(ActiveUserDetails &userDetails, std::string &error)
Definition: licensing.hpp:265
static bool setOnLogInLogOut(OnLogin loginCallback, OnLogout logoutCallback, const void *userData=nullptr)
Definition: licensing.hpp:249
static bool isInitialized()
Returns true if the main part of the client is initialized (the event server is not checked).
Definition: licensing.hpp:221
static bool setCustomPrompt(const char *loginPrompt, std::string &error)
Definition: licensing.hpp:307
static bool isEventServerStarted()
Returns true if the event server has been started and is listening on a valid port.
Definition: licensing.hpp:233
static void done()
Stops the event server and clears other internally held resources.
Definition: licensing.hpp:238
static bool logout(std::string &error)
Definition: licensing.hpp:291
static bool startEventServer(std::string &error)
A function for dedicated start of the event server, in case the delayetServer flag was used during in...
Definition: licensing.hpp:226
Flags
A collection of flags that may be used to modify the way the client is used and what resources it wil...
Definition: licensing.hpp:172
@ flag_delayedServer
Disables the usage of a listening event server. A client with disabled server may be used for active ...
Definition: licensing.hpp:175
@ flag_default
Default initialization. Suitable for a single global instance, because it starts a dedicated listenin...
Definition: licensing.hpp:173
@ flag_uniqueProcess
Delays the start of the event server, either until explicitly started or until a synchronous login or...
Definition: licensing.hpp:176
static bool getActiveUserDetails(ActiveUserDetails &userDetails, std::string &error)
Definition: licensing.hpp:256
static int getEventServerPort()
Returns the port number on which the event server is listening. Returns 0 if the server is not starte...
Definition: licensing.hpp:243
static bool logoutSync(std::string &error)
Definition: licensing.hpp:282
Basic structure storing a string-based access token with its expiry information.
Definition: licensing.hpp:68
std::string token
The actual access token. Can be an arbitrarily long string in any format. Currently used mostly for J...
Definition: licensing.hpp:70
int isValid() const
Returns true if the token is still valid. This includes non-empty check for the token contents and ex...
Definition: licensing.hpp:76
long long getRelativeExpiry() const
Returns the number of seconds until the token would expire. A negative value is returned if the token...
Definition: licensing.hpp:81
long long expiry
Definition: licensing.hpp:73
Basic structure storing a string-based access token with its expiry information.
Definition: licensing.hpp:36
const char * token
The actual access token. Can be an arbitrarily long string in any format. Currently used mostly for J...
Definition: licensing.hpp:38
int isValid() const
Returns true if the token is still valid. This includes non-empty check for the token contents and ex...
Definition: licensing.hpp:44
long long getRelativeExpiry() const
Returns the number of seconds until the token would expire. A negative value is returned if the token...
Definition: licensing.hpp:49
long long expiry
Definition: licensing.hpp:41
Struct with the most relevant details for the actively logged in user.
Definition: licensing.hpp:96
ActiveUserDetails(const ActiveUserDetailsView &view)
An access token that may be used for communication with other Chaos services.
Definition: licensing.hpp:103
std::string firstName
The user UUID (unique universal identifier). Should always be a valid non-empty string (for valid det...
Definition: licensing.hpp:99
AccessToken userAccessToken
The registered last name of the user. May be an empty string.
Definition: licensing.hpp:101
std::string uuid
Contains the user email. Should always be a valid non-empty string (for valid details).
Definition: licensing.hpp:98
std::string lastName
The registered first name of the user. May be an empty string.
Definition: licensing.hpp:100
Struct with the most relevant details for the actively logged in user.
Definition: licensing.hpp:59
const char * lastName
The registered first name of the user. May be an empty string.
Definition: licensing.hpp:63
const char * firstName
The user UUID (unique universal identifier). Should always be a valid non-empty string (for valid det...
Definition: licensing.hpp:62
const char * uuid
Contains the user email. Should always be a valid non-empty string (for valid details).
Definition: licensing.hpp:61
AccessTokenView userAccessToken
The registered last name of the user. May be an empty string.
Definition: licensing.hpp:64