PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llwebsharing.h

https://bitbucket.org/lindenlab/viewer-beta/
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. #ifndef LL_LLWEBSHARING_H
  28. #define LL_LLWEBSHARING_H
  29. #include "llimagejpeg.h"
  30. #include "llsingleton.h"
  31. /**
  32. * @class LLWebSharing
  33. *
  34. * Manages authentication to, and interaction with, a web service allowing the
  35. * upload of snapshot images taken within the viewer, using OpenID and the
  36. * OpenSocial APIs.
  37. * http://www.opensocial.org/Technical-Resources/opensocial-spec-v09/RPC-Protocol.html
  38. */
  39. class LLWebSharing : public LLSingleton<LLWebSharing>
  40. {
  41. LOG_CLASS(LLWebSharing);
  42. public:
  43. /*
  44. * Performs initial setup, by requesting config data from the web service if
  45. * it has not already been received.
  46. */
  47. void init();
  48. /*
  49. * @return true if both the OpenID cookie and config data have been received.
  50. */
  51. bool enabled() const { return mEnabled; };
  52. /*
  53. * Sets the OpenID cookie to use for login to the web service.
  54. *
  55. * @param cookie a string containing the OpenID cookie.
  56. *
  57. * @return true if both the OpenID cookie and config data have been received.
  58. */
  59. bool setOpenIDCookie(const std::string& cookie);
  60. /*
  61. * Receive config data used to connect to the web service.
  62. *
  63. * @param config an LLSD map of URL templates for the web service end-points.
  64. *
  65. * @return true if both the OpenID cookie and config data have been received.
  66. *
  67. * @see sendConfigRequest()
  68. */
  69. bool receiveConfig(const LLSD& config);
  70. /*
  71. * Receive the session cookie from the web service, which is the result of
  72. * the OpenID login process.
  73. *
  74. * @see sendOpenIDAuthRequest()
  75. */
  76. bool receiveSessionCookie(const std::string& cookie);
  77. /*
  78. * Receive a security token for the upload service.
  79. *
  80. * @see sendSecurityTokenRequest()
  81. */
  82. bool receiveSecurityToken(const std::string& token, const std::string& expires);
  83. /*
  84. * Restarts the authentication process if the maximum number of retries has
  85. * not been exceeded.
  86. *
  87. * @return true if retrying, false if LLWebSharing::MAX_AUTH_RETRIES has been exceeded.
  88. */
  89. bool retryOpenIDAuth();
  90. /*
  91. * Post a snapshot to the upload service.
  92. *
  93. * @return true if accepted for upload, false if already uploading another image.
  94. */
  95. bool shareSnapshot(LLImageJPEG* snapshot, LLSD& metadata);
  96. private:
  97. static const S32 MAX_AUTH_RETRIES = 4;
  98. friend class LLSingleton<LLWebSharing>;
  99. LLWebSharing();
  100. ~LLWebSharing() {};
  101. /*
  102. * Request a map of URLs and URL templates to the web service end-points.
  103. *
  104. * @see receiveConfig()
  105. */
  106. void sendConfigRequest();
  107. /*
  108. * Initiate the OpenID login process.
  109. *
  110. * @see receiveSessionCookie()
  111. */
  112. void sendOpenIDAuthRequest();
  113. /*
  114. * Request a security token for the upload service.
  115. *
  116. * @see receiveSecurityToken()
  117. */
  118. void sendSecurityTokenRequest();
  119. /*
  120. * Request a security token for the upload service.
  121. *
  122. * @see receiveSecurityToken()
  123. */
  124. void sendUploadRequest();
  125. /*
  126. * Checks all necessary config information has been received, and sets mEnabled.
  127. *
  128. * @return true if both the OpenID cookie and config data have been received.
  129. */
  130. bool validateConfig();
  131. /*
  132. * Checks the security token is present and has not expired.
  133. *
  134. * @param token an LLSD map containing the token string and the time it expires.
  135. *
  136. * @return true if the token is not empty and has not expired.
  137. */
  138. static bool securityTokenIsValid(LLSD& token);
  139. std::string mOpenIDCookie;
  140. std::string mSessionCookie;
  141. LLSD mSecurityToken;
  142. LLSD mConfig;
  143. bool mEnabled;
  144. LLPointer<LLImageJPEG> mImage;
  145. LLSD mMetadata;
  146. S32 mRetries;
  147. };
  148. /**
  149. * @class LLUriTemplate
  150. *
  151. * @brief Builds complete URIs, given URI template and a map of keys and values
  152. * to use for substition.
  153. * Note: This is only a partial implementation of a draft standard required
  154. * by the web API used by LLWebSharing.
  155. * See: http://tools.ietf.org/html/draft-gregorio-uritemplate-03
  156. *
  157. * @see LLWebSharing
  158. */
  159. class LLUriTemplate
  160. {
  161. LOG_CLASS(LLUriTemplate);
  162. public:
  163. LLUriTemplate(const std::string& uri_template);
  164. ~LLUriTemplate() {};
  165. /*
  166. * Builds a complete URI from the template.
  167. *
  168. * @param vars an LLSD map of keys and values for substitution.
  169. *
  170. * @return a string containing the complete URI.
  171. */
  172. std::string buildURI(const LLSD& vars);
  173. private:
  174. /*
  175. * Builds a URL query string.
  176. *
  177. * @param delim a string containing the separator to use between name=value pairs.
  178. * @param var_list a string containing a comma separated list of variable names.
  179. * @param vars an LLSD map of keys and values for substitution.
  180. *
  181. * @return a URL query string.
  182. */
  183. std::string expandJoin(const std::string& delim, const std::string& var_list, const LLSD& vars);
  184. /*
  185. * URL escape the given string.
  186. * LLWeb::escapeURL() only does a partial escape, so this uses curl_escape() instead.
  187. */
  188. static std::string escapeURL(const std::string& unescaped);
  189. std::string mTemplate;
  190. };
  191. #endif // LL_LLWEBSHARING_H