Skip to content

Commit 76d0884

Browse files
committed
[[ Trial ]] Add deployment of banner section to capsule.
The deploy command will now emit a banner section if the current license type is a trial. What the section contains is controlled by the PreDeploy hook which is implemented differently in commercial from community.
1 parent a5aa8fc commit 76d0884

6 files changed

Lines changed: 175 additions & 10 deletions

File tree

engine/src/capsule.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ enum MCCapsuleSectionType
101101
// AL-2015-02-10: [[ Standalone Inclusions ]] Library consists of the mappings from universal names
102102
// of resources to their platform-specific paths relative to the executable.
103103
kMCCapsuleSectionTypeLibrary,
104-
105-
// MW-2016-02-17: [[ LicenseChecks ]] License consists of the array-encoded
106-
// 'revLicenseInfo' array in use at the point the standalone was built.
107-
kMCCapsuleSectionTypeLicense,
104+
105+
// MW-2016-02-17: [[ LicenseChecks ]] License consists of the array-encoded
106+
// 'revLicenseInfo' array in use at the point the standalone was built.
107+
kMCCapsuleSectionTypeLicense,
108+
109+
// MW-2016-02-17: [[ Trial ]] If a banner is present, it is serialized as a
110+
// stackfile in this section.
111+
kMCCapsuleSectionTypeBanner,
108112
};
109113

110114
// Each section begins with a header that defines its type and length. This is
@@ -133,6 +137,8 @@ struct MCCapsuleEpilogueSection
133137
// The Prologue section is defined by the following structure:
134138
struct MCCapsulePrologueSection
135139
{
140+
uint32_t banner_timeout;
141+
uint32_t program_timeout;
136142
};
137143

138144
IO_stat MCCapsulePrologueSectionRead(IO_handle p_stream, MCCapsulePrologueSection& r_prologue);

engine/src/deploy.cpp

Lines changed: 125 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
8181
#include "deploy.h"
8282
#include "mode.h"
8383
#include "license.h"
84+
#include "stacksecurity.h"
8485

8586
#include "debug.h"
8687

@@ -353,6 +354,19 @@ bool MCDeployParameters::InitWithArray(MCExecContext &ctxt, MCArrayRef p_array)
353354
}
354355
}
355356

357+
// If the 'banner_class' string is present, then set the class override.
358+
MCAutoStringRef t_banner_class;
359+
if (!ctxt . CopyOptElementAsString(p_array, MCNAME("banner_class"), false, &t_banner_class))
360+
return false;
361+
if (MCStringIsEqualToCString(*t_banner_class,
362+
"commercial",
363+
kMCStringOptionCompareCaseless))
364+
banner_class = kMCLicenseClassEvaluation;
365+
else if (MCStringIsEqualToCString(*t_banner_class,
366+
"professional",
367+
kMCStringOptionCompareCaseless))
368+
banner_class = kMCLicenseClassProfessionalEvaluation;
369+
356370
return true;
357371
}
358372

@@ -361,6 +375,10 @@ bool MCDeployParameters::InitWithArray(MCExecContext &ctxt, MCArrayRef p_array)
361375
static bool MCDeployWriteDefinePrologueSection(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
362376
{
363377
MCCapsulePrologueSection t_prologue;
378+
t_prologue . banner_timeout = p_params . banner_timeout;
379+
t_prologue . program_timeout = p_params . timeout;
380+
381+
MCDeployByteSwapRecord(true, "ll", &t_prologue, sizeof(t_prologue));
364382

365383
return MCDeployCapsuleDefine(p_capsule, kMCCapsuleSectionTypePrologue, &t_prologue, sizeof(t_prologue));
366384
}
@@ -379,11 +397,13 @@ static bool MCDeployWriteDefineLicenseSection(const MCDeployParameters& p_params
379397
case kMCLicenseClassCommunity:
380398
t_edition = 1;
381399
break;
382-
400+
401+
case kMCLicenseClassEvaluation:
383402
case kMCLicenseClassCommercial:
384403
t_edition = 2;
385404
break;
386405

406+
case kMCLicenseClassProfessionalEvaluation:
387407
case kMCLicenseClassProfessional:
388408
t_edition = 3;
389409
break;
@@ -395,6 +415,11 @@ static bool MCDeployWriteDefineLicenseSection(const MCDeployParameters& p_params
395415
sizeof(t_edition));
396416
}
397417

418+
static bool MCDeployWriteDefineBannerSecion(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
419+
{
420+
return MCDeployCapsuleDefine(p_capsule, kMCCapsuleSectionTypeBanner, MCDataGetBytePtr(p_params . banner_stackfile), MCDataGetLength(p_params . banner_stackfile));
421+
}
422+
398423
// This method generates the standalone specific capsule elements. This is
399424
// just a Standalone Prologue section at the moment.
400425
static bool MCDeployWriteCapsuleDefineStandaloneSections(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
@@ -405,11 +430,16 @@ static bool MCDeployWriteCapsuleDefineStandaloneSections(const MCDeployParameter
405430
// First emit the prologue.
406431
if (t_success)
407432
t_success = MCDeployWriteDefinePrologueSection(p_params, p_capsule);
408-
409-
// Next emit the license info.
410-
if (t_success)
433+
434+
// Next emit the license info.
435+
if (t_success)
411436
t_success = MCDeployWriteDefineLicenseSection(p_params, p_capsule);
412437

438+
// Next emit the banner.
439+
if (t_success &&
440+
!MCDataIsEmpty(p_params . banner_stackfile))
441+
t_success = MCDeployWriteDefineBannerSecion(p_params, p_capsule);
442+
413443
return t_success;
414444
}
415445

@@ -710,11 +740,48 @@ void MCIdeDeploy::exec_ctxt(MCExecContext& ctxt)
710740
}
711741
#endif
712742

713-
// Now, if we are not licensed for a target, then its an error.
743+
// If the banner_class field is set and we are not a trial license, we
744+
// override the license class with that specified.
745+
uint32_t t_license_class;
746+
t_license_class = kMCLicenseClassNone;
747+
if (MClicenseparameters . license_class == kMCLicenseClassCommercial)
748+
{
749+
// If we have a commercial license, then we only allow a commercial
750+
// evaluation.
751+
if (t_params . banner_class == kMCLicenseClassEvaluation)
752+
t_license_class = kMCLicenseClassEvaluation;
753+
}
754+
else if (MClicenseparameters . license_class == kMCLicenseClassProfessional)
755+
{
756+
// If we are a professional license, then we allow any kind of
757+
// trial.
758+
t_license_class = t_params . banner_class;
759+
}
760+
761+
if (t_license_class == kMCLicenseClassNone)
762+
t_license_class = MClicenseparameters . license_class;
763+
764+
// Now check to see if we should build a trial - this if the license class is a
765+
// trail, or the banner_class override is specified and the chosen option is
766+
// compatible with the license class.
767+
bool t_is_trial;
768+
t_is_trial = false;
769+
if (t_license_class == kMCLicenseClassEvaluation ||
770+
t_license_class == kMCLicenseClassProfessionalEvaluation)
771+
t_is_trial = true;
772+
773+
// Now, if we are not licensed for a target, then its an error. If we are in trial
774+
// mode, however, all platforms are licensed (apart from embedded) they just will
775+
// timeout.
714776
bool t_is_licensed;
715777
t_is_licensed = false;
778+
716779
if (MCnoui && MClicenseparameters . license_class == kMCLicenseClassCommunity)
717780
t_is_licensed = true;
781+
else if (t_is_trial &&
782+
m_platform != PLATFORM_IOS_EMBEDDED &&
783+
m_platform != PLATFORM_ANDROID_EMBEDDED)
784+
t_is_licensed = true;
718785
else if (m_platform == PLATFORM_WINDOWS)
719786
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToWindows) != 0;
720787
else if (m_platform == PLATFORM_MACOSX)
@@ -738,7 +805,59 @@ void MCIdeDeploy::exec_ctxt(MCExecContext& ctxt)
738805
t_soft_error = true;
739806
t_has_error = true;
740807
}
741-
808+
809+
uint32_t t_platform;
810+
switch(m_platform)
811+
{
812+
case PLATFORM_MACOSX:
813+
t_platform = kMCLicenseDeployToMacOSX;
814+
break;
815+
case PLATFORM_WINDOWS:
816+
t_platform = kMCLicenseDeployToWindows;
817+
break;
818+
case PLATFORM_LINUX:
819+
t_platform = kMCLicenseDeployToLinux;
820+
break;
821+
case PLATFORM_IOS:
822+
t_platform = kMCLicenseDeployToIOS;
823+
break;
824+
case PLATFORM_ANDROID:
825+
t_platform = kMCLicenseDeployToAndroid;
826+
break;
827+
case PLATFORM_IOS_EMBEDDED:
828+
t_platform = kMCLicenseDeployToIOSEmbedded;
829+
break;
830+
case PLATFORM_ANDROID_EMBEDDED:
831+
t_platform = kMCLicenseDeployToAndroidEmbedded;
832+
break;
833+
case PLATFORM_EMSCRIPTEN:
834+
t_platform = kMCLicenseDeployToHTML5;
835+
break;
836+
}
837+
838+
if (!t_has_error)
839+
{
840+
// If this is a trial then set the timeout.
841+
if (t_is_trial)
842+
{
843+
if (m_platform != PLATFORM_IOS &&
844+
m_platform != PLATFORM_ANDROID &&
845+
m_platform != PLATFORM_EMSCRIPTEN)
846+
t_params . timeout = 5 * 60;
847+
else
848+
t_params . timeout = 1 * 60;
849+
850+
t_params . banner_timeout = 10;
851+
}
852+
853+
// Pass the deploy parameters through any stack security related steps.
854+
if (!MCStackSecurityPreDeploy(t_platform, t_params))
855+
{
856+
t_soft_error = true;
857+
t_has_error = true;
858+
}
859+
}
860+
742861
if (!t_has_error)
743862
{
744863
if (m_platform == PLATFORM_WINDOWS)

engine/src/deploy.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818
#define __MC_DEPLOY__
1919

2020
#include "mcio.h"
21+
#include "license.h"
2122

2223
////////////////////////////////////////////////////////////////////////////////
2324

@@ -108,6 +109,16 @@ struct MCDeployParameters
108109
// List of architectures to retain when building universal binaries
109110
MCAutoArray<MCDeployArchitecture> architectures;
110111

112+
// This can be set to commercial or professional trial. In that
113+
// case, the standalone will be built in that mode.
114+
uint32_t banner_class;
115+
116+
// The timeout for the banner that's displayed before startup.
117+
uint32_t banner_timeout;
118+
119+
// The data for the banner stackfile.
120+
MCDataRef banner_stackfile;
121+
111122

112123
MCDeployParameters()
113124
{
@@ -136,6 +147,10 @@ struct MCDeployParameters
136147
// SN-2015-02-04: [[ Merge-6.7.2 ]] Init the versions pointer / count
137148
min_os_versions = nil;
138149
min_os_version_count = 0;
150+
151+
banner_timeout = 0;
152+
banner_stackfile = MCValueRetain(kMCEmptyData);
153+
banner_class = kMCLicenseClassNone;
139154
}
140155

141156
~MCDeployParameters()
@@ -158,6 +173,7 @@ struct MCDeployParameters
158173
MCValueRelease(modules);
159174
MCValueRelease(library);
160175
MCMemoryDeleteArray(min_os_versions);
176+
MCValueRelease(banner_stackfile);
161177
}
162178

163179
// Creates using an array of parameters
@@ -436,6 +452,9 @@ enum MCDeployError
436452

437453
/* An error occurred while creating the startup stack */
438454
kMCDeployErrorEmscriptenBadStack,
455+
456+
/* An error occured with the pre-deploy step */
457+
kMCDeployErrorTrialBannerError,
439458

440459
// SIGN ERRORS
441460

engine/src/deploy_file.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ const char *MCDeployErrorToString(MCDeployError p_error)
313313

314314
case kMCDeployErrorEmscriptenBadStack:
315315
return "could not prepare startup stack";
316+
317+
case kMCDeployErrorTrialBannerError:
318+
return "could not create trial banner";
316319

317320
case kMCDeployErrorNoCertificate:
318321
return "could not load certificate";

engine/src/stacksecurity.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ IO_stat MCStackSecurityRead(char *r_string, uint32_t p_length, IO_handle p_strea
108108
void MCStackSecurityProcessCapsule(void *p_start, void *p_finish)
109109
{
110110
}
111+
112+
///////////
113+
114+
bool MCStackSecurityPreDeploy(uint32_t p_platform, MCDeployParameters& p_params)
115+
{
116+
return true;
117+
}
118+
119+
void MCStackSecurityExecutionTimeout(void)
120+
{
121+
}
122+
111123
////////////////////////////////////////////////////////////////////////////////
112124

113125
/* ================================================================

engine/src/stacksecurity.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ bool MCStackSecurityEmscriptenStartupCheck(MCStack *p_stack);
6363

6464
#endif /* __EMSCRIPTEN__ */
6565

66+
//////////
67+
68+
struct MCDeployParameters;
69+
bool MCStackSecurityPreDeploy(uint32_t p_platform, MCDeployParameters& p_params);
70+
void MCStackSecurityExecutionTimeout(void);
71+
6672
////////////////////////////////////////////////////////////////////////////////
6773

6874
#endif

0 commit comments

Comments
 (0)