Avoid appending null byte to RTMP method name.
[gnash.git] / libbase / NetworkAdapter.h
blobf4a77d409a7113e367362e126692d26291190a88
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
20 #ifndef NETWORK_ADAPTER_H
21 #define NETWORK_ADAPTER_H
23 #include "dsodefs.h"
25 #include <map>
26 #include <string>
27 #include <memory>
28 #include <set>
29 #include "StringPredicates.h"
31 namespace gnash {
32 class IOChannel;
34 /// Code to use libcurl as an IOChannel stream.
35 class NetworkAdapter {
37 public:
39 /// Custom headers for addRequestHeader. These are case insensitive, and
40 /// subsequent addition of a header already there replaces any previous one.
41 /// Some values are not allowed.
42 typedef std::map<std::string, std::string, StringNoCaseLessThan>
43 RequestHeaders;
45 /// \brief
46 /// Returns a read-only IOChannel that fetches data
47 /// from an url.
49 /// @param url The url to fetch data from.
50 DSOEXPORT static std::auto_ptr<IOChannel> makeStream(
51 const std::string& url, const std::string& cachefile);
53 /// \brief
54 /// Returns a read-only IOChannel that fetches data
55 /// from an url getting posted to.
57 /// The caller owns the returned IOChannel.
58 ///
59 /// @param url The url to post to.
60 /// @param postdata The url-encoded post data
61 DSOEXPORT static std::auto_ptr<IOChannel> makeStream(
62 const std::string& url, const std::string& postdata,
63 const std::string& cachefile);
65 /// \brief
66 /// Returns a read-only IOChannel that fetches data
67 /// from an url getting posted to.
69 /// The caller owns the returned IOChannel.
70 ///
71 /// @param url The url to post to.
72 /// @param postdata The url-encoded post data
73 /// @param headers A RequestHeaders map of custom headers to send.
74 DSOEXPORT static std::auto_ptr<IOChannel> makeStream(const std::string& url,
75 const std::string& postdata, const RequestHeaders& headers,
76 const std::string& cachefile);
79 typedef std::set<std::string, StringNoCaseLessThan> ReservedNames;
81 /// Check whether a RequestHeader is permitted.
83 /// @param headerName is checked against a set of reserved names
84 /// (case-insensitive).
85 /// @return true if the name is allowed.
86 DSOEXPORT static bool isHeaderAllowed(const std::string& headerName)
88 const ReservedNames& names = reservedNames();
89 return (names.find(headerName) == names.end());
92 private:
94 static const ReservedNames& reservedNames();
98 } // namespace gnash
100 #endif // CURL_ADAPTER_H
102 // Local Variables:
103 // mode: C++
104 // indent-tabs-mode: t
105 // End: