Do not expect exact load timing. Hopefull makes buildbot results more stable (see...
[gnash.git] / libbase / StreamProvider.h
blob30f04fd8f883771c509577d9191f43f4ceab8d6a
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_STREAMPROVIDER_H
20 #define GNASH_STREAMPROVIDER_H
22 #include "NetworkAdapter.h"
23 #include "dsodefs.h" // for DSOEXPORT
24 #include "NamingPolicy.h"
26 #include <string>
27 #include <memory>
29 // Forward declarations
30 namespace gnash {
31 class URL;
32 class IOChannel;
36 namespace gnash {
38 /// A StreamProvider makes IOChannels available to the core on request.
40 /// The current functions of this class are:
41 /// 1. Inform users whether a connection to a certain URL is allowed.
42 /// 2. Make a connection and return an IOChannel (this performs a separate
43 /// access check).
44 ///
45 /// The class should in future also:
46 /// 3. Take relative URLs and resolve them against the base URL.
48 /// TODO: this class should become an abstract interface.
49 class DSOEXPORT StreamProvider
51 public:
53 /// Construct a StreamProvider
55 /// @param original The original URL, used to decide whether to allow
56 /// connections.
57 /// @param base The base URL, used to resolve URLs.
58 /// @param np A policy to decide the name of cached files.
59 StreamProvider(const URL& original, const URL& base,
60 std::auto_ptr<NamingPolicy> np =
61 std::auto_ptr<NamingPolicy>(new NamingPolicy));
63 virtual ~StreamProvider() {}
65 /// Returned stream ownership is transferred to caller.
67 /// On error NULL is returned
68 /// Derive from this for a CachingStreamProvider
69 virtual std::auto_ptr<IOChannel> getStream(const URL& url,
70 bool namedCacheFile = false) const;
72 /// Get a stream from the response of a POST operation
74 /// Returned stream ownership is transferred to caller.
75 ///
76 /// On error NULL is returned
77 /// Derive from this for a CachingStreamProvider
78 ///
79 /// @param url The url to post to.
80 /// @param postdata Post data in url-encoded form.
81 virtual std::auto_ptr<IOChannel> getStream(const URL& url,
82 const std::string& postdata, bool namedCacheFile = false) const;
84 virtual std::auto_ptr<IOChannel> getStream(const URL& url,
85 const std::string& postdata,
86 const NetworkAdapter::RequestHeaders& headers,
87 bool namedCacheFile = false) const;
89 /// Set the NamingPolicy for cache files
91 /// This is only used when cache file naming is requested in getStream()
92 /// This StreamProvider owns the NamingPolicy instance.
93 void setNamingPolicy(std::auto_ptr<NamingPolicy> np) {
94 _namingPolicy = np;
97 /// Return the currently selected policy for converting URL to filename
98 const NamingPolicy& namingPolicy() const {
99 assert(_namingPolicy.get());
100 return *_namingPolicy;
103 /// Check whether access to a URL is allowed
105 /// This is used by the core to check whether a connection can be
106 /// made before trying to make it. It's useful currently for
107 /// some functions to decide what to return.
109 /// @param url The url to check
110 /// @return true if allowed, false if not.
111 bool allow(const URL& url) const;
113 /// The base URL that should be used to resolve all relative URLs.
115 /// TODO: drop this if possible and handle all resolution in
116 /// this class.
117 const URL& baseURL() const {
118 return _base;
121 private:
123 /// The current naming policy for cache files.
124 std::auto_ptr<NamingPolicy> _namingPolicy;
126 const URL _base;
128 const URL _original;
132 } // namespace gnash
134 #endif
137 // Local Variables:
138 // mode: C++
139 // indent-tabs-mode: t
140 // End: