2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
29 #include "StringPredicates.h"
34 /// Code to use libcurl as an IOChannel stream.
35 class NetworkAdapter
{
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
>
46 /// Returns a read-only IOChannel that fetches data
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
);
54 /// Returns a read-only IOChannel that fetches data
55 /// from an url getting posted to.
57 /// The caller owns the returned IOChannel.
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
);
66 /// Returns a read-only IOChannel that fetches data
67 /// from an url getting posted to.
69 /// The caller owns the returned IOChannel.
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());
94 static const ReservedNames
& reservedNames();
100 #endif // CURL_ADAPTER_H
104 // indent-tabs-mode: t