summaryrefslogtreecommitdiff
path: root/indra/llprimitive/llmediaentry.h
blob: 2a5486666a42df0f8798bf930515690d01b8a7a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/** 
 * @file llmediaentry.h
 * @brief This is a single instance of media data related to the face of a prim
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 * 
 * Copyright (c) 2001-2009, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at
 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#ifndef LL_LLMEDIAENTRY_H
#define LL_LLMEDIAENTRY_H

#include "llsd.h"
#include "llstring.h"

// For return values of set*
#include "lllslconstants.h"

class LLMediaEntry
{
public: 
    enum MediaControls {
        STANDARD = 0,
        MINI
    };
    
    // Constructors
    LLMediaEntry();
    LLMediaEntry(const LLMediaEntry &rhs);

    LLMediaEntry &operator=(const LLMediaEntry &rhs);
    virtual ~LLMediaEntry();

    bool operator==(const LLMediaEntry &rhs) const;
    bool operator!=(const LLMediaEntry &rhs) const;
    
    // Render as LLSD
    LLSD asLLSD() const;
    void asLLSD(LLSD& sd) const;
    operator LLSD() const { return asLLSD(); }
    // Returns false iff the given LLSD contains fields that violate any bounds
    // limits.
    static bool checkLLSD(const LLSD& sd);
    // This doesn't merge, it overwrites the data, so will use
    // LLSD defaults if need be.  Note: does not check limits!
    // Use checkLLSD() above first to ensure the LLSD is valid.
    void fromLLSD(const LLSD& sd);  
    // This merges data from the incoming LLSD into our fields.
    // Note that it also does NOT check limits!  Use checkLLSD() above first.
    void mergeFromLLSD(const LLSD& sd);

    // "general" fields
    bool getAltImageEnable() const { return mAltImageEnable; }
    MediaControls getControls() const { return mControls; }
    std::string getCurrentURL() const { return mCurrentURL; }
    std::string getHomeURL() const { return mHomeURL; }
    bool getAutoLoop() const { return mAutoLoop; }
    bool getAutoPlay() const { return mAutoPlay; }
    bool getAutoScale() const { return mAutoScale; }
    bool getAutoZoom() const { return mAutoZoom; }
    bool getFirstClickInteract() const { return mFirstClickInteract; }
    U16 getWidthPixels() const { return mWidthPixels; }
    U16 getHeightPixels() const { return mHeightPixels; }

    // "security" fields
    bool getWhiteListEnable() const { return mWhiteListEnable; }
    const std::vector<std::string> &getWhiteList() const { return mWhiteList; }

    // "permissions" fields
    U8 getPermsInteract() const { return mPermsInteract; }
    U8 getPermsControl() const { return mPermsControl; }

    // Setters.  Those that return a U32 return a status error code
    // See lllslconstants.h
    
    // "general" fields
    U32 setAltImageEnable(bool alt_image_enable) { mAltImageEnable = alt_image_enable; return LSL_STATUS_OK; }
    U32 setControls(MediaControls controls);
    U32 setCurrentURL(const std::string& current_url);
    U32 setHomeURL(const std::string& home_url);
    U32 setAutoLoop(bool auto_loop) { mAutoLoop = auto_loop; return LSL_STATUS_OK; }
    U32 setAutoPlay(bool auto_play) { mAutoPlay = auto_play; return LSL_STATUS_OK; }
    U32 setAutoScale(bool auto_scale) { mAutoScale = auto_scale; return LSL_STATUS_OK; }
    U32 setAutoZoom(bool auto_zoom) { mAutoZoom = auto_zoom; return LSL_STATUS_OK; }
    U32 setFirstClickInteract(bool first_click) { mFirstClickInteract = first_click; return LSL_STATUS_OK; }
    U32 setWidthPixels(U16 width);
    U32 setHeightPixels(U16 height);

    // "security" fields
    U32 setWhiteListEnable( bool whitelist_enable ) { mWhiteListEnable = whitelist_enable; return LSL_STATUS_OK; }
    U32 setWhiteList( const std::vector<std::string> &whitelist );
    U32 setWhiteList( const LLSD &whitelist );  // takes an LLSD array

    // "permissions" fields
    U32 setPermsInteract( U8 val );
    U32 setPermsControl( U8 val );

    const LLUUID& getMediaID() const;

    // Helper function to check a candidate URL against the whitelist
    // Returns true iff candidate URL passes (or if there is no whitelist), false otherwise
    bool checkCandidateUrl(const std::string& url) const;

public:
    // Static function to check a URL against a whitelist
    // Returns true iff url passes the given whitelist
    static bool checkUrlAgainstWhitelist(const std::string &url, 
                                         const std::vector<std::string> &whitelist);
    
public:
        // LLSD key defines
    // "general" fields
    static const char*  ALT_IMAGE_ENABLE_KEY;
    static const char*  CONTROLS_KEY;
    static const char*  CURRENT_URL_KEY;
    static const char*  HOME_URL_KEY;
    static const char*  AUTO_LOOP_KEY;
    static const char*  AUTO_PLAY_KEY;
    static const char*  AUTO_SCALE_KEY;
    static const char*  AUTO_ZOOM_KEY;
    static const char*  FIRST_CLICK_INTERACT_KEY;
    static const char*  WIDTH_PIXELS_KEY;
    static const char*  HEIGHT_PIXELS_KEY;

    // "security" fields
    static const char*  WHITELIST_ENABLE_KEY;
    static const char*  WHITELIST_KEY;

    // "permissions" fields
    static const char*  PERMS_INTERACT_KEY;
    static const char*  PERMS_CONTROL_KEY;

    // Field enumerations & constants

    // *NOTE: DO NOT change the order of these, and do not insert values
    // in the middle!
    // Add values to the end, and make sure to change PARAM_MAX_ID!
    enum Fields {
         ALT_IMAGE_ENABLE_ID = 0,
         CONTROLS_ID = 1,
         CURRENT_URL_ID = 2,
         HOME_URL_ID = 3,
         AUTO_LOOP_ID = 4,
         AUTO_PLAY_ID = 5,
         AUTO_SCALE_ID = 6,
         AUTO_ZOOM_ID = 7,
         FIRST_CLICK_INTERACT_ID = 8,
         WIDTH_PIXELS_ID = 9,
         HEIGHT_PIXELS_ID = 10,
         WHITELIST_ENABLE_ID = 11,
         WHITELIST_ID = 12,
         PERMS_INTERACT_ID = 13,
         PERMS_CONTROL_ID = 14,
         PARAM_MAX_ID = PERMS_CONTROL_ID
    };

    // "permissions" values
    // (e.g. (PERM_OWNER | PERM_GROUP) sets permissions on for OWNER and GROUP
    static const U8    PERM_NONE             = 0x0;
    static const U8    PERM_OWNER            = 0x1;
    static const U8    PERM_GROUP            = 0x2;
    static const U8    PERM_ANYONE           = 0x4;
    static const U8    PERM_ALL              = PERM_OWNER|PERM_GROUP|PERM_ANYONE;
    static const U8    PERM_MASK             = PERM_OWNER|PERM_GROUP|PERM_ANYONE;

    // Limits (in bytes)
    static const U32   MAX_URL_LENGTH        = 1024;
    static const U32   MAX_WHITELIST_SIZE    = 1024;
    static const U32   MAX_WHITELIST_COUNT   = 64;
    static const U16   MAX_WIDTH_PIXELS      = 2048;
    static const U16   MAX_HEIGHT_PIXELS     = 2048;

private:

    U32 setStringFieldWithLimit( std::string &field, const std::string &value, U32 limit );
    U32 setCurrentURLInternal( const std::string &url, bool check_whitelist);
    bool fromLLSDInternal(const LLSD &sd, bool overwrite);

private:
     // "general" fields
    bool mAltImageEnable;
    MediaControls mControls;
    std::string mCurrentURL;
    std::string mHomeURL;
    bool mAutoLoop;
    bool mAutoPlay;
    bool mAutoScale;
    bool mAutoZoom;
    bool mFirstClickInteract;
    U16 mWidthPixels;
    U16 mHeightPixels;

    // "security" fields
    bool mWhiteListEnable;
    std::vector<std::string> mWhiteList;

    // "permissions" fields
    U8 mPermsInteract;
    U8 mPermsControl;
    
    mutable LLUUID *mMediaIDp;            // temporary id assigned to media on the viewer
};

#endif