Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
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 <boost/lexical_cast.hpp>
31
#include <boost/regex.hpp>
32
#include <boost/utility/string_ref.hpp>
33
#include <string>
34
#include <utility>
35
36
#include "
string_tools.h
"
37
38
#undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
39
#define ELECTRONEUM_DEFAULT_LOG_CATEGORY "net.http"
40
41
namespace
epee
42
{
43
namespace
net_utils
44
{
45
namespace
http
46
{
47
48
enum
http_method
{
49
http_method_options
,
50
http_method_get
,
51
http_method_post
,
52
http_method_put
,
53
http_method_head
,
54
http_method_etc
,
55
http_method_unknown
56
};
57
58
enum
http_content_type
59
{
60
http_content_type_text_html
,
61
http_content_type_image_gif
,
62
http_content_type_other
,
63
http_content_type_not_set
64
};
65
66
typedef
std::list<std::pair<std::string, std::string> >
fields_list
;
67
68
inline
69
std::string
get_value_from_fields_list
(
const
std::string& param_name,
const
net_utils::http::fields_list
& fields)
70
{
71
fields_list::const_iterator it = fields.begin();
72
for
(; it != fields.end(); it++)
73
if
(!
string_tools::compare_no_case
(param_name, it->first))
74
break
;
75
76
if
(it==fields.end())
77
return
std::string();
78
79
return
it->second;
80
}
81
82
83
inline
84
std::string
get_value_from_uri_line
(
const
std::string& param_name,
const
std::string& uri)
85
{
86
std::string buff =
"([\\?|&])"
;
87
buff += param_name +
"=([^&]*)"
;
88
boost::regex match_param(buff.c_str(), boost::regex::icase | boost::regex::normal);
89
boost::smatch result;
90
if
(boost::regex_search(uri, result, match_param, boost::match_default) && result[0].matched)
91
{
92
return
result[2];
93
}
94
return
std::string();
95
}
96
97
static
inline
void
add_field(std::string& out,
const
boost::string_ref name,
const
boost::string_ref
value
)
98
{
99
out.append(name.data(), name.size()).append(
": "
);
100
out.append(
value
.data(),
value
.size()).append(
"\r\n"
);
101
}
102
static
inline
void
add_field(std::string& out,
const
std::pair<std::string, std::string>& field)
103
{
104
add_field(out, field.first, field.second);
105
}
106
107
108
struct
http_header_info
109
{
110
std::string
m_connection
;
//"Connection:"
111
std::string
m_referer
;
//"Referer:"
112
std::string
m_content_length
;
//"Content-Length:"
113
std::string
m_content_type
;
//"Content-Type:"
114
std::string
m_transfer_encoding
;
//"Transfer-Encoding:"
115
std::string
m_content_encoding
;
//"Content-Encoding:"
116
std::string
m_host
;
//"Host:"
117
std::string
m_cookie
;
//"Cookie:"
118
std::string
m_user_agent
;
//"User-Agent:"
119
std::string
m_origin
;
//"Origin:"
120
fields_list
m_etc_fields
;
121
122
void
clear
()
123
{
124
m_connection
.clear();
125
m_referer
.clear();
126
m_content_length
.clear();
127
m_content_type
.clear();
128
m_transfer_encoding
.clear();
129
m_content_encoding
.clear();
130
m_host
.clear();
131
m_cookie
.clear();
132
m_user_agent
.clear();
133
m_origin
.clear();
134
m_etc_fields
.clear();
135
}
136
};
137
138
struct
uri_content
139
{
140
std::string
m_path
;
141
std::string
m_query
;
142
std::string
m_fragment
;
143
std::list<std::pair<std::string, std::string> >
m_query_params
;
144
};
145
146
struct
url_content
147
{
148
std::string
schema
;
149
std::string
host
;
150
std::string
uri
;
151
uint64_t
port
;
152
uri_content
m_uri_content
;
153
};
154
155
156
struct
http_request_info
157
{
158
http_request_info
():
m_http_method
(
http_method_unknown
),
159
m_http_ver_hi
(0),
160
m_http_ver_lo
(0),
161
m_have_to_block
(
false
),
162
m_full_request_buf_size
(0)
163
{}
164
165
http_method
m_http_method
;
166
std::string
m_URI
;
167
std::string
m_http_method_str
;
168
std::string
m_full_request_str
;
169
std::string
m_replace_html
;
170
std::string
m_request_head
;
171
int
m_http_ver_hi
;
172
int
m_http_ver_lo
;
173
bool
m_have_to_block
;
174
http_header_info
m_header_info
;
175
uri_content
m_uri_content
;
176
size_t
m_full_request_buf_size
;
177
std::string
m_body
;
178
179
void
clear
()
180
{
181
this->
~http_request_info
();
182
new
(
this
)
http_request_info
();
183
}
184
};
185
186
187
struct
http_response_info
188
{
189
int
m_response_code
;
190
std::string
m_response_comment
;
191
fields_list
m_additional_fields
;
192
std::string
m_body
;
193
std::string
m_mime_tipe
;
194
http_header_info
m_header_info
;
195
int
m_http_ver_hi
;
// OUT paramter only
196
int
m_http_ver_lo
;
// OUT paramter only
197
198
void
clear
()
199
{
200
this->
~http_response_info
();
201
new
(
this
)
http_response_info
();
202
}
203
};
204
}
205
}
206
}
epee::net_utils::http::http_method
http_method
Definition
http_base.h:48
epee::net_utils::http::http_method_head
@ http_method_head
Definition
http_base.h:53
epee::net_utils::http::http_method_etc
@ http_method_etc
Definition
http_base.h:54
epee::net_utils::http::http_method_put
@ http_method_put
Definition
http_base.h:52
epee::net_utils::http::http_method_get
@ http_method_get
Definition
http_base.h:50
epee::net_utils::http::http_method_post
@ http_method_post
Definition
http_base.h:51
epee::net_utils::http::http_method_options
@ http_method_options
Definition
http_base.h:49
epee::net_utils::http::http_method_unknown
@ http_method_unknown
Definition
http_base.h:55
epee::net_utils::http::http_content_type
http_content_type
Definition
http_base.h:59
epee::net_utils::http::http_content_type_text_html
@ http_content_type_text_html
Definition
http_base.h:60
epee::net_utils::http::http_content_type_other
@ http_content_type_other
Definition
http_base.h:62
epee::net_utils::http::http_content_type_not_set
@ http_content_type_not_set
Definition
http_base.h:63
epee::net_utils::http::http_content_type_image_gif
@ http_content_type_image_gif
Definition
http_base.h:61
epee::net_utils::http::fields_list
std::list< std::pair< std::string, std::string > > fields_list
Definition
http_base.h:66
epee::net_utils::http::get_value_from_fields_list
std::string get_value_from_fields_list(const std::string ¶m_name, const net_utils::http::fields_list &fields)
Definition
http_base.h:69
epee::net_utils::http::get_value_from_uri_line
std::string get_value_from_uri_line(const std::string ¶m_name, const std::string &uri)
Definition
http_base.h:84
epee::string_tools::compare_no_case
bool compare_no_case(const std::string &str1, const std::string &str2)
Definition
string_tools.h:221
epee
Definition
ado_db_helper.h:67
value
const GenericPointer< typename T::ValueType > T2 value
Definition
pointer.h:1225
false
#define false
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
string_tools.h
epee::net_utils::http::http_header_info
Definition
http_base.h:109
epee::net_utils::http::http_header_info::m_etc_fields
fields_list m_etc_fields
Definition
http_base.h:120
epee::net_utils::http::http_header_info::m_content_length
std::string m_content_length
Definition
http_base.h:112
epee::net_utils::http::http_header_info::m_content_encoding
std::string m_content_encoding
Definition
http_base.h:115
epee::net_utils::http::http_header_info::m_origin
std::string m_origin
Definition
http_base.h:119
epee::net_utils::http::http_header_info::m_referer
std::string m_referer
Definition
http_base.h:111
epee::net_utils::http::http_header_info::m_cookie
std::string m_cookie
Definition
http_base.h:117
epee::net_utils::http::http_header_info::clear
void clear()
Definition
http_base.h:122
epee::net_utils::http::http_header_info::m_connection
std::string m_connection
Definition
http_base.h:110
epee::net_utils::http::http_header_info::m_user_agent
std::string m_user_agent
Definition
http_base.h:118
epee::net_utils::http::http_header_info::m_content_type
std::string m_content_type
Definition
http_base.h:113
epee::net_utils::http::http_header_info::m_transfer_encoding
std::string m_transfer_encoding
Definition
http_base.h:114
epee::net_utils::http::http_header_info::m_host
std::string m_host
Definition
http_base.h:116
epee::net_utils::http::http_request_info::http_request_info
http_request_info()
Definition
http_base.h:158
epee::net_utils::http::http_request_info::m_have_to_block
bool m_have_to_block
Definition
http_base.h:173
epee::net_utils::http::http_request_info::m_full_request_str
std::string m_full_request_str
Definition
http_base.h:168
epee::net_utils::http::http_request_info::m_full_request_buf_size
size_t m_full_request_buf_size
Definition
http_base.h:176
epee::net_utils::http::http_request_info::m_uri_content
uri_content m_uri_content
Definition
http_base.h:175
epee::net_utils::http::http_request_info::m_http_ver_hi
int m_http_ver_hi
Definition
http_base.h:171
epee::net_utils::http::http_request_info::m_body
std::string m_body
Definition
http_base.h:177
epee::net_utils::http::http_request_info::m_http_method_str
std::string m_http_method_str
Definition
http_base.h:167
epee::net_utils::http::http_request_info::m_header_info
http_header_info m_header_info
Definition
http_base.h:174
epee::net_utils::http::http_request_info::m_replace_html
std::string m_replace_html
Definition
http_base.h:169
epee::net_utils::http::http_request_info::m_http_method
http_method m_http_method
Definition
http_base.h:165
epee::net_utils::http::http_request_info::m_request_head
std::string m_request_head
Definition
http_base.h:170
epee::net_utils::http::http_request_info::m_URI
std::string m_URI
Definition
http_base.h:166
epee::net_utils::http::http_request_info::clear
void clear()
Definition
http_base.h:179
epee::net_utils::http::http_request_info::m_http_ver_lo
int m_http_ver_lo
Definition
http_base.h:172
epee::net_utils::http::http_response_info
Definition
http_base.h:188
epee::net_utils::http::http_response_info::m_http_ver_lo
int m_http_ver_lo
Definition
http_base.h:196
epee::net_utils::http::http_response_info::clear
void clear()
Definition
http_base.h:198
epee::net_utils::http::http_response_info::m_http_ver_hi
int m_http_ver_hi
Definition
http_base.h:195
epee::net_utils::http::http_response_info::m_response_comment
std::string m_response_comment
Definition
http_base.h:190
epee::net_utils::http::http_response_info::m_mime_tipe
std::string m_mime_tipe
Definition
http_base.h:193
epee::net_utils::http::http_response_info::m_response_code
int m_response_code
Definition
http_base.h:189
epee::net_utils::http::http_response_info::m_header_info
http_header_info m_header_info
Definition
http_base.h:194
epee::net_utils::http::http_response_info::m_body
std::string m_body
Definition
http_base.h:192
epee::net_utils::http::http_response_info::m_additional_fields
fields_list m_additional_fields
Definition
http_base.h:191
epee::net_utils::http::uri_content
Definition
http_base.h:139
epee::net_utils::http::uri_content::m_path
std::string m_path
Definition
http_base.h:140
epee::net_utils::http::uri_content::m_fragment
std::string m_fragment
Definition
http_base.h:142
epee::net_utils::http::uri_content::m_query_params
std::list< std::pair< std::string, std::string > > m_query_params
Definition
http_base.h:143
epee::net_utils::http::uri_content::m_query
std::string m_query
Definition
http_base.h:141
epee::net_utils::http::url_content
Definition
http_base.h:147
epee::net_utils::http::url_content::m_uri_content
uri_content m_uri_content
Definition
http_base.h:152
epee::net_utils::http::url_content::schema
std::string schema
Definition
http_base.h:148
epee::net_utils::http::url_content::uri
std::string uri
Definition
http_base.h:150
epee::net_utils::http::url_content::host
std::string host
Definition
http_base.h:149
epee::net_utils::http::url_content::port
uint64_t port
Definition
http_base.h:151
contrib
epee
include
net
http_base.h
Generated on
for Electroneum by
1.17.0