Monero
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 "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
42namespace epee
43{
44namespace net_utils
45{
46 namespace http
47 {
48
58
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
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
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
123 {
124 std::string schema;
125 std::string host;
126 std::string uri;
129 };
130
131
161
162
164 {
168 std::string m_body;
169 std::string m_mime_tipe;
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}
#define false
void * memwipe(void *src, size_t n)
Definition memwipe.c:107
http_method
Definition http_base.h:49
@ http_method_head
Definition http_base.h:54
@ http_method_etc
Definition http_base.h:55
@ http_method_put
Definition http_base.h:53
@ http_method_get
Definition http_base.h:51
@ http_method_post
Definition http_base.h:52
@ http_method_options
Definition http_base.h:50
@ http_method_unknown
Definition http_base.h:56
http_content_type
Definition http_base.h:60
@ http_content_type_text_html
Definition http_base.h:61
@ http_content_type_other
Definition http_base.h:63
@ http_content_type_not_set
Definition http_base.h:64
@ http_content_type_image_gif
Definition http_base.h:62
static void add_field(std::string &out, const boost::string_ref name, const boost::string_ref value)
Definition http_base.h:73
std::list< std::pair< std::string, std::string > > fields_list
Definition http_base.h:67
std::string get_value_from_fields_list(const std::string &param_name, const net_utils::http::fields_list &fields)
Definition http_base.cpp:44
std::string get_value_from_uri_line(const std::string &param_name, const std::string &uri)
Definition http_base.cpp:57
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
Definition uri.py:1
const char * name
Definition options.c:30
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
unsigned __int64 uint64_t
Definition stdint.h:136
fields_list m_etc_fields
Definition http_base.h:96
std::string m_content_length
Definition http_base.h:88
std::string m_content_encoding
Definition http_base.h:91
std::string m_origin
Definition http_base.h:95
std::string m_referer
Definition http_base.h:87
std::string m_cookie
Definition http_base.h:93
void clear()
Definition http_base.h:98
std::string m_connection
Definition http_base.h:86
std::string m_user_agent
Definition http_base.h:94
std::string m_content_type
Definition http_base.h:89
std::string m_transfer_encoding
Definition http_base.h:90
std::string m_host
Definition http_base.h:92
http_request_info()
Definition http_base.h:134
bool m_have_to_block
Definition http_base.h:149
std::string m_full_request_str
Definition http_base.h:144
size_t m_full_request_buf_size
Definition http_base.h:152
uri_content m_uri_content
Definition http_base.h:151
int m_http_ver_hi
Definition http_base.h:147
std::string m_body
Definition http_base.h:153
std::string m_http_method_str
Definition http_base.h:143
http_header_info m_header_info
Definition http_base.h:150
std::string m_replace_html
Definition http_base.h:145
http_method m_http_method
Definition http_base.h:141
std::string m_request_head
Definition http_base.h:146
std::string m_URI
Definition http_base.h:142
void clear()
Definition http_base.h:155
int m_http_ver_lo
Definition http_base.h:148
int m_http_ver_lo
Definition http_base.h:172
void clear()
Definition http_base.h:174
int m_http_ver_hi
Definition http_base.h:171
void wipe()
Definition http_base.h:180
std::string m_response_comment
Definition http_base.h:166
std::string m_mime_tipe
Definition http_base.h:169
int m_response_code
Definition http_base.h:165
http_header_info m_header_info
Definition http_base.h:170
std::string m_body
Definition http_base.h:168
fields_list m_additional_fields
Definition http_base.h:167
Definition http_base.h:115
std::string m_path
Definition http_base.h:116
std::string m_fragment
Definition http_base.h:118
std::list< std::pair< std::string, std::string > > m_query_params
Definition http_base.h:119
std::string m_query
Definition http_base.h:117
Definition http_base.h:123
uri_content m_uri_content
Definition http_base.h:128
std::string schema
Definition http_base.h:124
std::string host
Definition http_base.h:125
uint64_t port
Definition http_base.h:127