Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
message.h
Go to the documentation of this file.
1
// Copyright (c) 2016-2019, The Monero Project
2
//
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without modification, are
6
// permitted provided that the following conditions are met:
7
//
8
// 1. Redistributions of source code must retain the above copyright notice, this list of
9
// conditions and the following disclaimer.
10
//
11
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12
// of conditions and the following disclaimer in the documentation and/or other
13
// materials provided with the distribution.
14
//
15
// 3. Neither the name of the copyright holder nor the names of its contributors may be
16
// used to endorse or promote products derived from this software without specific
17
// prior written permission.
18
//
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
#pragma once
30
31
#include "
rapidjson/document.h
"
32
#include "
rpc/message_data_structs.h
"
33
#include <string>
34
35
/* I normally hate using macros, but in this case it would be untenably
36
* verbose to not use a macro. This macro saves the trouble of explicitly
37
* writing the below if block for every single RPC call.
38
*/
39
#define REQ_RESP_TYPES_MACRO( runtime_str, type, reqjson, resp_message_ptr, handler) \
40
\
41
if (runtime_str == type::name) \
42
{ \
43
type::Request reqvar; \
44
type::Response *respvar = new type::Response(); \
45
\
46
reqvar.fromJson(reqjson); \
47
\
48
handler(reqvar, *respvar); \
49
\
50
resp_message_ptr = respvar; \
51
}
52
53
namespace
cryptonote
54
{
55
56
namespace
rpc
57
{
58
59
class
Message
60
{
61
public
:
62
static
const
char
*
STATUS_OK
;
63
static
const
char
*
STATUS_RETRY
;
64
static
const
char
*
STATUS_FAILED
;
65
static
const
char
*
STATUS_BAD_REQUEST
;
66
static
const
char
*
STATUS_BAD_JSON
;
67
68
Message
() :
status
(
STATUS_OK
),
rpc_version
(0) { }
69
70
virtual
~Message
() { }
71
72
virtual
rapidjson::Value
toJson
(rapidjson::Document& doc)
const
;
73
74
virtual
void
fromJson
(rapidjson::Value& val);
75
76
std::string
status
;
77
std::string
error_details
;
78
uint32_t
rpc_version
;
79
};
80
81
class
FullMessage
82
{
83
public
:
84
~FullMessage
() { }
85
86
FullMessage
(
FullMessage
&& rhs) noexcept : doc(std::move(rhs.doc)) { }
87
88
FullMessage
(
const
std::string& json_string,
bool
request=
false
);
89
90
std::string
getJson
();
91
92
std::string
getRequestType
()
const
;
93
94
rapidjson::Value&
getMessage
();
95
96
rapidjson::Value
getMessageCopy
();
97
98
rapidjson::Value&
getID
();
99
100
void
setID
(rapidjson::Value&
id
);
101
102
cryptonote::rpc::error
getError
();
103
104
static
FullMessage
requestMessage
(
const
std::string& request,
Message
*
message
);
105
static
FullMessage
requestMessage
(
const
std::string& request,
Message
*
message
, rapidjson::Value&
id
);
106
107
static
FullMessage
responseMessage
(
Message
*
message
);
108
static
FullMessage
responseMessage
(
Message
*
message
, rapidjson::Value&
id
);
109
110
static
FullMessage
*
timeoutMessage
();
111
private
:
112
113
FullMessage
() =
default
;
114
115
FullMessage
(
const
std::string& request,
Message
*
message
);
116
FullMessage
(
Message
*
message
);
117
118
rapidjson::Document doc;
119
};
120
121
122
// convenience functions for bad input
123
std::string
BAD_REQUEST
(
const
std::string& request);
124
std::string
BAD_REQUEST
(
const
std::string& request, rapidjson::Value&
id
);
125
126
std::string
BAD_JSON
(
const
std::string& error_details);
127
128
129
}
// namespace rpc
130
131
}
// namespace cryptonote
cryptonote::rpc::FullMessage
Definition
message.h:82
cryptonote::rpc::FullMessage::~FullMessage
~FullMessage()
Definition
message.h:84
cryptonote::rpc::FullMessage::getID
rapidjson::Value & getID()
Definition
message.cpp:182
cryptonote::rpc::FullMessage::timeoutMessage
static FullMessage * timeoutMessage()
Definition
message.cpp:238
cryptonote::rpc::FullMessage::getJson
std::string getJson()
Definition
message.cpp:135
cryptonote::rpc::FullMessage::FullMessage
FullMessage(FullMessage &&rhs) noexcept
Definition
message.h:86
cryptonote::rpc::FullMessage::getMessage
rapidjson::Value & getMessage()
Definition
message.cpp:158
cryptonote::rpc::FullMessage::responseMessage
static FullMessage responseMessage(Message *message)
Definition
message.cpp:226
cryptonote::rpc::FullMessage::getMessageCopy
rapidjson::Value getMessageCopy()
Definition
message.cpp:175
cryptonote::rpc::FullMessage::getRequestType
std::string getRequestType() const
Definition
message.cpp:152
cryptonote::rpc::FullMessage::requestMessage
static FullMessage requestMessage(const std::string &request, Message *message)
Definition
message.cpp:214
cryptonote::rpc::FullMessage::getError
cryptonote::rpc::error getError()
Definition
message.cpp:201
cryptonote::rpc::FullMessage::setID
void setID(rapidjson::Value &id)
Definition
message.cpp:188
cryptonote::rpc::Message
Definition
message.h:60
cryptonote::rpc::Message::STATUS_FAILED
static const char * STATUS_FAILED
Definition
message.h:64
cryptonote::rpc::Message::status
std::string status
Definition
message.h:76
cryptonote::rpc::Message::STATUS_OK
static const char * STATUS_OK
Definition
message.h:62
cryptonote::rpc::Message::Message
Message()
Definition
message.h:68
cryptonote::rpc::Message::STATUS_BAD_JSON
static const char * STATUS_BAD_JSON
Definition
message.h:66
cryptonote::rpc::Message::STATUS_RETRY
static const char * STATUS_RETRY
Definition
message.h:63
cryptonote::rpc::Message::fromJson
virtual void fromJson(rapidjson::Value &val)
Definition
message.cpp:70
cryptonote::rpc::Message::rpc_version
uint32_t rpc_version
Definition
message.h:78
cryptonote::rpc::Message::error_details
std::string error_details
Definition
message.h:77
cryptonote::rpc::Message::toJson
virtual rapidjson::Value toJson(rapidjson::Document &doc) const
Definition
message.cpp:57
cryptonote::rpc::Message::STATUS_BAD_REQUEST
static const char * STATUS_BAD_REQUEST
Definition
message.h:65
cryptonote::rpc::Message::~Message
virtual ~Message()
Definition
message.h:70
message
std::string message("Message requiring signing")
document.h
message_data_structs.h
cryptonote::rpc::BAD_REQUEST
std::string BAD_REQUEST(const std::string &request)
Definition
message.cpp:259
cryptonote::rpc::BAD_JSON
std::string BAD_JSON(const std::string &error_details)
Definition
message.cpp:281
cryptonote
Holds cryptonote related classes and helpers.
Definition
ban.cpp:40
uint32_t
unsigned int uint32_t
Definition
stdint.h:126
cryptonote::rpc::error
Definition
message_data_structs.h:144
src
rpc
message.h
Generated on
for Electroneum by
1.17.0