PageRenderTime 54ms CodeModel.GetById 17ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llmessage/llhttpassetstorage.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 159 lines | 93 code | 32 blank | 34 comment | 0 complexity | 317355f8ee237c531e1e60938d5f7b35 MD5 | raw file
  1/** 
  2 * @file llhttpassetstorage.h
  3 * @brief Class for loading asset data to/from an external source over http.
  4 *
  5 * $LicenseInfo:firstyear=2003&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 LLHTTPASSETSTORAGE_H
 28#define LLHTTPASSETSTORAGE_H
 29
 30#include "llassetstorage.h"
 31#include "curl/curl.h"
 32
 33class LLVFile;
 34class LLHTTPAssetRequest;
 35typedef void (*progress_callback)(void* userdata);
 36
 37struct LLTempAssetData;
 38
 39typedef std::map<LLUUID,LLTempAssetData> uuid_tempdata_map;
 40
 41class LLHTTPAssetStorage : public LLAssetStorage
 42{
 43public:
 44	LLHTTPAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
 45					   LLVFS *vfs, LLVFS *static_vfs,
 46					   const LLHost &upstream_host,
 47					   const std::string& web_host,
 48					   const std::string& local_web_host,
 49					   const std::string& host_name);
 50
 51	LLHTTPAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
 52					   LLVFS *vfs, LLVFS *static_vfs,
 53					   const std::string& web_host,
 54					   const std::string& local_web_host,
 55					   const std::string& host_name);
 56
 57
 58	virtual ~LLHTTPAssetStorage();
 59
 60	using LLAssetStorage::storeAssetData; // Unhiding virtuals...
 61
 62	virtual void storeAssetData(
 63		const LLUUID& uuid,
 64		LLAssetType::EType atype,
 65		LLStoreAssetCallback callback,
 66		void* user_data,
 67		bool temp_file = false,
 68		bool is_priority = false,
 69		bool store_local = false,
 70		const LLUUID& requesting_agent_id = LLUUID::null,
 71		bool user_waiting=FALSE,
 72		F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
 73
 74	virtual void storeAssetData(
 75		const std::string& filename,
 76		const LLUUID& asset_id,
 77		LLAssetType::EType atype,
 78		LLStoreAssetCallback callback,
 79		void* user_data,
 80		bool temp_file,
 81		bool is_priority,
 82		bool user_waiting=FALSE,
 83		F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
 84
 85	virtual LLSD getPendingDetails(ERequestType rt,
 86	 				LLAssetType::EType asset_type,
 87	 				const std::string& detail_prefix) const;
 88
 89	virtual LLSD getPendingRequest(ERequestType rt,
 90							LLAssetType::EType asset_type,
 91							const LLUUID& asset_id) const;
 92
 93	virtual bool deletePendingRequest(ERequestType rt,
 94							LLAssetType::EType asset_type,
 95							const LLUUID& asset_id);
 96
 97	// Hack.  One off curl download an URL to a file.  Probably should be elsewhere.
 98	// Only used by lldynamicstate.  The API is broken, and should be replaced with
 99	// a generic HTTP file fetch - Doug 9/25/06
100	S32 getURLToFile(const LLUUID& uuid, LLAssetType::EType asset_type, const std::string &url, const std::string& filename, progress_callback callback, void *userdata);
101	
102	LLAssetRequest* findNextRequest(request_list_t& pending, request_list_t& running);
103
104	void checkForTimeouts();
105	
106	static size_t curlDownCallback(void *data, size_t size, size_t nmemb, void *user_data);
107	static size_t curlFileDownCallback(void *data, size_t size, size_t nmemb, void *user_data);
108	static size_t curlUpCallback(void *data, size_t size, size_t nmemb, void *user_data);
109	static size_t nullOutputCallback(void *data, size_t size, size_t nmemb, void *user_data);
110
111	// Should only be used by the LLHTTPAssetRequest
112	void addRunningRequest(ERequestType rt, LLHTTPAssetRequest* request);
113	void removeRunningRequest(ERequestType rt, LLHTTPAssetRequest* request);
114
115	request_list_t* getRunningList(ERequestType rt);
116	const request_list_t* getRunningList(ERequestType rt) const;
117
118	// Temp assets are stored on sim nodes, they have agent ID and location data associated with them.
119	virtual void addTempAssetData(const LLUUID& asset_id, const LLUUID& agent_id, const std::string& host_name);
120	virtual BOOL hasTempAssetData(const LLUUID& texture_id) const;
121	virtual std::string getTempAssetHostName(const LLUUID& texture_id) const;
122	virtual LLUUID getTempAssetAgentID(const LLUUID& texture_id) const;
123	virtual void removeTempAssetData(const LLUUID& asset_id);
124	virtual void removeTempAssetDataByAgentID(const LLUUID& agent_id);
125
126	// Pass LLUUID::null for all
127	virtual void dumpTempAssetData(const LLUUID& avatar_id) const;
128	virtual void clearTempAssetData();
129
130protected:
131	void _queueDataRequest(const LLUUID& uuid, LLAssetType::EType type,
132						   void (*callback)(LLVFS *vfs, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat),
133						   void *user_data, BOOL duplicate, BOOL is_priority);
134
135private:
136	void _init(const std::string& web_host, const std::string& local_web_host, const std::string& host_name);
137
138	// This will return the correct base URI for any http asset request
139	std::string getBaseURL(const LLUUID& asset_id, LLAssetType::EType asset_type);
140
141	// Check for running uploads that have timed out
142	// Bump these to the back of the line to let other uploads complete.
143	void bumpTimedOutUploads();
144
145protected:
146	std::string		mBaseURL;
147	std::string		mLocalBaseURL;
148	std::string		mHostName;
149
150	CURLM  *mCurlMultiHandle;
151
152	request_list_t mRunningDownloads;
153	request_list_t mRunningUploads;
154	request_list_t mRunningLocalUploads;
155
156	uuid_tempdata_map mTempAssets;
157};
158
159#endif