| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 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 |
|
| 49 |
enum http_method{ |
| 50 |
http_method_options, |
| 51 |
http_method_get, |
| 52 |
http_method_post, |
| 53 |
http_method_put, |
| 54 |
http_method_head, |
| 55 |
http_method_etc, |
| 56 |
http_method_unknown |
| 57 |
}; |
| 58 |
|
| 59 |
enum http_content_type |
| 60 |
{ |
| 61 |
http_content_type_text_html, |
| 62 |
http_content_type_image_gif, |
| 63 |
http_content_type_other, |
| 64 |
http_content_type_not_set |
| 65 |
}; |
| 66 |
|
| 67 |
typedef std::list<std::pair<std::string, std::string> > fields_list; |
| 68 |
|
| 69 |
std::string get_value_from_fields_list(const std::string& param_name, const net_utils::http::fields_list& fields); |
| 70 |
|
| 71 |
std::string get_value_from_uri_line(const std::string& param_name, const std::string& uri); |
| 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 |
|
| 84 |
struct http_header_info |
| 85 |
{ |
| 86 |
std::string m_connection; |
| 87 |
std::string m_referer; |
| 88 |
std::string m_content_length; |
| 89 |
std::string m_content_type; |
| 90 |
std::string m_transfer_encoding; |
| 91 |
std::string m_content_encoding; |
| 92 |
std::string m_host; |
| 93 |
std::string m_cookie; |
| 94 |
std::string m_user_agent; |
| 95 |
std::string m_origin; |
| 96 |
fields_list m_etc_fields; |
| 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 |
{ |
| 116 |
std::string m_path; |
| 117 |
std::string m_query; |
| 118 |
std::string m_fragment; |
| 119 |
std::list<std::pair<std::string, std::string> > m_query_params; |
| 120 |
}; |
| 121 |
|
| 122 |
struct url_content |
| 123 |
{ |
| 124 |
std::string schema; |
| 125 |
std::string host; |
| 126 |
std::string uri; |
| 127 |
uint64_t port; |
| 128 |
uri_content m_uri_content; |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
struct http_request_info |
| 133 |
{ |
| 134 |
http_request_info():m_http_method(http_method_unknown), |
| 135 |
m_http_ver_hi(0), |
| 136 |
m_http_ver_lo(0), |
| 137 |
m_have_to_block(false), |
| 138 |
m_full_request_buf_size(0) |
| 139 |
{} |
| 140 |
|
| 141 |
http_method m_http_method; |
| 142 |
std::string m_URI; |
| 143 |
std::string m_http_method_str; |
| 144 |
std::string m_full_request_str; |
| 145 |
std::string m_replace_html; |
| 146 |
std::string m_request_head; |
| 147 |
int m_http_ver_hi; |
| 148 |
int m_http_ver_lo; |
| 149 |
bool m_have_to_block; |
| 150 |
http_header_info m_header_info; |
| 151 |
uri_content m_uri_content; |
| 152 |
size_t m_full_request_buf_size; |
| 153 |
std::string m_body; |
| 154 |
|
| 155 |
void clear() |
| 156 |
{ |
| 157 |
this->~http_request_info(); |
| 158 |
new(this) http_request_info(); |
| 159 |
} |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
struct http_response_info |
| 164 |
{ |
| 165 |
int m_response_code; |
| 166 |
std::string m_response_comment; |
| 167 |
fields_list m_additional_fields; |
| 168 |
std::string m_body; |
| 169 |
std::string m_mime_tipe; |
| 170 |
http_header_info m_header_info; |
| 171 |
int m_http_ver_hi; |
| 172 |
int m_http_ver_lo; |
| 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 |
} |