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
229
230
|
/**
* @file llwebsharing.h
* @author Aimee
* @brief Web Snapshot Sharing
*
* $LicenseInfo:firstyear=2010&license=viewergpl$
*
* Copyright (c) 2010, 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_LLWEBSHARING_H
#define LL_LLWEBSHARING_H
#include "llimagejpeg.h"
#include "llsingleton.h"
/**
* @class LLWebSharing
*
* Manages authentication to, and interaction with, a web service allowing the
* upload of snapshot images taken within the viewer, using OpenID and the
* OpenSocial APIs.
* http://www.opensocial.org/Technical-Resources/opensocial-spec-v09/RPC-Protocol.html
*/
class LLWebSharing : public LLSingleton<LLWebSharing>
{
LOG_CLASS(LLWebSharing);
public:
/*
* Performs initial setup, by requesting config data from the web service if
* it has not already been received.
*/
void init();
/*
* @return true if both the OpenID cookie and config data have been received.
*/
bool enabled() const { return mEnabled; };
/*
* Sets the OpenID cookie to use for login to the web service.
*
* @param cookie a string containing the OpenID cookie.
*
* @return true if both the OpenID cookie and config data have been received.
*/
bool setOpenIDCookie(const std::string& cookie);
/*
* Receive config data used to connect to the web service.
*
* @param config an LLSD map of URL templates for the web service end-points.
*
* @return true if both the OpenID cookie and config data have been received.
*
* @see sendConfigRequest()
*/
bool receiveConfig(const LLSD& config);
/*
* Receive the session cookie from the web service, which is the result of
* the OpenID login process.
*
* @see sendOpenIDAuthRequest()
*/
bool receiveSessionCookie(const std::string& cookie);
/*
* Receive a security token for the upload service.
*
* @see sendSecurityTokenRequest()
*/
bool receiveSecurityToken(const std::string& token, const std::string& expires);
/*
* Restarts the authentication process if the maximum number of retries has
* not been exceeded.
*
* @return true if retrying, false if LLWebSharing::MAX_AUTH_RETRIES has been exceeded.
*/
bool retryOpenIDAuth();
/*
* Post a snapshot to the upload service.
*
* @return true if accepted for upload, false if already uploading another image.
*/
bool shareSnapshot(LLImageJPEG* snapshot, LLSD& metadata);
private:
static const S32 MAX_AUTH_RETRIES = 4;
friend class LLSingleton<LLWebSharing>;
LLWebSharing();
~LLWebSharing() {};
/*
* Request a map of URLs and URL templates to the web service end-points.
*
* @see receiveConfig()
*/
void sendConfigRequest();
/*
* Initiate the OpenID login process.
*
* @see receiveSessionCookie()
*/
void sendOpenIDAuthRequest();
/*
* Request a security token for the upload service.
*
* @see receiveSecurityToken()
*/
void sendSecurityTokenRequest();
/*
* Request a security token for the upload service.
*
* @see receiveSecurityToken()
*/
void sendUploadRequest();
/*
* Checks all necessary config information has been received, and sets mEnabled.
*
* @return true if both the OpenID cookie and config data have been received.
*/
bool validateConfig();
/*
* Checks the security token is present and has not expired.
*
* @param token an LLSD map containing the token string and the time it expires.
*
* @return true if the token is not empty and has not expired.
*/
static bool securityTokenIsValid(LLSD& token);
std::string mOpenIDCookie;
std::string mSessionCookie;
LLSD mSecurityToken;
LLSD mConfig;
bool mEnabled;
LLPointer<LLImageJPEG> mImage;
LLSD mMetadata;
S32 mRetries;
};
/**
* @class LLUriTemplate
*
* @brief Builds complete URIs, given URI template and a map of keys and values
* to use for substition.
* Note: This is only a partial implementation of a draft standard required
* by the web API used by LLWebSharing.
* See: http://tools.ietf.org/html/draft-gregorio-uritemplate-03
*
* @see LLWebSharing
*/
class LLUriTemplate
{
LOG_CLASS(LLUriTemplate);
public:
LLUriTemplate(const std::string& uri_template);
~LLUriTemplate() {};
/*
* Builds a complete URI from the template.
*
* @param vars an LLSD map of keys and values for substitution.
*
* @return a string containing the complete URI.
*/
std::string buildURI(const LLSD& vars);
private:
/*
* Builds a URL query string.
*
* @param delim a string containing the separator to use between name=value pairs.
* @param var_list a string containing a comma separated list of variable names.
* @param vars an LLSD map of keys and values for substitution.
*
* @return a URL query string.
*/
std::string expandJoin(const std::string& delim, const std::string& var_list, const LLSD& vars);
/*
* URL escape the given string.
* LLWeb::escapeURL() only does a partial escape, so this uses curl_escape() instead.
*/
static std::string escapeURL(const std::string& unescaped);
std::string mTemplate;
};
#endif // LL_LLWEBSHARING_H
|