Debian Codegraph @

contrib/epee/include/net/abstract_http_client.h

raw symbols SCIP
1 // Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of the Andrey N. Sabelnikov nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26 #pragma once
27
28 #include <string>
29 #include <boost/optional/optional.hpp>
30 #include "http_auth.h"
31 #include "net/net_ssl.h"
32
33 namespace epee
34 {
35 namespace net_utils
36 {
37 inline const char* get_hex_vals()
38 {
39 static constexpr const char hexVals[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
40 return hexVals;
41 }
42
43 inline const char* get_unsave_chars()
44 {
45 //static constexpr char unsave_chars[] = "\"<>%\\^[]`+$,@:;/!#?=&";
46 static constexpr const char unsave_chars[] = "\"<>%\\^[]`+$,@:;!#&";
47 return unsave_chars;
48 }
49
50 bool is_unsafe(unsigned char compare_char);
51 std::string dec_to_hex(char num, int radix);
52 int get_index(const char *s, char c);
53 std::string hex_to_dec_2bytes(const char *s);
54 std::string convert(char val);
55 std::string conver_to_url_format(const std::string& uri);
56 std::string convert_from_url_format(const std::string& uri);
57 std::string convert_to_url_format_force_all(const std::string& uri);
58
59 namespace http
60 {
61 class abstract_http_client
62 {
63 public:
64 abstract_http_client() {}
65 virtual ~abstract_http_client() {}
66 bool set_server(const std::string& address, boost::optional<login> user, ssl_options_t ssl_options = ssl_support_t::e_ssl_support_autodetect);
67 virtual bool set_proxy(const std::string& address);
68 virtual void set_server(std::string host, std::string port, boost::optional<login> user, ssl_options_t ssl_options = ssl_support_t::e_ssl_support_autodetect) = 0;
69 virtual void set_auto_connect(bool auto_connect) = 0;
70 virtual bool connect(std::chrono::milliseconds timeout) = 0;
71 virtual bool disconnect() = 0;
72 virtual bool is_connected(bool *ssl = NULL) = 0;
73 virtual bool invoke(const boost::string_ref uri, const boost::string_ref method, const boost::string_ref body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0;
74 virtual bool invoke_get(const boost::string_ref uri, std::chrono::milliseconds timeout, const std::string& body = std::string(), const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0;
75 virtual bool invoke_post(const boost::string_ref uri, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0;
76 virtual uint64_t get_bytes_sent() const = 0;
77 virtual uint64_t get_bytes_received() const = 0;
78 };
79
80 class http_client_factory
81 {
82 public:
83 virtual ~http_client_factory() {}
84 virtual std::unique_ptr<abstract_http_client> create() = 0;
85 };
86 }
87 }
88 }