The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
8.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /**
  18. Contains information about whether your app has been unlocked for the current machine,
  19. and handles communication with the web-store to perform the unlock procedure.
  20. To use this class, create a subclass of it, and implement its pure virtual methods
  21. (see their comments to find out what you'll need to make them do).
  22. Then you can create an instance of your subclass which will hold the registration
  23. state. Typically, you'll want to just keep a single instance of the class around for
  24. the duration of your app. You can then call its methods to handle the various
  25. registration tasks.
  26. Areas of your code that need to know whether the user is registered (e.g. to decide
  27. whether a particular feature is available) should call isUnlocked() to find out.
  28. If you want to create a GUI that allows your users to enter their details and
  29. register, see the TracktionMarketplaceUnlockForm class.
  30. @see TracktionMarketplaceUnlockForm, TracktionMarketplaceKeyGeneration
  31. */
  32. class JUCE_API TracktionMarketplaceStatus
  33. {
  34. public:
  35. TracktionMarketplaceStatus();
  36. /** Destructor. */
  37. virtual ~TracktionMarketplaceStatus();
  38. //==============================================================================
  39. /** This must return your product's ID, as allocated by the store. */
  40. virtual String getMarketplaceProductID() = 0;
  41. /** This must return the RSA public key for authenticating responses from
  42. the server for this app. You can get this key from your marketplace
  43. account page.
  44. */
  45. virtual RSAKey getPublicKey() = 0;
  46. /** This method must store the given string somewhere in your app's
  47. persistent properties, so it can be retrieved later by getState().
  48. */
  49. virtual void saveState (const String&) = 0;
  50. /** This method must retrieve the last state that was provided by the
  51. saveState method.
  52. On first-run, it should just return an empty string.
  53. */
  54. virtual String getState() = 0;
  55. /** Returns a list of strings, any of which should be unique to this
  56. physical computer.
  57. When testing whether the user is allowed to use the product on this
  58. machine, this list of tokens is compared to the ones that were stored
  59. on the Tracktion marketplace webserver.
  60. The default implementation of this method will calculate some
  61. machine IDs based on things like network MAC addresses, hard-disk
  62. IDs, etc, but if you want, you can overload it to generate your
  63. own list of IDs.
  64. The IDs that are returned should be short alphanumeric strings
  65. without any punctuation characters. Since users may need to type
  66. them, case is ignored when comparing them.
  67. Note that the first item in the list is considered to be the
  68. "main" ID, and this will be the one that is displayed to the user
  69. and registered with the marketplace webserver. Subsequent IDs are
  70. just used as fallback to avoid false negatives when checking for
  71. registration on machines which have had hardware added/removed
  72. since the product was first registered.
  73. */
  74. virtual StringArray getLocalMachineIDs();
  75. /** Can be overridden if necessary, but by default returns the tracktion.com
  76. marketplace server.
  77. */
  78. virtual URL getServerAuthenticationURL();
  79. /** Can be overridden if necessary, but by default returns "tracktion.com". */
  80. virtual String getWebsiteName();
  81. //==============================================================================
  82. // The following methods can be called by your app:
  83. /** Returns true if the product has been successfully authorised for this machine.
  84. The reason it returns a variant rather than a bool is just to make it marginally
  85. more tedious for crackers to work around. Hopefully if this method gets inlined
  86. they'll need to hack all the places where you call it, rather than just the
  87. function itself.
  88. Bear in mind that each place where you check this return value will need to be
  89. changed by a cracker in order to unlock your app, so the more places you call this
  90. method, the more hassle it will be for them to find and crack them all.
  91. */
  92. inline var isUnlocked() const { return status[unlockedProp]; }
  93. /** Optionally allows the app to provide the user's email address if
  94. it is known.
  95. You don't need to call this, but if you do it may save the user
  96. typing it in.
  97. */
  98. void setUserEmail (const String& usernameOrEmail);
  99. /** Returns the user name if known. */
  100. String getUserEmail() const;
  101. /** Attempts to perform an unlock using a block of key-file data provided.
  102. You may wish to use this as a way of allowing a user to unlock your app
  103. by drag-and-dropping a file containing the key data, or by letting them
  104. select such a file. This is often needed for allowing registration on
  105. machines without internet access.
  106. */
  107. bool applyKeyFile (String keyFileContent);
  108. /** This provides some details about the reply that the server gave in a call
  109. to attemptWebserverUnlock().
  110. */
  111. struct UnlockResult
  112. {
  113. /** If an unlock operation fails, this is the error message that the webserver
  114. supplied (or a message saying that the server couldn't be contacted)
  115. */
  116. String errorMessage;
  117. /** This is a message that the webserver returned, and which the user should
  118. be shown.
  119. It's not necessarily an error message, e.g. it might say that there's a
  120. new version of the app available or some other status update.
  121. */
  122. String informativeMessage;
  123. /** If the webserver wants the user to be directed to a web-page for further
  124. information, this is the URL that it would like them to go to.
  125. */
  126. String urlToLaunch;
  127. /** If the unlock operation succeeded, this will be set to true. */
  128. bool succeeded;
  129. };
  130. /** Contacts the webserver and attempts to perform a registration with the
  131. given user details.
  132. The return value will either be a success, or a failure with an error message
  133. from the server, so you should show this message to your user.
  134. Note that this is designed for the Tracktion marketplace server - if you're
  135. building your own server, this function probably won't do the right thing for you.
  136. */
  137. UnlockResult attemptWebserverUnlock (const String& email, const String& password);
  138. /** Attempts to load the status from the state retrieved by getState().
  139. Call this somewhere in your app's startup code.
  140. */
  141. void load();
  142. /** Triggers a call to saveState which you can use to store the current unlock status
  143. in your app's settings.
  144. */
  145. void save();
  146. private:
  147. ValueTree status;
  148. UnlockResult handleXmlReply (XmlElement);
  149. UnlockResult handleFailedConnection();
  150. static const char* unlockedProp;
  151. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TracktionMarketplaceStatus)
  152. };