Monero
http_base.h
Go to the documentation of this file.
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 
27 
28 
29 #pragma once
30 #include "memwipe.h"
31 
32 #include <boost/utility/string_ref.hpp>
33 
34 #include <string>
35 #include <utility>
36 #include <list>
37 
38 #undef MONERO_DEFAULT_LOG_CATEGORY
39 #define MONERO_DEFAULT_LOG_CATEGORY "net.http"
40 
41 namespace epee
42 {
43 namespace net_utils
44 {
45  namespace http
46  {
47 
56  };
57 
59  {
64  };
65 
66  typedef std::list<std::pair<std::string, std::string> > fields_list;
67 
69 
71 
72  static inline void add_field(std::string& out, const boost::string_ref name, const boost::string_ref value)
73  {
74  out.append(name.data(), name.size()).append(": ");
75  out.append(value.data(), value.size()).append("\r\n");
76  }
77  static inline void add_field(std::string& out, const std::pair<std::string, std::string>& field)
78  {
79  add_field(out, field.first, field.second);
80  }
81 
82 
84  {
85  std::string m_connection; //"Connection:"
86  std::string m_referer; //"Referer:"
87  std::string m_content_length; //"Content-Length:"
88  std::string m_content_type; //"Content-Type:"
89  std::string m_transfer_encoding;//"Transfer-Encoding:"
90  std::string m_content_encoding; //"Content-Encoding:"
91  std::string m_host; //"Host:"
92  std::string m_cookie; //"Cookie:"
93  std::string m_user_agent; //"User-Agent:"
94  std::string m_origin; //"Origin:"
96 
97  void clear()
98  {
99  m_connection.clear();
100  m_referer.clear();
101  m_content_length.clear();
102  m_content_type.clear();
103  m_transfer_encoding.clear();
104  m_content_encoding.clear();
105  m_host.clear();
106  m_cookie.clear();
107  m_user_agent.clear();
108  m_origin.clear();
109  m_etc_fields.clear();
110  }
111  };
112 
113  struct uri_content
114  {
118  std::list<std::pair<std::string, std::string> > m_query_params;
119  };
120 
121  struct url_content
122  {
128  };
129 
130 
132  {
134  m_http_ver_hi(0),
135  m_http_ver_lo(0),
138  {}
139 
153 
154  void clear()
155  {
156  this->~http_request_info();
157  new(this) http_request_info();
158  }
159  };
160 
161 
163  {
170  int m_http_ver_hi;// OUT paramter only
171  int m_http_ver_lo;// OUT paramter only
172 
173  void clear()
174  {
175  this->~http_response_info();
176  new(this) http_response_info();
177  }
178 
179  void wipe()
180  {
181  memwipe(&m_body[0], m_body.size());
182  }
183  };
184  }
185 }
186 }
void clear()
Definition: http_base.h:154
std::string m_content_type
Definition: http_base.h:88
std::string m_fragment
Definition: http_base.h:117
std::string m_URI
Definition: http_base.h:141
std::string m_content_length
Definition: http_base.h:87
std::list< std::pair< std::string, std::string > > fields_list
Definition: http_base.h:66
static void add_field(std::string &out, const boost::string_ref name, const boost::string_ref value)
Definition: http_base.h:72
std::string m_query
Definition: http_base.h:116
Definition: http_base.h:54
http_header_info m_header_info
Definition: http_base.h:149
http_header_info m_header_info
Definition: http_base.h:169
::std::string string
Definition: gtest-port.h:1097
http_method
Definition: http_base.h:48
void clear()
Definition: http_base.h:97
std::string m_full_request_str
Definition: http_base.h:143
Definition: http_base.h:53
int m_http_ver_hi
Definition: http_base.h:170
std::string m_transfer_encoding
Definition: http_base.h:89
std::string m_origin
Definition: http_base.h:94
Definition: http_base.h:52
Definition: abstract_http_client.h:59
std::string m_mime_tipe
Definition: http_base.h:168
std::string m_cookie
Definition: http_base.h:92
std::string m_connection
Definition: http_base.h:85
uri_content m_uri_content
Definition: http_base.h:127
std::string get_value_from_uri_line(const std::string &param_name, const std::string &uri)
Definition: http_base.cpp:57
std::string m_host
Definition: http_base.h:91
void clear()
Definition: http_base.h:173
std::string schema
Definition: http_base.h:123
std::string m_path
Definition: http_base.h:115
Definition: http_base.h:51
int m_http_ver_lo
Definition: http_base.h:147
int m_http_ver_hi
Definition: http_base.h:146
std::string m_request_head
Definition: http_base.h:145
Definition: http_base.h:83
std::string m_response_comment
Definition: http_base.h:165
bool m_have_to_block
Definition: http_base.h:148
unsigned __int64 uint64_t
Definition: stdint.h:136
Definition: http_base.h:121
std::string uri
Definition: http_base.h:125
uri_content m_uri_content
Definition: http_base.h:150
int m_response_code
Definition: http_base.h:164
#define false
Definition: stdbool.h:37
std::string m_body
Definition: http_base.h:152
http_request_info()
Definition: http_base.h:133
std::string m_http_method_str
Definition: http_base.h:142
int m_http_ver_lo
Definition: http_base.h:171
http_method m_http_method
Definition: http_base.h:140
std::string m_content_encoding
Definition: http_base.h:90
std::string m_replace_html
Definition: http_base.h:144
TODO: (mj-xmr) This will be reduced in an another PR.
Definition: byte_slice.h:39
fields_list m_etc_fields
Definition: http_base.h:95
std::list< std::pair< std::string, std::string > > m_query_params
Definition: http_base.h:118
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
http_content_type
Definition: http_base.h:58
std::string m_user_agent
Definition: http_base.h:93
Definition: uri.py:1
Definition: http_base.h:50
std::string m_body
Definition: http_base.h:167
std::string host
Definition: http_base.h:124
Definition: http_base.h:113
void * memwipe(void *src, size_t n)
Definition: memwipe.c:107
const char * name
Definition: options.c:30
uint64_t port
Definition: http_base.h:126
Definition: http_base.h:131
std::string m_referer
Definition: http_base.h:86
std::string get_value_from_fields_list(const std::string &param_name, const net_utils::http::fields_list &fields)
Definition: http_base.cpp:44
size_t m_full_request_buf_size
Definition: http_base.h:151
void wipe()
Definition: http_base.h:179
fields_list m_additional_fields
Definition: http_base.h:166