llmediaentry.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * @file llmediaentry.h
  3. * @brief This is a single instance of media data related to the face of a prim
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLMEDIAENTRY_H
  33. #define LL_LLMEDIAENTRY_H
  34. #include "lllslconstants.h" // For return values of set*
  35. #include "llsd.h"
  36. #include "llstring.h"
  37. class LLMediaEntry final
  38. {
  39. public:
  40. enum MediaControls
  41. {
  42. STANDARD = 0,
  43. MINI
  44. };
  45. // Constructors
  46. LLMediaEntry();
  47. LLMediaEntry(const LLMediaEntry& rhs);
  48. LLMediaEntry& operator=(const LLMediaEntry& rhs);
  49. ~LLMediaEntry();
  50. bool operator==(const LLMediaEntry& rhs) const;
  51. bool operator!=(const LLMediaEntry& rhs) const;
  52. // Render as LLSD
  53. LLSD asLLSD() const;
  54. void asLLSD(LLSD& sd) const;
  55. operator LLSD() const { return asLLSD(); }
  56. // Returns false iff the given LLSD contains fields that violate any bounds
  57. // limits.
  58. static bool checkLLSD(const LLSD& sd);
  59. // This doesn't merge, it overwrites the data, so will use
  60. // LLSD defaults if need be. Note: does not check limits!
  61. // Use checkLLSD() above first to ensure the LLSD is valid.
  62. void fromLLSD(const LLSD& sd);
  63. // This merges data from the incoming LLSD into our fields.
  64. // Note that it also does NOT check limits! Use checkLLSD() above first.
  65. void mergeFromLLSD(const LLSD& sd);
  66. // "general" fields
  67. bool getAltImageEnable() const { return mAltImageEnable; }
  68. MediaControls getControls() const { return mControls; }
  69. std::string getCurrentURL() const { return mCurrentURL; }
  70. std::string getHomeURL() const { return mHomeURL; }
  71. bool getAutoLoop() const { return mAutoLoop; }
  72. bool getAutoPlay() const { return mAutoPlay; }
  73. bool getAutoScale() const { return mAutoScale; }
  74. bool getAutoZoom() const { return mAutoZoom; }
  75. bool getFirstClickInteract() const { return mFirstClickInteract; }
  76. U16 getWidthPixels() const { return mWidthPixels; }
  77. U16 getHeightPixels() const { return mHeightPixels; }
  78. // "security" fields
  79. bool getWhiteListEnable() const { return mWhiteListEnable; }
  80. const std::vector<std::string>& getWhiteList() const { return mWhiteList; }
  81. // "permissions" fields
  82. U8 getPermsInteract() const { return mPermsInteract; }
  83. U8 getPermsControl() const { return mPermsControl; }
  84. // Setters. Those that return a U32 return a status error code
  85. // See lllslconstants.h
  86. // "general" fields
  87. U32 setAltImageEnable(bool alt_image_enable) { mAltImageEnable = alt_image_enable; return LSL_STATUS_OK; }
  88. U32 setControls(MediaControls controls);
  89. U32 setCurrentURL(const std::string& current_url);
  90. U32 setHomeURL(const std::string& home_url);
  91. U32 setAutoLoop(bool auto_loop) { mAutoLoop = auto_loop; return LSL_STATUS_OK; }
  92. U32 setAutoPlay(bool auto_play) { mAutoPlay = auto_play; return LSL_STATUS_OK; }
  93. U32 setAutoScale(bool auto_scale) { mAutoScale = auto_scale; return LSL_STATUS_OK; }
  94. U32 setAutoZoom(bool auto_zoom) { mAutoZoom = auto_zoom; return LSL_STATUS_OK; }
  95. U32 setFirstClickInteract(bool first_click) { mFirstClickInteract = first_click; return LSL_STATUS_OK; }
  96. U32 setWidthPixels(U16 width);
  97. U32 setHeightPixels(U16 height);
  98. // "security" fields
  99. U32 setWhiteListEnable(bool whitelist_enable) { mWhiteListEnable = whitelist_enable; return LSL_STATUS_OK; }
  100. U32 setWhiteList(const std::vector<std::string>& whitelist);
  101. U32 setWhiteList(const LLSD& whitelist); // takes an LLSD array
  102. // "permissions" fields
  103. U32 setPermsInteract(U8 val);
  104. U32 setPermsControl(U8 val);
  105. const LLUUID& getMediaID() const;
  106. // Helper function to check a candidate URL against the whitelist. Returns
  107. // true if candidate URL passes (or if there is no whitelist), false
  108. // otherwise.
  109. bool checkCandidateUrl(const std::string& url) const;
  110. public:
  111. // Static function to check a URL against a whitelist
  112. // Returns true iff url passes the given whitelist
  113. static bool checkUrlAgainstWhitelist(const std::string& url,
  114. const std::vector<std::string>& whitelist);
  115. public:
  116. // LLSD key defines
  117. // "general" fields
  118. static const char* ALT_IMAGE_ENABLE_KEY;
  119. static const char* CONTROLS_KEY;
  120. static const char* CURRENT_URL_KEY;
  121. static const char* HOME_URL_KEY;
  122. static const char* AUTO_LOOP_KEY;
  123. static const char* AUTO_PLAY_KEY;
  124. static const char* AUTO_SCALE_KEY;
  125. static const char* AUTO_ZOOM_KEY;
  126. static const char* FIRST_CLICK_INTERACT_KEY;
  127. static const char* WIDTH_PIXELS_KEY;
  128. static const char* HEIGHT_PIXELS_KEY;
  129. // "security" fields
  130. static const char* WHITELIST_ENABLE_KEY;
  131. static const char* WHITELIST_KEY;
  132. // "permissions" fields
  133. static const char* PERMS_INTERACT_KEY;
  134. static const char* PERMS_CONTROL_KEY;
  135. // These permission fields are used when editing media settings
  136. static const char* PERMS_OWNER_INTERACT_KEY;
  137. static const char* PERMS_OWNER_CONTROL_KEY;
  138. static const char* PERMS_GROUP_INTERACT_KEY;
  139. static const char* PERMS_GROUP_CONTROL_KEY;
  140. static const char* PERMS_ANYONE_INTERACT_KEY;
  141. static const char* PERMS_ANYONE_CONTROL_KEY;
  142. // Key suffix for "tentative" fields
  143. static const char* TENTATIVE_SUFFIX;
  144. // Field enumerations& constants
  145. // *NOTE: DO NOT change the order of these, and do not insert values
  146. // in the middle!
  147. // Add values to the end, and make sure to change PARAM_MAX_ID!
  148. enum Fields
  149. {
  150. ALT_IMAGE_ENABLE_ID = 0,
  151. CONTROLS_ID = 1,
  152. CURRENT_URL_ID = 2,
  153. HOME_URL_ID = 3,
  154. AUTO_LOOP_ID = 4,
  155. AUTO_PLAY_ID = 5,
  156. AUTO_SCALE_ID = 6,
  157. AUTO_ZOOM_ID = 7,
  158. FIRST_CLICK_INTERACT_ID = 8,
  159. WIDTH_PIXELS_ID = 9,
  160. HEIGHT_PIXELS_ID = 10,
  161. WHITELIST_ENABLE_ID = 11,
  162. WHITELIST_ID = 12,
  163. PERMS_INTERACT_ID = 13,
  164. PERMS_CONTROL_ID = 14,
  165. PARAM_MAX_ID = PERMS_CONTROL_ID
  166. };
  167. // "permissions" values
  168. // (e.g. (PERM_OWNER | PERM_GROUP) sets permissions on for OWNER and GROUP
  169. static constexpr U8 PERM_NONE = 0x0;
  170. static constexpr U8 PERM_OWNER = 0x1;
  171. static constexpr U8 PERM_GROUP = 0x2;
  172. static constexpr U8 PERM_ANYONE = 0x4;
  173. static constexpr U8 PERM_ALL = PERM_OWNER|PERM_GROUP|PERM_ANYONE;
  174. static constexpr U8 PERM_MASK = PERM_OWNER|PERM_GROUP|PERM_ANYONE;
  175. // Limits (in bytes)
  176. static constexpr U32 MAX_URL_LENGTH = 1024;
  177. static constexpr U32 MAX_WHITELIST_SIZE = 1024;
  178. static constexpr U32 MAX_WHITELIST_COUNT = 64;
  179. static constexpr U16 MAX_WIDTH_PIXELS = 2048;
  180. static constexpr U16 MAX_HEIGHT_PIXELS = 2048;
  181. private:
  182. U32 setStringFieldWithLimit(std::string& field, const std::string& value,
  183. U32 limit);
  184. U32 setCurrentURLInternal(const std::string& url, bool check_whitelist);
  185. bool fromLLSDInternal(const LLSD& sd, bool overwrite);
  186. private:
  187. // Temporary Id assigned to media on the viewer
  188. mutable LLUUID* mMediaIDp;
  189. std::string mHomeURL;
  190. std::string mCurrentURL;
  191. std::vector<std::string> mWhiteList;
  192. U16 mWidthPixels;
  193. U16 mHeightPixels;
  194. MediaControls mControls;
  195. U8 mPermsInteract;
  196. U8 mPermsControl;
  197. bool mAltImageEnable;
  198. bool mAutoLoop;
  199. bool mAutoPlay;
  200. bool mAutoScale;
  201. bool mAutoZoom;
  202. bool mFirstClickInteract;
  203. bool mWhiteListEnable;
  204. };
  205. #endif