Electroneum
epee::net_utils Namespace Reference

Namespaces

 http
 
 jsonrpc2
 
 munin
 
 smtp
 

Classes

class  abstract_tcp_server
 
class  async_blocked_mode_client
 
class  blocked_mode_client
 
class  boosted_tcp_server
 
class  buffer
 
struct  calculate_times_struct
 
class  connection
 Represents a single connection from a client. More...
 
class  connection_basic
 
class  connection_basic_pimpl
 
class  connection_basic_shared_state
 
struct  connection_context_base
 
class  content_encoding_gzip
 
class  cp_server_impl
 
struct  direct_connect
 
class  do_nothing_sub_handler
 
struct  i_connection_filter
 
class  i_network_throttle
 
struct  i_protocol_handler
 
struct  i_service_endpoint
 
struct  i_sub_handler
 
struct  i_target_handler
 
class  ipv4_network_address
 
class  network_address
 
class  network_throttle
 
struct  network_throttle_bw
 
class  network_throttle_manager
 
struct  protocl_switcher_config
 
class  protocol_switcher
 
class  soket_sender
 
struct  ssl_authentication_t
 
class  ssl_options_t
 
class  t_protocol_handler
 

Typedefs

typedef std::map< SOCKET, boost::shared_ptr< connection< TProtocol > > > connections_container
 
typedef cp_server_impl< http::simple_http_connection_handlercp_http_server_file_system
 
typedef cp_server_impl< http::http_custom_handlercp_http_server_custum_handling
 
typedef boosted_tcp_server< http::simple_http_connection_handler<> > boosted_http_server_file_system
 
typedef boosted_tcp_server< http::http_custom_handler<> > boosted_http_server_custum_handling
 
typedef abstract_tcp_server< http::simple_http_connection_handlermt_http_server_file_system
 
typedef abstract_tcp_server< http::http_custom_handlermt_http_server_custum_handling
 
typedef levin::levin_client_impl levin_client
 
typedef levin::levin_client_impl2 levin_client2
 
typedef cp_server_impl< levin::protocol_handlercp_levin_server
 
typedef boosted_tcp_server< levin::protocol_handler<> > boosted_levin_server
 
typedef boosted_tcp_server< levin::async_protocol_handler<> > boosted_levin_async_server
 
typedef boosted_tcp_server< net_utils::protocol_switcherboosted_multiprotocol_server
 
typedef double network_speed_kbps
 
typedef double network_speed_bps
 
typedef double network_time_seconds
 
typedef double network_MB
 
typedef calculate_times_struct calculate_times_struct
 

Enumerations

enum  t_connection_type { e_connection_type_NET = 0, e_connection_type_RPC = 1, e_connection_type_P2P = 2 }
 
enum  address_type : std::uint8_t {
  address_type::invalid = 0, address_type::ipv4 = 1, address_type::ipv6 = 2, address_type::i2p = 3,
  address_type::tor = 4
}
 
enum  zone : std::uint8_t { zone::invalid = 0, zone::public_ = 1, zone::i2p = 2, zone::tor = 3 }
 
enum  ssl_support_t : uint8_t { ssl_support_t::e_ssl_support_disabled, ssl_support_t::e_ssl_support_enabled, ssl_support_t::e_ssl_support_autodetect }
 
enum  ssl_verification_t : uint8_t { ssl_verification_t::none = 0, ssl_verification_t::system_ca, ssl_verification_t::user_certificates, ssl_verification_t::user_ca }
 

Functions

PRAGMA_WARNING_POP bool worker_thread_member ()
 
bool add_new_connection (SOCKET new_sock, long ip_from, int port_from)
 
bool shutdown_connection (connection< TProtocol > *pconn)
 
std::string to_string (t_connection_type type)
 
const char * zone_to_string (zone value) noexcept
 
zone zone_from_string (boost::string_ref value) noexcept
 
bool http_ssl_invoke (const std::string &url, const std::string usr, const std::string psw, std::string &http_response_body, bool use_post=false)
 
bool is_ip_local (uint32_t ip)
 
bool is_ip_loopback (uint32_t ip)
 
bool parse_uri_query (const std::string &query, std::list< std::pair< std::string, std::string > > &params)
 
bool parse_uri (const std::string uri, http::uri_content &content)
 
bool parse_url (const std::string url_str, http::url_content &content)
 
constexpr size_t get_ssl_magic_size ()
 
bool is_ssl (const unsigned char *data, size_t len)
 
bool ssl_support_from_string (ssl_support_t &ssl, boost::string_ref s)
 
bool create_ec_ssl_certificate (EVP_PKEY *&pkey, X509 *&cert)
 
bool create_rsa_ssl_certificate (EVP_PKEY *&pkey, X509 *&cert)
 
bool operator== (const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
 
bool operator!= (const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
 
bool operator< (const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
 
bool operator<= (const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
 
bool operator> (const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
 
bool operator>= (const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
 
bool operator== (const network_address &lhs, const network_address &rhs)
 
bool operator!= (const network_address &lhs, const network_address &rhs)
 
bool operator< (const network_address &lhs, const network_address &rhs)
 
bool operator<= (const network_address &lhs, const network_address &rhs)
 
bool operator> (const network_address &lhs, const network_address &rhs)
 
bool operator>= (const network_address &lhs, const network_address &rhs)
 
std::string print_connection_context (const connection_context_base &ctx)
 
std::string print_connection_context_short (const connection_context_base &ctx)
 
 MAKE_LOGGABLE (connection_context_base, ct, os)
 
template<class t_request , class t_response , class t_transport >
bool invoke_http_json (const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
 
template<class t_response , class t_transport >
bool get_http_json (const boost::string_ref uri, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
 
template<class t_request , class t_response , class t_transport >
bool invoke_http_bin (const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
 
template<class t_request , class t_response , class t_transport >
bool invoke_http_json_rpc (const boost::string_ref uri, std::string method_name, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref http_method="GET", const std::string &req_id="0")
 
template<class t_command , class t_transport >
bool invoke_http_json_rpc (const boost::string_ref uri, typename t_command::request &out_struct, typename t_command::response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref http_method="GET", const std::string &req_id="0")
 
template<class t_arg , class t_result , class t_transport >
bool invoke_remote_command2 (int command, const t_arg &out_struct, t_result &result_struct, t_transport &transport)
 
template<class t_arg , class t_transport >
bool notify_remote_command2 (int command, const t_arg &out_struct, t_transport &transport)
 
template<class t_arg , class t_result , class t_transport >
bool invoke_remote_command2 (boost::uuids::uuid conn_id, int command, const t_arg &out_struct, t_result &result_struct, t_transport &transport)
 
template<class t_result , class t_arg , class callback_t , class t_transport >
bool async_invoke_remote_command2 (boost::uuids::uuid conn_id, int command, const t_arg &out_struct, t_transport &transport, const callback_t &cb, size_t inv_timeout=LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
 
template<class t_arg , class t_transport >
bool notify_remote_command2 (boost::uuids::uuid conn_id, int command, const t_arg &out_struct, t_transport &transport)
 
template<class t_owner , class t_in_type , class t_out_type , class t_context , class callback_t >
int buff_to_t_adapter (int command, const epee::span< const uint8_t > in_buff, std::string &buff_out, callback_t cb, t_context &context)
 
template<class t_owner , class t_in_type , class t_context , class callback_t >
int buff_to_t_adapter (t_owner *powner, int command, const epee::span< const uint8_t > in_buff, callback_t cb, t_context &context)
 
bool create_ec_ssl_certificate (EVP_PKEY *&pkey, X509 *&cert, int type)
 

Variables

SOCKET m_listen_socket
 
HANDLE m_completion_port
 
connections_container m_connections
 
critical_section m_connections_lock
 
int m_port
 
volatile LONG m_stop
 
bool m_initialized
 
volatile LONG m_worker_thread_counter
 
TProtocol::config_type m_config
 
class epee::net_utils::buffer resize_send_buff
 

Typedef Documentation

◆ boosted_http_server_custum_handling

◆ boosted_http_server_file_system

◆ boosted_levin_async_server

◆ boosted_levin_server

◆ boosted_multiprotocol_server

◆ calculate_times_struct

◆ connections_container

typedef std::map<SOCKET, boost::shared_ptr<connection<TProtocol> > > epee::net_utils::connections_container

Definition at line 219 of file abstract_tcp_server_cp.h.

◆ cp_http_server_custum_handling

◆ cp_http_server_file_system

◆ cp_levin_server

◆ levin_client

◆ levin_client2

◆ mt_http_server_custum_handling

◆ mt_http_server_file_system

◆ network_MB

Definition at line 87 of file network_throttle.hpp.

◆ network_speed_bps

Definition at line 85 of file network_throttle.hpp.

◆ network_speed_kbps

Definition at line 84 of file network_throttle.hpp.

◆ network_time_seconds

Definition at line 86 of file network_throttle.hpp.

Enumeration Type Documentation

◆ address_type

Enumerator
invalid 
ipv4 
ipv6 
i2p 
tor 

Definition at line 38 of file enums.h.

38  : std::uint8_t
39  {
40  // Do not change values, this will break serialization
41  invalid = 0,
42  ipv4 = 1,
43  ipv6 = 2,
44  i2p = 3,
45  tor = 4
46  };
unsigned char uint8_t
Definition: stdint.h:124

◆ ssl_support_t

Enumerator
e_ssl_support_disabled 
e_ssl_support_enabled 
e_ssl_support_autodetect 

Definition at line 46 of file net_ssl.h.

◆ ssl_verification_t

Enumerator
none 

Do not verify peer.

system_ca 

Verify peer via system ca only (do not inspect user certificates)

user_certificates 

Verify peer via specific (non-chain) certificate(s) only.

user_ca 

Verify peer via specific (possibly chain) certificate(s) only.

Definition at line 52 of file net_ssl.h.

52  : uint8_t
53  {
54  none = 0,
55  system_ca,
57  user_ca
58  };
unsigned char uint8_t
Definition: stdint.h:124
Verify peer via system ca only (do not inspect user certificates)
Verify peer via specific (possibly chain) certificate(s) only.
Verify peer via specific (non-chain) certificate(s) only.

◆ t_connection_type

Enumerator
e_connection_type_NET 
e_connection_type_RPC 
e_connection_type_P2P 

Definition at line 93 of file connection_basic.hpp.

93  { // type of the connection (of this server), e.g. so that we will know how to limit it
94  e_connection_type_NET = 0, // default (not used?)
95  e_connection_type_RPC = 1, // the rpc commands (probably not rate limited, not chunked, etc)
96  e_connection_type_P2P = 2 // to other p2p node (probably limited)
97  };

◆ zone

Enumerator
invalid 
public_ 
i2p 
tor 

Definition at line 48 of file enums.h.

48  : std::uint8_t
49  {
50  invalid = 0,
51  public_ = 1, // public is keyword
52  i2p = 2,
53  tor = 3
54  };
unsigned char uint8_t
Definition: stdint.h:124

Function Documentation

◆ add_new_connection()

bool epee::net_utils::add_new_connection ( SOCKET  new_sock,
long  ip_from,
int  port_from 
)

◆ async_invoke_remote_command2()

template<class t_result , class t_arg , class callback_t , class t_transport >
bool epee::net_utils::async_invoke_remote_command2 ( boost::uuids::uuid  conn_id,
int  command,
const t_arg &  out_struct,
t_transport &  transport,
const callback_t &  cb,
size_t  inv_timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED 
)

Definition at line 113 of file levin_abstract_invoke2.h.

114  {
115  typename serialization::portable_storage stg;
116  const_cast<t_arg&>(out_struct).store(stg);//TODO: add true const support to searilzation
117  std::string buff_to_send;
118  stg.store_to_binary(buff_to_send);
119  int res = transport.invoke_async(command, epee::strspan<uint8_t>(buff_to_send), conn_id, [cb, command](int code, const epee::span<const uint8_t> buff, typename t_transport::connection_context& context)->bool
120  {
121  t_result result_struct = AUTO_VAL_INIT(result_struct);
122  if( code <=0 )
123  {
124  LOG_PRINT_L1("Failed to invoke command " << command << " return code " << code);
125  cb(code, result_struct, context);
126  return false;
127  }
128  serialization::portable_storage stg_ret;
129  if(!stg_ret.load_from_binary(buff))
130  {
131  LOG_ERROR("Failed to load_from_binary on command " << command);
132  cb(LEVIN_ERROR_FORMAT, result_struct, context);
133  return false;
134  }
135  if (!result_struct.load(stg_ret))
136  {
137  LOG_ERROR("Failed to load result struct on command " << command);
138  cb(LEVIN_ERROR_FORMAT, result_struct, context);
139  return false;
140  }
141  cb(code, result_struct, context);
142  return true;
143  }, inv_timeout);
144  if( res <=0 )
145  {
146  LOG_PRINT_L1("Failed to invoke command " << command << " return code " << res);
147  return false;
148  }
149  return true;
150  }
const char * res
Definition: hmac_keccak.cpp:41
#define LEVIN_ERROR_FORMAT
Definition: levin_base.h:100
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
::std::string string
Definition: gtest-port.h:1097
Non-owning sequence of data. Does not deep copy.
Definition: span.h:56
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:

◆ buff_to_t_adapter() [1/2]

template<class t_owner , class t_in_type , class t_out_type , class t_context , class callback_t >
int epee::net_utils::buff_to_t_adapter ( int  command,
const epee::span< const uint8_t in_buff,
std::string &  buff_out,
callback_t  cb,
t_context &  context 
)

Definition at line 172 of file levin_abstract_invoke2.h.

173  {
174  serialization::portable_storage strg;
175  if(!strg.load_from_binary(in_buff))
176  {
177  LOG_ERROR("Failed to load_from_binary in command " << command);
178  return -1;
179  }
180  boost::value_initialized<t_in_type> in_struct;
181  boost::value_initialized<t_out_type> out_struct;
182 
183  if (!static_cast<t_in_type&>(in_struct).load(strg))
184  {
185  LOG_ERROR("Failed to load in_struct in command " << command);
186  return -1;
187  }
188  int res = cb(command, static_cast<t_in_type&>(in_struct), static_cast<t_out_type&>(out_struct), context);
189  serialization::portable_storage strg_out;
190  static_cast<t_out_type&>(out_struct).store(strg_out);
191 
192  if(!strg_out.store_to_binary(buff_out))
193  {
194  LOG_ERROR("Failed to store_to_binary in command" << command);
195  return -1;
196  }
197 
198  return res;
199  }
const char * res
Definition: hmac_keccak.cpp:41
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
void load(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
Here is the call graph for this function:

◆ buff_to_t_adapter() [2/2]

template<class t_owner , class t_in_type , class t_context , class callback_t >
int epee::net_utils::buff_to_t_adapter ( t_owner *  powner,
int  command,
const epee::span< const uint8_t in_buff,
callback_t  cb,
t_context &  context 
)

Definition at line 202 of file levin_abstract_invoke2.h.

203  {
204  serialization::portable_storage strg;
205  if(!strg.load_from_binary(in_buff))
206  {
207  LOG_ERROR("Failed to load_from_binary in notify " << command);
208  return -1;
209  }
210  boost::value_initialized<t_in_type> in_struct;
211  if (!static_cast<t_in_type&>(in_struct).load(strg))
212  {
213  LOG_ERROR("Failed to load in_struct in notify " << command);
214  return -1;
215  }
216  return cb(command, in_struct, context);
217  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
void load(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
Here is the call graph for this function:

◆ create_ec_ssl_certificate() [1/2]

bool epee::net_utils::create_ec_ssl_certificate ( EVP_PKEY *&  pkey,
X509 *&  cert 
)
Here is the caller graph for this function:

◆ create_ec_ssl_certificate() [2/2]

bool epee::net_utils::create_ec_ssl_certificate ( EVP_PKEY *&  pkey,
X509 *&  cert,
int  type 
)

Definition at line 192 of file net_ssl.cpp.

193 {
194  MGINFO("Generating SSL certificate");
195  pkey = EVP_PKEY_new();
196  if (!pkey)
197  {
198  MERROR("Failed to create new private key");
199  return false;
200  }
201 
202  openssl_pkey pkey_deleter{pkey};
203  openssl_ec_key ec_key{EC_KEY_new()};
204  if (!ec_key)
205  {
206  MERROR("Error allocating EC private key");
207  return false;
208  }
209 
210  EC_GROUP *group = EC_GROUP_new_by_curve_name(type);
211  if (!group)
212  {
213  MERROR("Error getting EC group " << type);
214  return false;
215  }
216  openssl_group group_deleter{group};
217 
218  EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
219  EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_UNCOMPRESSED);
220 
221  if (!EC_GROUP_check(group, NULL))
222  {
223  MERROR("Group failed check: " << ERR_reason_error_string(ERR_get_error()));
224  return false;
225  }
226  if (EC_KEY_set_group(ec_key.get(), group) != 1)
227  {
228  MERROR("Error setting EC group");
229  return false;
230  }
231  if (EC_KEY_generate_key(ec_key.get()) != 1)
232  {
233  MERROR("Error generating EC private key");
234  return false;
235  }
236  if (EVP_PKEY_assign_EC_KEY(pkey, ec_key.get()) <= 0)
237  {
238  MERROR("Error assigning EC private key");
239  return false;
240  }
241 
242  // the key is now managed by the EVP_PKEY structure
243  (void)ec_key.release();
244 
245  cert = X509_new();
246  if (!cert)
247  {
248  MERROR("Failed to create new X509 certificate");
249  return false;
250  }
251  ASN1_INTEGER_set(X509_get_serialNumber(cert), 1);
252  X509_gmtime_adj(X509_get_notBefore(cert), 0);
253  X509_gmtime_adj(X509_get_notAfter(cert), 3600 * 24 * 182); // half a year
254  if (!X509_set_pubkey(cert, pkey))
255  {
256  MERROR("Error setting pubkey on certificate");
257  X509_free(cert);
258  return false;
259  }
260  X509_NAME *name = X509_get_subject_name(cert);
261  X509_set_issuer_name(cert, name);
262 
263  if (X509_sign(cert, pkey, EVP_sha256()) == 0)
264  {
265  MERROR("Error signing certificate");
266  X509_free(cert);
267  return false;
268  }
269  (void)pkey_deleter.release();
270  return true;
271 }
#define MERROR(x)
Definition: misc_log_ex.h:73
const char * name
#define MGINFO(x)
Definition: misc_log_ex.h:80

◆ create_rsa_ssl_certificate()

bool epee::net_utils::create_rsa_ssl_certificate ( EVP_PKEY *&  pkey,
X509 *&  cert 
)

Definition at line 122 of file net_ssl.cpp.

123 {
124  MGINFO("Generating SSL certificate");
125  pkey = EVP_PKEY_new();
126  if (!pkey)
127  {
128  MERROR("Failed to create new private key");
129  return false;
130  }
131 
132  openssl_pkey pkey_deleter{pkey};
133  openssl_rsa rsa{RSA_new()};
134  if (!rsa)
135  {
136  MERROR("Error allocating RSA private key");
137  return false;
138  }
139 
140  openssl_bignum exponent{BN_new()};
141  if (!exponent)
142  {
143  MERROR("Error allocating exponent");
144  return false;
145  }
146 
147  BN_set_word(exponent.get(), RSA_F4);
148 
149  if (RSA_generate_key_ex(rsa.get(), 4096, exponent.get(), nullptr) != 1)
150  {
151  MERROR("Error generating RSA private key");
152  return false;
153  }
154 
155  if (EVP_PKEY_assign_RSA(pkey, rsa.get()) <= 0)
156  {
157  MERROR("Error assigning RSA private key");
158  return false;
159  }
160 
161  // the RSA key is now managed by the EVP_PKEY structure
162  (void)rsa.release();
163 
164  cert = X509_new();
165  if (!cert)
166  {
167  MERROR("Failed to create new X509 certificate");
168  return false;
169  }
170  ASN1_INTEGER_set(X509_get_serialNumber(cert), 1);
171  X509_gmtime_adj(X509_get_notBefore(cert), 0);
172  X509_gmtime_adj(X509_get_notAfter(cert), 3600 * 24 * 182); // half a year
173  if (!X509_set_pubkey(cert, pkey))
174  {
175  MERROR("Error setting pubkey on certificate");
176  X509_free(cert);
177  return false;
178  }
179  X509_NAME *name = X509_get_subject_name(cert);
180  X509_set_issuer_name(cert, name);
181 
182  if (X509_sign(cert, pkey, EVP_sha256()) == 0)
183  {
184  MERROR("Error signing certificate");
185  X509_free(cert);
186  return false;
187  }
188  (void)pkey_deleter.release();
189  return true;
190 }
#define MERROR(x)
Definition: misc_log_ex.h:73
const char * name
#define MGINFO(x)
Definition: misc_log_ex.h:80
Here is the caller graph for this function:

◆ get_http_json()

template<class t_response , class t_transport >
bool epee::net_utils::get_http_json ( const boost::string_ref  uri,
t_response &  result_struct,
t_transport &  transport,
std::chrono::milliseconds  timeout = std::chrono::seconds(15),
const boost::string_ref  method = "GET" 
)

Definition at line 73 of file http_abstract_invoke.h.

73  {
74 
75  const http::http_response_info* pri = NULL;
76  int retryCount = 0;
77  const int MAX_RETRY_COUNT = 10;
78 
79  //Boost asio read can be temperemental
80  while(!transport.invoke(uri, method, "", timeout, std::addressof(pri)) && retryCount < MAX_RETRY_COUNT) {
82  ++retryCount;
83  LOG_PRINT_L1("Failed to invoke http request. Retrying (" << retryCount << "/" << MAX_RETRY_COUNT << ").");
84  }
85 
86  if(retryCount == MAX_RETRY_COUNT) //Max retries reached
87  {
88  LOG_PRINT_L1("Failed to invoke http request to " << uri);
89  return false;
90  }
91 
92  if(!pri)
93  {
94  LOG_PRINT_L1("Failed to invoke http request to " << uri << ", internal error (null response ptr)");
95  return false;
96  }
97 
98  if(pri->m_response_code != 200)
99  {
100  LOG_PRINT_L1("Failed to invoke http request to " << uri << ", wrong response code: " << pri->m_response_code);
101  return false;
102  }
103 
104  return serialization::load_t_from_json(result_struct, pri->m_body);
105  }
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
bool load_t_from_json(t_struct &out, const std::string &json_buff)
bool sleep_no_w(long ms)
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_ssl_magic_size()

constexpr size_t epee::net_utils::get_ssl_magic_size ( )

Definition at line 135 of file net_ssl.h.

135 { return 9; }
Here is the caller graph for this function:

◆ http_ssl_invoke()

bool epee::net_utils::http_ssl_invoke ( const std::string &  url,
const std::string  usr,
const std::string  psw,
std::string &  http_response_body,
bool  use_post = false 
)
inline

Definition at line 43 of file http_client_via_api_helper.h.

44  {
45  bool final_res = false;
46 
47  ATL::CUrl url_obj;
48  BOOL crack_rss = url_obj.CrackUrl(string_encoding::convert_to_t<std::basic_string<TCHAR> >(url).c_str());
49 
50  HINTERNET hinet = ::InternetOpenA(SHARED_JOBSCOMMON_HTTP_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
51  if(!hinet)
52  {
53  int err = ::GetLastError();
54  LOG_PRINT("Failed to call InternetOpenA, \nError: " << err << " " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
55  return false;
56  }
57 
58  DWORD dwFlags = 0;
59  DWORD dwBuffLen = sizeof(dwFlags);
60 
61  if(usr.size())
62  {
63  dwFlags |= INTERNET_FLAG_IGNORE_CERT_CN_INVALID|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID|
64  INTERNET_FLAG_PRAGMA_NOCACHE | SECURITY_FLAG_IGNORE_UNKNOWN_CA|INTERNET_FLAG_SECURE;
65  }else
66  {
67  dwFlags |= INTERNET_FLAG_PRAGMA_NOCACHE;
68  }
69 
70 
71  int port = url_obj.GetPortNumber();
72  BOOL res = FALSE;
73 
74  HINTERNET hsession = ::InternetConnectA(hinet, string_encoding::convert_to_ansii(url_obj.GetHostName()).c_str(), port/*INTERNET_DEFAULT_HTTPS_PORT*/, usr.c_str(), psw.c_str(), INTERNET_SERVICE_HTTP, dwFlags, NULL);
75  if(hsession)
76  {
77  const std::string uri = string_encoding::convert_to_ansii(url_obj.GetUrlPath()) + string_encoding::convert_to_ansii(url_obj.GetExtraInfo());
78 
79  HINTERNET hrequest = ::HttpOpenRequestA(hsession, use_post?"POST":NULL, uri.c_str(), NULL, NULL,NULL, dwFlags, NULL);
80  if(hrequest)
81  {
82  while(true)
83  {
84  res = ::HttpSendRequestA(hrequest, NULL, 0, NULL, 0);
85  if(!res)
86  {
87  //ERROR_INTERNET_INVALID_CA 45
88  //ERROR_INTERNET_INVALID_URL (INTERNET_ERROR_BASE + 5)
89  int err = ::GetLastError();
90  LOG_PRINT("Failed to call HttpSendRequestA, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
91  break;
92  }
93 
94  DWORD code = 0;
95  DWORD buf_len = sizeof(code);
96  DWORD index = 0;
97  res = ::HttpQueryInfo(hrequest, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE, &code, &buf_len, &index);
98  if(!res)
99  {
100  //ERROR_INTERNET_INVALID_CA 45
101  //ERROR_INTERNET_INVALID_URL (INTERNET_ERROR_BASE + 5)
102  int err = ::GetLastError();
103  LOG_PRINT("Failed to call HttpQueryInfo, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
104  break;
105  }
106  if(code < 200 || code > 299)
107  {
108  LOG_PRINT("Wrong server response, HttpQueryInfo returned statuse code" << code , LOG_LEVEL_0);
109  break;
110  }
111 
112 
113  char buff[100000] = {0};
114  DWORD readed = 0;
115  while(true)
116  {
117  res = ::InternetReadFile(hrequest, buff, sizeof(buff), &readed);
118  if(!res)
119  {
120  int err = ::GetLastError();
121  LOG_PRINT("Failed to call InternetReadFile, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
122  break;
123  }
124  if(readed)
125  {
126  http_response_body.append(buff, readed);
127  }
128  else
129  break;
130  }
131 
132  if(!res)
133  break;
134 
135 
136  //we success
137  final_res = true;
138 
139  res = ::InternetCloseHandle(hrequest);
140  if(!res)
141  {
142  int err = ::GetLastError();
143  LOG_PRINT("Failed to call InternetCloseHandle, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
144  }
145 
146  break;
147  }
148  }
149  else
150  {
151  //ERROR_INTERNET_INVALID_CA
152  int err = ::GetLastError();
153  LOG_PRINT("Failed to call InternetOpenUrlA, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
154  return false;
155  }
156 
157  res = ::InternetCloseHandle(hsession);
158  if(!res)
159  {
160  int err = ::GetLastError();
161  LOG_PRINT("Failed to call InternetCloseHandle, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
162  }
163  }else
164  {
165  int err = ::GetLastError();
166  LOG_PRINT("Failed to call InternetConnectA(" << string_encoding::convert_to_ansii(url_obj.GetHostName()) << ", port " << port << " \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
167  }
168 
169 
170 
171  res = ::InternetCloseHandle(hinet);
172  if(!res)
173  {
174  int err = ::GetLastError();
175  LOG_PRINT("Failed to call InternetCloseHandle, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
176  }
177  return final_res;
178  }
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
std::string convert_to_ansii(const std::wstring &str_from)
Definition: string_coding.h:37
boost::endian::big_uint16_t port
Definition: socks.cpp:60
target_string convert_to_t(const std::wstring &str_from)
Here is the call graph for this function:

◆ invoke_http_bin()

template<class t_request , class t_response , class t_transport >
bool epee::net_utils::invoke_http_bin ( const boost::string_ref  uri,
const t_request &  out_struct,
t_response &  result_struct,
t_transport &  transport,
std::chrono::milliseconds  timeout = std::chrono::seconds(15),
const boost::string_ref  method = "GET" 
)

Definition at line 109 of file http_abstract_invoke.h.

110  {
111  std::string req_param;
112  if(!serialization::store_t_to_binary(out_struct, req_param))
113  return false;
114 
115  const http::http_response_info* pri = NULL;
116  if(!transport.invoke(uri, method, req_param, timeout, std::addressof(pri)))
117  {
118  LOG_PRINT_L1("Failed to invoke http request to " << uri);
119  return false;
120  }
121 
122  if(!pri)
123  {
124  LOG_PRINT_L1("Failed to invoke http request to " << uri << ", internal error (null response ptr)");
125  return false;
126  }
127 
128  if(pri->m_response_code != 200)
129  {
130  LOG_PRINT_L1("Failed to invoke http request to " << uri << ", wrong response code: " << pri->m_response_code);
131  return false;
132  }
133 
134  return serialization::load_t_from_binary(result_struct, epee::strspan<uint8_t>(pri->m_body));
135  }
bool store_t_to_binary(t_struct &str_in, std::string &binary_buff, size_t indent=0)
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
::std::string string
Definition: gtest-port.h:1097
bool load_t_from_binary(t_struct &out, const epee::span< const uint8_t > binary_buff)
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:
Here is the caller graph for this function:

◆ invoke_http_json()

template<class t_request , class t_response , class t_transport >
bool epee::net_utils::invoke_http_json ( const boost::string_ref  uri,
const t_request &  out_struct,
t_response &  result_struct,
t_transport &  transport,
std::chrono::milliseconds  timeout = std::chrono::seconds(15),
const boost::string_ref  method = "GET" 
)

Definition at line 41 of file http_abstract_invoke.h.

42  {
43  std::string req_param;
44  if(!serialization::store_t_to_json(out_struct, req_param))
45  return false;
46 
47  http::fields_list additional_params;
48  additional_params.push_back(std::make_pair("Content-Type","application/json; charset=utf-8"));
49 
50  const http::http_response_info* pri = NULL;
51  if(!transport.invoke(uri, method, req_param, timeout, std::addressof(pri), std::move(additional_params)))
52  {
53  LOG_PRINT_L1("Failed to invoke http request to " << uri);
54  return false;
55  }
56 
57  if(!pri)
58  {
59  LOG_PRINT_L1("Failed to invoke http request to " << uri << ", internal error (null response ptr)");
60  return false;
61  }
62 
63  if(pri->m_response_code != 200)
64  {
65  LOG_PRINT_L1("Failed to invoke http request to " << uri << ", wrong response code: " << pri->m_response_code);
66  return false;
67  }
68 
69  return serialization::load_t_from_json(result_struct, pri->m_body);
70  }
std::list< std::pair< std::string, std::string > > fields_list
Definition: http_base.h:66
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
::std::string string
Definition: gtest-port.h:1097
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
bool load_t_from_json(t_struct &out, const std::string &json_buff)
const T & move(const T &t)
Definition: gtest-port.h:1317
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:
Here is the caller graph for this function:

◆ invoke_http_json_rpc() [1/2]

template<class t_request , class t_response , class t_transport >
bool epee::net_utils::invoke_http_json_rpc ( const boost::string_ref  uri,
std::string  method_name,
const t_request &  out_struct,
t_response &  result_struct,
t_transport &  transport,
std::chrono::milliseconds  timeout = std::chrono::seconds(15),
const boost::string_ref  http_method = "GET",
const std::string &  req_id = "0" 
)

Definition at line 138 of file http_abstract_invoke.h.

139  {
141  req_t.jsonrpc = "2.0";
142  req_t.id = req_id;
143  req_t.method = std::move(method_name);
144  req_t.params = out_struct;
146  if(!epee::net_utils::invoke_http_json(uri, req_t, resp_t, transport, timeout, http_method))
147  {
148  return false;
149  }
150  if(resp_t.error.code || resp_t.error.message.size())
151  {
152  LOG_ERROR("RPC call of \"" << req_t.method << "\" returned error: " << resp_t.error.code << ", message: " << resp_t.error.message);
153  return false;
154  }
155  result_struct = resp_t.result;
156  return true;
157  }
epee::serialization::storage_entry id
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
const T & move(const T &t)
Definition: gtest-port.h:1317
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:
Here is the caller graph for this function:

◆ invoke_http_json_rpc() [2/2]

template<class t_command , class t_transport >
bool epee::net_utils::invoke_http_json_rpc ( const boost::string_ref  uri,
typename t_command::request &  out_struct,
typename t_command::response &  result_struct,
t_transport &  transport,
std::chrono::milliseconds  timeout = std::chrono::seconds(15),
const boost::string_ref  http_method = "GET",
const std::string &  req_id = "0" 
)

Definition at line 160 of file http_abstract_invoke.h.

161  {
162  return invoke_http_json_rpc(uri, t_command::methodname(), out_struct, result_struct, transport, timeout, http_method, req_id);
163  }
bool invoke_http_json_rpc(const boost::string_ref uri, typename t_command::request &out_struct, typename t_command::response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref http_method="GET", const std::string &req_id="0")
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:

◆ invoke_remote_command2() [1/2]

template<class t_arg , class t_result , class t_transport >
bool epee::net_utils::invoke_remote_command2 ( int  command,
const t_arg &  out_struct,
t_result &  result_struct,
t_transport &  transport 
)

Definition at line 43 of file levin_abstract_invoke2.h.

44  {
45  if(!transport.is_connected())
46  return false;
47 
48  serialization::portable_storage stg;
49  out_struct.store(stg);
50  std::string buff_to_send, buff_to_recv;
51  stg.store_to_binary(buff_to_send);
52 
53  int res = transport.invoke(command, buff_to_send, buff_to_recv);
54  if( res <=0 )
55  {
56  MERROR("Failed to invoke command " << command << " return code " << res);
57  return false;
58  }
59  serialization::portable_storage stg_ret;
60  if(!stg_ret.load_from_binary(buff_to_recv))
61  {
62  LOG_ERROR("Failed to load_from_binary on command " << command);
63  return false;
64  }
65  return result_struct.load(stg_ret);
66  }
const char * res
Definition: hmac_keccak.cpp:41
#define MERROR(x)
Definition: misc_log_ex.h:73
::std::string string
Definition: gtest-port.h:1097
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:

◆ invoke_remote_command2() [2/2]

template<class t_arg , class t_result , class t_transport >
bool epee::net_utils::invoke_remote_command2 ( boost::uuids::uuid  conn_id,
int  command,
const t_arg &  out_struct,
t_result &  result_struct,
t_transport &  transport 
)

Definition at line 89 of file levin_abstract_invoke2.h.

90  {
91 
92  typename serialization::portable_storage stg;
93  out_struct.store(stg);
94  std::string buff_to_send, buff_to_recv;
95  stg.store_to_binary(buff_to_send);
96 
97  int res = transport.invoke(command, buff_to_send, buff_to_recv, conn_id);
98  if( res <=0 )
99  {
100  LOG_PRINT_L1("Failed to invoke command " << command << " return code " << res);
101  return false;
102  }
103  typename serialization::portable_storage stg_ret;
104  if(!stg_ret.load_from_binary(buff_to_recv))
105  {
106  LOG_ERROR("Failed to load_from_binary on command " << command);
107  return false;
108  }
109  return result_struct.load(stg_ret);
110  }
const char * res
Definition: hmac_keccak.cpp:41
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
::std::string string
Definition: gtest-port.h:1097
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:

◆ is_ip_local()

bool epee::net_utils::is_ip_local ( uint32_t  ip)
inline

Definition at line 35 of file local_ip.h.

36  {
37  /*
38  local ip area
39  10.0.0.0 — 10.255.255.255
40  172.16.0.0 — 172.31.255.255
41  192.168.0.0 — 192.168.255.255
42  */
43  if( (ip | 0xffffff00) == 0xffffff0a)
44  return true;
45 
46  if( (ip | 0xffff0000) == 0xffffa8c0)
47  return true;
48 
49  if( (ip | 0xffffff00) == 0xffffffac)
50  {
51  uint32_t second_num = (ip >> 8) & 0xff;
52  if(second_num >= 16 && second_num <= 31 )
53  return true;
54  }
55  return false;
56  }
unsigned int uint32_t
Definition: stdint.h:126
boost::endian::big_uint32_t ip
Definition: socks.cpp:61
Here is the caller graph for this function:

◆ is_ip_loopback()

bool epee::net_utils::is_ip_loopback ( uint32_t  ip)
inline

Definition at line 58 of file local_ip.h.

59  {
60  if( (ip | 0xffffff00) == 0xffffff7f)
61  return true;
62  //MAKE_IP
63  /*
64  loopback ip
65  127.0.0.0 — 127.255.255.255
66  */
67  return false;
68  }
boost::endian::big_uint32_t ip
Definition: socks.cpp:61
Here is the caller graph for this function:

◆ is_ssl()

bool epee::net_utils::is_ssl ( const unsigned char *  data,
size_t  len 
)

Definition at line 382 of file net_ssl.cpp.

383 {
384  if (len < get_ssl_magic_size())
385  return false;
386 
387  // https://security.stackexchange.com/questions/34780/checking-client-hello-for-https-classification
388  MDEBUG("SSL detection buffer, " << len << " bytes: "
389  << (unsigned)(unsigned char)data[0] << " " << (unsigned)(unsigned char)data[1] << " "
390  << (unsigned)(unsigned char)data[2] << " " << (unsigned)(unsigned char)data[3] << " "
391  << (unsigned)(unsigned char)data[4] << " " << (unsigned)(unsigned char)data[5] << " "
392  << (unsigned)(unsigned char)data[6] << " " << (unsigned)(unsigned char)data[7] << " "
393  << (unsigned)(unsigned char)data[8]);
394  if (data[0] == 0x16) // record
395  if (data[1] == 3) // major version
396  if (data[5] == 1) // ClientHello
397  if (data[6] == 0 && data[3]*256 + data[4] == data[7]*256 + data[8] + 4) // length check
398  return true;
399  return false;
400 }
constexpr size_t get_ssl_magic_size()
Definition: net_ssl.h:135
#define MDEBUG(x)
Definition: misc_log_ex.h:76
Here is the call graph for this function:

◆ MAKE_LOGGABLE()

epee::net_utils::MAKE_LOGGABLE ( connection_context_base  ,
ct  ,
os   
)
inline

Definition at line 344 of file net_utils_base.h.

345 {
346  os << "[" << epee::net_utils::print_connection_context_short(ct) << "] ";
347  return os;
348 }
std::string print_connection_context_short(const connection_context_base &ctx)
Here is the call graph for this function:

◆ notify_remote_command2() [1/2]

template<class t_arg , class t_transport >
bool epee::net_utils::notify_remote_command2 ( int  command,
const t_arg &  out_struct,
t_transport &  transport 
)

Definition at line 69 of file levin_abstract_invoke2.h.

70  {
71  if(!transport.is_connected())
72  return false;
73 
74  serialization::portable_storage stg;
75  out_struct.store(&stg);
76  std::string buff_to_send;
77  stg.store_to_binary(buff_to_send);
78 
79  int res = transport.notify(command, buff_to_send);
80  if(res <=0 )
81  {
82  LOG_ERROR("Failed to notify command " << command << " return code " << res);
83  return false;
84  }
85  return true;
86  }
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_remote_command2() [2/2]

template<class t_arg , class t_transport >
bool epee::net_utils::notify_remote_command2 ( boost::uuids::uuid  conn_id,
int  command,
const t_arg &  out_struct,
t_transport &  transport 
)

Definition at line 153 of file levin_abstract_invoke2.h.

154  {
155 
156  serialization::portable_storage stg;
157  out_struct.store(stg);
158  std::string buff_to_send;
159  stg.store_to_binary(buff_to_send);
160 
161  int res = transport.notify(command, epee::strspan<uint8_t>(buff_to_send), conn_id);
162  if(res <=0 )
163  {
164  MERROR("Failed to notify command " << command << " return code " << res);
165  return false;
166  }
167  return true;
168  }
const char * res
Definition: hmac_keccak.cpp:41
#define MERROR(x)
Definition: misc_log_ex.h:73
::std::string string
Definition: gtest-port.h:1097
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:

◆ operator!=() [1/2]

bool epee::net_utils::operator!= ( const ipv4_network_address lhs,
const ipv4_network_address rhs 
)
inlinenoexcept

Definition at line 99 of file net_utils_base.h.

100  { return !lhs.equal(rhs); }

◆ operator!=() [2/2]

bool epee::net_utils::operator!= ( const network_address lhs,
const network_address rhs 
)
inline

Definition at line 233 of file net_utils_base.h.

234  { return !lhs.equal(rhs); }
Here is the call graph for this function:

◆ operator<() [1/2]

bool epee::net_utils::operator< ( const ipv4_network_address lhs,
const ipv4_network_address rhs 
)
inlinenoexcept

Definition at line 101 of file net_utils_base.h.

102  { return lhs.less(rhs); }

◆ operator<() [2/2]

bool epee::net_utils::operator< ( const network_address lhs,
const network_address rhs 
)
inline

Definition at line 235 of file net_utils_base.h.

236  { return lhs.less(rhs); }
Here is the call graph for this function:

◆ operator<=() [1/2]

bool epee::net_utils::operator<= ( const ipv4_network_address lhs,
const ipv4_network_address rhs 
)
inlinenoexcept

Definition at line 103 of file net_utils_base.h.

104  { return !rhs.less(lhs); }

◆ operator<=() [2/2]

bool epee::net_utils::operator<= ( const network_address lhs,
const network_address rhs 
)
inline

Definition at line 237 of file net_utils_base.h.

238  { return !rhs.less(lhs); }
Here is the call graph for this function:

◆ operator==() [1/2]

bool epee::net_utils::operator== ( const ipv4_network_address lhs,
const ipv4_network_address rhs 
)
inlinenoexcept

Definition at line 97 of file net_utils_base.h.

98  { return lhs.equal(rhs); }

◆ operator==() [2/2]

bool epee::net_utils::operator== ( const network_address lhs,
const network_address rhs 
)
inline

Definition at line 231 of file net_utils_base.h.

232  { return lhs.equal(rhs); }
Here is the call graph for this function:

◆ operator>() [1/2]

bool epee::net_utils::operator> ( const ipv4_network_address lhs,
const ipv4_network_address rhs 
)
inlinenoexcept

Definition at line 105 of file net_utils_base.h.

106  { return rhs.less(lhs); }

◆ operator>() [2/2]

bool epee::net_utils::operator> ( const network_address lhs,
const network_address rhs 
)
inline

Definition at line 239 of file net_utils_base.h.

240  { return rhs.less(lhs); }
Here is the call graph for this function:

◆ operator>=() [1/2]

bool epee::net_utils::operator>= ( const ipv4_network_address lhs,
const ipv4_network_address rhs 
)
inlinenoexcept

Definition at line 107 of file net_utils_base.h.

108  { return !lhs.less(rhs); }

◆ operator>=() [2/2]

bool epee::net_utils::operator>= ( const network_address lhs,
const network_address rhs 
)
inline

Definition at line 241 of file net_utils_base.h.

242  { return !lhs.less(rhs); }
Here is the call graph for this function:

◆ parse_uri()

bool epee::net_utils::parse_uri ( const std::string  uri,
http::uri_content content 
)
inline

iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash=

Definition at line 98 of file net_parse_helpers.h.

99  {
100 
102  content.m_query_params.clear();
103  STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal);
104 
105  boost::smatch result;
106  if(!(boost::regex_search(uri, result, rexp_match_uri, boost::match_default) && result[0].matched))
107  {
108  LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << uri);
109  content.m_path = uri;
110  return true;
111  }
112  if(result[1].matched)
113  {
114  content.m_path = result[1];
115  }
116  if(result[3].matched)
117  {
118  content.m_query = result[3];
119  }
120  if(result[5].matched)
121  {
122  content.m_fragment = result[5];
123  }
124  if(content.m_query.size())
125  {
126  parse_uri_query(content.m_query, content.m_query_params);
127  }
128  return true;
129  }
#define STATIC_REGEXP_EXPR_1(var_name, xpr_text, reg_exp_flags)
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
bool parse_uri_query(const std::string &query, std::list< std::pair< std::string, std::string > > &params)
std::list< std::pair< std::string, std::string > > m_query_params
Definition: http_base.h:143
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_uri_query()

bool epee::net_utils::parse_uri_query ( const std::string &  query,
std::list< std::pair< std::string, std::string > > &  params 
)
inline

Definition at line 42 of file net_parse_helpers.h.

43  {
44  enum state
45  {
46  st_param_name,
47  st_param_val
48  };
49  state st = st_param_name;
50  std::string::const_iterator start_it = query.begin();
51  std::pair<std::string, std::string> e;
52  for(std::string::const_iterator it = query.begin(); it != query.end(); it++)
53  {
54  switch(st)
55  {
56  case st_param_name:
57  if(*it == '=')
58  {
59  e.first.assign(start_it, it);
60  start_it = it;++start_it;
61  st = st_param_val;
62  }
63  break;
64  case st_param_val:
65  if(*it == '&')
66  {
67  e.second.assign(start_it, it);
68  start_it = it;++start_it;
69  params.push_back(e);
70  e.first.clear();e.second.clear();
71  st = st_param_name;
72  }
73  break;
74  default:
75  LOG_ERROR("Unknown state " << (int)st);
76  return false;
77  }
78  }
79  if(st == st_param_name)
80  {
81  if(start_it != query.end())
82  {
83  e.first.assign(start_it, query.end());
84  params.push_back(e);
85  }
86  }else
87  {
88  if(start_it != query.end())
89  e.second.assign(start_it, query.end());
90 
91  if(e.first.size())
92  params.push_back(e);
93  }
94  return true;
95  }
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
Definition: blake256.h:37
Here is the caller graph for this function:

◆ parse_url()

bool epee::net_utils::parse_url ( const std::string  url_str,
http::url_content content 
)
inline

iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash=

Definition at line 133 of file net_parse_helpers.h.

134  {
135 
137  //STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal);
138  STATIC_REGEXP_EXPR_1(rexp_match_uri, "^((.*?)://)?(([^/:]*)(:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal);
139  // 12 34 5 6 7
140  content.port = 0;
141  boost::smatch result;
142  if(!(boost::regex_search(url_str, result, rexp_match_uri, boost::match_default) && result[0].matched))
143  {
144  LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << rexp_match_uri);
145  //content.m_path = uri;
146  return true;
147  }
148  if(result[2].matched)
149  {
150  content.schema = result[2];
151  }
152  if(result[4].matched)
153  {
154  content.host = result[4];
155  }
156  if(result[6].matched)
157  {
158  content.port = boost::lexical_cast<uint64_t>(result[6]);
159  }
160  if(result[7].matched)
161  {
162  content.uri = result[7];
163  return parse_uri(result[7], content.m_uri_content);
164  }
165 
166  return true;
167  }
#define STATIC_REGEXP_EXPR_1(var_name, xpr_text, reg_exp_flags)
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
bool parse_uri(const std::string uri, http::uri_content &content)
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_connection_context()

std::string epee::net_utils::print_connection_context ( const connection_context_base ctx)

Definition at line 59 of file net_utils_base.cpp.

60  {
61  std::stringstream ss;
62  ss << ctx.m_remote_address.str() << " " << ctx.m_connection_id << (ctx.m_is_income ? " INC":" OUT");
63  return ss.str();
64  }
Here is the call graph for this function:

◆ print_connection_context_short()

std::string epee::net_utils::print_connection_context_short ( const connection_context_base ctx)

Definition at line 66 of file net_utils_base.cpp.

67  {
68  std::stringstream ss;
69  ss << ctx.m_remote_address.str() << (ctx.m_is_income ? " INC":" OUT");
70  return ss.str();
71  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown_connection()

bool epee::net_utils::shutdown_connection ( connection< TProtocol > *  pconn)

◆ ssl_support_from_string()

bool epee::net_utils::ssl_support_from_string ( ssl_support_t ssl,
boost::string_ref  s 
)

Definition at line 516 of file net_ssl.cpp.

◆ to_string()

std::string epee::net_utils::to_string ( t_connection_type  type)

Definition at line 78 of file connection_basic.cpp.

79  {
80  if (type == e_connection_type_NET)
81  return std::string("NET");
82  else if (type == e_connection_type_RPC)
83  return std::string("RPC");
84  else if (type == e_connection_type_P2P)
85  return std::string("P2P");
86 
87  return std::string("UNKNOWN");
88  }
::std::string string
Definition: gtest-port.h:1097
Here is the caller graph for this function:

◆ worker_thread_member()

PRAGMA_WARNING_POP bool epee::net_utils::worker_thread_member ( )

◆ zone_from_string()

zone epee::net_utils::zone_from_string ( boost::string_ref  value)
noexcept
Returns
zone enum of value or zone::invalid on error.

Definition at line 89 of file net_utils_base.cpp.

90  {
91  if (value == "public")
92  return zone::public_;
93  if (value == "i2p")
94  return zone::i2p;
95  if (value == "tor")
96  return zone::tor;
97  return zone::invalid;
98  }
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
Here is the caller graph for this function:

◆ zone_to_string()

const char * epee::net_utils::zone_to_string ( zone  value)
noexcept
Returns
String name of zone or "invalid" on error.

Definition at line 73 of file net_utils_base.cpp.

74  {
75  switch (value)
76  {
77  case zone::public_:
78  return "public";
79  case zone::i2p:
80  return "i2p";
81  case zone::tor:
82  return "tor";
83  default:
84  break;
85  }
86  return "invalid";
87  }
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
Here is the caller graph for this function:

Variable Documentation

◆ m_completion_port

HANDLE epee::net_utils::m_completion_port

Definition at line 221 of file abstract_tcp_server_cp.h.

◆ m_config

TProtocol::config_type epee::net_utils::m_config

Definition at line 229 of file abstract_tcp_server_cp.h.

◆ m_connections

connections_container epee::net_utils::m_connections

Definition at line 222 of file abstract_tcp_server_cp.h.

◆ m_connections_lock

critical_section epee::net_utils::m_connections_lock

Definition at line 223 of file abstract_tcp_server_cp.h.

◆ m_initialized

bool epee::net_utils::m_initialized

Definition at line 227 of file abstract_tcp_server_cp.h.

◆ m_listen_socket

SOCKET epee::net_utils::m_listen_socket

Definition at line 220 of file abstract_tcp_server_cp.h.

◆ m_port

int epee::net_utils::m_port

Definition at line 224 of file abstract_tcp_server_cp.h.

◆ m_stop

volatile LONG epee::net_utils::m_stop

Definition at line 225 of file abstract_tcp_server_cp.h.

◆ m_worker_thread_counter

volatile LONG epee::net_utils::m_worker_thread_counter

Definition at line 228 of file abstract_tcp_server_cp.h.

◆ resize_send_buff

class epee::net_utils::buffer epee::net_utils::resize_send_buff