1 // StreamProvider.cpp: ActionScript file: or http: stream reader, for Gnash.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "GnashFileUtilities.h"
22 #include "StreamProvider.h"
25 #include "NetworkAdapter.h"
26 #include "URLAccessManager.h"
28 #include "rc.h" // for rcfile
29 #include "NamingPolicy.h"
35 #include <boost/shared_ptr.hpp>
39 StreamProvider::StreamProvider(const URL
& orig
, const URL
& base
,
40 std::auto_ptr
<NamingPolicy
> np
)
49 StreamProvider::allow(const URL
& url
) const
51 return URLAccessManager::allow(url
, _original
);
54 std::auto_ptr
<IOChannel
>
55 StreamProvider::getStream(const URL
& url
, bool namedCacheFile
) const
58 std::auto_ptr
<IOChannel
> stream
;
60 if (url
.protocol() == "file") {
62 std::string path
= url
.path();
64 // TODO: only allow this as the *very first* call ?
65 // Rationale is a movie might request load of
66 // standard input, being a security issue.
67 // Note also that the FB gui will use stdin
70 FILE *newin
= fdopen(dup(0), "rb");
72 // Close on destruction.
73 stream
= makeFileChannel(newin
, true);
77 // check security here !!
78 if (!allow(url
)) return stream
;
80 FILE *newin
= std::fopen(path
.c_str(), "rb");
84 // Close on destruction
85 stream
= makeFileChannel(newin
, true);
91 stream
= NetworkAdapter::makeStream(url
.str(),
92 namedCacheFile
? namingPolicy()(url
) : "");
95 // Will return 0 auto_ptr if not allowed.
100 std::auto_ptr
<IOChannel
>
101 StreamProvider::getStream(const URL
& url
, const std::string
& postdata
,
102 const NetworkAdapter::RequestHeaders
& headers
, bool namedCacheFile
)
106 if (url
.protocol() == "file") {
107 if (!headers
.empty()) {
108 log_error("Request Headers discarded while getting stream "
111 return getStream(url
, postdata
);
115 return NetworkAdapter::makeStream(url
.str(), postdata
, headers
,
116 namedCacheFile
? namingPolicy()(url
) : "");
119 return std::auto_ptr
<IOChannel
>();
123 std::auto_ptr
<IOChannel
>
124 StreamProvider::getStream(const URL
& url
, const std::string
& postdata
,
125 bool namedCacheFile
) const
128 std::auto_ptr
<IOChannel
> stream
;
130 if (url
.protocol() == "file") {
131 if (!postdata
.empty()) {
132 log_error(_("POST data discarded while getting a stream "
135 std::string path
= url
.path();
137 FILE *newin
= fdopen(dup(0), "rb");
138 stream
= makeFileChannel(newin
, false);
142 if (!allow(url
)) return stream
;
144 FILE *newin
= std::fopen(path
.c_str(), "rb");
148 stream
= makeFileChannel(newin
, false);
154 stream
= NetworkAdapter::makeStream(url
.str(), postdata
,
155 namedCacheFile
? namingPolicy()(url
) : "");
157 // Will return 0 auto_ptr if not allowed.