/indra/newview/llwebsharing.h
C++ Header | 224 lines | 49 code | 33 blank | 142 comment | 0 complexity | 42ae2779880dc5440991d8d29620356a MD5 | raw file
Possible License(s): LGPL-2.1
1/** 2 * @file llwebsharing.h 3 * @author Aimee 4 * @brief Web Snapshot Sharing 5 * 6 * $LicenseInfo:firstyear=2010&license=viewerlgpl$ 7 * Second Life Viewer Source Code 8 * Copyright (C) 2010, Linden Research, Inc. 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; 13 * version 2.1 of the License only. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA 25 * $/LicenseInfo$ 26 */ 27 28#ifndef LL_LLWEBSHARING_H 29#define LL_LLWEBSHARING_H 30 31#include "llimagejpeg.h" 32#include "llsingleton.h" 33 34 35 36/** 37 * @class LLWebSharing 38 * 39 * Manages authentication to, and interaction with, a web service allowing the 40 * upload of snapshot images taken within the viewer, using OpenID and the 41 * OpenSocial APIs. 42 * http://www.opensocial.org/Technical-Resources/opensocial-spec-v09/RPC-Protocol.html 43 */ 44class LLWebSharing : public LLSingleton<LLWebSharing> 45{ 46 LOG_CLASS(LLWebSharing); 47public: 48 /* 49 * Performs initial setup, by requesting config data from the web service if 50 * it has not already been received. 51 */ 52 void init(); 53 54 /* 55 * @return true if both the OpenID cookie and config data have been received. 56 */ 57 bool enabled() const { return mEnabled; }; 58 59 /* 60 * Sets the OpenID cookie to use for login to the web service. 61 * 62 * @param cookie a string containing the OpenID cookie. 63 * 64 * @return true if both the OpenID cookie and config data have been received. 65 */ 66 bool setOpenIDCookie(const std::string& cookie); 67 68 /* 69 * Receive config data used to connect to the web service. 70 * 71 * @param config an LLSD map of URL templates for the web service end-points. 72 * 73 * @return true if both the OpenID cookie and config data have been received. 74 * 75 * @see sendConfigRequest() 76 */ 77 bool receiveConfig(const LLSD& config); 78 79 /* 80 * Receive the session cookie from the web service, which is the result of 81 * the OpenID login process. 82 * 83 * @see sendOpenIDAuthRequest() 84 */ 85 bool receiveSessionCookie(const std::string& cookie); 86 87 /* 88 * Receive a security token for the upload service. 89 * 90 * @see sendSecurityTokenRequest() 91 */ 92 bool receiveSecurityToken(const std::string& token, const std::string& expires); 93 94 /* 95 * Restarts the authentication process if the maximum number of retries has 96 * not been exceeded. 97 * 98 * @return true if retrying, false if LLWebSharing::MAX_AUTH_RETRIES has been exceeded. 99 */ 100 bool retryOpenIDAuth(); 101 102 /* 103 * Post a snapshot to the upload service. 104 * 105 * @return true if accepted for upload, false if already uploading another image. 106 */ 107 bool shareSnapshot(LLImageJPEG* snapshot, LLSD& metadata); 108 109private: 110 static const S32 MAX_AUTH_RETRIES = 4; 111 112 friend class LLSingleton<LLWebSharing>; 113 114 LLWebSharing(); 115 ~LLWebSharing() {}; 116 117 /* 118 * Request a map of URLs and URL templates to the web service end-points. 119 * 120 * @see receiveConfig() 121 */ 122 void sendConfigRequest(); 123 124 /* 125 * Initiate the OpenID login process. 126 * 127 * @see receiveSessionCookie() 128 */ 129 void sendOpenIDAuthRequest(); 130 131 /* 132 * Request a security token for the upload service. 133 * 134 * @see receiveSecurityToken() 135 */ 136 void sendSecurityTokenRequest(); 137 138 /* 139 * Request a security token for the upload service. 140 * 141 * @see receiveSecurityToken() 142 */ 143 void sendUploadRequest(); 144 145 /* 146 * Checks all necessary config information has been received, and sets mEnabled. 147 * 148 * @return true if both the OpenID cookie and config data have been received. 149 */ 150 bool validateConfig(); 151 152 /* 153 * Checks the security token is present and has not expired. 154 * 155 * @param token an LLSD map containing the token string and the time it expires. 156 * 157 * @return true if the token is not empty and has not expired. 158 */ 159 static bool securityTokenIsValid(LLSD& token); 160 161 std::string mOpenIDCookie; 162 std::string mSessionCookie; 163 LLSD mSecurityToken; 164 165 LLSD mConfig; 166 bool mEnabled; 167 168 LLPointer<LLImageJPEG> mImage; 169 LLSD mMetadata; 170 171 S32 mRetries; 172}; 173 174/** 175 * @class LLUriTemplate 176 * 177 * @brief Builds complete URIs, given URI template and a map of keys and values 178 * to use for substition. 179 * Note: This is only a partial implementation of a draft standard required 180 * by the web API used by LLWebSharing. 181 * See: http://tools.ietf.org/html/draft-gregorio-uritemplate-03 182 * 183 * @see LLWebSharing 184 */ 185class LLUriTemplate 186{ 187 LOG_CLASS(LLUriTemplate); 188public: 189 LLUriTemplate(const std::string& uri_template); 190 ~LLUriTemplate() {}; 191 192 /* 193 * Builds a complete URI from the template. 194 * 195 * @param vars an LLSD map of keys and values for substitution. 196 * 197 * @return a string containing the complete URI. 198 */ 199 std::string buildURI(const LLSD& vars); 200 201private: 202 /* 203 * Builds a URL query string. 204 * 205 * @param delim a string containing the separator to use between name=value pairs. 206 * @param var_list a string containing a comma separated list of variable names. 207 * @param vars an LLSD map of keys and values for substitution. 208 * 209 * @return a URL query string. 210 */ 211 std::string expandJoin(const std::string& delim, const std::string& var_list, const LLSD& vars); 212 213 /* 214 * URL escape the given string. 215 * LLWeb::escapeURL() only does a partial escape, so this uses curl_escape() instead. 216 */ 217 static std::string escapeURL(const std::string& unescaped); 218 219 std::string mTemplate; 220}; 221 222 223 224#endif // LL_LLWEBSHARING_H