PageRenderTime 38ms CodeModel.GetById 2ms app.highlight 31ms RepoModel.GetById 1ms 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
  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
 27#ifndef LL_LLMEDIAENTRY_H
 28#define LL_LLMEDIAENTRY_H
 29
 30#include "llsd.h"
 31#include "llstring.h"
 32
 33// For return values of set*
 34#include "lllslconstants.h"
 35
 36class LLMediaEntry
 37{
 38public: 
 39    enum MediaControls {
 40        STANDARD = 0,
 41        MINI
 42    };
 43    
 44    // Constructors
 45    LLMediaEntry();
 46    LLMediaEntry(const LLMediaEntry &rhs);
 47
 48    LLMediaEntry &operator=(const LLMediaEntry &rhs);
 49    virtual ~LLMediaEntry();
 50
 51    bool operator==(const LLMediaEntry &rhs) const;
 52    bool operator!=(const LLMediaEntry &rhs) const;
 53    
 54    // Render as LLSD
 55    LLSD asLLSD() const;
 56    void asLLSD(LLSD& sd) const;
 57    operator LLSD() const { return asLLSD(); }
 58    // Returns false iff the given LLSD contains fields that violate any bounds
 59    // limits.
 60    static bool checkLLSD(const LLSD& sd);
 61    // This doesn't merge, it overwrites the data, so will use
 62    // LLSD defaults if need be.  Note: does not check limits!
 63    // Use checkLLSD() above first to ensure the LLSD is valid.
 64    void fromLLSD(const LLSD& sd);  
 65    // This merges data from the incoming LLSD into our fields.
 66    // Note that it also does NOT check limits!  Use checkLLSD() above first.
 67    void mergeFromLLSD(const LLSD& sd);
 68
 69    // "general" fields
 70    bool getAltImageEnable() const { return mAltImageEnable; }
 71    MediaControls getControls() const { return mControls; }
 72    std::string getCurrentURL() const { return mCurrentURL; }
 73    std::string getHomeURL() const { return mHomeURL; }
 74    bool getAutoLoop() const { return mAutoLoop; }
 75    bool getAutoPlay() const { return mAutoPlay; }
 76    bool getAutoScale() const { return mAutoScale; }
 77    bool getAutoZoom() const { return mAutoZoom; }
 78    bool getFirstClickInteract() const { return mFirstClickInteract; }
 79    U16 getWidthPixels() const { return mWidthPixels; }
 80    U16 getHeightPixels() const { return mHeightPixels; }
 81
 82    // "security" fields
 83    bool getWhiteListEnable() const { return mWhiteListEnable; }
 84    const std::vector<std::string> &getWhiteList() const { return mWhiteList; }
 85
 86    // "permissions" fields
 87    U8 getPermsInteract() const { return mPermsInteract; }
 88    U8 getPermsControl() const { return mPermsControl; }
 89
 90    // Setters.  Those that return a U32 return a status error code
 91    // See lllslconstants.h
 92    
 93    // "general" fields
 94    U32 setAltImageEnable(bool alt_image_enable) { mAltImageEnable = alt_image_enable; return LSL_STATUS_OK; }
 95    U32 setControls(MediaControls controls);
 96    U32 setCurrentURL(const std::string& current_url);
 97    U32 setHomeURL(const std::string& home_url);
 98    U32 setAutoLoop(bool auto_loop) { mAutoLoop = auto_loop; return LSL_STATUS_OK; }
 99    U32 setAutoPlay(bool auto_play) { mAutoPlay = auto_play; return LSL_STATUS_OK; }
100    U32 setAutoScale(bool auto_scale) { mAutoScale = auto_scale; return LSL_STATUS_OK; }
101    U32 setAutoZoom(bool auto_zoom) { mAutoZoom = auto_zoom; return LSL_STATUS_OK; }
102    U32 setFirstClickInteract(bool first_click) { mFirstClickInteract = first_click; return LSL_STATUS_OK; }
103    U32 setWidthPixels(U16 width);
104    U32 setHeightPixels(U16 height);
105
106    // "security" fields
107    U32 setWhiteListEnable( bool whitelist_enable ) { mWhiteListEnable = whitelist_enable; return LSL_STATUS_OK; }
108    U32 setWhiteList( const std::vector<std::string> &whitelist );
109    U32 setWhiteList( const LLSD &whitelist );  // takes an LLSD array
110
111    // "permissions" fields
112    U32 setPermsInteract( U8 val );
113    U32 setPermsControl( U8 val );
114
115    const LLUUID& getMediaID() const;
116
117    // Helper function to check a candidate URL against the whitelist
118    // Returns true iff candidate URL passes (or if there is no whitelist), false otherwise
119    bool checkCandidateUrl(const std::string& url) const;
120
121public:
122    // Static function to check a URL against a whitelist
123    // Returns true iff url passes the given whitelist
124    static bool checkUrlAgainstWhitelist(const std::string &url, 
125                                         const std::vector<std::string> &whitelist);
126    
127public:
128        // LLSD key defines
129    // "general" fields
130    static const char*  ALT_IMAGE_ENABLE_KEY;
131    static const char*  CONTROLS_KEY;
132    static const char*  CURRENT_URL_KEY;
133    static const char*  HOME_URL_KEY;
134    static const char*  AUTO_LOOP_KEY;
135    static const char*  AUTO_PLAY_KEY;
136    static const char*  AUTO_SCALE_KEY;
137    static const char*  AUTO_ZOOM_KEY;
138    static const char*  FIRST_CLICK_INTERACT_KEY;
139    static const char*  WIDTH_PIXELS_KEY;
140    static const char*  HEIGHT_PIXELS_KEY;
141
142    // "security" fields
143    static const char*  WHITELIST_ENABLE_KEY;
144    static const char*  WHITELIST_KEY;
145
146    // "permissions" fields
147    static const char*  PERMS_INTERACT_KEY;
148    static const char*  PERMS_CONTROL_KEY;
149
150    // Field enumerations & constants
151
152    // *NOTE: DO NOT change the order of these, and do not insert values
153    // in the middle!
154    // Add values to the end, and make sure to change PARAM_MAX_ID!
155    enum Fields {
156         ALT_IMAGE_ENABLE_ID = 0,
157         CONTROLS_ID = 1,
158         CURRENT_URL_ID = 2,
159         HOME_URL_ID = 3,
160         AUTO_LOOP_ID = 4,
161         AUTO_PLAY_ID = 5,
162         AUTO_SCALE_ID = 6,
163         AUTO_ZOOM_ID = 7,
164         FIRST_CLICK_INTERACT_ID = 8,
165         WIDTH_PIXELS_ID = 9,
166         HEIGHT_PIXELS_ID = 10,
167         WHITELIST_ENABLE_ID = 11,
168         WHITELIST_ID = 12,
169         PERMS_INTERACT_ID = 13,
170         PERMS_CONTROL_ID = 14,
171         PARAM_MAX_ID = PERMS_CONTROL_ID
172    };
173
174    // "permissions" values
175    // (e.g. (PERM_OWNER | PERM_GROUP) sets permissions on for OWNER and GROUP
176    static const U8    PERM_NONE             = 0x0;
177    static const U8    PERM_OWNER            = 0x1;
178    static const U8    PERM_GROUP            = 0x2;
179    static const U8    PERM_ANYONE           = 0x4;
180    static const U8    PERM_ALL              = PERM_OWNER|PERM_GROUP|PERM_ANYONE;
181    static const U8    PERM_MASK             = PERM_OWNER|PERM_GROUP|PERM_ANYONE;
182
183    // Limits (in bytes)
184    static const U32   MAX_URL_LENGTH        = 1024;
185    static const U32   MAX_WHITELIST_SIZE    = 1024;
186    static const U32   MAX_WHITELIST_COUNT   = 64;
187    static const U16   MAX_WIDTH_PIXELS      = 2048;
188    static const U16   MAX_HEIGHT_PIXELS     = 2048;
189
190private:
191
192    U32 setStringFieldWithLimit( std::string &field, const std::string &value, U32 limit );
193    U32 setCurrentURLInternal( const std::string &url, bool check_whitelist);
194    bool fromLLSDInternal(const LLSD &sd, bool overwrite);
195
196private:
197     // "general" fields
198    bool mAltImageEnable;
199    MediaControls mControls;
200    std::string mCurrentURL;
201    std::string mHomeURL;
202    bool mAutoLoop;
203    bool mAutoPlay;
204    bool mAutoScale;
205    bool mAutoZoom;
206    bool mFirstClickInteract;
207    U16 mWidthPixels;
208    U16 mHeightPixels;
209
210    // "security" fields
211    bool mWhiteListEnable;
212    std::vector<std::string> mWhiteList;
213
214    // "permissions" fields
215    U8 mPermsInteract;
216    U8 mPermsControl;
217    
218    mutable LLUUID *mMediaIDp;            // temporary id assigned to media on the viewer
219};
220
221#endif
222