cpp-ipfs-http-client: include/ipfs/http/transport-curl.h Source File

cpp-ipfs-http-client IPFS C++ client library

transport-curl.h
1 /* Copyright (c) 2016-2019, The C++ IPFS client library developers
2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of
4 this software and associated documentation files (the "Software"), to deal in
5 the Software without restriction, including without limitation the rights to
6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 the Software, and to permit persons to whom the Software is furnished to do so,
8 subject to the following conditions:
9
10 The above copyright notice and this permission notice shall be included in all
11 copies or substantial portions of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
19
20 #ifndef IPFS_HTTP_TRANSPORT_CURL_H
21 #define IPFS_HTTP_TRANSPORT_CURL_H
22
23 #include <curl/curl.h>
24 #include <ipfs/http/transport.h>
25
26 #include <iostream>
27 #include <string>
28 #include <vector>
29
30 namespace ipfs {
31
32 namespace http {
33
35 class TransportCurl : public Transport {
36 public:
38 TransportCurl();
39
41 ~TransportCurl();
42
48 void Fetch(
50 const std::string& url,
52 const std::vector<FileUpload>& files,
54 std::iostream* response) override;
55
57 void UrlEncode(
59 const std::string& raw,
61 std::string* encoded) override;
62
65 void Test();
66
67 private:
69 void HandleSetup();
70
74 void Perform(
76 const std::string& url,
78 std::iostream* response);
79
81 void HandleDestroy();
82
84 CURL* curl_;
85
87 bool curl_is_setup_;
88
90 char curl_error_[CURL_ERROR_SIZE];
91
93 bool url_encode_injected_failure = false;
94
96 bool handle_setup_injected_failure = false;
97
99 bool perform_injected_failure = false;
100 };
101
102 } /* namespace http */
103 } /* namespace ipfs */
104
105 #endif /* IPFS_HTTP_TRANSPORT_CURL_H */
ipfs::http::TransportCurl::TransportCurl
TransportCurl()
Constructor.
Definition: transport-curl.cc:90
ipfs::http::TransportCurl
Convenience class for talking basic HTTP, implemented using CURL.
Definition: transport-curl.h:35
ipfs::http::TransportCurl::~TransportCurl
~TransportCurl()
Destructor.
Definition: transport-curl.cc:98
ipfs::http::Transport
Convenience interface for talking basic HTTP.
Definition: transport.h:53
ipfs::http::TransportCurl::UrlEncode
void UrlEncode(const std::string &raw, std::string *encoded) override
URL encode a string.
Definition: transport-curl.cc:180
ipfs::http::TransportCurl::Fetch
void Fetch(const std::string &url, const std::vector< FileUpload > &files, std::iostream *response) override
Fetch the contents of a given URL.
Definition: transport-curl.cc:100
ipfs::http::TransportCurl::Test
void Test()
Test the internals that are hard to execute from the public API, like error handling of some exceptio...
Definition: transport-curl.cc:276
ipfs
IPFS namespace.
Definition: client.h:32