PageRenderTime 32ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llprimitive/llmediaentry.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 222 lines | 128 code | 33 blank | 61 comment | 0 complexity | 7dac9a24b684c32311194de632bf6ba1 MD5 | raw file
Possible License(s): LGPL-2.1
  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=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLMEDIAENTRY_H
  27. #define LL_LLMEDIAENTRY_H
  28. #include "llsd.h"
  29. #include "llstring.h"
  30. // For return values of set*
  31. #include "lllslconstants.h"
  32. class LLMediaEntry
  33. {
  34. public:
  35. enum MediaControls {
  36. STANDARD = 0,
  37. MINI
  38. };
  39. // Constructors
  40. LLMediaEntry();
  41. LLMediaEntry(const LLMediaEntry &rhs);
  42. LLMediaEntry &operator=(const LLMediaEntry &rhs);
  43. virtual ~LLMediaEntry();
  44. bool operator==(const LLMediaEntry &rhs) const;
  45. bool operator!=(const LLMediaEntry &rhs) const;
  46. // Render as LLSD
  47. LLSD asLLSD() const;
  48. void asLLSD(LLSD& sd) const;
  49. operator LLSD() const { return asLLSD(); }
  50. // Returns false iff the given LLSD contains fields that violate any bounds
  51. // limits.
  52. static bool checkLLSD(const LLSD& sd);
  53. // This doesn't merge, it overwrites the data, so will use
  54. // LLSD defaults if need be. Note: does not check limits!
  55. // Use checkLLSD() above first to ensure the LLSD is valid.
  56. void fromLLSD(const LLSD& sd);
  57. // This merges data from the incoming LLSD into our fields.
  58. // Note that it also does NOT check limits! Use checkLLSD() above first.
  59. void mergeFromLLSD(const LLSD& sd);
  60. // "general" fields
  61. bool getAltImageEnable() const { return mAltImageEnable; }
  62. MediaControls getControls() const { return mControls; }
  63. std::string getCurrentURL() const { return mCurrentURL; }
  64. std::string getHomeURL() const { return mHomeURL; }
  65. bool getAutoLoop() const { return mAutoLoop; }
  66. bool getAutoPlay() const { return mAutoPlay; }
  67. bool getAutoScale() const { return mAutoScale; }
  68. bool getAutoZoom() const { return mAutoZoom; }
  69. bool getFirstClickInteract() const { return mFirstClickInteract; }
  70. U16 getWidthPixels() const { return mWidthPixels; }
  71. U16 getHeightPixels() const { return mHeightPixels; }
  72. // "security" fields
  73. bool getWhiteListEnable() const { return mWhiteListEnable; }
  74. const std::vector<std::string> &getWhiteList() const { return mWhiteList; }
  75. // "permissions" fields
  76. U8 getPermsInteract() const { return mPermsInteract; }
  77. U8 getPermsControl() const { return mPermsControl; }
  78. // Setters. Those that return a U32 return a status error code
  79. // See lllslconstants.h
  80. // "general" fields
  81. U32 setAltImageEnable(bool alt_image_enable) { mAltImageEnable = alt_image_enable; return LSL_STATUS_OK; }
  82. U32 setControls(MediaControls controls);
  83. U32 setCurrentURL(const std::string& current_url);
  84. U32 setHomeURL(const std::string& home_url);
  85. U32 setAutoLoop(bool auto_loop) { mAutoLoop = auto_loop; return LSL_STATUS_OK; }
  86. U32 setAutoPlay(bool auto_play) { mAutoPlay = auto_play; return LSL_STATUS_OK; }
  87. U32 setAutoScale(bool auto_scale) { mAutoScale = auto_scale; return LSL_STATUS_OK; }
  88. U32 setAutoZoom(bool auto_zoom) { mAutoZoom = auto_zoom; return LSL_STATUS_OK; }
  89. U32 setFirstClickInteract(bool first_click) { mFirstClickInteract = first_click; return LSL_STATUS_OK; }
  90. U32 setWidthPixels(U16 width);
  91. U32 setHeightPixels(U16 height);
  92. // "security" fields
  93. U32 setWhiteListEnable( bool whitelist_enable ) { mWhiteListEnable = whitelist_enable; return LSL_STATUS_OK; }
  94. U32 setWhiteList( const std::vector<std::string> &whitelist );
  95. U32 setWhiteList( const LLSD &whitelist ); // takes an LLSD array
  96. // "permissions" fields
  97. U32 setPermsInteract( U8 val );
  98. U32 setPermsControl( U8 val );
  99. const LLUUID& getMediaID() const;
  100. // Helper function to check a candidate URL against the whitelist
  101. // Returns true iff candidate URL passes (or if there is no whitelist), false otherwise
  102. bool checkCandidateUrl(const std::string& url) const;
  103. public:
  104. // Static function to check a URL against a whitelist
  105. // Returns true iff url passes the given whitelist
  106. static bool checkUrlAgainstWhitelist(const std::string &url,
  107. const std::vector<std::string> &whitelist);
  108. public:
  109. // LLSD key defines
  110. // "general" fields
  111. static const char* ALT_IMAGE_ENABLE_KEY;
  112. static const char* CONTROLS_KEY;
  113. static const char* CURRENT_URL_KEY;
  114. static const char* HOME_URL_KEY;
  115. static const char* AUTO_LOOP_KEY;
  116. static const char* AUTO_PLAY_KEY;
  117. static const char* AUTO_SCALE_KEY;
  118. static const char* AUTO_ZOOM_KEY;
  119. static const char* FIRST_CLICK_INTERACT_KEY;
  120. static const char* WIDTH_PIXELS_KEY;
  121. static const char* HEIGHT_PIXELS_KEY;
  122. // "security" fields
  123. static const char* WHITELIST_ENABLE_KEY;
  124. static const char* WHITELIST_KEY;
  125. // "permissions" fields
  126. static const char* PERMS_INTERACT_KEY;
  127. static const char* PERMS_CONTROL_KEY;
  128. // Field enumerations & constants
  129. // *NOTE: DO NOT change the order of these, and do not insert values
  130. // in the middle!
  131. // Add values to the end, and make sure to change PARAM_MAX_ID!
  132. enum Fields {
  133. ALT_IMAGE_ENABLE_ID = 0,
  134. CONTROLS_ID = 1,
  135. CURRENT_URL_ID = 2,
  136. HOME_URL_ID = 3,
  137. AUTO_LOOP_ID = 4,
  138. AUTO_PLAY_ID = 5,
  139. AUTO_SCALE_ID = 6,
  140. AUTO_ZOOM_ID = 7,
  141. FIRST_CLICK_INTERACT_ID = 8,
  142. WIDTH_PIXELS_ID = 9,
  143. HEIGHT_PIXELS_ID = 10,
  144. WHITELIST_ENABLE_ID = 11,
  145. WHITELIST_ID = 12,
  146. PERMS_INTERACT_ID = 13,
  147. PERMS_CONTROL_ID = 14,
  148. PARAM_MAX_ID = PERMS_CONTROL_ID
  149. };
  150. // "permissions" values
  151. // (e.g. (PERM_OWNER | PERM_GROUP) sets permissions on for OWNER and GROUP
  152. static const U8 PERM_NONE = 0x0;
  153. static const U8 PERM_OWNER = 0x1;
  154. static const U8 PERM_GROUP = 0x2;
  155. static const U8 PERM_ANYONE = 0x4;
  156. static const U8 PERM_ALL = PERM_OWNER|PERM_GROUP|PERM_ANYONE;
  157. static const U8 PERM_MASK = PERM_OWNER|PERM_GROUP|PERM_ANYONE;
  158. // Limits (in bytes)
  159. static const U32 MAX_URL_LENGTH = 1024;
  160. static const U32 MAX_WHITELIST_SIZE = 1024;
  161. static const U32 MAX_WHITELIST_COUNT = 64;
  162. static const U16 MAX_WIDTH_PIXELS = 2048;
  163. static const U16 MAX_HEIGHT_PIXELS = 2048;
  164. private:
  165. U32 setStringFieldWithLimit( std::string &field, const std::string &value, U32 limit );
  166. U32 setCurrentURLInternal( const std::string &url, bool check_whitelist);
  167. bool fromLLSDInternal(const LLSD &sd, bool overwrite);
  168. private:
  169. // "general" fields
  170. bool mAltImageEnable;
  171. MediaControls mControls;
  172. std::string mCurrentURL;
  173. std::string mHomeURL;
  174. bool mAutoLoop;
  175. bool mAutoPlay;
  176. bool mAutoScale;
  177. bool mAutoZoom;
  178. bool mFirstClickInteract;
  179. U16 mWidthPixels;
  180. U16 mHeightPixels;
  181. // "security" fields
  182. bool mWhiteListEnable;
  183. std::vector<std::string> mWhiteList;
  184. // "permissions" fields
  185. U8 mPermsInteract;
  186. U8 mPermsControl;
  187. mutable LLUUID *mMediaIDp; // temporary id assigned to media on the viewer
  188. };
  189. #endif