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